diff --git a/modules/@angular/compiler/test/output/js_emitter_spec.ts b/modules/@angular/compiler/test/output/js_emitter_spec.ts index f85c21d0d0..16f21d6994 100644 --- a/modules/@angular/compiler/test/output/js_emitter_spec.ts +++ b/modules/@angular/compiler/test/output/js_emitter_spec.ts @@ -9,19 +9,22 @@ import {CompileIdentifierMetadata} from '@angular/compiler/src/compile_metadata'; import {JavaScriptEmitter} from '@angular/compiler/src/output/js_emitter'; import * as o from '@angular/compiler/src/output/output_ast'; -import {beforeEach, describe, expect, it} from '@angular/core/testing/testing_internal'; - -import {SimpleJsImportGenerator} from './output_emitter_util'; +import {ImportResolver} from '@angular/compiler/src/output/path_util'; const someModuleUrl = 'somePackage/somePath'; const anotherModuleUrl = 'somePackage/someOtherPath'; const sameModuleIdentifier = new CompileIdentifierMetadata({name: 'someLocalId', moduleUrl: someModuleUrl}); - const externalModuleIdentifier = new CompileIdentifierMetadata({name: 'someExternalId', moduleUrl: anotherModuleUrl}); +class SimpleJsImportGenerator implements ImportResolver { + fileNameToModuleName(importedUrlStr: string, moduleUrlStr: string): string { + return importedUrlStr; + } +} + export function main() { // Note supported features of our OutputAstin JavaScript / ES5: // - types diff --git a/modules/@angular/compiler/test/output/output_emitter_codegen_typed.ts b/modules/@angular/compiler/test/output/output_emitter_codegen_typed.ts deleted file mode 100644 index 99351a4ca3..0000000000 --- a/modules/@angular/compiler/test/output/output_emitter_codegen_typed.ts +++ /dev/null @@ -1,38 +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 - */ - -// ATTENTION: This file will be overwritten with generated code by main() - -import {TypeScriptEmitter} from '@angular/compiler/src/output/ts_emitter'; - -import {print} from '../../src/facade/lang'; -import {assetUrl} from '../../src/identifiers'; - -function unimplemented(): any { - throw new Error('unimplemented'); -} - -import {SimpleJsImportGenerator, codegenExportsVars, codegenStmts} from './output_emitter_util'; - -export function getExpressions(): any { - return unimplemented(); -} - -// Generator -export function emit() { - const emitter = new TypeScriptEmitter(new SimpleJsImportGenerator()); - const emittedCode = emitter.emitStatements( - assetUrl('compiler', 'output/output_emitter_codegen_typed', 'test'), codegenStmts, - codegenExportsVars); - return emittedCode; -} - -export function main(args: string[]) { - const emittedCode = emit(); - print(emittedCode); -} diff --git a/modules/@angular/compiler/test/output/output_emitter_codegen_untyped.ts b/modules/@angular/compiler/test/output/output_emitter_codegen_untyped.ts deleted file mode 100644 index 093354168d..0000000000 --- a/modules/@angular/compiler/test/output/output_emitter_codegen_untyped.ts +++ /dev/null @@ -1,34 +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 - */ - -// ATTENTION: This file will be overwritten with generated code by main() -import {JavaScriptEmitter} from '@angular/compiler/src/output/js_emitter'; - -import {print} from '../../src/facade/lang'; -import {assetUrl} from '../../src/identifiers'; - -import {SimpleJsImportGenerator, codegenExportsVars, codegenStmts} from './output_emitter_util'; - -export function getExpressions(): any { - throw new Error('unimplemented'); -} - -// Generator -export function emit() { - const emitter = new JavaScriptEmitter(new SimpleJsImportGenerator()); - const emittedCode = emitter.emitStatements( - assetUrl('compiler', 'output/output_emitter_codegen_untyped', 'test'), codegenStmts, - codegenExportsVars); - return emittedCode; -} - -export function main(args: string[]) { - const emittedCode = emit(); - // debug: console.error(emittedCode); - print(emittedCode); -} diff --git a/modules/@angular/compiler/test/output/output_emitter_spec.ts b/modules/@angular/compiler/test/output/output_emitter_spec.ts deleted file mode 100644 index 1ce74929ec..0000000000 --- a/modules/@angular/compiler/test/output/output_emitter_spec.ts +++ /dev/null @@ -1,197 +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 {interpretStatements} from '@angular/compiler/src/output/output_interpreter'; -import {jitStatements} from '@angular/compiler/src/output/output_jit'; -import {EventEmitter} from '@angular/core'; -import {ViewType} from '@angular/core/src/linker/view_type'; -import {beforeEach, describe, it} from '@angular/core/testing/testing_internal'; -import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; -import {browserDetection} from '@angular/platform-browser/testing/browser_util'; -import {expect} from '@angular/platform-browser/testing/matchers'; - -import * as typed from './output_emitter_codegen_typed'; -import * as untyped from './output_emitter_codegen_untyped'; -import {ExternalClass, codegenStmts} from './output_emitter_util'; - -export function main() { - const outputDefs: any[] /** TODO #9100 */ = []; - outputDefs.push({ - 'getExpressions': () => interpretStatements(codegenStmts, 'getExpressions'), - 'name': 'interpreted' - }); - - if (!getDOM().supportsDOMEvents()) { - // Our generator only works on node.js - outputDefs.push({'getExpressions': () => typed.getExpressions, 'name': 'typed'}); - } else { - // Our generator only works on node.js - if (!getDOM().supportsDOMEvents()) { - outputDefs.push({'getExpressions': () => untyped.getExpressions, 'name': 'untyped'}); - } - outputDefs.push({ - 'getExpressions': () => jitStatements('output_emitter_spec', codegenStmts, 'getExpressions'), - 'name': 'jit' - }); - } - - describe('output emitter', () => { - outputDefs.forEach((outputDef) => { - describe(`${outputDef['name']}`, () => { - let expressions: {[k: string]: any}; - beforeEach(() => { expressions = outputDef['getExpressions']()(); }); - - it('should support literals', () => { - expect(expressions['stringLiteral']).toEqual('Hello World!'); - expect(expressions['intLiteral']).toEqual(42); - expect(expressions['boolLiteral']).toEqual(true); - expect(expressions['arrayLiteral']).toEqual([0]); - expect(expressions['mapLiteral']).toEqual({'key0': 0}); - }); - - it('should support reading vars/keys/props', () => { - expect(expressions['readVar']).toEqual('someValue'); - expect(expressions['readKey']).toEqual('someValue'); - expect(expressions['readPropExternalInstance']).toEqual('someValue'); - expect(expressions['readPropDynamicInstance']).toEqual('dynamicValue'); - expect(expressions['readGetterDynamicInstance']) - .toEqual({'data': 'someValue', 'dynamicProp': 'dynamicValue'}); - }); - - it('should support writing to vars / keys / props', () => { - expect(expressions['changedVar']).toEqual('changedValue'); - expect(expressions['changedKey']).toEqual('changedValue'); - expect(expressions['changedPropExternalInstance']).toEqual('changedValue'); - expect(expressions['changedPropDynamicInstance']).toEqual('changedValue'); - }); - - it('should support declaring functions with parameters and return', () => { - expect(expressions['fn']('someParam')).toEqual({'param': 'someParam'}); - expect(expressions['closureInDynamicInstance']('someParam')) - .toEqual({'param': 'someParam', 'data': 'someValue', 'dynamicProp': 'dynamicValue'}); - }); - - it('should support invoking functions and methods', () => { - expect(expressions['invokeFn']).toEqual({'param': 'someParam'}); - expect(expressions['concatedArray']).toEqual([0, 1]); - expect(expressions['invokeMethodExternalInstance']) - .toEqual({'data': 'someValue', 'param': 'someParam'}); - expect(expressions['invokeMethodExternalInstanceViaBind']) - .toEqual({'data': 'someValue', 'param': 'someParam'}); - expect(expressions['invokeMethodDynamicInstance']) - .toEqual({'data': 'someValue', 'dynamicProp': 'dynamicValue', 'param': 'someParam'}); - expect(expressions['invokeMethodDynamicInstanceViaBind']) - .toEqual({'data': 'someValue', 'dynamicProp': 'dynamicValue', 'param': 'someParam'}); - }); - - it('should support conditionals', () => { - expect(expressions['conditionalTrue']).toEqual('true'); - expect(expressions['conditionalFalse']).toEqual('false'); - }); - - it('should support not', () => { expect(expressions['not']).toEqual(true); }); - - it('should support reading external identifiers', () => { - expect(expressions['externalTestIdentifier']).toBe(ExternalClass); - expect(expressions['externalSrcIdentifier']).toBe(EventEmitter); - expect(expressions['externalEnumIdentifier']).toBe(ViewType.HOST); - }); - - it('should support instantiating classes', () => { - expect(expressions['externalInstance']).toBeAnInstanceOf(ExternalClass); - // Note: toBeAnInstanceOf does not check super classes in Dart... - expect(expressions['dynamicInstance'] instanceof ExternalClass).toBe(true); - }); - - describe('operators', () => { - let ops: {[k: string]: Function}; - let aObj: any; - let bObj: any; - - beforeEach(() => { - ops = expressions['operators']; - aObj = {}; - bObj = {}; - }); - - it('should support ==', () => { - expect(ops['=='](aObj, aObj)).toBe(true); - expect(ops['=='](aObj, bObj)).toBe(false); - expect(ops['=='](1, 1)).toBe(true); - expect(ops['=='](0, 1)).toBe(false); - expect(ops['==']('a', 'a')).toBe(true); - expect(ops['==']('a', 'b')).toBe(false); - }); - it('should support !=', () => { - expect(ops['!='](aObj, aObj)).toBe(false); - expect(ops['!='](aObj, bObj)).toBe(true); - expect(ops['!='](1, 1)).toBe(false); - expect(ops['!='](0, 1)).toBe(true); - expect(ops['!=']('a', 'a')).toBe(false); - expect(ops['!=']('a', 'b')).toBe(true); - }); - it('should support ===', () => { - expect(ops['==='](aObj, aObj)).toBe(true); - expect(ops['==='](aObj, bObj)).toBe(false); - expect(ops['==='](1, 1)).toBe(true); - expect(ops['==='](0, 1)).toBe(false); - }); - it('should support !==', () => { - expect(ops['!=='](aObj, aObj)).toBe(false); - expect(ops['!=='](aObj, bObj)).toBe(true); - expect(ops['!=='](1, 1)).toBe(false); - expect(ops['!=='](0, 1)).toBe(true); - }); - it('should support -', () => { expect(ops['-'](3, 2)).toEqual(1); }); - it('should support +', () => { expect(ops['+'](1, 2)).toEqual(3); }); - it('should support /', () => { expect(ops['/'](6, 2)).toEqual(3); }); - it('should support *', () => { expect(ops['*'](2, 3)).toEqual(6); }); - it('should support %', () => { expect(ops['%'](3, 2)).toEqual(1); }); - it('should support &&', () => { - expect(ops['&&'](true, true)).toBe(true); - expect(ops['&&'](true, false)).toBe(false); - }); - it('should support ||', () => { - expect(ops['||'](true, false)).toBe(true); - expect(ops['||'](false, false)).toBe(false); - }); - it('should support <', () => { - expect(ops['<'](1, 2)).toBe(true); - expect(ops['<'](1, 1)).toBe(false); - }); - it('should support <=', () => { - expect(ops['<='](1, 2)).toBe(true); - expect(ops['<='](1, 1)).toBe(true); - }); - it('should support >', () => { - expect(ops['>'](2, 1)).toBe(true); - expect(ops['>'](1, 1)).toBe(false); - }); - it('should support >=', () => { - expect(ops['>='](2, 1)).toBe(true); - expect(ops['>='](1, 1)).toBe(true); - }); - }); - - it('should support throwing errors', - () => { expect(expressions['throwError']).toThrowError('someError'); }); - - it('should support catching errors', () => { - function someOperation() { throw new Error('Boom!'); } - - const errorAndStack = expressions['catchError'](someOperation); - expect(errorAndStack[0].message).toEqual('Boom!'); - // Somehow we don't get stacktraces on ios7... - if (!browserDetection.isIOS7 && !browserDetection.isIE) { - expect(errorAndStack[1].toString()).toContain('someOperation'); - } - }); - }); - }); - }); -} diff --git a/modules/@angular/compiler/test/output/ts_emitter_spec.ts b/modules/@angular/compiler/test/output/ts_emitter_spec.ts index 5f221eb927..51986ab5e0 100644 --- a/modules/@angular/compiler/test/output/ts_emitter_spec.ts +++ b/modules/@angular/compiler/test/output/ts_emitter_spec.ts @@ -8,11 +8,10 @@ import {CompileIdentifierMetadata} from '@angular/compiler/src/compile_metadata'; import * as o from '@angular/compiler/src/output/output_ast'; +import {ImportResolver} from '@angular/compiler/src/output/path_util'; import {TypeScriptEmitter} from '@angular/compiler/src/output/ts_emitter'; import {beforeEach, describe, expect, it} from '@angular/core/testing/testing_internal'; -import {SimpleJsImportGenerator} from './output_emitter_util'; - const someModuleUrl = 'somePackage/somePath'; const anotherModuleUrl = 'somePackage/someOtherPath'; @@ -22,6 +21,12 @@ const sameModuleIdentifier = const externalModuleIdentifier = new CompileIdentifierMetadata({name: 'someExternalId', moduleUrl: anotherModuleUrl}); +class SimpleJsImportGenerator implements ImportResolver { + fileNameToModuleName(importedUrlStr: string, moduleUrlStr: string): string { + return importedUrlStr; + } +} + export function main() { // Note supported features of our OutputAsti n TS: // - real `const` like in Dart diff --git a/tools/cjs-jasmine/tsconfig-output_emitter_codegen.json b/tools/cjs-jasmine/tsconfig-output_emitter_codegen.json deleted file mode 100644 index b3a16d2314..0000000000 --- a/tools/cjs-jasmine/tsconfig-output_emitter_codegen.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "compilerOptions": { - "baseUrl": ".", - "declaration": true, - "emitDecoratorMetadata": true, - "experimentalDecorators": true, - "module": "commonjs", - "moduleResolution": "node", - "outDir": "../../dist/all/@angular", - "paths": { - "@angular/core": ["../../dist/all/@angular/core/index"], - "@angular/core/*": ["../../dist/all/@angular/core/*"], - "@angular/compiler/*": ["../../dist/all/@angular/compiler/*"] - }, - "rootDir": "../../dist/all/@angular", - "sourceMap": true, - "sourceRoot": ".", - "lib": ["es6", "dom"], - "target": "es5" - }, - "files": [ - "../../node_modules/@types/node/index.d.ts", - "../../dist/all/@angular/compiler/test/output/output_emitter_codegen_typed.ts", - "../../dist/all/@angular/compiler/test/output/output_emitter_codegen_untyped.ts" - ] -} diff --git a/tools/tsc-watch/index.ts b/tools/tsc-watch/index.ts index 856f4825ec..c399d11c2f 100644 --- a/tools/tsc-watch/index.ts +++ b/tools/tsc-watch/index.ts @@ -15,44 +15,6 @@ import {TSC, TscWatch, reportError} from './tsc_watch'; export * from './tsc_watch'; import 'reflect-metadata'; -const OFFLINE_COMPILE = - ['output/output_emitter_codegen_untyped', 'output/output_emitter_codegen_typed']; - -function processOutputEmitterCodeGen(): Promise { - return new Promise((resolve, reject) => { - const outDir = 'dist/all/@angular/compiler/test/'; - const promises: Promise[] = []; - console.log('Processing codegen...'); - OFFLINE_COMPILE.forEach((file: string) => { - const codegen = require('../../all/@angular/compiler/test/' + file + '.js'); - if (codegen.emit) { - console.log(` ${file} has changed, regenerating...`); - promises.push(Promise.resolve(codegen.emit()).then((code) => { - writeFileSync(outDir + file + '.ts', code); - })); - } - }); - if (promises.length) { - Promise.all(promises) - .then(() => { - const args = - ['--project', 'tools/cjs-jasmine/tsconfig-output_emitter_codegen.json']; - console.log(' compiling changes: tsc ' + args.join(' ')); - const tsc = spawn(TSC, args, {stdio: 'pipe'}); - tsc.stdout.on('data', (data: any) => process.stdout.write(data)); - tsc.stderr.on('data', (data: any) => process.stderr.write(data)); - tsc.on( - 'close', - (code: any) => code ? reject('Tsc exited with: ' + code) : resolve(code)); - }) - .catch(reportError); - } else { - resolve(0); - } - }) - .catch(reportError); -} - function md(dir: string, folders: string[]) { if (folders.length) { const next = folders.shift(); @@ -77,13 +39,10 @@ if (platform == 'node') { tscWatch = new TscWatch(Object.assign( { tsconfig: 'modules/tsconfig.json', - onChangeCmds: [ - processOutputEmitterCodeGen, - [ - 'node', 'dist/tools/cjs-jasmine', '--', '@angular/**/*_spec.js', - '@angular/compiler-cli/test/**/*_spec.js', '@angular/benchpress/test/**/*_spec.js' - ] - ] + onChangeCmds: [[ + 'node', 'dist/tools/cjs-jasmine', '--', '@angular/**/*_spec.js', + '@angular/compiler-cli/test/**/*_spec.js', '@angular/benchpress/test/**/*_spec.js' + ]] }, BaseConfig)); } else if (platform == 'browser') {