refactor(compiler): remove `asset:` urls
These urls were just relicts from Dart.
This commit is contained in:
parent
24099bdbd2
commit
484119e59f
|
@ -6,7 +6,7 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* 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 {AngularCompilerOptions, MetadataCollector, ModuleMetadata} from '@angular/tsc-wrapped';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
@ -60,20 +60,6 @@ export class NgHost implements AotCompilerHost {
|
||||||
return resolved ? resolved.resolvedFileName : null;
|
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.
|
* 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.
|
* 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`.
|
* NOTE: (*) the relative path is computed depending on `isGenDirChildOfRootDir`.
|
||||||
*/
|
*/
|
||||||
getImportPath(containingFile: string, importedFile: string): string {
|
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
|
// 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!
|
// assume it exists it so that the `resolve` method works!
|
||||||
if (!this.compilerHost.fileExists(importedFile)) {
|
if (!this.compilerHost.fileExists(importedFile)) {
|
||||||
|
|
|
@ -70,9 +70,6 @@ export class PathMappedNgHost extends NgHost {
|
||||||
* they are resolvable by the moduleResolution strategy from the CompilerHost.
|
* they are resolvable by the moduleResolution strategy from the CompilerHost.
|
||||||
*/
|
*/
|
||||||
getImportPath(containingFile: string, importedFile: string): string {
|
getImportPath(containingFile: string, importedFile: string): string {
|
||||||
importedFile = this.resolveAssetUrl(importedFile, containingFile);
|
|
||||||
containingFile = this.resolveAssetUrl(containingFile, '');
|
|
||||||
|
|
||||||
if (this.options.traceResolution) {
|
if (this.options.traceResolution) {
|
||||||
console.log(
|
console.log(
|
||||||
'getImportPath from containingFile', containingFile, 'to importedFile', importedFile);
|
'getImportPath from containingFile', containingFile, 'to importedFile', importedFile);
|
||||||
|
|
|
@ -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 {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 {ReflectorReader} from '../private_import_core';
|
||||||
import {AotCompilerHost} from './compiler_host';
|
import {AotCompilerHost} from './compiler_host';
|
||||||
import {StaticSymbol} from './static_symbol';
|
import {StaticSymbol} from './static_symbol';
|
||||||
|
@ -213,11 +212,6 @@ export class StaticReflector implements ReflectorReader {
|
||||||
return result;
|
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 {
|
private resolveExportedSymbol(filePath: string, symbolName: string): StaticSymbol {
|
||||||
const resolveModule = (moduleName: string): string => {
|
const resolveModule = (moduleName: string): string => {
|
||||||
const resolvedModulePath = this.host.resolveImportToFile(moduleName, filePath);
|
const resolvedModulePath = this.host.resolveImportToFile(moduleName, filePath);
|
||||||
|
@ -275,10 +269,6 @@ export class StaticReflector implements ReflectorReader {
|
||||||
return symbol;
|
return symbol;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const assetUrl = this.normalizeAssetUrl(module);
|
|
||||||
if (assetUrl) {
|
|
||||||
module = assetUrl;
|
|
||||||
}
|
|
||||||
const filePath = this.host.resolveImportToFile(module, containingFile);
|
const filePath = this.host.resolveImportToFile(module, containingFile);
|
||||||
|
|
||||||
if (!filePath) {
|
if (!filePath) {
|
||||||
|
|
|
@ -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 {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 {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';
|
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 {
|
export function assetUrl(pkg: string, path: string = null, type: string = 'src'): string {
|
||||||
if (path == null) {
|
if (path == null) {
|
||||||
return `asset:@angular/lib/${pkg}/index`;
|
return `@angular/${pkg}/index`;
|
||||||
} else {
|
} else {
|
||||||
return `asset:@angular/lib/${pkg}/src/${path}`;
|
return `@angular/${pkg}/${type}/${path}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resolveIdentifier(identifier: IdentifierSpec) {
|
export function resolveIdentifier(identifier: IdentifierSpec) {
|
||||||
return new CompileIdentifierMetadata({
|
let moduleUrl = identifier.moduleUrl;
|
||||||
name: identifier.name,
|
const reference =
|
||||||
moduleUrl: identifier.moduleUrl,
|
reflector.resolveIdentifier(identifier.name, identifier.moduleUrl, identifier.runtime);
|
||||||
reference:
|
if (isStaticSymbol(reference)) {
|
||||||
reflector.resolveIdentifier(identifier.name, identifier.moduleUrl, identifier.runtime)
|
moduleUrl = reference.filePath;
|
||||||
});
|
}
|
||||||
|
return new CompileIdentifierMetadata(
|
||||||
|
{name: identifier.name, moduleUrl: moduleUrl, reference: reference});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function identifierToken(identifier: CompileIdentifierMetadata): CompileTokenMetadata {
|
export function identifierToken(identifier: CompileIdentifierMetadata): CompileTokenMetadata {
|
||||||
|
|
|
@ -6,30 +6,9 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* 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.
|
* Interface that defines how import statements should be generated.
|
||||||
*/
|
*/
|
||||||
export abstract class ImportGenerator {
|
export abstract class ImportGenerator {
|
||||||
static parseAssetUrl(url: string): AssetUrl { return AssetUrl.parse(url); }
|
|
||||||
|
|
||||||
abstract getImportPath(moduleUrlStr: string, importedUrlStr: string): string;
|
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) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ import {AbstractEmitterVisitor, CATCH_ERROR_VAR, CATCH_STACK_VAR, EmitterVisitor
|
||||||
import * as o from './output_ast';
|
import * as o from './output_ast';
|
||||||
import {ImportGenerator} from './path_util';
|
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[]):
|
export function debugOutputAstAsTypeScript(ast: o.Statement | o.Expression | o.Type | any[]):
|
||||||
string {
|
string {
|
||||||
|
|
|
@ -10,9 +10,6 @@ import {Inject, Injectable, PACKAGE_ROOT_URL} from '@angular/core';
|
||||||
|
|
||||||
import {isBlank, isPresent} from './facade/lang';
|
import {isBlank, isPresent} from './facade/lang';
|
||||||
|
|
||||||
|
|
||||||
const _ASSET_SCHEME = 'asset:';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a {@link UrlResolver} with no package prefix.
|
* Create a {@link UrlResolver} with no package prefix.
|
||||||
*/
|
*/
|
||||||
|
@ -21,7 +18,7 @@ export function createUrlResolverWithoutPackagePrefix(): UrlResolver {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createOfflineCompileUrlResolver(): 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) &&
|
if (isPresent(prefix) && isPresent(resolvedParts) &&
|
||||||
resolvedParts[_ComponentIndex.Scheme] == 'package') {
|
resolvedParts[_ComponentIndex.Scheme] == 'package') {
|
||||||
let path = resolvedParts[_ComponentIndex.Path];
|
let path = resolvedParts[_ComponentIndex.Path];
|
||||||
if (this._packagePrefix === _ASSET_SCHEME) {
|
prefix = prefix.replace(/\/+$/, '');
|
||||||
const pathSegements = path.split(/\//);
|
path = path.replace(/^\/+/, '');
|
||||||
resolvedUrl = `asset:${pathSegements[0]}/lib/${pathSegements.slice(1).join('/')}`;
|
return `${prefix}/${path}`;
|
||||||
} else {
|
|
||||||
prefix = prefix.replace(/\/+$/, '');
|
|
||||||
path = path.replace(/^\/+/, '');
|
|
||||||
return `${prefix}/${path}`;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return resolvedUrl;
|
return resolvedUrl;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,8 @@ import {beforeEach, describe, expect, it} from '@angular/core/testing/testing_in
|
||||||
|
|
||||||
import {SimpleJsImportGenerator} from './output_emitter_util';
|
import {SimpleJsImportGenerator} from './output_emitter_util';
|
||||||
|
|
||||||
const someModuleUrl = 'asset:somePackage/lib/somePath';
|
const someModuleUrl = 'somePackage/somePath';
|
||||||
const anotherModuleUrl = 'asset:somePackage/lib/someOtherPath';
|
const anotherModuleUrl = 'somePackage/someOtherPath';
|
||||||
|
|
||||||
const sameModuleIdentifier =
|
const sameModuleIdentifier =
|
||||||
new CompileIdentifierMetadata({name: 'someLocalId', moduleUrl: someModuleUrl});
|
new CompileIdentifierMetadata({name: 'someLocalId', moduleUrl: someModuleUrl});
|
||||||
|
|
|
@ -22,7 +22,7 @@ export class ExternalClass {
|
||||||
|
|
||||||
const testDataIdentifier = new CompileIdentifierMetadata({
|
const testDataIdentifier = new CompileIdentifierMetadata({
|
||||||
name: 'ExternalClass',
|
name: 'ExternalClass',
|
||||||
moduleUrl: `asset:@angular/lib/compiler/test/output/output_emitter_util`,
|
moduleUrl: `@angular/compiler/test/output/output_emitter_util`,
|
||||||
reference: ExternalClass
|
reference: ExternalClass
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -253,12 +253,5 @@ function createOperatorFn(op: o.BinaryOperator) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SimpleJsImportGenerator implements ImportGenerator {
|
export class SimpleJsImportGenerator implements ImportGenerator {
|
||||||
getImportPath(moduleUrlStr: string, importedUrlStr: string): string {
|
getImportPath(moduleUrlStr: string, importedUrlStr: string): string { return importedUrlStr; }
|
||||||
const importedAssetUrl = ImportGenerator.parseAssetUrl(importedUrlStr);
|
|
||||||
if (importedAssetUrl) {
|
|
||||||
return `${importedAssetUrl.packageName}/${importedAssetUrl.modulePath}`;
|
|
||||||
} else {
|
|
||||||
return importedUrlStr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,8 @@ import {beforeEach, describe, expect, it} from '@angular/core/testing/testing_in
|
||||||
|
|
||||||
import {SimpleJsImportGenerator} from './output_emitter_util';
|
import {SimpleJsImportGenerator} from './output_emitter_util';
|
||||||
|
|
||||||
const someModuleUrl = 'asset:somePackage/lib/somePath';
|
const someModuleUrl = 'somePackage/somePath';
|
||||||
const anotherModuleUrl = 'asset:somePackage/lib/someOtherPath';
|
const anotherModuleUrl = 'somePackage/someOtherPath';
|
||||||
|
|
||||||
const sameModuleIdentifier =
|
const sameModuleIdentifier =
|
||||||
new CompileIdentifierMetadata({name: 'someLocalId', moduleUrl: someModuleUrl});
|
new CompileIdentifierMetadata({name: 'someLocalId', moduleUrl: someModuleUrl});
|
||||||
|
|
|
@ -91,9 +91,6 @@ export function main() {
|
||||||
it('should resolve package: urls',
|
it('should resolve package: urls',
|
||||||
() => { expect(isStyleUrlResolvable('package:someUrl.css')).toBe(true); });
|
() => { 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', () => {
|
it('should not resolve empty urls', () => {
|
||||||
expect(isStyleUrlResolvable(null)).toBe(false);
|
expect(isStyleUrlResolvable(null)).toBe(false);
|
||||||
expect(isStyleUrlResolvable('')).toBe(false);
|
expect(isStyleUrlResolvable('')).toBe(false);
|
||||||
|
|
|
@ -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', () => {
|
describe('corner and error cases', () => {
|
||||||
it('should encode URLs before resolving',
|
it('should encode URLs before resolving',
|
||||||
() => {
|
() => {
|
||||||
|
|
Loading…
Reference in New Issue