refactor(facade): inline StringWrapper (#12051)

This commit is contained in:
Alex Eagle
2016-10-06 15:10:27 -07:00
committed by Tobias Bosch
parent bb35fcb562
commit 8c975ed156
34 changed files with 105 additions and 288 deletions

View File

@ -9,7 +9,7 @@
import * as chars from '../chars';
import {BaseError} from '../facade/errors';
import {StringWrapper, isPresent} from '../facade/lang';
import {isPresent} from '../facade/lang';
export enum CssTokenType {
EOF,
@ -155,7 +155,7 @@ export class CssScanner {
}
peekAt(index: number): number {
return index >= this.length ? chars.$EOF : StringWrapper.charCodeAt(this.input, index);
return index >= this.length ? chars.$EOF : this.input.charCodeAt(index);
}
consumeEmptyStatements(): void {
@ -310,7 +310,7 @@ export class CssScanner {
return this.scanCharacter();
}
return this.error(`Unexpected character [${StringWrapper.fromCharCode(peek)}]`);
return this.error(`Unexpected character [${String.fromCharCode(peek)}]`);
}
scanComment(): CssToken {
@ -476,8 +476,7 @@ export class CssScanner {
var index: number = this.index;
var column: number = this.column;
var line: number = this.line;
errorTokenValue =
isPresent(errorTokenValue) ? errorTokenValue : StringWrapper.fromCharCode(this.peek);
errorTokenValue = isPresent(errorTokenValue) ? errorTokenValue : String.fromCharCode(this.peek);
var invalidToken = new CssToken(index, column, line, CssTokenType.Invalid, errorTokenValue);
var errorMessage =
generateErrorMessage(this.input, message, errorTokenValue, index, line, column);
@ -696,11 +695,11 @@ function isValidCssCharacter(code: number, mode: CssLexerMode): boolean {
}
function charCode(input: string, index: number): number {
return index >= input.length ? chars.$EOF : StringWrapper.charCodeAt(input, index);
return index >= input.length ? chars.$EOF : input.charCodeAt(index);
}
function charStr(code: number): string {
return StringWrapper.fromCharCode(code);
return String.fromCharCode(code);
}
export function isNewline(code: number): boolean {

View File

@ -8,7 +8,7 @@
import {Injectable} from '@angular/core';
import * as chars from '../chars';
import {NumberWrapper, StringJoiner, StringWrapper, isPresent} from '../facade/lang';
import {NumberWrapper, StringJoiner, isPresent} from '../facade/lang';
export enum TokenType {
Character,
@ -93,7 +93,7 @@ export class Token {
}
function newCharacterToken(index: number, code: number): Token {
return new Token(index, TokenType.Character, code, StringWrapper.fromCharCode(code));
return new Token(index, TokenType.Character, code, String.fromCharCode(code));
}
function newIdentifierToken(index: number, text: string): Token {
@ -133,8 +133,7 @@ class _Scanner {
}
advance() {
this.peek =
++this.index >= this.length ? chars.$EOF : StringWrapper.charCodeAt(this.input, this.index);
this.peek = ++this.index >= this.length ? chars.$EOF : this.input.charCodeAt(this.index);
}
scanToken(): Token {
@ -146,7 +145,7 @@ class _Scanner {
peek = chars.$EOF;
break;
} else {
peek = StringWrapper.charCodeAt(input, index);
peek = input.charCodeAt(index);
}
}
@ -187,16 +186,16 @@ class _Scanner {
case chars.$SLASH:
case chars.$PERCENT:
case chars.$CARET:
return this.scanOperator(start, StringWrapper.fromCharCode(peek));
return this.scanOperator(start, String.fromCharCode(peek));
case chars.$QUESTION:
return this.scanComplexOperator(start, '?', chars.$PERIOD, '.');
case chars.$LT:
case chars.$GT:
return this.scanComplexOperator(start, StringWrapper.fromCharCode(peek), chars.$EQ, '=');
return this.scanComplexOperator(start, String.fromCharCode(peek), chars.$EQ, '=');
case chars.$BANG:
case chars.$EQ:
return this.scanComplexOperator(
start, StringWrapper.fromCharCode(peek), chars.$EQ, '=', chars.$EQ, '=');
start, String.fromCharCode(peek), chars.$EQ, '=', chars.$EQ, '=');
case chars.$AMPERSAND:
return this.scanComplexOperator(start, '&', chars.$AMPERSAND, '&');
case chars.$BAR:
@ -207,7 +206,7 @@ class _Scanner {
}
this.advance();
return this.error(`Unexpected character [${StringWrapper.fromCharCode(peek)}]`, 0);
return this.error(`Unexpected character [${String.fromCharCode(peek)}]`, 0);
}
scanCharacter(start: number, code: number): Token {
@ -310,7 +309,7 @@ class _Scanner {
unescapedCode = unescape(this.peek);
this.advance();
}
buffer.add(StringWrapper.fromCharCode(unescapedCode));
buffer.add(String.fromCharCode(unescapedCode));
marker = this.index;
} else if (this.peek == chars.$EOF) {
return this.error('Unterminated quote', 0);

View File

@ -9,7 +9,7 @@
import {Injectable} from '@angular/core';
import * as chars from '../chars';
import {StringWrapper, escapeRegExp, isBlank, isPresent} from '../facade/lang';
import {escapeRegExp, isBlank, isPresent} from '../facade/lang';
import {DEFAULT_INTERPOLATION_CONFIG, InterpolationConfig} from '../ml_parser/interpolation_config';
import {AST, ASTWithSource, AstVisitor, Binary, BindingPipe, Chain, Conditional, EmptyExpr, FunctionCall, ImplicitReceiver, Interpolation, KeyedRead, KeyedWrite, LiteralArray, LiteralMap, LiteralPrimitive, MethodCall, ParseSpan, ParserError, PrefixNot, PropertyRead, PropertyWrite, Quote, SafeMethodCall, SafePropertyRead, TemplateBinding} from './ast';
@ -122,7 +122,7 @@ export class Parser {
input: string, location: string,
interpolationConfig: InterpolationConfig = DEFAULT_INTERPOLATION_CONFIG): SplitInterpolation {
const regexp = _createInterpolateRegExp(interpolationConfig);
const parts = StringWrapper.split(input, regexp);
const parts = input.split(regexp);
if (parts.length <= 1) {
return null;
}
@ -160,8 +160,8 @@ export class Parser {
private _commentStart(input: string): number {
var outerQuote: number = null;
for (let i = 0; i < input.length - 1; i++) {
const char = StringWrapper.charCodeAt(input, i);
const nextChar = StringWrapper.charCodeAt(input, i + 1);
const char = input.charCodeAt(i);
const nextChar = input.charCodeAt(i + 1);
if (char === chars.$SLASH && nextChar == chars.$SLASH && isBlank(outerQuote)) return i;
@ -177,7 +177,7 @@ export class Parser {
private _checkNoInterpolation(
input: string, location: any, interpolationConfig: InterpolationConfig): void {
var regexp = _createInterpolateRegExp(interpolationConfig);
var parts = StringWrapper.split(input, regexp);
var parts = input.split(regexp);
if (parts.length > 1) {
this._reportError(
`Got interpolation (${interpolationConfig.start}${interpolationConfig.end}) where expression was expected`,
@ -239,7 +239,7 @@ export class _ParseAST {
expectCharacter(code: number) {
if (this.optionalCharacter(code)) return;
this.error(`Missing expected ${StringWrapper.fromCharCode(code)}`);
this.error(`Missing expected ${String.fromCharCode(code)}`);
}
optionalOperator(op: string): boolean {

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {StringWrapper, isBlank, isPresent, isString} from '../facade/lang';
import {isBlank, isPresent, isString} from '../facade/lang';
import * as o from './output_ast';
@ -409,18 +409,17 @@ export function escapeIdentifier(
if (isBlank(input)) {
return null;
}
var body = StringWrapper.replaceAllMapped(
input, _SINGLE_QUOTE_ESCAPE_STRING_RE, (match: any /** TODO #9100 */) => {
if (match[0] == '$') {
return escapeDollar ? '\\$' : '$';
} else if (match[0] == '\n') {
return '\\n';
} else if (match[0] == '\r') {
return '\\r';
} else {
return `\\${match[0]}`;
}
});
var body = input.replace(_SINGLE_QUOTE_ESCAPE_STRING_RE, (...match: string[]) => {
if (match[0] == '$') {
return escapeDollar ? '\\$' : '$';
} else if (match[0] == '\n') {
return '\\n';
} else if (match[0] == '\r') {
return '\\r';
} else {
return `\\${match[0]}`;
}
});
let requiresQuotes = alwaysQuote || !_LEGAL_IDENTIFIER_RE.test(body);
return requiresQuotes ? `'${body}'` : body;
}

View File

@ -9,7 +9,7 @@
// Some of the code comes from WebComponents.JS
// https://github.com/webcomponents/webcomponentsjs/blob/master/src/HTMLImports/path.js
import {StringWrapper, isBlank, isPresent} from './facade/lang';
import {isBlank, isPresent} from './facade/lang';
import {UrlResolver} from './url_resolver';
@ -30,8 +30,8 @@ export function isStyleUrlResolvable(url: string): boolean {
export function extractStyleUrls(
resolver: UrlResolver, baseUrl: string, cssText: string): StyleWithImports {
var foundUrls: string[] = [];
var modifiedCssText = StringWrapper.replaceAllMapped(cssText, _cssImportRe, (m: string[]) => {
var url = isPresent(m[1]) ? m[1] : m[2];
var modifiedCssText = cssText.replace(_cssImportRe, function(...m: string[]) {
const url = isPresent(m[1]) ? m[1] : m[2];
if (!isStyleUrlResolvable(url)) {
// Do not attempt to resolve non-package absolute URLs with URI scheme
return m[0];

View File

@ -8,7 +8,7 @@
import {Inject, Injectable, PACKAGE_ROOT_URL} from '@angular/core';
import {StringWrapper, isBlank, isPresent} from './facade/lang';
import {isBlank, isPresent} from './facade/lang';
const _ASSET_SCHEME = 'asset:';
@ -74,8 +74,8 @@ export class UrlResolver {
var pathSegements = path.split(/\//);
resolvedUrl = `asset:${pathSegements[0]}/lib/${pathSegements.slice(1).join('/')}`;
} else {
prefix = StringWrapper.stripRight(prefix, '/');
path = StringWrapper.stripLeft(path, '/');
prefix = prefix.replace(/\/+$/, '');
path = path.replace(/^\/+/, '');
return `${prefix}/${path}`;
}
}

View File

@ -7,7 +7,7 @@
*/
import {CompileTokenMetadata} from './compile_metadata';
import {StringWrapper, isArray, isBlank, isPresent, isPrimitive, isStrictStringMap} from './facade/lang';
import {isArray, isBlank, isPresent, isPrimitive, isStrictStringMap} from './facade/lang';
import * as o from './output/output_ast';
export const MODULE_SUFFIX = '';
@ -15,8 +15,7 @@ export const MODULE_SUFFIX = '';
var CAMEL_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: any[]) => '-' + m[1].toLowerCase());
}
export function splitAtColon(input: string, defaultValues: string[]): string[] {
@ -34,7 +33,7 @@ function _splitAt(input: string, character: string, defaultValues: string[]): st
}
export function sanitizeIdentifier(name: string): string {
return StringWrapper.replaceAll(name, /\W/g, '_');
return name.replace(/\W/g, '_');
}
export function visitValue(value: any, visitor: ValueVisitor, context: any): any {

View File

@ -7,7 +7,7 @@
*/
import {CompileDirectiveMetadata} from '../compile_metadata';
import {StringWrapper, isPresent} from '../facade/lang';
import {isPresent} from '../facade/lang';
import {identifierToken} from '../identifiers';
import * as o from '../output/output_ast';
import {BoundEventAst, DirectiveAst} from '../template_parser/template_ast';
@ -200,5 +200,5 @@ function convertStmtIntoExpression(stmt: o.Statement): o.Expression {
}
function santitizeEventName(name: string): string {
return StringWrapper.replaceAll(name, /[^a-zA-Z_]/g, '_');
return name.replace(/[^a-zA-Z_]/g, '_');
}

View File

@ -10,7 +10,7 @@ import {ViewEncapsulation} from '@angular/core';
import {CompileDirectiveMetadata, CompileIdentifierMetadata, CompileTokenMetadata} from '../compile_metadata';
import {ListWrapper} from '../facade/collection';
import {StringWrapper, isPresent} from '../facade/lang';
import {isPresent} from '../facade/lang';
import {Identifiers, identifierToken, resolveIdentifier} from '../identifiers';
import * as o from '../output/output_ast';
import {ChangeDetectorStatus, ViewType, isDefaultChangeDetectionStrategy} from '../private_import_core';
@ -376,7 +376,7 @@ function mapToKeyValueArray(data: {[key: string]: string}): string[][] {
Object.keys(data).forEach(name => { entryArray.push([name, data[name]]); });
// We need to sort to get a defined output order
// for tests and for caching generated artifacts...
ListWrapper.sort(entryArray, (entry1, entry2) => StringWrapper.compare(entry1[0], entry2[0]));
ListWrapper.sort(entryArray);
return entryArray;
}