diff --git a/packages/@angular/cli/lib/ast-tools/ast-utils.ts b/packages/@angular/cli/lib/ast-tools/ast-utils.ts index c3ba6f37152b..d91203a84800 100644 --- a/packages/@angular/cli/lib/ast-tools/ast-utils.ts +++ b/packages/@angular/cli/lib/ast-tools/ast-utils.ts @@ -1,10 +1,5 @@ import * as ts from 'typescript'; import * as fs from 'fs'; -import {Symbols} from '@angular/tsc-wrapped/src/symbols'; -import { - isMetadataImportedSymbolReferenceExpression, - isMetadataModuleReferenceExpression -} from '@angular/tsc-wrapped'; import {Change, InsertChange, NoopChange, MultiChange} from './change'; import {findNodes} from './node'; import {insertImport} from './route-utils'; @@ -105,9 +100,64 @@ export function getContentOfKeyLiteral(source: ts.SourceFile, node: ts.Node): st } + +function _angularImportsFromNode(node: ts.ImportDeclaration, + sourceFile: ts.SourceFile): {[name: string]: string} { + const ms = node.moduleSpecifier; + let modulePath: string | null = null; + switch (ms.kind) { + case ts.SyntaxKind.StringLiteral: + modulePath = (ms as ts.StringLiteral).text; + break; + default: + return {}; + } + + if (!modulePath.startsWith('@angular/')) { + return {}; + } + + if (node.importClause) { + if (node.importClause.name) { + // This is of the form `import Name from 'path'`. Ignore. + return {}; + } else if (node.importClause.namedBindings) { + const nb = node.importClause.namedBindings; + if (nb.kind == ts.SyntaxKind.NamespaceImport) { + // This is of the form `import * as name from 'path'`. Return `name.`. + return { + [(nb as ts.NamespaceImport).name.text + '.']: modulePath + }; + } else { + // This is of the form `import {a,b,c} from 'path'` + const namedImports = nb as ts.NamedImports; + + return namedImports.elements + .map((is: ts.ImportSpecifier) => is.propertyName ? is.propertyName.text : is.name.text) + .reduce((acc: {[name: string]: string}, curr: string) => { + acc[curr] = modulePath; + return acc; + }, {}); + } + } + } else { + // This is of the form `import 'path';`. Nothing to do. + return {}; + } +} + + export function getDecoratorMetadata(source: ts.SourceFile, identifier: string, module: string): Observable { - const symbols = new Symbols(source as any); + const angularImports: {[name: string]: string} + = findNodes(source, ts.SyntaxKind.ImportDeclaration) + .map((node: ts.ImportDeclaration) => _angularImportsFromNode(node, source)) + .reduce((acc: {[name: string]: string}, current: {[name: string]: string}) => { + for (const key of Object.keys(current)) { + acc[key] = current[key]; + } + return acc; + }, {}); return getSourceNodes(source) .filter(node => { @@ -118,10 +168,8 @@ export function getDecoratorMetadata(source: ts.SourceFile, identifier: string, .filter(expr => { if (expr.expression.kind == ts.SyntaxKind.Identifier) { const id = expr.expression; - const metaData = symbols.resolve(id.getFullText(source)); - if (isMetadataImportedSymbolReferenceExpression(metaData)) { - return metaData.name == identifier && metaData.module == module; - } + return id.getFullText(source) == identifier + && angularImports[id.getFullText(source)] === module; } else if (expr.expression.kind == ts.SyntaxKind.PropertyAccessExpression) { // This covers foo.NgModule when importing * as foo. const paExpr = expr.expression; @@ -130,12 +178,9 @@ export function getDecoratorMetadata(source: ts.SourceFile, identifier: string, return false; } - const id = paExpr.name; - const moduleId = paExpr.expression; - const moduleMetaData = symbols.resolve(moduleId.getFullText(source)); - if (isMetadataModuleReferenceExpression(moduleMetaData)) { - return moduleMetaData.module == module && id.getFullText(source) == identifier; - } + const id = paExpr.name.text; + const moduleId = (paExpr.expression).getText(source); + return id === identifier && (angularImports[moduleId + '.'] === module); } return false; }) diff --git a/packages/@angular/cli/lib/cli/index.js b/packages/@angular/cli/lib/cli/index.js index 87e17842b98e..9e3dcaf89660 100644 --- a/packages/@angular/cli/lib/cli/index.js +++ b/packages/@angular/cli/lib/cli/index.js @@ -3,7 +3,6 @@ // Prevent the dependency validation from tripping because we don't import these. We need // it as a peer dependency of @angular/core. // require('zone.js') -// require('rxjs') // This file hooks up on require calls to transpile TypeScript. diff --git a/packages/@angular/cli/package.json b/packages/@angular/cli/package.json index 39b358e30dee..daeadf302e19 100644 --- a/packages/@angular/cli/package.json +++ b/packages/@angular/cli/package.json @@ -26,10 +26,6 @@ }, "homepage": "https://github.com/angular/angular-cli", "dependencies": { - "@angular/compiler": "^2.3.1", - "@angular/compiler-cli": "^2.3.1", - "@angular/core": "^2.3.1", - "@angular/tsc-wrapped": "^0.5.0", "@ngtools/json-schema": "^1.0.0", "@ngtools/webpack": "^1.2.3", "async": "^2.1.4",