refactor(compiler): remove `asset:` urls

These urls were just relicts from Dart.
This commit is contained in:
Tobias Bosch 2016-11-15 10:14:01 -08:00 committed by Chuck Jazdzewski
parent 24099bdbd2
commit 484119e59f
12 changed files with 23 additions and 99 deletions

View File

@ -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)) {

View File

@ -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);

View File

@ -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) {

View File

@ -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 {

View File

@ -6,30 +6,9 @@
* found in the LICENSE file at https://angular.io/license
*/
// asset:<package-name>/<realm>/<path-to-module>
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) {
}
}

View File

@ -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 {

View File

@ -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;
}

View File

@ -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});

View File

@ -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; }
}

View File

@ -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});

View File

@ -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);

View File

@ -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',
() => {