refactor: remove lang.ts (#14837)

This commit is contained in:
Miško Hevery
2017-03-02 09:37:01 -08:00
committed by Chuck Jazdzewski
parent 84a65cf788
commit 8343fb7740
139 changed files with 406 additions and 676 deletions

View File

@ -8,10 +8,9 @@
import {isDevMode} from '@angular/core';
import {isBlank, isPresent} from '../src/facade/lang';
export function assertArrayOfStrings(identifier: string, value: any) {
if (!isDevMode() || isBlank(value)) {
if (!isDevMode() || value == null) {
return;
}
if (!Array.isArray(value)) {
@ -33,9 +32,9 @@ const INTERPOLATION_BLACKLIST_REGEXPS = [
];
export function assertInterpolationSymbols(identifier: string, value: any): void {
if (isPresent(value) && !(Array.isArray(value) && value.length == 2)) {
if (value != null && !(Array.isArray(value) && value.length == 2)) {
throw new Error(`Expected '${identifier}' to be an array, [start, end].`);
} else if (isDevMode() && !isBlank(value)) {
} else if (isDevMode() && value != null) {
const start = value[0] as string;
const end = value[1] as string;
// black list checking

View File

@ -6,9 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
import {ChangeDetectionStrategy, ComponentFactory, RendererTypeV2, SchemaMetadata, Type, ViewEncapsulation, ɵLifecycleHooks, ɵreflector} from '@angular/core';
import {ChangeDetectionStrategy, ComponentFactory, RendererTypeV2, SchemaMetadata, Type, ViewEncapsulation, ɵLifecycleHooks, ɵreflector, ɵstringify as stringify} from '@angular/core';
import {StaticSymbol} from './aot/static_symbol';
import {isPresent, stringify} from './facade/lang';
import {CssSelector} from './selector';
import {splitAtColon} from './util';
@ -179,12 +178,11 @@ export interface CompileFactoryMetadata extends CompileIdentifierMetadata {
}
export function tokenName(token: CompileTokenMetadata) {
return isPresent(token.value) ? _sanitizeIdentifier(token.value) :
identifierName(token.identifier);
return token.value != null ? _sanitizeIdentifier(token.value) : identifierName(token.identifier);
}
export function tokenReference(token: CompileTokenMetadata) {
if (isPresent(token.identifier)) {
if (token.identifier != null) {
return token.identifier.reference;
} else {
return token.value;
@ -346,21 +344,21 @@ export class CompileDirectiveMetadata {
const hostListeners: {[key: string]: string} = {};
const hostProperties: {[key: string]: string} = {};
const hostAttributes: {[key: string]: string} = {};
if (isPresent(host)) {
if (host != null) {
Object.keys(host).forEach(key => {
const value = host[key];
const matches = key.match(HOST_REG_EXP);
if (matches === null) {
hostAttributes[key] = value;
} else if (isPresent(matches[1])) {
} else if (matches[1] != null) {
hostProperties[matches[1]] = value;
} else if (isPresent(matches[2])) {
} else if (matches[2] != null) {
hostListeners[matches[2]] = value;
}
});
}
const inputsMap: {[key: string]: string} = {};
if (isPresent(inputs)) {
if (inputs != null) {
inputs.forEach((bindConfig: string) => {
// canonical syntax: `dirProp: elProp`
// if there is no `:`, use dirProp = elProp
@ -369,7 +367,7 @@ export class CompileDirectiveMetadata {
});
}
const outputsMap: {[key: string]: string} = {};
if (isPresent(outputs)) {
if (outputs != null) {
outputs.forEach((bindConfig: string) => {
// canonical syntax: `dirProp: elProp`
// if there is no `:`, use dirProp = elProp

View File

@ -8,7 +8,6 @@
import * as cdAst from '../expression_parser/ast';
import {isBlank} from '../facade/lang';
import {Identifiers, createIdentifier} from '../identifiers';
import * as o from '../output/output_ast';
@ -338,7 +337,7 @@ class _AstToIrVisitor implements cdAst.AstVisitor {
result = varExpr.callFn(args);
}
}
if (isBlank(result)) {
if (result == null) {
result = receiver.callMethod(ast.name, args);
}
return convertToStatementIfNeeded(mode, result);
@ -359,7 +358,7 @@ class _AstToIrVisitor implements cdAst.AstVisitor {
if (receiver === this._implicitReceiver) {
result = this._getLocal(ast.name);
}
if (isBlank(result)) {
if (result == null) {
result = receiver.prop(ast.name);
}
return convertToStatementIfNeeded(mode, result);
@ -607,4 +606,4 @@ class BuiltinFunctionCall extends cdAst.FunctionCall {
constructor(span: cdAst.ParseSpan, public args: cdAst.AST[], public converter: BuiltinConverter) {
super(span, null, args);
}
}
}

View File

@ -8,7 +8,6 @@
import * as chars from '../chars';
import {isPresent} from '../facade/lang';
export enum CssTokenType {
EOF,
@ -200,9 +199,9 @@ export class CssScanner {
let next: CssToken;
const output = this.scan();
if (isPresent(output)) {
if (output != null) {
// just incase the inner scan method returned an error
if (isPresent(output.error)) {
if (output.error != null) {
this.setMode(mode);
return output;
}
@ -210,7 +209,7 @@ export class CssScanner {
next = output.token;
}
if (!isPresent(next)) {
if (next == null) {
next = new CssToken(this.index, this.column, this.line, CssTokenType.EOF, 'end of file');
}
@ -227,11 +226,11 @@ export class CssScanner {
this.setMode(mode);
let error: Error = null;
if (!isMatchingType || (isPresent(value) && value != next.strValue)) {
if (!isMatchingType || (value != null && value != next.strValue)) {
let errorMessage =
CssTokenType[next.type] + ' does not match expected ' + CssTokenType[type] + ' value';
if (isPresent(value)) {
if (value != null) {
errorMessage += ' ("' + next.strValue + '" should match "' + value + '")';
}

View File

@ -7,7 +7,6 @@
*/
import * as chars from '../chars';
import {isPresent} from '../facade/lang';
import {ParseError, ParseLocation, ParseSourceFile, ParseSourceSpan} from '../parse_util';
import {BlockType, CssAst, CssAtRulePredicateAst, CssBlockAst, CssBlockDefinitionRuleAst, CssBlockRuleAst, CssDefinitionAst, CssInlineRuleAst, CssKeyframeDefinitionAst, CssKeyframeRuleAst, CssMediaQueryRuleAst, CssPseudoSelectorAst, CssRuleAst, CssSelectorAst, CssSelectorRuleAst, CssSimpleSelectorAst, CssStyleSheetAst, CssStyleValueAst, CssStylesBlockAst, CssUnknownRuleAst, CssUnknownTokenListAst, mergeTokens} from './css_ast';
@ -127,7 +126,7 @@ export class CssParser {
}
/** @internal */
_getSourceContent(): string { return isPresent(this._scanner) ? this._scanner.input : ''; }
_getSourceContent(): string { return this._scanner != null ? this._scanner.input : ''; }
/** @internal */
_extractSourceContent(start: number, end: number): string {
@ -141,7 +140,7 @@ export class CssParser {
startLoc = start.location.start;
} else {
let token = start;
if (!isPresent(token)) {
if (token == null) {
// the data here is invalid, however, if and when this does
// occur, any other errors associated with this will be collected
token = this._lastToken;
@ -149,7 +148,7 @@ export class CssParser {
startLoc = new ParseLocation(this._file, token.index, token.line, token.column);
}
if (!isPresent(end)) {
if (end == null) {
end = this._lastToken;
}
@ -329,7 +328,7 @@ export class CssParser {
let ruleAst: CssRuleAst;
let span: ParseSourceSpan;
const startSelector = selectors[0];
if (isPresent(block)) {
if (block != null) {
span = this._generateSourceSpan(startSelector, block);
ruleAst = new CssSelectorRuleAst(span, selectors, block);
} else {
@ -377,7 +376,7 @@ export class CssParser {
const output = this._scanner.scan();
const token = output.token;
const error = output.error;
if (isPresent(error)) {
if (error != null) {
this._error(getRawMessage(error), token);
}
this._lastToken = token;
@ -392,7 +391,7 @@ export class CssParser {
const output = this._scanner.consume(type, value);
const token = output.token;
const error = output.error;
if (isPresent(error)) {
if (error != null) {
this._error(getRawMessage(error), token);
}
this._lastToken = token;
@ -601,7 +600,7 @@ export class CssParser {
let index = lastOperatorToken.index;
let line = lastOperatorToken.line;
let column = lastOperatorToken.column;
if (isPresent(deepToken) && deepToken.strValue.toLowerCase() == 'deep' &&
if (deepToken != null && deepToken.strValue.toLowerCase() == 'deep' &&
deepSlash.strValue == SLASH_CHARACTER) {
token = new CssToken(
lastOperatorToken.index, lastOperatorToken.column, lastOperatorToken.line,
@ -636,7 +635,7 @@ export class CssParser {
// so long as there is an operator then we can have an
// ending value that is beyond the selector value ...
// otherwise it's just a bunch of trailing whitespace
if (isPresent(operator)) {
if (operator != null) {
end = operator.index;
}
}
@ -664,7 +663,7 @@ export class CssParser {
startTokenOrAst = startTokenOrAst || pseudoSelectors[0];
endTokenOrAst = pseudoSelectors[pseudoSelectors.length - 1];
}
if (isPresent(operator)) {
if (operator != null) {
startTokenOrAst = startTokenOrAst || operator;
endTokenOrAst = operator;
}
@ -702,7 +701,7 @@ export class CssParser {
let previous: CssToken;
while (!characterContainsDelimiter(this._scanner.peek, delimiters)) {
let token: CssToken;
if (isPresent(previous) && previous.type == CssTokenType.Identifier &&
if (previous != null && previous.type == CssTokenType.Identifier &&
this._scanner.peek == chars.$LPAREN) {
token = this._consume(CssTokenType.Character, '(');
tokens.push(token);
@ -753,7 +752,7 @@ export class CssParser {
_collectUntilDelim(delimiters: number, assertType: CssTokenType = null): CssToken[] {
const tokens: CssToken[] = [];
while (!characterContainsDelimiter(this._scanner.peek, delimiters)) {
const val = isPresent(assertType) ? this._consume(assertType) : this._scan();
const val = assertType != null ? this._consume(assertType) : this._scan();
tokens.push(val);
}
return tokens;

View File

@ -6,11 +6,9 @@
* found in the LICENSE file at https://angular.io/license
*/
import {ViewEncapsulation} from '@angular/core';
import {ViewEncapsulation, ɵstringify as stringify} from '@angular/core';
import {CompileAnimationEntryMetadata, CompileDirectiveMetadata, CompileStylesheetMetadata, CompileTemplateMetadata} from './compile_metadata';
import {CompilerConfig} from './config';
import {stringify} from './facade/lang';
import {CompilerInjectable} from './injectable';
import * as html from './ml_parser/ast';
import {HtmlParser} from './ml_parser/html_parser';

View File

@ -6,9 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Component, Directive, HostBinding, HostListener, Input, Output, Query, Type, resolveForwardRef, ɵReflectorReader, ɵmerge as merge, ɵreflector} from '@angular/core';
import {stringify} from './facade/lang';
import {Component, Directive, HostBinding, HostListener, Input, Output, Query, Type, resolveForwardRef, ɵReflectorReader, ɵmerge as merge, ɵreflector, ɵstringify as stringify} from '@angular/core';
import {CompilerInjectable} from './injectable';
import {splitAtColon} from './util';

View File

@ -7,7 +7,6 @@
*/
import {isBlank} from '../facade/lang';
export class ParserError {
public message: string;
@ -196,7 +195,7 @@ export class ASTWithSource extends AST {
constructor(
public ast: AST, public source: string, public location: string,
public errors: ParserError[]) {
super(new ParseSpan(0, isBlank(source) ? 0 : source.length));
super(new ParseSpan(0, source == null ? 0 : source.length));
}
visit(visitor: AstVisitor, context: any = null): any { return this.ast.visit(visitor, context); }
toString(): string { return `${this.source} in ${this.location}`; }

View File

@ -7,7 +7,6 @@
*/
import * as chars from '../chars';
import {NumberWrapper} from '../facade/lang';
import {CompilerInjectable} from '../injectable';
export enum TokenType {
@ -276,7 +275,7 @@ class _Scanner {
this.advance();
}
const str: string = this.input.substring(start, this.index);
const value: number = simple ? NumberWrapper.parseIntAutoRadix(str) : parseFloat(str);
const value: number = simple ? parseIntAutoRadix(str) : parseFloat(str);
return newNumberToken(start, value);
}
@ -383,3 +382,11 @@ function unescape(code: number): number {
return code;
}
}
function parseIntAutoRadix(text: string): number {
const result: number = parseInt(text);
if (isNaN(result)) {
throw new Error('Invalid integer literal when parsing ' + text);
}
return result;
}

View File

@ -7,10 +7,9 @@
*/
import * as chars from '../chars';
import {escapeRegExp, isBlank, isPresent} from '../facade/lang';
import {CompilerInjectable} from '../injectable';
import {DEFAULT_INTERPOLATION_CONFIG, InterpolationConfig} from '../ml_parser/interpolation_config';
import {escapeRegExp} from '../util';
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';
import {EOF, Lexer, Token, TokenType, isIdentifier, isQuote} from './lexer';
@ -78,7 +77,7 @@ export class Parser {
// our lexer or parser for that, so we check for that ahead of time.
const quote = this._parseQuote(input, location);
if (isPresent(quote)) {
if (quote != null) {
return quote;
}
@ -92,7 +91,7 @@ export class Parser {
}
private _parseQuote(input: string, location: any): AST {
if (isBlank(input)) return null;
if (input == null) return null;
const prefixSeparatorIndex = input.indexOf(':');
if (prefixSeparatorIndex == -1) return null;
const prefix = input.substring(0, prefixSeparatorIndex).trim();
@ -137,7 +136,7 @@ export class Parser {
return new ASTWithSource(
new Interpolation(
new ParseSpan(0, isBlank(input) ? 0 : input.length), split.strings, expressions),
new ParseSpan(0, input == null ? 0 : input.length), split.strings, expressions),
input, location, this.errors);
}
@ -178,13 +177,13 @@ export class Parser {
wrapLiteralPrimitive(input: string, location: any): ASTWithSource {
return new ASTWithSource(
new LiteralPrimitive(new ParseSpan(0, isBlank(input) ? 0 : input.length), input), input,
new LiteralPrimitive(new ParseSpan(0, input == null ? 0 : input.length), input), input,
location, this.errors);
}
private _stripComments(input: string): string {
const i = this._commentStart(input);
return isPresent(i) ? input.substring(0, i).trim() : input;
return i != null ? input.substring(0, i).trim() : input;
}
private _commentStart(input: string): number {
@ -193,11 +192,11 @@ export class Parser {
const char = input.charCodeAt(i);
const nextChar = input.charCodeAt(i + 1);
if (char === chars.$SLASH && nextChar == chars.$SLASH && isBlank(outerQuote)) return i;
if (char === chars.$SLASH && nextChar == chars.$SLASH && outerQuote == null) return i;
if (outerQuote === char) {
outerQuote = null;
} else if (isBlank(outerQuote) && isQuote(char)) {
} else if (outerQuote == null && isQuote(char)) {
outerQuote = char;
}
}
@ -728,7 +727,7 @@ export class _ParseAST {
}
private locationText(index: number = null) {
if (isBlank(index)) index = this.index;
if (index == null) index = this.index;
return (index < this.tokens.length) ? `at column ${this.tokens[index].index + 1} in` :
`at the end of the expression`;
}

View File

@ -1 +0,0 @@
../../facade/src

View File

@ -6,11 +6,10 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Compiler, ComponentFactory, Inject, Injector, ModuleWithComponentFactories, NgModuleFactory, Type, ɵgetComponentViewDefinitionFactory as getComponentViewDefinitionFactory} from '@angular/core';
import {Compiler, ComponentFactory, Inject, Injector, ModuleWithComponentFactories, NgModuleFactory, Type, ɵgetComponentViewDefinitionFactory as getComponentViewDefinitionFactory, ɵstringify as stringify} from '@angular/core';
import {CompileDirectiveMetadata, CompileIdentifierMetadata, CompileNgModuleMetadata, ProviderMeta, ProxyClass, createHostComponentMeta, identifierName} from '../compile_metadata';
import {CompilerConfig} from '../config';
import {stringify} from '../facade/lang';
import {CompilerInjectable} from '../injectable';
import {CompileMetadataResolver} from '../metadata_resolver';
import {NgModuleCompiler} from '../ng_module_compiler';

View File

@ -6,8 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Attribute, ChangeDetectionStrategy, Component, ComponentFactory, Directive, Host, Inject, Injectable, InjectionToken, ModuleWithProviders, Optional, Provider, Query, RendererTypeV2, SchemaMetadata, Self, SkipSelf, Type, resolveForwardRef, ɵERROR_COMPONENT_TYPE, ɵLIFECYCLE_HOOKS_VALUES, ɵReflectorReader, ɵccf as createComponentFactory, ɵreflector} from '@angular/core';
import {Attribute, ChangeDetectionStrategy, Component, ComponentFactory, Directive, Host, Inject, Injectable, InjectionToken, ModuleWithProviders, Optional, Provider, Query, RendererTypeV2, SchemaMetadata, Self, SkipSelf, Type, resolveForwardRef, ɵERROR_COMPONENT_TYPE, ɵLIFECYCLE_HOOKS_VALUES, ɵReflectorReader, ɵccf as createComponentFactory, ɵreflector, ɵstringify as stringify} from '@angular/core';
import {StaticSymbol, StaticSymbolCache} from './aot/static_symbol';
import {ngfactoryFilePath} from './aot/util';
import {assertArrayOfStrings, assertInterpolationSymbols} from './assertions';
@ -15,7 +14,6 @@ import * as cpl from './compile_metadata';
import {CompilerConfig} from './config';
import {DirectiveNormalizer} from './directive_normalizer';
import {DirectiveResolver} from './directive_resolver';
import {stringify} from './facade/lang';
import {Identifiers, resolveIdentifier} from './identifiers';
import {CompilerInjectable} from './injectable';
import {hasLifecycleHook} from './lifecycle_reflector';

View File

@ -6,7 +6,6 @@
* found in the LICENSE file at https://angular.io/license
*/
import {isBlank, isPresent} from '../facade/lang';
import {ParseError, ParseSourceSpan} from '../parse_util';
import * as html from './ast';
@ -109,7 +108,7 @@ class _TreeBuilder {
private _consumeComment(token: lex.Token) {
const text = this._advanceIf(lex.TokenType.RAW_TEXT);
this._advanceIf(lex.TokenType.COMMENT_END);
const value = isPresent(text) ? text.parts[0].trim() : null;
const value = text != null ? text.parts[0].trim() : null;
this._addToParent(new html.Comment(value, token.sourceSpan));
}
@ -217,7 +216,7 @@ class _TreeBuilder {
let text = token.parts[0];
if (text.length > 0 && text[0] == '\n') {
const parent = this._getParentElement();
if (isPresent(parent) && parent.children.length == 0 &&
if (parent != null && parent.children.length == 0 &&
this.getTagDefinition(parent.name).ignoreFirstLf) {
text = text.substring(1);
}
@ -365,7 +364,7 @@ class _TreeBuilder {
private _addToParent(node: html.Node) {
const parent = this._getParentElement();
if (isPresent(parent)) {
if (parent != null) {
parent.children.push(node);
} else {
this._rootNodes.push(node);
@ -399,9 +398,9 @@ class _TreeBuilder {
private _getElementFullName(prefix: string, localName: string, parentElement: html.Element):
string {
if (isBlank(prefix)) {
if (prefix == null) {
prefix = this.getTagDefinition(localName).implicitNamespacePrefix;
if (isBlank(prefix) && isPresent(parentElement)) {
if (prefix == null && parentElement != null) {
prefix = getNsPrefix(parentElement.name);
}
}

View File

@ -9,7 +9,6 @@
import {ɵLifecycleHooks} from '@angular/core';
import {CompileDiDependencyMetadata, CompileIdentifierMetadata, CompileNgModuleMetadata, CompileProviderMetadata, CompileTokenMetadata, identifierModuleUrl, identifierName, tokenName, tokenReference} from './compile_metadata';
import {isPresent} from './facade/lang';
import {Identifiers, createIdentifier, resolveIdentifier} from './identifiers';
import {CompilerInjectable} from './injectable';
import {ClassBuilder, createClassStmt} from './output/class_builder';
@ -39,7 +38,7 @@ export class NgModuleCompiler {
compile(ngModuleMeta: CompileNgModuleMetadata, extraProviders: CompileProviderMetadata[]):
NgModuleCompileResult {
const moduleUrl = identifierModuleUrl(ngModuleMeta.type);
const sourceFileName = isPresent(moduleUrl) ?
const sourceFileName = moduleUrl != null ?
`in NgModule ${identifierName(ngModuleMeta.type)} in ${moduleUrl}` :
`in NgModule ${identifierName(ngModuleMeta.type)}`;
const sourceFile = new ParseSourceFile('', sourceFileName);
@ -161,13 +160,13 @@ class _InjectorBuilder implements ClassBuilder {
private _getProviderValue(provider: CompileProviderMetadata): o.Expression {
let result: o.Expression;
if (isPresent(provider.useExisting)) {
if (provider.useExisting != null) {
result = this._getDependency({token: provider.useExisting});
} else if (isPresent(provider.useFactory)) {
} else if (provider.useFactory != null) {
const deps = provider.deps || provider.useFactory.diDeps;
const depsExpr = deps.map((dep) => this._getDependency(dep));
result = o.importExpr(provider.useFactory).callFn(depsExpr);
} else if (isPresent(provider.useClass)) {
} else if (provider.useClass != null) {
const deps = provider.deps || provider.useClass.diDeps;
const depsExpr = deps.map((dep) => this._getDependency(dep));
result =
@ -239,7 +238,7 @@ class _InjectorBuilder implements ClassBuilder {
}
function createDiTokenExpression(token: CompileTokenMetadata): o.Expression {
if (isPresent(token.value)) {
if (token.value != null) {
return o.literal(token.value);
} else {
return o.importExpr(token.identifier);

View File

@ -6,9 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
import {NgModule, Type, ɵReflectorReader, ɵreflector} from '@angular/core';
import {NgModule, Type, ɵReflectorReader, ɵreflector, ɵstringify as stringify} from '@angular/core';
import {findLast} from './directive_resolver';
import {stringify} from './facade/lang';
import {CompilerInjectable} from './injectable';
function _isNgModuleMetadata(obj: any): obj is NgModule {

View File

@ -6,7 +6,6 @@
* found in the LICENSE file at https://angular.io/license
*/
import {isBlank, isPresent} from '../facade/lang';
import {ParseSourceSpan} from '../parse_util';
import * as o from './output_ast';
@ -164,7 +163,7 @@ export abstract class AbstractEmitterVisitor implements o.StatementVisitor, o.Ex
ctx.print(stmt, `if (`);
stmt.condition.visitExpression(this, ctx);
ctx.print(stmt, `) {`);
const hasElseCase = isPresent(stmt.falseCase) && stmt.falseCase.length > 0;
const hasElseCase = stmt.falseCase != null && stmt.falseCase.length > 0;
if (stmt.trueCase.length <= 1 && !hasElseCase) {
ctx.print(stmt, ` `);
this.visitAllStatements(stmt.trueCase, ctx);
@ -244,9 +243,9 @@ export abstract class AbstractEmitterVisitor implements o.StatementVisitor, o.Ex
visitInvokeMethodExpr(expr: o.InvokeMethodExpr, ctx: EmitterVisitorContext): any {
expr.receiver.visitExpression(this, ctx);
let name = expr.name;
if (isPresent(expr.builtin)) {
if (expr.builtin != null) {
name = this.getBuiltinMethodName(expr.builtin);
if (isBlank(name)) {
if (name == null) {
// some builtins just mean to skip the call.
return null;
}
@ -268,7 +267,7 @@ export abstract class AbstractEmitterVisitor implements o.StatementVisitor, o.Ex
}
visitReadVarExpr(ast: o.ReadVarExpr, ctx: EmitterVisitorContext): any {
let varName = ast.name;
if (isPresent(ast.builtin)) {
if (ast.builtin != null) {
switch (ast.builtin) {
case o.BuiltinVar.Super:
varName = 'super';
@ -450,7 +449,7 @@ export abstract class AbstractEmitterVisitor implements o.StatementVisitor, o.Ex
export function escapeIdentifier(
input: string, escapeDollar: boolean, alwaysQuote: boolean = true): any {
if (isBlank(input)) {
if (input == null) {
return null;
}
const body = input.replace(_SINGLE_QUOTE_ESCAPE_STRING_RE, (...match: string[]) => {

View File

@ -6,7 +6,6 @@
* found in the LICENSE file at https://angular.io/license
*/
import {isPresent} from '../facade/lang';
import {AbstractEmitterVisitor, CATCH_ERROR_VAR, CATCH_STACK_VAR, EmitterVisitorContext} from './abstract_emitter';
import * as o from './output_ast';
@ -17,7 +16,7 @@ export abstract class AbstractJsEmitterVisitor extends AbstractEmitterVisitor {
ctx.pushClass(stmt);
this._visitClassConstructor(stmt, ctx);
if (isPresent(stmt.parent)) {
if (stmt.parent != null) {
ctx.print(stmt, `${stmt.name}.prototype = Object.create(`);
stmt.parent.visitExpression(this, ctx);
ctx.println(stmt, `.prototype);`);
@ -30,12 +29,12 @@ export abstract class AbstractJsEmitterVisitor extends AbstractEmitterVisitor {
private _visitClassConstructor(stmt: o.ClassStmt, ctx: EmitterVisitorContext) {
ctx.print(stmt, `function ${stmt.name}(`);
if (isPresent(stmt.constructorMethod)) {
if (stmt.constructorMethod != null) {
this._visitParams(stmt.constructorMethod.params, ctx);
}
ctx.println(stmt, `) {`);
ctx.incIndent();
if (isPresent(stmt.constructorMethod)) {
if (stmt.constructorMethod != null) {
if (stmt.constructorMethod.body.length > 0) {
ctx.println(stmt, `var self = this;`);
this.visitAllStatements(stmt.constructorMethod.body, ctx);

View File

@ -9,7 +9,6 @@
import {StaticSymbol} from '../aot/static_symbol';
import {CompileIdentifierMetadata} from '../compile_metadata';
import {isBlank} from '../facade/lang';
import {EmitterVisitorContext, OutputEmitter} from './abstract_emitter';
import {AbstractJsEmitterVisitor} from './abstract_js_emitter';
@ -61,7 +60,7 @@ class JsEmitterVisitor extends AbstractJsEmitterVisitor {
const {name, filePath} = this._resolveStaticSymbol(ast.value);
if (filePath != this._genFilePath) {
let prefix = this.importsWithPrefixes.get(filePath);
if (isBlank(prefix)) {
if (prefix == null) {
prefix = `import${this.importsWithPrefixes.size}`;
this.importsWithPrefixes.set(filePath, prefix);
}

View File

@ -8,7 +8,6 @@
import {CompileIdentifierMetadata} from '../compile_metadata';
import {isPresent} from '../facade/lang';
import {ParseSourceSpan} from '../parse_util';
//// Types
@ -954,12 +953,12 @@ export function importExpr(
export function importType(
id: CompileIdentifierMetadata, typeParams: Type[] = null,
typeModifiers: TypeModifier[] = null): ExpressionType {
return isPresent(id) ? expressionType(importExpr(id, typeParams), typeModifiers) : null;
return id != null ? expressionType(importExpr(id, typeParams), typeModifiers) : null;
}
export function expressionType(
expr: Expression, typeModifiers: TypeModifier[] = null): ExpressionType {
return isPresent(expr) ? new ExpressionType(expr, typeModifiers) : null;
return expr != null ? new ExpressionType(expr, typeModifiers) : null;
}
export function literalArr(

View File

@ -7,7 +7,6 @@
*/
import {isPresent} from '../facade/lang';
import * as o from './output_ast';
import {debugOutputAstAsTypeScript} from './ts_emitter';
@ -18,7 +17,7 @@ export function interpretStatements(statements: o.Statement[], resultVars: strin
const ctx = new _ExecutionContext(null, null, null, new Map<string, any>());
const visitor = new StatementInterpreter();
const result = visitor.visitAllStatements(stmtsWithReturn, ctx);
return isPresent(result) ? result.value : null;
return result != null ? result.value : null;
}
function _executeFunctionStatements(
@ -107,7 +106,7 @@ class StatementInterpreter implements o.StatementVisitor, o.ExpressionVisitor {
}
visitReadVarExpr(ast: o.ReadVarExpr, ctx: _ExecutionContext): any {
let varName = ast.name;
if (isPresent(ast.builtin)) {
if (ast.builtin != null) {
switch (ast.builtin) {
case o.BuiltinVar.Super:
return ctx.instance.__proto__;
@ -150,7 +149,7 @@ class StatementInterpreter implements o.StatementVisitor, o.ExpressionVisitor {
const receiver = expr.receiver.visitExpression(this, ctx);
const args = this.visitAllExpressions(expr.args, ctx);
let result: any;
if (isPresent(expr.builtin)) {
if (expr.builtin != null) {
switch (expr.builtin) {
case o.BuiltinMethod.ConcatArray:
result = receiver.concat(...args);
@ -195,7 +194,7 @@ class StatementInterpreter implements o.StatementVisitor, o.ExpressionVisitor {
const condition = stmt.condition.visitExpression(this, ctx);
if (condition) {
return this.visitAllStatements(stmt.trueCase, ctx);
} else if (isPresent(stmt.falseCase)) {
} else if (stmt.falseCase != null) {
return this.visitAllStatements(stmt.falseCase, ctx);
}
return null;
@ -226,7 +225,7 @@ class StatementInterpreter implements o.StatementVisitor, o.ExpressionVisitor {
visitConditionalExpr(ast: o.ConditionalExpr, ctx: _ExecutionContext): any {
if (ast.condition.visitExpression(this, ctx)) {
return ast.trueCase.visitExpression(this, ctx);
} else if (isPresent(ast.falseCase)) {
} else if (ast.falseCase != null) {
return ast.falseCase.visitExpression(this, ctx);
}
return null;

View File

@ -9,7 +9,6 @@
import {StaticSymbol} from '../aot/static_symbol';
import {CompileIdentifierMetadata} from '../compile_metadata';
import {isBlank, isPresent} from '../facade/lang';
import {AbstractEmitterVisitor, CATCH_ERROR_VAR, CATCH_STACK_VAR, EmitterVisitorContext, OutputEmitter} from './abstract_emitter';
import * as o from './output_ast';
@ -91,7 +90,7 @@ class _TsEmitterVisitor extends AbstractEmitterVisitor implements o.TypeVisitor
reexports = new Map<string, {name: string, as: string}[]>();
visitType(t: o.Type, ctx: EmitterVisitorContext, defaultType: string = 'any') {
if (isPresent(t)) {
if (t != null) {
this.typeExpression++;
t.visitType(this, ctx);
this.typeExpression--;
@ -102,7 +101,7 @@ class _TsEmitterVisitor extends AbstractEmitterVisitor implements o.TypeVisitor
visitLiteralExpr(ast: o.LiteralExpr, ctx: EmitterVisitorContext): any {
const value = ast.value;
if (isBlank(value) && ast.type != o.INFERRED_TYPE) {
if (value == null && ast.type != o.INFERRED_TYPE) {
ctx.print(ast, `(${value} as any)`);
return null;
}
@ -186,7 +185,7 @@ class _TsEmitterVisitor extends AbstractEmitterVisitor implements o.TypeVisitor
ctx.print(stmt, `export `);
}
ctx.print(stmt, `class ${stmt.name}`);
if (isPresent(stmt.parent)) {
if (stmt.parent != null) {
ctx.print(stmt, ` extends `);
this.typeExpression++;
stmt.parent.visitExpression(this, ctx);
@ -195,7 +194,7 @@ class _TsEmitterVisitor extends AbstractEmitterVisitor implements o.TypeVisitor
ctx.println(stmt, ` {`);
ctx.incIndent();
stmt.fields.forEach((field) => this._visitClassField(field, ctx));
if (isPresent(stmt.constructorMethod)) {
if (stmt.constructorMethod != null) {
this._visitClassConstructor(stmt, ctx);
}
stmt.getters.forEach((getter) => this._visitClassGetter(getter, ctx));
@ -391,7 +390,7 @@ class _TsEmitterVisitor extends AbstractEmitterVisitor implements o.TypeVisitor
const {name, filePath, members, arity} = this._resolveStaticSymbol(value);
if (filePath != this._genFilePath) {
let prefix = this.importsWithPrefixes.get(filePath);
if (isBlank(prefix)) {
if (prefix == null) {
prefix = `import${this.importsWithPrefixes.size}`;
this.importsWithPrefixes.set(filePath, prefix);
}

View File

@ -6,7 +6,6 @@
* found in the LICENSE file at https://angular.io/license
*/
import * as chars from './chars';
import {isPresent} from './facade/lang';
export class ParseLocation {
constructor(
@ -14,7 +13,7 @@ export class ParseLocation {
public col: number) {}
toString(): string {
return isPresent(this.offset) ? `${this.file.url}@${this.line}:${this.col}` : this.file.url;
return this.offset != null ? `${this.file.url}@${this.line}:${this.col}` : this.file.url;
}
moveBy(delta: number): ParseLocation {
@ -55,7 +54,7 @@ export class ParseLocation {
const content = this.file.content;
let startOffset = this.offset;
if (isPresent(startOffset)) {
if (startOffset != null) {
if (startOffset > content.length - 1) {
startOffset = content.length - 1;
}

View File

@ -6,9 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Pipe, Type, resolveForwardRef, ɵReflectorReader, ɵreflector} from '@angular/core';
import {Pipe, Type, resolveForwardRef, ɵReflectorReader, ɵreflector, ɵstringify as stringify} from '@angular/core';
import {findLast} from './directive_resolver';
import {stringify} from './facade/lang';
import {CompilerInjectable} from './injectable';
function _isPipeMetadata(type: any): boolean {

View File

@ -8,7 +8,6 @@
import {CompileDiDependencyMetadata, CompileDirectiveMetadata, CompileDirectiveSummary, CompileNgModuleMetadata, CompileProviderMetadata, CompileQueryMetadata, CompileTokenMetadata, CompileTypeMetadata, tokenName, tokenReference} from './compile_metadata';
import {isBlank, isPresent} from './facade/lang';
import {Identifiers, createIdentifierToken, resolveIdentifier} from './identifiers';
import {ParseError, ParseSourceSpan} from './parse_util';
import {AttrAst, DirectiveAst, ProviderAst, ProviderAstType, QueryMatch, ReferenceAst} from './template_parser/template_ast';
@ -37,7 +36,7 @@ export class ProviderViewContext {
this.viewQueries = _getViewQueries(component);
this.viewProviders = new Map<any, boolean>();
component.viewProviders.forEach((provider) => {
if (isBlank(this.viewProviders.get(tokenReference(provider.token)))) {
if (this.viewProviders.get(tokenReference(provider.token)) == null) {
this.viewProviders.set(tokenReference(provider.token), true);
}
});
@ -171,7 +170,7 @@ export class ProviderElementContext {
if (transformedProviderAst) {
return transformedProviderAst;
}
if (isPresent(this._seenProviders.get(tokenReference(token)))) {
if (this._seenProviders.get(tokenReference(token)) != null) {
this.viewContext.errors.push(new ProviderError(
`Cannot instantiate cyclic dependency! ${tokenName(token)}`, this._sourceSpan));
return null;
@ -181,10 +180,10 @@ export class ProviderElementContext {
let transformedUseValue = provider.useValue;
let transformedUseExisting = provider.useExisting;
let transformedDeps: CompileDiDependencyMetadata[];
if (isPresent(provider.useExisting)) {
if (provider.useExisting != null) {
const existingDiDep = this._getDependency(
resolvedProvider.providerType, {token: provider.useExisting}, eager);
if (isPresent(existingDiDep.token)) {
if (existingDiDep.token != null) {
transformedUseExisting = existingDiDep.token;
} else {
transformedUseExisting = null;
@ -219,7 +218,7 @@ export class ProviderElementContext {
return {isValue: true, value: attrValue == null ? null : attrValue};
}
if (isPresent(dep.token)) {
if (dep.token != null) {
// access builtints
if ((requestingProviderType === ProviderAstType.Directive ||
requestingProviderType === ProviderAstType.Component)) {
@ -238,7 +237,7 @@ export class ProviderElementContext {
return dep;
}
// access providers
if (isPresent(this._getOrCreateLocalProvider(requestingProviderType, dep.token, eager))) {
if (this._getOrCreateLocalProvider(requestingProviderType, dep.token, eager) != null) {
return dep;
}
}
@ -272,7 +271,7 @@ export class ProviderElementContext {
if (!result) {
if (!dep.isHost || this.viewContext.component.isHost ||
this.viewContext.component.type.reference === tokenReference(dep.token) ||
isPresent(this.viewContext.viewProviders.get(tokenReference(dep.token)))) {
this.viewContext.viewProviders.get(tokenReference(dep.token)) != null) {
result = dep;
} else {
result = dep.isOptional ? result = {isValue: true, value: null} : null;
@ -329,7 +328,7 @@ export class NgModuleProviderAnalyzer {
if (transformedProviderAst) {
return transformedProviderAst;
}
if (isPresent(this._seenProviders.get(tokenReference(token)))) {
if (this._seenProviders.get(tokenReference(token)) != null) {
this._errors.push(new ProviderError(
`Cannot instantiate cyclic dependency! ${tokenName(token)}`,
resolvedProvider.sourceSpan));
@ -340,10 +339,10 @@ export class NgModuleProviderAnalyzer {
let transformedUseValue = provider.useValue;
let transformedUseExisting = provider.useExisting;
let transformedDeps: CompileDiDependencyMetadata[];
if (isPresent(provider.useExisting)) {
if (provider.useExisting != null) {
const existingDiDep =
this._getDependency({token: provider.useExisting}, eager, resolvedProvider.sourceSpan);
if (isPresent(existingDiDep.token)) {
if (existingDiDep.token != null) {
transformedUseExisting = existingDiDep.token;
} else {
transformedUseExisting = null;
@ -374,13 +373,13 @@ export class NgModuleProviderAnalyzer {
dep: CompileDiDependencyMetadata, eager: boolean = null,
requestorSourceSpan: ParseSourceSpan): CompileDiDependencyMetadata {
let foundLocal = false;
if (!dep.isSkipSelf && isPresent(dep.token)) {
if (!dep.isSkipSelf && dep.token != null) {
// access the injector
if (tokenReference(dep.token) === resolveIdentifier(Identifiers.Injector) ||
tokenReference(dep.token) === resolveIdentifier(Identifiers.ComponentFactoryResolver)) {
foundLocal = true;
// access providers
} else if (isPresent(this._getOrCreateLocalProvider(dep.token, eager))) {
} else if (this._getOrCreateLocalProvider(dep.token, eager) != null) {
foundLocal = true;
}
}
@ -453,7 +452,7 @@ function _resolveProviders(
targetProvidersByToken: Map<any, ProviderAst>) {
providers.forEach((provider) => {
let resolvedProvider = targetProvidersByToken.get(tokenReference(provider.token));
if (isPresent(resolvedProvider) && !!resolvedProvider.multiProvider !== !!provider.multi) {
if (resolvedProvider != null && !!resolvedProvider.multiProvider !== !!provider.multi) {
targetErrors.push(new ProviderError(
`Mixing multi and non multi provider is not possible for token ${tokenName(resolvedProvider.token)}`,
sourceSpan));

View File

@ -11,7 +11,6 @@ import {CompileDirectiveMetadata, CompileDirectiveSummary, CompilePipeSummary, C
import {CompilerConfig} from '../config';
import {AST, ASTWithSource, EmptyExpr} from '../expression_parser/ast';
import {Parser} from '../expression_parser/parser';
import {isPresent} from '../facade/lang';
import {I18NHtmlParser} from '../i18n/i18n_html_parser';
import {Identifiers, createIdentifierToken, identifierToken} from '../identifiers';
import {CompilerInjectable} from '../injectable';
@ -295,7 +294,7 @@ class TemplateParseVisitor implements html.Visitor {
prefixToken = normalizedName.substring(TEMPLATE_ATTR_PREFIX.length) + ':';
}
const hasTemplateBinding = isPresent(templateBindingsSource);
const hasTemplateBinding = templateBindingsSource != null;
if (hasTemplateBinding) {
if (hasInlineTemplates) {
this._reportError(
@ -338,7 +337,7 @@ class TemplateParseVisitor implements html.Visitor {
isTemplateElement ? parent.providerContext : providerContext));
providerContext.afterElement();
// Override the actual selector when the `ngProjectAs` attribute is provided
const projectionSelector = isPresent(preparsedElement.projectAs) ?
const projectionSelector = preparsedElement.projectAs != null ?
CssSelector.parse(preparsedElement.projectAs)[0] :
elementCssSelector;
const ngContentIndex = parent.findNgContentIndex(projectionSelector);
@ -415,7 +414,7 @@ class TemplateParseVisitor implements html.Visitor {
if (bindParts !== null) {
hasBinding = true;
if (isPresent(bindParts[KW_BIND_IDX])) {
if (bindParts[KW_BIND_IDX] != null) {
this._bindingParser.parsePropertyBinding(
bindParts[IDENT_KW_IDX], value, false, srcSpan, targetMatchableAttrs, targetProps);
@ -698,7 +697,7 @@ class TemplateParseVisitor implements html.Visitor {
});
events.forEach(event => {
if (isPresent(event.target) || !allDirectiveEvents.has(event.name)) {
if (event.target != null || !allDirectiveEvents.has(event.name)) {
this._reportError(
`Event binding ${event.fullName} not emitted by any directive on an embedded template. Make sure that the event name is spelled correctly and all directives are listed in the "@NgModule.declarations".`,
event.sourceSpan);
@ -811,7 +810,7 @@ class ElementContext {
this._ngContentIndexMatcher.match(
selector, (selector, ngContentIndex) => { ngContentIndices.push(ngContentIndex); });
ngContentIndices.sort();
if (isPresent(this._wildcardNgContentIndex)) {
if (this._wildcardNgContentIndex != null) {
ngContentIndices.push(this._wildcardNgContentIndex);
}
return ngContentIndices.length > 0 ? ngContentIndices[0] : null;
@ -882,4 +881,4 @@ function isTemplate(
return false;
}
}
}

View File

@ -8,7 +8,6 @@
import {Inject, InjectionToken, PACKAGE_ROOT_URL} from '@angular/core';
import {isBlank, isPresent} from './facade/lang';
import {CompilerInjectable} from './injectable';
@ -62,12 +61,12 @@ export class UrlResolver {
*/
resolve(baseUrl: string, url: string): string {
let resolvedUrl = url;
if (isPresent(baseUrl) && baseUrl.length > 0) {
if (baseUrl != null && baseUrl.length > 0) {
resolvedUrl = _resolveUrl(baseUrl, resolvedUrl);
}
const resolvedParts = _split(resolvedUrl);
let prefix = this._packagePrefix;
if (isPresent(prefix) && isPresent(resolvedParts) &&
if (prefix != null && resolvedParts != null &&
resolvedParts[_ComponentIndex.Scheme] == 'package') {
let path = resolvedParts[_ComponentIndex.Path];
prefix = prefix.replace(/\/+$/, '');
@ -111,33 +110,33 @@ function _buildFromEncodedParts(
opt_path?: string, opt_queryData?: string, opt_fragment?: string): string {
const out: string[] = [];
if (isPresent(opt_scheme)) {
if (opt_scheme != null) {
out.push(opt_scheme + ':');
}
if (isPresent(opt_domain)) {
if (opt_domain != null) {
out.push('//');
if (isPresent(opt_userInfo)) {
if (opt_userInfo != null) {
out.push(opt_userInfo + '@');
}
out.push(opt_domain);
if (isPresent(opt_port)) {
if (opt_port != null) {
out.push(':' + opt_port);
}
}
if (isPresent(opt_path)) {
if (opt_path != null) {
out.push(opt_path);
}
if (isPresent(opt_queryData)) {
if (opt_queryData != null) {
out.push('?' + opt_queryData);
}
if (isPresent(opt_fragment)) {
if (opt_fragment != null) {
out.push('#' + opt_fragment);
}
@ -309,7 +308,7 @@ function _removeDotSegments(path: string): string {
*/
function _joinAndCanonicalizePath(parts: any[]): string {
let path = parts[_ComponentIndex.Path];
path = isBlank(path) ? '' : _removeDotSegments(path);
path = path == null ? '' : _removeDotSegments(path);
parts[_ComponentIndex.Path] = path;
return _buildFromEncodedParts(
@ -327,14 +326,14 @@ function _resolveUrl(base: string, url: string): string {
const parts = _split(encodeURI(url));
const baseParts = _split(base);
if (isPresent(parts[_ComponentIndex.Scheme])) {
if (parts[_ComponentIndex.Scheme] != null) {
return _joinAndCanonicalizePath(parts);
} else {
parts[_ComponentIndex.Scheme] = baseParts[_ComponentIndex.Scheme];
}
for (let i = _ComponentIndex.Scheme; i <= _ComponentIndex.Port; i++) {
if (isBlank(parts[i])) {
if (parts[i] == null) {
parts[i] = baseParts[i];
}
}
@ -344,7 +343,7 @@ function _resolveUrl(base: string, url: string): string {
}
let path = baseParts[_ComponentIndex.Path];
if (isBlank(path)) path = '/';
if (path == null) path = '/';
const index = path.lastIndexOf('/');
path = path.substring(0, index + 1) + parts[_ComponentIndex.Path];
parts[_ComponentIndex.Path] = path;

View File

@ -6,7 +6,6 @@
* found in the LICENSE file at https://angular.io/license
*/
import {isPrimitive, isStrictStringMap} from './facade/lang';
export const MODULE_SUFFIX = '';
const CAMEL_CASE_REGEXP = /([A-Z])/g;
@ -43,7 +42,8 @@ export function visitValue(value: any, visitor: ValueVisitor, context: any): any
return visitor.visitStringMap(<{[key: string]: any}>value, context);
}
if (value == null || isPrimitive(value)) {
if (value == null || typeof value == 'string' || typeof value == 'number' ||
typeof value == 'boolean') {
return visitor.visitPrimitive(value, context);
}
@ -89,3 +89,12 @@ const ERROR_SYNTAX_ERROR = 'ngSyntaxError';
export function isSyntaxError(error: Error): boolean {
return (error as any)[ERROR_SYNTAX_ERROR];
}
export function escapeRegExp(s: string): string {
return s.replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1');
}
const STRING_MAP_PROTO = Object.getPrototypeOf({});
function isStrictStringMap(obj: any): boolean {
return typeof obj === 'object' && obj !== null && Object.getPrototypeOf(obj) === STRING_MAP_PROTO;
}