refactor: dart
This commit is contained in:
parent
106db0aba8
commit
2dfc9c653b
|
@ -83,10 +83,7 @@ export class HashLocationStrategy extends LocationStrategy {
|
|||
var path = this._platformLocation.hash;
|
||||
if (!isPresent(path)) path = '#';
|
||||
|
||||
// Dart will complain if a call to substring is
|
||||
// executed with a position value that extends the
|
||||
// length of string.
|
||||
return (path.length > 0 ? path.substring(1) : path);
|
||||
return path.length > 0 ? path.substring(1) : path;
|
||||
}
|
||||
|
||||
prepareExternalUrl(internal: string): string {
|
||||
|
|
|
@ -215,8 +215,6 @@ class TemplatePreparseVisitor implements html.Visitor {
|
|||
this.styleUrls.push(preparsedElement.hrefAttr);
|
||||
break;
|
||||
default:
|
||||
// DDC reports this as error. See:
|
||||
// https://github.com/dart-lang/dev_compiler/issues/428
|
||||
break;
|
||||
}
|
||||
if (preparsedElement.nonBindable) {
|
||||
|
|
|
@ -201,7 +201,6 @@ export abstract class AbstractEmitterVisitor implements o.StatementVisitor, o.Ex
|
|||
name = this.getBuiltinMethodName(expr.builtin);
|
||||
if (isBlank(name)) {
|
||||
// some builtins just mean to skip the call.
|
||||
// e.g. `bind` in Dart.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ import {ListWrapper} from '../facade/collection';
|
|||
import {BaseException, unimplemented} from '../facade/exceptions';
|
||||
import {isPresent} from '../facade/lang';
|
||||
|
||||
import {debugOutputAstAsDart} from './dart_emitter';
|
||||
import * as o from './output_ast';
|
||||
import {debugOutputAstAsTypeScript} from './ts_emitter';
|
||||
|
||||
|
|
|
@ -12,9 +12,7 @@ import {RegExpMatcherWrapper, RegExpWrapper, StringWrapper, isBlank, isPresent}
|
|||
|
||||
const _EMPTY_ATTR_VALUE = '';
|
||||
|
||||
// TODO: Can't use `const` here as
|
||||
// in Dart this is not transpiled into `final` yet...
|
||||
var _SELECTOR_REGEXP = RegExpWrapper.create(
|
||||
const _SELECTOR_REGEXP = RegExpWrapper.create(
|
||||
'(\\:not\\()|' + //":not("
|
||||
'([-\\w]+)|' + // "tag"
|
||||
'(?:\\.([-\\w]+))|' + // ".class"
|
||||
|
|
|
@ -1,316 +0,0 @@
|
|||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {beforeEach, ddescribe, describe, expect, iit, inject, it, xit,} from '@angular/core/testing/testing_internal';
|
||||
|
||||
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';
|
||||
|
||||
var sameModuleIdentifier =
|
||||
new CompileIdentifierMetadata({name: 'someLocalId', moduleUrl: someModuleUrl});
|
||||
|
||||
var externalModuleIdentifier =
|
||||
new CompileIdentifierMetadata({name: 'someExternalId', moduleUrl: anotherModuleUrl});
|
||||
|
||||
export function main() {
|
||||
// Not supported features of our OutputAst in Dart:
|
||||
// - declaring what should be exported via a special statement like `export`.
|
||||
// Dart exports everything that has no `_` in its name.
|
||||
// - declaring private fields via a statement like `private`.
|
||||
// Dart exports everything that has no `_` in its name.
|
||||
// - return types for function expressions
|
||||
|
||||
describe('DartEmitter', () => {
|
||||
var emitter: DartEmitter;
|
||||
var someVar: o.ReadVarExpr;
|
||||
|
||||
beforeEach(() => {
|
||||
emitter = new DartEmitter(new DartImportGenerator());
|
||||
someVar = o.variable('someVar');
|
||||
});
|
||||
|
||||
function emitStmt(stmt: o.Statement, exportedVars: string[] = null): string {
|
||||
if (isBlank(exportedVars)) {
|
||||
exportedVars = [];
|
||||
}
|
||||
return emitter.emitStatements(someModuleUrl, [stmt], exportedVars);
|
||||
}
|
||||
|
||||
it('should declare variables', () => {
|
||||
expect(emitStmt(someVar.set(o.literal(1)).toDeclStmt())).toEqual(`var someVar = 1;`);
|
||||
expect(emitStmt(someVar.set(o.literal(1)).toDeclStmt(null, [o.StmtModifier.Final])))
|
||||
.toEqual(`final someVar = 1;`);
|
||||
expect(emitStmt(someVar
|
||||
.set(o.literal(
|
||||
1, new o.BuiltinType(o.BuiltinTypeName.Int, [o.TypeModifier.Const])))
|
||||
.toDeclStmt(null, [o.StmtModifier.Final])))
|
||||
.toEqual(`const int someVar = 1;`);
|
||||
expect(emitStmt(someVar.set(o.literal(1)).toDeclStmt(), ['someVar']))
|
||||
.toEqual(`var someVar = 1;`);
|
||||
expect(emitStmt(someVar.set(o.literal(1)).toDeclStmt(o.INT_TYPE)))
|
||||
.toEqual(`int someVar = 1;`);
|
||||
});
|
||||
|
||||
it('should read and write variables', () => {
|
||||
expect(emitStmt(someVar.toStmt())).toEqual(`someVar;`);
|
||||
expect(emitStmt(someVar.set(o.literal(1)).toStmt())).toEqual(`someVar = 1;`);
|
||||
expect(emitStmt(someVar.set(o.variable('someOtherVar').set(o.literal(1))).toStmt()))
|
||||
.toEqual(`someVar = (someOtherVar = 1);`);
|
||||
});
|
||||
|
||||
it('should read and write keys', () => {
|
||||
expect(emitStmt(o.variable('someMap').key(o.variable('someKey')).toStmt()))
|
||||
.toEqual(`someMap[someKey];`);
|
||||
expect(emitStmt(o.variable('someMap').key(o.variable('someKey')).set(o.literal(1)).toStmt()))
|
||||
.toEqual(`someMap[someKey] = 1;`);
|
||||
});
|
||||
|
||||
it('should read and write properties', () => {
|
||||
expect(emitStmt(o.variable('someObj').prop('someProp').toStmt()))
|
||||
.toEqual(`someObj.someProp;`);
|
||||
expect(emitStmt(o.variable('someObj').prop('someProp').set(o.literal(1)).toStmt()))
|
||||
.toEqual(`someObj.someProp = 1;`);
|
||||
});
|
||||
|
||||
it('should invoke functions and methods and constructors', () => {
|
||||
expect(emitStmt(o.variable('someFn').callFn([o.literal(1)]).toStmt())).toEqual('someFn(1);');
|
||||
expect(emitStmt(o.variable('someObj').callMethod('someMethod', [o.literal(1)]).toStmt()))
|
||||
.toEqual('someObj.someMethod(1);');
|
||||
expect(emitStmt(o.variable('SomeClass').instantiate([o.literal(1)]).toStmt()))
|
||||
.toEqual('new SomeClass(1);');
|
||||
});
|
||||
|
||||
it('should support builtin methods', () => {
|
||||
expect(emitStmt(o.variable('arr1')
|
||||
.callMethod(o.BuiltinMethod.ConcatArray, [o.variable('arr2')])
|
||||
.toStmt()))
|
||||
.toEqual('arr1..addAll(arr2);');
|
||||
|
||||
expect(emitStmt(o.variable('observable')
|
||||
.callMethod(o.BuiltinMethod.SubscribeObservable, [o.variable('listener')])
|
||||
.toStmt()))
|
||||
.toEqual('observable.listen(listener);');
|
||||
|
||||
expect(
|
||||
emitStmt(
|
||||
o.variable('fn').callMethod(o.BuiltinMethod.bind, [o.variable('someObj')]).toStmt()))
|
||||
.toEqual('fn;');
|
||||
});
|
||||
|
||||
it('should support literals', () => {
|
||||
expect(emitStmt(o.literal(0).toStmt())).toEqual('0;');
|
||||
expect(emitStmt(o.literal(true).toStmt())).toEqual('true;');
|
||||
expect(emitStmt(o.literal('someStr').toStmt())).toEqual(`'someStr';`);
|
||||
expect(emitStmt(o.literal('$a').toStmt())).toEqual(`'\\$a';`);
|
||||
expect(emitStmt(o.literalArr([o.literal(1)]).toStmt())).toEqual(`[1];`);
|
||||
expect(emitStmt(o.literalMap([['someKey', o.literal(1)]]).toStmt()))
|
||||
.toEqual(`{'someKey': 1};`);
|
||||
expect(emitStmt(
|
||||
o.literalMap([['someKey', o.literal(1)]], new o.MapType(o.NUMBER_TYPE)).toStmt()))
|
||||
.toEqual(`<String, num>{'someKey': 1};`);
|
||||
});
|
||||
|
||||
it('should support external identifiers', () => {
|
||||
expect(emitStmt(o.importExpr(sameModuleIdentifier).toStmt())).toEqual('someLocalId;');
|
||||
expect(emitStmt(o.importExpr(externalModuleIdentifier).toStmt())).toEqual([
|
||||
`import 'someOtherPath' as import0;`, `import0.someExternalId;`
|
||||
].join('\n'));
|
||||
});
|
||||
|
||||
it('should support operators', () => {
|
||||
var lhs = o.variable('lhs');
|
||||
var rhs = o.variable('rhs');
|
||||
expect(emitStmt(someVar.cast(o.INT_TYPE).toStmt())).toEqual('(someVar as int);');
|
||||
expect(emitStmt(o.not(someVar).toStmt())).toEqual('!someVar;');
|
||||
expect(
|
||||
emitStmt(someVar.conditional(o.variable('trueCase'), o.variable('falseCase')).toStmt()))
|
||||
.toEqual('(someVar? trueCase: falseCase);');
|
||||
|
||||
expect(emitStmt(lhs.equals(rhs).toStmt())).toEqual('(lhs == rhs);');
|
||||
expect(emitStmt(lhs.notEquals(rhs).toStmt())).toEqual('(lhs != rhs);');
|
||||
expect(emitStmt(lhs.identical(rhs).toStmt())).toEqual('identical(lhs, rhs);');
|
||||
expect(emitStmt(lhs.notIdentical(rhs).toStmt())).toEqual('!identical(lhs, rhs);');
|
||||
expect(emitStmt(lhs.minus(rhs).toStmt())).toEqual('(lhs - rhs);');
|
||||
expect(emitStmt(lhs.plus(rhs).toStmt())).toEqual('(lhs + rhs);');
|
||||
expect(emitStmt(lhs.divide(rhs).toStmt())).toEqual('(lhs / rhs);');
|
||||
expect(emitStmt(lhs.multiply(rhs).toStmt())).toEqual('(lhs * rhs);');
|
||||
expect(emitStmt(lhs.modulo(rhs).toStmt())).toEqual('(lhs % rhs);');
|
||||
expect(emitStmt(lhs.and(rhs).toStmt())).toEqual('(lhs && rhs);');
|
||||
expect(emitStmt(lhs.or(rhs).toStmt())).toEqual('(lhs || rhs);');
|
||||
expect(emitStmt(lhs.lower(rhs).toStmt())).toEqual('(lhs < rhs);');
|
||||
expect(emitStmt(lhs.lowerEquals(rhs).toStmt())).toEqual('(lhs <= rhs);');
|
||||
expect(emitStmt(lhs.bigger(rhs).toStmt())).toEqual('(lhs > rhs);');
|
||||
expect(emitStmt(lhs.biggerEquals(rhs).toStmt())).toEqual('(lhs >= rhs);');
|
||||
});
|
||||
|
||||
it('should support function expressions', () => {
|
||||
expect(emitStmt(o.fn([], []).toStmt())).toEqual(['() {', '};'].join('\n'));
|
||||
expect(emitStmt(o.fn([new o.FnParam('param1', o.INT_TYPE)], []).toStmt())).toEqual([
|
||||
'(int param1) {', '};'
|
||||
].join('\n'));
|
||||
});
|
||||
|
||||
it('should support function statements', () => {
|
||||
expect(emitStmt(new o.DeclareFunctionStmt('someFn', [], [
|
||||
]))).toEqual(['void someFn() {', '}'].join('\n'));
|
||||
expect(emitStmt(new o.DeclareFunctionStmt(
|
||||
'someFn', [], [new o.ReturnStatement(o.literal(1))], o.INT_TYPE)))
|
||||
.toEqual(['int someFn() {', ' return 1;', '}'].join('\n'));
|
||||
expect(emitStmt(new o.DeclareFunctionStmt('someFn', [new o.FnParam('param1', o.INT_TYPE)], [
|
||||
]))).toEqual(['void someFn(int param1) {', '}'].join('\n'));
|
||||
});
|
||||
|
||||
it('should support comments', () => {
|
||||
expect(emitStmt(new o.CommentStmt('a\nb'))).toEqual(['// a', '// b'].join('\n'));
|
||||
});
|
||||
|
||||
it('should support if stmt', () => {
|
||||
var trueCase = o.variable('trueCase').callFn([]).toStmt();
|
||||
var falseCase = o.variable('falseCase').callFn([]).toStmt();
|
||||
expect(emitStmt(new o.IfStmt(o.variable('cond'), [trueCase]))).toEqual([
|
||||
'if (cond) { trueCase(); }'
|
||||
].join('\n'));
|
||||
expect(emitStmt(new o.IfStmt(o.variable('cond'), [trueCase], [falseCase]))).toEqual([
|
||||
'if (cond) {', ' trueCase();', '} else {', ' falseCase();', '}'
|
||||
].join('\n'));
|
||||
});
|
||||
|
||||
it('should support try/catch', () => {
|
||||
var bodyStmt = o.variable('body').callFn([]).toStmt();
|
||||
var catchStmt = o.variable('catchFn').callFn([o.CATCH_ERROR_VAR, o.CATCH_STACK_VAR]).toStmt();
|
||||
expect(emitStmt(new o.TryCatchStmt([bodyStmt], [catchStmt]))).toEqual([
|
||||
'try {', ' body();', '} catch (error, stack) {', ' catchFn(error,stack);', '}'
|
||||
].join('\n'));
|
||||
});
|
||||
|
||||
it('should support support throwing',
|
||||
() => { expect(emitStmt(new o.ThrowStmt(someVar))).toEqual('throw someVar;'); });
|
||||
|
||||
describe('classes', () => {
|
||||
var callSomeMethod: o.Statement;
|
||||
|
||||
beforeEach(() => { callSomeMethod = o.THIS_EXPR.callMethod('someMethod', []).toStmt(); });
|
||||
|
||||
it('should support declaring classes', () => {
|
||||
expect(emitStmt(new o.ClassStmt('SomeClass', null, [], [], null, [
|
||||
]))).toEqual(['class SomeClass {', '}'].join('\n'));
|
||||
expect(emitStmt(new o.ClassStmt('SomeClass', o.variable('SomeSuperClass'), [], [], null, [
|
||||
]))).toEqual(['class SomeClass extends SomeSuperClass {', '}'].join('\n'));
|
||||
});
|
||||
|
||||
it('should support declaring constructors', () => {
|
||||
var superCall = o.SUPER_EXPR.callFn([o.variable('someParam')]).toStmt();
|
||||
expect(emitStmt(
|
||||
new o.ClassStmt('SomeClass', null, [], [], new o.ClassMethod(null, [], []), [])))
|
||||
.toEqual(['class SomeClass {', ' SomeClass() {', ' }', '}'].join('\n'));
|
||||
expect(emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null, [], [],
|
||||
new o.ClassMethod(null, [new o.FnParam('someParam', o.INT_TYPE)], []), [])))
|
||||
.toEqual(['class SomeClass {', ' SomeClass(int someParam) {', ' }', '}'].join('\n'));
|
||||
expect(emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null, [], [], new o.ClassMethod(null, [], [superCall]), [])))
|
||||
.toEqual(
|
||||
['class SomeClass {', ' SomeClass(): super(someParam) {', ' }', '}'].join('\n'));
|
||||
expect(emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null, [], [], new o.ClassMethod(null, [], [callSomeMethod]), [])))
|
||||
.toEqual([
|
||||
'class SomeClass {', ' SomeClass() {', ' this.someMethod();', ' }', '}'
|
||||
].join('\n'));
|
||||
});
|
||||
|
||||
it('should support declaring fields', () => {
|
||||
expect(emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null, [new o.ClassField('someField')], [], null, [])))
|
||||
.toEqual(['class SomeClass {', ' var someField;', '}'].join('\n'));
|
||||
expect(emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null, [new o.ClassField('someField', o.INT_TYPE)], [], null, [])))
|
||||
.toEqual(['class SomeClass {', ' int someField;', '}'].join('\n'));
|
||||
expect(
|
||||
emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null,
|
||||
[new o.ClassField('someField', o.INT_TYPE, [o.StmtModifier.Final])], [], null, [])))
|
||||
.toEqual(['class SomeClass {', ' final int someField;', '}'].join('\n'));
|
||||
});
|
||||
|
||||
it('should support declaring getters', () => {
|
||||
expect(emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null, [], [new o.ClassGetter('someGetter', [])], null, [])))
|
||||
.toEqual(['class SomeClass {', ' get someGetter {', ' }', '}'].join('\n'));
|
||||
expect(emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null, [], [new o.ClassGetter('someGetter', [], o.INT_TYPE)], null,
|
||||
[])))
|
||||
.toEqual(['class SomeClass {', ' int get someGetter {', ' }', '}'].join('\n'));
|
||||
expect(emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null, [], [new o.ClassGetter('someGetter', [callSomeMethod])], null,
|
||||
[])))
|
||||
.toEqual([
|
||||
'class SomeClass {', ' get someGetter {', ' this.someMethod();', ' }', '}'
|
||||
].join('\n'));
|
||||
});
|
||||
|
||||
it('should support methods', () => {
|
||||
expect(emitStmt(new o.ClassStmt('SomeClass', null, [], [], null, [
|
||||
new o.ClassMethod('someMethod', [], [])
|
||||
]))).toEqual(['class SomeClass {', ' void someMethod() {', ' }', '}'].join('\n'));
|
||||
expect(emitStmt(new o.ClassStmt('SomeClass', null, [], [], null, [
|
||||
new o.ClassMethod('someMethod', [], [], o.INT_TYPE)
|
||||
]))).toEqual(['class SomeClass {', ' int someMethod() {', ' }', '}'].join('\n'));
|
||||
expect(
|
||||
emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null, [], [], null,
|
||||
[new o.ClassMethod('someMethod', [new o.FnParam('someParam', o.INT_TYPE)], [])])))
|
||||
.toEqual(
|
||||
['class SomeClass {', ' void someMethod(int someParam) {', ' }', '}'].join('\n'));
|
||||
expect(emitStmt(new o.ClassStmt(
|
||||
'SomeClass', null, [], [], null,
|
||||
[new o.ClassMethod('someMethod', [], [callSomeMethod])])))
|
||||
.toEqual([
|
||||
'class SomeClass {', ' void someMethod() {', ' this.someMethod();', ' }', '}'
|
||||
].join('\n'));
|
||||
});
|
||||
});
|
||||
|
||||
it('should support builtin types', () => {
|
||||
var writeVarExpr = o.variable('a').set(o.NULL_EXPR);
|
||||
expect(emitStmt(writeVarExpr.toDeclStmt(o.DYNAMIC_TYPE))).toEqual('dynamic a = null;');
|
||||
expect(emitStmt(writeVarExpr.toDeclStmt(o.BOOL_TYPE))).toEqual('bool a = null;');
|
||||
expect(emitStmt(writeVarExpr.toDeclStmt(o.INT_TYPE))).toEqual('int a = null;');
|
||||
expect(emitStmt(writeVarExpr.toDeclStmt(o.NUMBER_TYPE))).toEqual('num a = null;');
|
||||
expect(emitStmt(writeVarExpr.toDeclStmt(o.STRING_TYPE))).toEqual('String a = null;');
|
||||
expect(emitStmt(writeVarExpr.toDeclStmt(o.FUNCTION_TYPE))).toEqual('Function a = null;');
|
||||
});
|
||||
|
||||
it('should support external types', () => {
|
||||
var writeVarExpr = o.variable('a').set(o.NULL_EXPR);
|
||||
expect(emitStmt(writeVarExpr.toDeclStmt(o.importType(sameModuleIdentifier))))
|
||||
.toEqual('someLocalId a = null;');
|
||||
expect(emitStmt(writeVarExpr.toDeclStmt(o.importType(externalModuleIdentifier)))).toEqual([
|
||||
`import 'someOtherPath' as import0;`, `import0.someExternalId a = null;`
|
||||
].join('\n'));
|
||||
});
|
||||
|
||||
it('should support combined types', () => {
|
||||
var writeVarExpr = o.variable('a').set(o.NULL_EXPR);
|
||||
expect(emitStmt(writeVarExpr.toDeclStmt(new o.ArrayType(null))))
|
||||
.toEqual('List<dynamic> a = null;');
|
||||
expect(emitStmt(writeVarExpr.toDeclStmt(new o.ArrayType(o.INT_TYPE))))
|
||||
.toEqual('List<int> a = null;');
|
||||
|
||||
expect(emitStmt(writeVarExpr.toDeclStmt(new o.MapType(null))))
|
||||
.toEqual('Map<String, dynamic> a = null;');
|
||||
expect(emitStmt(writeVarExpr.toDeclStmt(new o.MapType(o.INT_TYPE))))
|
||||
.toEqual('Map<String, int> a = null;');
|
||||
});
|
||||
});
|
||||
}
|
|
@ -1,64 +0,0 @@
|
|||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
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');
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
|
@ -7,8 +7,6 @@
|
|||
*/
|
||||
|
||||
// ATTENTION: This file will be overwritten with generated code by main()
|
||||
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 {TypeScriptEmitter} from '@angular/compiler/src/output/ts_emitter';
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ export function main() {
|
|||
// Our generator only works on node.js
|
||||
outputDefs.push({'getExpressions': () => typed.getExpressions, 'name': 'typed'});
|
||||
} else {
|
||||
// Our generator only works on node.js and Dart...
|
||||
// Our generator only works on node.js
|
||||
if (!getDOM().supportsDOMEvents()) {
|
||||
outputDefs.push({'getExpressions': () => untyped.getExpressions, 'name': 'untyped'});
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ var externalModuleIdentifier =
|
|||
new CompileIdentifierMetadata({name: 'someExternalId', moduleUrl: anotherModuleUrl});
|
||||
|
||||
export function main() {
|
||||
// Note supported features of our OutputAstin TS:
|
||||
// Note supported features of our OutputAsti n TS:
|
||||
// - real `const` like in Dart
|
||||
// - final fields
|
||||
|
||||
|
|
|
@ -109,7 +109,6 @@ export function main() {
|
|||
});
|
||||
}
|
||||
|
||||
/// The real thing behaves differently between Dart and JS for package URIs.
|
||||
class FakeUrlResolver extends UrlResolver {
|
||||
constructor() { super(); }
|
||||
|
||||
|
|
|
@ -9,14 +9,9 @@
|
|||
import {Injectable} from './di/decorators';
|
||||
import {print, warn} from './facade/lang';
|
||||
|
||||
|
||||
// Note: Need to rename warn as in Dart
|
||||
// class members and imports can't use the same name.
|
||||
let _warnImpl = warn;
|
||||
|
||||
@Injectable()
|
||||
export class Console {
|
||||
log(message: string): void { print(message); }
|
||||
// Note: for reporting errors use `DOM.logError()` as it is platform specific
|
||||
warn(message: string): void { _warnImpl(message); }
|
||||
warn(message: string): void { warn(message); }
|
||||
}
|
||||
|
|
|
@ -884,8 +884,6 @@ export class ComponentMetadata extends DirectiveMetadata implements ComponentMet
|
|||
* In CommonJS, this can always be set to `module.id`, similarly SystemJS exposes `__moduleName`
|
||||
* variable within each module.
|
||||
*
|
||||
* In Dart, this can be determined automatically and does not need to be set.
|
||||
|
||||
*
|
||||
* ## Simple Example
|
||||
*
|
||||
|
|
|
@ -19,8 +19,6 @@ function _reflector(): Reflector {
|
|||
return reflector;
|
||||
}
|
||||
|
||||
var __unused: Type; // prevent missing use Dart warning.
|
||||
|
||||
const _CORE_PLATFORM_PROVIDERS: Array<any|Type|Provider|any[]> = [
|
||||
PlatformRef_, {provide: PlatformRef, useExisting: PlatformRef_},
|
||||
{provide: Reflector, useFactory: _reflector, deps: []},
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
# API Examples
|
||||
|
||||
This folder contains small example apps that get in-lined into our API docs.
|
||||
These examples are written with idiomatic TypeScript, and are not transpiled to Dart.
|
||||
Each example contains tests for application behavior (as opposed to testing Angular's
|
||||
behavior) just like an Angular application developer would write.
|
||||
|
|
|
@ -46,7 +46,7 @@ export abstract class MessageBus implements MessageBusSource, MessageBusSink {
|
|||
|
||||
/**
|
||||
* Returns an {@link EventEmitter} for the given channel
|
||||
* To publish methods to that channel just call next (or add in dart) on the returned emitter
|
||||
* To publish methods to that channel just call next on the returned emitter
|
||||
*/
|
||||
abstract to(channel: string): EventEmitter<any>;
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ export interface MessageBusSink {
|
|||
|
||||
/**
|
||||
* Returns an {@link EventEmitter} for the given channel
|
||||
* To publish methods to that channel just call next (or add in dart) on the returned emitter
|
||||
* To publish methods to that channel just call next on the returned emitter
|
||||
*/
|
||||
to(channel: string): EventEmitter<any>;
|
||||
}
|
||||
|
|
|
@ -163,7 +163,6 @@ export function main() {
|
|||
if (getDOM().supportsDOMEvents()) {
|
||||
it('should forward the error to promise when bootstrap fails',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
// Skip for dart since it causes a confusing error message in console when test passes.
|
||||
var logger = new _ArrayLogger();
|
||||
var exceptionHandler = new ExceptionHandler(logger, false);
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ import {createConnectedMessageBus} from './message_bus_util';
|
|||
|
||||
export function main() {
|
||||
/**
|
||||
* Tests the PostMessageBus in TypeScript and the IsolateMessageBus in Dart
|
||||
* Tests the PostMessageBus
|
||||
*/
|
||||
describe('MessageBus', () => {
|
||||
var bus: MessageBus;
|
||||
|
|
Loading…
Reference in New Issue