refactor(facade): inline StringWrapper (#12051)
This commit is contained in:
@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
import {Inject, Injectable, RenderComponentType, Renderer, RootRenderer, ViewEncapsulation} from '@angular/core';
|
||||
import {Json, StringWrapper, isArray, isBlank, isPresent, isString, stringify} from '../facade/lang';
|
||||
import {Json, isArray, isBlank, isPresent, isString, stringify} from '../facade/lang';
|
||||
import {AnimationKeyframe, AnimationPlayer, AnimationStyles, RenderDebugInfo} from '../private_import_core';
|
||||
|
||||
import {AnimationDriver} from './animation_driver';
|
||||
@ -192,13 +192,12 @@ export class DomRenderer implements Renderer {
|
||||
setBindingDebugInfo(renderElement: any, propertyName: string, propertyValue: string): void {
|
||||
var dashCasedPropertyName = camelCaseToDashCase(propertyName);
|
||||
if (getDOM().isCommentNode(renderElement)) {
|
||||
const existingBindings = StringWrapper.replaceAll(getDOM().getText(renderElement), /\n/g, '')
|
||||
.match(TEMPLATE_BINDINGS_EXP);
|
||||
const existingBindings =
|
||||
getDOM().getText(renderElement).replace(/\n/g, '').match(TEMPLATE_BINDINGS_EXP);
|
||||
var parsedBindings = Json.parse(existingBindings[1]);
|
||||
(parsedBindings as any /** TODO #9100 */)[dashCasedPropertyName] = propertyValue;
|
||||
getDOM().setText(
|
||||
renderElement,
|
||||
StringWrapper.replace(TEMPLATE_COMMENT_TEXT, '{}', Json.stringify(parsedBindings)));
|
||||
renderElement, TEMPLATE_COMMENT_TEXT.replace('{}', Json.stringify(parsedBindings)));
|
||||
} else {
|
||||
this.setElementAttribute(renderElement, propertyName, propertyValue);
|
||||
}
|
||||
@ -272,11 +271,11 @@ export const HOST_ATTR = `_nghost-${COMPONENT_VARIABLE}`;
|
||||
export const CONTENT_ATTR = `_ngcontent-${COMPONENT_VARIABLE}`;
|
||||
|
||||
function _shimContentAttribute(componentShortId: string): string {
|
||||
return StringWrapper.replaceAll(CONTENT_ATTR, COMPONENT_REGEX, componentShortId);
|
||||
return CONTENT_ATTR.replace(COMPONENT_REGEX, componentShortId);
|
||||
}
|
||||
|
||||
function _shimHostAttribute(componentShortId: string): string {
|
||||
return StringWrapper.replaceAll(HOST_ATTR, COMPONENT_REGEX, componentShortId);
|
||||
return HOST_ATTR.replace(COMPONENT_REGEX, componentShortId);
|
||||
}
|
||||
|
||||
function _flattenStyles(compId: string, styles: Array<any|any[]>, target: string[]): string[] {
|
||||
@ -285,7 +284,7 @@ function _flattenStyles(compId: string, styles: Array<any|any[]>, target: string
|
||||
if (isArray(style)) {
|
||||
_flattenStyles(compId, style, target);
|
||||
} else {
|
||||
style = StringWrapper.replaceAll(style, COMPONENT_REGEX, compId);
|
||||
style = style.replace(COMPONENT_REGEX, compId);
|
||||
target.push(style);
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
import {Injectable, NgZone} from '@angular/core';
|
||||
|
||||
import {ListWrapper} from '../../facade/collection';
|
||||
import {StringWrapper, isPresent} from '../../facade/lang';
|
||||
import {isPresent} from '../../facade/lang';
|
||||
import {getDOM} from '../dom_adapter';
|
||||
|
||||
import {EventManagerPlugin} from './event_manager';
|
||||
@ -50,9 +50,7 @@ export class KeyEventsPlugin extends EventManagerPlugin {
|
||||
var parts: string[] = eventName.toLowerCase().split('.');
|
||||
|
||||
var domEventName = parts.shift();
|
||||
if ((parts.length === 0) ||
|
||||
!(StringWrapper.equals(domEventName, 'keydown') ||
|
||||
StringWrapper.equals(domEventName, 'keyup'))) {
|
||||
if ((parts.length === 0) || !(domEventName === 'keydown' || domEventName === 'keyup')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -82,9 +80,9 @@ export class KeyEventsPlugin extends EventManagerPlugin {
|
||||
var fullKey = '';
|
||||
var key = getDOM().getEventKey(event);
|
||||
key = key.toLowerCase();
|
||||
if (StringWrapper.equals(key, ' ')) {
|
||||
if (key === ' ') {
|
||||
key = 'space'; // for readability
|
||||
} else if (StringWrapper.equals(key, '.')) {
|
||||
} else if (key === '.') {
|
||||
key = 'dot'; // because '.' is used as a separator in event names
|
||||
}
|
||||
modifierKeys.forEach(modifierName => {
|
||||
@ -102,7 +100,7 @@ export class KeyEventsPlugin extends EventManagerPlugin {
|
||||
static eventCallback(element: HTMLElement, fullKey: any, handler: Function, zone: NgZone):
|
||||
Function {
|
||||
return (event: any /** TODO #9100 */) => {
|
||||
if (StringWrapper.equals(KeyEventsPlugin.getEventFullKey(event), fullKey)) {
|
||||
if (KeyEventsPlugin.getEventFullKey(event) === fullKey) {
|
||||
zone.runGuarded(() => handler(event));
|
||||
}
|
||||
};
|
||||
|
@ -6,18 +6,14 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {StringWrapper} from '../facade/lang';
|
||||
|
||||
var CAMEL_CASE_REGEXP = /([A-Z])/g;
|
||||
var DASH_CASE_REGEXP = /-([a-z])/g;
|
||||
|
||||
|
||||
export function camelCaseToDashCase(input: string): string {
|
||||
return StringWrapper.replaceAllMapped(
|
||||
input, CAMEL_CASE_REGEXP, (m: string[]) => '-' + m[1].toLowerCase());
|
||||
return input.replace(CAMEL_CASE_REGEXP, (...m: string[]) => '-' + m[1].toLowerCase());
|
||||
}
|
||||
|
||||
export function dashCaseToCamelCase(input: string): string {
|
||||
return StringWrapper.replaceAllMapped(
|
||||
input, DASH_CASE_REGEXP, (m: string[]) => m[1].toUpperCase());
|
||||
return input.replace(DASH_CASE_REGEXP, (...m: string[]) => m[1].toUpperCase());
|
||||
}
|
||||
|
@ -7,7 +7,8 @@
|
||||
*/
|
||||
|
||||
import {AUTO_STYLE} from '@angular/core';
|
||||
import {StringWrapper, isNumber, isPresent} from '../facade/lang';
|
||||
|
||||
import {isNumber, isPresent} from '../facade/lang';
|
||||
import {AnimationKeyframe, AnimationStyles} from '../private_import_core';
|
||||
|
||||
import {AnimationDriver} from './animation_driver';
|
||||
@ -97,7 +98,7 @@ const _$PERIOD = 46;
|
||||
|
||||
function _findDimensionalSuffix(value: string): string {
|
||||
for (var i = 0; i < value.length; i++) {
|
||||
var c = StringWrapper.charCodeAt(value, i);
|
||||
var c = value.charCodeAt(i);
|
||||
if ((c >= _$0 && c <= _$9) || c == _$PERIOD) continue;
|
||||
return value.substring(i, value.length);
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
import {NgZone} from '@angular/core';
|
||||
|
||||
import {ListWrapper} from './facade/collection';
|
||||
import {StringWrapper, global, isPresent, isString} from './facade/lang';
|
||||
import {global, isPresent, isString} from './facade/lang';
|
||||
import {getDOM} from './private_import_platform-browser';
|
||||
|
||||
export class BrowserDetection {
|
||||
@ -83,16 +83,12 @@ export function el(html: string): HTMLElement {
|
||||
}
|
||||
|
||||
export function normalizeCSS(css: string): string {
|
||||
css = StringWrapper.replaceAll(css, /\s+/g, ' ');
|
||||
css = StringWrapper.replaceAll(css, /:\s/g, ':');
|
||||
css = StringWrapper.replaceAll(css, /'/g, '"');
|
||||
css = StringWrapper.replaceAll(css, / }/g, '}');
|
||||
css = StringWrapper.replaceAllMapped(
|
||||
css, /url\((\"|\s)(.+)(\"|\s)\)(\s*)/g,
|
||||
(match: any /** TODO #9100 */) => `url("${match[2]}")`);
|
||||
css = StringWrapper.replaceAllMapped(
|
||||
css, /\[(.+)=([^"\]]+)\]/g, (match: any /** TODO #9100 */) => `[${match[1]}="${match[2]}"]`);
|
||||
return css;
|
||||
return css.replace(/\s+/g, ' ')
|
||||
.replace(/:\s/g, ':')
|
||||
.replace(/'/g, '"')
|
||||
.replace(/ }/g, '}')
|
||||
.replace(/url\((\"|\s)(.+)(\"|\s)\)(\s*)/g, (...match: string[]) => `url("${match[2]}")`)
|
||||
.replace(/\[(.+)=([^"\]]+)\]/g, (...match: string[]) => `[${match[1]}="${match[2]}"]`);
|
||||
}
|
||||
|
||||
var _singleTagWhitelist = ['br', 'hr', 'input'];
|
||||
|
Reference in New Issue
Block a user