From 484119e59fef5e9395f54dac65eeb7d65b479fab Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Tue, 15 Nov 2016 10:14:01 -0800 Subject: [PATCH] refactor(compiler): remove `asset:` urls These urls were just relicts from Dart. --- modules/@angular/compiler-cli/src/ng_host.ts | 19 +---------------- .../compiler-cli/src/path_mapped_ng_host.ts | 3 --- .../compiler/src/aot/static_reflector.ts | 10 --------- modules/@angular/compiler/src/identifiers.ts | 19 ++++++++++------- .../@angular/compiler/src/output/path_util.ts | 21 ------------------- .../compiler/src/output/ts_emitter.ts | 2 +- modules/@angular/compiler/src/url_resolver.ts | 16 ++++---------- .../compiler/test/output/js_emitter_spec.ts | 4 ++-- .../test/output/output_emitter_util.ts | 11 ++-------- .../compiler/test/output/ts_emitter_spec.ts | 4 ++-- .../compiler/test/style_url_resolver_spec.ts | 3 --- .../compiler/test/url_resolver_spec.ts | 10 --------- 12 files changed, 23 insertions(+), 99 deletions(-) diff --git a/modules/@angular/compiler-cli/src/ng_host.ts b/modules/@angular/compiler-cli/src/ng_host.ts index 50c437bb04..e1d975033e 100644 --- a/modules/@angular/compiler-cli/src/ng_host.ts +++ b/modules/@angular/compiler-cli/src/ng_host.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {AotCompilerHost, AssetUrl, StaticSymbol} from '@angular/compiler'; +import {AotCompilerHost, StaticSymbol} from '@angular/compiler'; import {AngularCompilerOptions, MetadataCollector, ModuleMetadata} from '@angular/tsc-wrapped'; import * as fs from 'fs'; import * as path from 'path'; @@ -60,20 +60,6 @@ export class NgHost implements AotCompilerHost { return resolved ? resolved.resolvedFileName : null; }; - protected normalizeAssetUrl(url: string): string { - const assetUrl = AssetUrl.parse(url); - const path = assetUrl ? `${assetUrl.packageName}/${assetUrl.modulePath}` : null; - return this.getCanonicalFileName(path); - } - - protected resolveAssetUrl(url: string, containingFile: string): string { - const assetUrl = this.normalizeAssetUrl(url); - if (assetUrl) { - return this.getCanonicalFileName(this.resolveImportToFile(assetUrl, containingFile)); - } - return url; - } - /** * We want a moduleId that will appear in import statements in the generated code. * These need to be in a form that system.js can load, so absolute file paths don't work. @@ -90,9 +76,6 @@ export class NgHost implements AotCompilerHost { * NOTE: (*) the relative path is computed depending on `isGenDirChildOfRootDir`. */ getImportPath(containingFile: string, importedFile: string): string { - importedFile = this.resolveAssetUrl(importedFile, containingFile); - containingFile = this.resolveAssetUrl(containingFile, ''); - // If a file does not yet exist (because we compile it later), we still need to // assume it exists it so that the `resolve` method works! if (!this.compilerHost.fileExists(importedFile)) { diff --git a/modules/@angular/compiler-cli/src/path_mapped_ng_host.ts b/modules/@angular/compiler-cli/src/path_mapped_ng_host.ts index 863952cf7d..d37ec855ea 100644 --- a/modules/@angular/compiler-cli/src/path_mapped_ng_host.ts +++ b/modules/@angular/compiler-cli/src/path_mapped_ng_host.ts @@ -70,9 +70,6 @@ export class PathMappedNgHost extends NgHost { * they are resolvable by the moduleResolution strategy from the CompilerHost. */ getImportPath(containingFile: string, importedFile: string): string { - importedFile = this.resolveAssetUrl(importedFile, containingFile); - containingFile = this.resolveAssetUrl(containingFile, ''); - if (this.options.traceResolution) { console.log( 'getImportPath from containingFile', containingFile, 'to importedFile', importedFile); diff --git a/modules/@angular/compiler/src/aot/static_reflector.ts b/modules/@angular/compiler/src/aot/static_reflector.ts index 2efca94244..a026b8a710 100644 --- a/modules/@angular/compiler/src/aot/static_reflector.ts +++ b/modules/@angular/compiler/src/aot/static_reflector.ts @@ -7,7 +7,6 @@ */ import {Attribute, Component, ContentChild, ContentChildren, Directive, Host, HostBinding, HostListener, Inject, Injectable, Input, NgModule, Optional, Output, Pipe, Self, SkipSelf, ViewChild, ViewChildren, animate, group, keyframes, sequence, state, style, transition, trigger} from '@angular/core'; -import {AssetUrl} from '../output/path_util'; import {ReflectorReader} from '../private_import_core'; import {AotCompilerHost} from './compiler_host'; import {StaticSymbol} from './static_symbol'; @@ -213,11 +212,6 @@ export class StaticReflector implements ReflectorReader { return result; } - private normalizeAssetUrl(url: string): string { - const assetUrl = AssetUrl.parse(url); - return assetUrl ? `${assetUrl.packageName}@${assetUrl.modulePath}` : null; - } - private resolveExportedSymbol(filePath: string, symbolName: string): StaticSymbol { const resolveModule = (moduleName: string): string => { const resolvedModulePath = this.host.resolveImportToFile(moduleName, filePath); @@ -275,10 +269,6 @@ export class StaticReflector implements ReflectorReader { return symbol; } try { - const assetUrl = this.normalizeAssetUrl(module); - if (assetUrl) { - module = assetUrl; - } const filePath = this.host.resolveImportToFile(module, containingFile); if (!filePath) { diff --git a/modules/@angular/compiler/src/identifiers.ts b/modules/@angular/compiler/src/identifiers.ts index ab9fd5889a..0f6c664758 100644 --- a/modules/@angular/compiler/src/identifiers.ts +++ b/modules/@angular/compiler/src/identifiers.ts @@ -8,6 +8,7 @@ import {ANALYZE_FOR_ENTRY_COMPONENTS, AnimationTransitionEvent, ChangeDetectionStrategy, ChangeDetectorRef, ComponentFactory, ComponentFactoryResolver, ComponentRef, ElementRef, Injector, LOCALE_ID, NgModuleFactory, QueryList, RenderComponentType, Renderer, SecurityContext, SimpleChange, TRANSLATIONS_FORMAT, TemplateRef, ViewContainerRef, ViewEncapsulation} from '@angular/core'; +import {StaticSymbol, isStaticSymbol} from './aot/static_symbol'; import {CompileIdentifierMetadata, CompileTokenMetadata} from './compile_metadata'; import {AnimationGroupPlayer, AnimationKeyframe, AnimationSequencePlayer, AnimationStyles, AnimationTransition, AppView, ChangeDetectorStatus, CodegenComponentFactoryResolver, ComponentRef_, DebugAppView, DebugContext, NgModuleInjector, NoOpAnimationPlayer, StaticNodeDebugInfo, TemplateRef_, UNINITIALIZED, ValueUnwrapper, ViewContainer, ViewType, balanceAnimationKeyframes, clearStyles, collectAndResolveStyles, devModeEqual, prepareFinalAnimationStyles, reflector, registerModuleFactory, renderStyles, view_utils} from './private_import_core'; @@ -339,19 +340,21 @@ export class Identifiers { export function assetUrl(pkg: string, path: string = null, type: string = 'src'): string { if (path == null) { - return `asset:@angular/lib/${pkg}/index`; + return `@angular/${pkg}/index`; } else { - return `asset:@angular/lib/${pkg}/src/${path}`; + return `@angular/${pkg}/${type}/${path}`; } } export function resolveIdentifier(identifier: IdentifierSpec) { - return new CompileIdentifierMetadata({ - name: identifier.name, - moduleUrl: identifier.moduleUrl, - reference: - reflector.resolveIdentifier(identifier.name, identifier.moduleUrl, identifier.runtime) - }); + let moduleUrl = identifier.moduleUrl; + const reference = + reflector.resolveIdentifier(identifier.name, identifier.moduleUrl, identifier.runtime); + if (isStaticSymbol(reference)) { + moduleUrl = reference.filePath; + } + return new CompileIdentifierMetadata( + {name: identifier.name, moduleUrl: moduleUrl, reference: reference}); } export function identifierToken(identifier: CompileIdentifierMetadata): CompileTokenMetadata { diff --git a/modules/@angular/compiler/src/output/path_util.ts b/modules/@angular/compiler/src/output/path_util.ts index 9f1c30efd3..e8dfb24391 100644 --- a/modules/@angular/compiler/src/output/path_util.ts +++ b/modules/@angular/compiler/src/output/path_util.ts @@ -6,30 +6,9 @@ * found in the LICENSE file at https://angular.io/license */ -// asset:// -const _ASSET_URL_RE = /asset:([^\/]+)\/([^\/]+)\/(.+)/; - /** * Interface that defines how import statements should be generated. */ export abstract class ImportGenerator { - static parseAssetUrl(url: string): AssetUrl { return AssetUrl.parse(url); } - abstract getImportPath(moduleUrlStr: string, importedUrlStr: string): string; } - -export class AssetUrl { - static parse(url: string, allowNonMatching: boolean = true): AssetUrl { - const match = url.match(_ASSET_URL_RE); - if (match !== null) { - return new AssetUrl(match[1], match[2], match[3]); - } - if (allowNonMatching) { - return null; - } - throw new Error(`Url ${url} is not a valid asset: url`); - } - - constructor(public packageName: string, public firstLevelDir: string, public modulePath: string) { - } -} diff --git a/modules/@angular/compiler/src/output/ts_emitter.ts b/modules/@angular/compiler/src/output/ts_emitter.ts index 30ab03e794..e0628cd3f3 100644 --- a/modules/@angular/compiler/src/output/ts_emitter.ts +++ b/modules/@angular/compiler/src/output/ts_emitter.ts @@ -14,7 +14,7 @@ import {AbstractEmitterVisitor, CATCH_ERROR_VAR, CATCH_STACK_VAR, EmitterVisitor import * as o from './output_ast'; import {ImportGenerator} from './path_util'; -const _debugModuleUrl = 'asset://debug/lib'; +const _debugModuleUrl = '/debug/lib'; export function debugOutputAstAsTypeScript(ast: o.Statement | o.Expression | o.Type | any[]): string { diff --git a/modules/@angular/compiler/src/url_resolver.ts b/modules/@angular/compiler/src/url_resolver.ts index 84058063be..8d9c031c08 100644 --- a/modules/@angular/compiler/src/url_resolver.ts +++ b/modules/@angular/compiler/src/url_resolver.ts @@ -10,9 +10,6 @@ import {Inject, Injectable, PACKAGE_ROOT_URL} from '@angular/core'; import {isBlank, isPresent} from './facade/lang'; - -const _ASSET_SCHEME = 'asset:'; - /** * Create a {@link UrlResolver} with no package prefix. */ @@ -21,7 +18,7 @@ export function createUrlResolverWithoutPackagePrefix(): UrlResolver { } export function createOfflineCompileUrlResolver(): UrlResolver { - return new UrlResolver(_ASSET_SCHEME); + return new UrlResolver('.'); } /** @@ -70,14 +67,9 @@ export class UrlResolver { if (isPresent(prefix) && isPresent(resolvedParts) && resolvedParts[_ComponentIndex.Scheme] == 'package') { let path = resolvedParts[_ComponentIndex.Path]; - if (this._packagePrefix === _ASSET_SCHEME) { - const pathSegements = path.split(/\//); - resolvedUrl = `asset:${pathSegements[0]}/lib/${pathSegements.slice(1).join('/')}`; - } else { - prefix = prefix.replace(/\/+$/, ''); - path = path.replace(/^\/+/, ''); - return `${prefix}/${path}`; - } + prefix = prefix.replace(/\/+$/, ''); + path = path.replace(/^\/+/, ''); + return `${prefix}/${path}`; } return resolvedUrl; } diff --git a/modules/@angular/compiler/test/output/js_emitter_spec.ts b/modules/@angular/compiler/test/output/js_emitter_spec.ts index 8ec1565000..f85c21d0d0 100644 --- a/modules/@angular/compiler/test/output/js_emitter_spec.ts +++ b/modules/@angular/compiler/test/output/js_emitter_spec.ts @@ -13,8 +13,8 @@ import {beforeEach, describe, expect, it} from '@angular/core/testing/testing_in import {SimpleJsImportGenerator} from './output_emitter_util'; -const someModuleUrl = 'asset:somePackage/lib/somePath'; -const anotherModuleUrl = 'asset:somePackage/lib/someOtherPath'; +const someModuleUrl = 'somePackage/somePath'; +const anotherModuleUrl = 'somePackage/someOtherPath'; const sameModuleIdentifier = new CompileIdentifierMetadata({name: 'someLocalId', moduleUrl: someModuleUrl}); diff --git a/modules/@angular/compiler/test/output/output_emitter_util.ts b/modules/@angular/compiler/test/output/output_emitter_util.ts index 83b445a94a..c510b794cf 100644 --- a/modules/@angular/compiler/test/output/output_emitter_util.ts +++ b/modules/@angular/compiler/test/output/output_emitter_util.ts @@ -22,7 +22,7 @@ export class ExternalClass { const testDataIdentifier = new CompileIdentifierMetadata({ name: 'ExternalClass', - moduleUrl: `asset:@angular/lib/compiler/test/output/output_emitter_util`, + moduleUrl: `@angular/compiler/test/output/output_emitter_util`, reference: ExternalClass }); @@ -253,12 +253,5 @@ function createOperatorFn(op: o.BinaryOperator) { } export class SimpleJsImportGenerator implements ImportGenerator { - getImportPath(moduleUrlStr: string, importedUrlStr: string): string { - const importedAssetUrl = ImportGenerator.parseAssetUrl(importedUrlStr); - if (importedAssetUrl) { - return `${importedAssetUrl.packageName}/${importedAssetUrl.modulePath}`; - } else { - return importedUrlStr; - } - } + getImportPath(moduleUrlStr: string, importedUrlStr: string): string { return importedUrlStr; } } diff --git a/modules/@angular/compiler/test/output/ts_emitter_spec.ts b/modules/@angular/compiler/test/output/ts_emitter_spec.ts index 86d65d53e4..5f221eb927 100644 --- a/modules/@angular/compiler/test/output/ts_emitter_spec.ts +++ b/modules/@angular/compiler/test/output/ts_emitter_spec.ts @@ -13,8 +13,8 @@ import {beforeEach, describe, expect, it} from '@angular/core/testing/testing_in import {SimpleJsImportGenerator} from './output_emitter_util'; -const someModuleUrl = 'asset:somePackage/lib/somePath'; -const anotherModuleUrl = 'asset:somePackage/lib/someOtherPath'; +const someModuleUrl = 'somePackage/somePath'; +const anotherModuleUrl = 'somePackage/someOtherPath'; const sameModuleIdentifier = new CompileIdentifierMetadata({name: 'someLocalId', moduleUrl: someModuleUrl}); diff --git a/modules/@angular/compiler/test/style_url_resolver_spec.ts b/modules/@angular/compiler/test/style_url_resolver_spec.ts index 8f954bb946..700a8631ae 100644 --- a/modules/@angular/compiler/test/style_url_resolver_spec.ts +++ b/modules/@angular/compiler/test/style_url_resolver_spec.ts @@ -91,9 +91,6 @@ export function main() { it('should resolve package: urls', () => { expect(isStyleUrlResolvable('package:someUrl.css')).toBe(true); }); - it('should resolve asset: urls', - () => { expect(isStyleUrlResolvable('asset:someUrl.css')).toBe(true); }); - it('should not resolve empty urls', () => { expect(isStyleUrlResolvable(null)).toBe(false); expect(isStyleUrlResolvable('')).toBe(false); diff --git a/modules/@angular/compiler/test/url_resolver_spec.ts b/modules/@angular/compiler/test/url_resolver_spec.ts index 67f90bcd3a..b6a538d04b 100644 --- a/modules/@angular/compiler/test/url_resolver_spec.ts +++ b/modules/@angular/compiler/test/url_resolver_spec.ts @@ -106,16 +106,6 @@ export function main() { }); }); - describe('asset urls', () => { - let resolver: UrlResolver; - beforeEach(() => { resolver = createOfflineCompileUrlResolver(); }); - - it('should resolve package: urls into asset: urls', () => { - expect(resolver.resolve(null, 'package:somePkg/somePath')) - .toEqual('asset:somePkg/lib/somePath'); - }); - }); - describe('corner and error cases', () => { it('should encode URLs before resolving', () => {