fix(compiler): support css stylesheets in offline compiler
This commit is contained in:
@ -13,6 +13,7 @@ import {isBlank} from '../../src/facade/lang';
|
||||
import {DartEmitter} from '@angular/compiler/src/output/dart_emitter';
|
||||
import {CompileIdentifierMetadata} from '@angular/compiler/src/compile_metadata';
|
||||
import * as o from '@angular/compiler/src/output/output_ast';
|
||||
import {DartImportGenerator} from '@angular/compiler/src/output/dart_imports';
|
||||
|
||||
var someModuleUrl = 'asset:somePackage/lib/somePath';
|
||||
var anotherModuleUrl = 'asset:somePackage/lib/someOtherPath';
|
||||
@ -36,7 +37,7 @@ export function main() {
|
||||
var someVar: o.ReadVarExpr;
|
||||
|
||||
beforeEach(() => {
|
||||
emitter = new DartEmitter();
|
||||
emitter = new DartEmitter(new DartImportGenerator());
|
||||
someVar = o.variable('someVar');
|
||||
});
|
||||
|
||||
|
64
modules/@angular/compiler/test/output/dart_imports_spec.ts
Normal file
64
modules/@angular/compiler/test/output/dart_imports_spec.ts
Normal file
@ -0,0 +1,64 @@
|
||||
import {
|
||||
beforeEach,
|
||||
ddescribe,
|
||||
describe,
|
||||
expect,
|
||||
iit,
|
||||
inject,
|
||||
it,
|
||||
xit,
|
||||
} from '@angular/core/testing/testing_internal';
|
||||
|
||||
import {DartImportGenerator} from '@angular/compiler/src/output/dart_imports';
|
||||
|
||||
export function main() {
|
||||
describe('DartImportGenerator', () => {
|
||||
describe('getImportPath', () => {
|
||||
var generator: DartImportGenerator;
|
||||
beforeEach(() => { generator = new DartImportGenerator(); });
|
||||
|
||||
it('should calculate relative paths Dart', () => {
|
||||
expect(generator.getImportPath('asset:somePkg/lib/modPath', 'asset:somePkg/lib/impPath'))
|
||||
.toEqual('impPath');
|
||||
});
|
||||
|
||||
it('should calculate relative paths for different constellations', () => {
|
||||
expect(generator.getImportPath('asset:somePkg/test/modPath', 'asset:somePkg/test/impPath'))
|
||||
.toEqual('impPath');
|
||||
expect(
|
||||
generator.getImportPath('asset:somePkg/lib/modPath', 'asset:somePkg/lib/dir2/impPath'))
|
||||
.toEqual('dir2/impPath');
|
||||
expect(
|
||||
generator.getImportPath('asset:somePkg/lib/dir1/modPath', 'asset:somePkg/lib/impPath'))
|
||||
.toEqual('../impPath');
|
||||
expect(generator.getImportPath('asset:somePkg/lib/dir1/modPath',
|
||||
'asset:somePkg/lib/dir2/impPath'))
|
||||
.toEqual('../dir2/impPath');
|
||||
});
|
||||
|
||||
it('should calculate absolute paths', () => {
|
||||
expect(
|
||||
generator.getImportPath('asset:somePkg/lib/modPath', 'asset:someOtherPkg/lib/impPath'))
|
||||
.toEqual('package:someOtherPkg/impPath');
|
||||
});
|
||||
|
||||
it('should not allow absolute imports of non lib modules', () => {
|
||||
expect(() => generator.getImportPath('asset:somePkg/lib/modPath',
|
||||
'asset:somePkg/test/impPath'))
|
||||
.toThrowError(
|
||||
`Can't import url asset:somePkg/test/impPath from asset:somePkg/lib/modPath`);
|
||||
});
|
||||
|
||||
it('should not allow non asset urls as base url', () => {
|
||||
expect(
|
||||
() => generator.getImportPath('http:somePkg/lib/modPath', 'asset:somePkg/test/impPath'))
|
||||
.toThrowError(`Url http:somePkg/lib/modPath is not a valid asset: url`);
|
||||
});
|
||||
|
||||
it('should allow non asset urls as import urls and pass them through', () => {
|
||||
expect(generator.getImportPath('asset:somePkg/lib/modPath', 'dart:html'))
|
||||
.toEqual('dart:html');
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
@ -13,6 +13,7 @@ import {isBlank} from '../../src/facade/lang';
|
||||
import {JavaScriptEmitter} from '@angular/compiler/src/output/js_emitter';
|
||||
import {CompileIdentifierMetadata} from '@angular/compiler/src/compile_metadata';
|
||||
import * as o from '@angular/compiler/src/output/output_ast';
|
||||
import {SimpleJsImportGenerator} from '../offline_compiler_util';
|
||||
|
||||
var someModuleUrl = 'asset:somePackage/lib/somePath';
|
||||
var anotherModuleUrl = 'asset:somePackage/lib/someOtherPath';
|
||||
@ -33,7 +34,7 @@ export function main() {
|
||||
var someVar: o.ReadVarExpr;
|
||||
|
||||
beforeEach(() => {
|
||||
emitter = new JavaScriptEmitter();
|
||||
emitter = new JavaScriptEmitter(new SimpleJsImportGenerator());
|
||||
someVar = o.variable('someVar');
|
||||
});
|
||||
|
||||
@ -111,9 +112,10 @@ export function main() {
|
||||
it('should support external identifiers', () => {
|
||||
expect(emitStmt(o.importExpr(sameModuleIdentifier).toStmt())).toEqual('someLocalId;');
|
||||
expect(emitStmt(o.importExpr(externalModuleIdentifier).toStmt()))
|
||||
.toEqual(
|
||||
[`var import0 = re` + `quire('./someOtherPath');`, `import0.someExternalId;`].join(
|
||||
'\n'));
|
||||
.toEqual([
|
||||
`var import0 = re` + `quire('somePackage/someOtherPath');`,
|
||||
`import0.someExternalId;`
|
||||
].join('\n'));
|
||||
});
|
||||
|
||||
it('should support operators', () => {
|
||||
|
@ -4,8 +4,10 @@ import {unimplemented} from '../../src/facade/exceptions';
|
||||
import {codegenExportsVars, codegenStmts} from './output_emitter_util';
|
||||
import {TypeScriptEmitter} from '@angular/compiler/src/output/ts_emitter';
|
||||
import {DartEmitter} from '@angular/compiler/src/output/dart_emitter';
|
||||
import {DartImportGenerator} from '@angular/compiler/src/output/dart_imports';
|
||||
import * as o from '@angular/compiler/src/output/output_ast';
|
||||
import {assetUrl} from '../../src/util';
|
||||
import {SimpleJsImportGenerator} from '../offline_compiler_util';
|
||||
|
||||
export function getExpressions(): any {
|
||||
return unimplemented();
|
||||
@ -13,7 +15,8 @@ export function getExpressions(): any {
|
||||
|
||||
// Generator
|
||||
export function emit() {
|
||||
var emitter = IS_DART ? new DartEmitter() : new TypeScriptEmitter();
|
||||
var emitter = IS_DART ? new DartEmitter(new DartImportGenerator()) :
|
||||
new TypeScriptEmitter(new SimpleJsImportGenerator());
|
||||
var emittedCode =
|
||||
emitter.emitStatements(assetUrl('compiler', 'output/output_emitter_codegen_typed', 'test'),
|
||||
codegenStmts, codegenExportsVars);
|
||||
|
@ -4,6 +4,7 @@ import {unimplemented} from '../../src/facade/exceptions';
|
||||
import {codegenExportsVars, codegenStmts} from './output_emitter_util';
|
||||
import {JavaScriptEmitter} from '@angular/compiler/src/output/js_emitter';
|
||||
import {assetUrl} from '../../src/util';
|
||||
import {SimpleJsImportGenerator} from '../offline_compiler_util';
|
||||
|
||||
export function getExpressions(): any {
|
||||
return unimplemented();
|
||||
@ -11,7 +12,7 @@ export function getExpressions(): any {
|
||||
|
||||
// Generator
|
||||
export function emit() {
|
||||
var emitter = new JavaScriptEmitter();
|
||||
var emitter = new JavaScriptEmitter(new SimpleJsImportGenerator());
|
||||
var emittedCode =
|
||||
emitter.emitStatements(assetUrl('compiler', 'output/output_emitter_codegen_untyped', 'test'),
|
||||
codegenStmts, codegenExportsVars);
|
||||
|
@ -15,7 +15,7 @@ export class ExternalClass {
|
||||
|
||||
var testDataIdentifier = new CompileIdentifierMetadata({
|
||||
name: 'ExternalClass',
|
||||
moduleUrl: assetUrl('compiler', 'output/output_emitter_util'),
|
||||
moduleUrl: `asset:@angular/lib/compiler/test/output/output_emitter_util`,
|
||||
runtime: ExternalClass
|
||||
});
|
||||
|
||||
|
@ -1,69 +0,0 @@
|
||||
import {
|
||||
beforeEach,
|
||||
ddescribe,
|
||||
describe,
|
||||
expect,
|
||||
iit,
|
||||
inject,
|
||||
it,
|
||||
xit,
|
||||
} from '@angular/core/testing/testing_internal';
|
||||
|
||||
import {getImportModulePath, ImportEnv} from '@angular/compiler/src/output/path_util';
|
||||
|
||||
export function main() {
|
||||
describe('PathUtils', () => {
|
||||
describe('getImportModulePath', () => {
|
||||
it('should calculate relative paths for JS and Dart', () => {
|
||||
expect(getImportModulePath('asset:somePkg/lib/modPath', 'asset:somePkg/lib/impPath',
|
||||
ImportEnv.JS))
|
||||
.toEqual('./impPath');
|
||||
expect(getImportModulePath('asset:somePkg/lib/modPath', 'asset:somePkg/lib/impPath',
|
||||
ImportEnv.Dart))
|
||||
.toEqual('impPath');
|
||||
});
|
||||
|
||||
it('should calculate relative paths for different constellations', () => {
|
||||
expect(getImportModulePath('asset:somePkg/test/modPath', 'asset:somePkg/test/impPath',
|
||||
ImportEnv.JS))
|
||||
.toEqual('./impPath');
|
||||
expect(getImportModulePath('asset:somePkg/lib/modPath', 'asset:somePkg/lib/dir2/impPath',
|
||||
ImportEnv.JS))
|
||||
.toEqual('./dir2/impPath');
|
||||
expect(getImportModulePath('asset:somePkg/lib/dir1/modPath', 'asset:somePkg/lib/impPath',
|
||||
ImportEnv.JS))
|
||||
.toEqual('../impPath');
|
||||
expect(getImportModulePath('asset:somePkg/lib/dir1/modPath',
|
||||
'asset:somePkg/lib/dir2/impPath', ImportEnv.JS))
|
||||
.toEqual('../dir2/impPath');
|
||||
});
|
||||
|
||||
it('should calculate absolute paths for JS and Dart', () => {
|
||||
expect(getImportModulePath('asset:somePkg/lib/modPath', 'asset:someOtherPkg/lib/impPath',
|
||||
ImportEnv.JS))
|
||||
.toEqual('someOtherPkg/impPath');
|
||||
expect(getImportModulePath('asset:somePkg/lib/modPath', 'asset:someOtherPkg/lib/impPath',
|
||||
ImportEnv.Dart))
|
||||
.toEqual('package:someOtherPkg/impPath');
|
||||
});
|
||||
|
||||
it('should not allow absolute imports of non lib modules', () => {
|
||||
expect(() => getImportModulePath('asset:somePkg/lib/modPath', 'asset:somePkg/test/impPath',
|
||||
ImportEnv.Dart))
|
||||
.toThrowError(
|
||||
`Can't import url asset:somePkg/test/impPath from asset:somePkg/lib/modPath`);
|
||||
});
|
||||
|
||||
it('should not allow non asset urls as base url', () => {
|
||||
expect(() => getImportModulePath('http:somePkg/lib/modPath', 'asset:somePkg/test/impPath',
|
||||
ImportEnv.Dart))
|
||||
.toThrowError(`Url http:somePkg/lib/modPath is not a valid asset: url`);
|
||||
});
|
||||
|
||||
it('should allow non asset urls as import urls and pass them through', () => {
|
||||
expect(getImportModulePath('asset:somePkg/lib/modPath', 'dart:html', ImportEnv.Dart))
|
||||
.toEqual('dart:html');
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
@ -13,6 +13,7 @@ import {isBlank} from '../../src/facade/lang';
|
||||
import {TypeScriptEmitter} from '@angular/compiler/src/output/ts_emitter';
|
||||
import {CompileIdentifierMetadata} from '@angular/compiler/src/compile_metadata';
|
||||
import * as o from '@angular/compiler/src/output/output_ast';
|
||||
import {SimpleJsImportGenerator} from '../offline_compiler_util';
|
||||
|
||||
var someModuleUrl = 'asset:somePackage/lib/somePath';
|
||||
var anotherModuleUrl = 'asset:somePackage/lib/someOtherPath';
|
||||
@ -33,7 +34,7 @@ export function main() {
|
||||
var someVar: o.ReadVarExpr;
|
||||
|
||||
beforeEach(() => {
|
||||
emitter = new TypeScriptEmitter();
|
||||
emitter = new TypeScriptEmitter(new SimpleJsImportGenerator());
|
||||
someVar = o.variable('someVar');
|
||||
});
|
||||
|
||||
@ -112,8 +113,10 @@ export function main() {
|
||||
it('should support external identifiers', () => {
|
||||
expect(emitStmt(o.importExpr(sameModuleIdentifier).toStmt())).toEqual('someLocalId;');
|
||||
expect(emitStmt(o.importExpr(externalModuleIdentifier).toStmt()))
|
||||
.toEqual([`import * as import0 from './someOtherPath';`, `import0.someExternalId;`].join(
|
||||
'\n'));
|
||||
.toEqual([
|
||||
`import * as import0 from 'somePackage/someOtherPath';`,
|
||||
`import0.someExternalId;`
|
||||
].join('\n'));
|
||||
});
|
||||
|
||||
it('should support operators', () => {
|
||||
@ -302,7 +305,7 @@ export function main() {
|
||||
.toEqual('var a:someLocalId = null;');
|
||||
expect(emitStmt(writeVarExpr.toDeclStmt(o.importType(externalModuleIdentifier))))
|
||||
.toEqual([
|
||||
`import * as import0 from './someOtherPath';`,
|
||||
`import * as import0 from 'somePackage/someOtherPath';`,
|
||||
`var a:import0.someExternalId = null;`
|
||||
].join('\n'));
|
||||
});
|
||||
|
Reference in New Issue
Block a user