From 6ac1bcca08f916e3eeb47e56306b03b826e241d5 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 10 Feb 2015 13:43:05 -0800 Subject: [PATCH 001/224] Enable declaration emit for import "mod" syntax --- src/compiler/emitter.ts | 14 +++++++ .../reference/es6ImportWithoutFromClause.js | 9 ++++- .../es6ImportWithoutFromClause.types | 1 + .../es6ImportWithoutFromClauseAmd.js | 37 +++++++++++++++++++ .../es6ImportWithoutFromClauseAmd.types | 18 +++++++++ .../es6ImportWithoutFromClauseInEs5.js | 6 +++ ...tWithoutFromClauseNonInstantiatedModule.js | 20 ++++++++++ ...thoutFromClauseNonInstantiatedModule.types | 9 +++++ .../compiler/es6ImportWithoutFromClause.ts | 3 +- .../compiler/es6ImportWithoutFromClauseAmd.ts | 14 +++++++ .../es6ImportWithoutFromClauseInEs5.ts | 1 + ...tWithoutFromClauseNonInstantiatedModule.ts | 10 +++++ 12 files changed, 140 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/es6ImportWithoutFromClauseAmd.js create mode 100644 tests/baselines/reference/es6ImportWithoutFromClauseAmd.types create mode 100644 tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.js create mode 100644 tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.types create mode 100644 tests/cases/compiler/es6ImportWithoutFromClauseAmd.ts create mode 100644 tests/cases/compiler/es6ImportWithoutFromClauseNonInstantiatedModule.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 1ac305cf05563..0f309bc38099e 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -766,6 +766,18 @@ module ts { } } + function emitImportDeclaration(node: ImportDeclaration) { + // TODO(shkamat): Do the changes so that we emit only if declaration is visible + emitJsDocComments(node); + if (node.flags & NodeFlags.Export) { + write("export "); + } + write("import "); + writeTextOfNode(currentSourceFile, node.moduleSpecifier); + write(";"); + writer.writeLine(); + } + function emitModuleDeclaration(node: ModuleDeclaration) { if (resolver.isDeclarationVisible(node)) { emitJsDocComments(node); @@ -1483,6 +1495,8 @@ module ts { return emitImportEqualsDeclaration(node); case SyntaxKind.ExportAssignment: return emitExportAssignment(node); + case SyntaxKind.ImportDeclaration: + return emitImportDeclaration(node); case SyntaxKind.SourceFile: return emitSourceFile(node); } diff --git a/tests/baselines/reference/es6ImportWithoutFromClause.js b/tests/baselines/reference/es6ImportWithoutFromClause.js index 43d21885c2701..b5eb7a1ba0df2 100644 --- a/tests/baselines/reference/es6ImportWithoutFromClause.js +++ b/tests/baselines/reference/es6ImportWithoutFromClause.js @@ -5,9 +5,16 @@ export var a = 10; //// [es6ImportWithoutFromClause_1.ts] -import "es6ImportWithoutFromClause_0"; +import "es6ImportWithoutFromClause_0"; + //// [es6ImportWithoutFromClause_0.js] exports.a = 10; //// [es6ImportWithoutFromClause_1.js] require("es6ImportWithoutFromClause_0"); + + +//// [es6ImportWithoutFromClause_0.d.ts] +export declare var a: number; +//// [es6ImportWithoutFromClause_1.d.ts] +import "es6ImportWithoutFromClause_0"; diff --git a/tests/baselines/reference/es6ImportWithoutFromClause.types b/tests/baselines/reference/es6ImportWithoutFromClause.types index 1cd7df9962ee7..3cc5067891ad2 100644 --- a/tests/baselines/reference/es6ImportWithoutFromClause.types +++ b/tests/baselines/reference/es6ImportWithoutFromClause.types @@ -5,4 +5,5 @@ export var a = 10; === tests/cases/compiler/es6ImportWithoutFromClause_1.ts === import "es6ImportWithoutFromClause_0"; +No type information for this code. No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseAmd.js b/tests/baselines/reference/es6ImportWithoutFromClauseAmd.js new file mode 100644 index 0000000000000..0464794ea8915 --- /dev/null +++ b/tests/baselines/reference/es6ImportWithoutFromClauseAmd.js @@ -0,0 +1,37 @@ +//// [tests/cases/compiler/es6ImportWithoutFromClauseAmd.ts] //// + +//// [es6ImportWithoutFromClauseAmd_0.ts] + +export var a = 10; + +//// [es6ImportWithoutFromClauseAmd_1.ts] +export var b = 10; + +//// [es6ImportWithoutFromClauseAmd_2.ts] +import "es6ImportWithoutFromClauseAmd_0"; +import "es6ImportWithoutFromClauseAmd_2"; +var _a = 10; +var _b = 10; + +//// [es6ImportWithoutFromClauseAmd_0.js] +define(["require", "exports"], function (require, exports) { + exports.a = 10; +}); +//// [es6ImportWithoutFromClauseAmd_1.js] +define(["require", "exports"], function (require, exports) { + exports.b = 10; +}); +//// [es6ImportWithoutFromClauseAmd_2.js] +define(["require", "exports", "es6ImportWithoutFromClauseAmd_0", "es6ImportWithoutFromClauseAmd_2"], function (require, exports, _c, _d) { + var _a = 10; + var _b = 10; +}); + + +//// [es6ImportWithoutFromClauseAmd_0.d.ts] +export declare var a: number; +//// [es6ImportWithoutFromClauseAmd_1.d.ts] +export declare var b: number; +//// [es6ImportWithoutFromClauseAmd_2.d.ts] +import "es6ImportWithoutFromClauseAmd_0"; +import "es6ImportWithoutFromClauseAmd_2"; diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseAmd.types b/tests/baselines/reference/es6ImportWithoutFromClauseAmd.types new file mode 100644 index 0000000000000..c3d09388916bc --- /dev/null +++ b/tests/baselines/reference/es6ImportWithoutFromClauseAmd.types @@ -0,0 +1,18 @@ +=== tests/cases/compiler/es6ImportWithoutFromClauseAmd_0.ts === + +export var a = 10; +>a : number + +=== tests/cases/compiler/es6ImportWithoutFromClauseAmd_1.ts === +export var b = 10; +>b : number + +=== tests/cases/compiler/es6ImportWithoutFromClauseAmd_2.ts === +import "es6ImportWithoutFromClauseAmd_0"; +import "es6ImportWithoutFromClauseAmd_2"; +var _a = 10; +>_a : number + +var _b = 10; +>_b : number + diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js b/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js index f6610ac5ad295..9495bc1ffbcaf 100644 --- a/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js +++ b/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js @@ -11,3 +11,9 @@ import "es6ImportWithoutFromClauseInEs5_0"; exports.a = 10; //// [es6ImportWithoutFromClauseInEs5_1.js] require("es6ImportWithoutFromClauseInEs5_0"); + + +//// [es6ImportWithoutFromClauseInEs5_0.d.ts] +export declare var a: number; +//// [es6ImportWithoutFromClauseInEs5_1.d.ts] +import "es6ImportWithoutFromClauseInEs5_0"; diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.js b/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.js new file mode 100644 index 0000000000000..1c75b15c7d1c2 --- /dev/null +++ b/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.js @@ -0,0 +1,20 @@ +//// [tests/cases/compiler/es6ImportWithoutFromClauseNonInstantiatedModule.ts] //// + +//// [es6ImportWithoutFromClauseNonInstantiatedModule_0.ts] + +export interface i { +} + +//// [es6ImportWithoutFromClauseNonInstantiatedModule_1.ts] +import "es6ImportWithoutFromClauseNonInstantiatedModule_0"; + +//// [es6ImportWithoutFromClauseNonInstantiatedModule_0.js] +//// [es6ImportWithoutFromClauseNonInstantiatedModule_1.js] +require("es6ImportWithoutFromClauseNonInstantiatedModule_0"); + + +//// [es6ImportWithoutFromClauseNonInstantiatedModule_0.d.ts] +export interface i { +} +//// [es6ImportWithoutFromClauseNonInstantiatedModule_1.d.ts] +import "es6ImportWithoutFromClauseNonInstantiatedModule_0"; diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.types b/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.types new file mode 100644 index 0000000000000..2be3f67f1e963 --- /dev/null +++ b/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.types @@ -0,0 +1,9 @@ +=== tests/cases/compiler/es6ImportWithoutFromClauseNonInstantiatedModule_0.ts === + +export interface i { +>i : i +} + +=== tests/cases/compiler/es6ImportWithoutFromClauseNonInstantiatedModule_1.ts === +import "es6ImportWithoutFromClauseNonInstantiatedModule_0"; +No type information for this code. \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportWithoutFromClause.ts b/tests/cases/compiler/es6ImportWithoutFromClause.ts index 70a15a9bc54f7..d43aac9b63856 100644 --- a/tests/cases/compiler/es6ImportWithoutFromClause.ts +++ b/tests/cases/compiler/es6ImportWithoutFromClause.ts @@ -1,8 +1,9 @@ // @target: es6 // @module: commonjs +// @declaration: true // @filename: es6ImportWithoutFromClause_0.ts export var a = 10; // @filename: es6ImportWithoutFromClause_1.ts -import "es6ImportWithoutFromClause_0"; \ No newline at end of file +import "es6ImportWithoutFromClause_0"; diff --git a/tests/cases/compiler/es6ImportWithoutFromClauseAmd.ts b/tests/cases/compiler/es6ImportWithoutFromClauseAmd.ts new file mode 100644 index 0000000000000..8c43a19e4093e --- /dev/null +++ b/tests/cases/compiler/es6ImportWithoutFromClauseAmd.ts @@ -0,0 +1,14 @@ +// @module: amd +// @declaration: true + +// @filename: es6ImportWithoutFromClauseAmd_0.ts +export var a = 10; + +// @filename: es6ImportWithoutFromClauseAmd_1.ts +export var b = 10; + +// @filename: es6ImportWithoutFromClauseAmd_2.ts +import "es6ImportWithoutFromClauseAmd_0"; +import "es6ImportWithoutFromClauseAmd_2"; +var _a = 10; +var _b = 10; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportWithoutFromClauseInEs5.ts b/tests/cases/compiler/es6ImportWithoutFromClauseInEs5.ts index 339880ee097e3..08c21c236443a 100644 --- a/tests/cases/compiler/es6ImportWithoutFromClauseInEs5.ts +++ b/tests/cases/compiler/es6ImportWithoutFromClauseInEs5.ts @@ -1,5 +1,6 @@ // @target: es5 // @module: commonjs +// @declaration: true // @filename: es6ImportWithoutFromClauseInEs5_0.ts export var a = 10; diff --git a/tests/cases/compiler/es6ImportWithoutFromClauseNonInstantiatedModule.ts b/tests/cases/compiler/es6ImportWithoutFromClauseNonInstantiatedModule.ts new file mode 100644 index 0000000000000..8d364f75a9b17 --- /dev/null +++ b/tests/cases/compiler/es6ImportWithoutFromClauseNonInstantiatedModule.ts @@ -0,0 +1,10 @@ +// @target: es6 +// @module: commonjs +// @declaration: true + +// @filename: es6ImportWithoutFromClauseNonInstantiatedModule_0.ts +export interface i { +} + +// @filename: es6ImportWithoutFromClauseNonInstantiatedModule_1.ts +import "es6ImportWithoutFromClauseNonInstantiatedModule_0"; \ No newline at end of file From 96139ca4d8bd8c36ade8569086189a4151d02be4 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 10 Feb 2015 14:36:54 -0800 Subject: [PATCH 002/224] Enable declaration emit for import * as ns from "mod" syntax --- src/compiler/emitter.ts | 10 +++++++ .../reference/es6ImportNameSpaceImport.js | 14 +++++++++- .../reference/es6ImportNameSpaceImport.types | 9 +++++++ .../reference/es6ImportNameSpaceImportAmd.js | 27 +++++++++++++++++++ .../es6ImportNameSpaceImportAmd.types | 18 +++++++++++++ .../es6ImportNameSpaceImportInEs5.js | 14 +++++++++- .../es6ImportNameSpaceImportInEs5.types | 9 +++++++ ...mportNameSpaceImportMergeErrors.errors.txt | 25 +++++++++++++++++ .../es6ImportNameSpaceImportMergeErrors.js | 21 +++++++++++++++ .../es6ImportNameSpaceImportNoNamedExports.js | 14 ++++++++++ ...6ImportNameSpaceImportNoNamedExports.types | 12 +++++++++ .../compiler/es6ImportNameSpaceImport.ts | 5 +++- .../compiler/es6ImportNameSpaceImportAmd.ts | 10 +++++++ .../compiler/es6ImportNameSpaceImportInEs5.ts | 5 +++- .../es6ImportNameSpaceImportMergeErrors.ts | 15 +++++++++++ .../es6ImportNameSpaceImportNoNamedExports.ts | 9 +++++++ 16 files changed, 213 insertions(+), 4 deletions(-) create mode 100644 tests/baselines/reference/es6ImportNameSpaceImportAmd.js create mode 100644 tests/baselines/reference/es6ImportNameSpaceImportAmd.types create mode 100644 tests/baselines/reference/es6ImportNameSpaceImportMergeErrors.errors.txt create mode 100644 tests/baselines/reference/es6ImportNameSpaceImportMergeErrors.js create mode 100644 tests/baselines/reference/es6ImportNameSpaceImportNoNamedExports.js create mode 100644 tests/baselines/reference/es6ImportNameSpaceImportNoNamedExports.types create mode 100644 tests/cases/compiler/es6ImportNameSpaceImportAmd.ts create mode 100644 tests/cases/compiler/es6ImportNameSpaceImportMergeErrors.ts create mode 100644 tests/cases/compiler/es6ImportNameSpaceImportNoNamedExports.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 0f309bc38099e..db174b7059647 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -773,6 +773,16 @@ module ts { write("export "); } write("import "); + if (node.importClause) { + if (node.importClause.namedBindings) { + if (node.importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { + write("* as "); + writeTextOfNode(currentSourceFile,(node.importClause.namedBindings).name); + write(" "); + } + } + write("from "); + } writeTextOfNode(currentSourceFile, node.moduleSpecifier); write(";"); writer.writeLine(); diff --git a/tests/baselines/reference/es6ImportNameSpaceImport.js b/tests/baselines/reference/es6ImportNameSpaceImport.js index c6daa3b122255..6ee33d5e004eb 100644 --- a/tests/baselines/reference/es6ImportNameSpaceImport.js +++ b/tests/baselines/reference/es6ImportNameSpaceImport.js @@ -5,8 +5,20 @@ export var a = 10; //// [es6ImportNameSpaceImport_1.ts] -import * as nameSpaceBinding from "es6ImportNameSpaceImport_0"; +import * as nameSpaceBinding from "es6ImportNameSpaceImport_0"; +var x = nameSpaceBinding.a; +import * as nameSpaceBinding2 from "es6ImportNameSpaceImport_0"; // elide this + //// [es6ImportNameSpaceImport_0.js] exports.a = 10; //// [es6ImportNameSpaceImport_1.js] +var nameSpaceBinding = require("es6ImportNameSpaceImport_0"); +var x = nameSpaceBinding.a; + + +//// [es6ImportNameSpaceImport_0.d.ts] +export declare var a: number; +//// [es6ImportNameSpaceImport_1.d.ts] +import * as nameSpaceBinding from "es6ImportNameSpaceImport_0"; +import * as nameSpaceBinding2 from "es6ImportNameSpaceImport_0"; diff --git a/tests/baselines/reference/es6ImportNameSpaceImport.types b/tests/baselines/reference/es6ImportNameSpaceImport.types index 1e09de42ec6a2..d764a68eedea2 100644 --- a/tests/baselines/reference/es6ImportNameSpaceImport.types +++ b/tests/baselines/reference/es6ImportNameSpaceImport.types @@ -7,3 +7,12 @@ export var a = 10; import * as nameSpaceBinding from "es6ImportNameSpaceImport_0"; >nameSpaceBinding : typeof nameSpaceBinding +var x = nameSpaceBinding.a; +>x : number +>nameSpaceBinding.a : number +>nameSpaceBinding : typeof nameSpaceBinding +>a : number + +import * as nameSpaceBinding2 from "es6ImportNameSpaceImport_0"; // elide this +>nameSpaceBinding2 : typeof nameSpaceBinding + diff --git a/tests/baselines/reference/es6ImportNameSpaceImportAmd.js b/tests/baselines/reference/es6ImportNameSpaceImportAmd.js new file mode 100644 index 0000000000000..b63431d5df654 --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportAmd.js @@ -0,0 +1,27 @@ +//// [tests/cases/compiler/es6ImportNameSpaceImportAmd.ts] //// + +//// [es6ImportNameSpaceImportAmd_0.ts] + +export var a = 10; + +//// [es6ImportNameSpaceImportAmd_1.ts] +import * as nameSpaceBinding from "es6ImportNameSpaceImportAmd_0"; +var x = nameSpaceBinding.a; +import * as nameSpaceBinding2 from "es6ImportNameSpaceImportAmd_0"; // elide this + + +//// [es6ImportNameSpaceImportAmd_0.js] +define(["require", "exports"], function (require, exports) { + exports.a = 10; +}); +//// [es6ImportNameSpaceImportAmd_1.js] +define(["require", "exports", "es6ImportNameSpaceImportAmd_0"], function (require, exports, nameSpaceBinding) { + var x = nameSpaceBinding.a; +}); + + +//// [es6ImportNameSpaceImportAmd_0.d.ts] +export declare var a: number; +//// [es6ImportNameSpaceImportAmd_1.d.ts] +import * as nameSpaceBinding from "es6ImportNameSpaceImportAmd_0"; +import * as nameSpaceBinding2 from "es6ImportNameSpaceImportAmd_0"; diff --git a/tests/baselines/reference/es6ImportNameSpaceImportAmd.types b/tests/baselines/reference/es6ImportNameSpaceImportAmd.types new file mode 100644 index 0000000000000..623a7e8e160df --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportAmd.types @@ -0,0 +1,18 @@ +=== tests/cases/compiler/es6ImportNameSpaceImportAmd_0.ts === + +export var a = 10; +>a : number + +=== tests/cases/compiler/es6ImportNameSpaceImportAmd_1.ts === +import * as nameSpaceBinding from "es6ImportNameSpaceImportAmd_0"; +>nameSpaceBinding : typeof nameSpaceBinding + +var x = nameSpaceBinding.a; +>x : number +>nameSpaceBinding.a : number +>nameSpaceBinding : typeof nameSpaceBinding +>a : number + +import * as nameSpaceBinding2 from "es6ImportNameSpaceImportAmd_0"; // elide this +>nameSpaceBinding2 : typeof nameSpaceBinding + diff --git a/tests/baselines/reference/es6ImportNameSpaceImportInEs5.js b/tests/baselines/reference/es6ImportNameSpaceImportInEs5.js index 2c7785dec6ed5..f26e9073d2c19 100644 --- a/tests/baselines/reference/es6ImportNameSpaceImportInEs5.js +++ b/tests/baselines/reference/es6ImportNameSpaceImportInEs5.js @@ -5,8 +5,20 @@ export var a = 10; //// [es6ImportNameSpaceImportInEs5_1.ts] -import * as nameSpaceBinding from "es6ImportNameSpaceImportInEs5_0"; +import * as nameSpaceBinding from "es6ImportNameSpaceImportInEs5_0"; +var x = nameSpaceBinding.a; +import * as nameSpaceBinding2 from "es6ImportNameSpaceImportInEs5_0"; // elide this + //// [es6ImportNameSpaceImportInEs5_0.js] exports.a = 10; //// [es6ImportNameSpaceImportInEs5_1.js] +var nameSpaceBinding = require("es6ImportNameSpaceImportInEs5_0"); +var x = nameSpaceBinding.a; + + +//// [es6ImportNameSpaceImportInEs5_0.d.ts] +export declare var a: number; +//// [es6ImportNameSpaceImportInEs5_1.d.ts] +import * as nameSpaceBinding from "es6ImportNameSpaceImportInEs5_0"; +import * as nameSpaceBinding2 from "es6ImportNameSpaceImportInEs5_0"; diff --git a/tests/baselines/reference/es6ImportNameSpaceImportInEs5.types b/tests/baselines/reference/es6ImportNameSpaceImportInEs5.types index cb7b669eea1c0..6ba725f2494ce 100644 --- a/tests/baselines/reference/es6ImportNameSpaceImportInEs5.types +++ b/tests/baselines/reference/es6ImportNameSpaceImportInEs5.types @@ -7,3 +7,12 @@ export var a = 10; import * as nameSpaceBinding from "es6ImportNameSpaceImportInEs5_0"; >nameSpaceBinding : typeof nameSpaceBinding +var x = nameSpaceBinding.a; +>x : number +>nameSpaceBinding.a : number +>nameSpaceBinding : typeof nameSpaceBinding +>a : number + +import * as nameSpaceBinding2 from "es6ImportNameSpaceImportInEs5_0"; // elide this +>nameSpaceBinding2 : typeof nameSpaceBinding + diff --git a/tests/baselines/reference/es6ImportNameSpaceImportMergeErrors.errors.txt b/tests/baselines/reference/es6ImportNameSpaceImportMergeErrors.errors.txt new file mode 100644 index 0000000000000..98a6887083390 --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportMergeErrors.errors.txt @@ -0,0 +1,25 @@ +tests/cases/compiler/es6ImportNameSpaceImportMergeErrors_1.ts(4,13): error TS2300: Duplicate identifier 'nameSpaceBinding1'. +tests/cases/compiler/es6ImportNameSpaceImportMergeErrors_1.ts(5,13): error TS2300: Duplicate identifier 'nameSpaceBinding1'. +tests/cases/compiler/es6ImportNameSpaceImportMergeErrors_1.ts(7,8): error TS2440: Import declaration conflicts with local declaration of 'nameSpaceBinding3' + + +==== tests/cases/compiler/es6ImportNameSpaceImportMergeErrors_0.ts (0 errors) ==== + + export var a = 10; + +==== tests/cases/compiler/es6ImportNameSpaceImportMergeErrors_1.ts (3 errors) ==== + import * as nameSpaceBinding from "es6ImportNameSpaceImportMergeErrors_0"; + interface nameSpaceBinding { } // this should be ok + + import * as nameSpaceBinding1 from "es6ImportNameSpaceImportMergeErrors_0"; // should be error + ~~~~~~~~~~~~~~~~~ +!!! error TS2300: Duplicate identifier 'nameSpaceBinding1'. + import * as nameSpaceBinding1 from "es6ImportNameSpaceImportMergeErrors_0"; // should be error + ~~~~~~~~~~~~~~~~~ +!!! error TS2300: Duplicate identifier 'nameSpaceBinding1'. + + import * as nameSpaceBinding3 from "es6ImportNameSpaceImportMergeErrors_0"; // should be error + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2440: Import declaration conflicts with local declaration of 'nameSpaceBinding3' + var nameSpaceBinding3 = 10; + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNameSpaceImportMergeErrors.js b/tests/baselines/reference/es6ImportNameSpaceImportMergeErrors.js new file mode 100644 index 0000000000000..3c8461fba2b70 --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportMergeErrors.js @@ -0,0 +1,21 @@ +//// [tests/cases/compiler/es6ImportNameSpaceImportMergeErrors.ts] //// + +//// [es6ImportNameSpaceImportMergeErrors_0.ts] + +export var a = 10; + +//// [es6ImportNameSpaceImportMergeErrors_1.ts] +import * as nameSpaceBinding from "es6ImportNameSpaceImportMergeErrors_0"; +interface nameSpaceBinding { } // this should be ok + +import * as nameSpaceBinding1 from "es6ImportNameSpaceImportMergeErrors_0"; // should be error +import * as nameSpaceBinding1 from "es6ImportNameSpaceImportMergeErrors_0"; // should be error + +import * as nameSpaceBinding3 from "es6ImportNameSpaceImportMergeErrors_0"; // should be error +var nameSpaceBinding3 = 10; + + +//// [es6ImportNameSpaceImportMergeErrors_0.js] +exports.a = 10; +//// [es6ImportNameSpaceImportMergeErrors_1.js] +var nameSpaceBinding3 = 10; diff --git a/tests/baselines/reference/es6ImportNameSpaceImportNoNamedExports.js b/tests/baselines/reference/es6ImportNameSpaceImportNoNamedExports.js new file mode 100644 index 0000000000000..3d6dab177851d --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportNoNamedExports.js @@ -0,0 +1,14 @@ +//// [tests/cases/compiler/es6ImportNameSpaceImportNoNamedExports.ts] //// + +//// [es6ImportNameSpaceImportNoNamedExports_0.ts] + +var a = 10; +export = a; + +//// [es6ImportNameSpaceImportNoNamedExports_1.ts] +import * as nameSpaceBinding from "es6ImportNameSpaceImportNoNamedExports_0"; // error + +//// [es6ImportNameSpaceImportNoNamedExports_0.js] +var a = 10; +module.exports = a; +//// [es6ImportNameSpaceImportNoNamedExports_1.js] diff --git a/tests/baselines/reference/es6ImportNameSpaceImportNoNamedExports.types b/tests/baselines/reference/es6ImportNameSpaceImportNoNamedExports.types new file mode 100644 index 0000000000000..3ba19cef9b443 --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportNoNamedExports.types @@ -0,0 +1,12 @@ +=== tests/cases/compiler/es6ImportNameSpaceImportNoNamedExports_0.ts === + +var a = 10; +>a : number + +export = a; +>a : number + +=== tests/cases/compiler/es6ImportNameSpaceImportNoNamedExports_1.ts === +import * as nameSpaceBinding from "es6ImportNameSpaceImportNoNamedExports_0"; // error +>nameSpaceBinding : typeof nameSpaceBinding + diff --git a/tests/cases/compiler/es6ImportNameSpaceImport.ts b/tests/cases/compiler/es6ImportNameSpaceImport.ts index 9937606c41ff4..0c831d323d14a 100644 --- a/tests/cases/compiler/es6ImportNameSpaceImport.ts +++ b/tests/cases/compiler/es6ImportNameSpaceImport.ts @@ -1,8 +1,11 @@ // @target: es6 // @module: commonjs +// @declaration: true // @filename: es6ImportNameSpaceImport_0.ts export var a = 10; // @filename: es6ImportNameSpaceImport_1.ts -import * as nameSpaceBinding from "es6ImportNameSpaceImport_0"; \ No newline at end of file +import * as nameSpaceBinding from "es6ImportNameSpaceImport_0"; +var x = nameSpaceBinding.a; +import * as nameSpaceBinding2 from "es6ImportNameSpaceImport_0"; // elide this diff --git a/tests/cases/compiler/es6ImportNameSpaceImportAmd.ts b/tests/cases/compiler/es6ImportNameSpaceImportAmd.ts new file mode 100644 index 0000000000000..89a5ad7bc2c0b --- /dev/null +++ b/tests/cases/compiler/es6ImportNameSpaceImportAmd.ts @@ -0,0 +1,10 @@ +// @module: amd +// @declaration: true + +// @filename: es6ImportNameSpaceImportAmd_0.ts +export var a = 10; + +// @filename: es6ImportNameSpaceImportAmd_1.ts +import * as nameSpaceBinding from "es6ImportNameSpaceImportAmd_0"; +var x = nameSpaceBinding.a; +import * as nameSpaceBinding2 from "es6ImportNameSpaceImportAmd_0"; // elide this diff --git a/tests/cases/compiler/es6ImportNameSpaceImportInEs5.ts b/tests/cases/compiler/es6ImportNameSpaceImportInEs5.ts index ca00ac3f981e6..8104fe8b3c0ef 100644 --- a/tests/cases/compiler/es6ImportNameSpaceImportInEs5.ts +++ b/tests/cases/compiler/es6ImportNameSpaceImportInEs5.ts @@ -1,8 +1,11 @@ // @target: es5 // @module: commonjs +// @declaration: true // @filename: es6ImportNameSpaceImportInEs5_0.ts export var a = 10; // @filename: es6ImportNameSpaceImportInEs5_1.ts -import * as nameSpaceBinding from "es6ImportNameSpaceImportInEs5_0"; \ No newline at end of file +import * as nameSpaceBinding from "es6ImportNameSpaceImportInEs5_0"; +var x = nameSpaceBinding.a; +import * as nameSpaceBinding2 from "es6ImportNameSpaceImportInEs5_0"; // elide this diff --git a/tests/cases/compiler/es6ImportNameSpaceImportMergeErrors.ts b/tests/cases/compiler/es6ImportNameSpaceImportMergeErrors.ts new file mode 100644 index 0000000000000..1d491ce146ad5 --- /dev/null +++ b/tests/cases/compiler/es6ImportNameSpaceImportMergeErrors.ts @@ -0,0 +1,15 @@ +// @target: es6 +// @module: commonjs + +// @filename: es6ImportNameSpaceImportMergeErrors_0.ts +export var a = 10; + +// @filename: es6ImportNameSpaceImportMergeErrors_1.ts +import * as nameSpaceBinding from "es6ImportNameSpaceImportMergeErrors_0"; +interface nameSpaceBinding { } // this should be ok + +import * as nameSpaceBinding1 from "es6ImportNameSpaceImportMergeErrors_0"; // should be error +import * as nameSpaceBinding1 from "es6ImportNameSpaceImportMergeErrors_0"; // should be error + +import * as nameSpaceBinding3 from "es6ImportNameSpaceImportMergeErrors_0"; // should be error +var nameSpaceBinding3 = 10; diff --git a/tests/cases/compiler/es6ImportNameSpaceImportNoNamedExports.ts b/tests/cases/compiler/es6ImportNameSpaceImportNoNamedExports.ts new file mode 100644 index 0000000000000..237fe3649eaa7 --- /dev/null +++ b/tests/cases/compiler/es6ImportNameSpaceImportNoNamedExports.ts @@ -0,0 +1,9 @@ +// @target: es6 +// @module: commonjs + +// @filename: es6ImportNameSpaceImportNoNamedExports_0.ts +var a = 10; +export = a; + +// @filename: es6ImportNameSpaceImportNoNamedExports_1.ts +import * as nameSpaceBinding from "es6ImportNameSpaceImportNoNamedExports_0"; // error \ No newline at end of file From f2a28a5975825042efae1d52a0428d013c5cbffb Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 9 Feb 2015 08:51:55 -0800 Subject: [PATCH 003/224] Declaration emit for NamedImport syntax --- src/compiler/checker.ts | 8 +- src/compiler/emitter.ts | 14 ++ .../reference/es6ImportNamedImport.js | 85 +++++++++++- .../reference/es6ImportNamedImport.types | 73 +++++++++++ .../reference/es6ImportNamedImportAmd.js | 105 +++++++++++++++ .../reference/es6ImportNamedImportAmd.types | 123 ++++++++++++++++++ .../reference/es6ImportNamedImportInEs5.js | 85 +++++++++++- .../reference/es6ImportNamedImportInEs5.types | 73 +++++++++++ .../es6ImportNamedImportInExportAssignment.js | 16 +++ ...6ImportNamedImportInExportAssignment.types | 12 ++ ...rtNamedImportInIndirectExportAssignment.js | 29 +++++ ...amedImportInIndirectExportAssignment.types | 21 +++ ...es6ImportNamedImportMergeErrors.errors.txt | 33 +++++ .../es6ImportNamedImportMergeErrors.js | 30 +++++ ...ImportNamedImportNoExportMember.errors.txt | 16 +++ .../es6ImportNamedImportNoExportMember.js | 15 +++ ...ImportNamedImportNoNamedExports.errors.txt | 16 +++ .../es6ImportNamedImportNoNamedExports.js | 15 +++ tests/cases/compiler/es6ImportNamedImport.ts | 25 +++- .../cases/compiler/es6ImportNamedImportAmd.ts | 41 ++++++ .../compiler/es6ImportNamedImportInEs5.ts | 25 +++- .../es6ImportNamedImportInExportAssignment.ts | 9 ++ ...rtNamedImportInIndirectExportAssignment.ts | 13 ++ .../es6ImportNamedImportMergeErrors.ts | 20 +++ .../es6ImportNamedImportNoExportMember.ts | 10 ++ .../es6ImportNamedImportNoNamedExports.ts | 10 ++ 26 files changed, 917 insertions(+), 5 deletions(-) create mode 100644 tests/baselines/reference/es6ImportNamedImportAmd.js create mode 100644 tests/baselines/reference/es6ImportNamedImportAmd.types create mode 100644 tests/baselines/reference/es6ImportNamedImportInExportAssignment.js create mode 100644 tests/baselines/reference/es6ImportNamedImportInExportAssignment.types create mode 100644 tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.js create mode 100644 tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.types create mode 100644 tests/baselines/reference/es6ImportNamedImportMergeErrors.errors.txt create mode 100644 tests/baselines/reference/es6ImportNamedImportMergeErrors.js create mode 100644 tests/baselines/reference/es6ImportNamedImportNoExportMember.errors.txt create mode 100644 tests/baselines/reference/es6ImportNamedImportNoExportMember.js create mode 100644 tests/baselines/reference/es6ImportNamedImportNoNamedExports.errors.txt create mode 100644 tests/baselines/reference/es6ImportNamedImportNoNamedExports.js create mode 100644 tests/cases/compiler/es6ImportNamedImportAmd.ts create mode 100644 tests/cases/compiler/es6ImportNamedImportInExportAssignment.ts create mode 100644 tests/cases/compiler/es6ImportNamedImportInIndirectExportAssignment.ts create mode 100644 tests/cases/compiler/es6ImportNamedImportMergeErrors.ts create mode 100644 tests/cases/compiler/es6ImportNamedImportNoExportMember.ts create mode 100644 tests/cases/compiler/es6ImportNamedImportNoNamedExports.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 61cf3298fd84d..864e9551721df 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4912,7 +4912,13 @@ module ts { getSymbolLinks(rightSide).referenced = true; Debug.assert((rightSide.flags & SymbolFlags.Import) !== 0); - nodeLinks = getNodeLinks(getDeclarationOfKind(rightSide, SyntaxKind.ImportEqualsDeclaration)) + var importEqualsDeclaration = getDeclarationOfKind(rightSide, SyntaxKind.ImportEqualsDeclaration); + if (importEqualsDeclaration) { + nodeLinks = getNodeLinks(importEqualsDeclaration); + } + else { + break; + } } } } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index db174b7059647..60cde0743d070 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -780,6 +780,11 @@ module ts { writeTextOfNode(currentSourceFile,(node.importClause.namedBindings).name); write(" "); } + else { + write("{"); + emitCommaList((node.importClause.namedBindings).elements, emitImportSpecifier); + write(" } "); + } } write("from "); } @@ -788,6 +793,15 @@ module ts { writer.writeLine(); } + function emitImportSpecifier(node: ImportSpecifier) { + write(" "); + if (node.propertyName) { + writeTextOfNode(currentSourceFile, node.propertyName); + write(" as "); + } + writeTextOfNode(currentSourceFile, node.name); + } + function emitModuleDeclaration(node: ModuleDeclaration) { if (resolver.isDeclarationVisible(node)) { emitJsDocComments(node); diff --git a/tests/baselines/reference/es6ImportNamedImport.js b/tests/baselines/reference/es6ImportNamedImport.js index c52499ef994a7..9a1eba4259819 100644 --- a/tests/baselines/reference/es6ImportNamedImport.js +++ b/tests/baselines/reference/es6ImportNamedImport.js @@ -7,16 +7,39 @@ export var x = a; export var m = a; export var a1 = 10; export var x1 = 10; +export var z1 = 10; +export var z2 = 10; +export var aaaa = 10; //// [es6ImportNamedImport_1.ts] import { } from "es6ImportNamedImport_0"; import { a } from "es6ImportNamedImport_0"; +var xxxx = a; import { a as b } from "es6ImportNamedImport_0"; +var xxxx = b; import { x, a as y } from "es6ImportNamedImport_0"; +var xxxx = x; +var xxxx = y; import { x as z, } from "es6ImportNamedImport_0"; +var xxxx = z; import { m, } from "es6ImportNamedImport_0"; +var xxxx = m; import { a1, x1 } from "es6ImportNamedImport_0"; -import { a1 as a11, x1 as x11 } from "es6ImportNamedImport_0"; +var xxxx = a1; +var xxxx = x1; +import { a1 as a11, x1 as x11 } from "es6ImportNamedImport_0"; +var xxxx = a11; +var xxxx = x11; +import { z1 } from "es6ImportNamedImport_0"; +var z111 = z1; +import { z2 as z3 } from "es6ImportNamedImport_0"; +var z2 = z3; // z2 shouldn't give redeclare error + +// These are elided +import { aaaa } from "es6ImportNamedImport_0"; +// These are elided +import { aaaa as bbbb } from "es6ImportNamedImport_0"; + //// [es6ImportNamedImport_0.js] exports.a = 10; @@ -24,4 +47,64 @@ exports.x = exports.a; exports.m = exports.a; exports.a1 = 10; exports.x1 = 10; +exports.z1 = 10; +exports.z2 = 10; +exports.aaaa = 10; //// [es6ImportNamedImport_1.js] +var _a = require("es6ImportNamedImport_0"); +var a = _a.a; +var xxxx = a; +var _b = require("es6ImportNamedImport_0"); +var b = _b.a; +var xxxx = b; +var _c = require("es6ImportNamedImport_0"); +var x = _c.x; +var y = _c.a; +var xxxx = x; +var xxxx = y; +var _d = require("es6ImportNamedImport_0"); +var z = _d.x; +var xxxx = z; +var _e = require("es6ImportNamedImport_0"); +var m = _e.m; +var xxxx = m; +var _f = require("es6ImportNamedImport_0"); +var a1 = _f.a1; +var x1 = _f.x1; +var xxxx = a1; +var xxxx = x1; +var _g = require("es6ImportNamedImport_0"); +var a11 = _g.a1; +var x11 = _g.x1; +var xxxx = a11; +var xxxx = x11; +var _h = require("es6ImportNamedImport_0"); +var z1 = _h.z1; +var z111 = z1; +var _j = require("es6ImportNamedImport_0"); +var z3 = _j.z2; +var z2 = z3; // z2 shouldn't give redeclare error + + +//// [es6ImportNamedImport_0.d.ts] +export declare var a: number; +export declare var x: number; +export declare var m: number; +export declare var a1: number; +export declare var x1: number; +export declare var z1: number; +export declare var z2: number; +export declare var aaaa: number; +//// [es6ImportNamedImport_1.d.ts] +import { } from "es6ImportNamedImport_0"; +import { a } from "es6ImportNamedImport_0"; +import { a as b } from "es6ImportNamedImport_0"; +import { x, a as y } from "es6ImportNamedImport_0"; +import { x as z } from "es6ImportNamedImport_0"; +import { m } from "es6ImportNamedImport_0"; +import { a1, x1 } from "es6ImportNamedImport_0"; +import { a1 as a11, x1 as x11 } from "es6ImportNamedImport_0"; +import { z1 } from "es6ImportNamedImport_0"; +import { z2 as z3 } from "es6ImportNamedImport_0"; +import { aaaa } from "es6ImportNamedImport_0"; +import { aaaa as bbbb } from "es6ImportNamedImport_0"; diff --git a/tests/baselines/reference/es6ImportNamedImport.types b/tests/baselines/reference/es6ImportNamedImport.types index e86955b3c96fb..80a7fccbd28ac 100644 --- a/tests/baselines/reference/es6ImportNamedImport.types +++ b/tests/baselines/reference/es6ImportNamedImport.types @@ -17,34 +17,107 @@ export var a1 = 10; export var x1 = 10; >x1 : number +export var z1 = 10; +>z1 : number + +export var z2 = 10; +>z2 : number + +export var aaaa = 10; +>aaaa : number + === tests/cases/compiler/es6ImportNamedImport_1.ts === import { } from "es6ImportNamedImport_0"; import { a } from "es6ImportNamedImport_0"; >a : number +var xxxx = a; +>xxxx : number +>a : number + import { a as b } from "es6ImportNamedImport_0"; >a : unknown >b : number +var xxxx = b; +>xxxx : number +>b : number + import { x, a as y } from "es6ImportNamedImport_0"; >x : number >a : unknown >y : number +var xxxx = x; +>xxxx : number +>x : number + +var xxxx = y; +>xxxx : number +>y : number + import { x as z, } from "es6ImportNamedImport_0"; >x : unknown >z : number +var xxxx = z; +>xxxx : number +>z : number + import { m, } from "es6ImportNamedImport_0"; >m : number +var xxxx = m; +>xxxx : number +>m : number + import { a1, x1 } from "es6ImportNamedImport_0"; >a1 : number >x1 : number +var xxxx = a1; +>xxxx : number +>a1 : number + +var xxxx = x1; +>xxxx : number +>x1 : number + import { a1 as a11, x1 as x11 } from "es6ImportNamedImport_0"; >a1 : unknown >a11 : number >x1 : unknown >x11 : number +var xxxx = a11; +>xxxx : number +>a11 : number + +var xxxx = x11; +>xxxx : number +>x11 : number + +import { z1 } from "es6ImportNamedImport_0"; +>z1 : number + +var z111 = z1; +>z111 : number +>z1 : number + +import { z2 as z3 } from "es6ImportNamedImport_0"; +>z2 : unknown +>z3 : number + +var z2 = z3; // z2 shouldn't give redeclare error +>z2 : number +>z3 : number + +// These are elided +import { aaaa } from "es6ImportNamedImport_0"; +>aaaa : number + +// These are elided +import { aaaa as bbbb } from "es6ImportNamedImport_0"; +>aaaa : unknown +>bbbb : number + diff --git a/tests/baselines/reference/es6ImportNamedImportAmd.js b/tests/baselines/reference/es6ImportNamedImportAmd.js new file mode 100644 index 0000000000000..7510c8aeb6b01 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportAmd.js @@ -0,0 +1,105 @@ +//// [tests/cases/compiler/es6ImportNamedImportAmd.ts] //// + +//// [es6ImportNamedImportAmd_0.ts] + +export var a = 10; +export var x = a; +export var m = a; +export var a1 = 10; +export var x1 = 10; +export var z1 = 10; +export var z2 = 10; +export var aaaa = 10; + +//// [es6ImportNamedImportAmd_1.ts] +import { } from "es6ImportNamedImportAmd_0"; +import { a } from "es6ImportNamedImportAmd_0"; +var xxxx = a; +import { a as b } from "es6ImportNamedImportAmd_0"; +var xxxx = b; +import { x, a as y } from "es6ImportNamedImportAmd_0"; +var xxxx = x; +var xxxx = y; +import { x as z, } from "es6ImportNamedImportAmd_0"; +var xxxx = z; +import { m, } from "es6ImportNamedImportAmd_0"; +var xxxx = m; +import { a1, x1 } from "es6ImportNamedImportAmd_0"; +var xxxx = a1; +var xxxx = x1; +import { a1 as a11, x1 as x11 } from "es6ImportNamedImportAmd_0"; +var xxxx = a11; +var xxxx = x11; +import { z1 } from "es6ImportNamedImportAmd_0"; +var z111 = z1; +import { z2 as z3 } from "es6ImportNamedImportAmd_0"; +var z2 = z3; // z2 shouldn't give redeclare error + +// These are elided +import { aaaa } from "es6ImportNamedImportAmd_0"; +// These are elided +import { aaaa as bbbb } from "es6ImportNamedImportAmd_0"; + + +//// [es6ImportNamedImportAmd_0.js] +define(["require", "exports"], function (require, exports) { + exports.a = 10; + exports.x = exports.a; + exports.m = exports.a; + exports.a1 = 10; + exports.x1 = 10; + exports.z1 = 10; + exports.z2 = 10; + exports.aaaa = 10; +}); +//// [es6ImportNamedImportAmd_1.js] +define(["require", "exports", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0"], function (require, exports, _a, _b, _c, _d, _e, _f, _g, _h, _j) { + var a = _a.a; + var xxxx = a; + var b = _b.a; + var xxxx = b; + var x = _c.x; + var y = _c.a; + var xxxx = x; + var xxxx = y; + var z = _d.x; + var xxxx = z; + var m = _e.m; + var xxxx = m; + var a1 = _f.a1; + var x1 = _f.x1; + var xxxx = a1; + var xxxx = x1; + var a11 = _g.a1; + var x11 = _g.x1; + var xxxx = a11; + var xxxx = x11; + var z1 = _h.z1; + var z111 = z1; + var z3 = _j.z2; + var z2 = z3; // z2 shouldn't give redeclare error +}); + + +//// [es6ImportNamedImportAmd_0.d.ts] +export declare var a: number; +export declare var x: number; +export declare var m: number; +export declare var a1: number; +export declare var x1: number; +export declare var z1: number; +export declare var z2: number; +export declare var aaaa: number; +//// [es6ImportNamedImportAmd_1.d.ts] +import { } from "es6ImportNamedImportAmd_0"; +import { a } from "es6ImportNamedImportAmd_0"; +import { a as b } from "es6ImportNamedImportAmd_0"; +import { x, a as y } from "es6ImportNamedImportAmd_0"; +import { x as z } from "es6ImportNamedImportAmd_0"; +import { m } from "es6ImportNamedImportAmd_0"; +import { a1, x1 } from "es6ImportNamedImportAmd_0"; +import { a1 as a11, x1 as x11 } from "es6ImportNamedImportAmd_0"; +import { z1 } from "es6ImportNamedImportAmd_0"; +import { z2 as z3 } from "es6ImportNamedImportAmd_0"; +import { aaaa } from "es6ImportNamedImportAmd_0"; +import { aaaa as bbbb } from "es6ImportNamedImportAmd_0"; diff --git a/tests/baselines/reference/es6ImportNamedImportAmd.types b/tests/baselines/reference/es6ImportNamedImportAmd.types new file mode 100644 index 0000000000000..3a68df656febc --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportAmd.types @@ -0,0 +1,123 @@ +=== tests/cases/compiler/es6ImportNamedImportAmd_0.ts === + +export var a = 10; +>a : number + +export var x = a; +>x : number +>a : number + +export var m = a; +>m : number +>a : number + +export var a1 = 10; +>a1 : number + +export var x1 = 10; +>x1 : number + +export var z1 = 10; +>z1 : number + +export var z2 = 10; +>z2 : number + +export var aaaa = 10; +>aaaa : number + +=== tests/cases/compiler/es6ImportNamedImportAmd_1.ts === +import { } from "es6ImportNamedImportAmd_0"; +import { a } from "es6ImportNamedImportAmd_0"; +>a : number + +var xxxx = a; +>xxxx : number +>a : number + +import { a as b } from "es6ImportNamedImportAmd_0"; +>a : unknown +>b : number + +var xxxx = b; +>xxxx : number +>b : number + +import { x, a as y } from "es6ImportNamedImportAmd_0"; +>x : number +>a : unknown +>y : number + +var xxxx = x; +>xxxx : number +>x : number + +var xxxx = y; +>xxxx : number +>y : number + +import { x as z, } from "es6ImportNamedImportAmd_0"; +>x : unknown +>z : number + +var xxxx = z; +>xxxx : number +>z : number + +import { m, } from "es6ImportNamedImportAmd_0"; +>m : number + +var xxxx = m; +>xxxx : number +>m : number + +import { a1, x1 } from "es6ImportNamedImportAmd_0"; +>a1 : number +>x1 : number + +var xxxx = a1; +>xxxx : number +>a1 : number + +var xxxx = x1; +>xxxx : number +>x1 : number + +import { a1 as a11, x1 as x11 } from "es6ImportNamedImportAmd_0"; +>a1 : unknown +>a11 : number +>x1 : unknown +>x11 : number + +var xxxx = a11; +>xxxx : number +>a11 : number + +var xxxx = x11; +>xxxx : number +>x11 : number + +import { z1 } from "es6ImportNamedImportAmd_0"; +>z1 : number + +var z111 = z1; +>z111 : number +>z1 : number + +import { z2 as z3 } from "es6ImportNamedImportAmd_0"; +>z2 : unknown +>z3 : number + +var z2 = z3; // z2 shouldn't give redeclare error +>z2 : number +>z3 : number + +// These are elided +import { aaaa } from "es6ImportNamedImportAmd_0"; +>aaaa : number + +// These are elided +import { aaaa as bbbb } from "es6ImportNamedImportAmd_0"; +>aaaa : unknown +>bbbb : number + diff --git a/tests/baselines/reference/es6ImportNamedImportInEs5.js b/tests/baselines/reference/es6ImportNamedImportInEs5.js index 66f8ce0ef9268..79cbafeff2f79 100644 --- a/tests/baselines/reference/es6ImportNamedImportInEs5.js +++ b/tests/baselines/reference/es6ImportNamedImportInEs5.js @@ -7,16 +7,39 @@ export var x = a; export var m = a; export var a1 = 10; export var x1 = 10; +export var z1 = 10; +export var z2 = 10; +export var aaaa = 10; //// [es6ImportNamedImportInEs5_1.ts] import { } from "es6ImportNamedImportInEs5_0"; import { a } from "es6ImportNamedImportInEs5_0"; +var xxxx = a; import { a as b } from "es6ImportNamedImportInEs5_0"; +var xxxx = b; import { x, a as y } from "es6ImportNamedImportInEs5_0"; +var xxxx = x; +var xxxx = y; import { x as z, } from "es6ImportNamedImportInEs5_0"; +var xxxx = z; import { m, } from "es6ImportNamedImportInEs5_0"; +var xxxx = m; import { a1, x1 } from "es6ImportNamedImportInEs5_0"; -import { a1 as a11, x1 as x11 } from "es6ImportNamedImportInEs5_0"; +var xxxx = a1; +var xxxx = x1; +import { a1 as a11, x1 as x11 } from "es6ImportNamedImportInEs5_0"; +var xxxx = a11; +var xxxx = x11; +import { z1 } from "es6ImportNamedImportInEs5_0"; +var z111 = z1; +import { z2 as z3 } from "es6ImportNamedImportInEs5_0"; +var z2 = z3; // z2 shouldn't give redeclare error + +// These are elided +import { aaaa } from "es6ImportNamedImportInEs5_0"; +// These are elided +import { aaaa as bbbb } from "es6ImportNamedImportInEs5_0"; + //// [es6ImportNamedImportInEs5_0.js] exports.a = 10; @@ -24,4 +47,64 @@ exports.x = exports.a; exports.m = exports.a; exports.a1 = 10; exports.x1 = 10; +exports.z1 = 10; +exports.z2 = 10; +exports.aaaa = 10; //// [es6ImportNamedImportInEs5_1.js] +var _a = require("es6ImportNamedImportInEs5_0"); +var a = _a.a; +var xxxx = a; +var _b = require("es6ImportNamedImportInEs5_0"); +var b = _b.a; +var xxxx = b; +var _c = require("es6ImportNamedImportInEs5_0"); +var x = _c.x; +var y = _c.a; +var xxxx = x; +var xxxx = y; +var _d = require("es6ImportNamedImportInEs5_0"); +var z = _d.x; +var xxxx = z; +var _e = require("es6ImportNamedImportInEs5_0"); +var m = _e.m; +var xxxx = m; +var _f = require("es6ImportNamedImportInEs5_0"); +var a1 = _f.a1; +var x1 = _f.x1; +var xxxx = a1; +var xxxx = x1; +var _g = require("es6ImportNamedImportInEs5_0"); +var a11 = _g.a1; +var x11 = _g.x1; +var xxxx = a11; +var xxxx = x11; +var _h = require("es6ImportNamedImportInEs5_0"); +var z1 = _h.z1; +var z111 = z1; +var _j = require("es6ImportNamedImportInEs5_0"); +var z3 = _j.z2; +var z2 = z3; // z2 shouldn't give redeclare error + + +//// [es6ImportNamedImportInEs5_0.d.ts] +export declare var a: number; +export declare var x: number; +export declare var m: number; +export declare var a1: number; +export declare var x1: number; +export declare var z1: number; +export declare var z2: number; +export declare var aaaa: number; +//// [es6ImportNamedImportInEs5_1.d.ts] +import { } from "es6ImportNamedImportInEs5_0"; +import { a } from "es6ImportNamedImportInEs5_0"; +import { a as b } from "es6ImportNamedImportInEs5_0"; +import { x, a as y } from "es6ImportNamedImportInEs5_0"; +import { x as z } from "es6ImportNamedImportInEs5_0"; +import { m } from "es6ImportNamedImportInEs5_0"; +import { a1, x1 } from "es6ImportNamedImportInEs5_0"; +import { a1 as a11, x1 as x11 } from "es6ImportNamedImportInEs5_0"; +import { z1 } from "es6ImportNamedImportInEs5_0"; +import { z2 as z3 } from "es6ImportNamedImportInEs5_0"; +import { aaaa } from "es6ImportNamedImportInEs5_0"; +import { aaaa as bbbb } from "es6ImportNamedImportInEs5_0"; diff --git a/tests/baselines/reference/es6ImportNamedImportInEs5.types b/tests/baselines/reference/es6ImportNamedImportInEs5.types index 4f96b8a4dfad4..217b6e3b17862 100644 --- a/tests/baselines/reference/es6ImportNamedImportInEs5.types +++ b/tests/baselines/reference/es6ImportNamedImportInEs5.types @@ -17,34 +17,107 @@ export var a1 = 10; export var x1 = 10; >x1 : number +export var z1 = 10; +>z1 : number + +export var z2 = 10; +>z2 : number + +export var aaaa = 10; +>aaaa : number + === tests/cases/compiler/es6ImportNamedImportInEs5_1.ts === import { } from "es6ImportNamedImportInEs5_0"; import { a } from "es6ImportNamedImportInEs5_0"; >a : number +var xxxx = a; +>xxxx : number +>a : number + import { a as b } from "es6ImportNamedImportInEs5_0"; >a : unknown >b : number +var xxxx = b; +>xxxx : number +>b : number + import { x, a as y } from "es6ImportNamedImportInEs5_0"; >x : number >a : unknown >y : number +var xxxx = x; +>xxxx : number +>x : number + +var xxxx = y; +>xxxx : number +>y : number + import { x as z, } from "es6ImportNamedImportInEs5_0"; >x : unknown >z : number +var xxxx = z; +>xxxx : number +>z : number + import { m, } from "es6ImportNamedImportInEs5_0"; >m : number +var xxxx = m; +>xxxx : number +>m : number + import { a1, x1 } from "es6ImportNamedImportInEs5_0"; >a1 : number >x1 : number +var xxxx = a1; +>xxxx : number +>a1 : number + +var xxxx = x1; +>xxxx : number +>x1 : number + import { a1 as a11, x1 as x11 } from "es6ImportNamedImportInEs5_0"; >a1 : unknown >a11 : number >x1 : unknown >x11 : number +var xxxx = a11; +>xxxx : number +>a11 : number + +var xxxx = x11; +>xxxx : number +>x11 : number + +import { z1 } from "es6ImportNamedImportInEs5_0"; +>z1 : number + +var z111 = z1; +>z111 : number +>z1 : number + +import { z2 as z3 } from "es6ImportNamedImportInEs5_0"; +>z2 : unknown +>z3 : number + +var z2 = z3; // z2 shouldn't give redeclare error +>z2 : number +>z3 : number + +// These are elided +import { aaaa } from "es6ImportNamedImportInEs5_0"; +>aaaa : number + +// These are elided +import { aaaa as bbbb } from "es6ImportNamedImportInEs5_0"; +>aaaa : unknown +>bbbb : number + diff --git a/tests/baselines/reference/es6ImportNamedImportInExportAssignment.js b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.js new file mode 100644 index 0000000000000..dd79b2f1cfab2 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.js @@ -0,0 +1,16 @@ +//// [tests/cases/compiler/es6ImportNamedImportInExportAssignment.ts] //// + +//// [es6ImportNamedImportInExportAssignment_0.ts] + +export var a = 10; + +//// [es6ImportNamedImportInExportAssignment_1.ts] +import { a } from "es6ImportNamedImportInExportAssignment_0"; +export = a; + +//// [es6ImportNamedImportInExportAssignment_0.js] +exports.a = 10; +//// [es6ImportNamedImportInExportAssignment_1.js] +var _a = require("es6ImportNamedImportInExportAssignment_0"); +var a = _a.a; +module.exports = a; diff --git a/tests/baselines/reference/es6ImportNamedImportInExportAssignment.types b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.types new file mode 100644 index 0000000000000..cd72f35c8bf8b --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.types @@ -0,0 +1,12 @@ +=== tests/cases/compiler/es6ImportNamedImportInExportAssignment_0.ts === + +export var a = 10; +>a : number + +=== tests/cases/compiler/es6ImportNamedImportInExportAssignment_1.ts === +import { a } from "es6ImportNamedImportInExportAssignment_0"; +>a : number + +export = a; +>a : number + diff --git a/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.js b/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.js new file mode 100644 index 0000000000000..982209df18961 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.js @@ -0,0 +1,29 @@ +//// [tests/cases/compiler/es6ImportNamedImportInIndirectExportAssignment.ts] //// + +//// [es6ImportNamedImportInIndirectExportAssignment_0.ts] + +export module a { + export class c { + } +} + +//// [es6ImportNamedImportInIndirectExportAssignment_1.ts] +import { a } from "es6ImportNamedImportInIndirectExportAssignment_0"; +import x = a; +export = x; + +//// [es6ImportNamedImportInIndirectExportAssignment_0.js] +var a; +(function (a) { + var c = (function () { + function c() { + } + return c; + })(); + a.c = c; +})(a = exports.a || (exports.a = {})); +//// [es6ImportNamedImportInIndirectExportAssignment_1.js] +var _a = require("es6ImportNamedImportInIndirectExportAssignment_0"); +var a = _a.a; +var x = a; +module.exports = x; diff --git a/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.types b/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.types new file mode 100644 index 0000000000000..36792ece82e45 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.types @@ -0,0 +1,21 @@ +=== tests/cases/compiler/es6ImportNamedImportInIndirectExportAssignment_0.ts === + +export module a { +>a : typeof a + + export class c { +>c : c + } +} + +=== tests/cases/compiler/es6ImportNamedImportInIndirectExportAssignment_1.ts === +import { a } from "es6ImportNamedImportInIndirectExportAssignment_0"; +>a : typeof a + +import x = a; +>x : typeof a +>a : typeof a + +export = x; +>x : typeof a + diff --git a/tests/baselines/reference/es6ImportNamedImportMergeErrors.errors.txt b/tests/baselines/reference/es6ImportNamedImportMergeErrors.errors.txt new file mode 100644 index 0000000000000..b9461b6caca06 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportMergeErrors.errors.txt @@ -0,0 +1,33 @@ +tests/cases/compiler/es6ImportNamedImportMergeErrors_1.ts(5,10): error TS2440: Import declaration conflicts with local declaration of 'x' +tests/cases/compiler/es6ImportNamedImportMergeErrors_1.ts(7,10): error TS2440: Import declaration conflicts with local declaration of 'x44' +tests/cases/compiler/es6ImportNamedImportMergeErrors_1.ts(9,10): error TS2300: Duplicate identifier 'z'. +tests/cases/compiler/es6ImportNamedImportMergeErrors_1.ts(10,16): error TS2300: Duplicate identifier 'z'. + + +==== tests/cases/compiler/es6ImportNamedImportMergeErrors_0.ts (0 errors) ==== + + export var a = 10; + export var x = a; + export var z = a; + export var z1 = a; + +==== tests/cases/compiler/es6ImportNamedImportMergeErrors_1.ts (4 errors) ==== + import { a } from "es6ImportNamedImportMergeErrors_0"; + interface a { } // shouldnt be error + import { x as x1 } from "es6ImportNamedImportMergeErrors_0"; + interface x1 { } // shouldnt be error + import { x } from "es6ImportNamedImportMergeErrors_0"; // should be error + ~ +!!! error TS2440: Import declaration conflicts with local declaration of 'x' + var x = 10; + import { x as x44 } from "es6ImportNamedImportMergeErrors_0"; // should be error + ~~~~~~~~ +!!! error TS2440: Import declaration conflicts with local declaration of 'x44' + var x44 = 10; + import { z } from "es6ImportNamedImportMergeErrors_0"; // should be error + ~ +!!! error TS2300: Duplicate identifier 'z'. + import { z1 as z } from "es6ImportNamedImportMergeErrors_0"; // should be error + ~ +!!! error TS2300: Duplicate identifier 'z'. + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNamedImportMergeErrors.js b/tests/baselines/reference/es6ImportNamedImportMergeErrors.js new file mode 100644 index 0000000000000..fad411f557d55 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportMergeErrors.js @@ -0,0 +1,30 @@ +//// [tests/cases/compiler/es6ImportNamedImportMergeErrors.ts] //// + +//// [es6ImportNamedImportMergeErrors_0.ts] + +export var a = 10; +export var x = a; +export var z = a; +export var z1 = a; + +//// [es6ImportNamedImportMergeErrors_1.ts] +import { a } from "es6ImportNamedImportMergeErrors_0"; +interface a { } // shouldnt be error +import { x as x1 } from "es6ImportNamedImportMergeErrors_0"; +interface x1 { } // shouldnt be error +import { x } from "es6ImportNamedImportMergeErrors_0"; // should be error +var x = 10; +import { x as x44 } from "es6ImportNamedImportMergeErrors_0"; // should be error +var x44 = 10; +import { z } from "es6ImportNamedImportMergeErrors_0"; // should be error +import { z1 as z } from "es6ImportNamedImportMergeErrors_0"; // should be error + + +//// [es6ImportNamedImportMergeErrors_0.js] +exports.a = 10; +exports.x = exports.a; +exports.z = exports.a; +exports.z1 = exports.a; +//// [es6ImportNamedImportMergeErrors_1.js] +var x = 10; +var x44 = 10; diff --git a/tests/baselines/reference/es6ImportNamedImportNoExportMember.errors.txt b/tests/baselines/reference/es6ImportNamedImportNoExportMember.errors.txt new file mode 100644 index 0000000000000..57a77410cb24b --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportNoExportMember.errors.txt @@ -0,0 +1,16 @@ +tests/cases/compiler/es6ImportNamedImport_1.ts(1,10): error TS2305: Module '"tests/cases/compiler/es6ImportNamedImportNoExportMember_0"' has no exported member 'a1'. +tests/cases/compiler/es6ImportNamedImport_1.ts(2,10): error TS2305: Module '"tests/cases/compiler/es6ImportNamedImportNoExportMember_0"' has no exported member 'x1'. + + +==== tests/cases/compiler/es6ImportNamedImportNoExportMember_0.ts (0 errors) ==== + + export var a = 10; + export var x = a; + +==== tests/cases/compiler/es6ImportNamedImport_1.ts (2 errors) ==== + import { a1 } from "es6ImportNamedImportNoExportMember_0"; + ~~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportNamedImportNoExportMember_0"' has no exported member 'a1'. + import { x1 as x } from "es6ImportNamedImportNoExportMember_0"; + ~~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportNamedImportNoExportMember_0"' has no exported member 'x1'. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNamedImportNoExportMember.js b/tests/baselines/reference/es6ImportNamedImportNoExportMember.js new file mode 100644 index 0000000000000..da473fa42a38d --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportNoExportMember.js @@ -0,0 +1,15 @@ +//// [tests/cases/compiler/es6ImportNamedImportNoExportMember.ts] //// + +//// [es6ImportNamedImportNoExportMember_0.ts] + +export var a = 10; +export var x = a; + +//// [es6ImportNamedImport_1.ts] +import { a1 } from "es6ImportNamedImportNoExportMember_0"; +import { x1 as x } from "es6ImportNamedImportNoExportMember_0"; + +//// [es6ImportNamedImportNoExportMember_0.js] +exports.a = 10; +exports.x = exports.a; +//// [es6ImportNamedImport_1.js] diff --git a/tests/baselines/reference/es6ImportNamedImportNoNamedExports.errors.txt b/tests/baselines/reference/es6ImportNamedImportNoNamedExports.errors.txt new file mode 100644 index 0000000000000..a5abd986ee857 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportNoNamedExports.errors.txt @@ -0,0 +1,16 @@ +tests/cases/compiler/es6ImportNamedImportNoNamedExports_1.ts(1,10): error TS2305: Module '"tests/cases/compiler/es6ImportNamedImportNoNamedExports_0"' has no exported member 'a'. +tests/cases/compiler/es6ImportNamedImportNoNamedExports_1.ts(2,10): error TS2305: Module '"tests/cases/compiler/es6ImportNamedImportNoNamedExports_0"' has no exported member 'a'. + + +==== tests/cases/compiler/es6ImportNamedImportNoNamedExports_0.ts (0 errors) ==== + + var a = 10; + export = a; + +==== tests/cases/compiler/es6ImportNamedImportNoNamedExports_1.ts (2 errors) ==== + import { a } from "es6ImportNamedImportNoNamedExports_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportNamedImportNoNamedExports_0"' has no exported member 'a'. + import { a as x } from "es6ImportNamedImportNoNamedExports_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportNamedImportNoNamedExports_0"' has no exported member 'a'. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNamedImportNoNamedExports.js b/tests/baselines/reference/es6ImportNamedImportNoNamedExports.js new file mode 100644 index 0000000000000..524860827e6e8 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportNoNamedExports.js @@ -0,0 +1,15 @@ +//// [tests/cases/compiler/es6ImportNamedImportNoNamedExports.ts] //// + +//// [es6ImportNamedImportNoNamedExports_0.ts] + +var a = 10; +export = a; + +//// [es6ImportNamedImportNoNamedExports_1.ts] +import { a } from "es6ImportNamedImportNoNamedExports_0"; +import { a as x } from "es6ImportNamedImportNoNamedExports_0"; + +//// [es6ImportNamedImportNoNamedExports_0.js] +var a = 10; +module.exports = a; +//// [es6ImportNamedImportNoNamedExports_1.js] diff --git a/tests/cases/compiler/es6ImportNamedImport.ts b/tests/cases/compiler/es6ImportNamedImport.ts index ed34434bd292c..0a12e10169bd0 100644 --- a/tests/cases/compiler/es6ImportNamedImport.ts +++ b/tests/cases/compiler/es6ImportNamedImport.ts @@ -1,5 +1,6 @@ // @target: es6 // @module: commonjs +// @declaration: true // @filename: es6ImportNamedImport_0.ts export var a = 10; @@ -7,13 +8,35 @@ export var x = a; export var m = a; export var a1 = 10; export var x1 = 10; +export var z1 = 10; +export var z2 = 10; +export var aaaa = 10; // @filename: es6ImportNamedImport_1.ts import { } from "es6ImportNamedImport_0"; import { a } from "es6ImportNamedImport_0"; +var xxxx = a; import { a as b } from "es6ImportNamedImport_0"; +var xxxx = b; import { x, a as y } from "es6ImportNamedImport_0"; +var xxxx = x; +var xxxx = y; import { x as z, } from "es6ImportNamedImport_0"; +var xxxx = z; import { m, } from "es6ImportNamedImport_0"; +var xxxx = m; import { a1, x1 } from "es6ImportNamedImport_0"; -import { a1 as a11, x1 as x11 } from "es6ImportNamedImport_0"; \ No newline at end of file +var xxxx = a1; +var xxxx = x1; +import { a1 as a11, x1 as x11 } from "es6ImportNamedImport_0"; +var xxxx = a11; +var xxxx = x11; +import { z1 } from "es6ImportNamedImport_0"; +var z111 = z1; +import { z2 as z3 } from "es6ImportNamedImport_0"; +var z2 = z3; // z2 shouldn't give redeclare error + +// These are elided +import { aaaa } from "es6ImportNamedImport_0"; +// These are elided +import { aaaa as bbbb } from "es6ImportNamedImport_0"; diff --git a/tests/cases/compiler/es6ImportNamedImportAmd.ts b/tests/cases/compiler/es6ImportNamedImportAmd.ts new file mode 100644 index 0000000000000..3ddf1a4cf5219 --- /dev/null +++ b/tests/cases/compiler/es6ImportNamedImportAmd.ts @@ -0,0 +1,41 @@ +// @module: amd +// @declaration: true + +// @filename: es6ImportNamedImportAmd_0.ts +export var a = 10; +export var x = a; +export var m = a; +export var a1 = 10; +export var x1 = 10; +export var z1 = 10; +export var z2 = 10; +export var aaaa = 10; + +// @filename: es6ImportNamedImportAmd_1.ts +import { } from "es6ImportNamedImportAmd_0"; +import { a } from "es6ImportNamedImportAmd_0"; +var xxxx = a; +import { a as b } from "es6ImportNamedImportAmd_0"; +var xxxx = b; +import { x, a as y } from "es6ImportNamedImportAmd_0"; +var xxxx = x; +var xxxx = y; +import { x as z, } from "es6ImportNamedImportAmd_0"; +var xxxx = z; +import { m, } from "es6ImportNamedImportAmd_0"; +var xxxx = m; +import { a1, x1 } from "es6ImportNamedImportAmd_0"; +var xxxx = a1; +var xxxx = x1; +import { a1 as a11, x1 as x11 } from "es6ImportNamedImportAmd_0"; +var xxxx = a11; +var xxxx = x11; +import { z1 } from "es6ImportNamedImportAmd_0"; +var z111 = z1; +import { z2 as z3 } from "es6ImportNamedImportAmd_0"; +var z2 = z3; // z2 shouldn't give redeclare error + +// These are elided +import { aaaa } from "es6ImportNamedImportAmd_0"; +// These are elided +import { aaaa as bbbb } from "es6ImportNamedImportAmd_0"; diff --git a/tests/cases/compiler/es6ImportNamedImportInEs5.ts b/tests/cases/compiler/es6ImportNamedImportInEs5.ts index 22e66bc95fa42..e12a8d032d3d3 100644 --- a/tests/cases/compiler/es6ImportNamedImportInEs5.ts +++ b/tests/cases/compiler/es6ImportNamedImportInEs5.ts @@ -1,5 +1,6 @@ // @target: es5 // @module: commonjs +// @declaration: true // @filename: es6ImportNamedImportInEs5_0.ts export var a = 10; @@ -7,13 +8,35 @@ export var x = a; export var m = a; export var a1 = 10; export var x1 = 10; +export var z1 = 10; +export var z2 = 10; +export var aaaa = 10; // @filename: es6ImportNamedImportInEs5_1.ts import { } from "es6ImportNamedImportInEs5_0"; import { a } from "es6ImportNamedImportInEs5_0"; +var xxxx = a; import { a as b } from "es6ImportNamedImportInEs5_0"; +var xxxx = b; import { x, a as y } from "es6ImportNamedImportInEs5_0"; +var xxxx = x; +var xxxx = y; import { x as z, } from "es6ImportNamedImportInEs5_0"; +var xxxx = z; import { m, } from "es6ImportNamedImportInEs5_0"; +var xxxx = m; import { a1, x1 } from "es6ImportNamedImportInEs5_0"; -import { a1 as a11, x1 as x11 } from "es6ImportNamedImportInEs5_0"; \ No newline at end of file +var xxxx = a1; +var xxxx = x1; +import { a1 as a11, x1 as x11 } from "es6ImportNamedImportInEs5_0"; +var xxxx = a11; +var xxxx = x11; +import { z1 } from "es6ImportNamedImportInEs5_0"; +var z111 = z1; +import { z2 as z3 } from "es6ImportNamedImportInEs5_0"; +var z2 = z3; // z2 shouldn't give redeclare error + +// These are elided +import { aaaa } from "es6ImportNamedImportInEs5_0"; +// These are elided +import { aaaa as bbbb } from "es6ImportNamedImportInEs5_0"; diff --git a/tests/cases/compiler/es6ImportNamedImportInExportAssignment.ts b/tests/cases/compiler/es6ImportNamedImportInExportAssignment.ts new file mode 100644 index 0000000000000..9976f20f0800c --- /dev/null +++ b/tests/cases/compiler/es6ImportNamedImportInExportAssignment.ts @@ -0,0 +1,9 @@ +// @target: es6 +// @module: commonjs + +// @filename: es6ImportNamedImportInExportAssignment_0.ts +export var a = 10; + +// @filename: es6ImportNamedImportInExportAssignment_1.ts +import { a } from "es6ImportNamedImportInExportAssignment_0"; +export = a; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportNamedImportInIndirectExportAssignment.ts b/tests/cases/compiler/es6ImportNamedImportInIndirectExportAssignment.ts new file mode 100644 index 0000000000000..c9e85bbbd6527 --- /dev/null +++ b/tests/cases/compiler/es6ImportNamedImportInIndirectExportAssignment.ts @@ -0,0 +1,13 @@ +// @target: es6 +// @module: commonjs + +// @filename: es6ImportNamedImportInIndirectExportAssignment_0.ts +export module a { + export class c { + } +} + +// @filename: es6ImportNamedImportInIndirectExportAssignment_1.ts +import { a } from "es6ImportNamedImportInIndirectExportAssignment_0"; +import x = a; +export = x; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportNamedImportMergeErrors.ts b/tests/cases/compiler/es6ImportNamedImportMergeErrors.ts new file mode 100644 index 0000000000000..950554b971d87 --- /dev/null +++ b/tests/cases/compiler/es6ImportNamedImportMergeErrors.ts @@ -0,0 +1,20 @@ +// @target: es6 +// @module: commonjs + +// @filename: es6ImportNamedImportMergeErrors_0.ts +export var a = 10; +export var x = a; +export var z = a; +export var z1 = a; + +// @filename: es6ImportNamedImportMergeErrors_1.ts +import { a } from "es6ImportNamedImportMergeErrors_0"; +interface a { } // shouldnt be error +import { x as x1 } from "es6ImportNamedImportMergeErrors_0"; +interface x1 { } // shouldnt be error +import { x } from "es6ImportNamedImportMergeErrors_0"; // should be error +var x = 10; +import { x as x44 } from "es6ImportNamedImportMergeErrors_0"; // should be error +var x44 = 10; +import { z } from "es6ImportNamedImportMergeErrors_0"; // should be error +import { z1 as z } from "es6ImportNamedImportMergeErrors_0"; // should be error diff --git a/tests/cases/compiler/es6ImportNamedImportNoExportMember.ts b/tests/cases/compiler/es6ImportNamedImportNoExportMember.ts new file mode 100644 index 0000000000000..2dcb2364660fd --- /dev/null +++ b/tests/cases/compiler/es6ImportNamedImportNoExportMember.ts @@ -0,0 +1,10 @@ +// @target: es6 +// @module: commonjs + +// @filename: es6ImportNamedImportNoExportMember_0.ts +export var a = 10; +export var x = a; + +// @filename: es6ImportNamedImport_1.ts +import { a1 } from "es6ImportNamedImportNoExportMember_0"; +import { x1 as x } from "es6ImportNamedImportNoExportMember_0"; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportNamedImportNoNamedExports.ts b/tests/cases/compiler/es6ImportNamedImportNoNamedExports.ts new file mode 100644 index 0000000000000..a51d70ad50ee2 --- /dev/null +++ b/tests/cases/compiler/es6ImportNamedImportNoNamedExports.ts @@ -0,0 +1,10 @@ +// @target: es6 +// @module: commonjs + +// @filename: es6ImportNamedImportNoNamedExports_0.ts +var a = 10; +export = a; + +// @filename: es6ImportNamedImportNoNamedExports_1.ts +import { a } from "es6ImportNamedImportNoNamedExports_0"; +import { a as x } from "es6ImportNamedImportNoNamedExports_0"; \ No newline at end of file From 05fcdf0e30e2781f358ffc1399d6c4a87b7d3e2b Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 10 Feb 2015 15:39:24 -0800 Subject: [PATCH 004/224] Declaration for default bindings of the import syntax --- src/compiler/emitter.ts | 7 +++ .../es6ImportDefaultBinding.errors.txt | 11 ---- .../reference/es6ImportDefaultBinding.js | 21 ++++++- .../reference/es6ImportDefaultBinding.types | 19 +++++++ .../reference/es6ImportDefaultBindingAmd.js | 30 ++++++++++ .../es6ImportDefaultBindingAmd.types | 19 +++++++ ...tBindingFollowedWithNamedImport.errors.txt | 55 ++++++++----------- ...rtDefaultBindingFollowedWithNamedImport.js | 43 +++++++++++++-- ...BindingFollowedWithNamedImport1.errors.txt | 39 +++++++++++++ ...tDefaultBindingFollowedWithNamedImport1.js | 50 +++++++++++++++++ ...ngFollowedWithNamedImport1InEs5.errors.txt | 39 +++++++++++++ ...ultBindingFollowedWithNamedImport1InEs5.js | 50 +++++++++++++++++ ...ingFollowedWithNamedImportInEs5.errors.txt | 55 ++++++++----------- ...aultBindingFollowedWithNamedImportInEs5.js | 43 +++++++++++++-- ...ingFollowedWithNamespaceBinding.errors.txt | 3 +- ...aultBindingFollowedWithNamespaceBinding.js | 11 +++- ...ultBindingFollowedWithNamespaceBinding1.js | 24 ++++++++ ...BindingFollowedWithNamespaceBinding1.types | 17 ++++++ ...ndingFollowedWithNamespaceBinding1InEs5.js | 24 ++++++++ ...ngFollowedWithNamespaceBinding1InEs5.types | 17 ++++++ ...llowedWithNamespaceBindingInEs5.errors.txt | 3 +- ...indingFollowedWithNamespaceBindingInEs5.js | 11 +++- .../es6ImportDefaultBindingInEs5.errors.txt | 11 ---- .../reference/es6ImportDefaultBindingInEs5.js | 13 ++++- .../es6ImportDefaultBindingInEs5.types | 12 ++++ ...ImportDefaultBindingMergeErrors.errors.txt | 26 +++++++++ .../es6ImportDefaultBindingMergeErrors.js | 25 +++++++++ ...DefaultBindingNoDefaultProperty.errors.txt | 12 ++++ ...s6ImportDefaultBindingNoDefaultProperty.js | 13 +++++ .../cases/compiler/es6ImportDefaultBinding.ts | 8 ++- .../compiler/es6ImportDefaultBindingAmd.ts | 11 ++++ ...rtDefaultBindingFollowedWithNamedImport.ts | 19 +++++-- ...tDefaultBindingFollowedWithNamedImport1.ts | 21 +++++++ ...ultBindingFollowedWithNamedImport1InEs5.ts | 21 +++++++ ...aultBindingFollowedWithNamedImportInEs5.ts | 19 +++++-- ...aultBindingFollowedWithNamespaceBinding.ts | 4 +- ...ultBindingFollowedWithNamespaceBinding1.ts | 11 ++++ ...ndingFollowedWithNamespaceBinding1InEs5.ts | 11 ++++ ...indingFollowedWithNamespaceBindingInEs5.ts | 4 +- .../compiler/es6ImportDefaultBindingInEs5.ts | 4 +- .../es6ImportDefaultBindingMergeErrors.ts | 16 ++++++ ...s6ImportDefaultBindingNoDefaultProperty.ts | 8 +++ 42 files changed, 734 insertions(+), 126 deletions(-) delete mode 100644 tests/baselines/reference/es6ImportDefaultBinding.errors.txt create mode 100644 tests/baselines/reference/es6ImportDefaultBinding.types create mode 100644 tests/baselines/reference/es6ImportDefaultBindingAmd.js create mode 100644 tests/baselines/reference/es6ImportDefaultBindingAmd.types create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.errors.txt create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.js create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.errors.txt create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.js create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.js create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.types create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.js create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.types delete mode 100644 tests/baselines/reference/es6ImportDefaultBindingInEs5.errors.txt create mode 100644 tests/baselines/reference/es6ImportDefaultBindingInEs5.types create mode 100644 tests/baselines/reference/es6ImportDefaultBindingMergeErrors.errors.txt create mode 100644 tests/baselines/reference/es6ImportDefaultBindingMergeErrors.js create mode 100644 tests/baselines/reference/es6ImportDefaultBindingNoDefaultProperty.errors.txt create mode 100644 tests/baselines/reference/es6ImportDefaultBindingNoDefaultProperty.js create mode 100644 tests/cases/compiler/es6ImportDefaultBindingAmd.ts create mode 100644 tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1.ts create mode 100644 tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.ts create mode 100644 tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1.ts create mode 100644 tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.ts create mode 100644 tests/cases/compiler/es6ImportDefaultBindingMergeErrors.ts create mode 100644 tests/cases/compiler/es6ImportDefaultBindingNoDefaultProperty.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 60cde0743d070..000c0d0e81f1f 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -774,6 +774,13 @@ module ts { } write("import "); if (node.importClause) { + if (node.importClause.name) { + writeTextOfNode(currentSourceFile, node.importClause.name); + if (node.importClause.namedBindings) { + write(","); + } + write(" "); + } if (node.importClause.namedBindings) { if (node.importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { write("* as "); diff --git a/tests/baselines/reference/es6ImportDefaultBinding.errors.txt b/tests/baselines/reference/es6ImportDefaultBinding.errors.txt deleted file mode 100644 index 3f69c2d7de9ea..0000000000000 --- a/tests/baselines/reference/es6ImportDefaultBinding.errors.txt +++ /dev/null @@ -1,11 +0,0 @@ -tests/cases/compiler/es6ImportDefaultBinding_1.ts(1,8): error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBinding_0"' has no default export or export assignment. - - -==== tests/cases/compiler/es6ImportDefaultBinding_0.ts (0 errors) ==== - - export var a = 10; - -==== tests/cases/compiler/es6ImportDefaultBinding_1.ts (1 errors) ==== - import defaultBinding from "es6ImportDefaultBinding_0"; - ~~~~~~~~~~~~~~ -!!! error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBinding_0"' has no default export or export assignment. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBinding.js b/tests/baselines/reference/es6ImportDefaultBinding.js index d8d1fa8111dc3..d1e69585ba4e1 100644 --- a/tests/baselines/reference/es6ImportDefaultBinding.js +++ b/tests/baselines/reference/es6ImportDefaultBinding.js @@ -2,11 +2,26 @@ //// [es6ImportDefaultBinding_0.ts] -export var a = 10; +var a = 10; +export = a; //// [es6ImportDefaultBinding_1.ts] -import defaultBinding from "es6ImportDefaultBinding_0"; +import defaultBinding from "es6ImportDefaultBinding_0"; +var x = defaultBinding; +import defaultBinding2 from "es6ImportDefaultBinding_0"; // elide this import since defaultBinding2 is not used + //// [es6ImportDefaultBinding_0.js] -exports.a = 10; +var a = 10; +module.exports = a; //// [es6ImportDefaultBinding_1.js] +var defaultBinding = require("es6ImportDefaultBinding_0"); +var x = defaultBinding; + + +//// [es6ImportDefaultBinding_0.d.ts] +declare var a: number; +export = a; +//// [es6ImportDefaultBinding_1.d.ts] +import defaultBinding from "es6ImportDefaultBinding_0"; +import defaultBinding2 from "es6ImportDefaultBinding_0"; diff --git a/tests/baselines/reference/es6ImportDefaultBinding.types b/tests/baselines/reference/es6ImportDefaultBinding.types new file mode 100644 index 0000000000000..588940250fe75 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBinding.types @@ -0,0 +1,19 @@ +=== tests/cases/compiler/es6ImportDefaultBinding_0.ts === + +var a = 10; +>a : number + +export = a; +>a : number + +=== tests/cases/compiler/es6ImportDefaultBinding_1.ts === +import defaultBinding from "es6ImportDefaultBinding_0"; +>defaultBinding : number + +var x = defaultBinding; +>x : number +>defaultBinding : number + +import defaultBinding2 from "es6ImportDefaultBinding_0"; // elide this import since defaultBinding2 is not used +>defaultBinding2 : number + diff --git a/tests/baselines/reference/es6ImportDefaultBindingAmd.js b/tests/baselines/reference/es6ImportDefaultBindingAmd.js new file mode 100644 index 0000000000000..24e8ee047b87a --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingAmd.js @@ -0,0 +1,30 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingAmd.ts] //// + +//// [es6ImportDefaultBindingAmd_0.ts] + +var a = 10; +export = a; + +//// [es6ImportDefaultBindingAmd_1.ts] +import defaultBinding from "es6ImportDefaultBindingAmd_0"; +var x = defaultBinding; +import defaultBinding2 from "es6ImportDefaultBindingAmd_0"; // elide this import since defaultBinding2 is not used + + +//// [es6ImportDefaultBindingAmd_0.js] +define(["require", "exports"], function (require, exports) { + var a = 10; + return a; +}); +//// [es6ImportDefaultBindingAmd_1.js] +define(["require", "exports", "es6ImportDefaultBindingAmd_0"], function (require, exports, defaultBinding) { + var x = defaultBinding; +}); + + +//// [es6ImportDefaultBindingAmd_0.d.ts] +declare var a: number; +export = a; +//// [es6ImportDefaultBindingAmd_1.d.ts] +import defaultBinding from "es6ImportDefaultBindingAmd_0"; +import defaultBinding2 from "es6ImportDefaultBindingAmd_0"; diff --git a/tests/baselines/reference/es6ImportDefaultBindingAmd.types b/tests/baselines/reference/es6ImportDefaultBindingAmd.types new file mode 100644 index 0000000000000..9b067ef27a405 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingAmd.types @@ -0,0 +1,19 @@ +=== tests/cases/compiler/es6ImportDefaultBindingAmd_0.ts === + +var a = 10; +>a : number + +export = a; +>a : number + +=== tests/cases/compiler/es6ImportDefaultBindingAmd_1.ts === +import defaultBinding from "es6ImportDefaultBindingAmd_0"; +>defaultBinding : number + +var x = defaultBinding; +>x : number +>defaultBinding : number + +import defaultBinding2 from "es6ImportDefaultBindingAmd_0"; // elide this import since defaultBinding2 is not used +>defaultBinding2 : number + diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt index 5fc8e8f905812..1a45788819b93 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt @@ -1,15 +1,9 @@ tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(1,8): error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(1,8): error TS2300: Duplicate identifier 'defaultBinding'. tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(2,8): error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(2,8): error TS2300: Duplicate identifier 'defaultBinding'. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(3,8): error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(3,8): error TS2300: Duplicate identifier 'defaultBinding'. tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(4,8): error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(4,8): error TS2300: Duplicate identifier 'defaultBinding'. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(5,8): error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(5,8): error TS2300: Duplicate identifier 'defaultBinding'. tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(6,8): error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(6,8): error TS2300: Duplicate identifier 'defaultBinding'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(9,8): error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(11,8): error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. ==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0.ts (0 errors) ==== @@ -18,34 +12,29 @@ tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(6,8): e export var x = a; export var m = a; -==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts (12 errors) ==== - import defaultBinding, { } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; - ~~~~~~~~~~~~~~ +==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts (6 errors) ==== + import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; + ~~~~~~~~~~~~~~~ !!! error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. - import defaultBinding, { a } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; - ~~~~~~~~~~~~~~ + import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; + ~~~~~~~~~~~~~~~ !!! error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. - import defaultBinding, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; - ~~~~~~~~~~~~~~ + var x1: number = a; + import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; + ~~~~~~~~~~~~~~~ !!! error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. - import defaultBinding, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; - ~~~~~~~~~~~~~~ + var x1: number = b; + import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; + ~~~~~~~~~~~~~~~ !!! error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. - import defaultBinding, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; - ~~~~~~~~~~~~~~ + var x1: number = x; + var x1: number = y; + import defaultBinding5, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; + ~~~~~~~~~~~~~~~ !!! error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. - import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; - ~~~~~~~~~~~~~~ + var x1: number = z; + import defaultBinding6, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; + ~~~~~~~~~~~~~~~ !!! error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. \ No newline at end of file + var x1: number = m; + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js index a7402bfeb6a8e..48fb54151ba0a 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js @@ -7,15 +7,46 @@ export var x = a; export var m = a; //// [es6ImportDefaultBindingFollowedWithNamedImport_1.ts] -import defaultBinding, { } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -import defaultBinding, { a } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -import defaultBinding, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -import defaultBinding, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -import defaultBinding, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1: number = a; +import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1: number = b; +import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1: number = x; +var x1: number = y; +import defaultBinding5, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1: number = z; +import defaultBinding6, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1: number = m; + //// [es6ImportDefaultBindingFollowedWithNamedImport_0.js] exports.a = 10; exports.x = exports.a; exports.m = exports.a; //// [es6ImportDefaultBindingFollowedWithNamedImport_1.js] +var defaultBinding2 = require("es6ImportDefaultBindingFollowedWithNamedImport_0"); +var x1 = a; +var defaultBinding3 = require("es6ImportDefaultBindingFollowedWithNamedImport_0"); +var x1 = b; +var defaultBinding4 = require("es6ImportDefaultBindingFollowedWithNamedImport_0"); +var x1 = x; +var x1 = y; +var defaultBinding5 = require("es6ImportDefaultBindingFollowedWithNamedImport_0"); +var x1 = z; +var defaultBinding6 = require("es6ImportDefaultBindingFollowedWithNamedImport_0"); +var x1 = m; + + +//// [es6ImportDefaultBindingFollowedWithNamedImport_0.d.ts] +export declare var a: number; +export declare var x: number; +export declare var m: number; +//// [es6ImportDefaultBindingFollowedWithNamedImport_1.d.ts] +import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +import defaultBinding5, { x as z } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +import defaultBinding6, { m } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.errors.txt new file mode 100644 index 0000000000000..bdf2841ab0802 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.errors.txt @@ -0,0 +1,39 @@ +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_1.ts(3,27): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'a'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_1.ts(5,27): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'a'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_1.ts(7,27): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'x'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_1.ts(7,30): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'a'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_1.ts(9,27): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'x'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_1.ts(11,27): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'm'. + + +==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0.ts (0 errors) ==== + + var a = 10; + export = a; + +==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_1.ts (6 errors) ==== + import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; + var x1: number = defaultBinding1; + import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'a'. + var x1: number = defaultBinding2; + import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'a'. + var x1: number = defaultBinding3; + import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'x'. + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'a'. + var x1: number = defaultBinding4; + import defaultBinding5, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'x'. + var x1: number = defaultBinding5; + import defaultBinding6, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'm'. + var x1: number = defaultBinding6; + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.js new file mode 100644 index 0000000000000..451e2df15b624 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.js @@ -0,0 +1,50 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1.ts] //// + +//// [es6ImportDefaultBindingFollowedWithNamedImport1_0.ts] + +var a = 10; +export = a; + +//// [es6ImportDefaultBindingFollowedWithNamedImport1_1.ts] +import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding1; +import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding2; +import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding3; +import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding4; +import defaultBinding5, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding5; +import defaultBinding6, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding6; + + +//// [es6ImportDefaultBindingFollowedWithNamedImport1_0.js] +var a = 10; +module.exports = a; +//// [es6ImportDefaultBindingFollowedWithNamedImport1_1.js] +var defaultBinding1 = require("es6ImportDefaultBindingFollowedWithNamedImport1_0"); +var x1 = defaultBinding1; +var defaultBinding2 = require("es6ImportDefaultBindingFollowedWithNamedImport1_0"); +var x1 = defaultBinding2; +var defaultBinding3 = require("es6ImportDefaultBindingFollowedWithNamedImport1_0"); +var x1 = defaultBinding3; +var defaultBinding4 = require("es6ImportDefaultBindingFollowedWithNamedImport1_0"); +var x1 = defaultBinding4; +var defaultBinding5 = require("es6ImportDefaultBindingFollowedWithNamedImport1_0"); +var x1 = defaultBinding5; +var defaultBinding6 = require("es6ImportDefaultBindingFollowedWithNamedImport1_0"); +var x1 = defaultBinding6; + + +//// [es6ImportDefaultBindingFollowedWithNamedImport1_0.d.ts] +declare var a: number; +export = a; +//// [es6ImportDefaultBindingFollowedWithNamedImport1_1.d.ts] +import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +import defaultBinding5, { x as z } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +import defaultBinding6, { m } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.errors.txt new file mode 100644 index 0000000000000..9783ad4921e10 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.errors.txt @@ -0,0 +1,39 @@ +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.ts(3,27): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'a'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.ts(5,27): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'a'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.ts(7,27): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'x'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.ts(7,30): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'a'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.ts(9,27): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'x'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.ts(11,27): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'm'. + + +==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0.ts (0 errors) ==== + + var a = 10; + export = a; + +==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.ts (6 errors) ==== + import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; + var x: number = defaultBinding1; + import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'a'. + var x: number = defaultBinding2; + import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'a'. + var x: number = defaultBinding3; + import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'x'. + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'a'. + var x: number = defaultBinding4; + import defaultBinding5, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'x'. + var x: number = defaultBinding5; + import defaultBinding6, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"' has no exported member 'm'. + var x: number = defaultBinding6; + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.js new file mode 100644 index 0000000000000..323650fe205fd --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.js @@ -0,0 +1,50 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.ts] //// + +//// [es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0.ts] + +var a = 10; +export = a; + +//// [es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.ts] +import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; +var x: number = defaultBinding1; +import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; +var x: number = defaultBinding2; +import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; +var x: number = defaultBinding3; +import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; +var x: number = defaultBinding4; +import defaultBinding5, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; +var x: number = defaultBinding5; +import defaultBinding6, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; +var x: number = defaultBinding6; + + +//// [es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0.js] +var a = 10; +module.exports = a; +//// [es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.js] +var defaultBinding1 = require("es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"); +var x = defaultBinding1; +var defaultBinding2 = require("es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"); +var x = defaultBinding2; +var defaultBinding3 = require("es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"); +var x = defaultBinding3; +var defaultBinding4 = require("es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"); +var x = defaultBinding4; +var defaultBinding5 = require("es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"); +var x = defaultBinding5; +var defaultBinding6 = require("es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"); +var x = defaultBinding6; + + +//// [es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0.d.ts] +declare var a: number; +export = a; +//// [es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.d.ts] +import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; +import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; +import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; +import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; +import defaultBinding5, { x as z } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; +import defaultBinding6, { m } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.errors.txt index dc079cac8f7bf..2e25d60ce13a1 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.errors.txt +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.errors.txt @@ -1,15 +1,9 @@ tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(1,8): error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(1,8): error TS2300: Duplicate identifier 'defaultBinding'. tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(2,8): error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(2,8): error TS2300: Duplicate identifier 'defaultBinding'. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(3,8): error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(3,8): error TS2300: Duplicate identifier 'defaultBinding'. tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(4,8): error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(4,8): error TS2300: Duplicate identifier 'defaultBinding'. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(5,8): error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(5,8): error TS2300: Duplicate identifier 'defaultBinding'. tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(6,8): error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. -tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(6,8): error TS2300: Duplicate identifier 'defaultBinding'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(9,8): error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(11,8): error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. ==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0.ts (0 errors) ==== @@ -18,34 +12,29 @@ tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts(6, export var x = a; export var m = a; -==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts (12 errors) ==== - import defaultBinding, { } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; - ~~~~~~~~~~~~~~ +==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts (6 errors) ==== + import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; + ~~~~~~~~~~~~~~~ !!! error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. - import defaultBinding, { a } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; - ~~~~~~~~~~~~~~ + import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; + ~~~~~~~~~~~~~~~ !!! error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. - import defaultBinding, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; - ~~~~~~~~~~~~~~ + var x1: number = a; + import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; + ~~~~~~~~~~~~~~~ !!! error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. - import defaultBinding, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; - ~~~~~~~~~~~~~~ + var x1: number = b; + import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; + ~~~~~~~~~~~~~~~ !!! error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. - import defaultBinding, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; - ~~~~~~~~~~~~~~ + var x1: number = x; + var x1: number = y; + import defaultBinding5, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; + ~~~~~~~~~~~~~~~ !!! error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. - import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; - ~~~~~~~~~~~~~~ + var x1: number = z; + import defaultBinding6, { m, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; + ~~~~~~~~~~~~~~~ !!! error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"' has no default export or export assignment. - ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. \ No newline at end of file + var x1: number = m; + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.js index 4cf3046532a0a..5b211b9fcea6e 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.js @@ -7,15 +7,46 @@ export var x = a; export var m = a; //// [es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts] -import defaultBinding, { } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; -import defaultBinding, { a } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; -import defaultBinding, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; -import defaultBinding, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; -import defaultBinding, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; -import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +var x1: number = a; +import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +var x1: number = b; +import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +var x1: number = x; +var x1: number = y; +import defaultBinding5, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +var x1: number = z; +import defaultBinding6, { m, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +var x1: number = m; + //// [es6ImportDefaultBindingFollowedWithNamedImportInEs5_0.js] exports.a = 10; exports.x = exports.a; exports.m = exports.a; //// [es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.js] +var defaultBinding2 = require("es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"); +var x1 = a; +var defaultBinding3 = require("es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"); +var x1 = b; +var defaultBinding4 = require("es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"); +var x1 = x; +var x1 = y; +var defaultBinding5 = require("es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"); +var x1 = z; +var defaultBinding6 = require("es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"); +var x1 = m; + + +//// [es6ImportDefaultBindingFollowedWithNamedImportInEs5_0.d.ts] +export declare var a: number; +export declare var x: number; +export declare var m: number; +//// [es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.d.ts] +import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +import defaultBinding5, { x as z } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +import defaultBinding6, { m } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.errors.txt index c270b9bdd69b7..6295064b81ced 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.errors.txt +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.errors.txt @@ -8,4 +8,5 @@ tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_1.ts(1, ==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_1.ts (1 errors) ==== import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; ~~~~~~~~~~~~~~ -!!! error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_0"' has no default export or export assignment. \ No newline at end of file +!!! error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_0"' has no default export or export assignment. + var x: number = nameSpaceBinding.a; \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js index 5ec91279306dd..948c033f7def8 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js @@ -5,8 +5,17 @@ export var a = 10; //// [es6ImportDefaultBindingFollowedWithNamespaceBinding_1.ts] -import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; +var x: number = nameSpaceBinding.a; //// [es6ImportDefaultBindingFollowedWithNamespaceBinding_0.js] exports.a = 10; //// [es6ImportDefaultBindingFollowedWithNamespaceBinding_1.js] +var defaultBinding = require("es6ImportDefaultBindingFollowedWithNamespaceBinding_0"); +var x = nameSpaceBinding.a; + + +//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_0.d.ts] +export declare var a: number; +//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_1.d.ts] +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.js new file mode 100644 index 0000000000000..86869e052fe1f --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.js @@ -0,0 +1,24 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1.ts] //// + +//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_0.ts] + +var a = 10; +export = a; + +//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_1.ts] +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; +var x: number = defaultBinding; + +//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_0.js] +var a = 10; +module.exports = a; +//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_1.js] +var defaultBinding = require("es6ImportDefaultBindingFollowedWithNamespaceBinding_0"); +var x = defaultBinding; + + +//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_0.d.ts] +declare var a: number; +export = a; +//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_1.d.ts] +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.types b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.types new file mode 100644 index 0000000000000..ef6c7ac322184 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.types @@ -0,0 +1,17 @@ +=== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_0.ts === + +var a = 10; +>a : number + +export = a; +>a : number + +=== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_1.ts === +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; +>defaultBinding : number +>nameSpaceBinding : typeof nameSpaceBinding + +var x: number = defaultBinding; +>x : number +>defaultBinding : number + diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.js new file mode 100644 index 0000000000000..1052970fa99ff --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.js @@ -0,0 +1,24 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.ts] //// + +//// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.ts] + +var a = 10; +export = a; + +//// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.ts] +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"; +var x: number = defaultBinding; + +//// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.js] +var a = 10; +module.exports = a; +//// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.js] +var defaultBinding = require("es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"); +var x = defaultBinding; + + +//// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.d.ts] +declare var a: number; +export = a; +//// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.d.ts] +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.types b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.types new file mode 100644 index 0000000000000..dfbc8c0be07ce --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.types @@ -0,0 +1,17 @@ +=== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.ts === + +var a = 10; +>a : number + +export = a; +>a : number + +=== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.ts === +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"; +>defaultBinding : number +>nameSpaceBinding : typeof nameSpaceBinding + +var x: number = defaultBinding; +>x : number +>defaultBinding : number + diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.errors.txt index 37424bc7bd81a..d0a28bb0c47d3 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.errors.txt +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.errors.txt @@ -8,4 +8,5 @@ tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1. ==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.ts (1 errors) ==== import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"; ~~~~~~~~~~~~~~ -!!! error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"' has no default export or export assignment. \ No newline at end of file +!!! error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"' has no default export or export assignment. + var x: number = nameSpaceBinding.a; \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.js index abd4736fca706..5419ac20928fd 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.js @@ -5,8 +5,17 @@ export var a = 10; //// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.ts] -import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"; +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"; +var x: number = nameSpaceBinding.a; //// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.js] exports.a = 10; //// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.js] +var defaultBinding = require("es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"); +var x = nameSpaceBinding.a; + + +//// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.d.ts] +export declare var a: number; +//// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.d.ts] +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"; diff --git a/tests/baselines/reference/es6ImportDefaultBindingInEs5.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingInEs5.errors.txt deleted file mode 100644 index 34439fa91c1be..0000000000000 --- a/tests/baselines/reference/es6ImportDefaultBindingInEs5.errors.txt +++ /dev/null @@ -1,11 +0,0 @@ -tests/cases/compiler/es6ImportDefaultBindingInEs5_1.ts(1,8): error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBindingInEs5_0"' has no default export or export assignment. - - -==== tests/cases/compiler/es6ImportDefaultBindingInEs5_0.ts (0 errors) ==== - - export var a = 10; - -==== tests/cases/compiler/es6ImportDefaultBindingInEs5_1.ts (1 errors) ==== - import defaultBinding from "es6ImportDefaultBindingInEs5_0"; - ~~~~~~~~~~~~~~ -!!! error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBindingInEs5_0"' has no default export or export assignment. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingInEs5.js b/tests/baselines/reference/es6ImportDefaultBindingInEs5.js index b6d293225fd0b..e2b5d70b6b341 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingInEs5.js +++ b/tests/baselines/reference/es6ImportDefaultBindingInEs5.js @@ -2,11 +2,20 @@ //// [es6ImportDefaultBindingInEs5_0.ts] -export var a = 10; +var a = 10; +export = a; //// [es6ImportDefaultBindingInEs5_1.ts] import defaultBinding from "es6ImportDefaultBindingInEs5_0"; //// [es6ImportDefaultBindingInEs5_0.js] -exports.a = 10; +var a = 10; +module.exports = a; //// [es6ImportDefaultBindingInEs5_1.js] + + +//// [es6ImportDefaultBindingInEs5_0.d.ts] +declare var a: number; +export = a; +//// [es6ImportDefaultBindingInEs5_1.d.ts] +import defaultBinding from "es6ImportDefaultBindingInEs5_0"; diff --git a/tests/baselines/reference/es6ImportDefaultBindingInEs5.types b/tests/baselines/reference/es6ImportDefaultBindingInEs5.types new file mode 100644 index 0000000000000..03243fc014d86 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingInEs5.types @@ -0,0 +1,12 @@ +=== tests/cases/compiler/es6ImportDefaultBindingInEs5_0.ts === + +var a = 10; +>a : number + +export = a; +>a : number + +=== tests/cases/compiler/es6ImportDefaultBindingInEs5_1.ts === +import defaultBinding from "es6ImportDefaultBindingInEs5_0"; +>defaultBinding : number + diff --git a/tests/baselines/reference/es6ImportDefaultBindingMergeErrors.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingMergeErrors.errors.txt new file mode 100644 index 0000000000000..d6aacf0ba4062 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingMergeErrors.errors.txt @@ -0,0 +1,26 @@ +tests/cases/compiler/es6ImportDefaultBindingMergeErrors_1.ts(5,8): error TS2440: Import declaration conflicts with local declaration of 'defaultBinding2' +tests/cases/compiler/es6ImportDefaultBindingMergeErrors_1.ts(7,8): error TS2300: Duplicate identifier 'defaultBinding3'. +tests/cases/compiler/es6ImportDefaultBindingMergeErrors_1.ts(8,8): error TS2300: Duplicate identifier 'defaultBinding3'. + + +==== tests/cases/compiler/es6ImportDefaultBindingMergeErrors_0.ts (0 errors) ==== + + var a = 10; + export = a; + +==== tests/cases/compiler/es6ImportDefaultBindingMergeErrors_1.ts (3 errors) ==== + import defaultBinding from "es6ImportDefaultBindingMergeErrors_0"; + interface defaultBinding { // This is ok + } + var x = defaultBinding; + import defaultBinding2 from "es6ImportDefaultBindingMergeErrors_0"; // Should be error + ~~~~~~~~~~~~~~~ +!!! error TS2440: Import declaration conflicts with local declaration of 'defaultBinding2' + var defaultBinding2 = "hello world"; + import defaultBinding3 from "es6ImportDefaultBindingMergeErrors_0"; // Should be error + ~~~~~~~~~~~~~~~ +!!! error TS2300: Duplicate identifier 'defaultBinding3'. + import defaultBinding3 from "es6ImportDefaultBindingMergeErrors_0"; // SHould be error + ~~~~~~~~~~~~~~~ +!!! error TS2300: Duplicate identifier 'defaultBinding3'. + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingMergeErrors.js b/tests/baselines/reference/es6ImportDefaultBindingMergeErrors.js new file mode 100644 index 0000000000000..628faec6c27cc --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingMergeErrors.js @@ -0,0 +1,25 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingMergeErrors.ts] //// + +//// [es6ImportDefaultBindingMergeErrors_0.ts] + +var a = 10; +export = a; + +//// [es6ImportDefaultBindingMergeErrors_1.ts] +import defaultBinding from "es6ImportDefaultBindingMergeErrors_0"; +interface defaultBinding { // This is ok +} +var x = defaultBinding; +import defaultBinding2 from "es6ImportDefaultBindingMergeErrors_0"; // Should be error +var defaultBinding2 = "hello world"; +import defaultBinding3 from "es6ImportDefaultBindingMergeErrors_0"; // Should be error +import defaultBinding3 from "es6ImportDefaultBindingMergeErrors_0"; // SHould be error + + +//// [es6ImportDefaultBindingMergeErrors_0.js] +var a = 10; +module.exports = a; +//// [es6ImportDefaultBindingMergeErrors_1.js] +var defaultBinding = require("es6ImportDefaultBindingMergeErrors_0"); +var x = defaultBinding; +var defaultBinding2 = "hello world"; diff --git a/tests/baselines/reference/es6ImportDefaultBindingNoDefaultProperty.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingNoDefaultProperty.errors.txt new file mode 100644 index 0000000000000..822249c3b34cf --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingNoDefaultProperty.errors.txt @@ -0,0 +1,12 @@ +tests/cases/compiler/es6ImportDefaultBindingNoDefaultProperty_1.ts(1,8): error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBindingNoDefaultProperty_0"' has no default export or export assignment. + + +==== tests/cases/compiler/es6ImportDefaultBindingNoDefaultProperty_0.ts (0 errors) ==== + + export var a = 10; + +==== tests/cases/compiler/es6ImportDefaultBindingNoDefaultProperty_1.ts (1 errors) ==== + import defaultBinding from "es6ImportDefaultBindingNoDefaultProperty_0"; + ~~~~~~~~~~~~~~ +!!! error TS1189: External module '"tests/cases/compiler/es6ImportDefaultBindingNoDefaultProperty_0"' has no default export or export assignment. + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingNoDefaultProperty.js b/tests/baselines/reference/es6ImportDefaultBindingNoDefaultProperty.js new file mode 100644 index 0000000000000..f824dbf71d56e --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingNoDefaultProperty.js @@ -0,0 +1,13 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingNoDefaultProperty.ts] //// + +//// [es6ImportDefaultBindingNoDefaultProperty_0.ts] + +export var a = 10; + +//// [es6ImportDefaultBindingNoDefaultProperty_1.ts] +import defaultBinding from "es6ImportDefaultBindingNoDefaultProperty_0"; + + +//// [es6ImportDefaultBindingNoDefaultProperty_0.js] +exports.a = 10; +//// [es6ImportDefaultBindingNoDefaultProperty_1.js] diff --git a/tests/cases/compiler/es6ImportDefaultBinding.ts b/tests/cases/compiler/es6ImportDefaultBinding.ts index dc5b4ab98d61c..f589712822619 100644 --- a/tests/cases/compiler/es6ImportDefaultBinding.ts +++ b/tests/cases/compiler/es6ImportDefaultBinding.ts @@ -1,8 +1,12 @@ // @target: es6 // @module: commonjs +// @declaration: true // @filename: es6ImportDefaultBinding_0.ts -export var a = 10; +var a = 10; +export = a; // @filename: es6ImportDefaultBinding_1.ts -import defaultBinding from "es6ImportDefaultBinding_0"; \ No newline at end of file +import defaultBinding from "es6ImportDefaultBinding_0"; +var x = defaultBinding; +import defaultBinding2 from "es6ImportDefaultBinding_0"; // elide this import since defaultBinding2 is not used diff --git a/tests/cases/compiler/es6ImportDefaultBindingAmd.ts b/tests/cases/compiler/es6ImportDefaultBindingAmd.ts new file mode 100644 index 0000000000000..85e06b8c99d8c --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingAmd.ts @@ -0,0 +1,11 @@ +// @module: amd +// @declaration: true + +// @filename: es6ImportDefaultBindingAmd_0.ts +var a = 10; +export = a; + +// @filename: es6ImportDefaultBindingAmd_1.ts +import defaultBinding from "es6ImportDefaultBindingAmd_0"; +var x = defaultBinding; +import defaultBinding2 from "es6ImportDefaultBindingAmd_0"; // elide this import since defaultBinding2 is not used diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport.ts index 96b277d6640cd..a0524dd2138d5 100644 --- a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport.ts +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport.ts @@ -1,5 +1,6 @@ // @target: es6 // @module: commonjs +// @declaration: true // @filename: es6ImportDefaultBindingFollowedWithNamedImport_0.ts export var a = 10; @@ -7,9 +8,15 @@ export var x = a; export var m = a; // @filename: es6ImportDefaultBindingFollowedWithNamedImport_1.ts -import defaultBinding, { } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -import defaultBinding, { a } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -import defaultBinding, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -import defaultBinding, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -import defaultBinding, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; \ No newline at end of file +import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1: number = a; +import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1: number = b; +import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1: number = x; +var x1: number = y; +import defaultBinding5, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1: number = z; +import defaultBinding6, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +var x1: number = m; diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1.ts new file mode 100644 index 0000000000000..0db237a9c315a --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1.ts @@ -0,0 +1,21 @@ +// @target: es6 +// @module: commonjs +// @declaration: true + +// @filename: es6ImportDefaultBindingFollowedWithNamedImport1_0.ts +var a = 10; +export = a; + +// @filename: es6ImportDefaultBindingFollowedWithNamedImport1_1.ts +import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding1; +import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding2; +import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding3; +import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding4; +import defaultBinding5, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding5; +import defaultBinding6, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding6; diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.ts new file mode 100644 index 0000000000000..80bc2a4474e0c --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.ts @@ -0,0 +1,21 @@ +// @target: es5 +// @module: commonjs +// @declaration: true + +// @filename: es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0.ts +var a = 10; +export = a; + +// @filename: es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.ts +import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; +var x: number = defaultBinding1; +import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; +var x: number = defaultBinding2; +import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; +var x: number = defaultBinding3; +import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; +var x: number = defaultBinding4; +import defaultBinding5, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; +var x: number = defaultBinding5; +import defaultBinding6, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; +var x: number = defaultBinding6; diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5.ts index bf34687f79162..6e42898d1bca5 100644 --- a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5.ts +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportInEs5.ts @@ -1,5 +1,6 @@ // @target: es5 // @module: commonjs +// @declaration: true // @filename: es6ImportDefaultBindingFollowedWithNamedImportInEs5_0.ts export var a = 10; @@ -7,9 +8,15 @@ export var x = a; export var m = a; // @filename: es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.ts -import defaultBinding, { } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; -import defaultBinding, { a } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; -import defaultBinding, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; -import defaultBinding, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; -import defaultBinding, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; -import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; \ No newline at end of file +import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +var x1: number = a; +import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +var x1: number = b; +import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +var x1: number = x; +var x1: number = y; +import defaultBinding5, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +var x1: number = z; +import defaultBinding6, { m, } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; +var x1: number = m; diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding.ts index 3d029e28738bd..e5d2bfefb39b6 100644 --- a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding.ts +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding.ts @@ -1,8 +1,10 @@ // @target: es6 // @module: commonjs +// @declaration: true // @filename: es6ImportDefaultBindingFollowedWithNamespaceBinding_0.ts export var a = 10; // @filename: es6ImportDefaultBindingFollowedWithNamespaceBinding_1.ts -import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; \ No newline at end of file +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; +var x: number = nameSpaceBinding.a; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1.ts new file mode 100644 index 0000000000000..6590829e61867 --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1.ts @@ -0,0 +1,11 @@ +// @target: es6 +// @module: commonjs +// @declaration: true + +// @filename: es6ImportDefaultBindingFollowedWithNamespaceBinding_0.ts +var a = 10; +export = a; + +// @filename: es6ImportDefaultBindingFollowedWithNamespaceBinding_1.ts +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; +var x: number = defaultBinding; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.ts new file mode 100644 index 0000000000000..db076b87c9a92 --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.ts @@ -0,0 +1,11 @@ +// @target: es5 +// @module: commonjs +// @declaration: true + +// @filename: es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.ts +var a = 10; +export = a; + +// @filename: es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.ts +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"; +var x: number = defaultBinding; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.ts index 5943fa8bfc462..c58ba286e0a39 100644 --- a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.ts +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.ts @@ -1,8 +1,10 @@ // @target: es5 // @module: commonjs +// @declaration: true // @filename: es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.ts export var a = 10; // @filename: es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.ts -import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"; \ No newline at end of file +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"; +var x: number = nameSpaceBinding.a; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportDefaultBindingInEs5.ts b/tests/cases/compiler/es6ImportDefaultBindingInEs5.ts index c037d283dfa74..e0877bd74c1e8 100644 --- a/tests/cases/compiler/es6ImportDefaultBindingInEs5.ts +++ b/tests/cases/compiler/es6ImportDefaultBindingInEs5.ts @@ -1,8 +1,10 @@ // @target: es5 // @module: commonjs +// @declaration: true // @filename: es6ImportDefaultBindingInEs5_0.ts -export var a = 10; +var a = 10; +export = a; // @filename: es6ImportDefaultBindingInEs5_1.ts import defaultBinding from "es6ImportDefaultBindingInEs5_0"; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportDefaultBindingMergeErrors.ts b/tests/cases/compiler/es6ImportDefaultBindingMergeErrors.ts new file mode 100644 index 0000000000000..5aaf1e14c344a --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingMergeErrors.ts @@ -0,0 +1,16 @@ +// @target: es6 +// @module: commonjs + +// @filename: es6ImportDefaultBindingMergeErrors_0.ts +var a = 10; +export = a; + +// @filename: es6ImportDefaultBindingMergeErrors_1.ts +import defaultBinding from "es6ImportDefaultBindingMergeErrors_0"; +interface defaultBinding { // This is ok +} +var x = defaultBinding; +import defaultBinding2 from "es6ImportDefaultBindingMergeErrors_0"; // Should be error +var defaultBinding2 = "hello world"; +import defaultBinding3 from "es6ImportDefaultBindingMergeErrors_0"; // Should be error +import defaultBinding3 from "es6ImportDefaultBindingMergeErrors_0"; // SHould be error diff --git a/tests/cases/compiler/es6ImportDefaultBindingNoDefaultProperty.ts b/tests/cases/compiler/es6ImportDefaultBindingNoDefaultProperty.ts new file mode 100644 index 0000000000000..0436e8f4cdf5a --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingNoDefaultProperty.ts @@ -0,0 +1,8 @@ +// @target: es6 +// @module: commonjs + +// @filename: es6ImportDefaultBindingNoDefaultProperty_0.ts +export var a = 10; + +// @filename: es6ImportDefaultBindingNoDefaultProperty_1.ts +import defaultBinding from "es6ImportDefaultBindingNoDefaultProperty_0"; From e0323b4c2f503f0aac7550af3844942f8dfb1640 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 10 Feb 2015 17:02:11 -0800 Subject: [PATCH 005/224] Emit the import declaration in d.ts file only if it is visible --- src/compiler/checker.ts | 38 ++++-- src/compiler/emitter.ts | 112 +++++++++++++----- src/compiler/types.ts | 4 +- .../baselines/reference/APISample_compile.js | 3 +- .../reference/APISample_compile.types | 11 +- tests/baselines/reference/APISample_linter.js | 3 +- .../reference/APISample_linter.types | 11 +- .../reference/APISample_transform.js | 3 +- .../reference/APISample_transform.types | 11 +- .../baselines/reference/APISample_watcher.js | 3 +- .../reference/APISample_watcher.types | 11 +- .../reference/es6ImportDefaultBinding.js | 2 - .../reference/es6ImportDefaultBindingAmd.js | 2 - ...rtDefaultBindingFollowedWithNamedImport.js | 6 - ...tDefaultBindingFollowedWithNamedImport1.js | 6 - ...ultBindingFollowedWithNamedImport1InEs5.js | 6 - ...aultBindingFollowedWithNamedImportInEs5.js | 6 - ...aultBindingFollowedWithNamespaceBinding.js | 1 - ...ultBindingFollowedWithNamespaceBinding1.js | 1 - ...ndingFollowedWithNamespaceBinding1InEs5.js | 1 - ...indingFollowedWithNamespaceBindingInEs5.js | 1 - .../reference/es6ImportDefaultBindingInEs5.js | 1 - .../reference/es6ImportNameSpaceImport.js | 2 - .../reference/es6ImportNameSpaceImportAmd.js | 2 - .../es6ImportNameSpaceImportInEs5.js | 2 - .../reference/es6ImportNamedImport.js | 12 -- .../reference/es6ImportNamedImportAmd.js | 12 -- .../reference/es6ImportNamedImportInEs5.js | 12 -- 28 files changed, 154 insertions(+), 131 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 864e9551721df..2e4553a4bc023 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -449,6 +449,19 @@ module ts { node.kind === SyntaxKind.ImportSpecifier; } + function getAnyImportSyntax(node: Node): AnyImportSyntax { + if (isImportSymbolDeclaration(node)) { + if (node.kind === SyntaxKind.ImportEqualsDeclaration) { + return node; + } + + while (node.kind !== SyntaxKind.ImportDeclaration) { + node = node.parent; + } + return node; + } + } + function getDeclarationOfImportSymbol(symbol: Symbol): Declaration { return forEach(symbol.declarations, d => isImportSymbolDeclaration(d) ? d : undefined); } @@ -990,7 +1003,7 @@ module ts { } function hasVisibleDeclarations(symbol: Symbol): SymbolVisibilityResult { - var aliasesToMakeVisible: ImportEqualsDeclaration[]; + var aliasesToMakeVisible: AnyImportSyntax[]; if (forEach(symbol.declarations, declaration => !getIsDeclarationVisible(declaration))) { return undefined; } @@ -998,19 +1011,21 @@ module ts { function getIsDeclarationVisible(declaration: Declaration) { if (!isDeclarationVisible(declaration)) { - // Mark the unexported alias as visible if its parent is visible + // Mark the non exported alias as visible if its parent is visible // because these kind of aliases can be used to name types in declaration file - if (declaration.kind === SyntaxKind.ImportEqualsDeclaration && - !(declaration.flags & NodeFlags.Export) && - isDeclarationVisible(declaration.parent)) { + + var anyImportSyntax = getAnyImportSyntax(declaration); + if (anyImportSyntax && + !(anyImportSyntax.flags & NodeFlags.Export) && // import clause without export + isDeclarationVisible(anyImportSyntax.parent)) { getNodeLinks(declaration).isVisible = true; if (aliasesToMakeVisible) { - if (!contains(aliasesToMakeVisible, declaration)) { - aliasesToMakeVisible.push(declaration); + if (!contains(aliasesToMakeVisible, anyImportSyntax)) { + aliasesToMakeVisible.push(anyImportSyntax); } } else { - aliasesToMakeVisible = [declaration]; + aliasesToMakeVisible = [anyImportSyntax]; } return true; } @@ -1680,6 +1695,13 @@ module ts { case SyntaxKind.ParenthesizedType: return isDeclarationVisible(node.parent); + // Default binding, import specifier and namespace import is visible + // only if the import declaration is exported or it is used in export assignment + case SyntaxKind.ImportClause: + case SyntaxKind.NamespaceImport: + case SyntaxKind.ImportSpecifier: + return (node.name && isUsedInExportAssignment(node)); + // Type parameters are always visible case SyntaxKind.TypeParameter: // Source file is always visible diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 000c0d0e81f1f..d23b56a000164 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -35,10 +35,11 @@ module ts { } interface AliasDeclarationEmitInfo { - declaration: ImportEqualsDeclaration; + declaration: AnyImportSyntax; outputPos: number; indent: number; asynchronousOutput?: string; // If the output for alias was written asynchronously, the corresponding output + isVisible?: boolean; } interface DeclarationEmit { @@ -392,6 +393,21 @@ module ts { } emitSourceFile(root); + + // create asynchronous output for the importDeclarations + if (aliasDeclarationEmitInfo.length) { + var oldWriter = writer; + forEach(aliasDeclarationEmitInfo, aliasEmitInfo => { + if (aliasEmitInfo.isVisible) { + Debug.assert(aliasEmitInfo.declaration.kind === SyntaxKind.ImportDeclaration); + createAndSetNewTextWriterWithSymbolWriter(); + Debug.assert(aliasEmitInfo.indent === 0); + writeImportDeclaration(aliasEmitInfo.declaration); + aliasEmitInfo.asynchronousOutput = writer.getText(); + } + }); + setWriter(oldWriter); + } } else { // Emit references corresponding to this file @@ -465,9 +481,9 @@ module ts { decreaseIndent = newWriter.decreaseIndent; } - function writeAsychronousImportEqualsDeclarations(importEqualsDeclarations: ImportEqualsDeclaration[]) { + function writeAsychronousImportEqualsDeclarations(anyImportSyntax: AnyImportSyntax[]) { var oldWriter = writer; - forEach(importEqualsDeclarations, aliasToWrite => { + forEach(anyImportSyntax, aliasToWrite => { var aliasEmitInfo = forEach(aliasDeclarationEmitInfo, declEmitInfo => declEmitInfo.declaration === aliasToWrite ? declEmitInfo : undefined); // If the alias was marked as not visible when we saw its declaration, we would have saved the aliasEmitInfo, but if we haven't yet visited the alias declaration // then we don't need to write it at this point. We will write it when we actually see its declaration @@ -477,12 +493,19 @@ module ts { // Writing of function bar would mark alias declaration foo as visible but we haven't yet visited that declaration so do nothing, // we would write alias foo declaration when we visit it since it would now be marked as visible if (aliasEmitInfo) { - createAndSetNewTextWriterWithSymbolWriter(); - for (var declarationIndent = aliasEmitInfo.indent; declarationIndent; declarationIndent--) { - increaseIndent(); + if (aliasToWrite.kind === SyntaxKind.ImportEqualsDeclaration) { + createAndSetNewTextWriterWithSymbolWriter(); + for (var declarationIndent = aliasEmitInfo.indent; declarationIndent; declarationIndent--) { + increaseIndent(); + } + writeImportEqualsDeclaration(aliasToWrite); + aliasEmitInfo.asynchronousOutput = writer.getText(); + } + else { + // we have to create asynchronous output only after we have collected complete information + // because it is possible to enable multiple bindings as asynchronously visible + aliasEmitInfo.isVisible = true; } - writeImportEqualsDeclaration(aliasToWrite); - aliasEmitInfo.asynchronousOutput = writer.getText(); } }); setWriter(oldWriter); @@ -724,16 +747,16 @@ module ts { } function emitImportEqualsDeclaration(node: ImportEqualsDeclaration) { - var nodeEmitInfo = { - declaration: node, - outputPos: writer.getTextPos(), - indent: writer.getIndent(), - hasWritten: resolver.isDeclarationVisible(node) - }; - aliasDeclarationEmitInfo.push(nodeEmitInfo); - if (nodeEmitInfo.hasWritten) { + if (resolver.isDeclarationVisible(node)) { writeImportEqualsDeclaration(node); } + else { + aliasDeclarationEmitInfo.push({ + declaration: node, + outputPos: writer.getTextPos(), + indent: writer.getIndent(), + }); + } } function writeImportEqualsDeclaration(node: ImportEqualsDeclaration) { @@ -767,33 +790,58 @@ module ts { } function emitImportDeclaration(node: ImportDeclaration) { - // TODO(shkamat): Do the changes so that we emit only if declaration is visible + if (node.importClause) { + aliasDeclarationEmitInfo.push({ + declaration: node, + outputPos: writer.getTextPos(), + indent: writer.getIndent(), + isVisible: (node.importClause.name && resolver.isDeclarationVisible(node.importClause)) || + isVisibleNamedBinding(node.importClause.namedBindings) + }); + } + else { + writeImportDeclaration(node); + } + } + + function isVisibleNamedBinding(namedBindings: NamespaceImport | NamedImports): boolean { + if (namedBindings) { + if (namedBindings.kind === SyntaxKind.NamespaceImport) { + return resolver.isDeclarationVisible(namedBindings); + } + else { + return forEach((namedBindings).elements, namedImport => resolver.isDeclarationVisible(namedImport)); + } + } + } + + function writeImportDeclaration(node: ImportDeclaration) { emitJsDocComments(node); if (node.flags & NodeFlags.Export) { write("export "); } write("import "); if (node.importClause) { - if (node.importClause.name) { + var beforeDefaultBindingEmitPos = writer.getTextPos(); + if (node.importClause.name && resolver.isDeclarationVisible(node.importClause)) { writeTextOfNode(currentSourceFile, node.importClause.name); - if (node.importClause.namedBindings) { - write(","); - } - write(" "); } - if (node.importClause.namedBindings) { + if (node.importClause.namedBindings && isVisibleNamedBinding(node.importClause.namedBindings)) { + if (beforeDefaultBindingEmitPos !== writer.getTextPos()) { + // If the default binding was emitted, write the separated + write(", "); + } if (node.importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { write("* as "); writeTextOfNode(currentSourceFile,(node.importClause.namedBindings).name); - write(" "); } else { write("{"); emitCommaList((node.importClause.namedBindings).elements, emitImportSpecifier); - write(" } "); + write(" }"); } } - write("from "); + write(" from "); } writeTextOfNode(currentSourceFile, node.moduleSpecifier); write(";"); @@ -801,12 +849,14 @@ module ts { } function emitImportSpecifier(node: ImportSpecifier) { - write(" "); - if (node.propertyName) { - writeTextOfNode(currentSourceFile, node.propertyName); - write(" as "); + if (resolver.isDeclarationVisible(node)) { + write(" "); + if (node.propertyName) { + writeTextOfNode(currentSourceFile, node.propertyName); + write(" as "); + } + writeTextOfNode(currentSourceFile, node.name); } - writeTextOfNode(currentSourceFile, node.name); } function emitModuleDeclaration(node: ModuleDeclaration) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index d50b4bcf33581..1f7a8211dfcfb 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1151,9 +1151,11 @@ module ts { CannotBeNamed } + export type AnyImportSyntax = ImportDeclaration | ImportEqualsDeclaration; + export interface SymbolVisibilityResult { accessibility: SymbolAccessibility; - aliasesToMakeVisible?: ImportEqualsDeclaration[]; // aliases that need to have this symbol visible + aliasesToMakeVisible?: AnyImportSyntax[]; // aliases that need to have this symbol visible errorSymbolName?: string; // Optional symbol name that results in error errorNode?: Node; // optional node that results in error } diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index 5c74f2fa688f8..b9bc5d96d41ad 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -892,9 +892,10 @@ declare module "typescript" { NotAccessible = 1, CannotBeNamed = 2, } + type AnyImportSyntax = ImportDeclaration | ImportEqualsDeclaration; interface SymbolVisibilityResult { accessibility: SymbolAccessibility; - aliasesToMakeVisible?: ImportEqualsDeclaration[]; + aliasesToMakeVisible?: AnyImportSyntax[]; errorSymbolName?: string; errorNode?: Node; } diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index aebe5ea695a24..5146cde791cbd 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -2854,6 +2854,11 @@ declare module "typescript" { CannotBeNamed = 2, >CannotBeNamed : SymbolAccessibility } + type AnyImportSyntax = ImportDeclaration | ImportEqualsDeclaration; +>AnyImportSyntax : ImportEqualsDeclaration | ImportDeclaration +>ImportDeclaration : ImportDeclaration +>ImportEqualsDeclaration : ImportEqualsDeclaration + interface SymbolVisibilityResult { >SymbolVisibilityResult : SymbolVisibilityResult @@ -2861,9 +2866,9 @@ declare module "typescript" { >accessibility : SymbolAccessibility >SymbolAccessibility : SymbolAccessibility - aliasesToMakeVisible?: ImportEqualsDeclaration[]; ->aliasesToMakeVisible : ImportEqualsDeclaration[] ->ImportEqualsDeclaration : ImportEqualsDeclaration + aliasesToMakeVisible?: AnyImportSyntax[]; +>aliasesToMakeVisible : (ImportEqualsDeclaration | ImportDeclaration)[] +>AnyImportSyntax : ImportEqualsDeclaration | ImportDeclaration errorSymbolName?: string; >errorSymbolName : string diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index 8b40586e88bdb..012d635e4c562 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -923,9 +923,10 @@ declare module "typescript" { NotAccessible = 1, CannotBeNamed = 2, } + type AnyImportSyntax = ImportDeclaration | ImportEqualsDeclaration; interface SymbolVisibilityResult { accessibility: SymbolAccessibility; - aliasesToMakeVisible?: ImportEqualsDeclaration[]; + aliasesToMakeVisible?: AnyImportSyntax[]; errorSymbolName?: string; errorNode?: Node; } diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index 1bada73385fdd..4292108fc73cc 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -2998,6 +2998,11 @@ declare module "typescript" { CannotBeNamed = 2, >CannotBeNamed : SymbolAccessibility } + type AnyImportSyntax = ImportDeclaration | ImportEqualsDeclaration; +>AnyImportSyntax : ImportEqualsDeclaration | ImportDeclaration +>ImportDeclaration : ImportDeclaration +>ImportEqualsDeclaration : ImportEqualsDeclaration + interface SymbolVisibilityResult { >SymbolVisibilityResult : SymbolVisibilityResult @@ -3005,9 +3010,9 @@ declare module "typescript" { >accessibility : SymbolAccessibility >SymbolAccessibility : SymbolAccessibility - aliasesToMakeVisible?: ImportEqualsDeclaration[]; ->aliasesToMakeVisible : ImportEqualsDeclaration[] ->ImportEqualsDeclaration : ImportEqualsDeclaration + aliasesToMakeVisible?: AnyImportSyntax[]; +>aliasesToMakeVisible : (ImportEqualsDeclaration | ImportDeclaration)[] +>AnyImportSyntax : ImportEqualsDeclaration | ImportDeclaration errorSymbolName?: string; >errorSymbolName : string diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index 74aba68a76c58..8a3951bb19b51 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -924,9 +924,10 @@ declare module "typescript" { NotAccessible = 1, CannotBeNamed = 2, } + type AnyImportSyntax = ImportDeclaration | ImportEqualsDeclaration; interface SymbolVisibilityResult { accessibility: SymbolAccessibility; - aliasesToMakeVisible?: ImportEqualsDeclaration[]; + aliasesToMakeVisible?: AnyImportSyntax[]; errorSymbolName?: string; errorNode?: Node; } diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index 6be348b413155..ab2e05ac05259 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -2950,6 +2950,11 @@ declare module "typescript" { CannotBeNamed = 2, >CannotBeNamed : SymbolAccessibility } + type AnyImportSyntax = ImportDeclaration | ImportEqualsDeclaration; +>AnyImportSyntax : ImportEqualsDeclaration | ImportDeclaration +>ImportDeclaration : ImportDeclaration +>ImportEqualsDeclaration : ImportEqualsDeclaration + interface SymbolVisibilityResult { >SymbolVisibilityResult : SymbolVisibilityResult @@ -2957,9 +2962,9 @@ declare module "typescript" { >accessibility : SymbolAccessibility >SymbolAccessibility : SymbolAccessibility - aliasesToMakeVisible?: ImportEqualsDeclaration[]; ->aliasesToMakeVisible : ImportEqualsDeclaration[] ->ImportEqualsDeclaration : ImportEqualsDeclaration + aliasesToMakeVisible?: AnyImportSyntax[]; +>aliasesToMakeVisible : (ImportEqualsDeclaration | ImportDeclaration)[] +>AnyImportSyntax : ImportEqualsDeclaration | ImportDeclaration errorSymbolName?: string; >errorSymbolName : string diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index 79e2ac398029f..36eaccac6a8fb 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -961,9 +961,10 @@ declare module "typescript" { NotAccessible = 1, CannotBeNamed = 2, } + type AnyImportSyntax = ImportDeclaration | ImportEqualsDeclaration; interface SymbolVisibilityResult { accessibility: SymbolAccessibility; - aliasesToMakeVisible?: ImportEqualsDeclaration[]; + aliasesToMakeVisible?: AnyImportSyntax[]; errorSymbolName?: string; errorNode?: Node; } diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index 429a63daed814..99d84a928f80f 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -3123,6 +3123,11 @@ declare module "typescript" { CannotBeNamed = 2, >CannotBeNamed : SymbolAccessibility } + type AnyImportSyntax = ImportDeclaration | ImportEqualsDeclaration; +>AnyImportSyntax : ImportEqualsDeclaration | ImportDeclaration +>ImportDeclaration : ImportDeclaration +>ImportEqualsDeclaration : ImportEqualsDeclaration + interface SymbolVisibilityResult { >SymbolVisibilityResult : SymbolVisibilityResult @@ -3130,9 +3135,9 @@ declare module "typescript" { >accessibility : SymbolAccessibility >SymbolAccessibility : SymbolAccessibility - aliasesToMakeVisible?: ImportEqualsDeclaration[]; ->aliasesToMakeVisible : ImportEqualsDeclaration[] ->ImportEqualsDeclaration : ImportEqualsDeclaration + aliasesToMakeVisible?: AnyImportSyntax[]; +>aliasesToMakeVisible : (ImportEqualsDeclaration | ImportDeclaration)[] +>AnyImportSyntax : ImportEqualsDeclaration | ImportDeclaration errorSymbolName?: string; >errorSymbolName : string diff --git a/tests/baselines/reference/es6ImportDefaultBinding.js b/tests/baselines/reference/es6ImportDefaultBinding.js index d1e69585ba4e1..b3c6b71a4221c 100644 --- a/tests/baselines/reference/es6ImportDefaultBinding.js +++ b/tests/baselines/reference/es6ImportDefaultBinding.js @@ -23,5 +23,3 @@ var x = defaultBinding; declare var a: number; export = a; //// [es6ImportDefaultBinding_1.d.ts] -import defaultBinding from "es6ImportDefaultBinding_0"; -import defaultBinding2 from "es6ImportDefaultBinding_0"; diff --git a/tests/baselines/reference/es6ImportDefaultBindingAmd.js b/tests/baselines/reference/es6ImportDefaultBindingAmd.js index 24e8ee047b87a..34b39cda4b77b 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingAmd.js +++ b/tests/baselines/reference/es6ImportDefaultBindingAmd.js @@ -26,5 +26,3 @@ define(["require", "exports", "es6ImportDefaultBindingAmd_0"], function (require declare var a: number; export = a; //// [es6ImportDefaultBindingAmd_1.d.ts] -import defaultBinding from "es6ImportDefaultBindingAmd_0"; -import defaultBinding2 from "es6ImportDefaultBindingAmd_0"; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js index 48fb54151ba0a..aa10fb6e26f53 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js @@ -44,9 +44,3 @@ export declare var a: number; export declare var x: number; export declare var m: number; //// [es6ImportDefaultBindingFollowedWithNamedImport_1.d.ts] -import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -import defaultBinding5, { x as z } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -import defaultBinding6, { m } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.js index 451e2df15b624..765d09fae79c3 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.js @@ -42,9 +42,3 @@ var x1 = defaultBinding6; declare var a: number; export = a; //// [es6ImportDefaultBindingFollowedWithNamedImport1_1.d.ts] -import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; -import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; -import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; -import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; -import defaultBinding5, { x as z } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; -import defaultBinding6, { m } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.js index 323650fe205fd..2690e7a7f5166 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1InEs5.js @@ -42,9 +42,3 @@ var x = defaultBinding6; declare var a: number; export = a; //// [es6ImportDefaultBindingFollowedWithNamedImport1InEs5_1.d.ts] -import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; -import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; -import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; -import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; -import defaultBinding5, { x as z } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; -import defaultBinding6, { m } from "es6ImportDefaultBindingFollowedWithNamedImport1InEs5_0"; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.js index 5b211b9fcea6e..3613aaf55753d 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.js @@ -44,9 +44,3 @@ export declare var a: number; export declare var x: number; export declare var m: number; //// [es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.d.ts] -import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; -import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; -import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; -import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; -import defaultBinding5, { x as z } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; -import defaultBinding6, { m } from "es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js index 948c033f7def8..1241140b121d9 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js @@ -18,4 +18,3 @@ var x = nameSpaceBinding.a; //// [es6ImportDefaultBindingFollowedWithNamespaceBinding_0.d.ts] export declare var a: number; //// [es6ImportDefaultBindingFollowedWithNamespaceBinding_1.d.ts] -import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.js index 86869e052fe1f..7f67628c18e95 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.js @@ -21,4 +21,3 @@ var x = defaultBinding; declare var a: number; export = a; //// [es6ImportDefaultBindingFollowedWithNamespaceBinding_1.d.ts] -import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.js index 1052970fa99ff..00166b1bc41fc 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.js @@ -21,4 +21,3 @@ var x = defaultBinding; declare var a: number; export = a; //// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.d.ts] -import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.js index 5419ac20928fd..e8ce8b288755f 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.js @@ -18,4 +18,3 @@ var x = nameSpaceBinding.a; //// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.d.ts] export declare var a: number; //// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.d.ts] -import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"; diff --git a/tests/baselines/reference/es6ImportDefaultBindingInEs5.js b/tests/baselines/reference/es6ImportDefaultBindingInEs5.js index e2b5d70b6b341..0b703f829ca31 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingInEs5.js +++ b/tests/baselines/reference/es6ImportDefaultBindingInEs5.js @@ -18,4 +18,3 @@ module.exports = a; declare var a: number; export = a; //// [es6ImportDefaultBindingInEs5_1.d.ts] -import defaultBinding from "es6ImportDefaultBindingInEs5_0"; diff --git a/tests/baselines/reference/es6ImportNameSpaceImport.js b/tests/baselines/reference/es6ImportNameSpaceImport.js index 6ee33d5e004eb..4e53d54893dc6 100644 --- a/tests/baselines/reference/es6ImportNameSpaceImport.js +++ b/tests/baselines/reference/es6ImportNameSpaceImport.js @@ -20,5 +20,3 @@ var x = nameSpaceBinding.a; //// [es6ImportNameSpaceImport_0.d.ts] export declare var a: number; //// [es6ImportNameSpaceImport_1.d.ts] -import * as nameSpaceBinding from "es6ImportNameSpaceImport_0"; -import * as nameSpaceBinding2 from "es6ImportNameSpaceImport_0"; diff --git a/tests/baselines/reference/es6ImportNameSpaceImportAmd.js b/tests/baselines/reference/es6ImportNameSpaceImportAmd.js index b63431d5df654..e7d0eae9ca96b 100644 --- a/tests/baselines/reference/es6ImportNameSpaceImportAmd.js +++ b/tests/baselines/reference/es6ImportNameSpaceImportAmd.js @@ -23,5 +23,3 @@ define(["require", "exports", "es6ImportNameSpaceImportAmd_0"], function (requir //// [es6ImportNameSpaceImportAmd_0.d.ts] export declare var a: number; //// [es6ImportNameSpaceImportAmd_1.d.ts] -import * as nameSpaceBinding from "es6ImportNameSpaceImportAmd_0"; -import * as nameSpaceBinding2 from "es6ImportNameSpaceImportAmd_0"; diff --git a/tests/baselines/reference/es6ImportNameSpaceImportInEs5.js b/tests/baselines/reference/es6ImportNameSpaceImportInEs5.js index f26e9073d2c19..50a03972cc225 100644 --- a/tests/baselines/reference/es6ImportNameSpaceImportInEs5.js +++ b/tests/baselines/reference/es6ImportNameSpaceImportInEs5.js @@ -20,5 +20,3 @@ var x = nameSpaceBinding.a; //// [es6ImportNameSpaceImportInEs5_0.d.ts] export declare var a: number; //// [es6ImportNameSpaceImportInEs5_1.d.ts] -import * as nameSpaceBinding from "es6ImportNameSpaceImportInEs5_0"; -import * as nameSpaceBinding2 from "es6ImportNameSpaceImportInEs5_0"; diff --git a/tests/baselines/reference/es6ImportNamedImport.js b/tests/baselines/reference/es6ImportNamedImport.js index 9a1eba4259819..fe1dc0dbce358 100644 --- a/tests/baselines/reference/es6ImportNamedImport.js +++ b/tests/baselines/reference/es6ImportNamedImport.js @@ -96,15 +96,3 @@ export declare var z1: number; export declare var z2: number; export declare var aaaa: number; //// [es6ImportNamedImport_1.d.ts] -import { } from "es6ImportNamedImport_0"; -import { a } from "es6ImportNamedImport_0"; -import { a as b } from "es6ImportNamedImport_0"; -import { x, a as y } from "es6ImportNamedImport_0"; -import { x as z } from "es6ImportNamedImport_0"; -import { m } from "es6ImportNamedImport_0"; -import { a1, x1 } from "es6ImportNamedImport_0"; -import { a1 as a11, x1 as x11 } from "es6ImportNamedImport_0"; -import { z1 } from "es6ImportNamedImport_0"; -import { z2 as z3 } from "es6ImportNamedImport_0"; -import { aaaa } from "es6ImportNamedImport_0"; -import { aaaa as bbbb } from "es6ImportNamedImport_0"; diff --git a/tests/baselines/reference/es6ImportNamedImportAmd.js b/tests/baselines/reference/es6ImportNamedImportAmd.js index 7510c8aeb6b01..3f0cc2acee89c 100644 --- a/tests/baselines/reference/es6ImportNamedImportAmd.js +++ b/tests/baselines/reference/es6ImportNamedImportAmd.js @@ -91,15 +91,3 @@ export declare var z1: number; export declare var z2: number; export declare var aaaa: number; //// [es6ImportNamedImportAmd_1.d.ts] -import { } from "es6ImportNamedImportAmd_0"; -import { a } from "es6ImportNamedImportAmd_0"; -import { a as b } from "es6ImportNamedImportAmd_0"; -import { x, a as y } from "es6ImportNamedImportAmd_0"; -import { x as z } from "es6ImportNamedImportAmd_0"; -import { m } from "es6ImportNamedImportAmd_0"; -import { a1, x1 } from "es6ImportNamedImportAmd_0"; -import { a1 as a11, x1 as x11 } from "es6ImportNamedImportAmd_0"; -import { z1 } from "es6ImportNamedImportAmd_0"; -import { z2 as z3 } from "es6ImportNamedImportAmd_0"; -import { aaaa } from "es6ImportNamedImportAmd_0"; -import { aaaa as bbbb } from "es6ImportNamedImportAmd_0"; diff --git a/tests/baselines/reference/es6ImportNamedImportInEs5.js b/tests/baselines/reference/es6ImportNamedImportInEs5.js index 79cbafeff2f79..79f94a6c82c19 100644 --- a/tests/baselines/reference/es6ImportNamedImportInEs5.js +++ b/tests/baselines/reference/es6ImportNamedImportInEs5.js @@ -96,15 +96,3 @@ export declare var z1: number; export declare var z2: number; export declare var aaaa: number; //// [es6ImportNamedImportInEs5_1.d.ts] -import { } from "es6ImportNamedImportInEs5_0"; -import { a } from "es6ImportNamedImportInEs5_0"; -import { a as b } from "es6ImportNamedImportInEs5_0"; -import { x, a as y } from "es6ImportNamedImportInEs5_0"; -import { x as z } from "es6ImportNamedImportInEs5_0"; -import { m } from "es6ImportNamedImportInEs5_0"; -import { a1, x1 } from "es6ImportNamedImportInEs5_0"; -import { a1 as a11, x1 as x11 } from "es6ImportNamedImportInEs5_0"; -import { z1 } from "es6ImportNamedImportInEs5_0"; -import { z2 as z3 } from "es6ImportNamedImportInEs5_0"; -import { aaaa } from "es6ImportNamedImportInEs5_0"; -import { aaaa as bbbb } from "es6ImportNamedImportInEs5_0"; From c90f820b6cd0bd7bcdfed3d2961c85acbfc895dc Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 10 Feb 2015 17:06:04 -0800 Subject: [PATCH 006/224] Enable test cases when import binding is used in export assignment directly or indirectly --- .../es6ImportNamedImportInExportAssignment.js | 7 +++++++ .../es6ImportNamedImportInIndirectExportAssignment.js | 11 +++++++++++ .../es6ImportNamedImportInExportAssignment.ts | 1 + .../es6ImportNamedImportInIndirectExportAssignment.ts | 1 + 4 files changed, 20 insertions(+) diff --git a/tests/baselines/reference/es6ImportNamedImportInExportAssignment.js b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.js index dd79b2f1cfab2..a58206722471e 100644 --- a/tests/baselines/reference/es6ImportNamedImportInExportAssignment.js +++ b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.js @@ -14,3 +14,10 @@ exports.a = 10; var _a = require("es6ImportNamedImportInExportAssignment_0"); var a = _a.a; module.exports = a; + + +//// [es6ImportNamedImportInExportAssignment_0.d.ts] +export declare var a: number; +//// [es6ImportNamedImportInExportAssignment_1.d.ts] +import { a } from "es6ImportNamedImportInExportAssignment_0"; +export = a; diff --git a/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.js b/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.js index 982209df18961..c1a4b5d5e9ebe 100644 --- a/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.js +++ b/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.js @@ -27,3 +27,14 @@ var _a = require("es6ImportNamedImportInIndirectExportAssignment_0"); var a = _a.a; var x = a; module.exports = x; + + +//// [es6ImportNamedImportInIndirectExportAssignment_0.d.ts] +export declare module a { + class c { + } +} +//// [es6ImportNamedImportInIndirectExportAssignment_1.d.ts] +import { a } from "es6ImportNamedImportInIndirectExportAssignment_0"; +import x = a; +export = x; diff --git a/tests/cases/compiler/es6ImportNamedImportInExportAssignment.ts b/tests/cases/compiler/es6ImportNamedImportInExportAssignment.ts index 9976f20f0800c..7a4519c68bba7 100644 --- a/tests/cases/compiler/es6ImportNamedImportInExportAssignment.ts +++ b/tests/cases/compiler/es6ImportNamedImportInExportAssignment.ts @@ -1,5 +1,6 @@ // @target: es6 // @module: commonjs +// @declaration: true // @filename: es6ImportNamedImportInExportAssignment_0.ts export var a = 10; diff --git a/tests/cases/compiler/es6ImportNamedImportInIndirectExportAssignment.ts b/tests/cases/compiler/es6ImportNamedImportInIndirectExportAssignment.ts index c9e85bbbd6527..2f6073f2a1e3b 100644 --- a/tests/cases/compiler/es6ImportNamedImportInIndirectExportAssignment.ts +++ b/tests/cases/compiler/es6ImportNamedImportInIndirectExportAssignment.ts @@ -1,5 +1,6 @@ // @target: es6 // @module: commonjs +// @declaration: true // @filename: es6ImportNamedImportInIndirectExportAssignment_0.ts export module a { From 863e73c75ee9174f44b08b20eac9113315c0a6c8 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 10 Feb 2015 17:09:29 -0800 Subject: [PATCH 007/224] Test case for emitting partial part of import syntax --- src/compiler/emitter.ts | 97 +++++++++---------- .../es6ImportNamedImportWithTypesAndValues.js | 60 ++++++++++++ ...6ImportNamedImportWithTypesAndValues.types | 44 +++++++++ .../es6ImportNamedImportWithTypesAndValues.ts | 21 ++++ 4 files changed, 171 insertions(+), 51 deletions(-) create mode 100644 tests/baselines/reference/es6ImportNamedImportWithTypesAndValues.js create mode 100644 tests/baselines/reference/es6ImportNamedImportWithTypesAndValues.types create mode 100644 tests/cases/compiler/es6ImportNamedImportWithTypesAndValues.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index d23b56a000164..63e6e992b35f2 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -574,19 +574,21 @@ module ts { } } - function emitSeparatedList(nodes: Node[], separator: string, eachNodeEmitFn: (node: Node) => void) { + function emitSeparatedList(nodes: Node[], separator: string, eachNodeEmitFn: (node: Node) => void, canEmitFn?: (node: Node) => boolean) { var currentWriterPos = writer.getTextPos(); for (var i = 0, n = nodes.length; i < n; i++) { - if (currentWriterPos !== writer.getTextPos()) { - write(separator); + if (!canEmitFn || canEmitFn(nodes[i])) { + if (currentWriterPos !== writer.getTextPos()) { + write(separator); + } + currentWriterPos = writer.getTextPos(); + eachNodeEmitFn(nodes[i]); } - currentWriterPos = writer.getTextPos(); - eachNodeEmitFn(nodes[i]); } } - function emitCommaList(nodes: Node[], eachNodeEmitFn: (node: Node) => void) { - emitSeparatedList(nodes, ", ", eachNodeEmitFn); + function emitCommaList(nodes: Node[], eachNodeEmitFn: (node: Node) => void, canEmitFn?: (node: Node) => boolean) { + emitSeparatedList(nodes, ", ", eachNodeEmitFn, canEmitFn); } function writeJsDocComments(declaration: Node) { @@ -822,22 +824,22 @@ module ts { } write("import "); if (node.importClause) { - var beforeDefaultBindingEmitPos = writer.getTextPos(); + var currentWriterPos = writer.getTextPos(); if (node.importClause.name && resolver.isDeclarationVisible(node.importClause)) { writeTextOfNode(currentSourceFile, node.importClause.name); } if (node.importClause.namedBindings && isVisibleNamedBinding(node.importClause.namedBindings)) { - if (beforeDefaultBindingEmitPos !== writer.getTextPos()) { + if (currentWriterPos !== writer.getTextPos()) { // If the default binding was emitted, write the separated write(", "); } if (node.importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { write("* as "); - writeTextOfNode(currentSourceFile,(node.importClause.namedBindings).name); + writeTextOfNode(currentSourceFile, (node.importClause.namedBindings).name); } else { - write("{"); - emitCommaList((node.importClause.namedBindings).elements, emitImportSpecifier); + write("{ "); + emitCommaList((node.importClause.namedBindings).elements, emitImportSpecifier, resolver.isDeclarationVisible); write(" }"); } } @@ -849,14 +851,11 @@ module ts { } function emitImportSpecifier(node: ImportSpecifier) { - if (resolver.isDeclarationVisible(node)) { - write(" "); - if (node.propertyName) { - writeTextOfNode(currentSourceFile, node.propertyName); - write(" as "); - } - writeTextOfNode(currentSourceFile, node.name); + if (node.propertyName) { + writeTextOfNode(currentSourceFile, node.propertyName); + write(" as "); } + writeTextOfNode(currentSourceFile, node.name); } function emitModuleDeclaration(node: ModuleDeclaration) { @@ -1121,56 +1120,52 @@ module ts { } function emitVariableDeclaration(node: VariableDeclaration) { - // If we are emitting property it isn't moduleElement and hence we already know it needs to be emitted - // so there is no check needed to see if declaration is visible - if (node.kind !== SyntaxKind.VariableDeclaration || resolver.isDeclarationVisible(node)) { - // If this node is a computed name, it can only be a symbol, because we've already skipped - // it if it's not a well known symbol. In that case, the text of the name will be exactly - // what we want, namely the name expression enclosed in brackets. - writeTextOfNode(currentSourceFile, node.name); - // If optional property emit ? - if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) && hasQuestionToken(node)) { - write("?"); - } - if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) && node.parent.kind === SyntaxKind.TypeLiteral) { - emitTypeOfVariableDeclarationFromTypeLiteral(node); - } - else if (!(node.flags & NodeFlags.Private)) { - writeTypeOfDeclaration(node, node.type, getVariableDeclarationTypeVisibilityError); - } + // If this node is a computed name, it can only be a symbol, because we've already skipped + // it if it's not a well known symbol. In that case, the text of the name will be exactly + // what we want, namely the name expression enclosed in brackets. + writeTextOfNode(currentSourceFile, node.name); + // If optional property emit ? + if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) && hasQuestionToken(node)) { + write("?"); + } + if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) && node.parent.kind === SyntaxKind.TypeLiteral) { + emitTypeOfVariableDeclarationFromTypeLiteral(node); + } + else if (!(node.flags & NodeFlags.Private)) { + writeTypeOfDeclaration(node, node.type, getVariableDeclarationTypeVisibilityError); } function getVariableDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { var diagnosticMessage: DiagnosticMessage; if (node.kind === SyntaxKind.VariableDeclaration) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : - Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Exported_variable_0_has_or_is_using_private_name_1; + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : + Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Exported_variable_0_has_or_is_using_private_name_1; } // This check is to ensure we don't report error on constructor parameter property as that error would be reported during parameter emit else if (node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) { // TODO(jfreeman): Deal with computed properties in error reporting. if (node.flags & NodeFlags.Static) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : - Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_private_name_1; + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : + Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_private_name_1; } else if (node.parent.kind === SyntaxKind.ClassDeclaration) { diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : - Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Public_property_0_of_exported_class_has_or_is_using_private_name_1; + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : + Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Public_property_0_of_exported_class_has_or_is_using_private_name_1; } else { // Interfaces cannot have types that cannot be named diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Property_0_of_exported_interface_has_or_is_using_private_name_1; + Diagnostics.Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Property_0_of_exported_interface_has_or_is_using_private_name_1; } } @@ -1206,7 +1201,7 @@ module ts { else { write("var "); } - emitCommaList(node.declarationList.declarations, emitVariableDeclaration); + emitCommaList(node.declarationList.declarations, emitVariableDeclaration, resolver.isDeclarationVisible); write(";"); writeLine(); } diff --git a/tests/baselines/reference/es6ImportNamedImportWithTypesAndValues.js b/tests/baselines/reference/es6ImportNamedImportWithTypesAndValues.js new file mode 100644 index 0000000000000..a7827a5d56ac7 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportWithTypesAndValues.js @@ -0,0 +1,60 @@ +//// [tests/cases/compiler/es6ImportNamedImportWithTypesAndValues.ts] //// + +//// [server.ts] + +export interface I { + prop: string; +} +export interface I2 { + prop2: string; +} +export class C implements I { + prop = "hello"; +} +export class C2 implements I2 { + prop2 = "world"; +} + +//// [client.ts] +import { C, I, C2 } from "server"; // Shouldnt emit I and C2 into the js file and emit C and I in .d.ts file +export type cValInterface = I; +export var cVal = new C(); + +//// [server.js] +var C = (function () { + function C() { + this.prop = "hello"; + } + return C; +})(); +exports.C = C; +var C2 = (function () { + function C2() { + this.prop2 = "world"; + } + return C2; +})(); +exports.C2 = C2; +//// [client.js] +var _a = require("server"); +var C = _a.C; // Shouldnt emit I and C2 into the js file and emit C and I in .d.ts file +exports.cVal = new C(); + + +//// [server.d.ts] +export interface I { + prop: string; +} +export interface I2 { + prop2: string; +} +export declare class C implements I { + prop: string; +} +export declare class C2 implements I2 { + prop2: string; +} +//// [client.d.ts] +import { C, I } from "server"; +export declare type cValInterface = I; +export declare var cVal: C; diff --git a/tests/baselines/reference/es6ImportNamedImportWithTypesAndValues.types b/tests/baselines/reference/es6ImportNamedImportWithTypesAndValues.types new file mode 100644 index 0000000000000..62917e5ff36b5 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportWithTypesAndValues.types @@ -0,0 +1,44 @@ +=== tests/cases/compiler/server.ts === + +export interface I { +>I : I + + prop: string; +>prop : string +} +export interface I2 { +>I2 : I2 + + prop2: string; +>prop2 : string +} +export class C implements I { +>C : C +>I : I + + prop = "hello"; +>prop : string +} +export class C2 implements I2 { +>C2 : C2 +>I2 : I2 + + prop2 = "world"; +>prop2 : string +} + +=== tests/cases/compiler/client.ts === +import { C, I, C2 } from "server"; // Shouldnt emit I and C2 into the js file and emit C and I in .d.ts file +>C : typeof C +>I : unknown +>C2 : typeof C2 + +export type cValInterface = I; +>cValInterface : I +>I : I + +export var cVal = new C(); +>cVal : C +>new C() : C +>C : typeof C + diff --git a/tests/cases/compiler/es6ImportNamedImportWithTypesAndValues.ts b/tests/cases/compiler/es6ImportNamedImportWithTypesAndValues.ts new file mode 100644 index 0000000000000..08294e572325d --- /dev/null +++ b/tests/cases/compiler/es6ImportNamedImportWithTypesAndValues.ts @@ -0,0 +1,21 @@ +// @module: commonjs +// @declaration: true + +// @filename: server.ts +export interface I { + prop: string; +} +export interface I2 { + prop2: string; +} +export class C implements I { + prop = "hello"; +} +export class C2 implements I2 { + prop2 = "world"; +} + +// @filename: client.ts +import { C, I, C2 } from "server"; // Shouldnt emit I and C2 into the js file and emit C and I in .d.ts file +export type cValInterface = I; +export var cVal = new C(); \ No newline at end of file From 0dfe4255c99a726ab1e71ae51ddff01d165a3cf2 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 9 Feb 2015 08:54:48 -0800 Subject: [PATCH 008/224] Test cases for export import syntax --- ...lowedWithNamedImport1WithExport.errors.txt | 57 +++++++++ ...ndingFollowedWithNamedImport1WithExport.js | 50 ++++++++ ...llowedWithNamedImportWithExport.errors.txt | 58 ++++++++++ ...indingFollowedWithNamedImportWithExport.js | 51 ++++++++ ...WithNamespaceBinding1WithExport.errors.txt | 13 +++ ...FollowedWithNamespaceBinding1WithExport.js | 27 +++++ ...dWithNamespaceBindingWithExport.errors.txt | 15 +++ ...gFollowedWithNamespaceBindingWithExport.js | 21 ++++ ...6ImportDefaultBindingWithExport.errors.txt | 17 +++ .../es6ImportDefaultBindingWithExport.js | 28 +++++ ...ImportNameSpaceImportWithExport.errors.txt | 17 +++ .../es6ImportNameSpaceImportWithExport.js | 26 +++++ .../es6ImportNamedImportWithExport.errors.txt | 77 +++++++++++++ .../es6ImportNamedImportWithExport.js | 109 ++++++++++++++++++ ...portWithoutFromClauseWithExport.errors.txt | 11 ++ .../es6ImportWithoutFromClauseWithExport.js | 19 +++ ...ndingFollowedWithNamedImport1WithExport.ts | 20 ++++ ...indingFollowedWithNamedImportWithExport.ts | 21 ++++ ...FollowedWithNamespaceBinding1WithExport.ts | 10 ++ ...gFollowedWithNamespaceBindingWithExport.ts | 9 ++ .../es6ImportDefaultBindingWithExport.ts | 11 ++ .../es6ImportNameSpaceImportWithExport.ts | 10 ++ .../es6ImportNamedImportWithExport.ts | 40 +++++++ .../es6ImportWithoutFromClauseWithExport.ts | 8 ++ 24 files changed, 725 insertions(+) create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.errors.txt create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.js create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.errors.txt create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.js create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.errors.txt create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.js create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.errors.txt create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.js create mode 100644 tests/baselines/reference/es6ImportDefaultBindingWithExport.errors.txt create mode 100644 tests/baselines/reference/es6ImportDefaultBindingWithExport.js create mode 100644 tests/baselines/reference/es6ImportNameSpaceImportWithExport.errors.txt create mode 100644 tests/baselines/reference/es6ImportNameSpaceImportWithExport.js create mode 100644 tests/baselines/reference/es6ImportNamedImportWithExport.errors.txt create mode 100644 tests/baselines/reference/es6ImportNamedImportWithExport.js create mode 100644 tests/baselines/reference/es6ImportWithoutFromClauseWithExport.errors.txt create mode 100644 tests/baselines/reference/es6ImportWithoutFromClauseWithExport.js create mode 100644 tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.ts create mode 100644 tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportWithExport.ts create mode 100644 tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.ts create mode 100644 tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.ts create mode 100644 tests/cases/compiler/es6ImportDefaultBindingWithExport.ts create mode 100644 tests/cases/compiler/es6ImportNameSpaceImportWithExport.ts create mode 100644 tests/cases/compiler/es6ImportNamedImportWithExport.ts create mode 100644 tests/cases/compiler/es6ImportWithoutFromClauseWithExport.ts diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.errors.txt new file mode 100644 index 0000000000000..45a3f80058cbf --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.errors.txt @@ -0,0 +1,57 @@ +tests/cases/compiler/client.ts(1,1): error TS1188: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(3,1): error TS1188: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(3,34): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. +tests/cases/compiler/client.ts(5,1): error TS1188: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(5,34): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. +tests/cases/compiler/client.ts(7,1): error TS1188: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(7,34): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'x'. +tests/cases/compiler/client.ts(7,37): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. +tests/cases/compiler/client.ts(9,1): error TS1188: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(9,34): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'x'. +tests/cases/compiler/client.ts(11,1): error TS1188: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(11,34): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'm'. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + var a = 10; + export = a; + +==== tests/cases/compiler/client.ts (12 errors) ==== + export import defaultBinding1, { } from "server"; + ~~~~~~ +!!! error TS1188: An import declaration cannot have modifiers. + export var x1: number = defaultBinding1; + export import defaultBinding2, { a } from "server"; + ~~~~~~ +!!! error TS1188: An import declaration cannot have modifiers. + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. + export var x1: number = defaultBinding2; + export import defaultBinding3, { a as b } from "server"; + ~~~~~~ +!!! error TS1188: An import declaration cannot have modifiers. + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. + export var x1: number = defaultBinding3; + export import defaultBinding4, { x, a as y } from "server"; + ~~~~~~ +!!! error TS1188: An import declaration cannot have modifiers. + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'x'. + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. + export var x1: number = defaultBinding4; + export import defaultBinding5, { x as z, } from "server"; + ~~~~~~ +!!! error TS1188: An import declaration cannot have modifiers. + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'x'. + export var x1: number = defaultBinding5; + export import defaultBinding6, { m, } from "server"; + ~~~~~~ +!!! error TS1188: An import declaration cannot have modifiers. + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'm'. + export var x1: number = defaultBinding6; + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.js new file mode 100644 index 0000000000000..0239b68194fba --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.js @@ -0,0 +1,50 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.ts] //// + +//// [server.ts] + +var a = 10; +export = a; + +//// [client.ts] +export import defaultBinding1, { } from "server"; +export var x1: number = defaultBinding1; +export import defaultBinding2, { a } from "server"; +export var x1: number = defaultBinding2; +export import defaultBinding3, { a as b } from "server"; +export var x1: number = defaultBinding3; +export import defaultBinding4, { x, a as y } from "server"; +export var x1: number = defaultBinding4; +export import defaultBinding5, { x as z, } from "server"; +export var x1: number = defaultBinding5; +export import defaultBinding6, { m, } from "server"; +export var x1: number = defaultBinding6; + + +//// [server.js] +var a = 10; +module.exports = a; +//// [client.js] +var defaultBinding1 = require("server"); +exports.x1 = defaultBinding1; +var defaultBinding2 = require("server"); +exports.x1 = defaultBinding2; +var defaultBinding3 = require("server"); +exports.x1 = defaultBinding3; +var defaultBinding4 = require("server"); +exports.x1 = defaultBinding4; +var defaultBinding5 = require("server"); +exports.x1 = defaultBinding5; +var defaultBinding6 = require("server"); +exports.x1 = defaultBinding6; + + +//// [server.d.ts] +declare var a: number; +export = a; +//// [client.d.ts] +export declare var x1: number; +export declare var x1: number; +export declare var x1: number; +export declare var x1: number; +export declare var x1: number; +export declare var x1: number; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.errors.txt new file mode 100644 index 0000000000000..70e855810e376 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.errors.txt @@ -0,0 +1,58 @@ +tests/cases/compiler/client.ts(1,1): error TS1188: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(1,15): error TS1189: External module '"tests/cases/compiler/server"' has no default export or export assignment. +tests/cases/compiler/client.ts(2,1): error TS1188: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(2,15): error TS1189: External module '"tests/cases/compiler/server"' has no default export or export assignment. +tests/cases/compiler/client.ts(4,1): error TS1188: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(4,15): error TS1189: External module '"tests/cases/compiler/server"' has no default export or export assignment. +tests/cases/compiler/client.ts(6,1): error TS1188: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(6,15): error TS1189: External module '"tests/cases/compiler/server"' has no default export or export assignment. +tests/cases/compiler/client.ts(9,1): error TS1188: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(9,15): error TS1189: External module '"tests/cases/compiler/server"' has no default export or export assignment. +tests/cases/compiler/client.ts(11,1): error TS1188: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(11,15): error TS1189: External module '"tests/cases/compiler/server"' has no default export or export assignment. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + export var a = 10; + export var x = a; + export var m = a; + +==== tests/cases/compiler/client.ts (12 errors) ==== + export import defaultBinding1, { } from "server"; + ~~~~~~ +!!! error TS1188: An import declaration cannot have modifiers. + ~~~~~~~~~~~~~~~ +!!! error TS1189: External module '"tests/cases/compiler/server"' has no default export or export assignment. + export import defaultBinding2, { a } from "server"; + ~~~~~~ +!!! error TS1188: An import declaration cannot have modifiers. + ~~~~~~~~~~~~~~~ +!!! error TS1189: External module '"tests/cases/compiler/server"' has no default export or export assignment. + export var x1: number = a; + export import defaultBinding3, { a as b } from "server"; + ~~~~~~ +!!! error TS1188: An import declaration cannot have modifiers. + ~~~~~~~~~~~~~~~ +!!! error TS1189: External module '"tests/cases/compiler/server"' has no default export or export assignment. + export var x1: number = b; + export import defaultBinding4, { x, a as y } from "server"; + ~~~~~~ +!!! error TS1188: An import declaration cannot have modifiers. + ~~~~~~~~~~~~~~~ +!!! error TS1189: External module '"tests/cases/compiler/server"' has no default export or export assignment. + export var x1: number = x; + export var x1: number = y; + export import defaultBinding5, { x as z, } from "server"; + ~~~~~~ +!!! error TS1188: An import declaration cannot have modifiers. + ~~~~~~~~~~~~~~~ +!!! error TS1189: External module '"tests/cases/compiler/server"' has no default export or export assignment. + export var x1: number = z; + export import defaultBinding6, { m, } from "server"; + ~~~~~~ +!!! error TS1188: An import declaration cannot have modifiers. + ~~~~~~~~~~~~~~~ +!!! error TS1189: External module '"tests/cases/compiler/server"' has no default export or export assignment. + export var x1: number = m; + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.js new file mode 100644 index 0000000000000..147c3b42296a0 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.js @@ -0,0 +1,51 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportWithExport.ts] //// + +//// [server.ts] + +export var a = 10; +export var x = a; +export var m = a; + +//// [client.ts] +export import defaultBinding1, { } from "server"; +export import defaultBinding2, { a } from "server"; +export var x1: number = a; +export import defaultBinding3, { a as b } from "server"; +export var x1: number = b; +export import defaultBinding4, { x, a as y } from "server"; +export var x1: number = x; +export var x1: number = y; +export import defaultBinding5, { x as z, } from "server"; +export var x1: number = z; +export import defaultBinding6, { m, } from "server"; +export var x1: number = m; + + +//// [server.js] +define(["require", "exports"], function (require, exports) { + exports.a = 10; + exports.x = exports.a; + exports.m = exports.a; +}); +//// [client.js] +define(["require", "exports", "server", "server", "server", "server", "server"], function (require, exports, defaultBinding2, defaultBinding3, defaultBinding4, defaultBinding5, defaultBinding6) { + exports.x1 = a; + exports.x1 = b; + exports.x1 = x; + exports.x1 = y; + exports.x1 = z; + exports.x1 = m; +}); + + +//// [server.d.ts] +export declare var a: number; +export declare var x: number; +export declare var m: number; +//// [client.d.ts] +export declare var x1: number; +export declare var x1: number; +export declare var x1: number; +export declare var x1: number; +export declare var x1: number; +export declare var x1: number; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.errors.txt new file mode 100644 index 0000000000000..3cb1326cc8b16 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.errors.txt @@ -0,0 +1,13 @@ +tests/cases/compiler/client.ts(1,1): error TS1188: An import declaration cannot have modifiers. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + var a = 10; + export = a; + +==== tests/cases/compiler/client.ts (1 errors) ==== + export import defaultBinding, * as nameSpaceBinding from "server"; + ~~~~~~ +!!! error TS1188: An import declaration cannot have modifiers. + export var x: number = defaultBinding; \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.js new file mode 100644 index 0000000000000..d1dd565c81b48 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.js @@ -0,0 +1,27 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.ts] //// + +//// [server.ts] + +var a = 10; +export = a; + +//// [client.ts] +export import defaultBinding, * as nameSpaceBinding from "server"; +export var x: number = defaultBinding; + +//// [server.js] +define(["require", "exports"], function (require, exports) { + var a = 10; + return a; +}); +//// [client.js] +define(["require", "exports", "server"], function (require, exports, defaultBinding) { + exports.x = defaultBinding; +}); + + +//// [server.d.ts] +declare var a: number; +export = a; +//// [client.d.ts] +export declare var x: number; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.errors.txt new file mode 100644 index 0000000000000..88597138eb060 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.errors.txt @@ -0,0 +1,15 @@ +tests/cases/compiler/client.ts(1,1): error TS1188: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(1,15): error TS1189: External module '"tests/cases/compiler/server"' has no default export or export assignment. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + export var a = 10; + +==== tests/cases/compiler/client.ts (2 errors) ==== + export import defaultBinding, * as nameSpaceBinding from "server"; + ~~~~~~ +!!! error TS1188: An import declaration cannot have modifiers. + ~~~~~~~~~~~~~~ +!!! error TS1189: External module '"tests/cases/compiler/server"' has no default export or export assignment. + export var x: number = nameSpaceBinding.a; \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.js new file mode 100644 index 0000000000000..a386a42b5249b --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.js @@ -0,0 +1,21 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.ts] //// + +//// [server.ts] + +export var a = 10; + +//// [client.ts] +export import defaultBinding, * as nameSpaceBinding from "server"; +export var x: number = nameSpaceBinding.a; + +//// [server.js] +exports.a = 10; +//// [client.js] +var defaultBinding = require("server"); +exports.x = nameSpaceBinding.a; + + +//// [server.d.ts] +export declare var a: number; +//// [client.d.ts] +export declare var x: number; diff --git a/tests/baselines/reference/es6ImportDefaultBindingWithExport.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingWithExport.errors.txt new file mode 100644 index 0000000000000..20ea4335112c6 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingWithExport.errors.txt @@ -0,0 +1,17 @@ +tests/cases/compiler/client.ts(1,1): error TS1188: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(3,1): error TS1188: An import declaration cannot have modifiers. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + var a = 10; + export = a; + +==== tests/cases/compiler/client.ts (2 errors) ==== + export import defaultBinding from "server"; + ~~~~~~ +!!! error TS1188: An import declaration cannot have modifiers. + export var x = defaultBinding; + export import defaultBinding2 from "server"; // non referenced + ~~~~~~ +!!! error TS1188: An import declaration cannot have modifiers. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingWithExport.js b/tests/baselines/reference/es6ImportDefaultBindingWithExport.js new file mode 100644 index 0000000000000..a3f8dd11c6c51 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingWithExport.js @@ -0,0 +1,28 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingWithExport.ts] //// + +//// [server.ts] + +var a = 10; +export = a; + +//// [client.ts] +export import defaultBinding from "server"; +export var x = defaultBinding; +export import defaultBinding2 from "server"; // non referenced + +//// [server.js] +define(["require", "exports"], function (require, exports) { + var a = 10; + return a; +}); +//// [client.js] +define(["require", "exports", "server"], function (require, exports, defaultBinding) { + exports.x = defaultBinding; +}); + + +//// [server.d.ts] +declare var a: number; +export = a; +//// [client.d.ts] +export declare var x: number; diff --git a/tests/baselines/reference/es6ImportNameSpaceImportWithExport.errors.txt b/tests/baselines/reference/es6ImportNameSpaceImportWithExport.errors.txt new file mode 100644 index 0000000000000..8178cb40cb473 --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportWithExport.errors.txt @@ -0,0 +1,17 @@ +tests/cases/compiler/client.ts(1,1): error TS1188: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(3,1): error TS1188: An import declaration cannot have modifiers. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + export var a = 10; + +==== tests/cases/compiler/client.ts (2 errors) ==== + export import * as nameSpaceBinding from "server"; + ~~~~~~ +!!! error TS1188: An import declaration cannot have modifiers. + export var x = nameSpaceBinding.a; + export import * as nameSpaceBinding2 from "server"; // Not referenced imports + ~~~~~~ +!!! error TS1188: An import declaration cannot have modifiers. + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNameSpaceImportWithExport.js b/tests/baselines/reference/es6ImportNameSpaceImportWithExport.js new file mode 100644 index 0000000000000..84f6936d4b0f1 --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportWithExport.js @@ -0,0 +1,26 @@ +//// [tests/cases/compiler/es6ImportNameSpaceImportWithExport.ts] //// + +//// [server.ts] + +export var a = 10; + +//// [client.ts] +export import * as nameSpaceBinding from "server"; +export var x = nameSpaceBinding.a; +export import * as nameSpaceBinding2 from "server"; // Not referenced imports + + +//// [server.js] +define(["require", "exports"], function (require, exports) { + exports.a = 10; +}); +//// [client.js] +define(["require", "exports", "server"], function (require, exports, nameSpaceBinding) { + exports.x = nameSpaceBinding.a; +}); + + +//// [server.d.ts] +export declare var a: number; +//// [client.d.ts] +export declare var x: number; diff --git a/tests/baselines/reference/es6ImportNamedImportWithExport.errors.txt b/tests/baselines/reference/es6ImportNamedImportWithExport.errors.txt new file mode 100644 index 0000000000000..3696f8b28c9ca --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportWithExport.errors.txt @@ -0,0 +1,77 @@ +tests/cases/compiler/client.ts(1,1): error TS1188: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(2,1): error TS1188: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(4,1): error TS1188: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(6,1): error TS1188: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(9,1): error TS1188: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(11,1): error TS1188: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(13,1): error TS1188: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(16,1): error TS1188: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(19,1): error TS1188: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(21,1): error TS1188: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(25,1): error TS1188: An import declaration cannot have modifiers. +tests/cases/compiler/client.ts(26,1): error TS1188: An import declaration cannot have modifiers. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + export var a = 10; + export var x = a; + export var m = a; + export var a1 = 10; + export var x1 = 10; + export var z1 = 10; + export var z2 = 10; + export var aaaa = 10; + +==== tests/cases/compiler/client.ts (12 errors) ==== + export import { } from "server"; + ~~~~~~ +!!! error TS1188: An import declaration cannot have modifiers. + export import { a } from "server"; + ~~~~~~ +!!! error TS1188: An import declaration cannot have modifiers. + export var xxxx = a; + export import { a as b } from "server"; + ~~~~~~ +!!! error TS1188: An import declaration cannot have modifiers. + export var xxxx = b; + export import { x, a as y } from "server"; + ~~~~~~ +!!! error TS1188: An import declaration cannot have modifiers. + export var xxxx = x; + export var xxxx = y; + export import { x as z, } from "server"; + ~~~~~~ +!!! error TS1188: An import declaration cannot have modifiers. + export var xxxx = z; + export import { m, } from "server"; + ~~~~~~ +!!! error TS1188: An import declaration cannot have modifiers. + export var xxxx = m; + export import { a1, x1 } from "server"; + ~~~~~~ +!!! error TS1188: An import declaration cannot have modifiers. + export var xxxx = a1; + export var xxxx = x1; + export import { a1 as a11, x1 as x11 } from "server"; + ~~~~~~ +!!! error TS1188: An import declaration cannot have modifiers. + export var xxxx = a11; + export var xxxx = x11; + export import { z1 } from "server"; + ~~~~~~ +!!! error TS1188: An import declaration cannot have modifiers. + export var z111 = z1; + export import { z2 as z3 } from "server"; + ~~~~~~ +!!! error TS1188: An import declaration cannot have modifiers. + export var z2 = z3; // z2 shouldn't give redeclare error + + // Non referenced imports + export import { aaaa } from "server"; + ~~~~~~ +!!! error TS1188: An import declaration cannot have modifiers. + export import { aaaa as bbbb } from "server"; + ~~~~~~ +!!! error TS1188: An import declaration cannot have modifiers. + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNamedImportWithExport.js b/tests/baselines/reference/es6ImportNamedImportWithExport.js new file mode 100644 index 0000000000000..69ed42ca35c02 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportWithExport.js @@ -0,0 +1,109 @@ +//// [tests/cases/compiler/es6ImportNamedImportWithExport.ts] //// + +//// [server.ts] + +export var a = 10; +export var x = a; +export var m = a; +export var a1 = 10; +export var x1 = 10; +export var z1 = 10; +export var z2 = 10; +export var aaaa = 10; + +//// [client.ts] +export import { } from "server"; +export import { a } from "server"; +export var xxxx = a; +export import { a as b } from "server"; +export var xxxx = b; +export import { x, a as y } from "server"; +export var xxxx = x; +export var xxxx = y; +export import { x as z, } from "server"; +export var xxxx = z; +export import { m, } from "server"; +export var xxxx = m; +export import { a1, x1 } from "server"; +export var xxxx = a1; +export var xxxx = x1; +export import { a1 as a11, x1 as x11 } from "server"; +export var xxxx = a11; +export var xxxx = x11; +export import { z1 } from "server"; +export var z111 = z1; +export import { z2 as z3 } from "server"; +export var z2 = z3; // z2 shouldn't give redeclare error + +// Non referenced imports +export import { aaaa } from "server"; +export import { aaaa as bbbb } from "server"; + + +//// [server.js] +exports.a = 10; +exports.x = exports.a; +exports.m = exports.a; +exports.a1 = 10; +exports.x1 = 10; +exports.z1 = 10; +exports.z2 = 10; +exports.aaaa = 10; +//// [client.js] +var _a = require("server"); +var a = _a.a; +exports.xxxx = a; +var _b = require("server"); +var b = _b.a; +exports.xxxx = b; +var _c = require("server"); +var x = _c.x; +var y = _c.a; +exports.xxxx = x; +exports.xxxx = y; +var _d = require("server"); +var z = _d.x; +exports.xxxx = z; +var _e = require("server"); +var m = _e.m; +exports.xxxx = m; +var _f = require("server"); +var a1 = _f.a1; +var x1 = _f.x1; +exports.xxxx = a1; +exports.xxxx = x1; +var _g = require("server"); +var a11 = _g.a1; +var x11 = _g.x1; +exports.xxxx = a11; +exports.xxxx = x11; +var _h = require("server"); +var z1 = _h.z1; +exports.z111 = z1; +var _j = require("server"); +var z3 = _j.z2; +exports.z2 = z3; // z2 shouldn't give redeclare error + + +//// [server.d.ts] +export declare var a: number; +export declare var x: number; +export declare var m: number; +export declare var a1: number; +export declare var x1: number; +export declare var z1: number; +export declare var z2: number; +export declare var aaaa: number; +//// [client.d.ts] +export declare var xxxx: number; +export declare var xxxx: number; +export declare var xxxx: number; +export declare var xxxx: number; +export declare var xxxx: number; +export declare var xxxx: number; +export declare var xxxx: number; +export declare var xxxx: number; +export declare var xxxx: number; +export declare var xxxx: number; +export declare var z111: number; +export declare var z2: number; diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseWithExport.errors.txt b/tests/baselines/reference/es6ImportWithoutFromClauseWithExport.errors.txt new file mode 100644 index 0000000000000..c1fe9993d9525 --- /dev/null +++ b/tests/baselines/reference/es6ImportWithoutFromClauseWithExport.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/client.ts(1,1): error TS1188: An import declaration cannot have modifiers. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + export var a = 10; + +==== tests/cases/compiler/client.ts (1 errors) ==== + export import "server"; + ~~~~~~ +!!! error TS1188: An import declaration cannot have modifiers. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseWithExport.js b/tests/baselines/reference/es6ImportWithoutFromClauseWithExport.js new file mode 100644 index 0000000000000..208f71bcbfe9f --- /dev/null +++ b/tests/baselines/reference/es6ImportWithoutFromClauseWithExport.js @@ -0,0 +1,19 @@ +//// [tests/cases/compiler/es6ImportWithoutFromClauseWithExport.ts] //// + +//// [server.ts] + +export var a = 10; + +//// [client.ts] +export import "server"; + +//// [server.js] +exports.a = 10; +//// [client.js] +require("server"); + + +//// [server.d.ts] +export declare var a: number; +//// [client.d.ts] +export import "server"; diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.ts new file mode 100644 index 0000000000000..fef56560dcf81 --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1WithExport.ts @@ -0,0 +1,20 @@ +// @module: commonjs +// @declaration: true + +// @filename: server.ts +var a = 10; +export = a; + +// @filename: client.ts +export import defaultBinding1, { } from "server"; +export var x1: number = defaultBinding1; +export import defaultBinding2, { a } from "server"; +export var x1: number = defaultBinding2; +export import defaultBinding3, { a as b } from "server"; +export var x1: number = defaultBinding3; +export import defaultBinding4, { x, a as y } from "server"; +export var x1: number = defaultBinding4; +export import defaultBinding5, { x as z, } from "server"; +export var x1: number = defaultBinding5; +export import defaultBinding6, { m, } from "server"; +export var x1: number = defaultBinding6; diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportWithExport.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportWithExport.ts new file mode 100644 index 0000000000000..6e3ac5786d1e1 --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportWithExport.ts @@ -0,0 +1,21 @@ +// @module: amd +// @declaration: true + +// @filename: server.ts +export var a = 10; +export var x = a; +export var m = a; + +// @filename: client.ts +export import defaultBinding1, { } from "server"; +export import defaultBinding2, { a } from "server"; +export var x1: number = a; +export import defaultBinding3, { a as b } from "server"; +export var x1: number = b; +export import defaultBinding4, { x, a as y } from "server"; +export var x1: number = x; +export var x1: number = y; +export import defaultBinding5, { x as z, } from "server"; +export var x1: number = z; +export import defaultBinding6, { m, } from "server"; +export var x1: number = m; diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.ts new file mode 100644 index 0000000000000..ce42814a91818 --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1WithExport.ts @@ -0,0 +1,10 @@ +// @module: amd +// @declaration: true + +// @filename: server.ts +var a = 10; +export = a; + +// @filename: client.ts +export import defaultBinding, * as nameSpaceBinding from "server"; +export var x: number = defaultBinding; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.ts new file mode 100644 index 0000000000000..cafcace08a03d --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.ts @@ -0,0 +1,9 @@ +// @module: commonjs +// @declaration: true + +// @filename: server.ts +export var a = 10; + +// @filename: client.ts +export import defaultBinding, * as nameSpaceBinding from "server"; +export var x: number = nameSpaceBinding.a; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportDefaultBindingWithExport.ts b/tests/cases/compiler/es6ImportDefaultBindingWithExport.ts new file mode 100644 index 0000000000000..87494c8a62275 --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingWithExport.ts @@ -0,0 +1,11 @@ +// @module: amd +// @declaration: true + +// @filename: server.ts +var a = 10; +export = a; + +// @filename: client.ts +export import defaultBinding from "server"; +export var x = defaultBinding; +export import defaultBinding2 from "server"; // non referenced \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportNameSpaceImportWithExport.ts b/tests/cases/compiler/es6ImportNameSpaceImportWithExport.ts new file mode 100644 index 0000000000000..4110270d7ddb8 --- /dev/null +++ b/tests/cases/compiler/es6ImportNameSpaceImportWithExport.ts @@ -0,0 +1,10 @@ +// @module: amd +// @declaration: true + +// @filename: server.ts +export var a = 10; + +// @filename: client.ts +export import * as nameSpaceBinding from "server"; +export var x = nameSpaceBinding.a; +export import * as nameSpaceBinding2 from "server"; // Not referenced imports diff --git a/tests/cases/compiler/es6ImportNamedImportWithExport.ts b/tests/cases/compiler/es6ImportNamedImportWithExport.ts new file mode 100644 index 0000000000000..f25a3779b990e --- /dev/null +++ b/tests/cases/compiler/es6ImportNamedImportWithExport.ts @@ -0,0 +1,40 @@ +// @module: commonjs +// @declaration: true + +// @filename: server.ts +export var a = 10; +export var x = a; +export var m = a; +export var a1 = 10; +export var x1 = 10; +export var z1 = 10; +export var z2 = 10; +export var aaaa = 10; + +// @filename: client.ts +export import { } from "server"; +export import { a } from "server"; +export var xxxx = a; +export import { a as b } from "server"; +export var xxxx = b; +export import { x, a as y } from "server"; +export var xxxx = x; +export var xxxx = y; +export import { x as z, } from "server"; +export var xxxx = z; +export import { m, } from "server"; +export var xxxx = m; +export import { a1, x1 } from "server"; +export var xxxx = a1; +export var xxxx = x1; +export import { a1 as a11, x1 as x11 } from "server"; +export var xxxx = a11; +export var xxxx = x11; +export import { z1 } from "server"; +export var z111 = z1; +export import { z2 as z3 } from "server"; +export var z2 = z3; // z2 shouldn't give redeclare error + +// Non referenced imports +export import { aaaa } from "server"; +export import { aaaa as bbbb } from "server"; diff --git a/tests/cases/compiler/es6ImportWithoutFromClauseWithExport.ts b/tests/cases/compiler/es6ImportWithoutFromClauseWithExport.ts new file mode 100644 index 0000000000000..8c7ec10853830 --- /dev/null +++ b/tests/cases/compiler/es6ImportWithoutFromClauseWithExport.ts @@ -0,0 +1,8 @@ +// @module: commonjs +// @declaration: true + +// @filename: server.ts +export var a = 10; + +// @filename: client.ts +export import "server"; \ No newline at end of file From 00dc5fcce9fa56be9b133983ea1de23bb6e528bf Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 10 Feb 2015 17:53:29 -0800 Subject: [PATCH 009/224] Add test cases for dts generation without export tag --- .../reference/es6ImportDefaultBindingDts.js | 32 +++ .../es6ImportDefaultBindingDts.types | 20 ++ ...ndingFollowedWithNamedImportDts.errors.txt | 43 ++++ ...efaultBindingFollowedWithNamedImportDts.js | 102 ++++++++ ...dingFollowedWithNamedImportDts1.errors.txt | 38 +++ ...faultBindingFollowedWithNamedImportDts1.js | 55 +++++ ...FollowedWithNamespaceBindingDts.errors.txt | 12 + ...tBindingFollowedWithNamespaceBindingDts.js | 28 +++ ...BindingFollowedWithNamespaceBindingDts1.js | 33 +++ ...dingFollowedWithNamespaceBindingDts1.types | 18 ++ .../reference/es6ImportNameSpaceImportDts.js | 30 +++ .../es6ImportNameSpaceImportDts.types | 19 ++ .../reference/es6ImportNamedImportDts.js | 220 ++++++++++++++++++ .../reference/es6ImportNamedImportDts.types | 150 ++++++++++++ .../compiler/es6ImportDefaultBindingDts.ts | 11 + ...efaultBindingFollowedWithNamedImportDts.ts | 25 ++ ...faultBindingFollowedWithNamedImportDts1.ts | 20 ++ ...tBindingFollowedWithNamespaceBindingDts.ts | 9 + ...BindingFollowedWithNamespaceBindingDts1.ts | 10 + .../compiler/es6ImportNameSpaceImportDts.ts | 10 + .../cases/compiler/es6ImportNamedImportDts.ts | 46 ++++ 21 files changed, 931 insertions(+) create mode 100644 tests/baselines/reference/es6ImportDefaultBindingDts.js create mode 100644 tests/baselines/reference/es6ImportDefaultBindingDts.types create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.errors.txt create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.js create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts1.errors.txt create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts1.js create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.errors.txt create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.js create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.js create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.types create mode 100644 tests/baselines/reference/es6ImportNameSpaceImportDts.js create mode 100644 tests/baselines/reference/es6ImportNameSpaceImportDts.types create mode 100644 tests/baselines/reference/es6ImportNamedImportDts.js create mode 100644 tests/baselines/reference/es6ImportNamedImportDts.types create mode 100644 tests/cases/compiler/es6ImportDefaultBindingDts.ts create mode 100644 tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportDts.ts create mode 100644 tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportDts1.ts create mode 100644 tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.ts create mode 100644 tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.ts create mode 100644 tests/cases/compiler/es6ImportNameSpaceImportDts.ts create mode 100644 tests/cases/compiler/es6ImportNamedImportDts.ts diff --git a/tests/baselines/reference/es6ImportDefaultBindingDts.js b/tests/baselines/reference/es6ImportDefaultBindingDts.js new file mode 100644 index 0000000000000..4e9719892db40 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingDts.js @@ -0,0 +1,32 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingDts.ts] //// + +//// [server.ts] + +class c { } +export = c; + +//// [client.ts] +import defaultBinding from "server"; +export var x = new defaultBinding(); +import defaultBinding2 from "server"; // elide this import since defaultBinding2 is not used + + +//// [server.js] +var c = (function () { + function c() { + } + return c; +})(); +module.exports = c; +//// [client.js] +var defaultBinding = require("server"); +exports.x = new defaultBinding(); + + +//// [server.d.ts] +declare class c { +} +export = c; +//// [client.d.ts] +import defaultBinding from "server"; +export declare var x: defaultBinding; diff --git a/tests/baselines/reference/es6ImportDefaultBindingDts.types b/tests/baselines/reference/es6ImportDefaultBindingDts.types new file mode 100644 index 0000000000000..62f54168c3631 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingDts.types @@ -0,0 +1,20 @@ +=== tests/cases/compiler/server.ts === + +class c { } +>c : c + +export = c; +>c : c + +=== tests/cases/compiler/client.ts === +import defaultBinding from "server"; +>defaultBinding : typeof defaultBinding + +export var x = new defaultBinding(); +>x : defaultBinding +>new defaultBinding() : defaultBinding +>defaultBinding : typeof defaultBinding + +import defaultBinding2 from "server"; // elide this import since defaultBinding2 is not used +>defaultBinding2 : typeof defaultBinding + diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.errors.txt new file mode 100644 index 0000000000000..648868cf00114 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.errors.txt @@ -0,0 +1,43 @@ +tests/cases/compiler/client.ts(1,8): error TS1189: External module '"tests/cases/compiler/server"' has no default export or export assignment. +tests/cases/compiler/client.ts(2,8): error TS1189: External module '"tests/cases/compiler/server"' has no default export or export assignment. +tests/cases/compiler/client.ts(4,8): error TS1189: External module '"tests/cases/compiler/server"' has no default export or export assignment. +tests/cases/compiler/client.ts(6,8): error TS1189: External module '"tests/cases/compiler/server"' has no default export or export assignment. +tests/cases/compiler/client.ts(9,8): error TS1189: External module '"tests/cases/compiler/server"' has no default export or export assignment. +tests/cases/compiler/client.ts(11,8): error TS1189: External module '"tests/cases/compiler/server"' has no default export or export assignment. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + export class a { } + export class x { } + export class m { } + export class a11 { } + export class a12 { } + export class x11 { } + +==== tests/cases/compiler/client.ts (6 errors) ==== + import defaultBinding1, { } from "server"; + ~~~~~~~~~~~~~~~ +!!! error TS1189: External module '"tests/cases/compiler/server"' has no default export or export assignment. + import defaultBinding2, { a } from "server"; + ~~~~~~~~~~~~~~~ +!!! error TS1189: External module '"tests/cases/compiler/server"' has no default export or export assignment. + export var x1 = new a(); + import defaultBinding3, { a11 as b } from "server"; + ~~~~~~~~~~~~~~~ +!!! error TS1189: External module '"tests/cases/compiler/server"' has no default export or export assignment. + export var x2 = new b(); + import defaultBinding4, { x, a12 as y } from "server"; + ~~~~~~~~~~~~~~~ +!!! error TS1189: External module '"tests/cases/compiler/server"' has no default export or export assignment. + export var x4 = new x(); + export var x5 = new y(); + import defaultBinding5, { x11 as z, } from "server"; + ~~~~~~~~~~~~~~~ +!!! error TS1189: External module '"tests/cases/compiler/server"' has no default export or export assignment. + export var x3 = new z(); + import defaultBinding6, { m, } from "server"; + ~~~~~~~~~~~~~~~ +!!! error TS1189: External module '"tests/cases/compiler/server"' has no default export or export assignment. + export var x6 = new m(); + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.js new file mode 100644 index 0000000000000..3d404658e38fd --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.js @@ -0,0 +1,102 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportDts.ts] //// + +//// [server.ts] + +export class a { } +export class x { } +export class m { } +export class a11 { } +export class a12 { } +export class x11 { } + +//// [client.ts] +import defaultBinding1, { } from "server"; +import defaultBinding2, { a } from "server"; +export var x1 = new a(); +import defaultBinding3, { a11 as b } from "server"; +export var x2 = new b(); +import defaultBinding4, { x, a12 as y } from "server"; +export var x4 = new x(); +export var x5 = new y(); +import defaultBinding5, { x11 as z, } from "server"; +export var x3 = new z(); +import defaultBinding6, { m, } from "server"; +export var x6 = new m(); + + +//// [server.js] +var a = (function () { + function a() { + } + return a; +})(); +exports.a = a; +var x = (function () { + function x() { + } + return x; +})(); +exports.x = x; +var m = (function () { + function m() { + } + return m; +})(); +exports.m = m; +var a11 = (function () { + function a11() { + } + return a11; +})(); +exports.a11 = a11; +var a12 = (function () { + function a12() { + } + return a12; +})(); +exports.a12 = a12; +var x11 = (function () { + function x11() { + } + return x11; +})(); +exports.x11 = x11; +//// [client.js] +var defaultBinding2 = require("server"); +exports.x1 = new a(); +var defaultBinding3 = require("server"); +exports.x2 = new b(); +var defaultBinding4 = require("server"); +exports.x4 = new x(); +exports.x5 = new y(); +var defaultBinding5 = require("server"); +exports.x3 = new z(); +var defaultBinding6 = require("server"); +exports.x6 = new m(); + + +//// [server.d.ts] +export declare class a { +} +export declare class x { +} +export declare class m { +} +export declare class a11 { +} +export declare class a12 { +} +export declare class x11 { +} +//// [client.d.ts] +import { a } from "server"; +export declare var x1: a; +import { a11 as b } from "server"; +export declare var x2: b; +import { x, a12 as y } from "server"; +export declare var x4: x; +export declare var x5: y; +import { x11 as z } from "server"; +export declare var x3: z; +import { m } from "server"; +export declare var x6: m; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts1.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts1.errors.txt new file mode 100644 index 0000000000000..405fab0de509e --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts1.errors.txt @@ -0,0 +1,38 @@ +tests/cases/compiler/client.ts(3,27): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. +tests/cases/compiler/client.ts(5,27): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. +tests/cases/compiler/client.ts(7,27): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'x'. +tests/cases/compiler/client.ts(7,30): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. +tests/cases/compiler/client.ts(9,27): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'x'. +tests/cases/compiler/client.ts(11,27): error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'm'. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + class a { } + export = a; + +==== tests/cases/compiler/client.ts (6 errors) ==== + import defaultBinding1, { } from "server"; + export var x1 = new defaultBinding1(); + import defaultBinding2, { a } from "server"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. + export var x2 = new defaultBinding2(); + import defaultBinding3, { a as b } from "server"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. + export var x3 = new defaultBinding3(); + import defaultBinding4, { x, a as y } from "server"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'x'. + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'a'. + export var x4 = new defaultBinding4(); + import defaultBinding5, { x as z, } from "server"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'x'. + export var x5 = new defaultBinding5(); + import defaultBinding6, { m, } from "server"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/server"' has no exported member 'm'. + export var x6 = new defaultBinding6(); \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts1.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts1.js new file mode 100644 index 0000000000000..21ddcbc71d6c2 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts1.js @@ -0,0 +1,55 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportDts1.ts] //// + +//// [server.ts] + +class a { } +export = a; + +//// [client.ts] +import defaultBinding1, { } from "server"; +export var x1 = new defaultBinding1(); +import defaultBinding2, { a } from "server"; +export var x2 = new defaultBinding2(); +import defaultBinding3, { a as b } from "server"; +export var x3 = new defaultBinding3(); +import defaultBinding4, { x, a as y } from "server"; +export var x4 = new defaultBinding4(); +import defaultBinding5, { x as z, } from "server"; +export var x5 = new defaultBinding5(); +import defaultBinding6, { m, } from "server"; +export var x6 = new defaultBinding6(); + +//// [server.js] +var a = (function () { + function a() { + } + return a; +})(); +module.exports = a; +//// [client.js] +var defaultBinding1 = require("server"); +exports.x1 = new defaultBinding1(); +var defaultBinding2 = require("server"); +exports.x2 = new defaultBinding2(); +var defaultBinding3 = require("server"); +exports.x3 = new defaultBinding3(); +var defaultBinding4 = require("server"); +exports.x4 = new defaultBinding4(); +var defaultBinding5 = require("server"); +exports.x5 = new defaultBinding5(); +var defaultBinding6 = require("server"); +exports.x6 = new defaultBinding6(); + + +//// [server.d.ts] +declare class a { +} +export = a; +//// [client.d.ts] +import defaultBinding1 from "server"; +export declare var x1: defaultBinding1; +export declare var x2: defaultBinding1; +export declare var x3: defaultBinding1; +export declare var x4: defaultBinding1; +export declare var x5: defaultBinding1; +export declare var x6: defaultBinding1; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.errors.txt new file mode 100644 index 0000000000000..4df73e2ed9d8e --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.errors.txt @@ -0,0 +1,12 @@ +tests/cases/compiler/client.ts(1,8): error TS1189: External module '"tests/cases/compiler/server"' has no default export or export assignment. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + export class a { } + +==== tests/cases/compiler/client.ts (1 errors) ==== + import defaultBinding, * as nameSpaceBinding from "server"; + ~~~~~~~~~~~~~~ +!!! error TS1189: External module '"tests/cases/compiler/server"' has no default export or export assignment. + export var x = new nameSpaceBinding.a(); \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.js new file mode 100644 index 0000000000000..99ad9fd57ab2c --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.js @@ -0,0 +1,28 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.ts] //// + +//// [server.ts] + +export class a { } + +//// [client.ts] +import defaultBinding, * as nameSpaceBinding from "server"; +export var x = new nameSpaceBinding.a(); + +//// [server.js] +var a = (function () { + function a() { + } + return a; +})(); +exports.a = a; +//// [client.js] +var defaultBinding = require("server"); +exports.x = new nameSpaceBinding.a(); + + +//// [server.d.ts] +export declare class a { +} +//// [client.d.ts] +import * as nameSpaceBinding from "server"; +export declare var x: nameSpaceBinding.a; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.js new file mode 100644 index 0000000000000..69b76d79fbbd5 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.js @@ -0,0 +1,33 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.ts] //// + +//// [server.ts] + +class a { } +export = a; + +//// [client.ts] +import defaultBinding, * as nameSpaceBinding from "server"; +export var x = new defaultBinding(); + +//// [server.js] +define(["require", "exports"], function (require, exports) { + var a = (function () { + function a() { + } + return a; + })(); + return a; +}); +//// [client.js] +define(["require", "exports", "server"], function (require, exports, defaultBinding) { + exports.x = new defaultBinding(); +}); + + +//// [server.d.ts] +declare class a { +} +export = a; +//// [client.d.ts] +import defaultBinding from "server"; +export declare var x: defaultBinding; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.types b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.types new file mode 100644 index 0000000000000..e40d3893ee216 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.types @@ -0,0 +1,18 @@ +=== tests/cases/compiler/server.ts === + +class a { } +>a : a + +export = a; +>a : a + +=== tests/cases/compiler/client.ts === +import defaultBinding, * as nameSpaceBinding from "server"; +>defaultBinding : typeof defaultBinding +>nameSpaceBinding : typeof nameSpaceBinding + +export var x = new defaultBinding(); +>x : defaultBinding +>new defaultBinding() : defaultBinding +>defaultBinding : typeof defaultBinding + diff --git a/tests/baselines/reference/es6ImportNameSpaceImportDts.js b/tests/baselines/reference/es6ImportNameSpaceImportDts.js new file mode 100644 index 0000000000000..91e927428a166 --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportDts.js @@ -0,0 +1,30 @@ +//// [tests/cases/compiler/es6ImportNameSpaceImportDts.ts] //// + +//// [server.ts] + +export class c { }; + +//// [client.ts] +import * as nameSpaceBinding from "server"; +export var x = new nameSpaceBinding.c(); +import * as nameSpaceBinding2 from "server"; // unreferenced + +//// [server.js] +var c = (function () { + function c() { + } + return c; +})(); +exports.c = c; +; +//// [client.js] +var nameSpaceBinding = require("server"); +exports.x = new nameSpaceBinding.c(); + + +//// [server.d.ts] +export declare class c { +} +//// [client.d.ts] +import * as nameSpaceBinding from "server"; +export declare var x: nameSpaceBinding.c; diff --git a/tests/baselines/reference/es6ImportNameSpaceImportDts.types b/tests/baselines/reference/es6ImportNameSpaceImportDts.types new file mode 100644 index 0000000000000..345d593b1437b --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportDts.types @@ -0,0 +1,19 @@ +=== tests/cases/compiler/server.ts === + +export class c { }; +>c : c + +=== tests/cases/compiler/client.ts === +import * as nameSpaceBinding from "server"; +>nameSpaceBinding : typeof nameSpaceBinding + +export var x = new nameSpaceBinding.c(); +>x : nameSpaceBinding.c +>new nameSpaceBinding.c() : nameSpaceBinding.c +>nameSpaceBinding.c : typeof nameSpaceBinding.c +>nameSpaceBinding : typeof nameSpaceBinding +>c : typeof nameSpaceBinding.c + +import * as nameSpaceBinding2 from "server"; // unreferenced +>nameSpaceBinding2 : typeof nameSpaceBinding + diff --git a/tests/baselines/reference/es6ImportNamedImportDts.js b/tests/baselines/reference/es6ImportNamedImportDts.js new file mode 100644 index 0000000000000..6394240a93313 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportDts.js @@ -0,0 +1,220 @@ +//// [tests/cases/compiler/es6ImportNamedImportDts.ts] //// + +//// [server.ts] + +export class a { } +export class a11 { } +export class a12 { } +export class x { } +export class x11 { } +export class m { } +export class a1 { } +export class x1 { } +export class a111 { } +export class x111 { } +export class z1 { } +export class z2 { } +export class aaaa { } +export class aaaa1 { } + +//// [client.ts] +import { } from "server"; +import { a } from "server"; +export var xxxx = new a(); +import { a11 as b } from "server"; +export var xxxx1 = new b(); +import { x, a12 as y } from "server"; +export var xxxx2 = new x(); +export var xxxx3 = new y(); +import { x11 as z, } from "server"; +export var xxxx4 = new z(); +import { m, } from "server"; +export var xxxx5 = new m(); +import { a1, x1 } from "server"; +export var xxxx6 = new a1(); +export var xxxx7 = new x1(); +import { a111 as a11, x111 as x11 } from "server"; +export var xxxx8 = new a11(); +export var xxxx9 = new x11(); +import { z1 } from "server"; +export var z111 = new z1(); +import { z2 as z3 } from "server"; +export var z2 = new z3(); // z2 shouldn't give redeclare error + +// not referenced +import { aaaa } from "server"; +import { aaaa1 as bbbb } from "server"; + + +//// [server.js] +var a = (function () { + function a() { + } + return a; +})(); +exports.a = a; +var a11 = (function () { + function a11() { + } + return a11; +})(); +exports.a11 = a11; +var a12 = (function () { + function a12() { + } + return a12; +})(); +exports.a12 = a12; +var x = (function () { + function x() { + } + return x; +})(); +exports.x = x; +var x11 = (function () { + function x11() { + } + return x11; +})(); +exports.x11 = x11; +var m = (function () { + function m() { + } + return m; +})(); +exports.m = m; +var a1 = (function () { + function a1() { + } + return a1; +})(); +exports.a1 = a1; +var x1 = (function () { + function x1() { + } + return x1; +})(); +exports.x1 = x1; +var a111 = (function () { + function a111() { + } + return a111; +})(); +exports.a111 = a111; +var x111 = (function () { + function x111() { + } + return x111; +})(); +exports.x111 = x111; +var z1 = (function () { + function z1() { + } + return z1; +})(); +exports.z1 = z1; +var z2 = (function () { + function z2() { + } + return z2; +})(); +exports.z2 = z2; +var aaaa = (function () { + function aaaa() { + } + return aaaa; +})(); +exports.aaaa = aaaa; +var aaaa1 = (function () { + function aaaa1() { + } + return aaaa1; +})(); +exports.aaaa1 = aaaa1; +//// [client.js] +var _a = require("server"); +var a = _a.a; +exports.xxxx = new a(); +var _b = require("server"); +var b = _b.a11; +exports.xxxx1 = new b(); +var _c = require("server"); +var x = _c.x; +var y = _c.a12; +exports.xxxx2 = new x(); +exports.xxxx3 = new y(); +var _d = require("server"); +var z = _d.x11; +exports.xxxx4 = new z(); +var _e = require("server"); +var m = _e.m; +exports.xxxx5 = new m(); +var _f = require("server"); +var a1 = _f.a1; +var x1 = _f.x1; +exports.xxxx6 = new a1(); +exports.xxxx7 = new x1(); +var _g = require("server"); +var a11 = _g.a111; +var x11 = _g.x111; +exports.xxxx8 = new a11(); +exports.xxxx9 = new x11(); +var _h = require("server"); +var z1 = _h.z1; +exports.z111 = new z1(); +var _j = require("server"); +var z3 = _j.z2; +exports.z2 = new z3(); // z2 shouldn't give redeclare error + + +//// [server.d.ts] +export declare class a { +} +export declare class a11 { +} +export declare class a12 { +} +export declare class x { +} +export declare class x11 { +} +export declare class m { +} +export declare class a1 { +} +export declare class x1 { +} +export declare class a111 { +} +export declare class x111 { +} +export declare class z1 { +} +export declare class z2 { +} +export declare class aaaa { +} +export declare class aaaa1 { +} +//// [client.d.ts] +import { a } from "server"; +export declare var xxxx: a; +import { a11 as b } from "server"; +export declare var xxxx1: b; +import { x, a12 as y } from "server"; +export declare var xxxx2: x; +export declare var xxxx3: y; +import { x11 as z } from "server"; +export declare var xxxx4: z; +import { m } from "server"; +export declare var xxxx5: m; +import { a1, x1 } from "server"; +export declare var xxxx6: a1; +export declare var xxxx7: x1; +import { a111 as a11, x111 as x11 } from "server"; +export declare var xxxx8: a11; +export declare var xxxx9: x11; +import { z1 } from "server"; +export declare var z111: z1; +import { z2 as z3 } from "server"; +export declare var z2: z3; diff --git a/tests/baselines/reference/es6ImportNamedImportDts.types b/tests/baselines/reference/es6ImportNamedImportDts.types new file mode 100644 index 0000000000000..ba036202a52c2 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportDts.types @@ -0,0 +1,150 @@ +=== tests/cases/compiler/server.ts === + +export class a { } +>a : a + +export class a11 { } +>a11 : a11 + +export class a12 { } +>a12 : a12 + +export class x { } +>x : x + +export class x11 { } +>x11 : x11 + +export class m { } +>m : m + +export class a1 { } +>a1 : a1 + +export class x1 { } +>x1 : x1 + +export class a111 { } +>a111 : a111 + +export class x111 { } +>x111 : x111 + +export class z1 { } +>z1 : z1 + +export class z2 { } +>z2 : z2 + +export class aaaa { } +>aaaa : aaaa + +export class aaaa1 { } +>aaaa1 : aaaa1 + +=== tests/cases/compiler/client.ts === +import { } from "server"; +import { a } from "server"; +>a : typeof a + +export var xxxx = new a(); +>xxxx : a +>new a() : a +>a : typeof a + +import { a11 as b } from "server"; +>a11 : unknown +>b : typeof b + +export var xxxx1 = new b(); +>xxxx1 : b +>new b() : b +>b : typeof b + +import { x, a12 as y } from "server"; +>x : typeof x +>a12 : unknown +>y : typeof y + +export var xxxx2 = new x(); +>xxxx2 : x +>new x() : x +>x : typeof x + +export var xxxx3 = new y(); +>xxxx3 : y +>new y() : y +>y : typeof y + +import { x11 as z, } from "server"; +>x11 : unknown +>z : typeof z + +export var xxxx4 = new z(); +>xxxx4 : z +>new z() : z +>z : typeof z + +import { m, } from "server"; +>m : typeof m + +export var xxxx5 = new m(); +>xxxx5 : m +>new m() : m +>m : typeof m + +import { a1, x1 } from "server"; +>a1 : typeof a1 +>x1 : typeof x1 + +export var xxxx6 = new a1(); +>xxxx6 : a1 +>new a1() : a1 +>a1 : typeof a1 + +export var xxxx7 = new x1(); +>xxxx7 : x1 +>new x1() : x1 +>x1 : typeof x1 + +import { a111 as a11, x111 as x11 } from "server"; +>a111 : unknown +>a11 : typeof a11 +>x111 : unknown +>x11 : typeof x11 + +export var xxxx8 = new a11(); +>xxxx8 : a11 +>new a11() : a11 +>a11 : typeof a11 + +export var xxxx9 = new x11(); +>xxxx9 : x11 +>new x11() : x11 +>x11 : typeof x11 + +import { z1 } from "server"; +>z1 : typeof z1 + +export var z111 = new z1(); +>z111 : z1 +>new z1() : z1 +>z1 : typeof z1 + +import { z2 as z3 } from "server"; +>z2 : unknown +>z3 : typeof z3 + +export var z2 = new z3(); // z2 shouldn't give redeclare error +>z2 : z3 +>new z3() : z3 +>z3 : typeof z3 + +// not referenced +import { aaaa } from "server"; +>aaaa : typeof aaaa + +import { aaaa1 as bbbb } from "server"; +>aaaa1 : unknown +>bbbb : typeof bbbb + diff --git a/tests/cases/compiler/es6ImportDefaultBindingDts.ts b/tests/cases/compiler/es6ImportDefaultBindingDts.ts new file mode 100644 index 0000000000000..4700782b78e73 --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingDts.ts @@ -0,0 +1,11 @@ +// @module: commonjs +// @declaration: true + +// @filename: server.ts +class c { } +export = c; + +// @filename: client.ts +import defaultBinding from "server"; +export var x = new defaultBinding(); +import defaultBinding2 from "server"; // elide this import since defaultBinding2 is not used diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportDts.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportDts.ts new file mode 100644 index 0000000000000..64ae625c892b2 --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportDts.ts @@ -0,0 +1,25 @@ +// @target: es6 +// @module: commonjs +// @declaration: true + +// @filename: server.ts +export class a { } +export class x { } +export class m { } +export class a11 { } +export class a12 { } +export class x11 { } + +// @filename: client.ts +import defaultBinding1, { } from "server"; +import defaultBinding2, { a } from "server"; +export var x1 = new a(); +import defaultBinding3, { a11 as b } from "server"; +export var x2 = new b(); +import defaultBinding4, { x, a12 as y } from "server"; +export var x4 = new x(); +export var x5 = new y(); +import defaultBinding5, { x11 as z, } from "server"; +export var x3 = new z(); +import defaultBinding6, { m, } from "server"; +export var x6 = new m(); diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportDts1.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportDts1.ts new file mode 100644 index 0000000000000..1951a8a6b30e6 --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportDts1.ts @@ -0,0 +1,20 @@ +// @module: commonjs +// @declaration: true + +// @filename: server.ts +class a { } +export = a; + +// @filename: client.ts +import defaultBinding1, { } from "server"; +export var x1 = new defaultBinding1(); +import defaultBinding2, { a } from "server"; +export var x2 = new defaultBinding2(); +import defaultBinding3, { a as b } from "server"; +export var x3 = new defaultBinding3(); +import defaultBinding4, { x, a as y } from "server"; +export var x4 = new defaultBinding4(); +import defaultBinding5, { x as z, } from "server"; +export var x5 = new defaultBinding5(); +import defaultBinding6, { m, } from "server"; +export var x6 = new defaultBinding6(); \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.ts new file mode 100644 index 0000000000000..732f7ef7ba00b --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.ts @@ -0,0 +1,9 @@ +// @module: commonjs +// @declaration: true + +// @filename: server.ts +export class a { } + +// @filename: client.ts +import defaultBinding, * as nameSpaceBinding from "server"; +export var x = new nameSpaceBinding.a(); \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.ts new file mode 100644 index 0000000000000..1f026af8f34df --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.ts @@ -0,0 +1,10 @@ +// @module: amd +// @declaration: true + +// @filename: server.ts +class a { } +export = a; + +// @filename: client.ts +import defaultBinding, * as nameSpaceBinding from "server"; +export var x = new defaultBinding(); \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportNameSpaceImportDts.ts b/tests/cases/compiler/es6ImportNameSpaceImportDts.ts new file mode 100644 index 0000000000000..95b85e53edc2a --- /dev/null +++ b/tests/cases/compiler/es6ImportNameSpaceImportDts.ts @@ -0,0 +1,10 @@ +// @module: commonjs +// @declaration: true + +// @filename: server.ts +export class c { }; + +// @filename: client.ts +import * as nameSpaceBinding from "server"; +export var x = new nameSpaceBinding.c(); +import * as nameSpaceBinding2 from "server"; // unreferenced \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportNamedImportDts.ts b/tests/cases/compiler/es6ImportNamedImportDts.ts new file mode 100644 index 0000000000000..d83672f375446 --- /dev/null +++ b/tests/cases/compiler/es6ImportNamedImportDts.ts @@ -0,0 +1,46 @@ +// @module: commonjs +// @declaration: true + +// @filename: server.ts +export class a { } +export class a11 { } +export class a12 { } +export class x { } +export class x11 { } +export class m { } +export class a1 { } +export class x1 { } +export class a111 { } +export class x111 { } +export class z1 { } +export class z2 { } +export class aaaa { } +export class aaaa1 { } + +// @filename: client.ts +import { } from "server"; +import { a } from "server"; +export var xxxx = new a(); +import { a11 as b } from "server"; +export var xxxx1 = new b(); +import { x, a12 as y } from "server"; +export var xxxx2 = new x(); +export var xxxx3 = new y(); +import { x11 as z, } from "server"; +export var xxxx4 = new z(); +import { m, } from "server"; +export var xxxx5 = new m(); +import { a1, x1 } from "server"; +export var xxxx6 = new a1(); +export var xxxx7 = new x1(); +import { a111 as a11, x111 as x11 } from "server"; +export var xxxx8 = new a11(); +export var xxxx9 = new x11(); +import { z1 } from "server"; +export var z111 = new z1(); +import { z2 as z3 } from "server"; +export var z2 = new z3(); // z2 shouldn't give redeclare error + +// not referenced +import { aaaa } from "server"; +import { aaaa1 as bbbb } from "server"; From f8351c8865cede70161e75ee8590f60c0a345bea Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 10 Feb 2015 19:02:13 -0800 Subject: [PATCH 010/224] Set the declarations of export assignment visible on demand through dts emit Emit those new declarations asynchronously since they are otherwise not visible --- src/compiler/checker.ts | 94 ++-- src/compiler/emitter.ts | 430 ++++++++++-------- src/compiler/types.ts | 1 + .../baselines/reference/APISample_compile.js | 1 + .../reference/APISample_compile.types | 6 + tests/baselines/reference/APISample_linter.js | 1 + .../reference/APISample_linter.types | 6 + .../reference/APISample_transform.js | 1 + .../reference/APISample_transform.types | 6 + .../baselines/reference/APISample_watcher.js | 1 + .../reference/APISample_watcher.types | 6 + ...ationEmitImportInExportAssignmentModule.js | 39 ++ ...onEmitImportInExportAssignmentModule.types | 23 + ...ationEmitImportInExportAssignmentModule.ts | 12 + 14 files changed, 380 insertions(+), 247 deletions(-) create mode 100644 tests/baselines/reference/declarationEmitImportInExportAssignmentModule.js create mode 100644 tests/baselines/reference/declarationEmitImportInExportAssignmentModule.types create mode 100644 tests/cases/compiler/declarationEmitImportInExportAssignmentModule.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 2e4553a4bc023..249113e86f771 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1588,65 +1588,6 @@ module ts { } function isDeclarationVisible(node: Declaration): boolean { - function getContainingExternalModule(node: Node) { - for (; node; node = node.parent) { - if (node.kind === SyntaxKind.ModuleDeclaration) { - if ((node).name.kind === SyntaxKind.StringLiteral) { - return node; - } - } - else if (node.kind === SyntaxKind.SourceFile) { - return isExternalModule(node) ? node : undefined; - } - } - Debug.fail("getContainingModule cant reach here"); - } - - function isUsedInExportAssignment(node: Node) { - // Get source File and see if it is external module and has export assigned symbol - var externalModule = getContainingExternalModule(node); - if (externalModule) { - // This is export assigned symbol node - var externalModuleSymbol = getSymbolOfNode(externalModule); - var exportAssignmentSymbol = getExportAssignmentSymbol(externalModuleSymbol); - var resolvedExportSymbol: Symbol; - var symbolOfNode = getSymbolOfNode(node); - if (isSymbolUsedInExportAssignment(symbolOfNode)) { - return true; - } - - // if symbolOfNode is import declaration, resolve the symbol declaration and check - if (symbolOfNode.flags & SymbolFlags.Import) { - return isSymbolUsedInExportAssignment(resolveImport(symbolOfNode)); - } - } - - // Check if the symbol is used in export assignment - function isSymbolUsedInExportAssignment(symbol: Symbol) { - if (exportAssignmentSymbol === symbol) { - return true; - } - - if (exportAssignmentSymbol && !!(exportAssignmentSymbol.flags & SymbolFlags.Import)) { - // if export assigned symbol is import declaration, resolve the import - resolvedExportSymbol = resolvedExportSymbol || resolveImport(exportAssignmentSymbol); - if (resolvedExportSymbol === symbol) { - return true; - } - - // Container of resolvedExportSymbol is visible - return forEach(resolvedExportSymbol.declarations, (current: Node) => { - while (current) { - if (current === node) { - return true; - } - current = current.parent; - } - }); - } - } - } - function determineIfDeclarationIsVisible() { switch (node.kind) { case SyntaxKind.VariableDeclaration: @@ -1662,7 +1603,7 @@ module ts { // If the node is not exported or it is not ambient module element (except import declaration) if (!(getCombinedNodeFlags(node) & NodeFlags.Export) && !(node.kind !== SyntaxKind.ImportEqualsDeclaration && parent.kind !== SyntaxKind.SourceFile && isInAmbientContext(parent))) { - return isGlobalSourceFile(parent) || isUsedInExportAssignment(node); + return isGlobalSourceFile(parent); } // Exported members/ambient module elements (exception import declaration) are visible if parent is visible return isDeclarationVisible(parent); @@ -1696,11 +1637,11 @@ module ts { return isDeclarationVisible(node.parent); // Default binding, import specifier and namespace import is visible - // only if the import declaration is exported or it is used in export assignment + // only on demand so by default it is not visible case SyntaxKind.ImportClause: case SyntaxKind.NamespaceImport: case SyntaxKind.ImportSpecifier: - return (node.name && isUsedInExportAssignment(node)); + return false; // Type parameters are always visible case SyntaxKind.TypeParameter: @@ -1722,6 +1663,34 @@ module ts { } } + function setDeclarationsOfIdentifierAsVisible(node: Identifier): Node[]{ + if (node.parent && node.parent.kind === SyntaxKind.ExportAssignment) { + var exportSymbol = resolveName(node.parent, node.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, Diagnostics.Cannot_find_name_0, node); + var result: Node[] = []; + buildVisibleNodeList(exportSymbol.declarations); + return result; + } + + function buildVisibleNodeList(declarations: Declaration[]) { + forEach(declarations, declaration => { + getNodeLinks(declaration).isVisible = true; + var resultNode = getAnyImportSyntax(declaration) || declaration; + if (!contains(result, resultNode)) { + result.push(resultNode); + } + + if (isInternalModuleImportEqualsDeclaration(declaration)) { + // Add the referenced top container visible + var internalModuleReference = (declaration).moduleReference; + var firstIdentifier = getFirstIdentifier(internalModuleReference); + var importSymbol = resolveName(declaration, firstIdentifier.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, + Diagnostics.Cannot_find_name_0, firstIdentifier); + buildVisibleNodeList(importSymbol.declarations); + } + }); + } + } + function getRootDeclaration(node: Node): Node { while (node.kind === SyntaxKind.BindingElement) { node = node.parent.parent; @@ -10349,6 +10318,7 @@ module ts { isEntityNameVisible, getConstantValue, isUnknownIdentifier, + setDeclarationsOfIdentifierAsVisible }; } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 63e6e992b35f2..fff78fbb77470 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -34,17 +34,18 @@ module ts { getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic; } - interface AliasDeclarationEmitInfo { - declaration: AnyImportSyntax; + interface ModuleElementDeclarationEmitInfo { + node: Node; outputPos: number; indent: number; asynchronousOutput?: string; // If the output for alias was written asynchronously, the corresponding output + subModuleElementDeclarationEmitInfo?: ModuleElementDeclarationEmitInfo[]; isVisible?: boolean; } interface DeclarationEmit { reportedDeclarationError: boolean; - aliasDeclarationEmitInfo: AliasDeclarationEmitInfo[]; + moduleElementDeclarationEmitInfo: ModuleElementDeclarationEmitInfo[]; synchronousDeclarationOutput: string; referencePathsOutput: string; } @@ -365,7 +366,8 @@ module ts { var emitJsDocComments = compilerOptions.removeComments ? function (declaration: Node) { } : writeJsDocComments; var emit = compilerOptions.stripInternal ? stripInternal : emitNode; - var aliasDeclarationEmitInfo: AliasDeclarationEmitInfo[] = []; + var moduleElementDeclarationEmitInfo: ModuleElementDeclarationEmitInfo[] = []; + var asynchronousSubModuleDeclarationEmitInfo: ModuleElementDeclarationEmitInfo[]; // Contains the reference paths that needs to go in the declaration file. // Collecting this separately because reference paths need to be first thing in the declaration file @@ -395,14 +397,14 @@ module ts { emitSourceFile(root); // create asynchronous output for the importDeclarations - if (aliasDeclarationEmitInfo.length) { + if (moduleElementDeclarationEmitInfo.length) { var oldWriter = writer; - forEach(aliasDeclarationEmitInfo, aliasEmitInfo => { + forEach(moduleElementDeclarationEmitInfo, aliasEmitInfo => { if (aliasEmitInfo.isVisible) { - Debug.assert(aliasEmitInfo.declaration.kind === SyntaxKind.ImportDeclaration); + Debug.assert(aliasEmitInfo.node.kind === SyntaxKind.ImportDeclaration); createAndSetNewTextWriterWithSymbolWriter(); Debug.assert(aliasEmitInfo.indent === 0); - writeImportDeclaration(aliasEmitInfo.declaration); + writeImportDeclaration(aliasEmitInfo.node); aliasEmitInfo.asynchronousOutput = writer.getText(); } }); @@ -436,7 +438,7 @@ module ts { return { reportedDeclarationError, - aliasDeclarationEmitInfo, + moduleElementDeclarationEmitInfo, synchronousDeclarationOutput: writer.getText(), referencePathsOutput, } @@ -481,10 +483,23 @@ module ts { decreaseIndent = newWriter.decreaseIndent; } - function writeAsychronousImportEqualsDeclarations(anyImportSyntax: AnyImportSyntax[]) { + function writeAsynchronousModuleElements(nodes: Node[]) { var oldWriter = writer; - forEach(anyImportSyntax, aliasToWrite => { - var aliasEmitInfo = forEach(aliasDeclarationEmitInfo, declEmitInfo => declEmitInfo.declaration === aliasToWrite ? declEmitInfo : undefined); + forEach(nodes, declaration => { + var nodeToCheck: Node; + if (declaration.kind === SyntaxKind.VariableDeclaration) { + nodeToCheck = declaration.parent.parent; + } else if (declaration.kind === SyntaxKind.NamedImports || declaration.kind === SyntaxKind.ImportSpecifier || declaration.kind === SyntaxKind.ImportClause) { + Debug.fail("We should be getting ImportDeclaration instead to write"); + } else { + nodeToCheck = declaration; + } + + var moduleElementEmitInfo = forEach(moduleElementDeclarationEmitInfo, declEmitInfo => declEmitInfo.node === nodeToCheck ? declEmitInfo : undefined); + if (!moduleElementEmitInfo && asynchronousSubModuleDeclarationEmitInfo) { + moduleElementEmitInfo = forEach(asynchronousSubModuleDeclarationEmitInfo, declEmitInfo => declEmitInfo.node === nodeToCheck ? declEmitInfo : undefined); + } + // If the alias was marked as not visible when we saw its declaration, we would have saved the aliasEmitInfo, but if we haven't yet visited the alias declaration // then we don't need to write it at this point. We will write it when we actually see its declaration // Eg. @@ -492,19 +507,28 @@ module ts { // import foo = require("foo"); // Writing of function bar would mark alias declaration foo as visible but we haven't yet visited that declaration so do nothing, // we would write alias foo declaration when we visit it since it would now be marked as visible - if (aliasEmitInfo) { - if (aliasToWrite.kind === SyntaxKind.ImportEqualsDeclaration) { + if (moduleElementEmitInfo) { + if (moduleElementEmitInfo.node.kind === SyntaxKind.ImportDeclaration) { + // we have to create asynchronous output only after we have collected complete information + // because it is possible to enable multiple bindings as asynchronously visible + moduleElementEmitInfo.isVisible = true; + } + else { createAndSetNewTextWriterWithSymbolWriter(); - for (var declarationIndent = aliasEmitInfo.indent; declarationIndent; declarationIndent--) { + for (var declarationIndent = moduleElementEmitInfo.indent; declarationIndent; declarationIndent--) { increaseIndent(); } - writeImportEqualsDeclaration(aliasToWrite); - aliasEmitInfo.asynchronousOutput = writer.getText(); - } - else { - // we have to create asynchronous output only after we have collected complete information - // because it is possible to enable multiple bindings as asynchronously visible - aliasEmitInfo.isVisible = true; + + if (nodeToCheck.kind === SyntaxKind.ModuleDeclaration) { + Debug.assert(asynchronousSubModuleDeclarationEmitInfo === undefined); + asynchronousSubModuleDeclarationEmitInfo = []; + } + writeModuleElement(nodeToCheck); + if (nodeToCheck.kind === SyntaxKind.ModuleDeclaration) { + moduleElementEmitInfo.subModuleElementDeclarationEmitInfo = asynchronousSubModuleDeclarationEmitInfo; + asynchronousSubModuleDeclarationEmitInfo = undefined; + } + moduleElementEmitInfo.asynchronousOutput = writer.getText(); } } }); @@ -515,7 +539,7 @@ module ts { if (symbolAccesibilityResult.accessibility === SymbolAccessibility.Accessible) { // write the aliases if (symbolAccesibilityResult && symbolAccesibilityResult.aliasesToMakeVisible) { - writeAsychronousImportEqualsDeclarations(symbolAccesibilityResult.aliasesToMakeVisible); + writeAsynchronousModuleElements(symbolAccesibilityResult.aliasesToMakeVisible); } } else { @@ -719,6 +743,77 @@ module ts { writeTextOfNode(currentSourceFile, node.exportName); write(";"); writeLine(); + + // Make all the declarations visible for the export name + var nodes = resolver.setDeclarationsOfIdentifierAsVisible(node.exportName); + + // write each of these declarations asynchronously + writeAsynchronousModuleElements(nodes); + } + + function isModuleElementVisible(node: Declaration) { + return resolver.isDeclarationVisible(node); + } + + function emitModuleElement(node: Node, isModuleElementVisible: boolean) { + if (isModuleElementVisible) { + writeModuleElement(node); + } + // Import equals declaration in internal module can become visible as part of any emit so lets make sure we add these irrespective + else if (node.kind === SyntaxKind.ImportEqualsDeclaration || + (node.parent.kind === SyntaxKind.SourceFile && isExternalModule(currentSourceFile))) { + + if (asynchronousSubModuleDeclarationEmitInfo && node.parent.kind !== SyntaxKind.SourceFile) { + // Import declaration of another module that is visited async so lets put it in right spot + asynchronousSubModuleDeclarationEmitInfo.push({ + node, + outputPos: writer.getTextPos(), + indent: writer.getIndent(), + isVisible + }); + } + else { + var isVisible: boolean; + if (node.kind === SyntaxKind.ImportDeclaration) { + var importDeclaration = node; + if (importDeclaration.importClause) { + isVisible = (importDeclaration.importClause.name && resolver.isDeclarationVisible(importDeclaration.importClause)) || + isVisibleNamedBinding(importDeclaration.importClause.namedBindings); + } + } + moduleElementDeclarationEmitInfo.push({ + node, + outputPos: writer.getTextPos(), + indent: writer.getIndent(), + isVisible + }); + } + } + } + + function writeModuleElement(node: Node) { + switch (node.kind) { + case SyntaxKind.FunctionDeclaration: + return writeFunctionDeclaration(node); + case SyntaxKind.VariableStatement: + return writeVariableStatement(node); + case SyntaxKind.InterfaceDeclaration: + return writeInterfaceDeclaration(node); + case SyntaxKind.ClassDeclaration: + return writeClassDeclaration(node); + case SyntaxKind.TypeAliasDeclaration: + return writeTypeAliasDeclaration(node); + case SyntaxKind.EnumDeclaration: + return writeEnumDeclaration(node); + case SyntaxKind.ModuleDeclaration: + return writeModuleDeclaration(node); + case SyntaxKind.ImportEqualsDeclaration: + return writeImportEqualsDeclaration(node); + case SyntaxKind.ImportDeclaration: + return writeImportDeclaration(node); + default: + Debug.fail("Unknown symbol kind"); + } } function emitModuleElementDeclarationFlags(node: Node) { @@ -748,19 +843,6 @@ module ts { } } - function emitImportEqualsDeclaration(node: ImportEqualsDeclaration) { - if (resolver.isDeclarationVisible(node)) { - writeImportEqualsDeclaration(node); - } - else { - aliasDeclarationEmitInfo.push({ - declaration: node, - outputPos: writer.getTextPos(), - indent: writer.getIndent(), - }); - } - } - function writeImportEqualsDeclaration(node: ImportEqualsDeclaration) { // note usage of writer. methods instead of aliases created, just to make sure we are using // correct writer especially to handle asynchronous alias writing @@ -791,21 +873,6 @@ module ts { } } - function emitImportDeclaration(node: ImportDeclaration) { - if (node.importClause) { - aliasDeclarationEmitInfo.push({ - declaration: node, - outputPos: writer.getTextPos(), - indent: writer.getIndent(), - isVisible: (node.importClause.name && resolver.isDeclarationVisible(node.importClause)) || - isVisibleNamedBinding(node.importClause.namedBindings) - }); - } - else { - writeImportDeclaration(node); - } - } - function isVisibleNamedBinding(namedBindings: NamespaceImport | NamedImports): boolean { if (namedBindings) { if (namedBindings.kind === SyntaxKind.NamespaceImport) { @@ -858,41 +925,38 @@ module ts { writeTextOfNode(currentSourceFile, node.name); } - function emitModuleDeclaration(node: ModuleDeclaration) { - if (resolver.isDeclarationVisible(node)) { - emitJsDocComments(node); - emitModuleElementDeclarationFlags(node); - write("module "); + function writeModuleDeclaration(node: ModuleDeclaration) { + emitJsDocComments(node); + emitModuleElementDeclarationFlags(node); + write("module "); + writeTextOfNode(currentSourceFile, node.name); + while (node.body.kind !== SyntaxKind.ModuleBlock) { + node = node.body; + write("."); writeTextOfNode(currentSourceFile, node.name); - while (node.body.kind !== SyntaxKind.ModuleBlock) { - node = node.body; - write("."); - writeTextOfNode(currentSourceFile, node.name); - } - var prevEnclosingDeclaration = enclosingDeclaration; - enclosingDeclaration = node; - write(" {"); - writeLine(); - increaseIndent(); - emitLines((node.body).statements); - decreaseIndent(); - write("}"); - writeLine(); - enclosingDeclaration = prevEnclosingDeclaration; } + var prevEnclosingDeclaration = enclosingDeclaration; + enclosingDeclaration = node; + write(" {"); + writeLine(); + increaseIndent(); + emitLines((node.body).statements); + decreaseIndent(); + write("}"); + writeLine(); + enclosingDeclaration = prevEnclosingDeclaration; } - function emitTypeAliasDeclaration(node: TypeAliasDeclaration) { - if (resolver.isDeclarationVisible(node)) { - emitJsDocComments(node); - emitModuleElementDeclarationFlags(node); - write("type "); - writeTextOfNode(currentSourceFile, node.name); - write(" = "); - emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.type, getTypeAliasDeclarationVisibilityError); - write(";"); - writeLine(); - } + function writeTypeAliasDeclaration(node: TypeAliasDeclaration) { + emitJsDocComments(node); + emitModuleElementDeclarationFlags(node); + write("type "); + writeTextOfNode(currentSourceFile, node.name); + write(" = "); + emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.type, getTypeAliasDeclarationVisibilityError); + write(";"); + writeLine(); + function getTypeAliasDeclarationVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { return { diagnosticMessage: Diagnostics.Exported_type_alias_0_has_or_is_using_private_name_1, @@ -902,23 +966,21 @@ module ts { } } - function emitEnumDeclaration(node: EnumDeclaration) { - if (resolver.isDeclarationVisible(node)) { - emitJsDocComments(node); - emitModuleElementDeclarationFlags(node); - if (isConst(node)) { - write("const ") - } - write("enum "); - writeTextOfNode(currentSourceFile, node.name); - write(" {"); - writeLine(); - increaseIndent(); - emitLines(node.members); - decreaseIndent(); - write("}"); - writeLine(); + function writeEnumDeclaration(node: EnumDeclaration) { + emitJsDocComments(node); + emitModuleElementDeclarationFlags(node); + if (isConst(node)) { + write("const ") } + write("enum "); + writeTextOfNode(currentSourceFile, node.name); + write(" {"); + writeLine(); + increaseIndent(); + emitLines(node.members); + decreaseIndent(); + write("}"); + writeLine(); } function emitEnumMemberDeclaration(node: EnumMember) { @@ -1050,7 +1112,7 @@ module ts { } } - function emitClassDeclaration(node: ClassDeclaration) { + function writeClassDeclaration(node: ClassDeclaration) { function emitParameterProperties(constructorDeclaration: ConstructorDeclaration) { if (constructorDeclaration) { forEach(constructorDeclaration.parameters, param => { @@ -1061,50 +1123,46 @@ module ts { } } - if (resolver.isDeclarationVisible(node)) { - emitJsDocComments(node); - emitModuleElementDeclarationFlags(node); - write("class "); - writeTextOfNode(currentSourceFile, node.name); - var prevEnclosingDeclaration = enclosingDeclaration; - enclosingDeclaration = node; - emitTypeParameters(node.typeParameters); - var baseTypeNode = getClassBaseTypeNode(node); - if (baseTypeNode) { - emitHeritageClause([baseTypeNode], /*isImplementsList*/ false); - } - emitHeritageClause(getClassImplementedTypeNodes(node), /*isImplementsList*/ true); - write(" {"); - writeLine(); - increaseIndent(); - emitParameterProperties(getFirstConstructorWithBody(node)); - emitLines(node.members); - decreaseIndent(); - write("}"); - writeLine(); - enclosingDeclaration = prevEnclosingDeclaration; + emitJsDocComments(node); + emitModuleElementDeclarationFlags(node); + write("class "); + writeTextOfNode(currentSourceFile, node.name); + var prevEnclosingDeclaration = enclosingDeclaration; + enclosingDeclaration = node; + emitTypeParameters(node.typeParameters); + var baseTypeNode = getClassBaseTypeNode(node); + if (baseTypeNode) { + emitHeritageClause([baseTypeNode], /*isImplementsList*/ false); } + emitHeritageClause(getClassImplementedTypeNodes(node), /*isImplementsList*/ true); + write(" {"); + writeLine(); + increaseIndent(); + emitParameterProperties(getFirstConstructorWithBody(node)); + emitLines(node.members); + decreaseIndent(); + write("}"); + writeLine(); + enclosingDeclaration = prevEnclosingDeclaration; } - function emitInterfaceDeclaration(node: InterfaceDeclaration) { - if (resolver.isDeclarationVisible(node)) { - emitJsDocComments(node); - emitModuleElementDeclarationFlags(node); - write("interface "); - writeTextOfNode(currentSourceFile, node.name); - var prevEnclosingDeclaration = enclosingDeclaration; - enclosingDeclaration = node; - emitTypeParameters(node.typeParameters); - emitHeritageClause(getInterfaceBaseTypeNodes(node), /*isImplementsList*/ false); - write(" {"); - writeLine(); - increaseIndent(); - emitLines(node.members); - decreaseIndent(); - write("}"); - writeLine(); - enclosingDeclaration = prevEnclosingDeclaration; - } + function writeInterfaceDeclaration(node: InterfaceDeclaration) { + emitJsDocComments(node); + emitModuleElementDeclarationFlags(node); + write("interface "); + writeTextOfNode(currentSourceFile, node.name); + var prevEnclosingDeclaration = enclosingDeclaration; + enclosingDeclaration = node; + emitTypeParameters(node.typeParameters); + emitHeritageClause(getInterfaceBaseTypeNodes(node), /*isImplementsList*/ false); + write(" {"); + writeLine(); + increaseIndent(); + emitLines(node.members); + decreaseIndent(); + write("}"); + writeLine(); + enclosingDeclaration = prevEnclosingDeclaration; } function emitPropertyDeclaration(node: Declaration) { @@ -1187,24 +1245,25 @@ module ts { } } - function emitVariableStatement(node: VariableStatement) { - var hasDeclarationWithEmit = forEach(node.declarationList.declarations, varDeclaration => resolver.isDeclarationVisible(varDeclaration)); - if (hasDeclarationWithEmit) { - emitJsDocComments(node); - emitModuleElementDeclarationFlags(node); - if (isLet(node.declarationList)) { - write("let "); - } - else if (isConst(node.declarationList)) { - write("const "); - } - else { - write("var "); - } - emitCommaList(node.declarationList.declarations, emitVariableDeclaration, resolver.isDeclarationVisible); - write(";"); - writeLine(); + function isVariableStatementVisible(node: VariableStatement) { + return forEach(node.declarationList.declarations, varDeclaration => resolver.isDeclarationVisible(varDeclaration)); + } + + function writeVariableStatement(node: VariableStatement) { + emitJsDocComments(node); + emitModuleElementDeclarationFlags(node); + if (isLet(node.declarationList)) { + write("let "); + } + else if (isConst(node.declarationList)) { + write("const "); } + else { + write("var "); + } + emitCommaList(node.declarationList.declarations, emitVariableDeclaration, resolver.isDeclarationVisible); + write(";"); + writeLine(); } function emitAccessorDeclaration(node: AccessorDeclaration) { @@ -1290,15 +1349,14 @@ module ts { } } - function emitFunctionDeclaration(node: FunctionLikeDeclaration) { + function writeFunctionDeclaration(node: FunctionLikeDeclaration) { if (hasDynamicName(node)) { return; } // If we are emitting Method/Constructor it isn't moduleElement and hence already determined to be emitting // so no need to verify if the declaration is visible - if ((node.kind !== SyntaxKind.FunctionDeclaration || resolver.isDeclarationVisible(node)) && - !resolver.isImplementationOfOverload(node)) { + if (!resolver.isImplementationOfOverload(node)) { emitJsDocComments(node); if (node.kind === SyntaxKind.FunctionDeclaration) { emitModuleElementDeclarationFlags(node); @@ -1538,11 +1596,23 @@ module ts { function emitNode(node: Node) { switch (node.kind) { - case SyntaxKind.Constructor: case SyntaxKind.FunctionDeclaration: + case SyntaxKind.ModuleDeclaration: + case SyntaxKind.ImportEqualsDeclaration: + case SyntaxKind.InterfaceDeclaration: + case SyntaxKind.ClassDeclaration: + case SyntaxKind.TypeAliasDeclaration: + case SyntaxKind.EnumDeclaration: + return emitModuleElement(node, isModuleElementVisible(node)); + case SyntaxKind.VariableStatement: + return emitModuleElement(node, isVariableStatementVisible(node)); + case SyntaxKind.ImportDeclaration: + // Import declaration without import clause is visible, otherwise it is not visible + return emitModuleElement(node, /*isModuleElementVisible*/!(node).importClause); + case SyntaxKind.Constructor: case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: - return emitFunctionDeclaration(node); + return writeFunctionDeclaration(node); case SyntaxKind.ConstructSignature: case SyntaxKind.CallSignature: case SyntaxKind.IndexSignature: @@ -1550,29 +1620,13 @@ module ts { case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: return emitAccessorDeclaration(node); - case SyntaxKind.VariableStatement: - return emitVariableStatement(node); case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: return emitPropertyDeclaration(node); - case SyntaxKind.InterfaceDeclaration: - return emitInterfaceDeclaration(node); - case SyntaxKind.ClassDeclaration: - return emitClassDeclaration(node); - case SyntaxKind.TypeAliasDeclaration: - return emitTypeAliasDeclaration(node); case SyntaxKind.EnumMember: return emitEnumMemberDeclaration(node); - case SyntaxKind.EnumDeclaration: - return emitEnumDeclaration(node); - case SyntaxKind.ModuleDeclaration: - return emitModuleDeclaration(node); - case SyntaxKind.ImportEqualsDeclaration: - return emitImportEqualsDeclaration(node); case SyntaxKind.ExportAssignment: return emitExportAssignment(node); - case SyntaxKind.ImportDeclaration: - return emitImportDeclaration(node); case SyntaxKind.SourceFile: return emitSourceFile(node); } @@ -4626,18 +4680,24 @@ module ts { // TODO(shkamat): Should we not write any declaration file if any of them can produce error, // or should we just not write this file like we are doing now if (!emitDeclarationResult.reportedDeclarationError) { - var declarationOutput = emitDeclarationResult.referencePathsOutput; - // apply additions + var declarationOutput = emitDeclarationResult.referencePathsOutput + + getDeclarationOutput(emitDeclarationResult.synchronousDeclarationOutput, emitDeclarationResult.moduleElementDeclarationEmitInfo); + writeFile(host, diagnostics, removeFileExtension(jsFilePath) + ".d.ts", declarationOutput, compilerOptions.emitBOM); + } + + function getDeclarationOutput(synchronousDeclarationOutput: string, moduleElementDeclarationEmitInfo: ModuleElementDeclarationEmitInfo[]) { var appliedSyncOutputPos = 0; - forEach(emitDeclarationResult.aliasDeclarationEmitInfo, aliasEmitInfo => { + var declarationOutput = ""; + // apply asynchronous additions to the synchronous output + forEach(moduleElementDeclarationEmitInfo, aliasEmitInfo => { if (aliasEmitInfo.asynchronousOutput) { - declarationOutput += emitDeclarationResult.synchronousDeclarationOutput.substring(appliedSyncOutputPos, aliasEmitInfo.outputPos); - declarationOutput += aliasEmitInfo.asynchronousOutput; + declarationOutput += synchronousDeclarationOutput.substring(appliedSyncOutputPos, aliasEmitInfo.outputPos); + declarationOutput += getDeclarationOutput(aliasEmitInfo.asynchronousOutput, aliasEmitInfo.subModuleElementDeclarationEmitInfo); appliedSyncOutputPos = aliasEmitInfo.outputPos; } }); - declarationOutput += emitDeclarationResult.synchronousDeclarationOutput.substring(appliedSyncOutputPos); - writeFile(host, diagnostics, removeFileExtension(jsFilePath) + ".d.ts", declarationOutput, compilerOptions.emitBOM); + declarationOutput += synchronousDeclarationOutput.substring(appliedSyncOutputPos); + return declarationOutput; } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 1f7a8211dfcfb..1999c52e91a2d 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1172,6 +1172,7 @@ module ts { isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; isDeclarationVisible(node: Declaration): boolean; + setDeclarationsOfIdentifierAsVisible(node: Identifier): Node[]; isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index b9bc5d96d41ad..384e458d4ba54 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -910,6 +910,7 @@ declare module "typescript" { isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; isDeclarationVisible(node: Declaration): boolean; + setDeclarationsOfIdentifierAsVisible(node: Identifier): Node[]; isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index 5146cde791cbd..b659edba90aa4 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -2924,6 +2924,12 @@ declare module "typescript" { >node : Declaration >Declaration : Declaration + setDeclarationsOfIdentifierAsVisible(node: Identifier): Node[]; +>setDeclarationsOfIdentifierAsVisible : (node: Identifier) => Node[] +>node : Identifier +>Identifier : Identifier +>Node : Node + isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; >isImplementationOfOverload : (node: FunctionLikeDeclaration) => boolean >node : FunctionLikeDeclaration diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index 012d635e4c562..12dffb8665f21 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -941,6 +941,7 @@ declare module "typescript" { isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; isDeclarationVisible(node: Declaration): boolean; + setDeclarationsOfIdentifierAsVisible(node: Identifier): Node[]; isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index 4292108fc73cc..810bbe2aa18be 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -3068,6 +3068,12 @@ declare module "typescript" { >node : Declaration >Declaration : Declaration + setDeclarationsOfIdentifierAsVisible(node: Identifier): Node[]; +>setDeclarationsOfIdentifierAsVisible : (node: Identifier) => Node[] +>node : Identifier +>Identifier : Identifier +>Node : Node + isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; >isImplementationOfOverload : (node: FunctionLikeDeclaration) => boolean >node : FunctionLikeDeclaration diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index 8a3951bb19b51..2e8e40442d4d5 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -942,6 +942,7 @@ declare module "typescript" { isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; isDeclarationVisible(node: Declaration): boolean; + setDeclarationsOfIdentifierAsVisible(node: Identifier): Node[]; isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index ab2e05ac05259..a4a3e3048088b 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -3020,6 +3020,12 @@ declare module "typescript" { >node : Declaration >Declaration : Declaration + setDeclarationsOfIdentifierAsVisible(node: Identifier): Node[]; +>setDeclarationsOfIdentifierAsVisible : (node: Identifier) => Node[] +>node : Identifier +>Identifier : Identifier +>Node : Node + isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; >isImplementationOfOverload : (node: FunctionLikeDeclaration) => boolean >node : FunctionLikeDeclaration diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index 36eaccac6a8fb..18c4a3f70fe55 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -979,6 +979,7 @@ declare module "typescript" { isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; isDeclarationVisible(node: Declaration): boolean; + setDeclarationsOfIdentifierAsVisible(node: Identifier): Node[]; isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index 99d84a928f80f..f338788a8e4a7 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -3193,6 +3193,12 @@ declare module "typescript" { >node : Declaration >Declaration : Declaration + setDeclarationsOfIdentifierAsVisible(node: Identifier): Node[]; +>setDeclarationsOfIdentifierAsVisible : (node: Identifier) => Node[] +>node : Identifier +>Identifier : Identifier +>Node : Node + isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; >isImplementationOfOverload : (node: FunctionLikeDeclaration) => boolean >node : FunctionLikeDeclaration diff --git a/tests/baselines/reference/declarationEmitImportInExportAssignmentModule.js b/tests/baselines/reference/declarationEmitImportInExportAssignmentModule.js new file mode 100644 index 0000000000000..b41ca177b0558 --- /dev/null +++ b/tests/baselines/reference/declarationEmitImportInExportAssignmentModule.js @@ -0,0 +1,39 @@ +//// [declarationEmitImportInExportAssignmentModule.ts] + +module m { + export module c { + export class c { + } + } + import x = c; + export var a: typeof x; +} +export = m; + +//// [declarationEmitImportInExportAssignmentModule.js] +var m; +(function (m) { + var c; + (function (_c) { + var c = (function () { + function c() { + } + return c; + })(); + _c.c = c; + })(c = m.c || (m.c = {})); + m.a; +})(m || (m = {})); +module.exports = m; + + +//// [declarationEmitImportInExportAssignmentModule.d.ts] +declare module m { + module c { + class c { + } + } + import x = c; + var a: typeof x; +} +export = m; diff --git a/tests/baselines/reference/declarationEmitImportInExportAssignmentModule.types b/tests/baselines/reference/declarationEmitImportInExportAssignmentModule.types new file mode 100644 index 0000000000000..23176a0abe2e1 --- /dev/null +++ b/tests/baselines/reference/declarationEmitImportInExportAssignmentModule.types @@ -0,0 +1,23 @@ +=== tests/cases/compiler/declarationEmitImportInExportAssignmentModule.ts === + +module m { +>m : typeof m + + export module c { +>c : typeof x + + export class c { +>c : c + } + } + import x = c; +>x : typeof x +>c : typeof x + + export var a: typeof x; +>a : typeof x +>x : typeof x +} +export = m; +>m : typeof m + diff --git a/tests/cases/compiler/declarationEmitImportInExportAssignmentModule.ts b/tests/cases/compiler/declarationEmitImportInExportAssignmentModule.ts new file mode 100644 index 0000000000000..b246ba32ba4b6 --- /dev/null +++ b/tests/cases/compiler/declarationEmitImportInExportAssignmentModule.ts @@ -0,0 +1,12 @@ +// @declaration: true +// @module: commonjs + +module m { + export module c { + export class c { + } + } + import x = c; + export var a: typeof x; +} +export = m; \ No newline at end of file From 23c1c5e27cbb9cddbc4a36ca14ca64c9523913b2 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 10 Feb 2015 19:28:32 -0800 Subject: [PATCH 011/224] Baseline accept after merging --- ...rtDefaultBindingFollowedWithNamedImport.js | 12 ++--- ...efaultBindingFollowedWithNamedImportDts.js | 12 ++--- ...aultBindingFollowedWithNamedImportInEs5.js | 12 ++--- ...indingFollowedWithNamedImportWithExport.js | 12 ++--- .../reference/es6ImportNamedImport.js | 54 ++++++++----------- .../reference/es6ImportNamedImportAmd.js | 38 +++++-------- .../reference/es6ImportNamedImportDts.js | 54 ++++++++----------- .../reference/es6ImportNamedImportInEs5.js | 54 ++++++++----------- .../es6ImportNamedImportInExportAssignment.js | 3 +- ...rtNamedImportInIndirectExportAssignment.js | 5 +- .../es6ImportNamedImportWithExport.js | 54 ++++++++----------- .../es6ImportNamedImportWithTypesAndValues.js | 5 +- .../es6ImportWithoutFromClauseAmd.js | 2 +- 13 files changed, 127 insertions(+), 190 deletions(-) diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js index aa10fb6e26f53..ab7a3e205dd38 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js @@ -27,16 +27,16 @@ exports.x = exports.a; exports.m = exports.a; //// [es6ImportDefaultBindingFollowedWithNamedImport_1.js] var defaultBinding2 = require("es6ImportDefaultBindingFollowedWithNamedImport_0"); -var x1 = a; +var x1 = _es6ImportDefaultBindingFollowedWithNamedImport_0_1.a; var defaultBinding3 = require("es6ImportDefaultBindingFollowedWithNamedImport_0"); -var x1 = b; +var x1 = _es6ImportDefaultBindingFollowedWithNamedImport_0_2.a; var defaultBinding4 = require("es6ImportDefaultBindingFollowedWithNamedImport_0"); -var x1 = x; -var x1 = y; +var x1 = _es6ImportDefaultBindingFollowedWithNamedImport_0_3.x; +var x1 = _es6ImportDefaultBindingFollowedWithNamedImport_0_3.a; var defaultBinding5 = require("es6ImportDefaultBindingFollowedWithNamedImport_0"); -var x1 = z; +var x1 = _es6ImportDefaultBindingFollowedWithNamedImport_0_4.x; var defaultBinding6 = require("es6ImportDefaultBindingFollowedWithNamedImport_0"); -var x1 = m; +var x1 = _es6ImportDefaultBindingFollowedWithNamedImport_0_5.m; //// [es6ImportDefaultBindingFollowedWithNamedImport_0.d.ts] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.js index 3d404658e38fd..e2593a5d131b2 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.js @@ -63,16 +63,16 @@ var x11 = (function () { exports.x11 = x11; //// [client.js] var defaultBinding2 = require("server"); -exports.x1 = new a(); +exports.x1 = new _server_1.a(); var defaultBinding3 = require("server"); -exports.x2 = new b(); +exports.x2 = new _server_2.a11(); var defaultBinding4 = require("server"); -exports.x4 = new x(); -exports.x5 = new y(); +exports.x4 = new _server_3.x(); +exports.x5 = new _server_3.a12(); var defaultBinding5 = require("server"); -exports.x3 = new z(); +exports.x3 = new _server_4.x11(); var defaultBinding6 = require("server"); -exports.x6 = new m(); +exports.x6 = new _server_5.m(); //// [server.d.ts] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.js index 3613aaf55753d..dd31e82901aa7 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.js @@ -27,16 +27,16 @@ exports.x = exports.a; exports.m = exports.a; //// [es6ImportDefaultBindingFollowedWithNamedImportInEs5_1.js] var defaultBinding2 = require("es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"); -var x1 = a; +var x1 = _es6ImportDefaultBindingFollowedWithNamedImportInEs5_0_1.a; var defaultBinding3 = require("es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"); -var x1 = b; +var x1 = _es6ImportDefaultBindingFollowedWithNamedImportInEs5_0_2.a; var defaultBinding4 = require("es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"); -var x1 = x; -var x1 = y; +var x1 = _es6ImportDefaultBindingFollowedWithNamedImportInEs5_0_3.x; +var x1 = _es6ImportDefaultBindingFollowedWithNamedImportInEs5_0_3.a; var defaultBinding5 = require("es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"); -var x1 = z; +var x1 = _es6ImportDefaultBindingFollowedWithNamedImportInEs5_0_4.x; var defaultBinding6 = require("es6ImportDefaultBindingFollowedWithNamedImportInEs5_0"); -var x1 = m; +var x1 = _es6ImportDefaultBindingFollowedWithNamedImportInEs5_0_5.m; //// [es6ImportDefaultBindingFollowedWithNamedImportInEs5_0.d.ts] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.js index 147c3b42296a0..edf8487696411 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.js @@ -29,12 +29,12 @@ define(["require", "exports"], function (require, exports) { }); //// [client.js] define(["require", "exports", "server", "server", "server", "server", "server"], function (require, exports, defaultBinding2, defaultBinding3, defaultBinding4, defaultBinding5, defaultBinding6) { - exports.x1 = a; - exports.x1 = b; - exports.x1 = x; - exports.x1 = y; - exports.x1 = z; - exports.x1 = m; + exports.x1 = _server_1.a; + exports.x1 = _server_2.a; + exports.x1 = _server_3.x; + exports.x1 = _server_3.a; + exports.x1 = _server_4.x; + exports.x1 = _server_5.m; }); diff --git a/tests/baselines/reference/es6ImportNamedImport.js b/tests/baselines/reference/es6ImportNamedImport.js index fe1dc0dbce358..eb27c09695121 100644 --- a/tests/baselines/reference/es6ImportNamedImport.js +++ b/tests/baselines/reference/es6ImportNamedImport.js @@ -51,39 +51,27 @@ exports.z1 = 10; exports.z2 = 10; exports.aaaa = 10; //// [es6ImportNamedImport_1.js] -var _a = require("es6ImportNamedImport_0"); -var a = _a.a; -var xxxx = a; -var _b = require("es6ImportNamedImport_0"); -var b = _b.a; -var xxxx = b; -var _c = require("es6ImportNamedImport_0"); -var x = _c.x; -var y = _c.a; -var xxxx = x; -var xxxx = y; -var _d = require("es6ImportNamedImport_0"); -var z = _d.x; -var xxxx = z; -var _e = require("es6ImportNamedImport_0"); -var m = _e.m; -var xxxx = m; -var _f = require("es6ImportNamedImport_0"); -var a1 = _f.a1; -var x1 = _f.x1; -var xxxx = a1; -var xxxx = x1; -var _g = require("es6ImportNamedImport_0"); -var a11 = _g.a1; -var x11 = _g.x1; -var xxxx = a11; -var xxxx = x11; -var _h = require("es6ImportNamedImport_0"); -var z1 = _h.z1; -var z111 = z1; -var _j = require("es6ImportNamedImport_0"); -var z3 = _j.z2; -var z2 = z3; // z2 shouldn't give redeclare error +var _es6ImportNamedImport_0_1 = require("es6ImportNamedImport_0"); +var xxxx = _es6ImportNamedImport_0_1.a; +var _es6ImportNamedImport_0_2 = require("es6ImportNamedImport_0"); +var xxxx = _es6ImportNamedImport_0_2.a; +var _es6ImportNamedImport_0_3 = require("es6ImportNamedImport_0"); +var xxxx = _es6ImportNamedImport_0_3.x; +var xxxx = _es6ImportNamedImport_0_3.a; +var _es6ImportNamedImport_0_4 = require("es6ImportNamedImport_0"); +var xxxx = _es6ImportNamedImport_0_4.x; +var _es6ImportNamedImport_0_5 = require("es6ImportNamedImport_0"); +var xxxx = _es6ImportNamedImport_0_5.m; +var _es6ImportNamedImport_0_6 = require("es6ImportNamedImport_0"); +var xxxx = _es6ImportNamedImport_0_6.a1; +var xxxx = _es6ImportNamedImport_0_6.x1; +var _es6ImportNamedImport_0_7 = require("es6ImportNamedImport_0"); +var xxxx = _es6ImportNamedImport_0_7.a1; +var xxxx = _es6ImportNamedImport_0_7.x1; +var _es6ImportNamedImport_0_8 = require("es6ImportNamedImport_0"); +var z111 = _es6ImportNamedImport_0_8.z1; +var _es6ImportNamedImport_0_9 = require("es6ImportNamedImport_0"); +var z2 = _es6ImportNamedImport_0_9.z2; // z2 shouldn't give redeclare error //// [es6ImportNamedImport_0.d.ts] diff --git a/tests/baselines/reference/es6ImportNamedImportAmd.js b/tests/baselines/reference/es6ImportNamedImportAmd.js index 3f0cc2acee89c..5e3ddc433083a 100644 --- a/tests/baselines/reference/es6ImportNamedImportAmd.js +++ b/tests/baselines/reference/es6ImportNamedImportAmd.js @@ -53,31 +53,19 @@ define(["require", "exports"], function (require, exports) { exports.aaaa = 10; }); //// [es6ImportNamedImportAmd_1.js] -define(["require", "exports", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0"], function (require, exports, _a, _b, _c, _d, _e, _f, _g, _h, _j) { - var a = _a.a; - var xxxx = a; - var b = _b.a; - var xxxx = b; - var x = _c.x; - var y = _c.a; - var xxxx = x; - var xxxx = y; - var z = _d.x; - var xxxx = z; - var m = _e.m; - var xxxx = m; - var a1 = _f.a1; - var x1 = _f.x1; - var xxxx = a1; - var xxxx = x1; - var a11 = _g.a1; - var x11 = _g.x1; - var xxxx = a11; - var xxxx = x11; - var z1 = _h.z1; - var z111 = z1; - var z3 = _j.z2; - var z2 = z3; // z2 shouldn't give redeclare error +define(["require", "exports", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0", "es6ImportNamedImportAmd_0"], function (require, exports, _es6ImportNamedImportAmd_0_1, _es6ImportNamedImportAmd_0_2, _es6ImportNamedImportAmd_0_3, _es6ImportNamedImportAmd_0_4, _es6ImportNamedImportAmd_0_5, _es6ImportNamedImportAmd_0_6, _es6ImportNamedImportAmd_0_7, _es6ImportNamedImportAmd_0_8, _es6ImportNamedImportAmd_0_9) { + var xxxx = _es6ImportNamedImportAmd_0_1.a; + var xxxx = _es6ImportNamedImportAmd_0_2.a; + var xxxx = _es6ImportNamedImportAmd_0_3.x; + var xxxx = _es6ImportNamedImportAmd_0_3.a; + var xxxx = _es6ImportNamedImportAmd_0_4.x; + var xxxx = _es6ImportNamedImportAmd_0_5.m; + var xxxx = _es6ImportNamedImportAmd_0_6.a1; + var xxxx = _es6ImportNamedImportAmd_0_6.x1; + var xxxx = _es6ImportNamedImportAmd_0_7.a1; + var xxxx = _es6ImportNamedImportAmd_0_7.x1; + var z111 = _es6ImportNamedImportAmd_0_8.z1; + var z2 = _es6ImportNamedImportAmd_0_9.z2; // z2 shouldn't give redeclare error }); diff --git a/tests/baselines/reference/es6ImportNamedImportDts.js b/tests/baselines/reference/es6ImportNamedImportDts.js index 6394240a93313..877ae6fab74f3 100644 --- a/tests/baselines/reference/es6ImportNamedImportDts.js +++ b/tests/baselines/reference/es6ImportNamedImportDts.js @@ -132,39 +132,27 @@ var aaaa1 = (function () { })(); exports.aaaa1 = aaaa1; //// [client.js] -var _a = require("server"); -var a = _a.a; -exports.xxxx = new a(); -var _b = require("server"); -var b = _b.a11; -exports.xxxx1 = new b(); -var _c = require("server"); -var x = _c.x; -var y = _c.a12; -exports.xxxx2 = new x(); -exports.xxxx3 = new y(); -var _d = require("server"); -var z = _d.x11; -exports.xxxx4 = new z(); -var _e = require("server"); -var m = _e.m; -exports.xxxx5 = new m(); -var _f = require("server"); -var a1 = _f.a1; -var x1 = _f.x1; -exports.xxxx6 = new a1(); -exports.xxxx7 = new x1(); -var _g = require("server"); -var a11 = _g.a111; -var x11 = _g.x111; -exports.xxxx8 = new a11(); -exports.xxxx9 = new x11(); -var _h = require("server"); -var z1 = _h.z1; -exports.z111 = new z1(); -var _j = require("server"); -var z3 = _j.z2; -exports.z2 = new z3(); // z2 shouldn't give redeclare error +var _server_1 = require("server"); +exports.xxxx = new _server_1.a(); +var _server_2 = require("server"); +exports.xxxx1 = new _server_2.a11(); +var _server_3 = require("server"); +exports.xxxx2 = new _server_3.x(); +exports.xxxx3 = new _server_3.a12(); +var _server_4 = require("server"); +exports.xxxx4 = new _server_4.x11(); +var _server_5 = require("server"); +exports.xxxx5 = new _server_5.m(); +var _server_6 = require("server"); +exports.xxxx6 = new _server_6.a1(); +exports.xxxx7 = new _server_6.x1(); +var _server_7 = require("server"); +exports.xxxx8 = new _server_7.a111(); +exports.xxxx9 = new _server_7.x111(); +var _server_8 = require("server"); +exports.z111 = new _server_8.z1(); +var _server_9 = require("server"); +exports.z2 = new _server_9.z2(); // z2 shouldn't give redeclare error //// [server.d.ts] diff --git a/tests/baselines/reference/es6ImportNamedImportInEs5.js b/tests/baselines/reference/es6ImportNamedImportInEs5.js index 79f94a6c82c19..fcb88d55b333a 100644 --- a/tests/baselines/reference/es6ImportNamedImportInEs5.js +++ b/tests/baselines/reference/es6ImportNamedImportInEs5.js @@ -51,39 +51,27 @@ exports.z1 = 10; exports.z2 = 10; exports.aaaa = 10; //// [es6ImportNamedImportInEs5_1.js] -var _a = require("es6ImportNamedImportInEs5_0"); -var a = _a.a; -var xxxx = a; -var _b = require("es6ImportNamedImportInEs5_0"); -var b = _b.a; -var xxxx = b; -var _c = require("es6ImportNamedImportInEs5_0"); -var x = _c.x; -var y = _c.a; -var xxxx = x; -var xxxx = y; -var _d = require("es6ImportNamedImportInEs5_0"); -var z = _d.x; -var xxxx = z; -var _e = require("es6ImportNamedImportInEs5_0"); -var m = _e.m; -var xxxx = m; -var _f = require("es6ImportNamedImportInEs5_0"); -var a1 = _f.a1; -var x1 = _f.x1; -var xxxx = a1; -var xxxx = x1; -var _g = require("es6ImportNamedImportInEs5_0"); -var a11 = _g.a1; -var x11 = _g.x1; -var xxxx = a11; -var xxxx = x11; -var _h = require("es6ImportNamedImportInEs5_0"); -var z1 = _h.z1; -var z111 = z1; -var _j = require("es6ImportNamedImportInEs5_0"); -var z3 = _j.z2; -var z2 = z3; // z2 shouldn't give redeclare error +var _es6ImportNamedImportInEs5_0_1 = require("es6ImportNamedImportInEs5_0"); +var xxxx = _es6ImportNamedImportInEs5_0_1.a; +var _es6ImportNamedImportInEs5_0_2 = require("es6ImportNamedImportInEs5_0"); +var xxxx = _es6ImportNamedImportInEs5_0_2.a; +var _es6ImportNamedImportInEs5_0_3 = require("es6ImportNamedImportInEs5_0"); +var xxxx = _es6ImportNamedImportInEs5_0_3.x; +var xxxx = _es6ImportNamedImportInEs5_0_3.a; +var _es6ImportNamedImportInEs5_0_4 = require("es6ImportNamedImportInEs5_0"); +var xxxx = _es6ImportNamedImportInEs5_0_4.x; +var _es6ImportNamedImportInEs5_0_5 = require("es6ImportNamedImportInEs5_0"); +var xxxx = _es6ImportNamedImportInEs5_0_5.m; +var _es6ImportNamedImportInEs5_0_6 = require("es6ImportNamedImportInEs5_0"); +var xxxx = _es6ImportNamedImportInEs5_0_6.a1; +var xxxx = _es6ImportNamedImportInEs5_0_6.x1; +var _es6ImportNamedImportInEs5_0_7 = require("es6ImportNamedImportInEs5_0"); +var xxxx = _es6ImportNamedImportInEs5_0_7.a1; +var xxxx = _es6ImportNamedImportInEs5_0_7.x1; +var _es6ImportNamedImportInEs5_0_8 = require("es6ImportNamedImportInEs5_0"); +var z111 = _es6ImportNamedImportInEs5_0_8.z1; +var _es6ImportNamedImportInEs5_0_9 = require("es6ImportNamedImportInEs5_0"); +var z2 = _es6ImportNamedImportInEs5_0_9.z2; // z2 shouldn't give redeclare error //// [es6ImportNamedImportInEs5_0.d.ts] diff --git a/tests/baselines/reference/es6ImportNamedImportInExportAssignment.js b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.js index a58206722471e..5e39ae7854dee 100644 --- a/tests/baselines/reference/es6ImportNamedImportInExportAssignment.js +++ b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.js @@ -11,8 +11,7 @@ export = a; //// [es6ImportNamedImportInExportAssignment_0.js] exports.a = 10; //// [es6ImportNamedImportInExportAssignment_1.js] -var _a = require("es6ImportNamedImportInExportAssignment_0"); -var a = _a.a; +var _es6ImportNamedImportInExportAssignment_0 = require("es6ImportNamedImportInExportAssignment_0"); module.exports = a; diff --git a/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.js b/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.js index c1a4b5d5e9ebe..9c383ab3e3b36 100644 --- a/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.js +++ b/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.js @@ -23,9 +23,8 @@ var a; a.c = c; })(a = exports.a || (exports.a = {})); //// [es6ImportNamedImportInIndirectExportAssignment_1.js] -var _a = require("es6ImportNamedImportInIndirectExportAssignment_0"); -var a = _a.a; -var x = a; +var _es6ImportNamedImportInIndirectExportAssignment_0 = require("es6ImportNamedImportInIndirectExportAssignment_0"); +var x = _es6ImportNamedImportInIndirectExportAssignment_0.a; module.exports = x; diff --git a/tests/baselines/reference/es6ImportNamedImportWithExport.js b/tests/baselines/reference/es6ImportNamedImportWithExport.js index 69ed42ca35c02..71f4af721788c 100644 --- a/tests/baselines/reference/es6ImportNamedImportWithExport.js +++ b/tests/baselines/reference/es6ImportNamedImportWithExport.js @@ -50,39 +50,27 @@ exports.z1 = 10; exports.z2 = 10; exports.aaaa = 10; //// [client.js] -var _a = require("server"); -var a = _a.a; -exports.xxxx = a; -var _b = require("server"); -var b = _b.a; -exports.xxxx = b; -var _c = require("server"); -var x = _c.x; -var y = _c.a; -exports.xxxx = x; -exports.xxxx = y; -var _d = require("server"); -var z = _d.x; -exports.xxxx = z; -var _e = require("server"); -var m = _e.m; -exports.xxxx = m; -var _f = require("server"); -var a1 = _f.a1; -var x1 = _f.x1; -exports.xxxx = a1; -exports.xxxx = x1; -var _g = require("server"); -var a11 = _g.a1; -var x11 = _g.x1; -exports.xxxx = a11; -exports.xxxx = x11; -var _h = require("server"); -var z1 = _h.z1; -exports.z111 = z1; -var _j = require("server"); -var z3 = _j.z2; -exports.z2 = z3; // z2 shouldn't give redeclare error +var _server_1 = require("server"); +exports.xxxx = _server_1.a; +var _server_2 = require("server"); +exports.xxxx = _server_2.a; +var _server_3 = require("server"); +exports.xxxx = _server_3.x; +exports.xxxx = _server_3.a; +var _server_4 = require("server"); +exports.xxxx = _server_4.x; +var _server_5 = require("server"); +exports.xxxx = _server_5.m; +var _server_6 = require("server"); +exports.xxxx = _server_6.a1; +exports.xxxx = _server_6.x1; +var _server_7 = require("server"); +exports.xxxx = _server_7.a1; +exports.xxxx = _server_7.x1; +var _server_8 = require("server"); +exports.z111 = _server_8.z1; +var _server_9 = require("server"); +exports.z2 = _server_9.z2; // z2 shouldn't give redeclare error //// [server.d.ts] diff --git a/tests/baselines/reference/es6ImportNamedImportWithTypesAndValues.js b/tests/baselines/reference/es6ImportNamedImportWithTypesAndValues.js index a7827a5d56ac7..7852d2991bc8a 100644 --- a/tests/baselines/reference/es6ImportNamedImportWithTypesAndValues.js +++ b/tests/baselines/reference/es6ImportNamedImportWithTypesAndValues.js @@ -36,9 +36,8 @@ var C2 = (function () { })(); exports.C2 = C2; //// [client.js] -var _a = require("server"); -var C = _a.C; // Shouldnt emit I and C2 into the js file and emit C and I in .d.ts file -exports.cVal = new C(); +var _server = require("server"); // Shouldnt emit I and C2 into the js file and emit C and I in .d.ts file +exports.cVal = new _server.C(); //// [server.d.ts] diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseAmd.js b/tests/baselines/reference/es6ImportWithoutFromClauseAmd.js index 0464794ea8915..9c3066b6fc16e 100644 --- a/tests/baselines/reference/es6ImportWithoutFromClauseAmd.js +++ b/tests/baselines/reference/es6ImportWithoutFromClauseAmd.js @@ -22,7 +22,7 @@ define(["require", "exports"], function (require, exports) { exports.b = 10; }); //// [es6ImportWithoutFromClauseAmd_2.js] -define(["require", "exports", "es6ImportWithoutFromClauseAmd_0", "es6ImportWithoutFromClauseAmd_2"], function (require, exports, _c, _d) { +define(["require", "exports", "es6ImportWithoutFromClauseAmd_0", "es6ImportWithoutFromClauseAmd_2"], function (require, exports, , ) { var _a = 10; var _b = 10; }); From 649cd3bce12662d4107cb951323b4918b083b824 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 12 Feb 2015 13:23:49 -0800 Subject: [PATCH 012/224] Declaration emit fixes for binding pattern in variable statements Handles #2023 --- src/compiler/checker.ts | 9 +- src/compiler/emitter.ts | 96 +++++++++++------ ...clarationEmitDestructuringArrayPattern1.js | 28 +++++ ...rationEmitDestructuringArrayPattern1.types | 32 ++++++ ...clarationEmitDestructuringArrayPattern2.js | 31 ++++++ ...rationEmitDestructuringArrayPattern2.types | 54 ++++++++++ ...clarationEmitDestructuringArrayPattern3.js | 17 +++ ...rationEmitDestructuringArrayPattern3.types | 9 ++ ...clarationEmitDestructuringArrayPattern4.js | 31 ++++++ ...rationEmitDestructuringArrayPattern4.types | 45 ++++++++ ...onEmitDestructuringObjectLiteralPattern.js | 64 +++++++++++ ...mitDestructuringObjectLiteralPattern.types | 102 ++++++++++++++++++ ...nEmitDestructuringObjectLiteralPattern1.js | 27 +++++ ...itDestructuringObjectLiteralPattern1.types | 49 +++++++++ ...nEmitDestructuringObjectLiteralPattern2.js | 43 ++++++++ ...itDestructuringObjectLiteralPattern2.types | 55 ++++++++++ ...ingOptionalBindingParametersInOverloads.js | 33 ++++++ ...OptionalBindingParametersInOverloads.types | 27 +++++ ...estructuringParameterProperties.errors.txt | 28 +++++ ...ionEmitDestructuringParameterProperties.js | 61 +++++++++++ ...ngWithOptionalBindingParameters.errors.txt | 13 +++ ...tructuringWithOptionalBindingParameters.js | 22 ++++ ...clarationEmitDestructuringArrayPattern1.ts | 10 ++ ...clarationEmitDestructuringArrayPattern2.ts | 10 ++ ...clarationEmitDestructuringArrayPattern3.ts | 4 + ...clarationEmitDestructuringArrayPattern4.ts | 10 ++ ...onEmitDestructuringObjectLiteralPattern.ts | 23 ++++ ...nEmitDestructuringObjectLiteralPattern1.ts | 9 ++ ...nEmitDestructuringObjectLiteralPattern2.ts | 15 +++ ...ingOptionalBindingParametersInOverloads.ts | 10 ++ ...ionEmitDestructuringParameterProperties.ts | 17 +++ ...tructuringWithOptionalBindingParameters.ts | 5 + 32 files changed, 956 insertions(+), 33 deletions(-) create mode 100644 tests/baselines/reference/declarationEmitDestructuringArrayPattern1.js create mode 100644 tests/baselines/reference/declarationEmitDestructuringArrayPattern1.types create mode 100644 tests/baselines/reference/declarationEmitDestructuringArrayPattern2.js create mode 100644 tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types create mode 100644 tests/baselines/reference/declarationEmitDestructuringArrayPattern3.js create mode 100644 tests/baselines/reference/declarationEmitDestructuringArrayPattern3.types create mode 100644 tests/baselines/reference/declarationEmitDestructuringArrayPattern4.js create mode 100644 tests/baselines/reference/declarationEmitDestructuringArrayPattern4.types create mode 100644 tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.js create mode 100644 tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.types create mode 100644 tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.js create mode 100644 tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.types create mode 100644 tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.js create mode 100644 tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.types create mode 100644 tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.js create mode 100644 tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.types create mode 100644 tests/baselines/reference/declarationEmitDestructuringParameterProperties.errors.txt create mode 100644 tests/baselines/reference/declarationEmitDestructuringParameterProperties.js create mode 100644 tests/baselines/reference/declarationEmitDestructuringWithOptionalBindingParameters.errors.txt create mode 100644 tests/baselines/reference/declarationEmitDestructuringWithOptionalBindingParameters.js create mode 100644 tests/cases/compiler/declarationEmitDestructuringArrayPattern1.ts create mode 100644 tests/cases/compiler/declarationEmitDestructuringArrayPattern2.ts create mode 100644 tests/cases/compiler/declarationEmitDestructuringArrayPattern3.ts create mode 100644 tests/cases/compiler/declarationEmitDestructuringArrayPattern4.ts create mode 100644 tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts create mode 100644 tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts create mode 100644 tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern2.ts create mode 100644 tests/cases/compiler/declarationEmitDestructuringOptionalBindingParametersInOverloads.ts create mode 100644 tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts create mode 100644 tests/cases/compiler/declarationEmitDestructuringWithOptionalBindingParameters.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cccd74e3907d3..19a2f8121e9a7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1581,8 +1581,15 @@ module ts { function determineIfDeclarationIsVisible() { switch (node.kind) { - case SyntaxKind.VariableDeclaration: case SyntaxKind.BindingElement: + return isDeclarationVisible(node.parent.parent); + case SyntaxKind.VariableDeclaration: + if (isBindingPattern(node.name) && + !(node.name).elements.length) { + // If the binding pattern is empty, this variable declaration is not visible + return false; + } + // Otherwise fall through case SyntaxKind.ModuleDeclaration: case SyntaxKind.ClassDeclaration: case SyntaxKind.InterfaceDeclaration: diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 6a2338268e899..deb8d92dcef7e 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1024,62 +1024,94 @@ module ts { // If we are emitting property it isn't moduleElement and hence we already know it needs to be emitted // so there is no check needed to see if declaration is visible if (node.kind !== SyntaxKind.VariableDeclaration || resolver.isDeclarationVisible(node)) { - // If this node is a computed name, it can only be a symbol, because we've already skipped - // it if it's not a well known symbol. In that case, the text of the name will be exactly - // what we want, namely the name expression enclosed in brackets. - writeTextOfNode(currentSourceFile, node.name); - // If optional property emit ? - if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) && hasQuestionToken(node)) { - write("?"); - } - if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) && node.parent.kind === SyntaxKind.TypeLiteral) { - emitTypeOfVariableDeclarationFromTypeLiteral(node); + if (isBindingPattern(node.name)) { + emitBindingPattern(node.name); } - else if (!(node.flags & NodeFlags.Private)) { - writeTypeOfDeclaration(node, node.type, getVariableDeclarationTypeVisibilityError); + else { + // If this node is a computed name, it can only be a symbol, because we've already skipped + // it if it's not a well known symbol. In that case, the text of the name will be exactly + // what we want, namely the name expression enclosed in brackets. + writeTextOfNode(currentSourceFile, node.name); + // If optional property emit ? + if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) && hasQuestionToken(node)) { + write("?"); + } + if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) && node.parent.kind === SyntaxKind.TypeLiteral) { + emitTypeOfVariableDeclarationFromTypeLiteral(node); + } + else if (!(node.flags & NodeFlags.Private)) { + writeTypeOfDeclaration(node, node.type, getVariableDeclarationTypeVisibilityError); + } } } - function getVariableDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { - var diagnosticMessage: DiagnosticMessage; + function getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult: SymbolAccessiblityResult) { if (node.kind === SyntaxKind.VariableDeclaration) { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : - Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Exported_variable_0_has_or_is_using_private_name_1; + return symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : + Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Exported_variable_0_has_or_is_using_private_name_1; } // This check is to ensure we don't report error on constructor parameter property as that error would be reported during parameter emit else if (node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) { // TODO(jfreeman): Deal with computed properties in error reporting. if (node.flags & NodeFlags.Static) { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : - Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_private_name_1; + return symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : + Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_private_name_1; } else if (node.parent.kind === SyntaxKind.ClassDeclaration) { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : - Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Public_property_0_of_exported_class_has_or_is_using_private_name_1; + return symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : + Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Public_property_0_of_exported_class_has_or_is_using_private_name_1; } else { // Interfaces cannot have types that cannot be named - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Property_0_of_exported_interface_has_or_is_using_private_name_1; + return symbolAccesibilityResult.errorModuleName ? + Diagnostics.Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Property_0_of_exported_interface_has_or_is_using_private_name_1; } } + } + function getVariableDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { + var diagnosticMessage = getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult); return diagnosticMessage !== undefined ? { diagnosticMessage, errorNode: node, typeName: node.name } : undefined; } + + function emitBindingPattern(bindingPattern: BindingPattern) { + emitCommaList(bindingPattern.elements, emitBindingElement); + } + + function emitBindingElement(bindingElement: BindingElement) { + function getBindingElementTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { + var diagnosticMessage = getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult); + return diagnosticMessage !== undefined ? { + diagnosticMessage, + errorNode: bindingElement, + typeName: bindingElement.name + } : undefined; + } + + if (bindingElement.name) { + if (isBindingPattern(bindingElement.name)) { + emitBindingPattern(bindingElement.name); + } + else { + writeTextOfNode(currentSourceFile, bindingElement.name); + writeTypeOfDeclaration(bindingElement, /*type*/ undefined, getBindingElementTypeVisibilityError); + } + } + } } function emitTypeOfVariableDeclarationFromTypeLiteral(node: VariableLikeDeclaration) { diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.js b/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.js new file mode 100644 index 0000000000000..088bb4e849f20 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.js @@ -0,0 +1,28 @@ +//// [declarationEmitDestructuringArrayPattern1.ts] + +var [] = [1, "hello"]; // Dont emit anything +var [x] = [1, "hello"]; // emit x: number +var [x1, y1] = [1, "hello"]; // emit x1: number, y1: string +var [, , z1] = [0, 1, 2]; // emit z1: number + +var a = [1, "hello"]; +var [x2] = a; // emit x2: number | string +var [x3, y3, z3] = a; // emit x3, y3, z3 + +//// [declarationEmitDestructuringArrayPattern1.js] +var _a = [1, "hello"]; // Dont emit anything +var x = ([1, "hello"])[0]; // emit x: number +var _b = [1, "hello"], x1 = _b[0], y1 = _b[1]; // emit x1: number, y1: string +var _c = [0, 1, 2], z1 = _c[2]; // emit z1: number +var a = [1, "hello"]; +var x2 = a[0]; // emit x2: number | string +var x3 = a[0], y3 = a[1], z3 = a[2]; // emit x3, y3, z3 + + +//// [declarationEmitDestructuringArrayPattern1.d.ts] +declare var x: number; +declare var x1: number, y1: string; +declare var z1: number; +declare var a: (string | number)[]; +declare var x2: string | number; +declare var x3: string | number, y3: string | number, z3: string | number; diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.types b/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.types new file mode 100644 index 0000000000000..9f6f4c9857d7d --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern1.types @@ -0,0 +1,32 @@ +=== tests/cases/compiler/declarationEmitDestructuringArrayPattern1.ts === + +var [] = [1, "hello"]; // Dont emit anything +>[1, "hello"] : (string | number)[] + +var [x] = [1, "hello"]; // emit x: number +>x : number +>[1, "hello"] : [number, string] + +var [x1, y1] = [1, "hello"]; // emit x1: number, y1: string +>x1 : number +>y1 : string +>[1, "hello"] : [number, string] + +var [, , z1] = [0, 1, 2]; // emit z1: number +>z1 : number +>[0, 1, 2] : [number, number, number] + +var a = [1, "hello"]; +>a : (string | number)[] +>[1, "hello"] : (string | number)[] + +var [x2] = a; // emit x2: number | string +>x2 : string | number +>a : (string | number)[] + +var [x3, y3, z3] = a; // emit x3, y3, z3 +>x3 : string | number +>y3 : string | number +>z3 : string | number +>a : (string | number)[] + diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.js b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.js new file mode 100644 index 0000000000000..818b3a6f7a97b --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.js @@ -0,0 +1,31 @@ +//// [declarationEmitDestructuringArrayPattern2.ts] +var [x10, [y10, [z10]]] = [1, ["hello", [true]]]; + +var [x11 = 0, y11 = ""] = [1, "hello"]; +var [a11, b11, c11] = []; + +var [a2, [b2, { x12, y12: c2 }]=["abc", { x12: 10, y12: false }]] = [1, ["hello", { x12: 5, y12: true }]]; + +var [x13, y13] = [1, "hello"]; +var [a3, b3] = [[x13, y13], { x: x13, y: y13 }]; + + +//// [declarationEmitDestructuringArrayPattern2.js] +var _a = [1, ["hello", [true]]], x10 = _a[0], _b = _a[1], y10 = _b[0], z10 = _b[1][0]; +var _c = [1, "hello"], _d = _c[0], x11 = _d === void 0 ? 0 : _d, _e = _c[1], y11 = _e === void 0 ? "" : _e; +var _f = [], a11 = _f[0], b11 = _f[1], c11 = _f[2]; +var _g = [1, ["hello", { x12: 5, y12: true }]], a2 = _g[0], _h = _g[1], _j = _h === void 0 ? ["abc", { x12: 10, y12: false }] : _h, b2 = _j[0], _k = _j[1], x12 = _k.x12, c2 = _k.y12; +var _l = [1, "hello"], x13 = _l[0], y13 = _l[1]; +var _m = [[x13, y13], { x: x13, y: y13 }], a3 = _m[0], b3 = _m[1]; + + +//// [declarationEmitDestructuringArrayPattern2.d.ts] +declare var x10: number, y10: string, z10: boolean; +declare var x11: number, y11: string; +declare var a11: any, b11: any, c11: any; +declare var a2: number, b2: string, x12: number, c2: boolean; +declare var x13: number, y13: string; +declare var a3: (string | number)[], b3: { + x: number; + y: string; +}; diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types new file mode 100644 index 0000000000000..2b40a388e3ba9 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern2.types @@ -0,0 +1,54 @@ +=== tests/cases/compiler/declarationEmitDestructuringArrayPattern2.ts === +var [x10, [y10, [z10]]] = [1, ["hello", [true]]]; +>x10 : number +>y10 : string +>z10 : boolean +>[1, ["hello", [true]]] : [number, [string, [boolean]]] +>["hello", [true]] : [string, [boolean]] +>[true] : [boolean] + +var [x11 = 0, y11 = ""] = [1, "hello"]; +>x11 : number +>y11 : string +>[1, "hello"] : [number, string] + +var [a11, b11, c11] = []; +>a11 : any +>b11 : any +>c11 : any +>[] : undefined[] + +var [a2, [b2, { x12, y12: c2 }]=["abc", { x12: 10, y12: false }]] = [1, ["hello", { x12: 5, y12: true }]]; +>a2 : number +>b2 : string +>x12 : number +>y12 : unknown +>c2 : boolean +>["abc", { x12: 10, y12: false }] : [string, { x12: number; y12: boolean; }] +>{ x12: 10, y12: false } : { x12: number; y12: boolean; } +>x12 : number +>y12 : boolean +>[1, ["hello", { x12: 5, y12: true }]] : [number, [string, { x12: number; y12: boolean; }]] +>["hello", { x12: 5, y12: true }] : [string, { x12: number; y12: boolean; }] +>{ x12: 5, y12: true } : { x12: number; y12: boolean; } +>x12 : number +>y12 : boolean + +var [x13, y13] = [1, "hello"]; +>x13 : number +>y13 : string +>[1, "hello"] : [number, string] + +var [a3, b3] = [[x13, y13], { x: x13, y: y13 }]; +>a3 : (string | number)[] +>b3 : { x: number; y: string; } +>[[x13, y13], { x: x13, y: y13 }] : [(string | number)[], { x: number; y: string; }] +>[x13, y13] : (string | number)[] +>x13 : number +>y13 : string +>{ x: x13, y: y13 } : { x: number; y: string; } +>x : number +>x13 : number +>y : string +>y13 : string + diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern3.js b/tests/baselines/reference/declarationEmitDestructuringArrayPattern3.js new file mode 100644 index 0000000000000..84ab9f242e914 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern3.js @@ -0,0 +1,17 @@ +//// [declarationEmitDestructuringArrayPattern3.ts] +module M { + export var [a, b] = [1, 2]; +} + +//// [declarationEmitDestructuringArrayPattern3.js] +var M; +(function (M) { + _a = [1, 2], M.a = _a[0], M.b = _a[1]; + var _a; +})(M || (M = {})); + + +//// [declarationEmitDestructuringArrayPattern3.d.ts] +declare module M { + var a: number, b: number; +} diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern3.types b/tests/baselines/reference/declarationEmitDestructuringArrayPattern3.types new file mode 100644 index 0000000000000..4852a7e37fb02 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern3.types @@ -0,0 +1,9 @@ +=== tests/cases/compiler/declarationEmitDestructuringArrayPattern3.ts === +module M { +>M : typeof M + + export var [a, b] = [1, 2]; +>a : number +>b : number +>[1, 2] : [number, number] +} diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.js b/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.js new file mode 100644 index 0000000000000..f19a4a840bf23 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.js @@ -0,0 +1,31 @@ +//// [declarationEmitDestructuringArrayPattern4.ts] +var [...a5] = [1, 2, 3]; +var [x14, ...a6] = [1, 2, 3]; +var [x15, y15, ...a7] = [1, 2, 3]; +var [x16, y16, z16, ...a8] = [1, 2, 3]; + +var [...a9] = [1, "hello", true]; +var [x17, ...a10] = [1, "hello", true]; +var [x18, y18, ...a12] = [1, "hello", true]; +var [x19, y19, z19, ...a13] = [1, "hello", true]; + +//// [declarationEmitDestructuringArrayPattern4.js] +var _a = [1, 2, 3], a5 = _a.slice(0); +var _b = [1, 2, 3], x14 = _b[0], a6 = _b.slice(1); +var _c = [1, 2, 3], x15 = _c[0], y15 = _c[1], a7 = _c.slice(2); +var _d = [1, 2, 3], x16 = _d[0], y16 = _d[1], z16 = _d[2], a8 = _d.slice(3); +var _e = [1, "hello", true], a9 = _e.slice(0); +var _f = [1, "hello", true], x17 = _f[0], a10 = _f.slice(1); +var _g = [1, "hello", true], x18 = _g[0], y18 = _g[1], a12 = _g.slice(2); +var _h = [1, "hello", true], x19 = _h[0], y19 = _h[1], z19 = _h[2], a13 = _h.slice(3); + + +//// [declarationEmitDestructuringArrayPattern4.d.ts] +declare var a5: number[]; +declare var x14: number, a6: number[]; +declare var x15: number, y15: number, a7: number[]; +declare var x16: number, y16: number, z16: number, a8: number[]; +declare var a9: (string | number | boolean)[]; +declare var x17: string | number | boolean, a10: (string | number | boolean)[]; +declare var x18: string | number | boolean, y18: string | number | boolean, a12: (string | number | boolean)[]; +declare var x19: string | number | boolean, y19: string | number | boolean, z19: string | number | boolean, a13: (string | number | boolean)[]; diff --git a/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.types b/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.types new file mode 100644 index 0000000000000..d6d0fa758d7b2 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringArrayPattern4.types @@ -0,0 +1,45 @@ +=== tests/cases/compiler/declarationEmitDestructuringArrayPattern4.ts === +var [...a5] = [1, 2, 3]; +>a5 : number[] +>[1, 2, 3] : number[] + +var [x14, ...a6] = [1, 2, 3]; +>x14 : number +>a6 : number[] +>[1, 2, 3] : number[] + +var [x15, y15, ...a7] = [1, 2, 3]; +>x15 : number +>y15 : number +>a7 : number[] +>[1, 2, 3] : number[] + +var [x16, y16, z16, ...a8] = [1, 2, 3]; +>x16 : number +>y16 : number +>z16 : number +>a8 : number[] +>[1, 2, 3] : number[] + +var [...a9] = [1, "hello", true]; +>a9 : (string | number | boolean)[] +>[1, "hello", true] : (string | number | boolean)[] + +var [x17, ...a10] = [1, "hello", true]; +>x17 : string | number | boolean +>a10 : (string | number | boolean)[] +>[1, "hello", true] : (string | number | boolean)[] + +var [x18, y18, ...a12] = [1, "hello", true]; +>x18 : string | number | boolean +>y18 : string | number | boolean +>a12 : (string | number | boolean)[] +>[1, "hello", true] : (string | number | boolean)[] + +var [x19, y19, z19, ...a13] = [1, "hello", true]; +>x19 : string | number | boolean +>y19 : string | number | boolean +>z19 : string | number | boolean +>a13 : (string | number | boolean)[] +>[1, "hello", true] : (string | number | boolean)[] + diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.js b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.js new file mode 100644 index 0000000000000..d94da79ad9aa5 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.js @@ -0,0 +1,64 @@ +//// [declarationEmitDestructuringObjectLiteralPattern.ts] + +var { } = { x: 5, y: "hello" }; +var { x4 } = { x4: 5, y4: "hello" }; +var { y5 } = { x5: 5, y5: "hello" }; +var { x6, y6 } = { x6: 5, y6: "hello" }; +var { x7: a1 } = { x7: 5, y7: "hello" }; +var { y8: b1 } = { x8: 5, y8: "hello" }; +var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" }; + +var { a: x11, b: { a: y11, b: { a: z11 }}} = { a: 1, b: { a: "hello", b: { a: true } } }; + +function f15() { + var a4 = "hello"; + var b4 = 1; + var c4 = true; + return { a4, b4, c4 }; +} +var { a4, b4, c4 } = f15(); + +module m { + export var { a4, b4, c4 } = f15(); +} + +//// [declarationEmitDestructuringObjectLiteralPattern.js] +var _a = { x: 5, y: "hello" }; +var x4 = ({ x4: 5, y4: "hello" }).x4; +var y5 = ({ x5: 5, y5: "hello" }).y5; +var _b = { x6: 5, y6: "hello" }, x6 = _b.x6, y6 = _b.y6; +var a1 = ({ x7: 5, y7: "hello" }).x7; +var b1 = ({ x8: 5, y8: "hello" }).y8; +var _c = { x9: 5, y9: "hello" }, a2 = _c.x9, b2 = _c.y9; +var _d = { a: 1, b: { a: "hello", b: { a: true } } }, x11 = _d.a, _e = _d.b, y11 = _e.a, z11 = _e.b.a; +function f15() { + var a4 = "hello"; + var b4 = 1; + var c4 = true; + return { a4: a4, b4: b4, c4: c4 }; +} +var _f = f15(), a4 = _f.a4, b4 = _f.b4, c4 = _f.c4; +var m; +(function (m) { + _a = f15(), m.a4 = _a.a4, m.b4 = _a.b4, m.c4 = _a.c4; + var _a; +})(m || (m = {})); + + +//// [declarationEmitDestructuringObjectLiteralPattern.d.ts] +declare var x4: number; +declare var y5: string; +declare var x6: number, y6: string; +declare var a1: number; +declare var b1: string; +declare var a2: number, b2: string; +declare var x11: number, y11: string, z11: boolean; +declare function f15(): { + a4: string; + b4: number; + c4: boolean; +}; +declare var a4: string, b4: number, c4: boolean; +declare module m { + var a4: string, b4: number, c4: boolean; +} diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.types b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.types new file mode 100644 index 0000000000000..b3c422e495842 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern.types @@ -0,0 +1,102 @@ +=== tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts === + +var { } = { x: 5, y: "hello" }; +>{ x: 5, y: "hello" } : { x: number; y: string; } +>x : number +>y : string + +var { x4 } = { x4: 5, y4: "hello" }; +>x4 : number +>{ x4: 5, y4: "hello" } : { x4: number; y4: string; } +>x4 : number +>y4 : string + +var { y5 } = { x5: 5, y5: "hello" }; +>y5 : string +>{ x5: 5, y5: "hello" } : { x5: number; y5: string; } +>x5 : number +>y5 : string + +var { x6, y6 } = { x6: 5, y6: "hello" }; +>x6 : number +>y6 : string +>{ x6: 5, y6: "hello" } : { x6: number; y6: string; } +>x6 : number +>y6 : string + +var { x7: a1 } = { x7: 5, y7: "hello" }; +>x7 : unknown +>a1 : number +>{ x7: 5, y7: "hello" } : { x7: number; y7: string; } +>x7 : number +>y7 : string + +var { y8: b1 } = { x8: 5, y8: "hello" }; +>y8 : unknown +>b1 : string +>{ x8: 5, y8: "hello" } : { x8: number; y8: string; } +>x8 : number +>y8 : string + +var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" }; +>x9 : unknown +>a2 : number +>y9 : unknown +>b2 : string +>{ x9: 5, y9: "hello" } : { x9: number; y9: string; } +>x9 : number +>y9 : string + +var { a: x11, b: { a: y11, b: { a: z11 }}} = { a: 1, b: { a: "hello", b: { a: true } } }; +>a : unknown +>x11 : number +>b : unknown +>a : unknown +>y11 : string +>b : unknown +>a : unknown +>z11 : boolean +>{ a: 1, b: { a: "hello", b: { a: true } } } : { a: number; b: { a: string; b: { a: boolean; }; }; } +>a : number +>b : { a: string; b: { a: boolean; }; } +>{ a: "hello", b: { a: true } } : { a: string; b: { a: boolean; }; } +>a : string +>b : { a: boolean; } +>{ a: true } : { a: boolean; } +>a : boolean + +function f15() { +>f15 : () => { a4: string; b4: number; c4: boolean; } + + var a4 = "hello"; +>a4 : string + + var b4 = 1; +>b4 : number + + var c4 = true; +>c4 : boolean + + return { a4, b4, c4 }; +>{ a4, b4, c4 } : { a4: string; b4: number; c4: boolean; } +>a4 : string +>b4 : number +>c4 : boolean +} +var { a4, b4, c4 } = f15(); +>a4 : string +>b4 : number +>c4 : boolean +>f15() : { a4: string; b4: number; c4: boolean; } +>f15 : () => { a4: string; b4: number; c4: boolean; } + +module m { +>m : typeof m + + export var { a4, b4, c4 } = f15(); +>a4 : string +>b4 : number +>c4 : boolean +>f15() : { a4: string; b4: number; c4: boolean; } +>f15 : () => { a4: string; b4: number; c4: boolean; } +} diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.js b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.js new file mode 100644 index 0000000000000..2c14e743039ca --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.js @@ -0,0 +1,27 @@ +//// [declarationEmitDestructuringObjectLiteralPattern1.ts] + +var { } = { x: 5, y: "hello" }; +var { x4 } = { x4: 5, y4: "hello" }; +var { y5 } = { x5: 5, y5: "hello" }; +var { x6, y6 } = { x6: 5, y6: "hello" }; +var { x7: a1 } = { x7: 5, y7: "hello" }; +var { y8: b1 } = { x8: 5, y8: "hello" }; +var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" }; + +//// [declarationEmitDestructuringObjectLiteralPattern1.js] +var _a = { x: 5, y: "hello" }; +var x4 = ({ x4: 5, y4: "hello" }).x4; +var y5 = ({ x5: 5, y5: "hello" }).y5; +var _b = { x6: 5, y6: "hello" }, x6 = _b.x6, y6 = _b.y6; +var a1 = ({ x7: 5, y7: "hello" }).x7; +var b1 = ({ x8: 5, y8: "hello" }).y8; +var _c = { x9: 5, y9: "hello" }, a2 = _c.x9, b2 = _c.y9; + + +//// [declarationEmitDestructuringObjectLiteralPattern1.d.ts] +declare var x4: number; +declare var y5: string; +declare var x6: number, y6: string; +declare var a1: number; +declare var b1: string; +declare var a2: number, b2: string; diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.types b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.types new file mode 100644 index 0000000000000..cc2094c68f4d6 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern1.types @@ -0,0 +1,49 @@ +=== tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts === + +var { } = { x: 5, y: "hello" }; +>{ x: 5, y: "hello" } : { x: number; y: string; } +>x : number +>y : string + +var { x4 } = { x4: 5, y4: "hello" }; +>x4 : number +>{ x4: 5, y4: "hello" } : { x4: number; y4: string; } +>x4 : number +>y4 : string + +var { y5 } = { x5: 5, y5: "hello" }; +>y5 : string +>{ x5: 5, y5: "hello" } : { x5: number; y5: string; } +>x5 : number +>y5 : string + +var { x6, y6 } = { x6: 5, y6: "hello" }; +>x6 : number +>y6 : string +>{ x6: 5, y6: "hello" } : { x6: number; y6: string; } +>x6 : number +>y6 : string + +var { x7: a1 } = { x7: 5, y7: "hello" }; +>x7 : unknown +>a1 : number +>{ x7: 5, y7: "hello" } : { x7: number; y7: string; } +>x7 : number +>y7 : string + +var { y8: b1 } = { x8: 5, y8: "hello" }; +>y8 : unknown +>b1 : string +>{ x8: 5, y8: "hello" } : { x8: number; y8: string; } +>x8 : number +>y8 : string + +var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" }; +>x9 : unknown +>a2 : number +>y9 : unknown +>b2 : string +>{ x9: 5, y9: "hello" } : { x9: number; y9: string; } +>x9 : number +>y9 : string + diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.js b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.js new file mode 100644 index 0000000000000..7e5a3d9d2fa7c --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.js @@ -0,0 +1,43 @@ +//// [declarationEmitDestructuringObjectLiteralPattern2.ts] + +var { a: x11, b: { a: y11, b: { a: z11 }}} = { a: 1, b: { a: "hello", b: { a: true } } }; + +function f15() { + var a4 = "hello"; + var b4 = 1; + var c4 = true; + return { a4, b4, c4 }; +} +var { a4, b4, c4 } = f15(); + +module m { + export var { a4, b4, c4 } = f15(); +} + +//// [declarationEmitDestructuringObjectLiteralPattern2.js] +var _a = { a: 1, b: { a: "hello", b: { a: true } } }, x11 = _a.a, _b = _a.b, y11 = _b.a, z11 = _b.b.a; +function f15() { + var a4 = "hello"; + var b4 = 1; + var c4 = true; + return { a4: a4, b4: b4, c4: c4 }; +} +var _c = f15(), a4 = _c.a4, b4 = _c.b4, c4 = _c.c4; +var m; +(function (m) { + _a = f15(), m.a4 = _a.a4, m.b4 = _a.b4, m.c4 = _a.c4; + var _a; +})(m || (m = {})); + + +//// [declarationEmitDestructuringObjectLiteralPattern2.d.ts] +declare var x11: number, y11: string, z11: boolean; +declare function f15(): { + a4: string; + b4: number; + c4: boolean; +}; +declare var a4: string, b4: number, c4: boolean; +declare module m { + var a4: string, b4: number, c4: boolean; +} diff --git a/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.types b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.types new file mode 100644 index 0000000000000..68394686e31a0 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringObjectLiteralPattern2.types @@ -0,0 +1,55 @@ +=== tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern2.ts === + +var { a: x11, b: { a: y11, b: { a: z11 }}} = { a: 1, b: { a: "hello", b: { a: true } } }; +>a : unknown +>x11 : number +>b : unknown +>a : unknown +>y11 : string +>b : unknown +>a : unknown +>z11 : boolean +>{ a: 1, b: { a: "hello", b: { a: true } } } : { a: number; b: { a: string; b: { a: boolean; }; }; } +>a : number +>b : { a: string; b: { a: boolean; }; } +>{ a: "hello", b: { a: true } } : { a: string; b: { a: boolean; }; } +>a : string +>b : { a: boolean; } +>{ a: true } : { a: boolean; } +>a : boolean + +function f15() { +>f15 : () => { a4: string; b4: number; c4: boolean; } + + var a4 = "hello"; +>a4 : string + + var b4 = 1; +>b4 : number + + var c4 = true; +>c4 : boolean + + return { a4, b4, c4 }; +>{ a4, b4, c4 } : { a4: string; b4: number; c4: boolean; } +>a4 : string +>b4 : number +>c4 : boolean +} +var { a4, b4, c4 } = f15(); +>a4 : string +>b4 : number +>c4 : boolean +>f15() : { a4: string; b4: number; c4: boolean; } +>f15 : () => { a4: string; b4: number; c4: boolean; } + +module m { +>m : typeof m + + export var { a4, b4, c4 } = f15(); +>a4 : string +>b4 : number +>c4 : boolean +>f15() : { a4: string; b4: number; c4: boolean; } +>f15 : () => { a4: string; b4: number; c4: boolean; } +} diff --git a/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.js b/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.js new file mode 100644 index 0000000000000..c907add11f776 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.js @@ -0,0 +1,33 @@ +//// [declarationEmitDestructuringOptionalBindingParametersInOverloads.ts] + +function foo([x, y, z] ?: [string, number, boolean]); +function foo(...rest: any[]) { +} + +function foo2( { x, y, z }?: { x: string; y: number; z: boolean }); +function foo2(...rest: any[]) { + +} + +//// [declarationEmitDestructuringOptionalBindingParametersInOverloads.js] +function foo() { + var rest = []; + for (var _i = 0; _i < arguments.length; _i++) { + rest[_i - 0] = arguments[_i]; + } +} +function foo2() { + var rest = []; + for (var _i = 0; _i < arguments.length; _i++) { + rest[_i - 0] = arguments[_i]; + } +} + + +//// [declarationEmitDestructuringOptionalBindingParametersInOverloads.d.ts] +declare function foo(_0?: [string, number, boolean]): any; +declare function foo2(_0?: { + x: string; + y: number; + z: boolean; +}): any; diff --git a/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.types b/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.types new file mode 100644 index 0000000000000..1c75466f0c37c --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.types @@ -0,0 +1,27 @@ +=== tests/cases/compiler/declarationEmitDestructuringOptionalBindingParametersInOverloads.ts === + +function foo([x, y, z] ?: [string, number, boolean]); +>foo : ([x, y, z]?: [string, number, boolean]) => any +>x : string +>y : number +>z : boolean + +function foo(...rest: any[]) { +>foo : ([x, y, z]?: [string, number, boolean]) => any +>rest : any[] +} + +function foo2( { x, y, z }?: { x: string; y: number; z: boolean }); +>foo2 : ({ x, y, z }?: { x: string; y: number; z: boolean; }) => any +>x : string +>y : number +>z : boolean +>x : string +>y : number +>z : boolean + +function foo2(...rest: any[]) { +>foo2 : ({ x, y, z }?: { x: string; y: number; z: boolean; }) => any +>rest : any[] + +} diff --git a/tests/baselines/reference/declarationEmitDestructuringParameterProperties.errors.txt b/tests/baselines/reference/declarationEmitDestructuringParameterProperties.errors.txt new file mode 100644 index 0000000000000..83785e86f6585 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringParameterProperties.errors.txt @@ -0,0 +1,28 @@ +tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts(2,17): error TS1187: A parameter property may not be a binding pattern. +tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts(8,17): error TS1187: A parameter property may not be a binding pattern. +tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts(14,17): error TS1187: A parameter property may not be a binding pattern. + + +==== tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts (3 errors) ==== + class C1 { + constructor(public [x, y, z]: string[]) { + ~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1187: A parameter property may not be a binding pattern. + } + } + + type TupleType1 =[string, number, boolean]; + class C2 { + constructor(public [x, y, z]: TupleType1) { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1187: A parameter property may not be a binding pattern. + } + } + + type ObjType1 = { x: number; y: string; z: boolean } + class C3 { + constructor(public { x, y, z }: ObjType1) { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1187: A parameter property may not be a binding pattern. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDestructuringParameterProperties.js b/tests/baselines/reference/declarationEmitDestructuringParameterProperties.js new file mode 100644 index 0000000000000..cfe4acc1733d0 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringParameterProperties.js @@ -0,0 +1,61 @@ +//// [declarationEmitDestructuringParameterProperties.ts] +class C1 { + constructor(public [x, y, z]: string[]) { + } +} + +type TupleType1 =[string, number, boolean]; +class C2 { + constructor(public [x, y, z]: TupleType1) { + } +} + +type ObjType1 = { x: number; y: string; z: boolean } +class C3 { + constructor(public { x, y, z }: ObjType1) { + } +} + +//// [declarationEmitDestructuringParameterProperties.js] +var C1 = (function () { + function C1(_a) { + var x = _a[0], y = _a[1], z = _a[2]; + this.[x, y, z] = [x, y, z]; + } + return C1; +})(); +var C2 = (function () { + function C2(_a) { + var x = _a[0], y = _a[1], z = _a[2]; + this.[x, y, z] = [x, y, z]; + } + return C2; +})(); +var C3 = (function () { + function C3(_a) { + var x = _a.x, y = _a.y, z = _a.z; + this.{ x, y, z } = { x, y, z }; + } + return C3; +})(); + + +//// [declarationEmitDestructuringParameterProperties.d.ts] +declare class C1 { + x: string, y: string, z: string; + constructor(_0: string[]); +} +declare type TupleType1 = [string, number, boolean]; +declare class C2 { + x: string, y: number, z: boolean; + constructor(_0: TupleType1); +} +declare type ObjType1 = { + x: number; + y: string; + z: boolean; +}; +declare class C3 { + x: number, y: string, z: boolean; + constructor(_0: ObjType1); +} diff --git a/tests/baselines/reference/declarationEmitDestructuringWithOptionalBindingParameters.errors.txt b/tests/baselines/reference/declarationEmitDestructuringWithOptionalBindingParameters.errors.txt new file mode 100644 index 0000000000000..7b8a70ae8f16c --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringWithOptionalBindingParameters.errors.txt @@ -0,0 +1,13 @@ +tests/cases/compiler/declarationEmitDestructuringWithOptionalBindingParameters.ts(1,14): error TS2463: A binding pattern parameter cannot be optional in an implementation signature. +tests/cases/compiler/declarationEmitDestructuringWithOptionalBindingParameters.ts(3,16): error TS2463: A binding pattern parameter cannot be optional in an implementation signature. + + +==== tests/cases/compiler/declarationEmitDestructuringWithOptionalBindingParameters.ts (2 errors) ==== + function foo([x,y,z]?: [string, number, boolean]) { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2463: A binding pattern parameter cannot be optional in an implementation signature. + } + function foo1( { x, y, z }?: { x: string; y: number; z: boolean }) { + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2463: A binding pattern parameter cannot be optional in an implementation signature. + } \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDestructuringWithOptionalBindingParameters.js b/tests/baselines/reference/declarationEmitDestructuringWithOptionalBindingParameters.js new file mode 100644 index 0000000000000..284cf107782f0 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringWithOptionalBindingParameters.js @@ -0,0 +1,22 @@ +//// [declarationEmitDestructuringWithOptionalBindingParameters.ts] +function foo([x,y,z]?: [string, number, boolean]) { +} +function foo1( { x, y, z }?: { x: string; y: number; z: boolean }) { +} + +//// [declarationEmitDestructuringWithOptionalBindingParameters.js] +function foo(_a) { + var x = _a[0], y = _a[1], z = _a[2]; +} +function foo1(_a) { + var x = _a.x, y = _a.y, z = _a.z; +} + + +//// [declarationEmitDestructuringWithOptionalBindingParameters.d.ts] +declare function foo(_0?: [string, number, boolean]): void; +declare function foo1(_0?: { + x: string; + y: number; + z: boolean; +}): void; diff --git a/tests/cases/compiler/declarationEmitDestructuringArrayPattern1.ts b/tests/cases/compiler/declarationEmitDestructuringArrayPattern1.ts new file mode 100644 index 0000000000000..fc3dac87ae0f5 --- /dev/null +++ b/tests/cases/compiler/declarationEmitDestructuringArrayPattern1.ts @@ -0,0 +1,10 @@ +// @declaration: true + +var [] = [1, "hello"]; // Dont emit anything +var [x] = [1, "hello"]; // emit x: number +var [x1, y1] = [1, "hello"]; // emit x1: number, y1: string +var [, , z1] = [0, 1, 2]; // emit z1: number + +var a = [1, "hello"]; +var [x2] = a; // emit x2: number | string +var [x3, y3, z3] = a; // emit x3, y3, z3 \ No newline at end of file diff --git a/tests/cases/compiler/declarationEmitDestructuringArrayPattern2.ts b/tests/cases/compiler/declarationEmitDestructuringArrayPattern2.ts new file mode 100644 index 0000000000000..f116423715aff --- /dev/null +++ b/tests/cases/compiler/declarationEmitDestructuringArrayPattern2.ts @@ -0,0 +1,10 @@ +// @declaration: true +var [x10, [y10, [z10]]] = [1, ["hello", [true]]]; + +var [x11 = 0, y11 = ""] = [1, "hello"]; +var [a11, b11, c11] = []; + +var [a2, [b2, { x12, y12: c2 }]=["abc", { x12: 10, y12: false }]] = [1, ["hello", { x12: 5, y12: true }]]; + +var [x13, y13] = [1, "hello"]; +var [a3, b3] = [[x13, y13], { x: x13, y: y13 }]; diff --git a/tests/cases/compiler/declarationEmitDestructuringArrayPattern3.ts b/tests/cases/compiler/declarationEmitDestructuringArrayPattern3.ts new file mode 100644 index 0000000000000..9cdc6c2ec90ff --- /dev/null +++ b/tests/cases/compiler/declarationEmitDestructuringArrayPattern3.ts @@ -0,0 +1,4 @@ +// @declaration: true +module M { + export var [a, b] = [1, 2]; +} \ No newline at end of file diff --git a/tests/cases/compiler/declarationEmitDestructuringArrayPattern4.ts b/tests/cases/compiler/declarationEmitDestructuringArrayPattern4.ts new file mode 100644 index 0000000000000..8f162e33da3d9 --- /dev/null +++ b/tests/cases/compiler/declarationEmitDestructuringArrayPattern4.ts @@ -0,0 +1,10 @@ +// @declaration: true +var [...a5] = [1, 2, 3]; +var [x14, ...a6] = [1, 2, 3]; +var [x15, y15, ...a7] = [1, 2, 3]; +var [x16, y16, z16, ...a8] = [1, 2, 3]; + +var [...a9] = [1, "hello", true]; +var [x17, ...a10] = [1, "hello", true]; +var [x18, y18, ...a12] = [1, "hello", true]; +var [x19, y19, z19, ...a13] = [1, "hello", true]; \ No newline at end of file diff --git a/tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts b/tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts new file mode 100644 index 0000000000000..89e5b65a9d3b3 --- /dev/null +++ b/tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern.ts @@ -0,0 +1,23 @@ +// @declaration: true + +var { } = { x: 5, y: "hello" }; +var { x4 } = { x4: 5, y4: "hello" }; +var { y5 } = { x5: 5, y5: "hello" }; +var { x6, y6 } = { x6: 5, y6: "hello" }; +var { x7: a1 } = { x7: 5, y7: "hello" }; +var { y8: b1 } = { x8: 5, y8: "hello" }; +var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" }; + +var { a: x11, b: { a: y11, b: { a: z11 }}} = { a: 1, b: { a: "hello", b: { a: true } } }; + +function f15() { + var a4 = "hello"; + var b4 = 1; + var c4 = true; + return { a4, b4, c4 }; +} +var { a4, b4, c4 } = f15(); + +module m { + export var { a4, b4, c4 } = f15(); +} \ No newline at end of file diff --git a/tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts b/tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts new file mode 100644 index 0000000000000..6a65c92546504 --- /dev/null +++ b/tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern1.ts @@ -0,0 +1,9 @@ +// @declaration: true + +var { } = { x: 5, y: "hello" }; +var { x4 } = { x4: 5, y4: "hello" }; +var { y5 } = { x5: 5, y5: "hello" }; +var { x6, y6 } = { x6: 5, y6: "hello" }; +var { x7: a1 } = { x7: 5, y7: "hello" }; +var { y8: b1 } = { x8: 5, y8: "hello" }; +var { x9: a2, y9: b2 } = { x9: 5, y9: "hello" }; \ No newline at end of file diff --git a/tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern2.ts b/tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern2.ts new file mode 100644 index 0000000000000..f700e68e39727 --- /dev/null +++ b/tests/cases/compiler/declarationEmitDestructuringObjectLiteralPattern2.ts @@ -0,0 +1,15 @@ +// @declaration: true + +var { a: x11, b: { a: y11, b: { a: z11 }}} = { a: 1, b: { a: "hello", b: { a: true } } }; + +function f15() { + var a4 = "hello"; + var b4 = 1; + var c4 = true; + return { a4, b4, c4 }; +} +var { a4, b4, c4 } = f15(); + +module m { + export var { a4, b4, c4 } = f15(); +} \ No newline at end of file diff --git a/tests/cases/compiler/declarationEmitDestructuringOptionalBindingParametersInOverloads.ts b/tests/cases/compiler/declarationEmitDestructuringOptionalBindingParametersInOverloads.ts new file mode 100644 index 0000000000000..020a29ba21997 --- /dev/null +++ b/tests/cases/compiler/declarationEmitDestructuringOptionalBindingParametersInOverloads.ts @@ -0,0 +1,10 @@ +// @declaration: true + +function foo([x, y, z] ?: [string, number, boolean]); +function foo(...rest: any[]) { +} + +function foo2( { x, y, z }?: { x: string; y: number; z: boolean }); +function foo2(...rest: any[]) { + +} \ No newline at end of file diff --git a/tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts b/tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts new file mode 100644 index 0000000000000..597497feac0b2 --- /dev/null +++ b/tests/cases/compiler/declarationEmitDestructuringParameterProperties.ts @@ -0,0 +1,17 @@ +// @declaration: true +class C1 { + constructor(public [x, y, z]: string[]) { + } +} + +type TupleType1 =[string, number, boolean]; +class C2 { + constructor(public [x, y, z]: TupleType1) { + } +} + +type ObjType1 = { x: number; y: string; z: boolean } +class C3 { + constructor(public { x, y, z }: ObjType1) { + } +} \ No newline at end of file diff --git a/tests/cases/compiler/declarationEmitDestructuringWithOptionalBindingParameters.ts b/tests/cases/compiler/declarationEmitDestructuringWithOptionalBindingParameters.ts new file mode 100644 index 0000000000000..c3785acd09a7e --- /dev/null +++ b/tests/cases/compiler/declarationEmitDestructuringWithOptionalBindingParameters.ts @@ -0,0 +1,5 @@ +// @declaration: true +function foo([x,y,z]?: [string, number, boolean]) { +} +function foo1( { x, y, z }?: { x: string; y: number; z: boolean }) { +} \ No newline at end of file From b88efa1b80fea9d49e5385a33ccfb894c60e72d3 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 12 Feb 2015 13:26:59 -0800 Subject: [PATCH 013/224] Test cases to verify the privacy error reporting is done on correct node --- ...ionEmitDestructuringPrivacyError.errors.txt | 11 +++++++++++ ...declarationEmitDestructuringPrivacyError.js | 18 ++++++++++++++++++ ...declarationEmitDestructuringPrivacyError.ts | 6 ++++++ 3 files changed, 35 insertions(+) create mode 100644 tests/baselines/reference/declarationEmitDestructuringPrivacyError.errors.txt create mode 100644 tests/baselines/reference/declarationEmitDestructuringPrivacyError.js create mode 100644 tests/cases/compiler/declarationEmitDestructuringPrivacyError.ts diff --git a/tests/baselines/reference/declarationEmitDestructuringPrivacyError.errors.txt b/tests/baselines/reference/declarationEmitDestructuringPrivacyError.errors.txt new file mode 100644 index 0000000000000..e464b96a8bf77 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringPrivacyError.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/declarationEmitDestructuringPrivacyError.ts(4,20): error TS4025: Exported variable 'y' has or is using private name 'c'. + + +==== tests/cases/compiler/declarationEmitDestructuringPrivacyError.ts (1 errors) ==== + module m { + class c { + } + export var [x, y, z] = [10, new c(), 30]; + ~ +!!! error TS4025: Exported variable 'y' has or is using private name 'c'. + } \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDestructuringPrivacyError.js b/tests/baselines/reference/declarationEmitDestructuringPrivacyError.js new file mode 100644 index 0000000000000..fa3cae9478bdc --- /dev/null +++ b/tests/baselines/reference/declarationEmitDestructuringPrivacyError.js @@ -0,0 +1,18 @@ +//// [declarationEmitDestructuringPrivacyError.ts] +module m { + class c { + } + export var [x, y, z] = [10, new c(), 30]; +} + +//// [declarationEmitDestructuringPrivacyError.js] +var m; +(function (m) { + var c = (function () { + function c() { + } + return c; + })(); + _a = [10, new c(), 30], m.x = _a[0], m.y = _a[1], m.z = _a[2]; + var _a; +})(m || (m = {})); diff --git a/tests/cases/compiler/declarationEmitDestructuringPrivacyError.ts b/tests/cases/compiler/declarationEmitDestructuringPrivacyError.ts new file mode 100644 index 0000000000000..987fb67a08ba4 --- /dev/null +++ b/tests/cases/compiler/declarationEmitDestructuringPrivacyError.ts @@ -0,0 +1,6 @@ +// @declaration: true +module m { + class c { + } + export var [x, y, z] = [10, new c(), 30]; +} \ No newline at end of file From fc1528f3e5eeb3dbb59666bd60ef9f50651540b8 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 17 Feb 2015 09:28:55 -0800 Subject: [PATCH 014/224] Dts for export * from "mod" and export { a, b as c,...} [from "mod"] --- src/compiler/checker.ts | 12 +++- src/compiler/emitter.ts | 35 +++++++++- .../reference/es6ExportAll.errors.txt | 20 ++++++ tests/baselines/reference/es6ExportAll.js | 48 ++++++++++++++ .../baselines/reference/es6ExportAllInEs5.js | 48 ++++++++++++++ .../reference/es6ExportAllInEs5.types | 24 +++++++ .../reference/es6ExportClause.errors.txt | 22 +++++++ tests/baselines/reference/es6ExportClause.js | 47 ++++++++++++++ .../reference/es6ExportClauseInEs5.js | 51 +++++++++++++++ .../reference/es6ExportClauseInEs5.types | 38 +++++++++++ ...ortClauseWithoutModuleSpecifier.errors.txt | 24 +++++++ .../es6ExportClauseWithoutModuleSpecifier.js | 65 +++++++++++++++++++ ...ExportClauseWithoutModuleSpecifierInEs5.js | 65 +++++++++++++++++++ ...ortClauseWithoutModuleSpecifierInEs5.types | 40 ++++++++++++ tests/cases/compiler/es6ExportAll.ts | 17 +++++ tests/cases/compiler/es6ExportAllInEs5.ts | 18 +++++ tests/cases/compiler/es6ExportClause.ts | 19 ++++++ tests/cases/compiler/es6ExportClauseInEs5.ts | 20 ++++++ .../es6ExportClauseWithoutModuleSpecifier.ts | 21 ++++++ ...ExportClauseWithoutModuleSpecifierInEs5.ts | 22 +++++++ 20 files changed, 651 insertions(+), 5 deletions(-) create mode 100644 tests/baselines/reference/es6ExportAll.errors.txt create mode 100644 tests/baselines/reference/es6ExportAll.js create mode 100644 tests/baselines/reference/es6ExportAllInEs5.js create mode 100644 tests/baselines/reference/es6ExportAllInEs5.types create mode 100644 tests/baselines/reference/es6ExportClause.errors.txt create mode 100644 tests/baselines/reference/es6ExportClause.js create mode 100644 tests/baselines/reference/es6ExportClauseInEs5.js create mode 100644 tests/baselines/reference/es6ExportClauseInEs5.types create mode 100644 tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.errors.txt create mode 100644 tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js create mode 100644 tests/baselines/reference/es6ExportClauseWithoutModuleSpecifierInEs5.js create mode 100644 tests/baselines/reference/es6ExportClauseWithoutModuleSpecifierInEs5.types create mode 100644 tests/cases/compiler/es6ExportAll.ts create mode 100644 tests/cases/compiler/es6ExportAllInEs5.ts create mode 100644 tests/cases/compiler/es6ExportClause.ts create mode 100644 tests/cases/compiler/es6ExportClauseInEs5.ts create mode 100644 tests/cases/compiler/es6ExportClauseWithoutModuleSpecifier.ts create mode 100644 tests/cases/compiler/es6ExportClauseWithoutModuleSpecifierInEs5.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index db8c9fc832d50..b07c578c671d6 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1723,12 +1723,18 @@ module ts { } function setDeclarationsOfIdentifierAsVisible(node: Identifier): Node[]{ + var exportSymbol: Symbol; if (node.parent && node.parent.kind === SyntaxKind.ExportAssignment) { - var exportSymbol = resolveName(node.parent, node.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, Diagnostics.Cannot_find_name_0, node); - var result: Node[] = []; + exportSymbol = resolveName(node.parent, node.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, Diagnostics.Cannot_find_name_0, node); + } + else if (node.parent.kind === SyntaxKind.ExportSpecifier) { + exportSymbol = getTargetOfExportSpecifier(node.parent); + } + var result: Node[] = []; + if (exportSymbol) { buildVisibleNodeList(exportSymbol.declarations); - return result; } + return result; function buildVisibleNodeList(declarations: Declaration[]) { forEach(declarations, declaration => { diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 9fc10185a04e8..e94c40cee91b2 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -905,7 +905,7 @@ module ts { } else { write("{ "); - emitCommaList((node.importClause.namedBindings).elements, emitImportSpecifier, resolver.isDeclarationVisible); + emitCommaList((node.importClause.namedBindings).elements, emitImportOrExportSpecifier, resolver.isDeclarationVisible); write(" }"); } } @@ -916,7 +916,7 @@ module ts { writer.writeLine(); } - function emitImportSpecifier(node: ImportSpecifier) { + function emitImportOrExportSpecifier(node: ImportOrExportSpecifier) { if (node.propertyName) { writeTextOfNode(currentSourceFile, node.propertyName); write(" as "); @@ -924,6 +924,35 @@ module ts { writeTextOfNode(currentSourceFile, node.name); } + function emitExportSpecifier(node: ExportSpecifier) { + emitImportOrExportSpecifier(node); + + // Make all the declarations visible for the export name + var nodes = resolver.setDeclarationsOfIdentifierAsVisible(node.propertyName || node.name); + + // write each of these declarations asynchronously + writeAsynchronousModuleElements(nodes); + } + + function emitExportDeclaration(node: ExportDeclaration) { + emitJsDocComments(node); + write("export "); + if (node.exportClause) { + write("{ "); + emitCommaList(node.exportClause.elements, emitExportSpecifier); + write(" }"); + } + else { + write("*"); + } + if (node.moduleSpecifier) { + write(" from "); + writeTextOfNode(currentSourceFile, node.moduleSpecifier); + } + write(";"); + writer.writeLine(); + } + function writeModuleDeclaration(node: ModuleDeclaration) { emitJsDocComments(node); emitModuleElementDeclarationFlags(node); @@ -1608,6 +1637,8 @@ module ts { case SyntaxKind.ImportDeclaration: // Import declaration without import clause is visible, otherwise it is not visible return emitModuleElement(node, /*isModuleElementVisible*/!(node).importClause); + case SyntaxKind.ExportDeclaration: + return emitExportDeclaration(node); case SyntaxKind.Constructor: case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: diff --git a/tests/baselines/reference/es6ExportAll.errors.txt b/tests/baselines/reference/es6ExportAll.errors.txt new file mode 100644 index 0000000000000..98d40006854e3 --- /dev/null +++ b/tests/baselines/reference/es6ExportAll.errors.txt @@ -0,0 +1,20 @@ +tests/cases/compiler/server.ts(2,14): error TS1148: Cannot compile external modules unless the '--module' flag is provided. + + +==== tests/cases/compiler/server.ts (1 errors) ==== + + export class c { + ~ +!!! error TS1148: Cannot compile external modules unless the '--module' flag is provided. + } + export interface i { + } + export module m { + export var x = 10; + } + export var x = 10; + export module uninstantiated { + } + +==== tests/cases/compiler/client.ts (0 errors) ==== + export * from "server"; \ No newline at end of file diff --git a/tests/baselines/reference/es6ExportAll.js b/tests/baselines/reference/es6ExportAll.js new file mode 100644 index 0000000000000..7b99a3819e2b1 --- /dev/null +++ b/tests/baselines/reference/es6ExportAll.js @@ -0,0 +1,48 @@ +//// [tests/cases/compiler/es6ExportAll.ts] //// + +//// [server.ts] + +export class c { +} +export interface i { +} +export module m { + export var x = 10; +} +export var x = 10; +export module uninstantiated { +} + +//// [client.ts] +export * from "server"; + +//// [server.js] +var c = (function () { + function c() { + } + return c; +})(); +exports.c = c; +var m; +(function (m) { + m.x = 10; +})(m = exports.m || (exports.m = {})); +exports.x = 10; +//// [client.js] +var _server = require("server"); +for (var _a in _server) if (!exports.hasOwnProperty(_a)) exports[_a] = _server[_a]; + + +//// [server.d.ts] +export declare class c { +} +export interface i { +} +export declare module m { + var x: number; +} +export declare var x: number; +export declare module uninstantiated { +} +//// [client.d.ts] +export * from "server"; diff --git a/tests/baselines/reference/es6ExportAllInEs5.js b/tests/baselines/reference/es6ExportAllInEs5.js new file mode 100644 index 0000000000000..dd83c31b72a7f --- /dev/null +++ b/tests/baselines/reference/es6ExportAllInEs5.js @@ -0,0 +1,48 @@ +//// [tests/cases/compiler/es6ExportAllInEs5.ts] //// + +//// [server.ts] + +export class c { +} +export interface i { +} +export module m { + export var x = 10; +} +export var x = 10; +export module uninstantiated { +} + +//// [client.ts] +export * from "server"; + +//// [server.js] +var c = (function () { + function c() { + } + return c; +})(); +exports.c = c; +var m; +(function (m) { + m.x = 10; +})(m = exports.m || (exports.m = {})); +exports.x = 10; +//// [client.js] +var _server = require("server"); +for (var _a in _server) if (!exports.hasOwnProperty(_a)) exports[_a] = _server[_a]; + + +//// [server.d.ts] +export declare class c { +} +export interface i { +} +export declare module m { + var x: number; +} +export declare var x: number; +export declare module uninstantiated { +} +//// [client.d.ts] +export * from "server"; diff --git a/tests/baselines/reference/es6ExportAllInEs5.types b/tests/baselines/reference/es6ExportAllInEs5.types new file mode 100644 index 0000000000000..99e8fde9d4047 --- /dev/null +++ b/tests/baselines/reference/es6ExportAllInEs5.types @@ -0,0 +1,24 @@ +=== tests/cases/compiler/server.ts === + +export class c { +>c : c +} +export interface i { +>i : i +} +export module m { +>m : typeof m + + export var x = 10; +>x : number +} +export var x = 10; +>x : number + +export module uninstantiated { +>uninstantiated : unknown +} + +=== tests/cases/compiler/client.ts === +export * from "server"; +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es6ExportClause.errors.txt b/tests/baselines/reference/es6ExportClause.errors.txt new file mode 100644 index 0000000000000..464839e03a404 --- /dev/null +++ b/tests/baselines/reference/es6ExportClause.errors.txt @@ -0,0 +1,22 @@ +tests/cases/compiler/es6ExportClause.ts(12,1): error TS1148: Cannot compile external modules unless the '--module' flag is provided. + + +==== tests/cases/compiler/es6ExportClause.ts (1 errors) ==== + + class c { + } + interface i { + } + module m { + export var x = 10; + } + var x = 10; + module uninstantiated { + } + export { c }; + ~~~~~~~~~~~~~ +!!! error TS1148: Cannot compile external modules unless the '--module' flag is provided. + export { c as c2 }; + export { i, m as instantiatedModule }; + export { uninstantiated }; + export { x }; \ No newline at end of file diff --git a/tests/baselines/reference/es6ExportClause.js b/tests/baselines/reference/es6ExportClause.js new file mode 100644 index 0000000000000..27fc611692dc0 --- /dev/null +++ b/tests/baselines/reference/es6ExportClause.js @@ -0,0 +1,47 @@ +//// [es6ExportClause.ts] + +class c { +} +interface i { +} +module m { + export var x = 10; +} +var x = 10; +module uninstantiated { +} +export { c }; +export { c as c2 }; +export { i, m as instantiatedModule }; +export { uninstantiated }; +export { x }; + +//// [es6ExportClause.js] +var c = (function () { + function c() { + } + return c; +})(); +var m; +(function (m) { + m.x = 10; +})(m || (m = {})); +var x = 10; + + +//// [es6ExportClause.d.ts] +declare class c { +} +interface i { +} +declare module m { + var x: number; +} +declare var x: number; +declare module uninstantiated { +} +export { c }; +export { c as c2 }; +export { i, m as instantiatedModule }; +export { uninstantiated }; +export { x }; diff --git a/tests/baselines/reference/es6ExportClauseInEs5.js b/tests/baselines/reference/es6ExportClauseInEs5.js new file mode 100644 index 0000000000000..f987b48aecadd --- /dev/null +++ b/tests/baselines/reference/es6ExportClauseInEs5.js @@ -0,0 +1,51 @@ +//// [es6ExportClauseInEs5.ts] + +class c { +} +interface i { +} +module m { + export var x = 10; +} +var x = 10; +module uninstantiated { +} +export { c }; +export { c as c2 }; +export { i, m as instantiatedModule }; +export { uninstantiated }; +export { x }; + +//// [es6ExportClauseInEs5.js] +var c = (function () { + function c() { + } + return c; +})(); +exports.c = c; +exports.c2 = c; +var m; +(function (m) { + m.x = 10; +})(m || (m = {})); +exports.instantiatedModule = m; +var x = 10; +exports.x = x; + + +//// [es6ExportClauseInEs5.d.ts] +declare class c { +} +interface i { +} +declare module m { + var x: number; +} +declare var x: number; +declare module uninstantiated { +} +export { c }; +export { c as c2 }; +export { i, m as instantiatedModule }; +export { uninstantiated }; +export { x }; diff --git a/tests/baselines/reference/es6ExportClauseInEs5.types b/tests/baselines/reference/es6ExportClauseInEs5.types new file mode 100644 index 0000000000000..667a021466b34 --- /dev/null +++ b/tests/baselines/reference/es6ExportClauseInEs5.types @@ -0,0 +1,38 @@ +=== tests/cases/compiler/es6ExportClauseInEs5.ts === + +class c { +>c : c +} +interface i { +>i : i +} +module m { +>m : typeof m + + export var x = 10; +>x : number +} +var x = 10; +>x : number + +module uninstantiated { +>uninstantiated : unknown +} +export { c }; +>c : typeof c + +export { c as c2 }; +>c : unknown +>c2 : typeof c + +export { i, m as instantiatedModule }; +>i : unknown +>m : unknown +>instantiatedModule : typeof m + +export { uninstantiated }; +>uninstantiated : unknown + +export { x }; +>x : number + diff --git a/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.errors.txt b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.errors.txt new file mode 100644 index 0000000000000..7ac6946aedf99 --- /dev/null +++ b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.errors.txt @@ -0,0 +1,24 @@ +tests/cases/compiler/server.ts(2,14): error TS1148: Cannot compile external modules unless the '--module' flag is provided. + + +==== tests/cases/compiler/server.ts (1 errors) ==== + + export class c { + ~ +!!! error TS1148: Cannot compile external modules unless the '--module' flag is provided. + } + export interface i { + } + export module m { + export var x = 10; + } + export var x = 10; + export module uninstantiated { + } + +==== tests/cases/compiler/client.ts (0 errors) ==== + export { c } from "server"; + export { c as c2 } from "server"; + export { i, m as instantiatedModule } from "server"; + export { uninstantiated } from "server"; + export { x } from "server"; \ No newline at end of file diff --git a/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js new file mode 100644 index 0000000000000..69bb325ec753a --- /dev/null +++ b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js @@ -0,0 +1,65 @@ +//// [tests/cases/compiler/es6ExportClauseWithoutModuleSpecifier.ts] //// + +//// [server.ts] + +export class c { +} +export interface i { +} +export module m { + export var x = 10; +} +export var x = 10; +export module uninstantiated { +} + +//// [client.ts] +export { c } from "server"; +export { c as c2 } from "server"; +export { i, m as instantiatedModule } from "server"; +export { uninstantiated } from "server"; +export { x } from "server"; + +//// [server.js] +var c = (function () { + function c() { + } + return c; +})(); +exports.c = c; +var m; +(function (m) { + m.x = 10; +})(m = exports.m || (exports.m = {})); +exports.x = 10; +//// [client.js] +var _server = require("server"); +exports.c = _server.c; +var _server_1 = require("server"); +exports.c2 = _server_1.c; +var _server_2 = require("server"); +exports.i = _server_2.i; +exports.instantiatedModule = _server_2.m; +var _server_3 = require("server"); +exports.uninstantiated = _server_3.uninstantiated; +var _server_4 = require("server"); +exports.x = _server_4.x; + + +//// [server.d.ts] +export declare class c { +} +export interface i { +} +export declare module m { + var x: number; +} +export declare var x: number; +export declare module uninstantiated { +} +//// [client.d.ts] +export { c } from "server"; +export { c as c2 } from "server"; +export { i, m as instantiatedModule } from "server"; +export { uninstantiated } from "server"; +export { x } from "server"; diff --git a/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifierInEs5.js b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifierInEs5.js new file mode 100644 index 0000000000000..3e412c13a329a --- /dev/null +++ b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifierInEs5.js @@ -0,0 +1,65 @@ +//// [tests/cases/compiler/es6ExportClauseWithoutModuleSpecifierInEs5.ts] //// + +//// [server.ts] + +export class c { +} +export interface i { +} +export module m { + export var x = 10; +} +export var x = 10; +export module uninstantiated { +} + +//// [client.ts] +export { c } from "server"; +export { c as c2 } from "server"; +export { i, m as instantiatedModule } from "server"; +export { uninstantiated } from "server"; +export { x } from "server"; + +//// [server.js] +var c = (function () { + function c() { + } + return c; +})(); +exports.c = c; +var m; +(function (m) { + m.x = 10; +})(m = exports.m || (exports.m = {})); +exports.x = 10; +//// [client.js] +var _server = require("server"); +exports.c = _server.c; +var _server_1 = require("server"); +exports.c2 = _server_1.c; +var _server_2 = require("server"); +exports.i = _server_2.i; +exports.instantiatedModule = _server_2.m; +var _server_3 = require("server"); +exports.uninstantiated = _server_3.uninstantiated; +var _server_4 = require("server"); +exports.x = _server_4.x; + + +//// [server.d.ts] +export declare class c { +} +export interface i { +} +export declare module m { + var x: number; +} +export declare var x: number; +export declare module uninstantiated { +} +//// [client.d.ts] +export { c } from "server"; +export { c as c2 } from "server"; +export { i, m as instantiatedModule } from "server"; +export { uninstantiated } from "server"; +export { x } from "server"; diff --git a/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifierInEs5.types b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifierInEs5.types new file mode 100644 index 0000000000000..de81cf3f74f2a --- /dev/null +++ b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifierInEs5.types @@ -0,0 +1,40 @@ +=== tests/cases/compiler/server.ts === + +export class c { +>c : c +} +export interface i { +>i : i +} +export module m { +>m : typeof m + + export var x = 10; +>x : number +} +export var x = 10; +>x : number + +export module uninstantiated { +>uninstantiated : unknown +} + +=== tests/cases/compiler/client.ts === +export { c } from "server"; +>c : typeof c + +export { c as c2 } from "server"; +>c : unknown +>c2 : typeof c + +export { i, m as instantiatedModule } from "server"; +>i : unknown +>m : unknown +>instantiatedModule : typeof instantiatedModule + +export { uninstantiated } from "server"; +>uninstantiated : unknown + +export { x } from "server"; +>x : number + diff --git a/tests/cases/compiler/es6ExportAll.ts b/tests/cases/compiler/es6ExportAll.ts new file mode 100644 index 0000000000000..ed2b47c23c454 --- /dev/null +++ b/tests/cases/compiler/es6ExportAll.ts @@ -0,0 +1,17 @@ +// @target: es6 +// @declaration: true + +// @filename: server.ts +export class c { +} +export interface i { +} +export module m { + export var x = 10; +} +export var x = 10; +export module uninstantiated { +} + +// @filename: client.ts +export * from "server"; \ No newline at end of file diff --git a/tests/cases/compiler/es6ExportAllInEs5.ts b/tests/cases/compiler/es6ExportAllInEs5.ts new file mode 100644 index 0000000000000..ed754e5cacbb5 --- /dev/null +++ b/tests/cases/compiler/es6ExportAllInEs5.ts @@ -0,0 +1,18 @@ +// @target: es5 +// @module: commonjs +// @declaration: true + +// @filename: server.ts +export class c { +} +export interface i { +} +export module m { + export var x = 10; +} +export var x = 10; +export module uninstantiated { +} + +// @filename: client.ts +export * from "server"; \ No newline at end of file diff --git a/tests/cases/compiler/es6ExportClause.ts b/tests/cases/compiler/es6ExportClause.ts new file mode 100644 index 0000000000000..a16e2c9e7aa69 --- /dev/null +++ b/tests/cases/compiler/es6ExportClause.ts @@ -0,0 +1,19 @@ +// @target: es6 +// @declaration: true + +// @filename: server.ts +class c { +} +interface i { +} +module m { + export var x = 10; +} +var x = 10; +module uninstantiated { +} +export { c }; +export { c as c2 }; +export { i, m as instantiatedModule }; +export { uninstantiated }; +export { x }; \ No newline at end of file diff --git a/tests/cases/compiler/es6ExportClauseInEs5.ts b/tests/cases/compiler/es6ExportClauseInEs5.ts new file mode 100644 index 0000000000000..675f302bcb613 --- /dev/null +++ b/tests/cases/compiler/es6ExportClauseInEs5.ts @@ -0,0 +1,20 @@ +// @target: es5 +// @module: commonjs +// @declaration: true + +// @filename: server.ts +class c { +} +interface i { +} +module m { + export var x = 10; +} +var x = 10; +module uninstantiated { +} +export { c }; +export { c as c2 }; +export { i, m as instantiatedModule }; +export { uninstantiated }; +export { x }; \ No newline at end of file diff --git a/tests/cases/compiler/es6ExportClauseWithoutModuleSpecifier.ts b/tests/cases/compiler/es6ExportClauseWithoutModuleSpecifier.ts new file mode 100644 index 0000000000000..22a6cef420322 --- /dev/null +++ b/tests/cases/compiler/es6ExportClauseWithoutModuleSpecifier.ts @@ -0,0 +1,21 @@ +// @target: es6 +// @declaration: true + +// @filename: server.ts +export class c { +} +export interface i { +} +export module m { + export var x = 10; +} +export var x = 10; +export module uninstantiated { +} + +// @filename: client.ts +export { c } from "server"; +export { c as c2 } from "server"; +export { i, m as instantiatedModule } from "server"; +export { uninstantiated } from "server"; +export { x } from "server"; \ No newline at end of file diff --git a/tests/cases/compiler/es6ExportClauseWithoutModuleSpecifierInEs5.ts b/tests/cases/compiler/es6ExportClauseWithoutModuleSpecifierInEs5.ts new file mode 100644 index 0000000000000..6361c0133671c --- /dev/null +++ b/tests/cases/compiler/es6ExportClauseWithoutModuleSpecifierInEs5.ts @@ -0,0 +1,22 @@ +// @target: es5 +// @module: commonjs +// @declaration: true + +// @filename: server.ts +export class c { +} +export interface i { +} +export module m { + export var x = 10; +} +export var x = 10; +export module uninstantiated { +} + +// @filename: client.ts +export { c } from "server"; +export { c as c2 } from "server"; +export { i, m as instantiatedModule } from "server"; +export { uninstantiated } from "server"; +export { x } from "server"; \ No newline at end of file From f8ae8234c7262e9248ba95cd4dcb090a58d80a9c Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Tue, 24 Feb 2015 23:51:12 -0800 Subject: [PATCH 015/224] merge with master, fix emit for omitted expressions --- src/compiler/emitter.ts | 4 ++++ ...itDestructuringOptionalBindingParametersInOverloads.js | 8 -------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 13204ab22e8f3..17e1c82e9550c 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3726,6 +3726,10 @@ module ts { } function emitExportVariableAssignments(node: VariableDeclaration | BindingElement) { + if (node.kind === SyntaxKind.OmittedExpression) { + return; + } + var name = (node).name; if (name.kind === SyntaxKind.Identifier) { emitExportMemberAssignments(name); diff --git a/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.js b/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.js index c907add11f776..24b16a7742a29 100644 --- a/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.js +++ b/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.js @@ -11,16 +11,8 @@ function foo2(...rest: any[]) { //// [declarationEmitDestructuringOptionalBindingParametersInOverloads.js] function foo() { - var rest = []; - for (var _i = 0; _i < arguments.length; _i++) { - rest[_i - 0] = arguments[_i]; - } } function foo2() { - var rest = []; - for (var _i = 0; _i < arguments.length; _i++) { - rest[_i - 0] = arguments[_i]; - } } From 0e2fe027acf2721e6aeeb0530d80ca2547e5061d Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 2 Mar 2015 11:56:21 -0800 Subject: [PATCH 016/224] update baselines --- ...ucturingOptionalBindingParametersInOverloads.js | 8 ++++++++ .../baselines/reference/es6ExportClauseInEs5.types | 4 ++-- ...s6ExportClauseWithoutModuleSpecifierInEs5.types | 4 ++-- .../baselines/reference/es6ImportNamedImport.types | 4 ++-- .../reference/es6ImportNamedImportAmd.types | 14 +++++++------- .../reference/es6ImportNamedImportDts.types | 14 +++++++------- .../reference/es6ImportNamedImportInEs5.types | 4 ++-- 7 files changed, 30 insertions(+), 22 deletions(-) diff --git a/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.js b/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.js index 24b16a7742a29..c907add11f776 100644 --- a/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.js +++ b/tests/baselines/reference/declarationEmitDestructuringOptionalBindingParametersInOverloads.js @@ -11,8 +11,16 @@ function foo2(...rest: any[]) { //// [declarationEmitDestructuringOptionalBindingParametersInOverloads.js] function foo() { + var rest = []; + for (var _i = 0; _i < arguments.length; _i++) { + rest[_i - 0] = arguments[_i]; + } } function foo2() { + var rest = []; + for (var _i = 0; _i < arguments.length; _i++) { + rest[_i - 0] = arguments[_i]; + } } diff --git a/tests/baselines/reference/es6ExportClauseInEs5.types b/tests/baselines/reference/es6ExportClauseInEs5.types index 667a021466b34..8caedfa5ceb9e 100644 --- a/tests/baselines/reference/es6ExportClauseInEs5.types +++ b/tests/baselines/reference/es6ExportClauseInEs5.types @@ -22,12 +22,12 @@ export { c }; >c : typeof c export { c as c2 }; ->c : unknown +>c : typeof c >c2 : typeof c export { i, m as instantiatedModule }; >i : unknown ->m : unknown +>m : typeof m >instantiatedModule : typeof m export { uninstantiated }; diff --git a/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifierInEs5.types b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifierInEs5.types index de81cf3f74f2a..c0087dccd943a 100644 --- a/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifierInEs5.types +++ b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifierInEs5.types @@ -24,12 +24,12 @@ export { c } from "server"; >c : typeof c export { c as c2 } from "server"; ->c : unknown +>c : typeof c >c2 : typeof c export { i, m as instantiatedModule } from "server"; >i : unknown ->m : unknown +>m : typeof instantiatedModule >instantiatedModule : typeof instantiatedModule export { uninstantiated } from "server"; diff --git a/tests/baselines/reference/es6ImportNamedImport.types b/tests/baselines/reference/es6ImportNamedImport.types index 49771928f11bf..23dfe51c53dab 100644 --- a/tests/baselines/reference/es6ImportNamedImport.types +++ b/tests/baselines/reference/es6ImportNamedImport.types @@ -105,7 +105,7 @@ var z111 = z1; >z1 : number import { z2 as z3 } from "es6ImportNamedImport_0"; ->z2 : unknown +>z2 : number >z3 : number var z2 = z3; // z2 shouldn't give redeclare error @@ -118,6 +118,6 @@ import { aaaa } from "es6ImportNamedImport_0"; // These are elided import { aaaa as bbbb } from "es6ImportNamedImport_0"; ->aaaa : unknown +>aaaa : number >bbbb : number diff --git a/tests/baselines/reference/es6ImportNamedImportAmd.types b/tests/baselines/reference/es6ImportNamedImportAmd.types index 3a68df656febc..4a0abe853e025 100644 --- a/tests/baselines/reference/es6ImportNamedImportAmd.types +++ b/tests/baselines/reference/es6ImportNamedImportAmd.types @@ -36,7 +36,7 @@ var xxxx = a; >a : number import { a as b } from "es6ImportNamedImportAmd_0"; ->a : unknown +>a : number >b : number var xxxx = b; @@ -45,7 +45,7 @@ var xxxx = b; import { x, a as y } from "es6ImportNamedImportAmd_0"; >x : number ->a : unknown +>a : number >y : number var xxxx = x; @@ -57,7 +57,7 @@ var xxxx = y; >y : number import { x as z, } from "es6ImportNamedImportAmd_0"; ->x : unknown +>x : number >z : number var xxxx = z; @@ -84,9 +84,9 @@ var xxxx = x1; >x1 : number import { a1 as a11, x1 as x11 } from "es6ImportNamedImportAmd_0"; ->a1 : unknown +>a1 : number >a11 : number ->x1 : unknown +>x1 : number >x11 : number var xxxx = a11; @@ -105,7 +105,7 @@ var z111 = z1; >z1 : number import { z2 as z3 } from "es6ImportNamedImportAmd_0"; ->z2 : unknown +>z2 : number >z3 : number var z2 = z3; // z2 shouldn't give redeclare error @@ -118,6 +118,6 @@ import { aaaa } from "es6ImportNamedImportAmd_0"; // These are elided import { aaaa as bbbb } from "es6ImportNamedImportAmd_0"; ->aaaa : unknown +>aaaa : number >bbbb : number diff --git a/tests/baselines/reference/es6ImportNamedImportDts.types b/tests/baselines/reference/es6ImportNamedImportDts.types index ba036202a52c2..93bd55716a514 100644 --- a/tests/baselines/reference/es6ImportNamedImportDts.types +++ b/tests/baselines/reference/es6ImportNamedImportDts.types @@ -53,7 +53,7 @@ export var xxxx = new a(); >a : typeof a import { a11 as b } from "server"; ->a11 : unknown +>a11 : typeof b >b : typeof b export var xxxx1 = new b(); @@ -63,7 +63,7 @@ export var xxxx1 = new b(); import { x, a12 as y } from "server"; >x : typeof x ->a12 : unknown +>a12 : typeof y >y : typeof y export var xxxx2 = new x(); @@ -77,7 +77,7 @@ export var xxxx3 = new y(); >y : typeof y import { x11 as z, } from "server"; ->x11 : unknown +>x11 : typeof z >z : typeof z export var xxxx4 = new z(); @@ -108,9 +108,9 @@ export var xxxx7 = new x1(); >x1 : typeof x1 import { a111 as a11, x111 as x11 } from "server"; ->a111 : unknown +>a111 : typeof a11 >a11 : typeof a11 ->x111 : unknown +>x111 : typeof x11 >x11 : typeof x11 export var xxxx8 = new a11(); @@ -132,7 +132,7 @@ export var z111 = new z1(); >z1 : typeof z1 import { z2 as z3 } from "server"; ->z2 : unknown +>z2 : typeof z3 >z3 : typeof z3 export var z2 = new z3(); // z2 shouldn't give redeclare error @@ -145,6 +145,6 @@ import { aaaa } from "server"; >aaaa : typeof aaaa import { aaaa1 as bbbb } from "server"; ->aaaa1 : unknown +>aaaa1 : typeof bbbb >bbbb : typeof bbbb diff --git a/tests/baselines/reference/es6ImportNamedImportInEs5.types b/tests/baselines/reference/es6ImportNamedImportInEs5.types index 012caca48cfd1..f60644b262103 100644 --- a/tests/baselines/reference/es6ImportNamedImportInEs5.types +++ b/tests/baselines/reference/es6ImportNamedImportInEs5.types @@ -105,7 +105,7 @@ var z111 = z1; >z1 : number import { z2 as z3 } from "es6ImportNamedImportInEs5_0"; ->z2 : unknown +>z2 : number >z3 : number var z2 = z3; // z2 shouldn't give redeclare error @@ -118,6 +118,6 @@ import { aaaa } from "es6ImportNamedImportInEs5_0"; // These are elided import { aaaa as bbbb } from "es6ImportNamedImportInEs5_0"; ->aaaa : unknown +>aaaa : number >bbbb : number From 8d089afb34b2aaa054d018a6a2fa9ca94167dcd5 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 4 Mar 2015 08:17:18 -0800 Subject: [PATCH 017/224] enum cleanup: apply constant folding to all enum initializers, inline accesses only for const enums --- src/compiler/checker.ts | 52 +-- src/compiler/emitter.ts | 13 +- .../EnumAndModuleWithSameNameAndCommonRoot.js | 2 +- .../ModuleAndEnumWithSameNameAndCommonRoot.js | 2 +- .../ModuleWithExportedAndNonExportedEnums.js | 2 +- .../additionOperatorWithAnyAndEveryType.js | 2 +- .../additionOperatorWithInvalidOperands.js | 6 +- ...onOperatorWithNullValueAndValidOperator.js | 8 +- .../additionOperatorWithNumberAndEnum.js | 8 +- .../additionOperatorWithStringAndEveryType.js | 2 +- ...ratorWithUndefinedValueAndValidOperator.js | 8 +- .../reference/amdImportAsPrimaryExpression.js | 2 +- .../reference/arithmeticOperatorWithEnum.js | 140 ++++---- .../arithmeticOperatorWithEnumUnion.js | 140 ++++---- .../arithmeticOperatorWithInvalidOperands.js | 240 +++++++------- ...icOperatorWithNullValueAndValidOperands.js | 40 +-- ...ratorWithUndefinedValueAndValidOperands.js | 40 +-- .../reference/assignAnyToEveryType.js | 2 +- .../reference/assignEveryTypeToAny.js | 4 +- tests/baselines/reference/assignToEnum.js | 6 +- tests/baselines/reference/assignments.js | 2 +- .../reference/bestCommonTypeOfTuple.js | 4 +- .../bitwiseNotOperatorWithEnumType.js | 10 +- tests/baselines/reference/castingTuple.js | 2 +- ...lisionCodeGenEnumWithEnumMemberConflict.js | 2 +- ...sionCodeGenModuleWithEnumMemberConflict.js | 2 +- tests/baselines/reference/commentsEnums.js | 4 +- ...parisonOperatorWithSubtypeEnumAndNumber.js | 64 ++-- ...poundAdditionAssignmentLHSCanBeAssigned.js | 8 +- ...ndAdditionAssignmentWithInvalidOperands.js | 6 +- ...ArithmeticAssignmentWithInvalidOperands.js | 8 +- .../reference/computedPropertyNames47_ES5.js | 2 +- .../reference/computedPropertyNames47_ES6.js | 2 +- .../reference/computedPropertyNames48_ES5.js | 2 +- .../reference/computedPropertyNames48_ES6.js | 2 +- .../reference/computedPropertyNames7_ES5.js | 2 +- .../reference/computedPropertyNames7_ES6.js | 2 +- ...constructorWithIncompleteTypeAnnotation.js | 2 +- tests/baselines/reference/declFileEnums.js | 8 +- .../baselines/reference/declFileTypeofEnum.js | 2 +- .../declFileTypeofInAnonymousType.js | 2 +- .../decrementOperatorWithEnumType.js | 6 +- .../reference/deleteOperatorWithEnumType.js | 8 +- .../reference/duplicateLocalVariable4.js | 2 +- .../baselines/reference/enumAssignability.js | 4 +- .../enumAssignabilityInInheritance.js | 34 +- .../reference/enumAssignmentCompat.js | 12 +- .../reference/enumAssignmentCompat2.js | 12 +- tests/baselines/reference/enumBasics.js | 10 +- tests/baselines/reference/enumBasics1.js | 2 +- .../enumConflictsWithGlobalIdentifier.js | 2 +- .../baselines/reference/enumErrors.errors.txt | 8 +- tests/baselines/reference/enumErrors.js | 6 +- .../reference/enumFromExternalModule.js | 2 +- tests/baselines/reference/enumIndexer.js | 2 +- .../reference/enumMapBackIntoItself.js | 2 +- .../reference/enumMemberResolution.js | 2 +- tests/baselines/reference/enumMerging.js | 6 +- tests/baselines/reference/enumOperations.js | 2 +- .../baselines/reference/enumPropertyAccess.js | 2 +- .../enumWithParenthesizedInitializer1.js | 2 +- ...umWithoutInitializerAfterComputedMember.js | 4 +- .../reference/exportAssignmentEnum.js | 6 +- .../exportAssignmentTopLevelEnumdule.js | 2 +- tests/baselines/reference/for-inStatements.js | 2 +- tests/baselines/reference/for-of47.js | 2 +- tests/baselines/reference/for-of48.js | 2 +- ...nericCallWithGenericSignatureArguments2.js | 4 +- ...nericCallWithGenericSignatureArguments3.js | 2 +- .../inOperatorWithInvalidOperands.js | 2 +- .../reference/incrementAndDecrement.js | 2 +- .../incrementOperatorWithEnumType.js | 8 +- .../baselines/reference/instantiatedModule.js | 6 +- .../reference/interfaceAssignmentCompat.js | 6 +- .../interfaceWithPropertyOfEveryType.js | 2 +- .../baselines/reference/internalAliasEnum.js | 2 +- ...nalAliasEnumInsideLocalModuleWithExport.js | 2 +- ...AliasEnumInsideLocalModuleWithoutExport.js | 2 +- ...sideLocalModuleWithoutExportAccessError.js | 2 +- ...AliasEnumInsideTopLevelModuleWithExport.js | 2 +- ...asEnumInsideTopLevelModuleWithoutExport.js | 2 +- .../reference/invalidEnumAssignments.js | 4 +- .../reference/invalidUndefinedAssignments.js | 2 +- .../reference/invalidUndefinedValues.js | 2 +- .../reference/invalidVoidAssignments.js | 2 +- .../baselines/reference/invalidVoidValues.js | 2 +- .../reference/localImportNameVsGlobalName.js | 6 +- .../logicalNotOperatorWithEnumType.js | 8 +- .../reference/mergedDeclarations2.js | 2 +- .../reference/mergedEnumDeclarationCodeGen.js | 4 +- .../baselines/reference/moduleCodeGenTest5.js | 4 +- .../reference/moduleVisibilityTest1.js | 4 +- .../reference/negateOperatorWithEnumType.js | 6 +- .../reference/noImplicitAnyIndexing.js | 8 +- .../noImplicitAnyIndexingSuppressed.js | 8 +- .../nullIsSubtypeOfEverythingButUndefined.js | 4 +- .../reference/objectTypesIdentity2.js | 2 +- .../reference/operatorAddNullUndefined.js | 8 +- tests/baselines/reference/parserEnum1.js | 4 +- tests/baselines/reference/parserEnum2.js | 4 +- .../reference/parserEnumDeclaration6.js | 4 +- .../baselines/reference/parserRealSource10.js | 278 ++++++++-------- .../baselines/reference/parserRealSource14.js | 6 +- .../baselines/reference/parserRealSource2.js | 298 +++++++++--------- .../baselines/reference/parserRealSource3.js | 4 +- .../reference/plusOperatorWithEnumType.js | 6 +- ...yLocalInternalReferenceImportWithExport.js | 16 +- ...calInternalReferenceImportWithoutExport.js | 16 +- ...pLevelInternalReferenceImportWithExport.js | 8 +- ...velInternalReferenceImportWithoutExport.js | 8 +- tests/baselines/reference/propertyAccess.js | 10 +- .../reference/propertyNamesOfReservedWords.js | 4 +- .../reference/sourceMapValidationEnums.js.map | 2 +- .../sourceMapValidationEnums.sourcemap.txt | 40 +-- .../reference/subtypesOfTypeParameter.js | 4 +- ...subtypesOfTypeParameterWithConstraints2.js | 4 +- tests/baselines/reference/typeAliases.js | 2 +- .../typeArgumentInferenceWithObjectLiteral.js | 8 +- tests/baselines/reference/typeofEnum.js | 2 +- .../reference/typeofOperatorWithEnumType.js | 8 +- tests/baselines/reference/unaryPlus.js | 2 +- .../reference/validEnumAssignments.js | 8 +- .../reference/validNullAssignments.js | 2 +- .../reference/validNumberAssignments.js | 2 +- .../reference/voidOperatorWithEnumType.js | 8 +- 125 files changed, 935 insertions(+), 944 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 9daa87daed48e..06aa9fce35977 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9560,7 +9560,7 @@ module ts { } var initializer = member.initializer; if (initializer) { - autoValue = getConstantValueForEnumMemberInitializer(initializer, enumIsConst); + autoValue = getConstantValueForEnumMemberInitializer(initializer); if (autoValue === undefined) { if (enumIsConst) { error(initializer, Diagnostics.In_const_enum_declarations_member_initializer_must_be_constant_expression); @@ -9570,7 +9570,7 @@ module ts { // If it is a constant value (not undefined), it is syntactically constrained to be a number. // Also, we do not need to check this for ambients because there is already // a syntax error if it is not a constant. - checkTypeAssignableTo(checkExpression(initializer), enumType, initializer, /*headMessage*/ undefined); + checkTypeAssignableTo(checkExpression(initializer), enumType, initializer, /*headMessage*/ undefined); } } else if (enumIsConst) { @@ -9595,7 +9595,7 @@ module ts { nodeLinks.flags |= NodeCheckFlags.EnumValuesComputed; } - function getConstantValueForEnumMemberInitializer(initializer: Expression, enumIsConst: boolean): number { + function getConstantValueForEnumMemberInitializer(initializer: Expression): number { return evalConstant(initializer); function evalConstant(e: Node): number { @@ -9608,14 +9608,10 @@ module ts { switch ((e).operator) { case SyntaxKind.PlusToken: return value; case SyntaxKind.MinusToken: return -value; - case SyntaxKind.TildeToken: return enumIsConst ? ~value : undefined; + case SyntaxKind.TildeToken: return ~value; } return undefined; case SyntaxKind.BinaryExpression: - if (!enumIsConst) { - return undefined; - } - var left = evalConstant((e).left); if (left === undefined) { return undefined; @@ -9641,14 +9637,10 @@ module ts { case SyntaxKind.NumericLiteral: return +(e).text; case SyntaxKind.ParenthesizedExpression: - return enumIsConst ? evalConstant((e).expression) : undefined; + return evalConstant((e).expression); case SyntaxKind.Identifier: case SyntaxKind.ElementAccessExpression: case SyntaxKind.PropertyAccessExpression: - if (!enumIsConst) { - return undefined; - } - var member = initializer.parent; var currentType = getTypeOfSymbol(getSymbolOfNode(member.parent)); var enumType: Type; @@ -9661,19 +9653,37 @@ module ts { propertyName = (e).text; } else { + var expression: Expression; if (e.kind === SyntaxKind.ElementAccessExpression) { if ((e).argumentExpression === undefined || (e).argumentExpression.kind !== SyntaxKind.StringLiteral) { return undefined; } - var enumType = getTypeOfNode((e).expression); + expression = (e).expression; propertyName = ((e).argumentExpression).text; } else { - var enumType = getTypeOfNode((e).expression); + expression = (e).expression; propertyName = (e).name.text; } - if (enumType !== currentType) { + + // expression part in ElementAccess\PropertyAccess should be either identifier or dottedName + var current = expression; + while (current) { + if (current.kind === SyntaxKind.Identifier) { + break; + } + else if (current.kind === SyntaxKind.PropertyAccessExpression) { + current = (current).expression; + } + else { + return undefined; + } + } + + var enumType = checkExpression(expression); + // allow references to constant members of other enums + if (!(enumType.symbol && (enumType.symbol.flags & SymbolFlags.Enum))) { return undefined; } } @@ -9681,10 +9691,12 @@ module ts { if (propertyName === undefined) { return undefined; } + var property = getPropertyOfObjectType(enumType, propertyName); if (!property || !(property.flags & SymbolFlags.EnumMember)) { return undefined; } + var propertyDecl = property.valueDeclaration; // self references are illegal if (member === propertyDecl) { @@ -9695,6 +9707,7 @@ module ts { if (!isDefinedBefore(propertyDecl, member)) { return undefined; } + return getNodeLinks(propertyDecl).enumMemberValue; } } @@ -10866,10 +10879,9 @@ module ts { var symbol = getNodeLinks(node).resolvedSymbol; if (symbol && (symbol.flags & SymbolFlags.EnumMember)) { - var declaration = symbol.valueDeclaration; - var constantValue: number; - if (declaration.kind === SyntaxKind.EnumMember) { - return getEnumMemberValue(declaration); + // inline property\index accesses only for const enums + if (isConstEnumDeclaration(symbol.valueDeclaration.parent)) { + return getEnumMemberValue(symbol.valueDeclaration); } } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index a24e69e3005fc..347ce57034e8b 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4612,15 +4612,12 @@ module ts { } function writeEnumMemberDeclarationValue(member: EnumMember) { - if (!member.initializer || isConst(member.parent)) { - var value = resolver.getConstantValue(member); - if (value !== undefined) { - write(value.toString()); - return; - } + var value = resolver.getConstantValue(member); + if (value !== undefined) { + write(value.toString()); + return; } - - if (member.initializer) { + else if (member.initializer) { emit(member.initializer); } else { diff --git a/tests/baselines/reference/EnumAndModuleWithSameNameAndCommonRoot.js b/tests/baselines/reference/EnumAndModuleWithSameNameAndCommonRoot.js index d9fdb511fa213..4ca0b4cd5f740 100644 --- a/tests/baselines/reference/EnumAndModuleWithSameNameAndCommonRoot.js +++ b/tests/baselines/reference/EnumAndModuleWithSameNameAndCommonRoot.js @@ -34,6 +34,6 @@ var enumdule; enumdule.Point = Point; })(enumdule || (enumdule = {})); var x; -var x = 0 /* Red */; +var x = enumdule.Red; var y; var y = new enumdule.Point(0, 0); diff --git a/tests/baselines/reference/ModuleAndEnumWithSameNameAndCommonRoot.js b/tests/baselines/reference/ModuleAndEnumWithSameNameAndCommonRoot.js index 533843d294732..96df9812bc638 100644 --- a/tests/baselines/reference/ModuleAndEnumWithSameNameAndCommonRoot.js +++ b/tests/baselines/reference/ModuleAndEnumWithSameNameAndCommonRoot.js @@ -34,6 +34,6 @@ var enumdule; enumdule[enumdule["Blue"] = 1] = "Blue"; })(enumdule || (enumdule = {})); var x; -var x = 0 /* Red */; +var x = enumdule.Red; var y; var y = new enumdule.Point(0, 0); diff --git a/tests/baselines/reference/ModuleWithExportedAndNonExportedEnums.js b/tests/baselines/reference/ModuleWithExportedAndNonExportedEnums.js index afcef6bbb5c3c..3cd522d3c2c2f 100644 --- a/tests/baselines/reference/ModuleWithExportedAndNonExportedEnums.js +++ b/tests/baselines/reference/ModuleWithExportedAndNonExportedEnums.js @@ -26,6 +26,6 @@ var A; })(Day || (Day = {})); })(A || (A = {})); // not an error since exported -var a = 0 /* Red */; +var a = A.Color.Red; // error not exported var b = A.Day.Monday; diff --git a/tests/baselines/reference/additionOperatorWithAnyAndEveryType.js b/tests/baselines/reference/additionOperatorWithAnyAndEveryType.js index 26a77e917d951..04fb5a143c60e 100644 --- a/tests/baselines/reference/additionOperatorWithAnyAndEveryType.js +++ b/tests/baselines/reference/additionOperatorWithAnyAndEveryType.js @@ -79,7 +79,7 @@ var r11 = a + foo(); var r12 = a + C; var r13 = a + new C(); var r14 = a + E; -var r15 = a + 0 /* a */; +var r15 = a + E.a; var r16 = a + M; var r17 = a + ''; var r18 = a + 123; diff --git a/tests/baselines/reference/additionOperatorWithInvalidOperands.js b/tests/baselines/reference/additionOperatorWithInvalidOperands.js index 7bd31c7ae5317..a8edb4b187984 100644 --- a/tests/baselines/reference/additionOperatorWithInvalidOperands.js +++ b/tests/baselines/reference/additionOperatorWithInvalidOperands.js @@ -83,6 +83,6 @@ var r14 = b + d; var r15 = b + foo; var r16 = b + foo(); var r17 = b + C; -var r18 = 0 /* a */ + new C(); -var r19 = 0 /* a */ + C.foo(); -var r20 = 0 /* a */ + M; +var r18 = E.a + new C(); +var r19 = E.a + C.foo(); +var r20 = E.a + M; diff --git a/tests/baselines/reference/additionOperatorWithNullValueAndValidOperator.js b/tests/baselines/reference/additionOperatorWithNullValueAndValidOperator.js index 1ba54d47f1cb3..1b5cb877d21bc 100644 --- a/tests/baselines/reference/additionOperatorWithNullValueAndValidOperator.js +++ b/tests/baselines/reference/additionOperatorWithNullValueAndValidOperator.js @@ -49,13 +49,13 @@ var r2 = a + null; var r3 = null + b; var r4 = null + 1; var r5 = null + c; -var r6 = null + 0 /* a */; -var r7 = null + 0 /* 'a' */; +var r6 = null + E.a; +var r7 = null + E['a']; var r8 = b + null; var r9 = 1 + null; var r10 = c + null; -var r11 = 0 /* a */ + null; -var r12 = 0 /* 'a' */ + null; +var r11 = E.a + null; +var r12 = E['a'] + null; // null + string var r13 = null + d; var r14 = null + ''; diff --git a/tests/baselines/reference/additionOperatorWithNumberAndEnum.js b/tests/baselines/reference/additionOperatorWithNumberAndEnum.js index 231831518e6c7..d559e98dc3eff 100644 --- a/tests/baselines/reference/additionOperatorWithNumberAndEnum.js +++ b/tests/baselines/reference/additionOperatorWithNumberAndEnum.js @@ -43,10 +43,10 @@ var r2 = a + b; var r3 = b + a; var r4 = b + b; var r5 = 0 + a; -var r6 = 0 /* a */ + 0; -var r7 = 0 /* a */ + 1 /* b */; -var r8 = 0 /* 'a' */ + 1 /* 'b' */; -var r9 = 0 /* 'a' */ + 0 /* 'c' */; +var r6 = E.a + 0; +var r7 = E.a + E.b; +var r8 = E['a'] + E['b']; +var r9 = E['a'] + F['c']; var r10 = a + c; var r11 = c + a; var r12 = b + c; diff --git a/tests/baselines/reference/additionOperatorWithStringAndEveryType.js b/tests/baselines/reference/additionOperatorWithStringAndEveryType.js index ecce65ba577fb..03456020c802f 100644 --- a/tests/baselines/reference/additionOperatorWithStringAndEveryType.js +++ b/tests/baselines/reference/additionOperatorWithStringAndEveryType.js @@ -72,7 +72,7 @@ var r13 = f + x; var r14 = g + x; // other cases var r15 = x + E; -var r16 = x + 0 /* a */; +var r16 = x + E.a; var r17 = x + ''; var r18 = x + 0; var r19 = x + { a: '' }; diff --git a/tests/baselines/reference/additionOperatorWithUndefinedValueAndValidOperator.js b/tests/baselines/reference/additionOperatorWithUndefinedValueAndValidOperator.js index cb89d242a18a6..68804694449e1 100644 --- a/tests/baselines/reference/additionOperatorWithUndefinedValueAndValidOperator.js +++ b/tests/baselines/reference/additionOperatorWithUndefinedValueAndValidOperator.js @@ -49,13 +49,13 @@ var r2 = a + undefined; var r3 = undefined + b; var r4 = undefined + 1; var r5 = undefined + c; -var r6 = undefined + 0 /* a */; -var r7 = undefined + 0 /* 'a' */; +var r6 = undefined + E.a; +var r7 = undefined + E['a']; var r8 = b + undefined; var r9 = 1 + undefined; var r10 = c + undefined; -var r11 = 0 /* a */ + undefined; -var r12 = 0 /* 'a' */ + undefined; +var r11 = E.a + undefined; +var r12 = E['a'] + undefined; // undefined + string var r13 = undefined + d; var r14 = undefined + ''; diff --git a/tests/baselines/reference/amdImportAsPrimaryExpression.js b/tests/baselines/reference/amdImportAsPrimaryExpression.js index 4704b32d9891c..fc8d0420842e7 100644 --- a/tests/baselines/reference/amdImportAsPrimaryExpression.js +++ b/tests/baselines/reference/amdImportAsPrimaryExpression.js @@ -23,6 +23,6 @@ define(["require", "exports"], function (require, exports) { }); //// [foo_1.js] define(["require", "exports", "./foo_0"], function (require, exports, foo) { - if (0 /* A */ === 0) { + if (foo.E1.A === 0) { } }); diff --git a/tests/baselines/reference/arithmeticOperatorWithEnum.js b/tests/baselines/reference/arithmeticOperatorWithEnum.js index 9ef2790b4cef1..3572f3ecc41e4 100644 --- a/tests/baselines/reference/arithmeticOperatorWithEnum.js +++ b/tests/baselines/reference/arithmeticOperatorWithEnum.js @@ -166,127 +166,127 @@ var ra2 = c * b; var ra3 = c * c; var ra4 = a * c; var ra5 = b * c; -var ra6 = 0 /* a */ * a; -var ra7 = 0 /* a */ * b; -var ra8 = 0 /* a */ * 1 /* b */; -var ra9 = 0 /* a */ * 1; -var ra10 = a * 1 /* b */; -var ra11 = b * 1 /* b */; -var ra12 = 1 * 1 /* b */; +var ra6 = E.a * a; +var ra7 = E.a * b; +var ra8 = E.a * E.b; +var ra9 = E.a * 1; +var ra10 = a * E.b; +var ra11 = b * E.b; +var ra12 = 1 * E.b; // operator / var rb1 = c / a; var rb2 = c / b; var rb3 = c / c; var rb4 = a / c; var rb5 = b / c; -var rb6 = 0 /* a */ / a; -var rb7 = 0 /* a */ / b; -var rb8 = 0 /* a */ / 1 /* b */; -var rb9 = 0 /* a */ / 1; -var rb10 = a / 1 /* b */; -var rb11 = b / 1 /* b */; -var rb12 = 1 / 1 /* b */; +var rb6 = E.a / a; +var rb7 = E.a / b; +var rb8 = E.a / E.b; +var rb9 = E.a / 1; +var rb10 = a / E.b; +var rb11 = b / E.b; +var rb12 = 1 / E.b; // operator % var rc1 = c % a; var rc2 = c % b; var rc3 = c % c; var rc4 = a % c; var rc5 = b % c; -var rc6 = 0 /* a */ % a; -var rc7 = 0 /* a */ % b; -var rc8 = 0 /* a */ % 1 /* b */; -var rc9 = 0 /* a */ % 1; -var rc10 = a % 1 /* b */; -var rc11 = b % 1 /* b */; -var rc12 = 1 % 1 /* b */; +var rc6 = E.a % a; +var rc7 = E.a % b; +var rc8 = E.a % E.b; +var rc9 = E.a % 1; +var rc10 = a % E.b; +var rc11 = b % E.b; +var rc12 = 1 % E.b; // operator - var rd1 = c - a; var rd2 = c - b; var rd3 = c - c; var rd4 = a - c; var rd5 = b - c; -var rd6 = 0 /* a */ - a; -var rd7 = 0 /* a */ - b; -var rd8 = 0 /* a */ - 1 /* b */; -var rd9 = 0 /* a */ - 1; -var rd10 = a - 1 /* b */; -var rd11 = b - 1 /* b */; -var rd12 = 1 - 1 /* b */; +var rd6 = E.a - a; +var rd7 = E.a - b; +var rd8 = E.a - E.b; +var rd9 = E.a - 1; +var rd10 = a - E.b; +var rd11 = b - E.b; +var rd12 = 1 - E.b; // operator << var re1 = c << a; var re2 = c << b; var re3 = c << c; var re4 = a << c; var re5 = b << c; -var re6 = 0 /* a */ << a; -var re7 = 0 /* a */ << b; -var re8 = 0 /* a */ << 1 /* b */; -var re9 = 0 /* a */ << 1; -var re10 = a << 1 /* b */; -var re11 = b << 1 /* b */; -var re12 = 1 << 1 /* b */; +var re6 = E.a << a; +var re7 = E.a << b; +var re8 = E.a << E.b; +var re9 = E.a << 1; +var re10 = a << E.b; +var re11 = b << E.b; +var re12 = 1 << E.b; // operator >> var rf1 = c >> a; var rf2 = c >> b; var rf3 = c >> c; var rf4 = a >> c; var rf5 = b >> c; -var rf6 = 0 /* a */ >> a; -var rf7 = 0 /* a */ >> b; -var rf8 = 0 /* a */ >> 1 /* b */; -var rf9 = 0 /* a */ >> 1; -var rf10 = a >> 1 /* b */; -var rf11 = b >> 1 /* b */; -var rf12 = 1 >> 1 /* b */; +var rf6 = E.a >> a; +var rf7 = E.a >> b; +var rf8 = E.a >> E.b; +var rf9 = E.a >> 1; +var rf10 = a >> E.b; +var rf11 = b >> E.b; +var rf12 = 1 >> E.b; // operator >>> var rg1 = c >>> a; var rg2 = c >>> b; var rg3 = c >>> c; var rg4 = a >>> c; var rg5 = b >>> c; -var rg6 = 0 /* a */ >>> a; -var rg7 = 0 /* a */ >>> b; -var rg8 = 0 /* a */ >>> 1 /* b */; -var rg9 = 0 /* a */ >>> 1; -var rg10 = a >>> 1 /* b */; -var rg11 = b >>> 1 /* b */; -var rg12 = 1 >>> 1 /* b */; +var rg6 = E.a >>> a; +var rg7 = E.a >>> b; +var rg8 = E.a >>> E.b; +var rg9 = E.a >>> 1; +var rg10 = a >>> E.b; +var rg11 = b >>> E.b; +var rg12 = 1 >>> E.b; // operator & var rh1 = c & a; var rh2 = c & b; var rh3 = c & c; var rh4 = a & c; var rh5 = b & c; -var rh6 = 0 /* a */ & a; -var rh7 = 0 /* a */ & b; -var rh8 = 0 /* a */ & 1 /* b */; -var rh9 = 0 /* a */ & 1; -var rh10 = a & 1 /* b */; -var rh11 = b & 1 /* b */; -var rh12 = 1 & 1 /* b */; +var rh6 = E.a & a; +var rh7 = E.a & b; +var rh8 = E.a & E.b; +var rh9 = E.a & 1; +var rh10 = a & E.b; +var rh11 = b & E.b; +var rh12 = 1 & E.b; // operator ^ var ri1 = c ^ a; var ri2 = c ^ b; var ri3 = c ^ c; var ri4 = a ^ c; var ri5 = b ^ c; -var ri6 = 0 /* a */ ^ a; -var ri7 = 0 /* a */ ^ b; -var ri8 = 0 /* a */ ^ 1 /* b */; -var ri9 = 0 /* a */ ^ 1; -var ri10 = a ^ 1 /* b */; -var ri11 = b ^ 1 /* b */; -var ri12 = 1 ^ 1 /* b */; +var ri6 = E.a ^ a; +var ri7 = E.a ^ b; +var ri8 = E.a ^ E.b; +var ri9 = E.a ^ 1; +var ri10 = a ^ E.b; +var ri11 = b ^ E.b; +var ri12 = 1 ^ E.b; // operator | var rj1 = c | a; var rj2 = c | b; var rj3 = c | c; var rj4 = a | c; var rj5 = b | c; -var rj6 = 0 /* a */ | a; -var rj7 = 0 /* a */ | b; -var rj8 = 0 /* a */ | 1 /* b */; -var rj9 = 0 /* a */ | 1; -var rj10 = a | 1 /* b */; -var rj11 = b | 1 /* b */; -var rj12 = 1 | 1 /* b */; +var rj6 = E.a | a; +var rj7 = E.a | b; +var rj8 = E.a | E.b; +var rj9 = E.a | 1; +var rj10 = a | E.b; +var rj11 = b | E.b; +var rj12 = 1 | E.b; diff --git a/tests/baselines/reference/arithmeticOperatorWithEnumUnion.js b/tests/baselines/reference/arithmeticOperatorWithEnumUnion.js index 315f7dd237b7f..95bc0b866c91c 100644 --- a/tests/baselines/reference/arithmeticOperatorWithEnumUnion.js +++ b/tests/baselines/reference/arithmeticOperatorWithEnumUnion.js @@ -175,127 +175,127 @@ var ra2 = c * b; var ra3 = c * c; var ra4 = a * c; var ra5 = b * c; -var ra6 = 0 /* a */ * a; -var ra7 = 0 /* a */ * b; -var ra8 = 0 /* a */ * 1 /* b */; -var ra9 = 0 /* a */ * 1; -var ra10 = a * 1 /* b */; -var ra11 = b * 1 /* b */; -var ra12 = 1 * 1 /* b */; +var ra6 = E.a * a; +var ra7 = E.a * b; +var ra8 = E.a * E.b; +var ra9 = E.a * 1; +var ra10 = a * E.b; +var ra11 = b * E.b; +var ra12 = 1 * E.b; // operator / var rb1 = c / a; var rb2 = c / b; var rb3 = c / c; var rb4 = a / c; var rb5 = b / c; -var rb6 = 0 /* a */ / a; -var rb7 = 0 /* a */ / b; -var rb8 = 0 /* a */ / 1 /* b */; -var rb9 = 0 /* a */ / 1; -var rb10 = a / 1 /* b */; -var rb11 = b / 1 /* b */; -var rb12 = 1 / 1 /* b */; +var rb6 = E.a / a; +var rb7 = E.a / b; +var rb8 = E.a / E.b; +var rb9 = E.a / 1; +var rb10 = a / E.b; +var rb11 = b / E.b; +var rb12 = 1 / E.b; // operator % var rc1 = c % a; var rc2 = c % b; var rc3 = c % c; var rc4 = a % c; var rc5 = b % c; -var rc6 = 0 /* a */ % a; -var rc7 = 0 /* a */ % b; -var rc8 = 0 /* a */ % 1 /* b */; -var rc9 = 0 /* a */ % 1; -var rc10 = a % 1 /* b */; -var rc11 = b % 1 /* b */; -var rc12 = 1 % 1 /* b */; +var rc6 = E.a % a; +var rc7 = E.a % b; +var rc8 = E.a % E.b; +var rc9 = E.a % 1; +var rc10 = a % E.b; +var rc11 = b % E.b; +var rc12 = 1 % E.b; // operator - var rd1 = c - a; var rd2 = c - b; var rd3 = c - c; var rd4 = a - c; var rd5 = b - c; -var rd6 = 0 /* a */ - a; -var rd7 = 0 /* a */ - b; -var rd8 = 0 /* a */ - 1 /* b */; -var rd9 = 0 /* a */ - 1; -var rd10 = a - 1 /* b */; -var rd11 = b - 1 /* b */; -var rd12 = 1 - 1 /* b */; +var rd6 = E.a - a; +var rd7 = E.a - b; +var rd8 = E.a - E.b; +var rd9 = E.a - 1; +var rd10 = a - E.b; +var rd11 = b - E.b; +var rd12 = 1 - E.b; // operator << var re1 = c << a; var re2 = c << b; var re3 = c << c; var re4 = a << c; var re5 = b << c; -var re6 = 0 /* a */ << a; -var re7 = 0 /* a */ << b; -var re8 = 0 /* a */ << 1 /* b */; -var re9 = 0 /* a */ << 1; -var re10 = a << 1 /* b */; -var re11 = b << 1 /* b */; -var re12 = 1 << 1 /* b */; +var re6 = E.a << a; +var re7 = E.a << b; +var re8 = E.a << E.b; +var re9 = E.a << 1; +var re10 = a << E.b; +var re11 = b << E.b; +var re12 = 1 << E.b; // operator >> var rf1 = c >> a; var rf2 = c >> b; var rf3 = c >> c; var rf4 = a >> c; var rf5 = b >> c; -var rf6 = 0 /* a */ >> a; -var rf7 = 0 /* a */ >> b; -var rf8 = 0 /* a */ >> 1 /* b */; -var rf9 = 0 /* a */ >> 1; -var rf10 = a >> 1 /* b */; -var rf11 = b >> 1 /* b */; -var rf12 = 1 >> 1 /* b */; +var rf6 = E.a >> a; +var rf7 = E.a >> b; +var rf8 = E.a >> E.b; +var rf9 = E.a >> 1; +var rf10 = a >> E.b; +var rf11 = b >> E.b; +var rf12 = 1 >> E.b; // operator >>> var rg1 = c >>> a; var rg2 = c >>> b; var rg3 = c >>> c; var rg4 = a >>> c; var rg5 = b >>> c; -var rg6 = 0 /* a */ >>> a; -var rg7 = 0 /* a */ >>> b; -var rg8 = 0 /* a */ >>> 1 /* b */; -var rg9 = 0 /* a */ >>> 1; -var rg10 = a >>> 1 /* b */; -var rg11 = b >>> 1 /* b */; -var rg12 = 1 >>> 1 /* b */; +var rg6 = E.a >>> a; +var rg7 = E.a >>> b; +var rg8 = E.a >>> E.b; +var rg9 = E.a >>> 1; +var rg10 = a >>> E.b; +var rg11 = b >>> E.b; +var rg12 = 1 >>> E.b; // operator & var rh1 = c & a; var rh2 = c & b; var rh3 = c & c; var rh4 = a & c; var rh5 = b & c; -var rh6 = 0 /* a */ & a; -var rh7 = 0 /* a */ & b; -var rh8 = 0 /* a */ & 1 /* b */; -var rh9 = 0 /* a */ & 1; -var rh10 = a & 1 /* b */; -var rh11 = b & 1 /* b */; -var rh12 = 1 & 1 /* b */; +var rh6 = E.a & a; +var rh7 = E.a & b; +var rh8 = E.a & E.b; +var rh9 = E.a & 1; +var rh10 = a & E.b; +var rh11 = b & E.b; +var rh12 = 1 & E.b; // operator ^ var ri1 = c ^ a; var ri2 = c ^ b; var ri3 = c ^ c; var ri4 = a ^ c; var ri5 = b ^ c; -var ri6 = 0 /* a */ ^ a; -var ri7 = 0 /* a */ ^ b; -var ri8 = 0 /* a */ ^ 1 /* b */; -var ri9 = 0 /* a */ ^ 1; -var ri10 = a ^ 1 /* b */; -var ri11 = b ^ 1 /* b */; -var ri12 = 1 ^ 1 /* b */; +var ri6 = E.a ^ a; +var ri7 = E.a ^ b; +var ri8 = E.a ^ E.b; +var ri9 = E.a ^ 1; +var ri10 = a ^ E.b; +var ri11 = b ^ E.b; +var ri12 = 1 ^ E.b; // operator | var rj1 = c | a; var rj2 = c | b; var rj3 = c | c; var rj4 = a | c; var rj5 = b | c; -var rj6 = 0 /* a */ | a; -var rj7 = 0 /* a */ | b; -var rj8 = 0 /* a */ | 1 /* b */; -var rj9 = 0 /* a */ | 1; -var rj10 = a | 1 /* b */; -var rj11 = b | 1 /* b */; -var rj12 = 1 | 1 /* b */; +var rj6 = E.a | a; +var rj7 = E.a | b; +var rj8 = E.a | E.b; +var rj9 = E.a | 1; +var rj10 = a | E.b; +var rj11 = b | E.b; +var rj12 = 1 | E.b; diff --git a/tests/baselines/reference/arithmeticOperatorWithInvalidOperands.js b/tests/baselines/reference/arithmeticOperatorWithInvalidOperands.js index 8a9e65491446b..974e9930103d7 100644 --- a/tests/baselines/reference/arithmeticOperatorWithInvalidOperands.js +++ b/tests/baselines/reference/arithmeticOperatorWithInvalidOperands.js @@ -634,18 +634,18 @@ var r1f3 = f * c; var r1f4 = f * d; var r1f5 = f * e; var r1f6 = f * f; -var r1g1 = 0 /* a */ * a; //ok -var r1g2 = 0 /* a */ * b; -var r1g3 = 0 /* a */ * c; //ok -var r1g4 = 0 /* a */ * d; -var r1g5 = 0 /* a */ * e; -var r1g6 = 0 /* a */ * f; -var r1h1 = a * 1 /* b */; //ok -var r1h2 = b * 1 /* b */; -var r1h3 = c * 1 /* b */; //ok -var r1h4 = d * 1 /* b */; -var r1h5 = e * 1 /* b */; -var r1h6 = f * 1 /* b */; +var r1g1 = E.a * a; //ok +var r1g2 = E.a * b; +var r1g3 = E.a * c; //ok +var r1g4 = E.a * d; +var r1g5 = E.a * e; +var r1g6 = E.a * f; +var r1h1 = a * E.b; //ok +var r1h2 = b * E.b; +var r1h3 = c * E.b; //ok +var r1h4 = d * E.b; +var r1h5 = e * E.b; +var r1h6 = f * E.b; // operator / var r2a1 = a / a; //ok var r2a2 = a / b; @@ -683,18 +683,18 @@ var r2f3 = f / c; var r2f4 = f / d; var r2f5 = f / e; var r2f6 = f / f; -var r2g1 = 0 /* a */ / a; //ok -var r2g2 = 0 /* a */ / b; -var r2g3 = 0 /* a */ / c; //ok -var r2g4 = 0 /* a */ / d; -var r2g5 = 0 /* a */ / e; -var r2g6 = 0 /* a */ / f; -var r2h1 = a / 1 /* b */; //ok -var r2h2 = b / 1 /* b */; -var r2h3 = c / 1 /* b */; //ok -var r2h4 = d / 1 /* b */; -var r2h5 = e / 1 /* b */; -var r2h6 = f / 1 /* b */; +var r2g1 = E.a / a; //ok +var r2g2 = E.a / b; +var r2g3 = E.a / c; //ok +var r2g4 = E.a / d; +var r2g5 = E.a / e; +var r2g6 = E.a / f; +var r2h1 = a / E.b; //ok +var r2h2 = b / E.b; +var r2h3 = c / E.b; //ok +var r2h4 = d / E.b; +var r2h5 = e / E.b; +var r2h6 = f / E.b; // operator % var r3a1 = a % a; //ok var r3a2 = a % b; @@ -732,18 +732,18 @@ var r3f3 = f % c; var r3f4 = f % d; var r3f5 = f % e; var r3f6 = f % f; -var r3g1 = 0 /* a */ % a; //ok -var r3g2 = 0 /* a */ % b; -var r3g3 = 0 /* a */ % c; //ok -var r3g4 = 0 /* a */ % d; -var r3g5 = 0 /* a */ % e; -var r3g6 = 0 /* a */ % f; -var r3h1 = a % 1 /* b */; //ok -var r3h2 = b % 1 /* b */; -var r3h3 = c % 1 /* b */; //ok -var r3h4 = d % 1 /* b */; -var r3h5 = e % 1 /* b */; -var r3h6 = f % 1 /* b */; +var r3g1 = E.a % a; //ok +var r3g2 = E.a % b; +var r3g3 = E.a % c; //ok +var r3g4 = E.a % d; +var r3g5 = E.a % e; +var r3g6 = E.a % f; +var r3h1 = a % E.b; //ok +var r3h2 = b % E.b; +var r3h3 = c % E.b; //ok +var r3h4 = d % E.b; +var r3h5 = e % E.b; +var r3h6 = f % E.b; // operator - var r4a1 = a - a; //ok var r4a2 = a - b; @@ -781,18 +781,18 @@ var r4f3 = f - c; var r4f4 = f - d; var r4f5 = f - e; var r4f6 = f - f; -var r4g1 = 0 /* a */ - a; //ok -var r4g2 = 0 /* a */ - b; -var r4g3 = 0 /* a */ - c; //ok -var r4g4 = 0 /* a */ - d; -var r4g5 = 0 /* a */ - e; -var r4g6 = 0 /* a */ - f; -var r4h1 = a - 1 /* b */; //ok -var r4h2 = b - 1 /* b */; -var r4h3 = c - 1 /* b */; //ok -var r4h4 = d - 1 /* b */; -var r4h5 = e - 1 /* b */; -var r4h6 = f - 1 /* b */; +var r4g1 = E.a - a; //ok +var r4g2 = E.a - b; +var r4g3 = E.a - c; //ok +var r4g4 = E.a - d; +var r4g5 = E.a - e; +var r4g6 = E.a - f; +var r4h1 = a - E.b; //ok +var r4h2 = b - E.b; +var r4h3 = c - E.b; //ok +var r4h4 = d - E.b; +var r4h5 = e - E.b; +var r4h6 = f - E.b; // operator << var r5a1 = a << a; //ok var r5a2 = a << b; @@ -830,18 +830,18 @@ var r5f3 = f << c; var r5f4 = f << d; var r5f5 = f << e; var r5f6 = f << f; -var r5g1 = 0 /* a */ << a; //ok -var r5g2 = 0 /* a */ << b; -var r5g3 = 0 /* a */ << c; //ok -var r5g4 = 0 /* a */ << d; -var r5g5 = 0 /* a */ << e; -var r5g6 = 0 /* a */ << f; -var r5h1 = a << 1 /* b */; //ok -var r5h2 = b << 1 /* b */; -var r5h3 = c << 1 /* b */; //ok -var r5h4 = d << 1 /* b */; -var r5h5 = e << 1 /* b */; -var r5h6 = f << 1 /* b */; +var r5g1 = E.a << a; //ok +var r5g2 = E.a << b; +var r5g3 = E.a << c; //ok +var r5g4 = E.a << d; +var r5g5 = E.a << e; +var r5g6 = E.a << f; +var r5h1 = a << E.b; //ok +var r5h2 = b << E.b; +var r5h3 = c << E.b; //ok +var r5h4 = d << E.b; +var r5h5 = e << E.b; +var r5h6 = f << E.b; // operator >> var r6a1 = a >> a; //ok var r6a2 = a >> b; @@ -879,18 +879,18 @@ var r6f3 = f >> c; var r6f4 = f >> d; var r6f5 = f >> e; var r6f6 = f >> f; -var r6g1 = 0 /* a */ >> a; //ok -var r6g2 = 0 /* a */ >> b; -var r6g3 = 0 /* a */ >> c; //ok -var r6g4 = 0 /* a */ >> d; -var r6g5 = 0 /* a */ >> e; -var r6g6 = 0 /* a */ >> f; -var r6h1 = a >> 1 /* b */; //ok -var r6h2 = b >> 1 /* b */; -var r6h3 = c >> 1 /* b */; //ok -var r6h4 = d >> 1 /* b */; -var r6h5 = e >> 1 /* b */; -var r6h6 = f >> 1 /* b */; +var r6g1 = E.a >> a; //ok +var r6g2 = E.a >> b; +var r6g3 = E.a >> c; //ok +var r6g4 = E.a >> d; +var r6g5 = E.a >> e; +var r6g6 = E.a >> f; +var r6h1 = a >> E.b; //ok +var r6h2 = b >> E.b; +var r6h3 = c >> E.b; //ok +var r6h4 = d >> E.b; +var r6h5 = e >> E.b; +var r6h6 = f >> E.b; // operator >>> var r7a1 = a >>> a; //ok var r7a2 = a >>> b; @@ -928,18 +928,18 @@ var r7f3 = f >>> c; var r7f4 = f >>> d; var r7f5 = f >>> e; var r7f6 = f >>> f; -var r7g1 = 0 /* a */ >>> a; //ok -var r7g2 = 0 /* a */ >>> b; -var r7g3 = 0 /* a */ >>> c; //ok -var r7g4 = 0 /* a */ >>> d; -var r7g5 = 0 /* a */ >>> e; -var r7g6 = 0 /* a */ >>> f; -var r7h1 = a >>> 1 /* b */; //ok -var r7h2 = b >>> 1 /* b */; -var r7h3 = c >>> 1 /* b */; //ok -var r7h4 = d >>> 1 /* b */; -var r7h5 = e >>> 1 /* b */; -var r7h6 = f >>> 1 /* b */; +var r7g1 = E.a >>> a; //ok +var r7g2 = E.a >>> b; +var r7g3 = E.a >>> c; //ok +var r7g4 = E.a >>> d; +var r7g5 = E.a >>> e; +var r7g6 = E.a >>> f; +var r7h1 = a >>> E.b; //ok +var r7h2 = b >>> E.b; +var r7h3 = c >>> E.b; //ok +var r7h4 = d >>> E.b; +var r7h5 = e >>> E.b; +var r7h6 = f >>> E.b; // operator & var r8a1 = a & a; //ok var r8a2 = a & b; @@ -977,18 +977,18 @@ var r8f3 = f & c; var r8f4 = f & d; var r8f5 = f & e; var r8f6 = f & f; -var r8g1 = 0 /* a */ & a; //ok -var r8g2 = 0 /* a */ & b; -var r8g3 = 0 /* a */ & c; //ok -var r8g4 = 0 /* a */ & d; -var r8g5 = 0 /* a */ & e; -var r8g6 = 0 /* a */ & f; -var r8h1 = a & 1 /* b */; //ok -var r8h2 = b & 1 /* b */; -var r8h3 = c & 1 /* b */; //ok -var r8h4 = d & 1 /* b */; -var r8h5 = e & 1 /* b */; -var r8h6 = f & 1 /* b */; +var r8g1 = E.a & a; //ok +var r8g2 = E.a & b; +var r8g3 = E.a & c; //ok +var r8g4 = E.a & d; +var r8g5 = E.a & e; +var r8g6 = E.a & f; +var r8h1 = a & E.b; //ok +var r8h2 = b & E.b; +var r8h3 = c & E.b; //ok +var r8h4 = d & E.b; +var r8h5 = e & E.b; +var r8h6 = f & E.b; // operator ^ var r9a1 = a ^ a; //ok var r9a2 = a ^ b; @@ -1026,18 +1026,18 @@ var r9f3 = f ^ c; var r9f4 = f ^ d; var r9f5 = f ^ e; var r9f6 = f ^ f; -var r9g1 = 0 /* a */ ^ a; //ok -var r9g2 = 0 /* a */ ^ b; -var r9g3 = 0 /* a */ ^ c; //ok -var r9g4 = 0 /* a */ ^ d; -var r9g5 = 0 /* a */ ^ e; -var r9g6 = 0 /* a */ ^ f; -var r9h1 = a ^ 1 /* b */; //ok -var r9h2 = b ^ 1 /* b */; -var r9h3 = c ^ 1 /* b */; //ok -var r9h4 = d ^ 1 /* b */; -var r9h5 = e ^ 1 /* b */; -var r9h6 = f ^ 1 /* b */; +var r9g1 = E.a ^ a; //ok +var r9g2 = E.a ^ b; +var r9g3 = E.a ^ c; //ok +var r9g4 = E.a ^ d; +var r9g5 = E.a ^ e; +var r9g6 = E.a ^ f; +var r9h1 = a ^ E.b; //ok +var r9h2 = b ^ E.b; +var r9h3 = c ^ E.b; //ok +var r9h4 = d ^ E.b; +var r9h5 = e ^ E.b; +var r9h6 = f ^ E.b; // operator | var r10a1 = a | a; //ok var r10a2 = a | b; @@ -1075,15 +1075,15 @@ var r10f3 = f | c; var r10f4 = f | d; var r10f5 = f | e; var r10f6 = f | f; -var r10g1 = 0 /* a */ | a; //ok -var r10g2 = 0 /* a */ | b; -var r10g3 = 0 /* a */ | c; //ok -var r10g4 = 0 /* a */ | d; -var r10g5 = 0 /* a */ | e; -var r10g6 = 0 /* a */ | f; -var r10h1 = a | 1 /* b */; //ok -var r10h2 = b | 1 /* b */; -var r10h3 = c | 1 /* b */; //ok -var r10h4 = d | 1 /* b */; -var r10h5 = e | 1 /* b */; -var r10h6 = f | 1 /* b */; +var r10g1 = E.a | a; //ok +var r10g2 = E.a | b; +var r10g3 = E.a | c; //ok +var r10g4 = E.a | d; +var r10g5 = E.a | e; +var r10g6 = E.a | f; +var r10h1 = a | E.b; //ok +var r10h2 = b | E.b; +var r10h3 = c | E.b; //ok +var r10h4 = d | E.b; +var r10h5 = e | E.b; +var r10h6 = f | E.b; diff --git a/tests/baselines/reference/arithmeticOperatorWithNullValueAndValidOperands.js b/tests/baselines/reference/arithmeticOperatorWithNullValueAndValidOperands.js index 40676ef449586..0c30e8d048492 100644 --- a/tests/baselines/reference/arithmeticOperatorWithNullValueAndValidOperands.js +++ b/tests/baselines/reference/arithmeticOperatorWithNullValueAndValidOperands.js @@ -124,89 +124,89 @@ var b; var ra1 = null * a; var ra2 = null * b; var ra3 = null * 1; -var ra4 = null * 0 /* a */; +var ra4 = null * E.a; var ra5 = a * null; var ra6 = b * null; var ra7 = 0 * null; -var ra8 = 1 /* b */ * null; +var ra8 = E.b * null; // operator / var rb1 = null / a; var rb2 = null / b; var rb3 = null / 1; -var rb4 = null / 0 /* a */; +var rb4 = null / E.a; var rb5 = a / null; var rb6 = b / null; var rb7 = 0 / null; -var rb8 = 1 /* b */ / null; +var rb8 = E.b / null; // operator % var rc1 = null % a; var rc2 = null % b; var rc3 = null % 1; -var rc4 = null % 0 /* a */; +var rc4 = null % E.a; var rc5 = a % null; var rc6 = b % null; var rc7 = 0 % null; -var rc8 = 1 /* b */ % null; +var rc8 = E.b % null; // operator - var rd1 = null - a; var rd2 = null - b; var rd3 = null - 1; -var rd4 = null - 0 /* a */; +var rd4 = null - E.a; var rd5 = a - null; var rd6 = b - null; var rd7 = 0 - null; -var rd8 = 1 /* b */ - null; +var rd8 = E.b - null; // operator << var re1 = null << a; var re2 = null << b; var re3 = null << 1; -var re4 = null << 0 /* a */; +var re4 = null << E.a; var re5 = a << null; var re6 = b << null; var re7 = 0 << null; -var re8 = 1 /* b */ << null; +var re8 = E.b << null; // operator >> var rf1 = null >> a; var rf2 = null >> b; var rf3 = null >> 1; -var rf4 = null >> 0 /* a */; +var rf4 = null >> E.a; var rf5 = a >> null; var rf6 = b >> null; var rf7 = 0 >> null; -var rf8 = 1 /* b */ >> null; +var rf8 = E.b >> null; // operator >>> var rg1 = null >>> a; var rg2 = null >>> b; var rg3 = null >>> 1; -var rg4 = null >>> 0 /* a */; +var rg4 = null >>> E.a; var rg5 = a >>> null; var rg6 = b >>> null; var rg7 = 0 >>> null; -var rg8 = 1 /* b */ >>> null; +var rg8 = E.b >>> null; // operator & var rh1 = null & a; var rh2 = null & b; var rh3 = null & 1; -var rh4 = null & 0 /* a */; +var rh4 = null & E.a; var rh5 = a & null; var rh6 = b & null; var rh7 = 0 & null; -var rh8 = 1 /* b */ & null; +var rh8 = E.b & null; // operator ^ var ri1 = null ^ a; var ri2 = null ^ b; var ri3 = null ^ 1; -var ri4 = null ^ 0 /* a */; +var ri4 = null ^ E.a; var ri5 = a ^ null; var ri6 = b ^ null; var ri7 = 0 ^ null; -var ri8 = 1 /* b */ ^ null; +var ri8 = E.b ^ null; // operator | var rj1 = null | a; var rj2 = null | b; var rj3 = null | 1; -var rj4 = null | 0 /* a */; +var rj4 = null | E.a; var rj5 = a | null; var rj6 = b | null; var rj7 = 0 | null; -var rj8 = 1 /* b */ | null; +var rj8 = E.b | null; diff --git a/tests/baselines/reference/arithmeticOperatorWithUndefinedValueAndValidOperands.js b/tests/baselines/reference/arithmeticOperatorWithUndefinedValueAndValidOperands.js index ddc2c87dd7a60..60ea9af32c2b5 100644 --- a/tests/baselines/reference/arithmeticOperatorWithUndefinedValueAndValidOperands.js +++ b/tests/baselines/reference/arithmeticOperatorWithUndefinedValueAndValidOperands.js @@ -124,89 +124,89 @@ var b; var ra1 = undefined * a; var ra2 = undefined * b; var ra3 = undefined * 1; -var ra4 = undefined * 0 /* a */; +var ra4 = undefined * E.a; var ra5 = a * undefined; var ra6 = b * undefined; var ra7 = 0 * undefined; -var ra8 = 1 /* b */ * undefined; +var ra8 = E.b * undefined; // operator / var rb1 = undefined / a; var rb2 = undefined / b; var rb3 = undefined / 1; -var rb4 = undefined / 0 /* a */; +var rb4 = undefined / E.a; var rb5 = a / undefined; var rb6 = b / undefined; var rb7 = 0 / undefined; -var rb8 = 1 /* b */ / undefined; +var rb8 = E.b / undefined; // operator % var rc1 = undefined % a; var rc2 = undefined % b; var rc3 = undefined % 1; -var rc4 = undefined % 0 /* a */; +var rc4 = undefined % E.a; var rc5 = a % undefined; var rc6 = b % undefined; var rc7 = 0 % undefined; -var rc8 = 1 /* b */ % undefined; +var rc8 = E.b % undefined; // operator - var rd1 = undefined - a; var rd2 = undefined - b; var rd3 = undefined - 1; -var rd4 = undefined - 0 /* a */; +var rd4 = undefined - E.a; var rd5 = a - undefined; var rd6 = b - undefined; var rd7 = 0 - undefined; -var rd8 = 1 /* b */ - undefined; +var rd8 = E.b - undefined; // operator << var re1 = undefined << a; var re2 = undefined << b; var re3 = undefined << 1; -var re4 = undefined << 0 /* a */; +var re4 = undefined << E.a; var re5 = a << undefined; var re6 = b << undefined; var re7 = 0 << undefined; -var re8 = 1 /* b */ << undefined; +var re8 = E.b << undefined; // operator >> var rf1 = undefined >> a; var rf2 = undefined >> b; var rf3 = undefined >> 1; -var rf4 = undefined >> 0 /* a */; +var rf4 = undefined >> E.a; var rf5 = a >> undefined; var rf6 = b >> undefined; var rf7 = 0 >> undefined; -var rf8 = 1 /* b */ >> undefined; +var rf8 = E.b >> undefined; // operator >>> var rg1 = undefined >>> a; var rg2 = undefined >>> b; var rg3 = undefined >>> 1; -var rg4 = undefined >>> 0 /* a */; +var rg4 = undefined >>> E.a; var rg5 = a >>> undefined; var rg6 = b >>> undefined; var rg7 = 0 >>> undefined; -var rg8 = 1 /* b */ >>> undefined; +var rg8 = E.b >>> undefined; // operator & var rh1 = undefined & a; var rh2 = undefined & b; var rh3 = undefined & 1; -var rh4 = undefined & 0 /* a */; +var rh4 = undefined & E.a; var rh5 = a & undefined; var rh6 = b & undefined; var rh7 = 0 & undefined; -var rh8 = 1 /* b */ & undefined; +var rh8 = E.b & undefined; // operator ^ var ri1 = undefined ^ a; var ri2 = undefined ^ b; var ri3 = undefined ^ 1; -var ri4 = undefined ^ 0 /* a */; +var ri4 = undefined ^ E.a; var ri5 = a ^ undefined; var ri6 = b ^ undefined; var ri7 = 0 ^ undefined; -var ri8 = 1 /* b */ ^ undefined; +var ri8 = E.b ^ undefined; // operator | var rj1 = undefined | a; var rj2 = undefined | b; var rj3 = undefined | 1; -var rj4 = undefined | 0 /* a */; +var rj4 = undefined | E.a; var rj5 = a | undefined; var rj6 = b | undefined; var rj7 = 0 | undefined; -var rj8 = 1 /* b */ | undefined; +var rj8 = E.b | undefined; diff --git a/tests/baselines/reference/assignAnyToEveryType.js b/tests/baselines/reference/assignAnyToEveryType.js index 47093cd085290..94b8067ddd786 100644 --- a/tests/baselines/reference/assignAnyToEveryType.js +++ b/tests/baselines/reference/assignAnyToEveryType.js @@ -61,7 +61,7 @@ var E; E[E["A"] = 0] = "A"; })(E || (E = {})); var g = x; -var g2 = 0 /* A */; +var g2 = E.A; g2 = x; var C = (function () { function C() { diff --git a/tests/baselines/reference/assignEveryTypeToAny.js b/tests/baselines/reference/assignEveryTypeToAny.js index 15aa6bcdd91e2..bbe622b33005c 100644 --- a/tests/baselines/reference/assignEveryTypeToAny.js +++ b/tests/baselines/reference/assignEveryTypeToAny.js @@ -77,8 +77,8 @@ var E; (function (E) { E[E["A"] = 0] = "A"; })(E || (E = {})); -x = 0 /* A */; -var f = 0 /* A */; +x = E.A; +var f = E.A; x = f; var g; x = g; diff --git a/tests/baselines/reference/assignToEnum.js b/tests/baselines/reference/assignToEnum.js index 153068738d197..5f7048894fa32 100644 --- a/tests/baselines/reference/assignToEnum.js +++ b/tests/baselines/reference/assignToEnum.js @@ -14,6 +14,6 @@ var A; A[A["bar"] = 1] = "bar"; })(A || (A = {})); A = undefined; // invalid LHS -A = 1 /* bar */; // invalid LHS -0 /* foo */ = 1; // invalid LHS -0 /* foo */ = 1 /* bar */; // invalid LHS +A = A.bar; // invalid LHS +A.foo = 1; // invalid LHS +A.foo = A.bar; // invalid LHS diff --git a/tests/baselines/reference/assignments.js b/tests/baselines/reference/assignments.js index 363d2f2a017c0..e2c9c90d3757a 100644 --- a/tests/baselines/reference/assignments.js +++ b/tests/baselines/reference/assignments.js @@ -52,7 +52,7 @@ var E; E[E["A"] = 0] = "A"; })(E || (E = {})); E = null; // Error -0 /* A */ = null; // OK per spec, Error per implementation (509581) +E.A = null; // OK per spec, Error per implementation (509581) function fn() { } fn = null; // Should be error var v; diff --git a/tests/baselines/reference/bestCommonTypeOfTuple.js b/tests/baselines/reference/bestCommonTypeOfTuple.js index f78f8990db04c..81cfa752f5de5 100644 --- a/tests/baselines/reference/bestCommonTypeOfTuple.js +++ b/tests/baselines/reference/bestCommonTypeOfTuple.js @@ -43,9 +43,9 @@ var t3; var t4; // no error t1 = [f1, f2]; -t2 = [0 /* one */, 0 /* two */]; +t2 = [E1.one, E2.two]; t3 = [5, undefined]; -t4 = [0 /* one */, 0 /* two */, 20]; +t4 = [E1.one, E2.two, 20]; var e1 = t1[2]; // {} var e2 = t2[2]; // {} var e3 = t3[2]; // any diff --git a/tests/baselines/reference/bitwiseNotOperatorWithEnumType.js b/tests/baselines/reference/bitwiseNotOperatorWithEnumType.js index 710af4edfa779..0bcf2fa39569b 100644 --- a/tests/baselines/reference/bitwiseNotOperatorWithEnumType.js +++ b/tests/baselines/reference/bitwiseNotOperatorWithEnumType.js @@ -30,11 +30,11 @@ var ENUM1; // enum type var var ResultIsNumber1 = ~ENUM1; // enum type expressions -var ResultIsNumber2 = ~0 /* "A" */; -var ResultIsNumber3 = ~(0 /* A */ + 1 /* "B" */); +var ResultIsNumber2 = ~ENUM1["A"]; +var ResultIsNumber3 = ~(ENUM1.A + ENUM1["B"]); // multiple ~ operators -var ResultIsNumber4 = ~~~(0 /* "A" */ + 1 /* B */); +var ResultIsNumber4 = ~~~(ENUM1["A"] + ENUM1.B); // miss assignment operators ~ENUM1; -~0 /* "A" */; -~0 /* A */, ~1 /* "B" */; +~ENUM1["A"]; +~ENUM1.A, ~ENUM1["B"]; diff --git a/tests/baselines/reference/castingTuple.js b/tests/baselines/reference/castingTuple.js index fffadcbc070ba..2c41d81cd6a42 100644 --- a/tests/baselines/reference/castingTuple.js +++ b/tests/baselines/reference/castingTuple.js @@ -90,7 +90,7 @@ var interfaceIITuple = classCDTuple; var classCDATuple = classCDTuple; var eleFromCDA1 = classCDATuple[2]; // A var eleFromCDA2 = classCDATuple[5]; // C | D | A -var t10 = [0 /* one */, 0 /* one */]; +var t10 = [E1.one, E2.one]; var t11 = t10; var array1 = emptyObjTuple; var unionTuple = [new C(), "foo"]; diff --git a/tests/baselines/reference/collisionCodeGenEnumWithEnumMemberConflict.js b/tests/baselines/reference/collisionCodeGenEnumWithEnumMemberConflict.js index 454fddf6fa87c..1e56eb8bd9f3d 100644 --- a/tests/baselines/reference/collisionCodeGenEnumWithEnumMemberConflict.js +++ b/tests/baselines/reference/collisionCodeGenEnumWithEnumMemberConflict.js @@ -8,5 +8,5 @@ enum Color { var Color; (function (Color) { Color[Color["Color"] = 0] = "Color"; - Color[Color["Thing"] = Color.Color] = "Thing"; + Color[Color["Thing"] = 0] = "Thing"; })(Color || (Color = {})); diff --git a/tests/baselines/reference/collisionCodeGenModuleWithEnumMemberConflict.js b/tests/baselines/reference/collisionCodeGenModuleWithEnumMemberConflict.js index 0dc8e508d45ca..3662f5d6ddd44 100644 --- a/tests/baselines/reference/collisionCodeGenModuleWithEnumMemberConflict.js +++ b/tests/baselines/reference/collisionCodeGenModuleWithEnumMemberConflict.js @@ -12,6 +12,6 @@ var m1; var e; (function (e) { e[e["m1"] = 0] = "m1"; - e[e["m2"] = e.m1] = "m2"; + e[e["m2"] = 0] = "m2"; })(e || (e = {})); })(m1 || (m1 = {})); diff --git a/tests/baselines/reference/commentsEnums.js b/tests/baselines/reference/commentsEnums.js index c8bba8a4f776d..7be17f085b0ac 100644 --- a/tests/baselines/reference/commentsEnums.js +++ b/tests/baselines/reference/commentsEnums.js @@ -21,8 +21,8 @@ var Colors; /** Fancy name for 'pink'*/ Colors[Colors["FancyPink"] = 1] = "FancyPink"; })(Colors || (Colors = {})); // trailing comment -var x = 0 /* Cornflower */; -x = 1 /* FancyPink */; +var x = Colors.Cornflower; +x = Colors.FancyPink; //// [commentsEnums.d.ts] diff --git a/tests/baselines/reference/comparisonOperatorWithSubtypeEnumAndNumber.js b/tests/baselines/reference/comparisonOperatorWithSubtypeEnumAndNumber.js index e0c1f33cb4ada..fc0323a89aa08 100644 --- a/tests/baselines/reference/comparisonOperatorWithSubtypeEnumAndNumber.js +++ b/tests/baselines/reference/comparisonOperatorWithSubtypeEnumAndNumber.js @@ -80,56 +80,56 @@ var b; // operator < var ra1 = a < b; var ra2 = b < a; -var ra3 = 0 /* a */ < b; -var ra4 = b < 0 /* a */; -var ra5 = 0 /* a */ < 0; -var ra6 = 0 < 0 /* a */; +var ra3 = E.a < b; +var ra4 = b < E.a; +var ra5 = E.a < 0; +var ra6 = 0 < E.a; // operator > var rb1 = a > b; var rb2 = b > a; -var rb3 = 0 /* a */ > b; -var rb4 = b > 0 /* a */; -var rb5 = 0 /* a */ > 0; -var rb6 = 0 > 0 /* a */; +var rb3 = E.a > b; +var rb4 = b > E.a; +var rb5 = E.a > 0; +var rb6 = 0 > E.a; // operator <= var rc1 = a <= b; var rc2 = b <= a; -var rc3 = 0 /* a */ <= b; -var rc4 = b <= 0 /* a */; -var rc5 = 0 /* a */ <= 0; -var rc6 = 0 <= 0 /* a */; +var rc3 = E.a <= b; +var rc4 = b <= E.a; +var rc5 = E.a <= 0; +var rc6 = 0 <= E.a; // operator >= var rd1 = a >= b; var rd2 = b >= a; -var rd3 = 0 /* a */ >= b; -var rd4 = b >= 0 /* a */; -var rd5 = 0 /* a */ >= 0; -var rd6 = 0 >= 0 /* a */; +var rd3 = E.a >= b; +var rd4 = b >= E.a; +var rd5 = E.a >= 0; +var rd6 = 0 >= E.a; // operator == var re1 = a == b; var re2 = b == a; -var re3 = 0 /* a */ == b; -var re4 = b == 0 /* a */; -var re5 = 0 /* a */ == 0; -var re6 = 0 == 0 /* a */; +var re3 = E.a == b; +var re4 = b == E.a; +var re5 = E.a == 0; +var re6 = 0 == E.a; // operator != var rf1 = a != b; var rf2 = b != a; -var rf3 = 0 /* a */ != b; -var rf4 = b != 0 /* a */; -var rf5 = 0 /* a */ != 0; -var rf6 = 0 != 0 /* a */; +var rf3 = E.a != b; +var rf4 = b != E.a; +var rf5 = E.a != 0; +var rf6 = 0 != E.a; // operator === var rg1 = a === b; var rg2 = b === a; -var rg3 = 0 /* a */ === b; -var rg4 = b === 0 /* a */; -var rg5 = 0 /* a */ === 0; -var rg6 = 0 === 0 /* a */; +var rg3 = E.a === b; +var rg4 = b === E.a; +var rg5 = E.a === 0; +var rg6 = 0 === E.a; // operator !== var rh1 = a !== b; var rh2 = b !== a; -var rh3 = 0 /* a */ !== b; -var rh4 = b !== 0 /* a */; -var rh5 = 0 /* a */ !== 0; -var rh6 = 0 !== 0 /* a */; +var rh3 = E.a !== b; +var rh4 = b !== E.a; +var rh5 = E.a !== 0; +var rh6 = 0 !== E.a; diff --git a/tests/baselines/reference/compoundAdditionAssignmentLHSCanBeAssigned.js b/tests/baselines/reference/compoundAdditionAssignmentLHSCanBeAssigned.js index aebacb8882780..ae53d0641783a 100644 --- a/tests/baselines/reference/compoundAdditionAssignmentLHSCanBeAssigned.js +++ b/tests/baselines/reference/compoundAdditionAssignmentLHSCanBeAssigned.js @@ -64,7 +64,7 @@ x1 += b; x1 += true; x1 += 0; x1 += ''; -x1 += 0 /* a */; +x1 += E.a; x1 += {}; x1 += null; x1 += undefined; @@ -74,20 +74,20 @@ x2 += b; x2 += true; x2 += 0; x2 += ''; -x2 += 0 /* a */; +x2 += E.a; x2 += {}; x2 += null; x2 += undefined; var x3; x3 += a; x3 += 0; -x3 += 0 /* a */; +x3 += E.a; x3 += null; x3 += undefined; var x4; x4 += a; x4 += 0; -x4 += 0 /* a */; +x4 += E.a; x4 += null; x4 += undefined; var x5; diff --git a/tests/baselines/reference/compoundAdditionAssignmentWithInvalidOperands.js b/tests/baselines/reference/compoundAdditionAssignmentWithInvalidOperands.js index af4f1bc152193..cef1d3e424e97 100644 --- a/tests/baselines/reference/compoundAdditionAssignmentWithInvalidOperands.js +++ b/tests/baselines/reference/compoundAdditionAssignmentWithInvalidOperands.js @@ -51,7 +51,7 @@ var x1; x1 += a; x1 += true; x1 += 0; -x1 += 0 /* a */; +x1 += E.a; x1 += {}; x1 += null; x1 += undefined; @@ -59,7 +59,7 @@ var x2; x2 += a; x2 += true; x2 += 0; -x2 += 0 /* a */; +x2 += E.a; x2 += {}; x2 += null; x2 += undefined; @@ -67,7 +67,7 @@ var x3; x3 += a; x3 += true; x3 += 0; -x3 += 0 /* a */; +x3 += E.a; x3 += {}; x3 += null; x3 += undefined; diff --git a/tests/baselines/reference/compoundArithmeticAssignmentWithInvalidOperands.js b/tests/baselines/reference/compoundArithmeticAssignmentWithInvalidOperands.js index 61722df0fb043..5c71f717bb237 100644 --- a/tests/baselines/reference/compoundArithmeticAssignmentWithInvalidOperands.js +++ b/tests/baselines/reference/compoundArithmeticAssignmentWithInvalidOperands.js @@ -74,7 +74,7 @@ x1 *= b; x1 *= true; x1 *= 0; x1 *= ''; -x1 *= 0 /* a */; +x1 *= E.a; x1 *= {}; x1 *= null; x1 *= undefined; @@ -84,7 +84,7 @@ x2 *= b; x2 *= true; x2 *= 0; x2 *= ''; -x2 *= 0 /* a */; +x2 *= E.a; x2 *= {}; x2 *= null; x2 *= undefined; @@ -94,7 +94,7 @@ x3 *= b; x3 *= true; x3 *= 0; x3 *= ''; -x3 *= 0 /* a */; +x3 *= E.a; x3 *= {}; x3 *= null; x3 *= undefined; @@ -104,7 +104,7 @@ x4 *= b; x4 *= true; x4 *= 0; x4 *= ''; -x4 *= 0 /* a */; +x4 *= E.a; x4 *= {}; x4 *= null; x4 *= undefined; diff --git a/tests/baselines/reference/computedPropertyNames47_ES5.js b/tests/baselines/reference/computedPropertyNames47_ES5.js index 7d839e16ffb7d..a2fff2110b49f 100644 --- a/tests/baselines/reference/computedPropertyNames47_ES5.js +++ b/tests/baselines/reference/computedPropertyNames47_ES5.js @@ -15,6 +15,6 @@ var E2; E2[E2["x"] = 0] = "x"; })(E2 || (E2 = {})); var o = (_a = {}, - _a[0 /* x */ || 0 /* x */] = 0, + _a[E1.x || E2.x] = 0, _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNames47_ES6.js b/tests/baselines/reference/computedPropertyNames47_ES6.js index e104d33e7d37c..0b6cb352999c3 100644 --- a/tests/baselines/reference/computedPropertyNames47_ES6.js +++ b/tests/baselines/reference/computedPropertyNames47_ES6.js @@ -15,5 +15,5 @@ var E2; E2[E2["x"] = 0] = "x"; })(E2 || (E2 = {})); var o = { - [0 /* x */ || 0 /* x */]: 0 + [E1.x || E2.x]: 0 }; diff --git a/tests/baselines/reference/computedPropertyNames48_ES5.js b/tests/baselines/reference/computedPropertyNames48_ES5.js index c5ca0d5b241a2..55b08ef8301d3 100644 --- a/tests/baselines/reference/computedPropertyNames48_ES5.js +++ b/tests/baselines/reference/computedPropertyNames48_ES5.js @@ -27,7 +27,7 @@ extractIndexer((_a = {}, _a[a] = "", _a)); // Should return string extractIndexer((_b = {}, - _b[0 /* x */] = "", + _b[E.x] = "", _b)); // Should return string extractIndexer((_c = {}, _c["" || 0] = "", diff --git a/tests/baselines/reference/computedPropertyNames48_ES6.js b/tests/baselines/reference/computedPropertyNames48_ES6.js index 2782164756580..8e54d67238c21 100644 --- a/tests/baselines/reference/computedPropertyNames48_ES6.js +++ b/tests/baselines/reference/computedPropertyNames48_ES6.js @@ -27,7 +27,7 @@ extractIndexer({ [a]: "" }); // Should return string extractIndexer({ - [0 /* x */]: "" + [E.x]: "" }); // Should return string extractIndexer({ ["" || 0]: "" diff --git a/tests/baselines/reference/computedPropertyNames7_ES5.js b/tests/baselines/reference/computedPropertyNames7_ES5.js index 9c23dcab20d04..01cf2efc030b8 100644 --- a/tests/baselines/reference/computedPropertyNames7_ES5.js +++ b/tests/baselines/reference/computedPropertyNames7_ES5.js @@ -12,6 +12,6 @@ var E; E[E["member"] = 0] = "member"; })(E || (E = {})); var v = (_a = {}, - _a[0 /* member */] = 0, + _a[E.member] = 0, _a); var _a; diff --git a/tests/baselines/reference/computedPropertyNames7_ES6.js b/tests/baselines/reference/computedPropertyNames7_ES6.js index 5714fb747a6a3..ee1e1c85c06a8 100644 --- a/tests/baselines/reference/computedPropertyNames7_ES6.js +++ b/tests/baselines/reference/computedPropertyNames7_ES6.js @@ -12,5 +12,5 @@ var E; E[E["member"] = 0] = "member"; })(E || (E = {})); var v = { - [0 /* member */]: 0 + [E.member]: 0 }; diff --git a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.js b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.js index ac77cc177b869..1276763505e21 100644 --- a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.js +++ b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.js @@ -365,7 +365,7 @@ var BasicFeatures = (function () { var quoted = '"', quoted2 = "'"; var reg = /\w*/; var objLit = { "var": number = 42, equals: function (x) { return x["var"] === 42; }, instanceof: function () { return 'objLit{42}'; } }; - var weekday = 0 /* Monday */; + var weekday = Weekdays.Monday; var con = char + f + hexchar + float.toString() + float2.toString() + reg.toString() + objLit + weekday; // var any = 0 ^= diff --git a/tests/baselines/reference/declFileEnums.js b/tests/baselines/reference/declFileEnums.js index 97559f05574bc..34f1e386a964a 100644 --- a/tests/baselines/reference/declFileEnums.js +++ b/tests/baselines/reference/declFileEnums.js @@ -46,14 +46,14 @@ var e1; var e2; (function (e2) { e2[e2["a"] = 10] = "a"; - e2[e2["b"] = e2.a + 2] = "b"; + e2[e2["b"] = 12] = "b"; e2[e2["c"] = 10] = "c"; })(e2 || (e2 = {})); var e3; (function (e3) { e3[e3["a"] = 10] = "a"; e3[e3["b"] = Math.PI] = "b"; - e3[e3["c"] = e3.a + 3] = "c"; + e3[e3["c"] = 13] = "c"; })(e3 || (e3 = {})); var e4; (function (e4) { @@ -80,13 +80,13 @@ declare enum e1 { } declare enum e2 { a = 10, - b, + b = 12, c = 10, } declare enum e3 { a = 10, b, - c, + c = 13, } declare enum e4 { a = 0, diff --git a/tests/baselines/reference/declFileTypeofEnum.js b/tests/baselines/reference/declFileTypeofEnum.js index 8ced6f9e59554..5b1c697747230 100644 --- a/tests/baselines/reference/declFileTypeofEnum.js +++ b/tests/baselines/reference/declFileTypeofEnum.js @@ -25,7 +25,7 @@ var days; days[days["saturday"] = 5] = "saturday"; days[days["sunday"] = 6] = "sunday"; })(days || (days = {})); -var weekendDay = 5 /* saturday */; +var weekendDay = days.saturday; var daysOfMonth = days; var daysOfYear; diff --git a/tests/baselines/reference/declFileTypeofInAnonymousType.js b/tests/baselines/reference/declFileTypeofInAnonymousType.js index 2210f189d166e..01025ed180620 100644 --- a/tests/baselines/reference/declFileTypeofInAnonymousType.js +++ b/tests/baselines/reference/declFileTypeofInAnonymousType.js @@ -48,7 +48,7 @@ var d = { m: { mod: m1 }, mc: { cl: m1.c }, me: { en: m1.e }, - mh: 2 /* holiday */ + mh: m1.e.holiday }; diff --git a/tests/baselines/reference/decrementOperatorWithEnumType.js b/tests/baselines/reference/decrementOperatorWithEnumType.js index 15247ea4225b6..27cb376cc05d9 100644 --- a/tests/baselines/reference/decrementOperatorWithEnumType.js +++ b/tests/baselines/reference/decrementOperatorWithEnumType.js @@ -22,8 +22,8 @@ var ENUM1; })(ENUM1 || (ENUM1 = {})); ; // expression -var ResultIsNumber1 = --0 /* "A" */; -var ResultIsNumber2 = 0 /* A */--; +var ResultIsNumber1 = --ENUM1["A"]; +var ResultIsNumber2 = ENUM1.A--; // miss assignment operator ---0 /* "A" */; +--ENUM1["A"]; ENUM1[A]--; diff --git a/tests/baselines/reference/deleteOperatorWithEnumType.js b/tests/baselines/reference/deleteOperatorWithEnumType.js index b87ab8298a725..0a17b300d3d80 100644 --- a/tests/baselines/reference/deleteOperatorWithEnumType.js +++ b/tests/baselines/reference/deleteOperatorWithEnumType.js @@ -39,13 +39,13 @@ var ENUM1; var ResultIsBoolean1 = delete ENUM; var ResultIsBoolean2 = delete ENUM1; // enum type expressions -var ResultIsBoolean3 = delete 0 /* "A" */; -var ResultIsBoolean4 = delete (ENUM[0] + 1 /* "B" */); +var ResultIsBoolean3 = delete ENUM1["A"]; +var ResultIsBoolean4 = delete (ENUM[0] + ENUM1["B"]); // multiple delete operators var ResultIsBoolean5 = delete delete ENUM; -var ResultIsBoolean6 = delete delete delete (ENUM[0] + 1 /* "B" */); +var ResultIsBoolean6 = delete delete delete (ENUM[0] + ENUM1["B"]); // miss assignment operators delete ENUM; delete ENUM1; -delete 1 /* B */; +delete ENUM1.B; delete ENUM, ENUM1; diff --git a/tests/baselines/reference/duplicateLocalVariable4.js b/tests/baselines/reference/duplicateLocalVariable4.js index d7d67f28d5099..34fe30a1f1c12 100644 --- a/tests/baselines/reference/duplicateLocalVariable4.js +++ b/tests/baselines/reference/duplicateLocalVariable4.js @@ -12,4 +12,4 @@ var E; E[E["a"] = 0] = "a"; })(E || (E = {})); var x = E; -var x = 0 /* a */; +var x = E.a; diff --git a/tests/baselines/reference/enumAssignability.js b/tests/baselines/reference/enumAssignability.js index 874c177c4e6cd..5bf639d9cf1ad 100644 --- a/tests/baselines/reference/enumAssignability.js +++ b/tests/baselines/reference/enumAssignability.js @@ -64,8 +64,8 @@ var F; (function (F) { F[F["B"] = 0] = "B"; })(F || (F = {})); -var e = 0 /* A */; -var f = 0 /* B */; +var e = E.A; +var f = F.B; e = f; f = e; e = 1; // ok diff --git a/tests/baselines/reference/enumAssignabilityInInheritance.js b/tests/baselines/reference/enumAssignabilityInInheritance.js index a26bd0670f865..0143985425961 100644 --- a/tests/baselines/reference/enumAssignabilityInInheritance.js +++ b/tests/baselines/reference/enumAssignabilityInInheritance.js @@ -115,41 +115,41 @@ var E; (function (E) { E[E["A"] = 0] = "A"; })(E || (E = {})); -var r = foo(0 /* A */); // E +var r = foo(E.A); // E var r2 = foo(1); // number var r3 = foo(null); // any -var r4 = foo2(0 /* A */); -var r4 = foo3(0 /* A */); -var r4 = foo4(0 /* A */); -var r4 = foo5(0 /* A */); -var r4 = foo6(0 /* A */); -var r4 = foo7(0 /* A */); -var r4 = foo8(0 /* A */); +var r4 = foo2(E.A); +var r4 = foo3(E.A); +var r4 = foo4(E.A); +var r4 = foo5(E.A); +var r4 = foo6(E.A); +var r4 = foo7(E.A); +var r4 = foo8(E.A); var A = (function () { function A() { } return A; })(); -var r4 = foo9(0 /* A */); +var r4 = foo9(E.A); var A2 = (function () { function A2() { } return A2; })(); -var r4 = foo10(0 /* A */); -var r4 = foo11(0 /* A */); -var r4 = foo12(0 /* A */); +var r4 = foo10(E.A); +var r4 = foo11(E.A); +var r4 = foo12(E.A); var E2; (function (E2) { E2[E2["A"] = 0] = "A"; })(E2 || (E2 = {})); -var r4 = foo13(0 /* A */); +var r4 = foo13(E.A); function f() { } var f; (function (f) { f.bar = 1; })(f || (f = {})); -var r4 = foo14(0 /* A */); +var r4 = foo14(E.A); var CC = (function () { function CC() { } @@ -159,6 +159,6 @@ var CC; (function (CC) { CC.bar = 1; })(CC || (CC = {})); -var r4 = foo15(0 /* A */); -var r4 = foo16(0 /* A */); -var r4 = foo16(0 /* A */); +var r4 = foo15(E.A); +var r4 = foo16(E.A); +var r4 = foo16(E.A); diff --git a/tests/baselines/reference/enumAssignmentCompat.js b/tests/baselines/reference/enumAssignmentCompat.js index 24f65bc96a96f..f56b1f300ed53 100644 --- a/tests/baselines/reference/enumAssignmentCompat.js +++ b/tests/baselines/reference/enumAssignmentCompat.js @@ -57,15 +57,15 @@ var W; var x = W; var y = W; var z = W; // error -var a = 0 /* a */; -var b = 0 /* a */; // error -var c = 0 /* a */; +var a = W.a; +var b = W.a; // error +var c = W.a; var d = 3; // error var e = 4; -var f = 0 /* a */; // error +var f = W.a; // error var g = 5; // error var h = 3; -var i = 0 /* a */; -i = 0 /* a */; +var i = W.a; +i = W.a; W.D; var p; diff --git a/tests/baselines/reference/enumAssignmentCompat2.js b/tests/baselines/reference/enumAssignmentCompat2.js index 7ded9416c1116..1fb7eb65e3696 100644 --- a/tests/baselines/reference/enumAssignmentCompat2.js +++ b/tests/baselines/reference/enumAssignmentCompat2.js @@ -56,15 +56,15 @@ var W; var x = W; var y = W; var z = W; // error -var a = 0 /* a */; -var b = 0 /* a */; // error -var c = 0 /* a */; +var a = W.a; +var b = W.a; // error +var c = W.a; var d = 3; // error var e = 4; -var f = 0 /* a */; // error +var f = W.a; // error var g = 5; // error var h = 3; -var i = 0 /* a */; -i = 0 /* a */; +var i = W.a; +i = W.a; W.D; var p; diff --git a/tests/baselines/reference/enumBasics.js b/tests/baselines/reference/enumBasics.js index eca92215fb653..25aec5a72d84d 100644 --- a/tests/baselines/reference/enumBasics.js +++ b/tests/baselines/reference/enumBasics.js @@ -89,13 +89,13 @@ var E1; E1[E1["C"] = 2] = "C"; })(E1 || (E1 = {})); // Enum type is a subtype of Number -var x = 0 /* A */; +var x = E1.A; // Enum object type is anonymous with properties of the enum type and numeric indexer var e = E1; var e; var e; // Reverse mapping of enum returns string name of property -var s = E1[0 /* A */]; +var s = E1[e.A]; var s; // Enum with only constant members var E2; @@ -108,7 +108,7 @@ var E2; var E3; (function (E3) { E3[E3["X"] = 'foo'.length] = "X"; - E3[E3["Y"] = 4 + 3] = "Y"; + E3[E3["Y"] = 7] = "Y"; E3[E3["Z"] = +'foo'] = "Z"; })(E3 || (E3 = {})); // Enum with constant members followed by computed members @@ -145,7 +145,7 @@ var E8; var E9; (function (E9) { E9[E9["A"] = 0] = "A"; - E9[E9["B"] = E9.A] = "B"; + E9[E9["B"] = 0] = "B"; })(E9 || (E9 = {})); // (refer to .js to validate) // Enum constant members are propagated @@ -154,5 +154,5 @@ var doNotPropagate = [ ]; // Enum computed members are not propagated var doPropagate = [ - 0 /* A */, E9.B, 0 /* B */, 1 /* C */, 0 /* A */, 0 /* A */, 3 /* B */, 4 /* C */ + E9.A, E9.B, E6.B, E6.C, E6.A, E5.A, E5.B, E5.C ]; diff --git a/tests/baselines/reference/enumBasics1.js b/tests/baselines/reference/enumBasics1.js index 13b6da353b9b4..e5c9c6d29d4a6 100644 --- a/tests/baselines/reference/enumBasics1.js +++ b/tests/baselines/reference/enumBasics1.js @@ -63,7 +63,7 @@ class C { var e = E; // shouldn't error */ -1 /* A */.A; // should error +E.A.A; // should error var E2; (function (E2) { E2[E2["A"] = 0] = "A"; diff --git a/tests/baselines/reference/enumConflictsWithGlobalIdentifier.js b/tests/baselines/reference/enumConflictsWithGlobalIdentifier.js index 67d9a020bb60f..d463073bb81c5 100644 --- a/tests/baselines/reference/enumConflictsWithGlobalIdentifier.js +++ b/tests/baselines/reference/enumConflictsWithGlobalIdentifier.js @@ -12,4 +12,4 @@ var Position; Position[Position["IgnoreRulesSpecific"] = 0] = "IgnoreRulesSpecific"; })(Position || (Position = {})); var x = IgnoreRulesSpecific.; -var y = 0 /* IgnoreRulesSpecific */; +var y = Position.IgnoreRulesSpecific; diff --git a/tests/baselines/reference/enumErrors.errors.txt b/tests/baselines/reference/enumErrors.errors.txt index ca13ceba4aeff..14cad3cb53b06 100644 --- a/tests/baselines/reference/enumErrors.errors.txt +++ b/tests/baselines/reference/enumErrors.errors.txt @@ -3,15 +3,13 @@ tests/cases/conformance/enums/enumErrors.ts(3,6): error TS2431: Enum name cannot tests/cases/conformance/enums/enumErrors.ts(4,6): error TS2431: Enum name cannot be 'string' tests/cases/conformance/enums/enumErrors.ts(5,6): error TS2431: Enum name cannot be 'boolean' tests/cases/conformance/enums/enumErrors.ts(9,9): error TS2322: Type 'Number' is not assignable to type 'E5'. -tests/cases/conformance/enums/enumErrors.ts(20,9): error TS2322: Type 'E9' is not assignable to type 'E10'. -tests/cases/conformance/enums/enumErrors.ts(21,9): error TS2322: Type 'E9' is not assignable to type 'E10'. tests/cases/conformance/enums/enumErrors.ts(26,9): error TS2322: Type 'string' is not assignable to type 'E11'. tests/cases/conformance/enums/enumErrors.ts(27,9): error TS2322: Type 'Date' is not assignable to type 'E11'. tests/cases/conformance/enums/enumErrors.ts(28,9): error TS2304: Cannot find name 'window'. tests/cases/conformance/enums/enumErrors.ts(29,9): error TS2322: Type '{}' is not assignable to type 'E11'. -==== tests/cases/conformance/enums/enumErrors.ts (11 errors) ==== +==== tests/cases/conformance/enums/enumErrors.ts (9 errors) ==== // Enum named with PredefinedTypes enum any { } ~~~ @@ -42,11 +40,7 @@ tests/cases/conformance/enums/enumErrors.ts(29,9): error TS2322: Type '{}' is no // Bug 707850: This should be allowed enum E10 { A = E9.A, - ~~~~ -!!! error TS2322: Type 'E9' is not assignable to type 'E10'. B = E9.B - ~~~~ -!!! error TS2322: Type 'E9' is not assignable to type 'E10'. } // Enum with computed member intializer of other types diff --git a/tests/baselines/reference/enumErrors.js b/tests/baselines/reference/enumErrors.js index 44aa2f90162fe..a8ecdf2470a4c 100644 --- a/tests/baselines/reference/enumErrors.js +++ b/tests/baselines/reference/enumErrors.js @@ -53,14 +53,14 @@ var E5; var E9; (function (E9) { E9[E9["A"] = 0] = "A"; - E9[E9["B"] = E9.A] = "B"; + E9[E9["B"] = 0] = "B"; })(E9 || (E9 = {})); //Enum with computed member intializer of different enum type // Bug 707850: This should be allowed var E10; (function (E10) { - E10[E10["A"] = 0 /* A */] = "A"; - E10[E10["B"] = E9.B] = "B"; + E10[E10["A"] = 0] = "A"; + E10[E10["B"] = 0] = "B"; })(E10 || (E10 = {})); // Enum with computed member intializer of other types var E11; diff --git a/tests/baselines/reference/enumFromExternalModule.js b/tests/baselines/reference/enumFromExternalModule.js index 8e92cbbbda771..ed2a1f3926a34 100644 --- a/tests/baselines/reference/enumFromExternalModule.js +++ b/tests/baselines/reference/enumFromExternalModule.js @@ -18,4 +18,4 @@ var Mode = exports.Mode; //// [enumFromExternalModule_1.js] /// var f = require('enumFromExternalModule_0'); -var x = 0 /* Open */; +var x = f.Mode.Open; diff --git a/tests/baselines/reference/enumIndexer.js b/tests/baselines/reference/enumIndexer.js index f9f71a3ff982c..561461229c721 100644 --- a/tests/baselines/reference/enumIndexer.js +++ b/tests/baselines/reference/enumIndexer.js @@ -14,5 +14,5 @@ var MyEnumType; MyEnumType[MyEnumType["bar"] = 1] = "bar"; })(MyEnumType || (MyEnumType = {})); var _arr = [{ key: 'foo' }, { key: 'bar' }]; -var enumValue = 0 /* foo */; +var enumValue = MyEnumType.foo; var x = _arr.map(function (o) { return MyEnumType[o.key] === enumValue; }); // these are not same type diff --git a/tests/baselines/reference/enumMapBackIntoItself.js b/tests/baselines/reference/enumMapBackIntoItself.js index 2d177731b9572..80a4b88479f5d 100644 --- a/tests/baselines/reference/enumMapBackIntoItself.js +++ b/tests/baselines/reference/enumMapBackIntoItself.js @@ -16,7 +16,7 @@ var TShirtSize; TShirtSize[TShirtSize["Medium"] = 1] = "Medium"; TShirtSize[TShirtSize["Large"] = 2] = "Large"; })(TShirtSize || (TShirtSize = {})); -var mySize = 2 /* Large */; +var mySize = TShirtSize.Large; var test = TShirtSize[mySize]; // specifically checking output here, bug was that test used to be undefined at runtime test + ''; diff --git a/tests/baselines/reference/enumMemberResolution.js b/tests/baselines/reference/enumMemberResolution.js index e1d79ebeb92e8..c021eb8d47aed 100644 --- a/tests/baselines/reference/enumMemberResolution.js +++ b/tests/baselines/reference/enumMemberResolution.js @@ -14,4 +14,4 @@ var Position2; })(Position2 || (Position2 = {})); var x = IgnoreRulesSpecific.; // error var y = 1; -var z = 0 /* IgnoreRulesSpecific */; // no error +var z = Position2.IgnoreRulesSpecific; // no error diff --git a/tests/baselines/reference/enumMerging.js b/tests/baselines/reference/enumMerging.js index b0da96c4b6e17..5dc5a475b4000 100644 --- a/tests/baselines/reference/enumMerging.js +++ b/tests/baselines/reference/enumMerging.js @@ -95,7 +95,7 @@ var M1; EConst1[EConst1["F"] = 8] = "F"; })(M1.EConst1 || (M1.EConst1 = {})); var EConst1 = M1.EConst1; - var x = [3 /* A */, 2 /* B */, 1 /* C */, 7 /* D */, 9 /* E */, 8 /* F */]; + var x = [EConst1.A, EConst1.B, EConst1.C, EConst1.D, EConst1.E, EConst1.F]; })(M1 || (M1 = {})); // Enum with only computed members across 2 declarations with the same root module var M2; @@ -169,6 +169,6 @@ var M6; })(A.Color || (A.Color = {})); var Color = A.Color; })(A = M6.A || (M6.A = {})); - var t = 1 /* Yellow */; - t = 0 /* Red */; + var t = A.Color.Yellow; + t = A.Color.Red; })(M6 || (M6 = {})); diff --git a/tests/baselines/reference/enumOperations.js b/tests/baselines/reference/enumOperations.js index 902079c04c08d..96d9ace576c08 100644 --- a/tests/baselines/reference/enumOperations.js +++ b/tests/baselines/reference/enumOperations.js @@ -21,7 +21,7 @@ var Enum; (function (Enum) { Enum[Enum["None"] = 0] = "None"; })(Enum || (Enum = {})); -var enumType = 0 /* None */; +var enumType = Enum.None; var numberType = 0; var anyType = 0; enumType ^ numberType; diff --git a/tests/baselines/reference/enumPropertyAccess.js b/tests/baselines/reference/enumPropertyAccess.js index 4c2a7df3c94c9..1ac82b0a3de27 100644 --- a/tests/baselines/reference/enumPropertyAccess.js +++ b/tests/baselines/reference/enumPropertyAccess.js @@ -20,7 +20,7 @@ var Colors; Colors[Colors["Red"] = 0] = "Red"; Colors[Colors["Green"] = 1] = "Green"; })(Colors || (Colors = {})); -var x = 0 /* Red */; // type of 'x' should be 'Colors' +var x = Colors.Red; // type of 'x' should be 'Colors' var p = x.Green; // error x.toFixed(); // ok // Now with generics diff --git a/tests/baselines/reference/enumWithParenthesizedInitializer1.js b/tests/baselines/reference/enumWithParenthesizedInitializer1.js index 0c125b3d8b2b2..f81af2c4dda62 100644 --- a/tests/baselines/reference/enumWithParenthesizedInitializer1.js +++ b/tests/baselines/reference/enumWithParenthesizedInitializer1.js @@ -6,5 +6,5 @@ enum E { //// [enumWithParenthesizedInitializer1.js] var E; (function (E) { - E[E["e"] = -(3)] = "e"; + E[E["e"] = -3] = "e"; })(E || (E = {})); diff --git a/tests/baselines/reference/enumWithoutInitializerAfterComputedMember.js b/tests/baselines/reference/enumWithoutInitializerAfterComputedMember.js index ef9192c1c90f0..8d203e9fd71ae 100644 --- a/tests/baselines/reference/enumWithoutInitializerAfterComputedMember.js +++ b/tests/baselines/reference/enumWithoutInitializerAfterComputedMember.js @@ -9,6 +9,6 @@ enum E { var E; (function (E) { E[E["a"] = 0] = "a"; - E[E["b"] = E.a] = "b"; - E[E["c"] = undefined] = "c"; + E[E["b"] = 0] = "b"; + E[E["c"] = 1] = "c"; })(E || (E = {})); diff --git a/tests/baselines/reference/exportAssignmentEnum.js b/tests/baselines/reference/exportAssignmentEnum.js index 7b9981d97337c..a484e43738fda 100644 --- a/tests/baselines/reference/exportAssignmentEnum.js +++ b/tests/baselines/reference/exportAssignmentEnum.js @@ -26,6 +26,6 @@ var E; module.exports = E; //// [exportAssignmentEnum_B.js] var EnumE = require("exportAssignmentEnum_A"); -var a = 0 /* A */; -var b = 1 /* B */; -var c = 2 /* C */; +var a = EnumE.A; +var b = EnumE.B; +var c = EnumE.C; diff --git a/tests/baselines/reference/exportAssignmentTopLevelEnumdule.js b/tests/baselines/reference/exportAssignmentTopLevelEnumdule.js index fe6b80292d5e5..791fc4fbd7f96 100644 --- a/tests/baselines/reference/exportAssignmentTopLevelEnumdule.js +++ b/tests/baselines/reference/exportAssignmentTopLevelEnumdule.js @@ -34,7 +34,7 @@ define(["require", "exports"], function (require, exports) { //// [foo_1.js] define(["require", "exports", "./foo_0"], function (require, exports, foo) { var color; - if (color === 1 /* green */) { + if (color === foo.green) { color = foo.answer; } }); diff --git a/tests/baselines/reference/for-inStatements.js b/tests/baselines/reference/for-inStatements.js index 32e1389232dea..3db07d878bfcc 100644 --- a/tests/baselines/reference/for-inStatements.js +++ b/tests/baselines/reference/for-inStatements.js @@ -158,4 +158,4 @@ var Color; Color[Color["Blue"] = 1] = "Blue"; })(Color || (Color = {})); for (var x in Color) { } -for (var x in 1 /* Blue */) { } +for (var x in Color.Blue) { } diff --git a/tests/baselines/reference/for-of47.js b/tests/baselines/reference/for-of47.js index b2de46d677f7d..d7e596d2edc14 100644 --- a/tests/baselines/reference/for-of47.js +++ b/tests/baselines/reference/for-of47.js @@ -14,7 +14,7 @@ var E; (function (E) { E[E["x"] = 0] = "x"; })(E || (E = {})); -for ({ x, y: y = 0 /* x */ } of array) { +for ({ x, y: y = E.x } of array) { x; y; } diff --git a/tests/baselines/reference/for-of48.js b/tests/baselines/reference/for-of48.js index 15b9f5f12f61f..2a5e4e32b949b 100644 --- a/tests/baselines/reference/for-of48.js +++ b/tests/baselines/reference/for-of48.js @@ -14,7 +14,7 @@ var E; (function (E) { E[E["x"] = 0] = "x"; })(E || (E = {})); -for ({ x, y: = 0 /* x */ } of array) { +for ({ x, y: = E.x } of array) { x; y; } diff --git a/tests/baselines/reference/genericCallWithGenericSignatureArguments2.js b/tests/baselines/reference/genericCallWithGenericSignatureArguments2.js index 7acdcc32536b3..1aabe9cfa2b1c 100644 --- a/tests/baselines/reference/genericCallWithGenericSignatureArguments2.js +++ b/tests/baselines/reference/genericCallWithGenericSignatureArguments2.js @@ -109,7 +109,7 @@ var onlyT; var r; return r; } - var r7 = foo3(0 /* A */, function (x) { return 0 /* A */; }, function (x) { return 0 /* A */; }); // error + var r7 = foo3(E.A, function (x) { return E.A; }, function (x) { return F.A; }); // error })(onlyT || (onlyT = {})); var TU; (function (TU) { @@ -143,5 +143,5 @@ var TU; var r; return r; } - var r7 = foo3(0 /* A */, function (x) { return 0 /* A */; }, function (x) { return 0 /* A */; }); + var r7 = foo3(E.A, function (x) { return E.A; }, function (x) { return F.A; }); })(TU || (TU = {})); diff --git a/tests/baselines/reference/genericCallWithGenericSignatureArguments3.js b/tests/baselines/reference/genericCallWithGenericSignatureArguments3.js index ca28878daa389..36566033a489f 100644 --- a/tests/baselines/reference/genericCallWithGenericSignatureArguments3.js +++ b/tests/baselines/reference/genericCallWithGenericSignatureArguments3.js @@ -54,7 +54,7 @@ var F; (function (F) { F[F["A"] = 0] = "A"; })(F || (F = {})); -var r6 = foo(0 /* A */, function (x) { return 0 /* A */; }, function (x) { return 0 /* A */; }); // number => number +var r6 = foo(E.A, function (x) { return E.A; }, function (x) { return F.A; }); // number => number function foo2(x, a, b) { var r; return r; diff --git a/tests/baselines/reference/inOperatorWithInvalidOperands.js b/tests/baselines/reference/inOperatorWithInvalidOperands.js index 29293f880ed94..005681b62857b 100644 --- a/tests/baselines/reference/inOperatorWithInvalidOperands.js +++ b/tests/baselines/reference/inOperatorWithInvalidOperands.js @@ -61,7 +61,7 @@ var ra3 = a3 in x; var ra4 = a4 in x; var ra5 = null in x; var ra6 = undefined in x; -var ra7 = 0 /* a */ in x; +var ra7 = E.a in x; var ra8 = false in x; var ra9 = {} in x; // invalid right operands diff --git a/tests/baselines/reference/incrementAndDecrement.js b/tests/baselines/reference/incrementAndDecrement.js index 96794e3c956d2..09c0b3ae490bf 100644 --- a/tests/baselines/reference/incrementAndDecrement.js +++ b/tests/baselines/reference/incrementAndDecrement.js @@ -70,7 +70,7 @@ var E; })(E || (E = {})); ; var x = 4; -var e = 1 /* B */; +var e = E.B; var a; var w = window; // Assign to expression++ diff --git a/tests/baselines/reference/incrementOperatorWithEnumType.js b/tests/baselines/reference/incrementOperatorWithEnumType.js index 590815ffec55a..e3e843a45da57 100644 --- a/tests/baselines/reference/incrementOperatorWithEnumType.js +++ b/tests/baselines/reference/incrementOperatorWithEnumType.js @@ -22,8 +22,8 @@ var ENUM1; })(ENUM1 || (ENUM1 = {})); ; // expression -var ResultIsNumber1 = ++1 /* "B" */; -var ResultIsNumber2 = 1 /* B */++; +var ResultIsNumber1 = ++ENUM1["B"]; +var ResultIsNumber2 = ENUM1.B++; // miss assignment operator -++1 /* "B" */; -1 /* B */++; +++ENUM1["B"]; +ENUM1.B++; diff --git a/tests/baselines/reference/instantiatedModule.js b/tests/baselines/reference/instantiatedModule.js index 21411e09ff1b6..8cabdeabe49da 100644 --- a/tests/baselines/reference/instantiatedModule.js +++ b/tests/baselines/reference/instantiatedModule.js @@ -112,7 +112,7 @@ var m3 = M3; var a3; var a3 = m3.Color; var a3 = M3.Color; -var blue = 0 /* Blue */; +var blue = a3.Blue; var p3; -var p3 = 1 /* Red */; -var p3 = 0 /* Blue */; +var p3 = M3.Color.Red; +var p3 = m3.Color.Blue; diff --git a/tests/baselines/reference/interfaceAssignmentCompat.js b/tests/baselines/reference/interfaceAssignmentCompat.js index 1037df1769e1e..edaebbd38a25b 100644 --- a/tests/baselines/reference/interfaceAssignmentCompat.js +++ b/tests/baselines/reference/interfaceAssignmentCompat.js @@ -72,9 +72,9 @@ var M; function test() { var x = []; var result = ""; - x[0] = { color: 2 /* Brown */ }; - x[1] = { color: 1 /* Blue */ }; - x[2] = { color: 0 /* Green */ }; + x[0] = { color: Color.Brown }; + x[1] = { color: Color.Blue }; + x[2] = { color: Color.Green }; x = x.sort(CompareYeux); // parameter mismatch // type of z inferred from specialized array type var z = x.sort(CompareEyes); // ok diff --git a/tests/baselines/reference/interfaceWithPropertyOfEveryType.js b/tests/baselines/reference/interfaceWithPropertyOfEveryType.js index a7605dd52bc2a..90c0d257d6197 100644 --- a/tests/baselines/reference/interfaceWithPropertyOfEveryType.js +++ b/tests/baselines/reference/interfaceWithPropertyOfEveryType.js @@ -72,5 +72,5 @@ var a = { l: f1, m: M, n: {}, - o: 0 /* A */ + o: E.A }; diff --git a/tests/baselines/reference/internalAliasEnum.js b/tests/baselines/reference/internalAliasEnum.js index b5c68ea5c1663..6400cf26ddcff 100644 --- a/tests/baselines/reference/internalAliasEnum.js +++ b/tests/baselines/reference/internalAliasEnum.js @@ -26,7 +26,7 @@ var a; var c; (function (c) { var b = a.weekend; - c.bVal = 2 /* Sunday */; + c.bVal = b.Sunday; })(c || (c = {})); diff --git a/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithExport.js b/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithExport.js index e21dd35532271..f2223b197e00f 100644 --- a/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithExport.js +++ b/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithExport.js @@ -26,7 +26,7 @@ var a; var c; (function (c) { c.b = a.weekend; - c.bVal = 2 /* Sunday */; + c.bVal = c.b.Sunday; })(c = exports.c || (exports.c = {})); diff --git a/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithoutExport.js b/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithoutExport.js index 3d60e055edeed..afd6597869be6 100644 --- a/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithoutExport.js +++ b/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithoutExport.js @@ -26,7 +26,7 @@ var a; var c; (function (c) { var b = a.weekend; - c.bVal = 2 /* Sunday */; + c.bVal = b.Sunday; })(c = exports.c || (exports.c = {})); diff --git a/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithoutExportAccessError.js b/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithoutExportAccessError.js index f050d6f9a553c..acd3f4c61b185 100644 --- a/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithoutExportAccessError.js +++ b/tests/baselines/reference/internalAliasEnumInsideLocalModuleWithoutExportAccessError.js @@ -27,6 +27,6 @@ var a; var c; (function (c) { var b = a.weekend; - c.bVal = 2 /* Sunday */; + c.bVal = b.Sunday; })(c = exports.c || (exports.c = {})); var happyFriday = c.b.Friday; diff --git a/tests/baselines/reference/internalAliasEnumInsideTopLevelModuleWithExport.js b/tests/baselines/reference/internalAliasEnumInsideTopLevelModuleWithExport.js index e4dc73b2403f2..96e17c6f6e305 100644 --- a/tests/baselines/reference/internalAliasEnumInsideTopLevelModuleWithExport.js +++ b/tests/baselines/reference/internalAliasEnumInsideTopLevelModuleWithExport.js @@ -23,7 +23,7 @@ define(["require", "exports"], function (require, exports) { var weekend = a.weekend; })(a = exports.a || (exports.a = {})); exports.b = a.weekend; - exports.bVal = 2 /* Sunday */; + exports.bVal = exports.b.Sunday; }); diff --git a/tests/baselines/reference/internalAliasEnumInsideTopLevelModuleWithoutExport.js b/tests/baselines/reference/internalAliasEnumInsideTopLevelModuleWithoutExport.js index e81093147e881..b224c22f45e1a 100644 --- a/tests/baselines/reference/internalAliasEnumInsideTopLevelModuleWithoutExport.js +++ b/tests/baselines/reference/internalAliasEnumInsideTopLevelModuleWithoutExport.js @@ -23,7 +23,7 @@ define(["require", "exports"], function (require, exports) { var weekend = a.weekend; })(a = exports.a || (exports.a = {})); var b = a.weekend; - exports.bVal = 2 /* Sunday */; + exports.bVal = b.Sunday; }); diff --git a/tests/baselines/reference/invalidEnumAssignments.js b/tests/baselines/reference/invalidEnumAssignments.js index b9bb9e12cedd6..dfdd0600ed0ce 100644 --- a/tests/baselines/reference/invalidEnumAssignments.js +++ b/tests/baselines/reference/invalidEnumAssignments.js @@ -35,8 +35,8 @@ var E2; })(E2 || (E2 = {})); var e; var e2; -e = 0 /* A */; -e2 = 0 /* A */; +e = E2.A; +e2 = E.A; e = null; e = {}; e = ''; diff --git a/tests/baselines/reference/invalidUndefinedAssignments.js b/tests/baselines/reference/invalidUndefinedAssignments.js index 1feba71212dc2..dc846900ebb39 100644 --- a/tests/baselines/reference/invalidUndefinedAssignments.js +++ b/tests/baselines/reference/invalidUndefinedAssignments.js @@ -28,7 +28,7 @@ var E; E[E["A"] = 0] = "A"; })(E || (E = {})); E = x; -0 /* A */ = x; +E.A = x; var C = (function () { function C() { } diff --git a/tests/baselines/reference/invalidUndefinedValues.js b/tests/baselines/reference/invalidUndefinedValues.js index 819bf114cec02..a0ed1b4f98a9c 100644 --- a/tests/baselines/reference/invalidUndefinedValues.js +++ b/tests/baselines/reference/invalidUndefinedValues.js @@ -64,4 +64,4 @@ var E; E[E["A"] = 0] = "A"; })(E || (E = {})); x = E; -x = 0 /* A */; +x = E.A; diff --git a/tests/baselines/reference/invalidVoidAssignments.js b/tests/baselines/reference/invalidVoidAssignments.js index 40b83d329c1e0..1ce03d1382acc 100644 --- a/tests/baselines/reference/invalidVoidAssignments.js +++ b/tests/baselines/reference/invalidVoidAssignments.js @@ -58,5 +58,5 @@ var E; E[E["A"] = 0] = "A"; })(E || (E = {})); x = E; -x = 0 /* A */; +x = E.A; x = { f: function () { } }; diff --git a/tests/baselines/reference/invalidVoidValues.js b/tests/baselines/reference/invalidVoidValues.js index 658ebc7e1cacc..409df03ef373d 100644 --- a/tests/baselines/reference/invalidVoidValues.js +++ b/tests/baselines/reference/invalidVoidValues.js @@ -36,7 +36,7 @@ var E; E[E["A"] = 0] = "A"; })(E || (E = {})); x = E; -x = 0 /* A */; +x = E.A; var C = (function () { function C() { } diff --git a/tests/baselines/reference/localImportNameVsGlobalName.js b/tests/baselines/reference/localImportNameVsGlobalName.js index 6a4f1ceabc1d0..45ecdc4745e36 100644 --- a/tests/baselines/reference/localImportNameVsGlobalName.js +++ b/tests/baselines/reference/localImportNameVsGlobalName.js @@ -29,7 +29,7 @@ var App; var Key = Keyboard.Key; function foo(key) { } App.foo = foo; - foo(0 /* UP */); - foo(1 /* DOWN */); - foo(2 /* LEFT */); + foo(Key.UP); + foo(Key.DOWN); + foo(Key.LEFT); })(App || (App = {})); diff --git a/tests/baselines/reference/logicalNotOperatorWithEnumType.js b/tests/baselines/reference/logicalNotOperatorWithEnumType.js index 89ee1a148335a..382cf577713bc 100644 --- a/tests/baselines/reference/logicalNotOperatorWithEnumType.js +++ b/tests/baselines/reference/logicalNotOperatorWithEnumType.js @@ -37,13 +37,13 @@ var ENUM1; // enum type var var ResultIsBoolean1 = !ENUM; // enum type expressions -var ResultIsBoolean2 = !1 /* "B" */; -var ResultIsBoolean3 = !(1 /* B */ + 2 /* "C" */); +var ResultIsBoolean2 = !ENUM["B"]; +var ResultIsBoolean3 = !(ENUM.B + ENUM["C"]); // multiple ! operators var ResultIsBoolean4 = !!ENUM; -var ResultIsBoolean5 = !!!(1 /* "B" */ + 2 /* C */); +var ResultIsBoolean5 = !!!(ENUM["B"] + ENUM.C); // miss assignment operators !ENUM; !ENUM1; -!1 /* B */; +!ENUM.B; !ENUM, ENUM1; diff --git a/tests/baselines/reference/mergedDeclarations2.js b/tests/baselines/reference/mergedDeclarations2.js index 1e9254bb0bb75..962346541cc6c 100644 --- a/tests/baselines/reference/mergedDeclarations2.js +++ b/tests/baselines/reference/mergedDeclarations2.js @@ -17,7 +17,7 @@ var Foo; })(Foo || (Foo = {})); var Foo; (function (Foo) { - Foo[Foo["a"] = Foo.b] = "a"; + Foo[Foo["a"] = 0] = "a"; })(Foo || (Foo = {})); var Foo; (function (Foo) { diff --git a/tests/baselines/reference/mergedEnumDeclarationCodeGen.js b/tests/baselines/reference/mergedEnumDeclarationCodeGen.js index 574ef6fa2d040..57b6e8051f8e8 100644 --- a/tests/baselines/reference/mergedEnumDeclarationCodeGen.js +++ b/tests/baselines/reference/mergedEnumDeclarationCodeGen.js @@ -11,9 +11,9 @@ enum E { var E; (function (E) { E[E["a"] = 0] = "a"; - E[E["b"] = E.a] = "b"; + E[E["b"] = 0] = "b"; })(E || (E = {})); var E; (function (E) { - E[E["c"] = E.a] = "c"; + E[E["c"] = 0] = "c"; })(E || (E = {})); diff --git a/tests/baselines/reference/moduleCodeGenTest5.js b/tests/baselines/reference/moduleCodeGenTest5.js index a7580e97ef7a0..afc1ce23e3707 100644 --- a/tests/baselines/reference/moduleCodeGenTest5.js +++ b/tests/baselines/reference/moduleCodeGenTest5.js @@ -46,9 +46,9 @@ var C2 = (function () { E1[E1["A"] = 0] = "A"; })(exports.E1 || (exports.E1 = {})); var E1 = exports.E1; -var u = 0 /* A */; +var u = E1.A; var E2; (function (E2) { E2[E2["B"] = 0] = "B"; })(E2 || (E2 = {})); -var v = 0 /* B */; +var v = E2.B; diff --git a/tests/baselines/reference/moduleVisibilityTest1.js b/tests/baselines/reference/moduleVisibilityTest1.js index a2957cb958264..f4655513bec59 100644 --- a/tests/baselines/reference/moduleVisibilityTest1.js +++ b/tests/baselines/reference/moduleVisibilityTest1.js @@ -119,11 +119,11 @@ var M; var M; (function (M) { M.c = M.x; - M.meb = 1 /* B */; + M.meb = M.E.B; })(M || (M = {})); var cprime = null; var c = new M.C(); var z = M.x; -var alpha = 0 /* A */; +var alpha = M.E.A; var omega = M.exported_var; c.someMethodThatCallsAnOuterMethod(); diff --git a/tests/baselines/reference/negateOperatorWithEnumType.js b/tests/baselines/reference/negateOperatorWithEnumType.js index 77458f442df9a..e33e78110772b 100644 --- a/tests/baselines/reference/negateOperatorWithEnumType.js +++ b/tests/baselines/reference/negateOperatorWithEnumType.js @@ -33,10 +33,10 @@ var ENUM1; // enum type var var ResultIsNumber1 = -ENUM; // expressions -var ResultIsNumber2 = -1 /* "B" */; -var ResultIsNumber3 = -(1 /* B */ + 2 /* "" */); +var ResultIsNumber2 = -ENUM1["B"]; +var ResultIsNumber3 = -(ENUM1.B + ENUM1[""]); // miss assignment operators -ENUM; -ENUM1; --1 /* "B" */; +-ENUM1["B"]; -ENUM, ENUM1; diff --git a/tests/baselines/reference/noImplicitAnyIndexing.js b/tests/baselines/reference/noImplicitAnyIndexing.js index 91dbcae730c93..8451a1426a609 100644 --- a/tests/baselines/reference/noImplicitAnyIndexing.js +++ b/tests/baselines/reference/noImplicitAnyIndexing.js @@ -57,11 +57,11 @@ var MyEmusEnum; // Should be okay; should be a string. var strRepresentation1 = MyEmusEnum[0]; // Should be okay; should be a string. -var strRepresentation2 = MyEmusEnum[0 /* emu */]; +var strRepresentation2 = MyEmusEnum[MyEmusEnum.emu]; // Should be implicit 'any' ; property access fails, no string indexer. var strRepresentation3 = MyEmusEnum["monehh"]; // Should be okay; should be a MyEmusEnum -var strRepresentation4 = 0 /* "emu" */; +var strRepresentation4 = MyEmusEnum["emu"]; // Should report an implicit 'any'. var x = {}["hi"]; // Should report an implicit 'any'. @@ -77,6 +77,6 @@ var m = { "2": 2, "Okay that's enough for today.": NaN }; -var mResult1 = m[0 /* emu */]; -var mResult2 = m[MyEmusEnum[0 /* emu */]]; +var mResult1 = m[MyEmusEnum.emu]; +var mResult2 = m[MyEmusEnum[MyEmusEnum.emu]]; var mResult3 = m[hi]; diff --git a/tests/baselines/reference/noImplicitAnyIndexingSuppressed.js b/tests/baselines/reference/noImplicitAnyIndexingSuppressed.js index 5185a9b8db846..6d91d8eb83888 100644 --- a/tests/baselines/reference/noImplicitAnyIndexingSuppressed.js +++ b/tests/baselines/reference/noImplicitAnyIndexingSuppressed.js @@ -56,11 +56,11 @@ var MyEmusEnum; // Should be okay; should be a string. var strRepresentation1 = MyEmusEnum[0]; // Should be okay; should be a string. -var strRepresentation2 = MyEmusEnum[0 /* emu */]; +var strRepresentation2 = MyEmusEnum[MyEmusEnum.emu]; // Should be okay, as we suppress implicit 'any' property access checks var strRepresentation3 = MyEmusEnum["monehh"]; // Should be okay; should be a MyEmusEnum -var strRepresentation4 = 0 /* "emu" */; +var strRepresentation4 = MyEmusEnum["emu"]; // Should be okay, as we suppress implicit 'any' property access checks var x = {}["hi"]; // Should be okay, as we suppress implicit 'any' property access checks @@ -76,6 +76,6 @@ var m = { "2": 2, "Okay that's enough for today.": NaN }; -var mResult1 = m[0 /* emu */]; -var mResult2 = m[MyEmusEnum[0 /* emu */]]; +var mResult1 = m[MyEmusEnum.emu]; +var mResult2 = m[MyEmusEnum[MyEmusEnum.emu]]; var mResult3 = m[hi]; diff --git a/tests/baselines/reference/nullIsSubtypeOfEverythingButUndefined.js b/tests/baselines/reference/nullIsSubtypeOfEverythingButUndefined.js index c32cd84ce262c..646a347453663 100644 --- a/tests/baselines/reference/nullIsSubtypeOfEverythingButUndefined.js +++ b/tests/baselines/reference/nullIsSubtypeOfEverythingButUndefined.js @@ -139,8 +139,8 @@ var E; })(E || (E = {})); var r13 = true ? E : null; var r13 = true ? null : E; -var r14 = true ? 0 /* A */ : null; -var r14 = true ? null : 0 /* A */; +var r14 = true ? E.A : null; +var r14 = true ? null : E.A; function f() { } var f; (function (f) { diff --git a/tests/baselines/reference/objectTypesIdentity2.js b/tests/baselines/reference/objectTypesIdentity2.js index adbb9caeada36..87057754cab86 100644 --- a/tests/baselines/reference/objectTypesIdentity2.js +++ b/tests/baselines/reference/objectTypesIdentity2.js @@ -87,7 +87,7 @@ var E; (function (E) { E[E["A"] = 0] = "A"; })(E || (E = {})); -var b = { foo: 0 /* A */ }; +var b = { foo: E.A }; function foo5(x) { } function foo5b(x) { } function foo6(x) { } diff --git a/tests/baselines/reference/operatorAddNullUndefined.js b/tests/baselines/reference/operatorAddNullUndefined.js index f6b4fd240b257..4d52dbb234c68 100644 --- a/tests/baselines/reference/operatorAddNullUndefined.js +++ b/tests/baselines/reference/operatorAddNullUndefined.js @@ -34,7 +34,7 @@ var x9 = "test" + null; var x10 = "test" + undefined; var x11 = null + "test"; var x12 = undefined + "test"; -var x13 = null + 0 /* x */; -var x14 = undefined + 0 /* x */; -var x15 = 0 /* x */ + null; -var x16 = 0 /* x */ + undefined; +var x13 = null + E.x; +var x14 = undefined + E.x; +var x15 = E.x + null; +var x16 = E.x + undefined; diff --git a/tests/baselines/reference/parserEnum1.js b/tests/baselines/reference/parserEnum1.js index 8bd9d12823354..3b71eee5e49d8 100644 --- a/tests/baselines/reference/parserEnum1.js +++ b/tests/baselines/reference/parserEnum1.js @@ -12,7 +12,7 @@ (function (SignatureFlags) { SignatureFlags[SignatureFlags["None"] = 0] = "None"; SignatureFlags[SignatureFlags["IsIndexer"] = 1] = "IsIndexer"; - SignatureFlags[SignatureFlags["IsStringIndexer"] = 1 << 1] = "IsStringIndexer"; - SignatureFlags[SignatureFlags["IsNumberIndexer"] = 1 << 2] = "IsNumberIndexer"; + SignatureFlags[SignatureFlags["IsStringIndexer"] = 2] = "IsStringIndexer"; + SignatureFlags[SignatureFlags["IsNumberIndexer"] = 4] = "IsNumberIndexer"; })(exports.SignatureFlags || (exports.SignatureFlags = {})); var SignatureFlags = exports.SignatureFlags; diff --git a/tests/baselines/reference/parserEnum2.js b/tests/baselines/reference/parserEnum2.js index 22946153449ac..9a49b145954f0 100644 --- a/tests/baselines/reference/parserEnum2.js +++ b/tests/baselines/reference/parserEnum2.js @@ -12,7 +12,7 @@ (function (SignatureFlags) { SignatureFlags[SignatureFlags["None"] = 0] = "None"; SignatureFlags[SignatureFlags["IsIndexer"] = 1] = "IsIndexer"; - SignatureFlags[SignatureFlags["IsStringIndexer"] = 1 << 1] = "IsStringIndexer"; - SignatureFlags[SignatureFlags["IsNumberIndexer"] = 1 << 2] = "IsNumberIndexer"; + SignatureFlags[SignatureFlags["IsStringIndexer"] = 2] = "IsStringIndexer"; + SignatureFlags[SignatureFlags["IsNumberIndexer"] = 4] = "IsNumberIndexer"; })(exports.SignatureFlags || (exports.SignatureFlags = {})); var SignatureFlags = exports.SignatureFlags; diff --git a/tests/baselines/reference/parserEnumDeclaration6.js b/tests/baselines/reference/parserEnumDeclaration6.js index 5810ffc062077..a29226fbd1d7b 100644 --- a/tests/baselines/reference/parserEnumDeclaration6.js +++ b/tests/baselines/reference/parserEnumDeclaration6.js @@ -11,6 +11,6 @@ var E; (function (E) { E[E["A"] = 1] = "A"; E[E["B"] = 2] = "B"; - E[E["C"] = 1 << 1] = "C"; - E[E["D"] = undefined] = "D"; + E[E["C"] = 2] = "C"; + E[E["D"] = 3] = "D"; })(E || (E = {})); diff --git a/tests/baselines/reference/parserRealSource10.js b/tests/baselines/reference/parserRealSource10.js index 768e35c1a3b4f..2ddc7a8dce286 100644 --- a/tests/baselines/reference/parserRealSource10.js +++ b/tests/baselines/reference/parserRealSource10.js @@ -583,26 +583,26 @@ var TypeScript; TokenID[TokenID["Whitespace"] = 110] = "Whitespace"; TokenID[TokenID["Comment"] = 111] = "Comment"; TokenID[TokenID["Lim"] = 112] = "Lim"; - TokenID[TokenID["LimFixed"] = TokenID.EqualsGreaterThan] = "LimFixed"; - TokenID[TokenID["LimKeyword"] = TokenID.Yield] = "LimKeyword"; + TokenID[TokenID["LimFixed"] = 105] = "LimFixed"; + TokenID[TokenID["LimKeyword"] = 53] = "LimKeyword"; })(TypeScript.TokenID || (TypeScript.TokenID = {})); var TokenID = TypeScript.TokenID; TypeScript.tokenTable = new TokenInfo[]; TypeScript.nodeTypeTable = new string[]; TypeScript.nodeTypeToTokTable = new number[]; TypeScript.noRegexTable = new boolean[]; - TypeScript.noRegexTable[106 /* Identifier */] = true; - TypeScript.noRegexTable[107 /* StringLiteral */] = true; - TypeScript.noRegexTable[109 /* NumberLiteral */] = true; - TypeScript.noRegexTable[108 /* RegularExpressionLiteral */] = true; - TypeScript.noRegexTable[44 /* This */] = true; - TypeScript.noRegexTable[99 /* PlusPlus */] = true; - TypeScript.noRegexTable[100 /* MinusMinus */] = true; - TypeScript.noRegexTable[56 /* CloseParen */] = true; - TypeScript.noRegexTable[58 /* CloseBracket */] = true; - TypeScript.noRegexTable[60 /* CloseBrace */] = true; - TypeScript.noRegexTable[46 /* True */] = true; - TypeScript.noRegexTable[17 /* False */] = true; + TypeScript.noRegexTable[TokenID.Identifier] = true; + TypeScript.noRegexTable[TokenID.StringLiteral] = true; + TypeScript.noRegexTable[TokenID.NumberLiteral] = true; + TypeScript.noRegexTable[TokenID.RegularExpressionLiteral] = true; + TypeScript.noRegexTable[TokenID.This] = true; + TypeScript.noRegexTable[TokenID.PlusPlus] = true; + TypeScript.noRegexTable[TokenID.MinusMinus] = true; + TypeScript.noRegexTable[TokenID.CloseParen] = true; + TypeScript.noRegexTable[TokenID.CloseBracket] = true; + TypeScript.noRegexTable[TokenID.CloseBrace] = true; + TypeScript.noRegexTable[TokenID.True] = true; + TypeScript.noRegexTable[TokenID.False] = true; (function (OperatorPrecedence) { OperatorPrecedence[OperatorPrecedence["None"] = 0] = "None"; OperatorPrecedence[OperatorPrecedence["Comma"] = 1] = "Comma"; @@ -628,9 +628,9 @@ var TypeScript; Reservation[Reservation["JavascriptFuture"] = 2] = "JavascriptFuture"; Reservation[Reservation["TypeScript"] = 4] = "TypeScript"; Reservation[Reservation["JavascriptFutureStrict"] = 8] = "JavascriptFutureStrict"; - Reservation[Reservation["TypeScriptAndJS"] = Reservation.Javascript | Reservation.TypeScript] = "TypeScriptAndJS"; - Reservation[Reservation["TypeScriptAndJSFuture"] = Reservation.JavascriptFuture | Reservation.TypeScript] = "TypeScriptAndJSFuture"; - Reservation[Reservation["TypeScriptAndJSFutureStrict"] = Reservation.JavascriptFutureStrict | Reservation.TypeScript] = "TypeScriptAndJSFutureStrict"; + Reservation[Reservation["TypeScriptAndJS"] = 5] = "TypeScriptAndJS"; + Reservation[Reservation["TypeScriptAndJSFuture"] = 6] = "TypeScriptAndJSFuture"; + Reservation[Reservation["TypeScriptAndJSFutureStrict"] = 12] = "TypeScriptAndJSFutureStrict"; })(TypeScript.Reservation || (TypeScript.Reservation = {})); var Reservation = TypeScript.Reservation; var TokenInfo = (function () { @@ -659,117 +659,117 @@ var TypeScript; } } } - setTokenInfo(0 /* Any */, 4 /* TypeScript */, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "any", ErrorRecoverySet.PrimType); - setTokenInfo(1 /* Bool */, 4 /* TypeScript */, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "boolean", ErrorRecoverySet.PrimType); - setTokenInfo(2 /* Break */, Reservation.TypeScriptAndJS, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "break", ErrorRecoverySet.Stmt); - setTokenInfo(3 /* Case */, Reservation.TypeScriptAndJS, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "case", ErrorRecoverySet.SCase); - setTokenInfo(4 /* Catch */, Reservation.TypeScriptAndJS, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "catch", ErrorRecoverySet.Catch); - setTokenInfo(5 /* Class */, Reservation.TypeScriptAndJSFuture, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "class", ErrorRecoverySet.TypeScriptS); - setTokenInfo(6 /* Const */, Reservation.TypeScriptAndJSFuture, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "const", ErrorRecoverySet.Var); - setTokenInfo(7 /* Continue */, Reservation.TypeScriptAndJS, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "continue", ErrorRecoverySet.Stmt); - setTokenInfo(8 /* Debugger */, Reservation.TypeScriptAndJS, 0 /* None */, NodeType.None, 0 /* None */, NodeType.Debugger, "debugger", ErrorRecoverySet.Stmt); - setTokenInfo(9 /* Default */, Reservation.TypeScriptAndJS, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "default", ErrorRecoverySet.SCase); - setTokenInfo(10 /* Delete */, Reservation.TypeScriptAndJS, 0 /* None */, NodeType.None, 14 /* Unary */, NodeType.Delete, "delete", ErrorRecoverySet.Prefix); - setTokenInfo(11 /* Do */, Reservation.TypeScriptAndJS, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "do", ErrorRecoverySet.Stmt); - setTokenInfo(12 /* Else */, Reservation.TypeScriptAndJS, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "else", ErrorRecoverySet.Else); - setTokenInfo(13 /* Enum */, Reservation.TypeScriptAndJSFuture, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "enum", ErrorRecoverySet.TypeScriptS); - setTokenInfo(14 /* Export */, Reservation.TypeScriptAndJSFuture, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "export", ErrorRecoverySet.TypeScriptS); - setTokenInfo(15 /* Extends */, Reservation.TypeScriptAndJSFuture, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "extends", ErrorRecoverySet.None); - setTokenInfo(16 /* Declare */, 4 /* TypeScript */, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "declare", ErrorRecoverySet.Stmt); - setTokenInfo(17 /* False */, Reservation.TypeScriptAndJS, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "false", ErrorRecoverySet.RLit); - setTokenInfo(18 /* Finally */, Reservation.TypeScriptAndJS, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "finally", ErrorRecoverySet.Catch); - setTokenInfo(19 /* For */, Reservation.TypeScriptAndJS, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "for", ErrorRecoverySet.Stmt); - setTokenInfo(20 /* Function */, Reservation.TypeScriptAndJS, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "function", ErrorRecoverySet.Func); - setTokenInfo(21 /* Constructor */, Reservation.TypeScriptAndJSFutureStrict, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "constructor", ErrorRecoverySet.Func); - setTokenInfo(22 /* Get */, 4 /* TypeScript */, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "get", ErrorRecoverySet.Func); - setTokenInfo(39 /* Set */, 4 /* TypeScript */, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "set", ErrorRecoverySet.Func); - setTokenInfo(23 /* If */, Reservation.TypeScriptAndJS, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "if", ErrorRecoverySet.Stmt); - setTokenInfo(24 /* Implements */, Reservation.TypeScriptAndJSFutureStrict, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "implements", ErrorRecoverySet.None); - setTokenInfo(25 /* Import */, Reservation.TypeScriptAndJSFuture, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "import", ErrorRecoverySet.TypeScriptS); - setTokenInfo(26 /* In */, Reservation.TypeScriptAndJS, 10 /* Relational */, NodeType.In, 0 /* None */, NodeType.None, "in", ErrorRecoverySet.None); - setTokenInfo(27 /* InstanceOf */, Reservation.TypeScriptAndJS, 10 /* Relational */, NodeType.InstOf, 0 /* None */, NodeType.None, "instanceof", ErrorRecoverySet.BinOp); - setTokenInfo(28 /* Interface */, Reservation.TypeScriptAndJSFutureStrict, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "interface", ErrorRecoverySet.TypeScriptS); - setTokenInfo(29 /* Let */, 8 /* JavascriptFutureStrict */, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "let", ErrorRecoverySet.None); - setTokenInfo(30 /* Module */, 4 /* TypeScript */, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "module", ErrorRecoverySet.TypeScriptS); - setTokenInfo(31 /* New */, Reservation.TypeScriptAndJS, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "new", ErrorRecoverySet.PreOp); - setTokenInfo(32 /* Number */, 4 /* TypeScript */, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "number", ErrorRecoverySet.PrimType); - setTokenInfo(33 /* Null */, Reservation.TypeScriptAndJS, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "null", ErrorRecoverySet.RLit); - setTokenInfo(34 /* Package */, 8 /* JavascriptFutureStrict */, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "package", ErrorRecoverySet.None); - setTokenInfo(35 /* Private */, Reservation.TypeScriptAndJSFutureStrict, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "private", ErrorRecoverySet.TypeScriptS); - setTokenInfo(36 /* Protected */, 8 /* JavascriptFutureStrict */, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "protected", ErrorRecoverySet.None); - setTokenInfo(37 /* Public */, Reservation.TypeScriptAndJSFutureStrict, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "public", ErrorRecoverySet.TypeScriptS); - setTokenInfo(38 /* Return */, Reservation.TypeScriptAndJS, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "return", ErrorRecoverySet.Stmt); - setTokenInfo(40 /* Static */, Reservation.TypeScriptAndJSFutureStrict, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "static", ErrorRecoverySet.None); - setTokenInfo(41 /* String */, 4 /* TypeScript */, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "string", ErrorRecoverySet.PrimType); - setTokenInfo(42 /* Super */, Reservation.TypeScriptAndJSFuture, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "super", ErrorRecoverySet.RLit); - setTokenInfo(43 /* Switch */, Reservation.TypeScriptAndJS, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "switch", ErrorRecoverySet.Stmt); - setTokenInfo(44 /* This */, Reservation.TypeScriptAndJS, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "this", ErrorRecoverySet.RLit); - setTokenInfo(45 /* Throw */, Reservation.TypeScriptAndJS, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "throw", ErrorRecoverySet.Stmt); - setTokenInfo(46 /* True */, Reservation.TypeScriptAndJS, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "true", ErrorRecoverySet.RLit); - setTokenInfo(47 /* Try */, Reservation.TypeScriptAndJS, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "try", ErrorRecoverySet.Stmt); - setTokenInfo(48 /* TypeOf */, Reservation.TypeScriptAndJS, 0 /* None */, NodeType.None, 14 /* Unary */, NodeType.Typeof, "typeof", ErrorRecoverySet.Prefix); - setTokenInfo(49 /* Var */, Reservation.TypeScriptAndJS, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "var", ErrorRecoverySet.Var); - setTokenInfo(50 /* Void */, Reservation.TypeScriptAndJS, 0 /* None */, NodeType.None, 14 /* Unary */, NodeType.Void, "void", ErrorRecoverySet.Prefix); - setTokenInfo(51 /* With */, Reservation.TypeScriptAndJS, 0 /* None */, NodeType.None, 0 /* None */, NodeType.With, "with", ErrorRecoverySet.Stmt); - setTokenInfo(52 /* While */, Reservation.TypeScriptAndJS, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "while", ErrorRecoverySet.While); - setTokenInfo(53 /* Yield */, 8 /* JavascriptFutureStrict */, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "yield", ErrorRecoverySet.None); - setTokenInfo(106 /* Identifier */, 0 /* None */, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "identifier", ErrorRecoverySet.ID); - setTokenInfo(109 /* NumberLiteral */, 0 /* None */, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "numberLiteral", ErrorRecoverySet.Literal); - setTokenInfo(108 /* RegularExpressionLiteral */, 0 /* None */, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "regex", ErrorRecoverySet.RegExp); - setTokenInfo(107 /* StringLiteral */, 0 /* None */, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "qstring", ErrorRecoverySet.Literal); + setTokenInfo(TokenID.Any, Reservation.TypeScript, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "any", ErrorRecoverySet.PrimType); + setTokenInfo(TokenID.Bool, Reservation.TypeScript, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "boolean", ErrorRecoverySet.PrimType); + setTokenInfo(TokenID.Break, Reservation.TypeScriptAndJS, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "break", ErrorRecoverySet.Stmt); + setTokenInfo(TokenID.Case, Reservation.TypeScriptAndJS, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "case", ErrorRecoverySet.SCase); + setTokenInfo(TokenID.Catch, Reservation.TypeScriptAndJS, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "catch", ErrorRecoverySet.Catch); + setTokenInfo(TokenID.Class, Reservation.TypeScriptAndJSFuture, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "class", ErrorRecoverySet.TypeScriptS); + setTokenInfo(TokenID.Const, Reservation.TypeScriptAndJSFuture, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "const", ErrorRecoverySet.Var); + setTokenInfo(TokenID.Continue, Reservation.TypeScriptAndJS, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "continue", ErrorRecoverySet.Stmt); + setTokenInfo(TokenID.Debugger, Reservation.TypeScriptAndJS, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.Debugger, "debugger", ErrorRecoverySet.Stmt); + setTokenInfo(TokenID.Default, Reservation.TypeScriptAndJS, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "default", ErrorRecoverySet.SCase); + setTokenInfo(TokenID.Delete, Reservation.TypeScriptAndJS, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.Unary, NodeType.Delete, "delete", ErrorRecoverySet.Prefix); + setTokenInfo(TokenID.Do, Reservation.TypeScriptAndJS, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "do", ErrorRecoverySet.Stmt); + setTokenInfo(TokenID.Else, Reservation.TypeScriptAndJS, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "else", ErrorRecoverySet.Else); + setTokenInfo(TokenID.Enum, Reservation.TypeScriptAndJSFuture, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "enum", ErrorRecoverySet.TypeScriptS); + setTokenInfo(TokenID.Export, Reservation.TypeScriptAndJSFuture, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "export", ErrorRecoverySet.TypeScriptS); + setTokenInfo(TokenID.Extends, Reservation.TypeScriptAndJSFuture, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "extends", ErrorRecoverySet.None); + setTokenInfo(TokenID.Declare, Reservation.TypeScript, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "declare", ErrorRecoverySet.Stmt); + setTokenInfo(TokenID.False, Reservation.TypeScriptAndJS, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "false", ErrorRecoverySet.RLit); + setTokenInfo(TokenID.Finally, Reservation.TypeScriptAndJS, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "finally", ErrorRecoverySet.Catch); + setTokenInfo(TokenID.For, Reservation.TypeScriptAndJS, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "for", ErrorRecoverySet.Stmt); + setTokenInfo(TokenID.Function, Reservation.TypeScriptAndJS, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "function", ErrorRecoverySet.Func); + setTokenInfo(TokenID.Constructor, Reservation.TypeScriptAndJSFutureStrict, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "constructor", ErrorRecoverySet.Func); + setTokenInfo(TokenID.Get, Reservation.TypeScript, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "get", ErrorRecoverySet.Func); + setTokenInfo(TokenID.Set, Reservation.TypeScript, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "set", ErrorRecoverySet.Func); + setTokenInfo(TokenID.If, Reservation.TypeScriptAndJS, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "if", ErrorRecoverySet.Stmt); + setTokenInfo(TokenID.Implements, Reservation.TypeScriptAndJSFutureStrict, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "implements", ErrorRecoverySet.None); + setTokenInfo(TokenID.Import, Reservation.TypeScriptAndJSFuture, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "import", ErrorRecoverySet.TypeScriptS); + setTokenInfo(TokenID.In, Reservation.TypeScriptAndJS, OperatorPrecedence.Relational, NodeType.In, OperatorPrecedence.None, NodeType.None, "in", ErrorRecoverySet.None); + setTokenInfo(TokenID.InstanceOf, Reservation.TypeScriptAndJS, OperatorPrecedence.Relational, NodeType.InstOf, OperatorPrecedence.None, NodeType.None, "instanceof", ErrorRecoverySet.BinOp); + setTokenInfo(TokenID.Interface, Reservation.TypeScriptAndJSFutureStrict, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "interface", ErrorRecoverySet.TypeScriptS); + setTokenInfo(TokenID.Let, Reservation.JavascriptFutureStrict, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "let", ErrorRecoverySet.None); + setTokenInfo(TokenID.Module, Reservation.TypeScript, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "module", ErrorRecoverySet.TypeScriptS); + setTokenInfo(TokenID.New, Reservation.TypeScriptAndJS, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "new", ErrorRecoverySet.PreOp); + setTokenInfo(TokenID.Number, Reservation.TypeScript, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "number", ErrorRecoverySet.PrimType); + setTokenInfo(TokenID.Null, Reservation.TypeScriptAndJS, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "null", ErrorRecoverySet.RLit); + setTokenInfo(TokenID.Package, Reservation.JavascriptFutureStrict, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "package", ErrorRecoverySet.None); + setTokenInfo(TokenID.Private, Reservation.TypeScriptAndJSFutureStrict, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "private", ErrorRecoverySet.TypeScriptS); + setTokenInfo(TokenID.Protected, Reservation.JavascriptFutureStrict, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "protected", ErrorRecoverySet.None); + setTokenInfo(TokenID.Public, Reservation.TypeScriptAndJSFutureStrict, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "public", ErrorRecoverySet.TypeScriptS); + setTokenInfo(TokenID.Return, Reservation.TypeScriptAndJS, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "return", ErrorRecoverySet.Stmt); + setTokenInfo(TokenID.Static, Reservation.TypeScriptAndJSFutureStrict, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "static", ErrorRecoverySet.None); + setTokenInfo(TokenID.String, Reservation.TypeScript, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "string", ErrorRecoverySet.PrimType); + setTokenInfo(TokenID.Super, Reservation.TypeScriptAndJSFuture, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "super", ErrorRecoverySet.RLit); + setTokenInfo(TokenID.Switch, Reservation.TypeScriptAndJS, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "switch", ErrorRecoverySet.Stmt); + setTokenInfo(TokenID.This, Reservation.TypeScriptAndJS, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "this", ErrorRecoverySet.RLit); + setTokenInfo(TokenID.Throw, Reservation.TypeScriptAndJS, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "throw", ErrorRecoverySet.Stmt); + setTokenInfo(TokenID.True, Reservation.TypeScriptAndJS, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "true", ErrorRecoverySet.RLit); + setTokenInfo(TokenID.Try, Reservation.TypeScriptAndJS, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "try", ErrorRecoverySet.Stmt); + setTokenInfo(TokenID.TypeOf, Reservation.TypeScriptAndJS, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.Unary, NodeType.Typeof, "typeof", ErrorRecoverySet.Prefix); + setTokenInfo(TokenID.Var, Reservation.TypeScriptAndJS, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "var", ErrorRecoverySet.Var); + setTokenInfo(TokenID.Void, Reservation.TypeScriptAndJS, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.Unary, NodeType.Void, "void", ErrorRecoverySet.Prefix); + setTokenInfo(TokenID.With, Reservation.TypeScriptAndJS, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.With, "with", ErrorRecoverySet.Stmt); + setTokenInfo(TokenID.While, Reservation.TypeScriptAndJS, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "while", ErrorRecoverySet.While); + setTokenInfo(TokenID.Yield, Reservation.JavascriptFutureStrict, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "yield", ErrorRecoverySet.None); + setTokenInfo(TokenID.Identifier, Reservation.None, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "identifier", ErrorRecoverySet.ID); + setTokenInfo(TokenID.NumberLiteral, Reservation.None, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "numberLiteral", ErrorRecoverySet.Literal); + setTokenInfo(TokenID.RegularExpressionLiteral, Reservation.None, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "regex", ErrorRecoverySet.RegExp); + setTokenInfo(TokenID.StringLiteral, Reservation.None, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "qstring", ErrorRecoverySet.Literal); // Non-operator non-identifier tokens - setTokenInfo(54 /* Semicolon */, 0 /* None */, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, ";", ErrorRecoverySet.SColon); // ; - setTokenInfo(56 /* CloseParen */, 0 /* None */, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, ")", ErrorRecoverySet.RParen); // ) - setTokenInfo(58 /* CloseBracket */, 0 /* None */, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "]", ErrorRecoverySet.RBrack); // ] - setTokenInfo(59 /* OpenBrace */, 0 /* None */, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "{", ErrorRecoverySet.LCurly); // { - setTokenInfo(60 /* CloseBrace */, 0 /* None */, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "}", ErrorRecoverySet.RCurly); // } - setTokenInfo(102 /* DotDotDot */, 0 /* None */, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "...", ErrorRecoverySet.None); // ... + setTokenInfo(TokenID.Semicolon, Reservation.None, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, ";", ErrorRecoverySet.SColon); // ; + setTokenInfo(TokenID.CloseParen, Reservation.None, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, ")", ErrorRecoverySet.RParen); // ) + setTokenInfo(TokenID.CloseBracket, Reservation.None, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "]", ErrorRecoverySet.RBrack); // ] + setTokenInfo(TokenID.OpenBrace, Reservation.None, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "{", ErrorRecoverySet.LCurly); // { + setTokenInfo(TokenID.CloseBrace, Reservation.None, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "}", ErrorRecoverySet.RCurly); // } + setTokenInfo(TokenID.DotDotDot, Reservation.None, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "...", ErrorRecoverySet.None); // ... // Operator non-identifier tokens - setTokenInfo(61 /* Comma */, 0 /* None */, 1 /* Comma */, NodeType.Comma, 0 /* None */, NodeType.None, ",", ErrorRecoverySet.Comma); // , - setTokenInfo(62 /* Equals */, 0 /* None */, 2 /* Assignment */, NodeType.Asg, 0 /* None */, NodeType.None, "=", ErrorRecoverySet.Asg); // = - setTokenInfo(63 /* PlusEquals */, 0 /* None */, 2 /* Assignment */, NodeType.AsgAdd, 0 /* None */, NodeType.None, "+=", ErrorRecoverySet.BinOp); // += - setTokenInfo(64 /* MinusEquals */, 0 /* None */, 2 /* Assignment */, NodeType.AsgSub, 0 /* None */, NodeType.None, "-=", ErrorRecoverySet.BinOp); // -= - setTokenInfo(65 /* AsteriskEquals */, 0 /* None */, 2 /* Assignment */, NodeType.AsgMul, 0 /* None */, NodeType.None, "*=", ErrorRecoverySet.BinOp); // *= - setTokenInfo(66 /* SlashEquals */, 0 /* None */, 2 /* Assignment */, NodeType.AsgDiv, 0 /* None */, NodeType.None, "/=", ErrorRecoverySet.BinOp); // /= - setTokenInfo(67 /* PercentEquals */, 0 /* None */, 2 /* Assignment */, NodeType.AsgMod, 0 /* None */, NodeType.None, "%=", ErrorRecoverySet.BinOp); // %= - setTokenInfo(68 /* AmpersandEquals */, 0 /* None */, 2 /* Assignment */, NodeType.AsgAnd, 0 /* None */, NodeType.None, "&=", ErrorRecoverySet.BinOp); // &= - setTokenInfo(69 /* CaretEquals */, 0 /* None */, 2 /* Assignment */, NodeType.AsgXor, 0 /* None */, NodeType.None, "^=", ErrorRecoverySet.BinOp); // ^= - setTokenInfo(70 /* BarEquals */, 0 /* None */, 2 /* Assignment */, NodeType.AsgOr, 0 /* None */, NodeType.None, "|=", ErrorRecoverySet.BinOp); // |= - setTokenInfo(71 /* LessThanLessThanEquals */, 0 /* None */, 2 /* Assignment */, NodeType.AsgLsh, 0 /* None */, NodeType.None, "<<=", ErrorRecoverySet.BinOp); // <<= - setTokenInfo(72 /* GreaterThanGreaterThanEquals */, 0 /* None */, 2 /* Assignment */, NodeType.AsgRsh, 0 /* None */, NodeType.None, ">>=", ErrorRecoverySet.BinOp); // >>= - setTokenInfo(73 /* GreaterThanGreaterThanGreaterThanEquals */, 0 /* None */, 2 /* Assignment */, NodeType.AsgRs2, 0 /* None */, NodeType.None, ">>>=", ErrorRecoverySet.BinOp); // >>>= - setTokenInfo(74 /* Question */, 0 /* None */, 3 /* Conditional */, NodeType.ConditionalExpression, 0 /* None */, NodeType.None, "?", ErrorRecoverySet.BinOp); // ? - setTokenInfo(75 /* Colon */, 0 /* None */, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, ":", ErrorRecoverySet.Colon); // : - setTokenInfo(76 /* BarBar */, 0 /* None */, 4 /* LogicalOr */, NodeType.LogOr, 0 /* None */, NodeType.None, "||", ErrorRecoverySet.BinOp); // || - setTokenInfo(77 /* AmpersandAmpersand */, 0 /* None */, 5 /* LogicalAnd */, NodeType.LogAnd, 0 /* None */, NodeType.None, "&&", ErrorRecoverySet.BinOp); // && - setTokenInfo(78 /* Bar */, 0 /* None */, 6 /* BitwiseOr */, NodeType.Or, 0 /* None */, NodeType.None, "|", ErrorRecoverySet.BinOp); // | - setTokenInfo(79 /* Caret */, 0 /* None */, 7 /* BitwiseExclusiveOr */, NodeType.Xor, 0 /* None */, NodeType.None, "^", ErrorRecoverySet.BinOp); // ^ - setTokenInfo(80 /* And */, 0 /* None */, 8 /* BitwiseAnd */, NodeType.And, 0 /* None */, NodeType.None, "&", ErrorRecoverySet.BinOp); // & - setTokenInfo(81 /* EqualsEquals */, 0 /* None */, 9 /* Equality */, NodeType.Eq, 0 /* None */, NodeType.None, "==", ErrorRecoverySet.BinOp); // == - setTokenInfo(82 /* ExclamationEquals */, 0 /* None */, 9 /* Equality */, NodeType.Ne, 0 /* None */, NodeType.None, "!=", ErrorRecoverySet.BinOp); // != - setTokenInfo(83 /* EqualsEqualsEquals */, 0 /* None */, 9 /* Equality */, NodeType.Eqv, 0 /* None */, NodeType.None, "===", ErrorRecoverySet.BinOp); // === - setTokenInfo(84 /* ExclamationEqualsEquals */, 0 /* None */, 9 /* Equality */, NodeType.NEqv, 0 /* None */, NodeType.None, "!==", ErrorRecoverySet.BinOp); // !== - setTokenInfo(85 /* LessThan */, 0 /* None */, 10 /* Relational */, NodeType.Lt, 0 /* None */, NodeType.None, "<", ErrorRecoverySet.BinOp); // < - setTokenInfo(86 /* LessThanEquals */, 0 /* None */, 10 /* Relational */, NodeType.Le, 0 /* None */, NodeType.None, "<=", ErrorRecoverySet.BinOp); // <= - setTokenInfo(87 /* GreaterThan */, 0 /* None */, 10 /* Relational */, NodeType.Gt, 0 /* None */, NodeType.None, ">", ErrorRecoverySet.BinOp); // > - setTokenInfo(88 /* GreaterThanEquals */, 0 /* None */, 10 /* Relational */, NodeType.Ge, 0 /* None */, NodeType.None, ">=", ErrorRecoverySet.BinOp); // >= - setTokenInfo(89 /* LessThanLessThan */, 0 /* None */, 11 /* Shift */, NodeType.Lsh, 0 /* None */, NodeType.None, "<<", ErrorRecoverySet.BinOp); // << - setTokenInfo(90 /* GreaterThanGreaterThan */, 0 /* None */, 11 /* Shift */, NodeType.Rsh, 0 /* None */, NodeType.None, ">>", ErrorRecoverySet.BinOp); // >> - setTokenInfo(91 /* GreaterThanGreaterThanGreaterThan */, 0 /* None */, 11 /* Shift */, NodeType.Rs2, 0 /* None */, NodeType.None, ">>>", ErrorRecoverySet.BinOp); // >>> - setTokenInfo(92 /* Plus */, 0 /* None */, 12 /* Additive */, NodeType.Add, 14 /* Unary */, NodeType.Pos, "+", ErrorRecoverySet.AddOp); // + - setTokenInfo(93 /* Minus */, 0 /* None */, 12 /* Additive */, NodeType.Sub, 14 /* Unary */, NodeType.Neg, "-", ErrorRecoverySet.AddOp); // - - setTokenInfo(94 /* Asterisk */, 0 /* None */, 13 /* Multiplicative */, NodeType.Mul, 0 /* None */, NodeType.None, "*", ErrorRecoverySet.BinOp); // * - setTokenInfo(95 /* Slash */, 0 /* None */, 13 /* Multiplicative */, NodeType.Div, 0 /* None */, NodeType.None, "/", ErrorRecoverySet.BinOp); // / - setTokenInfo(96 /* Percent */, 0 /* None */, 13 /* Multiplicative */, NodeType.Mod, 0 /* None */, NodeType.None, "%", ErrorRecoverySet.BinOp); // % - setTokenInfo(97 /* Tilde */, 0 /* None */, 0 /* None */, NodeType.None, 14 /* Unary */, NodeType.Not, "~", ErrorRecoverySet.PreOp); // ~ - setTokenInfo(98 /* Exclamation */, 0 /* None */, 0 /* None */, NodeType.None, 14 /* Unary */, NodeType.LogNot, "!", ErrorRecoverySet.PreOp); // ! - setTokenInfo(99 /* PlusPlus */, 0 /* None */, 0 /* None */, NodeType.None, 14 /* Unary */, NodeType.IncPre, "++", ErrorRecoverySet.PreOp); // ++ - setTokenInfo(100 /* MinusMinus */, 0 /* None */, 0 /* None */, NodeType.None, 14 /* Unary */, NodeType.DecPre, "--", ErrorRecoverySet.PreOp); // -- - setTokenInfo(55 /* OpenParen */, 0 /* None */, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "(", ErrorRecoverySet.LParen); // ( - setTokenInfo(57 /* OpenBracket */, 0 /* None */, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "[", ErrorRecoverySet.LBrack); // [ - setTokenInfo(101 /* Dot */, 0 /* None */, 14 /* Unary */, NodeType.None, 0 /* None */, NodeType.None, ".", ErrorRecoverySet.Dot); // . - setTokenInfo(104 /* EndOfFile */, 0 /* None */, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "", ErrorRecoverySet.EOF); // EOF - setTokenInfo(105 /* EqualsGreaterThan */, 0 /* None */, 0 /* None */, NodeType.None, 0 /* None */, NodeType.None, "=>", ErrorRecoverySet.None); // => + setTokenInfo(TokenID.Comma, Reservation.None, OperatorPrecedence.Comma, NodeType.Comma, OperatorPrecedence.None, NodeType.None, ",", ErrorRecoverySet.Comma); // , + setTokenInfo(TokenID.Equals, Reservation.None, OperatorPrecedence.Assignment, NodeType.Asg, OperatorPrecedence.None, NodeType.None, "=", ErrorRecoverySet.Asg); // = + setTokenInfo(TokenID.PlusEquals, Reservation.None, OperatorPrecedence.Assignment, NodeType.AsgAdd, OperatorPrecedence.None, NodeType.None, "+=", ErrorRecoverySet.BinOp); // += + setTokenInfo(TokenID.MinusEquals, Reservation.None, OperatorPrecedence.Assignment, NodeType.AsgSub, OperatorPrecedence.None, NodeType.None, "-=", ErrorRecoverySet.BinOp); // -= + setTokenInfo(TokenID.AsteriskEquals, Reservation.None, OperatorPrecedence.Assignment, NodeType.AsgMul, OperatorPrecedence.None, NodeType.None, "*=", ErrorRecoverySet.BinOp); // *= + setTokenInfo(TokenID.SlashEquals, Reservation.None, OperatorPrecedence.Assignment, NodeType.AsgDiv, OperatorPrecedence.None, NodeType.None, "/=", ErrorRecoverySet.BinOp); // /= + setTokenInfo(TokenID.PercentEquals, Reservation.None, OperatorPrecedence.Assignment, NodeType.AsgMod, OperatorPrecedence.None, NodeType.None, "%=", ErrorRecoverySet.BinOp); // %= + setTokenInfo(TokenID.AmpersandEquals, Reservation.None, OperatorPrecedence.Assignment, NodeType.AsgAnd, OperatorPrecedence.None, NodeType.None, "&=", ErrorRecoverySet.BinOp); // &= + setTokenInfo(TokenID.CaretEquals, Reservation.None, OperatorPrecedence.Assignment, NodeType.AsgXor, OperatorPrecedence.None, NodeType.None, "^=", ErrorRecoverySet.BinOp); // ^= + setTokenInfo(TokenID.BarEquals, Reservation.None, OperatorPrecedence.Assignment, NodeType.AsgOr, OperatorPrecedence.None, NodeType.None, "|=", ErrorRecoverySet.BinOp); // |= + setTokenInfo(TokenID.LessThanLessThanEquals, Reservation.None, OperatorPrecedence.Assignment, NodeType.AsgLsh, OperatorPrecedence.None, NodeType.None, "<<=", ErrorRecoverySet.BinOp); // <<= + setTokenInfo(TokenID.GreaterThanGreaterThanEquals, Reservation.None, OperatorPrecedence.Assignment, NodeType.AsgRsh, OperatorPrecedence.None, NodeType.None, ">>=", ErrorRecoverySet.BinOp); // >>= + setTokenInfo(TokenID.GreaterThanGreaterThanGreaterThanEquals, Reservation.None, OperatorPrecedence.Assignment, NodeType.AsgRs2, OperatorPrecedence.None, NodeType.None, ">>>=", ErrorRecoverySet.BinOp); // >>>= + setTokenInfo(TokenID.Question, Reservation.None, OperatorPrecedence.Conditional, NodeType.ConditionalExpression, OperatorPrecedence.None, NodeType.None, "?", ErrorRecoverySet.BinOp); // ? + setTokenInfo(TokenID.Colon, Reservation.None, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, ":", ErrorRecoverySet.Colon); // : + setTokenInfo(TokenID.BarBar, Reservation.None, OperatorPrecedence.LogicalOr, NodeType.LogOr, OperatorPrecedence.None, NodeType.None, "||", ErrorRecoverySet.BinOp); // || + setTokenInfo(TokenID.AmpersandAmpersand, Reservation.None, OperatorPrecedence.LogicalAnd, NodeType.LogAnd, OperatorPrecedence.None, NodeType.None, "&&", ErrorRecoverySet.BinOp); // && + setTokenInfo(TokenID.Bar, Reservation.None, OperatorPrecedence.BitwiseOr, NodeType.Or, OperatorPrecedence.None, NodeType.None, "|", ErrorRecoverySet.BinOp); // | + setTokenInfo(TokenID.Caret, Reservation.None, OperatorPrecedence.BitwiseExclusiveOr, NodeType.Xor, OperatorPrecedence.None, NodeType.None, "^", ErrorRecoverySet.BinOp); // ^ + setTokenInfo(TokenID.And, Reservation.None, OperatorPrecedence.BitwiseAnd, NodeType.And, OperatorPrecedence.None, NodeType.None, "&", ErrorRecoverySet.BinOp); // & + setTokenInfo(TokenID.EqualsEquals, Reservation.None, OperatorPrecedence.Equality, NodeType.Eq, OperatorPrecedence.None, NodeType.None, "==", ErrorRecoverySet.BinOp); // == + setTokenInfo(TokenID.ExclamationEquals, Reservation.None, OperatorPrecedence.Equality, NodeType.Ne, OperatorPrecedence.None, NodeType.None, "!=", ErrorRecoverySet.BinOp); // != + setTokenInfo(TokenID.EqualsEqualsEquals, Reservation.None, OperatorPrecedence.Equality, NodeType.Eqv, OperatorPrecedence.None, NodeType.None, "===", ErrorRecoverySet.BinOp); // === + setTokenInfo(TokenID.ExclamationEqualsEquals, Reservation.None, OperatorPrecedence.Equality, NodeType.NEqv, OperatorPrecedence.None, NodeType.None, "!==", ErrorRecoverySet.BinOp); // !== + setTokenInfo(TokenID.LessThan, Reservation.None, OperatorPrecedence.Relational, NodeType.Lt, OperatorPrecedence.None, NodeType.None, "<", ErrorRecoverySet.BinOp); // < + setTokenInfo(TokenID.LessThanEquals, Reservation.None, OperatorPrecedence.Relational, NodeType.Le, OperatorPrecedence.None, NodeType.None, "<=", ErrorRecoverySet.BinOp); // <= + setTokenInfo(TokenID.GreaterThan, Reservation.None, OperatorPrecedence.Relational, NodeType.Gt, OperatorPrecedence.None, NodeType.None, ">", ErrorRecoverySet.BinOp); // > + setTokenInfo(TokenID.GreaterThanEquals, Reservation.None, OperatorPrecedence.Relational, NodeType.Ge, OperatorPrecedence.None, NodeType.None, ">=", ErrorRecoverySet.BinOp); // >= + setTokenInfo(TokenID.LessThanLessThan, Reservation.None, OperatorPrecedence.Shift, NodeType.Lsh, OperatorPrecedence.None, NodeType.None, "<<", ErrorRecoverySet.BinOp); // << + setTokenInfo(TokenID.GreaterThanGreaterThan, Reservation.None, OperatorPrecedence.Shift, NodeType.Rsh, OperatorPrecedence.None, NodeType.None, ">>", ErrorRecoverySet.BinOp); // >> + setTokenInfo(TokenID.GreaterThanGreaterThanGreaterThan, Reservation.None, OperatorPrecedence.Shift, NodeType.Rs2, OperatorPrecedence.None, NodeType.None, ">>>", ErrorRecoverySet.BinOp); // >>> + setTokenInfo(TokenID.Plus, Reservation.None, OperatorPrecedence.Additive, NodeType.Add, OperatorPrecedence.Unary, NodeType.Pos, "+", ErrorRecoverySet.AddOp); // + + setTokenInfo(TokenID.Minus, Reservation.None, OperatorPrecedence.Additive, NodeType.Sub, OperatorPrecedence.Unary, NodeType.Neg, "-", ErrorRecoverySet.AddOp); // - + setTokenInfo(TokenID.Asterisk, Reservation.None, OperatorPrecedence.Multiplicative, NodeType.Mul, OperatorPrecedence.None, NodeType.None, "*", ErrorRecoverySet.BinOp); // * + setTokenInfo(TokenID.Slash, Reservation.None, OperatorPrecedence.Multiplicative, NodeType.Div, OperatorPrecedence.None, NodeType.None, "/", ErrorRecoverySet.BinOp); // / + setTokenInfo(TokenID.Percent, Reservation.None, OperatorPrecedence.Multiplicative, NodeType.Mod, OperatorPrecedence.None, NodeType.None, "%", ErrorRecoverySet.BinOp); // % + setTokenInfo(TokenID.Tilde, Reservation.None, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.Unary, NodeType.Not, "~", ErrorRecoverySet.PreOp); // ~ + setTokenInfo(TokenID.Exclamation, Reservation.None, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.Unary, NodeType.LogNot, "!", ErrorRecoverySet.PreOp); // ! + setTokenInfo(TokenID.PlusPlus, Reservation.None, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.Unary, NodeType.IncPre, "++", ErrorRecoverySet.PreOp); // ++ + setTokenInfo(TokenID.MinusMinus, Reservation.None, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.Unary, NodeType.DecPre, "--", ErrorRecoverySet.PreOp); // -- + setTokenInfo(TokenID.OpenParen, Reservation.None, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "(", ErrorRecoverySet.LParen); // ( + setTokenInfo(TokenID.OpenBracket, Reservation.None, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "[", ErrorRecoverySet.LBrack); // [ + setTokenInfo(TokenID.Dot, Reservation.None, OperatorPrecedence.Unary, NodeType.None, OperatorPrecedence.None, NodeType.None, ".", ErrorRecoverySet.Dot); // . + setTokenInfo(TokenID.EndOfFile, Reservation.None, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "", ErrorRecoverySet.EOF); // EOF + setTokenInfo(TokenID.EqualsGreaterThan, Reservation.None, OperatorPrecedence.None, NodeType.None, OperatorPrecedence.None, NodeType.None, "=>", ErrorRecoverySet.None); // => function lookupToken(tokenId) { return TypeScript.tokenTable[tokenId]; } @@ -808,18 +808,18 @@ var TypeScript; }; Token.prototype.classification = function () { if (this.tokenId <= TokenID.LimKeyword) { - return 1 /* Keyword */; + return TokenClass.Keyword; } else { var tokenInfo = lookupToken(this.tokenId); if (tokenInfo != undefined) { if ((tokenInfo.unopNodeType != NodeType.None) || (tokenInfo.binopNodeType != NodeType.None)) { - return 2 /* Operator */; + return TokenClass.Operator; } } } - return 0 /* Punctuation */; + return TokenClass.Punctuation; }; return Token; })(); @@ -827,7 +827,7 @@ var TypeScript; var NumberLiteralToken = (function (_super) { __extends(NumberLiteralToken, _super); function NumberLiteralToken(value, hasEmptyFraction) { - _super.call(this, 109 /* NumberLiteral */); + _super.call(this, TokenID.NumberLiteral); this.value = value; this.hasEmptyFraction = hasEmptyFraction; } @@ -835,7 +835,7 @@ var TypeScript; return this.hasEmptyFraction ? this.value.toString() + ".0" : this.value.toString(); }; NumberLiteralToken.prototype.classification = function () { - return 6 /* Literal */; + return TokenClass.Literal; }; return NumberLiteralToken; })(Token); @@ -843,14 +843,14 @@ var TypeScript; var StringLiteralToken = (function (_super) { __extends(StringLiteralToken, _super); function StringLiteralToken(value) { - _super.call(this, 107 /* StringLiteral */); + _super.call(this, TokenID.StringLiteral); this.value = value; } StringLiteralToken.prototype.getText = function () { return this.value; }; StringLiteralToken.prototype.classification = function () { - return 6 /* Literal */; + return TokenClass.Literal; }; return StringLiteralToken; })(Token); @@ -858,7 +858,7 @@ var TypeScript; var IdentifierToken = (function (_super) { __extends(IdentifierToken, _super); function IdentifierToken(value, hasEscapeSequence) { - _super.call(this, 106 /* Identifier */); + _super.call(this, TokenID.Identifier); this.value = value; this.hasEscapeSequence = hasEscapeSequence; } @@ -866,7 +866,7 @@ var TypeScript; return this.value; }; IdentifierToken.prototype.classification = function () { - return 5 /* Identifier */; + return TokenClass.Identifier; }; return IdentifierToken; })(Token); @@ -881,7 +881,7 @@ var TypeScript; return this.value; }; WhitespaceToken.prototype.classification = function () { - return 4 /* Whitespace */; + return TokenClass.Whitespace; }; return WhitespaceToken; })(Token); @@ -900,7 +900,7 @@ var TypeScript; return this.value; }; CommentToken.prototype.classification = function () { - return 3 /* Comment */; + return TokenClass.Comment; }; return CommentToken; })(Token); @@ -908,14 +908,14 @@ var TypeScript; var RegularExpressionLiteralToken = (function (_super) { __extends(RegularExpressionLiteralToken, _super); function RegularExpressionLiteralToken(regex) { - _super.call(this, 108 /* RegularExpressionLiteral */); + _super.call(this, TokenID.RegularExpressionLiteral); this.regex = regex; } RegularExpressionLiteralToken.prototype.getText = function () { return this.regex.toString(); }; RegularExpressionLiteralToken.prototype.classification = function () { - return 6 /* Literal */; + return TokenClass.Literal; }; return RegularExpressionLiteralToken; })(Token); diff --git a/tests/baselines/reference/parserRealSource14.js b/tests/baselines/reference/parserRealSource14.js index 8deae79f5e2ec..4312cb385171c 100644 --- a/tests/baselines/reference/parserRealSource14.js +++ b/tests/baselines/reference/parserRealSource14.js @@ -967,14 +967,14 @@ var TypeScript; // the "{" character, meaning we don't traverse the tree down to the stmt list of the class, meaning // we don't find the "precomment" attached to the errorneous empty stmt. //TODO: It would be nice to be able to get rid of this. - GetAstPathOptions[GetAstPathOptions["DontPruneSearchBasedOnPosition"] = 1 << 1] = "DontPruneSearchBasedOnPosition"; + GetAstPathOptions[GetAstPathOptions["DontPruneSearchBasedOnPosition"] = 2] = "DontPruneSearchBasedOnPosition"; })(TypeScript.GetAstPathOptions || (TypeScript.GetAstPathOptions = {})); var GetAstPathOptions = TypeScript.GetAstPathOptions; /// /// Return the stack of AST nodes containing "position" /// function getAstPathToPosition(script, pos, options) { - if (options === void 0) { options = 0 /* Default */; } + if (options === void 0) { options = GetAstPathOptions.Default; } var lookInComments = function (comments) { if (comments && comments.length > 0) { for (var i = 0; i < comments.length; i++) { @@ -998,7 +998,7 @@ var TypeScript; // bar // 0123 // If "position == 3", the caret is at the "right" of the "r" character, which should be considered valid - var inclusive = hasFlag(options, 1 /* EdgeInclusive */) || + var inclusive = hasFlag(options, GetAstPathOptions.EdgeInclusive) || cur.nodeType === TypeScript.NodeType.Name || pos === script.limChar; // Special "EOF" case var minChar = cur.minChar; diff --git a/tests/baselines/reference/parserRealSource2.js b/tests/baselines/reference/parserRealSource2.js index 0dbe7dfef4056..c41f88bc9c20c 100644 --- a/tests/baselines/reference/parserRealSource2.js +++ b/tests/baselines/reference/parserRealSource2.js @@ -284,190 +284,190 @@ var TypeScript; (function (ErrorRecoverySet) { ErrorRecoverySet[ErrorRecoverySet["None"] = 0] = "None"; ErrorRecoverySet[ErrorRecoverySet["Comma"] = 1] = "Comma"; - ErrorRecoverySet[ErrorRecoverySet["SColon"] = 1 << 1] = "SColon"; - ErrorRecoverySet[ErrorRecoverySet["Asg"] = 1 << 2] = "Asg"; - ErrorRecoverySet[ErrorRecoverySet["BinOp"] = 1 << 3] = "BinOp"; + ErrorRecoverySet[ErrorRecoverySet["SColon"] = 2] = "SColon"; + ErrorRecoverySet[ErrorRecoverySet["Asg"] = 4] = "Asg"; + ErrorRecoverySet[ErrorRecoverySet["BinOp"] = 8] = "BinOp"; // AsgMod, AsgAdd, AsgSub, AsgLsh, AsgRsh, AsgRs2, AsgAnd, AsgXor, AsgOr, QMark, Mult, Div, // Pct, GT, LT, And, Xor, Or - ErrorRecoverySet[ErrorRecoverySet["RBrack"] = 1 << 4] = "RBrack"; - ErrorRecoverySet[ErrorRecoverySet["RCurly"] = 1 << 5] = "RCurly"; - ErrorRecoverySet[ErrorRecoverySet["RParen"] = 1 << 6] = "RParen"; - ErrorRecoverySet[ErrorRecoverySet["Dot"] = 1 << 7] = "Dot"; - ErrorRecoverySet[ErrorRecoverySet["Colon"] = 1 << 8] = "Colon"; - ErrorRecoverySet[ErrorRecoverySet["PrimType"] = 1 << 9] = "PrimType"; - ErrorRecoverySet[ErrorRecoverySet["AddOp"] = 1 << 10] = "AddOp"; - ErrorRecoverySet[ErrorRecoverySet["LCurly"] = 1 << 11] = "LCurly"; - ErrorRecoverySet[ErrorRecoverySet["PreOp"] = 1 << 12] = "PreOp"; - ErrorRecoverySet[ErrorRecoverySet["RegExp"] = 1 << 13] = "RegExp"; - ErrorRecoverySet[ErrorRecoverySet["LParen"] = 1 << 14] = "LParen"; - ErrorRecoverySet[ErrorRecoverySet["LBrack"] = 1 << 15] = "LBrack"; - ErrorRecoverySet[ErrorRecoverySet["Scope"] = 1 << 16] = "Scope"; - ErrorRecoverySet[ErrorRecoverySet["In"] = 1 << 17] = "In"; - ErrorRecoverySet[ErrorRecoverySet["SCase"] = 1 << 18] = "SCase"; - ErrorRecoverySet[ErrorRecoverySet["Else"] = 1 << 19] = "Else"; - ErrorRecoverySet[ErrorRecoverySet["Catch"] = 1 << 20] = "Catch"; - ErrorRecoverySet[ErrorRecoverySet["Var"] = 1 << 21] = "Var"; - ErrorRecoverySet[ErrorRecoverySet["Stmt"] = 1 << 22] = "Stmt"; - ErrorRecoverySet[ErrorRecoverySet["While"] = 1 << 23] = "While"; - ErrorRecoverySet[ErrorRecoverySet["ID"] = 1 << 24] = "ID"; - ErrorRecoverySet[ErrorRecoverySet["Prefix"] = 1 << 25] = "Prefix"; - ErrorRecoverySet[ErrorRecoverySet["Literal"] = 1 << 26] = "Literal"; - ErrorRecoverySet[ErrorRecoverySet["RLit"] = 1 << 27] = "RLit"; - ErrorRecoverySet[ErrorRecoverySet["Func"] = 1 << 28] = "Func"; - ErrorRecoverySet[ErrorRecoverySet["EOF"] = 1 << 29] = "EOF"; + ErrorRecoverySet[ErrorRecoverySet["RBrack"] = 16] = "RBrack"; + ErrorRecoverySet[ErrorRecoverySet["RCurly"] = 32] = "RCurly"; + ErrorRecoverySet[ErrorRecoverySet["RParen"] = 64] = "RParen"; + ErrorRecoverySet[ErrorRecoverySet["Dot"] = 128] = "Dot"; + ErrorRecoverySet[ErrorRecoverySet["Colon"] = 256] = "Colon"; + ErrorRecoverySet[ErrorRecoverySet["PrimType"] = 512] = "PrimType"; + ErrorRecoverySet[ErrorRecoverySet["AddOp"] = 1024] = "AddOp"; + ErrorRecoverySet[ErrorRecoverySet["LCurly"] = 2048] = "LCurly"; + ErrorRecoverySet[ErrorRecoverySet["PreOp"] = 4096] = "PreOp"; + ErrorRecoverySet[ErrorRecoverySet["RegExp"] = 8192] = "RegExp"; + ErrorRecoverySet[ErrorRecoverySet["LParen"] = 16384] = "LParen"; + ErrorRecoverySet[ErrorRecoverySet["LBrack"] = 32768] = "LBrack"; + ErrorRecoverySet[ErrorRecoverySet["Scope"] = 65536] = "Scope"; + ErrorRecoverySet[ErrorRecoverySet["In"] = 131072] = "In"; + ErrorRecoverySet[ErrorRecoverySet["SCase"] = 262144] = "SCase"; + ErrorRecoverySet[ErrorRecoverySet["Else"] = 524288] = "Else"; + ErrorRecoverySet[ErrorRecoverySet["Catch"] = 1048576] = "Catch"; + ErrorRecoverySet[ErrorRecoverySet["Var"] = 2097152] = "Var"; + ErrorRecoverySet[ErrorRecoverySet["Stmt"] = 4194304] = "Stmt"; + ErrorRecoverySet[ErrorRecoverySet["While"] = 8388608] = "While"; + ErrorRecoverySet[ErrorRecoverySet["ID"] = 16777216] = "ID"; + ErrorRecoverySet[ErrorRecoverySet["Prefix"] = 33554432] = "Prefix"; + ErrorRecoverySet[ErrorRecoverySet["Literal"] = 67108864] = "Literal"; + ErrorRecoverySet[ErrorRecoverySet["RLit"] = 134217728] = "RLit"; + ErrorRecoverySet[ErrorRecoverySet["Func"] = 268435456] = "Func"; + ErrorRecoverySet[ErrorRecoverySet["EOF"] = 536870912] = "EOF"; // REVIEW: Name this something clearer. - ErrorRecoverySet[ErrorRecoverySet["TypeScriptS"] = 1 << 30] = "TypeScriptS"; - ErrorRecoverySet[ErrorRecoverySet["ExprStart"] = ErrorRecoverySet.SColon | ErrorRecoverySet.AddOp | ErrorRecoverySet.LCurly | ErrorRecoverySet.PreOp | ErrorRecoverySet.RegExp | ErrorRecoverySet.LParen | ErrorRecoverySet.LBrack | ErrorRecoverySet.ID | ErrorRecoverySet.Prefix | ErrorRecoverySet.RLit | ErrorRecoverySet.Func | ErrorRecoverySet.Literal] = "ExprStart"; - ErrorRecoverySet[ErrorRecoverySet["StmtStart"] = ErrorRecoverySet.ExprStart | ErrorRecoverySet.SColon | ErrorRecoverySet.Var | ErrorRecoverySet.Stmt | ErrorRecoverySet.While | ErrorRecoverySet.TypeScriptS] = "StmtStart"; - ErrorRecoverySet[ErrorRecoverySet["Postfix"] = ErrorRecoverySet.Dot | ErrorRecoverySet.LParen | ErrorRecoverySet.LBrack] = "Postfix"; + ErrorRecoverySet[ErrorRecoverySet["TypeScriptS"] = 1073741824] = "TypeScriptS"; + ErrorRecoverySet[ErrorRecoverySet["ExprStart"] = 520158210] = "ExprStart"; + ErrorRecoverySet[ErrorRecoverySet["StmtStart"] = 1608580098] = "StmtStart"; + ErrorRecoverySet[ErrorRecoverySet["Postfix"] = 49280] = "Postfix"; })(TypeScript.ErrorRecoverySet || (TypeScript.ErrorRecoverySet = {})); var ErrorRecoverySet = TypeScript.ErrorRecoverySet; (function (AllowedElements) { AllowedElements[AllowedElements["None"] = 0] = "None"; - AllowedElements[AllowedElements["ModuleDeclarations"] = 1 << 2] = "ModuleDeclarations"; - AllowedElements[AllowedElements["ClassDeclarations"] = 1 << 3] = "ClassDeclarations"; - AllowedElements[AllowedElements["InterfaceDeclarations"] = 1 << 4] = "InterfaceDeclarations"; - AllowedElements[AllowedElements["AmbientDeclarations"] = 1 << 10] = "AmbientDeclarations"; - AllowedElements[AllowedElements["Properties"] = 1 << 11] = "Properties"; - AllowedElements[AllowedElements["Global"] = AllowedElements.ModuleDeclarations | AllowedElements.ClassDeclarations | AllowedElements.InterfaceDeclarations | AllowedElements.AmbientDeclarations] = "Global"; - AllowedElements[AllowedElements["QuickParse"] = AllowedElements.Global | AllowedElements.Properties] = "QuickParse"; + AllowedElements[AllowedElements["ModuleDeclarations"] = 4] = "ModuleDeclarations"; + AllowedElements[AllowedElements["ClassDeclarations"] = 8] = "ClassDeclarations"; + AllowedElements[AllowedElements["InterfaceDeclarations"] = 16] = "InterfaceDeclarations"; + AllowedElements[AllowedElements["AmbientDeclarations"] = 1024] = "AmbientDeclarations"; + AllowedElements[AllowedElements["Properties"] = 2048] = "Properties"; + AllowedElements[AllowedElements["Global"] = 1052] = "Global"; + AllowedElements[AllowedElements["QuickParse"] = 3100] = "QuickParse"; })(TypeScript.AllowedElements || (TypeScript.AllowedElements = {})); var AllowedElements = TypeScript.AllowedElements; (function (Modifiers) { Modifiers[Modifiers["None"] = 0] = "None"; Modifiers[Modifiers["Private"] = 1] = "Private"; - Modifiers[Modifiers["Public"] = 1 << 1] = "Public"; - Modifiers[Modifiers["Readonly"] = 1 << 2] = "Readonly"; - Modifiers[Modifiers["Ambient"] = 1 << 3] = "Ambient"; - Modifiers[Modifiers["Exported"] = 1 << 4] = "Exported"; - Modifiers[Modifiers["Getter"] = 1 << 5] = "Getter"; - Modifiers[Modifiers["Setter"] = 1 << 6] = "Setter"; - Modifiers[Modifiers["Static"] = 1 << 7] = "Static"; + Modifiers[Modifiers["Public"] = 2] = "Public"; + Modifiers[Modifiers["Readonly"] = 4] = "Readonly"; + Modifiers[Modifiers["Ambient"] = 8] = "Ambient"; + Modifiers[Modifiers["Exported"] = 16] = "Exported"; + Modifiers[Modifiers["Getter"] = 32] = "Getter"; + Modifiers[Modifiers["Setter"] = 64] = "Setter"; + Modifiers[Modifiers["Static"] = 128] = "Static"; })(TypeScript.Modifiers || (TypeScript.Modifiers = {})); var Modifiers = TypeScript.Modifiers; (function (ASTFlags) { ASTFlags[ASTFlags["None"] = 0] = "None"; ASTFlags[ASTFlags["ExplicitSemicolon"] = 1] = "ExplicitSemicolon"; - ASTFlags[ASTFlags["AutomaticSemicolon"] = 1 << 1] = "AutomaticSemicolon"; - ASTFlags[ASTFlags["Writeable"] = 1 << 2] = "Writeable"; - ASTFlags[ASTFlags["Error"] = 1 << 3] = "Error"; - ASTFlags[ASTFlags["DotLHSPartial"] = 1 << 4] = "DotLHSPartial"; - ASTFlags[ASTFlags["DotLHS"] = 1 << 5] = "DotLHS"; - ASTFlags[ASTFlags["IsStatement"] = 1 << 6] = "IsStatement"; - ASTFlags[ASTFlags["StrictMode"] = 1 << 7] = "StrictMode"; - ASTFlags[ASTFlags["PossibleOptionalParameter"] = 1 << 8] = "PossibleOptionalParameter"; - ASTFlags[ASTFlags["ClassBaseConstructorCall"] = 1 << 9] = "ClassBaseConstructorCall"; - ASTFlags[ASTFlags["OptionalName"] = 1 << 10] = "OptionalName"; + ASTFlags[ASTFlags["AutomaticSemicolon"] = 2] = "AutomaticSemicolon"; + ASTFlags[ASTFlags["Writeable"] = 4] = "Writeable"; + ASTFlags[ASTFlags["Error"] = 8] = "Error"; + ASTFlags[ASTFlags["DotLHSPartial"] = 16] = "DotLHSPartial"; + ASTFlags[ASTFlags["DotLHS"] = 32] = "DotLHS"; + ASTFlags[ASTFlags["IsStatement"] = 64] = "IsStatement"; + ASTFlags[ASTFlags["StrictMode"] = 128] = "StrictMode"; + ASTFlags[ASTFlags["PossibleOptionalParameter"] = 256] = "PossibleOptionalParameter"; + ASTFlags[ASTFlags["ClassBaseConstructorCall"] = 512] = "ClassBaseConstructorCall"; + ASTFlags[ASTFlags["OptionalName"] = 1024] = "OptionalName"; // REVIEW: This flag is to mark lambda nodes to note that the LParen of an expression has already been matched in the lambda header. // The flag is used to communicate this piece of information to the calling parseTerm, which intern will remove it. // Once we have a better way to associate information with nodes, this flag should not be used. - ASTFlags[ASTFlags["SkipNextRParen"] = 1 << 11] = "SkipNextRParen"; + ASTFlags[ASTFlags["SkipNextRParen"] = 2048] = "SkipNextRParen"; })(TypeScript.ASTFlags || (TypeScript.ASTFlags = {})); var ASTFlags = TypeScript.ASTFlags; (function (DeclFlags) { DeclFlags[DeclFlags["None"] = 0] = "None"; DeclFlags[DeclFlags["Exported"] = 1] = "Exported"; - DeclFlags[DeclFlags["Private"] = 1 << 1] = "Private"; - DeclFlags[DeclFlags["Public"] = 1 << 2] = "Public"; - DeclFlags[DeclFlags["Ambient"] = 1 << 3] = "Ambient"; - DeclFlags[DeclFlags["Static"] = 1 << 4] = "Static"; - DeclFlags[DeclFlags["LocalStatic"] = 1 << 5] = "LocalStatic"; - DeclFlags[DeclFlags["GetAccessor"] = 1 << 6] = "GetAccessor"; - DeclFlags[DeclFlags["SetAccessor"] = 1 << 7] = "SetAccessor"; + DeclFlags[DeclFlags["Private"] = 2] = "Private"; + DeclFlags[DeclFlags["Public"] = 4] = "Public"; + DeclFlags[DeclFlags["Ambient"] = 8] = "Ambient"; + DeclFlags[DeclFlags["Static"] = 16] = "Static"; + DeclFlags[DeclFlags["LocalStatic"] = 32] = "LocalStatic"; + DeclFlags[DeclFlags["GetAccessor"] = 64] = "GetAccessor"; + DeclFlags[DeclFlags["SetAccessor"] = 128] = "SetAccessor"; })(TypeScript.DeclFlags || (TypeScript.DeclFlags = {})); var DeclFlags = TypeScript.DeclFlags; (function (ModuleFlags) { ModuleFlags[ModuleFlags["None"] = 0] = "None"; ModuleFlags[ModuleFlags["Exported"] = 1] = "Exported"; - ModuleFlags[ModuleFlags["Private"] = 1 << 1] = "Private"; - ModuleFlags[ModuleFlags["Public"] = 1 << 2] = "Public"; - ModuleFlags[ModuleFlags["Ambient"] = 1 << 3] = "Ambient"; - ModuleFlags[ModuleFlags["Static"] = 1 << 4] = "Static"; - ModuleFlags[ModuleFlags["LocalStatic"] = 1 << 5] = "LocalStatic"; - ModuleFlags[ModuleFlags["GetAccessor"] = 1 << 6] = "GetAccessor"; - ModuleFlags[ModuleFlags["SetAccessor"] = 1 << 7] = "SetAccessor"; - ModuleFlags[ModuleFlags["IsEnum"] = 1 << 8] = "IsEnum"; - ModuleFlags[ModuleFlags["ShouldEmitModuleDecl"] = 1 << 9] = "ShouldEmitModuleDecl"; - ModuleFlags[ModuleFlags["IsWholeFile"] = 1 << 10] = "IsWholeFile"; - ModuleFlags[ModuleFlags["IsDynamic"] = 1 << 11] = "IsDynamic"; - ModuleFlags[ModuleFlags["MustCaptureThis"] = 1 << 12] = "MustCaptureThis"; + ModuleFlags[ModuleFlags["Private"] = 2] = "Private"; + ModuleFlags[ModuleFlags["Public"] = 4] = "Public"; + ModuleFlags[ModuleFlags["Ambient"] = 8] = "Ambient"; + ModuleFlags[ModuleFlags["Static"] = 16] = "Static"; + ModuleFlags[ModuleFlags["LocalStatic"] = 32] = "LocalStatic"; + ModuleFlags[ModuleFlags["GetAccessor"] = 64] = "GetAccessor"; + ModuleFlags[ModuleFlags["SetAccessor"] = 128] = "SetAccessor"; + ModuleFlags[ModuleFlags["IsEnum"] = 256] = "IsEnum"; + ModuleFlags[ModuleFlags["ShouldEmitModuleDecl"] = 512] = "ShouldEmitModuleDecl"; + ModuleFlags[ModuleFlags["IsWholeFile"] = 1024] = "IsWholeFile"; + ModuleFlags[ModuleFlags["IsDynamic"] = 2048] = "IsDynamic"; + ModuleFlags[ModuleFlags["MustCaptureThis"] = 4096] = "MustCaptureThis"; })(TypeScript.ModuleFlags || (TypeScript.ModuleFlags = {})); var ModuleFlags = TypeScript.ModuleFlags; (function (SymbolFlags) { SymbolFlags[SymbolFlags["None"] = 0] = "None"; SymbolFlags[SymbolFlags["Exported"] = 1] = "Exported"; - SymbolFlags[SymbolFlags["Private"] = 1 << 1] = "Private"; - SymbolFlags[SymbolFlags["Public"] = 1 << 2] = "Public"; - SymbolFlags[SymbolFlags["Ambient"] = 1 << 3] = "Ambient"; - SymbolFlags[SymbolFlags["Static"] = 1 << 4] = "Static"; - SymbolFlags[SymbolFlags["LocalStatic"] = 1 << 5] = "LocalStatic"; - SymbolFlags[SymbolFlags["GetAccessor"] = 1 << 6] = "GetAccessor"; - SymbolFlags[SymbolFlags["SetAccessor"] = 1 << 7] = "SetAccessor"; - SymbolFlags[SymbolFlags["Property"] = 1 << 8] = "Property"; - SymbolFlags[SymbolFlags["Readonly"] = 1 << 9] = "Readonly"; - SymbolFlags[SymbolFlags["ModuleMember"] = 1 << 10] = "ModuleMember"; - SymbolFlags[SymbolFlags["InterfaceMember"] = 1 << 11] = "InterfaceMember"; - SymbolFlags[SymbolFlags["ClassMember"] = 1 << 12] = "ClassMember"; - SymbolFlags[SymbolFlags["BuiltIn"] = 1 << 13] = "BuiltIn"; - SymbolFlags[SymbolFlags["TypeSetDuringScopeAssignment"] = 1 << 14] = "TypeSetDuringScopeAssignment"; - SymbolFlags[SymbolFlags["Constant"] = 1 << 15] = "Constant"; - SymbolFlags[SymbolFlags["Optional"] = 1 << 16] = "Optional"; - SymbolFlags[SymbolFlags["RecursivelyReferenced"] = 1 << 17] = "RecursivelyReferenced"; - SymbolFlags[SymbolFlags["Bound"] = 1 << 18] = "Bound"; - SymbolFlags[SymbolFlags["CompilerGenerated"] = 1 << 19] = "CompilerGenerated"; + SymbolFlags[SymbolFlags["Private"] = 2] = "Private"; + SymbolFlags[SymbolFlags["Public"] = 4] = "Public"; + SymbolFlags[SymbolFlags["Ambient"] = 8] = "Ambient"; + SymbolFlags[SymbolFlags["Static"] = 16] = "Static"; + SymbolFlags[SymbolFlags["LocalStatic"] = 32] = "LocalStatic"; + SymbolFlags[SymbolFlags["GetAccessor"] = 64] = "GetAccessor"; + SymbolFlags[SymbolFlags["SetAccessor"] = 128] = "SetAccessor"; + SymbolFlags[SymbolFlags["Property"] = 256] = "Property"; + SymbolFlags[SymbolFlags["Readonly"] = 512] = "Readonly"; + SymbolFlags[SymbolFlags["ModuleMember"] = 1024] = "ModuleMember"; + SymbolFlags[SymbolFlags["InterfaceMember"] = 2048] = "InterfaceMember"; + SymbolFlags[SymbolFlags["ClassMember"] = 4096] = "ClassMember"; + SymbolFlags[SymbolFlags["BuiltIn"] = 8192] = "BuiltIn"; + SymbolFlags[SymbolFlags["TypeSetDuringScopeAssignment"] = 16384] = "TypeSetDuringScopeAssignment"; + SymbolFlags[SymbolFlags["Constant"] = 32768] = "Constant"; + SymbolFlags[SymbolFlags["Optional"] = 65536] = "Optional"; + SymbolFlags[SymbolFlags["RecursivelyReferenced"] = 131072] = "RecursivelyReferenced"; + SymbolFlags[SymbolFlags["Bound"] = 262144] = "Bound"; + SymbolFlags[SymbolFlags["CompilerGenerated"] = 524288] = "CompilerGenerated"; })(TypeScript.SymbolFlags || (TypeScript.SymbolFlags = {})); var SymbolFlags = TypeScript.SymbolFlags; (function (VarFlags) { VarFlags[VarFlags["None"] = 0] = "None"; VarFlags[VarFlags["Exported"] = 1] = "Exported"; - VarFlags[VarFlags["Private"] = 1 << 1] = "Private"; - VarFlags[VarFlags["Public"] = 1 << 2] = "Public"; - VarFlags[VarFlags["Ambient"] = 1 << 3] = "Ambient"; - VarFlags[VarFlags["Static"] = 1 << 4] = "Static"; - VarFlags[VarFlags["LocalStatic"] = 1 << 5] = "LocalStatic"; - VarFlags[VarFlags["GetAccessor"] = 1 << 6] = "GetAccessor"; - VarFlags[VarFlags["SetAccessor"] = 1 << 7] = "SetAccessor"; - VarFlags[VarFlags["AutoInit"] = 1 << 8] = "AutoInit"; - VarFlags[VarFlags["Property"] = 1 << 9] = "Property"; - VarFlags[VarFlags["Readonly"] = 1 << 10] = "Readonly"; - VarFlags[VarFlags["Class"] = 1 << 11] = "Class"; - VarFlags[VarFlags["ClassProperty"] = 1 << 12] = "ClassProperty"; - VarFlags[VarFlags["ClassBodyProperty"] = 1 << 13] = "ClassBodyProperty"; - VarFlags[VarFlags["ClassConstructorProperty"] = 1 << 14] = "ClassConstructorProperty"; - VarFlags[VarFlags["ClassSuperMustBeFirstCallInConstructor"] = 1 << 15] = "ClassSuperMustBeFirstCallInConstructor"; - VarFlags[VarFlags["Constant"] = 1 << 16] = "Constant"; - VarFlags[VarFlags["MustCaptureThis"] = 1 << 17] = "MustCaptureThis"; + VarFlags[VarFlags["Private"] = 2] = "Private"; + VarFlags[VarFlags["Public"] = 4] = "Public"; + VarFlags[VarFlags["Ambient"] = 8] = "Ambient"; + VarFlags[VarFlags["Static"] = 16] = "Static"; + VarFlags[VarFlags["LocalStatic"] = 32] = "LocalStatic"; + VarFlags[VarFlags["GetAccessor"] = 64] = "GetAccessor"; + VarFlags[VarFlags["SetAccessor"] = 128] = "SetAccessor"; + VarFlags[VarFlags["AutoInit"] = 256] = "AutoInit"; + VarFlags[VarFlags["Property"] = 512] = "Property"; + VarFlags[VarFlags["Readonly"] = 1024] = "Readonly"; + VarFlags[VarFlags["Class"] = 2048] = "Class"; + VarFlags[VarFlags["ClassProperty"] = 4096] = "ClassProperty"; + VarFlags[VarFlags["ClassBodyProperty"] = 8192] = "ClassBodyProperty"; + VarFlags[VarFlags["ClassConstructorProperty"] = 16384] = "ClassConstructorProperty"; + VarFlags[VarFlags["ClassSuperMustBeFirstCallInConstructor"] = 32768] = "ClassSuperMustBeFirstCallInConstructor"; + VarFlags[VarFlags["Constant"] = 65536] = "Constant"; + VarFlags[VarFlags["MustCaptureThis"] = 131072] = "MustCaptureThis"; })(TypeScript.VarFlags || (TypeScript.VarFlags = {})); var VarFlags = TypeScript.VarFlags; (function (FncFlags) { FncFlags[FncFlags["None"] = 0] = "None"; FncFlags[FncFlags["Exported"] = 1] = "Exported"; - FncFlags[FncFlags["Private"] = 1 << 1] = "Private"; - FncFlags[FncFlags["Public"] = 1 << 2] = "Public"; - FncFlags[FncFlags["Ambient"] = 1 << 3] = "Ambient"; - FncFlags[FncFlags["Static"] = 1 << 4] = "Static"; - FncFlags[FncFlags["LocalStatic"] = 1 << 5] = "LocalStatic"; - FncFlags[FncFlags["GetAccessor"] = 1 << 6] = "GetAccessor"; - FncFlags[FncFlags["SetAccessor"] = 1 << 7] = "SetAccessor"; - FncFlags[FncFlags["Definition"] = 1 << 8] = "Definition"; - FncFlags[FncFlags["Signature"] = 1 << 9] = "Signature"; - FncFlags[FncFlags["Method"] = 1 << 10] = "Method"; - FncFlags[FncFlags["HasReturnExpression"] = 1 << 11] = "HasReturnExpression"; - FncFlags[FncFlags["CallMember"] = 1 << 12] = "CallMember"; - FncFlags[FncFlags["ConstructMember"] = 1 << 13] = "ConstructMember"; - FncFlags[FncFlags["HasSelfReference"] = 1 << 14] = "HasSelfReference"; - FncFlags[FncFlags["IsFatArrowFunction"] = 1 << 15] = "IsFatArrowFunction"; - FncFlags[FncFlags["IndexerMember"] = 1 << 16] = "IndexerMember"; - FncFlags[FncFlags["IsFunctionExpression"] = 1 << 17] = "IsFunctionExpression"; - FncFlags[FncFlags["ClassMethod"] = 1 << 18] = "ClassMethod"; - FncFlags[FncFlags["ClassPropertyMethodExported"] = 1 << 19] = "ClassPropertyMethodExported"; + FncFlags[FncFlags["Private"] = 2] = "Private"; + FncFlags[FncFlags["Public"] = 4] = "Public"; + FncFlags[FncFlags["Ambient"] = 8] = "Ambient"; + FncFlags[FncFlags["Static"] = 16] = "Static"; + FncFlags[FncFlags["LocalStatic"] = 32] = "LocalStatic"; + FncFlags[FncFlags["GetAccessor"] = 64] = "GetAccessor"; + FncFlags[FncFlags["SetAccessor"] = 128] = "SetAccessor"; + FncFlags[FncFlags["Definition"] = 256] = "Definition"; + FncFlags[FncFlags["Signature"] = 512] = "Signature"; + FncFlags[FncFlags["Method"] = 1024] = "Method"; + FncFlags[FncFlags["HasReturnExpression"] = 2048] = "HasReturnExpression"; + FncFlags[FncFlags["CallMember"] = 4096] = "CallMember"; + FncFlags[FncFlags["ConstructMember"] = 8192] = "ConstructMember"; + FncFlags[FncFlags["HasSelfReference"] = 16384] = "HasSelfReference"; + FncFlags[FncFlags["IsFatArrowFunction"] = 32768] = "IsFatArrowFunction"; + FncFlags[FncFlags["IndexerMember"] = 65536] = "IndexerMember"; + FncFlags[FncFlags["IsFunctionExpression"] = 131072] = "IsFunctionExpression"; + FncFlags[FncFlags["ClassMethod"] = 262144] = "ClassMethod"; + FncFlags[FncFlags["ClassPropertyMethodExported"] = 524288] = "ClassPropertyMethodExported"; })(TypeScript.FncFlags || (TypeScript.FncFlags = {})); var FncFlags = TypeScript.FncFlags; (function (SignatureFlags) { SignatureFlags[SignatureFlags["None"] = 0] = "None"; SignatureFlags[SignatureFlags["IsIndexer"] = 1] = "IsIndexer"; - SignatureFlags[SignatureFlags["IsStringIndexer"] = 1 << 1] = "IsStringIndexer"; - SignatureFlags[SignatureFlags["IsNumberIndexer"] = 1 << 2] = "IsNumberIndexer"; + SignatureFlags[SignatureFlags["IsStringIndexer"] = 2] = "IsStringIndexer"; + SignatureFlags[SignatureFlags["IsNumberIndexer"] = 4] = "IsNumberIndexer"; })(TypeScript.SignatureFlags || (TypeScript.SignatureFlags = {})); var SignatureFlags = TypeScript.SignatureFlags; function ToDeclFlags(fncOrVarOrSymbolOrModuleFlags) { @@ -477,24 +477,24 @@ var TypeScript; (function (TypeFlags) { TypeFlags[TypeFlags["None"] = 0] = "None"; TypeFlags[TypeFlags["HasImplementation"] = 1] = "HasImplementation"; - TypeFlags[TypeFlags["HasSelfReference"] = 1 << 1] = "HasSelfReference"; - TypeFlags[TypeFlags["MergeResult"] = 1 << 2] = "MergeResult"; - TypeFlags[TypeFlags["IsEnum"] = 1 << 3] = "IsEnum"; - TypeFlags[TypeFlags["BuildingName"] = 1 << 4] = "BuildingName"; - TypeFlags[TypeFlags["HasBaseType"] = 1 << 5] = "HasBaseType"; - TypeFlags[TypeFlags["HasBaseTypeOfObject"] = 1 << 6] = "HasBaseTypeOfObject"; - TypeFlags[TypeFlags["IsClass"] = 1 << 7] = "IsClass"; + TypeFlags[TypeFlags["HasSelfReference"] = 2] = "HasSelfReference"; + TypeFlags[TypeFlags["MergeResult"] = 4] = "MergeResult"; + TypeFlags[TypeFlags["IsEnum"] = 8] = "IsEnum"; + TypeFlags[TypeFlags["BuildingName"] = 16] = "BuildingName"; + TypeFlags[TypeFlags["HasBaseType"] = 32] = "HasBaseType"; + TypeFlags[TypeFlags["HasBaseTypeOfObject"] = 64] = "HasBaseTypeOfObject"; + TypeFlags[TypeFlags["IsClass"] = 128] = "IsClass"; })(TypeScript.TypeFlags || (TypeScript.TypeFlags = {})); var TypeFlags = TypeScript.TypeFlags; (function (TypeRelationshipFlags) { TypeRelationshipFlags[TypeRelationshipFlags["SuccessfulComparison"] = 0] = "SuccessfulComparison"; TypeRelationshipFlags[TypeRelationshipFlags["SourceIsNullTargetIsVoidOrUndefined"] = 1] = "SourceIsNullTargetIsVoidOrUndefined"; - TypeRelationshipFlags[TypeRelationshipFlags["RequiredPropertyIsMissing"] = 1 << 1] = "RequiredPropertyIsMissing"; - TypeRelationshipFlags[TypeRelationshipFlags["IncompatibleSignatures"] = 1 << 2] = "IncompatibleSignatures"; + TypeRelationshipFlags[TypeRelationshipFlags["RequiredPropertyIsMissing"] = 2] = "RequiredPropertyIsMissing"; + TypeRelationshipFlags[TypeRelationshipFlags["IncompatibleSignatures"] = 4] = "IncompatibleSignatures"; TypeRelationshipFlags[TypeRelationshipFlags["SourceSignatureHasTooManyParameters"] = 3] = "SourceSignatureHasTooManyParameters"; - TypeRelationshipFlags[TypeRelationshipFlags["IncompatibleReturnTypes"] = 1 << 4] = "IncompatibleReturnTypes"; - TypeRelationshipFlags[TypeRelationshipFlags["IncompatiblePropertyTypes"] = 1 << 5] = "IncompatiblePropertyTypes"; - TypeRelationshipFlags[TypeRelationshipFlags["IncompatibleParameterTypes"] = 1 << 6] = "IncompatibleParameterTypes"; + TypeRelationshipFlags[TypeRelationshipFlags["IncompatibleReturnTypes"] = 16] = "IncompatibleReturnTypes"; + TypeRelationshipFlags[TypeRelationshipFlags["IncompatiblePropertyTypes"] = 32] = "IncompatiblePropertyTypes"; + TypeRelationshipFlags[TypeRelationshipFlags["IncompatibleParameterTypes"] = 64] = "IncompatibleParameterTypes"; })(TypeScript.TypeRelationshipFlags || (TypeScript.TypeRelationshipFlags = {})); var TypeRelationshipFlags = TypeScript.TypeRelationshipFlags; (function (CodeGenTarget) { @@ -505,13 +505,13 @@ var TypeScript; (function (ModuleGenTarget) { ModuleGenTarget[ModuleGenTarget["Synchronous"] = 0] = "Synchronous"; ModuleGenTarget[ModuleGenTarget["Asynchronous"] = 1] = "Asynchronous"; - ModuleGenTarget[ModuleGenTarget["Local"] = 1 << 1] = "Local"; + ModuleGenTarget[ModuleGenTarget["Local"] = 2] = "Local"; })(TypeScript.ModuleGenTarget || (TypeScript.ModuleGenTarget = {})); var ModuleGenTarget = TypeScript.ModuleGenTarget; // Compiler defaults to generating ES5-compliant code for // - getters and setters - TypeScript.codeGenTarget = 0 /* ES3 */; - TypeScript.moduleGenTarget = 0 /* Synchronous */; + TypeScript.codeGenTarget = CodeGenTarget.ES3; + TypeScript.moduleGenTarget = ModuleGenTarget.Synchronous; TypeScript.optimizeModuleCodeGen = true; function flagsToString(e, flags) { var builder = ""; diff --git a/tests/baselines/reference/parserRealSource3.js b/tests/baselines/reference/parserRealSource3.js index cfe6800fcf547..38e9028297bc9 100644 --- a/tests/baselines/reference/parserRealSource3.js +++ b/tests/baselines/reference/parserRealSource3.js @@ -234,8 +234,8 @@ var TypeScript; NodeType[NodeType["Error"] = 104] = "Error"; NodeType[NodeType["Comment"] = 105] = "Comment"; NodeType[NodeType["Debugger"] = 106] = "Debugger"; - NodeType[NodeType["GeneralNode"] = NodeType.FuncDecl] = "GeneralNode"; - NodeType[NodeType["LastAsg"] = NodeType.AsgRs2] = "LastAsg"; + NodeType[NodeType["GeneralNode"] = 71] = "GeneralNode"; + NodeType[NodeType["LastAsg"] = 41] = "LastAsg"; })(TypeScript.NodeType || (TypeScript.NodeType = {})); var NodeType = TypeScript.NodeType; })(TypeScript || (TypeScript = {})); diff --git a/tests/baselines/reference/plusOperatorWithEnumType.js b/tests/baselines/reference/plusOperatorWithEnumType.js index 1ce6036d5ce15..39bd1777f6f0d 100644 --- a/tests/baselines/reference/plusOperatorWithEnumType.js +++ b/tests/baselines/reference/plusOperatorWithEnumType.js @@ -35,10 +35,10 @@ var ENUM1; var ResultIsNumber1 = +ENUM; var ResultIsNumber2 = +ENUM1; // enum type expressions -var ResultIsNumber3 = +0 /* "A" */; -var ResultIsNumber4 = +(ENUM[0] + 1 /* "B" */); +var ResultIsNumber3 = +ENUM1["A"]; +var ResultIsNumber4 = +(ENUM[0] + ENUM1["B"]); // miss assignment operators +ENUM; +ENUM1; -+1 /* B */; ++ENUM1.B; +ENUM, ENUM1; diff --git a/tests/baselines/reference/privacyLocalInternalReferenceImportWithExport.js b/tests/baselines/reference/privacyLocalInternalReferenceImportWithExport.js index c3c5ba3a7af61..9093787a6fc14 100644 --- a/tests/baselines/reference/privacyLocalInternalReferenceImportWithExport.js +++ b/tests/baselines/reference/privacyLocalInternalReferenceImportWithExport.js @@ -222,8 +222,8 @@ var import_public; // Usage of privacy error imports var privateUse_im_public_c_private = new import_public.im_public_c_private(); import_public.publicUse_im_public_c_private = new import_public.im_public_c_private(); - var privateUse_im_public_e_private = 0 /* Happy */; - import_public.publicUse_im_public_e_private = 1 /* Grumpy */; + var privateUse_im_public_e_private = import_public.im_public_e_private.Happy; + import_public.publicUse_im_public_e_private = import_public.im_public_e_private.Grumpy; var privateUse_im_public_f_private = import_public.im_public_f_private(); import_public.publicUse_im_public_f_private = import_public.im_public_f_private(); var privateUse_im_public_v_private = import_public.im_public_v_private; @@ -243,8 +243,8 @@ var import_public; // Usage of above var privateUse_im_public_c_public = new import_public.im_public_c_public(); import_public.publicUse_im_public_c_public = new import_public.im_public_c_public(); - var privateUse_im_public_e_public = 0 /* Happy */; - import_public.publicUse_im_public_e_public = 1 /* Grumpy */; + var privateUse_im_public_e_public = import_public.im_public_e_public.Happy; + import_public.publicUse_im_public_e_public = import_public.im_public_e_public.Grumpy; var privateUse_im_public_f_public = import_public.im_public_f_public(); import_public.publicUse_im_public_f_public = import_public.im_public_f_public(); var privateUse_im_public_v_public = import_public.im_public_v_public; @@ -267,8 +267,8 @@ var import_private; // Usage of above decls var privateUse_im_private_c_private = new import_private.im_private_c_private(); import_private.publicUse_im_private_c_private = new import_private.im_private_c_private(); - var privateUse_im_private_e_private = 0 /* Happy */; - import_private.publicUse_im_private_e_private = 1 /* Grumpy */; + var privateUse_im_private_e_private = import_private.im_private_e_private.Happy; + import_private.publicUse_im_private_e_private = import_private.im_private_e_private.Grumpy; var privateUse_im_private_f_private = import_private.im_private_f_private(); import_private.publicUse_im_private_f_private = import_private.im_private_f_private(); var privateUse_im_private_v_private = import_private.im_private_v_private; @@ -288,8 +288,8 @@ var import_private; // Usage of no privacy error imports var privateUse_im_private_c_public = new import_private.im_private_c_public(); import_private.publicUse_im_private_c_public = new import_private.im_private_c_public(); - var privateUse_im_private_e_public = 0 /* Happy */; - import_private.publicUse_im_private_e_public = 1 /* Grumpy */; + var privateUse_im_private_e_public = import_private.im_private_e_public.Happy; + import_private.publicUse_im_private_e_public = import_private.im_private_e_public.Grumpy; var privateUse_im_private_f_public = import_private.im_private_f_public(); import_private.publicUse_im_private_f_public = import_private.im_private_f_public(); var privateUse_im_private_v_public = import_private.im_private_v_public; diff --git a/tests/baselines/reference/privacyLocalInternalReferenceImportWithoutExport.js b/tests/baselines/reference/privacyLocalInternalReferenceImportWithoutExport.js index 9dae3ce7ce9b0..f3b8da0de825e 100644 --- a/tests/baselines/reference/privacyLocalInternalReferenceImportWithoutExport.js +++ b/tests/baselines/reference/privacyLocalInternalReferenceImportWithoutExport.js @@ -223,8 +223,8 @@ define(["require", "exports"], function (require, exports) { // Usage of above decls var privateUse_im_private_c_private = new im_private_c_private(); import_public.publicUse_im_private_c_private = new im_private_c_private(); - var privateUse_im_private_e_private = 0 /* Happy */; - import_public.publicUse_im_private_e_private = 1 /* Grumpy */; + var privateUse_im_private_e_private = im_private_e_private.Happy; + import_public.publicUse_im_private_e_private = im_private_e_private.Grumpy; var privateUse_im_private_f_private = im_private_f_private(); import_public.publicUse_im_private_f_private = im_private_f_private(); var privateUse_im_private_v_private = im_private_v_private; @@ -244,8 +244,8 @@ define(["require", "exports"], function (require, exports) { // Usage of above decls var privateUse_im_private_c_public = new im_private_c_public(); import_public.publicUse_im_private_c_public = new im_private_c_public(); - var privateUse_im_private_e_public = 0 /* Happy */; - import_public.publicUse_im_private_e_public = 1 /* Grumpy */; + var privateUse_im_private_e_public = im_private_e_public.Happy; + import_public.publicUse_im_private_e_public = im_private_e_public.Grumpy; var privateUse_im_private_f_public = im_private_f_public(); import_public.publicUse_im_private_f_public = im_private_f_public(); var privateUse_im_private_v_public = im_private_v_public; @@ -268,8 +268,8 @@ define(["require", "exports"], function (require, exports) { // Usage of above decls var privateUse_im_private_c_private = new im_private_c_private(); import_private.publicUse_im_private_c_private = new im_private_c_private(); - var privateUse_im_private_e_private = 0 /* Happy */; - import_private.publicUse_im_private_e_private = 1 /* Grumpy */; + var privateUse_im_private_e_private = im_private_e_private.Happy; + import_private.publicUse_im_private_e_private = im_private_e_private.Grumpy; var privateUse_im_private_f_private = im_private_f_private(); import_private.publicUse_im_private_f_private = im_private_f_private(); var privateUse_im_private_v_private = im_private_v_private; @@ -289,8 +289,8 @@ define(["require", "exports"], function (require, exports) { // Usage of above decls var privateUse_im_private_c_public = new im_private_c_public(); import_private.publicUse_im_private_c_public = new im_private_c_public(); - var privateUse_im_private_e_public = 0 /* Happy */; - import_private.publicUse_im_private_e_public = 1 /* Grumpy */; + var privateUse_im_private_e_public = im_private_e_public.Happy; + import_private.publicUse_im_private_e_public = im_private_e_public.Grumpy; var privateUse_im_private_f_public = im_private_f_public(); import_private.publicUse_im_private_f_public = im_private_f_public(); var privateUse_im_private_v_public = im_private_v_public; diff --git a/tests/baselines/reference/privacyTopLevelInternalReferenceImportWithExport.js b/tests/baselines/reference/privacyTopLevelInternalReferenceImportWithExport.js index 54f018fe47500..e73e398d437b8 100644 --- a/tests/baselines/reference/privacyTopLevelInternalReferenceImportWithExport.js +++ b/tests/baselines/reference/privacyTopLevelInternalReferenceImportWithExport.js @@ -168,8 +168,8 @@ define(["require", "exports"], function (require, exports) { // Usage of privacy error imports var privateUse_im_public_c_private = new exports.im_public_c_private(); exports.publicUse_im_public_c_private = new exports.im_public_c_private(); - var privateUse_im_public_e_private = 0 /* Happy */; - exports.publicUse_im_public_e_private = 1 /* Grumpy */; + var privateUse_im_public_e_private = exports.im_public_e_private.Happy; + exports.publicUse_im_public_e_private = exports.im_public_e_private.Grumpy; var privateUse_im_public_f_private = exports.im_public_f_private(); exports.publicUse_im_public_f_private = exports.im_public_f_private(); var privateUse_im_public_v_private = exports.im_public_v_private; @@ -189,8 +189,8 @@ define(["require", "exports"], function (require, exports) { // Usage of above decls var privateUse_im_public_c_public = new exports.im_public_c_public(); exports.publicUse_im_public_c_public = new exports.im_public_c_public(); - var privateUse_im_public_e_public = 0 /* Happy */; - exports.publicUse_im_public_e_public = 1 /* Grumpy */; + var privateUse_im_public_e_public = exports.im_public_e_public.Happy; + exports.publicUse_im_public_e_public = exports.im_public_e_public.Grumpy; var privateUse_im_public_f_public = exports.im_public_f_public(); exports.publicUse_im_public_f_public = exports.im_public_f_public(); var privateUse_im_public_v_public = exports.im_public_v_public; diff --git a/tests/baselines/reference/privacyTopLevelInternalReferenceImportWithoutExport.js b/tests/baselines/reference/privacyTopLevelInternalReferenceImportWithoutExport.js index d2f051bf331ac..11cd8c260b719 100644 --- a/tests/baselines/reference/privacyTopLevelInternalReferenceImportWithoutExport.js +++ b/tests/baselines/reference/privacyTopLevelInternalReferenceImportWithoutExport.js @@ -169,8 +169,8 @@ define(["require", "exports"], function (require, exports) { // Usage of above decls var privateUse_im_private_c_private = new im_private_c_private(); exports.publicUse_im_private_c_private = new im_private_c_private(); - var privateUse_im_private_e_private = 0 /* Happy */; - exports.publicUse_im_private_e_private = 1 /* Grumpy */; + var privateUse_im_private_e_private = im_private_e_private.Happy; + exports.publicUse_im_private_e_private = im_private_e_private.Grumpy; var privateUse_im_private_f_private = im_private_f_private(); exports.publicUse_im_private_f_private = im_private_f_private(); var privateUse_im_private_v_private = im_private_v_private; @@ -190,8 +190,8 @@ define(["require", "exports"], function (require, exports) { // Usage of above decls var privateUse_im_private_c_public = new im_private_c_public(); exports.publicUse_im_private_c_public = new im_private_c_public(); - var privateUse_im_private_e_public = 0 /* Happy */; - exports.publicUse_im_private_e_public = 1 /* Grumpy */; + var privateUse_im_private_e_public = im_private_e_public.Happy; + exports.publicUse_im_private_e_public = im_private_e_public.Grumpy; var privateUse_im_private_f_public = im_private_f_public(); exports.publicUse_im_private_f_public = im_private_f_public(); var privateUse_im_private_v_public = im_private_v_public; diff --git a/tests/baselines/reference/propertyAccess.js b/tests/baselines/reference/propertyAccess.js index 735c8d3908f3c..9295ce43b266a 100644 --- a/tests/baselines/reference/propertyAccess.js +++ b/tests/baselines/reference/propertyAccess.js @@ -177,7 +177,7 @@ var Compass; Compass[Compass["West"] = 3] = "West"; })(Compass || (Compass = {})); var numIndex = { 3: 'three', 'three': 'three' }; -var strIndex = { 'N': 0 /* North */, 'E': 2 /* East */ }; +var strIndex = { 'N': Compass.North, 'E': Compass.East }; var bothIndex; function noIndex() { } var obj = { @@ -216,7 +216,7 @@ var gg; var hh = numIndex[3.0]; var hh; // Bracket notation property access using enum value on type with numeric index signature -var ii = numIndex[1 /* South */]; +var ii = numIndex[Compass.South]; var ii; // Bracket notation property access using value of type 'any' on type with numeric index signature var jj = numIndex[anyVar]; @@ -235,7 +235,7 @@ var mm2; var nn = strIndex[10]; var nn; // Bracket notation property access using enum value on type with string index signature and no numeric index signature -var oo = strIndex[2 /* East */]; +var oo = strIndex[Compass.East]; var oo; // Bracket notation property access using value of type 'any' on type with string index signature and no numeric index signature var pp = strIndex[null]; @@ -247,7 +247,7 @@ var qq; var rr = noIndex['zzzz']; var rr; // Bracket notation property access using enum value on type with no index signatures -var ss = noIndex[1 /* South */]; +var ss = noIndex[Compass.South]; var ss; // Bracket notation property access using value of type 'any' on type with no index signatures var tt = noIndex[null]; @@ -258,7 +258,7 @@ var uu = noIndex[someObject]; // Error var vv = noIndex[32]; var vv; // Bracket notation property access using enum value on type with numeric index signature and string index signature -var ww = bothIndex[2 /* East */]; +var ww = bothIndex[Compass.East]; var ww; // Bracket notation property access using value of type 'any' on type with numeric index signature and string index signature var xx = bothIndex[null]; diff --git a/tests/baselines/reference/propertyNamesOfReservedWords.js b/tests/baselines/reference/propertyNamesOfReservedWords.js index 471787f43ee13..b2332345712e3 100644 --- a/tests/baselines/reference/propertyNamesOfReservedWords.js +++ b/tests/baselines/reference/propertyNamesOfReservedWords.js @@ -357,5 +357,5 @@ var E; E[E["while"] = 61] = "while"; E[E["with"] = 62] = "with"; })(E || (E = {})); -var r7 = 0 /* abstract */; -var r8 = 1 /* as */; +var r7 = E.abstract; +var r8 = E.as; diff --git a/tests/baselines/reference/sourceMapValidationEnums.js.map b/tests/baselines/reference/sourceMapValidationEnums.js.map index 1627788c6b6db..4729c3749b338 100644 --- a/tests/baselines/reference/sourceMapValidationEnums.js.map +++ b/tests/baselines/reference/sourceMapValidationEnums.js.map @@ -1,2 +1,2 @@ //// [sourceMapValidationEnums.js.map] -{"version":3,"file":"sourceMapValidationEnums.js","sourceRoot":"","sources":["sourceMapValidationEnums.ts"],"names":["e","e2","e3"],"mappings":"AAAA,IAAK,CAIJ;AAJD,WAAK,CAAC;IACFA,mBAACA,CAAAA;IACDA,mBAACA,CAAAA;IACDA,mBAACA,CAAAA;AACLA,CAACA,EAJI,CAAC,KAAD,CAAC,QAIL;AACD,IAAK,EAKJ;AALD,WAAK,EAAE;IACHC,aAAIA,EAAEA,OAAAA,CAAAA;IACNA,aAAIA,EAAEA,OAAAA,CAAAA;IACNA,sBAACA,CAAAA;IACDA,wBAAEA,CAAAA;AACNA,CAACA,EALI,EAAE,KAAF,EAAE,QAKN;AACD,IAAK,EACJ;AADD,WAAK,EAAE;AACPC,CAACA,EADI,EAAE,KAAF,EAAE,QACN"} \ No newline at end of file +{"version":3,"file":"sourceMapValidationEnums.js","sourceRoot":"","sources":["sourceMapValidationEnums.ts"],"names":["e","e2","e3"],"mappings":"AAAA,IAAK,CAIJ;AAJD,WAAK,CAAC;IACFA,mBAACA,CAAAA;IACDA,mBAACA,CAAAA;IACDA,mBAACA,CAAAA;AACLA,CAACA,EAJI,CAAC,KAAD,CAAC,QAIL;AACD,IAAK,EAKJ;AALD,WAAK,EAAE;IACHC,sBAAMA,CAAAA;IACNA,sBAAMA,CAAAA;IACNA,sBAACA,CAAAA;IACDA,wBAAEA,CAAAA;AACNA,CAACA,EALI,EAAE,KAAF,EAAE,QAKN;AACD,IAAK,EACJ;AADD,WAAK,EAAE;AACPC,CAACA,EADI,EAAE,KAAF,EAAE,QACN"} \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationEnums.sourcemap.txt b/tests/baselines/reference/sourceMapValidationEnums.sourcemap.txt index 337aa0989d3b6..9d8b36ca5ed3b 100644 --- a/tests/baselines/reference/sourceMapValidationEnums.sourcemap.txt +++ b/tests/baselines/reference/sourceMapValidationEnums.sourcemap.txt @@ -134,41 +134,29 @@ sourceFile:sourceMapValidationEnums.ts --- >>> e2[e2["x"] = 10] = "x"; 1->^^^^ -2 > ^^^^^^^^^^^^^ -3 > ^^ -4 > ^^^^^^^ -5 > ^ -6 > ^-> +2 > ^^^^^^^^^^^^^^^^^^^^^^ +3 > ^ +4 > ^-> 1-> { > -2 > x = -3 > 10 -4 > -5 > +2 > x = 10 +3 > 1->Emitted(9, 5) Source(7, 5) + SourceIndex(0) name (e2) -2 >Emitted(9, 18) Source(7, 9) + SourceIndex(0) name (e2) -3 >Emitted(9, 20) Source(7, 11) + SourceIndex(0) name (e2) -4 >Emitted(9, 27) Source(7, 11) + SourceIndex(0) name (e2) -5 >Emitted(9, 28) Source(7, 11) + SourceIndex(0) name (e2) +2 >Emitted(9, 27) Source(7, 11) + SourceIndex(0) name (e2) +3 >Emitted(9, 28) Source(7, 11) + SourceIndex(0) name (e2) --- >>> e2[e2["y"] = 10] = "y"; 1->^^^^ -2 > ^^^^^^^^^^^^^ -3 > ^^ -4 > ^^^^^^^ -5 > ^ -6 > ^-> +2 > ^^^^^^^^^^^^^^^^^^^^^^ +3 > ^ +4 > ^-> 1->, > -2 > y = -3 > 10 -4 > -5 > +2 > y = 10 +3 > 1->Emitted(10, 5) Source(8, 5) + SourceIndex(0) name (e2) -2 >Emitted(10, 18) Source(8, 9) + SourceIndex(0) name (e2) -3 >Emitted(10, 20) Source(8, 11) + SourceIndex(0) name (e2) -4 >Emitted(10, 27) Source(8, 11) + SourceIndex(0) name (e2) -5 >Emitted(10, 28) Source(8, 11) + SourceIndex(0) name (e2) +2 >Emitted(10, 27) Source(8, 11) + SourceIndex(0) name (e2) +3 >Emitted(10, 28) Source(8, 11) + SourceIndex(0) name (e2) --- >>> e2[e2["z"] = 11] = "z"; 1->^^^^ diff --git a/tests/baselines/reference/subtypesOfTypeParameter.js b/tests/baselines/reference/subtypesOfTypeParameter.js index 7d739132a7701..7fe3d28278b3b 100644 --- a/tests/baselines/reference/subtypesOfTypeParameter.js +++ b/tests/baselines/reference/subtypesOfTypeParameter.js @@ -191,8 +191,8 @@ function f2(x, y) { var r12 = true ? x : c2; var r13 = true ? E : x; var r13 = true ? x : E; - var r14 = true ? 0 /* A */ : x; - var r14 = true ? x : 0 /* A */; + var r14 = true ? E.A : x; + var r14 = true ? x : E.A; var af; var r15 = true ? af : x; var r15 = true ? x : af; diff --git a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints2.js b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints2.js index df4511fb7ad20..e1c137f77e4ab 100644 --- a/tests/baselines/reference/subtypesOfTypeParameterWithConstraints2.js +++ b/tests/baselines/reference/subtypesOfTypeParameterWithConstraints2.js @@ -270,8 +270,8 @@ function f15(x) { function f16(x) { var r13 = true ? E : x; // ok var r13 = true ? x : E; // ok - var r14 = true ? 0 /* A */ : x; // ok - var r14 = true ? x : 0 /* A */; // ok + var r14 = true ? E.A : x; // ok + var r14 = true ? x : E.A; // ok } function f17(x) { var af; diff --git a/tests/baselines/reference/typeAliases.js b/tests/baselines/reference/typeAliases.js index 0cf0dd9240270..c31a52bff4503 100644 --- a/tests/baselines/reference/typeAliases.js +++ b/tests/baselines/reference/typeAliases.js @@ -119,7 +119,7 @@ var E; (function (E) { E[E["x"] = 10] = "x"; })(E || (E = {})); -f15(10 /* x */).toLowerCase(); +f15(E.x).toLowerCase(); var x; f16(x); var y = ["1", false]; diff --git a/tests/baselines/reference/typeArgumentInferenceWithObjectLiteral.js b/tests/baselines/reference/typeArgumentInferenceWithObjectLiteral.js index 8e2445d249c27..4d040cfe13f76 100644 --- a/tests/baselines/reference/typeArgumentInferenceWithObjectLiteral.js +++ b/tests/baselines/reference/typeArgumentInferenceWithObjectLiteral.js @@ -58,8 +58,8 @@ var E2; })(E2 || (E2 = {})); var v1; var v1 = f1({ w: function (x) { return x; }, r: function () { return 0; } }, 0); -var v1 = f1({ w: function (x) { return x; }, r: function () { return 0; } }, 0 /* X */); -var v1 = f1({ w: function (x) { return x; }, r: function () { return 0 /* X */; } }, 0); +var v1 = f1({ w: function (x) { return x; }, r: function () { return 0; } }, E1.X); +var v1 = f1({ w: function (x) { return x; }, r: function () { return E1.X; } }, 0); var v2; -var v2 = f1({ w: function (x) { return x; }, r: function () { return 0 /* X */; } }, 0 /* X */); -var v3 = f1({ w: function (x) { return x; }, r: function () { return 0 /* X */; } }, 0 /* X */); // Error +var v2 = f1({ w: function (x) { return x; }, r: function () { return E1.X; } }, E1.X); +var v3 = f1({ w: function (x) { return x; }, r: function () { return E1.X; } }, E2.X); // Error diff --git a/tests/baselines/reference/typeofEnum.js b/tests/baselines/reference/typeofEnum.js index 388c6250aef41..b8286fac7135f 100644 --- a/tests/baselines/reference/typeofEnum.js +++ b/tests/baselines/reference/typeofEnum.js @@ -14,4 +14,4 @@ var E; E[E["e2"] = 1] = "e2"; })(E || (E = {})); var e1; -0 /* e1 */; +e1.e1; diff --git a/tests/baselines/reference/typeofOperatorWithEnumType.js b/tests/baselines/reference/typeofOperatorWithEnumType.js index 900b610cef463..2e2963b0955aa 100644 --- a/tests/baselines/reference/typeofOperatorWithEnumType.js +++ b/tests/baselines/reference/typeofOperatorWithEnumType.js @@ -44,15 +44,15 @@ var ENUM1; var ResultIsString1 = typeof ENUM; var ResultIsString2 = typeof ENUM1; // enum type expressions -var ResultIsString3 = typeof 0 /* "A" */; -var ResultIsString4 = typeof (ENUM[0] + 1 /* "B" */); +var ResultIsString3 = typeof ENUM1["A"]; +var ResultIsString4 = typeof (ENUM[0] + ENUM1["B"]); // multiple typeof operators var ResultIsString5 = typeof typeof ENUM; -var ResultIsString6 = typeof typeof typeof (ENUM[0] + 1 /* B */); +var ResultIsString6 = typeof typeof typeof (ENUM[0] + ENUM1.B); // miss assignment operators typeof ENUM; typeof ENUM1; -typeof 1 /* "B" */; +typeof ENUM1["B"]; typeof ENUM, ENUM1; // use typeof in type query var z; diff --git a/tests/baselines/reference/unaryPlus.js b/tests/baselines/reference/unaryPlus.js index 7daf873c32403..bc070c9655bac 100644 --- a/tests/baselines/reference/unaryPlus.js +++ b/tests/baselines/reference/unaryPlus.js @@ -21,7 +21,7 @@ var E; E[E["thing"] = 1] = "thing"; })(E || (E = {})); ; -var c = +0 /* some */; +var c = +E.some; // also allowed, used to be errors var x = +"3"; //should be valid var y = -"3"; // should be valid diff --git a/tests/baselines/reference/validEnumAssignments.js b/tests/baselines/reference/validEnumAssignments.js index 1d733882800d5..4cb975c42e424 100644 --- a/tests/baselines/reference/validEnumAssignments.js +++ b/tests/baselines/reference/validEnumAssignments.js @@ -36,13 +36,13 @@ var n; var a; var e; n = e; -n = 0 /* A */; +n = E.A; a = n; a = e; -a = 0 /* A */; +a = E.A; e = e; -e = 0 /* A */; -e = 1 /* B */; +e = E.A; +e = E.B; e = n; e = null; e = undefined; diff --git a/tests/baselines/reference/validNullAssignments.js b/tests/baselines/reference/validNullAssignments.js index 896e888b28f7c..46ef380746499 100644 --- a/tests/baselines/reference/validNullAssignments.js +++ b/tests/baselines/reference/validNullAssignments.js @@ -41,7 +41,7 @@ var E; (function (E) { E[E["A"] = 0] = "A"; })(E || (E = {})); -0 /* A */ = null; // error +E.A = null; // error var C = (function () { function C() { } diff --git a/tests/baselines/reference/validNumberAssignments.js b/tests/baselines/reference/validNumberAssignments.js index ec15502afa411..e81a5fd1ecb97 100644 --- a/tests/baselines/reference/validNumberAssignments.js +++ b/tests/baselines/reference/validNumberAssignments.js @@ -20,5 +20,5 @@ var E; })(E || (E = {})); ; var d = x; -var e = 0 /* A */; +var e = E.A; e = x; diff --git a/tests/baselines/reference/voidOperatorWithEnumType.js b/tests/baselines/reference/voidOperatorWithEnumType.js index 478ac85651b4d..d11245b3475b9 100644 --- a/tests/baselines/reference/voidOperatorWithEnumType.js +++ b/tests/baselines/reference/voidOperatorWithEnumType.js @@ -39,13 +39,13 @@ var ENUM1; var ResultIsAny1 = void ENUM; var ResultIsAny2 = void ENUM1; // enum type expressions -var ResultIsAny3 = void 0 /* "A" */; -var ResultIsAny4 = void (ENUM[0] + 1 /* "B" */); +var ResultIsAny3 = void ENUM1["A"]; +var ResultIsAny4 = void (ENUM[0] + ENUM1["B"]); // multiple void operators var ResultIsAny5 = void void ENUM; -var ResultIsAny6 = void void void (ENUM[0] + 1 /* B */); +var ResultIsAny6 = void void void (ENUM[0] + ENUM1.B); // miss assignment operators void ENUM; void ENUM1; -void 1 /* "B" */; +void ENUM1["B"]; void ENUM, ENUM1; From 033a83d44ae91c8014a846dc5e81920e3bb13748 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 10 Mar 2015 12:12:41 -0700 Subject: [PATCH 018/224] Basic emit for class constructor without static property assignment --- src/compiler/checker.ts | 4 +- src/compiler/emitter.ts | 145 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 142 insertions(+), 7 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8908501593cf3..135cecca73064 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9273,7 +9273,9 @@ module ts { var staticType = getTypeOfSymbol(symbol); var baseTypeNode = getClassBaseTypeNode(node); if (baseTypeNode) { - emitExtends = emitExtends || !isInAmbientContext(node); + if (languageVersion < ScriptTarget.ES6) { + emitExtends = emitExtends || !isInAmbientContext(node); + } checkTypeReference(baseTypeNode); } if (type.baseTypes.length) { diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 8947314a6f685..fc5479144eb0c 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3169,14 +3169,19 @@ module ts { } var superCall = false; if (node.expression.kind === SyntaxKind.SuperKeyword) { - write("_super"); + if (languageVersion < ScriptTarget.ES6) { + write("_super"); + } + else { + write("super"); + } superCall = true; } else { emit(node.expression); superCall = node.expression.kind === SyntaxKind.PropertyAccessExpression && (node.expression).expression.kind === SyntaxKind.SuperKeyword; } - if (superCall) { + if (superCall && languageVersion < ScriptTarget.ES6) { write(".call("); emitThis(node.expression); if (node.arguments.length) { @@ -3185,6 +3190,13 @@ module ts { } write(")"); } + else if (superCall && languageVersion >= ScriptTarget.ES6) { + write("("); + if (node.arguments.length) { + emitCommaList(node.arguments); + } + write(")"); + } else { write("("); emitCommaList(node.arguments); @@ -4502,7 +4514,128 @@ module ts { }); } - function emitClassDeclaration(node: ClassDeclaration) { + function emitConstructorOfClass(node: ClassDeclaration, baseTypeNode: TypeReferenceNode) { + var saveTempCount = tempCount; + var saveTempVariables = tempVariables; + var saveTempParameters = tempParameters; + tempCount = 0; + tempVariables = undefined; + tempParameters = undefined; + + var popFrame = enterNameScope(); + + // Emit the constructor overload pinned comments + forEach(node.members, member => { + if (member.kind === SyntaxKind.Constructor && !(member).body) { + emitPinnedOrTripleSlashComments(member); + } + }); + + var ctor = getFirstConstructorWithBody(node); + if (ctor) { + emitLeadingComments(ctor); + } + emitStart(ctor || node); + + if (languageVersion < ScriptTarget.ES6) { + write("function "); + emitDeclarationName(node); + emitSignatureParameters(ctor); + } + else { + Debug.assert(languageVersion >= ScriptTarget.ES6, "Expected Script Target to be ES6 or above"); + write("constructor"); + if (ctor) { + emitSignatureParameters(ctor); + } + else { + // Based on EcmaScript6 section 14.15.14: Runtime Semantics: ClassDefinitionEvaluation. + // If constructor is empty, then, + // If ClassHeritageopt is present, then + // Let constructor be the result of parsing the String "constructor(... args){ super (...args);}" using the syntactic grammar with the goal symbol MethodDefinition. + // Else, + // Let constructor be the result of parsing the String "constructor( ){ }" using the syntactic grammar with the goal symbol MethodDefinition + if (baseTypeNode) { + write("(...args)"); + } + else { + write("()"); + } + } + } + write(" {"); + scopeEmitStart(node, "constructor"); + increaseIndent(); + if (ctor) { + emitDetachedComments((ctor.body).statements); + } + emitCaptureThisForNodeIfNecessary(node); + if (ctor) { + emitDefaultValueAssignments(ctor); + emitRestParameter(ctor); + if (baseTypeNode) { + var superCall = findInitialSuperCall(ctor); + if (superCall) { + writeLine(); + emit(superCall); + } + } + emitParameterPropertyAssignments(ctor); + } + else { + if (baseTypeNode) { + writeLine(); + emitStart(baseTypeNode); + languageVersion < ScriptTarget.ES6 ? write("_super.apply(this, arguments);") : write("super(...args);"); + emitEnd(baseTypeNode); + } + } + emitMemberAssignments(node, /*nonstatic*/0); + if (ctor) { + var statements: Node[] = (ctor.body).statements; + if (superCall) statements = statements.slice(1); + emitLines(statements); + } + emitTempDeclarations(/*newLine*/ true); + writeLine(); + if (ctor) { + emitLeadingCommentsOfPosition((ctor.body).statements.end); + } + decreaseIndent(); + emitToken(SyntaxKind.CloseBraceToken, ctor ? (ctor.body).statements.end : node.members.end); + scopeEmitEnd(); + emitEnd(ctor || node); + if (ctor) { + emitTrailingComments(ctor); + } + + exitNameScope(popFrame); + + tempCount = saveTempCount; + tempVariables = saveTempVariables; + tempParameters = saveTempParameters; + } + + function emitClassDeclarationAboveES6(node: ClassDeclaration) { + write("class "); + emitDeclarationName(node); + var baseTypeNode = getClassBaseTypeNode(node); + if (baseTypeNode) { + write(" extends "); + emitDeclarationName(node); + } + write(" {"); + increaseIndent(); + scopeEmitStart(node); + writeLine(); + emitConstructorOfClass(node, baseTypeNode); + writeLine(); + scopeEmitEnd(); + decreaseIndent(); + write("}"); + } + + function emitClassDeclarationBelowES6(node: ClassDeclaration) { write("var "); emitDeclarationName(node); write(" = (function ("); @@ -4522,7 +4655,7 @@ module ts { emitEnd(baseTypeNode); } writeLine(); - emitConstructorOfClass(); + emitConstructorOfClass(node, baseTypeNode); emitMemberFunctions(node); emitMemberAssignments(node, NodeFlags.Static); writeLine(); @@ -4555,7 +4688,7 @@ module ts { emitExportMemberAssignments(node.name); } - function emitConstructorOfClass() { + function emitConstructorOfClassOLD() { var saveTempCount = tempCount; var saveTempVariables = tempVariables; var saveTempParameters = tempParameters; @@ -5352,7 +5485,7 @@ module ts { case SyntaxKind.VariableDeclaration: return emitVariableDeclaration(node); case SyntaxKind.ClassDeclaration: - return emitClassDeclaration(node); + return languageVersion < ScriptTarget.ES6 ? emitClassDeclarationBelowES6(node) : emitClassDeclarationAboveES6(node); case SyntaxKind.InterfaceDeclaration: return emitInterfaceDeclaration(node); case SyntaxKind.EnumDeclaration: From d3205ef9551ccc015a48bb37d3d4d4dfc457cb1c Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 10 Mar 2015 15:21:38 -0700 Subject: [PATCH 019/224] Remove redundant sourcemap span and comment. Differentiate between emit for below ES6 and above ES6 --- src/compiler/emitter.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index fc5479144eb0c..15b51ea206811 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4436,7 +4436,7 @@ module ts { }); } - function emitMemberFunctions(node: ClassDeclaration) { + function emitMemberFunctionsBelowES6(node: ClassDeclaration) { forEach(node.members, member => { if (member.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature) { if (!(member).body) { @@ -4446,19 +4446,14 @@ module ts { writeLine(); emitLeadingComments(member); emitStart(member); - emitStart((member).name); emitDeclarationName(node); if (!(member.flags & NodeFlags.Static)) { write(".prototype"); } emitMemberAccessForPropertyName((member).name); - emitEnd((member).name); write(" = "); - // TODO (drosen): Should we performing emitStart twice on emitStart(member)? - emitStart(member); emitFunctionDeclaration(member); emitEnd(member); - emitEnd(member); write(";"); emitTrailingComments(member); } @@ -4656,7 +4651,7 @@ module ts { } writeLine(); emitConstructorOfClass(node, baseTypeNode); - emitMemberFunctions(node); + emitMemberFunctionsBelowES6(node); emitMemberAssignments(node, NodeFlags.Static); writeLine(); emitToken(SyntaxKind.CloseBraceToken, node.members.end, () => { From 8576282975d2124139d618ec515276bfd157be1a Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 10 Mar 2015 15:41:41 -0700 Subject: [PATCH 020/224] Emit non-getter/setter member function --- src/compiler/emitter.ts | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 15b51ea206811..8047d911ca70a 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4407,7 +4407,9 @@ module ts { emitComputedPropertyName(memberName); } else { - write("."); + if (languageVersion < ScriptTarget.ES6) { + write("."); + } emitNodeWithoutSourceMap(memberName); } } @@ -4509,6 +4511,27 @@ module ts { }); } + function emitMemberFunctionsAboveES6(node: ClassDeclaration) { + forEach(node.members, member => { + if (member.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature) { + if (!(member).body) { + return emitPinnedOrTripleSlashComments(member); + } + + writeLine(); + emitLeadingComments(member); + emitStart(member); + if (member.flags & NodeFlags.Static) { + write("static "); + } + emitMemberAccessForPropertyName((member).name); + emitSignatureAndBody(member); + emitEnd(member); + emitTrailingComments(member); + } + }); + } + function emitConstructorOfClass(node: ClassDeclaration, baseTypeNode: TypeReferenceNode) { var saveTempCount = tempCount; var saveTempVariables = tempVariables; @@ -4624,6 +4647,7 @@ module ts { scopeEmitStart(node); writeLine(); emitConstructorOfClass(node, baseTypeNode); + emitMemberFunctionsAboveES6(node); writeLine(); scopeEmitEnd(); decreaseIndent(); From 1b84f1d1d09f57cde9d02c49f8b07b7cb05c8a83 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 10 Mar 2015 17:22:33 -0700 Subject: [PATCH 021/224] emit get/set member function --- src/compiler/emitter.ts | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 8047d911ca70a..db1cdee432c25 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4465,15 +4465,12 @@ module ts { writeLine(); emitStart(member); write("Object.defineProperty("); - emitStart((member).name); emitDeclarationName(node); if (!(member.flags & NodeFlags.Static)) { write(".prototype"); } write(", "); - // TODO: Shouldn't emitStart on name occur *here*? emitExpressionForPropertyName((member).name); - emitEnd((member).name); write(", {"); increaseIndent(); if (accessors.getAccessor) { @@ -4529,6 +4526,36 @@ module ts { emitEnd(member); emitTrailingComments(member); } + else if (member.kind === SyntaxKind.GetAccessor || member.kind === SyntaxKind.SetAccessor) { + var accessors = getAllAccessorDeclarations(node.members, member); + if (member === accessors.firstAccessor) { + writeLine(); + if (accessors.getAccessor) { + emitLeadingComments(accessors.getAccessor); + emitStart(accessors.getAccessor); + if (member.flags & NodeFlags.Static) { + write("static "); + } + write("get "); + emitMemberAccessForPropertyName((member).name); + emitSignatureAndBody(accessors.getAccessor); + emitEnd(accessors.getAccessor); + emitTrailingComments(accessors.getAccessor); + } + else if (accessors.setAccessor) { + emitLeadingComments(accessors.setAccessor); + emitStart(accessors.setAccessor); + if (member.flags & NodeFlags.Static) { + write("static "); + } + write("set "); + emitMemberAccessForPropertyName((member).name); + emitSignatureAndBody(accessors.setAccessor); + emitEnd(accessors.setAccessor); + emitTrailingComments(accessors.setAccessor);; + } + } + } }); } @@ -4567,7 +4594,7 @@ module ts { emitSignatureParameters(ctor); } else { - // Based on EcmaScript6 section 14.15.14: Runtime Semantics: ClassDefinitionEvaluation. + // Based on EcmaScript6 section 14.5.14: Runtime Semantics: ClassDefinitionEvaluation. // If constructor is empty, then, // If ClassHeritageopt is present, then // Let constructor be the result of parsing the String "constructor(... args){ super (...args);}" using the syntactic grammar with the goal symbol MethodDefinition. From 890aa4a84de28621503b6a620b0b02b17878a3f8 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 10 Mar 2015 17:39:13 -0700 Subject: [PATCH 022/224] test cases for constructor overload, non-static property assignment, getter/setter, method, static method, --- ...DeclarationWithConstructorOverloadInES6.js | 21 +++++++ ...larationWithConstructorOverloadInES6.types | 22 ++++++++ ...nWithConstructorPropertyAssignmentInES6.js | 51 +++++++++++++++++ ...thConstructorPropertyAssignmentInES6.types | 56 +++++++++++++++++++ ...itClassDeclarationWithGetterSetterInES6.js | 38 +++++++++++++ ...lassDeclarationWithGetterSetterInES6.types | 35 ++++++++++++ .../emitClassDeclarationWithMethodInES6.js | 34 +++++++++++ .../emitClassDeclarationWithMethodInES6.types | 27 +++++++++ ...itClassDeclarationWithStaticMethodInES6.js | 37 ++++++++++++ ...lassDeclarationWithStaticMethodInES6.types | 32 +++++++++++ ...DeclarationWithConstructorOverloadInES6.ts | 11 ++++ ...nWithConstructorPropertyAssignmentInES6.ts | 25 +++++++++ ...itClassDeclarationWithGetterSetterInES6.ts | 17 ++++++ .../emitClassDeclarationWithMethodInES6.ts | 13 +++++ ...itClassDeclarationWithStaticMethodInES6.ts | 13 +++++ 15 files changed, 432 insertions(+) create mode 100644 tests/baselines/reference/emitClassDeclarationWithConstructorOverloadInES6.js create mode 100644 tests/baselines/reference/emitClassDeclarationWithConstructorOverloadInES6.types create mode 100644 tests/baselines/reference/emitClassDeclarationWithConstructorPropertyAssignmentInES6.js create mode 100644 tests/baselines/reference/emitClassDeclarationWithConstructorPropertyAssignmentInES6.types create mode 100644 tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.js create mode 100644 tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.types create mode 100644 tests/baselines/reference/emitClassDeclarationWithMethodInES6.js create mode 100644 tests/baselines/reference/emitClassDeclarationWithMethodInES6.types create mode 100644 tests/baselines/reference/emitClassDeclarationWithStaticMethodInES6.js create mode 100644 tests/baselines/reference/emitClassDeclarationWithStaticMethodInES6.types create mode 100644 tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorOverloadInES6.ts create mode 100644 tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorPropertyAssignmentInES6.ts create mode 100644 tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithGetterSetterInES6.ts create mode 100644 tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithMethodInES6.ts create mode 100644 tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithStaticMethodInES6.ts diff --git a/tests/baselines/reference/emitClassDeclarationWithConstructorOverloadInES6.js b/tests/baselines/reference/emitClassDeclarationWithConstructorOverloadInES6.js new file mode 100644 index 0000000000000..b7fe4f0cda7a1 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithConstructorOverloadInES6.js @@ -0,0 +1,21 @@ +//// [emitClassDeclarationWithConstructorOverloadInES6.ts] +class C { + constructor(y: any) + constructor(x: number) { + } +} + +class D { + constructor(y: any) + constructor(x: number, z="hello") {} +} + +//// [emitClassDeclarationWithConstructorOverloadInES6.js] +class C { + constructor(x) { + } +} +class D { + constructor(x, z = "hello") { + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithConstructorOverloadInES6.types b/tests/baselines/reference/emitClassDeclarationWithConstructorOverloadInES6.types new file mode 100644 index 0000000000000..96e9f25549e77 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithConstructorOverloadInES6.types @@ -0,0 +1,22 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorOverloadInES6.ts === +class C { +>C : C + + constructor(y: any) +>y : any + + constructor(x: number) { +>x : number + } +} + +class D { +>D : D + + constructor(y: any) +>y : any + + constructor(x: number, z="hello") {} +>x : number +>z : string +} diff --git a/tests/baselines/reference/emitClassDeclarationWithConstructorPropertyAssignmentInES6.js b/tests/baselines/reference/emitClassDeclarationWithConstructorPropertyAssignmentInES6.js new file mode 100644 index 0000000000000..4f57c6345cf56 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithConstructorPropertyAssignmentInES6.js @@ -0,0 +1,51 @@ +//// [emitClassDeclarationWithConstructorPropertyAssignmentInES6.ts] +class C { + x: string = "Hello world"; +} + +class D { + x: string = "Hello world"; + y: number; + constructor() { + this.y = 10; + } +} + +class E extends D{ + z: boolean = true; +} + +class F extends D{ + z: boolean = true; + j: string; + constructor() { + super(); + this.j = "HI"; + } +} + +//// [emitClassDeclarationWithConstructorPropertyAssignmentInES6.js] +class C { + constructor() { + thisx = "Hello world"; + } +} +class D { + constructor() { + thisx = "Hello world"; + this.y = 10; + } +} +class E extends E { + constructor(...args) { + super(...args); + thisz = true; + } +} +class F extends F { + constructor() { + super(); + thisz = true; + this.j = "HI"; + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithConstructorPropertyAssignmentInES6.types b/tests/baselines/reference/emitClassDeclarationWithConstructorPropertyAssignmentInES6.types new file mode 100644 index 0000000000000..c121f936dbb96 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithConstructorPropertyAssignmentInES6.types @@ -0,0 +1,56 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorPropertyAssignmentInES6.ts === +class C { +>C : C + + x: string = "Hello world"; +>x : string +} + +class D { +>D : D + + x: string = "Hello world"; +>x : string + + y: number; +>y : number + + constructor() { + this.y = 10; +>this.y = 10 : number +>this.y : number +>this : D +>y : number + } +} + +class E extends D{ +>E : E +>D : D + + z: boolean = true; +>z : boolean +} + +class F extends D{ +>F : F +>D : D + + z: boolean = true; +>z : boolean + + j: string; +>j : string + + constructor() { + super(); +>super() : void +>super : typeof D + + this.j = "HI"; +>this.j = "HI" : string +>this.j : string +>this : F +>j : string + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.js b/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.js new file mode 100644 index 0000000000000..5d4a4fff6d649 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.js @@ -0,0 +1,38 @@ +//// [emitClassDeclarationWithGetterSetterInES6.ts] +class C { + _name: string; + get name(): string { + return this._name; + } + static get name2(): string { + return "BYE"; + } + static get ["computedname"]() { + return ""; + } + + set foo(a: string) { } + static set bar(b: number) { } + static set ["computedname"](b: string) { } +} + +//// [emitClassDeclarationWithGetterSetterInES6.js] +class C { + constructor() { + } + get name() { + return this._name; + } + static get name2() { + return "BYE"; + } + static get ["computedname"]() { + return ""; + } + set foo(a) { + } + static set bar(b) { + } + static set ["computedname"](b) { + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.types b/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.types new file mode 100644 index 0000000000000..4e4673a228f97 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.types @@ -0,0 +1,35 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithGetterSetterInES6.ts === +class C { +>C : C + + _name: string; +>_name : string + + get name(): string { +>name : string + + return this._name; +>this._name : string +>this : C +>_name : string + } + static get name2(): string { +>name2 : string + + return "BYE"; + } + static get ["computedname"]() { + return ""; + } + + set foo(a: string) { } +>foo : string +>a : string + + static set bar(b: number) { } +>bar : number +>b : number + + static set ["computedname"](b: string) { } +>b : string +} diff --git a/tests/baselines/reference/emitClassDeclarationWithMethodInES6.js b/tests/baselines/reference/emitClassDeclarationWithMethodInES6.js new file mode 100644 index 0000000000000..c443c0f0cfac4 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithMethodInES6.js @@ -0,0 +1,34 @@ +//// [emitClassDeclarationWithMethodInES6.ts] +class D { + foo() { } + ["computedName"]() { } + ["computedName"](a: string) { } + ["computedName"](a: string): number { return 1; } + bar(): string { + return "HI"; + } + baz(a: any, x: string): string { + return "HELLO"; + } +} + +//// [emitClassDeclarationWithMethodInES6.js] +class D { + constructor() { + } + foo() { + } + ["computedName"]() { + } + ["computedName"](a) { + } + ["computedName"](a) { + return 1; + } + bar() { + return "HI"; + } + baz(a, x) { + return "HELLO"; + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithMethodInES6.types b/tests/baselines/reference/emitClassDeclarationWithMethodInES6.types new file mode 100644 index 0000000000000..3803171137849 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithMethodInES6.types @@ -0,0 +1,27 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithMethodInES6.ts === +class D { +>D : D + + foo() { } +>foo : () => void + + ["computedName"]() { } + ["computedName"](a: string) { } +>a : string + + ["computedName"](a: string): number { return 1; } +>a : string + + bar(): string { +>bar : () => string + + return "HI"; + } + baz(a: any, x: string): string { +>baz : (a: any, x: string) => string +>a : any +>x : string + + return "HELLO"; + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithStaticMethodInES6.js b/tests/baselines/reference/emitClassDeclarationWithStaticMethodInES6.js new file mode 100644 index 0000000000000..b0809ab57b8eb --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithStaticMethodInES6.js @@ -0,0 +1,37 @@ +//// [emitClassDeclarationWithStaticMethodInES6.ts] +class E { + normalMethod() { } + static ["computedname"]() { } + static ["computedname"](a:string) { } + static ["computedname"](a: string): boolean { return true; } + static staticMethod() { + var x = 1 + 2; + return x + } + static foo(a: string) { } + static bar(a: string): number { return 1; } +} + +//// [emitClassDeclarationWithStaticMethodInES6.js] +class E { + constructor() { + } + normalMethod() { + } + static ["computedname"]() { + } + static ["computedname"](a) { + } + static ["computedname"](a) { + return true; + } + static staticMethod() { + var x = 1 + 2; + return x; + } + static foo(a) { + } + static bar(a) { + return 1; + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithStaticMethodInES6.types b/tests/baselines/reference/emitClassDeclarationWithStaticMethodInES6.types new file mode 100644 index 0000000000000..63bec899622de --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithStaticMethodInES6.types @@ -0,0 +1,32 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithStaticMethodInES6.ts === +class E { +>E : E + + normalMethod() { } +>normalMethod : () => void + + static ["computedname"]() { } + static ["computedname"](a:string) { } +>a : string + + static ["computedname"](a: string): boolean { return true; } +>a : string + + static staticMethod() { +>staticMethod : () => number + + var x = 1 + 2; +>x : number +>1 + 2 : number + + return x +>x : number + } + static foo(a: string) { } +>foo : (a: string) => void +>a : string + + static bar(a: string): number { return 1; } +>bar : (a: string) => number +>a : string +} diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorOverloadInES6.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorOverloadInES6.ts new file mode 100644 index 0000000000000..776d0b4584790 --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorOverloadInES6.ts @@ -0,0 +1,11 @@ +// @target: es6 +class C { + constructor(y: any) + constructor(x: number) { + } +} + +class D { + constructor(y: any) + constructor(x: number, z="hello") {} +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorPropertyAssignmentInES6.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorPropertyAssignmentInES6.ts new file mode 100644 index 0000000000000..dd97cfc85f351 --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorPropertyAssignmentInES6.ts @@ -0,0 +1,25 @@ +// @target:es6 +class C { + x: string = "Hello world"; +} + +class D { + x: string = "Hello world"; + y: number; + constructor() { + this.y = 10; + } +} + +class E extends D{ + z: boolean = true; +} + +class F extends D{ + z: boolean = true; + j: string; + constructor() { + super(); + this.j = "HI"; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithGetterSetterInES6.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithGetterSetterInES6.ts new file mode 100644 index 0000000000000..18ff3fa424de7 --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithGetterSetterInES6.ts @@ -0,0 +1,17 @@ +// @target:es6 +class C { + _name: string; + get name(): string { + return this._name; + } + static get name2(): string { + return "BYE"; + } + static get ["computedname"]() { + return ""; + } + + set foo(a: string) { } + static set bar(b: number) { } + static set ["computedname"](b: string) { } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithMethodInES6.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithMethodInES6.ts new file mode 100644 index 0000000000000..458a4bd3328ee --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithMethodInES6.ts @@ -0,0 +1,13 @@ +// @target:es6 +class D { + foo() { } + ["computedName"]() { } + ["computedName"](a: string) { } + ["computedName"](a: string): number { return 1; } + bar(): string { + return "HI"; + } + baz(a: any, x: string): string { + return "HELLO"; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithStaticMethodInES6.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithStaticMethodInES6.ts new file mode 100644 index 0000000000000..7a040649d749a --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithStaticMethodInES6.ts @@ -0,0 +1,13 @@ +// @target:es6 +class E { + normalMethod() { } + static ["computedname"]() { } + static ["computedname"](a:string) { } + static ["computedname"](a: string): boolean { return true; } + static staticMethod() { + var x = 1 + 2; + return x + } + static foo(a: string) { } + static bar(a: string): number { return 1; } +} \ No newline at end of file From da12d465d0bcfcc7c26931e3b7f6f20c45275f6b Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 10 Mar 2015 19:11:07 -0700 Subject: [PATCH 023/224] Add tests for extension, type arguments, overload --- src/compiler/emitter.ts | 6 +- ...mitClassDeclarationWithConstructorInES6.js | 26 +++++++ ...ClassDeclarationWithConstructorInES6.types | 32 ++++++++ ...nWithConstructorPropertyAssignmentInES6.js | 12 +-- ...rationWithExtensionAndTypeArgumentInES6.js | 27 +++++++ ...ionWithExtensionAndTypeArgumentInES6.types | 29 +++++++ .../emitClassDeclarationWithExtensionInES6.js | 25 +++++++ ...itClassDeclarationWithExtensionInES6.types | 19 +++++ .../emitClassDeclarationWithMethodInES6.js | 30 +++++++- .../emitClassDeclarationWithMethodInES6.types | 32 +++++++- ...ClassDeclarationWithMethodOverloadInES6.js | 22 ++++++ ...ssDeclarationWithMethodOverloadInES6.types | 29 +++++++ ...DeclarationWithRestAndDefaultArguements.js | 20 +++++ ...larationWithRestAndDefaultArguements.types | 25 +++++++ ...itClassDeclarationWithStaticMethodInES6.js | 37 --------- ...lassDeclarationWithStaticMethodInES6.types | 32 -------- ...sDeclarationWithTypeArgumentAndOverload.js | 39 ++++++++++ ...clarationWithTypeArgumentAndOverload.types | 75 +++++++++++++++++++ ...itClassDeclarationWithTypeArgumentInES6.js | 31 ++++++++ ...lassDeclarationWithTypeArgumentInES6.types | 53 +++++++++++++ ...mitClassDeclarationWithConstructorInES6.ts | 14 ++++ ...rationWithExtensionAndTypeArgumentInES6.ts | 11 +++ .../emitClassDeclarationWithExtensionInES6.ts | 8 ++ .../emitClassDeclarationWithMethodInES6.ts | 12 ++- ...ClassDeclarationWithMethodOverloadInES6.ts | 11 +++ ...DeclarationWithRestAndDefaultArguements.ts | 8 ++ ...itClassDeclarationWithStaticMethodInES6.ts | 13 ---- ...sDeclarationWithTypeArgumentAndOverload.ts | 23 ++++++ ...itClassDeclarationWithTypeArgumentInES6.ts | 15 ++++ 29 files changed, 622 insertions(+), 94 deletions(-) create mode 100644 tests/baselines/reference/emitClassDeclarationWithConstructorInES6.js create mode 100644 tests/baselines/reference/emitClassDeclarationWithConstructorInES6.types create mode 100644 tests/baselines/reference/emitClassDeclarationWithExtensionAndTypeArgumentInES6.js create mode 100644 tests/baselines/reference/emitClassDeclarationWithExtensionAndTypeArgumentInES6.types create mode 100644 tests/baselines/reference/emitClassDeclarationWithExtensionInES6.js create mode 100644 tests/baselines/reference/emitClassDeclarationWithExtensionInES6.types create mode 100644 tests/baselines/reference/emitClassDeclarationWithMethodOverloadInES6.js create mode 100644 tests/baselines/reference/emitClassDeclarationWithMethodOverloadInES6.types create mode 100644 tests/baselines/reference/emitClassDeclarationWithRestAndDefaultArguements.js create mode 100644 tests/baselines/reference/emitClassDeclarationWithRestAndDefaultArguements.types delete mode 100644 tests/baselines/reference/emitClassDeclarationWithStaticMethodInES6.js delete mode 100644 tests/baselines/reference/emitClassDeclarationWithStaticMethodInES6.types create mode 100644 tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverload.js create mode 100644 tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverload.types create mode 100644 tests/baselines/reference/emitClassDeclarationWithTypeArgumentInES6.js create mode 100644 tests/baselines/reference/emitClassDeclarationWithTypeArgumentInES6.types create mode 100644 tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorInES6.ts create mode 100644 tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExtensionAndTypeArgumentInES6.ts create mode 100644 tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExtensionInES6.ts create mode 100644 tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithMethodOverloadInES6.ts create mode 100644 tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithRestAndDefaultArguements.ts delete mode 100644 tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithStaticMethodInES6.ts create mode 100644 tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithTypeArgumentAndOverload.ts create mode 100644 tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithTypeArgumentInES6.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index db1cdee432c25..fa3854f15921b 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4407,7 +4407,9 @@ module ts { emitComputedPropertyName(memberName); } else { - if (languageVersion < ScriptTarget.ES6) { + // For script-target that is ES6 or above, we want to emit memberName by itself without prefix "." if the memberName is a name of method. + // If the memberName is the name of property, we need to emit it with prefix ".". + if (languageVersion < ScriptTarget.ES6 || memberName.parent.kind === SyntaxKind.PropertyDeclaration) { write("."); } emitNodeWithoutSourceMap(memberName); @@ -4667,7 +4669,7 @@ module ts { var baseTypeNode = getClassBaseTypeNode(node); if (baseTypeNode) { write(" extends "); - emitDeclarationName(node); + emitNodeWithoutSourceMap(baseTypeNode.typeName); } write(" {"); increaseIndent(); diff --git a/tests/baselines/reference/emitClassDeclarationWithConstructorInES6.js b/tests/baselines/reference/emitClassDeclarationWithConstructorInES6.js new file mode 100644 index 0000000000000..7877c957b29c7 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithConstructorInES6.js @@ -0,0 +1,26 @@ +//// [emitClassDeclarationWithConstructorInES6.ts] +class C { + y: number; + constructor(x: number) { + } +} + +class D { + y: number; + x: string = "hello"; + constructor(x: number, z = "hello") { + this.y = 10; + } +} + +//// [emitClassDeclarationWithConstructorInES6.js] +class C { + constructor(x) { + } +} +class D { + constructor(x, z = "hello") { + this.x = "hello"; + this.y = 10; + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithConstructorInES6.types b/tests/baselines/reference/emitClassDeclarationWithConstructorInES6.types new file mode 100644 index 0000000000000..359e58a4b32cc --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithConstructorInES6.types @@ -0,0 +1,32 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorInES6.ts === +class C { +>C : C + + y: number; +>y : number + + constructor(x: number) { +>x : number + } +} + +class D { +>D : D + + y: number; +>y : number + + x: string = "hello"; +>x : string + + constructor(x: number, z = "hello") { +>x : number +>z : string + + this.y = 10; +>this.y = 10 : number +>this.y : number +>this : D +>y : number + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithConstructorPropertyAssignmentInES6.js b/tests/baselines/reference/emitClassDeclarationWithConstructorPropertyAssignmentInES6.js index 4f57c6345cf56..8f65c8f9fdb87 100644 --- a/tests/baselines/reference/emitClassDeclarationWithConstructorPropertyAssignmentInES6.js +++ b/tests/baselines/reference/emitClassDeclarationWithConstructorPropertyAssignmentInES6.js @@ -27,25 +27,25 @@ class F extends D{ //// [emitClassDeclarationWithConstructorPropertyAssignmentInES6.js] class C { constructor() { - thisx = "Hello world"; + this.x = "Hello world"; } } class D { constructor() { - thisx = "Hello world"; + this.x = "Hello world"; this.y = 10; } } -class E extends E { +class E extends D { constructor(...args) { super(...args); - thisz = true; + this.z = true; } } -class F extends F { +class F extends D { constructor() { super(); - thisz = true; + this.z = true; this.j = "HI"; } } diff --git a/tests/baselines/reference/emitClassDeclarationWithExtensionAndTypeArgumentInES6.js b/tests/baselines/reference/emitClassDeclarationWithExtensionAndTypeArgumentInES6.js new file mode 100644 index 0000000000000..2409ebc0b663e --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithExtensionAndTypeArgumentInES6.js @@ -0,0 +1,27 @@ +//// [emitClassDeclarationWithExtensionAndTypeArgumentInES6.ts] +class B { + constructor(a: T) { } +} +class C extends B { } +class D extends B { + constructor(a: any) + constructor(b: number) { + super(b); + } +} + +//// [emitClassDeclarationWithExtensionAndTypeArgumentInES6.js] +class B { + constructor(a) { + } +} +class C extends B { + constructor(...args) { + super(...args); + } +} +class D extends B { + constructor(b) { + super(b); + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithExtensionAndTypeArgumentInES6.types b/tests/baselines/reference/emitClassDeclarationWithExtensionAndTypeArgumentInES6.types new file mode 100644 index 0000000000000..0f546fa7b8620 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithExtensionAndTypeArgumentInES6.types @@ -0,0 +1,29 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExtensionAndTypeArgumentInES6.ts === +class B { +>B : B +>T : T + + constructor(a: T) { } +>a : T +>T : T +} +class C extends B { } +>C : C +>B : B + +class D extends B { +>D : D +>B : B + + constructor(a: any) +>a : any + + constructor(b: number) { +>b : number + + super(b); +>super(b) : void +>super : typeof B +>b : number + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithExtensionInES6.js b/tests/baselines/reference/emitClassDeclarationWithExtensionInES6.js new file mode 100644 index 0000000000000..389d18d37a3d0 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithExtensionInES6.js @@ -0,0 +1,25 @@ +//// [emitClassDeclarationWithExtensionInES6.ts] +class B { } +class C extends B { } +class D extends B { + constructor() { + super(); + } +} + + +//// [emitClassDeclarationWithExtensionInES6.js] +class B { + constructor() { + } +} +class C extends B { + constructor(...args) { + super(...args); + } +} +class D extends B { + constructor() { + super(); + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithExtensionInES6.types b/tests/baselines/reference/emitClassDeclarationWithExtensionInES6.types new file mode 100644 index 0000000000000..f410340b50944 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithExtensionInES6.types @@ -0,0 +1,19 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExtensionInES6.ts === +class B { } +>B : B + +class C extends B { } +>C : C +>B : B + +class D extends B { +>D : D +>B : B + + constructor() { + super(); +>super() : void +>super : typeof B + } +} + diff --git a/tests/baselines/reference/emitClassDeclarationWithMethodInES6.js b/tests/baselines/reference/emitClassDeclarationWithMethodInES6.js index c443c0f0cfac4..fd8a3079f8b34 100644 --- a/tests/baselines/reference/emitClassDeclarationWithMethodInES6.js +++ b/tests/baselines/reference/emitClassDeclarationWithMethodInES6.js @@ -1,15 +1,25 @@ //// [emitClassDeclarationWithMethodInES6.ts] class D { + _bar: string; foo() { } ["computedName"]() { } ["computedName"](a: string) { } ["computedName"](a: string): number { return 1; } bar(): string { - return "HI"; + return this._bar; } baz(a: any, x: string): string { return "HELLO"; } + static ["computedname"]() { } + static ["computedname"](a: string) { } + static ["computedname"](a: string): boolean { return true; } + static staticMethod() { + var x = 1 + 2; + return x + } + static foo(a: string) { } + static bar(a: string): number { return 1; } } //// [emitClassDeclarationWithMethodInES6.js] @@ -26,9 +36,25 @@ class D { return 1; } bar() { - return "HI"; + return this._bar; } baz(a, x) { return "HELLO"; } + static ["computedname"]() { + } + static ["computedname"](a) { + } + static ["computedname"](a) { + return true; + } + static staticMethod() { + var x = 1 + 2; + return x; + } + static foo(a) { + } + static bar(a) { + return 1; + } } diff --git a/tests/baselines/reference/emitClassDeclarationWithMethodInES6.types b/tests/baselines/reference/emitClassDeclarationWithMethodInES6.types index 3803171137849..f26a9f87e6d25 100644 --- a/tests/baselines/reference/emitClassDeclarationWithMethodInES6.types +++ b/tests/baselines/reference/emitClassDeclarationWithMethodInES6.types @@ -2,6 +2,9 @@ class D { >D : D + _bar: string; +>_bar : string + foo() { } >foo : () => void @@ -15,7 +18,10 @@ class D { bar(): string { >bar : () => string - return "HI"; + return this._bar; +>this._bar : string +>this : D +>_bar : string } baz(a: any, x: string): string { >baz : (a: any, x: string) => string @@ -24,4 +30,28 @@ class D { return "HELLO"; } + static ["computedname"]() { } + static ["computedname"](a: string) { } +>a : string + + static ["computedname"](a: string): boolean { return true; } +>a : string + + static staticMethod() { +>staticMethod : () => number + + var x = 1 + 2; +>x : number +>1 + 2 : number + + return x +>x : number + } + static foo(a: string) { } +>foo : (a: string) => void +>a : string + + static bar(a: string): number { return 1; } +>bar : (a: string) => number +>a : string } diff --git a/tests/baselines/reference/emitClassDeclarationWithMethodOverloadInES6.js b/tests/baselines/reference/emitClassDeclarationWithMethodOverloadInES6.js new file mode 100644 index 0000000000000..252a44122eb02 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithMethodOverloadInES6.js @@ -0,0 +1,22 @@ +//// [emitClassDeclarationWithMethodOverloadInES6.ts] +class D { + _bar: string; + foo(a: any); + foo() { } + + baz(...args): string; + baz(z:string, v: number): string { + return this._bar; + } +} + +//// [emitClassDeclarationWithMethodOverloadInES6.js] +class D { + constructor() { + } + foo() { + } + baz(z, v) { + return this._bar; + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithMethodOverloadInES6.types b/tests/baselines/reference/emitClassDeclarationWithMethodOverloadInES6.types new file mode 100644 index 0000000000000..3017908e576d9 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithMethodOverloadInES6.types @@ -0,0 +1,29 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithMethodOverloadInES6.ts === +class D { +>D : D + + _bar: string; +>_bar : string + + foo(a: any); +>foo : (a: any) => any +>a : any + + foo() { } +>foo : (a: any) => any + + baz(...args): string; +>baz : (...args: any[]) => string +>args : any[] + + baz(z:string, v: number): string { +>baz : (...args: any[]) => string +>z : string +>v : number + + return this._bar; +>this._bar : string +>this : D +>_bar : string + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithRestAndDefaultArguements.js b/tests/baselines/reference/emitClassDeclarationWithRestAndDefaultArguements.js new file mode 100644 index 0000000000000..179818387da6d --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithRestAndDefaultArguements.js @@ -0,0 +1,20 @@ +//// [emitClassDeclarationWithRestAndDefaultArguements.ts] +class B { + constructor(y = 10, ...p) { } + foo(a = "hi") { } + bar(b = 10, ...p) { } + far(...p) + far(a: any) { } +} + +//// [emitClassDeclarationWithRestAndDefaultArguements.js] +class B { + constructor(y = 10, ...p) { + } + foo(a = "hi") { + } + bar(b = 10, ...p) { + } + far(a) { + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithRestAndDefaultArguements.types b/tests/baselines/reference/emitClassDeclarationWithRestAndDefaultArguements.types new file mode 100644 index 0000000000000..6f59f8220ade3 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithRestAndDefaultArguements.types @@ -0,0 +1,25 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithRestAndDefaultArguements.ts === +class B { +>B : B + + constructor(y = 10, ...p) { } +>y : number +>p : any[] + + foo(a = "hi") { } +>foo : (a?: string) => void +>a : string + + bar(b = 10, ...p) { } +>bar : (b?: number, ...p: any[]) => void +>b : number +>p : any[] + + far(...p) +>far : (...p: any[]) => any +>p : any[] + + far(a: any) { } +>far : (...p: any[]) => any +>a : any +} diff --git a/tests/baselines/reference/emitClassDeclarationWithStaticMethodInES6.js b/tests/baselines/reference/emitClassDeclarationWithStaticMethodInES6.js deleted file mode 100644 index b0809ab57b8eb..0000000000000 --- a/tests/baselines/reference/emitClassDeclarationWithStaticMethodInES6.js +++ /dev/null @@ -1,37 +0,0 @@ -//// [emitClassDeclarationWithStaticMethodInES6.ts] -class E { - normalMethod() { } - static ["computedname"]() { } - static ["computedname"](a:string) { } - static ["computedname"](a: string): boolean { return true; } - static staticMethod() { - var x = 1 + 2; - return x - } - static foo(a: string) { } - static bar(a: string): number { return 1; } -} - -//// [emitClassDeclarationWithStaticMethodInES6.js] -class E { - constructor() { - } - normalMethod() { - } - static ["computedname"]() { - } - static ["computedname"](a) { - } - static ["computedname"](a) { - return true; - } - static staticMethod() { - var x = 1 + 2; - return x; - } - static foo(a) { - } - static bar(a) { - return 1; - } -} diff --git a/tests/baselines/reference/emitClassDeclarationWithStaticMethodInES6.types b/tests/baselines/reference/emitClassDeclarationWithStaticMethodInES6.types deleted file mode 100644 index 63bec899622de..0000000000000 --- a/tests/baselines/reference/emitClassDeclarationWithStaticMethodInES6.types +++ /dev/null @@ -1,32 +0,0 @@ -=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithStaticMethodInES6.ts === -class E { ->E : E - - normalMethod() { } ->normalMethod : () => void - - static ["computedname"]() { } - static ["computedname"](a:string) { } ->a : string - - static ["computedname"](a: string): boolean { return true; } ->a : string - - static staticMethod() { ->staticMethod : () => number - - var x = 1 + 2; ->x : number ->1 + 2 : number - - return x ->x : number - } - static foo(a: string) { } ->foo : (a: string) => void ->a : string - - static bar(a: string): number { return 1; } ->bar : (a: string) => number ->a : string -} diff --git a/tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverload.js b/tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverload.js new file mode 100644 index 0000000000000..69801d6be122e --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverload.js @@ -0,0 +1,39 @@ +//// [emitClassDeclarationWithTypeArgumentAndOverload.ts] +class B { + x: T; + B: T; + + constructor(a: any) + constructor(a: any,b: T) + constructor(a: T) { this.B = a;} + + foo(a: T) + foo(a: any) + foo(b: string) + foo(): T { + return this.x; + } + + get BB(): T { + return this.B; + } + set BBWith(c: T) { + this.B = c; + } +} + +//// [emitClassDeclarationWithTypeArgumentAndOverload.js] +class B { + constructor(a) { + this.B = a; + } + foo() { + return this.x; + } + get BB() { + return this.B; + } + set BBWith(c) { + this.B = c; + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverload.types b/tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverload.types new file mode 100644 index 0000000000000..8b0feb72d2b53 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverload.types @@ -0,0 +1,75 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithTypeArgumentAndOverload.ts === +class B { +>B : B +>T : T + + x: T; +>x : T +>T : T + + B: T; +>B : T +>T : T + + constructor(a: any) +>a : any + + constructor(a: any,b: T) +>a : any +>b : T +>T : T + + constructor(a: T) { this.B = a;} +>a : T +>T : T +>this.B = a : T +>this.B : T +>this : B +>B : T +>a : T + + foo(a: T) +>foo : { (a: T): any; (a: any): any; (b: string): any; } +>a : T +>T : T + + foo(a: any) +>foo : { (a: T): any; (a: any): any; (b: string): any; } +>a : any + + foo(b: string) +>foo : { (a: T): any; (a: any): any; (b: string): any; } +>b : string + + foo(): T { +>foo : { (a: T): any; (a: any): any; (b: string): any; } +>T : T + + return this.x; +>this.x : T +>this : B +>x : T + } + + get BB(): T { +>BB : T +>T : T + + return this.B; +>this.B : T +>this : B +>B : T + } + set BBWith(c: T) { +>BBWith : T +>c : T +>T : T + + this.B = c; +>this.B = c : T +>this.B : T +>this : B +>B : T +>c : T + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithTypeArgumentInES6.js b/tests/baselines/reference/emitClassDeclarationWithTypeArgumentInES6.js new file mode 100644 index 0000000000000..4e2872b4f0646 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithTypeArgumentInES6.js @@ -0,0 +1,31 @@ +//// [emitClassDeclarationWithTypeArgumentInES6.ts] +class B { + x: T; + B: T; + constructor(a: T) { this.B = a;} + foo(): T { + return this.x; + } + get BB(): T { + return this.B; + } + set BBWith(c: T) { + this.B = c; + } +} + +//// [emitClassDeclarationWithTypeArgumentInES6.js] +class B { + constructor(a) { + this.B = a; + } + foo() { + return this.x; + } + get BB() { + return this.B; + } + set BBWith(c) { + this.B = c; + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithTypeArgumentInES6.types b/tests/baselines/reference/emitClassDeclarationWithTypeArgumentInES6.types new file mode 100644 index 0000000000000..8081d044e359e --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithTypeArgumentInES6.types @@ -0,0 +1,53 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithTypeArgumentInES6.ts === +class B { +>B : B +>T : T + + x: T; +>x : T +>T : T + + B: T; +>B : T +>T : T + + constructor(a: T) { this.B = a;} +>a : T +>T : T +>this.B = a : T +>this.B : T +>this : B +>B : T +>a : T + + foo(): T { +>foo : () => T +>T : T + + return this.x; +>this.x : T +>this : B +>x : T + } + get BB(): T { +>BB : T +>T : T + + return this.B; +>this.B : T +>this : B +>B : T + } + set BBWith(c: T) { +>BBWith : T +>c : T +>T : T + + this.B = c; +>this.B = c : T +>this.B : T +>this : B +>B : T +>c : T + } +} diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorInES6.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorInES6.ts new file mode 100644 index 0000000000000..9e06636da7e2a --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorInES6.ts @@ -0,0 +1,14 @@ +// @target: es6 +class C { + y: number; + constructor(x: number) { + } +} + +class D { + y: number; + x: string = "hello"; + constructor(x: number, z = "hello") { + this.y = 10; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExtensionAndTypeArgumentInES6.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExtensionAndTypeArgumentInES6.ts new file mode 100644 index 0000000000000..c27723e3391f3 --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExtensionAndTypeArgumentInES6.ts @@ -0,0 +1,11 @@ +// @target: es6 +class B { + constructor(a: T) { } +} +class C extends B { } +class D extends B { + constructor(a: any) + constructor(b: number) { + super(b); + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExtensionInES6.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExtensionInES6.ts new file mode 100644 index 0000000000000..519af626850ab --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExtensionInES6.ts @@ -0,0 +1,8 @@ +// @target: es6 +class B { } +class C extends B { } +class D extends B { + constructor() { + super(); + } +} diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithMethodInES6.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithMethodInES6.ts index 458a4bd3328ee..c5d95bc6cb16f 100644 --- a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithMethodInES6.ts +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithMethodInES6.ts @@ -1,13 +1,23 @@ // @target:es6 class D { + _bar: string; foo() { } ["computedName"]() { } ["computedName"](a: string) { } ["computedName"](a: string): number { return 1; } bar(): string { - return "HI"; + return this._bar; } baz(a: any, x: string): string { return "HELLO"; } + static ["computedname"]() { } + static ["computedname"](a: string) { } + static ["computedname"](a: string): boolean { return true; } + static staticMethod() { + var x = 1 + 2; + return x + } + static foo(a: string) { } + static bar(a: string): number { return 1; } } \ No newline at end of file diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithMethodOverloadInES6.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithMethodOverloadInES6.ts new file mode 100644 index 0000000000000..e1b277fae51cf --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithMethodOverloadInES6.ts @@ -0,0 +1,11 @@ +// @target:es6 +class D { + _bar: string; + foo(a: any); + foo() { } + + baz(...args): string; + baz(z:string, v: number): string { + return this._bar; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithRestAndDefaultArguements.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithRestAndDefaultArguements.ts new file mode 100644 index 0000000000000..20c251b2cfa17 --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithRestAndDefaultArguements.ts @@ -0,0 +1,8 @@ +// @target: es6 +class B { + constructor(y = 10, ...p) { } + foo(a = "hi") { } + bar(b = 10, ...p) { } + far(...p) + far(a: any) { } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithStaticMethodInES6.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithStaticMethodInES6.ts deleted file mode 100644 index 7a040649d749a..0000000000000 --- a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithStaticMethodInES6.ts +++ /dev/null @@ -1,13 +0,0 @@ -// @target:es6 -class E { - normalMethod() { } - static ["computedname"]() { } - static ["computedname"](a:string) { } - static ["computedname"](a: string): boolean { return true; } - static staticMethod() { - var x = 1 + 2; - return x - } - static foo(a: string) { } - static bar(a: string): number { return 1; } -} \ No newline at end of file diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithTypeArgumentAndOverload.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithTypeArgumentAndOverload.ts new file mode 100644 index 0000000000000..945b21010128d --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithTypeArgumentAndOverload.ts @@ -0,0 +1,23 @@ +// @target: es6 +class B { + x: T; + B: T; + + constructor(a: any) + constructor(a: any,b: T) + constructor(a: T) { this.B = a;} + + foo(a: T) + foo(a: any) + foo(b: string) + foo(): T { + return this.x; + } + + get BB(): T { + return this.B; + } + set BBWith(c: T) { + this.B = c; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithTypeArgumentInES6.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithTypeArgumentInES6.ts new file mode 100644 index 0000000000000..078356f6f1595 --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithTypeArgumentInES6.ts @@ -0,0 +1,15 @@ +// @target: es6 +class B { + x: T; + B: T; + constructor(a: T) { this.B = a;} + foo(): T { + return this.x; + } + get BB(): T { + return this.B; + } + set BBWith(c: T) { + this.B = c; + } +} \ No newline at end of file From a0a506b11b226a0762e03c1b42bb6388f202313b Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 11 Mar 2015 16:13:08 -0700 Subject: [PATCH 024/224] Emit class declaration with static property assignment --- src/compiler/emitter.ts | 11 +++++++-- ...DeclarationWithPropertyAssignmentInES6.js} | 4 ++-- ...larationWithPropertyAssignmentInES6.types} | 2 +- ...rationWithStaticPropertyAssignmentInES6.js | 23 +++++++++++++++++++ ...ionWithStaticPropertyAssignmentInES6.types | 18 +++++++++++++++ ...DeclarationWithPropertyAssignmentInES6.ts} | 0 ...rationWithStaticPropertyAssignmentInES6.ts | 9 ++++++++ 7 files changed, 62 insertions(+), 5 deletions(-) rename tests/baselines/reference/{emitClassDeclarationWithConstructorPropertyAssignmentInES6.js => emitClassDeclarationWithPropertyAssignmentInES6.js} (80%) rename tests/baselines/reference/{emitClassDeclarationWithConstructorPropertyAssignmentInES6.types => emitClassDeclarationWithPropertyAssignmentInES6.types} (86%) create mode 100644 tests/baselines/reference/emitClassDeclarationWithStaticPropertyAssignmentInES6.js create mode 100644 tests/baselines/reference/emitClassDeclarationWithStaticPropertyAssignmentInES6.types rename tests/cases/conformance/es6/classDeclaration/{emitClassDeclarationWithConstructorPropertyAssignmentInES6.ts => emitClassDeclarationWithPropertyAssignmentInES6.ts} (100%) create mode 100644 tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithStaticPropertyAssignmentInES6.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index fa3854f15921b..d4434c9bf4b71 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4677,10 +4677,17 @@ module ts { writeLine(); emitConstructorOfClass(node, baseTypeNode); emitMemberFunctionsAboveES6(node); + decreaseIndent(); writeLine(); + emitToken(SyntaxKind.CloseBraceToken, node.members.end); scopeEmitEnd(); - decreaseIndent(); - write("}"); + + // Emit static property assignment. Because classDeclaration is lexically evaluated, it is safe to emit static property assignment after classDeclaration + // From ES6 specification: + // HasLexicalDeclaration (N) : Determines if the argument identifier has a binding in this environment record that was created using + // a lexical declaration such as a LexicalDeclaration or a ClassDeclaration. + writeLine(); + emitMemberAssignments(node, NodeFlags.Static); } function emitClassDeclarationBelowES6(node: ClassDeclaration) { diff --git a/tests/baselines/reference/emitClassDeclarationWithConstructorPropertyAssignmentInES6.js b/tests/baselines/reference/emitClassDeclarationWithPropertyAssignmentInES6.js similarity index 80% rename from tests/baselines/reference/emitClassDeclarationWithConstructorPropertyAssignmentInES6.js rename to tests/baselines/reference/emitClassDeclarationWithPropertyAssignmentInES6.js index 8f65c8f9fdb87..03fb45b806e3d 100644 --- a/tests/baselines/reference/emitClassDeclarationWithConstructorPropertyAssignmentInES6.js +++ b/tests/baselines/reference/emitClassDeclarationWithPropertyAssignmentInES6.js @@ -1,4 +1,4 @@ -//// [emitClassDeclarationWithConstructorPropertyAssignmentInES6.ts] +//// [emitClassDeclarationWithPropertyAssignmentInES6.ts] class C { x: string = "Hello world"; } @@ -24,7 +24,7 @@ class F extends D{ } } -//// [emitClassDeclarationWithConstructorPropertyAssignmentInES6.js] +//// [emitClassDeclarationWithPropertyAssignmentInES6.js] class C { constructor() { this.x = "Hello world"; diff --git a/tests/baselines/reference/emitClassDeclarationWithConstructorPropertyAssignmentInES6.types b/tests/baselines/reference/emitClassDeclarationWithPropertyAssignmentInES6.types similarity index 86% rename from tests/baselines/reference/emitClassDeclarationWithConstructorPropertyAssignmentInES6.types rename to tests/baselines/reference/emitClassDeclarationWithPropertyAssignmentInES6.types index c121f936dbb96..5e7ebbc167c70 100644 --- a/tests/baselines/reference/emitClassDeclarationWithConstructorPropertyAssignmentInES6.types +++ b/tests/baselines/reference/emitClassDeclarationWithPropertyAssignmentInES6.types @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorPropertyAssignmentInES6.ts === +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithPropertyAssignmentInES6.ts === class C { >C : C diff --git a/tests/baselines/reference/emitClassDeclarationWithStaticPropertyAssignmentInES6.js b/tests/baselines/reference/emitClassDeclarationWithStaticPropertyAssignmentInES6.js new file mode 100644 index 0000000000000..69da64765a3a6 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithStaticPropertyAssignmentInES6.js @@ -0,0 +1,23 @@ +//// [emitClassDeclarationWithStaticPropertyAssignmentInES6.ts] +class C { + static z: string = "Foo"; +} + +class D { + x = 20000; + static b = true; +} + + +//// [emitClassDeclarationWithStaticPropertyAssignmentInES6.js] +class C { + constructor() { + } +} +C.z = "Foo"; +class D { + constructor() { + this.x = 20000; + } +} +D.b = true; diff --git a/tests/baselines/reference/emitClassDeclarationWithStaticPropertyAssignmentInES6.types b/tests/baselines/reference/emitClassDeclarationWithStaticPropertyAssignmentInES6.types new file mode 100644 index 0000000000000..6003b85b590ee --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithStaticPropertyAssignmentInES6.types @@ -0,0 +1,18 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithStaticPropertyAssignmentInES6.ts === +class C { +>C : C + + static z: string = "Foo"; +>z : string +} + +class D { +>D : D + + x = 20000; +>x : number + + static b = true; +>b : boolean +} + diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorPropertyAssignmentInES6.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithPropertyAssignmentInES6.ts similarity index 100% rename from tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorPropertyAssignmentInES6.ts rename to tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithPropertyAssignmentInES6.ts diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithStaticPropertyAssignmentInES6.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithStaticPropertyAssignmentInES6.ts new file mode 100644 index 0000000000000..7ed36bb22a2a1 --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithStaticPropertyAssignmentInES6.ts @@ -0,0 +1,9 @@ +// @target:es6 +class C { + static z: string = "Foo"; +} + +class D { + x = 20000; + static b = true; +} From 7ee587c43f737ed3823562260b091394d80df4c2 Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 11 Mar 2015 16:45:55 -0700 Subject: [PATCH 025/224] Emit class with export and export default --- src/compiler/emitter.ts | 7 ++++++ .../emitClassDeclarationWithExport.errors.txt | 16 +++++++++++++ .../emitClassDeclarationWithExport.js | 23 +++++++++++++++++++ .../emitClassDeclarationWithExport.ts | 8 +++++++ 4 files changed, 54 insertions(+) create mode 100644 tests/baselines/reference/emitClassDeclarationWithExport.errors.txt create mode 100644 tests/baselines/reference/emitClassDeclarationWithExport.js create mode 100644 tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index d4434c9bf4b71..606bd22f2c99e 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4664,6 +4664,13 @@ module ts { } function emitClassDeclarationAboveES6(node: ClassDeclaration) { + if (node.flags & NodeFlags.Export) { + write("export "); + + if (node.flags & NodeFlags.Default) { + write("default "); + } + } write("class "); emitDeclarationName(node); var baseTypeNode = getClassBaseTypeNode(node); diff --git a/tests/baselines/reference/emitClassDeclarationWithExport.errors.txt b/tests/baselines/reference/emitClassDeclarationWithExport.errors.txt new file mode 100644 index 0000000000000..11b1de11bf67a --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithExport.errors.txt @@ -0,0 +1,16 @@ +tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts(1,14): error TS1148: Cannot compile external modules unless the '--module' flag is provided. +tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts(5,22): error TS2309: An export assignment cannot be used in a module with other exported elements. + + +==== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts (2 errors) ==== + export class C { + ~ +!!! error TS1148: Cannot compile external modules unless the '--module' flag is provided. + foo() { } + } + + export default class D { + ~ +!!! error TS2309: An export assignment cannot be used in a module with other exported elements. + bar() { } + } \ No newline at end of file diff --git a/tests/baselines/reference/emitClassDeclarationWithExport.js b/tests/baselines/reference/emitClassDeclarationWithExport.js new file mode 100644 index 0000000000000..5a6c84389f333 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithExport.js @@ -0,0 +1,23 @@ +//// [emitClassDeclarationWithExport.ts] +export class C { + foo() { } +} + +export default class D { + bar() { } +} + +//// [emitClassDeclarationWithExport.js] +export class C { + constructor() { + } + foo() { + } +} +export default class D { + constructor() { + } + bar() { + } +} +module.exports = D; diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts new file mode 100644 index 0000000000000..f3ed5eb95d84f --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts @@ -0,0 +1,8 @@ +// @target: es6 +export class C { + foo() { } +} + +export default class D { + bar() { } +} \ No newline at end of file From e902d8462e96666a10b1f4c2fdcbca63d8caa997 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 11 Mar 2015 21:40:10 -0700 Subject: [PATCH 026/224] ES6 doesnt support import id = require("mod") syntax Conflicts: src/compiler/checker.ts src/compiler/diagnosticInformationMap.generated.ts src/compiler/diagnosticMessages.json --- scripts/processDiagnosticMessages.ts | 3 +- src/compiler/checker.ts | 6 + .../diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 5 + .../arityAndOrderCompatibility01.errors.txt | 292 +++++++++--------- .../reference/arityAndOrderCompatibility01.js | 56 ++-- .../constDeclarations-access5.errors.txt | 5 +- .../es6ImportEqualsDeclaration.errors.txt | 15 + .../reference/es6ImportEqualsDeclaration.js | 14 + .../compiler/es6ImportEqualsDeclaration.ts | 8 + 10 files changed, 228 insertions(+), 177 deletions(-) create mode 100644 tests/baselines/reference/es6ImportEqualsDeclaration.errors.txt create mode 100644 tests/baselines/reference/es6ImportEqualsDeclaration.js create mode 100644 tests/cases/compiler/es6ImportEqualsDeclaration.ts diff --git a/scripts/processDiagnosticMessages.ts b/scripts/processDiagnosticMessages.ts index 0d32c605fdc08..b97e4a2ea5427 100644 --- a/scripts/processDiagnosticMessages.ts +++ b/scripts/processDiagnosticMessages.ts @@ -65,8 +65,7 @@ function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable, nameMap: ' ' + convertPropertyName(nameMap[name]) + ': { code: ' + diagnosticDetails.code + ', category: DiagnosticCategory.' + diagnosticDetails.category + - ', key: "' + name.replace('"', '\\"') + '"' + - (diagnosticDetails.isEarly ? ', isEarly: true' : '') + + ', key: "' + name.replace(/[\"]/g, '\\"') + '"' + ' },\r\n'; } diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index afcf12fed1be5..9f120edbf8a84 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9896,6 +9896,12 @@ module ts { } } } + else { + if (compilerOptions.target >= ScriptTarget.ES6) { + // Import equals declaration is deprecated in es6 or above + grammarErrorOnNode(node, Diagnostics.Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_import_Asterisk_from_mod_import_a_from_mod_or_import_d_from_mod_instead); + } + } } } diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index b06a283a87616..8937c7a4a984c 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -157,6 +157,7 @@ module ts { Catch_clause_variable_cannot_have_an_initializer: { code: 1197, category: DiagnosticCategory.Error, key: "Catch clause variable cannot have an initializer." }, An_extended_Unicode_escape_value_must_be_between_0x0_and_0x10FFFF_inclusive: { code: 1198, category: DiagnosticCategory.Error, key: "An extended Unicode escape value must be between 0x0 and 0x10FFFF inclusive." }, Unterminated_Unicode_escape_sequence: { code: 1199, category: DiagnosticCategory.Error, key: "Unterminated Unicode escape sequence." }, + Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_import_Asterisk_from_mod_import_a_from_mod_or_import_d_from_mod_instead: { code: 1200, category: DiagnosticCategory.Error, key: "Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * from \"mod\"', 'import {a} from \"mod\"' or 'import d from \"mod\"' instead." }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index b265f5b528112..88801c8243d17 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -619,6 +619,11 @@ "category": "Error", "code": 1199 }, + "Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * from \"mod\"', 'import {a} from \"mod\"' or 'import d from \"mod\"' instead.": { + "category": "Error", + "code": 1200 + }, + "Duplicate identifier '{0}'.": { "category": "Error", "code": 2300 diff --git a/tests/baselines/reference/arityAndOrderCompatibility01.errors.txt b/tests/baselines/reference/arityAndOrderCompatibility01.errors.txt index 3925cdff74701..391fbf42384d7 100644 --- a/tests/baselines/reference/arityAndOrderCompatibility01.errors.txt +++ b/tests/baselines/reference/arityAndOrderCompatibility01.errors.txt @@ -1,147 +1,147 @@ -tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(13,12): error TS2493: Tuple type '[string, number]' with length '2' cannot be assigned to tuple with length '3'. -tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(14,12): error TS2460: Type 'StrNum' has no property '2'. -tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(15,5): error TS2461: Type '{ 0: string; 1: number; }' is not an array type. -tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(16,5): error TS2322: Type '[string, number]' is not assignable to type '[number, number, number]'. - Types of property '0' are incompatible. - Type 'string' is not assignable to type 'number'. -tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(17,5): error TS2322: Type 'StrNum' is not assignable to type '[number, number, number]'. - Types of property '0' are incompatible. - Type 'string' is not assignable to type 'number'. -tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(18,5): error TS2322: Type '{ 0: string; 1: number; }' is not assignable to type '[number, number, number]'. - Types of property '0' are incompatible. - Type 'string' is not assignable to type 'number'. -tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(19,5): error TS2322: Type '[string, number]' is not assignable to type '[string, number, number]'. - Property '2' is missing in type '[string, number]'. -tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(20,5): error TS2322: Type 'StrNum' is not assignable to type '[string, number, number]'. - Property '2' is missing in type 'StrNum'. -tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(21,5): error TS2322: Type '{ 0: string; 1: number; }' is not assignable to type '[string, number, number]'. - Property '2' is missing in type '{ 0: string; 1: number; }'. -tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(22,5): error TS2322: Type '[string, number]' is not assignable to type '[number]'. - Types of property '0' are incompatible. - Type 'string' is not assignable to type 'number'. -tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(23,5): error TS2322: Type 'StrNum' is not assignable to type '[number]'. - Types of property '0' are incompatible. - Type 'string' is not assignable to type 'number'. -tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(24,5): error TS2322: Type '{ 0: string; 1: number; }' is not assignable to type '[number]'. - Types of property '0' are incompatible. - Type 'string' is not assignable to type 'number'. -tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(25,5): error TS2322: Type '[string, number]' is not assignable to type '[string]'. - Types of property 'pop' are incompatible. - Type '() => string | number' is not assignable to type '() => string'. - Type 'string | number' is not assignable to type 'string'. - Type 'number' is not assignable to type 'string'. -tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(26,5): error TS2322: Type 'StrNum' is not assignable to type '[string]'. - Types of property 'pop' are incompatible. - Type '() => string | number' is not assignable to type '() => string'. -tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(27,5): error TS2322: Type '{ 0: string; 1: number; }' is not assignable to type '[string]'. - Property 'length' is missing in type '{ 0: string; 1: number; }'. -tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(28,5): error TS2322: Type '[string, number]' is not assignable to type '[number, string]'. - Types of property '0' are incompatible. - Type 'string' is not assignable to type 'number'. -tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(29,5): error TS2322: Type 'StrNum' is not assignable to type '[number, string]'. - Types of property '0' are incompatible. - Type 'string' is not assignable to type 'number'. -tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(30,5): error TS2322: Type '{ 0: string; 1: number; }' is not assignable to type '[number, string]'. - Types of property '0' are incompatible. - Type 'string' is not assignable to type 'number'. - - -==== tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts (18 errors) ==== - interface StrNum extends Array { - 0: string; - 1: number; - } - - var x: [string, number]; - var y: StrNum - var z: { - 0: string; - 1: number; - } - - var [a, b, c] = x; - ~ -!!! error TS2493: Tuple type '[string, number]' with length '2' cannot be assigned to tuple with length '3'. - var [d, e, f] = y; - ~ -!!! error TS2460: Type 'StrNum' has no property '2'. - var [g, h, i] = z; - ~~~~~~~~~ -!!! error TS2461: Type '{ 0: string; 1: number; }' is not an array type. - var j1: [number, number, number] = x; - ~~ -!!! error TS2322: Type '[string, number]' is not assignable to type '[number, number, number]'. -!!! error TS2322: Types of property '0' are incompatible. -!!! error TS2322: Type 'string' is not assignable to type 'number'. - var j2: [number, number, number] = y; - ~~ -!!! error TS2322: Type 'StrNum' is not assignable to type '[number, number, number]'. -!!! error TS2322: Types of property '0' are incompatible. -!!! error TS2322: Type 'string' is not assignable to type 'number'. - var j3: [number, number, number] = z; - ~~ -!!! error TS2322: Type '{ 0: string; 1: number; }' is not assignable to type '[number, number, number]'. -!!! error TS2322: Types of property '0' are incompatible. -!!! error TS2322: Type 'string' is not assignable to type 'number'. - var k1: [string, number, number] = x; - ~~ -!!! error TS2322: Type '[string, number]' is not assignable to type '[string, number, number]'. -!!! error TS2322: Property '2' is missing in type '[string, number]'. - var k2: [string, number, number] = y; - ~~ -!!! error TS2322: Type 'StrNum' is not assignable to type '[string, number, number]'. -!!! error TS2322: Property '2' is missing in type 'StrNum'. - var k3: [string, number, number] = z; - ~~ -!!! error TS2322: Type '{ 0: string; 1: number; }' is not assignable to type '[string, number, number]'. -!!! error TS2322: Property '2' is missing in type '{ 0: string; 1: number; }'. - var l1: [number] = x; - ~~ -!!! error TS2322: Type '[string, number]' is not assignable to type '[number]'. -!!! error TS2322: Types of property '0' are incompatible. -!!! error TS2322: Type 'string' is not assignable to type 'number'. - var l2: [number] = y; - ~~ -!!! error TS2322: Type 'StrNum' is not assignable to type '[number]'. -!!! error TS2322: Types of property '0' are incompatible. -!!! error TS2322: Type 'string' is not assignable to type 'number'. - var l3: [number] = z; - ~~ -!!! error TS2322: Type '{ 0: string; 1: number; }' is not assignable to type '[number]'. -!!! error TS2322: Types of property '0' are incompatible. -!!! error TS2322: Type 'string' is not assignable to type 'number'. - var m1: [string] = x; - ~~ -!!! error TS2322: Type '[string, number]' is not assignable to type '[string]'. -!!! error TS2322: Types of property 'pop' are incompatible. -!!! error TS2322: Type '() => string | number' is not assignable to type '() => string'. -!!! error TS2322: Type 'string | number' is not assignable to type 'string'. -!!! error TS2322: Type 'number' is not assignable to type 'string'. - var m2: [string] = y; - ~~ -!!! error TS2322: Type 'StrNum' is not assignable to type '[string]'. -!!! error TS2322: Types of property 'pop' are incompatible. -!!! error TS2322: Type '() => string | number' is not assignable to type '() => string'. - var m3: [string] = z; - ~~ -!!! error TS2322: Type '{ 0: string; 1: number; }' is not assignable to type '[string]'. -!!! error TS2322: Property 'length' is missing in type '{ 0: string; 1: number; }'. - var n1: [number, string] = x; - ~~ -!!! error TS2322: Type '[string, number]' is not assignable to type '[number, string]'. -!!! error TS2322: Types of property '0' are incompatible. -!!! error TS2322: Type 'string' is not assignable to type 'number'. - var n2: [number, string] = y; - ~~ -!!! error TS2322: Type 'StrNum' is not assignable to type '[number, string]'. -!!! error TS2322: Types of property '0' are incompatible. -!!! error TS2322: Type 'string' is not assignable to type 'number'. - var n3: [number, string] = z; - ~~ -!!! error TS2322: Type '{ 0: string; 1: number; }' is not assignable to type '[number, string]'. -!!! error TS2322: Types of property '0' are incompatible. -!!! error TS2322: Type 'string' is not assignable to type 'number'. - var o1: [string, number] = x; - var o2: [string, number] = y; - var o3: [string, number] = y; +tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(13,12): error TS2493: Tuple type '[string, number]' with length '2' cannot be assigned to tuple with length '3'. +tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(14,12): error TS2460: Type 'StrNum' has no property '2'. +tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(15,5): error TS2461: Type '{ 0: string; 1: number; }' is not an array type. +tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(16,5): error TS2322: Type '[string, number]' is not assignable to type '[number, number, number]'. + Types of property '0' are incompatible. + Type 'string' is not assignable to type 'number'. +tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(17,5): error TS2322: Type 'StrNum' is not assignable to type '[number, number, number]'. + Types of property '0' are incompatible. + Type 'string' is not assignable to type 'number'. +tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(18,5): error TS2322: Type '{ 0: string; 1: number; }' is not assignable to type '[number, number, number]'. + Types of property '0' are incompatible. + Type 'string' is not assignable to type 'number'. +tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(19,5): error TS2322: Type '[string, number]' is not assignable to type '[string, number, number]'. + Property '2' is missing in type '[string, number]'. +tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(20,5): error TS2322: Type 'StrNum' is not assignable to type '[string, number, number]'. + Property '2' is missing in type 'StrNum'. +tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(21,5): error TS2322: Type '{ 0: string; 1: number; }' is not assignable to type '[string, number, number]'. + Property '2' is missing in type '{ 0: string; 1: number; }'. +tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(22,5): error TS2322: Type '[string, number]' is not assignable to type '[number]'. + Types of property '0' are incompatible. + Type 'string' is not assignable to type 'number'. +tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(23,5): error TS2322: Type 'StrNum' is not assignable to type '[number]'. + Types of property '0' are incompatible. + Type 'string' is not assignable to type 'number'. +tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(24,5): error TS2322: Type '{ 0: string; 1: number; }' is not assignable to type '[number]'. + Types of property '0' are incompatible. + Type 'string' is not assignable to type 'number'. +tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(25,5): error TS2322: Type '[string, number]' is not assignable to type '[string]'. + Types of property 'pop' are incompatible. + Type '() => string | number' is not assignable to type '() => string'. + Type 'string | number' is not assignable to type 'string'. + Type 'number' is not assignable to type 'string'. +tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(26,5): error TS2322: Type 'StrNum' is not assignable to type '[string]'. + Types of property 'pop' are incompatible. + Type '() => string | number' is not assignable to type '() => string'. +tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(27,5): error TS2322: Type '{ 0: string; 1: number; }' is not assignable to type '[string]'. + Property 'length' is missing in type '{ 0: string; 1: number; }'. +tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(28,5): error TS2322: Type '[string, number]' is not assignable to type '[number, string]'. + Types of property '0' are incompatible. + Type 'string' is not assignable to type 'number'. +tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(29,5): error TS2322: Type 'StrNum' is not assignable to type '[number, string]'. + Types of property '0' are incompatible. + Type 'string' is not assignable to type 'number'. +tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts(30,5): error TS2322: Type '{ 0: string; 1: number; }' is not assignable to type '[number, string]'. + Types of property '0' are incompatible. + Type 'string' is not assignable to type 'number'. + + +==== tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts (18 errors) ==== + interface StrNum extends Array { + 0: string; + 1: number; + } + + var x: [string, number]; + var y: StrNum + var z: { + 0: string; + 1: number; + } + + var [a, b, c] = x; + ~ +!!! error TS2493: Tuple type '[string, number]' with length '2' cannot be assigned to tuple with length '3'. + var [d, e, f] = y; + ~ +!!! error TS2460: Type 'StrNum' has no property '2'. + var [g, h, i] = z; + ~~~~~~~~~ +!!! error TS2461: Type '{ 0: string; 1: number; }' is not an array type. + var j1: [number, number, number] = x; + ~~ +!!! error TS2322: Type '[string, number]' is not assignable to type '[number, number, number]'. +!!! error TS2322: Types of property '0' are incompatible. +!!! error TS2322: Type 'string' is not assignable to type 'number'. + var j2: [number, number, number] = y; + ~~ +!!! error TS2322: Type 'StrNum' is not assignable to type '[number, number, number]'. +!!! error TS2322: Types of property '0' are incompatible. +!!! error TS2322: Type 'string' is not assignable to type 'number'. + var j3: [number, number, number] = z; + ~~ +!!! error TS2322: Type '{ 0: string; 1: number; }' is not assignable to type '[number, number, number]'. +!!! error TS2322: Types of property '0' are incompatible. +!!! error TS2322: Type 'string' is not assignable to type 'number'. + var k1: [string, number, number] = x; + ~~ +!!! error TS2322: Type '[string, number]' is not assignable to type '[string, number, number]'. +!!! error TS2322: Property '2' is missing in type '[string, number]'. + var k2: [string, number, number] = y; + ~~ +!!! error TS2322: Type 'StrNum' is not assignable to type '[string, number, number]'. +!!! error TS2322: Property '2' is missing in type 'StrNum'. + var k3: [string, number, number] = z; + ~~ +!!! error TS2322: Type '{ 0: string; 1: number; }' is not assignable to type '[string, number, number]'. +!!! error TS2322: Property '2' is missing in type '{ 0: string; 1: number; }'. + var l1: [number] = x; + ~~ +!!! error TS2322: Type '[string, number]' is not assignable to type '[number]'. +!!! error TS2322: Types of property '0' are incompatible. +!!! error TS2322: Type 'string' is not assignable to type 'number'. + var l2: [number] = y; + ~~ +!!! error TS2322: Type 'StrNum' is not assignable to type '[number]'. +!!! error TS2322: Types of property '0' are incompatible. +!!! error TS2322: Type 'string' is not assignable to type 'number'. + var l3: [number] = z; + ~~ +!!! error TS2322: Type '{ 0: string; 1: number; }' is not assignable to type '[number]'. +!!! error TS2322: Types of property '0' are incompatible. +!!! error TS2322: Type 'string' is not assignable to type 'number'. + var m1: [string] = x; + ~~ +!!! error TS2322: Type '[string, number]' is not assignable to type '[string]'. +!!! error TS2322: Types of property 'pop' are incompatible. +!!! error TS2322: Type '() => string | number' is not assignable to type '() => string'. +!!! error TS2322: Type 'string | number' is not assignable to type 'string'. +!!! error TS2322: Type 'number' is not assignable to type 'string'. + var m2: [string] = y; + ~~ +!!! error TS2322: Type 'StrNum' is not assignable to type '[string]'. +!!! error TS2322: Types of property 'pop' are incompatible. +!!! error TS2322: Type '() => string | number' is not assignable to type '() => string'. + var m3: [string] = z; + ~~ +!!! error TS2322: Type '{ 0: string; 1: number; }' is not assignable to type '[string]'. +!!! error TS2322: Property 'length' is missing in type '{ 0: string; 1: number; }'. + var n1: [number, string] = x; + ~~ +!!! error TS2322: Type '[string, number]' is not assignable to type '[number, string]'. +!!! error TS2322: Types of property '0' are incompatible. +!!! error TS2322: Type 'string' is not assignable to type 'number'. + var n2: [number, string] = y; + ~~ +!!! error TS2322: Type 'StrNum' is not assignable to type '[number, string]'. +!!! error TS2322: Types of property '0' are incompatible. +!!! error TS2322: Type 'string' is not assignable to type 'number'. + var n3: [number, string] = z; + ~~ +!!! error TS2322: Type '{ 0: string; 1: number; }' is not assignable to type '[number, string]'. +!!! error TS2322: Types of property '0' are incompatible. +!!! error TS2322: Type 'string' is not assignable to type 'number'. + var o1: [string, number] = x; + var o2: [string, number] = y; + var o3: [string, number] = y; \ No newline at end of file diff --git a/tests/baselines/reference/arityAndOrderCompatibility01.js b/tests/baselines/reference/arityAndOrderCompatibility01.js index 5b88697fd4f8e..2eb1bcf8bd8a0 100644 --- a/tests/baselines/reference/arityAndOrderCompatibility01.js +++ b/tests/baselines/reference/arityAndOrderCompatibility01.js @@ -1,4 +1,4 @@ -//// [arityAndOrderCompatibility01.ts] +//// [arityAndOrderCompatibility01.ts] interface StrNum extends Array { 0: string; 1: number; @@ -32,30 +32,30 @@ var n3: [number, string] = z; var o1: [string, number] = x; var o2: [string, number] = y; var o3: [string, number] = y; - - -//// [arityAndOrderCompatibility01.js] -var x; -var y; -var z; -var a = x[0], b = x[1], c = x[2]; -var d = y[0], e = y[1], f = y[2]; -var g = z[0], h = z[1], i = z[2]; -var j1 = x; -var j2 = y; -var j3 = z; -var k1 = x; -var k2 = y; -var k3 = z; -var l1 = x; -var l2 = y; -var l3 = z; -var m1 = x; -var m2 = y; -var m3 = z; -var n1 = x; -var n2 = y; -var n3 = z; -var o1 = x; -var o2 = y; -var o3 = y; + + +//// [arityAndOrderCompatibility01.js] +var x; +var y; +var z; +var a = x[0], b = x[1], c = x[2]; +var d = y[0], e = y[1], f = y[2]; +var g = z[0], h = z[1], i = z[2]; +var j1 = x; +var j2 = y; +var j3 = z; +var k1 = x; +var k2 = y; +var k3 = z; +var l1 = x; +var l2 = y; +var l3 = z; +var m1 = x; +var m2 = y; +var m3 = z; +var n1 = x; +var n2 = y; +var n3 = z; +var o1 = x; +var o2 = y; +var o3 = y; diff --git a/tests/baselines/reference/constDeclarations-access5.errors.txt b/tests/baselines/reference/constDeclarations-access5.errors.txt index 23200e50ee42b..94aff02b63553 100644 --- a/tests/baselines/reference/constDeclarations-access5.errors.txt +++ b/tests/baselines/reference/constDeclarations-access5.errors.txt @@ -1,3 +1,4 @@ +tests/cases/compiler/constDeclarations_access_2.ts(2,1): error TS1200: Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * from "mod"', 'import {a} from "mod"' or 'import d from "mod"' instead. tests/cases/compiler/constDeclarations_access_2.ts(4,1): error TS2450: Left-hand side of assignment expression cannot be a constant. tests/cases/compiler/constDeclarations_access_2.ts(5,1): error TS2450: Left-hand side of assignment expression cannot be a constant. tests/cases/compiler/constDeclarations_access_2.ts(6,1): error TS2450: Left-hand side of assignment expression cannot be a constant. @@ -18,9 +19,11 @@ tests/cases/compiler/constDeclarations_access_2.ts(22,3): error TS2449: The oper tests/cases/compiler/constDeclarations_access_2.ts(24,1): error TS2450: Left-hand side of assignment expression cannot be a constant. -==== tests/cases/compiler/constDeclarations_access_2.ts (18 errors) ==== +==== tests/cases/compiler/constDeclarations_access_2.ts (19 errors) ==== /// import m = require('constDeclarations_access_1'); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1200: Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * from "mod"', 'import {a} from "mod"' or 'import d from "mod"' instead. // Errors m.x = 1; ~~~ diff --git a/tests/baselines/reference/es6ImportEqualsDeclaration.errors.txt b/tests/baselines/reference/es6ImportEqualsDeclaration.errors.txt new file mode 100644 index 0000000000000..9b354ebf14dff --- /dev/null +++ b/tests/baselines/reference/es6ImportEqualsDeclaration.errors.txt @@ -0,0 +1,15 @@ +tests/cases/compiler/client.ts(1,1): error TS1200: Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * from "mod"', 'import {a} from "mod"' or 'import d from "mod"' instead. +tests/cases/compiler/server.ts(3,1): error TS1148: Cannot compile external modules unless the '--module' flag is provided. + + +==== tests/cases/compiler/client.ts (1 errors) ==== + import a = require("server"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1200: Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * from "mod"', 'import {a} from "mod"' or 'import d from "mod"' instead. +==== tests/cases/compiler/server.ts (1 errors) ==== + + var a = 10; + export = a; + ~~~~~~~~~~~ +!!! error TS1148: Cannot compile external modules unless the '--module' flag is provided. + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportEqualsDeclaration.js b/tests/baselines/reference/es6ImportEqualsDeclaration.js new file mode 100644 index 0000000000000..47cfd2886322b --- /dev/null +++ b/tests/baselines/reference/es6ImportEqualsDeclaration.js @@ -0,0 +1,14 @@ +//// [tests/cases/compiler/es6ImportEqualsDeclaration.ts] //// + +//// [server.ts] + +var a = 10; +export = a; + +//// [client.ts] +import a = require("server"); + +//// [server.js] +var a = 10; +module.exports = a; +//// [client.js] diff --git a/tests/cases/compiler/es6ImportEqualsDeclaration.ts b/tests/cases/compiler/es6ImportEqualsDeclaration.ts new file mode 100644 index 0000000000000..7df85a31d75cd --- /dev/null +++ b/tests/cases/compiler/es6ImportEqualsDeclaration.ts @@ -0,0 +1,8 @@ +// @target: es6 + +// @filename: server.ts +var a = 10; +export = a; + +// @filename: client.ts +import a = require("server"); \ No newline at end of file From 61a5bfb09dcc9f0e5db41ffd5dc1ab21188dcb30 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 11 Mar 2015 21:53:37 -0700 Subject: [PATCH 027/224] Report error on export assignment with es6 and above target Conflicts: src/compiler/checker.ts tests/baselines/reference/es6ImportDefaultBinding.errors.txt tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.errors.txt tests/baselines/reference/es6ImportDefaultBindingMergeErrors.errors.txt tests/baselines/reference/es6ImportEqualsDeclaration.errors.txt tests/cases/compiler/es6ImportNameSpaceImportMergeErrors.ts tests/cases/compiler/es6ImportNameSpaceImportNoNamedExports.ts tests/cases/compiler/es6ImportNamedImportInExportAssignment.ts tests/cases/compiler/es6ImportNamedImportInIndirectExportAssignment.ts tests/cases/compiler/es6ImportNamedImportNoNamedExports.ts --- src/compiler/checker.ts | 5 +++++ src/compiler/diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 4 ++++ .../reference/es6ExportAssignment.errors.txt | 12 ++++++++++++ tests/baselines/reference/es6ExportAssignment.js | 8 ++++++++ .../reference/es6ImportEqualsDeclaration.errors.txt | 5 ++++- tests/cases/compiler/es6ExportAssignment.ts | 4 ++++ 7 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/es6ExportAssignment.errors.txt create mode 100644 tests/baselines/reference/es6ExportAssignment.js create mode 100644 tests/cases/compiler/es6ExportAssignment.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 9f120edbf8a84..f13b863b1603f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9940,6 +9940,11 @@ module ts { checkExpressionCached(node.expression); } checkExternalModuleExports(container); + + if (compilerOptions.target >= ScriptTarget.ES6) { + // export assignment is deprecated in es6 or above + grammarErrorOnNode(node, Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_export_default_instead); + } } function getModuleStatements(node: Declaration): ModuleElement[] { diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 8937c7a4a984c..fe89b8528e928 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -158,6 +158,7 @@ module ts { An_extended_Unicode_escape_value_must_be_between_0x0_and_0x10FFFF_inclusive: { code: 1198, category: DiagnosticCategory.Error, key: "An extended Unicode escape value must be between 0x0 and 0x10FFFF inclusive." }, Unterminated_Unicode_escape_sequence: { code: 1199, category: DiagnosticCategory.Error, key: "Unterminated Unicode escape sequence." }, Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_import_Asterisk_from_mod_import_a_from_mod_or_import_d_from_mod_instead: { code: 1200, category: DiagnosticCategory.Error, key: "Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * from \"mod\"', 'import {a} from \"mod\"' or 'import d from \"mod\"' instead." }, + Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_export_default_instead: { code: 1201, category: DiagnosticCategory.Error, key: "Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead." }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 88801c8243d17..56a6cd2b052f7 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -623,6 +623,10 @@ "category": "Error", "code": 1200 }, + "Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead.": { + "category": "Error", + "code": 1201 + }, "Duplicate identifier '{0}'.": { "category": "Error", diff --git a/tests/baselines/reference/es6ExportAssignment.errors.txt b/tests/baselines/reference/es6ExportAssignment.errors.txt new file mode 100644 index 0000000000000..d667423703e3a --- /dev/null +++ b/tests/baselines/reference/es6ExportAssignment.errors.txt @@ -0,0 +1,12 @@ +tests/cases/compiler/es6ExportAssignment.ts(3,1): error TS1148: Cannot compile external modules unless the '--module' flag is provided. +tests/cases/compiler/es6ExportAssignment.ts(3,1): error TS1201: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. + + +==== tests/cases/compiler/es6ExportAssignment.ts (2 errors) ==== + + var a = 10; + export = a; + ~~~~~~~~~~~ +!!! error TS1148: Cannot compile external modules unless the '--module' flag is provided. + ~~~~~~~~~~~ +!!! error TS1201: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. \ No newline at end of file diff --git a/tests/baselines/reference/es6ExportAssignment.js b/tests/baselines/reference/es6ExportAssignment.js new file mode 100644 index 0000000000000..7d603282b0c12 --- /dev/null +++ b/tests/baselines/reference/es6ExportAssignment.js @@ -0,0 +1,8 @@ +//// [es6ExportAssignment.ts] + +var a = 10; +export = a; + +//// [es6ExportAssignment.js] +var a = 10; +module.exports = a; diff --git a/tests/baselines/reference/es6ImportEqualsDeclaration.errors.txt b/tests/baselines/reference/es6ImportEqualsDeclaration.errors.txt index 9b354ebf14dff..74d102f1865d0 100644 --- a/tests/baselines/reference/es6ImportEqualsDeclaration.errors.txt +++ b/tests/baselines/reference/es6ImportEqualsDeclaration.errors.txt @@ -1,15 +1,18 @@ tests/cases/compiler/client.ts(1,1): error TS1200: Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * from "mod"', 'import {a} from "mod"' or 'import d from "mod"' instead. tests/cases/compiler/server.ts(3,1): error TS1148: Cannot compile external modules unless the '--module' flag is provided. +tests/cases/compiler/server.ts(3,1): error TS1201: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. ==== tests/cases/compiler/client.ts (1 errors) ==== import a = require("server"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS1200: Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * from "mod"', 'import {a} from "mod"' or 'import d from "mod"' instead. -==== tests/cases/compiler/server.ts (1 errors) ==== +==== tests/cases/compiler/server.ts (2 errors) ==== var a = 10; export = a; ~~~~~~~~~~~ !!! error TS1148: Cannot compile external modules unless the '--module' flag is provided. + ~~~~~~~~~~~ +!!! error TS1201: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. \ No newline at end of file diff --git a/tests/cases/compiler/es6ExportAssignment.ts b/tests/cases/compiler/es6ExportAssignment.ts new file mode 100644 index 0000000000000..f1f2cce99235b --- /dev/null +++ b/tests/cases/compiler/es6ExportAssignment.ts @@ -0,0 +1,4 @@ +// @target: es6 + +var a = 10; +export = a; \ No newline at end of file From a6e4e04bd9dbb36b0137fe7b39c7aeb295631433 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 11 Mar 2015 22:16:52 -0700 Subject: [PATCH 028/224] Add tests --- ...mportNameSpaceImportMergeErrors.errors.txt | 25 +++++++++++++++++++ .../es6ImportNameSpaceImportMergeErrors.js | 21 ++++++++++++++++ .../es6ImportNameSpaceImportNoNamedExports.js | 14 +++++++++++ ...6ImportNameSpaceImportNoNamedExports.types | 12 +++++++++ ...ImportNamedImportNoNamedExports.errors.txt | 16 ++++++++++++ .../es6ImportNameSpaceImportMergeErrors.ts | 15 +++++++++++ .../es6ImportNameSpaceImportNoNamedExports.ts | 9 +++++++ .../es6ImportNamedImportNoNamedExports.ts | 10 ++++++++ 8 files changed, 122 insertions(+) create mode 100644 tests/baselines/reference/es6ImportNameSpaceImportMergeErrors.errors.txt create mode 100644 tests/baselines/reference/es6ImportNameSpaceImportMergeErrors.js create mode 100644 tests/baselines/reference/es6ImportNameSpaceImportNoNamedExports.js create mode 100644 tests/baselines/reference/es6ImportNameSpaceImportNoNamedExports.types create mode 100644 tests/baselines/reference/es6ImportNamedImportNoNamedExports.errors.txt create mode 100644 tests/cases/compiler/es6ImportNameSpaceImportMergeErrors.ts create mode 100644 tests/cases/compiler/es6ImportNameSpaceImportNoNamedExports.ts create mode 100644 tests/cases/compiler/es6ImportNamedImportNoNamedExports.ts diff --git a/tests/baselines/reference/es6ImportNameSpaceImportMergeErrors.errors.txt b/tests/baselines/reference/es6ImportNameSpaceImportMergeErrors.errors.txt new file mode 100644 index 0000000000000..98a6887083390 --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportMergeErrors.errors.txt @@ -0,0 +1,25 @@ +tests/cases/compiler/es6ImportNameSpaceImportMergeErrors_1.ts(4,13): error TS2300: Duplicate identifier 'nameSpaceBinding1'. +tests/cases/compiler/es6ImportNameSpaceImportMergeErrors_1.ts(5,13): error TS2300: Duplicate identifier 'nameSpaceBinding1'. +tests/cases/compiler/es6ImportNameSpaceImportMergeErrors_1.ts(7,8): error TS2440: Import declaration conflicts with local declaration of 'nameSpaceBinding3' + + +==== tests/cases/compiler/es6ImportNameSpaceImportMergeErrors_0.ts (0 errors) ==== + + export var a = 10; + +==== tests/cases/compiler/es6ImportNameSpaceImportMergeErrors_1.ts (3 errors) ==== + import * as nameSpaceBinding from "es6ImportNameSpaceImportMergeErrors_0"; + interface nameSpaceBinding { } // this should be ok + + import * as nameSpaceBinding1 from "es6ImportNameSpaceImportMergeErrors_0"; // should be error + ~~~~~~~~~~~~~~~~~ +!!! error TS2300: Duplicate identifier 'nameSpaceBinding1'. + import * as nameSpaceBinding1 from "es6ImportNameSpaceImportMergeErrors_0"; // should be error + ~~~~~~~~~~~~~~~~~ +!!! error TS2300: Duplicate identifier 'nameSpaceBinding1'. + + import * as nameSpaceBinding3 from "es6ImportNameSpaceImportMergeErrors_0"; // should be error + ~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2440: Import declaration conflicts with local declaration of 'nameSpaceBinding3' + var nameSpaceBinding3 = 10; + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNameSpaceImportMergeErrors.js b/tests/baselines/reference/es6ImportNameSpaceImportMergeErrors.js new file mode 100644 index 0000000000000..3c8461fba2b70 --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportMergeErrors.js @@ -0,0 +1,21 @@ +//// [tests/cases/compiler/es6ImportNameSpaceImportMergeErrors.ts] //// + +//// [es6ImportNameSpaceImportMergeErrors_0.ts] + +export var a = 10; + +//// [es6ImportNameSpaceImportMergeErrors_1.ts] +import * as nameSpaceBinding from "es6ImportNameSpaceImportMergeErrors_0"; +interface nameSpaceBinding { } // this should be ok + +import * as nameSpaceBinding1 from "es6ImportNameSpaceImportMergeErrors_0"; // should be error +import * as nameSpaceBinding1 from "es6ImportNameSpaceImportMergeErrors_0"; // should be error + +import * as nameSpaceBinding3 from "es6ImportNameSpaceImportMergeErrors_0"; // should be error +var nameSpaceBinding3 = 10; + + +//// [es6ImportNameSpaceImportMergeErrors_0.js] +exports.a = 10; +//// [es6ImportNameSpaceImportMergeErrors_1.js] +var nameSpaceBinding3 = 10; diff --git a/tests/baselines/reference/es6ImportNameSpaceImportNoNamedExports.js b/tests/baselines/reference/es6ImportNameSpaceImportNoNamedExports.js new file mode 100644 index 0000000000000..3d6dab177851d --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportNoNamedExports.js @@ -0,0 +1,14 @@ +//// [tests/cases/compiler/es6ImportNameSpaceImportNoNamedExports.ts] //// + +//// [es6ImportNameSpaceImportNoNamedExports_0.ts] + +var a = 10; +export = a; + +//// [es6ImportNameSpaceImportNoNamedExports_1.ts] +import * as nameSpaceBinding from "es6ImportNameSpaceImportNoNamedExports_0"; // error + +//// [es6ImportNameSpaceImportNoNamedExports_0.js] +var a = 10; +module.exports = a; +//// [es6ImportNameSpaceImportNoNamedExports_1.js] diff --git a/tests/baselines/reference/es6ImportNameSpaceImportNoNamedExports.types b/tests/baselines/reference/es6ImportNameSpaceImportNoNamedExports.types new file mode 100644 index 0000000000000..3ba19cef9b443 --- /dev/null +++ b/tests/baselines/reference/es6ImportNameSpaceImportNoNamedExports.types @@ -0,0 +1,12 @@ +=== tests/cases/compiler/es6ImportNameSpaceImportNoNamedExports_0.ts === + +var a = 10; +>a : number + +export = a; +>a : number + +=== tests/cases/compiler/es6ImportNameSpaceImportNoNamedExports_1.ts === +import * as nameSpaceBinding from "es6ImportNameSpaceImportNoNamedExports_0"; // error +>nameSpaceBinding : typeof nameSpaceBinding + diff --git a/tests/baselines/reference/es6ImportNamedImportNoNamedExports.errors.txt b/tests/baselines/reference/es6ImportNamedImportNoNamedExports.errors.txt new file mode 100644 index 0000000000000..a5abd986ee857 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportNoNamedExports.errors.txt @@ -0,0 +1,16 @@ +tests/cases/compiler/es6ImportNamedImportNoNamedExports_1.ts(1,10): error TS2305: Module '"tests/cases/compiler/es6ImportNamedImportNoNamedExports_0"' has no exported member 'a'. +tests/cases/compiler/es6ImportNamedImportNoNamedExports_1.ts(2,10): error TS2305: Module '"tests/cases/compiler/es6ImportNamedImportNoNamedExports_0"' has no exported member 'a'. + + +==== tests/cases/compiler/es6ImportNamedImportNoNamedExports_0.ts (0 errors) ==== + + var a = 10; + export = a; + +==== tests/cases/compiler/es6ImportNamedImportNoNamedExports_1.ts (2 errors) ==== + import { a } from "es6ImportNamedImportNoNamedExports_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportNamedImportNoNamedExports_0"' has no exported member 'a'. + import { a as x } from "es6ImportNamedImportNoNamedExports_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportNamedImportNoNamedExports_0"' has no exported member 'a'. \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportNameSpaceImportMergeErrors.ts b/tests/cases/compiler/es6ImportNameSpaceImportMergeErrors.ts new file mode 100644 index 0000000000000..d4b69e8bcf4dc --- /dev/null +++ b/tests/cases/compiler/es6ImportNameSpaceImportMergeErrors.ts @@ -0,0 +1,15 @@ +// @target: es5 +// @module: commonjs + +// @filename: es6ImportNameSpaceImportMergeErrors_0.ts +export var a = 10; + +// @filename: es6ImportNameSpaceImportMergeErrors_1.ts +import * as nameSpaceBinding from "es6ImportNameSpaceImportMergeErrors_0"; +interface nameSpaceBinding { } // this should be ok + +import * as nameSpaceBinding1 from "es6ImportNameSpaceImportMergeErrors_0"; // should be error +import * as nameSpaceBinding1 from "es6ImportNameSpaceImportMergeErrors_0"; // should be error + +import * as nameSpaceBinding3 from "es6ImportNameSpaceImportMergeErrors_0"; // should be error +var nameSpaceBinding3 = 10; diff --git a/tests/cases/compiler/es6ImportNameSpaceImportNoNamedExports.ts b/tests/cases/compiler/es6ImportNameSpaceImportNoNamedExports.ts new file mode 100644 index 0000000000000..7d3bdcec94c27 --- /dev/null +++ b/tests/cases/compiler/es6ImportNameSpaceImportNoNamedExports.ts @@ -0,0 +1,9 @@ +// @target: es5 +// @module: commonjs + +// @filename: es6ImportNameSpaceImportNoNamedExports_0.ts +var a = 10; +export = a; + +// @filename: es6ImportNameSpaceImportNoNamedExports_1.ts +import * as nameSpaceBinding from "es6ImportNameSpaceImportNoNamedExports_0"; // error \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportNamedImportNoNamedExports.ts b/tests/cases/compiler/es6ImportNamedImportNoNamedExports.ts new file mode 100644 index 0000000000000..9dd243ff36d2e --- /dev/null +++ b/tests/cases/compiler/es6ImportNamedImportNoNamedExports.ts @@ -0,0 +1,10 @@ +// @target: es5 +// @module: commonjs + +// @filename: es6ImportNamedImportNoNamedExports_0.ts +var a = 10; +export = a; + +// @filename: es6ImportNamedImportNoNamedExports_1.ts +import { a } from "es6ImportNamedImportNoNamedExports_0"; +import { a as x } from "es6ImportNamedImportNoNamedExports_0"; \ No newline at end of file From 04ea7fe6de1926d8665536600c105e887961982e Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 11 Mar 2015 22:17:16 -0700 Subject: [PATCH 029/224] Handel isDeclaration visible for imports --- src/compiler/checker.ts | 5 +++ .../es6ImportNamedImportInExportAssignment.js | 37 +++++++++++++++++++ ...6ImportNamedImportInExportAssignment.types | 12 ++++++ ...mportInIndirectExportAssignment.errors.txt | 16 ++++++++ ...rtNamedImportInIndirectExportAssignment.js | 35 ++++++++++++++++++ .../es6ImportNamedImportNoNamedExports.js | 15 ++++++++ .../es6ImportNamedImportInExportAssignment.ts | 9 +++++ ...rtNamedImportInIndirectExportAssignment.ts | 13 +++++++ 8 files changed, 142 insertions(+) create mode 100644 tests/baselines/reference/es6ImportNamedImportInExportAssignment.js create mode 100644 tests/baselines/reference/es6ImportNamedImportInExportAssignment.types create mode 100644 tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.errors.txt create mode 100644 tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.js create mode 100644 tests/baselines/reference/es6ImportNamedImportNoNamedExports.js create mode 100644 tests/cases/compiler/es6ImportNamedImportInExportAssignment.ts create mode 100644 tests/cases/compiler/es6ImportNamedImportInIndirectExportAssignment.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f13b863b1603f..a43d291773555 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1754,6 +1754,11 @@ module ts { case SyntaxKind.ParenthesizedType: return isDeclarationVisible(node.parent); + case SyntaxKind.ImportClause: + case SyntaxKind.NamespaceImport: + case SyntaxKind.ImportSpecifier: + return false; + // Type parameters are always visible case SyntaxKind.TypeParameter: // Source file is always visible diff --git a/tests/baselines/reference/es6ImportNamedImportInExportAssignment.js b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.js new file mode 100644 index 0000000000000..cd2d5ef6922e8 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.js @@ -0,0 +1,37 @@ +//// [tests/cases/compiler/es6ImportNamedImportInExportAssignment.ts] //// + +//// [es6ImportNamedImportInExportAssignment_0.ts] + +export var a = 10; + +//// [es6ImportNamedImportInExportAssignment_1.ts] +import { a } from "es6ImportNamedImportInExportAssignment_0"; +export = a; + +//// [es6ImportNamedImportInExportAssignment_0.js] +exports.a = 10; +//// [es6ImportNamedImportInExportAssignment_1.js] +var _es6ImportNamedImportInExportAssignment_0 = require("es6ImportNamedImportInExportAssignment_0"); +module.exports = _es6ImportNamedImportInExportAssignment_0.a; + + +//// [es6ImportNamedImportInExportAssignment_0.d.ts] +export declare var a: number; +//// [es6ImportNamedImportInExportAssignment_1.d.ts] +export = a; + + +//// [DtsFileErrors] + + +tests/cases/compiler/es6ImportNamedImportInExportAssignment_1.d.ts(1,10): error TS2304: Cannot find name 'a'. + + +==== tests/cases/compiler/es6ImportNamedImportInExportAssignment_0.d.ts (0 errors) ==== + export declare var a: number; + +==== tests/cases/compiler/es6ImportNamedImportInExportAssignment_1.d.ts (1 errors) ==== + export = a; + ~ +!!! error TS2304: Cannot find name 'a'. + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNamedImportInExportAssignment.types b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.types new file mode 100644 index 0000000000000..cd72f35c8bf8b --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.types @@ -0,0 +1,12 @@ +=== tests/cases/compiler/es6ImportNamedImportInExportAssignment_0.ts === + +export var a = 10; +>a : number + +=== tests/cases/compiler/es6ImportNamedImportInExportAssignment_1.ts === +import { a } from "es6ImportNamedImportInExportAssignment_0"; +>a : number + +export = a; +>a : number + diff --git a/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.errors.txt b/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.errors.txt new file mode 100644 index 0000000000000..e896a1a88a143 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.errors.txt @@ -0,0 +1,16 @@ +tests/cases/compiler/es6ImportNamedImportInIndirectExportAssignment_1.ts(2,12): error TS4000: Import declaration 'x' is using private name 'a'. + + +==== tests/cases/compiler/es6ImportNamedImportInIndirectExportAssignment_0.ts (0 errors) ==== + + export module a { + export class c { + } + } + +==== tests/cases/compiler/es6ImportNamedImportInIndirectExportAssignment_1.ts (1 errors) ==== + import { a } from "es6ImportNamedImportInIndirectExportAssignment_0"; + import x = a; + ~ +!!! error TS4000: Import declaration 'x' is using private name 'a'. + export = x; \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.js b/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.js new file mode 100644 index 0000000000000..332be6074ad40 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportInIndirectExportAssignment.js @@ -0,0 +1,35 @@ +//// [tests/cases/compiler/es6ImportNamedImportInIndirectExportAssignment.ts] //// + +//// [es6ImportNamedImportInIndirectExportAssignment_0.ts] + +export module a { + export class c { + } +} + +//// [es6ImportNamedImportInIndirectExportAssignment_1.ts] +import { a } from "es6ImportNamedImportInIndirectExportAssignment_0"; +import x = a; +export = x; + +//// [es6ImportNamedImportInIndirectExportAssignment_0.js] +var a; +(function (a) { + var c = (function () { + function c() { + } + return c; + })(); + a.c = c; +})(a = exports.a || (exports.a = {})); +//// [es6ImportNamedImportInIndirectExportAssignment_1.js] +var _es6ImportNamedImportInIndirectExportAssignment_0 = require("es6ImportNamedImportInIndirectExportAssignment_0"); +var x = _es6ImportNamedImportInIndirectExportAssignment_0.a; +module.exports = x; + + +//// [es6ImportNamedImportInIndirectExportAssignment_0.d.ts] +export declare module a { + class c { + } +} diff --git a/tests/baselines/reference/es6ImportNamedImportNoNamedExports.js b/tests/baselines/reference/es6ImportNamedImportNoNamedExports.js new file mode 100644 index 0000000000000..524860827e6e8 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportNoNamedExports.js @@ -0,0 +1,15 @@ +//// [tests/cases/compiler/es6ImportNamedImportNoNamedExports.ts] //// + +//// [es6ImportNamedImportNoNamedExports_0.ts] + +var a = 10; +export = a; + +//// [es6ImportNamedImportNoNamedExports_1.ts] +import { a } from "es6ImportNamedImportNoNamedExports_0"; +import { a as x } from "es6ImportNamedImportNoNamedExports_0"; + +//// [es6ImportNamedImportNoNamedExports_0.js] +var a = 10; +module.exports = a; +//// [es6ImportNamedImportNoNamedExports_1.js] diff --git a/tests/cases/compiler/es6ImportNamedImportInExportAssignment.ts b/tests/cases/compiler/es6ImportNamedImportInExportAssignment.ts new file mode 100644 index 0000000000000..a27391757701d --- /dev/null +++ b/tests/cases/compiler/es6ImportNamedImportInExportAssignment.ts @@ -0,0 +1,9 @@ +// @module: commonjs +// @declaration: true + +// @filename: es6ImportNamedImportInExportAssignment_0.ts +export var a = 10; + +// @filename: es6ImportNamedImportInExportAssignment_1.ts +import { a } from "es6ImportNamedImportInExportAssignment_0"; +export = a; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportNamedImportInIndirectExportAssignment.ts b/tests/cases/compiler/es6ImportNamedImportInIndirectExportAssignment.ts new file mode 100644 index 0000000000000..16d11d4e19fcd --- /dev/null +++ b/tests/cases/compiler/es6ImportNamedImportInIndirectExportAssignment.ts @@ -0,0 +1,13 @@ +// @module: commonjs +// @declaration: true + +// @filename: es6ImportNamedImportInIndirectExportAssignment_0.ts +export module a { + export class c { + } +} + +// @filename: es6ImportNamedImportInIndirectExportAssignment_1.ts +import { a } from "es6ImportNamedImportInIndirectExportAssignment_0"; +import x = a; +export = x; \ No newline at end of file From b52d9ec23e670c6483fcceb40a1608e5f72ea9f6 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 11 Mar 2015 22:53:36 -0700 Subject: [PATCH 030/224] Report error if module gen target is specified in es6 Conflicts: src/compiler/diagnosticInformationMap.generated.ts src/compiler/diagnosticMessages.json src/compiler/program.ts tests/baselines/reference/constDeclarations-access5.errors.txt tests/baselines/reference/es6ExportAssignment.errors.txt tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.errors.txt tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js tests/baselines/reference/es6ImportDefaultBindingMergeErrors.errors.txt tests/baselines/reference/es6ImportEqualsDeclaration.errors.txt tests/cases/compiler/es6ImportDefaultBinding.ts tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport.ts tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1.ts tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportDts.ts tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding.ts tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1.ts tests/cases/compiler/es6ImportDefaultBindingMergeErrors.ts tests/cases/compiler/es6ImportDefaultBindingNoDefaultProperty.ts tests/cases/compiler/es6ImportNameSpaceImport.ts tests/cases/compiler/es6ImportNamedImport.ts tests/cases/compiler/es6ImportNamedImportMergeErrors.ts tests/cases/compiler/es6ImportNamedImportNoExportMember.ts tests/cases/compiler/es6ImportWithoutFromClause.ts tests/cases/compiler/es6ImportWithoutFromClauseNonInstantiatedModule.ts --- .../diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 4 +++ src/compiler/program.ts | 13 +++++++--- .../constDeclarations-access5.errors.txt | 2 ++ .../reference/es5ModuleWithModuleGenAmd.js | 25 +++++++++++++++++++ ....types => es5ModuleWithModuleGenAmd.types} | 6 ++--- .../es5ModuleWithModuleGenCommonjs.js | 23 +++++++++++++++++ ...s => es5ModuleWithModuleGenCommonjs.types} | 6 ++--- ...es5ModuleWithoutModuleGenTarget.errors.txt | 17 +++++++++++++ .../es5ModuleWithoutModuleGenTarget.js | 23 +++++++++++++++++ tests/baselines/reference/es6-amd.errors.txt | 18 +++++++++++++ .../reference/es6-declaration-amd.errors.txt | 18 +++++++++++++ .../reference/es6-sourcemap-amd.errors.txt | 18 +++++++++++++ .../reference/es6ExportAssignment.errors.txt | 5 +--- .../es6ImportDefaultBinding.errors.txt | 3 ++- .../reference/es6ImportDefaultBinding.js | 8 +++++- ...tBindingFollowedWithNamedImport.errors.txt | 3 ++- ...rtDefaultBindingFollowedWithNamedImport.js | 10 +++++++- ...ingFollowedWithNamespaceBinding.errors.txt | 3 ++- ...aultBindingFollowedWithNamespaceBinding.js | 10 +++++++- .../es6ImportEqualsDeclaration.errors.txt | 5 +--- .../reference/es6ImportNameSpaceImport.js | 8 +++++- .../reference/es6ImportNamedImport.js | 12 ++++++++- .../reference/es6ImportWithoutFromClause.js | 8 +++++- .../es6ImportWithoutFromClause.types | 1 + tests/baselines/reference/es6Module.js | 23 +++++++++++++++++ .../{es6-amd.types => es6Module.types} | 6 ++--- ...es6ModuleWithModuleGenTargetAmd.errors.txt | 16 ++++++++++++ .../es6ModuleWithModuleGenTargetAmd.js | 25 +++++++++++++++++++ ...duleWithModuleGenTargetCommonjs.errors.txt | 16 ++++++++++++ .../es6ModuleWithModuleGenTargetCommonjs.js | 23 +++++++++++++++++ .../compiler/es5ModuleWithModuleGenAmd.ts | 13 ++++++++++ .../es5ModuleWithModuleGenCommonjs.ts | 13 ++++++++++ .../es5ModuleWithoutModuleGenTarget.ts | 12 +++++++++ .../cases/compiler/es6ImportDefaultBinding.ts | 4 +-- ...rtDefaultBindingFollowedWithNamedImport.ts | 4 +-- ...aultBindingFollowedWithNamespaceBinding.ts | 5 ++-- .../compiler/es6ImportNameSpaceImport.ts | 4 +-- tests/cases/compiler/es6ImportNamedImport.ts | 4 +-- .../es6ImportNamedImportIdentifiersParsing.ts | 1 - .../es6ImportNamedImportParsingError.ts | 1 - tests/cases/compiler/es6ImportParseErrors.ts | 1 - .../compiler/es6ImportWithoutFromClause.ts | 4 +-- tests/cases/compiler/es6Module.ts | 12 +++++++++ .../es6ModuleWithModuleGenTargetAmd.ts | 13 ++++++++++ .../es6ModuleWithModuleGenTargetCommonjs.ts | 13 ++++++++++ 46 files changed, 416 insertions(+), 47 deletions(-) create mode 100644 tests/baselines/reference/es5ModuleWithModuleGenAmd.js rename tests/baselines/reference/{es6-declaration-amd.types => es5ModuleWithModuleGenAmd.types} (55%) create mode 100644 tests/baselines/reference/es5ModuleWithModuleGenCommonjs.js rename tests/baselines/reference/{es6-sourcemap-amd.types => es5ModuleWithModuleGenCommonjs.types} (53%) create mode 100644 tests/baselines/reference/es5ModuleWithoutModuleGenTarget.errors.txt create mode 100644 tests/baselines/reference/es5ModuleWithoutModuleGenTarget.js create mode 100644 tests/baselines/reference/es6-amd.errors.txt create mode 100644 tests/baselines/reference/es6-declaration-amd.errors.txt create mode 100644 tests/baselines/reference/es6-sourcemap-amd.errors.txt create mode 100644 tests/baselines/reference/es6Module.js rename tests/baselines/reference/{es6-amd.types => es6Module.types} (60%) create mode 100644 tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.errors.txt create mode 100644 tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.js create mode 100644 tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.errors.txt create mode 100644 tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.js create mode 100644 tests/cases/compiler/es5ModuleWithModuleGenAmd.ts create mode 100644 tests/cases/compiler/es5ModuleWithModuleGenCommonjs.ts create mode 100644 tests/cases/compiler/es5ModuleWithoutModuleGenTarget.ts create mode 100644 tests/cases/compiler/es6Module.ts create mode 100644 tests/cases/compiler/es6ModuleWithModuleGenTargetAmd.ts create mode 100644 tests/cases/compiler/es6ModuleWithModuleGenTargetCommonjs.ts diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index fe89b8528e928..8e70828e144dd 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -159,6 +159,7 @@ module ts { Unterminated_Unicode_escape_sequence: { code: 1199, category: DiagnosticCategory.Error, key: "Unterminated Unicode escape sequence." }, Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_import_Asterisk_from_mod_import_a_from_mod_or_import_d_from_mod_instead: { code: 1200, category: DiagnosticCategory.Error, key: "Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * from \"mod\"', 'import {a} from \"mod\"' or 'import d from \"mod\"' instead." }, Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_export_default_instead: { code: 1201, category: DiagnosticCategory.Error, key: "Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead." }, + Cannot_compile_external_modules_into_amd_or_commonjs_when_targeting_es6_or_higher: { code: 1202, category: DiagnosticCategory.Error, key: "Cannot compile external modules into amd or commonjs when targeting es6 or higher." }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 56a6cd2b052f7..86fc37fab2f6b 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -627,6 +627,10 @@ "category": "Error", "code": 1201 }, + "Cannot compile external modules into amd or commonjs when targeting es6 or higher.": { + "category": "Error", + "code": 1202 + }, "Duplicate identifier '{0}'.": { "category": "Error", diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 9b933cacf7420..a97da0dac137d 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -428,9 +428,16 @@ module ts { var firstExternalModuleSourceFile = forEach(files, f => isExternalModule(f) ? f : undefined); if (firstExternalModuleSourceFile && !options.module) { - // We cannot use createDiagnosticFromNode because nodes do not have parents yet - var span = getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); - diagnostics.add(createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_external_modules_unless_the_module_flag_is_provided)); + if (!options.module && options.target < ScriptTarget.ES6) { + // We cannot use createDiagnosticFromNode because nodes do not have parents yet + var span = getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); + diagnostics.add(createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_external_modules_unless_the_module_flag_is_provided)); + } + } + + // Cannot specify module gen target when in es6 or above + if (options.module && options.target >= ScriptTarget.ES6) { + diagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_compile_external_modules_into_amd_or_commonjs_when_targeting_es6_or_higher)); } // there has to be common source directory if user specified --outdir || --sourcRoot diff --git a/tests/baselines/reference/constDeclarations-access5.errors.txt b/tests/baselines/reference/constDeclarations-access5.errors.txt index 94aff02b63553..a5f5b1d0f243e 100644 --- a/tests/baselines/reference/constDeclarations-access5.errors.txt +++ b/tests/baselines/reference/constDeclarations-access5.errors.txt @@ -1,3 +1,4 @@ +error TS1202: Cannot compile external modules into amd or commonjs when targeting es6 or higher. tests/cases/compiler/constDeclarations_access_2.ts(2,1): error TS1200: Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * from "mod"', 'import {a} from "mod"' or 'import d from "mod"' instead. tests/cases/compiler/constDeclarations_access_2.ts(4,1): error TS2450: Left-hand side of assignment expression cannot be a constant. tests/cases/compiler/constDeclarations_access_2.ts(5,1): error TS2450: Left-hand side of assignment expression cannot be a constant. @@ -19,6 +20,7 @@ tests/cases/compiler/constDeclarations_access_2.ts(22,3): error TS2449: The oper tests/cases/compiler/constDeclarations_access_2.ts(24,1): error TS2450: Left-hand side of assignment expression cannot be a constant. +!!! error TS1202: Cannot compile external modules into amd or commonjs when targeting es6 or higher. ==== tests/cases/compiler/constDeclarations_access_2.ts (19 errors) ==== /// import m = require('constDeclarations_access_1'); diff --git a/tests/baselines/reference/es5ModuleWithModuleGenAmd.js b/tests/baselines/reference/es5ModuleWithModuleGenAmd.js new file mode 100644 index 0000000000000..f4757b539eb49 --- /dev/null +++ b/tests/baselines/reference/es5ModuleWithModuleGenAmd.js @@ -0,0 +1,25 @@ +//// [es5ModuleWithModuleGenAmd.ts] +export class A +{ + constructor () + { + } + + public B() + { + return 42; + } +} + +//// [es5ModuleWithModuleGenAmd.js] +define(["require", "exports"], function (require, exports) { + var A = (function () { + function A() { + } + A.prototype.B = function () { + return 42; + }; + return A; + })(); + exports.A = A; +}); diff --git a/tests/baselines/reference/es6-declaration-amd.types b/tests/baselines/reference/es5ModuleWithModuleGenAmd.types similarity index 55% rename from tests/baselines/reference/es6-declaration-amd.types rename to tests/baselines/reference/es5ModuleWithModuleGenAmd.types index e275fc5243961..e3453587a121b 100644 --- a/tests/baselines/reference/es6-declaration-amd.types +++ b/tests/baselines/reference/es5ModuleWithModuleGenAmd.types @@ -1,11 +1,9 @@ -=== tests/cases/compiler/es6-declaration-amd.ts === - -class A +=== tests/cases/compiler/es5ModuleWithModuleGenAmd.ts === +export class A >A : A { constructor () { - } public B() diff --git a/tests/baselines/reference/es5ModuleWithModuleGenCommonjs.js b/tests/baselines/reference/es5ModuleWithModuleGenCommonjs.js new file mode 100644 index 0000000000000..b4ca020f56677 --- /dev/null +++ b/tests/baselines/reference/es5ModuleWithModuleGenCommonjs.js @@ -0,0 +1,23 @@ +//// [es5ModuleWithModuleGenCommonjs.ts] +export class A +{ + constructor () + { + } + + public B() + { + return 42; + } +} + +//// [es5ModuleWithModuleGenCommonjs.js] +var A = (function () { + function A() { + } + A.prototype.B = function () { + return 42; + }; + return A; +})(); +exports.A = A; diff --git a/tests/baselines/reference/es6-sourcemap-amd.types b/tests/baselines/reference/es5ModuleWithModuleGenCommonjs.types similarity index 53% rename from tests/baselines/reference/es6-sourcemap-amd.types rename to tests/baselines/reference/es5ModuleWithModuleGenCommonjs.types index 661ab2e7cddfc..721df9afe58ef 100644 --- a/tests/baselines/reference/es6-sourcemap-amd.types +++ b/tests/baselines/reference/es5ModuleWithModuleGenCommonjs.types @@ -1,11 +1,9 @@ -=== tests/cases/compiler/es6-sourcemap-amd.ts === - -class A +=== tests/cases/compiler/es5ModuleWithModuleGenCommonjs.ts === +export class A >A : A { constructor () { - } public B() diff --git a/tests/baselines/reference/es5ModuleWithoutModuleGenTarget.errors.txt b/tests/baselines/reference/es5ModuleWithoutModuleGenTarget.errors.txt new file mode 100644 index 0000000000000..25e64fc72d0b7 --- /dev/null +++ b/tests/baselines/reference/es5ModuleWithoutModuleGenTarget.errors.txt @@ -0,0 +1,17 @@ +tests/cases/compiler/es5ModuleWithoutModuleGenTarget.ts(1,14): error TS1148: Cannot compile external modules unless the '--module' flag is provided. + + +==== tests/cases/compiler/es5ModuleWithoutModuleGenTarget.ts (1 errors) ==== + export class A + ~ +!!! error TS1148: Cannot compile external modules unless the '--module' flag is provided. + { + constructor () + { + } + + public B() + { + return 42; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/es5ModuleWithoutModuleGenTarget.js b/tests/baselines/reference/es5ModuleWithoutModuleGenTarget.js new file mode 100644 index 0000000000000..4f663875adee9 --- /dev/null +++ b/tests/baselines/reference/es5ModuleWithoutModuleGenTarget.js @@ -0,0 +1,23 @@ +//// [es5ModuleWithoutModuleGenTarget.ts] +export class A +{ + constructor () + { + } + + public B() + { + return 42; + } +} + +//// [es5ModuleWithoutModuleGenTarget.js] +var A = (function () { + function A() { + } + A.prototype.B = function () { + return 42; + }; + return A; +})(); +exports.A = A; diff --git a/tests/baselines/reference/es6-amd.errors.txt b/tests/baselines/reference/es6-amd.errors.txt new file mode 100644 index 0000000000000..b9a5efdfd4ad7 --- /dev/null +++ b/tests/baselines/reference/es6-amd.errors.txt @@ -0,0 +1,18 @@ +error TS1202: Cannot compile external modules into amd or commonjs when targeting es6 or higher. + + +!!! error TS1202: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +==== tests/cases/compiler/es6-amd.ts (0 errors) ==== + + class A + { + constructor () + { + + } + + public B() + { + return 42; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/es6-declaration-amd.errors.txt b/tests/baselines/reference/es6-declaration-amd.errors.txt new file mode 100644 index 0000000000000..afbab4d061015 --- /dev/null +++ b/tests/baselines/reference/es6-declaration-amd.errors.txt @@ -0,0 +1,18 @@ +error TS1202: Cannot compile external modules into amd or commonjs when targeting es6 or higher. + + +!!! error TS1202: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +==== tests/cases/compiler/es6-declaration-amd.ts (0 errors) ==== + + class A + { + constructor () + { + + } + + public B() + { + return 42; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/es6-sourcemap-amd.errors.txt b/tests/baselines/reference/es6-sourcemap-amd.errors.txt new file mode 100644 index 0000000000000..4214f69eca1db --- /dev/null +++ b/tests/baselines/reference/es6-sourcemap-amd.errors.txt @@ -0,0 +1,18 @@ +error TS1202: Cannot compile external modules into amd or commonjs when targeting es6 or higher. + + +!!! error TS1202: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +==== tests/cases/compiler/es6-sourcemap-amd.ts (0 errors) ==== + + class A + { + constructor () + { + + } + + public B() + { + return 42; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/es6ExportAssignment.errors.txt b/tests/baselines/reference/es6ExportAssignment.errors.txt index d667423703e3a..32d5411039667 100644 --- a/tests/baselines/reference/es6ExportAssignment.errors.txt +++ b/tests/baselines/reference/es6ExportAssignment.errors.txt @@ -1,12 +1,9 @@ -tests/cases/compiler/es6ExportAssignment.ts(3,1): error TS1148: Cannot compile external modules unless the '--module' flag is provided. tests/cases/compiler/es6ExportAssignment.ts(3,1): error TS1201: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. -==== tests/cases/compiler/es6ExportAssignment.ts (2 errors) ==== +==== tests/cases/compiler/es6ExportAssignment.ts (1 errors) ==== var a = 10; export = a; ~~~~~~~~~~~ -!!! error TS1148: Cannot compile external modules unless the '--module' flag is provided. - ~~~~~~~~~~~ !!! error TS1201: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBinding.errors.txt b/tests/baselines/reference/es6ImportDefaultBinding.errors.txt index 85390ecce4b8a..c07a84bb810d9 100644 --- a/tests/baselines/reference/es6ImportDefaultBinding.errors.txt +++ b/tests/baselines/reference/es6ImportDefaultBinding.errors.txt @@ -8,4 +8,5 @@ tests/cases/compiler/es6ImportDefaultBinding_1.ts(1,8): error TS1192: External m ==== tests/cases/compiler/es6ImportDefaultBinding_1.ts (1 errors) ==== import defaultBinding from "es6ImportDefaultBinding_0"; ~~~~~~~~~~~~~~ -!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBinding_0"' has no default export or export assignment. \ No newline at end of file +!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBinding_0"' has no default export or export assignment. + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBinding.js b/tests/baselines/reference/es6ImportDefaultBinding.js index d8d1fa8111dc3..630f601fbae49 100644 --- a/tests/baselines/reference/es6ImportDefaultBinding.js +++ b/tests/baselines/reference/es6ImportDefaultBinding.js @@ -5,8 +5,14 @@ export var a = 10; //// [es6ImportDefaultBinding_1.ts] -import defaultBinding from "es6ImportDefaultBinding_0"; +import defaultBinding from "es6ImportDefaultBinding_0"; + //// [es6ImportDefaultBinding_0.js] exports.a = 10; //// [es6ImportDefaultBinding_1.js] + + +//// [es6ImportDefaultBinding_0.d.ts] +export declare var a: number; +//// [es6ImportDefaultBinding_1.d.ts] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt index bd8714cb86fe1..c755b8207e7d8 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt @@ -48,4 +48,5 @@ tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_1.ts(6,8): e ~~~~~~~~~~~~~~ !!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0"' has no default export or export assignment. ~~~~~~~~~~~~~~ -!!! error TS2300: Duplicate identifier 'defaultBinding'. \ No newline at end of file +!!! error TS2300: Duplicate identifier 'defaultBinding'. + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js index a7402bfeb6a8e..a79a666506748 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js @@ -12,10 +12,18 @@ import defaultBinding, { a } from "es6ImportDefaultBindingFollowedWithNamedImpor import defaultBinding, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; import defaultBinding, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; import defaultBinding, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; +import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; + //// [es6ImportDefaultBindingFollowedWithNamedImport_0.js] exports.a = 10; exports.x = exports.a; exports.m = exports.a; //// [es6ImportDefaultBindingFollowedWithNamedImport_1.js] + + +//// [es6ImportDefaultBindingFollowedWithNamedImport_0.d.ts] +export declare var a: number; +export declare var x: number; +export declare var m: number; +//// [es6ImportDefaultBindingFollowedWithNamedImport_1.d.ts] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.errors.txt index 98371eb91988f..851a5189a5447 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.errors.txt +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.errors.txt @@ -8,4 +8,5 @@ tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_1.ts(1, ==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_1.ts (1 errors) ==== import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; ~~~~~~~~~~~~~~ -!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_0"' has no default export or export assignment. \ No newline at end of file +!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_0"' has no default export or export assignment. + var x: number = nameSpaceBinding.a; \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js index 5ec91279306dd..1241140b121d9 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js @@ -5,8 +5,16 @@ export var a = 10; //// [es6ImportDefaultBindingFollowedWithNamespaceBinding_1.ts] -import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; +var x: number = nameSpaceBinding.a; //// [es6ImportDefaultBindingFollowedWithNamespaceBinding_0.js] exports.a = 10; //// [es6ImportDefaultBindingFollowedWithNamespaceBinding_1.js] +var defaultBinding = require("es6ImportDefaultBindingFollowedWithNamespaceBinding_0"); +var x = nameSpaceBinding.a; + + +//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_0.d.ts] +export declare var a: number; +//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_1.d.ts] diff --git a/tests/baselines/reference/es6ImportEqualsDeclaration.errors.txt b/tests/baselines/reference/es6ImportEqualsDeclaration.errors.txt index 74d102f1865d0..41c3bc0eef4d4 100644 --- a/tests/baselines/reference/es6ImportEqualsDeclaration.errors.txt +++ b/tests/baselines/reference/es6ImportEqualsDeclaration.errors.txt @@ -1,5 +1,4 @@ tests/cases/compiler/client.ts(1,1): error TS1200: Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * from "mod"', 'import {a} from "mod"' or 'import d from "mod"' instead. -tests/cases/compiler/server.ts(3,1): error TS1148: Cannot compile external modules unless the '--module' flag is provided. tests/cases/compiler/server.ts(3,1): error TS1201: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. @@ -7,12 +6,10 @@ tests/cases/compiler/server.ts(3,1): error TS1201: Export assignment cannot be u import a = require("server"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS1200: Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * from "mod"', 'import {a} from "mod"' or 'import d from "mod"' instead. -==== tests/cases/compiler/server.ts (2 errors) ==== +==== tests/cases/compiler/server.ts (1 errors) ==== var a = 10; export = a; ~~~~~~~~~~~ -!!! error TS1148: Cannot compile external modules unless the '--module' flag is provided. - ~~~~~~~~~~~ !!! error TS1201: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNameSpaceImport.js b/tests/baselines/reference/es6ImportNameSpaceImport.js index c6daa3b122255..87c9b9fa90f43 100644 --- a/tests/baselines/reference/es6ImportNameSpaceImport.js +++ b/tests/baselines/reference/es6ImportNameSpaceImport.js @@ -5,8 +5,14 @@ export var a = 10; //// [es6ImportNameSpaceImport_1.ts] -import * as nameSpaceBinding from "es6ImportNameSpaceImport_0"; +import * as nameSpaceBinding from "es6ImportNameSpaceImport_0"; + //// [es6ImportNameSpaceImport_0.js] exports.a = 10; //// [es6ImportNameSpaceImport_1.js] + + +//// [es6ImportNameSpaceImport_0.d.ts] +export declare var a: number; +//// [es6ImportNameSpaceImport_1.d.ts] diff --git a/tests/baselines/reference/es6ImportNamedImport.js b/tests/baselines/reference/es6ImportNamedImport.js index c52499ef994a7..05ab441a69025 100644 --- a/tests/baselines/reference/es6ImportNamedImport.js +++ b/tests/baselines/reference/es6ImportNamedImport.js @@ -16,7 +16,8 @@ import { x, a as y } from "es6ImportNamedImport_0"; import { x as z, } from "es6ImportNamedImport_0"; import { m, } from "es6ImportNamedImport_0"; import { a1, x1 } from "es6ImportNamedImport_0"; -import { a1 as a11, x1 as x11 } from "es6ImportNamedImport_0"; +import { a1 as a11, x1 as x11 } from "es6ImportNamedImport_0"; + //// [es6ImportNamedImport_0.js] exports.a = 10; @@ -25,3 +26,12 @@ exports.m = exports.a; exports.a1 = 10; exports.x1 = 10; //// [es6ImportNamedImport_1.js] + + +//// [es6ImportNamedImport_0.d.ts] +export declare var a: number; +export declare var x: number; +export declare var m: number; +export declare var a1: number; +export declare var x1: number; +//// [es6ImportNamedImport_1.d.ts] diff --git a/tests/baselines/reference/es6ImportWithoutFromClause.js b/tests/baselines/reference/es6ImportWithoutFromClause.js index 43d21885c2701..2f35122571fec 100644 --- a/tests/baselines/reference/es6ImportWithoutFromClause.js +++ b/tests/baselines/reference/es6ImportWithoutFromClause.js @@ -5,9 +5,15 @@ export var a = 10; //// [es6ImportWithoutFromClause_1.ts] -import "es6ImportWithoutFromClause_0"; +import "es6ImportWithoutFromClause_0"; + //// [es6ImportWithoutFromClause_0.js] exports.a = 10; //// [es6ImportWithoutFromClause_1.js] require("es6ImportWithoutFromClause_0"); + + +//// [es6ImportWithoutFromClause_0.d.ts] +export declare var a: number; +//// [es6ImportWithoutFromClause_1.d.ts] diff --git a/tests/baselines/reference/es6ImportWithoutFromClause.types b/tests/baselines/reference/es6ImportWithoutFromClause.types index 1cd7df9962ee7..3cc5067891ad2 100644 --- a/tests/baselines/reference/es6ImportWithoutFromClause.types +++ b/tests/baselines/reference/es6ImportWithoutFromClause.types @@ -5,4 +5,5 @@ export var a = 10; === tests/cases/compiler/es6ImportWithoutFromClause_1.ts === import "es6ImportWithoutFromClause_0"; +No type information for this code. No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es6Module.js b/tests/baselines/reference/es6Module.js new file mode 100644 index 0000000000000..111d8fe203008 --- /dev/null +++ b/tests/baselines/reference/es6Module.js @@ -0,0 +1,23 @@ +//// [es6Module.ts] +export class A +{ + constructor () + { + } + + public B() + { + return 42; + } +} + +//// [es6Module.js] +var A = (function () { + function A() { + } + A.prototype.B = function () { + return 42; + }; + return A; +})(); +exports.A = A; diff --git a/tests/baselines/reference/es6-amd.types b/tests/baselines/reference/es6Module.types similarity index 60% rename from tests/baselines/reference/es6-amd.types rename to tests/baselines/reference/es6Module.types index 62815911f7f97..9391020021526 100644 --- a/tests/baselines/reference/es6-amd.types +++ b/tests/baselines/reference/es6Module.types @@ -1,11 +1,9 @@ -=== tests/cases/compiler/es6-amd.ts === - -class A +=== tests/cases/compiler/es6Module.ts === +export class A >A : A { constructor () { - } public B() diff --git a/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.errors.txt b/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.errors.txt new file mode 100644 index 0000000000000..18cd37c7351d6 --- /dev/null +++ b/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.errors.txt @@ -0,0 +1,16 @@ +error TS1202: Cannot compile external modules into amd or commonjs when targeting es6 or higher. + + +!!! error TS1202: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +==== tests/cases/compiler/es6ModuleWithModuleGenTargetAmd.ts (0 errors) ==== + export class A + { + constructor () + { + } + + public B() + { + return 42; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.js b/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.js new file mode 100644 index 0000000000000..90768d474d140 --- /dev/null +++ b/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.js @@ -0,0 +1,25 @@ +//// [es6ModuleWithModuleGenTargetAmd.ts] +export class A +{ + constructor () + { + } + + public B() + { + return 42; + } +} + +//// [es6ModuleWithModuleGenTargetAmd.js] +define(["require", "exports"], function (require, exports) { + var A = (function () { + function A() { + } + A.prototype.B = function () { + return 42; + }; + return A; + })(); + exports.A = A; +}); diff --git a/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.errors.txt b/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.errors.txt new file mode 100644 index 0000000000000..e00768eafd11f --- /dev/null +++ b/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.errors.txt @@ -0,0 +1,16 @@ +error TS1202: Cannot compile external modules into amd or commonjs when targeting es6 or higher. + + +!!! error TS1202: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +==== tests/cases/compiler/es6ModuleWithModuleGenTargetCommonjs.ts (0 errors) ==== + export class A + { + constructor () + { + } + + public B() + { + return 42; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.js b/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.js new file mode 100644 index 0000000000000..06cf44b4d5006 --- /dev/null +++ b/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.js @@ -0,0 +1,23 @@ +//// [es6ModuleWithModuleGenTargetCommonjs.ts] +export class A +{ + constructor () + { + } + + public B() + { + return 42; + } +} + +//// [es6ModuleWithModuleGenTargetCommonjs.js] +var A = (function () { + function A() { + } + A.prototype.B = function () { + return 42; + }; + return A; +})(); +exports.A = A; diff --git a/tests/cases/compiler/es5ModuleWithModuleGenAmd.ts b/tests/cases/compiler/es5ModuleWithModuleGenAmd.ts new file mode 100644 index 0000000000000..051c77f808e07 --- /dev/null +++ b/tests/cases/compiler/es5ModuleWithModuleGenAmd.ts @@ -0,0 +1,13 @@ +// @target: ES5 +// @module: amd +export class A +{ + constructor () + { + } + + public B() + { + return 42; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/es5ModuleWithModuleGenCommonjs.ts b/tests/cases/compiler/es5ModuleWithModuleGenCommonjs.ts new file mode 100644 index 0000000000000..31720bddbcbbe --- /dev/null +++ b/tests/cases/compiler/es5ModuleWithModuleGenCommonjs.ts @@ -0,0 +1,13 @@ +// @target: ES5 +// @module: commonjs +export class A +{ + constructor () + { + } + + public B() + { + return 42; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/es5ModuleWithoutModuleGenTarget.ts b/tests/cases/compiler/es5ModuleWithoutModuleGenTarget.ts new file mode 100644 index 0000000000000..c9504ef9fcbd9 --- /dev/null +++ b/tests/cases/compiler/es5ModuleWithoutModuleGenTarget.ts @@ -0,0 +1,12 @@ +// @target: ES5 +export class A +{ + constructor () + { + } + + public B() + { + return 42; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportDefaultBinding.ts b/tests/cases/compiler/es6ImportDefaultBinding.ts index dc5b4ab98d61c..9e779e8664d79 100644 --- a/tests/cases/compiler/es6ImportDefaultBinding.ts +++ b/tests/cases/compiler/es6ImportDefaultBinding.ts @@ -1,8 +1,8 @@ // @target: es6 -// @module: commonjs +// @declaration: true // @filename: es6ImportDefaultBinding_0.ts export var a = 10; // @filename: es6ImportDefaultBinding_1.ts -import defaultBinding from "es6ImportDefaultBinding_0"; \ No newline at end of file +import defaultBinding from "es6ImportDefaultBinding_0"; diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport.ts index 96b277d6640cd..20f0f122e99e0 100644 --- a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport.ts +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport.ts @@ -1,5 +1,5 @@ // @target: es6 -// @module: commonjs +// @declaration: true // @filename: es6ImportDefaultBindingFollowedWithNamedImport_0.ts export var a = 10; @@ -12,4 +12,4 @@ import defaultBinding, { a } from "es6ImportDefaultBindingFollowedWithNamedImpor import defaultBinding, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; import defaultBinding, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; import defaultBinding, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; -import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; \ No newline at end of file +import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport_0"; diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding.ts index 3d029e28738bd..3e2cdd3409257 100644 --- a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding.ts +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding.ts @@ -1,8 +1,9 @@ // @target: es6 -// @module: commonjs +// @declaration: true // @filename: es6ImportDefaultBindingFollowedWithNamespaceBinding_0.ts export var a = 10; // @filename: es6ImportDefaultBindingFollowedWithNamespaceBinding_1.ts -import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; \ No newline at end of file +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; +var x: number = nameSpaceBinding.a; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportNameSpaceImport.ts b/tests/cases/compiler/es6ImportNameSpaceImport.ts index 9937606c41ff4..58ef52daf53c0 100644 --- a/tests/cases/compiler/es6ImportNameSpaceImport.ts +++ b/tests/cases/compiler/es6ImportNameSpaceImport.ts @@ -1,8 +1,8 @@ // @target: es6 -// @module: commonjs +// @declaration: true // @filename: es6ImportNameSpaceImport_0.ts export var a = 10; // @filename: es6ImportNameSpaceImport_1.ts -import * as nameSpaceBinding from "es6ImportNameSpaceImport_0"; \ No newline at end of file +import * as nameSpaceBinding from "es6ImportNameSpaceImport_0"; diff --git a/tests/cases/compiler/es6ImportNamedImport.ts b/tests/cases/compiler/es6ImportNamedImport.ts index ed34434bd292c..df5de47897577 100644 --- a/tests/cases/compiler/es6ImportNamedImport.ts +++ b/tests/cases/compiler/es6ImportNamedImport.ts @@ -1,5 +1,5 @@ // @target: es6 -// @module: commonjs +// @declaration: true // @filename: es6ImportNamedImport_0.ts export var a = 10; @@ -16,4 +16,4 @@ import { x, a as y } from "es6ImportNamedImport_0"; import { x as z, } from "es6ImportNamedImport_0"; import { m, } from "es6ImportNamedImport_0"; import { a1, x1 } from "es6ImportNamedImport_0"; -import { a1 as a11, x1 as x11 } from "es6ImportNamedImport_0"; \ No newline at end of file +import { a1 as a11, x1 as x11 } from "es6ImportNamedImport_0"; diff --git a/tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts b/tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts index e1be293e4468e..ea1ed5cbff65a 100644 --- a/tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts +++ b/tests/cases/compiler/es6ImportNamedImportIdentifiersParsing.ts @@ -1,5 +1,4 @@ // @target: es6 -// @module: commonjs import { yield } from "somemodule"; // Allowed import { default } from "somemodule"; // Error - as this is keyword that is not allowed as identifier diff --git a/tests/cases/compiler/es6ImportNamedImportParsingError.ts b/tests/cases/compiler/es6ImportNamedImportParsingError.ts index a836acc11405d..26bd9b6915376 100644 --- a/tests/cases/compiler/es6ImportNamedImportParsingError.ts +++ b/tests/cases/compiler/es6ImportNamedImportParsingError.ts @@ -1,5 +1,4 @@ // @target: es6 -// @module: commonjs // @filename: es6ImportNamedImportParsingError_0.ts export var a = 10; diff --git a/tests/cases/compiler/es6ImportParseErrors.ts b/tests/cases/compiler/es6ImportParseErrors.ts index 2cc21dad7468f..9eb3ccba82a63 100644 --- a/tests/cases/compiler/es6ImportParseErrors.ts +++ b/tests/cases/compiler/es6ImportParseErrors.ts @@ -1,4 +1,3 @@ // @target: es6 -// @module: commonjs import 10; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportWithoutFromClause.ts b/tests/cases/compiler/es6ImportWithoutFromClause.ts index 70a15a9bc54f7..0a38cda093c44 100644 --- a/tests/cases/compiler/es6ImportWithoutFromClause.ts +++ b/tests/cases/compiler/es6ImportWithoutFromClause.ts @@ -1,8 +1,8 @@ // @target: es6 -// @module: commonjs +// @declaration: true // @filename: es6ImportWithoutFromClause_0.ts export var a = 10; // @filename: es6ImportWithoutFromClause_1.ts -import "es6ImportWithoutFromClause_0"; \ No newline at end of file +import "es6ImportWithoutFromClause_0"; diff --git a/tests/cases/compiler/es6Module.ts b/tests/cases/compiler/es6Module.ts new file mode 100644 index 0000000000000..33d70cd133f97 --- /dev/null +++ b/tests/cases/compiler/es6Module.ts @@ -0,0 +1,12 @@ +// @target: ES6 +export class A +{ + constructor () + { + } + + public B() + { + return 42; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/es6ModuleWithModuleGenTargetAmd.ts b/tests/cases/compiler/es6ModuleWithModuleGenTargetAmd.ts new file mode 100644 index 0000000000000..9521ec6cbdb39 --- /dev/null +++ b/tests/cases/compiler/es6ModuleWithModuleGenTargetAmd.ts @@ -0,0 +1,13 @@ +// @target: ES6 +// @module: amd +export class A +{ + constructor () + { + } + + public B() + { + return 42; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/es6ModuleWithModuleGenTargetCommonjs.ts b/tests/cases/compiler/es6ModuleWithModuleGenTargetCommonjs.ts new file mode 100644 index 0000000000000..616a375d9700d --- /dev/null +++ b/tests/cases/compiler/es6ModuleWithModuleGenTargetCommonjs.ts @@ -0,0 +1,13 @@ +// @target: ES6 +// @module: commonjs +export class A +{ + constructor () + { + } + + public B() + { + return 42; + } +} \ No newline at end of file From 4ef687c5fa1ae9077b96413af492e4f01b2d6312 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 11 Mar 2015 22:55:09 -0700 Subject: [PATCH 031/224] Add tests --- ...BindingFollowedWithNamedImport1.errors.txt | 42 +++++++++ ...tDefaultBindingFollowedWithNamedImport1.js | 44 +++++++++ ...ndingFollowedWithNamedImportDts.errors.txt | 61 +++++++++++++ ...efaultBindingFollowedWithNamedImportDts.js | 90 +++++++++++++++++++ ...ngFollowedWithNamespaceBinding1.errors.txt | 13 +++ ...ultBindingFollowedWithNamespaceBinding1.js | 23 +++++ ...ImportDefaultBindingMergeErrors.errors.txt | 26 ++++++ .../es6ImportDefaultBindingMergeErrors.js | 25 ++++++ ...DefaultBindingNoDefaultProperty.errors.txt | 12 +++ ...s6ImportDefaultBindingNoDefaultProperty.js | 13 +++ ...es6ImportNamedImportMergeErrors.errors.txt | 33 +++++++ .../es6ImportNamedImportMergeErrors.js | 30 +++++++ ...ImportNamedImportNoExportMember.errors.txt | 16 ++++ .../es6ImportNamedImportNoExportMember.js | 15 ++++ ...tWithoutFromClauseNonInstantiatedModule.js | 19 ++++ ...thoutFromClauseNonInstantiatedModule.types | 9 ++ ...tDefaultBindingFollowedWithNamedImport1.ts | 20 +++++ ...efaultBindingFollowedWithNamedImportDts.ts | 24 +++++ ...ultBindingFollowedWithNamespaceBinding1.ts | 10 +++ .../es6ImportDefaultBindingMergeErrors.ts | 15 ++++ ...s6ImportDefaultBindingNoDefaultProperty.ts | 7 ++ .../es6ImportNamedImportMergeErrors.ts | 19 ++++ .../es6ImportNamedImportNoExportMember.ts | 9 ++ ...tWithoutFromClauseNonInstantiatedModule.ts | 9 ++ 24 files changed, 584 insertions(+) create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.errors.txt create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.js create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.errors.txt create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.js create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.errors.txt create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.js create mode 100644 tests/baselines/reference/es6ImportDefaultBindingMergeErrors.errors.txt create mode 100644 tests/baselines/reference/es6ImportDefaultBindingMergeErrors.js create mode 100644 tests/baselines/reference/es6ImportDefaultBindingNoDefaultProperty.errors.txt create mode 100644 tests/baselines/reference/es6ImportDefaultBindingNoDefaultProperty.js create mode 100644 tests/baselines/reference/es6ImportNamedImportMergeErrors.errors.txt create mode 100644 tests/baselines/reference/es6ImportNamedImportMergeErrors.js create mode 100644 tests/baselines/reference/es6ImportNamedImportNoExportMember.errors.txt create mode 100644 tests/baselines/reference/es6ImportNamedImportNoExportMember.js create mode 100644 tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.js create mode 100644 tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.types create mode 100644 tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1.ts create mode 100644 tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportDts.ts create mode 100644 tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1.ts create mode 100644 tests/cases/compiler/es6ImportDefaultBindingMergeErrors.ts create mode 100644 tests/cases/compiler/es6ImportDefaultBindingNoDefaultProperty.ts create mode 100644 tests/cases/compiler/es6ImportNamedImportMergeErrors.ts create mode 100644 tests/cases/compiler/es6ImportNamedImportNoExportMember.ts create mode 100644 tests/cases/compiler/es6ImportWithoutFromClauseNonInstantiatedModule.ts diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.errors.txt new file mode 100644 index 0000000000000..030b0d11c7b71 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.errors.txt @@ -0,0 +1,42 @@ +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0.ts(3,1): error TS1201: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_1.ts(3,27): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'a'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_1.ts(5,27): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'a'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_1.ts(7,27): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'x'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_1.ts(7,30): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'a'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_1.ts(9,27): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'x'. +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_1.ts(11,27): error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'm'. + + +==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0.ts (1 errors) ==== + + var a = 10; + export = a; + ~~~~~~~~~~~ +!!! error TS1201: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. + +==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_1.ts (6 errors) ==== + import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; + var x1: number = defaultBinding1; + import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'a'. + var x1: number = defaultBinding2; + import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'a'. + var x1: number = defaultBinding3; + import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'x'. + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'a'. + var x1: number = defaultBinding4; + import defaultBinding5, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'x'. + var x1: number = defaultBinding5; + import defaultBinding6, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; + ~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1_0"' has no exported member 'm'. + var x1: number = defaultBinding6; + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.js new file mode 100644 index 0000000000000..765d09fae79c3 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.js @@ -0,0 +1,44 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1.ts] //// + +//// [es6ImportDefaultBindingFollowedWithNamedImport1_0.ts] + +var a = 10; +export = a; + +//// [es6ImportDefaultBindingFollowedWithNamedImport1_1.ts] +import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding1; +import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding2; +import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding3; +import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding4; +import defaultBinding5, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding5; +import defaultBinding6, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding6; + + +//// [es6ImportDefaultBindingFollowedWithNamedImport1_0.js] +var a = 10; +module.exports = a; +//// [es6ImportDefaultBindingFollowedWithNamedImport1_1.js] +var defaultBinding1 = require("es6ImportDefaultBindingFollowedWithNamedImport1_0"); +var x1 = defaultBinding1; +var defaultBinding2 = require("es6ImportDefaultBindingFollowedWithNamedImport1_0"); +var x1 = defaultBinding2; +var defaultBinding3 = require("es6ImportDefaultBindingFollowedWithNamedImport1_0"); +var x1 = defaultBinding3; +var defaultBinding4 = require("es6ImportDefaultBindingFollowedWithNamedImport1_0"); +var x1 = defaultBinding4; +var defaultBinding5 = require("es6ImportDefaultBindingFollowedWithNamedImport1_0"); +var x1 = defaultBinding5; +var defaultBinding6 = require("es6ImportDefaultBindingFollowedWithNamedImport1_0"); +var x1 = defaultBinding6; + + +//// [es6ImportDefaultBindingFollowedWithNamedImport1_0.d.ts] +declare var a: number; +export = a; +//// [es6ImportDefaultBindingFollowedWithNamedImport1_1.d.ts] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.errors.txt new file mode 100644 index 0000000000000..91d51d5f7ef64 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.errors.txt @@ -0,0 +1,61 @@ +tests/cases/compiler/client.ts(1,8): error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. +tests/cases/compiler/client.ts(2,8): error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. +tests/cases/compiler/client.ts(3,12): error TS4025: Exported variable 'x1' has or is using private name 'a'. +tests/cases/compiler/client.ts(4,8): error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. +tests/cases/compiler/client.ts(5,12): error TS4025: Exported variable 'x2' has or is using private name 'b'. +tests/cases/compiler/client.ts(6,8): error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. +tests/cases/compiler/client.ts(7,12): error TS4025: Exported variable 'x4' has or is using private name 'x'. +tests/cases/compiler/client.ts(8,12): error TS4025: Exported variable 'x5' has or is using private name 'y'. +tests/cases/compiler/client.ts(9,8): error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. +tests/cases/compiler/client.ts(10,12): error TS4025: Exported variable 'x3' has or is using private name 'z'. +tests/cases/compiler/client.ts(11,8): error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. +tests/cases/compiler/client.ts(12,12): error TS4025: Exported variable 'x6' has or is using private name 'm'. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + export class a { } + export class x { } + export class m { } + export class a11 { } + export class a12 { } + export class x11 { } + +==== tests/cases/compiler/client.ts (12 errors) ==== + import defaultBinding1, { } from "server"; + ~~~~~~~~~~~~~~~ +!!! error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. + import defaultBinding2, { a } from "server"; + ~~~~~~~~~~~~~~~ +!!! error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. + export var x1 = new a(); + ~~ +!!! error TS4025: Exported variable 'x1' has or is using private name 'a'. + import defaultBinding3, { a11 as b } from "server"; + ~~~~~~~~~~~~~~~ +!!! error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. + export var x2 = new b(); + ~~ +!!! error TS4025: Exported variable 'x2' has or is using private name 'b'. + import defaultBinding4, { x, a12 as y } from "server"; + ~~~~~~~~~~~~~~~ +!!! error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. + export var x4 = new x(); + ~~ +!!! error TS4025: Exported variable 'x4' has or is using private name 'x'. + export var x5 = new y(); + ~~ +!!! error TS4025: Exported variable 'x5' has or is using private name 'y'. + import defaultBinding5, { x11 as z, } from "server"; + ~~~~~~~~~~~~~~~ +!!! error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. + export var x3 = new z(); + ~~ +!!! error TS4025: Exported variable 'x3' has or is using private name 'z'. + import defaultBinding6, { m, } from "server"; + ~~~~~~~~~~~~~~~ +!!! error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. + export var x6 = new m(); + ~~ +!!! error TS4025: Exported variable 'x6' has or is using private name 'm'. + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.js new file mode 100644 index 0000000000000..15d4c7f2fc9e5 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.js @@ -0,0 +1,90 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportDts.ts] //// + +//// [server.ts] + +export class a { } +export class x { } +export class m { } +export class a11 { } +export class a12 { } +export class x11 { } + +//// [client.ts] +import defaultBinding1, { } from "server"; +import defaultBinding2, { a } from "server"; +export var x1 = new a(); +import defaultBinding3, { a11 as b } from "server"; +export var x2 = new b(); +import defaultBinding4, { x, a12 as y } from "server"; +export var x4 = new x(); +export var x5 = new y(); +import defaultBinding5, { x11 as z, } from "server"; +export var x3 = new z(); +import defaultBinding6, { m, } from "server"; +export var x6 = new m(); + + +//// [server.js] +var a = (function () { + function a() { + } + return a; +})(); +exports.a = a; +var x = (function () { + function x() { + } + return x; +})(); +exports.x = x; +var m = (function () { + function m() { + } + return m; +})(); +exports.m = m; +var a11 = (function () { + function a11() { + } + return a11; +})(); +exports.a11 = a11; +var a12 = (function () { + function a12() { + } + return a12; +})(); +exports.a12 = a12; +var x11 = (function () { + function x11() { + } + return x11; +})(); +exports.x11 = x11; +//// [client.js] +var defaultBinding2 = require("server"); +exports.x1 = new _server_1.a(); +var defaultBinding3 = require("server"); +exports.x2 = new _server_2.a11(); +var defaultBinding4 = require("server"); +exports.x4 = new _server_3.x(); +exports.x5 = new _server_3.a12(); +var defaultBinding5 = require("server"); +exports.x3 = new _server_4.x11(); +var defaultBinding6 = require("server"); +exports.x6 = new _server_5.m(); + + +//// [server.d.ts] +export declare class a { +} +export declare class x { +} +export declare class m { +} +export declare class a11 { +} +export declare class a12 { +} +export declare class x11 { +} diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.errors.txt new file mode 100644 index 0000000000000..bc66ab817acb5 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.errors.txt @@ -0,0 +1,13 @@ +tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_0.ts(3,1): error TS1201: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. + + +==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_0.ts (1 errors) ==== + + var a = 10; + export = a; + ~~~~~~~~~~~ +!!! error TS1201: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. + +==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding_1.ts (0 errors) ==== + import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; + var x: number = defaultBinding; \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.js new file mode 100644 index 0000000000000..7f67628c18e95 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.js @@ -0,0 +1,23 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1.ts] //// + +//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_0.ts] + +var a = 10; +export = a; + +//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_1.ts] +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; +var x: number = defaultBinding; + +//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_0.js] +var a = 10; +module.exports = a; +//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_1.js] +var defaultBinding = require("es6ImportDefaultBindingFollowedWithNamespaceBinding_0"); +var x = defaultBinding; + + +//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_0.d.ts] +declare var a: number; +export = a; +//// [es6ImportDefaultBindingFollowedWithNamespaceBinding_1.d.ts] diff --git a/tests/baselines/reference/es6ImportDefaultBindingMergeErrors.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingMergeErrors.errors.txt new file mode 100644 index 0000000000000..d6aacf0ba4062 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingMergeErrors.errors.txt @@ -0,0 +1,26 @@ +tests/cases/compiler/es6ImportDefaultBindingMergeErrors_1.ts(5,8): error TS2440: Import declaration conflicts with local declaration of 'defaultBinding2' +tests/cases/compiler/es6ImportDefaultBindingMergeErrors_1.ts(7,8): error TS2300: Duplicate identifier 'defaultBinding3'. +tests/cases/compiler/es6ImportDefaultBindingMergeErrors_1.ts(8,8): error TS2300: Duplicate identifier 'defaultBinding3'. + + +==== tests/cases/compiler/es6ImportDefaultBindingMergeErrors_0.ts (0 errors) ==== + + var a = 10; + export = a; + +==== tests/cases/compiler/es6ImportDefaultBindingMergeErrors_1.ts (3 errors) ==== + import defaultBinding from "es6ImportDefaultBindingMergeErrors_0"; + interface defaultBinding { // This is ok + } + var x = defaultBinding; + import defaultBinding2 from "es6ImportDefaultBindingMergeErrors_0"; // Should be error + ~~~~~~~~~~~~~~~ +!!! error TS2440: Import declaration conflicts with local declaration of 'defaultBinding2' + var defaultBinding2 = "hello world"; + import defaultBinding3 from "es6ImportDefaultBindingMergeErrors_0"; // Should be error + ~~~~~~~~~~~~~~~ +!!! error TS2300: Duplicate identifier 'defaultBinding3'. + import defaultBinding3 from "es6ImportDefaultBindingMergeErrors_0"; // SHould be error + ~~~~~~~~~~~~~~~ +!!! error TS2300: Duplicate identifier 'defaultBinding3'. + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingMergeErrors.js b/tests/baselines/reference/es6ImportDefaultBindingMergeErrors.js new file mode 100644 index 0000000000000..628faec6c27cc --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingMergeErrors.js @@ -0,0 +1,25 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingMergeErrors.ts] //// + +//// [es6ImportDefaultBindingMergeErrors_0.ts] + +var a = 10; +export = a; + +//// [es6ImportDefaultBindingMergeErrors_1.ts] +import defaultBinding from "es6ImportDefaultBindingMergeErrors_0"; +interface defaultBinding { // This is ok +} +var x = defaultBinding; +import defaultBinding2 from "es6ImportDefaultBindingMergeErrors_0"; // Should be error +var defaultBinding2 = "hello world"; +import defaultBinding3 from "es6ImportDefaultBindingMergeErrors_0"; // Should be error +import defaultBinding3 from "es6ImportDefaultBindingMergeErrors_0"; // SHould be error + + +//// [es6ImportDefaultBindingMergeErrors_0.js] +var a = 10; +module.exports = a; +//// [es6ImportDefaultBindingMergeErrors_1.js] +var defaultBinding = require("es6ImportDefaultBindingMergeErrors_0"); +var x = defaultBinding; +var defaultBinding2 = "hello world"; diff --git a/tests/baselines/reference/es6ImportDefaultBindingNoDefaultProperty.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingNoDefaultProperty.errors.txt new file mode 100644 index 0000000000000..a6aaf9f550866 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingNoDefaultProperty.errors.txt @@ -0,0 +1,12 @@ +tests/cases/compiler/es6ImportDefaultBindingNoDefaultProperty_1.ts(1,8): error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingNoDefaultProperty_0"' has no default export or export assignment. + + +==== tests/cases/compiler/es6ImportDefaultBindingNoDefaultProperty_0.ts (0 errors) ==== + + export var a = 10; + +==== tests/cases/compiler/es6ImportDefaultBindingNoDefaultProperty_1.ts (1 errors) ==== + import defaultBinding from "es6ImportDefaultBindingNoDefaultProperty_0"; + ~~~~~~~~~~~~~~ +!!! error TS1192: External module '"tests/cases/compiler/es6ImportDefaultBindingNoDefaultProperty_0"' has no default export or export assignment. + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingNoDefaultProperty.js b/tests/baselines/reference/es6ImportDefaultBindingNoDefaultProperty.js new file mode 100644 index 0000000000000..f824dbf71d56e --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingNoDefaultProperty.js @@ -0,0 +1,13 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingNoDefaultProperty.ts] //// + +//// [es6ImportDefaultBindingNoDefaultProperty_0.ts] + +export var a = 10; + +//// [es6ImportDefaultBindingNoDefaultProperty_1.ts] +import defaultBinding from "es6ImportDefaultBindingNoDefaultProperty_0"; + + +//// [es6ImportDefaultBindingNoDefaultProperty_0.js] +exports.a = 10; +//// [es6ImportDefaultBindingNoDefaultProperty_1.js] diff --git a/tests/baselines/reference/es6ImportNamedImportMergeErrors.errors.txt b/tests/baselines/reference/es6ImportNamedImportMergeErrors.errors.txt new file mode 100644 index 0000000000000..b9461b6caca06 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportMergeErrors.errors.txt @@ -0,0 +1,33 @@ +tests/cases/compiler/es6ImportNamedImportMergeErrors_1.ts(5,10): error TS2440: Import declaration conflicts with local declaration of 'x' +tests/cases/compiler/es6ImportNamedImportMergeErrors_1.ts(7,10): error TS2440: Import declaration conflicts with local declaration of 'x44' +tests/cases/compiler/es6ImportNamedImportMergeErrors_1.ts(9,10): error TS2300: Duplicate identifier 'z'. +tests/cases/compiler/es6ImportNamedImportMergeErrors_1.ts(10,16): error TS2300: Duplicate identifier 'z'. + + +==== tests/cases/compiler/es6ImportNamedImportMergeErrors_0.ts (0 errors) ==== + + export var a = 10; + export var x = a; + export var z = a; + export var z1 = a; + +==== tests/cases/compiler/es6ImportNamedImportMergeErrors_1.ts (4 errors) ==== + import { a } from "es6ImportNamedImportMergeErrors_0"; + interface a { } // shouldnt be error + import { x as x1 } from "es6ImportNamedImportMergeErrors_0"; + interface x1 { } // shouldnt be error + import { x } from "es6ImportNamedImportMergeErrors_0"; // should be error + ~ +!!! error TS2440: Import declaration conflicts with local declaration of 'x' + var x = 10; + import { x as x44 } from "es6ImportNamedImportMergeErrors_0"; // should be error + ~~~~~~~~ +!!! error TS2440: Import declaration conflicts with local declaration of 'x44' + var x44 = 10; + import { z } from "es6ImportNamedImportMergeErrors_0"; // should be error + ~ +!!! error TS2300: Duplicate identifier 'z'. + import { z1 as z } from "es6ImportNamedImportMergeErrors_0"; // should be error + ~ +!!! error TS2300: Duplicate identifier 'z'. + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNamedImportMergeErrors.js b/tests/baselines/reference/es6ImportNamedImportMergeErrors.js new file mode 100644 index 0000000000000..fad411f557d55 --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportMergeErrors.js @@ -0,0 +1,30 @@ +//// [tests/cases/compiler/es6ImportNamedImportMergeErrors.ts] //// + +//// [es6ImportNamedImportMergeErrors_0.ts] + +export var a = 10; +export var x = a; +export var z = a; +export var z1 = a; + +//// [es6ImportNamedImportMergeErrors_1.ts] +import { a } from "es6ImportNamedImportMergeErrors_0"; +interface a { } // shouldnt be error +import { x as x1 } from "es6ImportNamedImportMergeErrors_0"; +interface x1 { } // shouldnt be error +import { x } from "es6ImportNamedImportMergeErrors_0"; // should be error +var x = 10; +import { x as x44 } from "es6ImportNamedImportMergeErrors_0"; // should be error +var x44 = 10; +import { z } from "es6ImportNamedImportMergeErrors_0"; // should be error +import { z1 as z } from "es6ImportNamedImportMergeErrors_0"; // should be error + + +//// [es6ImportNamedImportMergeErrors_0.js] +exports.a = 10; +exports.x = exports.a; +exports.z = exports.a; +exports.z1 = exports.a; +//// [es6ImportNamedImportMergeErrors_1.js] +var x = 10; +var x44 = 10; diff --git a/tests/baselines/reference/es6ImportNamedImportNoExportMember.errors.txt b/tests/baselines/reference/es6ImportNamedImportNoExportMember.errors.txt new file mode 100644 index 0000000000000..57a77410cb24b --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportNoExportMember.errors.txt @@ -0,0 +1,16 @@ +tests/cases/compiler/es6ImportNamedImport_1.ts(1,10): error TS2305: Module '"tests/cases/compiler/es6ImportNamedImportNoExportMember_0"' has no exported member 'a1'. +tests/cases/compiler/es6ImportNamedImport_1.ts(2,10): error TS2305: Module '"tests/cases/compiler/es6ImportNamedImportNoExportMember_0"' has no exported member 'x1'. + + +==== tests/cases/compiler/es6ImportNamedImportNoExportMember_0.ts (0 errors) ==== + + export var a = 10; + export var x = a; + +==== tests/cases/compiler/es6ImportNamedImport_1.ts (2 errors) ==== + import { a1 } from "es6ImportNamedImportNoExportMember_0"; + ~~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportNamedImportNoExportMember_0"' has no exported member 'a1'. + import { x1 as x } from "es6ImportNamedImportNoExportMember_0"; + ~~ +!!! error TS2305: Module '"tests/cases/compiler/es6ImportNamedImportNoExportMember_0"' has no exported member 'x1'. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportNamedImportNoExportMember.js b/tests/baselines/reference/es6ImportNamedImportNoExportMember.js new file mode 100644 index 0000000000000..da473fa42a38d --- /dev/null +++ b/tests/baselines/reference/es6ImportNamedImportNoExportMember.js @@ -0,0 +1,15 @@ +//// [tests/cases/compiler/es6ImportNamedImportNoExportMember.ts] //// + +//// [es6ImportNamedImportNoExportMember_0.ts] + +export var a = 10; +export var x = a; + +//// [es6ImportNamedImport_1.ts] +import { a1 } from "es6ImportNamedImportNoExportMember_0"; +import { x1 as x } from "es6ImportNamedImportNoExportMember_0"; + +//// [es6ImportNamedImportNoExportMember_0.js] +exports.a = 10; +exports.x = exports.a; +//// [es6ImportNamedImport_1.js] diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.js b/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.js new file mode 100644 index 0000000000000..a0d88a5cf8c36 --- /dev/null +++ b/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.js @@ -0,0 +1,19 @@ +//// [tests/cases/compiler/es6ImportWithoutFromClauseNonInstantiatedModule.ts] //// + +//// [es6ImportWithoutFromClauseNonInstantiatedModule_0.ts] + +export interface i { +} + +//// [es6ImportWithoutFromClauseNonInstantiatedModule_1.ts] +import "es6ImportWithoutFromClauseNonInstantiatedModule_0"; + +//// [es6ImportWithoutFromClauseNonInstantiatedModule_0.js] +//// [es6ImportWithoutFromClauseNonInstantiatedModule_1.js] +require("es6ImportWithoutFromClauseNonInstantiatedModule_0"); + + +//// [es6ImportWithoutFromClauseNonInstantiatedModule_0.d.ts] +export interface i { +} +//// [es6ImportWithoutFromClauseNonInstantiatedModule_1.d.ts] diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.types b/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.types new file mode 100644 index 0000000000000..2be3f67f1e963 --- /dev/null +++ b/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.types @@ -0,0 +1,9 @@ +=== tests/cases/compiler/es6ImportWithoutFromClauseNonInstantiatedModule_0.ts === + +export interface i { +>i : i +} + +=== tests/cases/compiler/es6ImportWithoutFromClauseNonInstantiatedModule_1.ts === +import "es6ImportWithoutFromClauseNonInstantiatedModule_0"; +No type information for this code. \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1.ts new file mode 100644 index 0000000000000..c1ac752426e00 --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1.ts @@ -0,0 +1,20 @@ +// @target: es6 +// @declaration: true + +// @filename: es6ImportDefaultBindingFollowedWithNamedImport1_0.ts +var a = 10; +export = a; + +// @filename: es6ImportDefaultBindingFollowedWithNamedImport1_1.ts +import defaultBinding1, { } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding1; +import defaultBinding2, { a } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding2; +import defaultBinding3, { a as b } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding3; +import defaultBinding4, { x, a as y } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding4; +import defaultBinding5, { x as z, } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding5; +import defaultBinding6, { m, } from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; +var x1: number = defaultBinding6; diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportDts.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportDts.ts new file mode 100644 index 0000000000000..a84dab940338d --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportDts.ts @@ -0,0 +1,24 @@ +// @module: commonjs +// @declaration: true + +// @filename: server.ts +export class a { } +export class x { } +export class m { } +export class a11 { } +export class a12 { } +export class x11 { } + +// @filename: client.ts +import defaultBinding1, { } from "server"; +import defaultBinding2, { a } from "server"; +export var x1 = new a(); +import defaultBinding3, { a11 as b } from "server"; +export var x2 = new b(); +import defaultBinding4, { x, a12 as y } from "server"; +export var x4 = new x(); +export var x5 = new y(); +import defaultBinding5, { x11 as z, } from "server"; +export var x3 = new z(); +import defaultBinding6, { m, } from "server"; +export var x6 = new m(); diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1.ts new file mode 100644 index 0000000000000..81113b776b4eb --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1.ts @@ -0,0 +1,10 @@ +// @target: es6 +// @declaration: true + +// @filename: es6ImportDefaultBindingFollowedWithNamespaceBinding_0.ts +var a = 10; +export = a; + +// @filename: es6ImportDefaultBindingFollowedWithNamespaceBinding_1.ts +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; +var x: number = defaultBinding; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportDefaultBindingMergeErrors.ts b/tests/cases/compiler/es6ImportDefaultBindingMergeErrors.ts new file mode 100644 index 0000000000000..cd1bad8371680 --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingMergeErrors.ts @@ -0,0 +1,15 @@ +// @module: commonjs + +// @filename: es6ImportDefaultBindingMergeErrors_0.ts +var a = 10; +export = a; + +// @filename: es6ImportDefaultBindingMergeErrors_1.ts +import defaultBinding from "es6ImportDefaultBindingMergeErrors_0"; +interface defaultBinding { // This is ok +} +var x = defaultBinding; +import defaultBinding2 from "es6ImportDefaultBindingMergeErrors_0"; // Should be error +var defaultBinding2 = "hello world"; +import defaultBinding3 from "es6ImportDefaultBindingMergeErrors_0"; // Should be error +import defaultBinding3 from "es6ImportDefaultBindingMergeErrors_0"; // SHould be error diff --git a/tests/cases/compiler/es6ImportDefaultBindingNoDefaultProperty.ts b/tests/cases/compiler/es6ImportDefaultBindingNoDefaultProperty.ts new file mode 100644 index 0000000000000..5ab1c74372174 --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingNoDefaultProperty.ts @@ -0,0 +1,7 @@ +// @module: commonjs + +// @filename: es6ImportDefaultBindingNoDefaultProperty_0.ts +export var a = 10; + +// @filename: es6ImportDefaultBindingNoDefaultProperty_1.ts +import defaultBinding from "es6ImportDefaultBindingNoDefaultProperty_0"; diff --git a/tests/cases/compiler/es6ImportNamedImportMergeErrors.ts b/tests/cases/compiler/es6ImportNamedImportMergeErrors.ts new file mode 100644 index 0000000000000..54e30be1e2352 --- /dev/null +++ b/tests/cases/compiler/es6ImportNamedImportMergeErrors.ts @@ -0,0 +1,19 @@ +// @module: commonjs + +// @filename: es6ImportNamedImportMergeErrors_0.ts +export var a = 10; +export var x = a; +export var z = a; +export var z1 = a; + +// @filename: es6ImportNamedImportMergeErrors_1.ts +import { a } from "es6ImportNamedImportMergeErrors_0"; +interface a { } // shouldnt be error +import { x as x1 } from "es6ImportNamedImportMergeErrors_0"; +interface x1 { } // shouldnt be error +import { x } from "es6ImportNamedImportMergeErrors_0"; // should be error +var x = 10; +import { x as x44 } from "es6ImportNamedImportMergeErrors_0"; // should be error +var x44 = 10; +import { z } from "es6ImportNamedImportMergeErrors_0"; // should be error +import { z1 as z } from "es6ImportNamedImportMergeErrors_0"; // should be error diff --git a/tests/cases/compiler/es6ImportNamedImportNoExportMember.ts b/tests/cases/compiler/es6ImportNamedImportNoExportMember.ts new file mode 100644 index 0000000000000..bd507308d8d6f --- /dev/null +++ b/tests/cases/compiler/es6ImportNamedImportNoExportMember.ts @@ -0,0 +1,9 @@ +// @module: commonjs + +// @filename: es6ImportNamedImportNoExportMember_0.ts +export var a = 10; +export var x = a; + +// @filename: es6ImportNamedImport_1.ts +import { a1 } from "es6ImportNamedImportNoExportMember_0"; +import { x1 as x } from "es6ImportNamedImportNoExportMember_0"; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportWithoutFromClauseNonInstantiatedModule.ts b/tests/cases/compiler/es6ImportWithoutFromClauseNonInstantiatedModule.ts new file mode 100644 index 0000000000000..22b250435c821 --- /dev/null +++ b/tests/cases/compiler/es6ImportWithoutFromClauseNonInstantiatedModule.ts @@ -0,0 +1,9 @@ +// @target: es6 +// @declaration: true + +// @filename: es6ImportWithoutFromClauseNonInstantiatedModule_0.ts +export interface i { +} + +// @filename: es6ImportWithoutFromClauseNonInstantiatedModule_1.ts +import "es6ImportWithoutFromClauseNonInstantiatedModule_0"; \ No newline at end of file From 7b3e50fb98c6514680bb209f2f0683f72ee8e435 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 11 Mar 2015 23:29:30 -0700 Subject: [PATCH 032/224] Emit in ES6 module if script target is es6 or higher Conflicts: src/compiler/emitter.ts tests/baselines/reference/es6ImportDefaultBinding.js tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js tests/baselines/reference/es6ImportNameSpaceImport.js tests/baselines/reference/es6ImportNamedImport.js --- src/compiler/emitter.ts | 17 +++++++++++++++-- .../baselines/reference/es6ExportAssignment.js | 1 - ...ortDefaultBindingFollowedWithNamedImport1.js | 7 ------- ...efaultBindingFollowedWithNamespaceBinding.js | 1 - ...faultBindingFollowedWithNamespaceBinding1.js | 2 -- .../reference/es6ImportEqualsDeclaration.js | 1 - .../es6ImportNamedImportParsingError.js | 1 - .../reference/es6ImportWithoutFromClause.js | 1 - ...ortWithoutFromClauseNonInstantiatedModule.js | 1 - 9 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 4b038ab1c4cfd..7c435176b9cf5 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -5207,6 +5207,7 @@ module ts { } function emitAMDModule(node: SourceFile, startIndex: number) { + createExternalModuleInfo(node); writeLine(); write("define("); sortAMDModules(node.amdDependencies); @@ -5257,6 +5258,16 @@ module ts { } function emitCommonJSModule(node: SourceFile, startIndex: number) { + createExternalModuleInfo(node); + emitCaptureThisForNodeIfNecessary(node); + emitLinesStartingAt(node.statements, startIndex); + emitTempDeclarations(/*newLine*/ true); + emitExportDefault(node, /*emitAsReturn*/ false); + } + + function emitES6Module(node: SourceFile, startIndex: number) { + externalImports = undefined; + exportSpecifiers = undefined; emitCaptureThisForNodeIfNecessary(node); emitLinesStartingAt(node.statements, startIndex); emitTempDeclarations(/*newLine*/ true); @@ -5323,13 +5334,15 @@ module ts { extendsEmitted = true; } if (isExternalModule(node)) { - createExternalModuleInfo(node); if (compilerOptions.module === ModuleKind.AMD) { emitAMDModule(node, startIndex); } - else { + else if (compilerOptions.module === ModuleKind.CommonJS || compilerOptions.target < ScriptTarget.ES6) { emitCommonJSModule(node, startIndex); } + else { + emitES6Module(node, startIndex); + } } else { externalImports = undefined; diff --git a/tests/baselines/reference/es6ExportAssignment.js b/tests/baselines/reference/es6ExportAssignment.js index 7d603282b0c12..4a4e0368bb7e8 100644 --- a/tests/baselines/reference/es6ExportAssignment.js +++ b/tests/baselines/reference/es6ExportAssignment.js @@ -5,4 +5,3 @@ export = a; //// [es6ExportAssignment.js] var a = 10; -module.exports = a; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.js index 765d09fae79c3..2c234b60ae81e 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.js @@ -22,19 +22,12 @@ var x1: number = defaultBinding6; //// [es6ImportDefaultBindingFollowedWithNamedImport1_0.js] var a = 10; -module.exports = a; //// [es6ImportDefaultBindingFollowedWithNamedImport1_1.js] -var defaultBinding1 = require("es6ImportDefaultBindingFollowedWithNamedImport1_0"); var x1 = defaultBinding1; -var defaultBinding2 = require("es6ImportDefaultBindingFollowedWithNamedImport1_0"); var x1 = defaultBinding2; -var defaultBinding3 = require("es6ImportDefaultBindingFollowedWithNamedImport1_0"); var x1 = defaultBinding3; -var defaultBinding4 = require("es6ImportDefaultBindingFollowedWithNamedImport1_0"); var x1 = defaultBinding4; -var defaultBinding5 = require("es6ImportDefaultBindingFollowedWithNamedImport1_0"); var x1 = defaultBinding5; -var defaultBinding6 = require("es6ImportDefaultBindingFollowedWithNamedImport1_0"); var x1 = defaultBinding6; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js index 1241140b121d9..a67436de60c60 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js @@ -11,7 +11,6 @@ var x: number = nameSpaceBinding.a; //// [es6ImportDefaultBindingFollowedWithNamespaceBinding_0.js] exports.a = 10; //// [es6ImportDefaultBindingFollowedWithNamespaceBinding_1.js] -var defaultBinding = require("es6ImportDefaultBindingFollowedWithNamespaceBinding_0"); var x = nameSpaceBinding.a; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.js index 7f67628c18e95..f2a31d6c6627a 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.js @@ -11,9 +11,7 @@ var x: number = defaultBinding; //// [es6ImportDefaultBindingFollowedWithNamespaceBinding_0.js] var a = 10; -module.exports = a; //// [es6ImportDefaultBindingFollowedWithNamespaceBinding_1.js] -var defaultBinding = require("es6ImportDefaultBindingFollowedWithNamespaceBinding_0"); var x = defaultBinding; diff --git a/tests/baselines/reference/es6ImportEqualsDeclaration.js b/tests/baselines/reference/es6ImportEqualsDeclaration.js index 47cfd2886322b..5195bdc631b30 100644 --- a/tests/baselines/reference/es6ImportEqualsDeclaration.js +++ b/tests/baselines/reference/es6ImportEqualsDeclaration.js @@ -10,5 +10,4 @@ import a = require("server"); //// [server.js] var a = 10; -module.exports = a; //// [client.js] diff --git a/tests/baselines/reference/es6ImportNamedImportParsingError.js b/tests/baselines/reference/es6ImportNamedImportParsingError.js index f9d8e90f707f1..4b60b26f88d55 100644 --- a/tests/baselines/reference/es6ImportNamedImportParsingError.js +++ b/tests/baselines/reference/es6ImportNamedImportParsingError.js @@ -24,5 +24,4 @@ from; } from; "es6ImportNamedImportParsingError_0"; -var _module_1 = require(); "es6ImportNamedImportParsingError_0"; diff --git a/tests/baselines/reference/es6ImportWithoutFromClause.js b/tests/baselines/reference/es6ImportWithoutFromClause.js index 2f35122571fec..99d12a4107e19 100644 --- a/tests/baselines/reference/es6ImportWithoutFromClause.js +++ b/tests/baselines/reference/es6ImportWithoutFromClause.js @@ -11,7 +11,6 @@ import "es6ImportWithoutFromClause_0"; //// [es6ImportWithoutFromClause_0.js] exports.a = 10; //// [es6ImportWithoutFromClause_1.js] -require("es6ImportWithoutFromClause_0"); //// [es6ImportWithoutFromClause_0.d.ts] diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.js b/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.js index a0d88a5cf8c36..c676222ce8132 100644 --- a/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.js +++ b/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.js @@ -10,7 +10,6 @@ import "es6ImportWithoutFromClauseNonInstantiatedModule_0"; //// [es6ImportWithoutFromClauseNonInstantiatedModule_0.js] //// [es6ImportWithoutFromClauseNonInstantiatedModule_1.js] -require("es6ImportWithoutFromClauseNonInstantiatedModule_0"); //// [es6ImportWithoutFromClauseNonInstantiatedModule_0.d.ts] From 8c26507bd5346b5194e795493486023110366d9a Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 12 Mar 2015 00:17:40 -0700 Subject: [PATCH 033/224] Support for emitting import declaration in es6 format Conflicts: src/compiler/emitter.ts tests/baselines/reference/es6ImportDefaultBinding.js tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js tests/baselines/reference/es6ImportNameSpaceImport.js tests/baselines/reference/es6ImportNamedImport.js --- src/compiler/emitter.ts | 85 ++++++++++++++++++- ...tDefaultBindingFollowedWithNamedImport1.js | 6 ++ ...aultBindingFollowedWithNamespaceBinding.js | 1 + ...ultBindingFollowedWithNamespaceBinding1.js | 1 + .../es6ImportNamedImportParsingError.js | 1 + .../reference/es6ImportWithoutFromClause.js | 1 + ...tWithoutFromClauseNonInstantiatedModule.js | 1 + 7 files changed, 94 insertions(+), 2 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 7c435176b9cf5..8f79c036dfdc9 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4996,7 +4996,86 @@ module ts { } } - function emitImportDeclaration(node: ImportDeclaration | ImportEqualsDeclaration) { + function emitImportDeclaration(node: ImportDeclaration) { + if (compilerOptions.target < ScriptTarget.ES6) { + return emitExternalImportDeclaration(node); + } + + // ES6 import + if (node.importClause) { + var shouldEmitDefaultBindings = node.importClause.name && resolver.isReferencedAliasDeclaration(node.importClause); + var shouldEmitNamedBindings = hasReferencedNamedBindings(); + if (shouldEmitDefaultBindings || shouldEmitNamedBindings) { + write("import "); + emitStart(node.importClause); + if (shouldEmitDefaultBindings) { + emit(node.importClause.name); + if (shouldEmitNamedBindings) { + write(", "); + } + } + if (shouldEmitNamedBindings) { + emitLeadingComments(node.importClause.namedBindings); + emitStart(node.importClause.namedBindings); + if (node.importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { + write("* as "); + emit((node.importClause.namedBindings).name); + } + else { + write("{ "); + var importSpecifiers = (node.importClause.namedBindings).elements; + var currentTextPos = writer.getTextPos(); + var needsComma = false; + for (var i = 0, n = importSpecifiers.length; i < n; i++) { + if (resolver.isReferencedAliasDeclaration(importSpecifiers[i])) { + if (needsComma) { + write(", "); + } + needsComma = true; + emit(importSpecifiers[i]); + } + } + write(" }"); + } + emitEnd(node.importClause.namedBindings); + emitTrailingComments(node.importClause.namedBindings); + } + + emitEnd(node.importClause); + write(" from "); + emit(node.moduleSpecifier); + write(";"); + } + } + else { + write("import "); + emit(node.moduleSpecifier); + write(";"); + } + + function hasReferencedNamedBindings() { + if (node.importClause.namedBindings) { + if (node.importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { + return resolver.isReferencedAliasDeclaration(node.importClause.namedBindings); + } + else { + return forEach((node.importClause.namedBindings).elements, + namedImport => resolver.isReferencedAliasDeclaration(namedImport)); + } + } + } + } + + function emitImportSpecifier(node: ImportSpecifier) { + Debug.assert(compilerOptions.target >= ScriptTarget.ES6); + if (node.propertyName) { + emit(node.propertyName); + write(" as "); + } + emit(node.name); + } + + function emitExternalImportDeclaration(node: ImportDeclaration | ImportEqualsDeclaration) { var info = getExternalImportInfo(node); if (info) { var declarationNode = info.declarationNode; @@ -5038,7 +5117,7 @@ module ts { function emitImportEqualsDeclaration(node: ImportEqualsDeclaration) { if (isExternalModuleImportEqualsDeclaration(node)) { - emitImportDeclaration(node); + emitExternalImportDeclaration(node); return; } // preserve old compiler's behavior: emit 'var' for import declaration (even if we do not consider them referenced) when @@ -5561,6 +5640,8 @@ module ts { return emitModuleDeclaration(node); case SyntaxKind.ImportDeclaration: return emitImportDeclaration(node); + case SyntaxKind.ImportSpecifier: + return emitImportSpecifier(node); case SyntaxKind.ImportEqualsDeclaration: return emitImportEqualsDeclaration(node); case SyntaxKind.ExportDeclaration: diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.js index 2c234b60ae81e..bd6d6013c057b 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.js @@ -23,11 +23,17 @@ var x1: number = defaultBinding6; //// [es6ImportDefaultBindingFollowedWithNamedImport1_0.js] var a = 10; //// [es6ImportDefaultBindingFollowedWithNamedImport1_1.js] +import defaultBinding1 from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; var x1 = defaultBinding1; +import defaultBinding2 from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; var x1 = defaultBinding2; +import defaultBinding3 from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; var x1 = defaultBinding3; +import defaultBinding4 from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; var x1 = defaultBinding4; +import defaultBinding5 from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; var x1 = defaultBinding5; +import defaultBinding6 from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; var x1 = defaultBinding6; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js index a67436de60c60..3f11e5076efc8 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js @@ -11,6 +11,7 @@ var x: number = nameSpaceBinding.a; //// [es6ImportDefaultBindingFollowedWithNamespaceBinding_0.js] exports.a = 10; //// [es6ImportDefaultBindingFollowedWithNamespaceBinding_1.js] +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; var x = nameSpaceBinding.a; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.js index f2a31d6c6627a..9872df4ed5a59 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.js @@ -12,6 +12,7 @@ var x: number = defaultBinding; //// [es6ImportDefaultBindingFollowedWithNamespaceBinding_0.js] var a = 10; //// [es6ImportDefaultBindingFollowedWithNamespaceBinding_1.js] +import defaultBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; var x = defaultBinding; diff --git a/tests/baselines/reference/es6ImportNamedImportParsingError.js b/tests/baselines/reference/es6ImportNamedImportParsingError.js index 4b60b26f88d55..5d80a3d7a8c82 100644 --- a/tests/baselines/reference/es6ImportNamedImportParsingError.js +++ b/tests/baselines/reference/es6ImportNamedImportParsingError.js @@ -24,4 +24,5 @@ from; } from; "es6ImportNamedImportParsingError_0"; +import { a } from , from; "es6ImportNamedImportParsingError_0"; diff --git a/tests/baselines/reference/es6ImportWithoutFromClause.js b/tests/baselines/reference/es6ImportWithoutFromClause.js index 99d12a4107e19..cf0713d4ec525 100644 --- a/tests/baselines/reference/es6ImportWithoutFromClause.js +++ b/tests/baselines/reference/es6ImportWithoutFromClause.js @@ -11,6 +11,7 @@ import "es6ImportWithoutFromClause_0"; //// [es6ImportWithoutFromClause_0.js] exports.a = 10; //// [es6ImportWithoutFromClause_1.js] +import "es6ImportWithoutFromClause_0"; //// [es6ImportWithoutFromClause_0.d.ts] diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.js b/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.js index c676222ce8132..e63dd4bb53a0e 100644 --- a/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.js +++ b/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.js @@ -10,6 +10,7 @@ import "es6ImportWithoutFromClauseNonInstantiatedModule_0"; //// [es6ImportWithoutFromClauseNonInstantiatedModule_0.js] //// [es6ImportWithoutFromClauseNonInstantiatedModule_1.js] +import "es6ImportWithoutFromClauseNonInstantiatedModule_0"; //// [es6ImportWithoutFromClauseNonInstantiatedModule_0.d.ts] From 3ed8bcc179eb9f0707b01fb05f4aca0b871ac52c Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 12 Mar 2015 00:18:20 -0700 Subject: [PATCH 034/224] Simplify module kind selection --- src/compiler/emitter.ts | 10 +-- .../reference/constDeclarations-access5.js | 70 +++++++++---------- .../es6ModuleWithModuleGenTargetAmd.js | 20 +++--- 3 files changed, 47 insertions(+), 53 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 8f79c036dfdc9..c1e0b24e4057e 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -5413,14 +5413,14 @@ module ts { extendsEmitted = true; } if (isExternalModule(node)) { - if (compilerOptions.module === ModuleKind.AMD) { - emitAMDModule(node, startIndex); + if (compilerOptions.target >= ScriptTarget.ES6) { + emitES6Module(node, startIndex); } - else if (compilerOptions.module === ModuleKind.CommonJS || compilerOptions.target < ScriptTarget.ES6) { - emitCommonJSModule(node, startIndex); + else if (compilerOptions.module === ModuleKind.AMD) { + emitAMDModule(node, startIndex); } else { - emitES6Module(node, startIndex); + emitCommonJSModule(node, startIndex); } } else { diff --git a/tests/baselines/reference/constDeclarations-access5.js b/tests/baselines/reference/constDeclarations-access5.js index 7acc95ad05501..0d70eb8600054 100644 --- a/tests/baselines/reference/constDeclarations-access5.js +++ b/tests/baselines/reference/constDeclarations-access5.js @@ -49,41 +49,37 @@ m.x.toString(); //// [constDeclarations_access_1.js] -define(["require", "exports"], function (require, exports) { - exports.x = 0; -}); +exports.x = 0; //// [constDeclarations_access_2.js] -define(["require", "exports", 'constDeclarations_access_1'], function (require, exports, m) { - // Errors - m.x = 1; - m.x += 2; - m.x -= 3; - m.x *= 4; - m.x /= 5; - m.x %= 6; - m.x <<= 7; - m.x >>= 8; - m.x >>>= 9; - m.x &= 10; - m.x |= 11; - m.x ^= 12; - m; - m.x++; - m.x--; - ++m.x; - --m.x; - ++((m.x)); - m["x"] = 0; - // OK - var a = m.x + 1; - function f(v) { - } - f(m.x); - if (m.x) { - } - m.x; - (m.x); - -m.x; - +m.x; - m.x.toString(); -}); +// Errors +m.x = 1; +m.x += 2; +m.x -= 3; +m.x *= 4; +m.x /= 5; +m.x %= 6; +m.x <<= 7; +m.x >>= 8; +m.x >>>= 9; +m.x &= 10; +m.x |= 11; +m.x ^= 12; +m; +m.x++; +m.x--; +++m.x; +--m.x; +++((m.x)); +m["x"] = 0; +// OK +var a = m.x + 1; +function f(v) { +} +f(m.x); +if (m.x) { +} +m.x; +(m.x); +-m.x; ++m.x; +m.x.toString(); diff --git a/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.js b/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.js index 90768d474d140..fd0c07ecdc4df 100644 --- a/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.js +++ b/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.js @@ -12,14 +12,12 @@ export class A } //// [es6ModuleWithModuleGenTargetAmd.js] -define(["require", "exports"], function (require, exports) { - var A = (function () { - function A() { - } - A.prototype.B = function () { - return 42; - }; - return A; - })(); - exports.A = A; -}); +var A = (function () { + function A() { + } + A.prototype.B = function () { + return 42; + }; + return A; +})(); +exports.A = A; From 4b7548487c9df7bf387a7c36e84b8d61061d1de8 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 12 Feb 2015 17:54:30 -0800 Subject: [PATCH 035/224] Fix the checks with language version to use default es3 --- src/compiler/checker.ts | 6 +++--- src/compiler/emitter.ts | 8 ++++---- src/compiler/program.ts | 6 ++++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a43d291773555..935e82c5bd013 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -724,7 +724,7 @@ module ts { } function getExportsForModule(moduleSymbol: Symbol): SymbolTable { - if (compilerOptions.target < ScriptTarget.ES6) { + if (languageVersion < ScriptTarget.ES6) { // A default export hides all other exports in CommonJS and AMD modules var defaultSymbol = getExportAssignmentSymbol(moduleSymbol); if (defaultSymbol) { @@ -9902,7 +9902,7 @@ module ts { } } else { - if (compilerOptions.target >= ScriptTarget.ES6) { + if (languageVersion >= ScriptTarget.ES6) { // Import equals declaration is deprecated in es6 or above grammarErrorOnNode(node, Diagnostics.Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_import_Asterisk_from_mod_import_a_from_mod_or_import_d_from_mod_instead); } @@ -9946,7 +9946,7 @@ module ts { } checkExternalModuleExports(container); - if (compilerOptions.target >= ScriptTarget.ES6) { + if (languageVersion >= ScriptTarget.ES6) { // export assignment is deprecated in es6 or above grammarErrorOnNode(node, Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_export_default_instead); } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index c1e0b24e4057e..84312ef3be3f5 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3228,7 +3228,7 @@ module ts { } function emitTaggedTemplateExpression(node: TaggedTemplateExpression): void { - if (compilerOptions.target >= ScriptTarget.ES6) { + if (languageVersion >= ScriptTarget.ES6) { emit(node.tag); write(" "); emit(node.template); @@ -4997,7 +4997,7 @@ module ts { } function emitImportDeclaration(node: ImportDeclaration) { - if (compilerOptions.target < ScriptTarget.ES6) { + if (languageVersion < ScriptTarget.ES6) { return emitExternalImportDeclaration(node); } @@ -5067,7 +5067,7 @@ module ts { } function emitImportSpecifier(node: ImportSpecifier) { - Debug.assert(compilerOptions.target >= ScriptTarget.ES6); + Debug.assert(languageVersion >= ScriptTarget.ES6); if (node.propertyName) { emit(node.propertyName); write(" as "); @@ -5413,7 +5413,7 @@ module ts { extendsEmitted = true; } if (isExternalModule(node)) { - if (compilerOptions.target >= ScriptTarget.ES6) { + if (languageVersion >= ScriptTarget.ES6) { emitES6Module(node, startIndex); } else if (compilerOptions.module === ModuleKind.AMD) { diff --git a/src/compiler/program.ts b/src/compiler/program.ts index a97da0dac137d..d6160e1bee83e 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -426,9 +426,11 @@ module ts { return; } + var languageVersion = options.target || ScriptTarget.ES3; + var firstExternalModuleSourceFile = forEach(files, f => isExternalModule(f) ? f : undefined); if (firstExternalModuleSourceFile && !options.module) { - if (!options.module && options.target < ScriptTarget.ES6) { + if (!options.module && languageVersion < ScriptTarget.ES6) { // We cannot use createDiagnosticFromNode because nodes do not have parents yet var span = getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator); diagnostics.add(createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_external_modules_unless_the_module_flag_is_provided)); @@ -436,7 +438,7 @@ module ts { } // Cannot specify module gen target when in es6 or above - if (options.module && options.target >= ScriptTarget.ES6) { + if (options.module && languageVersion >= ScriptTarget.ES6) { diagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_compile_external_modules_into_amd_or_commonjs_when_targeting_es6_or_higher)); } From 006ed82730a4d113ddf30e7635fa5f1adbfcd5fd Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 17 Feb 2015 13:47:15 -0800 Subject: [PATCH 036/224] Remove references with exports.id as es6 module doesnt have exports.id Conflicts: tests/baselines/reference/es6ExportAll.js tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js tests/baselines/reference/es6ImportNamedImport.js --- src/compiler/checker.ts | 8 +++++++- src/compiler/emitter.ts | 10 ++++++++-- tests/baselines/reference/constDeclarations-access5.js | 2 +- tests/baselines/reference/es6ImportDefaultBinding.js | 2 +- .../es6ImportDefaultBindingFollowedWithNamedImport.js | 6 +++--- ...ImportDefaultBindingFollowedWithNamespaceBinding.js | 2 +- tests/baselines/reference/es6ImportNameSpaceImport.js | 2 +- tests/baselines/reference/es6ImportNamedImport.js | 10 +++++----- .../reference/es6ImportNamedImportParsingError.js | 6 +++--- .../baselines/reference/es6ImportWithoutFromClause.js | 2 +- tests/baselines/reference/es6Module.js | 2 +- .../reference/es6ModuleWithModuleGenTargetAmd.js | 2 +- .../reference/es6ModuleWithModuleGenTargetCommonjs.js | 2 +- 13 files changed, 34 insertions(+), 22 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 935e82c5bd013..a9b42e31090f2 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10817,7 +10817,13 @@ module ts { function getExportNameSubstitution(symbol: Symbol, location: Node): string { if (isExternalModuleSymbol(symbol.parent)) { - return "exports." + unescapeIdentifier(symbol.name); + var symbolName = unescapeIdentifier(symbol.name); + if (languageVersion >= ScriptTarget.ES6) { + return symbolName; + } + else { + return "exports." + symbolName; + } } var node = location; var containerSymbol = getParentOfSymbol(symbol); diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 84312ef3be3f5..ffdea4c71fbd4 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3810,8 +3810,14 @@ module ts { function emitModuleMemberName(node: Declaration) { emitStart(node.name); if (getCombinedNodeFlags(node) & NodeFlags.Export) { - emitContainingModuleName(node); - write("."); + var container = getContainingModule(node); + if (container) { + write(resolver.getGeneratedNameForNode(container)); + write("."); + } + else if (languageVersion < ScriptTarget.ES6) { + write("exports."); + } } emitNodeWithoutSourceMap(node.name); emitEnd(node.name); diff --git a/tests/baselines/reference/constDeclarations-access5.js b/tests/baselines/reference/constDeclarations-access5.js index 0d70eb8600054..6934658920caa 100644 --- a/tests/baselines/reference/constDeclarations-access5.js +++ b/tests/baselines/reference/constDeclarations-access5.js @@ -49,7 +49,7 @@ m.x.toString(); //// [constDeclarations_access_1.js] -exports.x = 0; +x = 0; //// [constDeclarations_access_2.js] // Errors m.x = 1; diff --git a/tests/baselines/reference/es6ImportDefaultBinding.js b/tests/baselines/reference/es6ImportDefaultBinding.js index 630f601fbae49..53b122a12cad4 100644 --- a/tests/baselines/reference/es6ImportDefaultBinding.js +++ b/tests/baselines/reference/es6ImportDefaultBinding.js @@ -9,7 +9,7 @@ import defaultBinding from "es6ImportDefaultBinding_0"; //// [es6ImportDefaultBinding_0.js] -exports.a = 10; +a = 10; //// [es6ImportDefaultBinding_1.js] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js index a79a666506748..12f64528164d0 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js @@ -16,9 +16,9 @@ import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImp //// [es6ImportDefaultBindingFollowedWithNamedImport_0.js] -exports.a = 10; -exports.x = exports.a; -exports.m = exports.a; +a = 10; +x = a; +m = a; //// [es6ImportDefaultBindingFollowedWithNamedImport_1.js] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js index 3f11e5076efc8..425fc0bd7781f 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js @@ -9,7 +9,7 @@ import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollo var x: number = nameSpaceBinding.a; //// [es6ImportDefaultBindingFollowedWithNamespaceBinding_0.js] -exports.a = 10; +a = 10; //// [es6ImportDefaultBindingFollowedWithNamespaceBinding_1.js] import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; var x = nameSpaceBinding.a; diff --git a/tests/baselines/reference/es6ImportNameSpaceImport.js b/tests/baselines/reference/es6ImportNameSpaceImport.js index 87c9b9fa90f43..86ac02be37aca 100644 --- a/tests/baselines/reference/es6ImportNameSpaceImport.js +++ b/tests/baselines/reference/es6ImportNameSpaceImport.js @@ -9,7 +9,7 @@ import * as nameSpaceBinding from "es6ImportNameSpaceImport_0"; //// [es6ImportNameSpaceImport_0.js] -exports.a = 10; +a = 10; //// [es6ImportNameSpaceImport_1.js] diff --git a/tests/baselines/reference/es6ImportNamedImport.js b/tests/baselines/reference/es6ImportNamedImport.js index 05ab441a69025..76627d4aaffa4 100644 --- a/tests/baselines/reference/es6ImportNamedImport.js +++ b/tests/baselines/reference/es6ImportNamedImport.js @@ -20,11 +20,11 @@ import { a1 as a11, x1 as x11 } from "es6ImportNamedImport_0"; //// [es6ImportNamedImport_0.js] -exports.a = 10; -exports.x = exports.a; -exports.m = exports.a; -exports.a1 = 10; -exports.x1 = 10; +a = 10; +x = a; +m = a; +a1 = 10; +x1 = 10; //// [es6ImportNamedImport_1.js] diff --git a/tests/baselines/reference/es6ImportNamedImportParsingError.js b/tests/baselines/reference/es6ImportNamedImportParsingError.js index 5d80a3d7a8c82..010e84ed8a494 100644 --- a/tests/baselines/reference/es6ImportNamedImportParsingError.js +++ b/tests/baselines/reference/es6ImportNamedImportParsingError.js @@ -13,9 +13,9 @@ import , { a } from "es6ImportNamedImportParsingError_0"; import { a }, from "es6ImportNamedImportParsingError_0"; //// [es6ImportNamedImportParsingError_0.js] -exports.a = 10; -exports.x = exports.a; -exports.m = exports.a; +a = 10; +x = a; +m = a; //// [es6ImportNamedImportParsingError_1.js] from; "es6ImportNamedImportParsingError_0"; diff --git a/tests/baselines/reference/es6ImportWithoutFromClause.js b/tests/baselines/reference/es6ImportWithoutFromClause.js index cf0713d4ec525..194ce8f9715ec 100644 --- a/tests/baselines/reference/es6ImportWithoutFromClause.js +++ b/tests/baselines/reference/es6ImportWithoutFromClause.js @@ -9,7 +9,7 @@ import "es6ImportWithoutFromClause_0"; //// [es6ImportWithoutFromClause_0.js] -exports.a = 10; +a = 10; //// [es6ImportWithoutFromClause_1.js] import "es6ImportWithoutFromClause_0"; diff --git a/tests/baselines/reference/es6Module.js b/tests/baselines/reference/es6Module.js index 111d8fe203008..56c5264c0534b 100644 --- a/tests/baselines/reference/es6Module.js +++ b/tests/baselines/reference/es6Module.js @@ -20,4 +20,4 @@ var A = (function () { }; return A; })(); -exports.A = A; +A = A; diff --git a/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.js b/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.js index fd0c07ecdc4df..36df01dc237b8 100644 --- a/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.js +++ b/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.js @@ -20,4 +20,4 @@ var A = (function () { }; return A; })(); -exports.A = A; +A = A; diff --git a/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.js b/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.js index 06cf44b4d5006..fbcebbd9d0d8c 100644 --- a/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.js +++ b/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.js @@ -20,4 +20,4 @@ var A = (function () { }; return A; })(); -exports.A = A; +A = A; From 29b221430f7d64b3db9a83309702bc4c7dba4625 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 12 Feb 2015 17:54:30 -0800 Subject: [PATCH 037/224] Do not rewrite substitute named import reference when generating es6 modules Conflicts: src/compiler/checker.ts tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js tests/baselines/reference/es6ImportNamedImport.js --- src/compiler/checker.ts | 2 +- tests/baselines/reference/es6ImportNamedImportParsingError.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a9b42e31090f2..1e0976c31a0a5 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10851,7 +10851,7 @@ module ts { return getExportNameSubstitution(exportSymbol, node.parent); } // Named imports from ES6 import declarations are rewritten - if (symbol.flags & SymbolFlags.Alias) { + if (symbol.flags & SymbolFlags.Alias && languageVersion < ScriptTarget.ES6) { return getAliasNameSubstitution(symbol); } } diff --git a/tests/baselines/reference/es6ImportNamedImportParsingError.js b/tests/baselines/reference/es6ImportNamedImportParsingError.js index 010e84ed8a494..8c971cc77d2ed 100644 --- a/tests/baselines/reference/es6ImportNamedImportParsingError.js +++ b/tests/baselines/reference/es6ImportNamedImportParsingError.js @@ -20,7 +20,7 @@ m = a; from; "es6ImportNamedImportParsingError_0"; { - _module_1.a; + a; } from; "es6ImportNamedImportParsingError_0"; From 05932fdddfc809eed45cd139f3b44bd30bbac0f6 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 17 Feb 2015 14:12:28 -0800 Subject: [PATCH 038/224] Es6 module emit for export VarDeclaration, export LexicalDeclaration Conflicts: src/compiler/emitter.ts tests/baselines/reference/es6ExportAll.js tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js tests/baselines/reference/es6ImportNamedImport.js --- src/compiler/emitter.ts | 5 ++ .../reference/constDeclarations-access5.js | 2 +- .../reference/es6ImportDefaultBinding.js | 2 +- ...rtDefaultBindingFollowedWithNamedImport.js | 6 +- ...aultBindingFollowedWithNamespaceBinding.js | 2 +- .../reference/es6ImportNameSpaceImport.js | 2 +- .../reference/es6ImportNamedImport.js | 10 +-- .../es6ImportNamedImportParsingError.js | 6 +- .../reference/es6ImportWithoutFromClause.js | 2 +- tests/baselines/reference/es6ModuleConst.js | 37 ++++++++++ .../baselines/reference/es6ModuleConst.types | 70 +++++++++++++++++++ tests/baselines/reference/es6ModuleLet.js | 37 ++++++++++ tests/baselines/reference/es6ModuleLet.types | 70 +++++++++++++++++++ .../reference/es6ModuleVariableStatement.js | 37 ++++++++++ .../es6ModuleVariableStatement.types | 70 +++++++++++++++++++ tests/cases/compiler/es6ModuleConst.ts | 17 +++++ tests/cases/compiler/es6ModuleLet.ts | 17 +++++ .../compiler/es6ModuleVariableStatement.ts | 17 +++++ 18 files changed, 393 insertions(+), 16 deletions(-) create mode 100644 tests/baselines/reference/es6ModuleConst.js create mode 100644 tests/baselines/reference/es6ModuleConst.types create mode 100644 tests/baselines/reference/es6ModuleLet.js create mode 100644 tests/baselines/reference/es6ModuleLet.types create mode 100644 tests/baselines/reference/es6ModuleVariableStatement.js create mode 100644 tests/baselines/reference/es6ModuleVariableStatement.types create mode 100644 tests/cases/compiler/es6ModuleConst.ts create mode 100644 tests/cases/compiler/es6ModuleLet.ts create mode 100644 tests/cases/compiler/es6ModuleVariableStatement.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index ffdea4c71fbd4..3558c60d66aca 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4202,6 +4202,11 @@ module ts { if (!(node.flags & NodeFlags.Export)) { emitStartOfVariableDeclarationList(node.declarationList); } + else if (languageVersion >= ScriptTarget.ES6 && node.parent.kind === SyntaxKind.SourceFile) { + // Exported ES6 module member + write("export "); + emitStartOfVariableDeclarationList(node.declarationList); + } emitCommaList(node.declarationList.declarations); write(";"); if (languageVersion < ScriptTarget.ES6 && node.parent === currentSourceFile) { diff --git a/tests/baselines/reference/constDeclarations-access5.js b/tests/baselines/reference/constDeclarations-access5.js index 6934658920caa..313ce3db21a8c 100644 --- a/tests/baselines/reference/constDeclarations-access5.js +++ b/tests/baselines/reference/constDeclarations-access5.js @@ -49,7 +49,7 @@ m.x.toString(); //// [constDeclarations_access_1.js] -x = 0; +export const x = 0; //// [constDeclarations_access_2.js] // Errors m.x = 1; diff --git a/tests/baselines/reference/es6ImportDefaultBinding.js b/tests/baselines/reference/es6ImportDefaultBinding.js index 53b122a12cad4..c7a320b76aabb 100644 --- a/tests/baselines/reference/es6ImportDefaultBinding.js +++ b/tests/baselines/reference/es6ImportDefaultBinding.js @@ -9,7 +9,7 @@ import defaultBinding from "es6ImportDefaultBinding_0"; //// [es6ImportDefaultBinding_0.js] -a = 10; +export var a = 10; //// [es6ImportDefaultBinding_1.js] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js index 12f64528164d0..d7196f86eaa7e 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js @@ -16,9 +16,9 @@ import defaultBinding, { m, } from "es6ImportDefaultBindingFollowedWithNamedImp //// [es6ImportDefaultBindingFollowedWithNamedImport_0.js] -a = 10; -x = a; -m = a; +export var a = 10; +export var x = a; +export var m = a; //// [es6ImportDefaultBindingFollowedWithNamedImport_1.js] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js index 425fc0bd7781f..1ba095221dce8 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js @@ -9,7 +9,7 @@ import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollo var x: number = nameSpaceBinding.a; //// [es6ImportDefaultBindingFollowedWithNamespaceBinding_0.js] -a = 10; +export var a = 10; //// [es6ImportDefaultBindingFollowedWithNamespaceBinding_1.js] import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; var x = nameSpaceBinding.a; diff --git a/tests/baselines/reference/es6ImportNameSpaceImport.js b/tests/baselines/reference/es6ImportNameSpaceImport.js index 86ac02be37aca..4f03e9a0ae29d 100644 --- a/tests/baselines/reference/es6ImportNameSpaceImport.js +++ b/tests/baselines/reference/es6ImportNameSpaceImport.js @@ -9,7 +9,7 @@ import * as nameSpaceBinding from "es6ImportNameSpaceImport_0"; //// [es6ImportNameSpaceImport_0.js] -a = 10; +export var a = 10; //// [es6ImportNameSpaceImport_1.js] diff --git a/tests/baselines/reference/es6ImportNamedImport.js b/tests/baselines/reference/es6ImportNamedImport.js index 76627d4aaffa4..7993af7fb079f 100644 --- a/tests/baselines/reference/es6ImportNamedImport.js +++ b/tests/baselines/reference/es6ImportNamedImport.js @@ -20,11 +20,11 @@ import { a1 as a11, x1 as x11 } from "es6ImportNamedImport_0"; //// [es6ImportNamedImport_0.js] -a = 10; -x = a; -m = a; -a1 = 10; -x1 = 10; +export var a = 10; +export var x = a; +export var m = a; +export var a1 = 10; +export var x1 = 10; //// [es6ImportNamedImport_1.js] diff --git a/tests/baselines/reference/es6ImportNamedImportParsingError.js b/tests/baselines/reference/es6ImportNamedImportParsingError.js index 8c971cc77d2ed..81f141b3dd858 100644 --- a/tests/baselines/reference/es6ImportNamedImportParsingError.js +++ b/tests/baselines/reference/es6ImportNamedImportParsingError.js @@ -13,9 +13,9 @@ import , { a } from "es6ImportNamedImportParsingError_0"; import { a }, from "es6ImportNamedImportParsingError_0"; //// [es6ImportNamedImportParsingError_0.js] -a = 10; -x = a; -m = a; +export var a = 10; +export var x = a; +export var m = a; //// [es6ImportNamedImportParsingError_1.js] from; "es6ImportNamedImportParsingError_0"; diff --git a/tests/baselines/reference/es6ImportWithoutFromClause.js b/tests/baselines/reference/es6ImportWithoutFromClause.js index 194ce8f9715ec..9666409b9249a 100644 --- a/tests/baselines/reference/es6ImportWithoutFromClause.js +++ b/tests/baselines/reference/es6ImportWithoutFromClause.js @@ -9,7 +9,7 @@ import "es6ImportWithoutFromClause_0"; //// [es6ImportWithoutFromClause_0.js] -a = 10; +export var a = 10; //// [es6ImportWithoutFromClause_1.js] import "es6ImportWithoutFromClause_0"; diff --git a/tests/baselines/reference/es6ModuleConst.js b/tests/baselines/reference/es6ModuleConst.js new file mode 100644 index 0000000000000..51df62059a3b5 --- /dev/null +++ b/tests/baselines/reference/es6ModuleConst.js @@ -0,0 +1,37 @@ +//// [es6ModuleConst.ts] +export const a = "hello"; +export const x: string = a, y = x; +const b = y; +const c: string = b, d = c; +export module m1 { + export const k = a; + export const l: string = b, m = k; + const n = m1.k; + const o: string = n, p = k; +} +module m2 { + export const k = a; + export const l: string = b, m = k; + const n = m1.k; + const o: string = n, p = k; +} + +//// [es6ModuleConst.js] +export const a = "hello"; +export const x = a, y = x; +const b = y; +const c = b, d = c; +var m1; +(function (m1) { + m1.k = a; + m1.l = b, m1.m = m1.k; + const n = m1.k; + const o = n, p = m1.k; +})(m1 = m1 || (m1 = {})); +var m2; +(function (m2) { + m2.k = a; + m2.l = b, m2.m = m2.k; + const n = m1.k; + const o = n, p = m2.k; +})(m2 || (m2 = {})); diff --git a/tests/baselines/reference/es6ModuleConst.types b/tests/baselines/reference/es6ModuleConst.types new file mode 100644 index 0000000000000..cceb74a5e1ed5 --- /dev/null +++ b/tests/baselines/reference/es6ModuleConst.types @@ -0,0 +1,70 @@ +=== tests/cases/compiler/es6ModuleConst.ts === +export const a = "hello"; +>a : string + +export const x: string = a, y = x; +>x : string +>a : string +>y : string +>x : string + +const b = y; +>b : string +>y : string + +const c: string = b, d = c; +>c : string +>b : string +>d : string +>c : string + +export module m1 { +>m1 : typeof m1 + + export const k = a; +>k : string +>a : string + + export const l: string = b, m = k; +>l : string +>b : string +>m : string +>k : string + + const n = m1.k; +>n : string +>m1.k : string +>m1 : typeof m1 +>k : string + + const o: string = n, p = k; +>o : string +>n : string +>p : string +>k : string +} +module m2 { +>m2 : typeof m2 + + export const k = a; +>k : string +>a : string + + export const l: string = b, m = k; +>l : string +>b : string +>m : string +>k : string + + const n = m1.k; +>n : string +>m1.k : string +>m1 : typeof m1 +>k : string + + const o: string = n, p = k; +>o : string +>n : string +>p : string +>k : string +} diff --git a/tests/baselines/reference/es6ModuleLet.js b/tests/baselines/reference/es6ModuleLet.js new file mode 100644 index 0000000000000..3663308733268 --- /dev/null +++ b/tests/baselines/reference/es6ModuleLet.js @@ -0,0 +1,37 @@ +//// [es6ModuleLet.ts] +export let a = "hello"; +export let x: string = a, y = x; +let b = y; +let c: string = b, d = c; +export module m1 { + export let k = a; + export let l: string = b, m = k; + let n = m1.k; + let o: string = n, p = k; +} +module m2 { + export let k = a; + export let l: string = b, m = k; + let n = m1.k; + let o: string = n, p = k; +} + +//// [es6ModuleLet.js] +export let a = "hello"; +export let x = a, y = x; +let b = y; +let c = b, d = c; +var m1; +(function (m1) { + m1.k = a; + m1.l = b, m1.m = m1.k; + let n = m1.k; + let o = n, p = m1.k; +})(m1 = m1 || (m1 = {})); +var m2; +(function (m2) { + m2.k = a; + m2.l = b, m2.m = m2.k; + let n = m1.k; + let o = n, p = m2.k; +})(m2 || (m2 = {})); diff --git a/tests/baselines/reference/es6ModuleLet.types b/tests/baselines/reference/es6ModuleLet.types new file mode 100644 index 0000000000000..4b30c89cc819c --- /dev/null +++ b/tests/baselines/reference/es6ModuleLet.types @@ -0,0 +1,70 @@ +=== tests/cases/compiler/es6ModuleLet.ts === +export let a = "hello"; +>a : string + +export let x: string = a, y = x; +>x : string +>a : string +>y : string +>x : string + +let b = y; +>b : string +>y : string + +let c: string = b, d = c; +>c : string +>b : string +>d : string +>c : string + +export module m1 { +>m1 : typeof m1 + + export let k = a; +>k : string +>a : string + + export let l: string = b, m = k; +>l : string +>b : string +>m : string +>k : string + + let n = m1.k; +>n : string +>m1.k : string +>m1 : typeof m1 +>k : string + + let o: string = n, p = k; +>o : string +>n : string +>p : string +>k : string +} +module m2 { +>m2 : typeof m2 + + export let k = a; +>k : string +>a : string + + export let l: string = b, m = k; +>l : string +>b : string +>m : string +>k : string + + let n = m1.k; +>n : string +>m1.k : string +>m1 : typeof m1 +>k : string + + let o: string = n, p = k; +>o : string +>n : string +>p : string +>k : string +} diff --git a/tests/baselines/reference/es6ModuleVariableStatement.js b/tests/baselines/reference/es6ModuleVariableStatement.js new file mode 100644 index 0000000000000..aefb8720e9c5e --- /dev/null +++ b/tests/baselines/reference/es6ModuleVariableStatement.js @@ -0,0 +1,37 @@ +//// [es6ModuleVariableStatement.ts] +export var a = "hello"; +export var x: string = a, y = x; +var b = y; +var c: string = b, d = c; +export module m1 { + export var k = a; + export var l: string = b, m = k; + var n = m1.k; + var o: string = n, p = k; +} +module m2 { + export var k = a; + export var l: string = b, m = k; + var n = m1.k; + var o: string = n, p = k; +} + +//// [es6ModuleVariableStatement.js] +export var a = "hello"; +export var x = a, y = x; +var b = y; +var c = b, d = c; +var m1; +(function (m1) { + m1.k = a; + m1.l = b, m1.m = m1.k; + var n = m1.k; + var o = n, p = m1.k; +})(m1 = m1 || (m1 = {})); +var m2; +(function (m2) { + m2.k = a; + m2.l = b, m2.m = m2.k; + var n = m1.k; + var o = n, p = m2.k; +})(m2 || (m2 = {})); diff --git a/tests/baselines/reference/es6ModuleVariableStatement.types b/tests/baselines/reference/es6ModuleVariableStatement.types new file mode 100644 index 0000000000000..a10d8f6cacbc4 --- /dev/null +++ b/tests/baselines/reference/es6ModuleVariableStatement.types @@ -0,0 +1,70 @@ +=== tests/cases/compiler/es6ModuleVariableStatement.ts === +export var a = "hello"; +>a : string + +export var x: string = a, y = x; +>x : string +>a : string +>y : string +>x : string + +var b = y; +>b : string +>y : string + +var c: string = b, d = c; +>c : string +>b : string +>d : string +>c : string + +export module m1 { +>m1 : typeof m1 + + export var k = a; +>k : string +>a : string + + export var l: string = b, m = k; +>l : string +>b : string +>m : string +>k : string + + var n = m1.k; +>n : string +>m1.k : string +>m1 : typeof m1 +>k : string + + var o: string = n, p = k; +>o : string +>n : string +>p : string +>k : string +} +module m2 { +>m2 : typeof m2 + + export var k = a; +>k : string +>a : string + + export var l: string = b, m = k; +>l : string +>b : string +>m : string +>k : string + + var n = m1.k; +>n : string +>m1.k : string +>m1 : typeof m1 +>k : string + + var o: string = n, p = k; +>o : string +>n : string +>p : string +>k : string +} diff --git a/tests/cases/compiler/es6ModuleConst.ts b/tests/cases/compiler/es6ModuleConst.ts new file mode 100644 index 0000000000000..42bf24698a943 --- /dev/null +++ b/tests/cases/compiler/es6ModuleConst.ts @@ -0,0 +1,17 @@ +// @target: ES6 +export const a = "hello"; +export const x: string = a, y = x; +const b = y; +const c: string = b, d = c; +export module m1 { + export const k = a; + export const l: string = b, m = k; + const n = m1.k; + const o: string = n, p = k; +} +module m2 { + export const k = a; + export const l: string = b, m = k; + const n = m1.k; + const o: string = n, p = k; +} \ No newline at end of file diff --git a/tests/cases/compiler/es6ModuleLet.ts b/tests/cases/compiler/es6ModuleLet.ts new file mode 100644 index 0000000000000..fc5dfc94bd50a --- /dev/null +++ b/tests/cases/compiler/es6ModuleLet.ts @@ -0,0 +1,17 @@ +// @target: ES6 +export let a = "hello"; +export let x: string = a, y = x; +let b = y; +let c: string = b, d = c; +export module m1 { + export let k = a; + export let l: string = b, m = k; + let n = m1.k; + let o: string = n, p = k; +} +module m2 { + export let k = a; + export let l: string = b, m = k; + let n = m1.k; + let o: string = n, p = k; +} \ No newline at end of file diff --git a/tests/cases/compiler/es6ModuleVariableStatement.ts b/tests/cases/compiler/es6ModuleVariableStatement.ts new file mode 100644 index 0000000000000..a3ae29fbe6a22 --- /dev/null +++ b/tests/cases/compiler/es6ModuleVariableStatement.ts @@ -0,0 +1,17 @@ +// @target: ES6 +export var a = "hello"; +export var x: string = a, y = x; +var b = y; +var c: string = b, d = c; +export module m1 { + export var k = a; + export var l: string = b, m = k; + var n = m1.k; + var o: string = n, p = k; +} +module m2 { + export var k = a; + export var l: string = b, m = k; + var n = m1.k; + var o: string = n, p = k; +} \ No newline at end of file From b9f63a85b127095703742d3c91378410464abea0 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 12 Mar 2015 01:38:35 -0700 Subject: [PATCH 039/224] Emit es6 export ModuleDeclaration Conflicts: src/compiler/emitter.ts tests/baselines/reference/es6ExportAll.js tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js --- src/compiler/emitter.ts | 19 +++++- tests/baselines/reference/es6ExportAll.js | 49 ++++++++++++++ .../es6ExportClauseWithoutModuleSpecifier.js | 66 +++++++++++++++++++ tests/baselines/reference/es6ModuleConst.js | 3 +- tests/baselines/reference/es6ModuleLet.js | 3 +- .../reference/es6ModuleModuleDeclaration.js | 58 ++++++++++++++++ .../es6ModuleModuleDeclaration.types | 57 ++++++++++++++++ .../reference/es6ModuleVariableStatement.js | 3 +- .../compiler/es6ModuleModuleDeclaration.ts | 25 +++++++ 9 files changed, 278 insertions(+), 5 deletions(-) create mode 100644 tests/baselines/reference/es6ExportAll.js create mode 100644 tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js create mode 100644 tests/baselines/reference/es6ModuleModuleDeclaration.js create mode 100644 tests/baselines/reference/es6ModuleModuleDeclaration.types create mode 100644 tests/cases/compiler/es6ModuleModuleDeclaration.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 3558c60d66aca..e4af747950c4a 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4198,6 +4198,12 @@ module ts { generatedBlockScopeNames[variableId] = generatedName; } + function isES6ModuleMemberDeclaration(node: Node) { + return !!(node.flags & NodeFlags.Export) && + languageVersion >= ScriptTarget.ES6 && + node.parent.kind === SyntaxKind.SourceFile; + } + function emitVariableStatement(node: VariableStatement) { if (!(node.flags & NodeFlags.Export)) { emitStartOfVariableDeclarationList(node.declarationList); @@ -4979,7 +4985,8 @@ module ts { scopeEmitEnd(); } write(")("); - if (node.flags & NodeFlags.Export) { + // write moduleDecl = containingModule.m only if it is not exported es6 module member + if ((node.flags & NodeFlags.Export) && !isES6ModuleMemberDeclaration(node)) { emit(node.name); write(" = "); } @@ -4988,7 +4995,15 @@ module ts { emitModuleMemberName(node); write(" = {}));"); emitEnd(node); - if (languageVersion < ScriptTarget.ES6 && node.name.kind === SyntaxKind.Identifier && node.parent === currentSourceFile) { + if (isES6ModuleMemberDeclaration(node)) { + writeLine(); + emitStart(node); + write("export { "); + emit(node.name); + write(" };"); + emitEnd(node); + } + else if (languageVersion < ScriptTarget.ES6 && node.name.kind === SyntaxKind.Identifier && node.parent === currentSourceFile) { emitExportMemberAssignments(node.name); } } diff --git a/tests/baselines/reference/es6ExportAll.js b/tests/baselines/reference/es6ExportAll.js new file mode 100644 index 0000000000000..c2cd962408b9a --- /dev/null +++ b/tests/baselines/reference/es6ExportAll.js @@ -0,0 +1,49 @@ +//// [tests/cases/compiler/es6ExportAll.ts] //// + +//// [server.ts] + +export class c { +} +export interface i { +} +export module m { + export var x = 10; +} +export var x = 10; +export module uninstantiated { +} + +//// [client.ts] +export * from "server"; + +//// [server.js] +var c = (function () { + function c() { + } + return c; +})(); +c = c; +var m; +(function (m) { + m.x = 10; +})(m || (m = {})); +export { m }; +export var x = 10; +//// [client.js] +var _server = require("server"); +for (var _a in _server) if (!exports.hasOwnProperty(_a)) exports[_a] = _server[_a]; + + +//// [server.d.ts] +export declare class c { +} +export interface i { +} +export declare module m { + var x: number; +} +export declare var x: number; +export declare module uninstantiated { +} +//// [client.d.ts] +export * from "server"; diff --git a/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js new file mode 100644 index 0000000000000..c3dcb4095e365 --- /dev/null +++ b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js @@ -0,0 +1,66 @@ +//// [tests/cases/compiler/es6ExportClauseWithoutModuleSpecifier.ts] //// + +//// [server.ts] + +export class c { +} +export interface i { +} +export module m { + export var x = 10; +} +export var x = 10; +export module uninstantiated { +} + +//// [client.ts] +export { c } from "server"; +export { c as c2 } from "server"; +export { i, m as instantiatedModule } from "server"; +export { uninstantiated } from "server"; +export { x } from "server"; + +//// [server.js] +var c = (function () { + function c() { + } + return c; +})(); +c = c; +var m; +(function (m) { + m.x = 10; +})(m || (m = {})); +export { m }; +export var x = 10; +//// [client.js] +var _server = require("server"); +exports.c = _server.c; +var _server_1 = require("server"); +exports.c2 = _server_1.c; +var _server_2 = require("server"); +exports.i = _server_2.i; +exports.instantiatedModule = _server_2.m; +var _server_3 = require("server"); +exports.uninstantiated = _server_3.uninstantiated; +var _server_4 = require("server"); +exports.x = _server_4.x; + + +//// [server.d.ts] +export declare class c { +} +export interface i { +} +export declare module m { + var x: number; +} +export declare var x: number; +export declare module uninstantiated { +} +//// [client.d.ts] +export { c } from "server"; +export { c as c2 } from "server"; +export { i, m as instantiatedModule } from "server"; +export { uninstantiated } from "server"; +export { x } from "server"; diff --git a/tests/baselines/reference/es6ModuleConst.js b/tests/baselines/reference/es6ModuleConst.js index 51df62059a3b5..2a11ec638a16c 100644 --- a/tests/baselines/reference/es6ModuleConst.js +++ b/tests/baselines/reference/es6ModuleConst.js @@ -27,7 +27,8 @@ var m1; m1.l = b, m1.m = m1.k; const n = m1.k; const o = n, p = m1.k; -})(m1 = m1 || (m1 = {})); +})(m1 || (m1 = {})); +export { m1 }; var m2; (function (m2) { m2.k = a; diff --git a/tests/baselines/reference/es6ModuleLet.js b/tests/baselines/reference/es6ModuleLet.js index 3663308733268..275fd39579e71 100644 --- a/tests/baselines/reference/es6ModuleLet.js +++ b/tests/baselines/reference/es6ModuleLet.js @@ -27,7 +27,8 @@ var m1; m1.l = b, m1.m = m1.k; let n = m1.k; let o = n, p = m1.k; -})(m1 = m1 || (m1 = {})); +})(m1 || (m1 = {})); +export { m1 }; var m2; (function (m2) { m2.k = a; diff --git a/tests/baselines/reference/es6ModuleModuleDeclaration.js b/tests/baselines/reference/es6ModuleModuleDeclaration.js new file mode 100644 index 0000000000000..1e3716ac8c20e --- /dev/null +++ b/tests/baselines/reference/es6ModuleModuleDeclaration.js @@ -0,0 +1,58 @@ +//// [es6ModuleModuleDeclaration.ts] +export module m1 { + export var a = 10; + var b = 10; + export module innerExportedModule { + export var k = 10; + var l = 10; + } + export module innerNonExportedModule { + export var x = 10; + var y = 10; + } +} +module m2 { + export var a = 10; + var b = 10; + export module innerExportedModule { + export var k = 10; + var l = 10; + } + export module innerNonExportedModule { + export var x = 10; + var y = 10; + } +} + +//// [es6ModuleModuleDeclaration.js] +var m1; +(function (m1) { + m1.a = 10; + var b = 10; + var innerExportedModule; + (function (innerExportedModule) { + innerExportedModule.k = 10; + var l = 10; + })(innerExportedModule = m1.innerExportedModule || (m1.innerExportedModule = {})); + var innerNonExportedModule; + (function (innerNonExportedModule) { + innerNonExportedModule.x = 10; + var y = 10; + })(innerNonExportedModule = m1.innerNonExportedModule || (m1.innerNonExportedModule = {})); +})(m1 || (m1 = {})); +export { m1 }; +var m2; +(function (m2) { + m2.a = 10; + var b = 10; + var innerExportedModule; + (function (innerExportedModule) { + innerExportedModule.k = 10; + var l = 10; + })(innerExportedModule = m2.innerExportedModule || (m2.innerExportedModule = {})); + var innerNonExportedModule; + (function (innerNonExportedModule) { + innerNonExportedModule.x = 10; + var y = 10; + })(innerNonExportedModule = m2.innerNonExportedModule || (m2.innerNonExportedModule = {})); +})(m2 || (m2 = {})); diff --git a/tests/baselines/reference/es6ModuleModuleDeclaration.types b/tests/baselines/reference/es6ModuleModuleDeclaration.types new file mode 100644 index 0000000000000..c174fe6f8c7c6 --- /dev/null +++ b/tests/baselines/reference/es6ModuleModuleDeclaration.types @@ -0,0 +1,57 @@ +=== tests/cases/compiler/es6ModuleModuleDeclaration.ts === +export module m1 { +>m1 : typeof m1 + + export var a = 10; +>a : number + + var b = 10; +>b : number + + export module innerExportedModule { +>innerExportedModule : typeof innerExportedModule + + export var k = 10; +>k : number + + var l = 10; +>l : number + } + export module innerNonExportedModule { +>innerNonExportedModule : typeof innerNonExportedModule + + export var x = 10; +>x : number + + var y = 10; +>y : number + } +} +module m2 { +>m2 : typeof m2 + + export var a = 10; +>a : number + + var b = 10; +>b : number + + export module innerExportedModule { +>innerExportedModule : typeof innerExportedModule + + export var k = 10; +>k : number + + var l = 10; +>l : number + } + export module innerNonExportedModule { +>innerNonExportedModule : typeof innerNonExportedModule + + export var x = 10; +>x : number + + var y = 10; +>y : number + } +} diff --git a/tests/baselines/reference/es6ModuleVariableStatement.js b/tests/baselines/reference/es6ModuleVariableStatement.js index aefb8720e9c5e..11b60555b0dba 100644 --- a/tests/baselines/reference/es6ModuleVariableStatement.js +++ b/tests/baselines/reference/es6ModuleVariableStatement.js @@ -27,7 +27,8 @@ var m1; m1.l = b, m1.m = m1.k; var n = m1.k; var o = n, p = m1.k; -})(m1 = m1 || (m1 = {})); +})(m1 || (m1 = {})); +export { m1 }; var m2; (function (m2) { m2.k = a; diff --git a/tests/cases/compiler/es6ModuleModuleDeclaration.ts b/tests/cases/compiler/es6ModuleModuleDeclaration.ts new file mode 100644 index 0000000000000..99868f6087b23 --- /dev/null +++ b/tests/cases/compiler/es6ModuleModuleDeclaration.ts @@ -0,0 +1,25 @@ +// @target: ES6 +export module m1 { + export var a = 10; + var b = 10; + export module innerExportedModule { + export var k = 10; + var l = 10; + } + export module innerNonExportedModule { + export var x = 10; + var y = 10; + } +} +module m2 { + export var a = 10; + var b = 10; + export module innerExportedModule { + export var k = 10; + var l = 10; + } + export module innerNonExportedModule { + export var x = 10; + var y = 10; + } +} \ No newline at end of file From 56839604da355d1121f55a7fd40e026e5ce2a771 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 12 Mar 2015 08:40:09 -0700 Subject: [PATCH 040/224] Disallow refering to static property in computed property name --- src/compiler/checker.ts | 23 ++++++++++++++++ .../diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 4 +++ ...PropertyNamesWithStaticProperty.errors.txt | 22 ++++++++++++++++ ...computedPropertyNamesWithStaticProperty.js | 26 +++++++++++++++++++ ...computedPropertyNamesWithStaticProperty.ts | 11 ++++++++ 6 files changed, 87 insertions(+) create mode 100644 tests/baselines/reference/computedPropertyNamesWithStaticProperty.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNamesWithStaticProperty.js create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNamesWithStaticProperty.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 135cecca73064..28b3b74b271a3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5696,6 +5696,29 @@ module ts { if (!links.resolvedType) { links.resolvedType = checkExpression(node.expression); + // Disallow using static property in computedPropertyName because classDeclaration is binded lexically in ES6 + // and its static property assignment will be emitted after classDeclaration. + // Therefore, using static property inside computedPropertyName will cause use-before-definition + // Example: + // * TypeScript + // class C { + // static p = 10; + // [C.p]() {} + // } + // * JavaScript + // class C { + // [C.p]() {} // Use before definition error + // } + // C.p = 10; + if (languageVersion >= ScriptTarget.ES6 && links.resolvedSymbol) { + var declarations = links.resolvedSymbol.declarations; + forEach(declarations, (declaration) => { + if (declaration.flags & NodeFlags.Static) { + error(node, Diagnostics.A_computed_property_name_cannot_reference_a_static_property); + } + }); + } + // This will allow types number, string, symbol or any. It will also allow enums, the unknown // type, and any union of these types (like string | number). if (!allConstituentTypesHaveKind(links.resolvedType, TypeFlags.Any | TypeFlags.NumberLike | TypeFlags.StringLike | TypeFlags.ESSymbol)) { diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 24ed8ce4e99c5..a8b41e2159d81 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -157,6 +157,7 @@ module ts { Catch_clause_variable_cannot_have_an_initializer: { code: 1197, category: DiagnosticCategory.Error, key: "Catch clause variable cannot have an initializer." }, An_extended_Unicode_escape_value_must_be_between_0x0_and_0x10FFFF_inclusive: { code: 1198, category: DiagnosticCategory.Error, key: "An extended Unicode escape value must be between 0x0 and 0x10FFFF inclusive." }, Unterminated_Unicode_escape_sequence: { code: 1199, category: DiagnosticCategory.Error, key: "Unterminated Unicode escape sequence." }, + A_computed_property_name_cannot_reference_a_static_property: { code: 1200, category: DiagnosticCategory.Error, key: "A computed property name cannot reference a static property" }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 40f7d55f9f0e9..489c929821d67 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -619,6 +619,10 @@ "category": "Error", "code": 1199 }, + "A computed property name cannot reference a static property": { + "category": "Error", + "code": 1200 + }, "Duplicate identifier '{0}'.": { "category": "Error", "code": 2300 diff --git a/tests/baselines/reference/computedPropertyNamesWithStaticProperty.errors.txt b/tests/baselines/reference/computedPropertyNamesWithStaticProperty.errors.txt new file mode 100644 index 0000000000000..f078365f60062 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesWithStaticProperty.errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es6/computedProperties/computedPropertyNamesWithStaticProperty.ts(3,9): error TS1200: A computed property name cannot reference a static property +tests/cases/conformance/es6/computedProperties/computedPropertyNamesWithStaticProperty.ts(6,9): error TS1200: A computed property name cannot reference a static property +tests/cases/conformance/es6/computedProperties/computedPropertyNamesWithStaticProperty.ts(9,5): error TS1200: A computed property name cannot reference a static property + + +==== tests/cases/conformance/es6/computedProperties/computedPropertyNamesWithStaticProperty.ts (3 errors) ==== + class C { + static staticProp = 10; + get [C.staticProp]() { + ~~~~~~~~~~~~~~ +!!! error TS1200: A computed property name cannot reference a static property + return "hello"; + } + set [C.staticProp](x: string) { + ~~~~~~~~~~~~~~ +!!! error TS1200: A computed property name cannot reference a static property + var y = x; + } + [C.staticProp]() { } + ~~~~~~~~~~~~~~ +!!! error TS1200: A computed property name cannot reference a static property + } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNamesWithStaticProperty.js b/tests/baselines/reference/computedPropertyNamesWithStaticProperty.js new file mode 100644 index 0000000000000..f7506d7904d6c --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesWithStaticProperty.js @@ -0,0 +1,26 @@ +//// [computedPropertyNamesWithStaticProperty.ts] +class C { + static staticProp = 10; + get [C.staticProp]() { + return "hello"; + } + set [C.staticProp](x: string) { + var y = x; + } + [C.staticProp]() { } +} + +//// [computedPropertyNamesWithStaticProperty.js] +class C { + constructor() { + } + get [C.staticProp]() { + return "hello"; + } + set [C.staticProp](x) { + var y = x; + } + [C.staticProp]() { + } +} +C.staticProp = 10; diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNamesWithStaticProperty.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesWithStaticProperty.ts new file mode 100644 index 0000000000000..4cd9047581f4d --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesWithStaticProperty.ts @@ -0,0 +1,11 @@ +// @target: es6 +class C { + static staticProp = 10; + get [C.staticProp]() { + return "hello"; + } + set [C.staticProp](x: string) { + var y = x; + } + [C.staticProp]() { } +} \ No newline at end of file From 58d19595f09f999a5ba813970ed3f91981de4466 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 12 Mar 2015 10:00:48 -0700 Subject: [PATCH 041/224] Emit ES6 module enum declaration Conflicts: src/compiler/emitter.ts --- src/compiler/emitter.ts | 23 ++- .../es6ModuleConstEnumDeclaration.js | 66 ++++++++ .../es6ModuleConstEnumDeclaration.types | 147 +++++++++++++++++ .../es6ModuleConstEnumDeclaration2.js | 104 ++++++++++++ .../es6ModuleConstEnumDeclaration2.types | 148 ++++++++++++++++++ .../reference/es6ModuleEnumDeclaration.js | 103 ++++++++++++ .../reference/es6ModuleEnumDeclaration.types | 147 +++++++++++++++++ .../compiler/es6ModuleConstEnumDeclaration.ts | 46 ++++++ .../es6ModuleConstEnumDeclaration2.ts | 48 ++++++ .../compiler/es6ModuleEnumDeclaration.ts | 46 ++++++ 10 files changed, 870 insertions(+), 8 deletions(-) create mode 100644 tests/baselines/reference/es6ModuleConstEnumDeclaration.js create mode 100644 tests/baselines/reference/es6ModuleConstEnumDeclaration.types create mode 100644 tests/baselines/reference/es6ModuleConstEnumDeclaration2.js create mode 100644 tests/baselines/reference/es6ModuleConstEnumDeclaration2.types create mode 100644 tests/baselines/reference/es6ModuleEnumDeclaration.js create mode 100644 tests/baselines/reference/es6ModuleEnumDeclaration.types create mode 100644 tests/cases/compiler/es6ModuleConstEnumDeclaration.ts create mode 100644 tests/cases/compiler/es6ModuleConstEnumDeclaration2.ts create mode 100644 tests/cases/compiler/es6ModuleEnumDeclaration.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index e4af747950c4a..7c367f2f84595 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4852,7 +4852,7 @@ module ts { return; } - if (!(node.flags & NodeFlags.Export)) { + if (!(node.flags & NodeFlags.Export) || isES6ModuleMemberDeclaration(node)) { emitStart(node); write("var "); emit(node.name); @@ -4879,7 +4879,10 @@ module ts { emitModuleMemberName(node); write(" = {}));"); emitEnd(node); - if (node.flags & NodeFlags.Export) { + if (isES6ModuleMemberDeclaration(node)) { + emitES6NamedExportForDeclaration(node); + } + else if (node.flags & NodeFlags.Export) { writeLine(); emitStart(node); write("var "); @@ -4996,18 +4999,22 @@ module ts { write(" = {}));"); emitEnd(node); if (isES6ModuleMemberDeclaration(node)) { - writeLine(); - emitStart(node); - write("export { "); - emit(node.name); - write(" };"); - emitEnd(node); + emitES6NamedExportForDeclaration(node); } else if (languageVersion < ScriptTarget.ES6 && node.name.kind === SyntaxKind.Identifier && node.parent === currentSourceFile) { emitExportMemberAssignments(node.name); } } + function emitES6NamedExportForDeclaration(node: Declaration) { + writeLine(); + emitStart(node); + write("export { "); + emit(node.name); + write(" };"); + emitEnd(node); + } + function emitRequire(moduleName: Expression) { if (moduleName.kind === SyntaxKind.StringLiteral) { write("require("); diff --git a/tests/baselines/reference/es6ModuleConstEnumDeclaration.js b/tests/baselines/reference/es6ModuleConstEnumDeclaration.js new file mode 100644 index 0000000000000..c8096c76c8e20 --- /dev/null +++ b/tests/baselines/reference/es6ModuleConstEnumDeclaration.js @@ -0,0 +1,66 @@ +//// [es6ModuleConstEnumDeclaration.ts] +export const enum e1 { + a, + b, + c +} +const enum e2 { + x, + y, + z +} +var x = e1.a; +var y = e2.x; +export module m1 { + export const enum e3 { + a, + b, + c + } + const enum e4 { + x, + y, + z + } + var x1 = e1.a; + var y1 = e2.x; + var x2 = e3.a; + var y2 = e4.x; +} +module m2 { + export const enum e5 { + a, + b, + c + } + const enum e6 { + x, + y, + z + } + var x1 = e1.a; + var y1 = e2.x; + var x2 = e5.a; + var y2 = e6.x; + var x3 = m1.e3.a; +} + +//// [es6ModuleConstEnumDeclaration.js] +var x = 0 /* a */; +var y = 0 /* x */; +var m1; +(function (m1) { + var x1 = 0 /* a */; + var y1 = 0 /* x */; + var x2 = 0 /* a */; + var y2 = 0 /* x */; +})(m1 || (m1 = {})); +export { m1 }; +var m2; +(function (m2) { + var x1 = 0 /* a */; + var y1 = 0 /* x */; + var x2 = 0 /* a */; + var y2 = 0 /* x */; + var x3 = 0 /* a */; +})(m2 || (m2 = {})); diff --git a/tests/baselines/reference/es6ModuleConstEnumDeclaration.types b/tests/baselines/reference/es6ModuleConstEnumDeclaration.types new file mode 100644 index 0000000000000..fae819f93b06f --- /dev/null +++ b/tests/baselines/reference/es6ModuleConstEnumDeclaration.types @@ -0,0 +1,147 @@ +=== tests/cases/compiler/es6ModuleConstEnumDeclaration.ts === +export const enum e1 { +>e1 : e1 + + a, +>a : e1 + + b, +>b : e1 + + c +>c : e1 +} +const enum e2 { +>e2 : e2 + + x, +>x : e2 + + y, +>y : e2 + + z +>z : e2 +} +var x = e1.a; +>x : e1 +>e1.a : e1 +>e1 : typeof e1 +>a : e1 + +var y = e2.x; +>y : e2 +>e2.x : e2 +>e2 : typeof e2 +>x : e2 + +export module m1 { +>m1 : typeof m1 + + export const enum e3 { +>e3 : e3 + + a, +>a : e3 + + b, +>b : e3 + + c +>c : e3 + } + const enum e4 { +>e4 : e4 + + x, +>x : e4 + + y, +>y : e4 + + z +>z : e4 + } + var x1 = e1.a; +>x1 : e1 +>e1.a : e1 +>e1 : typeof e1 +>a : e1 + + var y1 = e2.x; +>y1 : e2 +>e2.x : e2 +>e2 : typeof e2 +>x : e2 + + var x2 = e3.a; +>x2 : e3 +>e3.a : e3 +>e3 : typeof e3 +>a : e3 + + var y2 = e4.x; +>y2 : e4 +>e4.x : e4 +>e4 : typeof e4 +>x : e4 +} +module m2 { +>m2 : typeof m2 + + export const enum e5 { +>e5 : e5 + + a, +>a : e5 + + b, +>b : e5 + + c +>c : e5 + } + const enum e6 { +>e6 : e6 + + x, +>x : e6 + + y, +>y : e6 + + z +>z : e6 + } + var x1 = e1.a; +>x1 : e1 +>e1.a : e1 +>e1 : typeof e1 +>a : e1 + + var y1 = e2.x; +>y1 : e2 +>e2.x : e2 +>e2 : typeof e2 +>x : e2 + + var x2 = e5.a; +>x2 : e5 +>e5.a : e5 +>e5 : typeof e5 +>a : e5 + + var y2 = e6.x; +>y2 : e6 +>e6.x : e6 +>e6 : typeof e6 +>x : e6 + + var x3 = m1.e3.a; +>x3 : m1.e3 +>m1.e3.a : m1.e3 +>m1.e3 : typeof m1.e3 +>m1 : typeof m1 +>e3 : typeof m1.e3 +>a : m1.e3 +} diff --git a/tests/baselines/reference/es6ModuleConstEnumDeclaration2.js b/tests/baselines/reference/es6ModuleConstEnumDeclaration2.js new file mode 100644 index 0000000000000..5ec953aca88a1 --- /dev/null +++ b/tests/baselines/reference/es6ModuleConstEnumDeclaration2.js @@ -0,0 +1,104 @@ +//// [es6ModuleConstEnumDeclaration2.ts] + +export const enum e1 { + a, + b, + c +} +const enum e2 { + x, + y, + z +} +var x = e1.a; +var y = e2.x; +export module m1 { + export const enum e3 { + a, + b, + c + } + const enum e4 { + x, + y, + z + } + var x1 = e1.a; + var y1 = e2.x; + var x2 = e3.a; + var y2 = e4.x; +} +module m2 { + export const enum e5 { + a, + b, + c + } + const enum e6 { + x, + y, + z + } + var x1 = e1.a; + var y1 = e2.x; + var x2 = e5.a; + var y2 = e6.x; + var x3 = m1.e3.a; +} + +//// [es6ModuleConstEnumDeclaration2.js] +var e1; +(function (e1) { + e1[e1["a"] = 0] = "a"; + e1[e1["b"] = 1] = "b"; + e1[e1["c"] = 2] = "c"; +})(e1 || (e1 = {})); +export { e1 }; +var e2; +(function (e2) { + e2[e2["x"] = 0] = "x"; + e2[e2["y"] = 1] = "y"; + e2[e2["z"] = 2] = "z"; +})(e2 || (e2 = {})); +var x = 0 /* a */; +var y = 0 /* x */; +var m1; +(function (m1) { + (function (e3) { + e3[e3["a"] = 0] = "a"; + e3[e3["b"] = 1] = "b"; + e3[e3["c"] = 2] = "c"; + })(m1.e3 || (m1.e3 = {})); + var e3 = m1.e3; + var e4; + (function (e4) { + e4[e4["x"] = 0] = "x"; + e4[e4["y"] = 1] = "y"; + e4[e4["z"] = 2] = "z"; + })(e4 || (e4 = {})); + var x1 = 0 /* a */; + var y1 = 0 /* x */; + var x2 = 0 /* a */; + var y2 = 0 /* x */; +})(m1 || (m1 = {})); +export { m1 }; +var m2; +(function (m2) { + (function (e5) { + e5[e5["a"] = 0] = "a"; + e5[e5["b"] = 1] = "b"; + e5[e5["c"] = 2] = "c"; + })(m2.e5 || (m2.e5 = {})); + var e5 = m2.e5; + var e6; + (function (e6) { + e6[e6["x"] = 0] = "x"; + e6[e6["y"] = 1] = "y"; + e6[e6["z"] = 2] = "z"; + })(e6 || (e6 = {})); + var x1 = 0 /* a */; + var y1 = 0 /* x */; + var x2 = 0 /* a */; + var y2 = 0 /* x */; + var x3 = 0 /* a */; +})(m2 || (m2 = {})); diff --git a/tests/baselines/reference/es6ModuleConstEnumDeclaration2.types b/tests/baselines/reference/es6ModuleConstEnumDeclaration2.types new file mode 100644 index 0000000000000..c43a938c9b6a8 --- /dev/null +++ b/tests/baselines/reference/es6ModuleConstEnumDeclaration2.types @@ -0,0 +1,148 @@ +=== tests/cases/compiler/es6ModuleConstEnumDeclaration2.ts === + +export const enum e1 { +>e1 : e1 + + a, +>a : e1 + + b, +>b : e1 + + c +>c : e1 +} +const enum e2 { +>e2 : e2 + + x, +>x : e2 + + y, +>y : e2 + + z +>z : e2 +} +var x = e1.a; +>x : e1 +>e1.a : e1 +>e1 : typeof e1 +>a : e1 + +var y = e2.x; +>y : e2 +>e2.x : e2 +>e2 : typeof e2 +>x : e2 + +export module m1 { +>m1 : typeof m1 + + export const enum e3 { +>e3 : e3 + + a, +>a : e3 + + b, +>b : e3 + + c +>c : e3 + } + const enum e4 { +>e4 : e4 + + x, +>x : e4 + + y, +>y : e4 + + z +>z : e4 + } + var x1 = e1.a; +>x1 : e1 +>e1.a : e1 +>e1 : typeof e1 +>a : e1 + + var y1 = e2.x; +>y1 : e2 +>e2.x : e2 +>e2 : typeof e2 +>x : e2 + + var x2 = e3.a; +>x2 : e3 +>e3.a : e3 +>e3 : typeof e3 +>a : e3 + + var y2 = e4.x; +>y2 : e4 +>e4.x : e4 +>e4 : typeof e4 +>x : e4 +} +module m2 { +>m2 : typeof m2 + + export const enum e5 { +>e5 : e5 + + a, +>a : e5 + + b, +>b : e5 + + c +>c : e5 + } + const enum e6 { +>e6 : e6 + + x, +>x : e6 + + y, +>y : e6 + + z +>z : e6 + } + var x1 = e1.a; +>x1 : e1 +>e1.a : e1 +>e1 : typeof e1 +>a : e1 + + var y1 = e2.x; +>y1 : e2 +>e2.x : e2 +>e2 : typeof e2 +>x : e2 + + var x2 = e5.a; +>x2 : e5 +>e5.a : e5 +>e5 : typeof e5 +>a : e5 + + var y2 = e6.x; +>y2 : e6 +>e6.x : e6 +>e6 : typeof e6 +>x : e6 + + var x3 = m1.e3.a; +>x3 : m1.e3 +>m1.e3.a : m1.e3 +>m1.e3 : typeof m1.e3 +>m1 : typeof m1 +>e3 : typeof m1.e3 +>a : m1.e3 +} diff --git a/tests/baselines/reference/es6ModuleEnumDeclaration.js b/tests/baselines/reference/es6ModuleEnumDeclaration.js new file mode 100644 index 0000000000000..955fe3ed8d3f8 --- /dev/null +++ b/tests/baselines/reference/es6ModuleEnumDeclaration.js @@ -0,0 +1,103 @@ +//// [es6ModuleEnumDeclaration.ts] +export enum e1 { + a, + b, + c +} +enum e2 { + x, + y, + z +} +var x = e1.a; +var y = e2.x; +export module m1 { + export enum e3 { + a, + b, + c + } + enum e4 { + x, + y, + z + } + var x1 = e1.a; + var y1 = e2.x; + var x2 = e3.a; + var y2 = e4.x; +} +module m2 { + export enum e5 { + a, + b, + c + } + enum e6 { + x, + y, + z + } + var x1 = e1.a; + var y1 = e2.x; + var x2 = e5.a; + var y2 = e6.x; + var x3 = m1.e3.a; +} + +//// [es6ModuleEnumDeclaration.js] +var e1; +(function (e1) { + e1[e1["a"] = 0] = "a"; + e1[e1["b"] = 1] = "b"; + e1[e1["c"] = 2] = "c"; +})(e1 || (e1 = {})); +export { e1 }; +var e2; +(function (e2) { + e2[e2["x"] = 0] = "x"; + e2[e2["y"] = 1] = "y"; + e2[e2["z"] = 2] = "z"; +})(e2 || (e2 = {})); +var x = 0 /* a */; +var y = 0 /* x */; +var m1; +(function (m1) { + (function (e3) { + e3[e3["a"] = 0] = "a"; + e3[e3["b"] = 1] = "b"; + e3[e3["c"] = 2] = "c"; + })(m1.e3 || (m1.e3 = {})); + var e3 = m1.e3; + var e4; + (function (e4) { + e4[e4["x"] = 0] = "x"; + e4[e4["y"] = 1] = "y"; + e4[e4["z"] = 2] = "z"; + })(e4 || (e4 = {})); + var x1 = 0 /* a */; + var y1 = 0 /* x */; + var x2 = 0 /* a */; + var y2 = 0 /* x */; +})(m1 || (m1 = {})); +export { m1 }; +var m2; +(function (m2) { + (function (e5) { + e5[e5["a"] = 0] = "a"; + e5[e5["b"] = 1] = "b"; + e5[e5["c"] = 2] = "c"; + })(m2.e5 || (m2.e5 = {})); + var e5 = m2.e5; + var e6; + (function (e6) { + e6[e6["x"] = 0] = "x"; + e6[e6["y"] = 1] = "y"; + e6[e6["z"] = 2] = "z"; + })(e6 || (e6 = {})); + var x1 = 0 /* a */; + var y1 = 0 /* x */; + var x2 = 0 /* a */; + var y2 = 0 /* x */; + var x3 = 0 /* a */; +})(m2 || (m2 = {})); diff --git a/tests/baselines/reference/es6ModuleEnumDeclaration.types b/tests/baselines/reference/es6ModuleEnumDeclaration.types new file mode 100644 index 0000000000000..4b856fee00902 --- /dev/null +++ b/tests/baselines/reference/es6ModuleEnumDeclaration.types @@ -0,0 +1,147 @@ +=== tests/cases/compiler/es6ModuleEnumDeclaration.ts === +export enum e1 { +>e1 : e1 + + a, +>a : e1 + + b, +>b : e1 + + c +>c : e1 +} +enum e2 { +>e2 : e2 + + x, +>x : e2 + + y, +>y : e2 + + z +>z : e2 +} +var x = e1.a; +>x : e1 +>e1.a : e1 +>e1 : typeof e1 +>a : e1 + +var y = e2.x; +>y : e2 +>e2.x : e2 +>e2 : typeof e2 +>x : e2 + +export module m1 { +>m1 : typeof m1 + + export enum e3 { +>e3 : e3 + + a, +>a : e3 + + b, +>b : e3 + + c +>c : e3 + } + enum e4 { +>e4 : e4 + + x, +>x : e4 + + y, +>y : e4 + + z +>z : e4 + } + var x1 = e1.a; +>x1 : e1 +>e1.a : e1 +>e1 : typeof e1 +>a : e1 + + var y1 = e2.x; +>y1 : e2 +>e2.x : e2 +>e2 : typeof e2 +>x : e2 + + var x2 = e3.a; +>x2 : e3 +>e3.a : e3 +>e3 : typeof e3 +>a : e3 + + var y2 = e4.x; +>y2 : e4 +>e4.x : e4 +>e4 : typeof e4 +>x : e4 +} +module m2 { +>m2 : typeof m2 + + export enum e5 { +>e5 : e5 + + a, +>a : e5 + + b, +>b : e5 + + c +>c : e5 + } + enum e6 { +>e6 : e6 + + x, +>x : e6 + + y, +>y : e6 + + z +>z : e6 + } + var x1 = e1.a; +>x1 : e1 +>e1.a : e1 +>e1 : typeof e1 +>a : e1 + + var y1 = e2.x; +>y1 : e2 +>e2.x : e2 +>e2 : typeof e2 +>x : e2 + + var x2 = e5.a; +>x2 : e5 +>e5.a : e5 +>e5 : typeof e5 +>a : e5 + + var y2 = e6.x; +>y2 : e6 +>e6.x : e6 +>e6 : typeof e6 +>x : e6 + + var x3 = m1.e3.a; +>x3 : m1.e3 +>m1.e3.a : m1.e3 +>m1.e3 : typeof m1.e3 +>m1 : typeof m1 +>e3 : typeof m1.e3 +>a : m1.e3 +} diff --git a/tests/cases/compiler/es6ModuleConstEnumDeclaration.ts b/tests/cases/compiler/es6ModuleConstEnumDeclaration.ts new file mode 100644 index 0000000000000..c3490093d3ecd --- /dev/null +++ b/tests/cases/compiler/es6ModuleConstEnumDeclaration.ts @@ -0,0 +1,46 @@ +// @target: ES6 +export const enum e1 { + a, + b, + c +} +const enum e2 { + x, + y, + z +} +var x = e1.a; +var y = e2.x; +export module m1 { + export const enum e3 { + a, + b, + c + } + const enum e4 { + x, + y, + z + } + var x1 = e1.a; + var y1 = e2.x; + var x2 = e3.a; + var y2 = e4.x; +} +module m2 { + export const enum e5 { + a, + b, + c + } + const enum e6 { + x, + y, + z + } + var x1 = e1.a; + var y1 = e2.x; + var x2 = e5.a; + var y2 = e6.x; + var x3 = m1.e3.a; +} \ No newline at end of file diff --git a/tests/cases/compiler/es6ModuleConstEnumDeclaration2.ts b/tests/cases/compiler/es6ModuleConstEnumDeclaration2.ts new file mode 100644 index 0000000000000..6dddea09d8a65 --- /dev/null +++ b/tests/cases/compiler/es6ModuleConstEnumDeclaration2.ts @@ -0,0 +1,48 @@ +// @target: ES6 +// @preserveConstEnums: true + +export const enum e1 { + a, + b, + c +} +const enum e2 { + x, + y, + z +} +var x = e1.a; +var y = e2.x; +export module m1 { + export const enum e3 { + a, + b, + c + } + const enum e4 { + x, + y, + z + } + var x1 = e1.a; + var y1 = e2.x; + var x2 = e3.a; + var y2 = e4.x; +} +module m2 { + export const enum e5 { + a, + b, + c + } + const enum e6 { + x, + y, + z + } + var x1 = e1.a; + var y1 = e2.x; + var x2 = e5.a; + var y2 = e6.x; + var x3 = m1.e3.a; +} \ No newline at end of file diff --git a/tests/cases/compiler/es6ModuleEnumDeclaration.ts b/tests/cases/compiler/es6ModuleEnumDeclaration.ts new file mode 100644 index 0000000000000..a0cebde9947e1 --- /dev/null +++ b/tests/cases/compiler/es6ModuleEnumDeclaration.ts @@ -0,0 +1,46 @@ +// @target: ES6 +export enum e1 { + a, + b, + c +} +enum e2 { + x, + y, + z +} +var x = e1.a; +var y = e2.x; +export module m1 { + export enum e3 { + a, + b, + c + } + enum e4 { + x, + y, + z + } + var x1 = e1.a; + var y1 = e2.x; + var x2 = e3.a; + var y2 = e4.x; +} +module m2 { + export enum e5 { + a, + b, + c + } + enum e6 { + x, + y, + z + } + var x1 = e1.a; + var y1 = e2.x; + var x2 = e5.a; + var y2 = e6.x; + var x3 = m1.e3.a; +} \ No newline at end of file From b091fa57efcddbe9169e3358482e3ec80531ea0a Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 12 Mar 2015 10:11:37 -0700 Subject: [PATCH 042/224] Emit export function declaration in es6 format Conflicts: src/compiler/emitter.ts --- src/compiler/emitter.ts | 5 +- .../reference/es6ModuleFunctionDeclaration.js | 63 ++++++++++++++++ .../es6ModuleFunctionDeclaration.types | 71 +++++++++++++++++++ .../compiler/es6ModuleFunctionDeclaration.ts | 29 ++++++++ 4 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/es6ModuleFunctionDeclaration.js create mode 100644 tests/baselines/reference/es6ModuleFunctionDeclaration.types create mode 100644 tests/cases/compiler/es6ModuleFunctionDeclaration.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 7c367f2f84595..011a09ee64e53 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4344,6 +4344,9 @@ module ts { // For targeting below es6, emit functions-like declaration including arrow function using function keyword. // When targeting ES6, emit arrow function natively in ES6 by omitting function keyword and using fat arrow instead if (!shouldEmitAsArrowFunction(node)) { + if (isES6ModuleMemberDeclaration(node)) { + write("export "); + } write("function "); } @@ -4420,7 +4423,7 @@ module ts { emitExpressionFunctionBody(node, node.body); } - if (node.flags & NodeFlags.Export && !(node.flags & NodeFlags.Default)) { + if (node.flags & NodeFlags.Export && !(node.flags & NodeFlags.Default) && !isES6ModuleMemberDeclaration(node)) { writeLine(); emitStart(node); emitModuleMemberName(node); diff --git a/tests/baselines/reference/es6ModuleFunctionDeclaration.js b/tests/baselines/reference/es6ModuleFunctionDeclaration.js new file mode 100644 index 0000000000000..4c1fc33647c71 --- /dev/null +++ b/tests/baselines/reference/es6ModuleFunctionDeclaration.js @@ -0,0 +1,63 @@ +//// [es6ModuleFunctionDeclaration.ts] +export function foo() { +} +function foo2() { +} +foo(); +foo2(); + +export module m1 { + export function foo3() { + } + function foo4() { + } + foo(); + foo2(); + foo3(); + foo4(); +} +module m2 { + export function foo3() { + } + function foo4() { + } + foo(); + foo2(); + foo3(); + foo4(); + m1.foo3(); +} + +//// [es6ModuleFunctionDeclaration.js] +export function foo() { +} +function foo2() { +} +foo(); +foo2(); +var m1; +(function (m1) { + function foo3() { + } + m1.foo3 = foo3; + function foo4() { + } + foo(); + foo2(); + foo3(); + foo4(); +})(m1 || (m1 = {})); +export { m1 }; +var m2; +(function (m2) { + function foo3() { + } + m2.foo3 = foo3; + function foo4() { + } + foo(); + foo2(); + foo3(); + foo4(); + m1.foo3(); +})(m2 || (m2 = {})); diff --git a/tests/baselines/reference/es6ModuleFunctionDeclaration.types b/tests/baselines/reference/es6ModuleFunctionDeclaration.types new file mode 100644 index 0000000000000..b1252c1e8bcd3 --- /dev/null +++ b/tests/baselines/reference/es6ModuleFunctionDeclaration.types @@ -0,0 +1,71 @@ +=== tests/cases/compiler/es6ModuleFunctionDeclaration.ts === +export function foo() { +>foo : () => void +} +function foo2() { +>foo2 : () => void +} +foo(); +>foo() : void +>foo : () => void + +foo2(); +>foo2() : void +>foo2 : () => void + +export module m1 { +>m1 : typeof m1 + + export function foo3() { +>foo3 : () => void + } + function foo4() { +>foo4 : () => void + } + foo(); +>foo() : void +>foo : () => void + + foo2(); +>foo2() : void +>foo2 : () => void + + foo3(); +>foo3() : void +>foo3 : () => void + + foo4(); +>foo4() : void +>foo4 : () => void +} +module m2 { +>m2 : typeof m2 + + export function foo3() { +>foo3 : () => void + } + function foo4() { +>foo4 : () => void + } + foo(); +>foo() : void +>foo : () => void + + foo2(); +>foo2() : void +>foo2 : () => void + + foo3(); +>foo3() : void +>foo3 : () => void + + foo4(); +>foo4() : void +>foo4 : () => void + + m1.foo3(); +>m1.foo3() : void +>m1.foo3 : () => void +>m1 : typeof m1 +>foo3 : () => void +} diff --git a/tests/cases/compiler/es6ModuleFunctionDeclaration.ts b/tests/cases/compiler/es6ModuleFunctionDeclaration.ts new file mode 100644 index 0000000000000..82eebb1580ef7 --- /dev/null +++ b/tests/cases/compiler/es6ModuleFunctionDeclaration.ts @@ -0,0 +1,29 @@ +// @target: ES6 +export function foo() { +} +function foo2() { +} +foo(); +foo2(); + +export module m1 { + export function foo3() { + } + function foo4() { + } + foo(); + foo2(); + foo3(); + foo4(); +} +module m2 { + export function foo3() { + } + function foo4() { + } + foo(); + foo2(); + foo3(); + foo4(); + m1.foo3(); +} \ No newline at end of file From 6bcbe824aa159fc15f755c85381b435408fdf0a0 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 12 Mar 2015 10:27:46 -0700 Subject: [PATCH 043/224] Emit export class declaration in es6 format. Note since we havent yet changed the emitting of class declaration to es6 format, we are just exporting the constructor function Conflicts: src/compiler/emitter.ts --- src/compiler/emitter.ts | 8 +- tests/baselines/reference/es6ExportAll.js | 49 ---- .../es6ExportClauseWithoutModuleSpecifier.js | 66 ----- tests/baselines/reference/es6Module.js | 2 +- .../reference/es6ModuleClassDeclaration.js | 238 ++++++++++++++++++ .../reference/es6ModuleClassDeclaration.types | 233 +++++++++++++++++ .../es6ModuleWithModuleGenTargetAmd.js | 2 +- .../es6ModuleWithModuleGenTargetCommonjs.js | 2 +- .../compiler/es6ModuleClassDeclaration.ts | 113 +++++++++ 9 files changed, 594 insertions(+), 119 deletions(-) delete mode 100644 tests/baselines/reference/es6ExportAll.js delete mode 100644 tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js create mode 100644 tests/baselines/reference/es6ModuleClassDeclaration.js create mode 100644 tests/baselines/reference/es6ModuleClassDeclaration.types create mode 100644 tests/cases/compiler/es6ModuleClassDeclaration.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 011a09ee64e53..b114ffda86c46 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4748,7 +4748,12 @@ module ts { } write(");"); emitEnd(node); - if (node.flags & NodeFlags.Export && !(node.flags & NodeFlags.Default)) { + + if (isES6ModuleMemberDeclaration(node)) { + // TODO update this to emit "export class " when ES67 class emit is available + emitES6NamedExportForDeclaration(node); + } + else if (node.flags & NodeFlags.Export && !(node.flags & NodeFlags.Default)) { writeLine(); emitStart(node); emitModuleMemberName(node); @@ -4757,6 +4762,7 @@ module ts { emitEnd(node); write(";"); } + if (languageVersion < ScriptTarget.ES6 && node.parent === currentSourceFile && node.name) { emitExportMemberAssignments(node.name); } diff --git a/tests/baselines/reference/es6ExportAll.js b/tests/baselines/reference/es6ExportAll.js deleted file mode 100644 index c2cd962408b9a..0000000000000 --- a/tests/baselines/reference/es6ExportAll.js +++ /dev/null @@ -1,49 +0,0 @@ -//// [tests/cases/compiler/es6ExportAll.ts] //// - -//// [server.ts] - -export class c { -} -export interface i { -} -export module m { - export var x = 10; -} -export var x = 10; -export module uninstantiated { -} - -//// [client.ts] -export * from "server"; - -//// [server.js] -var c = (function () { - function c() { - } - return c; -})(); -c = c; -var m; -(function (m) { - m.x = 10; -})(m || (m = {})); -export { m }; -export var x = 10; -//// [client.js] -var _server = require("server"); -for (var _a in _server) if (!exports.hasOwnProperty(_a)) exports[_a] = _server[_a]; - - -//// [server.d.ts] -export declare class c { -} -export interface i { -} -export declare module m { - var x: number; -} -export declare var x: number; -export declare module uninstantiated { -} -//// [client.d.ts] -export * from "server"; diff --git a/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js deleted file mode 100644 index c3dcb4095e365..0000000000000 --- a/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js +++ /dev/null @@ -1,66 +0,0 @@ -//// [tests/cases/compiler/es6ExportClauseWithoutModuleSpecifier.ts] //// - -//// [server.ts] - -export class c { -} -export interface i { -} -export module m { - export var x = 10; -} -export var x = 10; -export module uninstantiated { -} - -//// [client.ts] -export { c } from "server"; -export { c as c2 } from "server"; -export { i, m as instantiatedModule } from "server"; -export { uninstantiated } from "server"; -export { x } from "server"; - -//// [server.js] -var c = (function () { - function c() { - } - return c; -})(); -c = c; -var m; -(function (m) { - m.x = 10; -})(m || (m = {})); -export { m }; -export var x = 10; -//// [client.js] -var _server = require("server"); -exports.c = _server.c; -var _server_1 = require("server"); -exports.c2 = _server_1.c; -var _server_2 = require("server"); -exports.i = _server_2.i; -exports.instantiatedModule = _server_2.m; -var _server_3 = require("server"); -exports.uninstantiated = _server_3.uninstantiated; -var _server_4 = require("server"); -exports.x = _server_4.x; - - -//// [server.d.ts] -export declare class c { -} -export interface i { -} -export declare module m { - var x: number; -} -export declare var x: number; -export declare module uninstantiated { -} -//// [client.d.ts] -export { c } from "server"; -export { c as c2 } from "server"; -export { i, m as instantiatedModule } from "server"; -export { uninstantiated } from "server"; -export { x } from "server"; diff --git a/tests/baselines/reference/es6Module.js b/tests/baselines/reference/es6Module.js index 56c5264c0534b..6c2e87fff1d2b 100644 --- a/tests/baselines/reference/es6Module.js +++ b/tests/baselines/reference/es6Module.js @@ -20,4 +20,4 @@ var A = (function () { }; return A; })(); -A = A; +export { A }; diff --git a/tests/baselines/reference/es6ModuleClassDeclaration.js b/tests/baselines/reference/es6ModuleClassDeclaration.js new file mode 100644 index 0000000000000..5ad7da0e8b28a --- /dev/null +++ b/tests/baselines/reference/es6ModuleClassDeclaration.js @@ -0,0 +1,238 @@ +//// [es6ModuleClassDeclaration.ts] +export class c { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } +} +class c2 { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } +} +new c(); +new c2(); + +export module m1 { + export class c3 { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } + } + class c4 { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } + } + new c(); + new c2(); + new c3(); + new c4(); +} +module m2 { + export class c3 { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } + } + class c4 { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } + } + new c(); + new c2(); + new c3(); + new c4(); + new m1.c3(); +} + +//// [es6ModuleClassDeclaration.js] +var c = (function () { + function c() { + this.x = 10; + this.y = 30; + } + c.prototype.method1 = function () { + }; + c.prototype.method2 = function () { + }; + c.method3 = function () { + }; + c.method4 = function () { + }; + c.k = 20; + c.l = 30; + return c; +})(); +export { c }; +var c2 = (function () { + function c2() { + this.x = 10; + this.y = 30; + } + c2.prototype.method1 = function () { + }; + c2.prototype.method2 = function () { + }; + c2.method3 = function () { + }; + c2.method4 = function () { + }; + c2.k = 20; + c2.l = 30; + return c2; +})(); +new c(); +new c2(); +var m1; +(function (m1) { + var c3 = (function () { + function c3() { + this.x = 10; + this.y = 30; + } + c3.prototype.method1 = function () { + }; + c3.prototype.method2 = function () { + }; + c3.method3 = function () { + }; + c3.method4 = function () { + }; + c3.k = 20; + c3.l = 30; + return c3; + })(); + m1.c3 = c3; + var c4 = (function () { + function c4() { + this.x = 10; + this.y = 30; + } + c4.prototype.method1 = function () { + }; + c4.prototype.method2 = function () { + }; + c4.method3 = function () { + }; + c4.method4 = function () { + }; + c4.k = 20; + c4.l = 30; + return c4; + })(); + new c(); + new c2(); + new c3(); + new c4(); +})(m1 || (m1 = {})); +export { m1 }; +var m2; +(function (m2) { + var c3 = (function () { + function c3() { + this.x = 10; + this.y = 30; + } + c3.prototype.method1 = function () { + }; + c3.prototype.method2 = function () { + }; + c3.method3 = function () { + }; + c3.method4 = function () { + }; + c3.k = 20; + c3.l = 30; + return c3; + })(); + m2.c3 = c3; + var c4 = (function () { + function c4() { + this.x = 10; + this.y = 30; + } + c4.prototype.method1 = function () { + }; + c4.prototype.method2 = function () { + }; + c4.method3 = function () { + }; + c4.method4 = function () { + }; + c4.k = 20; + c4.l = 30; + return c4; + })(); + new c(); + new c2(); + new c3(); + new c4(); + new m1.c3(); +})(m2 || (m2 = {})); diff --git a/tests/baselines/reference/es6ModuleClassDeclaration.types b/tests/baselines/reference/es6ModuleClassDeclaration.types new file mode 100644 index 0000000000000..09d50c4e542d5 --- /dev/null +++ b/tests/baselines/reference/es6ModuleClassDeclaration.types @@ -0,0 +1,233 @@ +=== tests/cases/compiler/es6ModuleClassDeclaration.ts === +export class c { +>c : c + + constructor() { + } + private x = 10; +>x : number + + public y = 30; +>y : number + + static k = 20; +>k : number + + private static l = 30; +>l : number + + private method1() { +>method1 : () => void + } + public method2() { +>method2 : () => void + } + static method3() { +>method3 : () => void + } + private static method4() { +>method4 : () => void + } +} +class c2 { +>c2 : c2 + + constructor() { + } + private x = 10; +>x : number + + public y = 30; +>y : number + + static k = 20; +>k : number + + private static l = 30; +>l : number + + private method1() { +>method1 : () => void + } + public method2() { +>method2 : () => void + } + static method3() { +>method3 : () => void + } + private static method4() { +>method4 : () => void + } +} +new c(); +>new c() : c +>c : typeof c + +new c2(); +>new c2() : c2 +>c2 : typeof c2 + +export module m1 { +>m1 : typeof m1 + + export class c3 { +>c3 : c3 + + constructor() { + } + private x = 10; +>x : number + + public y = 30; +>y : number + + static k = 20; +>k : number + + private static l = 30; +>l : number + + private method1() { +>method1 : () => void + } + public method2() { +>method2 : () => void + } + static method3() { +>method3 : () => void + } + private static method4() { +>method4 : () => void + } + } + class c4 { +>c4 : c4 + + constructor() { + } + private x = 10; +>x : number + + public y = 30; +>y : number + + static k = 20; +>k : number + + private static l = 30; +>l : number + + private method1() { +>method1 : () => void + } + public method2() { +>method2 : () => void + } + static method3() { +>method3 : () => void + } + private static method4() { +>method4 : () => void + } + } + new c(); +>new c() : c +>c : typeof c + + new c2(); +>new c2() : c2 +>c2 : typeof c2 + + new c3(); +>new c3() : c3 +>c3 : typeof c3 + + new c4(); +>new c4() : c4 +>c4 : typeof c4 +} +module m2 { +>m2 : typeof m2 + + export class c3 { +>c3 : c3 + + constructor() { + } + private x = 10; +>x : number + + public y = 30; +>y : number + + static k = 20; +>k : number + + private static l = 30; +>l : number + + private method1() { +>method1 : () => void + } + public method2() { +>method2 : () => void + } + static method3() { +>method3 : () => void + } + private static method4() { +>method4 : () => void + } + } + class c4 { +>c4 : c4 + + constructor() { + } + private x = 10; +>x : number + + public y = 30; +>y : number + + static k = 20; +>k : number + + private static l = 30; +>l : number + + private method1() { +>method1 : () => void + } + public method2() { +>method2 : () => void + } + static method3() { +>method3 : () => void + } + private static method4() { +>method4 : () => void + } + } + new c(); +>new c() : c +>c : typeof c + + new c2(); +>new c2() : c2 +>c2 : typeof c2 + + new c3(); +>new c3() : c3 +>c3 : typeof c3 + + new c4(); +>new c4() : c4 +>c4 : typeof c4 + + new m1.c3(); +>new m1.c3() : m1.c3 +>m1.c3 : typeof m1.c3 +>m1 : typeof m1 +>c3 : typeof m1.c3 +} diff --git a/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.js b/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.js index 36df01dc237b8..075cc28e82c63 100644 --- a/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.js +++ b/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.js @@ -20,4 +20,4 @@ var A = (function () { }; return A; })(); -A = A; +export { A }; diff --git a/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.js b/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.js index fbcebbd9d0d8c..de66fd0023b6f 100644 --- a/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.js +++ b/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.js @@ -20,4 +20,4 @@ var A = (function () { }; return A; })(); -A = A; +export { A }; diff --git a/tests/cases/compiler/es6ModuleClassDeclaration.ts b/tests/cases/compiler/es6ModuleClassDeclaration.ts new file mode 100644 index 0000000000000..3b36e53037f30 --- /dev/null +++ b/tests/cases/compiler/es6ModuleClassDeclaration.ts @@ -0,0 +1,113 @@ +// @target: ES6 +export class c { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } +} +class c2 { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } +} +new c(); +new c2(); + +export module m1 { + export class c3 { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } + } + class c4 { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } + } + new c(); + new c2(); + new c3(); + new c4(); +} +module m2 { + export class c3 { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } + } + class c4 { + constructor() { + } + private x = 10; + public y = 30; + static k = 20; + private static l = 30; + private method1() { + } + public method2() { + } + static method3() { + } + private static method4() { + } + } + new c(); + new c2(); + new c3(); + new c4(); + new m1.c3(); +} \ No newline at end of file From 680cf6d8442d7d2fe86425fdd8e286c586a1e561 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 12 Mar 2015 10:34:39 -0700 Subject: [PATCH 044/224] Emit export internal import equals declaration in es6 format --- src/compiler/emitter.ts | 8 +- .../reference/es6ModuleInternalImport.js | 46 ++++++++++ .../reference/es6ModuleInternalImport.types | 83 +++++++++++++++++++ .../cases/compiler/es6ModuleInternalImport.ts | 20 +++++ 4 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/es6ModuleInternalImport.js create mode 100644 tests/baselines/reference/es6ModuleInternalImport.types create mode 100644 tests/cases/compiler/es6ModuleInternalImport.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index b114ffda86c46..7e69d8edb713d 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -5169,7 +5169,13 @@ module ts { (!isExternalModule(currentSourceFile) && resolver.isTopLevelValueImportEqualsWithEntityName(node))) { emitLeadingComments(node); emitStart(node); - if (!(node.flags & NodeFlags.Export)) write("var "); + if (isES6ModuleMemberDeclaration(node)) { + write("export "); + write("var "); + } + else if (!(node.flags & NodeFlags.Export)) { + write("var "); + } emitModuleMemberName(node); write(" = "); emit(node.moduleReference); diff --git a/tests/baselines/reference/es6ModuleInternalImport.js b/tests/baselines/reference/es6ModuleInternalImport.js new file mode 100644 index 0000000000000..4a1659cb90167 --- /dev/null +++ b/tests/baselines/reference/es6ModuleInternalImport.js @@ -0,0 +1,46 @@ +//// [es6ModuleInternalImport.ts] +export module m { + export var a = 10; +} +export import a1 = m.a; +import a2 = m.a; +var x = a1 + a2; +export module m1 { + export import a3 = m.a; + import a4 = m.a; + var x = a1 + a2; + var x2 = a3 + a4; +} +module m2 { + export import a3 = m.a; + import a4 = m.a; + var x = a1 + a2; + var x2 = a3 + a4; + var x4 = m1.a3 + m2.a3; +} + +//// [es6ModuleInternalImport.js] +var m; +(function (m) { + m.a = 10; +})(m || (m = {})); +export { m }; +export var a1 = m.a; +var a2 = m.a; +var x = a1 + a2; +var m1; +(function (m1) { + m1.a3 = m.a; + var a4 = m.a; + var x = a1 + a2; + var x2 = m1.a3 + a4; +})(m1 || (m1 = {})); +export { m1 }; +var m2; +(function (m2) { + m2.a3 = m.a; + var a4 = m.a; + var x = a1 + a2; + var x2 = m2.a3 + a4; + var x4 = m1.a3 + m2.a3; +})(m2 || (m2 = {})); diff --git a/tests/baselines/reference/es6ModuleInternalImport.types b/tests/baselines/reference/es6ModuleInternalImport.types new file mode 100644 index 0000000000000..50db69d8edb22 --- /dev/null +++ b/tests/baselines/reference/es6ModuleInternalImport.types @@ -0,0 +1,83 @@ +=== tests/cases/compiler/es6ModuleInternalImport.ts === +export module m { +>m : typeof m + + export var a = 10; +>a : number +} +export import a1 = m.a; +>a1 : number +>m : typeof m +>a : number + +import a2 = m.a; +>a2 : number +>m : typeof m +>a : number + +var x = a1 + a2; +>x : number +>a1 + a2 : number +>a1 : number +>a2 : number + +export module m1 { +>m1 : typeof m1 + + export import a3 = m.a; +>a3 : number +>m : typeof m +>a : number + + import a4 = m.a; +>a4 : number +>m : typeof m +>a : number + + var x = a1 + a2; +>x : number +>a1 + a2 : number +>a1 : number +>a2 : number + + var x2 = a3 + a4; +>x2 : number +>a3 + a4 : number +>a3 : number +>a4 : number +} +module m2 { +>m2 : typeof m2 + + export import a3 = m.a; +>a3 : number +>m : typeof m +>a : number + + import a4 = m.a; +>a4 : number +>m : typeof m +>a : number + + var x = a1 + a2; +>x : number +>a1 + a2 : number +>a1 : number +>a2 : number + + var x2 = a3 + a4; +>x2 : number +>a3 + a4 : number +>a3 : number +>a4 : number + + var x4 = m1.a3 + m2.a3; +>x4 : number +>m1.a3 + m2.a3 : number +>m1.a3 : number +>m1 : typeof m1 +>a3 : number +>m2.a3 : number +>m2 : typeof m2 +>a3 : number +} diff --git a/tests/cases/compiler/es6ModuleInternalImport.ts b/tests/cases/compiler/es6ModuleInternalImport.ts new file mode 100644 index 0000000000000..24e209a87f656 --- /dev/null +++ b/tests/cases/compiler/es6ModuleInternalImport.ts @@ -0,0 +1,20 @@ +// @target: ES6 +export module m { + export var a = 10; +} +export import a1 = m.a; +import a2 = m.a; +var x = a1 + a2; +export module m1 { + export import a3 = m.a; + import a4 = m.a; + var x = a1 + a2; + var x2 = a3 + a4; +} +module m2 { + export import a3 = m.a; + import a4 = m.a; + var x = a1 + a2; + var x2 = a3 + a4; + var x4 = m1.a3 + m2.a3; +} \ No newline at end of file From fe9fff506d00c5bc2aff8ef086d00f5cc32a5096 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 12 Mar 2015 11:51:32 -0700 Subject: [PATCH 045/224] Export * and export { names } emit in es6 format Conflicts: src/compiler/emitter.ts tests/baselines/reference/es6ExportAll.js tests/baselines/reference/es6ExportClause.js tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js --- src/compiler/emitter.ts | 84 ++++++++++++------- tests/baselines/reference/es6ExportAll.js | 47 +++++++++++ tests/baselines/reference/es6ExportAll.types | 24 ++++++ .../baselines/reference/es6ExportAllInEs5.js | 47 +++++++++++ .../reference/es6ExportAllInEs5.types | 24 ++++++ tests/baselines/reference/es6ExportClause.js | 37 ++++++++ .../baselines/reference/es6ExportClause.types | 38 +++++++++ .../es6ExportClauseWithoutModuleSpecifier.js | 55 ++++++++++++ ...s6ExportClauseWithoutModuleSpecifier.types | 40 +++++++++ tests/cases/compiler/es6ExportAll.ts | 17 ++++ tests/cases/compiler/es6ExportAllInEs5.ts | 18 ++++ tests/cases/compiler/es6ExportClause.ts | 19 +++++ .../es6ExportClauseWithoutModuleSpecifier.ts | 21 +++++ 13 files changed, 439 insertions(+), 32 deletions(-) create mode 100644 tests/baselines/reference/es6ExportAll.js create mode 100644 tests/baselines/reference/es6ExportAll.types create mode 100644 tests/baselines/reference/es6ExportAllInEs5.js create mode 100644 tests/baselines/reference/es6ExportAllInEs5.types create mode 100644 tests/baselines/reference/es6ExportClause.js create mode 100644 tests/baselines/reference/es6ExportClause.types create mode 100644 tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js create mode 100644 tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.types create mode 100644 tests/cases/compiler/es6ExportAll.ts create mode 100644 tests/cases/compiler/es6ExportAllInEs5.ts create mode 100644 tests/cases/compiler/es6ExportClause.ts create mode 100644 tests/cases/compiler/es6ExportClauseWithoutModuleSpecifier.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 7e69d8edb713d..af7b0963643c0 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -5108,7 +5108,7 @@ module ts { } } - function emitImportSpecifier(node: ImportSpecifier) { + function emitImportOrExportSpecifier(node: ImportSpecifier) { Debug.assert(languageVersion >= ScriptTarget.ES6); if (node.propertyName) { emit(node.propertyName); @@ -5186,42 +5186,61 @@ module ts { } function emitExportDeclaration(node: ExportDeclaration) { - if (node.moduleSpecifier) { - emitStart(node); - var generatedName = resolver.getGeneratedNameForNode(node); - if (compilerOptions.module !== ModuleKind.AMD) { - write("var "); - write(generatedName); - write(" = "); - emitRequire(getExternalModuleName(node)); + if (languageVersion < ScriptTarget.ES6) { + if (node.moduleSpecifier) { + emitStart(node); + var generatedName = resolver.getGeneratedNameForNode(node); + if (compilerOptions.module !== ModuleKind.AMD) { + write("var "); + write(generatedName); + write(" = "); + emitRequire(getExternalModuleName(node)); + } + if (node.exportClause) { + // export { x, y, ... } + forEach(node.exportClause.elements, specifier => { + writeLine(); + emitStart(specifier); + emitContainingModuleName(specifier); + write("."); + emitNodeWithoutSourceMap(specifier.name); + write(" = "); + write(generatedName); + write("."); + emitNodeWithoutSourceMap(specifier.propertyName || specifier.name); + write(";"); + emitEnd(specifier); + }); + } + else { + // export * + var tempName = createTempVariable(node).text; + writeLine(); + write("for (var " + tempName + " in " + generatedName + ") if (!"); + emitContainingModuleName(node); + write(".hasOwnProperty(" + tempName + ")) "); + emitContainingModuleName(node); + write("[" + tempName + "] = " + generatedName + "[" + tempName + "];"); + } + emitEnd(node); } + } + else { + write("export "); if (node.exportClause) { // export { x, y, ... } - forEach(node.exportClause.elements, specifier => { - writeLine(); - emitStart(specifier); - emitContainingModuleName(specifier); - write("."); - emitNodeWithoutSourceMap(specifier.name); - write(" = "); - write(generatedName); - write("."); - emitNodeWithoutSourceMap(specifier.propertyName || specifier.name); - write(";"); - emitEnd(specifier); - }); + write("{ "); + emitCommaList(node.exportClause.elements); + write(" }"); } else { - // export * - var tempName = createTempVariable(node).text; - writeLine(); - write("for (var " + tempName + " in " + generatedName + ") if (!"); - emitContainingModuleName(node); - write(".hasOwnProperty(" + tempName + ")) "); - emitContainingModuleName(node); - write("[" + tempName + "] = " + generatedName + "[" + tempName + "];"); + write("*"); } - emitEnd(node); + if (node.moduleSpecifier) { + write(" from "); + emit(node.moduleSpecifier); + } + write(";"); } } @@ -5689,7 +5708,8 @@ module ts { case SyntaxKind.ImportDeclaration: return emitImportDeclaration(node); case SyntaxKind.ImportSpecifier: - return emitImportSpecifier(node); + case SyntaxKind.ExportSpecifier: + return emitImportOrExportSpecifier(node); case SyntaxKind.ImportEqualsDeclaration: return emitImportEqualsDeclaration(node); case SyntaxKind.ExportDeclaration: diff --git a/tests/baselines/reference/es6ExportAll.js b/tests/baselines/reference/es6ExportAll.js new file mode 100644 index 0000000000000..be58b3ff81e7b --- /dev/null +++ b/tests/baselines/reference/es6ExportAll.js @@ -0,0 +1,47 @@ +//// [tests/cases/compiler/es6ExportAll.ts] //// + +//// [server.ts] + +export class c { +} +export interface i { +} +export module m { + export var x = 10; +} +export var x = 10; +export module uninstantiated { +} + +//// [client.ts] +export * from "server"; + +//// [server.js] +var c = (function () { + function c() { + } + return c; +})(); +export { c }; +var m; +(function (m) { + m.x = 10; +})(m || (m = {})); +export { m }; +export var x = 10; +//// [client.js] +export * from "server"; + + +//// [server.d.ts] +export declare class c { +} +export interface i { +} +export declare module m { + var x: number; +} +export declare var x: number; +export declare module uninstantiated { +} +//// [client.d.ts] diff --git a/tests/baselines/reference/es6ExportAll.types b/tests/baselines/reference/es6ExportAll.types new file mode 100644 index 0000000000000..99e8fde9d4047 --- /dev/null +++ b/tests/baselines/reference/es6ExportAll.types @@ -0,0 +1,24 @@ +=== tests/cases/compiler/server.ts === + +export class c { +>c : c +} +export interface i { +>i : i +} +export module m { +>m : typeof m + + export var x = 10; +>x : number +} +export var x = 10; +>x : number + +export module uninstantiated { +>uninstantiated : unknown +} + +=== tests/cases/compiler/client.ts === +export * from "server"; +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es6ExportAllInEs5.js b/tests/baselines/reference/es6ExportAllInEs5.js new file mode 100644 index 0000000000000..9fd8c1c4b33e7 --- /dev/null +++ b/tests/baselines/reference/es6ExportAllInEs5.js @@ -0,0 +1,47 @@ +//// [tests/cases/compiler/es6ExportAllInEs5.ts] //// + +//// [server.ts] + +export class c { +} +export interface i { +} +export module m { + export var x = 10; +} +export var x = 10; +export module uninstantiated { +} + +//// [client.ts] +export * from "server"; + +//// [server.js] +var c = (function () { + function c() { + } + return c; +})(); +exports.c = c; +var m; +(function (m) { + m.x = 10; +})(m = exports.m || (exports.m = {})); +exports.x = 10; +//// [client.js] +var _server = require("server"); +for (var _a in _server) if (!exports.hasOwnProperty(_a)) exports[_a] = _server[_a]; + + +//// [server.d.ts] +export declare class c { +} +export interface i { +} +export declare module m { + var x: number; +} +export declare var x: number; +export declare module uninstantiated { +} +//// [client.d.ts] diff --git a/tests/baselines/reference/es6ExportAllInEs5.types b/tests/baselines/reference/es6ExportAllInEs5.types new file mode 100644 index 0000000000000..99e8fde9d4047 --- /dev/null +++ b/tests/baselines/reference/es6ExportAllInEs5.types @@ -0,0 +1,24 @@ +=== tests/cases/compiler/server.ts === + +export class c { +>c : c +} +export interface i { +>i : i +} +export module m { +>m : typeof m + + export var x = 10; +>x : number +} +export var x = 10; +>x : number + +export module uninstantiated { +>uninstantiated : unknown +} + +=== tests/cases/compiler/client.ts === +export * from "server"; +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es6ExportClause.js b/tests/baselines/reference/es6ExportClause.js new file mode 100644 index 0000000000000..03b49dfbd2a0e --- /dev/null +++ b/tests/baselines/reference/es6ExportClause.js @@ -0,0 +1,37 @@ +//// [es6ExportClause.ts] + +class c { +} +interface i { +} +module m { + export var x = 10; +} +var x = 10; +module uninstantiated { +} +export { c }; +export { c as c2 }; +export { i, m as instantiatedModule }; +export { uninstantiated }; +export { x }; + +//// [es6ExportClause.js] +var c = (function () { + function c() { + } + return c; +})(); +var m; +(function (m) { + m.x = 10; +})(m || (m = {})); +var x = 10; +export { c }; +export { c as c2 }; +export { i, m as instantiatedModule }; +export { uninstantiated }; +export { x }; + + +//// [es6ExportClause.d.ts] diff --git a/tests/baselines/reference/es6ExportClause.types b/tests/baselines/reference/es6ExportClause.types new file mode 100644 index 0000000000000..24b9859e0e84c --- /dev/null +++ b/tests/baselines/reference/es6ExportClause.types @@ -0,0 +1,38 @@ +=== tests/cases/compiler/es6ExportClause.ts === + +class c { +>c : c +} +interface i { +>i : i +} +module m { +>m : typeof m + + export var x = 10; +>x : number +} +var x = 10; +>x : number + +module uninstantiated { +>uninstantiated : unknown +} +export { c }; +>c : typeof c + +export { c as c2 }; +>c : typeof c +>c2 : typeof c + +export { i, m as instantiatedModule }; +>i : unknown +>m : typeof m +>instantiatedModule : typeof m + +export { uninstantiated }; +>uninstantiated : unknown + +export { x }; +>x : number + diff --git a/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js new file mode 100644 index 0000000000000..ab3087dc621f4 --- /dev/null +++ b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.js @@ -0,0 +1,55 @@ +//// [tests/cases/compiler/es6ExportClauseWithoutModuleSpecifier.ts] //// + +//// [server.ts] + +export class c { +} +export interface i { +} +export module m { + export var x = 10; +} +export var x = 10; +export module uninstantiated { +} + +//// [client.ts] +export { c } from "server"; +export { c as c2 } from "server"; +export { i, m as instantiatedModule } from "server"; +export { uninstantiated } from "server"; +export { x } from "server"; + +//// [server.js] +var c = (function () { + function c() { + } + return c; +})(); +export { c }; +var m; +(function (m) { + m.x = 10; +})(m || (m = {})); +export { m }; +export var x = 10; +//// [client.js] +export { c } from "server"; +export { c as c2 } from "server"; +export { i, m as instantiatedModule } from "server"; +export { uninstantiated } from "server"; +export { x } from "server"; + + +//// [server.d.ts] +export declare class c { +} +export interface i { +} +export declare module m { + var x: number; +} +export declare var x: number; +export declare module uninstantiated { +} +//// [client.d.ts] diff --git a/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.types b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.types new file mode 100644 index 0000000000000..c0087dccd943a --- /dev/null +++ b/tests/baselines/reference/es6ExportClauseWithoutModuleSpecifier.types @@ -0,0 +1,40 @@ +=== tests/cases/compiler/server.ts === + +export class c { +>c : c +} +export interface i { +>i : i +} +export module m { +>m : typeof m + + export var x = 10; +>x : number +} +export var x = 10; +>x : number + +export module uninstantiated { +>uninstantiated : unknown +} + +=== tests/cases/compiler/client.ts === +export { c } from "server"; +>c : typeof c + +export { c as c2 } from "server"; +>c : typeof c +>c2 : typeof c + +export { i, m as instantiatedModule } from "server"; +>i : unknown +>m : typeof instantiatedModule +>instantiatedModule : typeof instantiatedModule + +export { uninstantiated } from "server"; +>uninstantiated : unknown + +export { x } from "server"; +>x : number + diff --git a/tests/cases/compiler/es6ExportAll.ts b/tests/cases/compiler/es6ExportAll.ts new file mode 100644 index 0000000000000..ed2b47c23c454 --- /dev/null +++ b/tests/cases/compiler/es6ExportAll.ts @@ -0,0 +1,17 @@ +// @target: es6 +// @declaration: true + +// @filename: server.ts +export class c { +} +export interface i { +} +export module m { + export var x = 10; +} +export var x = 10; +export module uninstantiated { +} + +// @filename: client.ts +export * from "server"; \ No newline at end of file diff --git a/tests/cases/compiler/es6ExportAllInEs5.ts b/tests/cases/compiler/es6ExportAllInEs5.ts new file mode 100644 index 0000000000000..ed754e5cacbb5 --- /dev/null +++ b/tests/cases/compiler/es6ExportAllInEs5.ts @@ -0,0 +1,18 @@ +// @target: es5 +// @module: commonjs +// @declaration: true + +// @filename: server.ts +export class c { +} +export interface i { +} +export module m { + export var x = 10; +} +export var x = 10; +export module uninstantiated { +} + +// @filename: client.ts +export * from "server"; \ No newline at end of file diff --git a/tests/cases/compiler/es6ExportClause.ts b/tests/cases/compiler/es6ExportClause.ts new file mode 100644 index 0000000000000..a16e2c9e7aa69 --- /dev/null +++ b/tests/cases/compiler/es6ExportClause.ts @@ -0,0 +1,19 @@ +// @target: es6 +// @declaration: true + +// @filename: server.ts +class c { +} +interface i { +} +module m { + export var x = 10; +} +var x = 10; +module uninstantiated { +} +export { c }; +export { c as c2 }; +export { i, m as instantiatedModule }; +export { uninstantiated }; +export { x }; \ No newline at end of file diff --git a/tests/cases/compiler/es6ExportClauseWithoutModuleSpecifier.ts b/tests/cases/compiler/es6ExportClauseWithoutModuleSpecifier.ts new file mode 100644 index 0000000000000..22a6cef420322 --- /dev/null +++ b/tests/cases/compiler/es6ExportClauseWithoutModuleSpecifier.ts @@ -0,0 +1,21 @@ +// @target: es6 +// @declaration: true + +// @filename: server.ts +export class c { +} +export interface i { +} +export module m { + export var x = 10; +} +export var x = 10; +export module uninstantiated { +} + +// @filename: client.ts +export { c } from "server"; +export { c as c2 } from "server"; +export { i, m as instantiatedModule } from "server"; +export { uninstantiated } from "server"; +export { x } from "server"; \ No newline at end of file From 0672923323b35711cd65bf233955d4e848e449ef Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 12 Mar 2015 15:19:45 -0700 Subject: [PATCH 046/224] Parse classDeclaration in strict mode code for ES6 --- src/compiler/checker.ts | 6 ++- src/compiler/parser.ts | 22 ++++++++++- ...ationInStrictModeByDefaultInES6.errors.txt | 31 +++++++++++++++ ...ssDeclarationInStrictModeByDefaultInES6.js | 23 +++++++++++ ...ssDeclarationInStrictModeByDefaultInES6.ts | 9 +++++ tests/cases/unittests/incrementalParser.ts | 39 +++++++++++++++++++ 6 files changed, 128 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/parseClassDeclarationInStrictModeByDefaultInES6.errors.txt create mode 100644 tests/baselines/reference/parseClassDeclarationInStrictModeByDefaultInES6.js create mode 100644 tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 28b3b74b271a3..689f27af867b6 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11891,7 +11891,11 @@ module ts { var identifier = name; if (contextNode && (contextNode.parserContextFlags & ParserContextFlags.StrictMode) && isEvalOrArgumentsIdentifier(identifier)) { var nameText = declarationNameToString(identifier); - return grammarErrorOnNode(identifier, Diagnostics.Invalid_use_of_0_in_strict_mode, nameText); + + // Always report 'eval' and 'arguments' invalid usage in strict mode code regardless of parser diagnostics + var sourceFile = getSourceFileOfNode(identifier); + diagnostics.add(createDiagnosticForNode(identifier, Diagnostics.Invalid_use_of_0_in_strict_mode, nameText)); + return true; } } } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 0d6f002a3dae5..7658a49bc48e6 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4372,6 +4372,12 @@ module ts { function parsePropertyOrMethodDeclaration(fullStart: number, modifiers: ModifiersArray): ClassElement { var asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); + + // From ES6 Specification, "implements", "interface", "let", "package", "private", "protected", "public", "static", and "yield" are reserved words within strict mode code + if (inStrictModeContext() && (token > SyntaxKind.LastReservedWord)) { + parseErrorAtCurrentToken(Diagnostics.Invalid_use_of_0_in_strict_mode, tokenToString(token)); + } + var name = parsePropertyName(); // Note: this is not legal as per the grammar. But we allow it in the parser and @@ -4517,6 +4523,12 @@ module ts { } function parseClassDeclaration(fullStart: number, modifiers: ModifiersArray): ClassDeclaration { + // In ES6 specification, All parts of a ClassDeclaration or a ClassExpression are strict mode code + if (languageVersion >= ScriptTarget.ES6) { + var savedStrictModeContext = inStrictModeContext(); + setStrictModeContext(true); + } + var node = createNode(SyntaxKind.ClassDeclaration, fullStart); setModifiers(node, modifiers); parseExpected(SyntaxKind.ClassKeyword); @@ -4537,7 +4549,15 @@ module ts { else { node.members = createMissingList(); } - return finishNode(node); + + var finishedNode = finishNode(node); + if (languageVersion >= ScriptTarget.ES6) { + setStrictModeContext(savedStrictModeContext); + return finishedNode; + } + else { + return finishedNode; + } } function parseHeritageClauses(isClassHeritageClause: boolean): NodeArray { diff --git a/tests/baselines/reference/parseClassDeclarationInStrictModeByDefaultInES6.errors.txt b/tests/baselines/reference/parseClassDeclarationInStrictModeByDefaultInES6.errors.txt new file mode 100644 index 0000000000000..04ac8b28a8bdf --- /dev/null +++ b/tests/baselines/reference/parseClassDeclarationInStrictModeByDefaultInES6.errors.txt @@ -0,0 +1,31 @@ +tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(2,5): error TS1100: Invalid use of 'interface' in strict mode. +tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(3,12): error TS1100: Invalid use of 'implements' in strict mode. +tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(4,16): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(5,17): error TS1100: Invalid use of 'eval' in strict mode. +tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(6,9): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(6,9): error TS2322: Type 'string' is not assignable to type 'IArguments'. + Property 'callee' is missing in type 'String'. + + +==== tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts (6 errors) ==== + class C { + interface = 10; + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'interface' in strict mode. + public implements() { } + ~~~~~~~~~~ +!!! error TS1100: Invalid use of 'implements' in strict mode. + public foo(arguments: any) { } + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. + private bar(eval:any) { + ~~~~ +!!! error TS1100: Invalid use of 'eval' in strict mode. + arguments = "hello"; + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. + ~~~~~~~~~ +!!! error TS2322: Type 'string' is not assignable to type 'IArguments'. +!!! error TS2322: Property 'callee' is missing in type 'String'. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/parseClassDeclarationInStrictModeByDefaultInES6.js b/tests/baselines/reference/parseClassDeclarationInStrictModeByDefaultInES6.js new file mode 100644 index 0000000000000..2a8d75dde60aa --- /dev/null +++ b/tests/baselines/reference/parseClassDeclarationInStrictModeByDefaultInES6.js @@ -0,0 +1,23 @@ +//// [parseClassDeclarationInStrictModeByDefaultInES6.ts] +class C { + interface = 10; + public implements() { } + public foo(arguments: any) { } + private bar(eval:any) { + arguments = "hello"; + } +} + +//// [parseClassDeclarationInStrictModeByDefaultInES6.js] +class C { + constructor() { + this.interface = 10; + } + implements() { + } + foo(arguments) { + } + bar(eval) { + arguments = "hello"; + } +} diff --git a/tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts b/tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts new file mode 100644 index 0000000000000..b2517d89657a8 --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts @@ -0,0 +1,9 @@ +// @target: es6 +class C { + interface = 10; + public implements() { } + public foo(arguments: any) { } + private bar(eval:any) { + arguments = "hello"; + } +} \ No newline at end of file diff --git a/tests/cases/unittests/incrementalParser.ts b/tests/cases/unittests/incrementalParser.ts index e785f1cdf0083..87c0c3701f388 100644 --- a/tests/cases/unittests/incrementalParser.ts +++ b/tests/cases/unittests/incrementalParser.ts @@ -719,6 +719,16 @@ module m3 { }\ var oldText = ScriptSnapshot.fromString(source); var newTextAndChange = withChange(oldText, 0, "var v =".length, "class C"); + compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); // As specified in ES6 specification, all parts of a ClassDeclaration or a ClassExpression are strict mode code. + }); + + it('Moving methods from object literal to class in strict mode', () => { + debugger; + var source = "\"use strict\"; var v = { public A() { } public B() { } public C() { } }" + + var oldText = ScriptSnapshot.fromString(source); + var newTextAndChange = withChange(oldText, 14, "var v =".length, "class C"); + compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 4); }); @@ -728,6 +738,15 @@ module m3 { }\ var oldText = ScriptSnapshot.fromString(source); var newTextAndChange = withChange(oldText, 0, "class".length, "interface"); + compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); // As specified in ES6 specification, all parts of a ClassDeclaration or a ClassExpression are strict mode code. + }); + + it('Moving index signatures from class to interface in strict mode', () => { + var source = "\"use strict\"; class C { public [a: number]: string; public [a: number]: string; public [a: number]: string }" + + var oldText = ScriptSnapshot.fromString(source); + var newTextAndChange = withChange(oldText, 14, "class".length, "interface"); + compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 18); }); @@ -737,6 +756,16 @@ module m3 { }\ var oldText = ScriptSnapshot.fromString(source); var newTextAndChange = withChange(oldText, 0, "interface".length, "class"); + compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); // As specified in ES6 specification, all parts of a ClassDeclaration or a ClassExpression are strict mode code. + }); + + + it('Moving index signatures from interface to class in strict mode', () => { + var source = "\"use strict\"; interface C { public [a: number]: string; public [a: number]: string; public [a: number]: string }" + + var oldText = ScriptSnapshot.fromString(source); + var newTextAndChange = withChange(oldText, 14, "interface".length, "class"); + compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 18); }); @@ -755,6 +784,16 @@ module m3 { }\ var oldText = ScriptSnapshot.fromString(source); var newTextAndChange = withChange(oldText, 0, "var v =".length, "class C"); + compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); // As specified in ES6 specification, all parts of a ClassDeclaration or a ClassExpression are strict mode code. + }); + + + it('Moving accessors from object literal to class in strict mode', () => { + var source = "\"use strict\"; var v = { public get A() { } public get B() { } public get C() { } }" + + var oldText = ScriptSnapshot.fromString(source); + var newTextAndChange = withChange(oldText, 14, "var v =".length, "class C"); + compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 4); }); From 800c523f4f106fd8b5ebfd60287fe0375583e3b2 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 12 Mar 2015 16:02:43 -0700 Subject: [PATCH 047/224] Clean up redundant tests --- ...s => emitClassDeclarationOverloadInES6.js} | 4 +-- ...> emitClassDeclarationOverloadInES6.types} | 2 +- ...ClassDeclarationWithMethodOverloadInES6.js | 22 -------------- ...ssDeclarationWithMethodOverloadInES6.types | 29 ------------------- ...DeclarationWithRestAndDefaultArguements.js | 20 ------------- ...larationWithRestAndDefaultArguements.types | 25 ---------------- ...s => emitClassDeclarationOverloadInES6.ts} | 0 ...mitClassDeclarationWithConstructorInES6.ts | 18 +++++++++--- .../emitClassDeclarationWithExport.ts | 4 +-- .../emitClassDeclarationWithExtensionInES6.ts | 21 ++++++++++++-- ...ClassDeclarationWithMethodOverloadInES6.ts | 11 ------- ...DeclarationWithRestAndDefaultArguements.ts | 8 ----- .../emitClassDeclarationWithThisKeyword.ts | 18 ++++++++++++ 13 files changed, 55 insertions(+), 127 deletions(-) rename tests/baselines/reference/{emitClassDeclarationWithConstructorOverloadInES6.js => emitClassDeclarationOverloadInES6.js} (64%) rename tests/baselines/reference/{emitClassDeclarationWithConstructorOverloadInES6.types => emitClassDeclarationOverloadInES6.types} (81%) delete mode 100644 tests/baselines/reference/emitClassDeclarationWithMethodOverloadInES6.js delete mode 100644 tests/baselines/reference/emitClassDeclarationWithMethodOverloadInES6.types delete mode 100644 tests/baselines/reference/emitClassDeclarationWithRestAndDefaultArguements.js delete mode 100644 tests/baselines/reference/emitClassDeclarationWithRestAndDefaultArguements.types rename tests/cases/conformance/es6/classDeclaration/{emitClassDeclarationWithConstructorOverloadInES6.ts => emitClassDeclarationOverloadInES6.ts} (100%) delete mode 100644 tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithMethodOverloadInES6.ts delete mode 100644 tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithRestAndDefaultArguements.ts create mode 100644 tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithThisKeyword.ts diff --git a/tests/baselines/reference/emitClassDeclarationWithConstructorOverloadInES6.js b/tests/baselines/reference/emitClassDeclarationOverloadInES6.js similarity index 64% rename from tests/baselines/reference/emitClassDeclarationWithConstructorOverloadInES6.js rename to tests/baselines/reference/emitClassDeclarationOverloadInES6.js index b7fe4f0cda7a1..4cf96778f3f4d 100644 --- a/tests/baselines/reference/emitClassDeclarationWithConstructorOverloadInES6.js +++ b/tests/baselines/reference/emitClassDeclarationOverloadInES6.js @@ -1,4 +1,4 @@ -//// [emitClassDeclarationWithConstructorOverloadInES6.ts] +//// [emitClassDeclarationOverloadInES6.ts] class C { constructor(y: any) constructor(x: number) { @@ -10,7 +10,7 @@ class D { constructor(x: number, z="hello") {} } -//// [emitClassDeclarationWithConstructorOverloadInES6.js] +//// [emitClassDeclarationOverloadInES6.js] class C { constructor(x) { } diff --git a/tests/baselines/reference/emitClassDeclarationWithConstructorOverloadInES6.types b/tests/baselines/reference/emitClassDeclarationOverloadInES6.types similarity index 81% rename from tests/baselines/reference/emitClassDeclarationWithConstructorOverloadInES6.types rename to tests/baselines/reference/emitClassDeclarationOverloadInES6.types index 96e9f25549e77..850a5aa545621 100644 --- a/tests/baselines/reference/emitClassDeclarationWithConstructorOverloadInES6.types +++ b/tests/baselines/reference/emitClassDeclarationOverloadInES6.types @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorOverloadInES6.ts === +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationOverloadInES6.ts === class C { >C : C diff --git a/tests/baselines/reference/emitClassDeclarationWithMethodOverloadInES6.js b/tests/baselines/reference/emitClassDeclarationWithMethodOverloadInES6.js deleted file mode 100644 index 252a44122eb02..0000000000000 --- a/tests/baselines/reference/emitClassDeclarationWithMethodOverloadInES6.js +++ /dev/null @@ -1,22 +0,0 @@ -//// [emitClassDeclarationWithMethodOverloadInES6.ts] -class D { - _bar: string; - foo(a: any); - foo() { } - - baz(...args): string; - baz(z:string, v: number): string { - return this._bar; - } -} - -//// [emitClassDeclarationWithMethodOverloadInES6.js] -class D { - constructor() { - } - foo() { - } - baz(z, v) { - return this._bar; - } -} diff --git a/tests/baselines/reference/emitClassDeclarationWithMethodOverloadInES6.types b/tests/baselines/reference/emitClassDeclarationWithMethodOverloadInES6.types deleted file mode 100644 index 3017908e576d9..0000000000000 --- a/tests/baselines/reference/emitClassDeclarationWithMethodOverloadInES6.types +++ /dev/null @@ -1,29 +0,0 @@ -=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithMethodOverloadInES6.ts === -class D { ->D : D - - _bar: string; ->_bar : string - - foo(a: any); ->foo : (a: any) => any ->a : any - - foo() { } ->foo : (a: any) => any - - baz(...args): string; ->baz : (...args: any[]) => string ->args : any[] - - baz(z:string, v: number): string { ->baz : (...args: any[]) => string ->z : string ->v : number - - return this._bar; ->this._bar : string ->this : D ->_bar : string - } -} diff --git a/tests/baselines/reference/emitClassDeclarationWithRestAndDefaultArguements.js b/tests/baselines/reference/emitClassDeclarationWithRestAndDefaultArguements.js deleted file mode 100644 index 179818387da6d..0000000000000 --- a/tests/baselines/reference/emitClassDeclarationWithRestAndDefaultArguements.js +++ /dev/null @@ -1,20 +0,0 @@ -//// [emitClassDeclarationWithRestAndDefaultArguements.ts] -class B { - constructor(y = 10, ...p) { } - foo(a = "hi") { } - bar(b = 10, ...p) { } - far(...p) - far(a: any) { } -} - -//// [emitClassDeclarationWithRestAndDefaultArguements.js] -class B { - constructor(y = 10, ...p) { - } - foo(a = "hi") { - } - bar(b = 10, ...p) { - } - far(a) { - } -} diff --git a/tests/baselines/reference/emitClassDeclarationWithRestAndDefaultArguements.types b/tests/baselines/reference/emitClassDeclarationWithRestAndDefaultArguements.types deleted file mode 100644 index 6f59f8220ade3..0000000000000 --- a/tests/baselines/reference/emitClassDeclarationWithRestAndDefaultArguements.types +++ /dev/null @@ -1,25 +0,0 @@ -=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithRestAndDefaultArguements.ts === -class B { ->B : B - - constructor(y = 10, ...p) { } ->y : number ->p : any[] - - foo(a = "hi") { } ->foo : (a?: string) => void ->a : string - - bar(b = 10, ...p) { } ->bar : (b?: number, ...p: any[]) => void ->b : number ->p : any[] - - far(...p) ->far : (...p: any[]) => any ->p : any[] - - far(a: any) { } ->far : (...p: any[]) => any ->a : any -} diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorOverloadInES6.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationOverloadInES6.ts similarity index 100% rename from tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorOverloadInES6.ts rename to tests/cases/conformance/es6/classDeclaration/emitClassDeclarationOverloadInES6.ts diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorInES6.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorInES6.ts index 9e06636da7e2a..e6c71b0674071 100644 --- a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorInES6.ts +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorInES6.ts @@ -1,14 +1,24 @@ // @target: es6 -class C { +class A { y: number; constructor(x: number) { } + foo(a: any); + foo() { } } -class D { +class B { y: number; x: string = "hello"; - constructor(x: number, z = "hello") { + _bar: string; + + constructor(x: number, z = "hello", ...args) { this.y = 10; } -} \ No newline at end of file + baz(...args): string; + baz(z: string, v: number): string { + return this._bar; + } +} + + diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts index f3ed5eb95d84f..c7fd43cb9e283 100644 --- a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts @@ -1,8 +1,8 @@ // @target: es6 export class C { - foo() { } + foo(y: string, ...args: any) { } } export default class D { - bar() { } + bar(k = 10) {} } \ No newline at end of file diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExtensionInES6.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExtensionInES6.ts index 519af626850ab..9b79d1b003bf4 100644 --- a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExtensionInES6.ts +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExtensionInES6.ts @@ -1,8 +1,23 @@ // @target: es6 -class B { } -class C extends B { } -class D extends B { +class B { + baz(a: string, y = 10) { } +} +class C extends B { + foo() { } + baz(a: string, y:number) { + super.baz(a, y); + } +} +class D extends C { constructor() { super(); } + + foo() { + super.foo(); + } + + baz() { + super.baz("hello", 10); + } } diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithMethodOverloadInES6.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithMethodOverloadInES6.ts deleted file mode 100644 index e1b277fae51cf..0000000000000 --- a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithMethodOverloadInES6.ts +++ /dev/null @@ -1,11 +0,0 @@ -// @target:es6 -class D { - _bar: string; - foo(a: any); - foo() { } - - baz(...args): string; - baz(z:string, v: number): string { - return this._bar; - } -} \ No newline at end of file diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithRestAndDefaultArguements.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithRestAndDefaultArguements.ts deleted file mode 100644 index 20c251b2cfa17..0000000000000 --- a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithRestAndDefaultArguements.ts +++ /dev/null @@ -1,8 +0,0 @@ -// @target: es6 -class B { - constructor(y = 10, ...p) { } - foo(a = "hi") { } - bar(b = 10, ...p) { } - far(...p) - far(a: any) { } -} \ No newline at end of file diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithThisKeyword.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithThisKeyword.ts new file mode 100644 index 0000000000000..f78e012bc2073 --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithThisKeyword.ts @@ -0,0 +1,18 @@ +// @target: es6 +class B { + x = 10; + constructor() { + this.x = 10; + } + foo() { + console.log(this.x); + } + + get X() { + return this.x; + } + + set bX(y: number) { + this.x = y; + } +} \ No newline at end of file From af05afdc50617f783713b002470012d14b9e37e1 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 12 Mar 2015 16:34:06 -0700 Subject: [PATCH 048/224] Emit Super as super --- src/compiler/emitter.ts | 23 +++++--- .../emitClassDeclarationWithThisKeyword.js | 38 ++++++++++++++ .../emitClassDeclarationWithThisKeyword.types | 52 +++++++++++++++++++ .../emitClassDeclarationWithThisKeyword.ts | 3 +- 4 files changed, 107 insertions(+), 9 deletions(-) create mode 100644 tests/baselines/reference/emitClassDeclarationWithThisKeyword.js create mode 100644 tests/baselines/reference/emitClassDeclarationWithThisKeyword.types diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 606bd22f2c99e..a0303610a3da0 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2630,15 +2630,21 @@ module ts { } function emitSuper(node: Node) { - var flags = resolver.getNodeCheckFlags(node); - if (flags & NodeCheckFlags.SuperInstance) { - write("_super.prototype"); - } - else if (flags & NodeCheckFlags.SuperStatic) { - write("_super"); + if (languageVersion >= ScriptTarget.ES6) { + write("super"); } else { - write("super"); + Debug.assert(languageVersion < ScriptTarget.ES6) + var flags = resolver.getNodeCheckFlags(node); + if (flags & NodeCheckFlags.SuperInstance) { + write("_super.prototype"); + } + else if (flags & NodeCheckFlags.SuperStatic) { + write("_super"); + } + else { + write("super"); + } } } @@ -4544,7 +4550,8 @@ module ts { emitEnd(accessors.getAccessor); emitTrailingComments(accessors.getAccessor); } - else if (accessors.setAccessor) { + if (accessors.setAccessor) { + // We will only write new line if we just emit getAccessor emitLeadingComments(accessors.setAccessor); emitStart(accessors.setAccessor); if (member.flags & NodeFlags.Static) { diff --git a/tests/baselines/reference/emitClassDeclarationWithThisKeyword.js b/tests/baselines/reference/emitClassDeclarationWithThisKeyword.js new file mode 100644 index 0000000000000..de100457aa954 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithThisKeyword.js @@ -0,0 +1,38 @@ +//// [emitClassDeclarationWithThisKeyword.ts] +class B { + x = 10; + constructor() { + this.x = 10; + } + static log(a: number) { } + foo() { + B.log(this.x); + } + + get X() { + return this.x; + } + + set bX(y: number) { + this.x = y; + } +} + +//// [emitClassDeclarationWithThisKeyword.js] +class B { + constructor() { + this.x = 10; + this.x = 10; + } + static log(a) { + } + foo() { + B.log(this.x); + } + get X() { + return this.x; + } + set bX(y) { + this.x = y; + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithThisKeyword.types b/tests/baselines/reference/emitClassDeclarationWithThisKeyword.types new file mode 100644 index 0000000000000..ebb6f26598d1c --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithThisKeyword.types @@ -0,0 +1,52 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithThisKeyword.ts === +class B { +>B : B + + x = 10; +>x : number + + constructor() { + this.x = 10; +>this.x = 10 : number +>this.x : number +>this : B +>x : number + } + static log(a: number) { } +>log : (a: number) => void +>a : number + + foo() { +>foo : () => void + + B.log(this.x); +>B.log(this.x) : void +>B.log : (a: number) => void +>B : typeof B +>log : (a: number) => void +>this.x : number +>this : B +>x : number + } + + get X() { +>X : number + + return this.x; +>this.x : number +>this : B +>x : number + } + + set bX(y: number) { +>bX : number +>y : number + + this.x = y; +>this.x = y : number +>this.x : number +>this : B +>x : number +>y : number + } +} diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithThisKeyword.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithThisKeyword.ts index f78e012bc2073..4356fcce2ab2c 100644 --- a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithThisKeyword.ts +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithThisKeyword.ts @@ -4,8 +4,9 @@ class B { constructor() { this.x = 10; } + static log(a: number) { } foo() { - console.log(this.x); + B.log(this.x); } get X() { From b3c8bcb31924f11ce45b54b05bc1e8f49008edec Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 12 Mar 2015 17:14:33 -0700 Subject: [PATCH 049/224] Emit export default in ES6 --- src/compiler/checker.ts | 4 +- src/compiler/emitter.ts | 59 +++++++++++++++---- .../es5ExportDefaultClassDeclaration.js | 22 +++++++ .../es5ExportDefaultClassDeclaration.types | 9 +++ .../es5ExportDefaultClassDeclaration2.js | 52 ++++++++++++++++ .../es5ExportDefaultClassDeclaration2.types | 7 +++ .../reference/es5ExportDefaultExpression.js | 11 ++++ .../es5ExportDefaultExpression.types | 6 ++ .../es5ExportDefaultFunctionDeclaration.js | 13 ++++ .../es5ExportDefaultFunctionDeclaration.types | 5 ++ .../es5ExportDefaultFunctionDeclaration2.js | 26 ++++++++ ...es5ExportDefaultFunctionDeclaration2.types | 5 ++ .../es5ExportDefaultIdentifier.errors.txt | 11 ++++ .../reference/es5ExportDefaultIdentifier.js | 17 ++++++ .../reference/es5ExportEquals.errors.txt | 11 ++++ tests/baselines/reference/es5ExportEquals.js | 17 ++++++ .../reference/es6ExportAssignment.js | 1 + .../es6ExportDefaultClassDeclaration.js | 22 +++++++ .../es6ExportDefaultClassDeclaration.types | 9 +++ .../es6ExportDefaultClassDeclaration2.js | 52 ++++++++++++++++ .../es6ExportDefaultClassDeclaration2.types | 7 +++ .../reference/es6ExportDefaultExpression.js | 11 ++++ .../es6ExportDefaultExpression.types | 6 ++ .../es6ExportDefaultFunctionDeclaration.js | 12 ++++ .../es6ExportDefaultFunctionDeclaration.types | 5 ++ .../es6ExportDefaultFunctionDeclaration2.js | 25 ++++++++ ...es6ExportDefaultFunctionDeclaration2.types | 5 ++ .../reference/es6ExportDefaultIdentifier.js | 16 +++++ .../es6ExportDefaultIdentifier.types | 8 +++ .../reference/es6ExportEquals.errors.txt | 11 ++++ tests/baselines/reference/es6ExportEquals.js | 16 +++++ ...tDefaultBindingFollowedWithNamedImport1.js | 1 + ...ultBindingFollowedWithNamespaceBinding1.js | 1 + .../reference/es6ImportEqualsDeclaration.js | 1 + .../es5ExportDefaultClassDeclaration.ts | 7 +++ .../es5ExportDefaultClassDeclaration2.ts | 7 +++ .../compiler/es5ExportDefaultExpression.ts | 5 ++ .../es5ExportDefaultFunctionDeclaration.ts | 5 ++ .../es5ExportDefaultFunctionDeclaration2.ts | 5 ++ .../compiler/es5ExportDefaultIdentifier.ts | 7 +++ tests/cases/compiler/es5ExportEquals.ts | 7 +++ .../es6ExportDefaultClassDeclaration.ts | 6 ++ .../es6ExportDefaultClassDeclaration2.ts | 6 ++ .../compiler/es6ExportDefaultExpression.ts | 4 ++ .../es6ExportDefaultFunctionDeclaration.ts | 4 ++ .../es6ExportDefaultFunctionDeclaration2.ts | 4 ++ .../compiler/es6ExportDefaultIdentifier.ts | 6 ++ tests/cases/compiler/es6ExportEquals.ts | 6 ++ 48 files changed, 549 insertions(+), 14 deletions(-) create mode 100644 tests/baselines/reference/es5ExportDefaultClassDeclaration.js create mode 100644 tests/baselines/reference/es5ExportDefaultClassDeclaration.types create mode 100644 tests/baselines/reference/es5ExportDefaultClassDeclaration2.js create mode 100644 tests/baselines/reference/es5ExportDefaultClassDeclaration2.types create mode 100644 tests/baselines/reference/es5ExportDefaultExpression.js create mode 100644 tests/baselines/reference/es5ExportDefaultExpression.types create mode 100644 tests/baselines/reference/es5ExportDefaultFunctionDeclaration.js create mode 100644 tests/baselines/reference/es5ExportDefaultFunctionDeclaration.types create mode 100644 tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.js create mode 100644 tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.types create mode 100644 tests/baselines/reference/es5ExportDefaultIdentifier.errors.txt create mode 100644 tests/baselines/reference/es5ExportDefaultIdentifier.js create mode 100644 tests/baselines/reference/es5ExportEquals.errors.txt create mode 100644 tests/baselines/reference/es5ExportEquals.js create mode 100644 tests/baselines/reference/es6ExportDefaultClassDeclaration.js create mode 100644 tests/baselines/reference/es6ExportDefaultClassDeclaration.types create mode 100644 tests/baselines/reference/es6ExportDefaultClassDeclaration2.js create mode 100644 tests/baselines/reference/es6ExportDefaultClassDeclaration2.types create mode 100644 tests/baselines/reference/es6ExportDefaultExpression.js create mode 100644 tests/baselines/reference/es6ExportDefaultExpression.types create mode 100644 tests/baselines/reference/es6ExportDefaultFunctionDeclaration.js create mode 100644 tests/baselines/reference/es6ExportDefaultFunctionDeclaration.types create mode 100644 tests/baselines/reference/es6ExportDefaultFunctionDeclaration2.js create mode 100644 tests/baselines/reference/es6ExportDefaultFunctionDeclaration2.types create mode 100644 tests/baselines/reference/es6ExportDefaultIdentifier.js create mode 100644 tests/baselines/reference/es6ExportDefaultIdentifier.types create mode 100644 tests/baselines/reference/es6ExportEquals.errors.txt create mode 100644 tests/baselines/reference/es6ExportEquals.js create mode 100644 tests/cases/compiler/es5ExportDefaultClassDeclaration.ts create mode 100644 tests/cases/compiler/es5ExportDefaultClassDeclaration2.ts create mode 100644 tests/cases/compiler/es5ExportDefaultExpression.ts create mode 100644 tests/cases/compiler/es5ExportDefaultFunctionDeclaration.ts create mode 100644 tests/cases/compiler/es5ExportDefaultFunctionDeclaration2.ts create mode 100644 tests/cases/compiler/es5ExportDefaultIdentifier.ts create mode 100644 tests/cases/compiler/es5ExportEquals.ts create mode 100644 tests/cases/compiler/es6ExportDefaultClassDeclaration.ts create mode 100644 tests/cases/compiler/es6ExportDefaultClassDeclaration2.ts create mode 100644 tests/cases/compiler/es6ExportDefaultExpression.ts create mode 100644 tests/cases/compiler/es6ExportDefaultFunctionDeclaration.ts create mode 100644 tests/cases/compiler/es6ExportDefaultFunctionDeclaration2.ts create mode 100644 tests/cases/compiler/es6ExportDefaultIdentifier.ts create mode 100644 tests/cases/compiler/es6ExportEquals.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1e0976c31a0a5..7911c14e0def3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9946,7 +9946,7 @@ module ts { } checkExternalModuleExports(container); - if (languageVersion >= ScriptTarget.ES6) { + if (node.isExportEquals && languageVersion >= ScriptTarget.ES6) { // export assignment is deprecated in es6 or above grammarErrorOnNode(node, Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_export_default_instead); } @@ -9994,7 +9994,7 @@ module ts { if (!links.exportsChecked) { var defaultSymbol = getExportAssignmentSymbol(moduleSymbol); if (defaultSymbol) { - if (hasExportedMembers(moduleSymbol)) { + if (languageVersion < ScriptTarget.ES6 && hasExportedMembers(moduleSymbol)) { var declaration = getDeclarationOfAliasSymbol(defaultSymbol) || defaultSymbol.valueDeclaration; error(declaration, Diagnostics.An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements); } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index af7b0963643c0..a52daa512372e 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4331,6 +4331,19 @@ module ts { } } + function shouldEmitFunctionName(node: Declaration): boolean { + // Emit a declaration name for the function iff: + // it is a function expression with a name provided + // it is a function declaration with a name provided + // it is a function declaration is not the default export, and is missing a name (emit a generated name for it) + if (node.kind === SyntaxKind.FunctionExpression) { + return !!node.name; + } + else if (node.kind === SyntaxKind.FunctionDeclaration) { + return !!node.name || (languageVersion >= ScriptTarget.ES6 && !(node.flags & NodeFlags.Default)); + } + } + function emitFunctionDeclaration(node: FunctionLikeDeclaration) { if (nodeIsMissing(node.body)) { return emitPinnedOrTripleSlashComments(node); @@ -4346,13 +4359,17 @@ module ts { if (!shouldEmitAsArrowFunction(node)) { if (isES6ModuleMemberDeclaration(node)) { write("export "); + if (node.flags & NodeFlags.Default) { + write("default "); + } } write("function "); } - if (node.kind === SyntaxKind.FunctionDeclaration || (node.kind === SyntaxKind.FunctionExpression && node.name)) { + if (shouldEmitFunctionName(node)) { emitDeclarationName(node); } + emitSignatureAndBody(node); if (languageVersion < ScriptTarget.ES6 && node.kind === SyntaxKind.FunctionDeclaration && node.parent === currentSourceFile && node.name) { emitExportMemberAssignments((node).name); @@ -5412,6 +5429,7 @@ module ts { } function emitES6Module(node: SourceFile, startIndex: number) { + createExternalModuleInfo(node); externalImports = undefined; exportSpecifiers = undefined; emitCaptureThisForNodeIfNecessary(node); @@ -5422,20 +5440,37 @@ module ts { function emitExportDefault(sourceFile: SourceFile, emitAsReturn: boolean) { if (exportDefault && resolver.hasExportDefaultValue(sourceFile)) { - writeLine(); - emitStart(exportDefault); - write(emitAsReturn ? "return " : "module.exports = "); - if (exportDefault.kind === SyntaxKind.ExportAssignment) { - emit((exportDefault).expression); - } - else if (exportDefault.kind === SyntaxKind.ExportSpecifier) { - emit((exportDefault).propertyName); + if (languageVersion >= ScriptTarget.ES6) { + Debug.assert(!emitAsReturn); + if (exportDefault.kind === SyntaxKind.ExportAssignment) { + writeLine(); + emitStart(exportDefault); + write("export default "); + var expression = (exportDefault).expression; + emit(expression); + if (expression.kind !== SyntaxKind.FunctionDeclaration && + expression.kind !== SyntaxKind.ClassDeclaration) { + write(";"); + } + emitEnd(exportDefault); + } } else { - emitDeclarationName(exportDefault); + writeLine(); + emitStart(exportDefault); + write(emitAsReturn ? "return " : "module.exports = "); + if (exportDefault.kind === SyntaxKind.ExportAssignment) { + emit((exportDefault).expression); + } + else if (exportDefault.kind === SyntaxKind.ExportSpecifier) { + emit((exportDefault).propertyName); + } + else { + emitDeclarationName(exportDefault); + } + write(";"); + emitEnd(exportDefault); } - write(";"); - emitEnd(exportDefault); } } diff --git a/tests/baselines/reference/es5ExportDefaultClassDeclaration.js b/tests/baselines/reference/es5ExportDefaultClassDeclaration.js new file mode 100644 index 0000000000000..3ac92c5d9eaa5 --- /dev/null +++ b/tests/baselines/reference/es5ExportDefaultClassDeclaration.js @@ -0,0 +1,22 @@ +//// [es5ExportDefaultClassDeclaration.ts] + +export default class C { + method() { } +} + + +//// [es5ExportDefaultClassDeclaration.js] +var C = (function () { + function C() { + } + C.prototype.method = function () { + }; + return C; +})(); +module.exports = C; + + +//// [es5ExportDefaultClassDeclaration.d.ts] +export declare class C { + method(): void; +} diff --git a/tests/baselines/reference/es5ExportDefaultClassDeclaration.types b/tests/baselines/reference/es5ExportDefaultClassDeclaration.types new file mode 100644 index 0000000000000..34fb87fcbb2bb --- /dev/null +++ b/tests/baselines/reference/es5ExportDefaultClassDeclaration.types @@ -0,0 +1,9 @@ +=== tests/cases/compiler/es5ExportDefaultClassDeclaration.ts === + +export default class C { +>C : C + + method() { } +>method : () => void +} + diff --git a/tests/baselines/reference/es5ExportDefaultClassDeclaration2.js b/tests/baselines/reference/es5ExportDefaultClassDeclaration2.js new file mode 100644 index 0000000000000..8c07ff12599cc --- /dev/null +++ b/tests/baselines/reference/es5ExportDefaultClassDeclaration2.js @@ -0,0 +1,52 @@ +//// [es5ExportDefaultClassDeclaration2.ts] + +export default class { + method() { } +} + + +//// [es5ExportDefaultClassDeclaration2.js] +var _default = (function () { + function _default() { + } + _default.prototype.method = function () { + }; + return _default; +})(); +module.exports = _default; + + +//// [es5ExportDefaultClassDeclaration2.d.ts] +export declare class { + method(): void; +} + + +//// [DtsFileErrors] + + +tests/cases/compiler/es5ExportDefaultClassDeclaration2.d.ts(1,1): error TS1128: Declaration or statement expected. +tests/cases/compiler/es5ExportDefaultClassDeclaration2.d.ts(1,8): error TS2304: Cannot find name 'declare'. +tests/cases/compiler/es5ExportDefaultClassDeclaration2.d.ts(1,16): error TS1005: ';' expected. +tests/cases/compiler/es5ExportDefaultClassDeclaration2.d.ts(2,5): error TS2304: Cannot find name 'method'. +tests/cases/compiler/es5ExportDefaultClassDeclaration2.d.ts(2,13): error TS1005: ';' expected. +tests/cases/compiler/es5ExportDefaultClassDeclaration2.d.ts(2,19): error TS1109: Expression expected. + + +==== tests/cases/compiler/es5ExportDefaultClassDeclaration2.d.ts (6 errors) ==== + export declare class { + ~~~~~~ +!!! error TS1128: Declaration or statement expected. + ~~~~~~~ +!!! error TS2304: Cannot find name 'declare'. + ~~~~~ +!!! error TS1005: ';' expected. + method(): void; + ~~~~~~ +!!! error TS2304: Cannot find name 'method'. + ~ +!!! error TS1005: ';' expected. + ~ +!!! error TS1109: Expression expected. + } + \ No newline at end of file diff --git a/tests/baselines/reference/es5ExportDefaultClassDeclaration2.types b/tests/baselines/reference/es5ExportDefaultClassDeclaration2.types new file mode 100644 index 0000000000000..e4c7a59e0e740 --- /dev/null +++ b/tests/baselines/reference/es5ExportDefaultClassDeclaration2.types @@ -0,0 +1,7 @@ +=== tests/cases/compiler/es5ExportDefaultClassDeclaration2.ts === + +export default class { + method() { } +>method : () => void +} + diff --git a/tests/baselines/reference/es5ExportDefaultExpression.js b/tests/baselines/reference/es5ExportDefaultExpression.js new file mode 100644 index 0000000000000..f0c3da6657bdd --- /dev/null +++ b/tests/baselines/reference/es5ExportDefaultExpression.js @@ -0,0 +1,11 @@ +//// [es5ExportDefaultExpression.ts] + +export default (1 + 2); + + +//// [es5ExportDefaultExpression.js] +module.exports = (1 + 2); + + +//// [es5ExportDefaultExpression.d.ts] +export default (1 + 2); diff --git a/tests/baselines/reference/es5ExportDefaultExpression.types b/tests/baselines/reference/es5ExportDefaultExpression.types new file mode 100644 index 0000000000000..2f4e2b5728499 --- /dev/null +++ b/tests/baselines/reference/es5ExportDefaultExpression.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/es5ExportDefaultExpression.ts === + +export default (1 + 2); +>(1 + 2) : number +>1 + 2 : number + diff --git a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.js b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.js new file mode 100644 index 0000000000000..015767435817d --- /dev/null +++ b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.js @@ -0,0 +1,13 @@ +//// [es5ExportDefaultFunctionDeclaration.ts] + +export default function f() { } + + +//// [es5ExportDefaultFunctionDeclaration.js] +function f() { +} +module.exports = f; + + +//// [es5ExportDefaultFunctionDeclaration.d.ts] +export declare function f(): void; diff --git a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.types b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.types new file mode 100644 index 0000000000000..446bd8e2a3144 --- /dev/null +++ b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration.types @@ -0,0 +1,5 @@ +=== tests/cases/compiler/es5ExportDefaultFunctionDeclaration.ts === + +export default function f() { } +>f : () => void + diff --git a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.js b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.js new file mode 100644 index 0000000000000..6a99726655ff6 --- /dev/null +++ b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.js @@ -0,0 +1,26 @@ +//// [es5ExportDefaultFunctionDeclaration2.ts] + +export default function () { } + + +//// [es5ExportDefaultFunctionDeclaration2.js] +function () { +} +module.exports = _default; + + +//// [es5ExportDefaultFunctionDeclaration2.d.ts] +export declare function (): void; + + +//// [DtsFileErrors] + + +tests/cases/compiler/es5ExportDefaultFunctionDeclaration2.d.ts(1,25): error TS1003: Identifier expected. + + +==== tests/cases/compiler/es5ExportDefaultFunctionDeclaration2.d.ts (1 errors) ==== + export declare function (): void; + ~ +!!! error TS1003: Identifier expected. + \ No newline at end of file diff --git a/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.types b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.types new file mode 100644 index 0000000000000..1b9f9d2615114 --- /dev/null +++ b/tests/baselines/reference/es5ExportDefaultFunctionDeclaration2.types @@ -0,0 +1,5 @@ +=== tests/cases/compiler/es5ExportDefaultFunctionDeclaration2.ts === + +No type information for this code.export default function () { } +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es5ExportDefaultIdentifier.errors.txt b/tests/baselines/reference/es5ExportDefaultIdentifier.errors.txt new file mode 100644 index 0000000000000..7a4fdf52e887b --- /dev/null +++ b/tests/baselines/reference/es5ExportDefaultIdentifier.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/es5ExportDefaultIdentifier.ts(4,1): error TS2309: An export assignment cannot be used in a module with other exported elements. + + +==== tests/cases/compiler/es5ExportDefaultIdentifier.ts (1 errors) ==== + + export function f() { } + + export default f; + ~~~~~~~~~~~~~~~~~ +!!! error TS2309: An export assignment cannot be used in a module with other exported elements. + \ No newline at end of file diff --git a/tests/baselines/reference/es5ExportDefaultIdentifier.js b/tests/baselines/reference/es5ExportDefaultIdentifier.js new file mode 100644 index 0000000000000..0c3a601308bf3 --- /dev/null +++ b/tests/baselines/reference/es5ExportDefaultIdentifier.js @@ -0,0 +1,17 @@ +//// [es5ExportDefaultIdentifier.ts] + +export function f() { } + +export default f; + + +//// [es5ExportDefaultIdentifier.js] +function f() { +} +exports.f = f; +module.exports = f; + + +//// [es5ExportDefaultIdentifier.d.ts] +export declare function f(): void; +export default f; diff --git a/tests/baselines/reference/es5ExportEquals.errors.txt b/tests/baselines/reference/es5ExportEquals.errors.txt new file mode 100644 index 0000000000000..89197aca632c0 --- /dev/null +++ b/tests/baselines/reference/es5ExportEquals.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/es5ExportEquals.ts(4,1): error TS2309: An export assignment cannot be used in a module with other exported elements. + + +==== tests/cases/compiler/es5ExportEquals.ts (1 errors) ==== + + export function f() { } + + export = f; + ~~~~~~~~~~~ +!!! error TS2309: An export assignment cannot be used in a module with other exported elements. + \ No newline at end of file diff --git a/tests/baselines/reference/es5ExportEquals.js b/tests/baselines/reference/es5ExportEquals.js new file mode 100644 index 0000000000000..04a34b1e23b0e --- /dev/null +++ b/tests/baselines/reference/es5ExportEquals.js @@ -0,0 +1,17 @@ +//// [es5ExportEquals.ts] + +export function f() { } + +export = f; + + +//// [es5ExportEquals.js] +function f() { +} +exports.f = f; +module.exports = f; + + +//// [es5ExportEquals.d.ts] +export declare function f(): void; +export = f; diff --git a/tests/baselines/reference/es6ExportAssignment.js b/tests/baselines/reference/es6ExportAssignment.js index 4a4e0368bb7e8..113e28108b166 100644 --- a/tests/baselines/reference/es6ExportAssignment.js +++ b/tests/baselines/reference/es6ExportAssignment.js @@ -5,3 +5,4 @@ export = a; //// [es6ExportAssignment.js] var a = 10; +export default a; diff --git a/tests/baselines/reference/es6ExportDefaultClassDeclaration.js b/tests/baselines/reference/es6ExportDefaultClassDeclaration.js new file mode 100644 index 0000000000000..0eacb0a499504 --- /dev/null +++ b/tests/baselines/reference/es6ExportDefaultClassDeclaration.js @@ -0,0 +1,22 @@ +//// [es6ExportDefaultClassDeclaration.ts] + +export default class C { + method() { } +} + + +//// [es6ExportDefaultClassDeclaration.js] +var C = (function () { + function C() { + } + C.prototype.method = function () { + }; + return C; +})(); +export { C }; + + +//// [es6ExportDefaultClassDeclaration.d.ts] +export declare class C { + method(): void; +} diff --git a/tests/baselines/reference/es6ExportDefaultClassDeclaration.types b/tests/baselines/reference/es6ExportDefaultClassDeclaration.types new file mode 100644 index 0000000000000..59e74fc1257c5 --- /dev/null +++ b/tests/baselines/reference/es6ExportDefaultClassDeclaration.types @@ -0,0 +1,9 @@ +=== tests/cases/compiler/es6ExportDefaultClassDeclaration.ts === + +export default class C { +>C : C + + method() { } +>method : () => void +} + diff --git a/tests/baselines/reference/es6ExportDefaultClassDeclaration2.js b/tests/baselines/reference/es6ExportDefaultClassDeclaration2.js new file mode 100644 index 0000000000000..3f7996ad9f60c --- /dev/null +++ b/tests/baselines/reference/es6ExportDefaultClassDeclaration2.js @@ -0,0 +1,52 @@ +//// [es6ExportDefaultClassDeclaration2.ts] + +export default class { + method() { } +} + + +//// [es6ExportDefaultClassDeclaration2.js] +var _default = (function () { + function _default() { + } + _default.prototype.method = function () { + }; + return _default; +})(); +export { }; + + +//// [es6ExportDefaultClassDeclaration2.d.ts] +export declare class { + method(): void; +} + + +//// [DtsFileErrors] + + +tests/cases/compiler/es6ExportDefaultClassDeclaration2.d.ts(1,1): error TS1128: Declaration or statement expected. +tests/cases/compiler/es6ExportDefaultClassDeclaration2.d.ts(1,8): error TS2304: Cannot find name 'declare'. +tests/cases/compiler/es6ExportDefaultClassDeclaration2.d.ts(1,16): error TS1005: ';' expected. +tests/cases/compiler/es6ExportDefaultClassDeclaration2.d.ts(2,5): error TS2304: Cannot find name 'method'. +tests/cases/compiler/es6ExportDefaultClassDeclaration2.d.ts(2,13): error TS1005: ';' expected. +tests/cases/compiler/es6ExportDefaultClassDeclaration2.d.ts(2,19): error TS1109: Expression expected. + + +==== tests/cases/compiler/es6ExportDefaultClassDeclaration2.d.ts (6 errors) ==== + export declare class { + ~~~~~~ +!!! error TS1128: Declaration or statement expected. + ~~~~~~~ +!!! error TS2304: Cannot find name 'declare'. + ~~~~~ +!!! error TS1005: ';' expected. + method(): void; + ~~~~~~ +!!! error TS2304: Cannot find name 'method'. + ~ +!!! error TS1005: ';' expected. + ~ +!!! error TS1109: Expression expected. + } + \ No newline at end of file diff --git a/tests/baselines/reference/es6ExportDefaultClassDeclaration2.types b/tests/baselines/reference/es6ExportDefaultClassDeclaration2.types new file mode 100644 index 0000000000000..513cacf05e4d0 --- /dev/null +++ b/tests/baselines/reference/es6ExportDefaultClassDeclaration2.types @@ -0,0 +1,7 @@ +=== tests/cases/compiler/es6ExportDefaultClassDeclaration2.ts === + +export default class { + method() { } +>method : () => void +} + diff --git a/tests/baselines/reference/es6ExportDefaultExpression.js b/tests/baselines/reference/es6ExportDefaultExpression.js new file mode 100644 index 0000000000000..e0d910437662d --- /dev/null +++ b/tests/baselines/reference/es6ExportDefaultExpression.js @@ -0,0 +1,11 @@ +//// [es6ExportDefaultExpression.ts] + +export default (1 + 2); + + +//// [es6ExportDefaultExpression.js] +export default (1 + 2); + + +//// [es6ExportDefaultExpression.d.ts] +export default (1 + 2); diff --git a/tests/baselines/reference/es6ExportDefaultExpression.types b/tests/baselines/reference/es6ExportDefaultExpression.types new file mode 100644 index 0000000000000..3b056b8d9f920 --- /dev/null +++ b/tests/baselines/reference/es6ExportDefaultExpression.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/es6ExportDefaultExpression.ts === + +export default (1 + 2); +>(1 + 2) : number +>1 + 2 : number + diff --git a/tests/baselines/reference/es6ExportDefaultFunctionDeclaration.js b/tests/baselines/reference/es6ExportDefaultFunctionDeclaration.js new file mode 100644 index 0000000000000..fafc5a114f5a2 --- /dev/null +++ b/tests/baselines/reference/es6ExportDefaultFunctionDeclaration.js @@ -0,0 +1,12 @@ +//// [es6ExportDefaultFunctionDeclaration.ts] + +export default function f() { } + + +//// [es6ExportDefaultFunctionDeclaration.js] +export default function f() { +} + + +//// [es6ExportDefaultFunctionDeclaration.d.ts] +export declare function f(): void; diff --git a/tests/baselines/reference/es6ExportDefaultFunctionDeclaration.types b/tests/baselines/reference/es6ExportDefaultFunctionDeclaration.types new file mode 100644 index 0000000000000..6179bde9613aa --- /dev/null +++ b/tests/baselines/reference/es6ExportDefaultFunctionDeclaration.types @@ -0,0 +1,5 @@ +=== tests/cases/compiler/es6ExportDefaultFunctionDeclaration.ts === + +export default function f() { } +>f : () => void + diff --git a/tests/baselines/reference/es6ExportDefaultFunctionDeclaration2.js b/tests/baselines/reference/es6ExportDefaultFunctionDeclaration2.js new file mode 100644 index 0000000000000..2071e56c539b1 --- /dev/null +++ b/tests/baselines/reference/es6ExportDefaultFunctionDeclaration2.js @@ -0,0 +1,25 @@ +//// [es6ExportDefaultFunctionDeclaration2.ts] + +export default function () { } + + +//// [es6ExportDefaultFunctionDeclaration2.js] +export default function () { +} + + +//// [es6ExportDefaultFunctionDeclaration2.d.ts] +export declare function (): void; + + +//// [DtsFileErrors] + + +tests/cases/compiler/es6ExportDefaultFunctionDeclaration2.d.ts(1,25): error TS1003: Identifier expected. + + +==== tests/cases/compiler/es6ExportDefaultFunctionDeclaration2.d.ts (1 errors) ==== + export declare function (): void; + ~ +!!! error TS1003: Identifier expected. + \ No newline at end of file diff --git a/tests/baselines/reference/es6ExportDefaultFunctionDeclaration2.types b/tests/baselines/reference/es6ExportDefaultFunctionDeclaration2.types new file mode 100644 index 0000000000000..3cb2fc9b1cd0c --- /dev/null +++ b/tests/baselines/reference/es6ExportDefaultFunctionDeclaration2.types @@ -0,0 +1,5 @@ +=== tests/cases/compiler/es6ExportDefaultFunctionDeclaration2.ts === + +No type information for this code.export default function () { } +No type information for this code. +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/es6ExportDefaultIdentifier.js b/tests/baselines/reference/es6ExportDefaultIdentifier.js new file mode 100644 index 0000000000000..5785220dfeefb --- /dev/null +++ b/tests/baselines/reference/es6ExportDefaultIdentifier.js @@ -0,0 +1,16 @@ +//// [es6ExportDefaultIdentifier.ts] + +export function f() { } + +export default f; + + +//// [es6ExportDefaultIdentifier.js] +export function f() { +} +export default f; + + +//// [es6ExportDefaultIdentifier.d.ts] +export declare function f(): void; +export default f; diff --git a/tests/baselines/reference/es6ExportDefaultIdentifier.types b/tests/baselines/reference/es6ExportDefaultIdentifier.types new file mode 100644 index 0000000000000..81dc168efd0cf --- /dev/null +++ b/tests/baselines/reference/es6ExportDefaultIdentifier.types @@ -0,0 +1,8 @@ +=== tests/cases/compiler/es6ExportDefaultIdentifier.ts === + +export function f() { } +>f : () => void + +export default f; +>f : () => void + diff --git a/tests/baselines/reference/es6ExportEquals.errors.txt b/tests/baselines/reference/es6ExportEquals.errors.txt new file mode 100644 index 0000000000000..713517c87af06 --- /dev/null +++ b/tests/baselines/reference/es6ExportEquals.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/es6ExportEquals.ts(4,1): error TS1201: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. + + +==== tests/cases/compiler/es6ExportEquals.ts (1 errors) ==== + + export function f() { } + + export = f; + ~~~~~~~~~~~ +!!! error TS1201: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. + \ No newline at end of file diff --git a/tests/baselines/reference/es6ExportEquals.js b/tests/baselines/reference/es6ExportEquals.js new file mode 100644 index 0000000000000..d51f8740da076 --- /dev/null +++ b/tests/baselines/reference/es6ExportEquals.js @@ -0,0 +1,16 @@ +//// [es6ExportEquals.ts] + +export function f() { } + +export = f; + + +//// [es6ExportEquals.js] +export function f() { +} +export default f; + + +//// [es6ExportEquals.d.ts] +export declare function f(): void; +export = f; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.js index bd6d6013c057b..3c8a4080ba77b 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport1.js @@ -22,6 +22,7 @@ var x1: number = defaultBinding6; //// [es6ImportDefaultBindingFollowedWithNamedImport1_0.js] var a = 10; +export default a; //// [es6ImportDefaultBindingFollowedWithNamedImport1_1.js] import defaultBinding1 from "es6ImportDefaultBindingFollowedWithNamedImport1_0"; var x1 = defaultBinding1; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.js index 9872df4ed5a59..927ed3243e78b 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1.js @@ -11,6 +11,7 @@ var x: number = defaultBinding; //// [es6ImportDefaultBindingFollowedWithNamespaceBinding_0.js] var a = 10; +export default a; //// [es6ImportDefaultBindingFollowedWithNamespaceBinding_1.js] import defaultBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; var x = defaultBinding; diff --git a/tests/baselines/reference/es6ImportEqualsDeclaration.js b/tests/baselines/reference/es6ImportEqualsDeclaration.js index 5195bdc631b30..b8e9777a894c5 100644 --- a/tests/baselines/reference/es6ImportEqualsDeclaration.js +++ b/tests/baselines/reference/es6ImportEqualsDeclaration.js @@ -10,4 +10,5 @@ import a = require("server"); //// [server.js] var a = 10; +export default a; //// [client.js] diff --git a/tests/cases/compiler/es5ExportDefaultClassDeclaration.ts b/tests/cases/compiler/es5ExportDefaultClassDeclaration.ts new file mode 100644 index 0000000000000..bea07832cd564 --- /dev/null +++ b/tests/cases/compiler/es5ExportDefaultClassDeclaration.ts @@ -0,0 +1,7 @@ +// @target: es5 +// @module: commonjs +// @declaration: true + +export default class C { + method() { } +} diff --git a/tests/cases/compiler/es5ExportDefaultClassDeclaration2.ts b/tests/cases/compiler/es5ExportDefaultClassDeclaration2.ts new file mode 100644 index 0000000000000..e7ae24f5d879f --- /dev/null +++ b/tests/cases/compiler/es5ExportDefaultClassDeclaration2.ts @@ -0,0 +1,7 @@ +// @target: es5 +// @module: commonjs +// @declaration: true + +export default class { + method() { } +} diff --git a/tests/cases/compiler/es5ExportDefaultExpression.ts b/tests/cases/compiler/es5ExportDefaultExpression.ts new file mode 100644 index 0000000000000..772998decefa6 --- /dev/null +++ b/tests/cases/compiler/es5ExportDefaultExpression.ts @@ -0,0 +1,5 @@ +// @target: es5 +// @module: commonjs +// @declaration: true + +export default (1 + 2); diff --git a/tests/cases/compiler/es5ExportDefaultFunctionDeclaration.ts b/tests/cases/compiler/es5ExportDefaultFunctionDeclaration.ts new file mode 100644 index 0000000000000..ef9da753ab063 --- /dev/null +++ b/tests/cases/compiler/es5ExportDefaultFunctionDeclaration.ts @@ -0,0 +1,5 @@ +// @target: es5 +// @module: commonjs +// @declaration: true + +export default function f() { } diff --git a/tests/cases/compiler/es5ExportDefaultFunctionDeclaration2.ts b/tests/cases/compiler/es5ExportDefaultFunctionDeclaration2.ts new file mode 100644 index 0000000000000..2b8a99a381780 --- /dev/null +++ b/tests/cases/compiler/es5ExportDefaultFunctionDeclaration2.ts @@ -0,0 +1,5 @@ +// @target: es5 +// @module: commonjs +// @declaration: true + +export default function () { } diff --git a/tests/cases/compiler/es5ExportDefaultIdentifier.ts b/tests/cases/compiler/es5ExportDefaultIdentifier.ts new file mode 100644 index 0000000000000..8f34253208ed7 --- /dev/null +++ b/tests/cases/compiler/es5ExportDefaultIdentifier.ts @@ -0,0 +1,7 @@ +// @target: es5 +// @module: commonjs +// @declaration: true + +export function f() { } + +export default f; diff --git a/tests/cases/compiler/es5ExportEquals.ts b/tests/cases/compiler/es5ExportEquals.ts new file mode 100644 index 0000000000000..5016bdb7b1ba0 --- /dev/null +++ b/tests/cases/compiler/es5ExportEquals.ts @@ -0,0 +1,7 @@ +// @target: es5 +// @module: commonjs +// @declaration: true + +export function f() { } + +export = f; diff --git a/tests/cases/compiler/es6ExportDefaultClassDeclaration.ts b/tests/cases/compiler/es6ExportDefaultClassDeclaration.ts new file mode 100644 index 0000000000000..3d731753ee46d --- /dev/null +++ b/tests/cases/compiler/es6ExportDefaultClassDeclaration.ts @@ -0,0 +1,6 @@ +// @target: es6 +// @declaration: true + +export default class C { + method() { } +} diff --git a/tests/cases/compiler/es6ExportDefaultClassDeclaration2.ts b/tests/cases/compiler/es6ExportDefaultClassDeclaration2.ts new file mode 100644 index 0000000000000..7092d15ef52ec --- /dev/null +++ b/tests/cases/compiler/es6ExportDefaultClassDeclaration2.ts @@ -0,0 +1,6 @@ +// @target: es6 +// @declaration: true + +export default class { + method() { } +} diff --git a/tests/cases/compiler/es6ExportDefaultExpression.ts b/tests/cases/compiler/es6ExportDefaultExpression.ts new file mode 100644 index 0000000000000..ef47621054160 --- /dev/null +++ b/tests/cases/compiler/es6ExportDefaultExpression.ts @@ -0,0 +1,4 @@ +// @target: es6 +// @declaration: true + +export default (1 + 2); diff --git a/tests/cases/compiler/es6ExportDefaultFunctionDeclaration.ts b/tests/cases/compiler/es6ExportDefaultFunctionDeclaration.ts new file mode 100644 index 0000000000000..19984bde2a6f6 --- /dev/null +++ b/tests/cases/compiler/es6ExportDefaultFunctionDeclaration.ts @@ -0,0 +1,4 @@ +// @target: es6 +// @declaration: true + +export default function f() { } diff --git a/tests/cases/compiler/es6ExportDefaultFunctionDeclaration2.ts b/tests/cases/compiler/es6ExportDefaultFunctionDeclaration2.ts new file mode 100644 index 0000000000000..022fbd81233c3 --- /dev/null +++ b/tests/cases/compiler/es6ExportDefaultFunctionDeclaration2.ts @@ -0,0 +1,4 @@ +// @target: es6 +// @declaration: true + +export default function () { } diff --git a/tests/cases/compiler/es6ExportDefaultIdentifier.ts b/tests/cases/compiler/es6ExportDefaultIdentifier.ts new file mode 100644 index 0000000000000..1590677d4ce93 --- /dev/null +++ b/tests/cases/compiler/es6ExportDefaultIdentifier.ts @@ -0,0 +1,6 @@ +// @target: es6 +// @declaration: true + +export function f() { } + +export default f; diff --git a/tests/cases/compiler/es6ExportEquals.ts b/tests/cases/compiler/es6ExportEquals.ts new file mode 100644 index 0000000000000..5dfc98b4c93fa --- /dev/null +++ b/tests/cases/compiler/es6ExportEquals.ts @@ -0,0 +1,6 @@ +// @target: es6 +// @declaration: true + +export function f() { } + +export = f; From b6bbf06e13be21f3bf763882fa411d55ae64cdd7 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 12 Mar 2015 17:21:04 -0700 Subject: [PATCH 050/224] Update error message --- src/compiler/checker.ts | 2 +- src/compiler/diagnosticInformationMap.generated.ts | 2 +- src/compiler/diagnosticMessages.json | 2 +- .../baselines/reference/constDeclarations-access5.errors.txt | 4 ++-- .../baselines/reference/es6ImportEqualsDeclaration.errors.txt | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7911c14e0def3..033121a99bc4e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9904,7 +9904,7 @@ module ts { else { if (languageVersion >= ScriptTarget.ES6) { // Import equals declaration is deprecated in es6 or above - grammarErrorOnNode(node, Diagnostics.Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_import_Asterisk_from_mod_import_a_from_mod_or_import_d_from_mod_instead); + grammarErrorOnNode(node, Diagnostics.Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_or_import_d_from_mod_instead); } } } diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 8e70828e144dd..a27e159cdffa4 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -157,7 +157,7 @@ module ts { Catch_clause_variable_cannot_have_an_initializer: { code: 1197, category: DiagnosticCategory.Error, key: "Catch clause variable cannot have an initializer." }, An_extended_Unicode_escape_value_must_be_between_0x0_and_0x10FFFF_inclusive: { code: 1198, category: DiagnosticCategory.Error, key: "An extended Unicode escape value must be between 0x0 and 0x10FFFF inclusive." }, Unterminated_Unicode_escape_sequence: { code: 1199, category: DiagnosticCategory.Error, key: "Unterminated Unicode escape sequence." }, - Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_import_Asterisk_from_mod_import_a_from_mod_or_import_d_from_mod_instead: { code: 1200, category: DiagnosticCategory.Error, key: "Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * from \"mod\"', 'import {a} from \"mod\"' or 'import d from \"mod\"' instead." }, + Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_or_import_d_from_mod_instead: { code: 1200, category: DiagnosticCategory.Error, key: "Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * as ns from \"mod\"', 'import {a} from \"mod\"' or 'import d from \"mod\"' instead." }, Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_export_default_instead: { code: 1201, category: DiagnosticCategory.Error, key: "Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead." }, Cannot_compile_external_modules_into_amd_or_commonjs_when_targeting_es6_or_higher: { code: 1202, category: DiagnosticCategory.Error, key: "Cannot compile external modules into amd or commonjs when targeting es6 or higher." }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 86fc37fab2f6b..da5a02e4eea57 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -619,7 +619,7 @@ "category": "Error", "code": 1199 }, - "Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * from \"mod\"', 'import {a} from \"mod\"' or 'import d from \"mod\"' instead.": { + "Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * as ns from \"mod\"', 'import {a} from \"mod\"' or 'import d from \"mod\"' instead.": { "category": "Error", "code": 1200 }, diff --git a/tests/baselines/reference/constDeclarations-access5.errors.txt b/tests/baselines/reference/constDeclarations-access5.errors.txt index a5f5b1d0f243e..3d5319f9a2f5d 100644 --- a/tests/baselines/reference/constDeclarations-access5.errors.txt +++ b/tests/baselines/reference/constDeclarations-access5.errors.txt @@ -1,5 +1,5 @@ error TS1202: Cannot compile external modules into amd or commonjs when targeting es6 or higher. -tests/cases/compiler/constDeclarations_access_2.ts(2,1): error TS1200: Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * from "mod"', 'import {a} from "mod"' or 'import d from "mod"' instead. +tests/cases/compiler/constDeclarations_access_2.ts(2,1): error TS1200: Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * as ns from "mod"', 'import {a} from "mod"' or 'import d from "mod"' instead. tests/cases/compiler/constDeclarations_access_2.ts(4,1): error TS2450: Left-hand side of assignment expression cannot be a constant. tests/cases/compiler/constDeclarations_access_2.ts(5,1): error TS2450: Left-hand side of assignment expression cannot be a constant. tests/cases/compiler/constDeclarations_access_2.ts(6,1): error TS2450: Left-hand side of assignment expression cannot be a constant. @@ -25,7 +25,7 @@ tests/cases/compiler/constDeclarations_access_2.ts(24,1): error TS2450: Left-han /// import m = require('constDeclarations_access_1'); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1200: Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * from "mod"', 'import {a} from "mod"' or 'import d from "mod"' instead. +!!! error TS1200: Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * as ns from "mod"', 'import {a} from "mod"' or 'import d from "mod"' instead. // Errors m.x = 1; ~~~ diff --git a/tests/baselines/reference/es6ImportEqualsDeclaration.errors.txt b/tests/baselines/reference/es6ImportEqualsDeclaration.errors.txt index 41c3bc0eef4d4..1f30b7002fa5b 100644 --- a/tests/baselines/reference/es6ImportEqualsDeclaration.errors.txt +++ b/tests/baselines/reference/es6ImportEqualsDeclaration.errors.txt @@ -1,11 +1,11 @@ -tests/cases/compiler/client.ts(1,1): error TS1200: Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * from "mod"', 'import {a} from "mod"' or 'import d from "mod"' instead. +tests/cases/compiler/client.ts(1,1): error TS1200: Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * as ns from "mod"', 'import {a} from "mod"' or 'import d from "mod"' instead. tests/cases/compiler/server.ts(3,1): error TS1201: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. ==== tests/cases/compiler/client.ts (1 errors) ==== import a = require("server"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1200: Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * from "mod"', 'import {a} from "mod"' or 'import d from "mod"' instead. +!!! error TS1200: Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * as ns from "mod"', 'import {a} from "mod"' or 'import d from "mod"' instead. ==== tests/cases/compiler/server.ts (1 errors) ==== var a = 10; From a6a8a9624985bd7d70583154f6dc3f2868c1a0a3 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 12 Mar 2015 22:52:54 -0700 Subject: [PATCH 051/224] Support an optional type annotation on export default statement --- src/compiler/binder.ts | 2 +- src/compiler/checker.ts | 34 ++++++++++++++----- .../diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 7 +++- src/compiler/parser.ts | 12 +++++-- src/compiler/types.ts | 3 +- src/services/breakpoints.ts | 4 +++ .../baselines/reference/APISample_compile.js | 3 +- .../reference/APISample_compile.types | 6 +++- tests/baselines/reference/APISample_linter.js | 3 +- .../reference/APISample_linter.types | 6 +++- .../reference/APISample_transform.js | 3 +- .../reference/APISample_transform.types | 6 +++- .../baselines/reference/APISample_watcher.js | 3 +- .../reference/APISample_watcher.types | 6 +++- .../exportDefaultTypeAnnoation.errors.txt | 8 +++++ .../reference/exportDefaultTypeAnnoation.js | 6 ++++ .../reference/exportDefaultTypeAnnoation2.js | 7 ++++ .../exportDefaultTypeAnnoation2.types | 6 ++++ .../exportDefaultTypeAnnoation3.errors.txt | 21 ++++++++++++ .../reference/exportDefaultTypeAnnoation3.js | 22 ++++++++++++ .../compiler/exportDefaultTypeAnnoation.ts | 4 +++ .../compiler/exportDefaultTypeAnnoation2.ts | 6 ++++ .../compiler/exportDefaultTypeAnnoation3.ts | 15 ++++++++ 24 files changed, 172 insertions(+), 22 deletions(-) create mode 100644 tests/baselines/reference/exportDefaultTypeAnnoation.errors.txt create mode 100644 tests/baselines/reference/exportDefaultTypeAnnoation.js create mode 100644 tests/baselines/reference/exportDefaultTypeAnnoation2.js create mode 100644 tests/baselines/reference/exportDefaultTypeAnnoation2.types create mode 100644 tests/baselines/reference/exportDefaultTypeAnnoation3.errors.txt create mode 100644 tests/baselines/reference/exportDefaultTypeAnnoation3.js create mode 100644 tests/cases/compiler/exportDefaultTypeAnnoation.ts create mode 100644 tests/cases/compiler/exportDefaultTypeAnnoation2.ts create mode 100644 tests/cases/compiler/exportDefaultTypeAnnoation3.ts diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index e325b2033e7ae..af496db7ded6d 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -504,7 +504,7 @@ module ts { bindChildren(node, 0, /*isBlockScopeContainer*/ false); break; case SyntaxKind.ExportAssignment: - if ((node).expression.kind === SyntaxKind.Identifier) { + if ((node).expression && (node).expression.kind === SyntaxKind.Identifier) { // An export default clause with an identifier exports all meanings of that identifier declareSymbol(container.symbol.exports, container.symbol, node, SymbolFlags.Alias, SymbolFlags.AliasExcludes); } diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1500a47f19787..a8713c50afc47 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -566,7 +566,7 @@ module ts { } function getTargetOfExportAssignment(node: ExportAssignment): Symbol { - return resolveEntityName(node.expression, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace); + return node.expression && resolveEntityName(node.expression, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace); } function getTargetOfImportDeclaration(node: Declaration): Symbol { @@ -622,7 +622,7 @@ module ts { if (!links.referenced) { links.referenced = true; var node = getDeclarationOfAliasSymbol(symbol); - if (node.kind === SyntaxKind.ExportAssignment) { + if (node.kind === SyntaxKind.ExportAssignment && (node).expression) { // export default checkExpressionCached((node).expression); } @@ -2061,7 +2061,16 @@ module ts { } // Handle export default expressions if (declaration.kind === SyntaxKind.ExportAssignment) { - return links.type = checkExpression((declaration).expression); + var exportAssignment = (declaration); + if (exportAssignment.expression) { + return links.type = checkExpression(exportAssignment.expression); + } + else if (exportAssignment.type) { + return links.type = getTypeFromTypeNode(exportAssignment.type); + } + else { + return links.type = anyType; + } } // Handle variable, parameter or property links.type = resolvingType; @@ -10039,12 +10048,21 @@ module ts { if (!checkGrammarModifiers(node) && (node.flags & NodeFlags.Modifier)) { grammarErrorOnFirstToken(node, Diagnostics.An_export_assignment_cannot_have_modifiers); } - if (node.expression.kind === SyntaxKind.Identifier) { - markExportAsReferenced(node); + if (node.expression) { + if (node.expression.kind === SyntaxKind.Identifier) { + markExportAsReferenced(node); + } + else { + checkExpressionCached(node.expression); + } } - else { - checkExpressionCached(node.expression); + if (node.type) { + checkSourceElement(node.type); + if (!isInAmbientContext(node)) { + grammarErrorOnFirstToken(node.type, Diagnostics.Type_annotation_on_export_statements_are_only_allowed_in_ambient_module_declarations); + } } + checkExternalModuleExports(container); } @@ -10880,7 +10898,7 @@ module ts { } function generateNameForExportAssignment(node: ExportAssignment) { - if (node.expression.kind !== SyntaxKind.Identifier) { + if (node.expression && node.expression.kind !== SyntaxKind.Identifier) { assignGeneratedName(node, makeUniqueName("default")); } } diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index d40fcd25ce089..5d3bafc45a778 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -157,6 +157,7 @@ module ts { Catch_clause_variable_cannot_have_an_initializer: { code: 1197, category: DiagnosticCategory.Error, key: "Catch clause variable cannot have an initializer." }, An_extended_Unicode_escape_value_must_be_between_0x0_and_0x10FFFF_inclusive: { code: 1198, category: DiagnosticCategory.Error, key: "An extended Unicode escape value must be between 0x0 and 0x10FFFF inclusive." }, Unterminated_Unicode_escape_sequence: { code: 1199, category: DiagnosticCategory.Error, key: "Unterminated Unicode escape sequence." }, + Type_annotation_on_export_statements_are_only_allowed_in_ambient_module_declarations: { code: 1200, category: DiagnosticCategory.Error, key: "Type annotation on export statements are only allowed in ambient module declarations." }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index c4121e92251b2..779e3891766b7 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -617,8 +617,13 @@ }, "Unterminated Unicode escape sequence.": { "category": "Error", - "code": 1199 + "code": 1199 }, + "Type annotation on export statements are only allowed in ambient module declarations.": { + "category": "Error", + "code": 1200 + }, + "Duplicate identifier '{0}'.": { "category": "Error", "code": 2300 diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 6e444eb23c7f5..d76385ff9c0bb 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -282,7 +282,8 @@ module ts { visitNode(cbNode, (node).name); case SyntaxKind.ExportAssignment: return visitNodes(cbNodes, node.modifiers) || - visitNode(cbNode, (node).expression); + visitNode(cbNode, (node).expression) || + visitNode(cbNode, (node).type); case SyntaxKind.TemplateExpression: return visitNode(cbNode, (node).head) || visitNodes(cbNodes, (node).templateSpans); case SyntaxKind.TemplateSpan: @@ -4862,12 +4863,17 @@ module ts { setModifiers(node, modifiers); if (parseOptional(SyntaxKind.EqualsToken)) { node.isExportEquals = true; + node.expression = parseAssignmentExpressionOrHigher(); } else { parseExpected(SyntaxKind.DefaultKeyword); + if (parseOptional(SyntaxKind.ColonToken)) { + node.type = parseType(); + } + else { + node.expression = parseAssignmentExpressionOrHigher(); + } } - //node.exportName = parseIdentifier(); - node.expression = parseAssignmentExpressionOrHigher(); parseSemicolon(); return finishNode(node); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 7301e087ae1b2..a893c36c35992 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -940,7 +940,8 @@ module ts { export interface ExportAssignment extends Declaration, ModuleElement { isExportEquals?: boolean; - expression: Expression; + expression?: Expression; + type?: TypeNode; } export interface FileReference extends TextRange { diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index 1f87ae40745e5..e3d8fa9256eb2 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -173,6 +173,10 @@ module ts.BreakpointResolver { return textSpan(node, (node).expression); case SyntaxKind.ExportAssignment: + if (!(node).expression) { + return undefined; + } + // span on export = id return textSpan(node, (node).expression); diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index 6e6adb2cd4545..abe0700f66b8a 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -762,7 +762,8 @@ declare module "typescript" { type ExportSpecifier = ImportOrExportSpecifier; interface ExportAssignment extends Declaration, ModuleElement { isExportEquals?: boolean; - expression: Expression; + expression?: Expression; + type?: TypeNode; } interface FileReference extends TextRange { fileName: string; diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index 17ce175ebdf82..088424863e813 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -2324,9 +2324,13 @@ declare module "typescript" { isExportEquals?: boolean; >isExportEquals : boolean - expression: Expression; + expression?: Expression; >expression : Expression >Expression : Expression + + type?: TypeNode; +>type : TypeNode +>TypeNode : TypeNode } interface FileReference extends TextRange { >FileReference : FileReference diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index 4f1fc899a8911..f24be65ecb912 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -793,7 +793,8 @@ declare module "typescript" { type ExportSpecifier = ImportOrExportSpecifier; interface ExportAssignment extends Declaration, ModuleElement { isExportEquals?: boolean; - expression: Expression; + expression?: Expression; + type?: TypeNode; } interface FileReference extends TextRange { fileName: string; diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index d1dcad98d85e2..cafe25ed5bc1b 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -2470,9 +2470,13 @@ declare module "typescript" { isExportEquals?: boolean; >isExportEquals : boolean - expression: Expression; + expression?: Expression; >expression : Expression >Expression : Expression + + type?: TypeNode; +>type : TypeNode +>TypeNode : TypeNode } interface FileReference extends TextRange { >FileReference : FileReference diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index 3ef3d7bc0f5f1..2ce87d5c9ef13 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -794,7 +794,8 @@ declare module "typescript" { type ExportSpecifier = ImportOrExportSpecifier; interface ExportAssignment extends Declaration, ModuleElement { isExportEquals?: boolean; - expression: Expression; + expression?: Expression; + type?: TypeNode; } interface FileReference extends TextRange { fileName: string; diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index 4bfac42f571a3..afc61a39fdf10 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -2420,9 +2420,13 @@ declare module "typescript" { isExportEquals?: boolean; >isExportEquals : boolean - expression: Expression; + expression?: Expression; >expression : Expression >Expression : Expression + + type?: TypeNode; +>type : TypeNode +>TypeNode : TypeNode } interface FileReference extends TextRange { >FileReference : FileReference diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index c85be654c8976..b1124e6c64f00 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -831,7 +831,8 @@ declare module "typescript" { type ExportSpecifier = ImportOrExportSpecifier; interface ExportAssignment extends Declaration, ModuleElement { isExportEquals?: boolean; - expression: Expression; + expression?: Expression; + type?: TypeNode; } interface FileReference extends TextRange { fileName: string; diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index e4b53feeac065..36958c9320dcb 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -2593,9 +2593,13 @@ declare module "typescript" { isExportEquals?: boolean; >isExportEquals : boolean - expression: Expression; + expression?: Expression; >expression : Expression >Expression : Expression + + type?: TypeNode; +>type : TypeNode +>TypeNode : TypeNode } interface FileReference extends TextRange { >FileReference : FileReference diff --git a/tests/baselines/reference/exportDefaultTypeAnnoation.errors.txt b/tests/baselines/reference/exportDefaultTypeAnnoation.errors.txt new file mode 100644 index 0000000000000..fa7806a17dd72 --- /dev/null +++ b/tests/baselines/reference/exportDefaultTypeAnnoation.errors.txt @@ -0,0 +1,8 @@ +tests/cases/compiler/exportDefaultTypeAnnoation.ts(2,18): error TS1200: Type annotation on export statements are only allowed in ambient module declarations. + + +==== tests/cases/compiler/exportDefaultTypeAnnoation.ts (1 errors) ==== + + export default : number; + ~~~~~~ +!!! error TS1200: Type annotation on export statements are only allowed in ambient module declarations. \ No newline at end of file diff --git a/tests/baselines/reference/exportDefaultTypeAnnoation.js b/tests/baselines/reference/exportDefaultTypeAnnoation.js new file mode 100644 index 0000000000000..8adf31a5f186a --- /dev/null +++ b/tests/baselines/reference/exportDefaultTypeAnnoation.js @@ -0,0 +1,6 @@ +//// [exportDefaultTypeAnnoation.ts] + +export default : number; + +//// [exportDefaultTypeAnnoation.js] +module.exports = ; diff --git a/tests/baselines/reference/exportDefaultTypeAnnoation2.js b/tests/baselines/reference/exportDefaultTypeAnnoation2.js new file mode 100644 index 0000000000000..2c918954702b6 --- /dev/null +++ b/tests/baselines/reference/exportDefaultTypeAnnoation2.js @@ -0,0 +1,7 @@ +//// [exportDefaultTypeAnnoation2.ts] + +declare module "mod" { + export default : number; +} + +//// [exportDefaultTypeAnnoation2.js] diff --git a/tests/baselines/reference/exportDefaultTypeAnnoation2.types b/tests/baselines/reference/exportDefaultTypeAnnoation2.types new file mode 100644 index 0000000000000..53ca78586ccd5 --- /dev/null +++ b/tests/baselines/reference/exportDefaultTypeAnnoation2.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/exportDefaultTypeAnnoation2.ts === + +No type information for this code.declare module "mod" { +No type information for this code. export default : number; +No type information for this code.} +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/exportDefaultTypeAnnoation3.errors.txt b/tests/baselines/reference/exportDefaultTypeAnnoation3.errors.txt new file mode 100644 index 0000000000000..326713e059e72 --- /dev/null +++ b/tests/baselines/reference/exportDefaultTypeAnnoation3.errors.txt @@ -0,0 +1,21 @@ +tests/cases/compiler/reference1.ts(2,5): error TS2322: Type 'number' is not assignable to type 'string'. +tests/cases/compiler/reference2.ts(2,5): error TS2322: Type 'number' is not assignable to type 'string'. + + +==== tests/cases/compiler/mod.d.ts (0 errors) ==== + + declare module "mod" { + export default : number; + } + +==== tests/cases/compiler/reference1.ts (1 errors) ==== + import d from "mod"; + var s: string = d; // Error + ~ +!!! error TS2322: Type 'number' is not assignable to type 'string'. + +==== tests/cases/compiler/reference2.ts (1 errors) ==== + import { default as d } from "mod"; + var s: string = d; // Error + ~ +!!! error TS2322: Type 'number' is not assignable to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/exportDefaultTypeAnnoation3.js b/tests/baselines/reference/exportDefaultTypeAnnoation3.js new file mode 100644 index 0000000000000..069c8385e77e6 --- /dev/null +++ b/tests/baselines/reference/exportDefaultTypeAnnoation3.js @@ -0,0 +1,22 @@ +//// [tests/cases/compiler/exportDefaultTypeAnnoation3.ts] //// + +//// [mod.d.ts] + +declare module "mod" { + export default : number; +} + +//// [reference1.ts] +import d from "mod"; +var s: string = d; // Error + +//// [reference2.ts] +import { default as d } from "mod"; +var s: string = d; // Error + +//// [reference1.js] +var d = require("mod"); +var s = d; // Error +//// [reference2.js] +var _mod = require("mod"); +var s = _mod.default; // Error diff --git a/tests/cases/compiler/exportDefaultTypeAnnoation.ts b/tests/cases/compiler/exportDefaultTypeAnnoation.ts new file mode 100644 index 0000000000000..d7fd24d5be311 --- /dev/null +++ b/tests/cases/compiler/exportDefaultTypeAnnoation.ts @@ -0,0 +1,4 @@ +// @target: es5 +// @module: commonjs + +export default : number; \ No newline at end of file diff --git a/tests/cases/compiler/exportDefaultTypeAnnoation2.ts b/tests/cases/compiler/exportDefaultTypeAnnoation2.ts new file mode 100644 index 0000000000000..ddb317bd8fcb3 --- /dev/null +++ b/tests/cases/compiler/exportDefaultTypeAnnoation2.ts @@ -0,0 +1,6 @@ +// @target: es5 +// @module: commonjs + +declare module "mod" { + export default : number; +} \ No newline at end of file diff --git a/tests/cases/compiler/exportDefaultTypeAnnoation3.ts b/tests/cases/compiler/exportDefaultTypeAnnoation3.ts new file mode 100644 index 0000000000000..88a45de2d326f --- /dev/null +++ b/tests/cases/compiler/exportDefaultTypeAnnoation3.ts @@ -0,0 +1,15 @@ +// @target: es5 +// @module: commonjs + +// @fileName: mod.d.ts +declare module "mod" { + export default : number; +} + +// @fileName: reference1.ts +import d from "mod"; +var s: string = d; // Error + +// @fileName: reference2.ts +import { default as d } from "mod"; +var s: string = d; // Error \ No newline at end of file From 0675a92accb49b217b33941ca17f030a6d2bf6db Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Fri, 13 Mar 2015 14:34:10 -0700 Subject: [PATCH 052/224] consider binding elements as always initialized with doing shadow check --- src/compiler/checker.ts | 71 +++++++++++-------- ...ngViaLocalValueOrBindingElement.errors.txt | 28 ++++++++ .../shadowingViaLocalValueOrBindingElement.js | 31 ++++++++ .../shadowingViaLocalValueOrBindingElement.ts | 10 +++ 4 files changed, 110 insertions(+), 30 deletions(-) create mode 100644 tests/baselines/reference/shadowingViaLocalValueOrBindingElement.errors.txt create mode 100644 tests/baselines/reference/shadowingViaLocalValueOrBindingElement.js create mode 100644 tests/cases/compiler/shadowingViaLocalValueOrBindingElement.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 782ffccc0edf8..000ee35d21f42 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8609,36 +8609,47 @@ module ts { // const x = 0; // localDeclarationSymbol obtained after name resolution will correspond to this declaration // var x = 0; // symbol for this declaration will be 'symbol' // } - if (node.initializer && (getCombinedNodeFlags(node) & NodeFlags.BlockScoped) === 0) { - var symbol = getSymbolOfNode(node); - if (symbol.flags & SymbolFlags.FunctionScopedVariable) { - var localDeclarationSymbol = resolveName(node, (node.name).text, SymbolFlags.Variable, /*nodeNotFoundErrorMessage*/ undefined, /*nameArg*/ undefined); - if (localDeclarationSymbol && - localDeclarationSymbol !== symbol && - localDeclarationSymbol.flags & SymbolFlags.BlockScopedVariable) { - if (getDeclarationFlagsFromSymbol(localDeclarationSymbol) & NodeFlags.BlockScoped) { - - var varDeclList = getAncestor(localDeclarationSymbol.valueDeclaration, SyntaxKind.VariableDeclarationList); - var container = - varDeclList.parent.kind === SyntaxKind.VariableStatement && - varDeclList.parent.parent; - - // names of block-scoped and function scoped variables can collide only - // if block scoped variable is defined in the function\module\source file scope (because of variable hoisting) - var namesShareScope = - container && - (container.kind === SyntaxKind.Block && isFunctionLike(container.parent) || - (container.kind === SyntaxKind.ModuleBlock && container.kind === SyntaxKind.ModuleDeclaration) || - container.kind === SyntaxKind.SourceFile); - - // here we know that function scoped variable is shadowed by block scoped one - // if they are defined in the same scope - binder has already reported redeclaration error - // otherwise if variable has an initializer - show error that initialization will fail - // since LHS will be block scoped name instead of function scoped - if (!namesShareScope) { - var name = symbolToString(localDeclarationSymbol); - error(node, Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name, name); - } + + // skip block-scoped variables and parameters + if ((getCombinedNodeFlags(node) & NodeFlags.BlockScoped) !== 0 || isParameterDeclaration(node)) { + return; + } + + // skip variable declarations that don't have initializers + // NOTE: in ES6 spec initializer is required in variable declarations where name is binding pattern + // so we'll always treat binding elements as initialized + if (node.kind === SyntaxKind.VariableDeclaration && !node.initializer) { + return; + } + + var symbol = getSymbolOfNode(node); + if (symbol.flags & SymbolFlags.FunctionScopedVariable) { + var localDeclarationSymbol = resolveName(node, (node.name).text, SymbolFlags.Variable, /*nodeNotFoundErrorMessage*/ undefined, /*nameArg*/ undefined); + if (localDeclarationSymbol && + localDeclarationSymbol !== symbol && + localDeclarationSymbol.flags & SymbolFlags.BlockScopedVariable) { + if (getDeclarationFlagsFromSymbol(localDeclarationSymbol) & NodeFlags.BlockScoped) { + + var varDeclList = getAncestor(localDeclarationSymbol.valueDeclaration, SyntaxKind.VariableDeclarationList); + var container = + varDeclList.parent.kind === SyntaxKind.VariableStatement && + varDeclList.parent.parent; + + // names of block-scoped and function scoped variables can collide only + // if block scoped variable is defined in the function\module\source file scope (because of variable hoisting) + var namesShareScope = + container && + (container.kind === SyntaxKind.Block && isFunctionLike(container.parent) || + (container.kind === SyntaxKind.ModuleBlock && container.kind === SyntaxKind.ModuleDeclaration) || + container.kind === SyntaxKind.SourceFile); + + // here we know that function scoped variable is shadowed by block scoped one + // if they are defined in the same scope - binder has already reported redeclaration error + // otherwise if variable has an initializer - show error that initialization will fail + // since LHS will be block scoped name instead of function scoped + if (!namesShareScope) { + var name = symbolToString(localDeclarationSymbol); + error(node, Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name, name); } } } diff --git a/tests/baselines/reference/shadowingViaLocalValueOrBindingElement.errors.txt b/tests/baselines/reference/shadowingViaLocalValueOrBindingElement.errors.txt new file mode 100644 index 0000000000000..663f83c1ffbfc --- /dev/null +++ b/tests/baselines/reference/shadowingViaLocalValueOrBindingElement.errors.txt @@ -0,0 +1,28 @@ +tests/cases/compiler/shadowingViaLocalValueOrBindingElement.ts(4,13): error TS2481: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'. +tests/cases/compiler/shadowingViaLocalValueOrBindingElement.ts(5,15): error TS2481: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'. +tests/cases/compiler/shadowingViaLocalValueOrBindingElement.ts(6,18): error TS2481: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'. +tests/cases/compiler/shadowingViaLocalValueOrBindingElement.ts(7,15): error TS2481: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'. +tests/cases/compiler/shadowingViaLocalValueOrBindingElement.ts(8,18): error TS2481: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'. + + +==== tests/cases/compiler/shadowingViaLocalValueOrBindingElement.ts (5 errors) ==== + if (true) { + let x; + if (true) { + var x = 0; // Error + ~ +!!! error TS2481: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'. + var { x = 0 } = { x: 0 }; // Error + ~ +!!! error TS2481: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'. + var { x: x = 0 } = { x: 0 }; // Error + ~ +!!! error TS2481: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'. + var { x } = { x: 0 }; // No error, even though the let x is being initialized + ~ +!!! error TS2481: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'. + var { x: x } = { x: 0 }; // No error, even though the let x is being initialized + ~ +!!! error TS2481: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/shadowingViaLocalValueOrBindingElement.js b/tests/baselines/reference/shadowingViaLocalValueOrBindingElement.js new file mode 100644 index 0000000000000..8d6319f5ea716 --- /dev/null +++ b/tests/baselines/reference/shadowingViaLocalValueOrBindingElement.js @@ -0,0 +1,31 @@ +//// [shadowingViaLocalValueOrBindingElement.ts] +if (true) { + let x; + if (true) { + var x = 0; // Error + var { x = 0 } = { x: 0 }; // Error + var { x: x = 0 } = { x: 0 }; // Error + var { x } = { x: 0 }; // No error, even though the let x is being initialized + var { x: x } = { x: 0 }; // No error, even though the let x is being initialized + } +} + +//// [shadowingViaLocalValueOrBindingElement.js] +if (true) { + var _x; + if (true) { + var x = 0; // Error + var _a = ({ + _x: 0 + }).x, x = _a === void 0 ? 0 : _a; // Error + var _b = ({ + _x: 0 + }).x, x = _b === void 0 ? 0 : _b; // Error + var x = ({ + _x: 0 + }).x; // No error, even though the let x is being initialized + var x = ({ + _x: 0 + }).x; // No error, even though the let x is being initialized + } +} diff --git a/tests/cases/compiler/shadowingViaLocalValueOrBindingElement.ts b/tests/cases/compiler/shadowingViaLocalValueOrBindingElement.ts new file mode 100644 index 0000000000000..9afeb79aa791e --- /dev/null +++ b/tests/cases/compiler/shadowingViaLocalValueOrBindingElement.ts @@ -0,0 +1,10 @@ +if (true) { + let x; + if (true) { + var x = 0; // Error + var { x = 0 } = { x: 0 }; // Error + var { x: x = 0 } = { x: 0 }; // Error + var { x } = { x: 0 }; // No error, even though the let x is being initialized + var { x: x } = { x: 0 }; // No error, even though the let x is being initialized + } +} \ No newline at end of file From c4b0302acf7517e7955bcc7d9f2c43b9bd51af8c Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 13 Mar 2015 14:49:32 -0700 Subject: [PATCH 053/224] Clean up diagnostic timers and -diagnostic output --- src/compiler/program.ts | 46 +++++++++++++++++++++++------------------ src/compiler/tsc.ts | 39 ++++++++++++++-------------------- 2 files changed, 41 insertions(+), 44 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 9b933cacf7420..eda6833e77187 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -2,8 +2,10 @@ /// module ts { + /* @internal */ export var programTime = 0; /* @internal */ export var emitTime = 0; /* @internal */ export var ioReadTime = 0; + /* @internal */ export var ioWriteTime = 0; /** The version of the TypeScript compiler release */ export var version = "1.5.0.0"; @@ -35,33 +37,34 @@ module ts { } text = ""; } - return text !== undefined ? createSourceFile(fileName, text, languageVersion) : undefined; } - function writeFile(fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void) { - function directoryExists(directoryPath: string): boolean { - if (hasProperty(existingDirectories, directoryPath)) { - return true; - } - if (sys.directoryExists(directoryPath)) { - existingDirectories[directoryPath] = true; - return true; - } - return false; + function directoryExists(directoryPath: string): boolean { + if (hasProperty(existingDirectories, directoryPath)) { + return true; + } + if (sys.directoryExists(directoryPath)) { + existingDirectories[directoryPath] = true; + return true; } + return false; + } - function ensureDirectoriesExist(directoryPath: string) { - if (directoryPath.length > getRootLength(directoryPath) && !directoryExists(directoryPath)) { - var parentDirectory = getDirectoryPath(directoryPath); - ensureDirectoriesExist(parentDirectory); - sys.createDirectory(directoryPath); - } + function ensureDirectoriesExist(directoryPath: string) { + if (directoryPath.length > getRootLength(directoryPath) && !directoryExists(directoryPath)) { + var parentDirectory = getDirectoryPath(directoryPath); + ensureDirectoriesExist(parentDirectory); + sys.createDirectory(directoryPath); } + } + function writeFile(fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void) { try { + var start = new Date().getTime(); ensureDirectoriesExist(getDirectoryPath(normalizePath(fileName))); sys.writeFile(fileName, data, writeByteOrderMark); + ioWriteTime += new Date().getTime() - start; } catch (e) { if (onError) { @@ -119,16 +122,19 @@ module ts { var diagnostics = createDiagnosticCollection(); var seenNoDefaultLib = options.noLib; var commonSourceDirectory: string; + var diagnosticsProducingTypeChecker: TypeChecker; + var noDiagnosticsTypeChecker: TypeChecker; + host = host || createCompilerHost(options); + var start = new Date().getTime(); forEach(rootNames, name => processRootFile(name, false)); if (!seenNoDefaultLib) { processRootFile(host.getDefaultLibFileName(options), true); } - verifyCompilerOptions(); + programTime += new Date().getTime() - start; - var diagnosticsProducingTypeChecker: TypeChecker; - var noDiagnosticsTypeChecker: TypeChecker; + verifyCompilerOptions(); program = { getSourceFile: getSourceFile, diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index e9c5e17c751ee..3f82d6c8cf509 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -320,22 +320,16 @@ module ts { } function compile(fileNames: string[], compilerOptions: CompilerOptions, compilerHost: CompilerHost) { - ts.ioReadTime = 0; - ts.parseTime = 0; - ts.bindTime = 0; - ts.checkTime = 0; - ts.emitTime = 0; - - var start = new Date().getTime(); + ioReadTime = 0; + ioWriteTime = 0; + programTime = 0; + bindTime = 0; + checkTime = 0; + emitTime = 0; var program = createProgram(fileNames, compilerOptions, compilerHost); - var programTime = new Date().getTime() - start; - var exitStatus = compileProgram(); - var end = new Date().getTime() - start; - var compileTime = end - programTime; - if (compilerOptions.listFiles) { forEach(program.getSourceFiles(), file => { sys.write(file.fileName + sys.newLine); @@ -356,19 +350,16 @@ module ts { } // Individual component times. - // Note: we output 'programTime' as parseTime to match the tsc 1.3 behavior. tsc 1.3 - // measured parse time along with read IO as a single counter. We preserve that - // behavior so we can accurately compare times. For actual parse times (in isolation) - // is reported below. + // Note: To match the behavior of previous versions of the compiler, the reported parse time includes + // I/O read time and processing time for triple-slash references and module imports, and the reported + // emit time includes I/O write time. We preserve this behavior so we can accurately compare times. + reportTimeStatistic("I/O read", ioReadTime); + reportTimeStatistic("I/O write", ioWriteTime); reportTimeStatistic("Parse time", programTime); - reportTimeStatistic("Bind time", ts.bindTime); - reportTimeStatistic("Check time", ts.checkTime); - reportTimeStatistic("Emit time", ts.emitTime); - - reportTimeStatistic("Parse time w/o IO", ts.parseTime); - reportTimeStatistic("IO read", ts.ioReadTime); - reportTimeStatistic("Compile time", compileTime); - reportTimeStatistic("Total time", end); + reportTimeStatistic("Bind time", bindTime); + reportTimeStatistic("Check time", checkTime); + reportTimeStatistic("Emit time", emitTime); + reportTimeStatistic("Total time", programTime + bindTime + checkTime + emitTime); } return { program, exitStatus }; From 99a6f2b194a92bc3a0753b0bc5ce01c4c4638e03 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 13 Mar 2015 14:49:54 -0700 Subject: [PATCH 054/224] Removing unused function from emitter --- src/compiler/emitter.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 8947314a6f685..a592c033c22ef 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4999,14 +4999,6 @@ module ts { } } - function getFirstExportAssignment(sourceFile: SourceFile) { - return forEach(sourceFile.statements, node => { - if (node.kind === SyntaxKind.ExportAssignment) { - return node; - } - }); - } - function sortAMDModules(amdModules: {name: string; path: string}[]) { // AMD modules with declared variable names go first return amdModules.sort((moduleA, moduleB) => { From d163205da6281cb840312b7c8ee9d5a75512d375 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Fri, 13 Mar 2015 15:59:22 -0700 Subject: [PATCH 055/224] accepted baselines --- .../shadowingViaLocalValueOrBindingElement.errors.txt | 4 ++-- .../reference/shadowingViaLocalValueOrBindingElement.js | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/baselines/reference/shadowingViaLocalValueOrBindingElement.errors.txt b/tests/baselines/reference/shadowingViaLocalValueOrBindingElement.errors.txt index 663f83c1ffbfc..4fc1d47c3837f 100644 --- a/tests/baselines/reference/shadowingViaLocalValueOrBindingElement.errors.txt +++ b/tests/baselines/reference/shadowingViaLocalValueOrBindingElement.errors.txt @@ -18,10 +18,10 @@ tests/cases/compiler/shadowingViaLocalValueOrBindingElement.ts(8,18): error TS24 var { x: x = 0 } = { x: 0 }; // Error ~ !!! error TS2481: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'. - var { x } = { x: 0 }; // No error, even though the let x is being initialized + var { x } = { x: 0 }; // Error ~ !!! error TS2481: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'. - var { x: x } = { x: 0 }; // No error, even though the let x is being initialized + var { x: x } = { x: 0 }; // Error ~ !!! error TS2481: Cannot initialize outer scoped variable 'x' in the same scope as block scoped declaration 'x'. } diff --git a/tests/baselines/reference/shadowingViaLocalValueOrBindingElement.js b/tests/baselines/reference/shadowingViaLocalValueOrBindingElement.js index 8d6319f5ea716..76c4a7ac3a646 100644 --- a/tests/baselines/reference/shadowingViaLocalValueOrBindingElement.js +++ b/tests/baselines/reference/shadowingViaLocalValueOrBindingElement.js @@ -5,8 +5,8 @@ if (true) { var x = 0; // Error var { x = 0 } = { x: 0 }; // Error var { x: x = 0 } = { x: 0 }; // Error - var { x } = { x: 0 }; // No error, even though the let x is being initialized - var { x: x } = { x: 0 }; // No error, even though the let x is being initialized + var { x } = { x: 0 }; // Error + var { x: x } = { x: 0 }; // Error } } @@ -23,9 +23,9 @@ if (true) { }).x, x = _b === void 0 ? 0 : _b; // Error var x = ({ _x: 0 - }).x; // No error, even though the let x is being initialized + }).x; // Error var x = ({ _x: 0 - }).x; // No error, even though the let x is being initialized + }).x; // Error } } From f6de919407e5134f68dd7a450f77cb2adc3db121 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Fri, 13 Mar 2015 15:35:58 -0700 Subject: [PATCH 056/224] Add assert in reportNoCommonSupertypeError --- src/compiler/checker.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0dacb20ece41c..957a3e3630aef 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4379,6 +4379,8 @@ module ts { } } + Debug.assert(!!downfallType, "If there is no common supertype, each type should have a downfallType"); + if (score > bestSupertypeScore) { bestSupertype = types[i]; bestSupertypeDownfallType = downfallType; From df6f856ad530e553696e6ba5c0abe33e8752baa6 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Fri, 13 Mar 2015 16:41:26 -0700 Subject: [PATCH 057/224] Persist inference context object throughout the signature, and add isFixed property --- src/compiler/checker.ts | 46 +++++++++++-------- src/compiler/types.ts | 2 + .../baselines/reference/APISample_compile.js | 1 + .../reference/APISample_compile.types | 3 ++ tests/baselines/reference/APISample_linter.js | 1 + .../reference/APISample_linter.types | 3 ++ .../reference/APISample_transform.js | 1 + .../reference/APISample_transform.types | 3 ++ .../baselines/reference/APISample_watcher.js | 1 + .../reference/APISample_watcher.types | 3 ++ 10 files changed, 44 insertions(+), 20 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 957a3e3630aef..44178aed74b23 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3505,6 +3505,7 @@ module ts { return t => { for (let i = 0; i < context.typeParameters.length; i++) { if (t === context.typeParameters[i]) { + context.inferences[i].isFixed = true; return getInferredType(context, i); } } @@ -4563,12 +4564,11 @@ module ts { function createInferenceContext(typeParameters: TypeParameter[], inferUnionTypes: boolean): InferenceContext { let inferences: TypeInferences[] = []; for (let unused of typeParameters) { - inferences.push({ primary: undefined, secondary: undefined }); + inferences.push({ primary: undefined, secondary: undefined, isFixed: false }); } return { typeParameters: typeParameters, inferUnionTypes: inferUnionTypes, - inferenceCount: 0, inferences: inferences, inferredTypes: new Array(typeParameters.length), }; @@ -4615,11 +4615,13 @@ module ts { for (let i = 0; i < typeParameters.length; i++) { if (target === typeParameters[i]) { let inferences = context.inferences[i]; - let candidates = inferiority ? - inferences.secondary || (inferences.secondary = []) : - inferences.primary || (inferences.primary = []); - if (!contains(candidates, source)) candidates.push(source); - break; + if (!inferences.isFixed) { + let candidates = inferiority ? + inferences.secondary || (inferences.secondary = []) : + inferences.primary || (inferences.primary = []); + if (!contains(candidates, source)) candidates.push(source); + } + return; } } } @@ -6336,11 +6338,15 @@ module ts { return getSignatureInstantiation(signature, getInferredTypes(context)); } - function inferTypeArguments(signature: Signature, args: Expression[], excludeArgument: boolean[]): InferenceContext { + function inferTypeArguments(signature: Signature, args: Expression[], excludeArgument: boolean[], context: InferenceContext): void { let typeParameters = signature.typeParameters; - let context = createInferenceContext(typeParameters, /*inferUnionTypes*/ false); let inferenceMapper = createInferenceMapper(context); + // Clear out all the inference results from the last time inferTypeArguments was called on this context + for (let i = 0; i < typeParameters.length; i++) { + context.inferredTypes[i] = undefined; + } + // We perform two passes over the arguments. In the first pass we infer from all arguments, but use // wildcards for all context sensitive function expressions. for (let i = 0; i < args.length; i++) { @@ -6385,8 +6391,6 @@ module ts { inferredTypes[i] = unknownType; } } - - return context; } function checkTypeArguments(signature: Signature, typeArguments: TypeNode[], typeArgumentResultTypes: Type[], reportErrors: boolean): boolean { @@ -6620,15 +6624,17 @@ module ts { return resolveErrorCall(node); function chooseOverload(candidates: Signature[], relation: Map) { - for (let current of candidates) { - if (!hasCorrectArity(node, args, current)) { + for (let originalCandidate of candidates) { + if (!hasCorrectArity(node, args, originalCandidate)) { continue; } - - let originalCandidate = current; - let inferenceResult: InferenceContext; + let candidate: Signature; let typeArgumentsAreValid: boolean; + let inferenceContext = originalCandidate.typeParameters + ? createInferenceContext(originalCandidate.typeParameters, /*inferUnionTypes*/ false) + : undefined; + while (true) { candidate = originalCandidate; if (candidate.typeParameters) { @@ -6638,9 +6644,9 @@ module ts { typeArgumentsAreValid = checkTypeArguments(candidate, typeArguments, typeArgumentTypes, /*reportErrors*/ false) } else { - inferenceResult = inferTypeArguments(candidate, args, excludeArgument); - typeArgumentsAreValid = inferenceResult.failedTypeParameterIndex < 0; - typeArgumentTypes = inferenceResult.inferredTypes; + inferTypeArguments(candidate, args, excludeArgument, inferenceContext); + typeArgumentsAreValid = inferenceContext.failedTypeParameterIndex < 0; + typeArgumentTypes = inferenceContext.inferredTypes; } if (!typeArgumentsAreValid) { break; @@ -6670,7 +6676,7 @@ module ts { else { candidateForTypeArgumentError = originalCandidate; if (!typeArguments) { - resultOfFailedInference = inferenceResult; + resultOfFailedInference = inferenceContext; } } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index c43591911abd4..5880dfdce92ce 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1485,6 +1485,8 @@ module ts { export interface TypeInferences { primary: Type[]; // Inferences made directly to a type parameter secondary: Type[]; // Inferences made to a type parameter in a union type + isFixed: boolean; // Whether the type parameter is fixed, as defined in section 4.12.2 of the TypeScript spec + // If a type parameter is fixed, no more inferences can be made for the type parameter } export interface InferenceContext { diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index 985718231810c..d08d0b3fcc276 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -1175,6 +1175,7 @@ declare module "typescript" { interface TypeInferences { primary: Type[]; secondary: Type[]; + isFixed: boolean; } interface InferenceContext { typeParameters: TypeParameter[]; diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index 087c0389d0fce..df0c57444b0a8 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -3767,6 +3767,9 @@ declare module "typescript" { secondary: Type[]; >secondary : Type[] >Type : Type + + isFixed: boolean; +>isFixed : boolean } interface InferenceContext { >InferenceContext : InferenceContext diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index d43d622007210..fb390d78f8f2e 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -1206,6 +1206,7 @@ declare module "typescript" { interface TypeInferences { primary: Type[]; secondary: Type[]; + isFixed: boolean; } interface InferenceContext { typeParameters: TypeParameter[]; diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index 14eb2936242bd..90360b5fe6122 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -3913,6 +3913,9 @@ declare module "typescript" { secondary: Type[]; >secondary : Type[] >Type : Type + + isFixed: boolean; +>isFixed : boolean } interface InferenceContext { >InferenceContext : InferenceContext diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index bfe62135a0db3..96b54ccd91730 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -1207,6 +1207,7 @@ declare module "typescript" { interface TypeInferences { primary: Type[]; secondary: Type[]; + isFixed: boolean; } interface InferenceContext { typeParameters: TypeParameter[]; diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index baa497c95fa50..999c81af401e2 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -3863,6 +3863,9 @@ declare module "typescript" { secondary: Type[]; >secondary : Type[] >Type : Type + + isFixed: boolean; +>isFixed : boolean } interface InferenceContext { >InferenceContext : InferenceContext diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index ee1fd06251576..8a3d2065a23b4 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -1244,6 +1244,7 @@ declare module "typescript" { interface TypeInferences { primary: Type[]; secondary: Type[]; + isFixed: boolean; } interface InferenceContext { typeParameters: TypeParameter[]; diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index a8b534439d546..f66c818c53dc4 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -4036,6 +4036,9 @@ declare module "typescript" { secondary: Type[]; >secondary : Type[] >Type : Type + + isFixed: boolean; +>isFixed : boolean } interface InferenceContext { >InferenceContext : InferenceContext From 495caf0f6728e881e67b7fbe077a2c782b8e3f4d Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Fri, 13 Mar 2015 17:03:13 -0700 Subject: [PATCH 058/224] Optimize the clearing of inferredTypes --- src/compiler/checker.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 44178aed74b23..0d29e928e31ff 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6344,7 +6344,11 @@ module ts { // Clear out all the inference results from the last time inferTypeArguments was called on this context for (let i = 0; i < typeParameters.length; i++) { - context.inferredTypes[i] = undefined; + // As an optimization, we don't have to clear (and later recompute) inferred types + // for type parameters that have already been fixed on the previous call to inferTypeArguments + if (!context.inferences[i].isFixed) { + context.inferredTypes[i] = undefined; + } } // We perform two passes over the arguments. In the first pass we infer from all arguments, but use From a0b96079c226f949256de391dac1cb03343c6d22 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Fri, 13 Mar 2015 17:43:37 -0700 Subject: [PATCH 059/224] Get rid of inferenceFailureType, just set the failedTypeParameterIndex directly --- src/compiler/checker.ts | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0d29e928e31ff..21707940a5aeb 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -79,8 +79,7 @@ module ts { let emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); let anyFunctionType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); let noConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); - let inferenceFailureType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); - + let anySignature = createSignature(undefined, undefined, emptyArray, anyType, 0, false, false); let unknownSignature = createSignature(undefined, undefined, emptyArray, unknownType, 0, false, false); @@ -4727,21 +4726,32 @@ module ts { function getInferredType(context: InferenceContext, index: number): Type { let inferredType = context.inferredTypes[index]; + let inferenceSucceeded: boolean; if (!inferredType) { let inferences = getInferenceCandidates(context, index); if (inferences.length) { // Infer widened union or supertype, or the undefined type for no common supertype let unionOrSuperType = context.inferUnionTypes ? getUnionType(inferences) : getCommonSupertype(inferences); - inferredType = unionOrSuperType ? getWidenedType(unionOrSuperType) : inferenceFailureType; + inferredType = unionOrSuperType ? getWidenedType(unionOrSuperType) : unknownType; + inferenceSucceeded = !!unionOrSuperType; } else { // Infer the empty object type when no inferences were made inferredType = emptyObjectType; + inferenceSucceeded = true; } - if (inferredType !== inferenceFailureType) { + + // Only do the constraint check if inference succeeded (to prevent cascading errors) + if (inferenceSucceeded) { let constraint = getConstraintOfTypeParameter(context.typeParameters[index]); inferredType = constraint && !isTypeAssignableTo(inferredType, constraint) ? constraint : inferredType; } + // If inference failed, it is necessary to record the index of the failed type parameter (the one we are on). + // It might be that inference has already failed on a later type parameter on a previous call to inferTypeArguments. + // So if this failure is on preceding type parameter, this type parameter is the new failure index. + else if (context.failedTypeParameterIndex === undefined || context.failedTypeParameterIndex > index) { + context.failedTypeParameterIndex = index; + } context.inferredTypes[index] = inferredType; } return inferredType; @@ -6350,6 +6360,9 @@ module ts { context.inferredTypes[i] = undefined; } } + if (context.failedTypeParameterIndex >= 0 && !context.inferences[context.failedTypeParameterIndex].isFixed) { + context.failedTypeParameterIndex = undefined; + } // We perform two passes over the arguments. In the first pass we infer from all arguments, but use // wildcards for all context sensitive function expressions. @@ -6385,16 +6398,7 @@ module ts { } } - let inferredTypes = getInferredTypes(context); - // Inference has failed if the inferenceFailureType type is in list of inferences - context.failedTypeParameterIndex = indexOf(inferredTypes, inferenceFailureType); - - // Wipe out the inferenceFailureType from the array so that error recovery can work properly - for (let i = 0; i < inferredTypes.length; i++) { - if (inferredTypes[i] === inferenceFailureType) { - inferredTypes[i] = unknownType; - } - } + getInferredTypes(context); } function checkTypeArguments(signature: Signature, typeArguments: TypeNode[], typeArgumentResultTypes: Type[], reportErrors: boolean): boolean { @@ -6649,7 +6653,7 @@ module ts { } else { inferTypeArguments(candidate, args, excludeArgument, inferenceContext); - typeArgumentsAreValid = inferenceContext.failedTypeParameterIndex < 0; + typeArgumentsAreValid = inferenceContext.failedTypeParameterIndex === undefined; typeArgumentTypes = inferenceContext.inferredTypes; } if (!typeArgumentsAreValid) { From a29b6fe8c759fd673f5199997af40cea5725a977 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Fri, 13 Mar 2015 18:22:30 -0700 Subject: [PATCH 060/224] Add tests for type parameter fixing --- .../typeParameterFixingWithConstraints.js | 21 ++++++ .../typeParameterFixingWithConstraints.types | 44 ++++++++++++ ...eterFixingWithContextSensitiveArguments.js | 28 ++++++++ ...rFixingWithContextSensitiveArguments.types | 71 +++++++++++++++++++ ...gWithContextSensitiveArguments2.errors.txt | 15 ++++ ...terFixingWithContextSensitiveArguments2.js | 22 ++++++ ...gWithContextSensitiveArguments3.errors.txt | 15 ++++ ...terFixingWithContextSensitiveArguments3.js | 22 ++++++ ...terFixingWithContextSensitiveArguments4.js | 22 ++++++ ...FixingWithContextSensitiveArguments4.types | 55 ++++++++++++++ ...terFixingWithContextSensitiveArguments5.js | 22 ++++++ ...FixingWithContextSensitiveArguments5.types | 56 +++++++++++++++ .../typeParameterFixingWithConstraints.ts | 10 +++ ...eterFixingWithContextSensitiveArguments.ts | 9 +++ ...terFixingWithContextSensitiveArguments2.ts | 7 ++ ...terFixingWithContextSensitiveArguments3.ts | 7 ++ ...terFixingWithContextSensitiveArguments4.ts | 7 ++ ...terFixingWithContextSensitiveArguments5.ts | 7 ++ 18 files changed, 440 insertions(+) create mode 100644 tests/baselines/reference/typeParameterFixingWithConstraints.js create mode 100644 tests/baselines/reference/typeParameterFixingWithConstraints.types create mode 100644 tests/baselines/reference/typeParameterFixingWithContextSensitiveArguments.js create mode 100644 tests/baselines/reference/typeParameterFixingWithContextSensitiveArguments.types create mode 100644 tests/baselines/reference/typeParameterFixingWithContextSensitiveArguments2.errors.txt create mode 100644 tests/baselines/reference/typeParameterFixingWithContextSensitiveArguments2.js create mode 100644 tests/baselines/reference/typeParameterFixingWithContextSensitiveArguments3.errors.txt create mode 100644 tests/baselines/reference/typeParameterFixingWithContextSensitiveArguments3.js create mode 100644 tests/baselines/reference/typeParameterFixingWithContextSensitiveArguments4.js create mode 100644 tests/baselines/reference/typeParameterFixingWithContextSensitiveArguments4.types create mode 100644 tests/baselines/reference/typeParameterFixingWithContextSensitiveArguments5.js create mode 100644 tests/baselines/reference/typeParameterFixingWithContextSensitiveArguments5.types create mode 100644 tests/cases/compiler/typeParameterFixingWithConstraints.ts create mode 100644 tests/cases/compiler/typeParameterFixingWithContextSensitiveArguments.ts create mode 100644 tests/cases/compiler/typeParameterFixingWithContextSensitiveArguments2.ts create mode 100644 tests/cases/compiler/typeParameterFixingWithContextSensitiveArguments3.ts create mode 100644 tests/cases/compiler/typeParameterFixingWithContextSensitiveArguments4.ts create mode 100644 tests/cases/compiler/typeParameterFixingWithContextSensitiveArguments5.ts diff --git a/tests/baselines/reference/typeParameterFixingWithConstraints.js b/tests/baselines/reference/typeParameterFixingWithConstraints.js new file mode 100644 index 0000000000000..49b2c48fbe22b --- /dev/null +++ b/tests/baselines/reference/typeParameterFixingWithConstraints.js @@ -0,0 +1,21 @@ +//// [typeParameterFixingWithConstraints.ts] +interface IBar { + [barId: string]: any; +} + +interface IFoo { + foo(bar: TBar, bar1: (bar: TBar) => TBar, bar2: (bar: TBar) => TBar): TBar; +} + +var foo: IFoo; +foo.foo({ bar: null }, bar => null, bar => null); + +//// [typeParameterFixingWithConstraints.js] +var foo; +foo.foo({ + bar: null +}, function (bar) { + return null; +}, function (bar) { + return null; +}); diff --git a/tests/baselines/reference/typeParameterFixingWithConstraints.types b/tests/baselines/reference/typeParameterFixingWithConstraints.types new file mode 100644 index 0000000000000..c15f22fc974ba --- /dev/null +++ b/tests/baselines/reference/typeParameterFixingWithConstraints.types @@ -0,0 +1,44 @@ +=== tests/cases/compiler/typeParameterFixingWithConstraints.ts === +interface IBar { +>IBar : IBar + + [barId: string]: any; +>barId : string +} + +interface IFoo { +>IFoo : IFoo + + foo(bar: TBar, bar1: (bar: TBar) => TBar, bar2: (bar: TBar) => TBar): TBar; +>foo : (bar: TBar, bar1: (bar: TBar) => TBar, bar2: (bar: TBar) => TBar) => TBar +>TBar : TBar +>IBar : IBar +>bar : TBar +>TBar : TBar +>bar1 : (bar: TBar) => TBar +>bar : TBar +>TBar : TBar +>TBar : TBar +>bar2 : (bar: TBar) => TBar +>bar : TBar +>TBar : TBar +>TBar : TBar +>TBar : TBar +} + +var foo: IFoo; +>foo : IFoo +>IFoo : IFoo + +foo.foo({ bar: null }, bar => null, bar => null); +>foo.foo({ bar: null }, bar => null, bar => null) : IBar +>foo.foo : (bar: TBar, bar1: (bar: TBar) => TBar, bar2: (bar: TBar) => TBar) => TBar +>foo : IFoo +>foo : (bar: TBar, bar1: (bar: TBar) => TBar, bar2: (bar: TBar) => TBar) => TBar +>{ bar: null } : { [x: string]: null; bar: null; } +>bar : null +>bar => null : (bar: IBar) => any +>bar : IBar +>bar => null : (bar: IBar) => any +>bar : IBar + diff --git a/tests/baselines/reference/typeParameterFixingWithContextSensitiveArguments.js b/tests/baselines/reference/typeParameterFixingWithContextSensitiveArguments.js new file mode 100644 index 0000000000000..170bd711b6148 --- /dev/null +++ b/tests/baselines/reference/typeParameterFixingWithContextSensitiveArguments.js @@ -0,0 +1,28 @@ +//// [typeParameterFixingWithContextSensitiveArguments.ts] +function f(y: T, f: (x: T) => U, x: T): [T, U] { return [y, f(x)]; } +interface A { a: A; } +interface B extends A { b; } + +var a: A, b: B; + +var d = f(b, x => x.a, a); // type [A, A] +var d2 = f(b, x => x.a, null); // type [B, A] +var d3 = f(b, x => x.b, null); // type [B, any] + +//// [typeParameterFixingWithContextSensitiveArguments.js] +function f(y, f, x) { + return [ + y, + f(x) + ]; +} +var a, b; +var d = f(b, function (x) { + return x.a; +}, a); // type [A, A] +var d2 = f(b, function (x) { + return x.a; +}, null); // type [B, A] +var d3 = f(b, function (x) { + return x.b; +}, null); // type [B, any] diff --git a/tests/baselines/reference/typeParameterFixingWithContextSensitiveArguments.types b/tests/baselines/reference/typeParameterFixingWithContextSensitiveArguments.types new file mode 100644 index 0000000000000..d6bd1b3b271b0 --- /dev/null +++ b/tests/baselines/reference/typeParameterFixingWithContextSensitiveArguments.types @@ -0,0 +1,71 @@ +=== tests/cases/compiler/typeParameterFixingWithContextSensitiveArguments.ts === +function f(y: T, f: (x: T) => U, x: T): [T, U] { return [y, f(x)]; } +>f : (y: T, f: (x: T) => U, x: T) => [T, U] +>T : T +>U : U +>y : T +>T : T +>f : (x: T) => U +>x : T +>T : T +>U : U +>x : T +>T : T +>T : T +>U : U +>[y, f(x)] : [T, U] +>y : T +>f(x) : U +>f : (x: T) => U +>x : T + +interface A { a: A; } +>A : A +>a : A +>A : A + +interface B extends A { b; } +>B : B +>A : A +>b : any + +var a: A, b: B; +>a : A +>A : A +>b : B +>B : B + +var d = f(b, x => x.a, a); // type [A, A] +>d : [A, A] +>f(b, x => x.a, a) : [A, A] +>f : (y: T, f: (x: T) => U, x: T) => [T, U] +>b : B +>x => x.a : (x: A) => A +>x : A +>x.a : A +>x : A +>a : A +>a : A + +var d2 = f(b, x => x.a, null); // type [B, A] +>d2 : [B, A] +>f(b, x => x.a, null) : [B, A] +>f : (y: T, f: (x: T) => U, x: T) => [T, U] +>b : B +>x => x.a : (x: B) => A +>x : B +>x.a : A +>x : B +>a : A + +var d3 = f(b, x => x.b, null); // type [B, any] +>d3 : [B, any] +>f(b, x => x.b, null) : [B, any] +>f : (y: T, f: (x: T) => U, x: T) => [T, U] +>b : B +>x => x.b : (x: B) => any +>x : B +>x.b : any +>x : B +>b : any + diff --git a/tests/baselines/reference/typeParameterFixingWithContextSensitiveArguments2.errors.txt b/tests/baselines/reference/typeParameterFixingWithContextSensitiveArguments2.errors.txt new file mode 100644 index 0000000000000..6a7975b4b6212 --- /dev/null +++ b/tests/baselines/reference/typeParameterFixingWithContextSensitiveArguments2.errors.txt @@ -0,0 +1,15 @@ +tests/cases/compiler/typeParameterFixingWithContextSensitiveArguments2.ts(7,25): error TS2345: Argument of type '(x: A) => A' is not assignable to parameter of type '(x: A) => B'. + Type 'A' is not assignable to type 'B'. + + +==== tests/cases/compiler/typeParameterFixingWithContextSensitiveArguments2.ts (1 errors) ==== + function f(y: T, y1: U, p: (z: U) => T, p1: (x: T) => U): [T, U] { return [y, p1(y)]; } + interface A { a: A; } + interface B extends A { b; } + + var a: A, b: B; + + var d = f(a, b, x => x, x => x); // A => A not assignable to A => B + ~~~~~~ +!!! error TS2345: Argument of type '(x: A) => A' is not assignable to parameter of type '(x: A) => B'. +!!! error TS2345: Type 'A' is not assignable to type 'B'. \ No newline at end of file diff --git a/tests/baselines/reference/typeParameterFixingWithContextSensitiveArguments2.js b/tests/baselines/reference/typeParameterFixingWithContextSensitiveArguments2.js new file mode 100644 index 0000000000000..1b97f04953e33 --- /dev/null +++ b/tests/baselines/reference/typeParameterFixingWithContextSensitiveArguments2.js @@ -0,0 +1,22 @@ +//// [typeParameterFixingWithContextSensitiveArguments2.ts] +function f(y: T, y1: U, p: (z: U) => T, p1: (x: T) => U): [T, U] { return [y, p1(y)]; } +interface A { a: A; } +interface B extends A { b; } + +var a: A, b: B; + +var d = f(a, b, x => x, x => x); // A => A not assignable to A => B + +//// [typeParameterFixingWithContextSensitiveArguments2.js] +function f(y, y1, p, p1) { + return [ + y, + p1(y) + ]; +} +var a, b; +var d = f(a, b, function (x) { + return x; +}, function (x) { + return x; +}); // A => A not assignable to A => B diff --git a/tests/baselines/reference/typeParameterFixingWithContextSensitiveArguments3.errors.txt b/tests/baselines/reference/typeParameterFixingWithContextSensitiveArguments3.errors.txt new file mode 100644 index 0000000000000..89be3c06c6497 --- /dev/null +++ b/tests/baselines/reference/typeParameterFixingWithContextSensitiveArguments3.errors.txt @@ -0,0 +1,15 @@ +tests/cases/compiler/typeParameterFixingWithContextSensitiveArguments3.ts(7,29): error TS2345: Argument of type '(t2: A) => A' is not assignable to parameter of type '(t2: A) => B'. + Type 'A' is not assignable to type 'B'. + + +==== tests/cases/compiler/typeParameterFixingWithContextSensitiveArguments3.ts (1 errors) ==== + function f(t1: T, u1: U, pf1: (u2: U) => T, pf2: (t2: T) => U): [T, U] { return [t1, pf2(t1)]; } + interface A { a: A; } + interface B extends A { b: B; } + + var a: A, b: B; + + var d = f(a, b, u2 => u2.b, t2 => t2); + ~~~~~~~~ +!!! error TS2345: Argument of type '(t2: A) => A' is not assignable to parameter of type '(t2: A) => B'. +!!! error TS2345: Type 'A' is not assignable to type 'B'. \ No newline at end of file diff --git a/tests/baselines/reference/typeParameterFixingWithContextSensitiveArguments3.js b/tests/baselines/reference/typeParameterFixingWithContextSensitiveArguments3.js new file mode 100644 index 0000000000000..4b5370cfc1ce7 --- /dev/null +++ b/tests/baselines/reference/typeParameterFixingWithContextSensitiveArguments3.js @@ -0,0 +1,22 @@ +//// [typeParameterFixingWithContextSensitiveArguments3.ts] +function f(t1: T, u1: U, pf1: (u2: U) => T, pf2: (t2: T) => U): [T, U] { return [t1, pf2(t1)]; } +interface A { a: A; } +interface B extends A { b: B; } + +var a: A, b: B; + +var d = f(a, b, u2 => u2.b, t2 => t2); + +//// [typeParameterFixingWithContextSensitiveArguments3.js] +function f(t1, u1, pf1, pf2) { + return [ + t1, + pf2(t1) + ]; +} +var a, b; +var d = f(a, b, function (u2) { + return u2.b; +}, function (t2) { + return t2; +}); diff --git a/tests/baselines/reference/typeParameterFixingWithContextSensitiveArguments4.js b/tests/baselines/reference/typeParameterFixingWithContextSensitiveArguments4.js new file mode 100644 index 0000000000000..7efab1f62c5fb --- /dev/null +++ b/tests/baselines/reference/typeParameterFixingWithContextSensitiveArguments4.js @@ -0,0 +1,22 @@ +//// [typeParameterFixingWithContextSensitiveArguments4.ts] +function f(y: T, y1: U, p: (z: U) => T, p1: (x: T) => U): [T, U] { return [y, p1(y)]; } +interface A { a: A; } +interface B extends A { b; } + +var a: A, b: B; + +var d = f(a, b, x => x, x => x); // Type [A, B] + +//// [typeParameterFixingWithContextSensitiveArguments4.js] +function f(y, y1, p, p1) { + return [ + y, + p1(y) + ]; +} +var a, b; +var d = f(a, b, function (x) { + return x; +}, function (x) { + return x; +}); // Type [A, B] diff --git a/tests/baselines/reference/typeParameterFixingWithContextSensitiveArguments4.types b/tests/baselines/reference/typeParameterFixingWithContextSensitiveArguments4.types new file mode 100644 index 0000000000000..61158ae97384f --- /dev/null +++ b/tests/baselines/reference/typeParameterFixingWithContextSensitiveArguments4.types @@ -0,0 +1,55 @@ +=== tests/cases/compiler/typeParameterFixingWithContextSensitiveArguments4.ts === +function f(y: T, y1: U, p: (z: U) => T, p1: (x: T) => U): [T, U] { return [y, p1(y)]; } +>f : (y: T, y1: U, p: (z: U) => T, p1: (x: T) => U) => [T, U] +>T : T +>U : U +>y : T +>T : T +>y1 : U +>U : U +>p : (z: U) => T +>z : U +>U : U +>T : T +>p1 : (x: T) => U +>x : T +>T : T +>U : U +>T : T +>U : U +>[y, p1(y)] : [T, U] +>y : T +>p1(y) : U +>p1 : (x: T) => U +>y : T + +interface A { a: A; } +>A : A +>a : A +>A : A + +interface B extends A { b; } +>B : B +>A : A +>b : any + +var a: A, b: B; +>a : A +>A : A +>b : B +>B : B + +var d = f(a, b, x => x, x => x); // Type [A, B] +>d : [A, B] +>f(a, b, x => x, x => x) : [A, B] +>f : (y: T, y1: U, p: (z: U) => T, p1: (x: T) => U) => [T, U] +>a : A +>b : B +>x => x : (x: B) => B +>x : B +>x : B +>x => x : (x: A) => any +>x : A +>x : any +>x : A + diff --git a/tests/baselines/reference/typeParameterFixingWithContextSensitiveArguments5.js b/tests/baselines/reference/typeParameterFixingWithContextSensitiveArguments5.js new file mode 100644 index 0000000000000..7ab2502e02cc8 --- /dev/null +++ b/tests/baselines/reference/typeParameterFixingWithContextSensitiveArguments5.js @@ -0,0 +1,22 @@ +//// [typeParameterFixingWithContextSensitiveArguments5.ts] +function f(t1: T, u1: U, pf1: (u2: U) => T, pf2: (t2: T) => U): [T, U] { return [t1, pf2(t1)]; } +interface A { a: A; } +interface B extends A { b: any; } + +var a: A, b: B; + +var d = f(a, b, u2 => u2.b, t2 => t2); + +//// [typeParameterFixingWithContextSensitiveArguments5.js] +function f(t1, u1, pf1, pf2) { + return [ + t1, + pf2(t1) + ]; +} +var a, b; +var d = f(a, b, function (u2) { + return u2.b; +}, function (t2) { + return t2; +}); diff --git a/tests/baselines/reference/typeParameterFixingWithContextSensitiveArguments5.types b/tests/baselines/reference/typeParameterFixingWithContextSensitiveArguments5.types new file mode 100644 index 0000000000000..3eb7d07bc3ce9 --- /dev/null +++ b/tests/baselines/reference/typeParameterFixingWithContextSensitiveArguments5.types @@ -0,0 +1,56 @@ +=== tests/cases/compiler/typeParameterFixingWithContextSensitiveArguments5.ts === +function f(t1: T, u1: U, pf1: (u2: U) => T, pf2: (t2: T) => U): [T, U] { return [t1, pf2(t1)]; } +>f : (t1: T, u1: U, pf1: (u2: U) => T, pf2: (t2: T) => U) => [T, U] +>T : T +>U : U +>t1 : T +>T : T +>u1 : U +>U : U +>pf1 : (u2: U) => T +>u2 : U +>U : U +>T : T +>pf2 : (t2: T) => U +>t2 : T +>T : T +>U : U +>T : T +>U : U +>[t1, pf2(t1)] : [T, U] +>t1 : T +>pf2(t1) : U +>pf2 : (t2: T) => U +>t1 : T + +interface A { a: A; } +>A : A +>a : A +>A : A + +interface B extends A { b: any; } +>B : B +>A : A +>b : any + +var a: A, b: B; +>a : A +>A : A +>b : B +>B : B + +var d = f(a, b, u2 => u2.b, t2 => t2); +>d : [any, B] +>f(a, b, u2 => u2.b, t2 => t2) : [any, B] +>f : (t1: T, u1: U, pf1: (u2: U) => T, pf2: (t2: T) => U) => [T, U] +>a : A +>b : B +>u2 => u2.b : (u2: B) => any +>u2 : B +>u2.b : any +>u2 : B +>b : any +>t2 => t2 : (t2: any) => any +>t2 : any +>t2 : any + diff --git a/tests/cases/compiler/typeParameterFixingWithConstraints.ts b/tests/cases/compiler/typeParameterFixingWithConstraints.ts new file mode 100644 index 0000000000000..3d8536ab4cfd6 --- /dev/null +++ b/tests/cases/compiler/typeParameterFixingWithConstraints.ts @@ -0,0 +1,10 @@ +interface IBar { + [barId: string]: any; +} + +interface IFoo { + foo(bar: TBar, bar1: (bar: TBar) => TBar, bar2: (bar: TBar) => TBar): TBar; +} + +var foo: IFoo; +foo.foo({ bar: null }, bar => null, bar => null); \ No newline at end of file diff --git a/tests/cases/compiler/typeParameterFixingWithContextSensitiveArguments.ts b/tests/cases/compiler/typeParameterFixingWithContextSensitiveArguments.ts new file mode 100644 index 0000000000000..c05b26fd2fcc5 --- /dev/null +++ b/tests/cases/compiler/typeParameterFixingWithContextSensitiveArguments.ts @@ -0,0 +1,9 @@ +function f(y: T, f: (x: T) => U, x: T): [T, U] { return [y, f(x)]; } +interface A { a: A; } +interface B extends A { b; } + +var a: A, b: B; + +var d = f(b, x => x.a, a); // type [A, A] +var d2 = f(b, x => x.a, null); // type [B, A] +var d3 = f(b, x => x.b, null); // type [B, any] \ No newline at end of file diff --git a/tests/cases/compiler/typeParameterFixingWithContextSensitiveArguments2.ts b/tests/cases/compiler/typeParameterFixingWithContextSensitiveArguments2.ts new file mode 100644 index 0000000000000..f4f001c9f2795 --- /dev/null +++ b/tests/cases/compiler/typeParameterFixingWithContextSensitiveArguments2.ts @@ -0,0 +1,7 @@ +function f(y: T, y1: U, p: (z: U) => T, p1: (x: T) => U): [T, U] { return [y, p1(y)]; } +interface A { a: A; } +interface B extends A { b; } + +var a: A, b: B; + +var d = f(a, b, x => x, x => x); // A => A not assignable to A => B \ No newline at end of file diff --git a/tests/cases/compiler/typeParameterFixingWithContextSensitiveArguments3.ts b/tests/cases/compiler/typeParameterFixingWithContextSensitiveArguments3.ts new file mode 100644 index 0000000000000..1bf4169624db5 --- /dev/null +++ b/tests/cases/compiler/typeParameterFixingWithContextSensitiveArguments3.ts @@ -0,0 +1,7 @@ +function f(t1: T, u1: U, pf1: (u2: U) => T, pf2: (t2: T) => U): [T, U] { return [t1, pf2(t1)]; } +interface A { a: A; } +interface B extends A { b: B; } + +var a: A, b: B; + +var d = f(a, b, u2 => u2.b, t2 => t2); \ No newline at end of file diff --git a/tests/cases/compiler/typeParameterFixingWithContextSensitiveArguments4.ts b/tests/cases/compiler/typeParameterFixingWithContextSensitiveArguments4.ts new file mode 100644 index 0000000000000..8fa501906b862 --- /dev/null +++ b/tests/cases/compiler/typeParameterFixingWithContextSensitiveArguments4.ts @@ -0,0 +1,7 @@ +function f(y: T, y1: U, p: (z: U) => T, p1: (x: T) => U): [T, U] { return [y, p1(y)]; } +interface A { a: A; } +interface B extends A { b; } + +var a: A, b: B; + +var d = f(a, b, x => x, x => x); // Type [A, B] \ No newline at end of file diff --git a/tests/cases/compiler/typeParameterFixingWithContextSensitiveArguments5.ts b/tests/cases/compiler/typeParameterFixingWithContextSensitiveArguments5.ts new file mode 100644 index 0000000000000..a74eb04269229 --- /dev/null +++ b/tests/cases/compiler/typeParameterFixingWithContextSensitiveArguments5.ts @@ -0,0 +1,7 @@ +function f(t1: T, u1: U, pf1: (u2: U) => T, pf2: (t2: T) => U): [T, U] { return [t1, pf2(t1)]; } +interface A { a: A; } +interface B extends A { b: any; } + +var a: A, b: B; + +var d = f(a, b, u2 => u2.b, t2 => t2); \ No newline at end of file From 84634ac25da26513935d62177aedff1a01fee668 Mon Sep 17 00:00:00 2001 From: Caitlin Potter Date: Mon, 9 Mar 2015 22:51:23 -0400 Subject: [PATCH 061/224] Disallow line terminator after arrow function parameters, before => Closes #2282 --- src/compiler/parser.ts | 327 +++++++++--------- ...sallowLineTerminatorBeforeArrow.errors.txt | 70 ++++ .../disallowLineTerminatorBeforeArrow.js | 60 ++++ .../disallowLineTerminatorBeforeArrow.ts | 22 ++ 4 files changed, 318 insertions(+), 161 deletions(-) create mode 100644 tests/baselines/reference/disallowLineTerminatorBeforeArrow.errors.txt create mode 100644 tests/baselines/reference/disallowLineTerminatorBeforeArrow.js create mode 100644 tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 7f89ff6153bc3..fc02c3f3eef3f 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -8,7 +8,7 @@ module ts { export function getNodeConstructor(kind: SyntaxKind): new () => Node { return nodeConstructors[kind] || (nodeConstructors[kind] = objectAllocator.getNodeConstructor(kind)); } - + export function createNode(kind: SyntaxKind): Node { return new (getNodeConstructor(kind))(); } @@ -369,7 +369,7 @@ module ts { function fixupParentReferences(sourceFile: SourceFile) { // normally parent references are set during binding. However, for clients that only need - // a syntax tree, and no semantic features, then the binding process is an unnecessary + // a syntax tree, and no semantic features, then the binding process is an unnecessary // overhead. This functions allows us to set all the parents, without all the expense of // binding. @@ -379,7 +379,7 @@ module ts { function visitNode(n: Node): void { // walk down setting parents that differ from the parent we think it should be. This - // allows us to quickly bail out of setting parents for subtrees during incremental + // allows us to quickly bail out of setting parents for subtrees during incremental // parsing if (n.parent !== parent) { n.parent = parent; @@ -417,7 +417,7 @@ module ts { var text = oldText.substring(node.pos, node.end); } - // Ditch any existing LS children we may have created. This way we can avoid + // Ditch any existing LS children we may have created. This way we can avoid // moving them forward. node._children = undefined; node.pos += delta; @@ -455,9 +455,9 @@ module ts { // We may need to update both the 'pos' and the 'end' of the element. - // If the 'pos' is before the start of the change, then we don't need to touch it. - // If it isn't, then the 'pos' must be inside the change. How we update it will - // depend if delta is positive or negative. If delta is positive then we have + // If the 'pos' is before the start of the change, then we don't need to touch it. + // If it isn't, then the 'pos' must be inside the change. How we update it will + // depend if delta is positive or negative. If delta is positive then we have // something like: // // -------------------AAA----------------- @@ -471,7 +471,7 @@ module ts { // -------------------XXXYYYYYYY----------------- // -------------------ZZZ----------------- // - // In this case, any element that started in the 'X' range will keep its position. + // In this case, any element that started in the 'X' range will keep its position. // However any element htat started after that will have their pos adjusted to be // at the end of the new range. i.e. any node that started in the 'Y' range will // be adjusted to have their start at the end of the 'Z' range. @@ -481,7 +481,7 @@ module ts { element.pos = Math.min(element.pos, changeRangeNewEnd); // If the 'end' is after the change range, then we always adjust it by the delta - // amount. However, if the end is in the change range, then how we adjust it + // amount. However, if the end is in the change range, then how we adjust it // will depend on if delta is positive or negative. If delta is positive then we // have something like: // @@ -496,7 +496,7 @@ module ts { // -------------------XXXYYYYYYY----------------- // -------------------ZZZ----------------- // - // In this case, any element that ended in the 'X' range will keep its position. + // In this case, any element that ended in the 'X' range will keep its position. // However any element htat ended after that will have their pos adjusted to be // at the end of the new range. i.e. any node that ended in the 'Y' range will // be adjusted to have their end at the end of the 'Z' range. @@ -505,7 +505,7 @@ module ts { element.end += delta; } else { - // Element ends in the change range. The element will keep its position if + // Element ends in the change range. The element will keep its position if // possible. Or Move backward to the new-end if it's in the 'Y' range. element.end = Math.min(element.end, changeRangeNewEnd); } @@ -544,7 +544,7 @@ module ts { function visitNode(child: IncrementalNode) { Debug.assert(child.pos <= child.end); if (child.pos > changeRangeOldEnd) { - // Node is entirely past the change range. We need to move both its pos and + // Node is entirely past the change range. We need to move both its pos and // end, forward or backward appropriately. moveElementEntirelyPastChangeRange(child, /*isArray:*/ false, delta, oldText, newText, aggressiveChecks); return; @@ -607,12 +607,12 @@ module ts { // If the text changes with an insertion of / just before the semicolon then we end up with: // void foo() { //; } // - // If we were to just use the changeRange a is, then we would not rescan the { token + // If we were to just use the changeRange a is, then we would not rescan the { token // (as it does not intersect the actual original change range). Because an edit may // change the token touching it, we actually need to look back *at least* one token so - // that the prior token sees that change. + // that the prior token sees that change. let maxLookahead = 1; - + let start = changeRange.span.start; // the first iteration aligns us with the change start. subsequent iteration move us to @@ -676,7 +676,7 @@ module ts { return; } - // If the child intersects this position, then this node is currently the nearest + // If the child intersects this position, then this node is currently the nearest // node that starts before the position. if (child.pos <= position) { if (child.pos >= bestResult.pos) { @@ -687,7 +687,7 @@ module ts { // Now, the node may overlap the position, or it may end entirely before the // position. If it overlaps with the position, then either it, or one of its - // children must be the nearest node before the position. So we can just + // children must be the nearest node before the position. So we can just // recurse into this child to see if we can find something better. if (position < child.end) { // The nearest node is either this child, or one of the children inside @@ -703,15 +703,15 @@ module ts { Debug.assert(child.end <= position); // The child ends entirely before this position. Say you have the following // (where $ is the position) - // - // ? $ : <...> <...> // - // We would want to find the nearest preceding node in "complex expr 2". + // ? $ : <...> <...> + // + // We would want to find the nearest preceding node in "complex expr 2". // To support that, we keep track of this node, and once we're done searching // for a best node, we recurse down this node to see if we can find a good // result in it. // - // This approach allows us to quickly skip over nodes that are entirely + // This approach allows us to quickly skip over nodes that are entirely // before the position, while still allowing us to find any nodes in the // last one that might be what we want. lastNodeEntirelyBeforePosition = child; @@ -744,13 +744,13 @@ module ts { } } - // Produces a new SourceFile for the 'newText' provided. The 'textChangeRange' parameter + // Produces a new SourceFile for the 'newText' provided. The 'textChangeRange' parameter // indicates what changed between the 'text' that this SourceFile has and the 'newText'. - // The SourceFile will be created with the compiler attempting to reuse as many nodes from + // The SourceFile will be created with the compiler attempting to reuse as many nodes from // this file as possible. // // Note: this function mutates nodes from this SourceFile. That means any existing nodes - // from this SourceFile that are being held onto may change as a result (including + // from this SourceFile that are being held onto may change as a result (including // becoming detached from any SourceFile). It is recommended that this SourceFile not // be used once 'update' is called on it. export function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile { @@ -769,7 +769,7 @@ module ts { } // Make sure we're not trying to incrementally update a source file more than once. Once - // we do an update the original source file is considered unusbale from that point onwards. + // we do an update the original source file is considered unusbale from that point onwards. // // This is because we do incremental parsing in-place. i.e. we take nodes from the old // tree and give them new positions and parents. From that point on, trusting the old @@ -781,24 +781,24 @@ module ts { let oldText = sourceFile.text; let syntaxCursor = createSyntaxCursor(sourceFile); - // Make the actual change larger so that we know to reparse anything whose lookahead + // Make the actual change larger so that we know to reparse anything whose lookahead // might have intersected the change. let changeRange = extendToAffectedRange(sourceFile, textChangeRange); checkChangeRange(sourceFile, newText, changeRange, aggressiveChecks); - // Ensure that extending the affected range only moved the start of the change range + // Ensure that extending the affected range only moved the start of the change range // earlier in the file. Debug.assert(changeRange.span.start <= textChangeRange.span.start); Debug.assert(textSpanEnd(changeRange.span) === textSpanEnd(textChangeRange.span)); Debug.assert(textSpanEnd(textChangeRangeNewSpan(changeRange)) === textSpanEnd(textChangeRangeNewSpan(textChangeRange))); - // The is the amount the nodes after the edit range need to be adjusted. It can be + // The is the amount the nodes after the edit range need to be adjusted. It can be // positive (if the edit added characters), negative (if the edit deleted characters) // or zero (if this was a pure overwrite with nothing added/removed). let delta = textChangeRangeNewSpan(changeRange).length - changeRange.span.length; // If we added or removed characters during the edit, then we need to go and adjust all - // the nodes after the edit. Those nodes may move forward (if we inserted chars) or they + // the nodes after the edit. Those nodes may move forward (if we inserted chars) or they // may move backward (if we deleted chars). // // Doing this helps us out in two ways. First, it means that any nodes/tokens we want @@ -811,7 +811,7 @@ module ts { // // We will also adjust the positions of nodes that intersect the change range as well. // By doing this, we ensure that all the positions in the old tree are consistent, not - // just the positions of nodes entirely before/after the change range. By being + // just the positions of nodes entirely before/after the change range. By being // consistent, we can then easily map from positions to nodes in the old tree easily. // // Also, mark any syntax elements that intersect the changed span. We know, up front, @@ -822,15 +822,15 @@ module ts { // Now that we've set up our internal incremental state just proceed and parse the // source file in the normal fashion. When possible the parser will retrieve and // reuse nodes from the old tree. - // + // // Note: passing in 'true' for setNodeParents is very important. When incrementally // parsing, we will be reusing nodes from the old tree, and placing it into new - // parents. If we don't set the parents now, we'll end up with an observably - // inconsistent tree. Setting the parents on the new tree should be very fast. We + // parents. If we don't set the parents now, we'll end up with an observably + // inconsistent tree. Setting the parents on the new tree should be very fast. We // will immediately bail out of walking any subtrees when we can see that their parents // are already correct. - let result = parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, syntaxCursor, /* setParentNode */ true) - + let result = parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, syntaxCursor, /* setParentNode */ true) + return result; } @@ -885,13 +885,13 @@ module ts { return { currentNode(position: number) { - // Only compute the current node if the position is different than the last time - // we were asked. The parser commonly asks for the node at the same position + // Only compute the current node if the position is different than the last time + // we were asked. The parser commonly asks for the node at the same position // twice. Once to know if can read an appropriate list element at a certain point, // and then to actually read and consume the node. if (position !== lastQueriedPosition) { - // Much of the time the parser will need the very next node in the array that - // we just returned a node from.So just simply check for that case and move + // Much of the time the parser will need the very next node in the array that + // we just returned a node from.So just simply check for that case and move // forward in the array instead of searching for the node again. if (current && current.end === position && currentArrayIndex < (currentArray.length - 1)) { currentArrayIndex++; @@ -905,7 +905,7 @@ module ts { } } - // Cache this query so that we don't do any extra work if the parser calls back + // Cache this query so that we don't do any extra work if the parser calls back // into us. Note: this is very common as the parser will make pairs of calls like // 'isListElement -> parseListElement'. If we were unable to find a node when // called with 'isListElement', we don't want to redo the work when parseListElement @@ -917,7 +917,7 @@ module ts { return current; } }; - + // Finds the highest element in the tree we can find that starts at the provided position. // The element must be a direct child of some node list in the tree. This way after we // return it, we can easily return its next sibling in the list. @@ -960,7 +960,7 @@ module ts { } else { if (child.pos < position && position < child.end) { - // Position in somewhere within this child. Search in it and + // Position in somewhere within this child. Search in it and // stop searching in this array. forEachChild(child, visitNode, visitArray); return true; @@ -1007,10 +1007,10 @@ module ts { // Whether or not we are in strict parsing mode. All that changes in strict parsing mode is // that some tokens that would be considered identifiers may be considered keywords. // - // When adding more parser context flags, consider which is the more common case that the + // When adding more parser context flags, consider which is the more common case that the // flag will be in. This should be hte 'false' state for that flag. The reason for this is // that we don't store data in our nodes unless the value is in the *non-default* state. So, - // for example, more often than code 'allows-in' (or doesn't 'disallow-in'). We opt for + // for example, more often than code 'allows-in' (or doesn't 'disallow-in'). We opt for // 'disallow-in' set to 'false'. Otherwise, if we had 'allowsIn' set to 'true', then almost // all nodes would need extra state on them to store this info. // @@ -1030,20 +1030,20 @@ module ts { // EqualityExpression[?In, ?Yield] === RelationalExpression[?In, ?Yield] // EqualityExpression[?In, ?Yield] !== RelationalExpression[?In, ?Yield] // - // Where you have to be careful is then understanding what the points are in the grammar + // Where you have to be careful is then understanding what the points are in the grammar // where the values are *not* passed along. For example: // // SingleNameBinding[Yield,GeneratorParameter] // [+GeneratorParameter]BindingIdentifier[Yield] Initializer[In]opt // [~GeneratorParameter]BindingIdentifier[?Yield]Initializer[In, ?Yield]opt // - // Here this is saying that if the GeneratorParameter context flag is set, that we should + // Here this is saying that if the GeneratorParameter context flag is set, that we should // explicitly set the 'yield' context flag to false before calling into the BindingIdentifier // and we should explicitly unset the 'yield' context flag before calling into the Initializer. - // production. Conversely, if the GeneratorParameter context flag is not set, then we + // production. Conversely, if the GeneratorParameter context flag is not set, then we // should leave the 'yield' context flag alone. // - // Getting this all correct is tricky and requires careful reading of the grammar to + // Getting this all correct is tricky and requires careful reading of the grammar to // understand when these values should be changed versus when they should be inherited. // // Note: it should not be necessary to save/restore these flags during speculative/lookahead @@ -1051,7 +1051,7 @@ module ts { // descent parsing and unwinding. let contextFlags: ParserContextFlags = 0; - // Whether or not we've had a parse error since creating the last AST node. If we have + // Whether or not we've had a parse error since creating the last AST node. If we have // encountered an error, it will be stored on the next AST node we create. Parse errors // can be broken down into three categories: // @@ -1062,7 +1062,7 @@ module ts { // by the 'parseExpected' function. // // 3) A token was present that no parsing function was able to consume. This type of error - // only occurs in the 'abortParsingListOrMoveToNextToken' function when the parser + // only occurs in the 'abortParsingListOrMoveToNextToken' function when the parser // decides to skip the token. // // In all of these cases, we want to mark the next node as having had an error before it. @@ -1071,8 +1071,8 @@ module ts { // node. in that event we would then not produce the same errors as we did before, causing // significant confusion problems. // - // Note: it is necessary that this value be saved/restored during speculative/lookahead - // parsing. During lookahead parsing, we will often create a node. That node will have + // Note: it is necessary that this value be saved/restored during speculative/lookahead + // parsing. During lookahead parsing, we will often create a node. That node will have // this value attached, and then this value will be set back to 'false'. If we decide to // rewind, we must get back to the same value we had prior to the lookahead. // @@ -1135,7 +1135,7 @@ module ts { setDisallowInContext(true); return result; } - + // no need to do anything special if 'in' is already allowed. return func(); } @@ -1206,7 +1206,7 @@ module ts { sourceFile.parseDiagnostics.push(createFileDiagnostic(sourceFile, start, length, message, arg0)); } - // Mark that we've encountered an error. We'll set an appropriate bit on the next + // Mark that we've encountered an error. We'll set an appropriate bit on the next // node we finish so that it can't be reused incrementally. parseErrorBeforeNextFinishedNode = true; } @@ -1245,7 +1245,7 @@ module ts { } function speculationHelper(callback: () => T, isLookAhead: boolean): T { - // Keep track of the state we'll need to rollback to if lookahead fails (or if the + // Keep track of the state we'll need to rollback to if lookahead fails (or if the // caller asked us to always reset our state). let saveToken = token; let saveParseDiagnosticsLength = sourceFile.parseDiagnostics.length; @@ -1253,13 +1253,13 @@ module ts { // Note: it is not actually necessary to save/restore the context flags here. That's // because the saving/restorating of these flags happens naturally through the recursive - // descent nature of our parser. However, we still store this here just so we can + // descent nature of our parser. However, we still store this here just so we can // assert that that invariant holds. let saveContextFlags = contextFlags; // If we're only looking ahead, then tell the scanner to only lookahead as well. - // Otherwise, if we're actually speculatively parsing, then tell the scanner to do the - // same. + // Otherwise, if we're actually speculatively parsing, then tell the scanner to do the + // same. let result = isLookAhead ? scanner.lookAhead(callback) : scanner.tryScan(callback); @@ -1277,15 +1277,15 @@ module ts { return result; } - // Invokes the provided callback then unconditionally restores the parser to the state it + // Invokes the provided callback then unconditionally restores the parser to the state it // was in immediately prior to invoking the callback. The result of invoking the callback // is returned from this function. function lookAhead(callback: () => T): T { return speculationHelper(callback, /*isLookAhead:*/ true); } - + // Invokes the provided callback. If the callback returns something falsy, then it restores - // the parser to the state it was in immediately prior to invoking the callback. If the + // the parser to the state it was in immediately prior to invoking the callback. If the // callback returns something truthy, then the parser state is not rolled back. The result // of invoking the callback is returned from this function. function tryParse(callback: () => T): T { @@ -1296,8 +1296,8 @@ module ts { if (token === SyntaxKind.Identifier) { return true; } - - // If we have a 'yield' keyword, and we're in the [yield] context, then 'yield' is + + // If we have a 'yield' keyword, and we're in the [yield] context, then 'yield' is // considered a keyword and is not an identifier. if (token === SyntaxKind.YieldKeyword && inYieldContext()) { return false; @@ -1464,7 +1464,7 @@ module ts { // LiteralPropertyName // [+GeneratorParameter] ComputedPropertyName // [~GeneratorParameter] ComputedPropertyName[?Yield] - // + // // ComputedPropertyName[Yield] : // [ AssignmentExpression[In, ?Yield] ] // @@ -1648,13 +1648,13 @@ module ts { } function isVariableDeclaratorListTerminator(): boolean { - // If we can consume a semicolon (either explicitly, or with ASI), then consider us done + // If we can consume a semicolon (either explicitly, or with ASI), then consider us done // with parsing the list of variable declarators. if (canParseSemicolon()) { return true; } - // in the case where we're parsing the variable declarator of a 'for-in' statement, we + // in the case where we're parsing the variable declarator of a 'for-in' statement, we // are done if we see an 'in' keyword in front of us. Same with for-of if (isInOrOfKeyword(token)) { return true; @@ -1730,7 +1730,7 @@ module ts { if (node) { return consumeNode(node); } - + return parseElement(); } @@ -1738,9 +1738,9 @@ module ts { // If there is an outstanding parse error that we've encountered, but not attached to // some node, then we cannot get a node from the old source tree. This is because we // want to mark the next node we encounter as being unusable. - // + // // Note: This may be too conservative. Perhaps we could reuse hte node and set the bit - // on it (or its leftmost child) as having the error. For now though, being conservative + // on it (or its leftmost child) as having the error. For now though, being conservative // is nice and likely won't ever affect perf. if (parseErrorBeforeNextFinishedNode) { return undefined; @@ -1763,18 +1763,18 @@ module ts { return undefined; } - // Can't reuse a node that contains a parse error. This is necessary so that we + // Can't reuse a node that contains a parse error. This is necessary so that we // produce the same set of errors again. if (containsParseError(node)) { return undefined; } - // We can only reuse a node if it was parsed under the same strict mode that we're + // We can only reuse a node if it was parsed under the same strict mode that we're // currently in. i.e. if we originally parsed a node in non-strict mode, but then // the user added 'using strict' at the top of the file, then we can't use that node // again as the presense of strict mode may cause us to parse the tokens in the file // differetly. - // + // // Note: we *can* reuse tokens when the strict mode changes. That's because tokens // are unaffected by strict mode. It's just the parser will decide what to do with it // differently depending on what mode it is in. @@ -1828,32 +1828,32 @@ module ts { case ParsingContext.Parameters: return isReusableParameter(node); - // Any other lists we do not care about reusing nodes in. But feel free to add if + // Any other lists we do not care about reusing nodes in. But feel free to add if // you can do so safely. Danger areas involve nodes that may involve speculative // parsing. If speculative parsing is involved with the node, then the range the // parser reached while looking ahead might be in the edited range (see the example // in canReuseVariableDeclaratorNode for a good case of this). case ParsingContext.HeritageClauses: - // This would probably be safe to reuse. There is no speculative parsing with + // This would probably be safe to reuse. There is no speculative parsing with // heritage clauses. case ParsingContext.TypeReferences: - // This would probably be safe to reuse. There is no speculative parsing with + // This would probably be safe to reuse. There is no speculative parsing with // type names in a heritage clause. There can be generic names in the type - // name list. But because it is a type context, we never use speculative + // name list. But because it is a type context, we never use speculative // parsing on the type argument list. case ParsingContext.TypeParameters: - // This would probably be safe to reuse. There is no speculative parsing with + // This would probably be safe to reuse. There is no speculative parsing with // type parameters. Note that that's because type *parameters* only occur in // unambiguous *type* contexts. While type *arguments* occur in very ambiguous // *expression* contexts. case ParsingContext.TupleElementTypes: - // This would probably be safe to reuse. There is no speculative parsing with + // This would probably be safe to reuse. There is no speculative parsing with // tuple types. - // Technically, type argument list types are probably safe to reuse. While + // Technically, type argument list types are probably safe to reuse. While // speculative parsing is involved with them (since type argument lists are only // produced from speculative parsing a < as a type argument list), we only have // the types because speculative parsing succeeded. Thus, the lookahead never @@ -1861,12 +1861,12 @@ module ts { case ParsingContext.TypeArguments: // Note: these are almost certainly not safe to ever reuse. Expressions commonly - // need a large amount of lookahead, and we should not reuse them as they may + // need a large amount of lookahead, and we should not reuse them as they may // have actually intersected the edit. case ParsingContext.ArgumentExpressions: // This is not safe to reuse for the same reason as the 'AssignmentExpression' - // cases. i.e. a property assignment may end with an expression, and thus might + // cases. i.e. a property assignment may end with an expression, and thus might // have lookahead far beyond it's old node. case ParsingContext.ObjectLiteralMembers: } @@ -1980,12 +1980,12 @@ module ts { // // let v = new List < A, B // - // This is actually legal code. It's a list of variable declarators "v = new List() - // - // then we have a problem. "v = new ListcreateMissingNode(SyntaxKind.Identifier, /*reportAtCurrentToken:*/ true, Diagnostics.Identifier_expected); } @@ -2185,7 +2185,7 @@ module ts { if (scanner.hasExtendedUnicodeEscape()) { node.hasExtendedUnicodeEscape = true; } - + if (scanner.isUnterminated()) { node.isUnterminated = true; } @@ -2193,7 +2193,7 @@ module ts { let tokenPos = scanner.getTokenPos(); nextToken(); finishNode(node); - + // Octal literals are not allowed in strict mode or ES5 // Note that theoretically the following condition would hold true literals like 009, // which is not octal.But because of how the scanner separates the tokens, we would @@ -2232,7 +2232,7 @@ module ts { let node = createNode(SyntaxKind.TypeParameter); node.name = parseIdentifier(); if (parseOptional(SyntaxKind.ExtendsKeyword)) { - // It's not uncommon for people to write improper constraints to a generic. If the + // It's not uncommon for people to write improper constraints to a generic. If the // user writes a constraint that is an expression and not an actual type, then parse // it out as an expression (so we can recover well), but report that a type is needed // instead. @@ -2294,7 +2294,7 @@ module ts { if (getFullWidth(node.name) === 0 && node.flags === 0 && isModifier(token)) { // in cases like - // 'use strict' + // 'use strict' // function foo(static) // isParameter('static') === true, because of isModifier('static') // however 'static' is not a legal identifier in a strict mode. @@ -2341,7 +2341,7 @@ module ts { } } - // Note: after careful analysis of the grammar, it does not appear to be possible to + // Note: after careful analysis of the grammar, it does not appear to be possible to // have 'Yield' And 'GeneratorParameter' not in sync. i.e. any production calling // this FormalParameters production either always sets both to true, or always sets // both to false. As such we only have a single parameter to represent both. @@ -2388,7 +2388,7 @@ module ts { } function parseTypeMemberSemicolon() { - // We allow type members to be separated by commas or (possibly ASI) semicolons. + // We allow type members to be separated by commas or (possibly ASI) semicolons. // First check if it was a comma. If so, we're done with the member. if (parseOptional(SyntaxKind.CommaToken)) { return; @@ -2561,9 +2561,9 @@ module ts { case SyntaxKind.NumericLiteral: return parsePropertyOrMethodSignature(); default: - // Index declaration as allowed as a type member. But as per the grammar, + // Index declaration as allowed as a type member. But as per the grammar, // they also allow modifiers. So we have to check for an index declaration - // that might be following modifiers. This ensures that things work properly + // that might be following modifiers. This ensures that things work properly // when incrementally parsing as the parser will produce the Index declaration // if it has the same text regardless of whether it is inside a class or an // object type. @@ -2844,7 +2844,7 @@ module ts { function parseExpression(): Expression { // Expression[in]: - // AssignmentExpression[in] + // AssignmentExpression[in] // Expression[in] , AssignmentExpression[in] let expr = parseAssignmentExpressionOrHigher(); @@ -2860,13 +2860,13 @@ module ts { // It's not uncommon during typing for the user to miss writing the '=' token. Check if // there is no newline after the last token and if we're on an expression. If so, parse // this as an equals-value clause with a missing equals. - // NOTE: There are two places where we allow equals-value clauses. The first is in a + // NOTE: There are two places where we allow equals-value clauses. The first is in a // variable declarator. The second is with a parameter. For variable declarators // it's more likely that a { would be a allowed (as an object literal). While this // is also allowed for parameters, the risk is that we consume the { as an object // literal when it really will be for the block following the parameter. if (scanner.hasPrecedingLineBreak() || (inParameter && token === SyntaxKind.OpenBraceToken) || !isStartOfExpression()) { - // preceding line break, open brace in a parameter (likely a function body) or current token is not an expression - + // preceding line break, open brace in a parameter (likely a function body) or current token is not an expression - // do not try to parse initializer return undefined; } @@ -2887,17 +2887,17 @@ module ts { // 4) ArrowFunctionExpression[?in,?yield] // 5) [+Yield] YieldExpression[?In] // - // Note: for ease of implementation we treat productions '2' and '3' as the same thing. + // Note: for ease of implementation we treat productions '2' and '3' as the same thing. // (i.e. they're both BinaryExpressions with an assignment operator in it). // First, do the simple check if we have a YieldExpression (production '5'). if (isYieldExpression()) { return parseYieldExpression(); - } + } // Then, check if we have an arrow function (production '4') that starts with a parenthesized // parameter list. If we do, we must *not* recurse for productions 1, 2 or 3. An ArrowFunction is - // not a LeftHandSideExpression, nor does it start a ConditionalExpression. So we are done + // not a LeftHandSideExpression, nor does it start a ConditionalExpression. So we are done // with AssignmentExpression if we see one. let arrowExpression = tryParseParenthesizedArrowFunctionExpression(); if (arrowExpression) { @@ -2908,9 +2908,9 @@ module ts { // start with a LogicalOrExpression, while the assignment productions can only start with // LeftHandSideExpressions. // - // So, first, we try to just parse out a BinaryExpression. If we get something that is a - // LeftHandSide or higher, then we can try to parse out the assignment expression part. - // Otherwise, we try to parse out the conditional expression bit. We want to allow any + // So, first, we try to just parse out a BinaryExpression. If we get something that is a + // LeftHandSide or higher, then we can try to parse out the assignment expression part. + // Otherwise, we try to parse out the conditional expression bit. We want to allow any // binary expression here, so we pass in the 'lowest' precedence here so that it matches // and consumes anything. let expr = parseBinaryExpressionOrHigher(/*precedence:*/ 0); @@ -2918,12 +2918,12 @@ module ts { // To avoid a look-ahead, we did not handle the case of an arrow function with a single un-parenthesized // parameter ('x => ...') above. We handle it here by checking if the parsed expression was a single // identifier and the current token is an arrow. - if (expr.kind === SyntaxKind.Identifier && token === SyntaxKind.EqualsGreaterThanToken) { + if (expr.kind === SyntaxKind.Identifier && token === SyntaxKind.EqualsGreaterThanToken && !scanner.hasPrecedingLineBreak()) { return parseSimpleArrowFunctionExpression(expr); } // Now see if we might be in cases '2' or '3'. - // If the expression was a LHS expression, and we have an assignment operator, then + // If the expression was a LHS expression, and we have an assignment operator, then // we're in '2' or '3'. Consume the assignment and return. // // Note: we call reScanGreaterToken so that we get an appropriately merged token @@ -2938,7 +2938,7 @@ module ts { function isYieldExpression(): boolean { if (token === SyntaxKind.YieldKeyword) { - // If we have a 'yield' keyword, and htis is a context where yield expressions are + // If we have a 'yield' keyword, and htis is a context where yield expressions are // allowed, then definitely parse out a yield expression. if (inYieldContext()) { return true; @@ -2953,12 +2953,12 @@ module ts { // We're in a context where 'yield expr' is not allowed. However, if we can // definitely tell that the user was trying to parse a 'yield expr' and not // just a normal expr that start with a 'yield' identifier, then parse out - // a 'yield expr'. We can then report an error later that they are only + // a 'yield expr'. We can then report an error later that they are only // allowed in generator expressions. - // + // // for example, if we see 'yield(foo)', then we'll have to treat that as an // invocation expression of something called 'yield'. However, if we have - // 'yield foo' then that is not legal as a normal expression, so we can + // 'yield foo' then that is not legal as a normal expression, so we can // definitely recognize this as a yield expression. // // for now we just check if the next token is an identifier. More heuristics @@ -2997,7 +2997,7 @@ module ts { return finishNode(node); } else { - // if the next token is not on the same line as yield. or we don't have an '*' or + // if the next token is not on the same line as yield. or we don't have an '*' or // the start of an expressin, then this is just a simple "yield" expression. return finishNode(node); } @@ -3043,7 +3043,7 @@ module ts { return undefined; } - // If we have an arrow, then try to parse the body. Even if not, try to parse if we + // If we have an arrow, then try to parse the body. Even if not, try to parse if we // have an opening brace, just in case we're in an error state. if (parseExpected(SyntaxKind.EqualsGreaterThanToken) || token === SyntaxKind.OpenBraceToken) { arrowFunction.body = parseArrowFunctionExpressionBody(); @@ -3146,7 +3146,7 @@ module ts { // If we're speculatively parsing a signature for a parenthesized arrow function, then // we have to have a complete parameter list. Otherwise we might see something like // a => (b => c) - // And think that "(b =>" was actually a parenthesized arrow function with a missing + // And think that "(b =>" was actually a parenthesized arrow function with a missing // close paren. fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext:*/ false, /*requireCompleteParameterList:*/ !allowAmbiguity, node); @@ -3168,6 +3168,11 @@ module ts { return undefined; } + // Must be no line terminator before token `=>`. + if (scanner.hasPrecedingLineBreak()) { + return undefined; + } + return node; } @@ -3179,7 +3184,7 @@ module ts { if (isStartOfStatement(/*inErrorRecovery:*/ true) && !isStartOfExpressionStatement() && token !== SyntaxKind.FunctionKeyword) { // Check if we got a plain statement (i.e. no expression-statements, no functions expressions/declarations) // - // Here we try to recover from a potential error situation in the case where the + // Here we try to recover from a potential error situation in the case where the // user meant to supply a block. For example, if the user wrote: // // a => @@ -3204,10 +3209,10 @@ module ts { return leftOperand; } - // Note: we explicitly 'allowIn' in the whenTrue part of the condition expression, and - // we do not that for the 'whenFalse' part. + // Note: we explicitly 'allowIn' in the whenTrue part of the condition expression, and + // we do not that for the 'whenFalse' part. let node = createNode(SyntaxKind.ConditionalExpression, leftOperand.pos); - node.condition = leftOperand; + node.condition = leftOperand; node.questionToken = questionToken; node.whenTrue = allowInAnd(parseAssignmentExpressionOrHigher); node.colonToken = parseExpectedToken(SyntaxKind.ColonToken, /*reportAtCurrentPosition:*/ false, @@ -3227,7 +3232,7 @@ module ts { function parseBinaryExpressionRest(precedence: number, leftOperand: Expression): Expression { while (true) { - // We either have a binary operator here, or we're finished. We call + // We either have a binary operator here, or we're finished. We call // reScanGreaterToken so that we merge token sequences like > and = into >= reScanGreaterToken(); @@ -3374,15 +3379,15 @@ module ts { function parseLeftHandSideExpressionOrHigher(): LeftHandSideExpression { // Original Ecma: - // LeftHandSideExpression: See 11.2 + // LeftHandSideExpression: See 11.2 // NewExpression - // CallExpression + // CallExpression // // Our simplification: // - // LeftHandSideExpression: See 11.2 - // MemberExpression - // CallExpression + // LeftHandSideExpression: See 11.2 + // MemberExpression + // CallExpression // // See comment in parseMemberExpressionOrHigher on how we replaced NewExpression with // MemberExpression to make our lives easier. @@ -3391,14 +3396,14 @@ module ts { // out into its own productions: // // CallExpression: - // MemberExpression Arguments + // MemberExpression Arguments // CallExpression Arguments // CallExpression[Expression] // CallExpression.IdentifierName // super ( ArgumentListopt ) // super.IdentifierName // - // Because of the recursion in these calls, we need to bottom out first. There are two + // Because of the recursion in these calls, we need to bottom out first. There are two // bottom out states we can run into. Either we see 'super' which must start either of // the last two CallExpression productions. Or we have a MemberExpression which either // completes the LeftHandSideExpression, or starts the beginning of the first four @@ -3407,7 +3412,7 @@ module ts { ? parseSuperExpression() : parseMemberExpressionOrHigher(); - // Now, we *may* be complete. However, we might have consumed the start of a + // Now, we *may* be complete. However, we might have consumed the start of a // CallExpression. As such, we need to consume the rest of it here to be complete. return parseCallExpressionRest(expression); } @@ -3417,39 +3422,39 @@ module ts { // place ObjectCreationExpression and FunctionExpression into PrimaryExpression. // like so: // - // PrimaryExpression : See 11.1 + // PrimaryExpression : See 11.1 // this // Identifier // Literal // ArrayLiteral // ObjectLiteral - // (Expression) + // (Expression) // FunctionExpression // new MemberExpression Arguments? // - // MemberExpression : See 11.2 - // PrimaryExpression + // MemberExpression : See 11.2 + // PrimaryExpression // MemberExpression[Expression] // MemberExpression.IdentifierName // - // CallExpression : See 11.2 - // MemberExpression + // CallExpression : See 11.2 + // MemberExpression // CallExpression Arguments // CallExpression[Expression] - // CallExpression.IdentifierName + // CallExpression.IdentifierName // // Technically this is ambiguous. i.e. CallExpression defines: // // CallExpression: // CallExpression Arguments - // + // // If you see: "new Foo()" // - // Then that could be treated as a single ObjectCreationExpression, or it could be + // Then that could be treated as a single ObjectCreationExpression, or it could be // treated as the invocation of "new Foo". We disambiguate that in code (to match // the original grammar) by making sure that if we see an ObjectCreationExpression // we always consume arguments if they are there. So we treat "new Foo()" as an - // object creation only, and not at all as an invocation) Another way to think + // object creation only, and not at all as an invocation) Another way to think // about this is that for every "new" that we see, we will consume an argument list if // it is there as part of the *associated* object creation node. Any additional // argument lists we see, will become invocation expressions. @@ -3539,7 +3544,7 @@ module ts { if (token === SyntaxKind.LessThanToken) { // See if this is the start of a generic invocation. If so, consume it and - // keep checking for postfix expressions. Otherwise, it's just a '<' that's + // keep checking for postfix expressions. Otherwise, it's just a '<' that's // part of an arithmetic expression. Break out so we consume it higher in the // stack. let typeArguments = tryParse(parseTypeArgumentsInExpression); @@ -3593,8 +3598,8 @@ module ts { function canFollowTypeArgumentsInExpression(): boolean { switch (token) { - case SyntaxKind.OpenParenToken: // foo( - // this case are the only case where this token can legally follow a type argument + case SyntaxKind.OpenParenToken: // foo( + // this case are the only case where this token can legally follow a type argument // list. So we definitely want to treat this as a type arg list. case SyntaxKind.DotToken: // foo. @@ -3615,7 +3620,7 @@ module ts { case SyntaxKind.BarToken: // foo | case SyntaxKind.CloseBraceToken: // foo } case SyntaxKind.EndOfFileToken: // foo - // these cases can't legally follow a type arg list. However, they're not legal + // these cases can't legally follow a type arg list. However, they're not legal // expressions either. The user is probably in the middle of a generic type. So // treat it as such. return true; @@ -3836,7 +3841,7 @@ module ts { parseExpected(SyntaxKind.CloseParenToken); // From: https://mail.mozilla.org/pipermail/es-discuss/2011-August/016188.html - // 157 min --- All allen at wirfs-brock.com CONF --- "do{;}while(false)false" prohibited in + // 157 min --- All allen at wirfs-brock.com CONF --- "do{;}while(false)false" prohibited in // spec but allowed in consensus reality. Approved -- this is the de-facto standard whereby // do;while(0)x will have a semicolon inserted before x. parseOptional(SyntaxKind.SemicolonToken); @@ -3974,9 +3979,9 @@ module ts { // ThrowStatement[Yield] : // throw [no LineTerminator here]Expression[In, ?Yield]; - // Because of automatic semicolon insertion, we need to report error if this + // Because of automatic semicolon insertion, we need to report error if this // throw could be terminated with a semicolon. Note: we can't call 'parseExpression' - // directly as that might consume an expression on the following line. + // directly as that might consume an expression on the following line. // We just return 'undefined' in that case. The actual error will be reported in the // grammar walker. let node = createNode(SyntaxKind.ThrowStatement); @@ -4046,9 +4051,9 @@ module ts { function isStartOfStatement(inErrorRecovery: boolean): boolean { // Functions and variable statements are allowed as a statement. But as per the grammar, - // they also allow modifiers. So we have to check for those statements that might be - // following modifiers.This ensures that things work properly when incrementally parsing - // as the parser will produce the same FunctionDeclaraiton or VariableStatement if it has + // they also allow modifiers. So we have to check for those statements that might be + // following modifiers.This ensures that things work properly when incrementally parsing + // as the parser will produce the same FunctionDeclaraiton or VariableStatement if it has // the same text regardless of whether it is inside a block or not. if (isModifier(token)) { let result = lookAhead(parseVariableStatementOrFunctionDeclarationWithModifiers); @@ -4134,7 +4139,7 @@ module ts { return parseBlock(/*ignoreMissingOpenBrace:*/ false, /*checkForStrictMode:*/ false); case SyntaxKind.VarKeyword: case SyntaxKind.ConstKeyword: - // const here should always be parsed as const declaration because of check in 'isStatement' + // const here should always be parsed as const declaration because of check in 'isStatement' return parseVariableStatement(scanner.getStartPos(), /*modifiers:*/ undefined); case SyntaxKind.FunctionKeyword: return parseFunctionDeclaration(scanner.getStartPos(), /*modifiers:*/ undefined); @@ -4174,8 +4179,8 @@ module ts { } // Else parse it like identifier - fall through default: - // Functions and variable statements are allowed as a statement. But as per - // the grammar, they also allow modifiers. So we have to check for those + // Functions and variable statements are allowed as a statement. But as per + // the grammar, they also allow modifiers. So we have to check for those // statements that might be following modifiers. This ensures that things // work properly when incrementally parsing as the parser will produce the // same FunctionDeclaraiton or VariableStatement if it has the same text @@ -4336,7 +4341,7 @@ module ts { return finishNode(node); } - + function canFollowContextualOfKeyword(): boolean { return nextTokenIsIdentifier() && nextToken() === SyntaxKind.CloseParenToken; } @@ -4439,7 +4444,7 @@ module ts { if (token === SyntaxKind.OpenBracketToken) { return true; } - + // If we were able to get any potential identifier... if (idToken !== undefined) { // If we have a non-keyword identifier, or if we have an accessor, then it's safe to parse. @@ -4718,7 +4723,7 @@ module ts { // import ImportClause from ModuleSpecifier ; // import ModuleSpecifier; if (identifier || // import id - token === SyntaxKind.AsteriskToken || // import * + token === SyntaxKind.AsteriskToken || // import * token === SyntaxKind.OpenBraceToken) { // import { importDeclaration.importClause = parseImportClause(identifier, afterImportPos); parseExpected(SyntaxKind.FromKeyword); @@ -4744,7 +4749,7 @@ module ts { importClause.name = identifier; } - // If there was no default import or if there is comma token after default import + // If there was no default import or if there is comma token after default import // parse namespace or named imports if (!importClause.name || parseOptional(SyntaxKind.CommaToken)) { @@ -4770,12 +4775,12 @@ module ts { } function parseModuleSpecifier(): Expression { - // We allow arbitrary expressions here, even though the grammar only allows string + // We allow arbitrary expressions here, even though the grammar only allows string // literals. We check to ensure that it is only a string literal later in the grammar // walker. let result = parseExpression(); - // Ensure the string being required is in our 'identifier' table. This will ensure - // that features like 'find refs' will look inside this file when search for its name. + // Ensure the string being required is in our 'identifier' table. This will ensure + // that features like 'find refs' will look inside this file when search for its name. if (result.kind === SyntaxKind.StringLiteral) { internIdentifier((result).text); } @@ -5013,8 +5018,8 @@ module ts { let amdDependencies: {path: string; name: string}[] = []; let amdModuleName: string; - // Keep scanning all the leading trivia in the file until we get to something that - // isn't trivia. Any single line comment will be analyzed to see if it is a + // Keep scanning all the leading trivia in the file until we get to something that + // isn't trivia. Any single line comment will be analyzed to see if it is a // reference comment. while (true) { let kind = triviaScanner.scan(); diff --git a/tests/baselines/reference/disallowLineTerminatorBeforeArrow.errors.txt b/tests/baselines/reference/disallowLineTerminatorBeforeArrow.errors.txt new file mode 100644 index 0000000000000..0450903f7174c --- /dev/null +++ b/tests/baselines/reference/disallowLineTerminatorBeforeArrow.errors.txt @@ -0,0 +1,70 @@ +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(2,5): error TS1109: Expression expected. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(4,7): error TS1109: Expression expected. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(6,5): error TS1109: Expression expected. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(8,7): error TS1109: Expression expected. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(10,5): error TS1109: Expression expected. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(12,7): error TS1109: Expression expected. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(14,5): error TS1109: Expression expected. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(16,7): error TS1109: Expression expected. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(19,1): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(20,5): error TS1109: Expression expected. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(21,1): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(22,5): error TS1109: Expression expected. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(22,17): error TS1005: ':' expected. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(22,22): error TS1005: ',' expected. + + +==== tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts (14 errors) ==== + var f1 = () + => { } + ~~ +!!! error TS1109: Expression expected. + var f2 = (x: string, y: string) /* + */ => { } + ~~ +!!! error TS1109: Expression expected. + var f3 = (x: string, y: number, ...rest) + => { } + ~~ +!!! error TS1109: Expression expected. + var f4 = (x: string, y: number, ...rest) /* + */ => { } + ~~ +!!! error TS1109: Expression expected. + var f5 = (...rest) + => { } + ~~ +!!! error TS1109: Expression expected. + var f6 = (...rest) /* + */ => { } + ~~ +!!! error TS1109: Expression expected. + var f7 = (x: string, y: number, z = 10) + => { } + ~~ +!!! error TS1109: Expression expected. + var f8 = (x: string, y: number, z = 10) /* + */ => { } + ~~ +!!! error TS1109: Expression expected. + + function foo(func: () => boolean) { } + foo(() + ~~~~~~ + => true); + ~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + ~~ +!!! error TS1109: Expression expected. + foo(() + ~~~~~~ + => { return false; }); + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + ~~ +!!! error TS1109: Expression expected. + ~~~~~ +!!! error TS1005: ':' expected. + ~ +!!! error TS1005: ',' expected. + \ No newline at end of file diff --git a/tests/baselines/reference/disallowLineTerminatorBeforeArrow.js b/tests/baselines/reference/disallowLineTerminatorBeforeArrow.js new file mode 100644 index 0000000000000..c98b6a89d4f16 --- /dev/null +++ b/tests/baselines/reference/disallowLineTerminatorBeforeArrow.js @@ -0,0 +1,60 @@ +//// [disallowLineTerminatorBeforeArrow.ts] +var f1 = () + => { } +var f2 = (x: string, y: string) /* + */ => { } +var f3 = (x: string, y: number, ...rest) + => { } +var f4 = (x: string, y: number, ...rest) /* + */ => { } +var f5 = (...rest) + => { } +var f6 = (...rest) /* + */ => { } +var f7 = (x: string, y: number, z = 10) + => { } +var f8 = (x: string, y: number, z = 10) /* + */ => { } + +function foo(func: () => boolean) { } +foo(() + => true); +foo(() + => { return false; }); + + +//// [disallowLineTerminatorBeforeArrow.js] +var f1 = ; +{ +} +var f2 = ; /* + */ +{ +} +var f3 = ; +{ +} +var f4 = ; /* + */ +{ +} +var f5 = ; +{ +} +var f6 = ; /* + */ +{ +} +var f7 = ; +{ +} +var f8 = ; /* + */ +{ +} +function foo(func) { +} +foo(, true); +foo(, { + return: false +}); diff --git a/tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts b/tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts new file mode 100644 index 0000000000000..316ff92c56c12 --- /dev/null +++ b/tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts @@ -0,0 +1,22 @@ +var f1 = () + => { } +var f2 = (x: string, y: string) /* + */ => { } +var f3 = (x: string, y: number, ...rest) + => { } +var f4 = (x: string, y: number, ...rest) /* + */ => { } +var f5 = (...rest) + => { } +var f6 = (...rest) /* + */ => { } +var f7 = (x: string, y: number, z = 10) + => { } +var f8 = (x: string, y: number, z = 10) /* + */ => { } + +function foo(func: () => boolean) { } +foo(() + => true); +foo(() + => { return false; }); From dd16fed21e5cf96e87a27ce25c5fe3bdb3ece9f0 Mon Sep 17 00:00:00 2001 From: Caitlin Potter Date: Tue, 10 Mar 2015 17:11:25 -0400 Subject: [PATCH 062/224] Perform error reporting in checker --- src/compiler/checker.ts | 12 ++- .../diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 4 + src/compiler/parser.ts | 14 ++- src/compiler/types.ts | 44 +++++----- .../baselines/reference/APISample_compile.js | 3 + .../reference/APISample_compile.types | 7 ++ tests/baselines/reference/APISample_linter.js | 3 + .../reference/APISample_linter.types | 7 ++ .../reference/APISample_transform.js | 3 + .../reference/APISample_transform.types | 7 ++ .../baselines/reference/APISample_watcher.js | 3 + .../reference/APISample_watcher.types | 7 ++ ...sallowLineTerminatorBeforeArrow.errors.txt | 86 +++++++++---------- .../disallowLineTerminatorBeforeArrow.js | 70 ++++++++------- 15 files changed, 166 insertions(+), 105 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0dacb20ece41c..dae254253ca95 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11377,7 +11377,17 @@ module ts { function checkGrammarFunctionLikeDeclaration(node: FunctionLikeDeclaration): boolean { // Prevent cascading error by short-circuit - return checkGrammarModifiers(node) || checkGrammarTypeParameterList(node, node.typeParameters) || checkGrammarParameterList(node.parameters); + return checkGrammarModifiers(node) || checkGrammarTypeParameterList(node, node.typeParameters) || checkGrammarParameterList(node.parameters) || checkGrammarArrowFunction(node); + } + + function checkGrammarArrowFunction(node: FunctionLikeDeclaration): boolean { + if (node.kind === SyntaxKind.ArrowFunction) { + if ((node).lineTerminatorBeforeArrow) { + grammarErrorOnNode(node, Diagnostics.Line_terminator_not_permitted_before_arrow); + return true; + } + } + return false; } function checkGrammarIndexSignatureParameters(node: SignatureDeclaration): boolean { diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index d40fcd25ce089..556df1565b0f8 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -157,6 +157,7 @@ module ts { Catch_clause_variable_cannot_have_an_initializer: { code: 1197, category: DiagnosticCategory.Error, key: "Catch clause variable cannot have an initializer." }, An_extended_Unicode_escape_value_must_be_between_0x0_and_0x10FFFF_inclusive: { code: 1198, category: DiagnosticCategory.Error, key: "An extended Unicode escape value must be between 0x0 and 0x10FFFF inclusive." }, Unterminated_Unicode_escape_sequence: { code: 1199, category: DiagnosticCategory.Error, key: "Unterminated Unicode escape sequence." }, + Line_terminator_not_permitted_before_arrow: { code: 1200, category: DiagnosticCategory.Error, key: "Line terminator not permitted before arrow." }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index c4121e92251b2..0c00d8c974ce1 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -619,6 +619,10 @@ "category": "Error", "code": 1199 }, + "Line terminator not permitted before arrow.": { + "category": "Error", + "code": 1200 + }, "Duplicate identifier '{0}'.": { "category": "Error", "code": 2300 diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index fc02c3f3eef3f..06655b1d822f3 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -2918,7 +2918,7 @@ module ts { // To avoid a look-ahead, we did not handle the case of an arrow function with a single un-parenthesized // parameter ('x => ...') above. We handle it here by checking if the parsed expression was a single // identifier and the current token is an arrow. - if (expr.kind === SyntaxKind.Identifier && token === SyntaxKind.EqualsGreaterThanToken && !scanner.hasPrecedingLineBreak()) { + if (expr.kind === SyntaxKind.Identifier && token === SyntaxKind.EqualsGreaterThanToken) { return parseSimpleArrowFunctionExpression(expr); } @@ -3007,7 +3007,7 @@ module ts { Debug.assert(token === SyntaxKind.EqualsGreaterThanToken, "parseSimpleArrowFunctionExpression should only have been called if we had a =>"); let node = createNode(SyntaxKind.ArrowFunction, identifier.pos); - + let parameter = createNode(SyntaxKind.Parameter, identifier.pos); parameter.name = identifier; finishNode(parameter); @@ -3016,6 +3016,7 @@ module ts { node.parameters.pos = parameter.pos; node.parameters.end = parameter.end; + node.lineTerminatorBeforeArrow = scanner.hasPrecedingLineBreak(); parseExpected(SyntaxKind.EqualsGreaterThanToken); node.body = parseArrowFunctionExpressionBody(); @@ -3140,8 +3141,8 @@ module ts { } function parseParenthesizedArrowFunctionExpressionHead(allowAmbiguity: boolean): FunctionExpression { - let node = createNode(SyntaxKind.ArrowFunction); - // Arrow functions are never generators. + let node = createNode(SyntaxKind.ArrowFunction); + // Arrow functions are never generators. // // If we're speculatively parsing a signature for a parenthesized arrow function, then // we have to have a complete parameter list. Otherwise we might see something like @@ -3168,10 +3169,7 @@ module ts { return undefined; } - // Must be no line terminator before token `=>`. - if (scanner.hasPrecedingLineBreak()) { - return undefined; - } + node.lineTerminatorBeforeArrow = scanner.hasPrecedingLineBreak(); return node; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index c43591911abd4..56820a10924f5 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -329,7 +329,7 @@ module ts { // If the parser encountered an error when parsing the code that created this node. Note // the parser only sets this directly on the node it creates right after encountering the - // error. + // error. ThisNodeHasError = 1 << 4, // Context flags set directly by the parser. @@ -337,7 +337,7 @@ module ts { // Context flags computed by aggregating child flags upwards. - // Used during incremental parsing to determine if this node or any of its children had an + // Used during incremental parsing to determine if this node or any of its children had an // error. Computed only once and then cached. ThisNodeOrAnySubNodesHasError = 1 << 5, @@ -354,7 +354,7 @@ module ts { export interface Node extends TextRange { kind: SyntaxKind; flags: NodeFlags; - // Specific context the parser was in when this node was created. Normally undefined. + // Specific context the parser was in when this node was created. Normally undefined. // Only set when the parser was in some interesting context (like async/yield). parserContextFlags?: ParserContextFlags; modifiers?: ModifiersArray; // Array of modifiers @@ -524,7 +524,7 @@ module ts { body?: Block; } - // See the comment on MethodDeclaration for the intuition behind AccessorDeclaration being a + // See the comment on MethodDeclaration for the intuition behind AccessorDeclaration being a // ClassElement and an ObjectLiteralElement. export interface AccessorDeclaration extends FunctionLikeDeclaration, ClassElement, ObjectLiteralElement { _accessorDeclarationBrand: any; @@ -575,12 +575,12 @@ module ts { export interface StringLiteralTypeNode extends LiteralExpression, TypeNode { } - // Note: 'brands' in our syntax nodes serve to give us a small amount of nominal typing. + // Note: 'brands' in our syntax nodes serve to give us a small amount of nominal typing. // Consider 'Expression'. Without the brand, 'Expression' is actually no different // (structurally) than 'Node'. Because of this you can pass any Node to a function that // takes an Expression without any error. By using the 'brands' we ensure that the type - // checker actually thinks you have something of the right type. Note: the brands are - // never actually given values. At runtime they have zero cost. + // checker actually thinks you have something of the right type. Note: the brands are + // never actually given values. At runtime they have zero cost. export interface Expression extends Node { _expressionBrand: any; @@ -653,6 +653,10 @@ module ts { body: Block | Expression; // Required, whereas the member inherited from FunctionDeclaration is optional } + export interface ArrowFunctionExpression extends FunctionExpression { + lineTerminatorBeforeArrow: boolean; + } + // The text property of a LiteralExpression stores the interpreted value of the literal in text form. For a StringLiteral, // or any literal of a template, this means quotes have been removed and escapes have been converted to actual characters. // For a NumericLiteral, the stored value is the toString() representation of the number. For example 1, 1.00, and 1e0 are all stored as just "1". @@ -735,7 +739,7 @@ module ts { } export interface VariableStatement extends Statement { - declarationList: VariableDeclarationList; + declarationList: VariableDeclarationList; } export interface ExpressionStatement extends Statement { @@ -903,7 +907,7 @@ module ts { moduleSpecifier: Expression; } - // In case of: + // In case of: // import d from "mod" => name = d, namedBinding = undefined // import * as ns from "mod" => name = undefined, namedBinding: NamespaceImport = { name: ns } // import d, * as ns from "mod" => name = d, namedBinding: NamespaceImport = { name: ns } @@ -969,7 +973,7 @@ module ts { externalModuleIndicator: Node; languageVersion: ScriptTarget; identifiers: Map; - + /* @internal */ nodeCount: number; /* @internal */ identifierCount: number; /* @internal */ symbolCount: number; @@ -977,10 +981,10 @@ module ts { // File level diagnostics reported by the parser (includes diagnostics about /// references // as well as code diagnostics). /* @internal */ parseDiagnostics: Diagnostic[]; - + // File level diagnostics reported by the binder. /* @internal */ bindDiagnostics: Diagnostic[]; - + // Stores a line map for the file. // This field should never be used directly to obtain line map, use getLineMap function instead. /* @internal */ lineMap: number[]; @@ -1000,10 +1004,10 @@ module ts { getSourceFiles(): SourceFile[]; /** - * Emits the javascript and declaration files. If targetSourceFile is not specified, then + * Emits the javascript and declaration files. If targetSourceFile is not specified, then * the javascript and declaration files will be produced for all the files in this program. * If targetSourceFile is specified, then only the javascript and declaration for that - * specific file will be generated. + * specific file will be generated. * * If writeFile is not specified then the writeFile callback from the compiler host will be * used for writing the javascript and declaration files. Otherwise, the writeFile parameter @@ -1021,7 +1025,7 @@ module ts { getCommonSourceDirectory(): string; - // For testing purposes only. Should not be used by any other consumers (including the + // For testing purposes only. Should not be used by any other consumers (including the // language service). /* @internal */ getDiagnosticsProducingTypeChecker(): TypeChecker; @@ -1058,7 +1062,7 @@ module ts { // when -version or -help was provided, or this was a normal compilation, no diagnostics // were produced, and all outputs were generated successfully. Success = 0, - + // Diagnostics were produced and because of them no code was generated. DiagnosticsPresent_OutputsSkipped = 1, @@ -1168,12 +1172,12 @@ module ts { // Write symbols's type argument if it is instantiated symbol // eg. class C { p: T } <-- Show p as C.p here - // var a: C; + // var a: C; // var p = a.p; <--- Here p is property of C so show it as C.p instead of just C.p - WriteTypeParametersOrArguments = 0x00000001, + WriteTypeParametersOrArguments = 0x00000001, // Use only external alias information to get the symbol name in the given context - // eg. module m { export class c { } } import x = m.c; + // eg. module m { export class c { } } import x = m.c; // When this flag is specified m.c will be used to refer to the class instead of alias symbol x UseOnlyExternalAliasing = 0x00000002, } @@ -1778,7 +1782,7 @@ module ts { // Gets a count of how many times this collection has been modified. This value changes // each time 'add' is called (regardless of whether or not an equivalent diagnostic was // already in the collection). As such, it can be used as a simple way to tell if any - // operation caused diagnostics to be returned by storing and comparing the return value + // operation caused diagnostics to be returned by storing and comparing the return value // of this method before/after the operation is performed. getModificationCount(): number; } diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index 985718231810c..316649a35c978 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -553,6 +553,9 @@ declare module "typescript" { name?: Identifier; body: Block | Expression; } + interface ArrowFunctionExpression extends FunctionExpression { + lineTerminatorBeforeArrow: boolean; + } interface LiteralExpression extends PrimaryExpression { text: string; isUnterminated?: boolean; diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index 087c0389d0fce..bf51bb946c015 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -1668,6 +1668,13 @@ declare module "typescript" { >body : Expression | Block >Block : Block >Expression : Expression + } + interface ArrowFunctionExpression extends FunctionExpression { +>ArrowFunctionExpression : ArrowFunctionExpression +>FunctionExpression : FunctionExpression + + lineTerminatorBeforeArrow: boolean; +>lineTerminatorBeforeArrow : boolean } interface LiteralExpression extends PrimaryExpression { >LiteralExpression : LiteralExpression diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index d43d622007210..5f7dc308820c8 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -584,6 +584,9 @@ declare module "typescript" { name?: Identifier; body: Block | Expression; } + interface ArrowFunctionExpression extends FunctionExpression { + lineTerminatorBeforeArrow: boolean; + } interface LiteralExpression extends PrimaryExpression { text: string; isUnterminated?: boolean; diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index 14eb2936242bd..ede73749eb018 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -1814,6 +1814,13 @@ declare module "typescript" { >body : Expression | Block >Block : Block >Expression : Expression + } + interface ArrowFunctionExpression extends FunctionExpression { +>ArrowFunctionExpression : ArrowFunctionExpression +>FunctionExpression : FunctionExpression + + lineTerminatorBeforeArrow: boolean; +>lineTerminatorBeforeArrow : boolean } interface LiteralExpression extends PrimaryExpression { >LiteralExpression : LiteralExpression diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index bfe62135a0db3..2d39e9a3c0c38 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -585,6 +585,9 @@ declare module "typescript" { name?: Identifier; body: Block | Expression; } + interface ArrowFunctionExpression extends FunctionExpression { + lineTerminatorBeforeArrow: boolean; + } interface LiteralExpression extends PrimaryExpression { text: string; isUnterminated?: boolean; diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index baa497c95fa50..d9d1482fbc874 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -1764,6 +1764,13 @@ declare module "typescript" { >body : Expression | Block >Block : Block >Expression : Expression + } + interface ArrowFunctionExpression extends FunctionExpression { +>ArrowFunctionExpression : ArrowFunctionExpression +>FunctionExpression : FunctionExpression + + lineTerminatorBeforeArrow: boolean; +>lineTerminatorBeforeArrow : boolean } interface LiteralExpression extends PrimaryExpression { >LiteralExpression : LiteralExpression diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index ee1fd06251576..7fa2a92afae9e 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -622,6 +622,9 @@ declare module "typescript" { name?: Identifier; body: Block | Expression; } + interface ArrowFunctionExpression extends FunctionExpression { + lineTerminatorBeforeArrow: boolean; + } interface LiteralExpression extends PrimaryExpression { text: string; isUnterminated?: boolean; diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index a8b534439d546..23f7ffb714899 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -1937,6 +1937,13 @@ declare module "typescript" { >body : Expression | Block >Block : Block >Expression : Expression + } + interface ArrowFunctionExpression extends FunctionExpression { +>ArrowFunctionExpression : ArrowFunctionExpression +>FunctionExpression : FunctionExpression + + lineTerminatorBeforeArrow: boolean; +>lineTerminatorBeforeArrow : boolean } interface LiteralExpression extends PrimaryExpression { >LiteralExpression : LiteralExpression diff --git a/tests/baselines/reference/disallowLineTerminatorBeforeArrow.errors.txt b/tests/baselines/reference/disallowLineTerminatorBeforeArrow.errors.txt index 0450903f7174c..c64d42b7fffd2 100644 --- a/tests/baselines/reference/disallowLineTerminatorBeforeArrow.errors.txt +++ b/tests/baselines/reference/disallowLineTerminatorBeforeArrow.errors.txt @@ -1,70 +1,66 @@ -tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(2,5): error TS1109: Expression expected. -tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(4,7): error TS1109: Expression expected. -tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(6,5): error TS1109: Expression expected. -tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(8,7): error TS1109: Expression expected. -tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(10,5): error TS1109: Expression expected. -tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(12,7): error TS1109: Expression expected. -tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(14,5): error TS1109: Expression expected. -tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(16,7): error TS1109: Expression expected. -tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(19,1): error TS2346: Supplied parameters do not match any signature of call target. -tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(20,5): error TS1109: Expression expected. -tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(21,1): error TS2346: Supplied parameters do not match any signature of call target. -tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(22,5): error TS1109: Expression expected. -tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(22,17): error TS1005: ':' expected. -tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(22,22): error TS1005: ',' expected. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(1,10): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(3,10): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(5,10): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(7,10): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(9,10): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(11,10): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(13,10): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(15,10): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(19,5): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(21,5): error TS1200: Line terminator not permitted before arrow. -==== tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts (14 errors) ==== +==== tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts (10 errors) ==== var f1 = () + ~~ => { } - ~~ -!!! error TS1109: Expression expected. + ~~~~~~~~~~ +!!! error TS1200: Line terminator not permitted before arrow. var f2 = (x: string, y: string) /* + ~~~~~~~~~~~~~~~~~~~~~~~~~ */ => { } - ~~ -!!! error TS1109: Expression expected. + ~~~~~~~~~~~~ +!!! error TS1200: Line terminator not permitted before arrow. var f3 = (x: string, y: number, ...rest) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => { } - ~~ -!!! error TS1109: Expression expected. + ~~~~~~~~~~ +!!! error TS1200: Line terminator not permitted before arrow. var f4 = (x: string, y: number, ...rest) /* + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ => { } - ~~ -!!! error TS1109: Expression expected. + ~~~~~~~~~~~~ +!!! error TS1200: Line terminator not permitted before arrow. var f5 = (...rest) + ~~~~~~~~~ => { } - ~~ -!!! error TS1109: Expression expected. + ~~~~~~~~~~ +!!! error TS1200: Line terminator not permitted before arrow. var f6 = (...rest) /* + ~~~~~~~~~~~~ */ => { } - ~~ -!!! error TS1109: Expression expected. + ~~~~~~~~~~~~ +!!! error TS1200: Line terminator not permitted before arrow. var f7 = (x: string, y: number, z = 10) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => { } - ~~ -!!! error TS1109: Expression expected. + ~~~~~~~~~~ +!!! error TS1200: Line terminator not permitted before arrow. var f8 = (x: string, y: number, z = 10) /* + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ => { } - ~~ -!!! error TS1109: Expression expected. + ~~~~~~~~~~~~ +!!! error TS1200: Line terminator not permitted before arrow. function foo(func: () => boolean) { } foo(() - ~~~~~~ - => true); - ~~~~~~~~~~~~ -!!! error TS2346: Supplied parameters do not match any signature of call target. ~~ -!!! error TS1109: Expression expected. + => true); + ~~~~~~~~~~~ +!!! error TS1200: Line terminator not permitted before arrow. foo(() - ~~~~~~ - => { return false; }); - ~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2346: Supplied parameters do not match any signature of call target. ~~ -!!! error TS1109: Expression expected. - ~~~~~ -!!! error TS1005: ':' expected. - ~ -!!! error TS1005: ',' expected. + => { return false; }); + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1200: Line terminator not permitted before arrow. \ No newline at end of file diff --git a/tests/baselines/reference/disallowLineTerminatorBeforeArrow.js b/tests/baselines/reference/disallowLineTerminatorBeforeArrow.js index c98b6a89d4f16..2619b41bf3881 100644 --- a/tests/baselines/reference/disallowLineTerminatorBeforeArrow.js +++ b/tests/baselines/reference/disallowLineTerminatorBeforeArrow.js @@ -24,37 +24,45 @@ foo(() //// [disallowLineTerminatorBeforeArrow.js] -var f1 = ; -{ -} -var f2 = ; /* - */ -{ -} -var f3 = ; -{ -} -var f4 = ; /* - */ -{ -} -var f5 = ; -{ -} -var f6 = ; /* - */ -{ -} -var f7 = ; -{ -} -var f8 = ; /* - */ -{ -} +var f1 = function () { +}; +var f2 = function (x, y) { +}; +var f3 = function (x, y) { + var rest = []; + for (var _i = 2; _i < arguments.length; _i++) { + rest[_i - 2] = arguments[_i]; + } +}; +var f4 = function (x, y) { + var rest = []; + for (var _i = 2; _i < arguments.length; _i++) { + rest[_i - 2] = arguments[_i]; + } +}; +var f5 = function () { + var rest = []; + for (var _i = 0; _i < arguments.length; _i++) { + rest[_i - 0] = arguments[_i]; + } +}; +var f6 = function () { + var rest = []; + for (var _i = 0; _i < arguments.length; _i++) { + rest[_i - 0] = arguments[_i]; + } +}; +var f7 = function (x, y, z) { + if (z === void 0) { z = 10; } +}; +var f8 = function (x, y, z) { + if (z === void 0) { z = 10; } +}; function foo(func) { } -foo(, true); -foo(, { - return: false +foo(function () { + return true; +}); +foo(function () { + return false; }); From 231f522d8967dd103246ed4f7aeb2048b7ffff64 Mon Sep 17 00:00:00 2001 From: Caitlin Potter Date: Tue, 10 Mar 2015 17:20:28 -0400 Subject: [PATCH 063/224] Add additional test-cases for arrow function grammar As suggested by @DanielRosenwasser --- ...sallowLineTerminatorBeforeArrow.errors.txt | 37 +++++++++++++++- .../disallowLineTerminatorBeforeArrow.js | 42 +++++++++++++++++++ .../disallowLineTerminatorBeforeArrow.ts | 19 +++++++++ 3 files changed, 97 insertions(+), 1 deletion(-) diff --git a/tests/baselines/reference/disallowLineTerminatorBeforeArrow.errors.txt b/tests/baselines/reference/disallowLineTerminatorBeforeArrow.errors.txt index c64d42b7fffd2..e9f079985048a 100644 --- a/tests/baselines/reference/disallowLineTerminatorBeforeArrow.errors.txt +++ b/tests/baselines/reference/disallowLineTerminatorBeforeArrow.errors.txt @@ -8,9 +8,13 @@ tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(1 tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(15,10): error TS1200: Line terminator not permitted before arrow. tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(19,5): error TS1200: Line terminator not permitted before arrow. tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(21,5): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(26,40): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(30,20): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(35,17): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(39,20): error TS1200: Line terminator not permitted before arrow. -==== tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts (10 errors) ==== +==== tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts (14 errors) ==== var f1 = () ~~ => { } @@ -63,4 +67,35 @@ tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(2 => { return false; }); ~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS1200: Line terminator not permitted before arrow. + + module m { + class City { + constructor(x: number, thing = () + ~~ + => 100) { + ~~~~~~~~~~~~~~~~~~ +!!! error TS1200: Line terminator not permitted before arrow. + } + + public m = () + ~~ + => 2 * 2 * 2 + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1200: Line terminator not permitted before arrow. + } + + export enum Enum { + claw = (() + ~~ + => 10)() + ~~~~~~~~~~~~~~~~~ +!!! error TS1200: Line terminator not permitted before arrow. + } + + export var v = x + ~ + => new City(Enum.claw); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1200: Line terminator not permitted before arrow. + } \ No newline at end of file diff --git a/tests/baselines/reference/disallowLineTerminatorBeforeArrow.js b/tests/baselines/reference/disallowLineTerminatorBeforeArrow.js index 2619b41bf3881..122c229d7d948 100644 --- a/tests/baselines/reference/disallowLineTerminatorBeforeArrow.js +++ b/tests/baselines/reference/disallowLineTerminatorBeforeArrow.js @@ -21,6 +21,25 @@ foo(() => true); foo(() => { return false; }); + +module m { + class City { + constructor(x: number, thing = () + => 100) { + } + + public m = () + => 2 * 2 * 2 + } + + export enum Enum { + claw = (() + => 10)() + } + + export var v = x + => new City(Enum.claw); +} //// [disallowLineTerminatorBeforeArrow.js] @@ -66,3 +85,26 @@ foo(function () { foo(function () { return false; }); +var m; +(function (m) { + var City = (function () { + function City(x, thing) { + if (thing === void 0) { thing = function () { + return 100; + }; } + this.m = function () { + return 2 * 2 * 2; + }; + } + return City; + })(); + (function (Enum) { + Enum[Enum["claw"] = (function () { + return 10; + })()] = "claw"; + })(m.Enum || (m.Enum = {})); + var Enum = m.Enum; + m.v = function (x) { + return new City(Enum.claw); + }; +})(m || (m = {})); diff --git a/tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts b/tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts index 316ff92c56c12..f11fed6b47813 100644 --- a/tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts +++ b/tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts @@ -20,3 +20,22 @@ foo(() => true); foo(() => { return false; }); + +module m { + class City { + constructor(x: number, thing = () + => 100) { + } + + public m = () + => 2 * 2 * 2 + } + + export enum Enum { + claw = (() + => 10)() + } + + export var v = x + => new City(Enum.claw); +} From aa3cefb63d75ec91b50717ffb41e994b6dd0b3f6 Mon Sep 17 00:00:00 2001 From: Caitlin Potter Date: Tue, 10 Mar 2015 20:59:16 -0400 Subject: [PATCH 064/224] Check that arrow is on same line as parameters --- src/compiler/checker.ts | 11 +-- src/compiler/parser.ts | 19 ++--- src/compiler/types.ts | 4 +- .../baselines/reference/APISample_compile.js | 4 +- .../reference/APISample_compile.types | 12 ++-- tests/baselines/reference/APISample_linter.js | 4 +- .../reference/APISample_linter.types | 12 ++-- .../reference/APISample_transform.js | 4 +- .../reference/APISample_transform.types | 12 ++-- .../baselines/reference/APISample_watcher.js | 4 +- .../reference/APISample_watcher.types | 12 ++-- ...sallowLineTerminatorBeforeArrow.errors.txt | 70 ++++++++----------- 12 files changed, 82 insertions(+), 86 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index dae254253ca95..8322bb7c5d3cd 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11381,11 +11381,12 @@ module ts { } function checkGrammarArrowFunction(node: FunctionLikeDeclaration): boolean { - if (node.kind === SyntaxKind.ArrowFunction) { - if ((node).lineTerminatorBeforeArrow) { - grammarErrorOnNode(node, Diagnostics.Line_terminator_not_permitted_before_arrow); - return true; - } + if (node.kind === SyntaxKind.ArrowFunction && (node).arrow) { + var arrowFunction = node; + var sourceFile = getSourceFileOfNode(node); + if (getLineAndCharacterOfPosition(sourceFile, getTokenPosOfNode(arrowFunction.arrow, sourceFile)).line !== getLineAndCharacterOfPosition(sourceFile, arrowFunction.parameters.end).line) { + return grammarErrorOnNode(arrowFunction.arrow, Diagnostics.Line_terminator_not_permitted_before_arrow); + } } return false; } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 06655b1d822f3..6b010f584a2a8 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -95,6 +95,7 @@ module ts { visitNodes(cbNodes, (node).typeParameters) || visitNodes(cbNodes, (node).parameters) || visitNode(cbNode, (node).type) || + visitNode(cbNode, (node).arrow) || visitNode(cbNode, (node).body); case SyntaxKind.TypeReference: return visitNode(cbNode, (node).typeName) || @@ -3006,18 +3007,19 @@ module ts { function parseSimpleArrowFunctionExpression(identifier: Identifier): Expression { Debug.assert(token === SyntaxKind.EqualsGreaterThanToken, "parseSimpleArrowFunctionExpression should only have been called if we had a =>"); - let node = createNode(SyntaxKind.ArrowFunction, identifier.pos); + let node = createNode(SyntaxKind.ArrowFunction, identifier.pos); let parameter = createNode(SyntaxKind.Parameter, identifier.pos); - parameter.name = identifier; + parameter.name = identifier; finishNode(parameter); node.parameters = >[parameter]; node.parameters.pos = parameter.pos; node.parameters.end = parameter.end; - node.lineTerminatorBeforeArrow = scanner.hasPrecedingLineBreak(); - parseExpected(SyntaxKind.EqualsGreaterThanToken); + if ((node.arrow = parseExpectedToken(SyntaxKind.EqualsGreaterThanToken, false, Diagnostics._0_expected, "=>"))) { + node.arrow.parent = node; + } node.body = parseArrowFunctionExpressionBody(); return finishNode(node); @@ -3046,7 +3048,8 @@ module ts { // If we have an arrow, then try to parse the body. Even if not, try to parse if we // have an opening brace, just in case we're in an error state. - if (parseExpected(SyntaxKind.EqualsGreaterThanToken) || token === SyntaxKind.OpenBraceToken) { + if ((arrowFunction.arrow = parseExpectedToken(SyntaxKind.EqualsGreaterThanToken, false, Diagnostics._0_expected, "=>")) || token === SyntaxKind.OpenBraceToken) { + arrowFunction.arrow.parent = arrowFunction; arrowFunction.body = parseArrowFunctionExpressionBody(); } else { @@ -3141,9 +3144,9 @@ module ts { } function parseParenthesizedArrowFunctionExpressionHead(allowAmbiguity: boolean): FunctionExpression { - let node = createNode(SyntaxKind.ArrowFunction); + let node = createNode(SyntaxKind.ArrowFunction); // Arrow functions are never generators. - // + // // If we're speculatively parsing a signature for a parenthesized arrow function, then // we have to have a complete parameter list. Otherwise we might see something like // a => (b => c) @@ -3169,8 +3172,6 @@ module ts { return undefined; } - node.lineTerminatorBeforeArrow = scanner.hasPrecedingLineBreak(); - return node; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 56820a10924f5..49529bed9c6c5 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -653,8 +653,8 @@ module ts { body: Block | Expression; // Required, whereas the member inherited from FunctionDeclaration is optional } - export interface ArrowFunctionExpression extends FunctionExpression { - lineTerminatorBeforeArrow: boolean; + export interface ArrowFunction extends Expression, FunctionLikeDeclaration { + arrow: Node; } // The text property of a LiteralExpression stores the interpreted value of the literal in text form. For a StringLiteral, diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index 316649a35c978..997bd2bd33740 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -553,8 +553,8 @@ declare module "typescript" { name?: Identifier; body: Block | Expression; } - interface ArrowFunctionExpression extends FunctionExpression { - lineTerminatorBeforeArrow: boolean; + interface ArrowFunction extends Expression, FunctionLikeDeclaration { + arrow: Node; } interface LiteralExpression extends PrimaryExpression { text: string; diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index bf51bb946c015..d91d860ca8f72 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -1669,12 +1669,14 @@ declare module "typescript" { >Block : Block >Expression : Expression } - interface ArrowFunctionExpression extends FunctionExpression { ->ArrowFunctionExpression : ArrowFunctionExpression ->FunctionExpression : FunctionExpression + interface ArrowFunction extends Expression, FunctionLikeDeclaration { +>ArrowFunction : ArrowFunction +>Expression : Expression +>FunctionLikeDeclaration : FunctionLikeDeclaration - lineTerminatorBeforeArrow: boolean; ->lineTerminatorBeforeArrow : boolean + arrow: Node; +>arrow : Node +>Node : Node } interface LiteralExpression extends PrimaryExpression { >LiteralExpression : LiteralExpression diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index 5f7dc308820c8..b941acdbc52ae 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -584,8 +584,8 @@ declare module "typescript" { name?: Identifier; body: Block | Expression; } - interface ArrowFunctionExpression extends FunctionExpression { - lineTerminatorBeforeArrow: boolean; + interface ArrowFunction extends Expression, FunctionLikeDeclaration { + arrow: Node; } interface LiteralExpression extends PrimaryExpression { text: string; diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index ede73749eb018..b8701020e0354 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -1815,12 +1815,14 @@ declare module "typescript" { >Block : Block >Expression : Expression } - interface ArrowFunctionExpression extends FunctionExpression { ->ArrowFunctionExpression : ArrowFunctionExpression ->FunctionExpression : FunctionExpression + interface ArrowFunction extends Expression, FunctionLikeDeclaration { +>ArrowFunction : ArrowFunction +>Expression : Expression +>FunctionLikeDeclaration : FunctionLikeDeclaration - lineTerminatorBeforeArrow: boolean; ->lineTerminatorBeforeArrow : boolean + arrow: Node; +>arrow : Node +>Node : Node } interface LiteralExpression extends PrimaryExpression { >LiteralExpression : LiteralExpression diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index 2d39e9a3c0c38..baf3f9d850318 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -585,8 +585,8 @@ declare module "typescript" { name?: Identifier; body: Block | Expression; } - interface ArrowFunctionExpression extends FunctionExpression { - lineTerminatorBeforeArrow: boolean; + interface ArrowFunction extends Expression, FunctionLikeDeclaration { + arrow: Node; } interface LiteralExpression extends PrimaryExpression { text: string; diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index d9d1482fbc874..d214a6fc959a7 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -1765,12 +1765,14 @@ declare module "typescript" { >Block : Block >Expression : Expression } - interface ArrowFunctionExpression extends FunctionExpression { ->ArrowFunctionExpression : ArrowFunctionExpression ->FunctionExpression : FunctionExpression + interface ArrowFunction extends Expression, FunctionLikeDeclaration { +>ArrowFunction : ArrowFunction +>Expression : Expression +>FunctionLikeDeclaration : FunctionLikeDeclaration - lineTerminatorBeforeArrow: boolean; ->lineTerminatorBeforeArrow : boolean + arrow: Node; +>arrow : Node +>Node : Node } interface LiteralExpression extends PrimaryExpression { >LiteralExpression : LiteralExpression diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index 7fa2a92afae9e..d963aaff481a4 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -622,8 +622,8 @@ declare module "typescript" { name?: Identifier; body: Block | Expression; } - interface ArrowFunctionExpression extends FunctionExpression { - lineTerminatorBeforeArrow: boolean; + interface ArrowFunction extends Expression, FunctionLikeDeclaration { + arrow: Node; } interface LiteralExpression extends PrimaryExpression { text: string; diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index 23f7ffb714899..da00b9bf46631 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -1938,12 +1938,14 @@ declare module "typescript" { >Block : Block >Expression : Expression } - interface ArrowFunctionExpression extends FunctionExpression { ->ArrowFunctionExpression : ArrowFunctionExpression ->FunctionExpression : FunctionExpression + interface ArrowFunction extends Expression, FunctionLikeDeclaration { +>ArrowFunction : ArrowFunction +>Expression : Expression +>FunctionLikeDeclaration : FunctionLikeDeclaration - lineTerminatorBeforeArrow: boolean; ->lineTerminatorBeforeArrow : boolean + arrow: Node; +>arrow : Node +>Node : Node } interface LiteralExpression extends PrimaryExpression { >LiteralExpression : LiteralExpression diff --git a/tests/baselines/reference/disallowLineTerminatorBeforeArrow.errors.txt b/tests/baselines/reference/disallowLineTerminatorBeforeArrow.errors.txt index e9f079985048a..e441752338c12 100644 --- a/tests/baselines/reference/disallowLineTerminatorBeforeArrow.errors.txt +++ b/tests/baselines/reference/disallowLineTerminatorBeforeArrow.errors.txt @@ -1,101 +1,87 @@ -tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(1,10): error TS1200: Line terminator not permitted before arrow. -tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(3,10): error TS1200: Line terminator not permitted before arrow. -tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(5,10): error TS1200: Line terminator not permitted before arrow. -tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(7,10): error TS1200: Line terminator not permitted before arrow. -tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(9,10): error TS1200: Line terminator not permitted before arrow. -tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(11,10): error TS1200: Line terminator not permitted before arrow. -tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(13,10): error TS1200: Line terminator not permitted before arrow. -tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(15,10): error TS1200: Line terminator not permitted before arrow. -tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(19,5): error TS1200: Line terminator not permitted before arrow. -tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(21,5): error TS1200: Line terminator not permitted before arrow. -tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(26,40): error TS1200: Line terminator not permitted before arrow. -tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(30,20): error TS1200: Line terminator not permitted before arrow. -tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(35,17): error TS1200: Line terminator not permitted before arrow. -tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(39,20): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(2,5): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(4,7): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(6,5): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(8,7): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(10,5): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(12,7): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(14,5): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(16,7): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(20,5): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(22,5): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(27,13): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(31,13): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(36,13): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(40,9): error TS1200: Line terminator not permitted before arrow. ==== tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts (14 errors) ==== var f1 = () - ~~ => { } - ~~~~~~~~~~ + ~~ !!! error TS1200: Line terminator not permitted before arrow. var f2 = (x: string, y: string) /* - ~~~~~~~~~~~~~~~~~~~~~~~~~ */ => { } - ~~~~~~~~~~~~ + ~~ !!! error TS1200: Line terminator not permitted before arrow. var f3 = (x: string, y: number, ...rest) - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => { } - ~~~~~~~~~~ + ~~ !!! error TS1200: Line terminator not permitted before arrow. var f4 = (x: string, y: number, ...rest) /* - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ => { } - ~~~~~~~~~~~~ + ~~ !!! error TS1200: Line terminator not permitted before arrow. var f5 = (...rest) - ~~~~~~~~~ => { } - ~~~~~~~~~~ + ~~ !!! error TS1200: Line terminator not permitted before arrow. var f6 = (...rest) /* - ~~~~~~~~~~~~ */ => { } - ~~~~~~~~~~~~ + ~~ !!! error TS1200: Line terminator not permitted before arrow. var f7 = (x: string, y: number, z = 10) - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ => { } - ~~~~~~~~~~ + ~~ !!! error TS1200: Line terminator not permitted before arrow. var f8 = (x: string, y: number, z = 10) /* - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ => { } - ~~~~~~~~~~~~ + ~~ !!! error TS1200: Line terminator not permitted before arrow. function foo(func: () => boolean) { } foo(() - ~~ => true); - ~~~~~~~~~~~ + ~~ !!! error TS1200: Line terminator not permitted before arrow. foo(() - ~~ => { return false; }); - ~~~~~~~~~~~~~~~~~~~~~~~~ + ~~ !!! error TS1200: Line terminator not permitted before arrow. module m { class City { constructor(x: number, thing = () - ~~ => 100) { - ~~~~~~~~~~~~~~~~~~ + ~~ !!! error TS1200: Line terminator not permitted before arrow. } public m = () - ~~ => 2 * 2 * 2 - ~~~~~~~~~~~~~~~~~~~~~~~~ + ~~ !!! error TS1200: Line terminator not permitted before arrow. } export enum Enum { claw = (() - ~~ => 10)() - ~~~~~~~~~~~~~~~~~ + ~~ !!! error TS1200: Line terminator not permitted before arrow. } export var v = x - ~ => new City(Enum.claw); - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~ !!! error TS1200: Line terminator not permitted before arrow. } \ No newline at end of file From fdc673f5eba6d0709a340cd67790e0a670175d89 Mon Sep 17 00:00:00 2001 From: Caitlin Potter Date: Tue, 10 Mar 2015 21:07:05 -0400 Subject: [PATCH 065/224] Fix line wrapping --- src/compiler/checker.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8322bb7c5d3cd..d0c9ff8714009 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11384,7 +11384,8 @@ module ts { if (node.kind === SyntaxKind.ArrowFunction && (node).arrow) { var arrowFunction = node; var sourceFile = getSourceFileOfNode(node); - if (getLineAndCharacterOfPosition(sourceFile, getTokenPosOfNode(arrowFunction.arrow, sourceFile)).line !== getLineAndCharacterOfPosition(sourceFile, arrowFunction.parameters.end).line) { + if (getLineAndCharacterOfPosition(sourceFile, getTokenPosOfNode(arrowFunction.arrow, sourceFile)).line !== + getLineAndCharacterOfPosition(sourceFile, arrowFunction.parameters.end).line) { return grammarErrorOnNode(arrowFunction.arrow, Diagnostics.Line_terminator_not_permitted_before_arrow); } } From 5e107e6042cc83bf7071051631fe4b6c0bd61ae0 Mon Sep 17 00:00:00 2001 From: Caitlin Potter Date: Tue, 10 Mar 2015 21:22:41 -0400 Subject: [PATCH 066/224] Address slew of review comments --- src/compiler/checker.ts | 9 +++++---- src/compiler/parser.ts | 9 +++------ src/compiler/types.ts | 2 +- tests/baselines/reference/APISample_compile.js | 2 +- tests/baselines/reference/APISample_compile.types | 4 ++-- tests/baselines/reference/APISample_linter.js | 2 +- tests/baselines/reference/APISample_linter.types | 4 ++-- tests/baselines/reference/APISample_transform.js | 2 +- tests/baselines/reference/APISample_transform.types | 4 ++-- tests/baselines/reference/APISample_watcher.js | 2 +- tests/baselines/reference/APISample_watcher.types | 4 ++-- 11 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d0c9ff8714009..df1b70ab6ff48 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11381,12 +11381,13 @@ module ts { } function checkGrammarArrowFunction(node: FunctionLikeDeclaration): boolean { - if (node.kind === SyntaxKind.ArrowFunction && (node).arrow) { + if (node.kind === SyntaxKind.ArrowFunction) { var arrowFunction = node; var sourceFile = getSourceFileOfNode(node); - if (getLineAndCharacterOfPosition(sourceFile, getTokenPosOfNode(arrowFunction.arrow, sourceFile)).line !== - getLineAndCharacterOfPosition(sourceFile, arrowFunction.parameters.end).line) { - return grammarErrorOnNode(arrowFunction.arrow, Diagnostics.Line_terminator_not_permitted_before_arrow); + var equalsGreaterThanLine = getLineAndCharacterOfPosition(sourceFile, getTokenPosOfNode(arrowFunction.equalsGreaterThanToken, sourceFile)).line; + var parametersLine = getLineAndCharacterOfPosition(sourceFile, arrowFunction.parameters.end).line; + if (equalsGreaterThanLine !== parametersLine) { + return grammarErrorOnNode(arrowFunction.equalsGreaterThanToken, Diagnostics.Line_terminator_not_permitted_before_arrow); } } return false; diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 6b010f584a2a8..5756f379685a1 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -95,7 +95,7 @@ module ts { visitNodes(cbNodes, (node).typeParameters) || visitNodes(cbNodes, (node).parameters) || visitNode(cbNode, (node).type) || - visitNode(cbNode, (node).arrow) || + visitNode(cbNode, (node).equalsGreaterThanToken) || visitNode(cbNode, (node).body); case SyntaxKind.TypeReference: return visitNode(cbNode, (node).typeName) || @@ -3017,9 +3017,7 @@ module ts { node.parameters.pos = parameter.pos; node.parameters.end = parameter.end; - if ((node.arrow = parseExpectedToken(SyntaxKind.EqualsGreaterThanToken, false, Diagnostics._0_expected, "=>"))) { - node.arrow.parent = node; - } + node.equalsGreaterThanToken = parseExpectedToken(SyntaxKind.EqualsGreaterThanToken, false, Diagnostics._0_expected, "=>"); node.body = parseArrowFunctionExpressionBody(); return finishNode(node); @@ -3048,8 +3046,7 @@ module ts { // If we have an arrow, then try to parse the body. Even if not, try to parse if we // have an opening brace, just in case we're in an error state. - if ((arrowFunction.arrow = parseExpectedToken(SyntaxKind.EqualsGreaterThanToken, false, Diagnostics._0_expected, "=>")) || token === SyntaxKind.OpenBraceToken) { - arrowFunction.arrow.parent = arrowFunction; + if ((arrowFunction.equalsGreaterThanToken = parseExpectedToken(SyntaxKind.EqualsGreaterThanToken, false, Diagnostics._0_expected, "=>")) || token === SyntaxKind.OpenBraceToken) { arrowFunction.body = parseArrowFunctionExpressionBody(); } else { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 49529bed9c6c5..25a8ce75245ab 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -654,7 +654,7 @@ module ts { } export interface ArrowFunction extends Expression, FunctionLikeDeclaration { - arrow: Node; + equalsGreaterThanToken: Node; } // The text property of a LiteralExpression stores the interpreted value of the literal in text form. For a StringLiteral, diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index 997bd2bd33740..6244dc73951f6 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -554,7 +554,7 @@ declare module "typescript" { body: Block | Expression; } interface ArrowFunction extends Expression, FunctionLikeDeclaration { - arrow: Node; + equalsGreaterThanToken: Node; } interface LiteralExpression extends PrimaryExpression { text: string; diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index d91d860ca8f72..43e88c27e414b 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -1674,8 +1674,8 @@ declare module "typescript" { >Expression : Expression >FunctionLikeDeclaration : FunctionLikeDeclaration - arrow: Node; ->arrow : Node + equalsGreaterThanToken: Node; +>equalsGreaterThanToken : Node >Node : Node } interface LiteralExpression extends PrimaryExpression { diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index b941acdbc52ae..fd4649f614daf 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -585,7 +585,7 @@ declare module "typescript" { body: Block | Expression; } interface ArrowFunction extends Expression, FunctionLikeDeclaration { - arrow: Node; + equalsGreaterThanToken: Node; } interface LiteralExpression extends PrimaryExpression { text: string; diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index b8701020e0354..984b59ca7ee74 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -1820,8 +1820,8 @@ declare module "typescript" { >Expression : Expression >FunctionLikeDeclaration : FunctionLikeDeclaration - arrow: Node; ->arrow : Node + equalsGreaterThanToken: Node; +>equalsGreaterThanToken : Node >Node : Node } interface LiteralExpression extends PrimaryExpression { diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index baf3f9d850318..4222e1b2d98fb 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -586,7 +586,7 @@ declare module "typescript" { body: Block | Expression; } interface ArrowFunction extends Expression, FunctionLikeDeclaration { - arrow: Node; + equalsGreaterThanToken: Node; } interface LiteralExpression extends PrimaryExpression { text: string; diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index d214a6fc959a7..bea3f1e723146 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -1770,8 +1770,8 @@ declare module "typescript" { >Expression : Expression >FunctionLikeDeclaration : FunctionLikeDeclaration - arrow: Node; ->arrow : Node + equalsGreaterThanToken: Node; +>equalsGreaterThanToken : Node >Node : Node } interface LiteralExpression extends PrimaryExpression { diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index d963aaff481a4..0928c2cf13988 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -623,7 +623,7 @@ declare module "typescript" { body: Block | Expression; } interface ArrowFunction extends Expression, FunctionLikeDeclaration { - arrow: Node; + equalsGreaterThanToken: Node; } interface LiteralExpression extends PrimaryExpression { text: string; diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index da00b9bf46631..4498a5538e4e9 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -1943,8 +1943,8 @@ declare module "typescript" { >Expression : Expression >FunctionLikeDeclaration : FunctionLikeDeclaration - arrow: Node; ->arrow : Node + equalsGreaterThanToken: Node; +>equalsGreaterThanToken : Node >Node : Node } interface LiteralExpression extends PrimaryExpression { From bd828e3024ecd34f60df57ee20514d637b198945 Mon Sep 17 00:00:00 2001 From: Caitlin Potter Date: Tue, 10 Mar 2015 22:14:58 -0400 Subject: [PATCH 067/224] Parse arrow function body as identifier if missing => or { Restores functionality broken in previous commit --- src/compiler/parser.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 5756f379685a1..eb43f7746053f 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3046,7 +3046,8 @@ module ts { // If we have an arrow, then try to parse the body. Even if not, try to parse if we // have an opening brace, just in case we're in an error state. - if ((arrowFunction.equalsGreaterThanToken = parseExpectedToken(SyntaxKind.EqualsGreaterThanToken, false, Diagnostics._0_expected, "=>")) || token === SyntaxKind.OpenBraceToken) { + arrowFunction.equalsGreaterThanToken = parseExpectedToken(SyntaxKind.EqualsGreaterThanToken, false, Diagnostics._0_expected, "=>"); + if (arrowFunction.equalsGreaterThanToken.kind === SyntaxKind.EqualsGreaterThanToken || token === SyntaxKind.OpenBraceToken) { arrowFunction.body = parseArrowFunctionExpressionBody(); } else { From 3dc5faf70779d286405faf05b240feac7687f001 Mon Sep 17 00:00:00 2001 From: Caitlin Potter Date: Wed, 11 Mar 2015 16:40:31 -0400 Subject: [PATCH 068/224] Restore earlier behaviour when parsing non-simple arrow function bodies --- src/compiler/parser.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index eb43f7746053f..f996af5f5e44c 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3046,14 +3046,11 @@ module ts { // If we have an arrow, then try to parse the body. Even if not, try to parse if we // have an opening brace, just in case we're in an error state. - arrowFunction.equalsGreaterThanToken = parseExpectedToken(SyntaxKind.EqualsGreaterThanToken, false, Diagnostics._0_expected, "=>"); - if (arrowFunction.equalsGreaterThanToken.kind === SyntaxKind.EqualsGreaterThanToken || token === SyntaxKind.OpenBraceToken) { - arrowFunction.body = parseArrowFunctionExpressionBody(); - } - else { - // If not, we're probably better off bailing out and returning a bogus function expression. - arrowFunction.body = parseIdentifier(); - } + var lastToken = token; + arrowFunction.equalsGreaterThanToken = parseExpectedToken(SyntaxKind.EqualsGreaterThanToken, /*reportAtCurrentPosition:*/false, Diagnostics._0_expected, "=>"); + arrowFunction.body = (lastToken === SyntaxKind.EqualsGreaterThanToken || lastToken === SyntaxKind.OpenBraceToken) + ? parseArrowFunctionExpressionBody() + : parseIdentifier(); return finishNode(arrowFunction); } From 10925c1e9ba8cd7d5babc76823c458fb0dbfc886 Mon Sep 17 00:00:00 2001 From: Caitlin Potter Date: Fri, 13 Mar 2015 01:30:07 -0400 Subject: [PATCH 069/224] Make sure arrow function grammar rules can deal with type annotations --- src/compiler/checker.ts | 8 +-- ...sallowLineTerminatorBeforeArrow.errors.txt | 58 ++++++++++++++-- .../disallowLineTerminatorBeforeArrow.js | 68 +++++++++++++++++++ .../disallowLineTerminatorBeforeArrow.ts | 32 +++++++++ 4 files changed, 155 insertions(+), 11 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index df1b70ab6ff48..be1b6f943cac3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4412,7 +4412,7 @@ module ts { } /** - * Check if a Type was written as a tuple type literal. + * Check if a Type was written as a tuple type literal. * Prefer using isTupleLikeType() unless the use of `elementTypes` is required. */ function isTupleType(type: Type) : boolean { @@ -11384,9 +11384,9 @@ module ts { if (node.kind === SyntaxKind.ArrowFunction) { var arrowFunction = node; var sourceFile = getSourceFileOfNode(node); - var equalsGreaterThanLine = getLineAndCharacterOfPosition(sourceFile, getTokenPosOfNode(arrowFunction.equalsGreaterThanToken, sourceFile)).line; - var parametersLine = getLineAndCharacterOfPosition(sourceFile, arrowFunction.parameters.end).line; - if (equalsGreaterThanLine !== parametersLine) { + var startLine = getLineAndCharacterOfPosition(sourceFile, arrowFunction.equalsGreaterThanToken.pos).line; + var endLine = getLineAndCharacterOfPosition(sourceFile, arrowFunction.equalsGreaterThanToken.end).line; + if (startLine !== endLine) { return grammarErrorOnNode(arrowFunction.equalsGreaterThanToken, Diagnostics.Line_terminator_not_permitted_before_arrow); } } diff --git a/tests/baselines/reference/disallowLineTerminatorBeforeArrow.errors.txt b/tests/baselines/reference/disallowLineTerminatorBeforeArrow.errors.txt index e441752338c12..fbd9be772faab 100644 --- a/tests/baselines/reference/disallowLineTerminatorBeforeArrow.errors.txt +++ b/tests/baselines/reference/disallowLineTerminatorBeforeArrow.errors.txt @@ -6,15 +6,19 @@ tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(1 tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(12,7): error TS1200: Line terminator not permitted before arrow. tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(14,5): error TS1200: Line terminator not permitted before arrow. tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(16,7): error TS1200: Line terminator not permitted before arrow. -tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(20,5): error TS1200: Line terminator not permitted before arrow. -tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(22,5): error TS1200: Line terminator not permitted before arrow. -tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(27,13): error TS1200: Line terminator not permitted before arrow. -tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(31,13): error TS1200: Line terminator not permitted before arrow. -tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(36,13): error TS1200: Line terminator not permitted before arrow. -tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(40,9): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(18,5): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(21,5): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(23,8): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(26,8): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(52,5): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(54,5): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(59,13): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(63,13): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(68,13): error TS1200: Line terminator not permitted before arrow. +tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(72,9): error TS1200: Line terminator not permitted before arrow. -==== tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts (14 errors) ==== +==== tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts (18 errors) ==== var f1 = () => { } ~~ @@ -47,6 +51,46 @@ tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts(4 */ => { } ~~ !!! error TS1200: Line terminator not permitted before arrow. + var f9 = (a: number): number + => a; + ~~ +!!! error TS1200: Line terminator not permitted before arrow. + var f10 = (a: number) : + number + => a + ~~ +!!! error TS1200: Line terminator not permitted before arrow. + var f11 = (a: number): number /* + */ => a; + ~~ +!!! error TS1200: Line terminator not permitted before arrow. + var f12 = (a: number) : + number /* + */ => a + ~~ +!!! error TS1200: Line terminator not permitted before arrow. + + // Should be valid. + var f11 = (a: number + ) => a; + + // Should be valid. + var f12 = (a: number) + : number => a; + + // Should be valid. + var f13 = (a: number): + number => a; + + // Should be valid. + var f14 = () /* */ => {} + + // Should be valid. + var f15 = (a: number): number /* */ => a + + // Should be valid. + var f16 = (a: number, b = 10): + number /* */ => a + b; function foo(func: () => boolean) { } foo(() diff --git a/tests/baselines/reference/disallowLineTerminatorBeforeArrow.js b/tests/baselines/reference/disallowLineTerminatorBeforeArrow.js index 122c229d7d948..610cbe62c1bd8 100644 --- a/tests/baselines/reference/disallowLineTerminatorBeforeArrow.js +++ b/tests/baselines/reference/disallowLineTerminatorBeforeArrow.js @@ -15,6 +15,38 @@ var f7 = (x: string, y: number, z = 10) => { } var f8 = (x: string, y: number, z = 10) /* */ => { } +var f9 = (a: number): number + => a; +var f10 = (a: number) : + number + => a +var f11 = (a: number): number /* + */ => a; +var f12 = (a: number) : + number /* + */ => a + +// Should be valid. +var f11 = (a: number + ) => a; + +// Should be valid. +var f12 = (a: number) + : number => a; + +// Should be valid. +var f13 = (a: number): + number => a; + +// Should be valid. +var f14 = () /* */ => {} + +// Should be valid. +var f15 = (a: number): number /* */ => a + +// Should be valid. +var f16 = (a: number, b = 10): + number /* */ => a + b; function foo(func: () => boolean) { } foo(() @@ -77,6 +109,42 @@ var f7 = function (x, y, z) { var f8 = function (x, y, z) { if (z === void 0) { z = 10; } }; +var f9 = function (a) { + return a; +}; +var f10 = function (a) { + return a; +}; +var f11 = function (a) { + return a; +}; +var f12 = function (a) { + return a; +}; +// Should be valid. +var f11 = function (a) { + return a; +}; +// Should be valid. +var f12 = function (a) { + return a; +}; +// Should be valid. +var f13 = function (a) { + return a; +}; +// Should be valid. +var f14 = function () { +}; +// Should be valid. +var f15 = function (a) { + return a; +}; +// Should be valid. +var f16 = function (a, b) { + if (b === void 0) { b = 10; } + return a + b; +}; function foo(func) { } foo(function () { diff --git a/tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts b/tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts index f11fed6b47813..bd984ba4da0e1 100644 --- a/tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts +++ b/tests/cases/conformance/es6/arrowFunction/disallowLineTerminatorBeforeArrow.ts @@ -14,6 +14,38 @@ var f7 = (x: string, y: number, z = 10) => { } var f8 = (x: string, y: number, z = 10) /* */ => { } +var f9 = (a: number): number + => a; +var f10 = (a: number) : + number + => a +var f11 = (a: number): number /* + */ => a; +var f12 = (a: number) : + number /* + */ => a + +// Should be valid. +var f11 = (a: number + ) => a; + +// Should be valid. +var f12 = (a: number) + : number => a; + +// Should be valid. +var f13 = (a: number): + number => a; + +// Should be valid. +var f14 = () /* */ => {} + +// Should be valid. +var f15 = (a: number): number /* */ => a + +// Should be valid. +var f16 = (a: number, b = 10): + number /* */ => a + b; function foo(func: () => boolean) { } foo(() From 13e55ae8cbfff8ebb44e3285f7146163d00b3848 Mon Sep 17 00:00:00 2001 From: Yui T Date: Sat, 14 Mar 2015 16:53:33 -0700 Subject: [PATCH 070/224] Address code review --- src/compiler/checker.ts | 12 ++-- src/compiler/emitter.ts | 137 +++++++++------------------------------- src/compiler/parser.ts | 6 -- 3 files changed, 36 insertions(+), 119 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 689f27af867b6..feb95b4da16d5 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5696,9 +5696,9 @@ module ts { if (!links.resolvedType) { links.resolvedType = checkExpression(node.expression); - // Disallow using static property in computedPropertyName because classDeclaration is binded lexically in ES6 + // Disallow using a static property in computedPropertyName because classDeclaration is bound lexically in ES6 // and its static property assignment will be emitted after classDeclaration. - // Therefore, using static property inside computedPropertyName will cause use-before-definition + // Therefore, using static property inside computedPropertyName will cause an use-before-definition error // Example: // * TypeScript // class C { @@ -5710,9 +5710,9 @@ module ts { // [C.p]() {} // Use before definition error // } // C.p = 10; - if (languageVersion >= ScriptTarget.ES6 && links.resolvedSymbol) { + if (links.resolvedSymbol) { var declarations = links.resolvedSymbol.declarations; - forEach(declarations, (declaration) => { + forEach(declarations, declaration => { if (declaration.flags & NodeFlags.Static) { error(node, Diagnostics.A_computed_property_name_cannot_reference_a_static_property); } @@ -9296,9 +9296,7 @@ module ts { var staticType = getTypeOfSymbol(symbol); var baseTypeNode = getClassBaseTypeNode(node); if (baseTypeNode) { - if (languageVersion < ScriptTarget.ES6) { - emitExtends = emitExtends || !isInAmbientContext(node); - } + emitExtends = emitExtends || !isInAmbientContext(node); checkTypeReference(baseTypeNode); } if (type.baseTypes.length) { diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index a0303610a3da0..96c34ae743db4 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2634,7 +2634,6 @@ module ts { write("super"); } else { - Debug.assert(languageVersion < ScriptTarget.ES6) var flags = resolver.getNodeCheckFlags(node); if (flags & NodeCheckFlags.SuperInstance) { write("_super.prototype"); @@ -3175,12 +3174,7 @@ module ts { } var superCall = false; if (node.expression.kind === SyntaxKind.SuperKeyword) { - if (languageVersion < ScriptTarget.ES6) { - write("_super"); - } - else { - write("super"); - } + emitSuper(node.expression); superCall = true; } else { @@ -3196,18 +3190,13 @@ module ts { } write(")"); } - else if (superCall && languageVersion >= ScriptTarget.ES6) { + else { write("("); if (node.arguments.length) { emitCommaList(node.arguments); } write(")"); } - else { - write("("); - emitCommaList(node.arguments); - write(")"); - } } function emitNewExpression(node: NewExpression) { @@ -4413,8 +4402,20 @@ module ts { emitComputedPropertyName(memberName); } else { - // For script-target that is ES6 or above, we want to emit memberName by itself without prefix "." if the memberName is a name of method. - // If the memberName is the name of property, we need to emit it with prefix ".". + // For ES6 and above, we want to emit memberName by itself without prefix ".", + // For ES5 and below, we want to prefix memberName with ".". For example, + // Typescript: + // class C { + // x = 10; + // foo () {} + // } + // Javascript: + // var C = (function () { + // function C() { + // this.x = 10; // Property "x" need to be prefixed with "." + // } + // C.prototype.foo = function() {}; // Similarly property "foo" need to be prefixed with "." + // } if (languageVersion < ScriptTarget.ES6 || memberName.parent.kind === SyntaxKind.PropertyDeclaration) { write("."); } @@ -4446,7 +4447,7 @@ module ts { }); } - function emitMemberFunctionsBelowES6(node: ClassDeclaration) { + function emitMemberFunctionsForES5AndLower(node: ClassDeclaration) { forEach(node.members, member => { if (member.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature) { if (!(member).body) { @@ -4516,7 +4517,7 @@ module ts { }); } - function emitMemberFunctionsAboveES6(node: ClassDeclaration) { + function emitMemberFunctionsForES6AndHigher(node: ClassDeclaration) { forEach(node.members, member => { if (member.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature) { if (!(member).body) { @@ -4568,7 +4569,7 @@ module ts { }); } - function emitConstructorOfClass(node: ClassDeclaration, baseTypeNode: TypeReferenceNode) { + function emitConstructor(node: ClassDeclaration, baseTypeNode: TypeReferenceNode) { var saveTempCount = tempCount; var saveTempVariables = tempVariables; var saveTempParameters = tempParameters; @@ -4597,7 +4598,6 @@ module ts { emitSignatureParameters(ctor); } else { - Debug.assert(languageVersion >= ScriptTarget.ES6, "Expected Script Target to be ES6 or above"); write("constructor"); if (ctor) { emitSignatureParameters(ctor); @@ -4670,7 +4670,7 @@ module ts { tempParameters = saveTempParameters; } - function emitClassDeclarationAboveES6(node: ClassDeclaration) { + function emitClassDeclarationForES6AndHigher(node: ClassDeclaration) { if (node.flags & NodeFlags.Export) { write("export "); @@ -4683,20 +4683,21 @@ module ts { var baseTypeNode = getClassBaseTypeNode(node); if (baseTypeNode) { write(" extends "); - emitNodeWithoutSourceMap(baseTypeNode.typeName); + emit(baseTypeNode.typeName); } write(" {"); increaseIndent(); scopeEmitStart(node); writeLine(); - emitConstructorOfClass(node, baseTypeNode); - emitMemberFunctionsAboveES6(node); + emitConstructor(node, baseTypeNode); + emitMemberFunctionsForES6AndHigher(node); decreaseIndent(); writeLine(); emitToken(SyntaxKind.CloseBraceToken, node.members.end); scopeEmitEnd(); - // Emit static property assignment. Because classDeclaration is lexically evaluated, it is safe to emit static property assignment after classDeclaration + // Emit static property assignment. Because classDeclaration is lexically evaluated, + // it is safe to emit static property assignment after classDeclaration // From ES6 specification: // HasLexicalDeclaration (N) : Determines if the argument identifier has a binding in this environment record that was created using // a lexical declaration such as a LexicalDeclaration or a ClassDeclaration. @@ -4724,8 +4725,8 @@ module ts { emitEnd(baseTypeNode); } writeLine(); - emitConstructorOfClass(node, baseTypeNode); - emitMemberFunctionsBelowES6(node); + emitConstructor(node, baseTypeNode); + emitMemberFunctionsForES5AndLower(node); emitMemberAssignments(node, NodeFlags.Static); writeLine(); emitToken(SyntaxKind.CloseBraceToken, node.members.end, () => { @@ -4756,84 +4757,6 @@ module ts { if (languageVersion < ScriptTarget.ES6 && node.parent === currentSourceFile && node.name) { emitExportMemberAssignments(node.name); } - - function emitConstructorOfClassOLD() { - var saveTempCount = tempCount; - var saveTempVariables = tempVariables; - var saveTempParameters = tempParameters; - tempCount = 0; - tempVariables = undefined; - tempParameters = undefined; - - var popFrame = enterNameScope(); - - // Emit the constructor overload pinned comments - forEach(node.members, member => { - if (member.kind === SyntaxKind.Constructor && !(member).body) { - emitPinnedOrTripleSlashComments(member); - } - }); - - var ctor = getFirstConstructorWithBody(node); - if (ctor) { - emitLeadingComments(ctor); - } - emitStart(ctor || node); - write("function "); - emitDeclarationName(node); - emitSignatureParameters(ctor); - write(" {"); - scopeEmitStart(node, "constructor"); - increaseIndent(); - if (ctor) { - emitDetachedComments((ctor.body).statements); - } - emitCaptureThisForNodeIfNecessary(node); - if (ctor) { - emitDefaultValueAssignments(ctor); - emitRestParameter(ctor); - if (baseTypeNode) { - var superCall = findInitialSuperCall(ctor); - if (superCall) { - writeLine(); - emit(superCall); - } - } - emitParameterPropertyAssignments(ctor); - } - else { - if (baseTypeNode) { - writeLine(); - emitStart(baseTypeNode); - write("_super.apply(this, arguments);"); - emitEnd(baseTypeNode); - } - } - emitMemberAssignments(node, /*nonstatic*/0); - if (ctor) { - var statements: Node[] = (ctor.body).statements; - if (superCall) statements = statements.slice(1); - emitLines(statements); - } - emitTempDeclarations(/*newLine*/ true); - writeLine(); - if (ctor) { - emitLeadingCommentsOfPosition((ctor.body).statements.end); - } - decreaseIndent(); - emitToken(SyntaxKind.CloseBraceToken, ctor ? (ctor.body).statements.end : node.members.end); - scopeEmitEnd(); - emitEnd(ctor || node); - if (ctor) { - emitTrailingComments(ctor); - } - - exitNameScope(popFrame); - - tempCount = saveTempCount; - tempVariables = saveTempVariables; - tempParameters = saveTempParameters; - } } function emitInterfaceDeclaration(node: InterfaceDeclaration) { @@ -5322,7 +5245,9 @@ module ts { // emit prologue directives prior to __extends var startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false); - if (!extendsEmitted && resolver.getNodeCheckFlags(node) & NodeCheckFlags.EmitExtends) { + // Only Emit __extends function when target ES5. + // For target ES6 and above, we can emit classDeclaration as if. + if ((languageVersion < ScriptTarget.ES6) && (!extendsEmitted && resolver.getNodeCheckFlags(node) & NodeCheckFlags.EmitExtends)) { writeLine(); write("var __extends = this.__extends || function (d, b) {"); increaseIndent(); @@ -5554,7 +5479,7 @@ module ts { case SyntaxKind.VariableDeclaration: return emitVariableDeclaration(node); case SyntaxKind.ClassDeclaration: - return languageVersion < ScriptTarget.ES6 ? emitClassDeclarationBelowES6(node) : emitClassDeclarationAboveES6(node); + return languageVersion < ScriptTarget.ES6 ? emitClassDeclarationBelowES6(node) : emitClassDeclarationForES6AndHigher(node); case SyntaxKind.InterfaceDeclaration: return emitInterfaceDeclaration(node); case SyntaxKind.EnumDeclaration: diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 7658a49bc48e6..5a07b22153d6d 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4372,12 +4372,6 @@ module ts { function parsePropertyOrMethodDeclaration(fullStart: number, modifiers: ModifiersArray): ClassElement { var asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); - - // From ES6 Specification, "implements", "interface", "let", "package", "private", "protected", "public", "static", and "yield" are reserved words within strict mode code - if (inStrictModeContext() && (token > SyntaxKind.LastReservedWord)) { - parseErrorAtCurrentToken(Diagnostics.Invalid_use_of_0_in_strict_mode, tokenToString(token)); - } - var name = parsePropertyName(); // Note: this is not legal as per the grammar. But we allow it in the parser and From 02d356800f36ecd548641d993ab4b70359de2e70 Mon Sep 17 00:00:00 2001 From: Caitlin Potter Date: Sat, 14 Mar 2015 20:12:10 -0400 Subject: [PATCH 071/224] Share SourceFile with other grammar checker that needs it --- src/compiler/checker.ts | 26 +++++++++++++------------- src/compiler/parser.ts | 4 ++-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index be1b6f943cac3..03a4ee6d04ab5 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -448,7 +448,7 @@ module ts { let declaration = forEach(result.declarations, d => isBlockOrCatchScoped(d) ? d : undefined); Debug.assert(declaration !== undefined, "Block-scoped variable declaration is undefined"); - + // first check if usage is lexically located after the declaration let isUsedBeforeDeclaration = !isDefinedBefore(declaration, errorLocation); if (!isUsedBeforeDeclaration) { @@ -465,7 +465,7 @@ module ts { if (variableDeclaration.parent.parent.kind === SyntaxKind.VariableStatement || variableDeclaration.parent.parent.kind === SyntaxKind.ForStatement) { - // variable statement/for statement case, + // variable statement/for statement case, // use site should not be inside variable declaration (initializer of declaration or binding element) isUsedBeforeDeclaration = isSameScopeDescendentOf(errorLocation, variableDeclaration, container); } @@ -9080,7 +9080,7 @@ module ts { */ function checkElementTypeOfArrayOrString(arrayOrStringType: Type, expressionForError: Expression): Type { Debug.assert(languageVersion < ScriptTarget.ES6); - + // After we remove all types that are StringLike, we will know if there was a string constituent // based on whether the remaining type is the same as the initial type. let arrayType = removeTypesFromUnionType(arrayOrStringType, TypeFlags.StringLike, /*isTypeOfKind*/ true, /*allowEmptyUnionResult*/ true); @@ -11324,16 +11324,15 @@ module ts { } } - function checkGrammarTypeParameterList(node: FunctionLikeDeclaration, typeParameters: NodeArray): boolean { + function checkGrammarTypeParameterList(node: FunctionLikeDeclaration, typeParameters: NodeArray, file: SourceFile): boolean { if (checkGrammarForDisallowedTrailingComma(typeParameters)) { return true; } if (typeParameters && typeParameters.length === 0) { let start = typeParameters.pos - "<".length; - let sourceFile = getSourceFileOfNode(node); - let end = skipTrivia(sourceFile.text, typeParameters.end) + ">".length; - return grammarErrorAtPos(sourceFile, start, end - start, Diagnostics.Type_parameter_list_cannot_be_empty); + let end = skipTrivia(file.text, typeParameters.end) + ">".length; + return grammarErrorAtPos(file, start, end - start, Diagnostics.Type_parameter_list_cannot_be_empty); } } @@ -11377,15 +11376,16 @@ module ts { function checkGrammarFunctionLikeDeclaration(node: FunctionLikeDeclaration): boolean { // Prevent cascading error by short-circuit - return checkGrammarModifiers(node) || checkGrammarTypeParameterList(node, node.typeParameters) || checkGrammarParameterList(node.parameters) || checkGrammarArrowFunction(node); + let file = getSourceFileOfNode(node); + return checkGrammarModifiers(node) || checkGrammarTypeParameterList(node, node.typeParameters, file) || + checkGrammarParameterList(node.parameters) || checkGrammarArrowFunction(node, file); } - function checkGrammarArrowFunction(node: FunctionLikeDeclaration): boolean { + function checkGrammarArrowFunction(node: FunctionLikeDeclaration, file: SourceFile): boolean { if (node.kind === SyntaxKind.ArrowFunction) { - var arrowFunction = node; - var sourceFile = getSourceFileOfNode(node); - var startLine = getLineAndCharacterOfPosition(sourceFile, arrowFunction.equalsGreaterThanToken.pos).line; - var endLine = getLineAndCharacterOfPosition(sourceFile, arrowFunction.equalsGreaterThanToken.end).line; + let arrowFunction = node; + let startLine = getLineAndCharacterOfPosition(file, arrowFunction.equalsGreaterThanToken.pos).line; + let endLine = getLineAndCharacterOfPosition(file, arrowFunction.equalsGreaterThanToken.end).line; if (startLine !== endLine) { return grammarErrorOnNode(arrowFunction.equalsGreaterThanToken, Diagnostics.Line_terminator_not_permitted_before_arrow); } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index f996af5f5e44c..27f550778c19d 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3134,11 +3134,11 @@ module ts { } } - function parsePossibleParenthesizedArrowFunctionExpressionHead() { + function parsePossibleParenthesizedArrowFunctionExpressionHead(): ArrowFunction { return parseParenthesizedArrowFunctionExpressionHead(/*allowAmbiguity:*/ false); } - function parseParenthesizedArrowFunctionExpressionHead(allowAmbiguity: boolean): FunctionExpression { + function parseParenthesizedArrowFunctionExpressionHead(allowAmbiguity: boolean): ArrowFunction { let node = createNode(SyntaxKind.ArrowFunction); // Arrow functions are never generators. // From fac3cf8b5541216ee7fa01451daffc044986b060 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Sat, 14 Mar 2015 18:50:05 -0700 Subject: [PATCH 072/224] addressed PR feedback --- src/compiler/checker.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1ce946493b00f..e59996c078169 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8625,18 +8625,19 @@ module ts { localDeclarationSymbol !== symbol && localDeclarationSymbol.flags & SymbolFlags.BlockScopedVariable) { if (getDeclarationFlagsFromSymbol(localDeclarationSymbol) & NodeFlags.BlockScoped) { - let varDeclList = getAncestor(localDeclarationSymbol.valueDeclaration, SyntaxKind.VariableDeclarationList); let container = - varDeclList.parent.kind === SyntaxKind.VariableStatement && - varDeclList.parent.parent; + varDeclList.parent.kind === SyntaxKind.VariableStatement && varDeclList.parent.parent + ? varDeclList.parent.parent + : undefined; // names of block-scoped and function scoped variables can collide only // if block scoped variable is defined in the function\module\source file scope (because of variable hoisting) let namesShareScope = container && (container.kind === SyntaxKind.Block && isFunctionLike(container.parent) || - (container.kind === SyntaxKind.ModuleBlock && container.kind === SyntaxKind.ModuleDeclaration) || + container.kind === SyntaxKind.ModuleBlock || + container.kind === SyntaxKind.ModuleDeclaration || container.kind === SyntaxKind.SourceFile); // here we know that function scoped variable is shadowed by block scoped one From 2a07d3f8db9e4bf8da8a74f8c3d184082a1d5e57 Mon Sep 17 00:00:00 2001 From: Yui T Date: Sun, 15 Mar 2015 12:33:29 -0700 Subject: [PATCH 073/224] Address code review: do not emit default constructor --- src/compiler/emitter.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 96c34ae743db4..b3b305dd6c494 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4578,15 +4578,29 @@ module ts { tempParameters = undefined; var popFrame = enterNameScope(); + // Check if we have property assignment inside class declaration. + // If there is property assignment, we need to emit constructor whether users define it or not + // If there is no property assignment, we can omit constructor if users do not define it + var hasPropertyAssignment = false; // Emit the constructor overload pinned comments forEach(node.members, member => { if (member.kind === SyntaxKind.Constructor && !(member).body) { emitPinnedOrTripleSlashComments(member); } + if (member.kind === SyntaxKind.PropertyDeclaration && (member).initializer) { + hasPropertyAssignment = true; + } }); var ctor = getFirstConstructorWithBody(node); + + // For target ES6 and above, if there is no user-defined constructor and there is no property assignment + // do not emit constructor in class declaration. + if (languageVersion >= ScriptTarget.ES6 && !ctor && !hasPropertyAssignment) { + return; + } + if (ctor) { emitLeadingComments(ctor); } @@ -4617,6 +4631,7 @@ module ts { } } } + write(" {"); scopeEmitStart(node, "constructor"); increaseIndent(); From ebcb86b0773320ae00d52b7d534b404943377a3a Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 4 Mar 2015 17:34:07 -0800 Subject: [PATCH 074/224] enable navbar for export defaults Conflicts: src/services/navigationBar.ts --- src/services/navigationBar.ts | 13 ++++------ tests/cases/fourslash/navbar_exportDefault.ts | 24 +++++++++++++++++++ 2 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 tests/cases/fourslash/navbar_exportDefault.ts diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index 06eaa481dfb12..c6463aba7333c 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -418,10 +418,10 @@ module ts.NavigationBar { } function createFunctionItem(node: FunctionDeclaration) { - if (node.name && node.body && node.body.kind === SyntaxKind.Block) { + if ((node.name || node.flags & NodeFlags.Default) && node.body && node.body.kind === SyntaxKind.Block) { let childItems = getItemsWorker(sortNodes((node.body).statements), createChildItem); - return getNavigationBarItem(node.name.text, + return getNavigationBarItem((!node.name && node.flags & NodeFlags.Default) ? "default": node.name.text , ts.ScriptElementKind.functionElement, getNodeModifiers(node), [getNodeSpan(node)], @@ -452,11 +452,6 @@ module ts.NavigationBar { } function createClassItem(node: ClassDeclaration): ts.NavigationBarItem { - if (!node.name) { - // An export default class may be nameless - return undefined; - } - let childItems: NavigationBarItem[]; if (node.members) { @@ -475,8 +470,10 @@ module ts.NavigationBar { childItems = getItemsWorker(sortNodes(nodes), createChildItem); } + var nodeName = !node.name && (node.flags & NodeFlags.Default) ? "default" : node.name.text; + return getNavigationBarItem( - node.name.text, + nodeName, ts.ScriptElementKind.classElement, getNodeModifiers(node), [getNodeSpan(node)], diff --git a/tests/cases/fourslash/navbar_exportDefault.ts b/tests/cases/fourslash/navbar_exportDefault.ts new file mode 100644 index 0000000000000..a8fe854fa2889 --- /dev/null +++ b/tests/cases/fourslash/navbar_exportDefault.ts @@ -0,0 +1,24 @@ +/// + +// @Filename: a.ts +//// {| "itemName": "default", "kind": "class", "parentName": "" |}export default class { } + +// @Filename: b.ts +//// {| "itemName": "C", "kind": "class", "parentName": "" |}export default class C { } + +// @Filename: c.ts +//// {| "itemName": "default", "kind": "function", "parentName": "" |}export default function { } + +// @Filename: d.ts +//// {| "itemName": "Func", "kind": "function", "parentName": "" |}export default function Func { } + +test.markers().forEach(marker => { + goTo.file(marker.fileName); + verify.getScriptLexicalStructureListContains( + marker.data.itemName, + marker.data.kind, + marker.fileName, + marker.data.parentName, + marker.data.isAdditionalRange, + marker.position); +}); \ No newline at end of file From 44a5343c1ecb295835b21247e572d4c9c760fc4e Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Sun, 15 Mar 2015 14:37:12 -0700 Subject: [PATCH 075/224] Upate error message --- src/compiler/checker.ts | 4 ++-- src/compiler/diagnosticInformationMap.generated.ts | 2 +- src/compiler/diagnosticMessages.json | 2 +- .../baselines/reference/exportDefaultTypeAnnoation.errors.txt | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c79ca2f1fd2a4..66f317900289f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2073,7 +2073,7 @@ module ts { } // Handle export default expressions if (declaration.kind === SyntaxKind.ExportAssignment) { - var exportAssignment = (declaration); + var exportAssignment = declaration; if (exportAssignment.expression) { return links.type = checkExpression(exportAssignment.expression); } @@ -10095,7 +10095,7 @@ module ts { if (node.type) { checkSourceElement(node.type); if (!isInAmbientContext(node)) { - grammarErrorOnFirstToken(node.type, Diagnostics.Type_annotation_on_export_statements_are_only_allowed_in_ambient_module_declarations); + grammarErrorOnFirstToken(node.type, Diagnostics.A_type_annotation_on_an_export_statement_is_only_allowed_in_an_ambient_external_module_declaration); } } diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 5d3bafc45a778..e3bb7aa8f43ed 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -157,7 +157,7 @@ module ts { Catch_clause_variable_cannot_have_an_initializer: { code: 1197, category: DiagnosticCategory.Error, key: "Catch clause variable cannot have an initializer." }, An_extended_Unicode_escape_value_must_be_between_0x0_and_0x10FFFF_inclusive: { code: 1198, category: DiagnosticCategory.Error, key: "An extended Unicode escape value must be between 0x0 and 0x10FFFF inclusive." }, Unterminated_Unicode_escape_sequence: { code: 1199, category: DiagnosticCategory.Error, key: "Unterminated Unicode escape sequence." }, - Type_annotation_on_export_statements_are_only_allowed_in_ambient_module_declarations: { code: 1200, category: DiagnosticCategory.Error, key: "Type annotation on export statements are only allowed in ambient module declarations." }, + A_type_annotation_on_an_export_statement_is_only_allowed_in_an_ambient_external_module_declaration: { code: 1200, category: DiagnosticCategory.Error, key: "A type annotation on an export statement is only allowed in an ambient external module declaration." }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 779e3891766b7..3c8ecadee02bb 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -619,7 +619,7 @@ "category": "Error", "code": 1199 }, - "Type annotation on export statements are only allowed in ambient module declarations.": { + "A type annotation on an export statement is only allowed in an ambient external module declaration.": { "category": "Error", "code": 1200 }, diff --git a/tests/baselines/reference/exportDefaultTypeAnnoation.errors.txt b/tests/baselines/reference/exportDefaultTypeAnnoation.errors.txt index fa7806a17dd72..472dc0c74c130 100644 --- a/tests/baselines/reference/exportDefaultTypeAnnoation.errors.txt +++ b/tests/baselines/reference/exportDefaultTypeAnnoation.errors.txt @@ -1,8 +1,8 @@ -tests/cases/compiler/exportDefaultTypeAnnoation.ts(2,18): error TS1200: Type annotation on export statements are only allowed in ambient module declarations. +tests/cases/compiler/exportDefaultTypeAnnoation.ts(2,18): error TS1200: A type annotation on an export statement is only allowed in an ambient external module declaration. ==== tests/cases/compiler/exportDefaultTypeAnnoation.ts (1 errors) ==== export default : number; ~~~~~~ -!!! error TS1200: Type annotation on export statements are only allowed in ambient module declarations. \ No newline at end of file +!!! error TS1200: A type annotation on an export statement is only allowed in an ambient external module declaration. \ No newline at end of file From 9bf5a11befa3c25ddccc8b7ef444f9d9ecf41d83 Mon Sep 17 00:00:00 2001 From: Yui T Date: Sun, 15 Mar 2015 16:29:41 -0700 Subject: [PATCH 076/224] Update baselines --- src/compiler/emitter.ts | 9 +- .../baselines/reference/callWithSpreadES6.js | 37 +++--- .../reference/computedPropertyNames12_ES6.js | 9 +- .../reference/computedPropertyNames13_ES6.js | 51 ++++----- .../reference/computedPropertyNames14_ES6.js | 29 +++-- .../reference/computedPropertyNames15_ES6.js | 17 ++- .../reference/computedPropertyNames16_ES6.js | 105 +++++------------- .../reference/computedPropertyNames17_ES6.js | 59 +++------- .../reference/computedPropertyNames21_ES6.js | 15 +-- .../reference/computedPropertyNames22_ES6.js | 11 +- .../reference/computedPropertyNames23_ES6.js | 17 ++- .../reference/computedPropertyNames24_ES6.js | 28 ++--- .../reference/computedPropertyNames25_ES6.js | 30 ++--- .../reference/computedPropertyNames26_ES6.js | 32 ++---- .../reference/computedPropertyNames27_ES6.js | 24 +--- .../reference/computedPropertyNames28_ES6.js | 25 ++--- .../reference/computedPropertyNames29_ES6.js | 11 +- .../reference/computedPropertyNames2_ES6.js | 45 +++----- .../reference/computedPropertyNames30_ES6.js | 25 ++--- .../reference/computedPropertyNames31_ES6.js | 30 ++--- .../reference/computedPropertyNames32_ES6.js | 15 +-- .../reference/computedPropertyNames33_ES6.js | 11 +- .../reference/computedPropertyNames34_ES6.js | 11 +- .../reference/computedPropertyNames36_ES6.js | 37 ++---- .../reference/computedPropertyNames37_ES6.js | 37 ++---- .../reference/computedPropertyNames38_ES6.js | 37 ++---- .../reference/computedPropertyNames39_ES6.js | 37 ++---- .../computedPropertyNames3_ES6.errors.txt | 5 +- .../reference/computedPropertyNames3_ES6.js | 49 +++----- .../reference/computedPropertyNames40_ES6.js | 29 ++--- .../reference/computedPropertyNames41_ES6.js | 25 ++--- .../reference/computedPropertyNames42_ES6.js | 21 +--- .../reference/computedPropertyNames43_ES6.js | 52 ++------- .../reference/computedPropertyNames44_ES6.js | 50 ++------- .../reference/computedPropertyNames45_ES6.js | 50 ++------- ...mputedPropertyNamesDeclarationEmit1_ES6.js | 27 ++--- ...mputedPropertyNamesDeclarationEmit2_ES6.js | 27 ++--- .../computedPropertyNamesOnOverloads_ES6.js | 9 +- ...computedPropertyNamesSourceMap1_ES5.js.map | 2 +- ...dPropertyNamesSourceMap1_ES5.sourcemap.txt | 8 +- .../computedPropertyNamesSourceMap1_ES6.js | 11 +- ...computedPropertyNamesSourceMap1_ES6.js.map | 2 +- ...dPropertyNamesSourceMap1_ES6.sourcemap.txt | 96 +++++----------- .../reference/constDeclarations-scopes.js | 33 +++--- .../constDeclarations-validContexts.js | 29 ++--- .../destructuringParameterProperties4.js | 36 ++---- .../emitDefaultParametersMethodES6.js | 37 +++--- .../reference/emitRestParametersMethodES6.js | 30 +++-- 48 files changed, 453 insertions(+), 969 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index b3b305dd6c494..a079994e5c8f7 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2630,6 +2630,7 @@ module ts { } function emitSuper(node: Node) { + debugger; if (languageVersion >= ScriptTarget.ES6) { write("super"); } @@ -2638,11 +2639,11 @@ module ts { if (flags & NodeCheckFlags.SuperInstance) { write("_super.prototype"); } - else if (flags & NodeCheckFlags.SuperStatic) { + else if ((flags & NodeCheckFlags.SuperStatic) || (node.parent.kind === SyntaxKind.Constructor)) { write("_super"); } else { - write("super"); + write("_super"); } } } @@ -4538,8 +4539,8 @@ module ts { else if (member.kind === SyntaxKind.GetAccessor || member.kind === SyntaxKind.SetAccessor) { var accessors = getAllAccessorDeclarations(node.members, member); if (member === accessors.firstAccessor) { - writeLine(); if (accessors.getAccessor) { + writeLine(); emitLeadingComments(accessors.getAccessor); emitStart(accessors.getAccessor); if (member.flags & NodeFlags.Static) { @@ -4553,6 +4554,7 @@ module ts { } if (accessors.setAccessor) { // We will only write new line if we just emit getAccessor + writeLine(); emitLeadingComments(accessors.setAccessor); emitStart(accessors.setAccessor); if (member.flags & NodeFlags.Static) { @@ -4570,6 +4572,7 @@ module ts { } function emitConstructor(node: ClassDeclaration, baseTypeNode: TypeReferenceNode) { + debugger; var saveTempCount = tempCount; var saveTempVariables = tempVariables; var saveTempParameters = tempParameters; diff --git a/tests/baselines/reference/callWithSpreadES6.js b/tests/baselines/reference/callWithSpreadES6.js index 0becb4c6e3e0d..d1589d7f6fad1 100644 --- a/tests/baselines/reference/callWithSpreadES6.js +++ b/tests/baselines/reference/callWithSpreadES6.js @@ -55,12 +55,6 @@ var c = new C(1, 2, ...a); //// [callWithSpreadES6.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; function foo(x, y, ...z) { } var a; @@ -84,26 +78,23 @@ xa[1].foo(...[ 2, "abc" ]); -var C = (function () { - function C(x, y, ...z) { +class C { + constructor(x, y, ...z) { this.foo(x, y); this.foo(x, y, ...z); } - C.prototype.foo = function (x, y, ...z) { - }; - return C; -})(); -var D = (function (_super) { - __extends(D, _super); - function D() { - _super.call(this, 1, 2); - _super.call(this, 1, 2, ...a); + foo(x, y, ...z) { } - D.prototype.foo = function () { - _super.prototype.foo.call(this, 1, 2); - _super.prototype.foo.call(this, 1, 2, ...a); - }; - return D; -})(C); +} +class D extends C { + constructor() { + super(1, 2); + super(1, 2, ...a); + } + foo() { + super.foo(1, 2); + super.foo(1, 2, ...a); + } +} // Only supported in when target is ES6 var c = new C(1, 2, ...a); diff --git a/tests/baselines/reference/computedPropertyNames12_ES6.js b/tests/baselines/reference/computedPropertyNames12_ES6.js index 5ab6e4c09b312..fd6ccb6e4860f 100644 --- a/tests/baselines/reference/computedPropertyNames12_ES6.js +++ b/tests/baselines/reference/computedPropertyNames12_ES6.js @@ -20,12 +20,11 @@ class C { var s; var n; var a; -var C = (function () { - function C() { +class C { + constructor() { this[n] = n; this[s + n] = 2; this[`hello bye`] = 0; } - C[`hello ${a} bye`] = 0; - return C; -})(); +} +C[`hello ${a} bye`] = 0; diff --git a/tests/baselines/reference/computedPropertyNames13_ES6.js b/tests/baselines/reference/computedPropertyNames13_ES6.js index 07aa1673aba27..18d81fcec59e4 100644 --- a/tests/baselines/reference/computedPropertyNames13_ES6.js +++ b/tests/baselines/reference/computedPropertyNames13_ES6.js @@ -20,30 +20,27 @@ class C { var s; var n; var a; -var C = (function () { - function C() { - } - C.prototype[s] = function () { - }; - C.prototype[n] = function () { - }; - C[s + s] = function () { - }; - C.prototype[s + n] = function () { - }; - C.prototype[+s] = function () { - }; - C[""] = function () { - }; - C.prototype[0] = function () { - }; - C.prototype[a] = function () { - }; - C[true] = function () { - }; - C.prototype[`hello bye`] = function () { - }; - C[`hello ${a} bye`] = function () { - }; - return C; -})(); +class C { + [s]() { + } + [n]() { + } + static [s + s]() { + } + [s + n]() { + } + [+s]() { + } + static [""]() { + } + [0]() { + } + [a]() { + } + static [true]() { + } + [`hello bye`]() { + } + static [`hello ${a} bye`]() { + } +} diff --git a/tests/baselines/reference/computedPropertyNames14_ES6.js b/tests/baselines/reference/computedPropertyNames14_ES6.js index 7a58ad9a80a19..b1b2a9bf28542 100644 --- a/tests/baselines/reference/computedPropertyNames14_ES6.js +++ b/tests/baselines/reference/computedPropertyNames14_ES6.js @@ -11,20 +11,17 @@ class C { //// [computedPropertyNames14_ES6.js] var b; -var C = (function () { - function C() { +class C { + [b]() { } - C.prototype[b] = function () { - }; - C[true] = function () { - }; - C.prototype[[]] = function () { - }; - C[{}] = function () { - }; - C.prototype[undefined] = function () { - }; - C[null] = function () { - }; - return C; -})(); + static [true]() { + } + [[]]() { + } + static [{}]() { + } + [undefined]() { + } + static [null]() { + } +} diff --git a/tests/baselines/reference/computedPropertyNames15_ES6.js b/tests/baselines/reference/computedPropertyNames15_ES6.js index 70c2e7b451c3a..1a9141ab13d74 100644 --- a/tests/baselines/reference/computedPropertyNames15_ES6.js +++ b/tests/baselines/reference/computedPropertyNames15_ES6.js @@ -12,14 +12,11 @@ class C { var p1; var p2; var p3; -var C = (function () { - function C() { +class C { + [p1]() { } - C.prototype[p1] = function () { - }; - C.prototype[p2] = function () { - }; - C.prototype[p3] = function () { - }; - return C; -})(); + [p2]() { + } + [p3]() { + } +} diff --git a/tests/baselines/reference/computedPropertyNames16_ES6.js b/tests/baselines/reference/computedPropertyNames16_ES6.js index 90f15f6cf2e2e..96e175976da1e 100644 --- a/tests/baselines/reference/computedPropertyNames16_ES6.js +++ b/tests/baselines/reference/computedPropertyNames16_ES6.js @@ -20,80 +20,33 @@ class C { var s; var n; var a; -var C = (function () { - function C() { +class C { + get [s]() { + return 0; } - Object.defineProperty(C.prototype, s, { - get: function () { - return 0; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, n, { - set: function (v) { - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C, s + s, { - get: function () { - return 0; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, s + n, { - set: function (v) { - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, +s, { - get: function () { - return 0; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C, "", { - set: function (v) { - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, 0, { - get: function () { - return 0; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, a, { - set: function (v) { - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C, true, { - get: function () { - return 0; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, `hello bye`, { - set: function (v) { - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, `hello ${a} bye`, { - get: function () { - return 0; - }, - enumerable: true, - configurable: true - }); - return C; -})(); + set [n](v) { + } + static get [s + s]() { + return 0; + } + set [s + n](v) { + } + get [+s]() { + return 0; + } + static set [""](v) { + } + get [0]() { + return 0; + } + set [a](v) { + } + static get [true]() { + return 0; + } + set [`hello bye`](v) { + } + get [`hello ${a} bye`]() { + return 0; + } +} diff --git a/tests/baselines/reference/computedPropertyNames17_ES6.js b/tests/baselines/reference/computedPropertyNames17_ES6.js index e9b19202e088a..a181a61004eda 100644 --- a/tests/baselines/reference/computedPropertyNames17_ES6.js +++ b/tests/baselines/reference/computedPropertyNames17_ES6.js @@ -11,47 +11,20 @@ class C { //// [computedPropertyNames17_ES6.js] var b; -var C = (function () { - function C() { +class C { + get [b]() { + return 0; } - Object.defineProperty(C.prototype, b, { - get: function () { - return 0; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C, true, { - set: function (v) { - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, [], { - get: function () { - return 0; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, {}, { - set: function (v) { - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C, undefined, { - get: function () { - return 0; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, null, { - set: function (v) { - }, - enumerable: true, - configurable: true - }); - return C; -})(); + static set [true](v) { + } + get [[]]() { + return 0; + } + set [{}](v) { + } + static get [undefined]() { + return 0; + } + set [null](v) { + } +} diff --git a/tests/baselines/reference/computedPropertyNames21_ES6.js b/tests/baselines/reference/computedPropertyNames21_ES6.js index f51f6faed2424..c5f6b4e22b199 100644 --- a/tests/baselines/reference/computedPropertyNames21_ES6.js +++ b/tests/baselines/reference/computedPropertyNames21_ES6.js @@ -7,13 +7,10 @@ class C { } //// [computedPropertyNames21_ES6.js] -var C = (function () { - function C() { - } - C.prototype.bar = function () { +class C { + bar() { return 0; - }; - C.prototype[this.bar()] = function () { - }; - return C; -})(); + } + [this.bar()]() { + } +} diff --git a/tests/baselines/reference/computedPropertyNames22_ES6.js b/tests/baselines/reference/computedPropertyNames22_ES6.js index 9872605c20ed0..c88ceb6bc8f53 100644 --- a/tests/baselines/reference/computedPropertyNames22_ES6.js +++ b/tests/baselines/reference/computedPropertyNames22_ES6.js @@ -9,15 +9,12 @@ class C { } //// [computedPropertyNames22_ES6.js] -var C = (function () { - function C() { - } - C.prototype.bar = function () { +class C { + bar() { var obj = { [this.bar()]() { } }; return 0; - }; - return C; -})(); + } +} diff --git a/tests/baselines/reference/computedPropertyNames23_ES6.js b/tests/baselines/reference/computedPropertyNames23_ES6.js index f5687952b88da..0bae1abdad2c1 100644 --- a/tests/baselines/reference/computedPropertyNames23_ES6.js +++ b/tests/baselines/reference/computedPropertyNames23_ES6.js @@ -9,15 +9,12 @@ class C { } //// [computedPropertyNames23_ES6.js] -var C = (function () { - function C() { - } - C.prototype.bar = function () { +class C { + bar() { return 0; - }; - C.prototype[{ + } + [{ [this.bar()]: 1 - }[0]] = function () { - }; - return C; -})(); + }[0]]() { + } +} diff --git a/tests/baselines/reference/computedPropertyNames24_ES6.js b/tests/baselines/reference/computedPropertyNames24_ES6.js index 12aef63396342..8d33db10f71ba 100644 --- a/tests/baselines/reference/computedPropertyNames24_ES6.js +++ b/tests/baselines/reference/computedPropertyNames24_ES6.js @@ -11,28 +11,14 @@ class C extends Base { } //// [computedPropertyNames24_ES6.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var Base = (function () { - function Base() { - } - Base.prototype.bar = function () { +class Base { + bar() { return 0; - }; - return Base; -})(); -var C = (function (_super) { - __extends(C, _super); - function C() { - _super.apply(this, arguments); } +} +class C extends Base { // Gets emitted as super, not _super, which is consistent with // use of super in static properties initializers. - C.prototype[super.bar.call(this)] = function () { - }; - return C; -})(Base); + [super.bar()]() { + } +} diff --git a/tests/baselines/reference/computedPropertyNames25_ES6.js b/tests/baselines/reference/computedPropertyNames25_ES6.js index 1a600df5040cf..cc6a0670b2186 100644 --- a/tests/baselines/reference/computedPropertyNames25_ES6.js +++ b/tests/baselines/reference/computedPropertyNames25_ES6.js @@ -14,31 +14,17 @@ class C extends Base { } //// [computedPropertyNames25_ES6.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var Base = (function () { - function Base() { - } - Base.prototype.bar = function () { +class Base { + bar() { return 0; - }; - return Base; -})(); -var C = (function (_super) { - __extends(C, _super); - function C() { - _super.apply(this, arguments); } - C.prototype.foo = function () { +} +class C extends Base { + foo() { var obj = { - [_super.prototype.bar.call(this)]() { + [super.bar()]() { } }; return 0; - }; - return C; -})(Base); + } +} diff --git a/tests/baselines/reference/computedPropertyNames26_ES6.js b/tests/baselines/reference/computedPropertyNames26_ES6.js index fc53d91e627dd..4526368de7a0a 100644 --- a/tests/baselines/reference/computedPropertyNames26_ES6.js +++ b/tests/baselines/reference/computedPropertyNames26_ES6.js @@ -13,30 +13,16 @@ class C extends Base { } //// [computedPropertyNames26_ES6.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var Base = (function () { - function Base() { - } - Base.prototype.bar = function () { +class Base { + bar() { return 0; - }; - return Base; -})(); -var C = (function (_super) { - __extends(C, _super); - function C() { - _super.apply(this, arguments); } +} +class C extends Base { // Gets emitted as super, not _super, which is consistent with // use of super in static properties initializers. - C.prototype[{ - [super.bar.call(this)]: 1 - }[0]] = function () { - }; - return C; -})(Base); + [{ + [super.bar()]: 1 + }[0]]() { + } +} diff --git a/tests/baselines/reference/computedPropertyNames27_ES6.js b/tests/baselines/reference/computedPropertyNames27_ES6.js index 54a20a5220058..57589dfcaf507 100644 --- a/tests/baselines/reference/computedPropertyNames27_ES6.js +++ b/tests/baselines/reference/computedPropertyNames27_ES6.js @@ -6,23 +6,9 @@ class C extends Base { } //// [computedPropertyNames27_ES6.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var Base = (function () { - function Base() { - } - return Base; -})(); -var C = (function (_super) { - __extends(C, _super); - function C() { - _super.apply(this, arguments); +class Base { +} +class C extends Base { + [(super(), "prop")]() { } - C.prototype[(_super.call(this), "prop")] = function () { - }; - return C; -})(Base); +} diff --git a/tests/baselines/reference/computedPropertyNames28_ES6.js b/tests/baselines/reference/computedPropertyNames28_ES6.js index 09e1b33bf981d..bc0e32593de1f 100644 --- a/tests/baselines/reference/computedPropertyNames28_ES6.js +++ b/tests/baselines/reference/computedPropertyNames28_ES6.js @@ -11,25 +11,14 @@ class C extends Base { } //// [computedPropertyNames28_ES6.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var Base = (function () { - function Base() { - } - return Base; -})(); -var C = (function (_super) { - __extends(C, _super); - function C() { - _super.call(this); +class Base { +} +class C extends Base { + constructor() { + super(); var obj = { - [(_super.call(this), "prop")]() { + [(super(), "prop")]() { } }; } - return C; -})(Base); +} diff --git a/tests/baselines/reference/computedPropertyNames29_ES6.js b/tests/baselines/reference/computedPropertyNames29_ES6.js index e1e6be51b2155..35958b372b09c 100644 --- a/tests/baselines/reference/computedPropertyNames29_ES6.js +++ b/tests/baselines/reference/computedPropertyNames29_ES6.js @@ -11,10 +11,8 @@ class C { } //// [computedPropertyNames29_ES6.js] -var C = (function () { - function C() { - } - C.prototype.bar = function () { +class C { + bar() { (() => { var obj = { [this.bar()]() { @@ -22,6 +20,5 @@ var C = (function () { }; }); return 0; - }; - return C; -})(); + } +} diff --git a/tests/baselines/reference/computedPropertyNames2_ES6.js b/tests/baselines/reference/computedPropertyNames2_ES6.js index e5fcfaac8f927..4287cb2c4b8d7 100644 --- a/tests/baselines/reference/computedPropertyNames2_ES6.js +++ b/tests/baselines/reference/computedPropertyNames2_ES6.js @@ -13,36 +13,17 @@ class C { //// [computedPropertyNames2_ES6.js] var methodName = "method"; var accessorName = "accessor"; -var C = (function () { - function C() { +class C { + [methodName]() { } - C.prototype[methodName] = function () { - }; - C[methodName] = function () { - }; - Object.defineProperty(C.prototype, accessorName, { - get: function () { - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, accessorName, { - set: function (v) { - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C, accessorName, { - get: function () { - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C, accessorName, { - set: function (v) { - }, - enumerable: true, - configurable: true - }); - return C; -})(); + static [methodName]() { + } + get [accessorName]() { + } + set [accessorName](v) { + } + static get [accessorName]() { + } + static set [accessorName](v) { + } +} diff --git a/tests/baselines/reference/computedPropertyNames30_ES6.js b/tests/baselines/reference/computedPropertyNames30_ES6.js index c88fa98be5e86..cda2a278d47aa 100644 --- a/tests/baselines/reference/computedPropertyNames30_ES6.js +++ b/tests/baselines/reference/computedPropertyNames30_ES6.js @@ -16,30 +16,19 @@ class C extends Base { } //// [computedPropertyNames30_ES6.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var Base = (function () { - function Base() { - } - return Base; -})(); -var C = (function (_super) { - __extends(C, _super); - function C() { - _super.call(this); +class Base { +} +class C extends Base { + constructor() { + super(); (() => { var obj = { // Ideally, we would capture this. But the reference is // illegal, and not capturing this is consistent with //treatment of other similar violations. - [(_super.call(this), "prop")]() { + [(super(), "prop")]() { } }; }); } - return C; -})(Base); +} diff --git a/tests/baselines/reference/computedPropertyNames31_ES6.js b/tests/baselines/reference/computedPropertyNames31_ES6.js index 33f5319ded98b..777e03bbcacad 100644 --- a/tests/baselines/reference/computedPropertyNames31_ES6.js +++ b/tests/baselines/reference/computedPropertyNames31_ES6.js @@ -16,34 +16,20 @@ class C extends Base { } //// [computedPropertyNames31_ES6.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var Base = (function () { - function Base() { - } - Base.prototype.bar = function () { +class Base { + bar() { return 0; - }; - return Base; -})(); -var C = (function (_super) { - __extends(C, _super); - function C() { - _super.apply(this, arguments); } - C.prototype.foo = function () { +} +class C extends Base { + foo() { var _this = this; (() => { var obj = { - [_super.prototype.bar.call(_this)]() { + [super.bar()]() { } // needs capture }; }); return 0; - }; - return C; -})(Base); + } +} diff --git a/tests/baselines/reference/computedPropertyNames32_ES6.js b/tests/baselines/reference/computedPropertyNames32_ES6.js index a87f7715d890e..198c5e9981e58 100644 --- a/tests/baselines/reference/computedPropertyNames32_ES6.js +++ b/tests/baselines/reference/computedPropertyNames32_ES6.js @@ -11,13 +11,10 @@ class C { function foo() { return ''; } -var C = (function () { - function C() { - } - C.prototype.bar = function () { +class C { + bar() { return 0; - }; - C.prototype[foo()] = function () { - }; - return C; -})(); + } + [foo()]() { + } +} diff --git a/tests/baselines/reference/computedPropertyNames33_ES6.js b/tests/baselines/reference/computedPropertyNames33_ES6.js index 03c503caec45d..7fb08d2852d8d 100644 --- a/tests/baselines/reference/computedPropertyNames33_ES6.js +++ b/tests/baselines/reference/computedPropertyNames33_ES6.js @@ -13,15 +13,12 @@ class C { function foo() { return ''; } -var C = (function () { - function C() { - } - C.prototype.bar = function () { +class C { + bar() { var obj = { [foo()]() { } }; return 0; - }; - return C; -})(); + } +} diff --git a/tests/baselines/reference/computedPropertyNames34_ES6.js b/tests/baselines/reference/computedPropertyNames34_ES6.js index 62e2e151cd3ac..e73d349bcd73f 100644 --- a/tests/baselines/reference/computedPropertyNames34_ES6.js +++ b/tests/baselines/reference/computedPropertyNames34_ES6.js @@ -13,15 +13,12 @@ class C { function foo() { return ''; } -var C = (function () { - function C() { - } - C.bar = function () { +class C { + static bar() { var obj = { [foo()]() { } }; return 0; - }; - return C; -})(); + } +} diff --git a/tests/baselines/reference/computedPropertyNames36_ES6.js b/tests/baselines/reference/computedPropertyNames36_ES6.js index 5b71326fbc459..573b8fa0c17b4 100644 --- a/tests/baselines/reference/computedPropertyNames36_ES6.js +++ b/tests/baselines/reference/computedPropertyNames36_ES6.js @@ -11,32 +11,15 @@ class C { } //// [computedPropertyNames36_ES6.js] -var Foo = (function () { - function Foo() { - } - return Foo; -})(); -var Foo2 = (function () { - function Foo2() { +class Foo { +} +class Foo2 { +} +class C { + // Computed properties + get ["get1"]() { + return new Foo; } - return Foo2; -})(); -var C = (function () { - function C() { + set ["set1"](p) { } - Object.defineProperty(C.prototype, "get1", { - // Computed properties - get: function () { - return new Foo; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, "set1", { - set: function (p) { - }, - enumerable: true, - configurable: true - }); - return C; -})(); +} diff --git a/tests/baselines/reference/computedPropertyNames37_ES6.js b/tests/baselines/reference/computedPropertyNames37_ES6.js index 992035f68657d..d62c95e6f8c12 100644 --- a/tests/baselines/reference/computedPropertyNames37_ES6.js +++ b/tests/baselines/reference/computedPropertyNames37_ES6.js @@ -11,32 +11,15 @@ class C { } //// [computedPropertyNames37_ES6.js] -var Foo = (function () { - function Foo() { - } - return Foo; -})(); -var Foo2 = (function () { - function Foo2() { +class Foo { +} +class Foo2 { +} +class C { + // Computed properties + get ["get1"]() { + return new Foo; } - return Foo2; -})(); -var C = (function () { - function C() { + set ["set1"](p) { } - Object.defineProperty(C.prototype, "get1", { - // Computed properties - get: function () { - return new Foo; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, "set1", { - set: function (p) { - }, - enumerable: true, - configurable: true - }); - return C; -})(); +} diff --git a/tests/baselines/reference/computedPropertyNames38_ES6.js b/tests/baselines/reference/computedPropertyNames38_ES6.js index 0fdcdb1d63cb9..cf1d01873f296 100644 --- a/tests/baselines/reference/computedPropertyNames38_ES6.js +++ b/tests/baselines/reference/computedPropertyNames38_ES6.js @@ -11,32 +11,15 @@ class C { } //// [computedPropertyNames38_ES6.js] -var Foo = (function () { - function Foo() { - } - return Foo; -})(); -var Foo2 = (function () { - function Foo2() { +class Foo { +} +class Foo2 { +} +class C { + // Computed properties + get [1 << 6]() { + return new Foo; } - return Foo2; -})(); -var C = (function () { - function C() { + set [1 << 6](p) { } - Object.defineProperty(C.prototype, 1 << 6, { - // Computed properties - get: function () { - return new Foo; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, 1 << 6, { - set: function (p) { - }, - enumerable: true, - configurable: true - }); - return C; -})(); +} diff --git a/tests/baselines/reference/computedPropertyNames39_ES6.js b/tests/baselines/reference/computedPropertyNames39_ES6.js index 8e458ad83d7df..9afd60b6464ef 100644 --- a/tests/baselines/reference/computedPropertyNames39_ES6.js +++ b/tests/baselines/reference/computedPropertyNames39_ES6.js @@ -11,32 +11,15 @@ class C { } //// [computedPropertyNames39_ES6.js] -var Foo = (function () { - function Foo() { - } - return Foo; -})(); -var Foo2 = (function () { - function Foo2() { +class Foo { +} +class Foo2 { +} +class C { + // Computed properties + get [1 << 6]() { + return new Foo; } - return Foo2; -})(); -var C = (function () { - function C() { + set [1 << 6](p) { } - Object.defineProperty(C.prototype, 1 << 6, { - // Computed properties - get: function () { - return new Foo; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, 1 << 6, { - set: function (p) { - }, - enumerable: true, - configurable: true - }); - return C; -})(); +} diff --git a/tests/baselines/reference/computedPropertyNames3_ES6.errors.txt b/tests/baselines/reference/computedPropertyNames3_ES6.errors.txt index 3df6d6d97440d..b90091123473a 100644 --- a/tests/baselines/reference/computedPropertyNames3_ES6.errors.txt +++ b/tests/baselines/reference/computedPropertyNames3_ES6.errors.txt @@ -1,12 +1,13 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES6.ts(4,12): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES6.ts(5,9): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES6.ts(5,9): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES6.ts(5,17): error TS1102: 'delete' cannot be called on an identifier in strict mode. tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES6.ts(6,9): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES6.ts(7,16): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES6.ts(7,16): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. -==== tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES6.ts (6 errors) ==== +==== tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES6.ts (7 errors) ==== var id; class C { [0 + 1]() { } @@ -18,6 +19,8 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES6.ts(7,1 !!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. ~~~~~~~~~~~ !!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. + ~~ +!!! error TS1102: 'delete' cannot be called on an identifier in strict mode. set [[0, 1]](v) { } ~~~~~~~~ !!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. diff --git a/tests/baselines/reference/computedPropertyNames3_ES6.js b/tests/baselines/reference/computedPropertyNames3_ES6.js index 1a9c9ee465b2e..b5fb9e88001f4 100644 --- a/tests/baselines/reference/computedPropertyNames3_ES6.js +++ b/tests/baselines/reference/computedPropertyNames3_ES6.js @@ -11,40 +11,21 @@ class C { //// [computedPropertyNames3_ES6.js] var id; -var C = (function () { - function C() { +class C { + [0 + 1]() { } - C.prototype[0 + 1] = function () { - }; - C[() => { - }] = function () { - }; - Object.defineProperty(C.prototype, delete id, { - get: function () { - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, [ + static [() => { + }]() { + } + get [delete id]() { + } + set [[ 0, 1 - ], { - set: function (v) { - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C, "", { - get: function () { - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C, id.toString(), { - set: function (v) { - }, - enumerable: true, - configurable: true - }); - return C; -})(); + ]](v) { + } + static get [""]() { + } + static set [id.toString()](v) { + } +} diff --git a/tests/baselines/reference/computedPropertyNames40_ES6.js b/tests/baselines/reference/computedPropertyNames40_ES6.js index 99d28688a298f..c4820e0ca9823 100644 --- a/tests/baselines/reference/computedPropertyNames40_ES6.js +++ b/tests/baselines/reference/computedPropertyNames40_ES6.js @@ -11,25 +11,16 @@ class C { } //// [computedPropertyNames40_ES6.js] -var Foo = (function () { - function Foo() { - } - return Foo; -})(); -var Foo2 = (function () { - function Foo2() { - } - return Foo2; -})(); -var C = (function () { - function C() { - } +class Foo { +} +class Foo2 { +} +class C { // Computed properties - C.prototype[""] = function () { + [""]() { return new Foo; - }; - C.prototype[""] = function () { + } + [""]() { return new Foo2; - }; - return C; -})(); + } +} diff --git a/tests/baselines/reference/computedPropertyNames41_ES6.js b/tests/baselines/reference/computedPropertyNames41_ES6.js index f0c386706a3f7..5773f892fd597 100644 --- a/tests/baselines/reference/computedPropertyNames41_ES6.js +++ b/tests/baselines/reference/computedPropertyNames41_ES6.js @@ -10,22 +10,13 @@ class C { } //// [computedPropertyNames41_ES6.js] -var Foo = (function () { - function Foo() { - } - return Foo; -})(); -var Foo2 = (function () { - function Foo2() { - } - return Foo2; -})(); -var C = (function () { - function C() { - } +class Foo { +} +class Foo2 { +} +class C { // Computed properties - C[""] = function () { + static [""]() { return new Foo; - }; - return C; -})(); + } +} diff --git a/tests/baselines/reference/computedPropertyNames42_ES6.js b/tests/baselines/reference/computedPropertyNames42_ES6.js index 8538088f4500a..b6114f06bac84 100644 --- a/tests/baselines/reference/computedPropertyNames42_ES6.js +++ b/tests/baselines/reference/computedPropertyNames42_ES6.js @@ -10,18 +10,9 @@ class C { } //// [computedPropertyNames42_ES6.js] -var Foo = (function () { - function Foo() { - } - return Foo; -})(); -var Foo2 = (function () { - function Foo2() { - } - return Foo2; -})(); -var C = (function () { - function C() { - } - return C; -})(); +class Foo { +} +class Foo2 { +} +class C { +} diff --git a/tests/baselines/reference/computedPropertyNames43_ES6.js b/tests/baselines/reference/computedPropertyNames43_ES6.js index ba0c228c30738..ab9d09834d20a 100644 --- a/tests/baselines/reference/computedPropertyNames43_ES6.js +++ b/tests/baselines/reference/computedPropertyNames43_ES6.js @@ -13,45 +13,17 @@ class D extends C { } //// [computedPropertyNames43_ES6.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var Foo = (function () { - function Foo() { - } - return Foo; -})(); -var Foo2 = (function () { - function Foo2() { - } - return Foo2; -})(); -var C = (function () { - function C() { +class Foo { +} +class Foo2 { +} +class C { +} +class D extends C { + // Computed properties + get ["get1"]() { + return new Foo; } - return C; -})(); -var D = (function (_super) { - __extends(D, _super); - function D() { - _super.apply(this, arguments); + set ["set1"](p) { } - Object.defineProperty(D.prototype, "get1", { - // Computed properties - get: function () { - return new Foo; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(D.prototype, "set1", { - set: function (p) { - }, - enumerable: true, - configurable: true - }); - return D; -})(C); +} diff --git a/tests/baselines/reference/computedPropertyNames44_ES6.js b/tests/baselines/reference/computedPropertyNames44_ES6.js index 72729054e076f..13d46131e924b 100644 --- a/tests/baselines/reference/computedPropertyNames44_ES6.js +++ b/tests/baselines/reference/computedPropertyNames44_ES6.js @@ -12,44 +12,16 @@ class D extends C { } //// [computedPropertyNames44_ES6.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var Foo = (function () { - function Foo() { - } - return Foo; -})(); -var Foo2 = (function () { - function Foo2() { - } - return Foo2; -})(); -var C = (function () { - function C() { +class Foo { +} +class Foo2 { +} +class C { + get ["get1"]() { + return new Foo; } - Object.defineProperty(C.prototype, "get1", { - get: function () { - return new Foo; - }, - enumerable: true, - configurable: true - }); - return C; -})(); -var D = (function (_super) { - __extends(D, _super); - function D() { - _super.apply(this, arguments); +} +class D extends C { + set ["set1"](p) { } - Object.defineProperty(D.prototype, "set1", { - set: function (p) { - }, - enumerable: true, - configurable: true - }); - return D; -})(C); +} diff --git a/tests/baselines/reference/computedPropertyNames45_ES6.js b/tests/baselines/reference/computedPropertyNames45_ES6.js index 23dccc7795691..bea5f5211ea7d 100644 --- a/tests/baselines/reference/computedPropertyNames45_ES6.js +++ b/tests/baselines/reference/computedPropertyNames45_ES6.js @@ -13,44 +13,16 @@ class D extends C { } //// [computedPropertyNames45_ES6.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var Foo = (function () { - function Foo() { - } - return Foo; -})(); -var Foo2 = (function () { - function Foo2() { - } - return Foo2; -})(); -var C = (function () { - function C() { +class Foo { +} +class Foo2 { +} +class C { + get ["get1"]() { + return new Foo; } - Object.defineProperty(C.prototype, "get1", { - get: function () { - return new Foo; - }, - enumerable: true, - configurable: true - }); - return C; -})(); -var D = (function (_super) { - __extends(D, _super); - function D() { - _super.apply(this, arguments); +} +class D extends C { + set ["set1"](p) { } - Object.defineProperty(D.prototype, "set1", { - set: function (p) { - }, - enumerable: true, - configurable: true - }); - return D; -})(C); +} diff --git a/tests/baselines/reference/computedPropertyNamesDeclarationEmit1_ES6.js b/tests/baselines/reference/computedPropertyNamesDeclarationEmit1_ES6.js index eb7dab0b660f4..f234ae0d97e2b 100644 --- a/tests/baselines/reference/computedPropertyNamesDeclarationEmit1_ES6.js +++ b/tests/baselines/reference/computedPropertyNamesDeclarationEmit1_ES6.js @@ -6,26 +6,15 @@ class C { } //// [computedPropertyNamesDeclarationEmit1_ES6.js] -var C = (function () { - function C() { +class C { + ["" + ""]() { } - C.prototype["" + ""] = function () { - }; - Object.defineProperty(C.prototype, "" + "", { - get: function () { - return 0; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, "" + "", { - set: function (x) { - }, - enumerable: true, - configurable: true - }); - return C; -})(); + get ["" + ""]() { + return 0; + } + set ["" + ""](x) { + } +} //// [computedPropertyNamesDeclarationEmit1_ES6.d.ts] diff --git a/tests/baselines/reference/computedPropertyNamesDeclarationEmit2_ES6.js b/tests/baselines/reference/computedPropertyNamesDeclarationEmit2_ES6.js index 3912113905c84..b5e70193b0d11 100644 --- a/tests/baselines/reference/computedPropertyNamesDeclarationEmit2_ES6.js +++ b/tests/baselines/reference/computedPropertyNamesDeclarationEmit2_ES6.js @@ -6,26 +6,15 @@ class C { } //// [computedPropertyNamesDeclarationEmit2_ES6.js] -var C = (function () { - function C() { +class C { + static ["" + ""]() { } - C["" + ""] = function () { - }; - Object.defineProperty(C, "" + "", { - get: function () { - return 0; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C, "" + "", { - set: function (x) { - }, - enumerable: true, - configurable: true - }); - return C; -})(); + static get ["" + ""]() { + return 0; + } + static set ["" + ""](x) { + } +} //// [computedPropertyNamesDeclarationEmit2_ES6.d.ts] diff --git a/tests/baselines/reference/computedPropertyNamesOnOverloads_ES6.js b/tests/baselines/reference/computedPropertyNamesOnOverloads_ES6.js index 264a6a75074b1..ced0a8d449a2e 100644 --- a/tests/baselines/reference/computedPropertyNamesOnOverloads_ES6.js +++ b/tests/baselines/reference/computedPropertyNamesOnOverloads_ES6.js @@ -10,10 +10,7 @@ class C { //// [computedPropertyNamesOnOverloads_ES6.js] var methodName = "method"; var accessorName = "accessor"; -var C = (function () { - function C() { +class C { + [methodName](v) { } - C.prototype[methodName] = function (v) { - }; - return C; -})(); +} diff --git a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES5.js.map b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES5.js.map index c47fcfcad3114..3457187e78a61 100644 --- a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES5.js.map +++ b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES5.js.map @@ -1,2 +1,2 @@ //// [computedPropertyNamesSourceMap1_ES5.js.map] -{"version":3,"file":"computedPropertyNamesSourceMap1_ES5.js","sourceRoot":"","sources":["computedPropertyNamesSourceMap1_ES5.ts"],"names":["C","C.constructor","C[\"hello\"]"],"mappings":"AAAA;IAAAA;IAIAC,CAACA;IAHGD,YAACA,OAAOA,CAACA,GAATA;QACIE,QAAQA,CAACA;IACbA,CAACA;IACLF,QAACA;AAADA,CAACA,AAJD,IAIC"} \ No newline at end of file +{"version":3,"file":"computedPropertyNamesSourceMap1_ES5.js","sourceRoot":"","sources":["computedPropertyNamesSourceMap1_ES5.ts"],"names":["C","C.constructor","C[\"hello\"]"],"mappings":"AAAA;IAAAA;IAIAC,CAACA;IAHGD,YAACA,OAAOA;QACJE,QAAQA,CAACA;IACbA,CAACA;IACLF,QAACA;AAADA,CAACA,AAJD,IAIC"} \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES5.sourcemap.txt b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES5.sourcemap.txt index df0af71fb0224..be0f79edd17a3 100644 --- a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES5.sourcemap.txt +++ b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES5.sourcemap.txt @@ -37,24 +37,18 @@ sourceFile:computedPropertyNamesSourceMap1_ES5.ts 1->^^^^ 2 > ^^^^^^^^^^^^ 3 > ^^^^^^^ -4 > ^ -5 > ^^^ 1-> 2 > [ 3 > "hello" -4 > ] -5 > 1->Emitted(4, 5) Source(2, 5) + SourceIndex(0) name (C) 2 >Emitted(4, 17) Source(2, 6) + SourceIndex(0) name (C) 3 >Emitted(4, 24) Source(2, 13) + SourceIndex(0) name (C) -4 >Emitted(4, 25) Source(2, 14) + SourceIndex(0) name (C) -5 >Emitted(4, 28) Source(2, 5) + SourceIndex(0) name (C) --- >>> debugger; 1 >^^^^^^^^ 2 > ^^^^^^^^ 3 > ^ -1 >["hello"]() { +1 >]() { > 2 > debugger 3 > ; diff --git a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.js b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.js index f7dc9e1783690..749ab99b18b02 100644 --- a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.js +++ b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.js @@ -6,12 +6,9 @@ class C { } //// [computedPropertyNamesSourceMap1_ES6.js] -var C = (function () { - function C() { - } - C.prototype["hello"] = function () { +class C { + ["hello"]() { debugger; - }; - return C; -})(); + } +} //# sourceMappingURL=computedPropertyNamesSourceMap1_ES6.js.map \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.js.map b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.js.map index 20765a5b2d4e2..ff47df55493af 100644 --- a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.js.map +++ b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.js.map @@ -1,2 +1,2 @@ //// [computedPropertyNamesSourceMap1_ES6.js.map] -{"version":3,"file":"computedPropertyNamesSourceMap1_ES6.js","sourceRoot":"","sources":["computedPropertyNamesSourceMap1_ES6.ts"],"names":["C","C.constructor","C[\"hello\"]"],"mappings":"AAAA;IAAAA;IAIAC,CAACA;IAHGD,YAACA,OAAOA,CAACA,GAATA;QACIE,QAAQA,CAACA;IACbA,CAACA;IACLF,QAACA;AAADA,CAACA,AAJD,IAIC"} \ No newline at end of file +{"version":3,"file":"computedPropertyNamesSourceMap1_ES6.js","sourceRoot":"","sources":["computedPropertyNamesSourceMap1_ES6.ts"],"names":["C","C[\"hello\"]"],"mappings":"AAAA;IACIA,CAACA,OAAOA;QACJC,QAAQA,CAACA;IACbA,CAACA;AACLD,CAACA;AAAA"} \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.sourcemap.txt b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.sourcemap.txt index 64713447e4333..36535c1aa4f26 100644 --- a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.sourcemap.txt +++ b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.sourcemap.txt @@ -8,96 +8,58 @@ sources: computedPropertyNamesSourceMap1_ES6.ts emittedFile:tests/cases/conformance/es6/computedProperties/computedPropertyNamesSourceMap1_ES6.js sourceFile:computedPropertyNamesSourceMap1_ES6.ts ------------------------------------------------------------------- ->>>var C = (function () { +>>>class C { 1 > -2 >^^^^^^^^^^^^^^^^^^^-> +2 >^^^^^^^^^^^^^^^^^^-> 1 > 1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0) --- ->>> function C() { -1->^^^^ -2 > ^^-> -1-> -1->Emitted(2, 5) Source(1, 1) + SourceIndex(0) name (C) ---- ->>> } +>>> ["hello"]() { 1->^^^^ 2 > ^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +3 > ^^^^^^^ +4 > ^^^^^^-> 1->class C { - > ["hello"]() { - > debugger; - > } - > -2 > } -1->Emitted(3, 5) Source(5, 1) + SourceIndex(0) name (C.constructor) -2 >Emitted(3, 6) Source(5, 2) + SourceIndex(0) name (C.constructor) ---- ->>> C.prototype["hello"] = function () { -1->^^^^ -2 > ^^^^^^^^^^^^ -3 > ^^^^^^^ -4 > ^ -5 > ^^^ -1-> + > 2 > [ -3 > "hello" -4 > ] -5 > -1->Emitted(4, 5) Source(2, 5) + SourceIndex(0) name (C) -2 >Emitted(4, 17) Source(2, 6) + SourceIndex(0) name (C) -3 >Emitted(4, 24) Source(2, 13) + SourceIndex(0) name (C) -4 >Emitted(4, 25) Source(2, 14) + SourceIndex(0) name (C) -5 >Emitted(4, 28) Source(2, 5) + SourceIndex(0) name (C) +3 > "hello" +1->Emitted(2, 5) Source(2, 5) + SourceIndex(0) name (C) +2 >Emitted(2, 6) Source(2, 6) + SourceIndex(0) name (C) +3 >Emitted(2, 13) Source(2, 13) + SourceIndex(0) name (C) --- >>> debugger; -1 >^^^^^^^^ +1->^^^^^^^^ 2 > ^^^^^^^^ 3 > ^ -1 >["hello"]() { +1->]() { > 2 > debugger 3 > ; -1 >Emitted(5, 9) Source(3, 9) + SourceIndex(0) name (C["hello"]) -2 >Emitted(5, 17) Source(3, 17) + SourceIndex(0) name (C["hello"]) -3 >Emitted(5, 18) Source(3, 18) + SourceIndex(0) name (C["hello"]) +1->Emitted(3, 9) Source(3, 9) + SourceIndex(0) name (C["hello"]) +2 >Emitted(3, 17) Source(3, 17) + SourceIndex(0) name (C["hello"]) +3 >Emitted(3, 18) Source(3, 18) + SourceIndex(0) name (C["hello"]) --- ->>> }; +>>> } 1 >^^^^ 2 > ^ -3 > ^^^^^^^^^-> 1 > > 2 > } -1 >Emitted(6, 5) Source(4, 5) + SourceIndex(0) name (C["hello"]) -2 >Emitted(6, 6) Source(4, 6) + SourceIndex(0) name (C["hello"]) ---- ->>> return C; -1->^^^^ -2 > ^^^^^^^^ -1-> - > -2 > } -1->Emitted(7, 5) Source(5, 1) + SourceIndex(0) name (C) -2 >Emitted(7, 13) Source(5, 2) + SourceIndex(0) name (C) +1 >Emitted(4, 5) Source(4, 5) + SourceIndex(0) name (C["hello"]) +2 >Emitted(4, 6) Source(4, 6) + SourceIndex(0) name (C["hello"]) --- ->>>})(); +>>>} 1 > 2 >^ -3 > -4 > ^^^^ -5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 > +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + > 2 >} -3 > -4 > class C { - > ["hello"]() { - > debugger; - > } - > } -1 >Emitted(8, 1) Source(5, 1) + SourceIndex(0) name (C) -2 >Emitted(8, 2) Source(5, 2) + SourceIndex(0) name (C) -3 >Emitted(8, 2) Source(1, 1) + SourceIndex(0) -4 >Emitted(8, 6) Source(5, 2) + SourceIndex(0) +1 >Emitted(5, 1) Source(5, 1) + SourceIndex(0) name (C) +2 >Emitted(5, 2) Source(5, 2) + SourceIndex(0) name (C) --- ->>>//# sourceMappingURL=computedPropertyNamesSourceMap1_ES6.js.map \ No newline at end of file +>>>//# sourceMappingURL=computedPropertyNamesSourceMap1_ES6.js.map1-> +2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1-> +1->Emitted(6, 1) Source(5, 2) + SourceIndex(0) +--- \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-scopes.js b/tests/baselines/reference/constDeclarations-scopes.js index f8fbc47312b1b..b144b4f83a553 100644 --- a/tests/baselines/reference/constDeclarations-scopes.js +++ b/tests/baselines/reference/constDeclarations-scopes.js @@ -242,30 +242,25 @@ var m; } })(m || (m = {})); // methods -var C = (function () { - function C() { +class C { + constructor() { const c = 0; n = c; } - C.prototype.method = function () { + method() { const c = 0; n = c; - }; - Object.defineProperty(C.prototype, "v", { - get: function () { - const c = 0; - n = c; - return n; - }, - set: function (value) { - const c = 0; - n = c; - }, - enumerable: true, - configurable: true - }); - return C; -})(); + } + get v() { + const c = 0; + n = c; + return n; + } + set v(value) { + const c = 0; + n = c; + } +} // object literals var o = { f() { diff --git a/tests/baselines/reference/constDeclarations-validContexts.js b/tests/baselines/reference/constDeclarations-validContexts.js index 5a54e915713ad..7d3269c66832d 100644 --- a/tests/baselines/reference/constDeclarations-validContexts.js +++ b/tests/baselines/reference/constDeclarations-validContexts.js @@ -201,26 +201,21 @@ var m; } })(m || (m = {})); // methods -var C = (function () { - function C() { +class C { + constructor() { const c24 = 0; } - C.prototype.method = function () { + method() { const c25 = 0; - }; - Object.defineProperty(C.prototype, "v", { - get: function () { - const c26 = 0; - return c26; - }, - set: function (value) { - const c27 = value; - }, - enumerable: true, - configurable: true - }); - return C; -})(); + } + get v() { + const c26 = 0; + return c26; + } + set v(value) { + const c27 = value; + } +} // object literals var o = { f() { diff --git a/tests/baselines/reference/destructuringParameterProperties4.js b/tests/baselines/reference/destructuringParameterProperties4.js index 6da6f53a4fe04..cd6334c8568cd 100644 --- a/tests/baselines/reference/destructuringParameterProperties4.js +++ b/tests/baselines/reference/destructuringParameterProperties4.js @@ -28,38 +28,26 @@ class C2 extends C1 { //// [destructuringParameterProperties4.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var C1 = (function () { - function C1(k, [a, b, c]) { +class C1 { + constructor(k, [a, b, c]) { this.k = k; this.[a, b, c] = [a, b, c]; if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { this.a = a || k; } } - C1.prototype.getA = function () { + getA() { return this.a; - }; - C1.prototype.getB = function () { + } + getB() { return this.b; - }; - C1.prototype.getC = function () { + } + getC() { return this.c; - }; - return C1; -})(); -var C2 = (function (_super) { - __extends(C2, _super); - function C2() { - _super.apply(this, arguments); } - C2.prototype.doSomethingWithSuperProperties = function () { +} +class C2 extends C1 { + doSomethingWithSuperProperties() { return `${this.a} ${this.b} ${this.c}`; - }; - return C2; -})(C1); + } +} diff --git a/tests/baselines/reference/emitDefaultParametersMethodES6.js b/tests/baselines/reference/emitDefaultParametersMethodES6.js index bf96e00e375fd..3981ddcba3cc6 100644 --- a/tests/baselines/reference/emitDefaultParametersMethodES6.js +++ b/tests/baselines/reference/emitDefaultParametersMethodES6.js @@ -17,26 +17,23 @@ class E { } //// [emitDefaultParametersMethodES6.js] -var C = (function () { - function C(t, z, x, y = "hello") { +class C { + constructor(t, z, x, y = "hello") { } - C.prototype.foo = function (x, t = false) { - }; - C.prototype.foo1 = function (x, t = false, ...rest) { - }; - C.prototype.bar = function (t = false) { - }; - C.prototype.boo = function (t = false, ...rest) { - }; - return C; -})(); -var D = (function () { - function D(y = "hello") { + foo(x, t = false) { } - return D; -})(); -var E = (function () { - function E(y = "hello", ...rest) { + foo1(x, t = false, ...rest) { } - return E; -})(); + bar(t = false) { + } + boo(t = false, ...rest) { + } +} +class D { + constructor(y = "hello") { + } +} +class E { + constructor(y = "hello", ...rest) { + } +} diff --git a/tests/baselines/reference/emitRestParametersMethodES6.js b/tests/baselines/reference/emitRestParametersMethodES6.js index d0a0e2a120ccc..fba6ed01e676f 100644 --- a/tests/baselines/reference/emitRestParametersMethodES6.js +++ b/tests/baselines/reference/emitRestParametersMethodES6.js @@ -15,21 +15,19 @@ class D { //// [emitRestParametersMethodES6.js] -var C = (function () { - function C(name, ...rest) { +class C { + constructor(name, ...rest) { } - C.prototype.bar = function (...rest) { - }; - C.prototype.foo = function (x, ...rest) { - }; - return C; -})(); -var D = (function () { - function D(...rest) { + bar(...rest) { } - D.prototype.bar = function (...rest) { - }; - D.prototype.foo = function (x, ...rest) { - }; - return D; -})(); + foo(x, ...rest) { + } +} +class D { + constructor(...rest) { + } + bar(...rest) { + } + foo(x, ...rest) { + } +} From c984e8105311631fdf2d1a4ffc3d1557e7f1ce95 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Sun, 15 Mar 2015 18:23:48 -0700 Subject: [PATCH 077/224] Fix issue of the default binding not elided if namedImport is reference Conflicts: src/compiler/checker.ts src/compiler/emitter.ts tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.js tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportInEs5.js tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportWithExport.js tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.js tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5.js tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingWithExport.js --- src/compiler/checker.ts | 1 - src/compiler/emitter.ts | 64 ++++++++++--------- ...efaultBindingFollowedWithNamedImportDts.js | 10 +-- ...aultBindingFollowedWithNamespaceBinding.js | 2 +- 4 files changed, 41 insertions(+), 36 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8f76a4392fcaa..8bead03a49bb6 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11033,7 +11033,6 @@ module ts { return true; } } - return forEachChild(node, isReferencedAliasDeclaration); } function isImplementationOfOverload(node: FunctionLikeDeclaration) { diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 67dbb375fdf1c..363f547477b46 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -5061,7 +5061,7 @@ module ts { // ES6 import if (node.importClause) { let shouldEmitDefaultBindings = node.importClause.name && resolver.isReferencedAliasDeclaration(node.importClause); - let shouldEmitNamedBindings = hasReferencedNamedBindings(); + let shouldEmitNamedBindings = hasReferencedNamedBindings(node.importClause); if (shouldEmitDefaultBindings || shouldEmitNamedBindings) { write("import "); emitStart(node.importClause); @@ -5109,16 +5109,16 @@ module ts { emit(node.moduleSpecifier); write(";"); } + } - function hasReferencedNamedBindings() { - if (node.importClause.namedBindings) { - if (node.importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { - return resolver.isReferencedAliasDeclaration(node.importClause.namedBindings); - } - else { - return forEach((node.importClause.namedBindings).elements, - namedImport => resolver.isReferencedAliasDeclaration(namedImport)); - } + function hasReferencedNamedBindings(importClause: ImportClause) { + if (importClause && importClause.namedBindings) { + if (importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { + return resolver.isReferencedAliasDeclaration(importClause.namedBindings); + } + else { + return forEach((importClause.namedBindings).elements, + namedImport => resolver.isReferencedAliasDeclaration(namedImport)); } } } @@ -5262,36 +5262,44 @@ module ts { function createExternalImportInfo(node: Node): ExternalImportInfo { if (node.kind === SyntaxKind.ImportEqualsDeclaration) { if ((node).moduleReference.kind === SyntaxKind.ExternalModuleReference) { - return { - rootNode: node, - declarationNode: node - }; + if (resolver.isReferencedAliasDeclaration(node)) { + return { + rootNode: node, + declarationNode: node + }; + } } } else if (node.kind === SyntaxKind.ImportDeclaration) { let importClause = (node).importClause; if (importClause) { - if (importClause.name) { + if (importClause.name && resolver.isReferencedAliasDeclaration(importClause)) { return { rootNode: node, declarationNode: importClause }; } - if (importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { - return { - rootNode: node, - declarationNode: importClause.namedBindings - }; + if (hasReferencedNamedBindings(importClause)) { + if (importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { + return { + rootNode: node, + declarationNode: importClause.namedBindings + }; + } + else { + return { + rootNode: node, + namedImports: importClause.namedBindings, + localName: resolver.getGeneratedNameForNode(node) + }; + } } + } + else { return { - rootNode: node, - namedImports: importClause.namedBindings, - localName: resolver.getGeneratedNameForNode(node) + rootNode: node }; } - return { - rootNode: node - } } else if (node.kind === SyntaxKind.ExportDeclaration) { if ((node).moduleSpecifier) { @@ -5327,9 +5335,7 @@ module ts { else { let info = createExternalImportInfo(node); if (info) { - if ((!info.declarationNode && !info.namedImports) || resolver.isReferencedAliasDeclaration(node)) { - externalImports.push(info); - } + externalImports.push(info); } } }); diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.js index 15d4c7f2fc9e5..a6b2c9a16701a 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImportDts.js @@ -62,16 +62,16 @@ var x11 = (function () { })(); exports.x11 = x11; //// [client.js] -var defaultBinding2 = require("server"); +var _server_1 = require("server"); exports.x1 = new _server_1.a(); -var defaultBinding3 = require("server"); +var _server_2 = require("server"); exports.x2 = new _server_2.a11(); -var defaultBinding4 = require("server"); +var _server_3 = require("server"); exports.x4 = new _server_3.x(); exports.x5 = new _server_3.a12(); -var defaultBinding5 = require("server"); +var _server_4 = require("server"); exports.x3 = new _server_4.x11(); -var defaultBinding6 = require("server"); +var _server_5 = require("server"); exports.x6 = new _server_5.m(); diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js index 1ba095221dce8..2b24fda075559 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding.js @@ -11,7 +11,7 @@ var x: number = nameSpaceBinding.a; //// [es6ImportDefaultBindingFollowedWithNamespaceBinding_0.js] export var a = 10; //// [es6ImportDefaultBindingFollowedWithNamespaceBinding_1.js] -import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; +import * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBinding_0"; var x = nameSpaceBinding.a; From c877b1e0a59761a18c147bb931c7e7103b42fecd Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Sun, 15 Mar 2015 18:24:12 -0700 Subject: [PATCH 078/224] Add tests --- .../reference/es6ImportDefaultBindingAmd.js | 28 +++++++++++++++++ .../es6ImportDefaultBindingAmd.types | 19 ++++++++++++ .../es6ImportDefaultBindingDts.errors.txt | 15 ++++++++++ .../reference/es6ImportDefaultBindingDts.js | 29 ++++++++++++++++++ ...ndingFollowedWithNamespaceBinding1InEs5.js | 23 ++++++++++++++ ...ngFollowedWithNamespaceBinding1InEs5.types | 17 +++++++++++ ...FollowedWithNamespaceBindingDts.errors.txt | 15 ++++++++++ ...tBindingFollowedWithNamespaceBindingDts.js | 25 ++++++++++++++++ ...ollowedWithNamespaceBindingDts1.errors.txt | 13 ++++++++ ...BindingFollowedWithNamespaceBindingDts1.js | 30 +++++++++++++++++++ .../compiler/es6ImportDefaultBindingAmd.ts | 11 +++++++ .../compiler/es6ImportDefaultBindingDts.ts | 11 +++++++ ...ndingFollowedWithNamespaceBinding1InEs5.ts | 11 +++++++ ...tBindingFollowedWithNamespaceBindingDts.ts | 9 ++++++ ...BindingFollowedWithNamespaceBindingDts1.ts | 10 +++++++ 15 files changed, 266 insertions(+) create mode 100644 tests/baselines/reference/es6ImportDefaultBindingAmd.js create mode 100644 tests/baselines/reference/es6ImportDefaultBindingAmd.types create mode 100644 tests/baselines/reference/es6ImportDefaultBindingDts.errors.txt create mode 100644 tests/baselines/reference/es6ImportDefaultBindingDts.js create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.js create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.types create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.errors.txt create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.js create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.errors.txt create mode 100644 tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.js create mode 100644 tests/cases/compiler/es6ImportDefaultBindingAmd.ts create mode 100644 tests/cases/compiler/es6ImportDefaultBindingDts.ts create mode 100644 tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.ts create mode 100644 tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.ts create mode 100644 tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.ts diff --git a/tests/baselines/reference/es6ImportDefaultBindingAmd.js b/tests/baselines/reference/es6ImportDefaultBindingAmd.js new file mode 100644 index 0000000000000..34b39cda4b77b --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingAmd.js @@ -0,0 +1,28 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingAmd.ts] //// + +//// [es6ImportDefaultBindingAmd_0.ts] + +var a = 10; +export = a; + +//// [es6ImportDefaultBindingAmd_1.ts] +import defaultBinding from "es6ImportDefaultBindingAmd_0"; +var x = defaultBinding; +import defaultBinding2 from "es6ImportDefaultBindingAmd_0"; // elide this import since defaultBinding2 is not used + + +//// [es6ImportDefaultBindingAmd_0.js] +define(["require", "exports"], function (require, exports) { + var a = 10; + return a; +}); +//// [es6ImportDefaultBindingAmd_1.js] +define(["require", "exports", "es6ImportDefaultBindingAmd_0"], function (require, exports, defaultBinding) { + var x = defaultBinding; +}); + + +//// [es6ImportDefaultBindingAmd_0.d.ts] +declare var a: number; +export = a; +//// [es6ImportDefaultBindingAmd_1.d.ts] diff --git a/tests/baselines/reference/es6ImportDefaultBindingAmd.types b/tests/baselines/reference/es6ImportDefaultBindingAmd.types new file mode 100644 index 0000000000000..9b067ef27a405 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingAmd.types @@ -0,0 +1,19 @@ +=== tests/cases/compiler/es6ImportDefaultBindingAmd_0.ts === + +var a = 10; +>a : number + +export = a; +>a : number + +=== tests/cases/compiler/es6ImportDefaultBindingAmd_1.ts === +import defaultBinding from "es6ImportDefaultBindingAmd_0"; +>defaultBinding : number + +var x = defaultBinding; +>x : number +>defaultBinding : number + +import defaultBinding2 from "es6ImportDefaultBindingAmd_0"; // elide this import since defaultBinding2 is not used +>defaultBinding2 : number + diff --git a/tests/baselines/reference/es6ImportDefaultBindingDts.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingDts.errors.txt new file mode 100644 index 0000000000000..fc1e1a1925c63 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingDts.errors.txt @@ -0,0 +1,15 @@ +tests/cases/compiler/client.ts(2,12): error TS4025: Exported variable 'x' has or is using private name 'defaultBinding'. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + class c { } + export = c; + +==== tests/cases/compiler/client.ts (1 errors) ==== + import defaultBinding from "server"; + export var x = new defaultBinding(); + ~ +!!! error TS4025: Exported variable 'x' has or is using private name 'defaultBinding'. + import defaultBinding2 from "server"; // elide this import since defaultBinding2 is not used + \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingDts.js b/tests/baselines/reference/es6ImportDefaultBindingDts.js new file mode 100644 index 0000000000000..ad58abd8125a8 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingDts.js @@ -0,0 +1,29 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingDts.ts] //// + +//// [server.ts] + +class c { } +export = c; + +//// [client.ts] +import defaultBinding from "server"; +export var x = new defaultBinding(); +import defaultBinding2 from "server"; // elide this import since defaultBinding2 is not used + + +//// [server.js] +var c = (function () { + function c() { + } + return c; +})(); +module.exports = c; +//// [client.js] +var defaultBinding = require("server"); +exports.x = new defaultBinding(); + + +//// [server.d.ts] +declare class c { +} +export = c; diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.js new file mode 100644 index 0000000000000..00166b1bc41fc --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.js @@ -0,0 +1,23 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.ts] //// + +//// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.ts] + +var a = 10; +export = a; + +//// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.ts] +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"; +var x: number = defaultBinding; + +//// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.js] +var a = 10; +module.exports = a; +//// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.js] +var defaultBinding = require("es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"); +var x = defaultBinding; + + +//// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.d.ts] +declare var a: number; +export = a; +//// [es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.d.ts] diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.types b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.types new file mode 100644 index 0000000000000..dfbc8c0be07ce --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.types @@ -0,0 +1,17 @@ +=== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.ts === + +var a = 10; +>a : number + +export = a; +>a : number + +=== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.ts === +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"; +>defaultBinding : number +>nameSpaceBinding : typeof nameSpaceBinding + +var x: number = defaultBinding; +>x : number +>defaultBinding : number + diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.errors.txt new file mode 100644 index 0000000000000..b82fb1155e94b --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.errors.txt @@ -0,0 +1,15 @@ +tests/cases/compiler/client.ts(1,8): error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. +tests/cases/compiler/client.ts(2,12): error TS4025: Exported variable 'x' has or is using private name 'nameSpaceBinding.a'. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + export class a { } + +==== tests/cases/compiler/client.ts (2 errors) ==== + import defaultBinding, * as nameSpaceBinding from "server"; + ~~~~~~~~~~~~~~ +!!! error TS1192: External module '"tests/cases/compiler/server"' has no default export or export assignment. + export var x = new nameSpaceBinding.a(); + ~ +!!! error TS4025: Exported variable 'x' has or is using private name 'nameSpaceBinding.a'. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.js new file mode 100644 index 0000000000000..3068fb6d39dc7 --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.js @@ -0,0 +1,25 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.ts] //// + +//// [server.ts] + +export class a { } + +//// [client.ts] +import defaultBinding, * as nameSpaceBinding from "server"; +export var x = new nameSpaceBinding.a(); + +//// [server.js] +var a = (function () { + function a() { + } + return a; +})(); +exports.a = a; +//// [client.js] +var nameSpaceBinding = require("server"); +exports.x = new nameSpaceBinding.a(); + + +//// [server.d.ts] +export declare class a { +} diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.errors.txt new file mode 100644 index 0000000000000..3b09108bbfc3a --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.errors.txt @@ -0,0 +1,13 @@ +tests/cases/compiler/client.ts(2,12): error TS4025: Exported variable 'x' has or is using private name 'defaultBinding'. + + +==== tests/cases/compiler/server.ts (0 errors) ==== + + class a { } + export = a; + +==== tests/cases/compiler/client.ts (1 errors) ==== + import defaultBinding, * as nameSpaceBinding from "server"; + export var x = new defaultBinding(); + ~ +!!! error TS4025: Exported variable 'x' has or is using private name 'defaultBinding'. \ No newline at end of file diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.js b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.js new file mode 100644 index 0000000000000..708cffca29d1d --- /dev/null +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.js @@ -0,0 +1,30 @@ +//// [tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.ts] //// + +//// [server.ts] + +class a { } +export = a; + +//// [client.ts] +import defaultBinding, * as nameSpaceBinding from "server"; +export var x = new defaultBinding(); + +//// [server.js] +define(["require", "exports"], function (require, exports) { + var a = (function () { + function a() { + } + return a; + })(); + return a; +}); +//// [client.js] +define(["require", "exports", "server"], function (require, exports, defaultBinding) { + exports.x = new defaultBinding(); +}); + + +//// [server.d.ts] +declare class a { +} +export = a; diff --git a/tests/cases/compiler/es6ImportDefaultBindingAmd.ts b/tests/cases/compiler/es6ImportDefaultBindingAmd.ts new file mode 100644 index 0000000000000..85e06b8c99d8c --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingAmd.ts @@ -0,0 +1,11 @@ +// @module: amd +// @declaration: true + +// @filename: es6ImportDefaultBindingAmd_0.ts +var a = 10; +export = a; + +// @filename: es6ImportDefaultBindingAmd_1.ts +import defaultBinding from "es6ImportDefaultBindingAmd_0"; +var x = defaultBinding; +import defaultBinding2 from "es6ImportDefaultBindingAmd_0"; // elide this import since defaultBinding2 is not used diff --git a/tests/cases/compiler/es6ImportDefaultBindingDts.ts b/tests/cases/compiler/es6ImportDefaultBindingDts.ts new file mode 100644 index 0000000000000..4700782b78e73 --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingDts.ts @@ -0,0 +1,11 @@ +// @module: commonjs +// @declaration: true + +// @filename: server.ts +class c { } +export = c; + +// @filename: client.ts +import defaultBinding from "server"; +export var x = new defaultBinding(); +import defaultBinding2 from "server"; // elide this import since defaultBinding2 is not used diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.ts new file mode 100644 index 0000000000000..db076b87c9a92 --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1InEs5.ts @@ -0,0 +1,11 @@ +// @target: es5 +// @module: commonjs +// @declaration: true + +// @filename: es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0.ts +var a = 10; +export = a; + +// @filename: es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_1.ts +import defaultBinding, * as nameSpaceBinding from "es6ImportDefaultBindingFollowedWithNamespaceBindingInEs5_0"; +var x: number = defaultBinding; \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.ts new file mode 100644 index 0000000000000..732f7ef7ba00b --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingDts.ts @@ -0,0 +1,9 @@ +// @module: commonjs +// @declaration: true + +// @filename: server.ts +export class a { } + +// @filename: client.ts +import defaultBinding, * as nameSpaceBinding from "server"; +export var x = new nameSpaceBinding.a(); \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.ts b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.ts new file mode 100644 index 0000000000000..1f026af8f34df --- /dev/null +++ b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBindingDts1.ts @@ -0,0 +1,10 @@ +// @module: amd +// @declaration: true + +// @filename: server.ts +class a { } +export = a; + +// @filename: client.ts +import defaultBinding, * as nameSpaceBinding from "server"; +export var x = new defaultBinding(); \ No newline at end of file From c70385c2573e230742aa3be04aa9a1e7158b212f Mon Sep 17 00:00:00 2001 From: Yui T Date: Sun, 15 Mar 2015 21:27:54 -0700 Subject: [PATCH 079/224] Update baselines --- tests/baselines/reference/for-of14.js | 11 ++++------- tests/baselines/reference/for-of15.js | 15 ++++++--------- tests/baselines/reference/for-of16.js | 11 ++++------- tests/baselines/reference/for-of17.js | 15 ++++++--------- tests/baselines/reference/for-of18.js | 15 ++++++--------- tests/baselines/reference/for-of19.js | 22 ++++++++-------------- tests/baselines/reference/for-of20.js | 22 ++++++++-------------- tests/baselines/reference/for-of21.js | 22 ++++++++-------------- tests/baselines/reference/for-of22.js | 22 ++++++++-------------- tests/baselines/reference/for-of23.js | 22 ++++++++-------------- tests/baselines/reference/for-of25.js | 11 ++++------- tests/baselines/reference/for-of26.js | 15 ++++++--------- tests/baselines/reference/for-of27.js | 7 ++----- tests/baselines/reference/for-of28.js | 11 ++++------- tests/baselines/reference/for-of30.js | 15 +++++++-------- tests/baselines/reference/for-of31.js | 15 ++++++--------- tests/baselines/reference/for-of33.js | 11 ++++------- tests/baselines/reference/for-of34.js | 15 ++++++--------- tests/baselines/reference/for-of35.js | 15 ++++++--------- 19 files changed, 111 insertions(+), 181 deletions(-) diff --git a/tests/baselines/reference/for-of14.js b/tests/baselines/reference/for-of14.js index 65ac7119fb610..958e621c8aa5b 100644 --- a/tests/baselines/reference/for-of14.js +++ b/tests/baselines/reference/for-of14.js @@ -12,11 +12,8 @@ class StringIterator { var v; for (v of new StringIterator) { } // Should fail because the iterator is not iterable -var StringIterator = (function () { - function StringIterator() { - } - StringIterator.prototype.next = function () { +class StringIterator { + next() { return ""; - }; - return StringIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of15.js b/tests/baselines/reference/for-of15.js index 74e34c2b2ae0c..2b4846ec8bef5 100644 --- a/tests/baselines/reference/for-of15.js +++ b/tests/baselines/reference/for-of15.js @@ -15,14 +15,11 @@ class StringIterator { var v; for (v of new StringIterator) { } // Should fail -var StringIterator = (function () { - function StringIterator() { - } - StringIterator.prototype.next = function () { +class StringIterator { + next() { return ""; - }; - StringIterator.prototype[Symbol.iterator] = function () { + } + [Symbol.iterator]() { return this; - }; - return StringIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of16.js b/tests/baselines/reference/for-of16.js index 526dc277be7c1..1cdf72c26ac03 100644 --- a/tests/baselines/reference/for-of16.js +++ b/tests/baselines/reference/for-of16.js @@ -12,11 +12,8 @@ class StringIterator { var v; for (v of new StringIterator) { } // Should fail -var StringIterator = (function () { - function StringIterator() { - } - StringIterator.prototype[Symbol.iterator] = function () { +class StringIterator { + [Symbol.iterator]() { return this; - }; - return StringIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of17.js b/tests/baselines/reference/for-of17.js index 268ead7ee18da..3fb4fac91d603 100644 --- a/tests/baselines/reference/for-of17.js +++ b/tests/baselines/reference/for-of17.js @@ -18,17 +18,14 @@ class NumberIterator { var v; for (v of new NumberIterator) { } // Should succeed -var NumberIterator = (function () { - function NumberIterator() { - } - NumberIterator.prototype.next = function () { +class NumberIterator { + next() { return { value: 0, done: false }; - }; - NumberIterator.prototype[Symbol.iterator] = function () { + } + [Symbol.iterator]() { return this; - }; - return NumberIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of18.js b/tests/baselines/reference/for-of18.js index 3be876409dc4f..ae3a9e130f003 100644 --- a/tests/baselines/reference/for-of18.js +++ b/tests/baselines/reference/for-of18.js @@ -18,17 +18,14 @@ class StringIterator { var v; for (v of new StringIterator) { } // Should succeed -var StringIterator = (function () { - function StringIterator() { - } - StringIterator.prototype.next = function () { +class StringIterator { + next() { return { value: "", done: false }; - }; - StringIterator.prototype[Symbol.iterator] = function () { + } + [Symbol.iterator]() { return this; - }; - return StringIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of19.js b/tests/baselines/reference/for-of19.js index eefb9339f18bd..d0f95caa1e27d 100644 --- a/tests/baselines/reference/for-of19.js +++ b/tests/baselines/reference/for-of19.js @@ -20,22 +20,16 @@ class FooIterator { for (var v of new FooIterator) { v; } -var Foo = (function () { - function Foo() { - } - return Foo; -})(); -var FooIterator = (function () { - function FooIterator() { - } - FooIterator.prototype.next = function () { +class Foo { +} +class FooIterator { + next() { return { value: new Foo, done: false }; - }; - FooIterator.prototype[Symbol.iterator] = function () { + } + [Symbol.iterator]() { return this; - }; - return FooIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of20.js b/tests/baselines/reference/for-of20.js index 39b1081954be7..c098abd2f73a0 100644 --- a/tests/baselines/reference/for-of20.js +++ b/tests/baselines/reference/for-of20.js @@ -20,22 +20,16 @@ class FooIterator { for (let v of new FooIterator) { v; } -var Foo = (function () { - function Foo() { - } - return Foo; -})(); -var FooIterator = (function () { - function FooIterator() { - } - FooIterator.prototype.next = function () { +class Foo { +} +class FooIterator { + next() { return { value: new Foo, done: false }; - }; - FooIterator.prototype[Symbol.iterator] = function () { + } + [Symbol.iterator]() { return this; - }; - return FooIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of21.js b/tests/baselines/reference/for-of21.js index 5deaad3c2d8f6..27da28e3b4f40 100644 --- a/tests/baselines/reference/for-of21.js +++ b/tests/baselines/reference/for-of21.js @@ -20,22 +20,16 @@ class FooIterator { for (const v of new FooIterator) { v; } -var Foo = (function () { - function Foo() { - } - return Foo; -})(); -var FooIterator = (function () { - function FooIterator() { - } - FooIterator.prototype.next = function () { +class Foo { +} +class FooIterator { + next() { return { value: new Foo, done: false }; - }; - FooIterator.prototype[Symbol.iterator] = function () { + } + [Symbol.iterator]() { return this; - }; - return FooIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of22.js b/tests/baselines/reference/for-of22.js index d38accb6cd818..886e8dba7c33d 100644 --- a/tests/baselines/reference/for-of22.js +++ b/tests/baselines/reference/for-of22.js @@ -21,22 +21,16 @@ class FooIterator { v; for (var v of new FooIterator) { } -var Foo = (function () { - function Foo() { - } - return Foo; -})(); -var FooIterator = (function () { - function FooIterator() { - } - FooIterator.prototype.next = function () { +class Foo { +} +class FooIterator { + next() { return { value: new Foo, done: false }; - }; - FooIterator.prototype[Symbol.iterator] = function () { + } + [Symbol.iterator]() { return this; - }; - return FooIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of23.js b/tests/baselines/reference/for-of23.js index 87bb1fd428d29..f5649128c115c 100644 --- a/tests/baselines/reference/for-of23.js +++ b/tests/baselines/reference/for-of23.js @@ -20,22 +20,16 @@ class FooIterator { for (const v of new FooIterator) { const v = 0; // new scope } -var Foo = (function () { - function Foo() { - } - return Foo; -})(); -var FooIterator = (function () { - function FooIterator() { - } - FooIterator.prototype.next = function () { +class Foo { +} +class FooIterator { + next() { return { value: new Foo, done: false }; - }; - FooIterator.prototype[Symbol.iterator] = function () { + } + [Symbol.iterator]() { return this; - }; - return FooIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of25.js b/tests/baselines/reference/for-of25.js index 86c175f861e8e..2c85a4dc2fd34 100644 --- a/tests/baselines/reference/for-of25.js +++ b/tests/baselines/reference/for-of25.js @@ -12,11 +12,8 @@ class StringIterator { var x; for (var v of new StringIterator) { } -var StringIterator = (function () { - function StringIterator() { - } - StringIterator.prototype[Symbol.iterator] = function () { +class StringIterator { + [Symbol.iterator]() { return x; - }; - return StringIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of26.js b/tests/baselines/reference/for-of26.js index edb6b4c38b264..e048caf1006d5 100644 --- a/tests/baselines/reference/for-of26.js +++ b/tests/baselines/reference/for-of26.js @@ -15,14 +15,11 @@ class StringIterator { var x; for (var v of new StringIterator) { } -var StringIterator = (function () { - function StringIterator() { - } - StringIterator.prototype.next = function () { +class StringIterator { + next() { return x; - }; - StringIterator.prototype[Symbol.iterator] = function () { + } + [Symbol.iterator]() { return this; - }; - return StringIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of27.js b/tests/baselines/reference/for-of27.js index 379b95c5b09d7..8b44ca03ef455 100644 --- a/tests/baselines/reference/for-of27.js +++ b/tests/baselines/reference/for-of27.js @@ -8,8 +8,5 @@ class StringIterator { //// [for-of27.js] for (var v of new StringIterator) { } -var StringIterator = (function () { - function StringIterator() { - } - return StringIterator; -})(); +class StringIterator { +} diff --git a/tests/baselines/reference/for-of28.js b/tests/baselines/reference/for-of28.js index 79b1590e12fb1..69c8ccab72798 100644 --- a/tests/baselines/reference/for-of28.js +++ b/tests/baselines/reference/for-of28.js @@ -11,11 +11,8 @@ class StringIterator { //// [for-of28.js] for (var v of new StringIterator) { } -var StringIterator = (function () { - function StringIterator() { - } - StringIterator.prototype[Symbol.iterator] = function () { +class StringIterator { + [Symbol.iterator]() { return this; - }; - return StringIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of30.js b/tests/baselines/reference/for-of30.js index 759c7823e63e1..0ed6caaf81e61 100644 --- a/tests/baselines/reference/for-of30.js +++ b/tests/baselines/reference/for-of30.js @@ -19,18 +19,17 @@ class StringIterator { //// [for-of30.js] for (var v of new StringIterator) { } -var StringIterator = (function () { - function StringIterator() { +class StringIterator { + constructor() { this.return = 0; } - StringIterator.prototype.next = function () { + next() { return { done: false, value: "" }; - }; - StringIterator.prototype[Symbol.iterator] = function () { + } + [Symbol.iterator]() { return this; - }; - return StringIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of31.js b/tests/baselines/reference/for-of31.js index 6773c8a3452ca..d38c1fa017d26 100644 --- a/tests/baselines/reference/for-of31.js +++ b/tests/baselines/reference/for-of31.js @@ -17,17 +17,14 @@ class StringIterator { //// [for-of31.js] for (var v of new StringIterator) { } -var StringIterator = (function () { - function StringIterator() { - } - StringIterator.prototype.next = function () { +class StringIterator { + next() { return { // no done property value: "" }; - }; - StringIterator.prototype[Symbol.iterator] = function () { + } + [Symbol.iterator]() { return this; - }; - return StringIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of33.js b/tests/baselines/reference/for-of33.js index f3a75eec13701..66097f777c8c2 100644 --- a/tests/baselines/reference/for-of33.js +++ b/tests/baselines/reference/for-of33.js @@ -10,11 +10,8 @@ class StringIterator { //// [for-of33.js] for (var v of new StringIterator) { } -var StringIterator = (function () { - function StringIterator() { - } - StringIterator.prototype[Symbol.iterator] = function () { +class StringIterator { + [Symbol.iterator]() { return v; - }; - return StringIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of34.js b/tests/baselines/reference/for-of34.js index 521b4f3c2a4aa..568a9f73535f9 100644 --- a/tests/baselines/reference/for-of34.js +++ b/tests/baselines/reference/for-of34.js @@ -14,14 +14,11 @@ class StringIterator { //// [for-of34.js] for (var v of new StringIterator) { } -var StringIterator = (function () { - function StringIterator() { - } - StringIterator.prototype.next = function () { +class StringIterator { + next() { return v; - }; - StringIterator.prototype[Symbol.iterator] = function () { + } + [Symbol.iterator]() { return this; - }; - return StringIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of35.js b/tests/baselines/reference/for-of35.js index cb6dc0e532fc5..a157d5e2e8eb1 100644 --- a/tests/baselines/reference/for-of35.js +++ b/tests/baselines/reference/for-of35.js @@ -17,17 +17,14 @@ class StringIterator { //// [for-of35.js] for (var v of new StringIterator) { } -var StringIterator = (function () { - function StringIterator() { - } - StringIterator.prototype.next = function () { +class StringIterator { + next() { return { done: true, value: v }; - }; - StringIterator.prototype[Symbol.iterator] = function () { + } + [Symbol.iterator]() { return this; - }; - return StringIterator; -})(); + } +} From 3bb4b50b4fe5b7424087732329a34e9ce91d9b7e Mon Sep 17 00:00:00 2001 From: Yui T Date: Sun, 15 Mar 2015 21:33:39 -0700 Subject: [PATCH 080/224] Update baselines for symbol --- tests/baselines/reference/symbolProperty10.js | 7 ++--- tests/baselines/reference/symbolProperty11.js | 7 ++--- tests/baselines/reference/symbolProperty12.js | 7 ++--- tests/baselines/reference/symbolProperty13.js | 7 ++--- tests/baselines/reference/symbolProperty14.js | 7 ++--- tests/baselines/reference/symbolProperty15.js | 7 ++--- tests/baselines/reference/symbolProperty16.js | 7 ++--- tests/baselines/reference/symbolProperty23.js | 11 +++----- tests/baselines/reference/symbolProperty24.js | 11 +++----- tests/baselines/reference/symbolProperty25.js | 11 +++----- tests/baselines/reference/symbolProperty26.js | 28 +++++-------------- tests/baselines/reference/symbolProperty27.js | 28 +++++-------------- tests/baselines/reference/symbolProperty28.js | 24 ++++------------ tests/baselines/reference/symbolProperty29.js | 11 +++----- tests/baselines/reference/symbolProperty30.js | 11 +++----- tests/baselines/reference/symbolProperty31.js | 24 ++++------------ tests/baselines/reference/symbolProperty32.js | 24 ++++------------ tests/baselines/reference/symbolProperty33.js | 24 ++++------------ tests/baselines/reference/symbolProperty34.js | 24 ++++------------ tests/baselines/reference/symbolProperty39.js | 15 ++++------ tests/baselines/reference/symbolProperty40.js | 11 +++----- tests/baselines/reference/symbolProperty41.js | 11 +++----- tests/baselines/reference/symbolProperty42.js | 11 +++----- tests/baselines/reference/symbolProperty43.js | 7 ++--- tests/baselines/reference/symbolProperty44.js | 15 +++------- tests/baselines/reference/symbolProperty45.js | 25 +++++------------ tests/baselines/reference/symbolProperty46.js | 21 +++++--------- tests/baselines/reference/symbolProperty47.js | 21 +++++--------- tests/baselines/reference/symbolProperty48.js | 9 ++---- tests/baselines/reference/symbolProperty49.js | 9 ++---- tests/baselines/reference/symbolProperty50.js | 9 ++---- tests/baselines/reference/symbolProperty51.js | 9 ++---- tests/baselines/reference/symbolProperty6.js | 21 ++++++-------- tests/baselines/reference/symbolProperty7.js | 21 ++++++-------- tests/baselines/reference/symbolProperty9.js | 7 ++--- 35 files changed, 148 insertions(+), 354 deletions(-) diff --git a/tests/baselines/reference/symbolProperty10.js b/tests/baselines/reference/symbolProperty10.js index 5b4e44f11abd8..74bcf886461e5 100644 --- a/tests/baselines/reference/symbolProperty10.js +++ b/tests/baselines/reference/symbolProperty10.js @@ -11,11 +11,8 @@ i = new C; var c: C = i; //// [symbolProperty10.js] -var C = (function () { - function C() { - } - return C; -})(); +class C { +} var i; i = new C; var c = i; diff --git a/tests/baselines/reference/symbolProperty11.js b/tests/baselines/reference/symbolProperty11.js index 83a380c79e7c3..97fa4fc992f8e 100644 --- a/tests/baselines/reference/symbolProperty11.js +++ b/tests/baselines/reference/symbolProperty11.js @@ -9,11 +9,8 @@ i = new C; var c: C = i; //// [symbolProperty11.js] -var C = (function () { - function C() { - } - return C; -})(); +class C { +} var i; i = new C; var c = i; diff --git a/tests/baselines/reference/symbolProperty12.js b/tests/baselines/reference/symbolProperty12.js index 9f63f86bc182b..474ec4a0ffad8 100644 --- a/tests/baselines/reference/symbolProperty12.js +++ b/tests/baselines/reference/symbolProperty12.js @@ -11,11 +11,8 @@ i = new C; var c: C = i; //// [symbolProperty12.js] -var C = (function () { - function C() { - } - return C; -})(); +class C { +} var i; i = new C; var c = i; diff --git a/tests/baselines/reference/symbolProperty13.js b/tests/baselines/reference/symbolProperty13.js index 1cf24a49c7e2c..d7620d01159dc 100644 --- a/tests/baselines/reference/symbolProperty13.js +++ b/tests/baselines/reference/symbolProperty13.js @@ -17,11 +17,8 @@ var i: I; bar(i); //// [symbolProperty13.js] -var C = (function () { - function C() { - } - return C; -})(); +class C { +} foo(new C); var i; bar(i); diff --git a/tests/baselines/reference/symbolProperty14.js b/tests/baselines/reference/symbolProperty14.js index 0283cb01b792a..716bc68b43029 100644 --- a/tests/baselines/reference/symbolProperty14.js +++ b/tests/baselines/reference/symbolProperty14.js @@ -17,11 +17,8 @@ var i: I; bar(i); //// [symbolProperty14.js] -var C = (function () { - function C() { - } - return C; -})(); +class C { +} foo(new C); var i; bar(i); diff --git a/tests/baselines/reference/symbolProperty15.js b/tests/baselines/reference/symbolProperty15.js index 0c1980370937a..dec61964252ce 100644 --- a/tests/baselines/reference/symbolProperty15.js +++ b/tests/baselines/reference/symbolProperty15.js @@ -15,11 +15,8 @@ var i: I; bar(i); //// [symbolProperty15.js] -var C = (function () { - function C() { - } - return C; -})(); +class C { +} foo(new C); var i; bar(i); diff --git a/tests/baselines/reference/symbolProperty16.js b/tests/baselines/reference/symbolProperty16.js index 1a1f3f857af97..1382d913104f9 100644 --- a/tests/baselines/reference/symbolProperty16.js +++ b/tests/baselines/reference/symbolProperty16.js @@ -17,11 +17,8 @@ var i: I; bar(i); //// [symbolProperty16.js] -var C = (function () { - function C() { - } - return C; -})(); +class C { +} foo(new C); var i; bar(i); diff --git a/tests/baselines/reference/symbolProperty23.js b/tests/baselines/reference/symbolProperty23.js index b3291ad34e8bc..3210f6dfed7d2 100644 --- a/tests/baselines/reference/symbolProperty23.js +++ b/tests/baselines/reference/symbolProperty23.js @@ -10,11 +10,8 @@ class C implements I { } //// [symbolProperty23.js] -var C = (function () { - function C() { - } - C.prototype[Symbol.toPrimitive] = function () { +class C { + [Symbol.toPrimitive]() { return true; - }; - return C; -})(); + } +} diff --git a/tests/baselines/reference/symbolProperty24.js b/tests/baselines/reference/symbolProperty24.js index b5d059dd29f1a..3d582d8025440 100644 --- a/tests/baselines/reference/symbolProperty24.js +++ b/tests/baselines/reference/symbolProperty24.js @@ -10,11 +10,8 @@ class C implements I { } //// [symbolProperty24.js] -var C = (function () { - function C() { - } - C.prototype[Symbol.toPrimitive] = function () { +class C { + [Symbol.toPrimitive]() { return ""; - }; - return C; -})(); + } +} diff --git a/tests/baselines/reference/symbolProperty25.js b/tests/baselines/reference/symbolProperty25.js index c932da1e3ebea..33c398a6c0ee4 100644 --- a/tests/baselines/reference/symbolProperty25.js +++ b/tests/baselines/reference/symbolProperty25.js @@ -10,11 +10,8 @@ class C implements I { } //// [symbolProperty25.js] -var C = (function () { - function C() { - } - C.prototype[Symbol.toStringTag] = function () { +class C { + [Symbol.toStringTag]() { return ""; - }; - return C; -})(); + } +} diff --git a/tests/baselines/reference/symbolProperty26.js b/tests/baselines/reference/symbolProperty26.js index 9e98027603d43..837ef5837b0ee 100644 --- a/tests/baselines/reference/symbolProperty26.js +++ b/tests/baselines/reference/symbolProperty26.js @@ -12,27 +12,13 @@ class C2 extends C1 { } //// [symbolProperty26.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var C1 = (function () { - function C1() { - } - C1.prototype[Symbol.toStringTag] = function () { +class C1 { + [Symbol.toStringTag]() { return ""; - }; - return C1; -})(); -var C2 = (function (_super) { - __extends(C2, _super); - function C2() { - _super.apply(this, arguments); } - C2.prototype[Symbol.toStringTag] = function () { +} +class C2 extends C1 { + [Symbol.toStringTag]() { return ""; - }; - return C2; -})(C1); + } +} diff --git a/tests/baselines/reference/symbolProperty27.js b/tests/baselines/reference/symbolProperty27.js index f19d05233cb28..d4eb6fcafa786 100644 --- a/tests/baselines/reference/symbolProperty27.js +++ b/tests/baselines/reference/symbolProperty27.js @@ -12,27 +12,13 @@ class C2 extends C1 { } //// [symbolProperty27.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var C1 = (function () { - function C1() { - } - C1.prototype[Symbol.toStringTag] = function () { +class C1 { + [Symbol.toStringTag]() { return {}; - }; - return C1; -})(); -var C2 = (function (_super) { - __extends(C2, _super); - function C2() { - _super.apply(this, arguments); } - C2.prototype[Symbol.toStringTag] = function () { +} +class C2 extends C1 { + [Symbol.toStringTag]() { return ""; - }; - return C2; -})(C1); + } +} diff --git a/tests/baselines/reference/symbolProperty28.js b/tests/baselines/reference/symbolProperty28.js index 57c826cb7ab1b..ed53a88f95716 100644 --- a/tests/baselines/reference/symbolProperty28.js +++ b/tests/baselines/reference/symbolProperty28.js @@ -11,28 +11,14 @@ var c: C2; var obj = c[Symbol.toStringTag]().x; //// [symbolProperty28.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var C1 = (function () { - function C1() { - } - C1.prototype[Symbol.toStringTag] = function () { +class C1 { + [Symbol.toStringTag]() { return { x: "" }; - }; - return C1; -})(); -var C2 = (function (_super) { - __extends(C2, _super); - function C2() { - _super.apply(this, arguments); } - return C2; -})(C1); +} +class C2 extends C1 { +} var c; var obj = c[Symbol.toStringTag]().x; diff --git a/tests/baselines/reference/symbolProperty29.js b/tests/baselines/reference/symbolProperty29.js index da6afdc642062..759a775482689 100644 --- a/tests/baselines/reference/symbolProperty29.js +++ b/tests/baselines/reference/symbolProperty29.js @@ -7,13 +7,10 @@ class C1 { } //// [symbolProperty29.js] -var C1 = (function () { - function C1() { - } - C1.prototype[Symbol.toStringTag] = function () { +class C1 { + [Symbol.toStringTag]() { return { x: "" }; - }; - return C1; -})(); + } +} diff --git a/tests/baselines/reference/symbolProperty30.js b/tests/baselines/reference/symbolProperty30.js index af151e0efd5c3..263fdc1041be5 100644 --- a/tests/baselines/reference/symbolProperty30.js +++ b/tests/baselines/reference/symbolProperty30.js @@ -7,13 +7,10 @@ class C1 { } //// [symbolProperty30.js] -var C1 = (function () { - function C1() { - } - C1.prototype[Symbol.toStringTag] = function () { +class C1 { + [Symbol.toStringTag]() { return { x: "" }; - }; - return C1; -})(); + } +} diff --git a/tests/baselines/reference/symbolProperty31.js b/tests/baselines/reference/symbolProperty31.js index e8388225dd7f1..a9db50061b31b 100644 --- a/tests/baselines/reference/symbolProperty31.js +++ b/tests/baselines/reference/symbolProperty31.js @@ -9,26 +9,12 @@ class C2 extends C1 { } //// [symbolProperty31.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var C1 = (function () { - function C1() { - } - C1.prototype[Symbol.toStringTag] = function () { +class C1 { + [Symbol.toStringTag]() { return { x: "" }; - }; - return C1; -})(); -var C2 = (function (_super) { - __extends(C2, _super); - function C2() { - _super.apply(this, arguments); } - return C2; -})(C1); +} +class C2 extends C1 { +} diff --git a/tests/baselines/reference/symbolProperty32.js b/tests/baselines/reference/symbolProperty32.js index b544c60da7e10..52db43bb9de8c 100644 --- a/tests/baselines/reference/symbolProperty32.js +++ b/tests/baselines/reference/symbolProperty32.js @@ -9,26 +9,12 @@ class C2 extends C1 { } //// [symbolProperty32.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var C1 = (function () { - function C1() { - } - C1.prototype[Symbol.toStringTag] = function () { +class C1 { + [Symbol.toStringTag]() { return { x: "" }; - }; - return C1; -})(); -var C2 = (function (_super) { - __extends(C2, _super); - function C2() { - _super.apply(this, arguments); } - return C2; -})(C1); +} +class C2 extends C1 { +} diff --git a/tests/baselines/reference/symbolProperty33.js b/tests/baselines/reference/symbolProperty33.js index 082c0fe7e656a..8a0e3f691b5ac 100644 --- a/tests/baselines/reference/symbolProperty33.js +++ b/tests/baselines/reference/symbolProperty33.js @@ -9,26 +9,12 @@ class C2 { } //// [symbolProperty33.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var C1 = (function (_super) { - __extends(C1, _super); - function C1() { - _super.apply(this, arguments); - } - C1.prototype[Symbol.toStringTag] = function () { +class C1 extends C2 { + [Symbol.toStringTag]() { return { x: "" }; - }; - return C1; -})(C2); -var C2 = (function () { - function C2() { } - return C2; -})(); +} +class C2 { +} diff --git a/tests/baselines/reference/symbolProperty34.js b/tests/baselines/reference/symbolProperty34.js index de7d722227b08..b8bcd54487f81 100644 --- a/tests/baselines/reference/symbolProperty34.js +++ b/tests/baselines/reference/symbolProperty34.js @@ -9,26 +9,12 @@ class C2 { } //// [symbolProperty34.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var C1 = (function (_super) { - __extends(C1, _super); - function C1() { - _super.apply(this, arguments); - } - C1.prototype[Symbol.toStringTag] = function () { +class C1 extends C2 { + [Symbol.toStringTag]() { return { x: "" }; - }; - return C1; -})(C2); -var C2 = (function () { - function C2() { } - return C2; -})(); +} +class C2 { +} diff --git a/tests/baselines/reference/symbolProperty39.js b/tests/baselines/reference/symbolProperty39.js index 18551d20c0b33..6454d4a983f49 100644 --- a/tests/baselines/reference/symbolProperty39.js +++ b/tests/baselines/reference/symbolProperty39.js @@ -11,14 +11,11 @@ class C { } //// [symbolProperty39.js] -var C = (function () { - function C() { - } - C.prototype[Symbol.iterator] = function (x) { +class C { + [Symbol.iterator](x) { return undefined; - }; - C.prototype[Symbol.iterator] = function (x) { + } + [Symbol.iterator](x) { return undefined; - }; - return C; -})(); + } +} diff --git a/tests/baselines/reference/symbolProperty40.js b/tests/baselines/reference/symbolProperty40.js index 15d8c5c6fba81..cf5a3c4396dc1 100644 --- a/tests/baselines/reference/symbolProperty40.js +++ b/tests/baselines/reference/symbolProperty40.js @@ -13,14 +13,11 @@ c[Symbol.iterator](0); //// [symbolProperty40.js] -var C = (function () { - function C() { - } - C.prototype[Symbol.iterator] = function (x) { +class C { + [Symbol.iterator](x) { return undefined; - }; - return C; -})(); + } +} var c = new C; c[Symbol.iterator](""); c[Symbol.iterator](0); diff --git a/tests/baselines/reference/symbolProperty41.js b/tests/baselines/reference/symbolProperty41.js index d26b2c7682aee..fd9d58082b6c2 100644 --- a/tests/baselines/reference/symbolProperty41.js +++ b/tests/baselines/reference/symbolProperty41.js @@ -13,14 +13,11 @@ c[Symbol.iterator]("hello"); //// [symbolProperty41.js] -var C = (function () { - function C() { - } - C.prototype[Symbol.iterator] = function (x) { +class C { + [Symbol.iterator](x) { return undefined; - }; - return C; -})(); + } +} var c = new C; c[Symbol.iterator](""); c[Symbol.iterator]("hello"); diff --git a/tests/baselines/reference/symbolProperty42.js b/tests/baselines/reference/symbolProperty42.js index 1990f54066c6c..082e862f0fcf1 100644 --- a/tests/baselines/reference/symbolProperty42.js +++ b/tests/baselines/reference/symbolProperty42.js @@ -8,11 +8,8 @@ class C { } //// [symbolProperty42.js] -var C = (function () { - function C() { - } - C.prototype[Symbol.iterator] = function (x) { +class C { + [Symbol.iterator](x) { return undefined; - }; - return C; -})(); + } +} diff --git a/tests/baselines/reference/symbolProperty43.js b/tests/baselines/reference/symbolProperty43.js index fcb1fd3f8e511..fdeb52ca89357 100644 --- a/tests/baselines/reference/symbolProperty43.js +++ b/tests/baselines/reference/symbolProperty43.js @@ -5,8 +5,5 @@ class C { } //// [symbolProperty43.js] -var C = (function () { - function C() { - } - return C; -})(); +class C { +} diff --git a/tests/baselines/reference/symbolProperty44.js b/tests/baselines/reference/symbolProperty44.js index d4824e79318a3..a3de33640af56 100644 --- a/tests/baselines/reference/symbolProperty44.js +++ b/tests/baselines/reference/symbolProperty44.js @@ -9,15 +9,8 @@ class C { } //// [symbolProperty44.js] -var C = (function () { - function C() { +class C { + get [Symbol.hasInstance]() { + return ""; } - Object.defineProperty(C.prototype, Symbol.hasInstance, { - get: function () { - return ""; - }, - enumerable: true, - configurable: true - }); - return C; -})(); +} diff --git a/tests/baselines/reference/symbolProperty45.js b/tests/baselines/reference/symbolProperty45.js index d056aba9f560d..97b1252b8256d 100644 --- a/tests/baselines/reference/symbolProperty45.js +++ b/tests/baselines/reference/symbolProperty45.js @@ -9,22 +9,11 @@ class C { } //// [symbolProperty45.js] -var C = (function () { - function C() { +class C { + get [Symbol.hasInstance]() { + return ""; } - Object.defineProperty(C.prototype, Symbol.hasInstance, { - get: function () { - return ""; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, Symbol.toPrimitive, { - get: function () { - return ""; - }, - enumerable: true, - configurable: true - }); - return C; -})(); + get [Symbol.toPrimitive]() { + return ""; + } +} diff --git a/tests/baselines/reference/symbolProperty46.js b/tests/baselines/reference/symbolProperty46.js index 255fbac080944..1d4a373f03cd3 100644 --- a/tests/baselines/reference/symbolProperty46.js +++ b/tests/baselines/reference/symbolProperty46.js @@ -12,20 +12,13 @@ class C { (new C)[Symbol.hasInstance] = ""; //// [symbolProperty46.js] -var C = (function () { - function C() { +class C { + get [Symbol.hasInstance]() { + return ""; } - Object.defineProperty(C.prototype, Symbol.hasInstance, { - get: function () { - return ""; - }, - // Should take a string - set: function (x) { - }, - enumerable: true, - configurable: true - }); - return C; -})(); + // Should take a string + set [Symbol.hasInstance](x) { + } +} (new C)[Symbol.hasInstance] = 0; (new C)[Symbol.hasInstance] = ""; diff --git a/tests/baselines/reference/symbolProperty47.js b/tests/baselines/reference/symbolProperty47.js index 92429c720c19e..7c6886f280b2e 100644 --- a/tests/baselines/reference/symbolProperty47.js +++ b/tests/baselines/reference/symbolProperty47.js @@ -12,20 +12,13 @@ class C { (new C)[Symbol.hasInstance] = ""; //// [symbolProperty47.js] -var C = (function () { - function C() { +class C { + get [Symbol.hasInstance]() { + return ""; } - Object.defineProperty(C.prototype, Symbol.hasInstance, { - get: function () { - return ""; - }, - // Should take a string - set: function (x) { - }, - enumerable: true, - configurable: true - }); - return C; -})(); + // Should take a string + set [Symbol.hasInstance](x) { + } +} (new C)[Symbol.hasInstance] = 0; (new C)[Symbol.hasInstance] = ""; diff --git a/tests/baselines/reference/symbolProperty48.js b/tests/baselines/reference/symbolProperty48.js index b0dc2b46dba47..283c3d0d2c5b0 100644 --- a/tests/baselines/reference/symbolProperty48.js +++ b/tests/baselines/reference/symbolProperty48.js @@ -11,11 +11,8 @@ module M { var M; (function (M) { var Symbol; - var C = (function () { - function C() { + class C { + [Symbol.iterator]() { } - C.prototype[Symbol.iterator] = function () { - }; - return C; - })(); + } })(M || (M = {})); diff --git a/tests/baselines/reference/symbolProperty49.js b/tests/baselines/reference/symbolProperty49.js index ea6e6f2c5234a..027b76f76d16b 100644 --- a/tests/baselines/reference/symbolProperty49.js +++ b/tests/baselines/reference/symbolProperty49.js @@ -11,11 +11,8 @@ module M { var M; (function (M) { M.Symbol; - var C = (function () { - function C() { + class C { + [M.Symbol.iterator]() { } - C.prototype[M.Symbol.iterator] = function () { - }; - return C; - })(); + } })(M || (M = {})); diff --git a/tests/baselines/reference/symbolProperty50.js b/tests/baselines/reference/symbolProperty50.js index 0a668e9550980..30c911e8fabb7 100644 --- a/tests/baselines/reference/symbolProperty50.js +++ b/tests/baselines/reference/symbolProperty50.js @@ -10,11 +10,8 @@ module M { //// [symbolProperty50.js] var M; (function (M) { - var C = (function () { - function C() { + class C { + [Symbol.iterator]() { } - C.prototype[Symbol.iterator] = function () { - }; - return C; - })(); + } })(M || (M = {})); diff --git a/tests/baselines/reference/symbolProperty51.js b/tests/baselines/reference/symbolProperty51.js index b3b9902fcd650..a9a790984247c 100644 --- a/tests/baselines/reference/symbolProperty51.js +++ b/tests/baselines/reference/symbolProperty51.js @@ -10,11 +10,8 @@ module M { //// [symbolProperty51.js] var M; (function (M) { - var C = (function () { - function C() { + class C { + [Symbol.iterator]() { } - C.prototype[Symbol.iterator] = function () { - }; - return C; - })(); + } })(M || (M = {})); diff --git a/tests/baselines/reference/symbolProperty6.js b/tests/baselines/reference/symbolProperty6.js index 114999dc873e9..311baf2c18774 100644 --- a/tests/baselines/reference/symbolProperty6.js +++ b/tests/baselines/reference/symbolProperty6.js @@ -9,18 +9,13 @@ class C { } //// [symbolProperty6.js] -var C = (function () { - function C() { +class C { + constructor() { this[Symbol.iterator] = 0; } - C.prototype[Symbol.isRegExp] = function () { - }; - Object.defineProperty(C.prototype, Symbol.toStringTag, { - get: function () { - return 0; - }, - enumerable: true, - configurable: true - }); - return C; -})(); + [Symbol.isRegExp]() { + } + get [Symbol.toStringTag]() { + return 0; + } +} diff --git a/tests/baselines/reference/symbolProperty7.js b/tests/baselines/reference/symbolProperty7.js index 42d19616ce396..b833eecff32fb 100644 --- a/tests/baselines/reference/symbolProperty7.js +++ b/tests/baselines/reference/symbolProperty7.js @@ -9,18 +9,13 @@ class C { } //// [symbolProperty7.js] -var C = (function () { - function C() { +class C { + constructor() { this[Symbol()] = 0; } - C.prototype[Symbol()] = function () { - }; - Object.defineProperty(C.prototype, Symbol(), { - get: function () { - return 0; - }, - enumerable: true, - configurable: true - }); - return C; -})(); + [Symbol()]() { + } + get [Symbol()]() { + return 0; + } +} diff --git a/tests/baselines/reference/symbolProperty9.js b/tests/baselines/reference/symbolProperty9.js index f97a1d44a21df..e6c8f7299a9e8 100644 --- a/tests/baselines/reference/symbolProperty9.js +++ b/tests/baselines/reference/symbolProperty9.js @@ -11,11 +11,8 @@ i = new C; var c: C = i; //// [symbolProperty9.js] -var C = (function () { - function C() { - } - return C; -})(); +class C { +} var i; i = new C; var c = i; From 0eeb7ce7b8d3c854493972ec28e06f15b5c2ae96 Mon Sep 17 00:00:00 2001 From: Yui T Date: Sun, 15 Mar 2015 21:40:15 -0700 Subject: [PATCH 081/224] Update baselines --- ...mitClassDeclarationWithConstructorInES6.js | 30 ++++++++--- ...ClassDeclarationWithConstructorInES6.types | 39 +++++++++++--- ...rationWithExtensionAndTypeArgumentInES6.js | 3 -- .../emitClassDeclarationWithExtensionInES6.js | 37 ++++++++++--- ...itClassDeclarationWithExtensionInES6.types | 52 +++++++++++++++++-- ...itClassDeclarationWithGetterSetterInES6.js | 2 - .../emitClassDeclarationWithMethodInES6.js | 2 - .../reference/symbolDeclarationEmit1.js | 7 +-- .../reference/symbolDeclarationEmit11.js | 27 ++++------ .../reference/symbolDeclarationEmit12.js | 28 ++++------ .../reference/symbolDeclarationEmit13.js | 23 +++----- .../reference/symbolDeclarationEmit14.js | 25 +++------ .../reference/symbolDeclarationEmit2.js | 7 ++- .../reference/symbolDeclarationEmit3.js | 9 ++-- .../reference/symbolDeclarationEmit4.js | 19 +++---- ...plateStringsArrayTypeRedefinedInES6Mode.js | 7 +-- 16 files changed, 183 insertions(+), 134 deletions(-) diff --git a/tests/baselines/reference/emitClassDeclarationWithConstructorInES6.js b/tests/baselines/reference/emitClassDeclarationWithConstructorInES6.js index 7877c957b29c7..8c115b17e9c2c 100644 --- a/tests/baselines/reference/emitClassDeclarationWithConstructorInES6.js +++ b/tests/baselines/reference/emitClassDeclarationWithConstructorInES6.js @@ -1,26 +1,42 @@ //// [emitClassDeclarationWithConstructorInES6.ts] -class C { +class A { y: number; constructor(x: number) { } + foo(a: any); + foo() { } } -class D { +class B { y: number; x: string = "hello"; - constructor(x: number, z = "hello") { + _bar: string; + + constructor(x: number, z = "hello", ...args) { this.y = 10; } -} + baz(...args): string; + baz(z: string, v: number): string { + return this._bar; + } +} + + + //// [emitClassDeclarationWithConstructorInES6.js] -class C { +class A { constructor(x) { } + foo() { + } } -class D { - constructor(x, z = "hello") { +class B { + constructor(x, z = "hello", ...args) { this.x = "hello"; this.y = 10; } + baz(z, v) { + return this._bar; + } } diff --git a/tests/baselines/reference/emitClassDeclarationWithConstructorInES6.types b/tests/baselines/reference/emitClassDeclarationWithConstructorInES6.types index 359e58a4b32cc..10244bf61702d 100644 --- a/tests/baselines/reference/emitClassDeclarationWithConstructorInES6.types +++ b/tests/baselines/reference/emitClassDeclarationWithConstructorInES6.types @@ -1,6 +1,6 @@ === tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorInES6.ts === -class C { ->C : C +class A { +>A : A y: number; >y : number @@ -8,10 +8,16 @@ class C { constructor(x: number) { >x : number } + foo(a: any); +>foo : (a: any) => any +>a : any + + foo() { } +>foo : (a: any) => any } -class D { ->D : D +class B { +>B : B y: number; >y : number @@ -19,14 +25,35 @@ class D { x: string = "hello"; >x : string - constructor(x: number, z = "hello") { + _bar: string; +>_bar : string + + constructor(x: number, z = "hello", ...args) { >x : number >z : string +>args : any[] this.y = 10; >this.y = 10 : number >this.y : number ->this : D +>this : B >y : number } + baz(...args): string; +>baz : (...args: any[]) => string +>args : any[] + + baz(z: string, v: number): string { +>baz : (...args: any[]) => string +>z : string +>v : number + + return this._bar; +>this._bar : string +>this : B +>_bar : string + } } + + + diff --git a/tests/baselines/reference/emitClassDeclarationWithExtensionAndTypeArgumentInES6.js b/tests/baselines/reference/emitClassDeclarationWithExtensionAndTypeArgumentInES6.js index 2409ebc0b663e..cd217af6a81d3 100644 --- a/tests/baselines/reference/emitClassDeclarationWithExtensionAndTypeArgumentInES6.js +++ b/tests/baselines/reference/emitClassDeclarationWithExtensionAndTypeArgumentInES6.js @@ -16,9 +16,6 @@ class B { } } class C extends B { - constructor(...args) { - super(...args); - } } class D extends B { constructor(b) { diff --git a/tests/baselines/reference/emitClassDeclarationWithExtensionInES6.js b/tests/baselines/reference/emitClassDeclarationWithExtensionInES6.js index 389d18d37a3d0..5c64aebd16a56 100644 --- a/tests/baselines/reference/emitClassDeclarationWithExtensionInES6.js +++ b/tests/baselines/reference/emitClassDeclarationWithExtensionInES6.js @@ -1,25 +1,48 @@ //// [emitClassDeclarationWithExtensionInES6.ts] -class B { } -class C extends B { } -class D extends B { +class B { + baz(a: string, y = 10) { } +} +class C extends B { + foo() { } + baz(a: string, y:number) { + super.baz(a, y); + } +} +class D extends C { constructor() { super(); } + + foo() { + super.foo(); + } + + baz() { + super.baz("hello", 10); + } } //// [emitClassDeclarationWithExtensionInES6.js] class B { - constructor() { + baz(a, y = 10) { } } class C extends B { - constructor(...args) { - super(...args); + foo() { + } + baz(a, y) { + super.baz(a, y); } } -class D extends B { +class D extends C { constructor() { super(); } + foo() { + super.foo(); + } + baz() { + super.baz("hello", 10); + } } diff --git a/tests/baselines/reference/emitClassDeclarationWithExtensionInES6.types b/tests/baselines/reference/emitClassDeclarationWithExtensionInES6.types index f410340b50944..a1549be5df4ac 100644 --- a/tests/baselines/reference/emitClassDeclarationWithExtensionInES6.types +++ b/tests/baselines/reference/emitClassDeclarationWithExtensionInES6.types @@ -1,19 +1,61 @@ === tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExtensionInES6.ts === -class B { } +class B { >B : B -class C extends B { } + baz(a: string, y = 10) { } +>baz : (a: string, y?: number) => void +>a : string +>y : number +} +class C extends B { >C : C >B : B -class D extends B { + foo() { } +>foo : () => void + + baz(a: string, y:number) { +>baz : (a: string, y: number) => void +>a : string +>y : number + + super.baz(a, y); +>super.baz(a, y) : void +>super.baz : (a: string, y?: number) => void +>super : B +>baz : (a: string, y?: number) => void +>a : string +>y : number + } +} +class D extends C { >D : D ->B : B +>C : C constructor() { super(); >super() : void ->super : typeof B +>super : typeof C + } + + foo() { +>foo : () => void + + super.foo(); +>super.foo() : void +>super.foo : () => void +>super : C +>foo : () => void + } + + baz() { +>baz : () => void + + super.baz("hello", 10); +>super.baz("hello", 10) : void +>super.baz : (a: string, y: number) => void +>super : C +>baz : (a: string, y: number) => void } } diff --git a/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.js b/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.js index 5d4a4fff6d649..55d72a8b8d522 100644 --- a/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.js +++ b/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.js @@ -18,8 +18,6 @@ class C { //// [emitClassDeclarationWithGetterSetterInES6.js] class C { - constructor() { - } get name() { return this._name; } diff --git a/tests/baselines/reference/emitClassDeclarationWithMethodInES6.js b/tests/baselines/reference/emitClassDeclarationWithMethodInES6.js index fd8a3079f8b34..20f58b4274e1d 100644 --- a/tests/baselines/reference/emitClassDeclarationWithMethodInES6.js +++ b/tests/baselines/reference/emitClassDeclarationWithMethodInES6.js @@ -24,8 +24,6 @@ class D { //// [emitClassDeclarationWithMethodInES6.js] class D { - constructor() { - } foo() { } ["computedName"]() { diff --git a/tests/baselines/reference/symbolDeclarationEmit1.js b/tests/baselines/reference/symbolDeclarationEmit1.js index 16d208db5eb86..7c3b39b9d86f4 100644 --- a/tests/baselines/reference/symbolDeclarationEmit1.js +++ b/tests/baselines/reference/symbolDeclarationEmit1.js @@ -4,11 +4,8 @@ class C { } //// [symbolDeclarationEmit1.js] -var C = (function () { - function C() { - } - return C; -})(); +class C { +} //// [symbolDeclarationEmit1.d.ts] diff --git a/tests/baselines/reference/symbolDeclarationEmit11.js b/tests/baselines/reference/symbolDeclarationEmit11.js index c9c819eefa266..8af17c95815a6 100644 --- a/tests/baselines/reference/symbolDeclarationEmit11.js +++ b/tests/baselines/reference/symbolDeclarationEmit11.js @@ -7,23 +7,18 @@ class C { } //// [symbolDeclarationEmit11.js] -var C = (function () { - function C() { +class C { + constructor() { } - C[Symbol.toPrimitive] = function () { - }; - Object.defineProperty(C, Symbol.isRegExp, { - get: function () { - return ""; - }, - set: function (x) { - }, - enumerable: true, - configurable: true - }); - C[Symbol.iterator] = 0; - return C; -})(); + static [Symbol.toPrimitive]() { + } + static get [Symbol.isRegExp]() { + return ""; + } + static set [Symbol.isRegExp](x) { + } +} +C[Symbol.iterator] = 0; //// [symbolDeclarationEmit11.d.ts] diff --git a/tests/baselines/reference/symbolDeclarationEmit12.js b/tests/baselines/reference/symbolDeclarationEmit12.js index 49ff8b3597672..9a75f6d573cb8 100644 --- a/tests/baselines/reference/symbolDeclarationEmit12.js +++ b/tests/baselines/reference/symbolDeclarationEmit12.js @@ -15,24 +15,16 @@ module M { //// [symbolDeclarationEmit12.js] var M; (function (M) { - var C = (function () { - function C() { + export class C { + [Symbol.toPrimitive](x) { } - C.prototype[Symbol.toPrimitive] = function (x) { - }; - C.prototype[Symbol.isConcatSpreadable] = function () { + [Symbol.isConcatSpreadable]() { return undefined; - }; - Object.defineProperty(C.prototype, Symbol.isRegExp, { - get: function () { - return undefined; - }, - set: function (x) { - }, - enumerable: true, - configurable: true - }); - return C; - })(); - M.C = C; + } + get [Symbol.isRegExp]() { + return undefined; + } + set [Symbol.isRegExp](x) { + } + } })(M || (M = {})); diff --git a/tests/baselines/reference/symbolDeclarationEmit13.js b/tests/baselines/reference/symbolDeclarationEmit13.js index 51b6edcece5ee..f48a918a6f2d7 100644 --- a/tests/baselines/reference/symbolDeclarationEmit13.js +++ b/tests/baselines/reference/symbolDeclarationEmit13.js @@ -5,24 +5,13 @@ class C { } //// [symbolDeclarationEmit13.js] -var C = (function () { - function C() { +class C { + get [Symbol.isRegExp]() { + return ""; } - Object.defineProperty(C.prototype, Symbol.isRegExp, { - get: function () { - return ""; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, Symbol.toStringTag, { - set: function (x) { - }, - enumerable: true, - configurable: true - }); - return C; -})(); + set [Symbol.toStringTag](x) { + } +} //// [symbolDeclarationEmit13.d.ts] diff --git a/tests/baselines/reference/symbolDeclarationEmit14.js b/tests/baselines/reference/symbolDeclarationEmit14.js index d81bc329927d0..6197ffa2b4fc0 100644 --- a/tests/baselines/reference/symbolDeclarationEmit14.js +++ b/tests/baselines/reference/symbolDeclarationEmit14.js @@ -5,25 +5,14 @@ class C { } //// [symbolDeclarationEmit14.js] -var C = (function () { - function C() { +class C { + get [Symbol.isRegExp]() { + return ""; } - Object.defineProperty(C.prototype, Symbol.isRegExp, { - get: function () { - return ""; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, Symbol.toStringTag, { - get: function () { - return ""; - }, - enumerable: true, - configurable: true - }); - return C; -})(); + get [Symbol.toStringTag]() { + return ""; + } +} //// [symbolDeclarationEmit14.d.ts] diff --git a/tests/baselines/reference/symbolDeclarationEmit2.js b/tests/baselines/reference/symbolDeclarationEmit2.js index 2112f9e774874..5558bebc64efa 100644 --- a/tests/baselines/reference/symbolDeclarationEmit2.js +++ b/tests/baselines/reference/symbolDeclarationEmit2.js @@ -4,12 +4,11 @@ class C { } //// [symbolDeclarationEmit2.js] -var C = (function () { - function C() { +class C { + constructor() { this[Symbol.isRegExp] = ""; } - return C; -})(); +} //// [symbolDeclarationEmit2.d.ts] diff --git a/tests/baselines/reference/symbolDeclarationEmit3.js b/tests/baselines/reference/symbolDeclarationEmit3.js index 6d06c09bd692e..6f513b053c7c4 100644 --- a/tests/baselines/reference/symbolDeclarationEmit3.js +++ b/tests/baselines/reference/symbolDeclarationEmit3.js @@ -6,13 +6,10 @@ class C { } //// [symbolDeclarationEmit3.js] -var C = (function () { - function C() { +class C { + [Symbol.isRegExp](x) { } - C.prototype[Symbol.isRegExp] = function (x) { - }; - return C; -})(); +} //// [symbolDeclarationEmit3.d.ts] diff --git a/tests/baselines/reference/symbolDeclarationEmit4.js b/tests/baselines/reference/symbolDeclarationEmit4.js index cd3fc53a5bb9b..14f50a03ee740 100644 --- a/tests/baselines/reference/symbolDeclarationEmit4.js +++ b/tests/baselines/reference/symbolDeclarationEmit4.js @@ -5,20 +5,13 @@ class C { } //// [symbolDeclarationEmit4.js] -var C = (function () { - function C() { +class C { + get [Symbol.isRegExp]() { + return ""; } - Object.defineProperty(C.prototype, Symbol.isRegExp, { - get: function () { - return ""; - }, - set: function (x) { - }, - enumerable: true, - configurable: true - }); - return C; -})(); + set [Symbol.isRegExp](x) { + } +} //// [symbolDeclarationEmit4.d.ts] diff --git a/tests/baselines/reference/templateStringsArrayTypeRedefinedInES6Mode.js b/tests/baselines/reference/templateStringsArrayTypeRedefinedInES6Mode.js index 22ce6831f0083..95ab43743aecf 100644 --- a/tests/baselines/reference/templateStringsArrayTypeRedefinedInES6Mode.js +++ b/tests/baselines/reference/templateStringsArrayTypeRedefinedInES6Mode.js @@ -11,11 +11,8 @@ f({}, 10, 10); f `abcdef${ 1234 }${ 5678 }ghijkl`; //// [templateStringsArrayTypeRedefinedInES6Mode.js] -var TemplateStringsArray = (function () { - function TemplateStringsArray() { - } - return TemplateStringsArray; -})(); +class TemplateStringsArray { +} function f(x, y, z) { } f({}, 10, 10); From 9933f6cd00f456442551a5ef9aeb6d48783e00f8 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Mon, 16 Mar 2015 11:04:11 -0700 Subject: [PATCH 082/224] Address PR feedback --- src/compiler/checker.ts | 13 ++++--- src/compiler/types.ts | 2 ++ .../baselines/reference/APISample_compile.js | 12 ------- .../reference/APISample_compile.types | 35 ------------------- tests/baselines/reference/APISample_linter.js | 12 ------- .../reference/APISample_linter.types | 35 ------------------- .../reference/APISample_transform.js | 12 ------- .../reference/APISample_transform.types | 35 ------------------- .../baselines/reference/APISample_watcher.js | 12 ------- .../reference/APISample_watcher.types | 35 ------------------- 10 files changed, 10 insertions(+), 193 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 21707940a5aeb..bb866c6b8cbdb 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4730,13 +4730,16 @@ module ts { if (!inferredType) { let inferences = getInferenceCandidates(context, index); if (inferences.length) { - // Infer widened union or supertype, or the undefined type for no common supertype + // Infer widened union or supertype, or the unknown type for no common supertype let unionOrSuperType = context.inferUnionTypes ? getUnionType(inferences) : getCommonSupertype(inferences); inferredType = unionOrSuperType ? getWidenedType(unionOrSuperType) : unknownType; inferenceSucceeded = !!unionOrSuperType; } else { - // Infer the empty object type when no inferences were made + // Infer the empty object type when no inferences were made. It is important to remember that + // in this case, inference still succeeds, meaning there is no error for not having inference + // candidates. An inference error only occurs when there are *conflicting* candidates, i.e. + // candidates with no common supertype. inferredType = emptyObjectType; inferenceSucceeded = true; } @@ -4746,10 +4749,10 @@ module ts { let constraint = getConstraintOfTypeParameter(context.typeParameters[index]); inferredType = constraint && !isTypeAssignableTo(inferredType, constraint) ? constraint : inferredType; } - // If inference failed, it is necessary to record the index of the failed type parameter (the one we are on). - // It might be that inference has already failed on a later type parameter on a previous call to inferTypeArguments. - // So if this failure is on preceding type parameter, this type parameter is the new failure index. else if (context.failedTypeParameterIndex === undefined || context.failedTypeParameterIndex > index) { + // If inference failed, it is necessary to record the index of the failed type parameter (the one we are on). + // It might be that inference has already failed on a later type parameter on a previous call to inferTypeArguments. + // So if this failure is on preceding type parameter, this type parameter is the new failure index. context.failedTypeParameterIndex = index; } context.inferredTypes[index] = inferredType; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 5880dfdce92ce..403c96b239b2f 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1482,6 +1482,7 @@ module ts { (t: Type): Type; } + // @internal export interface TypeInferences { primary: Type[]; // Inferences made directly to a type parameter secondary: Type[]; // Inferences made to a type parameter in a union type @@ -1489,6 +1490,7 @@ module ts { // If a type parameter is fixed, no more inferences can be made for the type parameter } + // @internal export interface InferenceContext { typeParameters: TypeParameter[]; // Type parameters for which inferences are made inferUnionTypes: boolean; // Infer union types for disjoint candidates (otherwise undefinedType) diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index d08d0b3fcc276..e2c0341d5dd90 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -1172,18 +1172,6 @@ declare module "typescript" { interface TypeMapper { (t: Type): Type; } - interface TypeInferences { - primary: Type[]; - secondary: Type[]; - isFixed: boolean; - } - interface InferenceContext { - typeParameters: TypeParameter[]; - inferUnionTypes: boolean; - inferences: TypeInferences[]; - inferredTypes: Type[]; - failedTypeParameterIndex?: number; - } interface DiagnosticMessage { key: string; category: DiagnosticCategory; diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index df0c57444b0a8..12803044f6e33 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -3756,41 +3756,6 @@ declare module "typescript" { >t : Type >Type : Type >Type : Type - } - interface TypeInferences { ->TypeInferences : TypeInferences - - primary: Type[]; ->primary : Type[] ->Type : Type - - secondary: Type[]; ->secondary : Type[] ->Type : Type - - isFixed: boolean; ->isFixed : boolean - } - interface InferenceContext { ->InferenceContext : InferenceContext - - typeParameters: TypeParameter[]; ->typeParameters : TypeParameter[] ->TypeParameter : TypeParameter - - inferUnionTypes: boolean; ->inferUnionTypes : boolean - - inferences: TypeInferences[]; ->inferences : TypeInferences[] ->TypeInferences : TypeInferences - - inferredTypes: Type[]; ->inferredTypes : Type[] ->Type : Type - - failedTypeParameterIndex?: number; ->failedTypeParameterIndex : number } interface DiagnosticMessage { >DiagnosticMessage : DiagnosticMessage diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index fb390d78f8f2e..265d84ac5b3d6 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -1203,18 +1203,6 @@ declare module "typescript" { interface TypeMapper { (t: Type): Type; } - interface TypeInferences { - primary: Type[]; - secondary: Type[]; - isFixed: boolean; - } - interface InferenceContext { - typeParameters: TypeParameter[]; - inferUnionTypes: boolean; - inferences: TypeInferences[]; - inferredTypes: Type[]; - failedTypeParameterIndex?: number; - } interface DiagnosticMessage { key: string; category: DiagnosticCategory; diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index 90360b5fe6122..f818edbaf39ae 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -3902,41 +3902,6 @@ declare module "typescript" { >t : Type >Type : Type >Type : Type - } - interface TypeInferences { ->TypeInferences : TypeInferences - - primary: Type[]; ->primary : Type[] ->Type : Type - - secondary: Type[]; ->secondary : Type[] ->Type : Type - - isFixed: boolean; ->isFixed : boolean - } - interface InferenceContext { ->InferenceContext : InferenceContext - - typeParameters: TypeParameter[]; ->typeParameters : TypeParameter[] ->TypeParameter : TypeParameter - - inferUnionTypes: boolean; ->inferUnionTypes : boolean - - inferences: TypeInferences[]; ->inferences : TypeInferences[] ->TypeInferences : TypeInferences - - inferredTypes: Type[]; ->inferredTypes : Type[] ->Type : Type - - failedTypeParameterIndex?: number; ->failedTypeParameterIndex : number } interface DiagnosticMessage { >DiagnosticMessage : DiagnosticMessage diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index 96b54ccd91730..f1da0e2533aba 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -1204,18 +1204,6 @@ declare module "typescript" { interface TypeMapper { (t: Type): Type; } - interface TypeInferences { - primary: Type[]; - secondary: Type[]; - isFixed: boolean; - } - interface InferenceContext { - typeParameters: TypeParameter[]; - inferUnionTypes: boolean; - inferences: TypeInferences[]; - inferredTypes: Type[]; - failedTypeParameterIndex?: number; - } interface DiagnosticMessage { key: string; category: DiagnosticCategory; diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index 999c81af401e2..6f22fb1ec6aeb 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -3852,41 +3852,6 @@ declare module "typescript" { >t : Type >Type : Type >Type : Type - } - interface TypeInferences { ->TypeInferences : TypeInferences - - primary: Type[]; ->primary : Type[] ->Type : Type - - secondary: Type[]; ->secondary : Type[] ->Type : Type - - isFixed: boolean; ->isFixed : boolean - } - interface InferenceContext { ->InferenceContext : InferenceContext - - typeParameters: TypeParameter[]; ->typeParameters : TypeParameter[] ->TypeParameter : TypeParameter - - inferUnionTypes: boolean; ->inferUnionTypes : boolean - - inferences: TypeInferences[]; ->inferences : TypeInferences[] ->TypeInferences : TypeInferences - - inferredTypes: Type[]; ->inferredTypes : Type[] ->Type : Type - - failedTypeParameterIndex?: number; ->failedTypeParameterIndex : number } interface DiagnosticMessage { >DiagnosticMessage : DiagnosticMessage diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index 8a3d2065a23b4..734467a1c5928 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -1241,18 +1241,6 @@ declare module "typescript" { interface TypeMapper { (t: Type): Type; } - interface TypeInferences { - primary: Type[]; - secondary: Type[]; - isFixed: boolean; - } - interface InferenceContext { - typeParameters: TypeParameter[]; - inferUnionTypes: boolean; - inferences: TypeInferences[]; - inferredTypes: Type[]; - failedTypeParameterIndex?: number; - } interface DiagnosticMessage { key: string; category: DiagnosticCategory; diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index f66c818c53dc4..37940e9a1f849 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -4025,41 +4025,6 @@ declare module "typescript" { >t : Type >Type : Type >Type : Type - } - interface TypeInferences { ->TypeInferences : TypeInferences - - primary: Type[]; ->primary : Type[] ->Type : Type - - secondary: Type[]; ->secondary : Type[] ->Type : Type - - isFixed: boolean; ->isFixed : boolean - } - interface InferenceContext { ->InferenceContext : InferenceContext - - typeParameters: TypeParameter[]; ->typeParameters : TypeParameter[] ->TypeParameter : TypeParameter - - inferUnionTypes: boolean; ->inferUnionTypes : boolean - - inferences: TypeInferences[]; ->inferences : TypeInferences[] ->TypeInferences : TypeInferences - - inferredTypes: Type[]; ->inferredTypes : Type[] ->Type : Type - - failedTypeParameterIndex?: number; ->failedTypeParameterIndex : number } interface DiagnosticMessage { >DiagnosticMessage : DiagnosticMessage From f5a4b0b31aa12ff09b8846d6a41cab3538ff12ec Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 16 Mar 2015 12:37:21 -0700 Subject: [PATCH 083/224] use 'allowGeneratedIdentifiers' to explicitly tell when identifier can be renamed --- src/compiler/checker.ts | 23 +----- src/compiler/emitter.ts | 75 ++++++++++++------- .../initializePropertiesWithRenamedLet.js | 46 ++++++++++++ .../initializePropertiesWithRenamedLet.types | 58 ++++++++++++++ .../shadowingViaLocalValueOrBindingElement.js | 8 +- .../initializePropertiesWithRenamedLet.ts | 17 +++++ 6 files changed, 176 insertions(+), 51 deletions(-) create mode 100644 tests/baselines/reference/initializePropertiesWithRenamedLet.js create mode 100644 tests/baselines/reference/initializePropertiesWithRenamedLet.types create mode 100644 tests/cases/compiler/initializePropertiesWithRenamedLet.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1f27d1e217a4c..4816bac9fcb84 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11085,26 +11085,11 @@ module ts { function getBlockScopedVariableId(n: Identifier): number { Debug.assert(!nodeIsSynthesized(n)); - // ignore name parts of property access expressions - if (n.parent.kind === SyntaxKind.PropertyAccessExpression && - (n.parent).name === n) { - return undefined; - } - - // ignore property names in object binding patterns - if (n.parent.kind === SyntaxKind.BindingElement && - (n.parent).propertyName === n) { - return undefined; - } - - // for names in variable declarations and binding elements try to short circuit and fetch symbol from the node - let declarationSymbol: Symbol = - (n.parent.kind === SyntaxKind.VariableDeclaration && (n.parent).name === n) || - n.parent.kind === SyntaxKind.BindingElement - ? getSymbolOfNode(n.parent) - : undefined; + let isVariableDeclarationOrBindingElement = + n.parent.kind === SyntaxKind.BindingElement || (n.parent.kind === SyntaxKind.VariableDeclaration && (n.parent).name === n); - let symbol = declarationSymbol || + let symbol = + (isVariableDeclarationOrBindingElement ? getSymbolOfNode(n.parent) : undefined) || getNodeLinks(n).resolvedSymbol || resolveName(n, n.text, SymbolFlags.Value | SymbolFlags.Alias, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined); diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 54ec39a5b5568..86385ab543a8a 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2074,19 +2074,19 @@ module ts { sourceMapDir = getDirectoryPath(normalizePath(jsFilePath)); } - function emitNodeWithSourceMap(node: Node) { + function emitNodeWithSourceMap(node: Node, allowGeneratedIdentifiers?: boolean) { if (node) { if (nodeIsSynthesized(node)) { - return emitNodeWithoutSourceMap(node); + return emitNodeWithoutSourceMap(node, /*allowGeneratedIdentifiers*/ false); } if (node.kind != SyntaxKind.SourceFile) { recordEmitNodeStartSpan(node); - emitNodeWithoutSourceMap(node); + emitNodeWithoutSourceMap(node, allowGeneratedIdentifiers); recordEmitNodeEndSpan(node); } else { recordNewSourceFileStart(node); - emitNodeWithoutSourceMap(node); + emitNodeWithoutSourceMap(node, /*allowGeneratedIdentifiers*/ false); } } } @@ -2623,17 +2623,24 @@ module ts { } } - function getBlockScopedVariableId(node: Identifier): number { - // return undefined for synthesized nodes - return !nodeIsSynthesized(node) && resolver.getBlockScopedVariableId(node); + function getGeneratedNameForIdentifier(node: Identifier): string { + if (nodeIsSynthesized(node) || !generatedBlockScopeNames) { + return undefined; + } + + var variableId = resolver.getBlockScopedVariableId(node) + if (variableId === undefined) { + return undefined; + } + + return generatedBlockScopeNames[variableId]; } - function emitIdentifier(node: Identifier) { - let variableId = getBlockScopedVariableId(node); - if (variableId !== undefined && generatedBlockScopeNames) { - let text = generatedBlockScopeNames[variableId]; - if (text) { - write(text); + function emitIdentifier(node: Identifier, allowGeneratedIdentifiers: boolean) { + if (allowGeneratedIdentifiers) { + let generatedName = getGeneratedNameForIdentifier(node); + if (generatedName) { + write(generatedName); return; } } @@ -2686,7 +2693,7 @@ module ts { function emitBindingElement(node: BindingElement) { if (node.propertyName) { - emit(node.propertyName); + emit(node.propertyName, /*allowGeneratedIdentifiers*/ false); write(": "); } if (node.dotDotDotToken) { @@ -3030,7 +3037,7 @@ module ts { } function emitMethod(node: MethodDeclaration) { - emit(node.name); + emit(node.name, /*allowGeneratedIdentifiers*/ false); if (languageVersion < ScriptTarget.ES6) { write(": function "); } @@ -3038,13 +3045,13 @@ module ts { } function emitPropertyAssignment(node: PropertyDeclaration) { - emit(node.name); + emit(node.name, /*allowGeneratedIdentifiers*/ false); write(": "); emit(node.initializer); } function emitShorthandPropertyAssignment(node: ShorthandPropertyAssignment) { - emit(node.name); + emit(node.name, /*allowGeneratedIdentifiers*/ false); // If short-hand property has a prefix, then regardless of the target version, we will emit it as normal property assignment. For example: // module m { // export let y; @@ -3053,7 +3060,20 @@ module ts { // export let obj = { y }; // } // The short-hand property in obj need to emit as such ... = { y : m.y } regardless of the TargetScript version - if (languageVersion < ScriptTarget.ES6 || resolver.getExpressionNameSubstitution(node.name)) { + if (languageVersion < ScriptTarget.ES6) { + // Emit identifier as an identifier + write(": "); + var generatedName = getGeneratedNameForIdentifier(node.name); + if (generatedName) { + write(generatedName); + } + else { + // Even though this is stored as identifier treat it as an expression + // Short-hand, { x }, is equivalent of normal form { x: x } + emitExpressionIdentifier(node.name); + } + } + else if (resolver.getExpressionNameSubstitution(node.name)) { // Emit identifier as an identifier write(": "); // Even though this is stored as identifier treat it as an expression @@ -3106,7 +3126,7 @@ module ts { let indentedBeforeDot = indentIfOnDifferentLines(node, node.expression, node.dotToken); write("."); let indentedAfterDot = indentIfOnDifferentLines(node, node.dotToken, node.name); - emit(node.name); + emit(node.name, /*allowGeneratedIdentifiers*/ false); decreaseIndentIf(indentedBeforeDot, indentedAfterDot); } @@ -3897,8 +3917,7 @@ module ts { renameNonTopLevelLetAndConst(name); if (name.parent && (name.parent.kind === SyntaxKind.VariableDeclaration || name.parent.kind === SyntaxKind.BindingElement)) { emitModuleMemberName(name.parent); - } - else { + } else { emit(name); } write(" = "); @@ -4294,7 +4313,7 @@ module ts { function emitAccessor(node: AccessorDeclaration) { write(node.kind === SyntaxKind.GetAccessor ? "get " : "set "); - emit(node.name); + emit(node.name, /*allowGeneratedIdentifiers*/ false); emitSignatureAndBody(node); } @@ -5340,7 +5359,7 @@ module ts { emitLeadingComments(node.endOfFileToken); } - function emitNodeWithoutSourceMapWithComments(node: Node): void { + function emitNodeWithoutSourceMapWithComments(node: Node, allowGeneratedIdentifiers?: boolean): void { if (!node) { return; } @@ -5354,14 +5373,14 @@ module ts { emitLeadingComments(node); } - emitJavaScriptWorker(node); + emitJavaScriptWorker(node, (allowGeneratedIdentifiers === undefined) || allowGeneratedIdentifiers); if (emitComments) { emitTrailingComments(node); } } - function emitNodeWithoutSourceMapWithoutComments(node: Node): void { + function emitNodeWithoutSourceMapWithoutComments(node: Node, allowGeneratedIdentifiers?: boolean): void { if (!node) { return; } @@ -5370,7 +5389,7 @@ module ts { return emitPinnedOrTripleSlashComments(node); } - emitJavaScriptWorker(node); + emitJavaScriptWorker(node, (allowGeneratedIdentifiers === undefined) || allowGeneratedIdentifiers); } function shouldEmitLeadingAndTrailingComments(node: Node) { @@ -5400,11 +5419,11 @@ module ts { return true; } - function emitJavaScriptWorker(node: Node) { + function emitJavaScriptWorker(node: Node, allowGeneratedIdentifiers: boolean) { // Check if the node can be emitted regardless of the ScriptTarget switch (node.kind) { case SyntaxKind.Identifier: - return emitIdentifier(node); + return emitIdentifier(node, allowGeneratedIdentifiers); case SyntaxKind.Parameter: return emitParameter(node); case SyntaxKind.MethodDeclaration: diff --git a/tests/baselines/reference/initializePropertiesWithRenamedLet.js b/tests/baselines/reference/initializePropertiesWithRenamedLet.js new file mode 100644 index 0000000000000..902a23f5886e0 --- /dev/null +++ b/tests/baselines/reference/initializePropertiesWithRenamedLet.js @@ -0,0 +1,46 @@ +//// [initializePropertiesWithRenamedLet.ts] + +var x0; +if (true) { + let x0; + var obj1 = { x0: x0 }; + var obj2 = { x0 }; +} + +var x, y, z; +if (true) { + let { x: x } = { x: 0 }; + let { y } = { y: 0 }; + let z; + ({ z: z } = { z: 0 }); + ({ z } = { z: 0 }); +} + +//// [initializePropertiesWithRenamedLet.js] +var x0; +if (true) { + var _x0; + var obj1 = { + x0: _x0 + }; + var obj2 = { + x0: _x0 + }; +} +var x, y, z; +if (true) { + var _x = ({ + x: 0 + }).x; + var _y = ({ + y: 0 + }).y; + var _z; + (_a = { + z: 0 + }, _z = _a.z, _a); + (_b = { + z: 0 + }, _z = _b.z, _b); +} +var _a, _b; diff --git a/tests/baselines/reference/initializePropertiesWithRenamedLet.types b/tests/baselines/reference/initializePropertiesWithRenamedLet.types new file mode 100644 index 0000000000000..77f16756fdb23 --- /dev/null +++ b/tests/baselines/reference/initializePropertiesWithRenamedLet.types @@ -0,0 +1,58 @@ +=== tests/cases/compiler/initializePropertiesWithRenamedLet.ts === + +var x0; +>x0 : any + +if (true) { + let x0; +>x0 : any + + var obj1 = { x0: x0 }; +>obj1 : { x0: any; } +>{ x0: x0 } : { x0: any; } +>x0 : any +>x0 : any + + var obj2 = { x0 }; +>obj2 : { x0: any; } +>{ x0 } : { x0: any; } +>x0 : any +} + +var x, y, z; +>x : any +>y : any +>z : any + +if (true) { + let { x: x } = { x: 0 }; +>x : unknown +>x : number +>{ x: 0 } : { x: number; } +>x : number + + let { y } = { y: 0 }; +>y : number +>{ y: 0 } : { y: number; } +>y : number + + let z; +>z : any + + ({ z: z } = { z: 0 }); +>({ z: z } = { z: 0 }) : { z: number; } +>{ z: z } = { z: 0 } : { z: number; } +>{ z: z } : { z: any; } +>z : any +>z : any +>{ z: 0 } : { z: number; } +>z : number + + ({ z } = { z: 0 }); +>({ z } = { z: 0 }) : { z: number; } +>{ z } = { z: 0 } : { z: number; } +>{ z } : { z: any; } +>z : any +>{ z: 0 } : { z: number; } +>z : number +} diff --git a/tests/baselines/reference/shadowingViaLocalValueOrBindingElement.js b/tests/baselines/reference/shadowingViaLocalValueOrBindingElement.js index 76c4a7ac3a646..594ec1ca18e81 100644 --- a/tests/baselines/reference/shadowingViaLocalValueOrBindingElement.js +++ b/tests/baselines/reference/shadowingViaLocalValueOrBindingElement.js @@ -16,16 +16,16 @@ if (true) { if (true) { var x = 0; // Error var _a = ({ - _x: 0 + x: 0 }).x, x = _a === void 0 ? 0 : _a; // Error var _b = ({ - _x: 0 + x: 0 }).x, x = _b === void 0 ? 0 : _b; // Error var x = ({ - _x: 0 + x: 0 }).x; // Error var x = ({ - _x: 0 + x: 0 }).x; // Error } } diff --git a/tests/cases/compiler/initializePropertiesWithRenamedLet.ts b/tests/cases/compiler/initializePropertiesWithRenamedLet.ts new file mode 100644 index 0000000000000..b30ce60977502 --- /dev/null +++ b/tests/cases/compiler/initializePropertiesWithRenamedLet.ts @@ -0,0 +1,17 @@ +// @target: es5 + +var x0; +if (true) { + let x0; + var obj1 = { x0: x0 }; + var obj2 = { x0 }; +} + +var x, y, z; +if (true) { + let { x: x } = { x: 0 }; + let { y } = { y: 0 }; + let z; + ({ z: z } = { z: 0 }); + ({ z } = { z: 0 }); +} \ No newline at end of file From 7f8ef3881ba3c0322c47d1ba20f98dd4428b86dd Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 16 Mar 2015 13:36:34 -0700 Subject: [PATCH 084/224] addressed PR feedback --- src/compiler/emitter.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 86385ab543a8a..5bf678f5436bf 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3917,7 +3917,8 @@ module ts { renameNonTopLevelLetAndConst(name); if (name.parent && (name.parent.kind === SyntaxKind.VariableDeclaration || name.parent.kind === SyntaxKind.BindingElement)) { emitModuleMemberName(name.parent); - } else { + } + else { emit(name); } write(" = "); @@ -5373,7 +5374,7 @@ module ts { emitLeadingComments(node); } - emitJavaScriptWorker(node, (allowGeneratedIdentifiers === undefined) || allowGeneratedIdentifiers); + emitJavaScriptWorker(node, allowGeneratedIdentifiers); if (emitComments) { emitTrailingComments(node); @@ -5389,7 +5390,7 @@ module ts { return emitPinnedOrTripleSlashComments(node); } - emitJavaScriptWorker(node, (allowGeneratedIdentifiers === undefined) || allowGeneratedIdentifiers); + emitJavaScriptWorker(node, allowGeneratedIdentifiers); } function shouldEmitLeadingAndTrailingComments(node: Node) { @@ -5419,7 +5420,7 @@ module ts { return true; } - function emitJavaScriptWorker(node: Node, allowGeneratedIdentifiers: boolean) { + function emitJavaScriptWorker(node: Node, allowGeneratedIdentifiers: boolean = true) { // Check if the node can be emitted regardless of the ScriptTarget switch (node.kind) { case SyntaxKind.Identifier: From 2c7ea7f6b26faadf61ad7d7d48a77594248b2287 Mon Sep 17 00:00:00 2001 From: Yui T Date: Mon, 16 Mar 2015 14:28:29 -0700 Subject: [PATCH 085/224] Update Baselines --- .../computedPropertyNames24_ES5.errors.txt | 4 +- .../reference/computedPropertyNames24_ES5.js | 6 +- .../computedPropertyNames26_ES5.errors.txt | 4 +- .../reference/computedPropertyNames26_ES5.js | 6 +- ...computedPropertyNamesSourceMap1_ES5.js.map | 2 +- ...dPropertyNamesSourceMap1_ES5.sourcemap.txt | 8 ++- ...computedPropertyNamesSourceMap1_ES6.js.map | 2 +- ...dPropertyNamesSourceMap1_ES6.sourcemap.txt | 7 +- ...computedPropertyNamesWithStaticProperty.js | 2 - .../emitClassDeclarationWithExport.errors.txt | 16 ----- .../emitClassDeclarationWithExport.js | 23 ------ ...rationWithStaticPropertyAssignmentInES6.js | 2 - .../reference/emitThisInSuperMethodCall.js | 6 +- .../reference/errorSuperPropertyAccess.js | 26 +++---- tests/baselines/reference/es6-amd.js | 11 ++- tests/baselines/reference/es6-amd.js.map | 2 +- .../baselines/reference/es6-amd.sourcemap.txt | 70 ++++++------------- .../reference/es6-declaration-amd.js | 11 ++- .../reference/es6-declaration-amd.js.map | 2 +- .../es6-declaration-amd.sourcemap.txt | 70 ++++++------------- .../baselines/reference/es6-sourcemap-amd.js | 11 ++- .../reference/es6-sourcemap-amd.js.map | 2 +- .../reference/es6-sourcemap-amd.sourcemap.txt | 70 ++++++------------- .../reference/letDeclarations-scopes.js | 33 ++++----- .../letDeclarations-validContexts.js | 29 ++++---- ...ationInStrictModeByDefaultInES6.errors.txt | 8 +-- .../reference/parserComputedPropertyName10.js | 7 +- .../reference/parserComputedPropertyName11.js | 7 +- .../reference/parserComputedPropertyName12.js | 9 +-- .../reference/parserComputedPropertyName24.js | 13 +--- .../reference/parserComputedPropertyName25.js | 7 +- .../reference/parserComputedPropertyName27.js | 7 +- .../reference/parserComputedPropertyName28.js | 7 +- .../reference/parserComputedPropertyName29.js | 7 +- .../reference/parserComputedPropertyName31.js | 7 +- .../reference/parserComputedPropertyName33.js | 7 +- .../parserComputedPropertyName36.errors.txt | 15 ++-- .../reference/parserComputedPropertyName36.js | 7 +- .../parserComputedPropertyName38.errors.txt | 20 ++++-- .../reference/parserComputedPropertyName38.js | 11 ++- .../reference/parserComputedPropertyName39.js | 7 +- .../reference/parserComputedPropertyName40.js | 9 +-- .../reference/parserComputedPropertyName7.js | 7 +- .../reference/parserComputedPropertyName8.js | 7 +- .../reference/parserComputedPropertyName9.js | 7 +- .../reference/parserSuperExpression1.js | 4 +- .../reference/parserSuperExpression2.js | 2 +- .../reference/parserSuperExpression4.js | 4 +- .../reference/parserSymbolIndexer2.js | 7 +- .../reference/parserSymbolIndexer3.js | 7 +- .../reference/parserSymbolProperty5.js | 7 +- .../reference/parserSymbolProperty6.js | 7 +- .../reference/parserSymbolProperty7.js | 9 +-- tests/baselines/reference/properties.js.map | 2 +- .../reference/properties.sourcemap.txt | 11 ++- .../reference/sourceMapValidationClass.js.map | 2 +- .../sourceMapValidationClass.sourcemap.txt | 13 ++-- tests/baselines/reference/super.js | 2 +- tests/baselines/reference/super1.js | 2 +- tests/baselines/reference/superAccess2.js | 2 +- tests/baselines/reference/superErrors.js | 16 ++--- ...side-object-literal-getters-and-setters.js | 8 +-- .../reference/symbolDeclarationEmit11.js | 2 - .../emitClassDeclarationWithExport.ts | 8 --- .../computedPropertyNames24_ES5.ts | 2 - .../computedPropertyNames26_ES5.ts | 2 - 66 files changed, 261 insertions(+), 459 deletions(-) delete mode 100644 tests/baselines/reference/emitClassDeclarationWithExport.errors.txt delete mode 100644 tests/baselines/reference/emitClassDeclarationWithExport.js delete mode 100644 tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts diff --git a/tests/baselines/reference/computedPropertyNames24_ES5.errors.txt b/tests/baselines/reference/computedPropertyNames24_ES5.errors.txt index a1290e06956cb..121b39450a61d 100644 --- a/tests/baselines/reference/computedPropertyNames24_ES5.errors.txt +++ b/tests/baselines/reference/computedPropertyNames24_ES5.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNames24_ES5.ts(9,6): error TS2466: 'super' cannot be referenced in a computed property name. +tests/cases/conformance/es6/computedProperties/computedPropertyNames24_ES5.ts(7,6): error TS2466: 'super' cannot be referenced in a computed property name. ==== tests/cases/conformance/es6/computedProperties/computedPropertyNames24_ES5.ts (1 errors) ==== @@ -8,8 +8,6 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames24_ES5.ts(9, } } class C extends Base { - // Gets emitted as super, not _super, which is consistent with - // use of super in static properties initializers. [super.bar()]() { } ~~~~~ !!! error TS2466: 'super' cannot be referenced in a computed property name. diff --git a/tests/baselines/reference/computedPropertyNames24_ES5.js b/tests/baselines/reference/computedPropertyNames24_ES5.js index d24f406c1adb1..cea5240003b2e 100644 --- a/tests/baselines/reference/computedPropertyNames24_ES5.js +++ b/tests/baselines/reference/computedPropertyNames24_ES5.js @@ -5,8 +5,6 @@ class Base { } } class C extends Base { - // Gets emitted as super, not _super, which is consistent with - // use of super in static properties initializers. [super.bar()]() { } } @@ -30,9 +28,7 @@ var C = (function (_super) { function C() { _super.apply(this, arguments); } - // Gets emitted as super, not _super, which is consistent with - // use of super in static properties initializers. - C.prototype[super.bar.call(this)] = function () { + C.prototype[_super.bar.call(this)] = function () { }; return C; })(Base); diff --git a/tests/baselines/reference/computedPropertyNames26_ES5.errors.txt b/tests/baselines/reference/computedPropertyNames26_ES5.errors.txt index 77408f0a9f895..e703971273469 100644 --- a/tests/baselines/reference/computedPropertyNames26_ES5.errors.txt +++ b/tests/baselines/reference/computedPropertyNames26_ES5.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNames26_ES5.ts(10,12): error TS2466: 'super' cannot be referenced in a computed property name. +tests/cases/conformance/es6/computedProperties/computedPropertyNames26_ES5.ts(8,12): error TS2466: 'super' cannot be referenced in a computed property name. ==== tests/cases/conformance/es6/computedProperties/computedPropertyNames26_ES5.ts (1 errors) ==== @@ -8,8 +8,6 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames26_ES5.ts(10 } } class C extends Base { - // Gets emitted as super, not _super, which is consistent with - // use of super in static properties initializers. [ { [super.bar()]: 1 }[0] ~~~~~ diff --git a/tests/baselines/reference/computedPropertyNames26_ES5.js b/tests/baselines/reference/computedPropertyNames26_ES5.js index 217a0dfc74cff..5651ee266c94e 100644 --- a/tests/baselines/reference/computedPropertyNames26_ES5.js +++ b/tests/baselines/reference/computedPropertyNames26_ES5.js @@ -5,8 +5,6 @@ class Base { } } class C extends Base { - // Gets emitted as super, not _super, which is consistent with - // use of super in static properties initializers. [ { [super.bar()]: 1 }[0] ]() { } @@ -32,10 +30,8 @@ var C = (function (_super) { function C() { _super.apply(this, arguments); } - // Gets emitted as super, not _super, which is consistent with - // use of super in static properties initializers. C.prototype[(_a = {}, - _a[super.bar.call(this)] = 1, + _a[_super.bar.call(this)] = 1, _a)[0]] = function () { }; return C; diff --git a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES5.js.map b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES5.js.map index 3457187e78a61..c47fcfcad3114 100644 --- a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES5.js.map +++ b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES5.js.map @@ -1,2 +1,2 @@ //// [computedPropertyNamesSourceMap1_ES5.js.map] -{"version":3,"file":"computedPropertyNamesSourceMap1_ES5.js","sourceRoot":"","sources":["computedPropertyNamesSourceMap1_ES5.ts"],"names":["C","C.constructor","C[\"hello\"]"],"mappings":"AAAA;IAAAA;IAIAC,CAACA;IAHGD,YAACA,OAAOA;QACJE,QAAQA,CAACA;IACbA,CAACA;IACLF,QAACA;AAADA,CAACA,AAJD,IAIC"} \ No newline at end of file +{"version":3,"file":"computedPropertyNamesSourceMap1_ES5.js","sourceRoot":"","sources":["computedPropertyNamesSourceMap1_ES5.ts"],"names":["C","C.constructor","C[\"hello\"]"],"mappings":"AAAA;IAAAA;IAIAC,CAACA;IAHGD,YAACA,OAAOA,CAACA,GAATA;QACIE,QAAQA,CAACA;IACbA,CAACA;IACLF,QAACA;AAADA,CAACA,AAJD,IAIC"} \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES5.sourcemap.txt b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES5.sourcemap.txt index be0f79edd17a3..df0af71fb0224 100644 --- a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES5.sourcemap.txt +++ b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES5.sourcemap.txt @@ -37,18 +37,24 @@ sourceFile:computedPropertyNamesSourceMap1_ES5.ts 1->^^^^ 2 > ^^^^^^^^^^^^ 3 > ^^^^^^^ +4 > ^ +5 > ^^^ 1-> 2 > [ 3 > "hello" +4 > ] +5 > 1->Emitted(4, 5) Source(2, 5) + SourceIndex(0) name (C) 2 >Emitted(4, 17) Source(2, 6) + SourceIndex(0) name (C) 3 >Emitted(4, 24) Source(2, 13) + SourceIndex(0) name (C) +4 >Emitted(4, 25) Source(2, 14) + SourceIndex(0) name (C) +5 >Emitted(4, 28) Source(2, 5) + SourceIndex(0) name (C) --- >>> debugger; 1 >^^^^^^^^ 2 > ^^^^^^^^ 3 > ^ -1 >]() { +1 >["hello"]() { > 2 > debugger 3 > ; diff --git a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.js.map b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.js.map index ff47df55493af..9a2dd60999ef8 100644 --- a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.js.map +++ b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.js.map @@ -1,2 +1,2 @@ //// [computedPropertyNamesSourceMap1_ES6.js.map] -{"version":3,"file":"computedPropertyNamesSourceMap1_ES6.js","sourceRoot":"","sources":["computedPropertyNamesSourceMap1_ES6.ts"],"names":["C","C[\"hello\"]"],"mappings":"AAAA;IACIA,CAACA,OAAOA;QACJC,QAAQA,CAACA;IACbA,CAACA;AACLD,CAACA;AAAA"} \ No newline at end of file +{"version":3,"file":"computedPropertyNamesSourceMap1_ES6.js","sourceRoot":"","sources":["computedPropertyNamesSourceMap1_ES6.ts"],"names":["C","C[\"hello\"]"],"mappings":"AAAA;IACIA,CAACA,OAAOA,CAACA;QACLC,QAAQA,CAACA;IACbA,CAACA;AACLD,CAACA;AAAA"} \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.sourcemap.txt b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.sourcemap.txt index 36535c1aa4f26..30493b9734737 100644 --- a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.sourcemap.txt +++ b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.sourcemap.txt @@ -18,20 +18,23 @@ sourceFile:computedPropertyNamesSourceMap1_ES6.ts 1->^^^^ 2 > ^ 3 > ^^^^^^^ -4 > ^^^^^^-> +4 > ^ +5 > ^^^^^-> 1->class C { > 2 > [ 3 > "hello" +4 > ] 1->Emitted(2, 5) Source(2, 5) + SourceIndex(0) name (C) 2 >Emitted(2, 6) Source(2, 6) + SourceIndex(0) name (C) 3 >Emitted(2, 13) Source(2, 13) + SourceIndex(0) name (C) +4 >Emitted(2, 14) Source(2, 14) + SourceIndex(0) name (C) --- >>> debugger; 1->^^^^^^^^ 2 > ^^^^^^^^ 3 > ^ -1->]() { +1->() { > 2 > debugger 3 > ; diff --git a/tests/baselines/reference/computedPropertyNamesWithStaticProperty.js b/tests/baselines/reference/computedPropertyNamesWithStaticProperty.js index f7506d7904d6c..e6b7bd5aae2de 100644 --- a/tests/baselines/reference/computedPropertyNamesWithStaticProperty.js +++ b/tests/baselines/reference/computedPropertyNamesWithStaticProperty.js @@ -12,8 +12,6 @@ class C { //// [computedPropertyNamesWithStaticProperty.js] class C { - constructor() { - } get [C.staticProp]() { return "hello"; } diff --git a/tests/baselines/reference/emitClassDeclarationWithExport.errors.txt b/tests/baselines/reference/emitClassDeclarationWithExport.errors.txt deleted file mode 100644 index 11b1de11bf67a..0000000000000 --- a/tests/baselines/reference/emitClassDeclarationWithExport.errors.txt +++ /dev/null @@ -1,16 +0,0 @@ -tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts(1,14): error TS1148: Cannot compile external modules unless the '--module' flag is provided. -tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts(5,22): error TS2309: An export assignment cannot be used in a module with other exported elements. - - -==== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts (2 errors) ==== - export class C { - ~ -!!! error TS1148: Cannot compile external modules unless the '--module' flag is provided. - foo() { } - } - - export default class D { - ~ -!!! error TS2309: An export assignment cannot be used in a module with other exported elements. - bar() { } - } \ No newline at end of file diff --git a/tests/baselines/reference/emitClassDeclarationWithExport.js b/tests/baselines/reference/emitClassDeclarationWithExport.js deleted file mode 100644 index 5a6c84389f333..0000000000000 --- a/tests/baselines/reference/emitClassDeclarationWithExport.js +++ /dev/null @@ -1,23 +0,0 @@ -//// [emitClassDeclarationWithExport.ts] -export class C { - foo() { } -} - -export default class D { - bar() { } -} - -//// [emitClassDeclarationWithExport.js] -export class C { - constructor() { - } - foo() { - } -} -export default class D { - constructor() { - } - bar() { - } -} -module.exports = D; diff --git a/tests/baselines/reference/emitClassDeclarationWithStaticPropertyAssignmentInES6.js b/tests/baselines/reference/emitClassDeclarationWithStaticPropertyAssignmentInES6.js index 69da64765a3a6..8e0bf3de06bcd 100644 --- a/tests/baselines/reference/emitClassDeclarationWithStaticPropertyAssignmentInES6.js +++ b/tests/baselines/reference/emitClassDeclarationWithStaticPropertyAssignmentInES6.js @@ -11,8 +11,6 @@ class D { //// [emitClassDeclarationWithStaticPropertyAssignmentInES6.js] class C { - constructor() { - } } C.z = "Foo"; class D { diff --git a/tests/baselines/reference/emitThisInSuperMethodCall.js b/tests/baselines/reference/emitThisInSuperMethodCall.js index 383da7d419f26..de47b0b95aff4 100644 --- a/tests/baselines/reference/emitThisInSuperMethodCall.js +++ b/tests/baselines/reference/emitThisInSuperMethodCall.js @@ -49,20 +49,20 @@ var RegisteredUser = (function (_super) { RegisteredUser.prototype.f = function () { (function () { function inner() { - super.sayHello.call(this); + _super.sayHello.call(this); } }); }; RegisteredUser.prototype.g = function () { function inner() { (function () { - super.sayHello.call(this); + _super.sayHello.call(this); }); } }; RegisteredUser.prototype.h = function () { function inner() { - super.sayHello.call(this); + _super.sayHello.call(this); } }; return RegisteredUser; diff --git a/tests/baselines/reference/errorSuperPropertyAccess.js b/tests/baselines/reference/errorSuperPropertyAccess.js index 17cd2c265edef..4ddcca530f11a 100644 --- a/tests/baselines/reference/errorSuperPropertyAccess.js +++ b/tests/baselines/reference/errorSuperPropertyAccess.js @@ -140,27 +140,27 @@ var __extends = this.__extends || function (d, b) { //super property access in instance member accessor(get and set) of class with no base type var NoBase = (function () { function NoBase() { - this.m = super.prototype; - this.n = super.hasOwnProperty.call(this, ''); - var a = super.prototype; - var b = super.hasOwnProperty.call(this, ''); + this.m = _super.prototype; + this.n = _super.hasOwnProperty.call(this, ''); + var a = _super.prototype; + var b = _super.hasOwnProperty.call(this, ''); } NoBase.prototype.fn = function () { - var a = super.prototype; - var b = super.hasOwnProperty.call(this, ''); + var a = _super.prototype; + var b = _super.hasOwnProperty.call(this, ''); }; //super static property access in static member function of class with no base type //super static property access in static member accessor(get and set) of class with no base type NoBase.static1 = function () { - super.hasOwnProperty.call(this, ''); + _super.hasOwnProperty.call(this, ''); }; Object.defineProperty(NoBase, "static2", { get: function () { - super.hasOwnProperty.call(this, ''); + _super.hasOwnProperty.call(this, ''); return ''; }, set: function (n) { - super.hasOwnProperty.call(this, ''); + _super.hasOwnProperty.call(this, ''); }, enumerable: true, configurable: true @@ -210,11 +210,11 @@ var SomeDerived1 = (function (_super) { }); SomeDerived1.prototype.fn2 = function () { function inner() { - super.publicFunc.call(this); + _super.publicFunc.call(this); } var x = { test: function () { - return super.publicFunc.call(this); + return _super.publicFunc.call(this); } }; }; @@ -278,6 +278,6 @@ var SomeDerived3 = (function (_super) { })(SomeBase); // In object literal var obj = { - n: super.wat, - p: super.foo.call(this) + n: _super.wat, + p: _super.foo.call(this) }; diff --git a/tests/baselines/reference/es6-amd.js b/tests/baselines/reference/es6-amd.js index 0cce3af04463a..74f3037303e35 100644 --- a/tests/baselines/reference/es6-amd.js +++ b/tests/baselines/reference/es6-amd.js @@ -14,14 +14,13 @@ class A } //// [es6-amd.js] -var A = (function () { - function A() { +class A { + constructor() { } - A.prototype.B = function () { + B() { return 42; - }; - return A; -})(); + } +} //# sourceMappingURL=es6-amd.js.map //// [es6-amd.d.ts] diff --git a/tests/baselines/reference/es6-amd.js.map b/tests/baselines/reference/es6-amd.js.map index c9866d87884cb..fe234f8424b52 100644 --- a/tests/baselines/reference/es6-amd.js.map +++ b/tests/baselines/reference/es6-amd.js.map @@ -1,2 +1,2 @@ //// [es6-amd.js.map] -{"version":3,"file":"es6-amd.js","sourceRoot":"","sources":["es6-amd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA;IAEIA;IAGAC,CAACA;IAEMD,aAACA,GAARA;QAEIE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;IACLF,QAACA;AAADA,CAACA,AAXD,IAWC"} \ No newline at end of file +{"version":3,"file":"es6-amd.js","sourceRoot":"","sources":["es6-amd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA;IAEIA;IAGAC,CAACA;IAEMD,CAACA;QAEJE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;AACLF,CAACA;AAAA"} \ No newline at end of file diff --git a/tests/baselines/reference/es6-amd.sourcemap.txt b/tests/baselines/reference/es6-amd.sourcemap.txt index 2b27109940124..1ab547073c61d 100644 --- a/tests/baselines/reference/es6-amd.sourcemap.txt +++ b/tests/baselines/reference/es6-amd.sourcemap.txt @@ -8,14 +8,14 @@ sources: es6-amd.ts emittedFile:tests/cases/compiler/es6-amd.js sourceFile:es6-amd.ts ------------------------------------------------------------------- ->>>var A = (function () { +>>>class A { 1 > -2 >^^^^^^^^^^^^^^^^^^^-> +2 >^^^^^^^^^^^^^^^^^^^^-> 1 > > 1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) --- ->>> function A() { +>>> constructor() { 1->^^^^ 2 > ^^-> 1->class A @@ -26,7 +26,7 @@ sourceFile:es6-amd.ts >>> } 1->^^^^ 2 > ^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +3 > ^^^^^-> 1->constructor () > { > @@ -35,81 +35,57 @@ sourceFile:es6-amd.ts 1->Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor) 2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor) --- ->>> A.prototype.B = function () { +>>> B() { 1->^^^^ -2 > ^^^^^^^^^^^^^ -3 > ^^^ +2 > ^ +3 > ^^^^^^^^^^^^^^-> 1-> > > public 2 > B -3 > 1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A) -2 >Emitted(4, 18) Source(9, 13) + SourceIndex(0) name (A) -3 >Emitted(4, 21) Source(9, 5) + SourceIndex(0) name (A) +2 >Emitted(4, 6) Source(9, 13) + SourceIndex(0) name (A) --- >>> return 42; -1 >^^^^^^^^ +1->^^^^^^^^ 2 > ^^^^^^ 3 > ^ 4 > ^^ 5 > ^ -1 >public B() +1->() > { > 2 > return 3 > 4 > 42 5 > ; -1 >Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) +1->Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) 2 >Emitted(5, 15) Source(11, 15) + SourceIndex(0) name (A.B) 3 >Emitted(5, 16) Source(11, 16) + SourceIndex(0) name (A.B) 4 >Emitted(5, 18) Source(11, 18) + SourceIndex(0) name (A.B) 5 >Emitted(5, 19) Source(11, 19) + SourceIndex(0) name (A.B) --- ->>> }; +>>> } 1 >^^^^ 2 > ^ -3 > ^^^^^^^^^-> 1 > > 2 > } 1 >Emitted(6, 5) Source(12, 5) + SourceIndex(0) name (A.B) 2 >Emitted(6, 6) Source(12, 6) + SourceIndex(0) name (A.B) --- ->>> return A; -1->^^^^ -2 > ^^^^^^^^ -1-> - > -2 > } -1->Emitted(7, 5) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(7, 13) Source(13, 2) + SourceIndex(0) name (A) ---- ->>>})(); +>>>} 1 > 2 >^ -3 > -4 > ^^^^ -5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 > +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + > 2 >} -3 > -4 > class A - > { - > constructor () - > { - > - > } - > - > public B() - > { - > return 42; - > } - > } -1 >Emitted(8, 1) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(8, 2) Source(13, 2) + SourceIndex(0) name (A) -3 >Emitted(8, 2) Source(2, 1) + SourceIndex(0) -4 >Emitted(8, 6) Source(13, 2) + SourceIndex(0) +1 >Emitted(7, 1) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(7, 2) Source(13, 2) + SourceIndex(0) name (A) --- ->>>//# sourceMappingURL=es6-amd.js.map \ No newline at end of file +>>>//# sourceMappingURL=es6-amd.js.map1-> +2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1-> +1->Emitted(8, 1) Source(13, 2) + SourceIndex(0) +--- \ No newline at end of file diff --git a/tests/baselines/reference/es6-declaration-amd.js b/tests/baselines/reference/es6-declaration-amd.js index 471f96b223d1a..aeba23e0b6ede 100644 --- a/tests/baselines/reference/es6-declaration-amd.js +++ b/tests/baselines/reference/es6-declaration-amd.js @@ -14,14 +14,13 @@ class A } //// [es6-declaration-amd.js] -var A = (function () { - function A() { +class A { + constructor() { } - A.prototype.B = function () { + B() { return 42; - }; - return A; -})(); + } +} //# sourceMappingURL=es6-declaration-amd.js.map //// [es6-declaration-amd.d.ts] diff --git a/tests/baselines/reference/es6-declaration-amd.js.map b/tests/baselines/reference/es6-declaration-amd.js.map index 03f79f6c66778..ca1899e03f559 100644 --- a/tests/baselines/reference/es6-declaration-amd.js.map +++ b/tests/baselines/reference/es6-declaration-amd.js.map @@ -1,2 +1,2 @@ //// [es6-declaration-amd.js.map] -{"version":3,"file":"es6-declaration-amd.js","sourceRoot":"","sources":["es6-declaration-amd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA;IAEIA;IAGAC,CAACA;IAEMD,aAACA,GAARA;QAEIE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;IACLF,QAACA;AAADA,CAACA,AAXD,IAWC"} \ No newline at end of file +{"version":3,"file":"es6-declaration-amd.js","sourceRoot":"","sources":["es6-declaration-amd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA;IAEIA;IAGAC,CAACA;IAEMD,CAACA;QAEJE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;AACLF,CAACA;AAAA"} \ No newline at end of file diff --git a/tests/baselines/reference/es6-declaration-amd.sourcemap.txt b/tests/baselines/reference/es6-declaration-amd.sourcemap.txt index 198a68633b1df..9061bc1ed7c48 100644 --- a/tests/baselines/reference/es6-declaration-amd.sourcemap.txt +++ b/tests/baselines/reference/es6-declaration-amd.sourcemap.txt @@ -8,14 +8,14 @@ sources: es6-declaration-amd.ts emittedFile:tests/cases/compiler/es6-declaration-amd.js sourceFile:es6-declaration-amd.ts ------------------------------------------------------------------- ->>>var A = (function () { +>>>class A { 1 > -2 >^^^^^^^^^^^^^^^^^^^-> +2 >^^^^^^^^^^^^^^^^^^^^-> 1 > > 1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) --- ->>> function A() { +>>> constructor() { 1->^^^^ 2 > ^^-> 1->class A @@ -26,7 +26,7 @@ sourceFile:es6-declaration-amd.ts >>> } 1->^^^^ 2 > ^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +3 > ^^^^^-> 1->constructor () > { > @@ -35,81 +35,57 @@ sourceFile:es6-declaration-amd.ts 1->Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor) 2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor) --- ->>> A.prototype.B = function () { +>>> B() { 1->^^^^ -2 > ^^^^^^^^^^^^^ -3 > ^^^ +2 > ^ +3 > ^^^^^^^^^^^^^^-> 1-> > > public 2 > B -3 > 1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A) -2 >Emitted(4, 18) Source(9, 13) + SourceIndex(0) name (A) -3 >Emitted(4, 21) Source(9, 5) + SourceIndex(0) name (A) +2 >Emitted(4, 6) Source(9, 13) + SourceIndex(0) name (A) --- >>> return 42; -1 >^^^^^^^^ +1->^^^^^^^^ 2 > ^^^^^^ 3 > ^ 4 > ^^ 5 > ^ -1 >public B() +1->() > { > 2 > return 3 > 4 > 42 5 > ; -1 >Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) +1->Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) 2 >Emitted(5, 15) Source(11, 15) + SourceIndex(0) name (A.B) 3 >Emitted(5, 16) Source(11, 16) + SourceIndex(0) name (A.B) 4 >Emitted(5, 18) Source(11, 18) + SourceIndex(0) name (A.B) 5 >Emitted(5, 19) Source(11, 19) + SourceIndex(0) name (A.B) --- ->>> }; +>>> } 1 >^^^^ 2 > ^ -3 > ^^^^^^^^^-> 1 > > 2 > } 1 >Emitted(6, 5) Source(12, 5) + SourceIndex(0) name (A.B) 2 >Emitted(6, 6) Source(12, 6) + SourceIndex(0) name (A.B) --- ->>> return A; -1->^^^^ -2 > ^^^^^^^^ -1-> - > -2 > } -1->Emitted(7, 5) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(7, 13) Source(13, 2) + SourceIndex(0) name (A) ---- ->>>})(); +>>>} 1 > 2 >^ -3 > -4 > ^^^^ -5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 > +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + > 2 >} -3 > -4 > class A - > { - > constructor () - > { - > - > } - > - > public B() - > { - > return 42; - > } - > } -1 >Emitted(8, 1) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(8, 2) Source(13, 2) + SourceIndex(0) name (A) -3 >Emitted(8, 2) Source(2, 1) + SourceIndex(0) -4 >Emitted(8, 6) Source(13, 2) + SourceIndex(0) +1 >Emitted(7, 1) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(7, 2) Source(13, 2) + SourceIndex(0) name (A) --- ->>>//# sourceMappingURL=es6-declaration-amd.js.map \ No newline at end of file +>>>//# sourceMappingURL=es6-declaration-amd.js.map1-> +2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1-> +1->Emitted(8, 1) Source(13, 2) + SourceIndex(0) +--- \ No newline at end of file diff --git a/tests/baselines/reference/es6-sourcemap-amd.js b/tests/baselines/reference/es6-sourcemap-amd.js index 805e56cf830d0..106726c0f2cfb 100644 --- a/tests/baselines/reference/es6-sourcemap-amd.js +++ b/tests/baselines/reference/es6-sourcemap-amd.js @@ -14,12 +14,11 @@ class A } //// [es6-sourcemap-amd.js] -var A = (function () { - function A() { +class A { + constructor() { } - A.prototype.B = function () { + B() { return 42; - }; - return A; -})(); + } +} //# sourceMappingURL=es6-sourcemap-amd.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es6-sourcemap-amd.js.map b/tests/baselines/reference/es6-sourcemap-amd.js.map index ef22eb4638c8b..779c13b129698 100644 --- a/tests/baselines/reference/es6-sourcemap-amd.js.map +++ b/tests/baselines/reference/es6-sourcemap-amd.js.map @@ -1,2 +1,2 @@ //// [es6-sourcemap-amd.js.map] -{"version":3,"file":"es6-sourcemap-amd.js","sourceRoot":"","sources":["es6-sourcemap-amd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA;IAEIA;IAGAC,CAACA;IAEMD,aAACA,GAARA;QAEIE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;IACLF,QAACA;AAADA,CAACA,AAXD,IAWC"} \ No newline at end of file +{"version":3,"file":"es6-sourcemap-amd.js","sourceRoot":"","sources":["es6-sourcemap-amd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA;IAEIA;IAGAC,CAACA;IAEMD,CAACA;QAEJE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;AACLF,CAACA;AAAA"} \ No newline at end of file diff --git a/tests/baselines/reference/es6-sourcemap-amd.sourcemap.txt b/tests/baselines/reference/es6-sourcemap-amd.sourcemap.txt index bcfc33d04055c..179dd79ba1700 100644 --- a/tests/baselines/reference/es6-sourcemap-amd.sourcemap.txt +++ b/tests/baselines/reference/es6-sourcemap-amd.sourcemap.txt @@ -8,14 +8,14 @@ sources: es6-sourcemap-amd.ts emittedFile:tests/cases/compiler/es6-sourcemap-amd.js sourceFile:es6-sourcemap-amd.ts ------------------------------------------------------------------- ->>>var A = (function () { +>>>class A { 1 > -2 >^^^^^^^^^^^^^^^^^^^-> +2 >^^^^^^^^^^^^^^^^^^^^-> 1 > > 1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) --- ->>> function A() { +>>> constructor() { 1->^^^^ 2 > ^^-> 1->class A @@ -26,7 +26,7 @@ sourceFile:es6-sourcemap-amd.ts >>> } 1->^^^^ 2 > ^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +3 > ^^^^^-> 1->constructor () > { > @@ -35,81 +35,57 @@ sourceFile:es6-sourcemap-amd.ts 1->Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor) 2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor) --- ->>> A.prototype.B = function () { +>>> B() { 1->^^^^ -2 > ^^^^^^^^^^^^^ -3 > ^^^ +2 > ^ +3 > ^^^^^^^^^^^^^^-> 1-> > > public 2 > B -3 > 1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A) -2 >Emitted(4, 18) Source(9, 13) + SourceIndex(0) name (A) -3 >Emitted(4, 21) Source(9, 5) + SourceIndex(0) name (A) +2 >Emitted(4, 6) Source(9, 13) + SourceIndex(0) name (A) --- >>> return 42; -1 >^^^^^^^^ +1->^^^^^^^^ 2 > ^^^^^^ 3 > ^ 4 > ^^ 5 > ^ -1 >public B() +1->() > { > 2 > return 3 > 4 > 42 5 > ; -1 >Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) +1->Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) 2 >Emitted(5, 15) Source(11, 15) + SourceIndex(0) name (A.B) 3 >Emitted(5, 16) Source(11, 16) + SourceIndex(0) name (A.B) 4 >Emitted(5, 18) Source(11, 18) + SourceIndex(0) name (A.B) 5 >Emitted(5, 19) Source(11, 19) + SourceIndex(0) name (A.B) --- ->>> }; +>>> } 1 >^^^^ 2 > ^ -3 > ^^^^^^^^^-> 1 > > 2 > } 1 >Emitted(6, 5) Source(12, 5) + SourceIndex(0) name (A.B) 2 >Emitted(6, 6) Source(12, 6) + SourceIndex(0) name (A.B) --- ->>> return A; -1->^^^^ -2 > ^^^^^^^^ -1-> - > -2 > } -1->Emitted(7, 5) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(7, 13) Source(13, 2) + SourceIndex(0) name (A) ---- ->>>})(); +>>>} 1 > 2 >^ -3 > -4 > ^^^^ -5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 > +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + > 2 >} -3 > -4 > class A - > { - > constructor () - > { - > - > } - > - > public B() - > { - > return 42; - > } - > } -1 >Emitted(8, 1) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(8, 2) Source(13, 2) + SourceIndex(0) name (A) -3 >Emitted(8, 2) Source(2, 1) + SourceIndex(0) -4 >Emitted(8, 6) Source(13, 2) + SourceIndex(0) +1 >Emitted(7, 1) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(7, 2) Source(13, 2) + SourceIndex(0) name (A) --- ->>>//# sourceMappingURL=es6-sourcemap-amd.js.map \ No newline at end of file +>>>//# sourceMappingURL=es6-sourcemap-amd.js.map1-> +2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1-> +1->Emitted(8, 1) Source(13, 2) + SourceIndex(0) +--- \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-scopes.js b/tests/baselines/reference/letDeclarations-scopes.js index fc7218079940d..d0489820d0b90 100644 --- a/tests/baselines/reference/letDeclarations-scopes.js +++ b/tests/baselines/reference/letDeclarations-scopes.js @@ -259,30 +259,25 @@ var m; lable: let l2 = 0; })(m || (m = {})); // methods -var C = (function () { - function C() { +class C { + constructor() { let l = 0; n = l; } - C.prototype.method = function () { + method() { let l = 0; n = l; - }; - Object.defineProperty(C.prototype, "v", { - get: function () { - let l = 0; - n = l; - return n; - }, - set: function (value) { - let l = 0; - n = l; - }, - enumerable: true, - configurable: true - }); - return C; -})(); + } + get v() { + let l = 0; + n = l; + return n; + } + set v(value) { + let l = 0; + n = l; + } +} // object literals var o = { f() { diff --git a/tests/baselines/reference/letDeclarations-validContexts.js b/tests/baselines/reference/letDeclarations-validContexts.js index f6d404135f695..b11a19223836d 100644 --- a/tests/baselines/reference/letDeclarations-validContexts.js +++ b/tests/baselines/reference/letDeclarations-validContexts.js @@ -221,26 +221,21 @@ var m; } })(m || (m = {})); // methods -var C = (function () { - function C() { +class C { + constructor() { let l24 = 0; } - C.prototype.method = function () { + method() { let l25 = 0; - }; - Object.defineProperty(C.prototype, "v", { - get: function () { - let l26 = 0; - return l26; - }, - set: function (value) { - let l27 = value; - }, - enumerable: true, - configurable: true - }); - return C; -})(); + } + get v() { + let l26 = 0; + return l26; + } + set v(value) { + let l27 = value; + } +} // object literals var o = { f() { diff --git a/tests/baselines/reference/parseClassDeclarationInStrictModeByDefaultInES6.errors.txt b/tests/baselines/reference/parseClassDeclarationInStrictModeByDefaultInES6.errors.txt index 04ac8b28a8bdf..d109b0480854b 100644 --- a/tests/baselines/reference/parseClassDeclarationInStrictModeByDefaultInES6.errors.txt +++ b/tests/baselines/reference/parseClassDeclarationInStrictModeByDefaultInES6.errors.txt @@ -1,5 +1,3 @@ -tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(2,5): error TS1100: Invalid use of 'interface' in strict mode. -tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(3,12): error TS1100: Invalid use of 'implements' in strict mode. tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(4,16): error TS1100: Invalid use of 'arguments' in strict mode. tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(5,17): error TS1100: Invalid use of 'eval' in strict mode. tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(6,9): error TS1100: Invalid use of 'arguments' in strict mode. @@ -7,14 +5,10 @@ tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeBy Property 'callee' is missing in type 'String'. -==== tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts (6 errors) ==== +==== tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts (4 errors) ==== class C { interface = 10; - ~~~~~~~~~ -!!! error TS1100: Invalid use of 'interface' in strict mode. public implements() { } - ~~~~~~~~~~ -!!! error TS1100: Invalid use of 'implements' in strict mode. public foo(arguments: any) { } ~~~~~~~~~ !!! error TS1100: Invalid use of 'arguments' in strict mode. diff --git a/tests/baselines/reference/parserComputedPropertyName10.js b/tests/baselines/reference/parserComputedPropertyName10.js index c00d3292f7e48..eba480ba81088 100644 --- a/tests/baselines/reference/parserComputedPropertyName10.js +++ b/tests/baselines/reference/parserComputedPropertyName10.js @@ -4,9 +4,8 @@ class C { } //// [parserComputedPropertyName10.js] -var C = (function () { - function C() { +class C { + constructor() { this[e] = 1; } - return C; -})(); +} diff --git a/tests/baselines/reference/parserComputedPropertyName11.js b/tests/baselines/reference/parserComputedPropertyName11.js index 1b9575184f257..dc63d6385d848 100644 --- a/tests/baselines/reference/parserComputedPropertyName11.js +++ b/tests/baselines/reference/parserComputedPropertyName11.js @@ -4,8 +4,5 @@ class C { } //// [parserComputedPropertyName11.js] -var C = (function () { - function C() { - } - return C; -})(); +class C { +} diff --git a/tests/baselines/reference/parserComputedPropertyName12.js b/tests/baselines/reference/parserComputedPropertyName12.js index 96e62b626e759..71cf1d352f48a 100644 --- a/tests/baselines/reference/parserComputedPropertyName12.js +++ b/tests/baselines/reference/parserComputedPropertyName12.js @@ -4,10 +4,7 @@ class C { } //// [parserComputedPropertyName12.js] -var C = (function () { - function C() { +class C { + [e]() { } - C.prototype[e] = function () { - }; - return C; -})(); +} diff --git a/tests/baselines/reference/parserComputedPropertyName24.js b/tests/baselines/reference/parserComputedPropertyName24.js index 0b9467fb26d26..8fc0a5be3a50d 100644 --- a/tests/baselines/reference/parserComputedPropertyName24.js +++ b/tests/baselines/reference/parserComputedPropertyName24.js @@ -4,14 +4,7 @@ class C { } //// [parserComputedPropertyName24.js] -var C = (function () { - function C() { +class C { + set [e](v) { } - Object.defineProperty(C.prototype, e, { - set: function (v) { - }, - enumerable: true, - configurable: true - }); - return C; -})(); +} diff --git a/tests/baselines/reference/parserComputedPropertyName25.js b/tests/baselines/reference/parserComputedPropertyName25.js index a00cec2e6dd72..47670fe14b8dc 100644 --- a/tests/baselines/reference/parserComputedPropertyName25.js +++ b/tests/baselines/reference/parserComputedPropertyName25.js @@ -6,10 +6,9 @@ class C { } //// [parserComputedPropertyName25.js] -var C = (function () { - function C() { +class C { + constructor() { // No ASI this[e] = 0[e2] = 1; } - return C; -})(); +} diff --git a/tests/baselines/reference/parserComputedPropertyName27.js b/tests/baselines/reference/parserComputedPropertyName27.js index 03b156af840a3..f872e95e7e659 100644 --- a/tests/baselines/reference/parserComputedPropertyName27.js +++ b/tests/baselines/reference/parserComputedPropertyName27.js @@ -6,10 +6,9 @@ class C { } //// [parserComputedPropertyName27.js] -var C = (function () { - function C() { +class C { + constructor() { // No ASI this[e] = 0[e2]; } - return C; -})(); +} diff --git a/tests/baselines/reference/parserComputedPropertyName28.js b/tests/baselines/reference/parserComputedPropertyName28.js index 60fb25dfa209e..998f60db91462 100644 --- a/tests/baselines/reference/parserComputedPropertyName28.js +++ b/tests/baselines/reference/parserComputedPropertyName28.js @@ -5,9 +5,8 @@ class C { } //// [parserComputedPropertyName28.js] -var C = (function () { - function C() { +class C { + constructor() { this[e] = 0; } - return C; -})(); +} diff --git a/tests/baselines/reference/parserComputedPropertyName29.js b/tests/baselines/reference/parserComputedPropertyName29.js index 05ced020aff21..a100cbf17915c 100644 --- a/tests/baselines/reference/parserComputedPropertyName29.js +++ b/tests/baselines/reference/parserComputedPropertyName29.js @@ -6,10 +6,9 @@ class C { } //// [parserComputedPropertyName29.js] -var C = (function () { - function C() { +class C { + constructor() { // yes ASI this[e] = id++; } - return C; -})(); +} diff --git a/tests/baselines/reference/parserComputedPropertyName31.js b/tests/baselines/reference/parserComputedPropertyName31.js index 2a07155a2f025..cee09fb0ab7bb 100644 --- a/tests/baselines/reference/parserComputedPropertyName31.js +++ b/tests/baselines/reference/parserComputedPropertyName31.js @@ -6,8 +6,5 @@ class C { } //// [parserComputedPropertyName31.js] -var C = (function () { - function C() { - } - return C; -})(); +class C { +} diff --git a/tests/baselines/reference/parserComputedPropertyName33.js b/tests/baselines/reference/parserComputedPropertyName33.js index 1cc06c06780e7..64239bc1284a1 100644 --- a/tests/baselines/reference/parserComputedPropertyName33.js +++ b/tests/baselines/reference/parserComputedPropertyName33.js @@ -6,12 +6,11 @@ class C { } //// [parserComputedPropertyName33.js] -var C = (function () { - function C() { +class C { + constructor() { // No ASI this[e] = 0[e2](); } - return C; -})(); +} { } diff --git a/tests/baselines/reference/parserComputedPropertyName36.errors.txt b/tests/baselines/reference/parserComputedPropertyName36.errors.txt index 07e937b3b42a6..8c647be13c9d6 100644 --- a/tests/baselines/reference/parserComputedPropertyName36.errors.txt +++ b/tests/baselines/reference/parserComputedPropertyName36.errors.txt @@ -1,12 +1,15 @@ -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName36.ts(2,5): error TS1166: A computed property name in a class property declaration must directly refer to a built-in symbol. -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName36.ts(2,6): error TS2304: Cannot find name 'public'. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName36.ts(2,6): error TS1109: Expression expected. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName36.ts(2,13): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName36.ts(2,14): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName36.ts (2 errors) ==== +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName36.ts (3 errors) ==== class C { [public ]: string; - ~~~~~~~~~ -!!! error TS1166: A computed property name in a class property declaration must directly refer to a built-in symbol. ~~~~~~ -!!! error TS2304: Cannot find name 'public'. +!!! error TS1109: Expression expected. + ~ +!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. + ~ +!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. } \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName36.js b/tests/baselines/reference/parserComputedPropertyName36.js index 264a351207581..fd6f376ef2b1c 100644 --- a/tests/baselines/reference/parserComputedPropertyName36.js +++ b/tests/baselines/reference/parserComputedPropertyName36.js @@ -4,8 +4,5 @@ class C { } //// [parserComputedPropertyName36.js] -var C = (function () { - function C() { - } - return C; -})(); +class C { +} diff --git a/tests/baselines/reference/parserComputedPropertyName38.errors.txt b/tests/baselines/reference/parserComputedPropertyName38.errors.txt index 4322abf44edaf..28daf32274860 100644 --- a/tests/baselines/reference/parserComputedPropertyName38.errors.txt +++ b/tests/baselines/reference/parserComputedPropertyName38.errors.txt @@ -1,9 +1,21 @@ -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName38.ts(2,6): error TS2304: Cannot find name 'public'. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName38.ts(2,6): error TS1109: Expression expected. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName38.ts(2,12): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName38.ts(2,13): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName38.ts(2,16): error TS1005: '=>' expected. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName38.ts(3,1): error TS1128: Declaration or statement expected. -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName38.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName38.ts (5 errors) ==== class C { [public]() { } ~~~~~~ -!!! error TS2304: Cannot find name 'public'. - } \ No newline at end of file +!!! error TS1109: Expression expected. + ~ +!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. + ~ +!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. + ~ +!!! error TS1005: '=>' expected. + } + ~ +!!! error TS1128: Declaration or statement expected. \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName38.js b/tests/baselines/reference/parserComputedPropertyName38.js index 487ff4078fde4..e5c9512ad2d31 100644 --- a/tests/baselines/reference/parserComputedPropertyName38.js +++ b/tests/baselines/reference/parserComputedPropertyName38.js @@ -4,10 +4,7 @@ class C { } //// [parserComputedPropertyName38.js] -var C = (function () { - function C() { - } - C.prototype[public] = function () { - }; - return C; -})(); +class C { +} +(() => { +}); diff --git a/tests/baselines/reference/parserComputedPropertyName39.js b/tests/baselines/reference/parserComputedPropertyName39.js index c37312f003421..cee81ccc3d0f3 100644 --- a/tests/baselines/reference/parserComputedPropertyName39.js +++ b/tests/baselines/reference/parserComputedPropertyName39.js @@ -6,10 +6,7 @@ class C { //// [parserComputedPropertyName39.js] "use strict"; -var C = (function () { - function C() { - } - return C; -})(); +class C { +} (() => { }); diff --git a/tests/baselines/reference/parserComputedPropertyName40.js b/tests/baselines/reference/parserComputedPropertyName40.js index 5f6381360fc2f..417e37067d1b1 100644 --- a/tests/baselines/reference/parserComputedPropertyName40.js +++ b/tests/baselines/reference/parserComputedPropertyName40.js @@ -4,10 +4,7 @@ class C { } //// [parserComputedPropertyName40.js] -var C = (function () { - function C() { +class C { + [a ? "" : ""]() { } - C.prototype[a ? "" : ""] = function () { - }; - return C; -})(); +} diff --git a/tests/baselines/reference/parserComputedPropertyName7.js b/tests/baselines/reference/parserComputedPropertyName7.js index 70ed8b7b0738e..aa18db09bc682 100644 --- a/tests/baselines/reference/parserComputedPropertyName7.js +++ b/tests/baselines/reference/parserComputedPropertyName7.js @@ -4,8 +4,5 @@ class C { } //// [parserComputedPropertyName7.js] -var C = (function () { - function C() { - } - return C; -})(); +class C { +} diff --git a/tests/baselines/reference/parserComputedPropertyName8.js b/tests/baselines/reference/parserComputedPropertyName8.js index 4b79c45966301..bab7c3198bd77 100644 --- a/tests/baselines/reference/parserComputedPropertyName8.js +++ b/tests/baselines/reference/parserComputedPropertyName8.js @@ -4,8 +4,5 @@ class C { } //// [parserComputedPropertyName8.js] -var C = (function () { - function C() { - } - return C; -})(); +class C { +} diff --git a/tests/baselines/reference/parserComputedPropertyName9.js b/tests/baselines/reference/parserComputedPropertyName9.js index 4b62cc0ecd968..3ba028a4a1c26 100644 --- a/tests/baselines/reference/parserComputedPropertyName9.js +++ b/tests/baselines/reference/parserComputedPropertyName9.js @@ -4,8 +4,5 @@ class C { } //// [parserComputedPropertyName9.js] -var C = (function () { - function C() { - } - return C; -})(); +class C { +} diff --git a/tests/baselines/reference/parserSuperExpression1.js b/tests/baselines/reference/parserSuperExpression1.js index d0d7f4dcd5261..0d312f79104e1 100644 --- a/tests/baselines/reference/parserSuperExpression1.js +++ b/tests/baselines/reference/parserSuperExpression1.js @@ -18,7 +18,7 @@ var C = (function () { function C() { } C.prototype.foo = function () { - super.foo.call(this); + _super.foo.call(this); }; return C; })(); @@ -30,7 +30,7 @@ var M1; function C() { } C.prototype.foo = function () { - super.foo.call(this); + _super.foo.call(this); }; return C; })(); diff --git a/tests/baselines/reference/parserSuperExpression2.js b/tests/baselines/reference/parserSuperExpression2.js index 8d0c6cf369839..7a77c28ef5240 100644 --- a/tests/baselines/reference/parserSuperExpression2.js +++ b/tests/baselines/reference/parserSuperExpression2.js @@ -10,7 +10,7 @@ var C = (function () { function C() { } C.prototype.M = function () { - super..call(this, 0); + _super..call(this, 0); }; return C; })(); diff --git a/tests/baselines/reference/parserSuperExpression4.js b/tests/baselines/reference/parserSuperExpression4.js index a36981416df43..46ffc65f57cd5 100644 --- a/tests/baselines/reference/parserSuperExpression4.js +++ b/tests/baselines/reference/parserSuperExpression4.js @@ -18,7 +18,7 @@ var C = (function () { function C() { } C.prototype.foo = function () { - super.foo = 1; + _super.foo = 1; }; return C; })(); @@ -30,7 +30,7 @@ var M1; function C() { } C.prototype.foo = function () { - super.foo = 1; + _super.foo = 1; }; return C; })(); diff --git a/tests/baselines/reference/parserSymbolIndexer2.js b/tests/baselines/reference/parserSymbolIndexer2.js index 563614e1c8cf7..4bfe400de53a5 100644 --- a/tests/baselines/reference/parserSymbolIndexer2.js +++ b/tests/baselines/reference/parserSymbolIndexer2.js @@ -4,8 +4,5 @@ class C { } //// [parserSymbolIndexer2.js] -var C = (function () { - function C() { - } - return C; -})(); +class C { +} diff --git a/tests/baselines/reference/parserSymbolIndexer3.js b/tests/baselines/reference/parserSymbolIndexer3.js index 917945193aee0..36247ea2a139a 100644 --- a/tests/baselines/reference/parserSymbolIndexer3.js +++ b/tests/baselines/reference/parserSymbolIndexer3.js @@ -4,8 +4,5 @@ class C { } //// [parserSymbolIndexer3.js] -var C = (function () { - function C() { - } - return C; -})(); +class C { +} diff --git a/tests/baselines/reference/parserSymbolProperty5.js b/tests/baselines/reference/parserSymbolProperty5.js index 922e1fb0323ba..a8b1d564fa800 100644 --- a/tests/baselines/reference/parserSymbolProperty5.js +++ b/tests/baselines/reference/parserSymbolProperty5.js @@ -4,8 +4,5 @@ class C { } //// [parserSymbolProperty5.js] -var C = (function () { - function C() { - } - return C; -})(); +class C { +} diff --git a/tests/baselines/reference/parserSymbolProperty6.js b/tests/baselines/reference/parserSymbolProperty6.js index cbc06cd295173..d2aa55fe0859a 100644 --- a/tests/baselines/reference/parserSymbolProperty6.js +++ b/tests/baselines/reference/parserSymbolProperty6.js @@ -4,9 +4,8 @@ class C { } //// [parserSymbolProperty6.js] -var C = (function () { - function C() { +class C { + constructor() { this[Symbol.toStringTag] = ""; } - return C; -})(); +} diff --git a/tests/baselines/reference/parserSymbolProperty7.js b/tests/baselines/reference/parserSymbolProperty7.js index 9d34b9e3bcef2..a3061ee1b5867 100644 --- a/tests/baselines/reference/parserSymbolProperty7.js +++ b/tests/baselines/reference/parserSymbolProperty7.js @@ -4,10 +4,7 @@ class C { } //// [parserSymbolProperty7.js] -var C = (function () { - function C() { +class C { + [Symbol.toStringTag]() { } - C.prototype[Symbol.toStringTag] = function () { - }; - return C; -})(); +} diff --git a/tests/baselines/reference/properties.js.map b/tests/baselines/reference/properties.js.map index 6e68d36e346f9..e55d29427348e 100644 --- a/tests/baselines/reference/properties.js.map +++ b/tests/baselines/reference/properties.js.map @@ -1,2 +1,2 @@ //// [properties.js.map] -{"version":3,"file":"properties.js","sourceRoot":"","sources":["properties.ts"],"names":["MyClass","MyClass.constructor","MyClass.Count"],"mappings":"AACA;IAAAA;IAWAC,CAACA;IATGD,sBAAWA,0BAAKA;aAAhBA;YAEIE,MAAMA,CAACA,EAAEA,CAACA;QACdA,CAACA;aAEDF,UAAiBA,KAAaA;YAE1BE,EAAEA;QACNA,CAACA;;;OALAF;IAMLA,cAACA;AAADA,CAACA,AAXD,IAWC"} \ No newline at end of file +{"version":3,"file":"properties.js","sourceRoot":"","sources":["properties.ts"],"names":["MyClass","MyClass.constructor","MyClass.Count"],"mappings":"AACA;IAAAA;IAWAC,CAACA;IATcD,gDAAKA;aAAhBA;YAEIE,MAAMA,CAACA,EAAEA,CAACA;QACdA,CAACA;aAEDF,UAAiBA,KAAaA;YAE1BE,EAAEA;QACNA,CAACA;;;OALAF;IAMLA,cAACA;AAADA,CAACA,AAXD,IAWC"} \ No newline at end of file diff --git a/tests/baselines/reference/properties.sourcemap.txt b/tests/baselines/reference/properties.sourcemap.txt index 9ff77cc2c5d80..caf72da0b7b1b 100644 --- a/tests/baselines/reference/properties.sourcemap.txt +++ b/tests/baselines/reference/properties.sourcemap.txt @@ -43,14 +43,11 @@ sourceFile:properties.ts --- >>> Object.defineProperty(MyClass.prototype, "Count", { 1->^^^^ -2 > ^^^^^^^^^^^^^^^^^^^^^^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^ +2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1-> -2 > public get -3 > Count -1->Emitted(4, 5) Source(4, 5) + SourceIndex(0) name (MyClass) -2 >Emitted(4, 27) Source(4, 16) + SourceIndex(0) name (MyClass) -3 >Emitted(4, 53) Source(4, 21) + SourceIndex(0) name (MyClass) +2 > Count +1->Emitted(4, 5) Source(4, 16) + SourceIndex(0) name (MyClass) +2 >Emitted(4, 53) Source(4, 21) + SourceIndex(0) name (MyClass) --- >>> get: function () { 1 >^^^^^^^^^^^^^ diff --git a/tests/baselines/reference/sourceMapValidationClass.js.map b/tests/baselines/reference/sourceMapValidationClass.js.map index 8693cf5d0fe67..79ae9de95eed4 100644 --- a/tests/baselines/reference/sourceMapValidationClass.js.map +++ b/tests/baselines/reference/sourceMapValidationClass.js.map @@ -1,2 +1,2 @@ //// [sourceMapValidationClass.js.map] -{"version":3,"file":"sourceMapValidationClass.js","sourceRoot":"","sources":["sourceMapValidationClass.ts"],"names":["Greeter","Greeter.constructor","Greeter.greet","Greeter.fn","Greeter.greetings"],"mappings":"AAAA;IACIA,iBAAmBA,QAAgBA;QAAEC,WAAcA;aAAdA,WAAcA,CAAdA,sBAAcA,CAAdA,IAAcA;YAAdA,0BAAcA;;QAAhCA,aAAQA,GAARA,QAAQA,CAAQA;QAM3BA,OAAEA,GAAWA,EAAEA,CAACA;IALxBA,CAACA;IACDD,uBAAKA,GAALA;QACIE,MAAMA,CAACA,MAAMA,GAAGA,IAAIA,CAACA,QAAQA,GAAGA,OAAOA,CAACA;IAC5CA,CAACA;IAGOF,oBAAEA,GAAVA;QACIG,MAAMA,CAACA,IAAIA,CAACA,QAAQA,CAACA;IACzBA,CAACA;IACDH,sBAAIA,8BAASA;aAAbA;YACII,MAAMA,CAACA,IAAIA,CAACA,QAAQA,CAACA;QACzBA,CAACA;aACDJ,UAAcA,SAAiBA;YAC3BI,IAAIA,CAACA,QAAQA,GAAGA,SAASA,CAACA;QAC9BA,CAACA;;;OAHAJ;IAILA,cAACA;AAADA,CAACA,AAjBD,IAiBC"} \ No newline at end of file +{"version":3,"file":"sourceMapValidationClass.js","sourceRoot":"","sources":["sourceMapValidationClass.ts"],"names":["Greeter","Greeter.constructor","Greeter.greet","Greeter.fn","Greeter.greetings"],"mappings":"AAAA;IACIA,iBAAmBA,QAAgBA;QAAEC,WAAcA;aAAdA,WAAcA,CAAdA,sBAAcA,CAAdA,IAAcA;YAAdA,0BAAcA;;QAAhCA,aAAQA,GAARA,QAAQA,CAAQA;QAM3BA,OAAEA,GAAWA,EAAEA,CAACA;IALxBA,CAACA;IACDD,uBAAKA,GAALA;QACIE,MAAMA,CAACA,MAAMA,GAAGA,IAAIA,CAACA,QAAQA,GAAGA,OAAOA,CAACA;IAC5CA,CAACA;IAGOF,oBAAEA,GAAVA;QACIG,MAAMA,CAACA,IAAIA,CAACA,QAAQA,CAACA;IACzBA,CAACA;IACGH,oDAASA;aAAbA;YACII,MAAMA,CAACA,IAAIA,CAACA,QAAQA,CAACA;QACzBA,CAACA;aACDJ,UAAcA,SAAiBA;YAC3BI,IAAIA,CAACA,QAAQA,GAAGA,SAASA,CAACA;QAC9BA,CAACA;;;OAHAJ;IAILA,cAACA;AAADA,CAACA,AAjBD,IAiBC"} \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationClass.sourcemap.txt b/tests/baselines/reference/sourceMapValidationClass.sourcemap.txt index 0e019b487bbca..d4c4e0ed365c9 100644 --- a/tests/baselines/reference/sourceMapValidationClass.sourcemap.txt +++ b/tests/baselines/reference/sourceMapValidationClass.sourcemap.txt @@ -223,15 +223,12 @@ sourceFile:sourceMapValidationClass.ts --- >>> Object.defineProperty(Greeter.prototype, "greetings", { 1->^^^^ -2 > ^^^^^^^^^^^^^^^^^^^^^^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1-> - > -2 > get -3 > greetings -1->Emitted(16, 5) Source(12, 5) + SourceIndex(0) name (Greeter) -2 >Emitted(16, 27) Source(12, 9) + SourceIndex(0) name (Greeter) -3 >Emitted(16, 57) Source(12, 18) + SourceIndex(0) name (Greeter) + > get +2 > greetings +1->Emitted(16, 5) Source(12, 9) + SourceIndex(0) name (Greeter) +2 >Emitted(16, 57) Source(12, 18) + SourceIndex(0) name (Greeter) --- >>> get: function () { 1 >^^^^^^^^^^^^^ diff --git a/tests/baselines/reference/super.js b/tests/baselines/reference/super.js index 5c3102cd877ec..453eb820ddbee 100644 --- a/tests/baselines/reference/super.js +++ b/tests/baselines/reference/super.js @@ -80,7 +80,7 @@ var Base2 = (function () { function Base2() { } Base2.prototype.foo = function () { - super.foo.call(this); + _super.foo.call(this); }; return Base2; })(); diff --git a/tests/baselines/reference/super1.js b/tests/baselines/reference/super1.js index acc5b4072f5de..ab982aa8fdf0c 100644 --- a/tests/baselines/reference/super1.js +++ b/tests/baselines/reference/super1.js @@ -166,7 +166,7 @@ var Base4; function Sub4E() { } Sub4E.prototype.x = function () { - return super.x.call(this); + return _super.x.call(this); }; return Sub4E; })(); diff --git a/tests/baselines/reference/superAccess2.js b/tests/baselines/reference/superAccess2.js index cd3d9c63e4140..259afb1af0f5a 100644 --- a/tests/baselines/reference/superAccess2.js +++ b/tests/baselines/reference/superAccess2.js @@ -64,6 +64,6 @@ var Q = (function (_super) { _super.x.call(this); // error _super.y.call(this); }; - Q.yy = super.; // error for static initializer accessing super + Q.yy = _super.; // error for static initializer accessing super return Q; })(P); diff --git a/tests/baselines/reference/superErrors.js b/tests/baselines/reference/superErrors.js index 2dc2db1a3d422..2b1a508261710 100644 --- a/tests/baselines/reference/superErrors.js +++ b/tests/baselines/reference/superErrors.js @@ -60,14 +60,14 @@ var __extends = this.__extends || function (d, b) { }; function foo() { // super in a non class context - var x = super.; + var x = _super.; var y = function () { - return super.; + return _super.; }; var z = function () { return function () { return function () { - return super.; + return _super.; }; }; }; @@ -88,18 +88,18 @@ var RegisteredUser = (function (_super) { this.name = "Frank"; // super call in an inner function in a constructor function inner() { - super.sayHello.call(this); + _super.sayHello.call(this); } // super call in a lambda in an inner function in a constructor function inner2() { var x = function () { - return super.sayHello.call(this); + return _super.sayHello.call(this); }; } // super call in a lambda in a function expression in a constructor (function () { return function () { - return super.; + return _super.; }; })(); } @@ -109,13 +109,13 @@ var RegisteredUser = (function (_super) { // super call in a lambda in an inner function in a method function inner() { var x = function () { - return super.sayHello.call(this); + return _super.sayHello.call(this); }; } // super call in a lambda in a function expression in a constructor (function () { return function () { - return super.; + return _super.; }; })(); }; diff --git a/tests/baselines/reference/super_inside-object-literal-getters-and-setters.js b/tests/baselines/reference/super_inside-object-literal-getters-and-setters.js index 48ae609cdc604..c4ced2a9dcc7d 100644 --- a/tests/baselines/reference/super_inside-object-literal-getters-and-setters.js +++ b/tests/baselines/reference/super_inside-object-literal-getters-and-setters.js @@ -39,13 +39,13 @@ var ObjectLiteral; var ThisInObjectLiteral = { _foo: '1', get foo() { - return super._foo; + return _super._foo; }, set foo(value) { - super._foo = value; + _super._foo = value; }, test: function () { - return super._foo; + return _super._foo; } }; })(ObjectLiteral || (ObjectLiteral = {})); @@ -65,7 +65,7 @@ var SuperObjectTest = (function (_super) { SuperObjectTest.prototype.testing = function () { var test = { get F() { - return super.test.call(this); + return _super.test.call(this); } }; }; diff --git a/tests/baselines/reference/symbolDeclarationEmit11.js b/tests/baselines/reference/symbolDeclarationEmit11.js index 8af17c95815a6..599f7393f4bc2 100644 --- a/tests/baselines/reference/symbolDeclarationEmit11.js +++ b/tests/baselines/reference/symbolDeclarationEmit11.js @@ -8,8 +8,6 @@ class C { //// [symbolDeclarationEmit11.js] class C { - constructor() { - } static [Symbol.toPrimitive]() { } static get [Symbol.isRegExp]() { diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts deleted file mode 100644 index c7fd43cb9e283..0000000000000 --- a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts +++ /dev/null @@ -1,8 +0,0 @@ -// @target: es6 -export class C { - foo(y: string, ...args: any) { } -} - -export default class D { - bar(k = 10) {} -} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames24_ES5.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames24_ES5.ts index ff94b6c961763..ac9ffd50fd660 100644 --- a/tests/cases/conformance/es6/computedProperties/computedPropertyNames24_ES5.ts +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames24_ES5.ts @@ -5,7 +5,5 @@ class Base { } } class C extends Base { - // Gets emitted as super, not _super, which is consistent with - // use of super in static properties initializers. [super.bar()]() { } } \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames26_ES5.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames26_ES5.ts index 4b0d794b1a791..3b2f66fe588fd 100644 --- a/tests/cases/conformance/es6/computedProperties/computedPropertyNames26_ES5.ts +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames26_ES5.ts @@ -5,8 +5,6 @@ class Base { } } class C extends Base { - // Gets emitted as super, not _super, which is consistent with - // use of super in static properties initializers. [ { [super.bar()]: 1 }[0] ]() { } From e573461745b52e23490fdd6aa3ec98323846f0d3 Mon Sep 17 00:00:00 2001 From: Yui T Date: Mon, 16 Mar 2015 14:43:53 -0700 Subject: [PATCH 086/224] Address code review. Use-before-def check will be added to separate work item --- src/compiler/checker.ts | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index feb95b4da16d5..05c6e71ef439d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5696,29 +5696,6 @@ module ts { if (!links.resolvedType) { links.resolvedType = checkExpression(node.expression); - // Disallow using a static property in computedPropertyName because classDeclaration is bound lexically in ES6 - // and its static property assignment will be emitted after classDeclaration. - // Therefore, using static property inside computedPropertyName will cause an use-before-definition error - // Example: - // * TypeScript - // class C { - // static p = 10; - // [C.p]() {} - // } - // * JavaScript - // class C { - // [C.p]() {} // Use before definition error - // } - // C.p = 10; - if (links.resolvedSymbol) { - var declarations = links.resolvedSymbol.declarations; - forEach(declarations, declaration => { - if (declaration.flags & NodeFlags.Static) { - error(node, Diagnostics.A_computed_property_name_cannot_reference_a_static_property); - } - }); - } - // This will allow types number, string, symbol or any. It will also allow enums, the unknown // type, and any union of these types (like string | number). if (!allConstituentTypesHaveKind(links.resolvedType, TypeFlags.Any | TypeFlags.NumberLike | TypeFlags.StringLike | TypeFlags.ESSymbol)) { @@ -11891,9 +11868,7 @@ module ts { var nameText = declarationNameToString(identifier); // Always report 'eval' and 'arguments' invalid usage in strict mode code regardless of parser diagnostics - var sourceFile = getSourceFileOfNode(identifier); - diagnostics.add(createDiagnosticForNode(identifier, Diagnostics.Invalid_use_of_0_in_strict_mode, nameText)); - return true; + return grammarErrorOnNode(identifier, Diagnostics.Invalid_use_of_0_in_strict_mode, nameText); } } } From 51c64b385c817f48b8c4d9e239ac143650520e3f Mon Sep 17 00:00:00 2001 From: steveluc Date: Mon, 16 Mar 2015 14:47:46 -0700 Subject: [PATCH 087/224] Added configuration message. Added logic to expand tabs to spaces using host-configured tab size. --- src/server/editorServices.ts | 45 ++++++++++++++++++++++++++++-------- src/server/protocol.d.ts | 30 ++++++++++++++++++++++++ src/server/session.ts | 19 +++++++++++---- 3 files changed, 80 insertions(+), 14 deletions(-) diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 7c9ccfa785464..e3ed6914b6778 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -153,10 +153,10 @@ module ts.server { } } - reloadScript(filename: string, tmpfilename: string, cb: () => any) { + reloadScript(filename: string, tmpfilename: string, tabSize: number, cb: () => any) { var script = this.getScriptInfo(filename); if (script) { - script.svc.reloadFromFile(tmpfilename, cb); + script.svc.reloadFromFile(tmpfilename, tabSize, cb); } } @@ -259,7 +259,6 @@ module ts.server { interface ProjectOptions { // these fields can be present in the project file files?: string[]; - formatCodeOptions?: ts.FormatCodeOptions; compilerOptions?: ts.CompilerOptions; } @@ -338,7 +337,6 @@ module ts.server { if (projectOptions.compilerOptions) { this.compilerService.setCompilerOptions(projectOptions.compilerOptions); } - // TODO: format code options } } @@ -362,6 +360,11 @@ module ts.server { (eventName: string, project: Project, fileName: string): void; } + interface HostConfiguration { + formatCodeOptions: ts.FormatCodeOptions; + hostInfo: string; + } + export class ProjectService { filenameToScriptInfo: ts.Map = {}; // open, non-configured files in two lists @@ -369,9 +372,22 @@ module ts.server { openFilesReferenced: ScriptInfo[] = []; // projects covering open files inferredProjects: Project[] = []; + hostConfiguration: HostConfiguration; constructor(public host: ServerHost, public psLogger: Logger, public eventHandler?: ProjectServiceEventHandler) { // ts.disableIncrementalParsing = true; + this.addDefaultHostConfiguration(); + } + + addDefaultHostConfiguration() { + this.hostConfiguration = { + formatCodeOptions: ts.clone(CompilerService.defaultFormatCodeOptions), + hostInfo: "Unknown host" + } + } + + getFormatCodeOptions() { + return this.hostConfiguration.formatCodeOptions; } watchedFileChanged(fileName: string) { @@ -386,7 +402,7 @@ module ts.server { } else { if (info && (!info.isOpen)) { - info.svc.reloadFromFile(info.fileName); + info.svc.reloadFromFile(info.fileName, this.hostConfiguration.formatCodeOptions.TabSize); } } } @@ -395,6 +411,18 @@ module ts.server { this.psLogger.msg(msg, type); } + setHostConfiguration(args: ts.server.protocol.ConfigureRequestArguments) { + this.hostConfiguration.formatCodeOptions.TabSize = args.tabSize; + this.hostConfiguration.formatCodeOptions.IndentSize = args.indentSize; + this.hostConfiguration.hostInfo = args.hostInfo; + this.log("Host information " + args.hostInfo, "Info"); + } + + expandTabs(text: string) { + var spaces = generateSpaces(this.hostConfiguration.formatCodeOptions.TabSize); + return text.replace(/\t/g, spaces); + } + closeLog() { this.psLogger.close(); } @@ -609,6 +637,7 @@ module ts.server { } } if (content !== undefined) { + content = this.expandTabs(content); info = new ScriptInfo(this.host, fileName, content, openedByClient); this.filenameToScriptInfo[fileName] = info; if (!info.isOpen) { @@ -742,9 +771,6 @@ module ts.server { files: parsedCommandLine.fileNames, compilerOptions: parsedCommandLine.options }; - if (rawConfig.formatCodeOptions) { - projectOptions.formatCodeOptions = rawConfig.formatCodeOptions; - } proj.setProjectOptions(projectOptions); return { success: true, project: proj }; } @@ -768,7 +794,6 @@ module ts.server { classifier: ts.Classifier; settings = ts.getDefaultCompilerOptions(); documentRegistry = ts.createDocumentRegistry(); - formatCodeOptions: ts.FormatCodeOptions = CompilerService.defaultFormatCodeOptions; constructor(public project: Project) { this.host = new LSHost(project.projectService.host, project); @@ -1096,7 +1121,7 @@ module ts.server { return this.currentVersion; } - reloadFromFile(filename: string, cb?: () => any) { + reloadFromFile(filename: string, tabSize: number, cb?: () => any) { var content = ts.sys.readFile(filename); this.reload(content); if (cb) diff --git a/src/server/protocol.d.ts b/src/server/protocol.d.ts index 23ef00d6b44c7..0adda71cac243 100644 --- a/src/server/protocol.d.ts +++ b/src/server/protocol.d.ts @@ -299,6 +299,36 @@ declare module ts.server.protocol { body?: RenameResponseBody; } + /** + * Information found in a configure request. + */ + export interface ConfigureRequestArguments { + /** Number of spaces for each tab */ + tabSize: number; + /** Number of spaces to indent during formatting */ + indentSize: number; + /** + * Information about the host, for example 'Emacs 24.4' or + * 'Sublime Text version 3075' + */ + hostInfo: string; + } + + /** + * Configure request; value of command field is "configure". Specifies + * host information, such as host type, tab size, and indent size. + */ + export interface ConfigureRequest extends Request { + arguments: ConfigureRequestArguments; + } + + /** + * Response to "configure" request. This is just an acknowledgement, so + * no body field is required. + */ + export interface ConfigureResponse extends Response { + } + /** * Open request; value of command field is "open". Notify the * server that the client has file open. The server will not diff --git a/src/server/session.ts b/src/server/session.ts index cc705d64d5e93..9917632383186 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -11,7 +11,7 @@ module ts.server { stack?: string; } - function generateSpaces(n: number): string { + export function generateSpaces(n: number): string { if (!spaceCache[n]) { var strBuilder = ""; for (var i = 0; i < n; i++) { @@ -80,6 +80,7 @@ module ts.server { export var Close = "close"; export var Completions = "completions"; export var CompletionDetails = "completionEntryDetails"; + export var Configure = "configure"; export var Definition = "definition"; export var Format = "format"; export var Formatonkey = "formatonkey"; @@ -439,7 +440,8 @@ module ts.server { var endPosition = compilerService.host.lineColToPosition(file, endLine, endCol); // TODO: avoid duplicate code (with formatonkey) - var edits = compilerService.languageService.getFormattingEditsForRange(file, startPosition, endPosition, compilerService.formatCodeOptions); + var edits = compilerService.languageService.getFormattingEditsForRange(file, startPosition, endPosition, + this.projectService.getFormatCodeOptions()); if (!edits) { return undefined; } @@ -464,7 +466,7 @@ module ts.server { var compilerService = project.compilerService; var position = compilerService.host.lineColToPosition(file, line, col); var edits = compilerService.languageService.getFormattingEditsAfterKeystroke(file, position, key, - compilerService.formatCodeOptions); + this.projectService.getFormatCodeOptions()); // Check whether we should auto-indent. This will be when // the position is on a line containing only whitespace. // This should leave the edits returned from @@ -608,7 +610,8 @@ module ts.server { if (project) { this.changeSeq++; // make sure no changes happen before this one is finished - project.compilerService.host.reloadScript(file, tmpfile,() => { + project.compilerService.host.reloadScript(file, tmpfile, + this.projectService.getFormatCodeOptions().TabSize, () => { this.output(undefined, CommandNames.Reload, reqSeq); }); } @@ -796,9 +799,17 @@ module ts.server { responseRequired = false; break; } + case CommandNames.Configure: { + var configureArgs = request.arguments; + this.projectService.setHostConfiguration(configureArgs); + this.output(undefined, CommandNames.Configure, request.seq); + responseRequired = false; + break; + } case CommandNames.Reload: { var reloadArgs = request.arguments; this.reload(reloadArgs.file, reloadArgs.tmpfile, request.seq); + responseRequired = false; break; } case CommandNames.Saveto: { From 90fae03f1f45708815ee7470183b7c3cf7e669bc Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Mon, 16 Mar 2015 14:52:03 -0700 Subject: [PATCH 088/224] More PR feedback --- src/compiler/checker.ts | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index eed4b25959695..efaaafd2e1967 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4615,10 +4615,18 @@ module ts { if (target === typeParameters[i]) { let inferences = context.inferences[i]; if (!inferences.isFixed) { + // Any inferences that are made to a type parameter in a union type are inferior + // to inferences made to a flat (non-union) type. This is because if we infer to + // T | string[], we really don't know if we should be inferring to T or not (because + // the correct constituent on the target side could be string[]). Therefore, we put + // such inferior inferences into a secondary bucket, and only use them if the primary + // bucket is empty. let candidates = inferiority ? inferences.secondary || (inferences.secondary = []) : inferences.primary || (inferences.primary = []); - if (!contains(candidates, source)) candidates.push(source); + if (!contains(candidates, source)) { + candidates.push(source); + } } return; } @@ -6358,12 +6366,22 @@ module ts { // Clear out all the inference results from the last time inferTypeArguments was called on this context for (let i = 0; i < typeParameters.length; i++) { // As an optimization, we don't have to clear (and later recompute) inferred types - // for type parameters that have already been fixed on the previous call to inferTypeArguments + // for type parameters that have already been fixed on the previous call to inferTypeArguments. + // It would be just as correct to reset all of them. But then we'd be repeating the same work + // for the type parameters that were fixed, namely the work done by getInferredType. if (!context.inferences[i].isFixed) { context.inferredTypes[i] = undefined; } } - if (context.failedTypeParameterIndex >= 0 && !context.inferences[context.failedTypeParameterIndex].isFixed) { + + // On this call to inferTypeArguments, we may get more inferences for certain type parameters that were not + // fixed last time. This means that a type parameter that failed inference last time may succeed this time, + // or vice versa. Therefore, the failedTypeParameterIndex is useless if it points to an unfixed type parameter, + // because it may change. So here we reset it. However, getInferredType will not revisit any type parameters + // that were previously fixed. So if a fixed type parameter failed previously, it will fail again because + // it will contain the exact same set of inferences. So if we reset the index from a fixed type parameter, + // we will lose information that we won't recover this time around. + if (context.failedTypeParameterIndex !== undefined && !context.inferences[context.failedTypeParameterIndex].isFixed) { context.failedTypeParameterIndex = undefined; } From 2c60cf96dd8a76fd0e8302b2213b174fd7805e94 Mon Sep 17 00:00:00 2001 From: steveluc Date: Mon, 16 Mar 2015 15:10:58 -0700 Subject: [PATCH 089/224] Add use of host-configured format options to additional code site. --- src/server/session.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/server/session.ts b/src/server/session.ts index 9917632383186..012c7ad6ae4f5 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -465,8 +465,9 @@ module ts.server { var compilerService = project.compilerService; var position = compilerService.host.lineColToPosition(file, line, col); + var formatOptions = this.projectService.getFormatCodeOptions(); var edits = compilerService.languageService.getFormattingEditsAfterKeystroke(file, position, key, - this.projectService.getFormatCodeOptions()); + formatOptions); // Check whether we should auto-indent. This will be when // the position is on a line containing only whitespace. // This should leave the edits returned from @@ -482,8 +483,8 @@ module ts.server { if (lineText.search("\\S") < 0) { // TODO: get these options from host var editorOptions: ts.EditorOptions = { - IndentSize: 4, - TabSize: 4, + IndentSize: formatOptions.IndentSize, + TabSize: formatOptions.TabSize, NewLineCharacter: "\n", ConvertTabsToSpaces: true, }; From 88933d54cc24eb98f1013e0d09aafacade4a0374 Mon Sep 17 00:00:00 2001 From: Yui T Date: Mon, 16 Mar 2015 15:20:40 -0700 Subject: [PATCH 090/224] Address code review --- src/compiler/emitter.ts | 66 ++++++++----------- src/compiler/parser.ts | 11 +--- ...PropertyNamesWithStaticProperty.errors.txt | 22 ------- ...putedPropertyNamesWithStaticProperty.types | 29 ++++++++ tests/baselines/reference/properties.js.map | 2 +- .../reference/properties.sourcemap.txt | 11 ++-- .../reference/sourceMapValidationClass.js.map | 2 +- .../sourceMapValidationClass.sourcemap.txt | 13 ++-- 8 files changed, 77 insertions(+), 79 deletions(-) delete mode 100644 tests/baselines/reference/computedPropertyNamesWithStaticProperty.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNamesWithStaticProperty.types diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index a079994e5c8f7..8e53b3e96c475 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2630,7 +2630,6 @@ module ts { } function emitSuper(node: Node) { - debugger; if (languageVersion >= ScriptTarget.ES6) { write("super"); } @@ -2639,9 +2638,6 @@ module ts { if (flags & NodeCheckFlags.SuperInstance) { write("_super.prototype"); } - else if ((flags & NodeCheckFlags.SuperStatic) || (node.parent.kind === SyntaxKind.Constructor)) { - write("_super"); - } else { write("_super"); } @@ -4403,23 +4399,7 @@ module ts { emitComputedPropertyName(memberName); } else { - // For ES6 and above, we want to emit memberName by itself without prefix ".", - // For ES5 and below, we want to prefix memberName with ".". For example, - // Typescript: - // class C { - // x = 10; - // foo () {} - // } - // Javascript: - // var C = (function () { - // function C() { - // this.x = 10; // Property "x" need to be prefixed with "." - // } - // C.prototype.foo = function() {}; // Similarly property "foo" need to be prefixed with "." - // } - if (languageVersion < ScriptTarget.ES6 || memberName.parent.kind === SyntaxKind.PropertyDeclaration) { - write("."); - } + write("."); emitNodeWithoutSourceMap(memberName); } } @@ -4458,14 +4438,18 @@ module ts { writeLine(); emitLeadingComments(member); emitStart(member); + emitStart((member).name); emitDeclarationName(node); if (!(member.flags & NodeFlags.Static)) { write(".prototype"); } emitMemberAccessForPropertyName((member).name); + emitEnd((member).name); write(" = "); + emitStart(member); emitFunctionDeclaration(member); emitEnd(member); + emitEnd(member); write(";"); emitTrailingComments(member); } @@ -4475,12 +4459,14 @@ module ts { writeLine(); emitStart(member); write("Object.defineProperty("); + emitStart((member).name); emitDeclarationName(node); if (!(member.flags & NodeFlags.Static)) { write(".prototype"); } write(", "); emitExpressionForPropertyName((member).name); + emitEnd((member).name); write(", {"); increaseIndent(); if (accessors.getAccessor) { @@ -4531,7 +4517,7 @@ module ts { if (member.flags & NodeFlags.Static) { write("static "); } - emitMemberAccessForPropertyName((member).name); + emit((member).name); emitSignatureAndBody(member); emitEnd(member); emitTrailingComments(member); @@ -4539,6 +4525,7 @@ module ts { else if (member.kind === SyntaxKind.GetAccessor || member.kind === SyntaxKind.SetAccessor) { var accessors = getAllAccessorDeclarations(node.members, member); if (member === accessors.firstAccessor) { + writeLine(); if (accessors.getAccessor) { writeLine(); emitLeadingComments(accessors.getAccessor); @@ -4547,7 +4534,7 @@ module ts { write("static "); } write("get "); - emitMemberAccessForPropertyName((member).name); + emit((member).name); emitSignatureAndBody(accessors.getAccessor); emitEnd(accessors.getAccessor); emitTrailingComments(accessors.getAccessor); @@ -4561,7 +4548,7 @@ module ts { write("static "); } write("set "); - emitMemberAccessForPropertyName((member).name); + emit((member).name); emitSignatureAndBody(accessors.setAccessor); emitEnd(accessors.setAccessor); emitTrailingComments(accessors.setAccessor);; @@ -4572,42 +4559,42 @@ module ts { } function emitConstructor(node: ClassDeclaration, baseTypeNode: TypeReferenceNode) { - debugger; - var saveTempCount = tempCount; - var saveTempVariables = tempVariables; - var saveTempParameters = tempParameters; + let saveTempCount = tempCount; + let saveTempVariables = tempVariables; + let saveTempParameters = tempParameters; tempCount = 0; tempVariables = undefined; tempParameters = undefined; - var popFrame = enterNameScope(); + let popFrame = enterNameScope(); // Check if we have property assignment inside class declaration. // If there is property assignment, we need to emit constructor whether users define it or not // If there is no property assignment, we can omit constructor if users do not define it - var hasPropertyAssignment = false; + let hasInstancePropertyWithInitializer = false; // Emit the constructor overload pinned comments forEach(node.members, member => { if (member.kind === SyntaxKind.Constructor && !(member).body) { emitPinnedOrTripleSlashComments(member); } - if (member.kind === SyntaxKind.PropertyDeclaration && (member).initializer) { - hasPropertyAssignment = true; + // Check if there is any non-static property assignment + if (member.kind === SyntaxKind.PropertyDeclaration && (member).initializer && (member.flags & NodeFlags.Static) === 0) { + hasInstancePropertyWithInitializer = true; } }); - var ctor = getFirstConstructorWithBody(node); + let ctor = getFirstConstructorWithBody(node); // For target ES6 and above, if there is no user-defined constructor and there is no property assignment // do not emit constructor in class declaration. - if (languageVersion >= ScriptTarget.ES6 && !ctor && !hasPropertyAssignment) { + if (languageVersion >= ScriptTarget.ES6 && !ctor && !hasInstancePropertyWithInitializer) { return; } if (ctor) { emitLeadingComments(ctor); } - emitStart(ctor || node); + emitStart(ctor || node); if (languageVersion < ScriptTarget.ES6) { write("function "); @@ -4639,7 +4626,7 @@ module ts { scopeEmitStart(node, "constructor"); increaseIndent(); if (ctor) { - emitDetachedComments((ctor.body).statements); + emitDetachedComments(ctor.body.statements); } emitCaptureThisForNodeIfNecessary(node); if (ctor) { @@ -4662,10 +4649,12 @@ module ts { emitEnd(baseTypeNode); } } - emitMemberAssignments(node, /*nonstatic*/0); + emitMemberAssignments(node, /*staticFlag*/0); if (ctor) { var statements: Node[] = (ctor.body).statements; - if (superCall) statements = statements.slice(1); + if (superCall) { + statements = statements.slice(1); + } emitLines(statements); } emitTempDeclarations(/*newLine*/ true); @@ -4696,6 +4685,7 @@ module ts { write("default "); } } + write("class "); emitDeclarationName(node); var baseTypeNode = getClassBaseTypeNode(node); diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 5a07b22153d6d..48ece8b1b791a 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4518,8 +4518,8 @@ module ts { function parseClassDeclaration(fullStart: number, modifiers: ModifiersArray): ClassDeclaration { // In ES6 specification, All parts of a ClassDeclaration or a ClassExpression are strict mode code + let savedStrictModeContext = inStrictModeContext(); if (languageVersion >= ScriptTarget.ES6) { - var savedStrictModeContext = inStrictModeContext(); setStrictModeContext(true); } @@ -4545,13 +4545,8 @@ module ts { } var finishedNode = finishNode(node); - if (languageVersion >= ScriptTarget.ES6) { - setStrictModeContext(savedStrictModeContext); - return finishedNode; - } - else { - return finishedNode; - } + setStrictModeContext(savedStrictModeContext); + return finishedNode; } function parseHeritageClauses(isClassHeritageClause: boolean): NodeArray { diff --git a/tests/baselines/reference/computedPropertyNamesWithStaticProperty.errors.txt b/tests/baselines/reference/computedPropertyNamesWithStaticProperty.errors.txt deleted file mode 100644 index f078365f60062..0000000000000 --- a/tests/baselines/reference/computedPropertyNamesWithStaticProperty.errors.txt +++ /dev/null @@ -1,22 +0,0 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNamesWithStaticProperty.ts(3,9): error TS1200: A computed property name cannot reference a static property -tests/cases/conformance/es6/computedProperties/computedPropertyNamesWithStaticProperty.ts(6,9): error TS1200: A computed property name cannot reference a static property -tests/cases/conformance/es6/computedProperties/computedPropertyNamesWithStaticProperty.ts(9,5): error TS1200: A computed property name cannot reference a static property - - -==== tests/cases/conformance/es6/computedProperties/computedPropertyNamesWithStaticProperty.ts (3 errors) ==== - class C { - static staticProp = 10; - get [C.staticProp]() { - ~~~~~~~~~~~~~~ -!!! error TS1200: A computed property name cannot reference a static property - return "hello"; - } - set [C.staticProp](x: string) { - ~~~~~~~~~~~~~~ -!!! error TS1200: A computed property name cannot reference a static property - var y = x; - } - [C.staticProp]() { } - ~~~~~~~~~~~~~~ -!!! error TS1200: A computed property name cannot reference a static property - } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNamesWithStaticProperty.types b/tests/baselines/reference/computedPropertyNamesWithStaticProperty.types new file mode 100644 index 0000000000000..b23d986f89450 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesWithStaticProperty.types @@ -0,0 +1,29 @@ +=== tests/cases/conformance/es6/computedProperties/computedPropertyNamesWithStaticProperty.ts === +class C { +>C : C + + static staticProp = 10; +>staticProp : number + + get [C.staticProp]() { +>C.staticProp : number +>C : typeof C +>staticProp : number + + return "hello"; + } + set [C.staticProp](x: string) { +>C.staticProp : number +>C : typeof C +>staticProp : number +>x : string + + var y = x; +>y : string +>x : string + } + [C.staticProp]() { } +>C.staticProp : number +>C : typeof C +>staticProp : number +} diff --git a/tests/baselines/reference/properties.js.map b/tests/baselines/reference/properties.js.map index e55d29427348e..6e68d36e346f9 100644 --- a/tests/baselines/reference/properties.js.map +++ b/tests/baselines/reference/properties.js.map @@ -1,2 +1,2 @@ //// [properties.js.map] -{"version":3,"file":"properties.js","sourceRoot":"","sources":["properties.ts"],"names":["MyClass","MyClass.constructor","MyClass.Count"],"mappings":"AACA;IAAAA;IAWAC,CAACA;IATcD,gDAAKA;aAAhBA;YAEIE,MAAMA,CAACA,EAAEA,CAACA;QACdA,CAACA;aAEDF,UAAiBA,KAAaA;YAE1BE,EAAEA;QACNA,CAACA;;;OALAF;IAMLA,cAACA;AAADA,CAACA,AAXD,IAWC"} \ No newline at end of file +{"version":3,"file":"properties.js","sourceRoot":"","sources":["properties.ts"],"names":["MyClass","MyClass.constructor","MyClass.Count"],"mappings":"AACA;IAAAA;IAWAC,CAACA;IATGD,sBAAWA,0BAAKA;aAAhBA;YAEIE,MAAMA,CAACA,EAAEA,CAACA;QACdA,CAACA;aAEDF,UAAiBA,KAAaA;YAE1BE,EAAEA;QACNA,CAACA;;;OALAF;IAMLA,cAACA;AAADA,CAACA,AAXD,IAWC"} \ No newline at end of file diff --git a/tests/baselines/reference/properties.sourcemap.txt b/tests/baselines/reference/properties.sourcemap.txt index caf72da0b7b1b..9ff77cc2c5d80 100644 --- a/tests/baselines/reference/properties.sourcemap.txt +++ b/tests/baselines/reference/properties.sourcemap.txt @@ -43,11 +43,14 @@ sourceFile:properties.ts --- >>> Object.defineProperty(MyClass.prototype, "Count", { 1->^^^^ -2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +2 > ^^^^^^^^^^^^^^^^^^^^^^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^ 1-> -2 > Count -1->Emitted(4, 5) Source(4, 16) + SourceIndex(0) name (MyClass) -2 >Emitted(4, 53) Source(4, 21) + SourceIndex(0) name (MyClass) +2 > public get +3 > Count +1->Emitted(4, 5) Source(4, 5) + SourceIndex(0) name (MyClass) +2 >Emitted(4, 27) Source(4, 16) + SourceIndex(0) name (MyClass) +3 >Emitted(4, 53) Source(4, 21) + SourceIndex(0) name (MyClass) --- >>> get: function () { 1 >^^^^^^^^^^^^^ diff --git a/tests/baselines/reference/sourceMapValidationClass.js.map b/tests/baselines/reference/sourceMapValidationClass.js.map index 79ae9de95eed4..8693cf5d0fe67 100644 --- a/tests/baselines/reference/sourceMapValidationClass.js.map +++ b/tests/baselines/reference/sourceMapValidationClass.js.map @@ -1,2 +1,2 @@ //// [sourceMapValidationClass.js.map] -{"version":3,"file":"sourceMapValidationClass.js","sourceRoot":"","sources":["sourceMapValidationClass.ts"],"names":["Greeter","Greeter.constructor","Greeter.greet","Greeter.fn","Greeter.greetings"],"mappings":"AAAA;IACIA,iBAAmBA,QAAgBA;QAAEC,WAAcA;aAAdA,WAAcA,CAAdA,sBAAcA,CAAdA,IAAcA;YAAdA,0BAAcA;;QAAhCA,aAAQA,GAARA,QAAQA,CAAQA;QAM3BA,OAAEA,GAAWA,EAAEA,CAACA;IALxBA,CAACA;IACDD,uBAAKA,GAALA;QACIE,MAAMA,CAACA,MAAMA,GAAGA,IAAIA,CAACA,QAAQA,GAAGA,OAAOA,CAACA;IAC5CA,CAACA;IAGOF,oBAAEA,GAAVA;QACIG,MAAMA,CAACA,IAAIA,CAACA,QAAQA,CAACA;IACzBA,CAACA;IACGH,oDAASA;aAAbA;YACII,MAAMA,CAACA,IAAIA,CAACA,QAAQA,CAACA;QACzBA,CAACA;aACDJ,UAAcA,SAAiBA;YAC3BI,IAAIA,CAACA,QAAQA,GAAGA,SAASA,CAACA;QAC9BA,CAACA;;;OAHAJ;IAILA,cAACA;AAADA,CAACA,AAjBD,IAiBC"} \ No newline at end of file +{"version":3,"file":"sourceMapValidationClass.js","sourceRoot":"","sources":["sourceMapValidationClass.ts"],"names":["Greeter","Greeter.constructor","Greeter.greet","Greeter.fn","Greeter.greetings"],"mappings":"AAAA;IACIA,iBAAmBA,QAAgBA;QAAEC,WAAcA;aAAdA,WAAcA,CAAdA,sBAAcA,CAAdA,IAAcA;YAAdA,0BAAcA;;QAAhCA,aAAQA,GAARA,QAAQA,CAAQA;QAM3BA,OAAEA,GAAWA,EAAEA,CAACA;IALxBA,CAACA;IACDD,uBAAKA,GAALA;QACIE,MAAMA,CAACA,MAAMA,GAAGA,IAAIA,CAACA,QAAQA,GAAGA,OAAOA,CAACA;IAC5CA,CAACA;IAGOF,oBAAEA,GAAVA;QACIG,MAAMA,CAACA,IAAIA,CAACA,QAAQA,CAACA;IACzBA,CAACA;IACDH,sBAAIA,8BAASA;aAAbA;YACII,MAAMA,CAACA,IAAIA,CAACA,QAAQA,CAACA;QACzBA,CAACA;aACDJ,UAAcA,SAAiBA;YAC3BI,IAAIA,CAACA,QAAQA,GAAGA,SAASA,CAACA;QAC9BA,CAACA;;;OAHAJ;IAILA,cAACA;AAADA,CAACA,AAjBD,IAiBC"} \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationClass.sourcemap.txt b/tests/baselines/reference/sourceMapValidationClass.sourcemap.txt index d4c4e0ed365c9..0e019b487bbca 100644 --- a/tests/baselines/reference/sourceMapValidationClass.sourcemap.txt +++ b/tests/baselines/reference/sourceMapValidationClass.sourcemap.txt @@ -223,12 +223,15 @@ sourceFile:sourceMapValidationClass.ts --- >>> Object.defineProperty(Greeter.prototype, "greetings", { 1->^^^^ -2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +2 > ^^^^^^^^^^^^^^^^^^^^^^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1-> - > get -2 > greetings -1->Emitted(16, 5) Source(12, 9) + SourceIndex(0) name (Greeter) -2 >Emitted(16, 57) Source(12, 18) + SourceIndex(0) name (Greeter) + > +2 > get +3 > greetings +1->Emitted(16, 5) Source(12, 5) + SourceIndex(0) name (Greeter) +2 >Emitted(16, 27) Source(12, 9) + SourceIndex(0) name (Greeter) +3 >Emitted(16, 57) Source(12, 18) + SourceIndex(0) name (Greeter) --- >>> get: function () { 1 >^^^^^^^^^^^^^ From 91c5bae6e5b86834b9dd88f7777ec4e5ddde971d Mon Sep 17 00:00:00 2001 From: Yui T Date: Mon, 16 Mar 2015 15:41:51 -0700 Subject: [PATCH 091/224] Address code review --- src/compiler/emitter.ts | 42 ++++--------------- ...itClassDeclarationWithGetterSetterInES6.js | 21 ++++++++++ ...lassDeclarationWithGetterSetterInES6.types | 13 ++++++ ...DeclarationWithLiteralPropertyNameInES6.js | 37 ++++++++++++++++ ...larationWithLiteralPropertyNameInES6.types | 19 +++++++++ ...itClassDeclarationWithThisKeywordInES6.js} | 4 +- ...lassDeclarationWithThisKeywordInES6.types} | 2 +- ...rationWithTypeArgumentAndOverloadInES6.js} | 4 +- ...ionWithTypeArgumentAndOverloadInES6.types} | 2 +- tests/baselines/reference/symbolProperty44.js | 3 ++ ...itClassDeclarationWithGetterSetterInES6.ts | 11 +++++ ...DeclarationWithLiteralPropertyNameInES6.ts | 15 +++++++ ...itClassDeclarationWithThisKeywordInES6.ts} | 0 ...rationWithTypeArgumentAndOverloadInES6.ts} | 0 14 files changed, 134 insertions(+), 39 deletions(-) create mode 100644 tests/baselines/reference/emitClassDeclarationWithLiteralPropertyNameInES6.js create mode 100644 tests/baselines/reference/emitClassDeclarationWithLiteralPropertyNameInES6.types rename tests/baselines/reference/{emitClassDeclarationWithThisKeyword.js => emitClassDeclarationWithThisKeywordInES6.js} (79%) rename tests/baselines/reference/{emitClassDeclarationWithThisKeyword.types => emitClassDeclarationWithThisKeywordInES6.types} (89%) rename tests/baselines/reference/{emitClassDeclarationWithTypeArgumentAndOverload.js => emitClassDeclarationWithTypeArgumentAndOverloadInES6.js} (77%) rename tests/baselines/reference/{emitClassDeclarationWithTypeArgumentAndOverload.types => emitClassDeclarationWithTypeArgumentAndOverloadInES6.types} (88%) create mode 100644 tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithLiteralPropertyNameInES6.ts rename tests/cases/conformance/es6/classDeclaration/{emitClassDeclarationWithThisKeyword.ts => emitClassDeclarationWithThisKeywordInES6.ts} (100%) rename tests/cases/conformance/es6/classDeclaration/{emitClassDeclarationWithTypeArgumentAndOverload.ts => emitClassDeclarationWithTypeArgumentAndOverloadInES6.ts} (100%) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 8e53b3e96c475..fbaaf2493c701 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4511,50 +4511,26 @@ module ts { return emitPinnedOrTripleSlashComments(member); } + } + if (member.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature || member.kind === SyntaxKind.GetAccessor || member.kind === SyntaxKind.SetAccessor) { writeLine(); emitLeadingComments(member); emitStart(member); if (member.flags & NodeFlags.Static) { write("static "); } + + if (member.kind === SyntaxKind.GetAccessor) { + write("get "); + } + else if (member.kind === SyntaxKind.SetAccessor) { + write("set "); + } emit((member).name); emitSignatureAndBody(member); emitEnd(member); emitTrailingComments(member); } - else if (member.kind === SyntaxKind.GetAccessor || member.kind === SyntaxKind.SetAccessor) { - var accessors = getAllAccessorDeclarations(node.members, member); - if (member === accessors.firstAccessor) { - writeLine(); - if (accessors.getAccessor) { - writeLine(); - emitLeadingComments(accessors.getAccessor); - emitStart(accessors.getAccessor); - if (member.flags & NodeFlags.Static) { - write("static "); - } - write("get "); - emit((member).name); - emitSignatureAndBody(accessors.getAccessor); - emitEnd(accessors.getAccessor); - emitTrailingComments(accessors.getAccessor); - } - if (accessors.setAccessor) { - // We will only write new line if we just emit getAccessor - writeLine(); - emitLeadingComments(accessors.setAccessor); - emitStart(accessors.setAccessor); - if (member.flags & NodeFlags.Static) { - write("static "); - } - write("set "); - emit((member).name); - emitSignatureAndBody(accessors.setAccessor); - emitEnd(accessors.setAccessor); - emitTrailingComments(accessors.setAccessor);; - } - } - } }); } diff --git a/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.js b/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.js index 55d72a8b8d522..68ccd1568edd7 100644 --- a/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.js +++ b/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.js @@ -10,6 +10,17 @@ class C { static get ["computedname"]() { return ""; } + get ["computedname"]() { + return ""; + } + get ["computedname"]() { + return ""; + } + + set ["computedname"](x: any) { + } + set ["computedname"](y: string) { + } set foo(a: string) { } static set bar(b: number) { } @@ -27,6 +38,16 @@ class C { static get ["computedname"]() { return ""; } + get ["computedname"]() { + return ""; + } + get ["computedname"]() { + return ""; + } + set ["computedname"](x) { + } + set ["computedname"](y) { + } set foo(a) { } static set bar(b) { diff --git a/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.types b/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.types index 4e4673a228f97..83d4fcd0d802f 100644 --- a/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.types +++ b/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.types @@ -21,6 +21,19 @@ class C { static get ["computedname"]() { return ""; } + get ["computedname"]() { + return ""; + } + get ["computedname"]() { + return ""; + } + + set ["computedname"](x: any) { +>x : any + } + set ["computedname"](y: string) { +>y : string + } set foo(a: string) { } >foo : string diff --git a/tests/baselines/reference/emitClassDeclarationWithLiteralPropertyNameInES6.js b/tests/baselines/reference/emitClassDeclarationWithLiteralPropertyNameInES6.js new file mode 100644 index 0000000000000..d82750f276fcc --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithLiteralPropertyNameInES6.js @@ -0,0 +1,37 @@ +//// [emitClassDeclarationWithLiteralPropertyNameInES6.ts] +class B { + "hello" = 10; + 0b110 = "world"; + 0o23534 = "WORLD"; + 20 = "twenty"; + "foo"() { } + 0b1110() {} + 11() { } + interface() { } + static "hi" = 10000; + static 22 = "twenty-two"; + static 0b101 = "binary"; + static 0o3235 = "octal"; +} + +//// [emitClassDeclarationWithLiteralPropertyNameInES6.js] +class B { + constructor() { + this["hello"] = 10; + this[0b110] = "world"; + this[0o23534] = "WORLD"; + this[20] = "twenty"; + } + "foo"() { + } + 0b1110() { + } + 11() { + } + interface() { + } +} +B["hi"] = 10000; +B[22] = "twenty-two"; +B[0b101] = "binary"; +B[0o3235] = "octal"; diff --git a/tests/baselines/reference/emitClassDeclarationWithLiteralPropertyNameInES6.types b/tests/baselines/reference/emitClassDeclarationWithLiteralPropertyNameInES6.types new file mode 100644 index 0000000000000..65ba8f7d2b9b0 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithLiteralPropertyNameInES6.types @@ -0,0 +1,19 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithLiteralPropertyNameInES6.ts === +class B { +>B : B + + "hello" = 10; + 0b110 = "world"; + 0o23534 = "WORLD"; + 20 = "twenty"; + "foo"() { } + 0b1110() {} + 11() { } + interface() { } +>interface : () => void + + static "hi" = 10000; + static 22 = "twenty-two"; + static 0b101 = "binary"; + static 0o3235 = "octal"; +} diff --git a/tests/baselines/reference/emitClassDeclarationWithThisKeyword.js b/tests/baselines/reference/emitClassDeclarationWithThisKeywordInES6.js similarity index 79% rename from tests/baselines/reference/emitClassDeclarationWithThisKeyword.js rename to tests/baselines/reference/emitClassDeclarationWithThisKeywordInES6.js index de100457aa954..14f74682c008d 100644 --- a/tests/baselines/reference/emitClassDeclarationWithThisKeyword.js +++ b/tests/baselines/reference/emitClassDeclarationWithThisKeywordInES6.js @@ -1,4 +1,4 @@ -//// [emitClassDeclarationWithThisKeyword.ts] +//// [emitClassDeclarationWithThisKeywordInES6.ts] class B { x = 10; constructor() { @@ -18,7 +18,7 @@ class B { } } -//// [emitClassDeclarationWithThisKeyword.js] +//// [emitClassDeclarationWithThisKeywordInES6.js] class B { constructor() { this.x = 10; diff --git a/tests/baselines/reference/emitClassDeclarationWithThisKeyword.types b/tests/baselines/reference/emitClassDeclarationWithThisKeywordInES6.types similarity index 89% rename from tests/baselines/reference/emitClassDeclarationWithThisKeyword.types rename to tests/baselines/reference/emitClassDeclarationWithThisKeywordInES6.types index ebb6f26598d1c..bb0f7e9993977 100644 --- a/tests/baselines/reference/emitClassDeclarationWithThisKeyword.types +++ b/tests/baselines/reference/emitClassDeclarationWithThisKeywordInES6.types @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithThisKeyword.ts === +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithThisKeywordInES6.ts === class B { >B : B diff --git a/tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverload.js b/tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverloadInES6.js similarity index 77% rename from tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverload.js rename to tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverloadInES6.js index 69801d6be122e..8dc5b6cddaabc 100644 --- a/tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverload.js +++ b/tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverloadInES6.js @@ -1,4 +1,4 @@ -//// [emitClassDeclarationWithTypeArgumentAndOverload.ts] +//// [emitClassDeclarationWithTypeArgumentAndOverloadInES6.ts] class B { x: T; B: T; @@ -22,7 +22,7 @@ class B { } } -//// [emitClassDeclarationWithTypeArgumentAndOverload.js] +//// [emitClassDeclarationWithTypeArgumentAndOverloadInES6.js] class B { constructor(a) { this.B = a; diff --git a/tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverload.types b/tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverloadInES6.types similarity index 88% rename from tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverload.types rename to tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverloadInES6.types index 8b0feb72d2b53..ba515168a5d7d 100644 --- a/tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverload.types +++ b/tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverloadInES6.types @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithTypeArgumentAndOverload.ts === +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithTypeArgumentAndOverloadInES6.ts === class B { >B : B >T : T diff --git a/tests/baselines/reference/symbolProperty44.js b/tests/baselines/reference/symbolProperty44.js index a3de33640af56..1f4aaf73b3c20 100644 --- a/tests/baselines/reference/symbolProperty44.js +++ b/tests/baselines/reference/symbolProperty44.js @@ -13,4 +13,7 @@ class C { get [Symbol.hasInstance]() { return ""; } + get [Symbol.hasInstance]() { + return ""; + } } diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithGetterSetterInES6.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithGetterSetterInES6.ts index 18ff3fa424de7..70c0b35763e9b 100644 --- a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithGetterSetterInES6.ts +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithGetterSetterInES6.ts @@ -10,6 +10,17 @@ class C { static get ["computedname"]() { return ""; } + get ["computedname"]() { + return ""; + } + get ["computedname"]() { + return ""; + } + + set ["computedname"](x: any) { + } + set ["computedname"](y: string) { + } set foo(a: string) { } static set bar(b: number) { } diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithLiteralPropertyNameInES6.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithLiteralPropertyNameInES6.ts new file mode 100644 index 0000000000000..87114db77392e --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithLiteralPropertyNameInES6.ts @@ -0,0 +1,15 @@ +// @target: es6 +class B { + "hello" = 10; + 0b110 = "world"; + 0o23534 = "WORLD"; + 20 = "twenty"; + "foo"() { } + 0b1110() {} + 11() { } + interface() { } + static "hi" = 10000; + static 22 = "twenty-two"; + static 0b101 = "binary"; + static 0o3235 = "octal"; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithThisKeyword.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithThisKeywordInES6.ts similarity index 100% rename from tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithThisKeyword.ts rename to tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithThisKeywordInES6.ts diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithTypeArgumentAndOverload.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithTypeArgumentAndOverloadInES6.ts similarity index 100% rename from tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithTypeArgumentAndOverload.ts rename to tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithTypeArgumentAndOverloadInES6.ts From c51983df3cae44d239454f554a9d6758c6379e2a Mon Sep 17 00:00:00 2001 From: Yui T Date: Mon, 16 Mar 2015 15:48:03 -0700 Subject: [PATCH 092/224] Address code review --- src/compiler/emitter.ts | 4 +--- tests/cases/unittests/incrementalParser.ts | 2 -- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index fbaaf2493c701..196aeabe6385d 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3189,9 +3189,7 @@ module ts { } else { write("("); - if (node.arguments.length) { - emitCommaList(node.arguments); - } + emitCommaList(node.arguments); write(")"); } } diff --git a/tests/cases/unittests/incrementalParser.ts b/tests/cases/unittests/incrementalParser.ts index 87c0c3701f388..422675e9e0afb 100644 --- a/tests/cases/unittests/incrementalParser.ts +++ b/tests/cases/unittests/incrementalParser.ts @@ -686,7 +686,6 @@ module m3 { }\ }); it('Surrounding function declarations with block',() => { - debugger; var source = "declare function F1() { } export function F2() { } declare export function F3() { }" var oldText = ScriptSnapshot.fromString(source); @@ -723,7 +722,6 @@ module m3 { }\ }); it('Moving methods from object literal to class in strict mode', () => { - debugger; var source = "\"use strict\"; var v = { public A() { } public B() { } public C() { } }" var oldText = ScriptSnapshot.fromString(source); From 9b3fccd5c4885fc88e40a14fac6fa761a8739cff Mon Sep 17 00:00:00 2001 From: Yui T Date: Mon, 16 Mar 2015 16:24:40 -0700 Subject: [PATCH 093/224] Address code review; Use for..of and use if-statement --- src/compiler/emitter.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 522679adb0a46..4cae7d0749cc2 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4706,14 +4706,11 @@ module ts { } function emitMemberFunctionsForES6AndHigher(node: ClassDeclaration) { - forEach(node.members, member => { - if (member.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature) { - if (!(member).body) { - return emitPinnedOrTripleSlashComments(member); - } - + for (let member of node.members) { + if ((member.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature) && !(member).body) { + emitPinnedOrTripleSlashComments(member); } - if (member.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature || member.kind === SyntaxKind.GetAccessor || member.kind === SyntaxKind.SetAccessor) { + else if (member.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature || member.kind === SyntaxKind.GetAccessor || member.kind === SyntaxKind.SetAccessor) { writeLine(); emitLeadingComments(member); emitStart(member); @@ -4732,7 +4729,7 @@ module ts { emitEnd(member); emitTrailingComments(member); } - }); + } } function emitConstructor(node: ClassDeclaration, baseTypeNode: TypeReferenceNode) { @@ -4822,7 +4819,12 @@ module ts { if (baseTypeNode) { writeLine(); emitStart(baseTypeNode); - languageVersion < ScriptTarget.ES6 ? write("_super.apply(this, arguments);") : write("super(...args);"); + if (languageVersion < ScriptTarget.ES6) { + write("_super.apply(this, arguments);"); + } + else { + write("super(...args);"); + } emitEnd(baseTypeNode); } } From 218736b23fed0ad5e573d0e39f8f0e4ea3349c14 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 16 Mar 2015 18:54:13 -0700 Subject: [PATCH 094/224] initial version of declaration emit for default export --- src/compiler/checker.ts | 6 +++++ .../diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 4 ++++ src/compiler/emitter.ts | 22 +++++++++++++++---- src/compiler/types.ts | 1 + .../baselines/reference/APISample_compile.js | 1 + .../reference/APISample_compile.types | 11 ++++++++++ tests/baselines/reference/APISample_linter.js | 1 + .../reference/APISample_linter.types | 11 ++++++++++ .../reference/APISample_transform.js | 1 + .../reference/APISample_transform.types | 11 ++++++++++ .../baselines/reference/APISample_watcher.js | 1 + .../reference/APISample_watcher.types | 11 ++++++++++ .../declarationEmitDefaultExport1.errors.txt | 8 +++++++ .../declarationEmitDefaultExport1.js | 16 ++++++++++++++ .../declarationEmitDefaultExport2.errors.txt | 8 +++++++ .../declarationEmitDefaultExport2.js | 16 ++++++++++++++ .../declarationEmitDefaultExport3.errors.txt | 9 ++++++++ .../declarationEmitDefaultExport3.js | 14 ++++++++++++ .../declarationEmitDefaultExport4.errors.txt | 9 ++++++++ .../declarationEmitDefaultExport4.js | 14 ++++++++++++ .../declarationEmitDefaultExport5.errors.txt | 8 +++++++ .../declarationEmitDefaultExport5.js | 10 +++++++++ .../declarationEmitDefaultExport6.errors.txt | 12 ++++++++++ .../declarationEmitDefaultExport6.js | 19 ++++++++++++++++ .../declarationEmitDefaultExport7.errors.txt | 12 ++++++++++ .../declarationEmitDefaultExport7.js | 12 ++++++++++ .../compiler/declarationEmitDefaultExport1.ts | 4 ++++ .../compiler/declarationEmitDefaultExport2.ts | 4 ++++ .../compiler/declarationEmitDefaultExport3.ts | 5 +++++ .../compiler/declarationEmitDefaultExport4.ts | 5 +++++ .../compiler/declarationEmitDefaultExport5.ts | 3 +++ .../compiler/declarationEmitDefaultExport6.ts | 4 ++++ .../compiler/declarationEmitDefaultExport7.ts | 4 ++++ 34 files changed, 274 insertions(+), 4 deletions(-) create mode 100644 tests/baselines/reference/declarationEmitDefaultExport1.errors.txt create mode 100644 tests/baselines/reference/declarationEmitDefaultExport1.js create mode 100644 tests/baselines/reference/declarationEmitDefaultExport2.errors.txt create mode 100644 tests/baselines/reference/declarationEmitDefaultExport2.js create mode 100644 tests/baselines/reference/declarationEmitDefaultExport3.errors.txt create mode 100644 tests/baselines/reference/declarationEmitDefaultExport3.js create mode 100644 tests/baselines/reference/declarationEmitDefaultExport4.errors.txt create mode 100644 tests/baselines/reference/declarationEmitDefaultExport4.js create mode 100644 tests/baselines/reference/declarationEmitDefaultExport5.errors.txt create mode 100644 tests/baselines/reference/declarationEmitDefaultExport5.js create mode 100644 tests/baselines/reference/declarationEmitDefaultExport6.errors.txt create mode 100644 tests/baselines/reference/declarationEmitDefaultExport6.js create mode 100644 tests/baselines/reference/declarationEmitDefaultExport7.errors.txt create mode 100644 tests/baselines/reference/declarationEmitDefaultExport7.js create mode 100644 tests/cases/compiler/declarationEmitDefaultExport1.ts create mode 100644 tests/cases/compiler/declarationEmitDefaultExport2.ts create mode 100644 tests/cases/compiler/declarationEmitDefaultExport3.ts create mode 100644 tests/cases/compiler/declarationEmitDefaultExport4.ts create mode 100644 tests/cases/compiler/declarationEmitDefaultExport5.ts create mode 100644 tests/cases/compiler/declarationEmitDefaultExport6.ts create mode 100644 tests/cases/compiler/declarationEmitDefaultExport7.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 28e45f92f8f7c..d95f790c8f599 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11157,6 +11157,11 @@ module ts { getSymbolDisplayBuilder().buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags); } + function writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter) { + var type = getTypeOfExpression(expr); + getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags); + } + function isUnknownIdentifier(location: Node, name: string): boolean { Debug.assert(!nodeIsSynthesized(location), "isUnknownIdentifier called with a synthesized location"); return !resolveName(location, name, SymbolFlags.Value, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined) && @@ -11200,6 +11205,7 @@ module ts { isImplementationOfOverload, writeTypeOfDeclaration, writeReturnTypeOfSignatureDeclaration, + writeTypeOfExpression, isSymbolAccessible, isEntityNameVisible, getConstantValue, diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 622b28d5f182d..506104ff3bcca 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -411,6 +411,7 @@ module ts { Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2: { code: 4077, category: DiagnosticCategory.Error, key: "Parameter '{0}' of exported function has or is using name '{1}' from private module '{2}'." }, Parameter_0_of_exported_function_has_or_is_using_private_name_1: { code: 4078, category: DiagnosticCategory.Error, key: "Parameter '{0}' of exported function has or is using private name '{1}'." }, Exported_type_alias_0_has_or_is_using_private_name_1: { code: 4081, category: DiagnosticCategory.Error, key: "Exported type alias '{0}' has or is using private name '{1}'." }, + Default_export_of_the_module_has_or_is_using_private_name_0: { code: 4081, category: DiagnosticCategory.Error, key: "Default export of the module has or is using private name '{0}'." }, Loop_contains_block_scoped_variable_0_referenced_by_a_function_in_the_loop_This_is_only_supported_in_ECMAScript_6_or_higher: { code: 4091, category: DiagnosticCategory.Error, key: "Loop contains block-scoped variable '{0}' referenced by a function in the loop. This is only supported in ECMAScript 6 or higher." }, The_current_host_does_not_support_the_0_option: { code: 5001, category: DiagnosticCategory.Error, key: "The current host does not support the '{0}' option." }, Cannot_find_the_common_subdirectory_path_for_the_input_files: { code: 5009, category: DiagnosticCategory.Error, key: "Cannot find the common subdirectory path for the input files." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 410cce54d173d..e2a89b91e33cf 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1637,6 +1637,10 @@ "category": "Error", "code": 4081 }, + "Default export of the module has or is using private name '{0}'.": { + "category": "Error", + "code": 4081 + }, "Loop contains block-scoped variable '{0}' referenced by a function in the loop. This is only supported in ECMAScript 6 or higher.": { "category": "Error", "code": 4091 diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 006b09892df12..6a4e945ffe769 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -751,7 +751,14 @@ module ts { function emitExportAssignment(node: ExportAssignment) { write(node.isExportEquals ? "export = " : "export default "); - writeTextOfNode(currentSourceFile, node.expression); + if (node.expression.kind === SyntaxKind.Identifier) { + writeTextOfNode(currentSourceFile, node.expression); + } + else { + write(": "); + writer.getSymbolAccessibilityDiagnostic = getDefaultExportAccessibilityDiagnostic; + resolver.writeTypeOfExpression(node.expression, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer); + } write(";"); writeLine(); @@ -762,8 +769,12 @@ module ts { // write each of these declarations asynchronously writeAsynchronousModuleElements(nodes); } - else { - Debug.fail("TODO(fixme)") + + function getDefaultExportAccessibilityDiagnostic(diagnostic: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { + return { + diagnosticMessage: Diagnostics.Default_export_of_the_module_has_or_is_using_private_name_0, + errorNode: node + }; } } @@ -839,7 +850,10 @@ module ts { write("export "); } - if (node.kind !== SyntaxKind.InterfaceDeclaration) { + if (node.flags & NodeFlags.Default) { + write("default "); + } + else if (node.kind !== SyntaxKind.InterfaceDeclaration) { write("declare "); } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 0cb8301be8a6a..675ccfbfc3922 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1214,6 +1214,7 @@ module ts { isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; + writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult; // Returns the constant value this property access resolves to, or 'undefined' for a non-constant diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index 246cf6569fcf9..ff68d4039f59a 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -949,6 +949,7 @@ declare module "typescript" { isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; + writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult; getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index 09f2e3223c474..fcccdc4dcd064 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -3071,6 +3071,17 @@ declare module "typescript" { >flags : TypeFormatFlags >TypeFormatFlags : TypeFormatFlags >writer : SymbolWriter +>SymbolWriter : SymbolWriter + + writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; +>writeTypeOfExpression : (expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter) => void +>expr : Expression +>Expression : Expression +>enclosingDeclaration : Node +>Node : Node +>flags : TypeFormatFlags +>TypeFormatFlags : TypeFormatFlags +>writer : SymbolWriter >SymbolWriter : SymbolWriter isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index adb7b56816357..1fb0e1d8407d1 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -980,6 +980,7 @@ declare module "typescript" { isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; + writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult; getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index 5c182d7e6ba7d..a13ce915920fb 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -3217,6 +3217,17 @@ declare module "typescript" { >flags : TypeFormatFlags >TypeFormatFlags : TypeFormatFlags >writer : SymbolWriter +>SymbolWriter : SymbolWriter + + writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; +>writeTypeOfExpression : (expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter) => void +>expr : Expression +>Expression : Expression +>enclosingDeclaration : Node +>Node : Node +>flags : TypeFormatFlags +>TypeFormatFlags : TypeFormatFlags +>writer : SymbolWriter >SymbolWriter : SymbolWriter isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index 080fec98e2f3b..07f7519d721ad 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -981,6 +981,7 @@ declare module "typescript" { isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; + writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult; getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index be2c226b8d08c..87ed0c073f28b 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -3167,6 +3167,17 @@ declare module "typescript" { >flags : TypeFormatFlags >TypeFormatFlags : TypeFormatFlags >writer : SymbolWriter +>SymbolWriter : SymbolWriter + + writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; +>writeTypeOfExpression : (expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter) => void +>expr : Expression +>Expression : Expression +>enclosingDeclaration : Node +>Node : Node +>flags : TypeFormatFlags +>TypeFormatFlags : TypeFormatFlags +>writer : SymbolWriter >SymbolWriter : SymbolWriter isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index 8061ff0d424ec..2eb306fd0490d 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -1018,6 +1018,7 @@ declare module "typescript" { isImplementationOfOverload(node: FunctionLikeDeclaration): boolean; writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; + writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult; getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index 7fa6478844d44..9b947a91d9a01 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -3340,6 +3340,17 @@ declare module "typescript" { >flags : TypeFormatFlags >TypeFormatFlags : TypeFormatFlags >writer : SymbolWriter +>SymbolWriter : SymbolWriter + + writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void; +>writeTypeOfExpression : (expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter) => void +>expr : Expression +>Expression : Expression +>enclosingDeclaration : Node +>Node : Node +>flags : TypeFormatFlags +>TypeFormatFlags : TypeFormatFlags +>writer : SymbolWriter >SymbolWriter : SymbolWriter isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessiblityResult; diff --git a/tests/baselines/reference/declarationEmitDefaultExport1.errors.txt b/tests/baselines/reference/declarationEmitDefaultExport1.errors.txt new file mode 100644 index 0000000000000..bf52e453002e7 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport1.errors.txt @@ -0,0 +1,8 @@ +tests/cases/compiler/declarationEmitDefaultExport1.ts(1,22): error TS1148: Cannot compile external modules unless the '--module' flag is provided. + + +==== tests/cases/compiler/declarationEmitDefaultExport1.ts (1 errors) ==== + export default class C { + ~ +!!! error TS1148: Cannot compile external modules unless the '--module' flag is provided. + } \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDefaultExport1.js b/tests/baselines/reference/declarationEmitDefaultExport1.js new file mode 100644 index 0000000000000..72c65b4576ccf --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport1.js @@ -0,0 +1,16 @@ +//// [declarationEmitDefaultExport1.ts] +export default class C { +} + +//// [declarationEmitDefaultExport1.js] +var C = (function () { + function C() { + } + return C; +})(); +module.exports = C; + + +//// [declarationEmitDefaultExport1.d.ts] +export default class C { +} diff --git a/tests/baselines/reference/declarationEmitDefaultExport2.errors.txt b/tests/baselines/reference/declarationEmitDefaultExport2.errors.txt new file mode 100644 index 0000000000000..95b7ace24d1e0 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport2.errors.txt @@ -0,0 +1,8 @@ +tests/cases/compiler/declarationEmitDefaultExport2.ts(1,1): error TS1148: Cannot compile external modules unless the '--module' flag is provided. + + +==== tests/cases/compiler/declarationEmitDefaultExport2.ts (1 errors) ==== + export default class { + ~~~~~~ +!!! error TS1148: Cannot compile external modules unless the '--module' flag is provided. + } \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDefaultExport2.js b/tests/baselines/reference/declarationEmitDefaultExport2.js new file mode 100644 index 0000000000000..c1841deefad21 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport2.js @@ -0,0 +1,16 @@ +//// [declarationEmitDefaultExport2.ts] +export default class { +} + +//// [declarationEmitDefaultExport2.js] +var _default = (function () { + function _default() { + } + return _default; +})(); +module.exports = _default; + + +//// [declarationEmitDefaultExport2.d.ts] +export default class { +} diff --git a/tests/baselines/reference/declarationEmitDefaultExport3.errors.txt b/tests/baselines/reference/declarationEmitDefaultExport3.errors.txt new file mode 100644 index 0000000000000..b6f8552265123 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport3.errors.txt @@ -0,0 +1,9 @@ +tests/cases/compiler/declarationEmitDefaultExport3.ts(1,25): error TS1148: Cannot compile external modules unless the '--module' flag is provided. + + +==== tests/cases/compiler/declarationEmitDefaultExport3.ts (1 errors) ==== + export default function foo() { + ~~~ +!!! error TS1148: Cannot compile external modules unless the '--module' flag is provided. + return "" + } \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDefaultExport3.js b/tests/baselines/reference/declarationEmitDefaultExport3.js new file mode 100644 index 0000000000000..4cc84d09fc6e3 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport3.js @@ -0,0 +1,14 @@ +//// [declarationEmitDefaultExport3.ts] +export default function foo() { + return "" +} + +//// [declarationEmitDefaultExport3.js] +function foo() { + return ""; +} +module.exports = foo; + + +//// [declarationEmitDefaultExport3.d.ts] +export default function foo(): string; diff --git a/tests/baselines/reference/declarationEmitDefaultExport4.errors.txt b/tests/baselines/reference/declarationEmitDefaultExport4.errors.txt new file mode 100644 index 0000000000000..dbd0c8b139fb8 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport4.errors.txt @@ -0,0 +1,9 @@ +tests/cases/compiler/declarationEmitDefaultExport4.ts(1,1): error TS1148: Cannot compile external modules unless the '--module' flag is provided. + + +==== tests/cases/compiler/declarationEmitDefaultExport4.ts (1 errors) ==== + export default function () { + ~~~~~~ +!!! error TS1148: Cannot compile external modules unless the '--module' flag is provided. + return 1; + } \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDefaultExport4.js b/tests/baselines/reference/declarationEmitDefaultExport4.js new file mode 100644 index 0000000000000..0913a047afafd --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport4.js @@ -0,0 +1,14 @@ +//// [declarationEmitDefaultExport4.ts] +export default function () { + return 1; +} + +//// [declarationEmitDefaultExport4.js] +function _default() { + return 1; +} +module.exports = _default; + + +//// [declarationEmitDefaultExport4.d.ts] +export default function (): number; diff --git a/tests/baselines/reference/declarationEmitDefaultExport5.errors.txt b/tests/baselines/reference/declarationEmitDefaultExport5.errors.txt new file mode 100644 index 0000000000000..79307703deef1 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport5.errors.txt @@ -0,0 +1,8 @@ +tests/cases/compiler/declarationEmitDefaultExport5.ts(1,1): error TS1148: Cannot compile external modules unless the '--module' flag is provided. + + +==== tests/cases/compiler/declarationEmitDefaultExport5.ts (1 errors) ==== + export default 1 + 2; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1148: Cannot compile external modules unless the '--module' flag is provided. + \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDefaultExport5.js b/tests/baselines/reference/declarationEmitDefaultExport5.js new file mode 100644 index 0000000000000..435ffc3bfda4b --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport5.js @@ -0,0 +1,10 @@ +//// [declarationEmitDefaultExport5.ts] +export default 1 + 2; + + +//// [declarationEmitDefaultExport5.js] +module.exports = 1 + 2; + + +//// [declarationEmitDefaultExport5.d.ts] +export default : number; diff --git a/tests/baselines/reference/declarationEmitDefaultExport6.errors.txt b/tests/baselines/reference/declarationEmitDefaultExport6.errors.txt new file mode 100644 index 0000000000000..f0d6a7a6c2ac2 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport6.errors.txt @@ -0,0 +1,12 @@ +tests/cases/compiler/declarationEmitDefaultExport6.ts(1,14): error TS1148: Cannot compile external modules unless the '--module' flag is provided. +tests/cases/compiler/declarationEmitDefaultExport6.ts(2,1): error TS2309: An export assignment cannot be used in a module with other exported elements. + + +==== tests/cases/compiler/declarationEmitDefaultExport6.ts (2 errors) ==== + export class A {} + ~ +!!! error TS1148: Cannot compile external modules unless the '--module' flag is provided. + export default new A(); + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2309: An export assignment cannot be used in a module with other exported elements. + \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDefaultExport6.js b/tests/baselines/reference/declarationEmitDefaultExport6.js new file mode 100644 index 0000000000000..b78706efdc12a --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport6.js @@ -0,0 +1,19 @@ +//// [declarationEmitDefaultExport6.ts] +export class A {} +export default new A(); + + +//// [declarationEmitDefaultExport6.js] +var A = (function () { + function A() { + } + return A; +})(); +exports.A = A; +module.exports = new A(); + + +//// [declarationEmitDefaultExport6.d.ts] +export declare class A { +} +export default : A; diff --git a/tests/baselines/reference/declarationEmitDefaultExport7.errors.txt b/tests/baselines/reference/declarationEmitDefaultExport7.errors.txt new file mode 100644 index 0000000000000..3e67b0856fc66 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport7.errors.txt @@ -0,0 +1,12 @@ +tests/cases/compiler/declarationEmitDefaultExport7.ts(2,1): error TS1148: Cannot compile external modules unless the '--module' flag is provided. +tests/cases/compiler/declarationEmitDefaultExport7.ts(2,1): error TS4081: Default export of the module has or is using private name 'A'. + + +==== tests/cases/compiler/declarationEmitDefaultExport7.ts (2 errors) ==== + class A {} + export default new A(); + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1148: Cannot compile external modules unless the '--module' flag is provided. + ~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS4081: Default export of the module has or is using private name 'A'. + \ No newline at end of file diff --git a/tests/baselines/reference/declarationEmitDefaultExport7.js b/tests/baselines/reference/declarationEmitDefaultExport7.js new file mode 100644 index 0000000000000..9e334552e04a6 --- /dev/null +++ b/tests/baselines/reference/declarationEmitDefaultExport7.js @@ -0,0 +1,12 @@ +//// [declarationEmitDefaultExport7.ts] +class A {} +export default new A(); + + +//// [declarationEmitDefaultExport7.js] +var A = (function () { + function A() { + } + return A; +})(); +module.exports = new A(); diff --git a/tests/cases/compiler/declarationEmitDefaultExport1.ts b/tests/cases/compiler/declarationEmitDefaultExport1.ts new file mode 100644 index 0000000000000..3ce76e2f3b333 --- /dev/null +++ b/tests/cases/compiler/declarationEmitDefaultExport1.ts @@ -0,0 +1,4 @@ +// @declaration: true +// @target: es6 +export default class C { +} \ No newline at end of file diff --git a/tests/cases/compiler/declarationEmitDefaultExport2.ts b/tests/cases/compiler/declarationEmitDefaultExport2.ts new file mode 100644 index 0000000000000..ee691f3bdcf99 --- /dev/null +++ b/tests/cases/compiler/declarationEmitDefaultExport2.ts @@ -0,0 +1,4 @@ +// @declaration: true +// @target: es6 +export default class { +} \ No newline at end of file diff --git a/tests/cases/compiler/declarationEmitDefaultExport3.ts b/tests/cases/compiler/declarationEmitDefaultExport3.ts new file mode 100644 index 0000000000000..fceefe32f7d64 --- /dev/null +++ b/tests/cases/compiler/declarationEmitDefaultExport3.ts @@ -0,0 +1,5 @@ +// @declaration: true +// @target: es6 +export default function foo() { + return "" +} \ No newline at end of file diff --git a/tests/cases/compiler/declarationEmitDefaultExport4.ts b/tests/cases/compiler/declarationEmitDefaultExport4.ts new file mode 100644 index 0000000000000..9daad837f73f5 --- /dev/null +++ b/tests/cases/compiler/declarationEmitDefaultExport4.ts @@ -0,0 +1,5 @@ +// @declaration: true +// @target: es6 +export default function () { + return 1; +} \ No newline at end of file diff --git a/tests/cases/compiler/declarationEmitDefaultExport5.ts b/tests/cases/compiler/declarationEmitDefaultExport5.ts new file mode 100644 index 0000000000000..3265753c514ac --- /dev/null +++ b/tests/cases/compiler/declarationEmitDefaultExport5.ts @@ -0,0 +1,3 @@ +// @declaration: true +// @target: es6 +export default 1 + 2; diff --git a/tests/cases/compiler/declarationEmitDefaultExport6.ts b/tests/cases/compiler/declarationEmitDefaultExport6.ts new file mode 100644 index 0000000000000..468486b9bb041 --- /dev/null +++ b/tests/cases/compiler/declarationEmitDefaultExport6.ts @@ -0,0 +1,4 @@ +// @declaration: true +// @target: es6 +export class A {} +export default new A(); diff --git a/tests/cases/compiler/declarationEmitDefaultExport7.ts b/tests/cases/compiler/declarationEmitDefaultExport7.ts new file mode 100644 index 0000000000000..960c203dcab0d --- /dev/null +++ b/tests/cases/compiler/declarationEmitDefaultExport7.ts @@ -0,0 +1,4 @@ +// @declaration: true +// @target: es6 +class A {} +export default new A(); From eb954e1cb5f701058afe1f253bb254c0d1513607 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 16 Mar 2015 19:25:02 -0700 Subject: [PATCH 095/224] Respond to code review comments --- src/compiler/emitter.ts | 54 ++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index b075730df8f60..22494407f6023 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -5080,7 +5080,7 @@ module ts { // ES6 import if (node.importClause) { - let shouldEmitDefaultBindings = node.importClause.name && resolver.isReferencedAliasDeclaration(node.importClause); + let shouldEmitDefaultBindings = hasReferencedDefaultName(node.importClause); let shouldEmitNamedBindings = hasReferencedNamedBindings(node.importClause); if (shouldEmitDefaultBindings || shouldEmitNamedBindings) { write("import "); @@ -5131,6 +5131,15 @@ module ts { } } + function hasReferencedDefaultName(importClause: ImportClause) { + // If the default import is used, the mark will be on the importClause, + // as the alias declaration. + // If there are other named bindings on the import clause, we will + // will mark either the namedBindings(import * as n) or the NamedImport + // in the case of import {a} + return resolver.isReferencedAliasDeclaration(importClause); + } + function hasReferencedNamedBindings(importClause: ImportClause) { if (importClause && importClause.namedBindings) { if (importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { @@ -5452,33 +5461,37 @@ module ts { } function emitES6Module(node: SourceFile, startIndex: number) { - createExternalModuleInfo(node); externalImports = undefined; exportSpecifiers = undefined; + exportDefault = undefined; emitCaptureThisForNodeIfNecessary(node); emitLinesStartingAt(node.statements, startIndex); emitTempDeclarations(/*newLine*/ true); - emitExportDefault(node, /*emitAsReturn*/ false); + // Emit exportDefault if it exists will happen as part + // or normal statment emit. + } + + function emitExportAssignment(node: ExportAssignment) { + // Only emit exportAssignment/export default if we are in ES6 + // Other modules will handel it diffrentlly + if (languageVersion >= ScriptTarget.ES6) { + writeLine(); + emitStart(node); + write("export default "); + var expression = node.expression; + emit(expression); + if (expression.kind !== SyntaxKind.FunctionDeclaration && + expression.kind !== SyntaxKind.ClassDeclaration) { + write(";"); + } + emitEnd(node); + } } function emitExportDefault(sourceFile: SourceFile, emitAsReturn: boolean) { + // ES6 emit is handled in emitExportAssignment if (exportDefault && resolver.hasExportDefaultValue(sourceFile)) { - if (languageVersion >= ScriptTarget.ES6) { - Debug.assert(!emitAsReturn); - if (exportDefault.kind === SyntaxKind.ExportAssignment) { - writeLine(); - emitStart(exportDefault); - write("export default "); - var expression = (exportDefault).expression; - emit(expression); - if (expression.kind !== SyntaxKind.FunctionDeclaration && - expression.kind !== SyntaxKind.ClassDeclaration) { - write(";"); - } - emitEnd(exportDefault); - } - } - else { + if (languageVersion < ScriptTarget.ES6) { writeLine(); emitStart(exportDefault); write(emitAsReturn ? "return " : "module.exports = "); @@ -5772,6 +5785,8 @@ module ts { return emitImportEqualsDeclaration(node); case SyntaxKind.ExportDeclaration: return emitExportDeclaration(node); + case SyntaxKind.ExportAssignment: + return emitExportAssignment(node); case SyntaxKind.SourceFile: return emitSourceFileNode(node); } @@ -5943,3 +5958,4 @@ module ts { } } } + From 74eb96a5b906d68c42e509432caad5c07a314f84 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 16 Mar 2015 19:51:22 -0700 Subject: [PATCH 096/224] correctly merge const enum only and instantiated modules --- src/compiler/binder.ts | 13 ++++--- .../reference/constEnumOnlyModuleMerging.js | 26 +++++++++++++ .../constEnumOnlyModuleMerging.types | 37 +++++++++++++++++++ .../compiler/constEnumOnlyModuleMerging.ts | 13 +++++++ 4 files changed, 83 insertions(+), 6 deletions(-) create mode 100644 tests/baselines/reference/constEnumOnlyModuleMerging.js create mode 100644 tests/baselines/reference/constEnumOnlyModuleMerging.types create mode 100644 tests/cases/compiler/constEnumOnlyModuleMerging.ts diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index f951fe49269d6..3535aaffb27c4 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -322,13 +322,14 @@ module ts { } else { bindDeclaration(node, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes, /*isBlockScopeContainer*/ true); - if (state === ModuleInstanceState.ConstEnumOnly) { - // mark value module as module that contains only enums - node.symbol.constEnumOnlyModule = true; + let currentModuleIsConstEnumOnly = state === ModuleInstanceState.ConstEnumOnly; + if (node.symbol.constEnumOnlyModule === undefined) { + // non-merged case - use the current state + node.symbol.constEnumOnlyModule = currentModuleIsConstEnumOnly; } - else if (node.symbol.constEnumOnlyModule) { - // const only value module was merged with instantiated module - reset flag - node.symbol.constEnumOnlyModule = false; + else { + // merged case: module is const enum only if all its pieces are non-instantiated or const enum + node.symbol.constEnumOnlyModule = node.symbol.constEnumOnlyModule && currentModuleIsConstEnumOnly; } } } diff --git a/tests/baselines/reference/constEnumOnlyModuleMerging.js b/tests/baselines/reference/constEnumOnlyModuleMerging.js new file mode 100644 index 0000000000000..1d32fe748ab1b --- /dev/null +++ b/tests/baselines/reference/constEnumOnlyModuleMerging.js @@ -0,0 +1,26 @@ +//// [constEnumOnlyModuleMerging.ts] +module Outer { + export var x = 1; +} + +module Outer { + export const enum A { X } +} + +module B { + import O = Outer; + var x = O.A.X; + var y = O.x; +} + +//// [constEnumOnlyModuleMerging.js] +var Outer; +(function (Outer) { + Outer.x = 1; +})(Outer || (Outer = {})); +var B; +(function (B) { + var O = Outer; + var x = 0 /* X */; + var y = O.x; +})(B || (B = {})); diff --git a/tests/baselines/reference/constEnumOnlyModuleMerging.types b/tests/baselines/reference/constEnumOnlyModuleMerging.types new file mode 100644 index 0000000000000..30426e3fa4ce9 --- /dev/null +++ b/tests/baselines/reference/constEnumOnlyModuleMerging.types @@ -0,0 +1,37 @@ +=== tests/cases/compiler/constEnumOnlyModuleMerging.ts === +module Outer { +>Outer : typeof Outer + + export var x = 1; +>x : number +} + +module Outer { +>Outer : typeof Outer + + export const enum A { X } +>A : A +>X : A +} + +module B { +>B : typeof B + + import O = Outer; +>O : typeof O +>Outer : typeof O + + var x = O.A.X; +>x : O.A +>O.A.X : O.A +>O.A : typeof O.A +>O : typeof O +>A : typeof O.A +>X : O.A + + var y = O.x; +>y : number +>O.x : number +>O : typeof O +>x : number +} diff --git a/tests/cases/compiler/constEnumOnlyModuleMerging.ts b/tests/cases/compiler/constEnumOnlyModuleMerging.ts new file mode 100644 index 0000000000000..0b1b9e3f0cba2 --- /dev/null +++ b/tests/cases/compiler/constEnumOnlyModuleMerging.ts @@ -0,0 +1,13 @@ +module Outer { + export var x = 1; +} + +module Outer { + export const enum A { X } +} + +module B { + import O = Outer; + var x = O.A.X; + var y = O.x; +} \ No newline at end of file From 99108694d55138cd2046970bac8e0b3ef1e6172e Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 16 Mar 2015 20:54:28 -0700 Subject: [PATCH 097/224] Do not emit "export" for classes within modules, and do not write the name of an export default class --- src/compiler/emitter.ts | 6 ++++-- .../reference/es6ExportDefaultClassDeclaration2.js | 2 +- tests/baselines/reference/es6ModuleClassDeclaration.js | 4 ++-- tests/baselines/reference/symbolDeclarationEmit12.js | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 888c37f2f85f6..f130525445510 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4894,7 +4894,7 @@ module ts { } function emitClassDeclarationForES6AndHigher(node: ClassDeclaration) { - if (node.flags & NodeFlags.Export) { + if (isES6ModuleMemberDeclaration(node)) { write("export "); if (node.flags & NodeFlags.Default) { @@ -4903,7 +4903,9 @@ module ts { } write("class "); - emitDeclarationName(node); + if (node.name || !(node.flags & NodeFlags.Default)) { + emitDeclarationName(node); + } var baseTypeNode = getClassBaseTypeNode(node); if (baseTypeNode) { write(" extends "); diff --git a/tests/baselines/reference/es6ExportDefaultClassDeclaration2.js b/tests/baselines/reference/es6ExportDefaultClassDeclaration2.js index 3941f3ee7d3f7..a975d4322f53a 100644 --- a/tests/baselines/reference/es6ExportDefaultClassDeclaration2.js +++ b/tests/baselines/reference/es6ExportDefaultClassDeclaration2.js @@ -6,7 +6,7 @@ export default class { //// [es6ExportDefaultClassDeclaration2.js] -export default class _default { +export default class { method() { } } diff --git a/tests/baselines/reference/es6ModuleClassDeclaration.js b/tests/baselines/reference/es6ModuleClassDeclaration.js index 633548155e702..fb555196315b5 100644 --- a/tests/baselines/reference/es6ModuleClassDeclaration.js +++ b/tests/baselines/reference/es6ModuleClassDeclaration.js @@ -149,7 +149,7 @@ new c(); new c2(); var m1; (function (m1) { - export class c3 { + class c3 { constructor() { this.x = 10; this.y = 30; @@ -189,7 +189,7 @@ var m1; export { m1 }; var m2; (function (m2) { - export class c3 { + class c3 { constructor() { this.x = 10; this.y = 30; diff --git a/tests/baselines/reference/symbolDeclarationEmit12.js b/tests/baselines/reference/symbolDeclarationEmit12.js index 9a75f6d573cb8..6165475a5002e 100644 --- a/tests/baselines/reference/symbolDeclarationEmit12.js +++ b/tests/baselines/reference/symbolDeclarationEmit12.js @@ -15,7 +15,7 @@ module M { //// [symbolDeclarationEmit12.js] var M; (function (M) { - export class C { + class C { [Symbol.toPrimitive](x) { } [Symbol.isConcatSpreadable]() { From 3d802438f1deff4aa9980f0f46e75341cb9dd02d Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 16 Mar 2015 21:18:31 -0700 Subject: [PATCH 098/224] Export classes defined wihtin internal modules correctelly --- src/compiler/emitter.ts | 18 +++++++++++++----- .../reference/es6ModuleClassDeclaration.js | 2 ++ .../reference/symbolDeclarationEmit12.js | 1 + 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index f130525445510..29d05519f76ec 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4929,6 +4929,18 @@ module ts { // a lexical declaration such as a LexicalDeclaration or a ClassDeclaration. writeLine(); emitMemberAssignments(node, NodeFlags.Static); + + // If this is an exported classes, but not on the top level (i.e. on an internal + // module), export it + if (!isES6ModuleMemberDeclaration(node) && (node.flags & NodeFlags.Export)) { + writeLine(); + emitStart(node); + emitModuleMemberName(node); + write(" = "); + emitDeclarationName(node); + emitEnd(node); + write(";"); + } } function emitClassDeclarationBelowES6(node: ClassDeclaration) { @@ -4972,11 +4984,7 @@ module ts { write(");"); emitEnd(node); - if (isES6ModuleMemberDeclaration(node)) { - // TODO update this to emit "export class " when ES67 class emit is available - emitES6NamedExportForDeclaration(node); - } - else if (node.flags & NodeFlags.Export && !(node.flags & NodeFlags.Default)) { + if (node.flags & NodeFlags.Export && !(node.flags & NodeFlags.Default)) { writeLine(); emitStart(node); emitModuleMemberName(node); diff --git a/tests/baselines/reference/es6ModuleClassDeclaration.js b/tests/baselines/reference/es6ModuleClassDeclaration.js index fb555196315b5..9676720fd0f1a 100644 --- a/tests/baselines/reference/es6ModuleClassDeclaration.js +++ b/tests/baselines/reference/es6ModuleClassDeclaration.js @@ -165,6 +165,7 @@ var m1; } c3.k = 20; c3.l = 30; + m1.c3 = c3; class c4 { constructor() { this.x = 10; @@ -205,6 +206,7 @@ var m2; } c3.k = 20; c3.l = 30; + m2.c3 = c3; class c4 { constructor() { this.x = 10; diff --git a/tests/baselines/reference/symbolDeclarationEmit12.js b/tests/baselines/reference/symbolDeclarationEmit12.js index 6165475a5002e..ab930b41580a3 100644 --- a/tests/baselines/reference/symbolDeclarationEmit12.js +++ b/tests/baselines/reference/symbolDeclarationEmit12.js @@ -27,4 +27,5 @@ var M; set [Symbol.isRegExp](x) { } } + M.C = C; })(M || (M = {})); From 686d1c60deb618040211c53c37590cf70187c74a Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 16 Mar 2015 21:33:39 -0700 Subject: [PATCH 099/224] A more complete isCompletedNode. --- src/harness/fourslash.ts | 8 ++-- src/services/formatting/smartIndenter.ts | 45 +++++++++++++++---- src/services/utilities.ts | 4 ++ tests/cases/fourslash/indentation.ts | 8 ++-- ...artIndentNonterminatedArgumentListAtEOF.ts | 2 +- 5 files changed, 51 insertions(+), 16 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index d8b7c358a5548..0ae29a6ec87b4 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -1621,8 +1621,9 @@ module FourSlash { this.taoInvalidReason = 'verifyIndentationAtCurrentPosition NYI'; var actual = this.getIndentation(this.activeFile.fileName, this.currentCaretPosition); - if (actual != numberOfSpaces) { - this.raiseError('verifyIndentationAtCurrentPosition failed - expected: ' + numberOfSpaces + ', actual: ' + actual); + var lineCol = this.getLineColStringAtPosition(this.currentCaretPosition); + if (actual !== numberOfSpaces) { + this.raiseError('verifyIndentationAtCurrentPosition failed at ' + lineCol + ' - expected: ' + numberOfSpaces + ', actual: ' + actual); } } @@ -1630,8 +1631,9 @@ module FourSlash { this.taoInvalidReason = 'verifyIndentationAtPosition NYI'; var actual = this.getIndentation(fileName, position); + var lineCol = this.getLineColStringAtPosition(position); if (actual !== numberOfSpaces) { - this.raiseError('verifyIndentationAtPosition failed - expected: ' + numberOfSpaces + ', actual: ' + actual); + this.raiseError('verifyIndentationAtCurrentPosition failed at ' + lineCol + ' - expected: ' + numberOfSpaces + ', actual: ' + actual); } } diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index f1d0935c132d4..38ed4cf8442cb 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -429,46 +429,74 @@ module ts.formatting { case SyntaxKind.InterfaceDeclaration: case SyntaxKind.EnumDeclaration: case SyntaxKind.ObjectLiteralExpression: + case SyntaxKind.ObjectBindingPattern: + case SyntaxKind.TypeLiteral: case SyntaxKind.Block: case SyntaxKind.ModuleBlock: case SyntaxKind.CaseBlock: return nodeEndsWith(n, SyntaxKind.CloseBraceToken, sourceFile); case SyntaxKind.CatchClause: return isCompletedNode((n).block, sourceFile); - case SyntaxKind.ParenthesizedExpression: - case SyntaxKind.CallSignature: + case SyntaxKind.NewExpression: + if (!(n).arguments) { + return true; + } + // fall through case SyntaxKind.CallExpression: case SyntaxKind.ConstructSignature: + case SyntaxKind.ParenthesizedExpression: + case SyntaxKind.ParenthesizedType: return nodeEndsWith(n, SyntaxKind.CloseParenToken, sourceFile); + + case SyntaxKind.FunctionType: + case SyntaxKind.ConstructorType: + return isCompletedNode((n).type, sourceFile); + + case SyntaxKind.Constructor: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: + case SyntaxKind.CallSignature: case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: case SyntaxKind.ArrowFunction: - return !(n).body || isCompletedNode((n).body, sourceFile); + if ((n).body) { + return isCompletedNode((n).body, sourceFile); + } + + return hasChildOfKind(n, SyntaxKind.CloseParenToken, sourceFile) || + (n).typeParameters && hasChildOfKind(n, SyntaxKind.GreaterThanToken, sourceFile) + case SyntaxKind.ModuleDeclaration: return (n).body && isCompletedNode((n).body, sourceFile); + case SyntaxKind.IfStatement: if ((n).elseStatement) { return isCompletedNode((n).elseStatement, sourceFile); } return isCompletedNode((n).thenStatement, sourceFile); + case SyntaxKind.ExpressionStatement: return isCompletedNode((n).expression, sourceFile); + case SyntaxKind.ArrayLiteralExpression: + case SyntaxKind.ArrayBindingPattern: + case SyntaxKind.IndexSignature: + case SyntaxKind.ComputedPropertyName: + case SyntaxKind.TupleType: return nodeEndsWith(n, SyntaxKind.CloseBracketToken, sourceFile); + case SyntaxKind.CaseClause: case SyntaxKind.DefaultClause: - // there is no such thing as terminator token for CaseClause\DefaultClause so for simplicitly always consider them non-completed + // there is no such thing as terminator token for CaseClause/DefaultClause so for simplicitly always consider them non-completed return false; + case SyntaxKind.ForStatement: - return isCompletedNode((n).statement, sourceFile); case SyntaxKind.ForInStatement: - return isCompletedNode((n).statement, sourceFile); case SyntaxKind.ForOfStatement: - return isCompletedNode((n).statement, sourceFile); case SyntaxKind.WhileStatement: - return isCompletedNode((n).statement, sourceFile); + return isCompletedNode((n).statement, sourceFile); case SyntaxKind.DoStatement: // rough approximation: if DoStatement has While keyword - then if node is completed is checking the presence of ')'; var hasWhileKeyword = findChildOfKind(n, SyntaxKind.WhileKeyword, sourceFile); @@ -476,6 +504,7 @@ module ts.formatting { return nodeEndsWith(n, SyntaxKind.CloseParenToken, sourceFile); } return isCompletedNode((n).statement, sourceFile); + default: return true; } diff --git a/src/services/utilities.ts b/src/services/utilities.ts index e0ff529354667..70c8eada5b738 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -79,6 +79,10 @@ module ts { }; } + export function hasChildOfKind(n: Node, kind: SyntaxKind, sourceFile?: SourceFile): boolean { + return !!findChildOfKind(n, kind, sourceFile); + } + export function findChildOfKind(n: Node, kind: SyntaxKind, sourceFile?: SourceFile): Node { return forEach(n.getChildren(sourceFile), c => c.kind === kind && c); } diff --git a/tests/cases/fourslash/indentation.ts b/tests/cases/fourslash/indentation.ts index 2a2090c1d87e9..356d076b9f21a 100644 --- a/tests/cases/fourslash/indentation.ts +++ b/tests/cases/fourslash/indentation.ts @@ -176,8 +176,8 @@ ////// the purpose of this test is to verity smart indent ////// works for unterminated function arguments at the end of a file. ////function unterminatedListIndentation(a, -////{| "indent": 0 |} +////{| "indent": 4 |} -test.markers().forEach((marker) => { - verify.indentationAtPositionIs(marker.fileName, marker.position, marker.data.indent); - }); +test.markers().forEach(marker => { + verify.indentationAtPositionIs(marker.fileName, marker.position, marker.data.indent); +}); diff --git a/tests/cases/fourslash/smartIndentNonterminatedArgumentListAtEOF.ts b/tests/cases/fourslash/smartIndentNonterminatedArgumentListAtEOF.ts index b2b1f746a327f..a533eca1d6767 100644 --- a/tests/cases/fourslash/smartIndentNonterminatedArgumentListAtEOF.ts +++ b/tests/cases/fourslash/smartIndentNonterminatedArgumentListAtEOF.ts @@ -4,4 +4,4 @@ /////**/ goTo.marker(); -verify.indentationIs(0); +verify.indentationIs(4); From 1932f720cb8c3449999a129b4f6e1e8444574f55 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 16 Mar 2015 21:58:57 -0700 Subject: [PATCH 100/224] Handel export name bindings in internal modules in ES6 --- src/compiler/emitter.ts | 21 ++++- .../es5ModuleInternalNamedImports.js | 73 ++++++++++++++++++ .../es5ModuleInternalNamedImports.types | 77 +++++++++++++++++++ .../es6ModuleInternalNamedImports.js | 69 +++++++++++++++++ .../es6ModuleInternalNamedImports.types | 77 +++++++++++++++++++ .../compiler/es5ModuleInternalNamedImports.ts | 33 ++++++++ .../compiler/es6ModuleInternalNamedImports.ts | 32 ++++++++ 7 files changed, 380 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/es5ModuleInternalNamedImports.js create mode 100644 tests/baselines/reference/es5ModuleInternalNamedImports.types create mode 100644 tests/baselines/reference/es6ModuleInternalNamedImports.js create mode 100644 tests/baselines/reference/es6ModuleInternalNamedImports.types create mode 100644 tests/cases/compiler/es5ModuleInternalNamedImports.ts create mode 100644 tests/cases/compiler/es6ModuleInternalNamedImports.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 29d05519f76ec..42856a570776f 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4930,7 +4930,7 @@ module ts { writeLine(); emitMemberAssignments(node, NodeFlags.Static); - // If this is an exported classes, but not on the top level (i.e. on an internal + // If this is an exported class, but not on the top level (i.e. on an internal // module), export it if (!isES6ModuleMemberDeclaration(node) && (node.flags & NodeFlags.Export)) { writeLine(); @@ -5348,7 +5348,7 @@ module ts { } function emitExportDeclaration(node: ExportDeclaration) { - if (languageVersion < ScriptTarget.ES6) { + if (languageVersion < ScriptTarget.ES6 || node.parent.kind !== SyntaxKind.SourceFile) { if (node.moduleSpecifier) { emitStart(node); let generatedName = resolver.getGeneratedNameForNode(node); @@ -5386,6 +5386,23 @@ module ts { } emitEnd(node); } + else { + // internal module + if (node.exportClause) { + // export { x, y, ... } + forEach(node.exportClause.elements, specifier => { + writeLine(); + emitStart(specifier); + emitContainingModuleName(specifier); + write("."); + emitNodeWithoutSourceMap(specifier.name); + write(" = "); + emitNodeWithoutSourceMap(specifier.propertyName || specifier.name); + write(";"); + emitEnd(specifier); + }); + } + } } else { write("export "); diff --git a/tests/baselines/reference/es5ModuleInternalNamedImports.js b/tests/baselines/reference/es5ModuleInternalNamedImports.js new file mode 100644 index 0000000000000..3d9966be7ddc4 --- /dev/null +++ b/tests/baselines/reference/es5ModuleInternalNamedImports.js @@ -0,0 +1,73 @@ +//// [es5ModuleInternalNamedImports.ts] + +export module M { + // variable + export var M_V = 0; + // interface + export interface M_I { } + //calss + export class M_C { } + // instantiated module + export module M_M { var x; } + // uninstantiated module + export module M_MU { } + // function + export function M_F() { } + // enum + export enum M_E { } + // type + export type M_T = number; + // alias + export import M_A = M_M; + + // Reexports + export {M_V as v}; + export {M_I as i}; + export {M_C as c}; + export {M_M as m}; + export {M_MU as mu}; + export {M_F as f}; + export {M_E as e}; + export {M_A as a}; +} + + +//// [es5ModuleInternalNamedImports.js] +define(["require", "exports"], function (require, exports) { + var M; + (function (M) { + // variable + M.M_V = 0; + //calss + var M_C = (function () { + function M_C() { + } + return M_C; + })(); + M.M_C = M_C; + // instantiated module + var M_M; + (function (M_M) { + var x; + })(M_M = M.M_M || (M.M_M = {})); + // function + function M_F() { + } + M.M_F = M_F; + // enum + (function (M_E) { + })(M.M_E || (M.M_E = {})); + var M_E = M.M_E; + // alias + M.M_A = M_M; + // Reexports + M.v = M.M_V; + M.i = M_I; + M.c = M_C; + M.m = M_M; + M.mu = M_MU; + M.f = M_F; + M.e = M_E; + M.a = M.M_A; + })(M = exports.M || (exports.M = {})); +}); diff --git a/tests/baselines/reference/es5ModuleInternalNamedImports.types b/tests/baselines/reference/es5ModuleInternalNamedImports.types new file mode 100644 index 0000000000000..fa88ab399a3fc --- /dev/null +++ b/tests/baselines/reference/es5ModuleInternalNamedImports.types @@ -0,0 +1,77 @@ +=== tests/cases/compiler/es5ModuleInternalNamedImports.ts === + +export module M { +>M : typeof M + + // variable + export var M_V = 0; +>M_V : number + + // interface + export interface M_I { } +>M_I : M_I + + //calss + export class M_C { } +>M_C : M_C + + // instantiated module + export module M_M { var x; } +>M_M : typeof M_M +>x : any + + // uninstantiated module + export module M_MU { } +>M_MU : unknown + + // function + export function M_F() { } +>M_F : () => void + + // enum + export enum M_E { } +>M_E : M_E + + // type + export type M_T = number; +>M_T : number + + // alias + export import M_A = M_M; +>M_A : typeof M_M +>M_M : typeof M_M + + // Reexports + export {M_V as v}; +>M_V : number +>v : number + + export {M_I as i}; +>M_I : unknown +>i : unknown + + export {M_C as c}; +>M_C : typeof M_C +>c : typeof M_C + + export {M_M as m}; +>M_M : typeof M_M +>m : typeof M_M + + export {M_MU as mu}; +>M_MU : unknown +>mu : unknown + + export {M_F as f}; +>M_F : () => void +>f : () => void + + export {M_E as e}; +>M_E : typeof M_E +>e : typeof M_E + + export {M_A as a}; +>M_A : typeof M_M +>a : typeof M_M +} + diff --git a/tests/baselines/reference/es6ModuleInternalNamedImports.js b/tests/baselines/reference/es6ModuleInternalNamedImports.js new file mode 100644 index 0000000000000..532025c4ee68d --- /dev/null +++ b/tests/baselines/reference/es6ModuleInternalNamedImports.js @@ -0,0 +1,69 @@ +//// [es6ModuleInternalNamedImports.ts] + +export module M { + // variable + export var M_V = 0; + // interface + export interface M_I { } + //calss + export class M_C { } + // instantiated module + export module M_M { var x; } + // uninstantiated module + export module M_MU { } + // function + export function M_F() { } + // enum + export enum M_E { } + // type + export type M_T = number; + // alias + export import M_A = M_M; + + // Reexports + export {M_V as v}; + export {M_I as i}; + export {M_C as c}; + export {M_M as m}; + export {M_MU as mu}; + export {M_F as f}; + export {M_E as e}; + export {M_A as a}; +} + + +//// [es6ModuleInternalNamedImports.js] +var M; +(function (M) { + // variable + M.M_V = 0; + //calss + class M_C { + } + M.M_C = M_C; + // instantiated module + var M_M; + (function (M_M) { + var x; + })(M_M = M.M_M || (M.M_M = {})); + // function + function M_F() { + } + M.M_F = M_F; + // enum + (function (M_E) { + })(M.M_E || (M.M_E = {})); + var M_E = M.M_E; + // alias + M.M_A = M_M; + // Reexports + M.v = M.M_V; + M.i = M_I; + M.c = M_C; + M.m = M_M; + M.mu = M_MU; + M.f = M_F; + M.e = M_E; + M.a = M.M_A; +})(M || (M = {})); +export { M }; diff --git a/tests/baselines/reference/es6ModuleInternalNamedImports.types b/tests/baselines/reference/es6ModuleInternalNamedImports.types new file mode 100644 index 0000000000000..6b614926a0af6 --- /dev/null +++ b/tests/baselines/reference/es6ModuleInternalNamedImports.types @@ -0,0 +1,77 @@ +=== tests/cases/compiler/es6ModuleInternalNamedImports.ts === + +export module M { +>M : typeof M + + // variable + export var M_V = 0; +>M_V : number + + // interface + export interface M_I { } +>M_I : M_I + + //calss + export class M_C { } +>M_C : M_C + + // instantiated module + export module M_M { var x; } +>M_M : typeof M_M +>x : any + + // uninstantiated module + export module M_MU { } +>M_MU : unknown + + // function + export function M_F() { } +>M_F : () => void + + // enum + export enum M_E { } +>M_E : M_E + + // type + export type M_T = number; +>M_T : number + + // alias + export import M_A = M_M; +>M_A : typeof M_M +>M_M : typeof M_M + + // Reexports + export {M_V as v}; +>M_V : number +>v : number + + export {M_I as i}; +>M_I : unknown +>i : unknown + + export {M_C as c}; +>M_C : typeof M_C +>c : typeof M_C + + export {M_M as m}; +>M_M : typeof M_M +>m : typeof M_M + + export {M_MU as mu}; +>M_MU : unknown +>mu : unknown + + export {M_F as f}; +>M_F : () => void +>f : () => void + + export {M_E as e}; +>M_E : typeof M_E +>e : typeof M_E + + export {M_A as a}; +>M_A : typeof M_M +>a : typeof M_M +} + diff --git a/tests/cases/compiler/es5ModuleInternalNamedImports.ts b/tests/cases/compiler/es5ModuleInternalNamedImports.ts new file mode 100644 index 0000000000000..05943d1c67e7a --- /dev/null +++ b/tests/cases/compiler/es5ModuleInternalNamedImports.ts @@ -0,0 +1,33 @@ +// @target: ES5 +// @module: AMD + +export module M { + // variable + export var M_V = 0; + // interface + export interface M_I { } + //calss + export class M_C { } + // instantiated module + export module M_M { var x; } + // uninstantiated module + export module M_MU { } + // function + export function M_F() { } + // enum + export enum M_E { } + // type + export type M_T = number; + // alias + export import M_A = M_M; + + // Reexports + export {M_V as v}; + export {M_I as i}; + export {M_C as c}; + export {M_M as m}; + export {M_MU as mu}; + export {M_F as f}; + export {M_E as e}; + export {M_A as a}; +} diff --git a/tests/cases/compiler/es6ModuleInternalNamedImports.ts b/tests/cases/compiler/es6ModuleInternalNamedImports.ts new file mode 100644 index 0000000000000..f696cee0aa350 --- /dev/null +++ b/tests/cases/compiler/es6ModuleInternalNamedImports.ts @@ -0,0 +1,32 @@ +// @target: ES6 + +export module M { + // variable + export var M_V = 0; + // interface + export interface M_I { } + //calss + export class M_C { } + // instantiated module + export module M_M { var x; } + // uninstantiated module + export module M_MU { } + // function + export function M_F() { } + // enum + export enum M_E { } + // type + export type M_T = number; + // alias + export import M_A = M_M; + + // Reexports + export {M_V as v}; + export {M_I as i}; + export {M_C as c}; + export {M_M as m}; + export {M_MU as mu}; + export {M_F as f}; + export {M_E as e}; + export {M_A as a}; +} From a7f57cbe41111938e60ee30a8717bd70ae73f5fc Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 16 Mar 2015 22:09:17 -0700 Subject: [PATCH 101/224] Indentation within binding patterns. Fixes #2380. --- src/services/formatting/smartIndenter.ts | 2 ++ .../indentationAfterArrayBindingPattern01.ts | 14 ++++++++++++++ .../indentationAfterArrayBindingPattern02.ts | 15 +++++++++++++++ .../indentationAfterObjectBindingPattern01.ts | 15 +++++++++++++++ .../indentationAfterObjectBindingPattern02.ts | 16 ++++++++++++++++ 5 files changed, 62 insertions(+) create mode 100644 tests/cases/fourslash/indentationAfterArrayBindingPattern01.ts create mode 100644 tests/cases/fourslash/indentationAfterArrayBindingPattern02.ts create mode 100644 tests/cases/fourslash/indentationAfterObjectBindingPattern01.ts create mode 100644 tests/cases/fourslash/indentationAfterObjectBindingPattern02.ts diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index 38ed4cf8442cb..c0a84e25e24cd 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -368,6 +368,8 @@ module ts.formatting { case SyntaxKind.ExportAssignment: case SyntaxKind.ReturnStatement: case SyntaxKind.ConditionalExpression: + case SyntaxKind.ArrayBindingPattern: + case SyntaxKind.ObjectBindingPattern: return true; } return false; diff --git a/tests/cases/fourslash/indentationAfterArrayBindingPattern01.ts b/tests/cases/fourslash/indentationAfterArrayBindingPattern01.ts new file mode 100644 index 0000000000000..980f238329910 --- /dev/null +++ b/tests/cases/fourslash/indentationAfterArrayBindingPattern01.ts @@ -0,0 +1,14 @@ +/// + +////var /*1*/[/*2*/a,/*3*/b,/*4*/ + +function verifyIndentationAfterNewLine(marker: string, indentation: number): void { + goTo.marker(marker); + edit.insert("\r\n"); + verify.indentationIs(indentation); +} + +verifyIndentationAfterNewLine("1", 4); +verifyIndentationAfterNewLine("2", 8); +verifyIndentationAfterNewLine("3", 8); +verifyIndentationAfterNewLine("4", 8); \ No newline at end of file diff --git a/tests/cases/fourslash/indentationAfterArrayBindingPattern02.ts b/tests/cases/fourslash/indentationAfterArrayBindingPattern02.ts new file mode 100644 index 0000000000000..b9a1da7796a7f --- /dev/null +++ b/tests/cases/fourslash/indentationAfterArrayBindingPattern02.ts @@ -0,0 +1,15 @@ +/// + +////var /*1*/[/*2*/a,/*3*/b/*4*/]/*5*/ + +function verifyIndentationAfterNewLine(marker: string, indentation: number): void { + goTo.marker(marker); + edit.insert("\r\n"); + verify.indentationIs(indentation); +} + +verifyIndentationAfterNewLine("1", 4); +verifyIndentationAfterNewLine("2", 8); +verifyIndentationAfterNewLine("3", 8); +verifyIndentationAfterNewLine("4", 8); +verifyIndentationAfterNewLine("5", 0); \ No newline at end of file diff --git a/tests/cases/fourslash/indentationAfterObjectBindingPattern01.ts b/tests/cases/fourslash/indentationAfterObjectBindingPattern01.ts new file mode 100644 index 0000000000000..8bfcbe83b726c --- /dev/null +++ b/tests/cases/fourslash/indentationAfterObjectBindingPattern01.ts @@ -0,0 +1,15 @@ +/// + +////var /*1*/{/*2*/a,/*3*/b:/*4*/k,/*5*/ + +function verifyIndentationAfterNewLine(marker: string, indentation: number): void { + goTo.marker(marker); + edit.insert("\r\n"); + verify.indentationIs(indentation); +} + +verifyIndentationAfterNewLine("1", 4); +verifyIndentationAfterNewLine("2", 8); +verifyIndentationAfterNewLine("3", 8); +verifyIndentationAfterNewLine("4", 8); +verifyIndentationAfterNewLine("5", 8); \ No newline at end of file diff --git a/tests/cases/fourslash/indentationAfterObjectBindingPattern02.ts b/tests/cases/fourslash/indentationAfterObjectBindingPattern02.ts new file mode 100644 index 0000000000000..e1612dffbb450 --- /dev/null +++ b/tests/cases/fourslash/indentationAfterObjectBindingPattern02.ts @@ -0,0 +1,16 @@ +/// + +////var /*1*/{/*2*/a,/*3*/b:/*4*/k,/*5*/}/*6*/ + +function verifyIndentationAfterNewLine(marker: string, indentation: number): void { + goTo.marker(marker); + edit.insert("\r\n"); + verify.indentationIs(indentation); +} + +verifyIndentationAfterNewLine("1", 4); +verifyIndentationAfterNewLine("2", 8); +verifyIndentationAfterNewLine("3", 8); +verifyIndentationAfterNewLine("4", 8); +verifyIndentationAfterNewLine("5", 8); +verifyIndentationAfterNewLine("6", 0); \ No newline at end of file From 3eea65512c5eb652c7dbd69175d1c87b4f190749 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 16 Mar 2015 22:13:55 -0700 Subject: [PATCH 102/224] Rename tests. --- ...rayBindingPattern01.ts => smartIndentArrayBindingPattern01.ts} | 0 ...rayBindingPattern02.ts => smartIndentArrayBindingPattern02.ts} | 0 ...ctBindingPattern01.ts => smartIndentObjectBindingPattern01.ts} | 0 ...ctBindingPattern02.ts => smartIndentObjectBindingPattern02.ts} | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename tests/cases/fourslash/{indentationAfterArrayBindingPattern01.ts => smartIndentArrayBindingPattern01.ts} (100%) rename tests/cases/fourslash/{indentationAfterArrayBindingPattern02.ts => smartIndentArrayBindingPattern02.ts} (100%) rename tests/cases/fourslash/{indentationAfterObjectBindingPattern01.ts => smartIndentObjectBindingPattern01.ts} (100%) rename tests/cases/fourslash/{indentationAfterObjectBindingPattern02.ts => smartIndentObjectBindingPattern02.ts} (100%) diff --git a/tests/cases/fourslash/indentationAfterArrayBindingPattern01.ts b/tests/cases/fourslash/smartIndentArrayBindingPattern01.ts similarity index 100% rename from tests/cases/fourslash/indentationAfterArrayBindingPattern01.ts rename to tests/cases/fourslash/smartIndentArrayBindingPattern01.ts diff --git a/tests/cases/fourslash/indentationAfterArrayBindingPattern02.ts b/tests/cases/fourslash/smartIndentArrayBindingPattern02.ts similarity index 100% rename from tests/cases/fourslash/indentationAfterArrayBindingPattern02.ts rename to tests/cases/fourslash/smartIndentArrayBindingPattern02.ts diff --git a/tests/cases/fourslash/indentationAfterObjectBindingPattern01.ts b/tests/cases/fourslash/smartIndentObjectBindingPattern01.ts similarity index 100% rename from tests/cases/fourslash/indentationAfterObjectBindingPattern01.ts rename to tests/cases/fourslash/smartIndentObjectBindingPattern01.ts diff --git a/tests/cases/fourslash/indentationAfterObjectBindingPattern02.ts b/tests/cases/fourslash/smartIndentObjectBindingPattern02.ts similarity index 100% rename from tests/cases/fourslash/indentationAfterObjectBindingPattern02.ts rename to tests/cases/fourslash/smartIndentObjectBindingPattern02.ts From 905e46e20f1a21358a4d0d2df49397702f3dba1b Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 16 Mar 2015 22:40:58 -0700 Subject: [PATCH 103/224] Account for call signatures properly. --- src/services/formatting/smartIndenter.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index c0a84e25e24cd..36e3f8579df91 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -390,6 +390,7 @@ module ts.formatting { case SyntaxKind.FunctionExpression: case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: + case SyntaxKind.CallSignature: case SyntaxKind.ArrowFunction: case SyntaxKind.Constructor: case SyntaxKind.GetAccessor: @@ -459,9 +460,9 @@ module ts.formatting { case SyntaxKind.SetAccessor: case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: - case SyntaxKind.CallSignature: case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: + case SyntaxKind.CallSignature: case SyntaxKind.ArrowFunction: if ((n).body) { return isCompletedNode((n).body, sourceFile); From 686a10085c55d3ab77ecacf2200596103629b540 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 16 Mar 2015 23:05:03 -0700 Subject: [PATCH 104/224] Moved construct signature down appropriately, fixed logic for function-like constructs. --- src/services/formatting/smartIndenter.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index 36e3f8579df91..76a95bcdadca6 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -446,7 +446,6 @@ module ts.formatting { } // fall through case SyntaxKind.CallExpression: - case SyntaxKind.ConstructSignature: case SyntaxKind.ParenthesizedExpression: case SyntaxKind.ParenthesizedType: return nodeEndsWith(n, SyntaxKind.CloseParenToken, sourceFile); @@ -462,14 +461,20 @@ module ts.formatting { case SyntaxKind.FunctionExpression: case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: + case SyntaxKind.ConstructSignature: case SyntaxKind.CallSignature: case SyntaxKind.ArrowFunction: if ((n).body) { return isCompletedNode((n).body, sourceFile); } - return hasChildOfKind(n, SyntaxKind.CloseParenToken, sourceFile) || - (n).typeParameters && hasChildOfKind(n, SyntaxKind.GreaterThanToken, sourceFile) + if ((n).type) { + return isCompletedNode((n).type, sourceFile); + } + + // Even though type parameters can be unclosed, we can get away with + // having at least a closing paren. + return hasChildOfKind(n, SyntaxKind.CloseParenToken, sourceFile); case SyntaxKind.ModuleDeclaration: return (n).body && isCompletedNode((n).body, sourceFile); From 6a6839a1b3bddf559ebf91f9901b23244900cc62 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 16 Mar 2015 23:10:36 -0700 Subject: [PATCH 105/224] Always indent on tuple type literals. --- src/services/formatting/smartIndenter.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index 76a95bcdadca6..0932ad042e7b0 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -357,6 +357,7 @@ module ts.formatting { case SyntaxKind.ModuleBlock: case SyntaxKind.ObjectLiteralExpression: case SyntaxKind.TypeLiteral: + case SyntaxKind.TupleType: case SyntaxKind.CaseBlock: case SyntaxKind.DefaultClause: case SyntaxKind.CaseClause: From 577c12e42e3ec3fb8fc3b237e3d62ae334786285 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 16 Mar 2015 23:19:21 -0700 Subject: [PATCH 106/224] Added accumulated tests. --- .../smartIndentAfterNewExpression.ts | 17 +++++++++ .../smartIndentInParenthesizedExpression01.ts | 13 +++++++ .../smartIndentInParenthesizedExpression02.ts | 8 +++++ .../cases/fourslash/smartIndentOnAccessors.ts | 36 +++++++++++++++++++ .../fourslash/smartIndentOnAccessors01.ts | 36 +++++++++++++++++++ .../fourslash/smartIndentOnAccessors02.ts | 9 +++++ .../smartIndentOnUnclosedArrowType01.ts | 8 +++++ ...smartIndentOnUnclosedComputedProperty01.ts | 11 ++++++ .../smartIndentOnUnclosedConstructorType01.ts | 8 +++++ ...rtIndentOnUnclosedFunctionDeclaration01.ts | 13 +++++++ ...rtIndentOnUnclosedFunctionDeclaration02.ts | 14 ++++++++ ...rtIndentOnUnclosedFunctionDeclaration03.ts | 12 +++++++ ...rtIndentOnUnclosedFunctionDeclaration04.ts | 17 +++++++++ ...rtIndentOnUnclosedFunctionDeclaration05.ts | 9 +++++ ...rtIndentOnUnclosedFunctionDeclaration06.ts | 10 ++++++ .../smartIndentOnUnclosedIndexSignature01.ts | 11 ++++++ ...martIndentOnUnclosedObjectTypeLiteral01.ts | 8 +++++ ...smartIndentOnUnclosedTupleTypeLiteral01.ts | 8 +++++ 18 files changed, 248 insertions(+) create mode 100644 tests/cases/fourslash/smartIndentAfterNewExpression.ts create mode 100644 tests/cases/fourslash/smartIndentInParenthesizedExpression01.ts create mode 100644 tests/cases/fourslash/smartIndentInParenthesizedExpression02.ts create mode 100644 tests/cases/fourslash/smartIndentOnAccessors.ts create mode 100644 tests/cases/fourslash/smartIndentOnAccessors01.ts create mode 100644 tests/cases/fourslash/smartIndentOnAccessors02.ts create mode 100644 tests/cases/fourslash/smartIndentOnUnclosedArrowType01.ts create mode 100644 tests/cases/fourslash/smartIndentOnUnclosedComputedProperty01.ts create mode 100644 tests/cases/fourslash/smartIndentOnUnclosedConstructorType01.ts create mode 100644 tests/cases/fourslash/smartIndentOnUnclosedFunctionDeclaration01.ts create mode 100644 tests/cases/fourslash/smartIndentOnUnclosedFunctionDeclaration02.ts create mode 100644 tests/cases/fourslash/smartIndentOnUnclosedFunctionDeclaration03.ts create mode 100644 tests/cases/fourslash/smartIndentOnUnclosedFunctionDeclaration04.ts create mode 100644 tests/cases/fourslash/smartIndentOnUnclosedFunctionDeclaration05.ts create mode 100644 tests/cases/fourslash/smartIndentOnUnclosedFunctionDeclaration06.ts create mode 100644 tests/cases/fourslash/smartIndentOnUnclosedIndexSignature01.ts create mode 100644 tests/cases/fourslash/smartIndentOnUnclosedObjectTypeLiteral01.ts create mode 100644 tests/cases/fourslash/smartIndentOnUnclosedTupleTypeLiteral01.ts diff --git a/tests/cases/fourslash/smartIndentAfterNewExpression.ts b/tests/cases/fourslash/smartIndentAfterNewExpression.ts new file mode 100644 index 0000000000000..f2d699f988bf8 --- /dev/null +++ b/tests/cases/fourslash/smartIndentAfterNewExpression.ts @@ -0,0 +1,17 @@ +/// + +//// +////new Array +////{| "indent": 0 |} +////new Array; +////{| "indent": 0 |} +////new Array(0); +////{| "indent": 0 |} +////new Array(; +////{| "indent": 0 |} +////new Array( +////{| "indent": 4 |} + +test.markers().forEach(marker => { + verify.indentationAtPositionIs(marker.fileName, marker.position, marker.data.indent); +}); diff --git a/tests/cases/fourslash/smartIndentInParenthesizedExpression01.ts b/tests/cases/fourslash/smartIndentInParenthesizedExpression01.ts new file mode 100644 index 0000000000000..253f58071d9c1 --- /dev/null +++ b/tests/cases/fourslash/smartIndentInParenthesizedExpression01.ts @@ -0,0 +1,13 @@ +/// + +////var x = (/*1*/1/*2*/)/*3*/ + +function verifyIndentationAfterNewLine(marker: string, indentation: number): void { + goTo.marker(marker); + edit.insert("\r\n"); + verify.indentationIs(indentation); +} + +verifyIndentationAfterNewLine("1", 4); +verifyIndentationAfterNewLine("2", 4); +verifyIndentationAfterNewLine("3", 0); \ No newline at end of file diff --git a/tests/cases/fourslash/smartIndentInParenthesizedExpression02.ts b/tests/cases/fourslash/smartIndentInParenthesizedExpression02.ts new file mode 100644 index 0000000000000..ac169d0b17e52 --- /dev/null +++ b/tests/cases/fourslash/smartIndentInParenthesizedExpression02.ts @@ -0,0 +1,8 @@ +/// + +////var y = ( +////{| "indent": 4 |} + +test.markers().forEach(marker => { + verify.indentationAtPositionIs(marker.fileName, marker.position, marker.data.indent); +}); \ No newline at end of file diff --git a/tests/cases/fourslash/smartIndentOnAccessors.ts b/tests/cases/fourslash/smartIndentOnAccessors.ts new file mode 100644 index 0000000000000..a7972b1f48bd3 --- /dev/null +++ b/tests/cases/fourslash/smartIndentOnAccessors.ts @@ -0,0 +1,36 @@ +/// + +////class Foo { +//// get foo(a, +//// /*1*/b,/*0*/ +//// //comment/*2*/ +//// /*3*/c +//// ) { +//// } +//// set foo(a, +//// /*5*/b,/*4*/ +//// //comment/*6*/ +//// /*7*/c +//// ) { +//// } +////} + + +goTo.marker("0"); +edit.insert("\r\n"); +verify.indentationIs(8); +goTo.marker("1"); +verify.currentLineContentIs(" b,"); +goTo.marker("2"); +verify.currentLineContentIs(" //comment"); +goTo.marker("3"); +verify.currentLineContentIs(" c"); +goTo.marker("4"); +edit.insert("\r\n"); +verify.indentationIs(8); +goTo.marker("5"); +verify.currentLineContentIs(" b,"); +goTo.marker("6"); +verify.currentLineContentIs(" //comment"); +goTo.marker("7"); +verify.currentLineContentIs(" c"); \ No newline at end of file diff --git a/tests/cases/fourslash/smartIndentOnAccessors01.ts b/tests/cases/fourslash/smartIndentOnAccessors01.ts new file mode 100644 index 0000000000000..a7972b1f48bd3 --- /dev/null +++ b/tests/cases/fourslash/smartIndentOnAccessors01.ts @@ -0,0 +1,36 @@ +/// + +////class Foo { +//// get foo(a, +//// /*1*/b,/*0*/ +//// //comment/*2*/ +//// /*3*/c +//// ) { +//// } +//// set foo(a, +//// /*5*/b,/*4*/ +//// //comment/*6*/ +//// /*7*/c +//// ) { +//// } +////} + + +goTo.marker("0"); +edit.insert("\r\n"); +verify.indentationIs(8); +goTo.marker("1"); +verify.currentLineContentIs(" b,"); +goTo.marker("2"); +verify.currentLineContentIs(" //comment"); +goTo.marker("3"); +verify.currentLineContentIs(" c"); +goTo.marker("4"); +edit.insert("\r\n"); +verify.indentationIs(8); +goTo.marker("5"); +verify.currentLineContentIs(" b,"); +goTo.marker("6"); +verify.currentLineContentIs(" //comment"); +goTo.marker("7"); +verify.currentLineContentIs(" c"); \ No newline at end of file diff --git a/tests/cases/fourslash/smartIndentOnAccessors02.ts b/tests/cases/fourslash/smartIndentOnAccessors02.ts new file mode 100644 index 0000000000000..08f0083f2f271 --- /dev/null +++ b/tests/cases/fourslash/smartIndentOnAccessors02.ts @@ -0,0 +1,9 @@ +/// + +////class Foo { +//// get foo() { +////{| "indent": 8 |} + +test.markers().forEach(marker => { + verify.indentationAtPositionIs(marker.fileName, marker.position, marker.data.indent); +}); diff --git a/tests/cases/fourslash/smartIndentOnUnclosedArrowType01.ts b/tests/cases/fourslash/smartIndentOnUnclosedArrowType01.ts new file mode 100644 index 0000000000000..44a47d984ab4b --- /dev/null +++ b/tests/cases/fourslash/smartIndentOnUnclosedArrowType01.ts @@ -0,0 +1,8 @@ +/// + +////var x: () => { +////{| "indent": 4 |} + +test.markers().forEach(marker => { + verify.indentationAtPositionIs(marker.fileName, marker.position, marker.data.indent); +}); diff --git a/tests/cases/fourslash/smartIndentOnUnclosedComputedProperty01.ts b/tests/cases/fourslash/smartIndentOnUnclosedComputedProperty01.ts new file mode 100644 index 0000000000000..0b57a2cb4669f --- /dev/null +++ b/tests/cases/fourslash/smartIndentOnUnclosedComputedProperty01.ts @@ -0,0 +1,11 @@ +/// + +////var x = { +//// [1123123123132 +////{| "indent": 4 |} +////} + +// Note that we currently do NOT indent further in a computed property. +test.markers().forEach(marker => { + verify.indentationAtPositionIs(marker.fileName, marker.position, marker.data.indent); +}); \ No newline at end of file diff --git a/tests/cases/fourslash/smartIndentOnUnclosedConstructorType01.ts b/tests/cases/fourslash/smartIndentOnUnclosedConstructorType01.ts new file mode 100644 index 0000000000000..ae76cbf06c951 --- /dev/null +++ b/tests/cases/fourslash/smartIndentOnUnclosedConstructorType01.ts @@ -0,0 +1,8 @@ +/// + +////var x: new () => { +////{| "indent": 4 |} + +test.markers().forEach(marker => { + verify.indentationAtPositionIs(marker.fileName, marker.position, marker.data.indent); +}); diff --git a/tests/cases/fourslash/smartIndentOnUnclosedFunctionDeclaration01.ts b/tests/cases/fourslash/smartIndentOnUnclosedFunctionDeclaration01.ts new file mode 100644 index 0000000000000..3e08fe5975ed1 --- /dev/null +++ b/tests/cases/fourslash/smartIndentOnUnclosedFunctionDeclaration01.ts @@ -0,0 +1,13 @@ +/// + +////function /*1*/f/*2*/ + + +function verifyIndentationAfterNewLine(marker: string, indentation: number): void { + goTo.marker(marker); + edit.insert("\r\n"); + verify.indentationIs(indentation); +} + +verifyIndentationAfterNewLine("1", 4); +verifyIndentationAfterNewLine("2", 4); \ No newline at end of file diff --git a/tests/cases/fourslash/smartIndentOnUnclosedFunctionDeclaration02.ts b/tests/cases/fourslash/smartIndentOnUnclosedFunctionDeclaration02.ts new file mode 100644 index 0000000000000..3de8b5ec6c378 --- /dev/null +++ b/tests/cases/fourslash/smartIndentOnUnclosedFunctionDeclaration02.ts @@ -0,0 +1,14 @@ +/// + +////function f + +////function f/*1*/ + + +function verifyIndentationAfterNewLine(marker: string, indentation: number): void { + goTo.marker(marker); + edit.insert("\r\n"); + verify.indentationIs(indentation); +} + +verifyIndentationAfterNewLine("1", 4); \ No newline at end of file diff --git a/tests/cases/fourslash/smartIndentOnUnclosedFunctionDeclaration04.ts b/tests/cases/fourslash/smartIndentOnUnclosedFunctionDeclaration04.ts new file mode 100644 index 0000000000000..3931433e51ff2 --- /dev/null +++ b/tests/cases/fourslash/smartIndentOnUnclosedFunctionDeclaration04.ts @@ -0,0 +1,17 @@ +/// + +////function f/*1*/(/*2*/a: A, /*3*/b:/*4*/B, c/*5*/, d: C/*6*/ + + +function verifyIndentationAfterNewLine(marker: string, indentation: number): void { + goTo.marker(marker); + edit.insert("\r\n"); + verify.indentationIs(indentation); +} + +verifyIndentationAfterNewLine("1", 4); +verifyIndentationAfterNewLine("2", 4); +verifyIndentationAfterNewLine("3", 4); +verifyIndentationAfterNewLine("4", 4); +verifyIndentationAfterNewLine("5", 4); +verifyIndentationAfterNewLine("6", 4); \ No newline at end of file diff --git a/tests/cases/fourslash/smartIndentOnUnclosedFunctionDeclaration05.ts b/tests/cases/fourslash/smartIndentOnUnclosedFunctionDeclaration05.ts new file mode 100644 index 0000000000000..24c2bca72f792 --- /dev/null +++ b/tests/cases/fourslash/smartIndentOnUnclosedFunctionDeclaration05.ts @@ -0,0 +1,9 @@ +/// + +////function f(a: A, b:B, c, d: C): { +////{| "indent": 4 |} +//// + +test.markers().forEach(marker => { + verify.indentationAtPositionIs(marker.fileName, marker.position, marker.data.indent); +}); diff --git a/tests/cases/fourslash/smartIndentOnUnclosedFunctionDeclaration06.ts b/tests/cases/fourslash/smartIndentOnUnclosedFunctionDeclaration06.ts new file mode 100644 index 0000000000000..782a85c908a02 --- /dev/null +++ b/tests/cases/fourslash/smartIndentOnUnclosedFunctionDeclaration06.ts @@ -0,0 +1,10 @@ +/// + +////function f(a: A, b:B, c, d: C): { +////{| "indent": 4 |} +////} { +////{| "indent": 4 |} + +test.markers().forEach(marker => { + verify.indentationAtPositionIs(marker.fileName, marker.position, marker.data.indent); +}); diff --git a/tests/cases/fourslash/smartIndentOnUnclosedIndexSignature01.ts b/tests/cases/fourslash/smartIndentOnUnclosedIndexSignature01.ts new file mode 100644 index 0000000000000..da88bc9d0c169 --- /dev/null +++ b/tests/cases/fourslash/smartIndentOnUnclosedIndexSignature01.ts @@ -0,0 +1,11 @@ +/// + +////class C { +////[x: string +////{| "indent": 4 |} +//// + +// Note that we currently do NOT indent further in an index signature. +test.markers().forEach(marker => { + verify.indentationAtPositionIs(marker.fileName, marker.position, marker.data.indent); +}); \ No newline at end of file diff --git a/tests/cases/fourslash/smartIndentOnUnclosedObjectTypeLiteral01.ts b/tests/cases/fourslash/smartIndentOnUnclosedObjectTypeLiteral01.ts new file mode 100644 index 0000000000000..f2f900ce5d8dc --- /dev/null +++ b/tests/cases/fourslash/smartIndentOnUnclosedObjectTypeLiteral01.ts @@ -0,0 +1,8 @@ +/// + +////var x: { +////{| "indent": 4 |} + +test.markers().forEach(marker => { + verify.indentationAtPositionIs(marker.fileName, marker.position, marker.data.indent); +}); \ No newline at end of file diff --git a/tests/cases/fourslash/smartIndentOnUnclosedTupleTypeLiteral01.ts b/tests/cases/fourslash/smartIndentOnUnclosedTupleTypeLiteral01.ts new file mode 100644 index 0000000000000..f2346e6bddcf8 --- /dev/null +++ b/tests/cases/fourslash/smartIndentOnUnclosedTupleTypeLiteral01.ts @@ -0,0 +1,8 @@ +/// + +////var x: [string, number, +////{| "indent": 4 |} + +test.markers().forEach(marker => { + verify.indentationAtPositionIs(marker.fileName, marker.position, marker.data.indent); +}); \ No newline at end of file From b4811fc8bed9dccf1f73efff81e6c4d1a87f745e Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 16 Mar 2015 23:22:15 -0700 Subject: [PATCH 107/224] Fix copy/paste error. --- src/harness/fourslash.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 0ae29a6ec87b4..95a320ac052c6 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -1633,7 +1633,7 @@ module FourSlash { var actual = this.getIndentation(fileName, position); var lineCol = this.getLineColStringAtPosition(position); if (actual !== numberOfSpaces) { - this.raiseError('verifyIndentationAtCurrentPosition failed at ' + lineCol + ' - expected: ' + numberOfSpaces + ', actual: ' + actual); + this.raiseError('verifyIndentationAtPosition failed at ' + lineCol + ' - expected: ' + numberOfSpaces + ', actual: ' + actual); } } From 26647d4ecf6b7f9c0b0072ecaf24e1436a955a3b Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 17 Mar 2015 00:15:53 -0700 Subject: [PATCH 108/224] Fixed harness. --- src/harness/fourslash.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 95a320ac052c6..5d488259a365b 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -620,7 +620,7 @@ module FourSlash { this.scenarioActions.push(''); var members = this.getMemberListAtCaret(); - if (members.entries.filter(e => e.name === symbol).length !== 0) { + if (members && members.entries.filter(e => e.name === symbol).length !== 0) { this.raiseError('Member list did contain ' + symbol); } } @@ -691,7 +691,12 @@ module FourSlash { public verifyCompletionListContains(symbol: string, text?: string, documentation?: string, kind?: string) { var completions = this.getCompletionListAtCaret(); - this.assertItemInCompletionList(completions.entries, symbol, text, documentation, kind); + if (completions) { + this.assertItemInCompletionList(completions.entries, symbol, text, documentation, kind); + } + else { + this.raiseError(`No completions at position '${ this.currentCaretPosition }' when looking for '${ symbol }'.`); + } } public verifyCompletionListDoesNotContain(symbol: string) { @@ -699,7 +704,7 @@ module FourSlash { this.scenarioActions.push(''); var completions = this.getCompletionListAtCaret(); - if (completions && completions.entries && completions.entries.filter(e => e.name === symbol).length !== 0) { + if (completions && completions.entries.filter(e => e.name === symbol).length !== 0) { this.raiseError('Completion list did contain ' + symbol); } } From 88adb8fbb4a8f13f845adcb8f319e04993ca68da Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 17 Mar 2015 00:02:18 -0700 Subject: [PATCH 109/224] Added tests for completions before a new scope. Tests for #2292. --- .../cases/fourslash/completionListBeforeNewScope01.ts | 11 +++++++++++ .../cases/fourslash/completionListBeforeNewScope02.ts | 10 ++++++++++ 2 files changed, 21 insertions(+) create mode 100644 tests/cases/fourslash/completionListBeforeNewScope01.ts create mode 100644 tests/cases/fourslash/completionListBeforeNewScope02.ts diff --git a/tests/cases/fourslash/completionListBeforeNewScope01.ts b/tests/cases/fourslash/completionListBeforeNewScope01.ts new file mode 100644 index 0000000000000..79159744b8103 --- /dev/null +++ b/tests/cases/fourslash/completionListBeforeNewScope01.ts @@ -0,0 +1,11 @@ +/// + +////p/*1*/ +//// +////function fun(param) { +//// let party = Math.random() < 0.99; +////} + +goTo.marker("1"); +verify.not.completionListContains("param"); +verify.not.completionListContains("party"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListBeforeNewScope02.ts b/tests/cases/fourslash/completionListBeforeNewScope02.ts new file mode 100644 index 0000000000000..9df03ec10a449 --- /dev/null +++ b/tests/cases/fourslash/completionListBeforeNewScope02.ts @@ -0,0 +1,10 @@ +/// + +////a +//// +////{ +//// let aaaaaa = 10; +////} + +goTo.marker("1"); +verify.not.completionListContains("aaaaa"); \ No newline at end of file From 693da9a6df1b12fce9ba4b66bd49e4359b93eab0 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 17 Mar 2015 00:05:34 -0700 Subject: [PATCH 110/224] Added tests. --- .../completionListInClosedFunction01.ts | 12 +++++++++ .../completionListInClosedFunction02.ts | 18 +++++++++++++ .../completionListInClosedFunction03.ts | 19 ++++++++++++++ .../completionListInClosedFunction04.ts | 19 ++++++++++++++ .../completionListInClosedFunction05.ts | 21 ++++++++++++++++ .../completionListInClosedFunction06.ts | 14 +++++++++++ .../completionListInClosedFunction07.ts | 25 +++++++++++++++++++ ...tInClosedObjectTypeLiteralInSignature01.ts | 16 ++++++++++++ ...tInClosedObjectTypeLiteralInSignature02.ts | 16 ++++++++++++ ...tInClosedObjectTypeLiteralInSignature03.ts | 16 ++++++++++++ ...tInClosedObjectTypeLiteralInSignature04.ts | 16 ++++++++++++ .../completionListInUnclosedFunction01.ts | 12 +++++++++ .../completionListInUnclosedFunction02.ts | 16 ++++++++++++ .../completionListInUnclosedFunction03.ts | 17 +++++++++++++ .../completionListInUnclosedFunction04.ts | 16 ++++++++++++ .../completionListInUnclosedFunction05.ts | 17 +++++++++++++ .../completionListInUnclosedFunction06.ts | 17 +++++++++++++ .../completionListInUnclosedFunction07.ts | 17 +++++++++++++ .../completionListInUnclosedFunction08.ts | 19 ++++++++++++++ .../completionListInUnclosedFunction09.ts | 20 +++++++++++++++ .../completionListInUnclosedFunction10.ts | 12 +++++++++ .../completionListInUnclosedFunction11.ts | 12 +++++++++ .../completionListInUnclosedFunction12.ts | 13 ++++++++++ .../completionListInUnclosedFunction13.ts | 14 +++++++++++ .../completionListInUnclosedFunction14.ts | 25 +++++++++++++++++++ .../completionListInUnclosedFunction15.ts | 24 ++++++++++++++++++ .../completionListInUnclosedFunction16.ts | 23 +++++++++++++++++ .../completionListInUnclosedFunction17.ts | 23 +++++++++++++++++ .../completionListInUnclosedFunction18.ts | 24 ++++++++++++++++++ .../completionListInUnclosedFunction19.ts | 23 +++++++++++++++++ ...nUnclosedObjectTypeLiteralInSignature01.ts | 16 ++++++++++++ ...nUnclosedObjectTypeLiteralInSignature02.ts | 16 ++++++++++++ ...nUnclosedObjectTypeLiteralInSignature03.ts | 16 ++++++++++++ ...nUnclosedObjectTypeLiteralInSignature04.ts | 16 ++++++++++++ 34 files changed, 600 insertions(+) create mode 100644 tests/cases/fourslash/completionListInClosedFunction01.ts create mode 100644 tests/cases/fourslash/completionListInClosedFunction02.ts create mode 100644 tests/cases/fourslash/completionListInClosedFunction03.ts create mode 100644 tests/cases/fourslash/completionListInClosedFunction04.ts create mode 100644 tests/cases/fourslash/completionListInClosedFunction05.ts create mode 100644 tests/cases/fourslash/completionListInClosedFunction06.ts create mode 100644 tests/cases/fourslash/completionListInClosedFunction07.ts create mode 100644 tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature01.ts create mode 100644 tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature02.ts create mode 100644 tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature03.ts create mode 100644 tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature04.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedFunction01.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedFunction02.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedFunction03.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedFunction04.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedFunction05.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedFunction06.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedFunction07.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedFunction08.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedFunction09.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedFunction10.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedFunction11.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedFunction12.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedFunction13.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedFunction14.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedFunction15.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedFunction16.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedFunction17.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedFunction18.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedFunction19.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature01.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature02.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature03.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature04.ts diff --git a/tests/cases/fourslash/completionListInClosedFunction01.ts b/tests/cases/fourslash/completionListInClosedFunction01.ts new file mode 100644 index 0000000000000..7c9c2a2013952 --- /dev/null +++ b/tests/cases/fourslash/completionListInClosedFunction01.ts @@ -0,0 +1,12 @@ +/// + +////function foo(x: string, y: number, z: boolean) { +//// /*1*/ +////} + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInClosedFunction02.ts b/tests/cases/fourslash/completionListInClosedFunction02.ts new file mode 100644 index 0000000000000..a2ae8a9da83fb --- /dev/null +++ b/tests/cases/fourslash/completionListInClosedFunction02.ts @@ -0,0 +1,18 @@ +/// + +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string, c: typeof /*1*/) { +//// } +////} + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); + +verify.memberListContains("bar"); +verify.memberListContains("a"); +verify.memberListContains("b"); +verify.memberListContains("c"); // questionable \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInClosedFunction03.ts b/tests/cases/fourslash/completionListInClosedFunction03.ts new file mode 100644 index 0000000000000..b1a10a4a4b292 --- /dev/null +++ b/tests/cases/fourslash/completionListInClosedFunction03.ts @@ -0,0 +1,19 @@ +/// + +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string, c: typeof x = /*1*/) { +//// +//// } +////} + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); + +verify.memberListContains("bar"); +verify.memberListContains("a"); +verify.memberListContains("b"); +verify.memberListContains("c"); // questionable \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInClosedFunction04.ts b/tests/cases/fourslash/completionListInClosedFunction04.ts new file mode 100644 index 0000000000000..fcc7d070eb7b2 --- /dev/null +++ b/tests/cases/fourslash/completionListInClosedFunction04.ts @@ -0,0 +1,19 @@ +/// + +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string = /*1*/, c: typeof x = "hello") { +//// +//// } +////} + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); + +verify.memberListContains("bar"); +verify.memberListContains("a"); +verify.memberListContains("b"); +verify.memberListContains("c"); // definitely questionable \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInClosedFunction05.ts b/tests/cases/fourslash/completionListInClosedFunction05.ts new file mode 100644 index 0000000000000..7ec3985caf0b5 --- /dev/null +++ b/tests/cases/fourslash/completionListInClosedFunction05.ts @@ -0,0 +1,21 @@ +/// + +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string = "hello", c: typeof x = "hello") { +//// var v = /*1*/ +//// } +////} + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); + +verify.memberListContains("bar"); +verify.memberListContains("a"); +verify.memberListContains("b"); +verify.memberListContains("c"); + +verify.memberListContains("v"); // questionable \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInClosedFunction06.ts b/tests/cases/fourslash/completionListInClosedFunction06.ts new file mode 100644 index 0000000000000..f1aed3ad1a472 --- /dev/null +++ b/tests/cases/fourslash/completionListInClosedFunction06.ts @@ -0,0 +1,14 @@ +/// + +////interface MyType { +////} +//// +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string = "hello", c: typeof x = "hello") { +//// var v = (x: /*1*/); +//// } +////} + +goTo.marker("1"); + +verify.memberListContains("MyType"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInClosedFunction07.ts b/tests/cases/fourslash/completionListInClosedFunction07.ts new file mode 100644 index 0000000000000..13b9f5787deb0 --- /dev/null +++ b/tests/cases/fourslash/completionListInClosedFunction07.ts @@ -0,0 +1,25 @@ +/// + +////interface MyType { +////} +//// +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string = "hello", c: typeof x = "hello") { +//// var v = (p: MyType) => /*1*/; +//// } +////} + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); + +verify.memberListContains("bar"); +verify.memberListContains("a"); +verify.memberListContains("b"); +verify.memberListContains("c"); + +verify.memberListContains("v"); +verify.memberListContains("p"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature01.ts b/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature01.ts new file mode 100644 index 0000000000000..5e7d8b304842d --- /dev/null +++ b/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature01.ts @@ -0,0 +1,16 @@ +/// + +////interface I { +//// [s: string]: TString; +//// [s: number]: TNumber; +////} +//// +////declare function foo(obj: I): { str: T/*1*/ } + +goTo.marker("1"); + +verify.memberListContains("I"); +verify.memberListContains("TString"); +verify.memberListContains("TNumber"); +verify.not.memberListContains("foo"); +verify.not.memberListContains("obj"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature02.ts b/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature02.ts new file mode 100644 index 0000000000000..ee0e1e8b90cdf --- /dev/null +++ b/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature02.ts @@ -0,0 +1,16 @@ +/// + +////interface I { +//// [s: string]: TString; +//// [s: number]: TNumber; +////} +//// +////declare function foo(obj: I): { str: TStr/*1*/ } + +goTo.marker("1"); + +verify.memberListContains("I"); +verify.memberListContains("TString"); +verify.not.memberListContains("TNumber"); +verify.not.memberListContains("foo"); +verify.not.memberListContains("obj"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature03.ts b/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature03.ts new file mode 100644 index 0000000000000..cdc4e9effff7b --- /dev/null +++ b/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature03.ts @@ -0,0 +1,16 @@ +/// + +////interface I { +//// [s: string]: TString; +//// [s: number]: TNumber; +////} +//// +////declare function foo(obj: I): { str: TString/*1*/ } + +goTo.marker("1"); + +verify.memberListContains("I"); +verify.memberListContains("TString"); +verify.not.memberListContains("TNumber"); +verify.not.memberListContains("foo"); +verify.not.memberListContains("obj"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature04.ts b/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature04.ts new file mode 100644 index 0000000000000..a45d98ad4df4f --- /dev/null +++ b/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature04.ts @@ -0,0 +1,16 @@ +/// + +////interface I { +//// [s: string]: TString; +//// [s: number]: TNumber; +////} +//// +////declare function foo(obj: I): { /*1*/ } + +goTo.marker("1"); + +verify.not.memberListContains("I"); +verify.not.memberListContains("TString"); +verify.not.memberListContains("TNumber"); +verify.not.memberListContains("foo"); +verify.not.memberListContains("obj"); diff --git a/tests/cases/fourslash/completionListInUnclosedFunction01.ts b/tests/cases/fourslash/completionListInUnclosedFunction01.ts new file mode 100644 index 0000000000000..4d33d1220f7a7 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedFunction01.ts @@ -0,0 +1,12 @@ +/// + +////function foo(x: string, y: number, z: boolean) { +//// /*1*/ +//// + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedFunction02.ts b/tests/cases/fourslash/completionListInUnclosedFunction02.ts new file mode 100644 index 0000000000000..c0c79e944332b --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedFunction02.ts @@ -0,0 +1,16 @@ +/// + +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string, c: typeof /*1*/ + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); + +verify.memberListContains("bar"); +verify.memberListContains("a"); +verify.memberListContains("b"); +verify.memberListContains("c"); // questionable \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedFunction03.ts b/tests/cases/fourslash/completionListInUnclosedFunction03.ts new file mode 100644 index 0000000000000..d8b3a0a132f7e --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedFunction03.ts @@ -0,0 +1,17 @@ +/// + +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string, c: typeof /*1*/ +////} + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); + +verify.memberListContains("bar"); +verify.memberListContains("a"); +verify.memberListContains("b"); +verify.memberListContains("c"); // questionable \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedFunction04.ts b/tests/cases/fourslash/completionListInUnclosedFunction04.ts new file mode 100644 index 0000000000000..e56978732c261 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedFunction04.ts @@ -0,0 +1,16 @@ +/// + +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string, c: typeof x = /*1*/ + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); + +verify.memberListContains("bar"); +verify.memberListContains("a"); +verify.memberListContains("b"); +verify.memberListContains("c"); // questionable \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedFunction05.ts b/tests/cases/fourslash/completionListInUnclosedFunction05.ts new file mode 100644 index 0000000000000..748a334f860da --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedFunction05.ts @@ -0,0 +1,17 @@ +/// + +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string, c: typeof x = /*1*/ +////} + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); + +verify.memberListContains("bar"); +verify.memberListContains("a"); +verify.memberListContains("b"); +verify.memberListContains("c"); // questionable \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedFunction06.ts b/tests/cases/fourslash/completionListInUnclosedFunction06.ts new file mode 100644 index 0000000000000..3ceaff78039c8 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedFunction06.ts @@ -0,0 +1,17 @@ +/// + +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string = /*1*/, c: typeof x = "hello" +//// + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); + +verify.memberListContains("bar"); +verify.memberListContains("a"); +verify.memberListContains("b"); +verify.memberListContains("c"); // definitely questionable \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedFunction07.ts b/tests/cases/fourslash/completionListInUnclosedFunction07.ts new file mode 100644 index 0000000000000..6968a878a771c --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedFunction07.ts @@ -0,0 +1,17 @@ +/// + +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string = /*1*/, c: typeof x = "hello" +////} + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); + +verify.memberListContains("bar"); +verify.memberListContains("a"); +verify.memberListContains("b"); +verify.memberListContains("c"); // definitely questionable \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedFunction08.ts b/tests/cases/fourslash/completionListInUnclosedFunction08.ts new file mode 100644 index 0000000000000..5e8b15941c19a --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedFunction08.ts @@ -0,0 +1,19 @@ +/// + +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string = "hello", c: typeof x = "hello") { +//// var v = /*1*/ + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); + +verify.memberListContains("bar"); +verify.memberListContains("a"); +verify.memberListContains("b"); +verify.memberListContains("c"); + +verify.memberListContains("v"); // questionable \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedFunction09.ts b/tests/cases/fourslash/completionListInUnclosedFunction09.ts new file mode 100644 index 0000000000000..0171ef96342a9 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedFunction09.ts @@ -0,0 +1,20 @@ +/// + +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string = "hello", c: typeof x = "hello") { +//// var v = /*1*/ +////} + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); + +verify.memberListContains("bar"); +verify.memberListContains("a"); +verify.memberListContains("b"); +verify.memberListContains("c"); + +verify.memberListContains("v"); // questionable \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedFunction10.ts b/tests/cases/fourslash/completionListInUnclosedFunction10.ts new file mode 100644 index 0000000000000..1d0162b600b6c --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedFunction10.ts @@ -0,0 +1,12 @@ +/// + +////interface MyType { +////} +//// +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string = "hello", c: typeof x = "hello") { +//// var v = (p: /*1*/ + +goTo.marker("1"); + +verify.memberListContains("MyType"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedFunction11.ts b/tests/cases/fourslash/completionListInUnclosedFunction11.ts new file mode 100644 index 0000000000000..1d0162b600b6c --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedFunction11.ts @@ -0,0 +1,12 @@ +/// + +////interface MyType { +////} +//// +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string = "hello", c: typeof x = "hello") { +//// var v = (p: /*1*/ + +goTo.marker("1"); + +verify.memberListContains("MyType"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedFunction12.ts b/tests/cases/fourslash/completionListInUnclosedFunction12.ts new file mode 100644 index 0000000000000..b0e36b2fb8a7a --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedFunction12.ts @@ -0,0 +1,13 @@ +/// + +////interface MyType { +////} +//// +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string = "hello", c: typeof x = "hello") { +//// var v = (p: /*1*/ +////} + +goTo.marker("1"); + +verify.memberListContains("MyType"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedFunction13.ts b/tests/cases/fourslash/completionListInUnclosedFunction13.ts new file mode 100644 index 0000000000000..8e1334941ad4e --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedFunction13.ts @@ -0,0 +1,14 @@ +/// + +////interface MyType { +////} +//// +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string = "hello", c: typeof x = "hello") { +//// var v = (p: /*1*/ +//// } +////} + +goTo.marker("1"); + +verify.memberListContains("MyType"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedFunction14.ts b/tests/cases/fourslash/completionListInUnclosedFunction14.ts new file mode 100644 index 0000000000000..412fcd8667022 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedFunction14.ts @@ -0,0 +1,25 @@ +/// + +////interface MyType { +////} +//// +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string = "hello", c: typeof x = "hello") { +//// var v = (p: MyType) => /*1*/ +//// } +////} + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); + +verify.memberListContains("bar"); +verify.memberListContains("a"); +verify.memberListContains("b"); +verify.memberListContains("c"); + +verify.memberListContains("v"); +verify.memberListContains("p"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedFunction15.ts b/tests/cases/fourslash/completionListInUnclosedFunction15.ts new file mode 100644 index 0000000000000..73a59795396a3 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedFunction15.ts @@ -0,0 +1,24 @@ +/// + +////interface MyType { +////} +//// +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string = "hello", c: typeof x = "hello") { +//// var v = (p: MyType) => /*1*/ +////} + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); + +verify.memberListContains("bar"); +verify.memberListContains("a"); +verify.memberListContains("b"); +verify.memberListContains("c"); + +verify.memberListContains("v"); +verify.memberListContains("p"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedFunction16.ts b/tests/cases/fourslash/completionListInUnclosedFunction16.ts new file mode 100644 index 0000000000000..4ec5f41df5343 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedFunction16.ts @@ -0,0 +1,23 @@ +/// + +////interface MyType { +////} +//// +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string = "hello", c: typeof x = "hello") { +//// var v = (p: MyType) => /*1*/ + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); + +verify.memberListContains("bar"); +verify.memberListContains("a"); +verify.memberListContains("b"); +verify.memberListContains("c"); + +verify.memberListContains("v"); +verify.memberListContains("p"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedFunction17.ts b/tests/cases/fourslash/completionListInUnclosedFunction17.ts new file mode 100644 index 0000000000000..8cded845673b5 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedFunction17.ts @@ -0,0 +1,23 @@ +/// + +////interface MyType { +////} +//// +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string = "hello", c: typeof x = "hello") { +//// var v = (p: MyType) => y + /*1*/ + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); + +verify.memberListContains("bar"); +verify.memberListContains("a"); +verify.memberListContains("b"); +verify.memberListContains("c"); + +verify.memberListContains("v"); +verify.memberListContains("p"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedFunction18.ts b/tests/cases/fourslash/completionListInUnclosedFunction18.ts new file mode 100644 index 0000000000000..182694d73d2a9 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedFunction18.ts @@ -0,0 +1,24 @@ +/// + +////interface MyType { +////} +//// +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string = "hello", c: typeof x = "hello") { +//// var v = (p: MyType) => y + /*1*/ +////} + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); + +verify.memberListContains("bar"); +verify.memberListContains("a"); +verify.memberListContains("b"); +verify.memberListContains("c"); + +verify.memberListContains("v"); +verify.memberListContains("p"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedFunction19.ts b/tests/cases/fourslash/completionListInUnclosedFunction19.ts new file mode 100644 index 0000000000000..6f49f2702507b --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedFunction19.ts @@ -0,0 +1,23 @@ +/// + +////interface MyType { +////} +//// +////function foo(x: string, y: number, z: boolean) { +//// function bar(a: number, b: string = "hello", c: typeof x = "hello") { +//// var v = (p: MyType) => { return y + /*1*/ + +goTo.marker("1"); + +verify.memberListContains("foo"); +verify.memberListContains("x"); +verify.memberListContains("y"); +verify.memberListContains("z"); + +verify.memberListContains("bar"); +verify.memberListContains("a"); +verify.memberListContains("b"); +verify.memberListContains("c"); + +verify.memberListContains("v"); +verify.memberListContains("p"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature01.ts b/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature01.ts new file mode 100644 index 0000000000000..888c6eeed0c11 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature01.ts @@ -0,0 +1,16 @@ +/// + +////interface I { +//// [s: string]: TString; +//// [s: number]: TNumber; +////} +//// +////declare function foo(obj: I): { str: T/*1*/ + +goTo.marker("1"); + +verify.memberListContains("I"); +verify.memberListContains("TString"); +verify.memberListContains("TNumber"); +verify.not.memberListContains("foo"); +verify.not.memberListContains("obj"); diff --git a/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature02.ts b/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature02.ts new file mode 100644 index 0000000000000..15372ccea0d03 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature02.ts @@ -0,0 +1,16 @@ +/// + +////interface I { +//// [s: string]: TString; +//// [s: number]: TNumber; +////} +//// +////declare function foo(obj: I): { str: TStr/*1*/ + +goTo.marker("1"); + +verify.memberListContains("I"); +verify.memberListContains("TString"); +verify.not.memberListContains("TNumber"); +verify.not.memberListContains("foo"); +verify.not.memberListContains("obj"); diff --git a/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature03.ts b/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature03.ts new file mode 100644 index 0000000000000..22821eb1084f8 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature03.ts @@ -0,0 +1,16 @@ +/// + +////interface I { +//// [s: string]: TString; +//// [s: number]: TNumber; +////} +//// +////declare function foo(obj: I): { str: TString/*1*/ + +goTo.marker("1"); + +verify.memberListContains("I"); +verify.memberListContains("TString"); +verify.not.memberListContains("TNumber"); +verify.not.memberListContains("foo"); +verify.not.memberListContains("obj"); diff --git a/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature04.ts b/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature04.ts new file mode 100644 index 0000000000000..c7f53e0e0dfec --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature04.ts @@ -0,0 +1,16 @@ +/// + +////interface I { +//// [s: string]: TString; +//// [s: number]: TNumber; +////} +//// +////declare function foo(obj: I): { /*1*/ + +goTo.marker("1"); + +verify.not.memberListContains("I"); +verify.not.memberListContains("TString"); +verify.not.memberListContains("TNumber"); +verify.not.memberListContains("foo"); +verify.not.memberListContains("obj"); From 8eae639a94335c78b4350ec98bf053b00eff6814 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 17 Mar 2015 00:06:18 -0700 Subject: [PATCH 111/224] Added tests for #1410. --- ...mpletionListInArrowFunctionInUnclosedCallSite01.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 tests/cases/fourslash/completionListInArrowFunctionInUnclosedCallSite01.ts diff --git a/tests/cases/fourslash/completionListInArrowFunctionInUnclosedCallSite01.ts b/tests/cases/fourslash/completionListInArrowFunctionInUnclosedCallSite01.ts new file mode 100644 index 0000000000000..82e4c6e4d1560 --- /dev/null +++ b/tests/cases/fourslash/completionListInArrowFunctionInUnclosedCallSite01.ts @@ -0,0 +1,11 @@ +/// + +////declare function foo(...params: any[]): any; +////function getAllFiles(rootFileNames: string[]) { +//// var processedFiles = rootFileNames.map(fileName => foo(/*1*/ + +goTo.marker("1"); +verify.not.completionListContains("fileName"); +verify.not.completionListContains("rootFileNames"); +verify.not.completionListContains("getAllFiles"); +verify.not.completionListContains("foo"); \ No newline at end of file From 92955a8f8d06af2cbdf47bd95b30f4a8181ca7a6 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 17 Mar 2015 00:32:57 -0700 Subject: [PATCH 112/224] Fixed up tests. --- ...pletionListInUnclosedObjectTypeLiteralInSignature01.ts | 6 ++++-- ...pletionListInUnclosedObjectTypeLiteralInSignature02.ts | 8 +++++--- ...pletionListInUnclosedObjectTypeLiteralInSignature03.ts | 8 +++++--- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature01.ts b/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature01.ts index 888c6eeed0c11..a931bed6a4b77 100644 --- a/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature01.ts +++ b/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature01.ts @@ -12,5 +12,7 @@ goTo.marker("1"); verify.memberListContains("I"); verify.memberListContains("TString"); verify.memberListContains("TNumber"); -verify.not.memberListContains("foo"); -verify.not.memberListContains("obj"); + +// Ideally the following shouldn't show up since they're not types. +verify.memberListContains("foo"); +verify.memberListContains("obj"); diff --git a/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature02.ts b/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature02.ts index 15372ccea0d03..32a9504ebc348 100644 --- a/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature02.ts +++ b/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature02.ts @@ -11,6 +11,8 @@ goTo.marker("1"); verify.memberListContains("I"); verify.memberListContains("TString"); -verify.not.memberListContains("TNumber"); -verify.not.memberListContains("foo"); -verify.not.memberListContains("obj"); +verify.memberListContains("TNumber"); // REVIEW: Is this intended behavior? + +// Ideally the following shouldn't show up since they're not types. +verify.memberListContains("foo"); +verify.memberListContains("obj"); diff --git a/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature03.ts b/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature03.ts index 22821eb1084f8..455f122888c35 100644 --- a/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature03.ts +++ b/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature03.ts @@ -11,6 +11,8 @@ goTo.marker("1"); verify.memberListContains("I"); verify.memberListContains("TString"); -verify.not.memberListContains("TNumber"); -verify.not.memberListContains("foo"); -verify.not.memberListContains("obj"); +verify.memberListContains("TNumber"); // REVIEW: Is this intended behavior? + +// Ideally the following shouldn't show up since they're not types. +verify.memberListContains("foo"); +verify.memberListContains("obj"); From c27e07a69b57dcc99a82fa127f7e1f626eaf3139 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 17 Mar 2015 00:33:58 -0700 Subject: [PATCH 113/224] Moved logic from smart indenter; use 'scope nodes' for completions. --- src/services/formatting/smartIndenter.ts | 123 +---------------------- src/services/services.ts | 11 +- src/services/utilities.ts | 118 ++++++++++++++++++++++ 3 files changed, 129 insertions(+), 123 deletions(-) diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index 0932ad042e7b0..050468cb9da1b 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -215,11 +215,7 @@ module ts.formatting { function getStartLineAndCharacterForNode(n: Node, sourceFile: SourceFile): LineAndCharacter { return sourceFile.getLineAndCharacterOfPosition(n.getStart(sourceFile)); } - - function positionBelongsToNode(candidate: Node, position: number, sourceFile: SourceFile): boolean { - return candidate.end > position || !isCompletedNode(candidate, sourceFile); - } - + export function childStartsOnTheSameLineWithElseInIfStatement(parent: Node, child: TextRangeWithKind, childStartLine: number, sourceFile: SourceFile): boolean { if (parent.kind === SyntaxKind.IfStatement && (parent).elseStatement === child) { var elseKeyword = findChildOfKind(parent, SyntaxKind.ElseKeyword, sourceFile); @@ -401,122 +397,5 @@ module ts.formatting { return false; } } - - /* - * Checks if node ends with 'expectedLastToken'. - * If child at position 'length - 1' is 'SemicolonToken' it is skipped and 'expectedLastToken' is compared with child at position 'length - 2'. - */ - function nodeEndsWith(n: Node, expectedLastToken: SyntaxKind, sourceFile: SourceFile): boolean { - var children = n.getChildren(sourceFile); - if (children.length) { - var last = children[children.length - 1]; - if (last.kind === expectedLastToken) { - return true; - } - else if (last.kind === SyntaxKind.SemicolonToken && children.length !== 1) { - return children[children.length - 2].kind === expectedLastToken; - } - } - return false; - } - - /* - * This function is always called when position of the cursor is located after the node - */ - function isCompletedNode(n: Node, sourceFile: SourceFile): boolean { - if (n.getFullWidth() === 0) { - return false; - } - - switch (n.kind) { - case SyntaxKind.ClassDeclaration: - case SyntaxKind.InterfaceDeclaration: - case SyntaxKind.EnumDeclaration: - case SyntaxKind.ObjectLiteralExpression: - case SyntaxKind.ObjectBindingPattern: - case SyntaxKind.TypeLiteral: - case SyntaxKind.Block: - case SyntaxKind.ModuleBlock: - case SyntaxKind.CaseBlock: - return nodeEndsWith(n, SyntaxKind.CloseBraceToken, sourceFile); - case SyntaxKind.CatchClause: - return isCompletedNode((n).block, sourceFile); - case SyntaxKind.NewExpression: - if (!(n).arguments) { - return true; - } - // fall through - case SyntaxKind.CallExpression: - case SyntaxKind.ParenthesizedExpression: - case SyntaxKind.ParenthesizedType: - return nodeEndsWith(n, SyntaxKind.CloseParenToken, sourceFile); - - case SyntaxKind.FunctionType: - case SyntaxKind.ConstructorType: - return isCompletedNode((n).type, sourceFile); - - case SyntaxKind.Constructor: - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - case SyntaxKind.FunctionDeclaration: - case SyntaxKind.FunctionExpression: - case SyntaxKind.MethodDeclaration: - case SyntaxKind.MethodSignature: - case SyntaxKind.ConstructSignature: - case SyntaxKind.CallSignature: - case SyntaxKind.ArrowFunction: - if ((n).body) { - return isCompletedNode((n).body, sourceFile); - } - - if ((n).type) { - return isCompletedNode((n).type, sourceFile); - } - - // Even though type parameters can be unclosed, we can get away with - // having at least a closing paren. - return hasChildOfKind(n, SyntaxKind.CloseParenToken, sourceFile); - - case SyntaxKind.ModuleDeclaration: - return (n).body && isCompletedNode((n).body, sourceFile); - - case SyntaxKind.IfStatement: - if ((n).elseStatement) { - return isCompletedNode((n).elseStatement, sourceFile); - } - return isCompletedNode((n).thenStatement, sourceFile); - - case SyntaxKind.ExpressionStatement: - return isCompletedNode((n).expression, sourceFile); - - case SyntaxKind.ArrayLiteralExpression: - case SyntaxKind.ArrayBindingPattern: - case SyntaxKind.IndexSignature: - case SyntaxKind.ComputedPropertyName: - case SyntaxKind.TupleType: - return nodeEndsWith(n, SyntaxKind.CloseBracketToken, sourceFile); - - case SyntaxKind.CaseClause: - case SyntaxKind.DefaultClause: - // there is no such thing as terminator token for CaseClause/DefaultClause so for simplicitly always consider them non-completed - return false; - - case SyntaxKind.ForStatement: - case SyntaxKind.ForInStatement: - case SyntaxKind.ForOfStatement: - case SyntaxKind.WhileStatement: - return isCompletedNode((n).statement, sourceFile); - case SyntaxKind.DoStatement: - // rough approximation: if DoStatement has While keyword - then if node is completed is checking the presence of ')'; - var hasWhileKeyword = findChildOfKind(n, SyntaxKind.WhileKeyword, sourceFile); - if (hasWhileKeyword) { - return nodeEndsWith(n, SyntaxKind.CloseParenToken, sourceFile); - } - return isCompletedNode((n).statement, sourceFile); - - default: - return true; - } - } } } \ No newline at end of file diff --git a/src/services/services.ts b/src/services/services.ts index 61d7a0736b0af..e9d207bddea10 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2595,8 +2595,9 @@ module ts { isNewIdentifierLocation = isNewIdentifierDefinitionLocation(previousToken); /// TODO filter meaning based on the current context + var scopeNode = getScopeNode(previousToken, position, sourceFile); var symbolMeanings = SymbolFlags.Type | SymbolFlags.Value | SymbolFlags.Namespace | SymbolFlags.Alias; - var symbols = typeInfoResolver.getSymbolsInScope(node, symbolMeanings); + var symbols = typeInfoResolver.getSymbolsInScope(scopeNode, symbolMeanings); getCompletionEntriesFromSymbols(symbols, activeCompletionSession); } @@ -2615,6 +2616,14 @@ module ts { entries: activeCompletionSession.entries }; + function getScopeNode(initialToken: Node, position: number, sourceFile: SourceFile) { + var scope = initialToken; + while (scope && (isToken(scope) || !positionBelongsToNode(scope, position, sourceFile))) { + scope = scope.parent; + } + return scope; + } + function getCompletionEntriesFromSymbols(symbols: Symbol[], session: CompletionSession): void { var start = new Date().getTime(); forEach(symbols, symbol => { diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 70c8eada5b738..11337b40e9d4e 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -59,6 +59,124 @@ module ts { return start < end; } + export function positionBelongsToNode(candidate: Node, position: number, sourceFile: SourceFile): boolean { + return candidate.end > position || !isCompletedNode(candidate, sourceFile); + } + + export function isCompletedNode(n: Node, sourceFile: SourceFile): boolean { + if (n.getFullWidth() === 0) { + return false; + } + + switch (n.kind) { + case SyntaxKind.ClassDeclaration: + case SyntaxKind.InterfaceDeclaration: + case SyntaxKind.EnumDeclaration: + case SyntaxKind.ObjectLiteralExpression: + case SyntaxKind.ObjectBindingPattern: + case SyntaxKind.TypeLiteral: + case SyntaxKind.Block: + case SyntaxKind.ModuleBlock: + case SyntaxKind.CaseBlock: + return nodeEndsWith(n, SyntaxKind.CloseBraceToken, sourceFile); + case SyntaxKind.CatchClause: + return isCompletedNode((n).block, sourceFile); + case SyntaxKind.NewExpression: + if (!(n).arguments) { + return true; + } + // fall through + case SyntaxKind.CallExpression: + case SyntaxKind.ParenthesizedExpression: + case SyntaxKind.ParenthesizedType: + return nodeEndsWith(n, SyntaxKind.CloseParenToken, sourceFile); + + case SyntaxKind.FunctionType: + case SyntaxKind.ConstructorType: + return isCompletedNode((n).type, sourceFile); + + case SyntaxKind.Constructor: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.FunctionExpression: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: + case SyntaxKind.ConstructSignature: + case SyntaxKind.CallSignature: + case SyntaxKind.ArrowFunction: + if ((n).body) { + return isCompletedNode((n).body, sourceFile); + } + + if ((n).type) { + return isCompletedNode((n).type, sourceFile); + } + + // Even though type parameters can be unclosed, we can get away with + // having at least a closing paren. + return hasChildOfKind(n, SyntaxKind.CloseParenToken, sourceFile); + + case SyntaxKind.ModuleDeclaration: + return (n).body && isCompletedNode((n).body, sourceFile); + + case SyntaxKind.IfStatement: + if ((n).elseStatement) { + return isCompletedNode((n).elseStatement, sourceFile); + } + return isCompletedNode((n).thenStatement, sourceFile); + + case SyntaxKind.ExpressionStatement: + return isCompletedNode((n).expression, sourceFile); + + case SyntaxKind.ArrayLiteralExpression: + case SyntaxKind.ArrayBindingPattern: + case SyntaxKind.IndexSignature: + case SyntaxKind.ComputedPropertyName: + case SyntaxKind.TupleType: + return nodeEndsWith(n, SyntaxKind.CloseBracketToken, sourceFile); + + case SyntaxKind.CaseClause: + case SyntaxKind.DefaultClause: + // there is no such thing as terminator token for CaseClause/DefaultClause so for simplicitly always consider them non-completed + return false; + + case SyntaxKind.ForStatement: + case SyntaxKind.ForInStatement: + case SyntaxKind.ForOfStatement: + case SyntaxKind.WhileStatement: + return isCompletedNode((n).statement, sourceFile); + case SyntaxKind.DoStatement: + // rough approximation: if DoStatement has While keyword - then if node is completed is checking the presence of ')'; + var hasWhileKeyword = findChildOfKind(n, SyntaxKind.WhileKeyword, sourceFile); + if (hasWhileKeyword) { + return nodeEndsWith(n, SyntaxKind.CloseParenToken, sourceFile); + } + return isCompletedNode((n).statement, sourceFile); + + default: + return true; + } + } + + /* + * Checks if node ends with 'expectedLastToken'. + * If child at position 'length - 1' is 'SemicolonToken' it is skipped and 'expectedLastToken' is compared with child at position 'length - 2'. + */ + function nodeEndsWith(n: Node, expectedLastToken: SyntaxKind, sourceFile: SourceFile): boolean { + var children = n.getChildren(sourceFile); + if (children.length) { + var last = children[children.length - 1]; + if (last.kind === expectedLastToken) { + return true; + } + else if (last.kind === SyntaxKind.SemicolonToken && children.length !== 1) { + return children[children.length - 2].kind === expectedLastToken; + } + } + return false; + } + export function findListItemInfo(node: Node): ListItemInfo { var list = findContainingList(node); From f1d5582a69ba1d36de21f47ebab2b15a1b1523be Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 17 Mar 2015 00:39:46 -0700 Subject: [PATCH 114/224] Fixed missing marker. --- tests/cases/fourslash/completionListBeforeNewScope02.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cases/fourslash/completionListBeforeNewScope02.ts b/tests/cases/fourslash/completionListBeforeNewScope02.ts index 9df03ec10a449..9fb1182b56e0a 100644 --- a/tests/cases/fourslash/completionListBeforeNewScope02.ts +++ b/tests/cases/fourslash/completionListBeforeNewScope02.ts @@ -1,6 +1,6 @@ /// -////a +////a/*1*/ //// ////{ //// let aaaaaa = 10; From c30b71db2ce37123953fed23eb63992464b50011 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 17 Mar 2015 00:41:09 -0700 Subject: [PATCH 115/224] Removed negations from test. --- .../completionListInArrowFunctionInUnclosedCallSite01.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/cases/fourslash/completionListInArrowFunctionInUnclosedCallSite01.ts b/tests/cases/fourslash/completionListInArrowFunctionInUnclosedCallSite01.ts index 82e4c6e4d1560..633dc00a94146 100644 --- a/tests/cases/fourslash/completionListInArrowFunctionInUnclosedCallSite01.ts +++ b/tests/cases/fourslash/completionListInArrowFunctionInUnclosedCallSite01.ts @@ -5,7 +5,7 @@ //// var processedFiles = rootFileNames.map(fileName => foo(/*1*/ goTo.marker("1"); -verify.not.completionListContains("fileName"); -verify.not.completionListContains("rootFileNames"); -verify.not.completionListContains("getAllFiles"); -verify.not.completionListContains("foo"); \ No newline at end of file +verify.completionListContains("fileName"); +verify.completionListContains("rootFileNames"); +verify.completionListContains("getAllFiles"); +verify.completionListContains("foo"); \ No newline at end of file From 34a3fc4f78fdf40ea2973fbb3ad02303b18212e8 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 17 Mar 2015 00:44:13 -0700 Subject: [PATCH 116/224] Fixed up more tests. --- ...ompletionListInClosedObjectTypeLiteralInSignature01.ts | 6 ++++-- ...ompletionListInClosedObjectTypeLiteralInSignature02.ts | 8 +++++--- ...ompletionListInClosedObjectTypeLiteralInSignature03.ts | 8 +++++--- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature01.ts b/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature01.ts index 5e7d8b304842d..690fb583f674b 100644 --- a/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature01.ts +++ b/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature01.ts @@ -12,5 +12,7 @@ goTo.marker("1"); verify.memberListContains("I"); verify.memberListContains("TString"); verify.memberListContains("TNumber"); -verify.not.memberListContains("foo"); -verify.not.memberListContains("obj"); \ No newline at end of file + +// Ideally the following shouldn't show up since they're not types. +verify.memberListContains("foo"); +verify.memberListContains("obj"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature02.ts b/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature02.ts index ee0e1e8b90cdf..57af3592d4492 100644 --- a/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature02.ts +++ b/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature02.ts @@ -11,6 +11,8 @@ goTo.marker("1"); verify.memberListContains("I"); verify.memberListContains("TString"); -verify.not.memberListContains("TNumber"); -verify.not.memberListContains("foo"); -verify.not.memberListContains("obj"); \ No newline at end of file +verify.memberListContains("TNumber"); // REVIEW: Is this intended behavior? + +// Ideally the following shouldn't show up since they're not types. +verify.memberListContains("foo"); +verify.memberListContains("obj"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature03.ts b/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature03.ts index cdc4e9effff7b..1e5e6256d6ef2 100644 --- a/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature03.ts +++ b/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature03.ts @@ -11,6 +11,8 @@ goTo.marker("1"); verify.memberListContains("I"); verify.memberListContains("TString"); -verify.not.memberListContains("TNumber"); -verify.not.memberListContains("foo"); -verify.not.memberListContains("obj"); \ No newline at end of file +verify.memberListContains("TNumber"); // REVIEW: Is this intended behavior? + +// Ideally the following shouldn't show up since they're not types. +verify.memberListContains("foo"); +verify.memberListContains("obj"); \ No newline at end of file From c89febeb238452402bfb5ffe802d1c424e9381b0 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 17 Mar 2015 00:46:21 -0700 Subject: [PATCH 117/224] Added completion check for prefix-unary, binary, and conditional expressions. --- src/services/utilities.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 11337b40e9d4e..cd7d48e7d0a3e 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -154,6 +154,13 @@ module ts { } return isCompletedNode((n).statement, sourceFile); + case SyntaxKind.PrefixUnaryExpression: + return isCompletedNode(n, sourceFile); + case SyntaxKind.BinaryExpression: + return isCompletedNode((n).right, sourceFile); + case SyntaxKind.ConditionalExpression: + return isCompletedNode((n).whenFalse, sourceFile); + default: return true; } From 857d1e0bb653959a36b4808bc805712386bd6b02 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 17 Mar 2015 07:42:24 -0700 Subject: [PATCH 118/224] Fixed case for index signatures. --- src/services/formatting/smartIndenter.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index 0932ad042e7b0..be21b69f56b45 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -491,11 +491,17 @@ module ts.formatting { case SyntaxKind.ArrayLiteralExpression: case SyntaxKind.ArrayBindingPattern: - case SyntaxKind.IndexSignature: case SyntaxKind.ComputedPropertyName: case SyntaxKind.TupleType: return nodeEndsWith(n, SyntaxKind.CloseBracketToken, sourceFile); + case SyntaxKind.IndexSignature: + if ((n).type) { + return isCompletedNode((n).type, sourceFile); + } + + return hasChildOfKind(n, SyntaxKind.CloseBracketToken, sourceFile); + case SyntaxKind.CaseClause: case SyntaxKind.DefaultClause: // there is no such thing as terminator token for CaseClause/DefaultClause so for simplicitly always consider them non-completed From f2a7367e9b63a2155d45708ac5b54161f8579926 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 17 Mar 2015 07:50:15 -0700 Subject: [PATCH 119/224] Added index signature case. --- .../completionListInUnclosedIndexSignature01.ts | 11 +++++++++++ .../completionListInUnclosedIndexSignature02.ts | 13 +++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 tests/cases/fourslash/completionListInUnclosedIndexSignature01.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedIndexSignature02.ts diff --git a/tests/cases/fourslash/completionListInUnclosedIndexSignature01.ts b/tests/cases/fourslash/completionListInUnclosedIndexSignature01.ts new file mode 100644 index 0000000000000..fd2e5664f04b9 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedIndexSignature01.ts @@ -0,0 +1,11 @@ +/// + + +////class C { +//// [foo: string]: typeof /*1*/ +////} + + +goTo.marker("1"); +verify.completionListContains("foo"); +verify.completionListContains("C"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedIndexSignature02.ts b/tests/cases/fourslash/completionListInUnclosedIndexSignature02.ts new file mode 100644 index 0000000000000..318730e41a65d --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedIndexSignature02.ts @@ -0,0 +1,13 @@ +/// + + +////class C { +//// [foo: /*1*/ +////} + +goTo.marker("1"); +verify.completionListContains("C"); +verify.completionListContains("foo"); // ideally this shouldn't show up for a type +edit.insert("typeof "); +verify.completionListContains("C"); +verify.completionListContains("foo"); \ No newline at end of file From ad084ded72cbfcf2ae581a333a5731cf22dacf1f Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 17 Mar 2015 08:07:40 -0700 Subject: [PATCH 120/224] Account for typeof expressions, added test. --- src/services/utilities.ts | 4 +++- .../completionListInUnclosedIndexSignature01.ts | 1 - .../completionListInUnclosedIndexSignature03.ts | 10 ++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 tests/cases/fourslash/completionListInUnclosedIndexSignature03.ts diff --git a/src/services/utilities.ts b/src/services/utilities.ts index ca047414e594c..679a97449ec39 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -160,8 +160,10 @@ module ts { } return isCompletedNode((n).statement, sourceFile); + case SyntaxKind.TypeOfExpression: + return isCompletedNode((n).expression, sourceFile); case SyntaxKind.PrefixUnaryExpression: - return isCompletedNode(n, sourceFile); + return isCompletedNode((n).operand, sourceFile); case SyntaxKind.BinaryExpression: return isCompletedNode((n).right, sourceFile); case SyntaxKind.ConditionalExpression: diff --git a/tests/cases/fourslash/completionListInUnclosedIndexSignature01.ts b/tests/cases/fourslash/completionListInUnclosedIndexSignature01.ts index fd2e5664f04b9..0667742d4cb9e 100644 --- a/tests/cases/fourslash/completionListInUnclosedIndexSignature01.ts +++ b/tests/cases/fourslash/completionListInUnclosedIndexSignature01.ts @@ -5,7 +5,6 @@ //// [foo: string]: typeof /*1*/ ////} - goTo.marker("1"); verify.completionListContains("foo"); verify.completionListContains("C"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedIndexSignature03.ts b/tests/cases/fourslash/completionListInUnclosedIndexSignature03.ts new file mode 100644 index 0000000000000..bb4ef808bff78 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedIndexSignature03.ts @@ -0,0 +1,10 @@ +/// + + +////class C { +//// [foo: string]: { x: typeof /*1*/ +////} + +goTo.marker("1"); +verify.completionListContains("foo"); +verify.completionListContains("C"); \ No newline at end of file From f14abfefabb7d238e53589e0af1d578190bd5303 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Mon, 16 Mar 2015 18:25:44 -0700 Subject: [PATCH 121/224] Add clarifying comment --- src/compiler/checker.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d86a461dbc38b..4f11923247657 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4372,8 +4372,11 @@ module ts { } function reportNoCommonSupertypeError(types: Type[], errorLocation: Node, errorMessageChainHead: DiagnosticMessageChain): void { + // The downfallType/bestSupertypeDownfallType is the first type that caused a particular candidate + // to not be the common supertype. So if it weren't for this one downfallType (and possibly others), + // the type in question could have been the common supertype. let bestSupertype: Type; - let bestSupertypeDownfallType: Type; // The type that caused bestSupertype not to be the common supertype + let bestSupertypeDownfallType: Type; let bestSupertypeScore = 0; for (let i = 0; i < types.length; i++) { @@ -4575,9 +4578,9 @@ module ts { inferences.push({ primary: undefined, secondary: undefined, isFixed: false }); } return { - typeParameters: typeParameters, - inferUnionTypes: inferUnionTypes, - inferences: inferences, + typeParameters, + inferUnionTypes, + inferences, inferredTypes: new Array(typeParameters.length), }; } From 87dacb8c91a19209d1d02a5b0ad75a234f7400b1 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 17 Mar 2015 11:57:40 -0700 Subject: [PATCH 122/224] Add .gitattributes to override GitHub Linguist language classification for the repo --- .gitattributes | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000000..74f5f4a640948 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.js linguist-language=TypeScript \ No newline at end of file From b2b3d8b2762710a00009c3341f71baf7778c4bc4 Mon Sep 17 00:00:00 2001 From: Dan Quirk Date: Tue, 17 Mar 2015 12:15:13 -0700 Subject: [PATCH 123/224] Remove CodeClimate stuff --- .travis.yml | 11 +---------- package.json | 3 +-- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index 305fad1e4a7e7..572ac835cd42f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,13 +3,4 @@ language: node_js node_js: - '0.10' -sudo: false - -before_script: npm install -g codeclimate-test-reporter - -after_script: - - cat coverage/lcov.info | codeclimate - -addons: - code_climate: - repo_token: 9852ac5362c8cc38c07ca5adc0f94c20c6c79bd78e17933dc284598a65338656 +sudo: false \ No newline at end of file diff --git a/package.json b/package.json index 9261174b68f3b..3fbd9b3313eb3 100644 --- a/package.json +++ b/package.json @@ -39,9 +39,8 @@ "chai": "latest", "browserify": "latest", "istanbul": "latest", - "codeclimate-test-reporter": "latest" }, "scripts": { - "test": "jake generate-code-coverage" + "test": "jake runtests" } } From 754a8a617c5868cda1094ab7474113c5eaff012d Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 17 Mar 2015 12:21:35 -0700 Subject: [PATCH 124/224] More cases and tests for them. --- src/services/utilities.ts | 19 ++++++++++++++++++- ...pletionListInUnclosedDeleteExpression01.ts | 7 +++++++ ...pletionListInUnclosedDeleteExpression02.ts | 8 ++++++++ ...pletionListInUnclosedSpreadExpression01.ts | 7 +++++++ ...pletionListInUnclosedSpreadExpression02.ts | 8 ++++++++ ...ompletionListInUnclosedTaggedTemplate01.ts | 8 ++++++++ ...ompletionListInUnclosedTaggedTemplate02.ts | 8 ++++++++ .../completionListInUnclosedTemplate01.ts | 8 ++++++++ .../completionListInUnclosedTemplate02.ts | 8 ++++++++ ...pletionListInUnclosedTypeOfExpression01.ts | 7 +++++++ ...pletionListInUnclosedTypeOfExpression02.ts | 8 ++++++++ ...ompletionListInUnclosedVoidExpression01.ts | 8 ++++++++ ...mpletionListInUnclosedYieldExpression01.ts | 10 ++++++++++ 13 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/completionListInUnclosedDeleteExpression01.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedDeleteExpression02.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedSpreadExpression01.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedSpreadExpression02.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedTaggedTemplate01.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedTaggedTemplate02.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedTemplate01.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedTemplate02.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedTypeOfExpression01.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedTypeOfExpression02.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedVoidExpression01.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedYieldExpression01.ts diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 679a97449ec39..a53ab212bf2a3 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -160,8 +160,25 @@ module ts { } return isCompletedNode((n).statement, sourceFile); + case SyntaxKind.TypeQuery: + return isCompletedNode((n).exprName, sourceFile); + case SyntaxKind.TypeOfExpression: - return isCompletedNode((n).expression, sourceFile); + case SyntaxKind.DeleteExpression: + case SyntaxKind.VoidExpression: + case SyntaxKind.YieldExpression: + case SyntaxKind.SpreadElementExpression: + let unaryWordExpression = (n); + return isCompletedNode(unaryWordExpression.expression, sourceFile); + + case SyntaxKind.TaggedTemplateExpression: + return isCompletedNode((n).template, sourceFile); + case SyntaxKind.TemplateExpression: + let lastSpan = lastOrUndefined((n).templateSpans); + return isCompletedNode(lastSpan, sourceFile); + case SyntaxKind.TemplateSpan: + return nodeIsPresent((n).literal); + case SyntaxKind.PrefixUnaryExpression: return isCompletedNode((n).operand, sourceFile); case SyntaxKind.BinaryExpression: diff --git a/tests/cases/fourslash/completionListInUnclosedDeleteExpression01.ts b/tests/cases/fourslash/completionListInUnclosedDeleteExpression01.ts new file mode 100644 index 0000000000000..fdb67dfc3354a --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedDeleteExpression01.ts @@ -0,0 +1,7 @@ +/// + +////var x; +////var y = delete /*1*/ + +goTo.marker("1"); +verify.completionListContains("x"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedDeleteExpression02.ts b/tests/cases/fourslash/completionListInUnclosedDeleteExpression02.ts new file mode 100644 index 0000000000000..3573c345285bd --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedDeleteExpression02.ts @@ -0,0 +1,8 @@ +/// + +////var x; +////var y = (p) => delete /*1*/ + +goTo.marker("1"); +verify.completionListContains("x"); +verify.completionListContains("p"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedSpreadExpression01.ts b/tests/cases/fourslash/completionListInUnclosedSpreadExpression01.ts new file mode 100644 index 0000000000000..b9cc01f0a66cb --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedSpreadExpression01.ts @@ -0,0 +1,7 @@ +/// + +////var x; +////var y = [1,2,.../*1*/ + +goTo.marker("1"); +verify.completionListContains("x"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedSpreadExpression02.ts b/tests/cases/fourslash/completionListInUnclosedSpreadExpression02.ts new file mode 100644 index 0000000000000..40d90370232e8 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedSpreadExpression02.ts @@ -0,0 +1,8 @@ +/// + +////var x; +////var y = (p) => [1,2,.../*1*/ + +goTo.marker("1"); +verify.completionListContains("p"); +verify.completionListContains("x"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedTaggedTemplate01.ts b/tests/cases/fourslash/completionListInUnclosedTaggedTemplate01.ts new file mode 100644 index 0000000000000..20e2a5d0663ed --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedTaggedTemplate01.ts @@ -0,0 +1,8 @@ +/// + +////var x; +////var y = (p) => x `abc ${ /*1*/ + +goTo.marker("1"); +verify.completionListContains("p"); +verify.completionListContains("x"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedTaggedTemplate02.ts b/tests/cases/fourslash/completionListInUnclosedTaggedTemplate02.ts new file mode 100644 index 0000000000000..d4bbd5992c63b --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedTaggedTemplate02.ts @@ -0,0 +1,8 @@ +/// + +////var x; +////var y = (p) => x `abc ${ 123 } ${ /*1*/ + +goTo.marker("1"); +verify.completionListContains("p"); +verify.completionListContains("x"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedTemplate01.ts b/tests/cases/fourslash/completionListInUnclosedTemplate01.ts new file mode 100644 index 0000000000000..c7b8f62817044 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedTemplate01.ts @@ -0,0 +1,8 @@ +/// + +////var x; +////var y = (p) => `abc ${ /*1*/ + +goTo.marker("1"); +verify.completionListContains("p"); +verify.completionListContains("x"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedTemplate02.ts b/tests/cases/fourslash/completionListInUnclosedTemplate02.ts new file mode 100644 index 0000000000000..5fd5c94ee3eb2 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedTemplate02.ts @@ -0,0 +1,8 @@ +/// + +////var x; +////var y = (p) => `abc ${ 123 } ${ /*1*/ + +goTo.marker("1"); +verify.completionListContains("p"); +verify.completionListContains("x"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedTypeOfExpression01.ts b/tests/cases/fourslash/completionListInUnclosedTypeOfExpression01.ts new file mode 100644 index 0000000000000..3da8b4fd6169f --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedTypeOfExpression01.ts @@ -0,0 +1,7 @@ +/// + +////var x; +////var y = typeof /*1*/ + +goTo.marker("1"); +verify.completionListContains("x"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedTypeOfExpression02.ts b/tests/cases/fourslash/completionListInUnclosedTypeOfExpression02.ts new file mode 100644 index 0000000000000..b1d347211ac69 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedTypeOfExpression02.ts @@ -0,0 +1,8 @@ +/// + +////var x; +////var y = (p) => typeof /*1*/ + +goTo.marker("1"); +verify.completionListContains("x"); +verify.completionListContains("p"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedVoidExpression01.ts b/tests/cases/fourslash/completionListInUnclosedVoidExpression01.ts new file mode 100644 index 0000000000000..d1cfecbffec3b --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedVoidExpression01.ts @@ -0,0 +1,8 @@ +/// + +////var x; +////var y = (p) => void /*1*/ + +goTo.marker("1"); +verify.completionListContains("p"); +verify.completionListContains("x"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedYieldExpression01.ts b/tests/cases/fourslash/completionListInUnclosedYieldExpression01.ts new file mode 100644 index 0000000000000..658b0de7dc812 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedYieldExpression01.ts @@ -0,0 +1,10 @@ +/// + +////var x; +////var y = function* gen(p) { yield /*1*/ + +goTo.marker("1"); +// These tentatively don't work. +verify.not.completionListContains("p"); +verify.not.completionListContains("gen"); +verify.not.completionListContains("x"); \ No newline at end of file From 83d38c46dcddf349f5b84a1233b7b925024a25cb Mon Sep 17 00:00:00 2001 From: Dan Quirk Date: Tue, 17 Mar 2015 12:25:01 -0700 Subject: [PATCH 125/224] Delete extra comma --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3fbd9b3313eb3..c33f2a93ec18f 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "mocha": "latest", "chai": "latest", "browserify": "latest", - "istanbul": "latest", + "istanbul": "latest" }, "scripts": { "test": "jake runtests" From 860c04637611adf2a3d512fe000a4e86c0afb880 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 17 Mar 2015 12:27:24 -0700 Subject: [PATCH 126/224] Start using nodeIsMissing. --- src/services/utilities.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/utilities.ts b/src/services/utilities.ts index a53ab212bf2a3..8758d126f6362 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -64,7 +64,7 @@ module ts { } export function isCompletedNode(n: Node, sourceFile: SourceFile): boolean { - if (n.getFullWidth() === 0) { + if (nodeIsMissing(n)) { return false; } From 7a716d9d42c25f53d5e35fa92e5b014bac285e74 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 17 Mar 2015 12:27:59 -0700 Subject: [PATCH 127/224] Start handling element access expressions. --- src/services/utilities.ts | 1 + .../completionListInUnclosedElementAccessExpression01.ts | 7 +++++++ .../completionListInUnclosedElementAccessExpression02.ts | 8 ++++++++ 3 files changed, 16 insertions(+) create mode 100644 tests/cases/fourslash/completionListInUnclosedElementAccessExpression01.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedElementAccessExpression02.ts diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 8758d126f6362..6147112c90971 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -131,6 +131,7 @@ module ts { case SyntaxKind.ArrayLiteralExpression: case SyntaxKind.ArrayBindingPattern: + case SyntaxKind.ElementAccessExpression: case SyntaxKind.ComputedPropertyName: case SyntaxKind.TupleType: return nodeEndsWith(n, SyntaxKind.CloseBracketToken, sourceFile); diff --git a/tests/cases/fourslash/completionListInUnclosedElementAccessExpression01.ts b/tests/cases/fourslash/completionListInUnclosedElementAccessExpression01.ts new file mode 100644 index 0000000000000..59c4922671eaf --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedElementAccessExpression01.ts @@ -0,0 +1,7 @@ +/// + +////var x; +////var y = x[/*1*/ + +goTo.marker("1"); +verify.completionListContains("x"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedElementAccessExpression02.ts b/tests/cases/fourslash/completionListInUnclosedElementAccessExpression02.ts new file mode 100644 index 0000000000000..1d6403cfa10af --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedElementAccessExpression02.ts @@ -0,0 +1,8 @@ +/// + +////var x; +////var y = (p) => x[/*1*/ + +goTo.marker("1"); +verify.completionListContains("p"); +verify.completionListContains("x"); \ No newline at end of file From 766cb68f7c2417b6edade146374c9e9d010db9ab Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 17 Mar 2015 13:03:13 -0700 Subject: [PATCH 128/224] Add comments --- src/compiler/checker.ts | 2 ++ src/compiler/emitter.ts | 1 + 2 files changed, 3 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7cfe69c5620ac..0bd577408038d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10982,6 +10982,8 @@ module ts { function getExportNameSubstitution(symbol: Symbol, location: Node): string { if (isExternalModuleSymbol(symbol.parent)) { var symbolName = unescapeIdentifier(symbol.name); + // If this is es6 or higher, just use the name of the export + // no need to qualify it. if (languageVersion >= ScriptTarget.ES6) { return symbolName; } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 42856a570776f..126ac7a4e69ad 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4903,6 +4903,7 @@ module ts { } write("class "); + // check if this is an "export default class" as it may not have a name if (node.name || !(node.flags & NodeFlags.Default)) { emitDeclarationName(node); } From 3418a49f8a29be430d9233d9638f8a2f2d9f93cb Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 17 Mar 2015 13:20:44 -0700 Subject: [PATCH 129/224] Line endings. --- src/services/services.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 95251b8198412..f5b9e36f59b7a 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2596,10 +2596,10 @@ module ts { isMemberCompletion = false; isNewIdentifierLocation = isNewIdentifierDefinitionLocation(previousToken); - /// TODO filter meaning based on the current context + /// TODO filter meaning based on the current context let scopeNode = getScopeNode(previousToken, position, sourceFile); let symbolMeanings = SymbolFlags.Type | SymbolFlags.Value | SymbolFlags.Namespace | SymbolFlags.Alias; - let symbols = typeInfoResolver.getSymbolsInScope(scopeNode, symbolMeanings); + let symbols = typeInfoResolver.getSymbolsInScope(scopeNode, symbolMeanings); getCompletionEntriesFromSymbols(symbols, activeCompletionSession); } From e49fc058b08b0d62fe573b20f3eba6f4ac51273e Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 17 Mar 2015 13:33:01 -0700 Subject: [PATCH 130/224] Added tests. --- .../completionListInUnclosedCommaExpression01.ts | 8 ++++++++ .../completionListInUnclosedCommaExpression02.ts | 8 ++++++++ .../cases/fourslash/completionListInUnclosedForLoop01.ts | 6 ++++++ .../cases/fourslash/completionListInUnclosedForLoop02.ts | 6 ++++++ .../completionListOutsideOfClosedArrowFunction01.ts | 8 ++++++++ .../completionListOutsideOfClosedArrowFunction02.ts | 8 ++++++++ .../completionListOutsideOfClosedFunctionDeclaration01.ts | 8 ++++++++ tests/cases/fourslash/completionListOutsideOfForLoop01.ts | 6 ++++++ tests/cases/fourslash/completionListOutsideOfForLoop02.ts | 6 ++++++ 9 files changed, 64 insertions(+) create mode 100644 tests/cases/fourslash/completionListInUnclosedCommaExpression01.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedCommaExpression02.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedForLoop01.ts create mode 100644 tests/cases/fourslash/completionListInUnclosedForLoop02.ts create mode 100644 tests/cases/fourslash/completionListOutsideOfClosedArrowFunction01.ts create mode 100644 tests/cases/fourslash/completionListOutsideOfClosedArrowFunction02.ts create mode 100644 tests/cases/fourslash/completionListOutsideOfClosedFunctionDeclaration01.ts create mode 100644 tests/cases/fourslash/completionListOutsideOfForLoop01.ts create mode 100644 tests/cases/fourslash/completionListOutsideOfForLoop02.ts diff --git a/tests/cases/fourslash/completionListInUnclosedCommaExpression01.ts b/tests/cases/fourslash/completionListInUnclosedCommaExpression01.ts new file mode 100644 index 0000000000000..de0f26eb86e2b --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedCommaExpression01.ts @@ -0,0 +1,8 @@ +/// + +////// should NOT see a and b +////foo((a, b) => a,/*1*/ + +goTo.marker("1"); +verify.not.completionListContains("a"); +verify.not.completionListContains("b"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedCommaExpression02.ts b/tests/cases/fourslash/completionListInUnclosedCommaExpression02.ts new file mode 100644 index 0000000000000..e0ea3abbd3815 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedCommaExpression02.ts @@ -0,0 +1,8 @@ +/// + +////// should NOT see a and b +////foo((a, b) => (a,/*1*/ + +goTo.marker("1"); +verify.completionListContains("a"); +verify.completionListContains("b"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedForLoop01.ts b/tests/cases/fourslash/completionListInUnclosedForLoop01.ts new file mode 100644 index 0000000000000..35e5efdd304d8 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedForLoop01.ts @@ -0,0 +1,6 @@ +/// + +////for (let i = 0; /*1*/ + +goTo.marker("1"); +verify.completionListContains("i"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListInUnclosedForLoop02.ts b/tests/cases/fourslash/completionListInUnclosedForLoop02.ts new file mode 100644 index 0000000000000..e79f428b2b066 --- /dev/null +++ b/tests/cases/fourslash/completionListInUnclosedForLoop02.ts @@ -0,0 +1,6 @@ +/// + +////for (let i = 0; i < 10; i++) /*1*/ + +goTo.marker("1"); +verify.completionListContains("i"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListOutsideOfClosedArrowFunction01.ts b/tests/cases/fourslash/completionListOutsideOfClosedArrowFunction01.ts new file mode 100644 index 0000000000000..d775371796fdc --- /dev/null +++ b/tests/cases/fourslash/completionListOutsideOfClosedArrowFunction01.ts @@ -0,0 +1,8 @@ +/// + +////// no a or b +/////*1*/(a, b) => { } + +goTo.marker("1"); +verify.not.completionListContains("a"); +verify.not.completionListContains("b"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListOutsideOfClosedArrowFunction02.ts b/tests/cases/fourslash/completionListOutsideOfClosedArrowFunction02.ts new file mode 100644 index 0000000000000..d9195ce5b9758 --- /dev/null +++ b/tests/cases/fourslash/completionListOutsideOfClosedArrowFunction02.ts @@ -0,0 +1,8 @@ +/// + +////// no a or b +////(a, b) => { }/*1*/ + +goTo.marker("1"); +verify.not.completionListContains("a"); +verify.not.completionListContains("b"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListOutsideOfClosedFunctionDeclaration01.ts b/tests/cases/fourslash/completionListOutsideOfClosedFunctionDeclaration01.ts new file mode 100644 index 0000000000000..8b6077e0f8b5a --- /dev/null +++ b/tests/cases/fourslash/completionListOutsideOfClosedFunctionDeclaration01.ts @@ -0,0 +1,8 @@ +/// + +////// no a or b +/////*1*/function f (a, b) {} + +goTo.marker("1"); +verify.not.completionListContains("a"); +verify.not.completionListContains("b"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListOutsideOfForLoop01.ts b/tests/cases/fourslash/completionListOutsideOfForLoop01.ts new file mode 100644 index 0000000000000..473a39a453d00 --- /dev/null +++ b/tests/cases/fourslash/completionListOutsideOfForLoop01.ts @@ -0,0 +1,6 @@ +/// + +////for (let i = 0; i < 10; i++) i;/*1*/ + +goTo.marker("1"); +verify.not.completionListContains("i"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListOutsideOfForLoop02.ts b/tests/cases/fourslash/completionListOutsideOfForLoop02.ts new file mode 100644 index 0000000000000..b1186ac7cce7f --- /dev/null +++ b/tests/cases/fourslash/completionListOutsideOfForLoop02.ts @@ -0,0 +1,6 @@ +/// + +////for (let i = 0; i < 10; i++);/*1*/ + +goTo.marker("1"); +verify.not.completionListContains("i"); \ No newline at end of file From eb1160731e7d0c8680c1c90ce1260e4ffa5cc2a2 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Tue, 17 Mar 2015 14:02:19 -0700 Subject: [PATCH 131/224] use type annotation when emitting declarations --- src/compiler/emitter.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 387a57fa7f4fe..e8f7ef77e5216 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -756,8 +756,13 @@ module ts { } else { write(": "); - writer.getSymbolAccessibilityDiagnostic = getDefaultExportAccessibilityDiagnostic; - resolver.writeTypeOfExpression(node.expression, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer); + if (node.type) { + emitType(node.type); + } + else { + writer.getSymbolAccessibilityDiagnostic = getDefaultExportAccessibilityDiagnostic; + resolver.writeTypeOfExpression(node.expression, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer); + } } write(";"); writeLine(); From 5db3b0d904b3448da48e5e2c821d34f9f970f316 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 17 Mar 2015 10:55:42 -0700 Subject: [PATCH 132/224] Types for decorators --- src/compiler/types.ts | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 87d219c2e844a..bdf824504c529 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -67,6 +67,7 @@ module ts { BarBarToken, QuestionToken, ColonToken, + AtToken, // Assignments EqualsToken, PlusEqualsToken, @@ -154,6 +155,7 @@ module ts { // Signature elements TypeParameter, Parameter, + Decorator, // TypeMember PropertySignature, PropertyDeclaration, @@ -244,6 +246,7 @@ module ts { ExportDeclaration, NamedExports, ExportSpecifier, + IncompleteDeclaration, // Module references ExternalModuleReference, @@ -327,22 +330,25 @@ module ts { // If this node was parsed in the parameters of a generator. GeneratorParameter = 1 << 3, + // If this node was parsed as part of a decorator + Decorator = 1 << 4, + // If the parser encountered an error when parsing the code that created this node. Note // the parser only sets this directly on the node it creates right after encountering the // error. - ThisNodeHasError = 1 << 4, + ThisNodeHasError = 1 << 5, // Context flags set directly by the parser. - ParserGeneratedFlags = StrictMode | DisallowIn | Yield | GeneratorParameter | ThisNodeHasError, + ParserGeneratedFlags = StrictMode | DisallowIn | Yield | GeneratorParameter | Decorator | ThisNodeHasError, // Context flags computed by aggregating child flags upwards. // Used during incremental parsing to determine if this node or any of its children had an // error. Computed only once and then cached. - ThisNodeOrAnySubNodesHasError = 1 << 5, + ThisNodeOrAnySubNodesHasError = 1 << 6, // Used to know if we've computed data from children and cached it in this node. - HasAggregatedChildData = 1 << 6 + HasAggregatedChildData = 1 << 7 } export const enum RelationComparisonResult { @@ -357,13 +363,14 @@ module ts { // Specific context the parser was in when this node was created. Normally undefined. // Only set when the parser was in some interesting context (like async/yield). parserContextFlags?: ParserContextFlags; - modifiers?: ModifiersArray; // Array of modifiers - id?: number; // Unique id (used to look up NodeLinks) - parent?: Node; // Parent node (initialized by binding) - symbol?: Symbol; // Symbol declared by node (initialized by binding) - locals?: SymbolTable; // Locals associated with node (initialized by binding) - nextContainer?: Node; // Next container in declaration order (initialized by binding) - localSymbol?: Symbol; // Local symbol declared by node (initialized by binding only for exported nodes) + decorators?: NodeArray; // Array of decorators + modifiers?: ModifiersArray; // Array of modifiers + id?: number; // Unique id (used to look up NodeLinks) + parent?: Node; // Parent node (initialized by binding) + symbol?: Symbol; // Symbol declared by node (initialized by binding) + locals?: SymbolTable; // Locals associated with node (initialized by binding) + nextContainer?: Node; // Next container in declaration order (initialized by binding) + localSymbol?: Symbol; // Local symbol declared by node (initialized by binding only for exported nodes) } export interface NodeArray extends Array, TextRange { @@ -397,6 +404,11 @@ module ts { expression: Expression; } + export interface Decorator extends Node { + atToken: Node; + expression: LeftHandSideExpression; + } + export interface TypeParameterDeclaration extends Declaration { name: Identifier; constraint?: TypeNode; @@ -687,7 +699,9 @@ module ts { } export interface ArrayLiteralExpression extends PrimaryExpression { + openBracketToken: Node; elements: NodeArray; + closeBracketToken: Node; } export interface SpreadElementExpression extends Expression { @@ -707,7 +721,9 @@ module ts { export interface ElementAccessExpression extends MemberExpression { expression: LeftHandSideExpression; + openBracketToken: Node; argumentExpression?: Expression; + closeBracketToken: Node; } export interface CallExpression extends LeftHandSideExpression { From fb7dd52bdc57fcaea357ceabfc557715bc709329 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 17 Mar 2015 10:57:06 -0700 Subject: [PATCH 133/224] Utilities for decorators --- src/compiler/utilities.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 4fce9c928f7b7..959476df2a647 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1,4 +1,4 @@ -/// +/// module ts { export interface ReferencePathMatchResult { @@ -575,6 +575,17 @@ module ts { return (node).expression; } + function getConstructorWithBody(member: ClassElement): ConstructorDeclaration { + if (member.kind === SyntaxKind.Constructor && nodeIsPresent((member).body)) { + return member; + } + return undefined; + } + + export function getFirstConstructorWithBody(node: ClassDeclaration): ConstructorDeclaration { + return forEach(node.members, getConstructorWithBody); + } + export function isExpression(node: Node): boolean { switch (node.kind) { case SyntaxKind.ThisKeyword: From efd8a89f691884059112113ad0b9452eb824e858 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 17 Mar 2015 10:58:42 -0700 Subject: [PATCH 134/224] Diagnostics for decorators --- .../diagnosticInformationMap.generated.ts | 5 + src/compiler/diagnosticMessages.json | 20 + .../baselines/reference/APISample_compile.js | 393 ++++++++-------- .../reference/APISample_compile.types | 425 ++++++++++-------- tests/baselines/reference/APISample_linter.js | 411 +++++++++-------- .../reference/APISample_linter.types | 425 ++++++++++-------- .../reference/APISample_transform.js | 393 ++++++++-------- .../reference/APISample_transform.types | 425 ++++++++++-------- .../baselines/reference/APISample_watcher.js | 393 ++++++++-------- .../reference/APISample_watcher.types | 425 ++++++++++-------- 10 files changed, 1786 insertions(+), 1529 deletions(-) diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index dd26ef281c4bb..005985b0d0cbf 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -162,6 +162,11 @@ module ts { Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_or_import_d_from_mod_instead: { code: 1202, category: DiagnosticCategory.Error, key: "Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * as ns from \"mod\"', 'import {a} from \"mod\"' or 'import d from \"mod\"' instead." }, Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_export_default_instead: { code: 1203, category: DiagnosticCategory.Error, key: "Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead." }, Cannot_compile_external_modules_into_amd_or_commonjs_when_targeting_es6_or_higher: { code: 1204, category: DiagnosticCategory.Error, key: "Cannot compile external modules into amd or commonjs when targeting es6 or higher." }, + Decorators_are_only_supported_on_class_members_when_targeting_ECMAScript_5_or_higher: { code: 1205, category: DiagnosticCategory.Error, key: "Decorators are only supported on class members when targeting ECMAScript 5 or higher." }, + Decorators_are_not_valid_on_this_declaration_type: { code: 1206, category: DiagnosticCategory.Error, key: "Decorators are not valid on this declaration type." }, + Argument_to_ambient_decorator_must_be_constant_expression: { code: 1207, category: DiagnosticCategory.Error, key: "Argument to ambient decorator must be constant expression." }, + Decorators_may_not_change_the_type_of_a_member: { code: 1208, category: DiagnosticCategory.Error, key: "Decorators may not change the type of a member." }, + Decorators_may_not_change_the_type_of_a_class: { code: 1209, category: DiagnosticCategory.Error, key: "Decorators may not change the type of a class." }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index e1767fe8de044..3dee5320eec4d 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -639,6 +639,26 @@ "category": "Error", "code": 1204 }, + "Decorators are only supported on class members when targeting ECMAScript 5 or higher.": { + "category": "Error", + "code": 1205 + }, + "Decorators are not valid on this declaration type.": { + "category": "Error", + "code": 1206 + }, + "Argument to ambient decorator must be constant expression.": { + "category": "Error", + "code": 1207 + }, + "Decorators may not change the type of a member.": { + "category": "Error", + "code": 1208 + }, + "Decorators may not change the type of a class.": { + "category": "Error", + "code": 1209 + }, "Duplicate identifier '{0}'.": { "category": "Error", diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index 575c2bdaf36d1..12a0a7c077058 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -111,192 +111,195 @@ declare module "typescript" { BarBarToken = 49, QuestionToken = 50, ColonToken = 51, - EqualsToken = 52, - PlusEqualsToken = 53, - MinusEqualsToken = 54, - AsteriskEqualsToken = 55, - SlashEqualsToken = 56, - PercentEqualsToken = 57, - LessThanLessThanEqualsToken = 58, - GreaterThanGreaterThanEqualsToken = 59, - GreaterThanGreaterThanGreaterThanEqualsToken = 60, - AmpersandEqualsToken = 61, - BarEqualsToken = 62, - CaretEqualsToken = 63, - Identifier = 64, - BreakKeyword = 65, - CaseKeyword = 66, - CatchKeyword = 67, - ClassKeyword = 68, - ConstKeyword = 69, - ContinueKeyword = 70, - DebuggerKeyword = 71, - DefaultKeyword = 72, - DeleteKeyword = 73, - DoKeyword = 74, - ElseKeyword = 75, - EnumKeyword = 76, - ExportKeyword = 77, - ExtendsKeyword = 78, - FalseKeyword = 79, - FinallyKeyword = 80, - ForKeyword = 81, - FunctionKeyword = 82, - IfKeyword = 83, - ImportKeyword = 84, - InKeyword = 85, - InstanceOfKeyword = 86, - NewKeyword = 87, - NullKeyword = 88, - ReturnKeyword = 89, - SuperKeyword = 90, - SwitchKeyword = 91, - ThisKeyword = 92, - ThrowKeyword = 93, - TrueKeyword = 94, - TryKeyword = 95, - TypeOfKeyword = 96, - VarKeyword = 97, - VoidKeyword = 98, - WhileKeyword = 99, - WithKeyword = 100, - AsKeyword = 101, - ImplementsKeyword = 102, - InterfaceKeyword = 103, - LetKeyword = 104, - PackageKeyword = 105, - PrivateKeyword = 106, - ProtectedKeyword = 107, - PublicKeyword = 108, - StaticKeyword = 109, - YieldKeyword = 110, - AnyKeyword = 111, - BooleanKeyword = 112, - ConstructorKeyword = 113, - DeclareKeyword = 114, - GetKeyword = 115, - ModuleKeyword = 116, - RequireKeyword = 117, - NumberKeyword = 118, - SetKeyword = 119, - StringKeyword = 120, - SymbolKeyword = 121, - TypeKeyword = 122, - FromKeyword = 123, - OfKeyword = 124, - QualifiedName = 125, - ComputedPropertyName = 126, - TypeParameter = 127, - Parameter = 128, - PropertySignature = 129, - PropertyDeclaration = 130, - MethodSignature = 131, - MethodDeclaration = 132, - Constructor = 133, - GetAccessor = 134, - SetAccessor = 135, - CallSignature = 136, - ConstructSignature = 137, - IndexSignature = 138, - TypeReference = 139, - FunctionType = 140, - ConstructorType = 141, - TypeQuery = 142, - TypeLiteral = 143, - ArrayType = 144, - TupleType = 145, - UnionType = 146, - ParenthesizedType = 147, - ObjectBindingPattern = 148, - ArrayBindingPattern = 149, - BindingElement = 150, - ArrayLiteralExpression = 151, - ObjectLiteralExpression = 152, - PropertyAccessExpression = 153, - ElementAccessExpression = 154, - CallExpression = 155, - NewExpression = 156, - TaggedTemplateExpression = 157, - TypeAssertionExpression = 158, - ParenthesizedExpression = 159, - FunctionExpression = 160, - ArrowFunction = 161, - DeleteExpression = 162, - TypeOfExpression = 163, - VoidExpression = 164, - PrefixUnaryExpression = 165, - PostfixUnaryExpression = 166, - BinaryExpression = 167, - ConditionalExpression = 168, - TemplateExpression = 169, - YieldExpression = 170, - SpreadElementExpression = 171, - OmittedExpression = 172, - TemplateSpan = 173, - Block = 174, - VariableStatement = 175, - EmptyStatement = 176, - ExpressionStatement = 177, - IfStatement = 178, - DoStatement = 179, - WhileStatement = 180, - ForStatement = 181, - ForInStatement = 182, - ForOfStatement = 183, - ContinueStatement = 184, - BreakStatement = 185, - ReturnStatement = 186, - WithStatement = 187, - SwitchStatement = 188, - LabeledStatement = 189, - ThrowStatement = 190, - TryStatement = 191, - DebuggerStatement = 192, - VariableDeclaration = 193, - VariableDeclarationList = 194, - FunctionDeclaration = 195, - ClassDeclaration = 196, - InterfaceDeclaration = 197, - TypeAliasDeclaration = 198, - EnumDeclaration = 199, - ModuleDeclaration = 200, - ModuleBlock = 201, - CaseBlock = 202, - ImportEqualsDeclaration = 203, - ImportDeclaration = 204, - ImportClause = 205, - NamespaceImport = 206, - NamedImports = 207, - ImportSpecifier = 208, - ExportAssignment = 209, - ExportDeclaration = 210, - NamedExports = 211, - ExportSpecifier = 212, - ExternalModuleReference = 213, - CaseClause = 214, - DefaultClause = 215, - HeritageClause = 216, - CatchClause = 217, - PropertyAssignment = 218, - ShorthandPropertyAssignment = 219, - EnumMember = 220, - SourceFile = 221, - SyntaxList = 222, - Count = 223, - FirstAssignment = 52, - LastAssignment = 63, - FirstReservedWord = 65, - LastReservedWord = 100, - FirstKeyword = 65, - LastKeyword = 124, - FirstFutureReservedWord = 102, - LastFutureReservedWord = 110, - FirstTypeNode = 139, - LastTypeNode = 147, + AtToken = 52, + EqualsToken = 53, + PlusEqualsToken = 54, + MinusEqualsToken = 55, + AsteriskEqualsToken = 56, + SlashEqualsToken = 57, + PercentEqualsToken = 58, + LessThanLessThanEqualsToken = 59, + GreaterThanGreaterThanEqualsToken = 60, + GreaterThanGreaterThanGreaterThanEqualsToken = 61, + AmpersandEqualsToken = 62, + BarEqualsToken = 63, + CaretEqualsToken = 64, + Identifier = 65, + BreakKeyword = 66, + CaseKeyword = 67, + CatchKeyword = 68, + ClassKeyword = 69, + ConstKeyword = 70, + ContinueKeyword = 71, + DebuggerKeyword = 72, + DefaultKeyword = 73, + DeleteKeyword = 74, + DoKeyword = 75, + ElseKeyword = 76, + EnumKeyword = 77, + ExportKeyword = 78, + ExtendsKeyword = 79, + FalseKeyword = 80, + FinallyKeyword = 81, + ForKeyword = 82, + FunctionKeyword = 83, + IfKeyword = 84, + ImportKeyword = 85, + InKeyword = 86, + InstanceOfKeyword = 87, + NewKeyword = 88, + NullKeyword = 89, + ReturnKeyword = 90, + SuperKeyword = 91, + SwitchKeyword = 92, + ThisKeyword = 93, + ThrowKeyword = 94, + TrueKeyword = 95, + TryKeyword = 96, + TypeOfKeyword = 97, + VarKeyword = 98, + VoidKeyword = 99, + WhileKeyword = 100, + WithKeyword = 101, + AsKeyword = 102, + ImplementsKeyword = 103, + InterfaceKeyword = 104, + LetKeyword = 105, + PackageKeyword = 106, + PrivateKeyword = 107, + ProtectedKeyword = 108, + PublicKeyword = 109, + StaticKeyword = 110, + YieldKeyword = 111, + AnyKeyword = 112, + BooleanKeyword = 113, + ConstructorKeyword = 114, + DeclareKeyword = 115, + GetKeyword = 116, + ModuleKeyword = 117, + RequireKeyword = 118, + NumberKeyword = 119, + SetKeyword = 120, + StringKeyword = 121, + SymbolKeyword = 122, + TypeKeyword = 123, + FromKeyword = 124, + OfKeyword = 125, + QualifiedName = 126, + ComputedPropertyName = 127, + TypeParameter = 128, + Parameter = 129, + Decorator = 130, + PropertySignature = 131, + PropertyDeclaration = 132, + MethodSignature = 133, + MethodDeclaration = 134, + Constructor = 135, + GetAccessor = 136, + SetAccessor = 137, + CallSignature = 138, + ConstructSignature = 139, + IndexSignature = 140, + TypeReference = 141, + FunctionType = 142, + ConstructorType = 143, + TypeQuery = 144, + TypeLiteral = 145, + ArrayType = 146, + TupleType = 147, + UnionType = 148, + ParenthesizedType = 149, + ObjectBindingPattern = 150, + ArrayBindingPattern = 151, + BindingElement = 152, + ArrayLiteralExpression = 153, + ObjectLiteralExpression = 154, + PropertyAccessExpression = 155, + ElementAccessExpression = 156, + CallExpression = 157, + NewExpression = 158, + TaggedTemplateExpression = 159, + TypeAssertionExpression = 160, + ParenthesizedExpression = 161, + FunctionExpression = 162, + ArrowFunction = 163, + DeleteExpression = 164, + TypeOfExpression = 165, + VoidExpression = 166, + PrefixUnaryExpression = 167, + PostfixUnaryExpression = 168, + BinaryExpression = 169, + ConditionalExpression = 170, + TemplateExpression = 171, + YieldExpression = 172, + SpreadElementExpression = 173, + OmittedExpression = 174, + TemplateSpan = 175, + Block = 176, + VariableStatement = 177, + EmptyStatement = 178, + ExpressionStatement = 179, + IfStatement = 180, + DoStatement = 181, + WhileStatement = 182, + ForStatement = 183, + ForInStatement = 184, + ForOfStatement = 185, + ContinueStatement = 186, + BreakStatement = 187, + ReturnStatement = 188, + WithStatement = 189, + SwitchStatement = 190, + LabeledStatement = 191, + ThrowStatement = 192, + TryStatement = 193, + DebuggerStatement = 194, + VariableDeclaration = 195, + VariableDeclarationList = 196, + FunctionDeclaration = 197, + ClassDeclaration = 198, + InterfaceDeclaration = 199, + TypeAliasDeclaration = 200, + EnumDeclaration = 201, + ModuleDeclaration = 202, + ModuleBlock = 203, + CaseBlock = 204, + ImportEqualsDeclaration = 205, + ImportDeclaration = 206, + ImportClause = 207, + NamespaceImport = 208, + NamedImports = 209, + ImportSpecifier = 210, + ExportAssignment = 211, + ExportDeclaration = 212, + NamedExports = 213, + ExportSpecifier = 214, + IncompleteDeclaration = 215, + ExternalModuleReference = 216, + CaseClause = 217, + DefaultClause = 218, + HeritageClause = 219, + CatchClause = 220, + PropertyAssignment = 221, + ShorthandPropertyAssignment = 222, + EnumMember = 223, + SourceFile = 224, + SyntaxList = 225, + Count = 226, + FirstAssignment = 53, + LastAssignment = 64, + FirstReservedWord = 66, + LastReservedWord = 101, + FirstKeyword = 66, + LastKeyword = 125, + FirstFutureReservedWord = 103, + LastFutureReservedWord = 111, + FirstTypeNode = 141, + LastTypeNode = 149, FirstPunctuation = 14, - LastPunctuation = 63, + LastPunctuation = 64, FirstToken = 0, - LastToken = 124, + LastToken = 125, FirstTriviaToken = 2, LastTriviaToken = 6, FirstLiteralToken = 7, @@ -304,8 +307,8 @@ declare module "typescript" { FirstTemplateToken = 10, LastTemplateToken = 13, FirstBinaryOperator = 24, - LastBinaryOperator = 63, - FirstNode = 125, + LastBinaryOperator = 64, + FirstNode = 126, } const enum NodeFlags { Export = 1, @@ -330,10 +333,11 @@ declare module "typescript" { DisallowIn = 2, Yield = 4, GeneratorParameter = 8, - ThisNodeHasError = 16, - ParserGeneratedFlags = 31, - ThisNodeOrAnySubNodesHasError = 32, - HasAggregatedChildData = 64, + Decorator = 16, + ThisNodeHasError = 32, + ParserGeneratedFlags = 63, + ThisNodeOrAnySubNodesHasError = 64, + HasAggregatedChildData = 128, } const enum RelationComparisonResult { Succeeded = 1, @@ -344,6 +348,7 @@ declare module "typescript" { kind: SyntaxKind; flags: NodeFlags; parserContextFlags?: ParserContextFlags; + decorators?: NodeArray; modifiers?: ModifiersArray; id?: number; parent?: Node; @@ -374,6 +379,10 @@ declare module "typescript" { interface ComputedPropertyName extends Node { expression: Expression; } + interface Decorator extends Node { + atToken: Node; + expression: LeftHandSideExpression; + } interface TypeParameterDeclaration extends Declaration { name: Identifier; constraint?: TypeNode; @@ -576,7 +585,9 @@ declare module "typescript" { expression: Expression; } interface ArrayLiteralExpression extends PrimaryExpression { + openBracketToken: Node; elements: NodeArray; + closeBracketToken: Node; } interface SpreadElementExpression extends Expression { expression: Expression; @@ -591,7 +602,9 @@ declare module "typescript" { } interface ElementAccessExpression extends MemberExpression { expression: LeftHandSideExpression; + openBracketToken: Node; argumentExpression?: Expression; + closeBracketToken: Node; } interface CallExpression extends LeftHandSideExpression { expression: LeftHandSideExpression; diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index 336d70aa1a196..0b00bbc191c54 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -351,562 +351,571 @@ declare module "typescript" { ColonToken = 51, >ColonToken : SyntaxKind - EqualsToken = 52, + AtToken = 52, +>AtToken : SyntaxKind + + EqualsToken = 53, >EqualsToken : SyntaxKind - PlusEqualsToken = 53, + PlusEqualsToken = 54, >PlusEqualsToken : SyntaxKind - MinusEqualsToken = 54, + MinusEqualsToken = 55, >MinusEqualsToken : SyntaxKind - AsteriskEqualsToken = 55, + AsteriskEqualsToken = 56, >AsteriskEqualsToken : SyntaxKind - SlashEqualsToken = 56, + SlashEqualsToken = 57, >SlashEqualsToken : SyntaxKind - PercentEqualsToken = 57, + PercentEqualsToken = 58, >PercentEqualsToken : SyntaxKind - LessThanLessThanEqualsToken = 58, + LessThanLessThanEqualsToken = 59, >LessThanLessThanEqualsToken : SyntaxKind - GreaterThanGreaterThanEqualsToken = 59, + GreaterThanGreaterThanEqualsToken = 60, >GreaterThanGreaterThanEqualsToken : SyntaxKind - GreaterThanGreaterThanGreaterThanEqualsToken = 60, + GreaterThanGreaterThanGreaterThanEqualsToken = 61, >GreaterThanGreaterThanGreaterThanEqualsToken : SyntaxKind - AmpersandEqualsToken = 61, + AmpersandEqualsToken = 62, >AmpersandEqualsToken : SyntaxKind - BarEqualsToken = 62, + BarEqualsToken = 63, >BarEqualsToken : SyntaxKind - CaretEqualsToken = 63, + CaretEqualsToken = 64, >CaretEqualsToken : SyntaxKind - Identifier = 64, + Identifier = 65, >Identifier : SyntaxKind - BreakKeyword = 65, + BreakKeyword = 66, >BreakKeyword : SyntaxKind - CaseKeyword = 66, + CaseKeyword = 67, >CaseKeyword : SyntaxKind - CatchKeyword = 67, + CatchKeyword = 68, >CatchKeyword : SyntaxKind - ClassKeyword = 68, + ClassKeyword = 69, >ClassKeyword : SyntaxKind - ConstKeyword = 69, + ConstKeyword = 70, >ConstKeyword : SyntaxKind - ContinueKeyword = 70, + ContinueKeyword = 71, >ContinueKeyword : SyntaxKind - DebuggerKeyword = 71, + DebuggerKeyword = 72, >DebuggerKeyword : SyntaxKind - DefaultKeyword = 72, + DefaultKeyword = 73, >DefaultKeyword : SyntaxKind - DeleteKeyword = 73, + DeleteKeyword = 74, >DeleteKeyword : SyntaxKind - DoKeyword = 74, + DoKeyword = 75, >DoKeyword : SyntaxKind - ElseKeyword = 75, + ElseKeyword = 76, >ElseKeyword : SyntaxKind - EnumKeyword = 76, + EnumKeyword = 77, >EnumKeyword : SyntaxKind - ExportKeyword = 77, + ExportKeyword = 78, >ExportKeyword : SyntaxKind - ExtendsKeyword = 78, + ExtendsKeyword = 79, >ExtendsKeyword : SyntaxKind - FalseKeyword = 79, + FalseKeyword = 80, >FalseKeyword : SyntaxKind - FinallyKeyword = 80, + FinallyKeyword = 81, >FinallyKeyword : SyntaxKind - ForKeyword = 81, + ForKeyword = 82, >ForKeyword : SyntaxKind - FunctionKeyword = 82, + FunctionKeyword = 83, >FunctionKeyword : SyntaxKind - IfKeyword = 83, + IfKeyword = 84, >IfKeyword : SyntaxKind - ImportKeyword = 84, + ImportKeyword = 85, >ImportKeyword : SyntaxKind - InKeyword = 85, + InKeyword = 86, >InKeyword : SyntaxKind - InstanceOfKeyword = 86, + InstanceOfKeyword = 87, >InstanceOfKeyword : SyntaxKind - NewKeyword = 87, + NewKeyword = 88, >NewKeyword : SyntaxKind - NullKeyword = 88, + NullKeyword = 89, >NullKeyword : SyntaxKind - ReturnKeyword = 89, + ReturnKeyword = 90, >ReturnKeyword : SyntaxKind - SuperKeyword = 90, + SuperKeyword = 91, >SuperKeyword : SyntaxKind - SwitchKeyword = 91, + SwitchKeyword = 92, >SwitchKeyword : SyntaxKind - ThisKeyword = 92, + ThisKeyword = 93, >ThisKeyword : SyntaxKind - ThrowKeyword = 93, + ThrowKeyword = 94, >ThrowKeyword : SyntaxKind - TrueKeyword = 94, + TrueKeyword = 95, >TrueKeyword : SyntaxKind - TryKeyword = 95, + TryKeyword = 96, >TryKeyword : SyntaxKind - TypeOfKeyword = 96, + TypeOfKeyword = 97, >TypeOfKeyword : SyntaxKind - VarKeyword = 97, + VarKeyword = 98, >VarKeyword : SyntaxKind - VoidKeyword = 98, + VoidKeyword = 99, >VoidKeyword : SyntaxKind - WhileKeyword = 99, + WhileKeyword = 100, >WhileKeyword : SyntaxKind - WithKeyword = 100, + WithKeyword = 101, >WithKeyword : SyntaxKind - AsKeyword = 101, + AsKeyword = 102, >AsKeyword : SyntaxKind - ImplementsKeyword = 102, + ImplementsKeyword = 103, >ImplementsKeyword : SyntaxKind - InterfaceKeyword = 103, + InterfaceKeyword = 104, >InterfaceKeyword : SyntaxKind - LetKeyword = 104, + LetKeyword = 105, >LetKeyword : SyntaxKind - PackageKeyword = 105, + PackageKeyword = 106, >PackageKeyword : SyntaxKind - PrivateKeyword = 106, + PrivateKeyword = 107, >PrivateKeyword : SyntaxKind - ProtectedKeyword = 107, + ProtectedKeyword = 108, >ProtectedKeyword : SyntaxKind - PublicKeyword = 108, + PublicKeyword = 109, >PublicKeyword : SyntaxKind - StaticKeyword = 109, + StaticKeyword = 110, >StaticKeyword : SyntaxKind - YieldKeyword = 110, + YieldKeyword = 111, >YieldKeyword : SyntaxKind - AnyKeyword = 111, + AnyKeyword = 112, >AnyKeyword : SyntaxKind - BooleanKeyword = 112, + BooleanKeyword = 113, >BooleanKeyword : SyntaxKind - ConstructorKeyword = 113, + ConstructorKeyword = 114, >ConstructorKeyword : SyntaxKind - DeclareKeyword = 114, + DeclareKeyword = 115, >DeclareKeyword : SyntaxKind - GetKeyword = 115, + GetKeyword = 116, >GetKeyword : SyntaxKind - ModuleKeyword = 116, + ModuleKeyword = 117, >ModuleKeyword : SyntaxKind - RequireKeyword = 117, + RequireKeyword = 118, >RequireKeyword : SyntaxKind - NumberKeyword = 118, + NumberKeyword = 119, >NumberKeyword : SyntaxKind - SetKeyword = 119, + SetKeyword = 120, >SetKeyword : SyntaxKind - StringKeyword = 120, + StringKeyword = 121, >StringKeyword : SyntaxKind - SymbolKeyword = 121, + SymbolKeyword = 122, >SymbolKeyword : SyntaxKind - TypeKeyword = 122, + TypeKeyword = 123, >TypeKeyword : SyntaxKind - FromKeyword = 123, + FromKeyword = 124, >FromKeyword : SyntaxKind - OfKeyword = 124, + OfKeyword = 125, >OfKeyword : SyntaxKind - QualifiedName = 125, + QualifiedName = 126, >QualifiedName : SyntaxKind - ComputedPropertyName = 126, + ComputedPropertyName = 127, >ComputedPropertyName : SyntaxKind - TypeParameter = 127, + TypeParameter = 128, >TypeParameter : SyntaxKind - Parameter = 128, + Parameter = 129, >Parameter : SyntaxKind - PropertySignature = 129, + Decorator = 130, +>Decorator : SyntaxKind + + PropertySignature = 131, >PropertySignature : SyntaxKind - PropertyDeclaration = 130, + PropertyDeclaration = 132, >PropertyDeclaration : SyntaxKind - MethodSignature = 131, + MethodSignature = 133, >MethodSignature : SyntaxKind - MethodDeclaration = 132, + MethodDeclaration = 134, >MethodDeclaration : SyntaxKind - Constructor = 133, + Constructor = 135, >Constructor : SyntaxKind - GetAccessor = 134, + GetAccessor = 136, >GetAccessor : SyntaxKind - SetAccessor = 135, + SetAccessor = 137, >SetAccessor : SyntaxKind - CallSignature = 136, + CallSignature = 138, >CallSignature : SyntaxKind - ConstructSignature = 137, + ConstructSignature = 139, >ConstructSignature : SyntaxKind - IndexSignature = 138, + IndexSignature = 140, >IndexSignature : SyntaxKind - TypeReference = 139, + TypeReference = 141, >TypeReference : SyntaxKind - FunctionType = 140, + FunctionType = 142, >FunctionType : SyntaxKind - ConstructorType = 141, + ConstructorType = 143, >ConstructorType : SyntaxKind - TypeQuery = 142, + TypeQuery = 144, >TypeQuery : SyntaxKind - TypeLiteral = 143, + TypeLiteral = 145, >TypeLiteral : SyntaxKind - ArrayType = 144, + ArrayType = 146, >ArrayType : SyntaxKind - TupleType = 145, + TupleType = 147, >TupleType : SyntaxKind - UnionType = 146, + UnionType = 148, >UnionType : SyntaxKind - ParenthesizedType = 147, + ParenthesizedType = 149, >ParenthesizedType : SyntaxKind - ObjectBindingPattern = 148, + ObjectBindingPattern = 150, >ObjectBindingPattern : SyntaxKind - ArrayBindingPattern = 149, + ArrayBindingPattern = 151, >ArrayBindingPattern : SyntaxKind - BindingElement = 150, + BindingElement = 152, >BindingElement : SyntaxKind - ArrayLiteralExpression = 151, + ArrayLiteralExpression = 153, >ArrayLiteralExpression : SyntaxKind - ObjectLiteralExpression = 152, + ObjectLiteralExpression = 154, >ObjectLiteralExpression : SyntaxKind - PropertyAccessExpression = 153, + PropertyAccessExpression = 155, >PropertyAccessExpression : SyntaxKind - ElementAccessExpression = 154, + ElementAccessExpression = 156, >ElementAccessExpression : SyntaxKind - CallExpression = 155, + CallExpression = 157, >CallExpression : SyntaxKind - NewExpression = 156, + NewExpression = 158, >NewExpression : SyntaxKind - TaggedTemplateExpression = 157, + TaggedTemplateExpression = 159, >TaggedTemplateExpression : SyntaxKind - TypeAssertionExpression = 158, + TypeAssertionExpression = 160, >TypeAssertionExpression : SyntaxKind - ParenthesizedExpression = 159, + ParenthesizedExpression = 161, >ParenthesizedExpression : SyntaxKind - FunctionExpression = 160, + FunctionExpression = 162, >FunctionExpression : SyntaxKind - ArrowFunction = 161, + ArrowFunction = 163, >ArrowFunction : SyntaxKind - DeleteExpression = 162, + DeleteExpression = 164, >DeleteExpression : SyntaxKind - TypeOfExpression = 163, + TypeOfExpression = 165, >TypeOfExpression : SyntaxKind - VoidExpression = 164, + VoidExpression = 166, >VoidExpression : SyntaxKind - PrefixUnaryExpression = 165, + PrefixUnaryExpression = 167, >PrefixUnaryExpression : SyntaxKind - PostfixUnaryExpression = 166, + PostfixUnaryExpression = 168, >PostfixUnaryExpression : SyntaxKind - BinaryExpression = 167, + BinaryExpression = 169, >BinaryExpression : SyntaxKind - ConditionalExpression = 168, + ConditionalExpression = 170, >ConditionalExpression : SyntaxKind - TemplateExpression = 169, + TemplateExpression = 171, >TemplateExpression : SyntaxKind - YieldExpression = 170, + YieldExpression = 172, >YieldExpression : SyntaxKind - SpreadElementExpression = 171, + SpreadElementExpression = 173, >SpreadElementExpression : SyntaxKind - OmittedExpression = 172, + OmittedExpression = 174, >OmittedExpression : SyntaxKind - TemplateSpan = 173, + TemplateSpan = 175, >TemplateSpan : SyntaxKind - Block = 174, + Block = 176, >Block : SyntaxKind - VariableStatement = 175, + VariableStatement = 177, >VariableStatement : SyntaxKind - EmptyStatement = 176, + EmptyStatement = 178, >EmptyStatement : SyntaxKind - ExpressionStatement = 177, + ExpressionStatement = 179, >ExpressionStatement : SyntaxKind - IfStatement = 178, + IfStatement = 180, >IfStatement : SyntaxKind - DoStatement = 179, + DoStatement = 181, >DoStatement : SyntaxKind - WhileStatement = 180, + WhileStatement = 182, >WhileStatement : SyntaxKind - ForStatement = 181, + ForStatement = 183, >ForStatement : SyntaxKind - ForInStatement = 182, + ForInStatement = 184, >ForInStatement : SyntaxKind - ForOfStatement = 183, + ForOfStatement = 185, >ForOfStatement : SyntaxKind - ContinueStatement = 184, + ContinueStatement = 186, >ContinueStatement : SyntaxKind - BreakStatement = 185, + BreakStatement = 187, >BreakStatement : SyntaxKind - ReturnStatement = 186, + ReturnStatement = 188, >ReturnStatement : SyntaxKind - WithStatement = 187, + WithStatement = 189, >WithStatement : SyntaxKind - SwitchStatement = 188, + SwitchStatement = 190, >SwitchStatement : SyntaxKind - LabeledStatement = 189, + LabeledStatement = 191, >LabeledStatement : SyntaxKind - ThrowStatement = 190, + ThrowStatement = 192, >ThrowStatement : SyntaxKind - TryStatement = 191, + TryStatement = 193, >TryStatement : SyntaxKind - DebuggerStatement = 192, + DebuggerStatement = 194, >DebuggerStatement : SyntaxKind - VariableDeclaration = 193, + VariableDeclaration = 195, >VariableDeclaration : SyntaxKind - VariableDeclarationList = 194, + VariableDeclarationList = 196, >VariableDeclarationList : SyntaxKind - FunctionDeclaration = 195, + FunctionDeclaration = 197, >FunctionDeclaration : SyntaxKind - ClassDeclaration = 196, + ClassDeclaration = 198, >ClassDeclaration : SyntaxKind - InterfaceDeclaration = 197, + InterfaceDeclaration = 199, >InterfaceDeclaration : SyntaxKind - TypeAliasDeclaration = 198, + TypeAliasDeclaration = 200, >TypeAliasDeclaration : SyntaxKind - EnumDeclaration = 199, + EnumDeclaration = 201, >EnumDeclaration : SyntaxKind - ModuleDeclaration = 200, + ModuleDeclaration = 202, >ModuleDeclaration : SyntaxKind - ModuleBlock = 201, + ModuleBlock = 203, >ModuleBlock : SyntaxKind - CaseBlock = 202, + CaseBlock = 204, >CaseBlock : SyntaxKind - ImportEqualsDeclaration = 203, + ImportEqualsDeclaration = 205, >ImportEqualsDeclaration : SyntaxKind - ImportDeclaration = 204, + ImportDeclaration = 206, >ImportDeclaration : SyntaxKind - ImportClause = 205, + ImportClause = 207, >ImportClause : SyntaxKind - NamespaceImport = 206, + NamespaceImport = 208, >NamespaceImport : SyntaxKind - NamedImports = 207, + NamedImports = 209, >NamedImports : SyntaxKind - ImportSpecifier = 208, + ImportSpecifier = 210, >ImportSpecifier : SyntaxKind - ExportAssignment = 209, + ExportAssignment = 211, >ExportAssignment : SyntaxKind - ExportDeclaration = 210, + ExportDeclaration = 212, >ExportDeclaration : SyntaxKind - NamedExports = 211, + NamedExports = 213, >NamedExports : SyntaxKind - ExportSpecifier = 212, + ExportSpecifier = 214, >ExportSpecifier : SyntaxKind - ExternalModuleReference = 213, + IncompleteDeclaration = 215, +>IncompleteDeclaration : SyntaxKind + + ExternalModuleReference = 216, >ExternalModuleReference : SyntaxKind - CaseClause = 214, + CaseClause = 217, >CaseClause : SyntaxKind - DefaultClause = 215, + DefaultClause = 218, >DefaultClause : SyntaxKind - HeritageClause = 216, + HeritageClause = 219, >HeritageClause : SyntaxKind - CatchClause = 217, + CatchClause = 220, >CatchClause : SyntaxKind - PropertyAssignment = 218, + PropertyAssignment = 221, >PropertyAssignment : SyntaxKind - ShorthandPropertyAssignment = 219, + ShorthandPropertyAssignment = 222, >ShorthandPropertyAssignment : SyntaxKind - EnumMember = 220, + EnumMember = 223, >EnumMember : SyntaxKind - SourceFile = 221, + SourceFile = 224, >SourceFile : SyntaxKind - SyntaxList = 222, + SyntaxList = 225, >SyntaxList : SyntaxKind - Count = 223, + Count = 226, >Count : SyntaxKind - FirstAssignment = 52, + FirstAssignment = 53, >FirstAssignment : SyntaxKind - LastAssignment = 63, + LastAssignment = 64, >LastAssignment : SyntaxKind - FirstReservedWord = 65, + FirstReservedWord = 66, >FirstReservedWord : SyntaxKind - LastReservedWord = 100, + LastReservedWord = 101, >LastReservedWord : SyntaxKind - FirstKeyword = 65, + FirstKeyword = 66, >FirstKeyword : SyntaxKind - LastKeyword = 124, + LastKeyword = 125, >LastKeyword : SyntaxKind - FirstFutureReservedWord = 102, + FirstFutureReservedWord = 103, >FirstFutureReservedWord : SyntaxKind - LastFutureReservedWord = 110, + LastFutureReservedWord = 111, >LastFutureReservedWord : SyntaxKind - FirstTypeNode = 139, + FirstTypeNode = 141, >FirstTypeNode : SyntaxKind - LastTypeNode = 147, + LastTypeNode = 149, >LastTypeNode : SyntaxKind FirstPunctuation = 14, >FirstPunctuation : SyntaxKind - LastPunctuation = 63, + LastPunctuation = 64, >LastPunctuation : SyntaxKind FirstToken = 0, >FirstToken : SyntaxKind - LastToken = 124, + LastToken = 125, >LastToken : SyntaxKind FirstTriviaToken = 2, @@ -930,10 +939,10 @@ declare module "typescript" { FirstBinaryOperator = 24, >FirstBinaryOperator : SyntaxKind - LastBinaryOperator = 63, + LastBinaryOperator = 64, >LastBinaryOperator : SyntaxKind - FirstNode = 125, + FirstNode = 126, >FirstNode : SyntaxKind } const enum NodeFlags { @@ -1002,16 +1011,19 @@ declare module "typescript" { GeneratorParameter = 8, >GeneratorParameter : ParserContextFlags - ThisNodeHasError = 16, + Decorator = 16, +>Decorator : ParserContextFlags + + ThisNodeHasError = 32, >ThisNodeHasError : ParserContextFlags - ParserGeneratedFlags = 31, + ParserGeneratedFlags = 63, >ParserGeneratedFlags : ParserContextFlags - ThisNodeOrAnySubNodesHasError = 32, + ThisNodeOrAnySubNodesHasError = 64, >ThisNodeOrAnySubNodesHasError : ParserContextFlags - HasAggregatedChildData = 64, + HasAggregatedChildData = 128, >HasAggregatedChildData : ParserContextFlags } const enum RelationComparisonResult { @@ -1042,6 +1054,11 @@ declare module "typescript" { >parserContextFlags : ParserContextFlags >ParserContextFlags : ParserContextFlags + decorators?: NodeArray; +>decorators : NodeArray +>NodeArray : NodeArray +>Decorator : Decorator + modifiers?: ModifiersArray; >modifiers : ModifiersArray >ModifiersArray : ModifiersArray @@ -1136,6 +1153,18 @@ declare module "typescript" { expression: Expression; >expression : Expression >Expression : Expression + } + interface Decorator extends Node { +>Decorator : Decorator +>Node : Node + + atToken: Node; +>atToken : Node +>Node : Node + + expression: LeftHandSideExpression; +>expression : LeftHandSideExpression +>LeftHandSideExpression : LeftHandSideExpression } interface TypeParameterDeclaration extends Declaration { >TypeParameterDeclaration : TypeParameterDeclaration @@ -1735,10 +1764,18 @@ declare module "typescript" { >ArrayLiteralExpression : ArrayLiteralExpression >PrimaryExpression : PrimaryExpression + openBracketToken: Node; +>openBracketToken : Node +>Node : Node + elements: NodeArray; >elements : NodeArray >NodeArray : NodeArray >Expression : Expression + + closeBracketToken: Node; +>closeBracketToken : Node +>Node : Node } interface SpreadElementExpression extends Expression { >SpreadElementExpression : SpreadElementExpression @@ -1782,9 +1819,17 @@ declare module "typescript" { >expression : LeftHandSideExpression >LeftHandSideExpression : LeftHandSideExpression + openBracketToken: Node; +>openBracketToken : Node +>Node : Node + argumentExpression?: Expression; >argumentExpression : Expression >Expression : Expression + + closeBracketToken: Node; +>closeBracketToken : Node +>Node : Node } interface CallExpression extends LeftHandSideExpression { >CallExpression : CallExpression diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index e7145e2407059..c819c0605677c 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -142,192 +142,195 @@ declare module "typescript" { BarBarToken = 49, QuestionToken = 50, ColonToken = 51, - EqualsToken = 52, - PlusEqualsToken = 53, - MinusEqualsToken = 54, - AsteriskEqualsToken = 55, - SlashEqualsToken = 56, - PercentEqualsToken = 57, - LessThanLessThanEqualsToken = 58, - GreaterThanGreaterThanEqualsToken = 59, - GreaterThanGreaterThanGreaterThanEqualsToken = 60, - AmpersandEqualsToken = 61, - BarEqualsToken = 62, - CaretEqualsToken = 63, - Identifier = 64, - BreakKeyword = 65, - CaseKeyword = 66, - CatchKeyword = 67, - ClassKeyword = 68, - ConstKeyword = 69, - ContinueKeyword = 70, - DebuggerKeyword = 71, - DefaultKeyword = 72, - DeleteKeyword = 73, - DoKeyword = 74, - ElseKeyword = 75, - EnumKeyword = 76, - ExportKeyword = 77, - ExtendsKeyword = 78, - FalseKeyword = 79, - FinallyKeyword = 80, - ForKeyword = 81, - FunctionKeyword = 82, - IfKeyword = 83, - ImportKeyword = 84, - InKeyword = 85, - InstanceOfKeyword = 86, - NewKeyword = 87, - NullKeyword = 88, - ReturnKeyword = 89, - SuperKeyword = 90, - SwitchKeyword = 91, - ThisKeyword = 92, - ThrowKeyword = 93, - TrueKeyword = 94, - TryKeyword = 95, - TypeOfKeyword = 96, - VarKeyword = 97, - VoidKeyword = 98, - WhileKeyword = 99, - WithKeyword = 100, - AsKeyword = 101, - ImplementsKeyword = 102, - InterfaceKeyword = 103, - LetKeyword = 104, - PackageKeyword = 105, - PrivateKeyword = 106, - ProtectedKeyword = 107, - PublicKeyword = 108, - StaticKeyword = 109, - YieldKeyword = 110, - AnyKeyword = 111, - BooleanKeyword = 112, - ConstructorKeyword = 113, - DeclareKeyword = 114, - GetKeyword = 115, - ModuleKeyword = 116, - RequireKeyword = 117, - NumberKeyword = 118, - SetKeyword = 119, - StringKeyword = 120, - SymbolKeyword = 121, - TypeKeyword = 122, - FromKeyword = 123, - OfKeyword = 124, - QualifiedName = 125, - ComputedPropertyName = 126, - TypeParameter = 127, - Parameter = 128, - PropertySignature = 129, - PropertyDeclaration = 130, - MethodSignature = 131, - MethodDeclaration = 132, - Constructor = 133, - GetAccessor = 134, - SetAccessor = 135, - CallSignature = 136, - ConstructSignature = 137, - IndexSignature = 138, - TypeReference = 139, - FunctionType = 140, - ConstructorType = 141, - TypeQuery = 142, - TypeLiteral = 143, - ArrayType = 144, - TupleType = 145, - UnionType = 146, - ParenthesizedType = 147, - ObjectBindingPattern = 148, - ArrayBindingPattern = 149, - BindingElement = 150, - ArrayLiteralExpression = 151, - ObjectLiteralExpression = 152, - PropertyAccessExpression = 153, - ElementAccessExpression = 154, - CallExpression = 155, - NewExpression = 156, - TaggedTemplateExpression = 157, - TypeAssertionExpression = 158, - ParenthesizedExpression = 159, - FunctionExpression = 160, - ArrowFunction = 161, - DeleteExpression = 162, - TypeOfExpression = 163, - VoidExpression = 164, - PrefixUnaryExpression = 165, - PostfixUnaryExpression = 166, - BinaryExpression = 167, - ConditionalExpression = 168, - TemplateExpression = 169, - YieldExpression = 170, - SpreadElementExpression = 171, - OmittedExpression = 172, - TemplateSpan = 173, - Block = 174, - VariableStatement = 175, - EmptyStatement = 176, - ExpressionStatement = 177, - IfStatement = 178, - DoStatement = 179, - WhileStatement = 180, - ForStatement = 181, - ForInStatement = 182, - ForOfStatement = 183, - ContinueStatement = 184, - BreakStatement = 185, - ReturnStatement = 186, - WithStatement = 187, - SwitchStatement = 188, - LabeledStatement = 189, - ThrowStatement = 190, - TryStatement = 191, - DebuggerStatement = 192, - VariableDeclaration = 193, - VariableDeclarationList = 194, - FunctionDeclaration = 195, - ClassDeclaration = 196, - InterfaceDeclaration = 197, - TypeAliasDeclaration = 198, - EnumDeclaration = 199, - ModuleDeclaration = 200, - ModuleBlock = 201, - CaseBlock = 202, - ImportEqualsDeclaration = 203, - ImportDeclaration = 204, - ImportClause = 205, - NamespaceImport = 206, - NamedImports = 207, - ImportSpecifier = 208, - ExportAssignment = 209, - ExportDeclaration = 210, - NamedExports = 211, - ExportSpecifier = 212, - ExternalModuleReference = 213, - CaseClause = 214, - DefaultClause = 215, - HeritageClause = 216, - CatchClause = 217, - PropertyAssignment = 218, - ShorthandPropertyAssignment = 219, - EnumMember = 220, - SourceFile = 221, - SyntaxList = 222, - Count = 223, - FirstAssignment = 52, - LastAssignment = 63, - FirstReservedWord = 65, - LastReservedWord = 100, - FirstKeyword = 65, - LastKeyword = 124, - FirstFutureReservedWord = 102, - LastFutureReservedWord = 110, - FirstTypeNode = 139, - LastTypeNode = 147, + AtToken = 52, + EqualsToken = 53, + PlusEqualsToken = 54, + MinusEqualsToken = 55, + AsteriskEqualsToken = 56, + SlashEqualsToken = 57, + PercentEqualsToken = 58, + LessThanLessThanEqualsToken = 59, + GreaterThanGreaterThanEqualsToken = 60, + GreaterThanGreaterThanGreaterThanEqualsToken = 61, + AmpersandEqualsToken = 62, + BarEqualsToken = 63, + CaretEqualsToken = 64, + Identifier = 65, + BreakKeyword = 66, + CaseKeyword = 67, + CatchKeyword = 68, + ClassKeyword = 69, + ConstKeyword = 70, + ContinueKeyword = 71, + DebuggerKeyword = 72, + DefaultKeyword = 73, + DeleteKeyword = 74, + DoKeyword = 75, + ElseKeyword = 76, + EnumKeyword = 77, + ExportKeyword = 78, + ExtendsKeyword = 79, + FalseKeyword = 80, + FinallyKeyword = 81, + ForKeyword = 82, + FunctionKeyword = 83, + IfKeyword = 84, + ImportKeyword = 85, + InKeyword = 86, + InstanceOfKeyword = 87, + NewKeyword = 88, + NullKeyword = 89, + ReturnKeyword = 90, + SuperKeyword = 91, + SwitchKeyword = 92, + ThisKeyword = 93, + ThrowKeyword = 94, + TrueKeyword = 95, + TryKeyword = 96, + TypeOfKeyword = 97, + VarKeyword = 98, + VoidKeyword = 99, + WhileKeyword = 100, + WithKeyword = 101, + AsKeyword = 102, + ImplementsKeyword = 103, + InterfaceKeyword = 104, + LetKeyword = 105, + PackageKeyword = 106, + PrivateKeyword = 107, + ProtectedKeyword = 108, + PublicKeyword = 109, + StaticKeyword = 110, + YieldKeyword = 111, + AnyKeyword = 112, + BooleanKeyword = 113, + ConstructorKeyword = 114, + DeclareKeyword = 115, + GetKeyword = 116, + ModuleKeyword = 117, + RequireKeyword = 118, + NumberKeyword = 119, + SetKeyword = 120, + StringKeyword = 121, + SymbolKeyword = 122, + TypeKeyword = 123, + FromKeyword = 124, + OfKeyword = 125, + QualifiedName = 126, + ComputedPropertyName = 127, + TypeParameter = 128, + Parameter = 129, + Decorator = 130, + PropertySignature = 131, + PropertyDeclaration = 132, + MethodSignature = 133, + MethodDeclaration = 134, + Constructor = 135, + GetAccessor = 136, + SetAccessor = 137, + CallSignature = 138, + ConstructSignature = 139, + IndexSignature = 140, + TypeReference = 141, + FunctionType = 142, + ConstructorType = 143, + TypeQuery = 144, + TypeLiteral = 145, + ArrayType = 146, + TupleType = 147, + UnionType = 148, + ParenthesizedType = 149, + ObjectBindingPattern = 150, + ArrayBindingPattern = 151, + BindingElement = 152, + ArrayLiteralExpression = 153, + ObjectLiteralExpression = 154, + PropertyAccessExpression = 155, + ElementAccessExpression = 156, + CallExpression = 157, + NewExpression = 158, + TaggedTemplateExpression = 159, + TypeAssertionExpression = 160, + ParenthesizedExpression = 161, + FunctionExpression = 162, + ArrowFunction = 163, + DeleteExpression = 164, + TypeOfExpression = 165, + VoidExpression = 166, + PrefixUnaryExpression = 167, + PostfixUnaryExpression = 168, + BinaryExpression = 169, + ConditionalExpression = 170, + TemplateExpression = 171, + YieldExpression = 172, + SpreadElementExpression = 173, + OmittedExpression = 174, + TemplateSpan = 175, + Block = 176, + VariableStatement = 177, + EmptyStatement = 178, + ExpressionStatement = 179, + IfStatement = 180, + DoStatement = 181, + WhileStatement = 182, + ForStatement = 183, + ForInStatement = 184, + ForOfStatement = 185, + ContinueStatement = 186, + BreakStatement = 187, + ReturnStatement = 188, + WithStatement = 189, + SwitchStatement = 190, + LabeledStatement = 191, + ThrowStatement = 192, + TryStatement = 193, + DebuggerStatement = 194, + VariableDeclaration = 195, + VariableDeclarationList = 196, + FunctionDeclaration = 197, + ClassDeclaration = 198, + InterfaceDeclaration = 199, + TypeAliasDeclaration = 200, + EnumDeclaration = 201, + ModuleDeclaration = 202, + ModuleBlock = 203, + CaseBlock = 204, + ImportEqualsDeclaration = 205, + ImportDeclaration = 206, + ImportClause = 207, + NamespaceImport = 208, + NamedImports = 209, + ImportSpecifier = 210, + ExportAssignment = 211, + ExportDeclaration = 212, + NamedExports = 213, + ExportSpecifier = 214, + IncompleteDeclaration = 215, + ExternalModuleReference = 216, + CaseClause = 217, + DefaultClause = 218, + HeritageClause = 219, + CatchClause = 220, + PropertyAssignment = 221, + ShorthandPropertyAssignment = 222, + EnumMember = 223, + SourceFile = 224, + SyntaxList = 225, + Count = 226, + FirstAssignment = 53, + LastAssignment = 64, + FirstReservedWord = 66, + LastReservedWord = 101, + FirstKeyword = 66, + LastKeyword = 125, + FirstFutureReservedWord = 103, + LastFutureReservedWord = 111, + FirstTypeNode = 141, + LastTypeNode = 149, FirstPunctuation = 14, - LastPunctuation = 63, + LastPunctuation = 64, FirstToken = 0, - LastToken = 124, + LastToken = 125, FirstTriviaToken = 2, LastTriviaToken = 6, FirstLiteralToken = 7, @@ -335,8 +338,8 @@ declare module "typescript" { FirstTemplateToken = 10, LastTemplateToken = 13, FirstBinaryOperator = 24, - LastBinaryOperator = 63, - FirstNode = 125, + LastBinaryOperator = 64, + FirstNode = 126, } const enum NodeFlags { Export = 1, @@ -361,10 +364,11 @@ declare module "typescript" { DisallowIn = 2, Yield = 4, GeneratorParameter = 8, - ThisNodeHasError = 16, - ParserGeneratedFlags = 31, - ThisNodeOrAnySubNodesHasError = 32, - HasAggregatedChildData = 64, + Decorator = 16, + ThisNodeHasError = 32, + ParserGeneratedFlags = 63, + ThisNodeOrAnySubNodesHasError = 64, + HasAggregatedChildData = 128, } const enum RelationComparisonResult { Succeeded = 1, @@ -375,6 +379,7 @@ declare module "typescript" { kind: SyntaxKind; flags: NodeFlags; parserContextFlags?: ParserContextFlags; + decorators?: NodeArray; modifiers?: ModifiersArray; id?: number; parent?: Node; @@ -405,6 +410,10 @@ declare module "typescript" { interface ComputedPropertyName extends Node { expression: Expression; } + interface Decorator extends Node { + atToken: Node; + expression: LeftHandSideExpression; + } interface TypeParameterDeclaration extends Declaration { name: Identifier; constraint?: TypeNode; @@ -607,7 +616,9 @@ declare module "typescript" { expression: Expression; } interface ArrayLiteralExpression extends PrimaryExpression { + openBracketToken: Node; elements: NodeArray; + closeBracketToken: Node; } interface SpreadElementExpression extends Expression { expression: Expression; @@ -622,7 +633,9 @@ declare module "typescript" { } interface ElementAccessExpression extends MemberExpression { expression: LeftHandSideExpression; + openBracketToken: Node; argumentExpression?: Expression; + closeBracketToken: Node; } interface CallExpression extends LeftHandSideExpression { expression: LeftHandSideExpression; @@ -2023,24 +2036,24 @@ function delint(sourceFile) { delintNode(sourceFile); function delintNode(node) { switch (node.kind) { - case 181 /* ForStatement */: - case 182 /* ForInStatement */: - case 180 /* WhileStatement */: - case 179 /* DoStatement */: - if (node.statement.kind !== 174 /* Block */) { + case 183 /* ForStatement */: + case 184 /* ForInStatement */: + case 182 /* WhileStatement */: + case 181 /* DoStatement */: + if (node.statement.kind !== 176 /* Block */) { report(node, "A looping statement's contents should be wrapped in a block body."); } break; - case 178 /* IfStatement */: + case 180 /* IfStatement */: var ifStatement = node; - if (ifStatement.thenStatement.kind !== 174 /* Block */) { + if (ifStatement.thenStatement.kind !== 176 /* Block */) { report(ifStatement.thenStatement, "An if statement's contents should be wrapped in a block body."); } - if (ifStatement.elseStatement && ifStatement.elseStatement.kind !== 174 /* Block */ && ifStatement.elseStatement.kind !== 178 /* IfStatement */) { + if (ifStatement.elseStatement && ifStatement.elseStatement.kind !== 176 /* Block */ && ifStatement.elseStatement.kind !== 180 /* IfStatement */) { report(ifStatement.elseStatement, "An else statement's contents should be wrapped in a block body."); } break; - case 167 /* BinaryExpression */: + case 169 /* BinaryExpression */: var op = node.operatorToken.kind; if (op === 28 /* EqualsEqualsToken */ || op === 29 /* ExclamationEqualsToken */) { report(node, "Use '===' and '!=='."); diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index a40848b9e4c63..c19778ea49926 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -497,562 +497,571 @@ declare module "typescript" { ColonToken = 51, >ColonToken : SyntaxKind - EqualsToken = 52, + AtToken = 52, +>AtToken : SyntaxKind + + EqualsToken = 53, >EqualsToken : SyntaxKind - PlusEqualsToken = 53, + PlusEqualsToken = 54, >PlusEqualsToken : SyntaxKind - MinusEqualsToken = 54, + MinusEqualsToken = 55, >MinusEqualsToken : SyntaxKind - AsteriskEqualsToken = 55, + AsteriskEqualsToken = 56, >AsteriskEqualsToken : SyntaxKind - SlashEqualsToken = 56, + SlashEqualsToken = 57, >SlashEqualsToken : SyntaxKind - PercentEqualsToken = 57, + PercentEqualsToken = 58, >PercentEqualsToken : SyntaxKind - LessThanLessThanEqualsToken = 58, + LessThanLessThanEqualsToken = 59, >LessThanLessThanEqualsToken : SyntaxKind - GreaterThanGreaterThanEqualsToken = 59, + GreaterThanGreaterThanEqualsToken = 60, >GreaterThanGreaterThanEqualsToken : SyntaxKind - GreaterThanGreaterThanGreaterThanEqualsToken = 60, + GreaterThanGreaterThanGreaterThanEqualsToken = 61, >GreaterThanGreaterThanGreaterThanEqualsToken : SyntaxKind - AmpersandEqualsToken = 61, + AmpersandEqualsToken = 62, >AmpersandEqualsToken : SyntaxKind - BarEqualsToken = 62, + BarEqualsToken = 63, >BarEqualsToken : SyntaxKind - CaretEqualsToken = 63, + CaretEqualsToken = 64, >CaretEqualsToken : SyntaxKind - Identifier = 64, + Identifier = 65, >Identifier : SyntaxKind - BreakKeyword = 65, + BreakKeyword = 66, >BreakKeyword : SyntaxKind - CaseKeyword = 66, + CaseKeyword = 67, >CaseKeyword : SyntaxKind - CatchKeyword = 67, + CatchKeyword = 68, >CatchKeyword : SyntaxKind - ClassKeyword = 68, + ClassKeyword = 69, >ClassKeyword : SyntaxKind - ConstKeyword = 69, + ConstKeyword = 70, >ConstKeyword : SyntaxKind - ContinueKeyword = 70, + ContinueKeyword = 71, >ContinueKeyword : SyntaxKind - DebuggerKeyword = 71, + DebuggerKeyword = 72, >DebuggerKeyword : SyntaxKind - DefaultKeyword = 72, + DefaultKeyword = 73, >DefaultKeyword : SyntaxKind - DeleteKeyword = 73, + DeleteKeyword = 74, >DeleteKeyword : SyntaxKind - DoKeyword = 74, + DoKeyword = 75, >DoKeyword : SyntaxKind - ElseKeyword = 75, + ElseKeyword = 76, >ElseKeyword : SyntaxKind - EnumKeyword = 76, + EnumKeyword = 77, >EnumKeyword : SyntaxKind - ExportKeyword = 77, + ExportKeyword = 78, >ExportKeyword : SyntaxKind - ExtendsKeyword = 78, + ExtendsKeyword = 79, >ExtendsKeyword : SyntaxKind - FalseKeyword = 79, + FalseKeyword = 80, >FalseKeyword : SyntaxKind - FinallyKeyword = 80, + FinallyKeyword = 81, >FinallyKeyword : SyntaxKind - ForKeyword = 81, + ForKeyword = 82, >ForKeyword : SyntaxKind - FunctionKeyword = 82, + FunctionKeyword = 83, >FunctionKeyword : SyntaxKind - IfKeyword = 83, + IfKeyword = 84, >IfKeyword : SyntaxKind - ImportKeyword = 84, + ImportKeyword = 85, >ImportKeyword : SyntaxKind - InKeyword = 85, + InKeyword = 86, >InKeyword : SyntaxKind - InstanceOfKeyword = 86, + InstanceOfKeyword = 87, >InstanceOfKeyword : SyntaxKind - NewKeyword = 87, + NewKeyword = 88, >NewKeyword : SyntaxKind - NullKeyword = 88, + NullKeyword = 89, >NullKeyword : SyntaxKind - ReturnKeyword = 89, + ReturnKeyword = 90, >ReturnKeyword : SyntaxKind - SuperKeyword = 90, + SuperKeyword = 91, >SuperKeyword : SyntaxKind - SwitchKeyword = 91, + SwitchKeyword = 92, >SwitchKeyword : SyntaxKind - ThisKeyword = 92, + ThisKeyword = 93, >ThisKeyword : SyntaxKind - ThrowKeyword = 93, + ThrowKeyword = 94, >ThrowKeyword : SyntaxKind - TrueKeyword = 94, + TrueKeyword = 95, >TrueKeyword : SyntaxKind - TryKeyword = 95, + TryKeyword = 96, >TryKeyword : SyntaxKind - TypeOfKeyword = 96, + TypeOfKeyword = 97, >TypeOfKeyword : SyntaxKind - VarKeyword = 97, + VarKeyword = 98, >VarKeyword : SyntaxKind - VoidKeyword = 98, + VoidKeyword = 99, >VoidKeyword : SyntaxKind - WhileKeyword = 99, + WhileKeyword = 100, >WhileKeyword : SyntaxKind - WithKeyword = 100, + WithKeyword = 101, >WithKeyword : SyntaxKind - AsKeyword = 101, + AsKeyword = 102, >AsKeyword : SyntaxKind - ImplementsKeyword = 102, + ImplementsKeyword = 103, >ImplementsKeyword : SyntaxKind - InterfaceKeyword = 103, + InterfaceKeyword = 104, >InterfaceKeyword : SyntaxKind - LetKeyword = 104, + LetKeyword = 105, >LetKeyword : SyntaxKind - PackageKeyword = 105, + PackageKeyword = 106, >PackageKeyword : SyntaxKind - PrivateKeyword = 106, + PrivateKeyword = 107, >PrivateKeyword : SyntaxKind - ProtectedKeyword = 107, + ProtectedKeyword = 108, >ProtectedKeyword : SyntaxKind - PublicKeyword = 108, + PublicKeyword = 109, >PublicKeyword : SyntaxKind - StaticKeyword = 109, + StaticKeyword = 110, >StaticKeyword : SyntaxKind - YieldKeyword = 110, + YieldKeyword = 111, >YieldKeyword : SyntaxKind - AnyKeyword = 111, + AnyKeyword = 112, >AnyKeyword : SyntaxKind - BooleanKeyword = 112, + BooleanKeyword = 113, >BooleanKeyword : SyntaxKind - ConstructorKeyword = 113, + ConstructorKeyword = 114, >ConstructorKeyword : SyntaxKind - DeclareKeyword = 114, + DeclareKeyword = 115, >DeclareKeyword : SyntaxKind - GetKeyword = 115, + GetKeyword = 116, >GetKeyword : SyntaxKind - ModuleKeyword = 116, + ModuleKeyword = 117, >ModuleKeyword : SyntaxKind - RequireKeyword = 117, + RequireKeyword = 118, >RequireKeyword : SyntaxKind - NumberKeyword = 118, + NumberKeyword = 119, >NumberKeyword : SyntaxKind - SetKeyword = 119, + SetKeyword = 120, >SetKeyword : SyntaxKind - StringKeyword = 120, + StringKeyword = 121, >StringKeyword : SyntaxKind - SymbolKeyword = 121, + SymbolKeyword = 122, >SymbolKeyword : SyntaxKind - TypeKeyword = 122, + TypeKeyword = 123, >TypeKeyword : SyntaxKind - FromKeyword = 123, + FromKeyword = 124, >FromKeyword : SyntaxKind - OfKeyword = 124, + OfKeyword = 125, >OfKeyword : SyntaxKind - QualifiedName = 125, + QualifiedName = 126, >QualifiedName : SyntaxKind - ComputedPropertyName = 126, + ComputedPropertyName = 127, >ComputedPropertyName : SyntaxKind - TypeParameter = 127, + TypeParameter = 128, >TypeParameter : SyntaxKind - Parameter = 128, + Parameter = 129, >Parameter : SyntaxKind - PropertySignature = 129, + Decorator = 130, +>Decorator : SyntaxKind + + PropertySignature = 131, >PropertySignature : SyntaxKind - PropertyDeclaration = 130, + PropertyDeclaration = 132, >PropertyDeclaration : SyntaxKind - MethodSignature = 131, + MethodSignature = 133, >MethodSignature : SyntaxKind - MethodDeclaration = 132, + MethodDeclaration = 134, >MethodDeclaration : SyntaxKind - Constructor = 133, + Constructor = 135, >Constructor : SyntaxKind - GetAccessor = 134, + GetAccessor = 136, >GetAccessor : SyntaxKind - SetAccessor = 135, + SetAccessor = 137, >SetAccessor : SyntaxKind - CallSignature = 136, + CallSignature = 138, >CallSignature : SyntaxKind - ConstructSignature = 137, + ConstructSignature = 139, >ConstructSignature : SyntaxKind - IndexSignature = 138, + IndexSignature = 140, >IndexSignature : SyntaxKind - TypeReference = 139, + TypeReference = 141, >TypeReference : SyntaxKind - FunctionType = 140, + FunctionType = 142, >FunctionType : SyntaxKind - ConstructorType = 141, + ConstructorType = 143, >ConstructorType : SyntaxKind - TypeQuery = 142, + TypeQuery = 144, >TypeQuery : SyntaxKind - TypeLiteral = 143, + TypeLiteral = 145, >TypeLiteral : SyntaxKind - ArrayType = 144, + ArrayType = 146, >ArrayType : SyntaxKind - TupleType = 145, + TupleType = 147, >TupleType : SyntaxKind - UnionType = 146, + UnionType = 148, >UnionType : SyntaxKind - ParenthesizedType = 147, + ParenthesizedType = 149, >ParenthesizedType : SyntaxKind - ObjectBindingPattern = 148, + ObjectBindingPattern = 150, >ObjectBindingPattern : SyntaxKind - ArrayBindingPattern = 149, + ArrayBindingPattern = 151, >ArrayBindingPattern : SyntaxKind - BindingElement = 150, + BindingElement = 152, >BindingElement : SyntaxKind - ArrayLiteralExpression = 151, + ArrayLiteralExpression = 153, >ArrayLiteralExpression : SyntaxKind - ObjectLiteralExpression = 152, + ObjectLiteralExpression = 154, >ObjectLiteralExpression : SyntaxKind - PropertyAccessExpression = 153, + PropertyAccessExpression = 155, >PropertyAccessExpression : SyntaxKind - ElementAccessExpression = 154, + ElementAccessExpression = 156, >ElementAccessExpression : SyntaxKind - CallExpression = 155, + CallExpression = 157, >CallExpression : SyntaxKind - NewExpression = 156, + NewExpression = 158, >NewExpression : SyntaxKind - TaggedTemplateExpression = 157, + TaggedTemplateExpression = 159, >TaggedTemplateExpression : SyntaxKind - TypeAssertionExpression = 158, + TypeAssertionExpression = 160, >TypeAssertionExpression : SyntaxKind - ParenthesizedExpression = 159, + ParenthesizedExpression = 161, >ParenthesizedExpression : SyntaxKind - FunctionExpression = 160, + FunctionExpression = 162, >FunctionExpression : SyntaxKind - ArrowFunction = 161, + ArrowFunction = 163, >ArrowFunction : SyntaxKind - DeleteExpression = 162, + DeleteExpression = 164, >DeleteExpression : SyntaxKind - TypeOfExpression = 163, + TypeOfExpression = 165, >TypeOfExpression : SyntaxKind - VoidExpression = 164, + VoidExpression = 166, >VoidExpression : SyntaxKind - PrefixUnaryExpression = 165, + PrefixUnaryExpression = 167, >PrefixUnaryExpression : SyntaxKind - PostfixUnaryExpression = 166, + PostfixUnaryExpression = 168, >PostfixUnaryExpression : SyntaxKind - BinaryExpression = 167, + BinaryExpression = 169, >BinaryExpression : SyntaxKind - ConditionalExpression = 168, + ConditionalExpression = 170, >ConditionalExpression : SyntaxKind - TemplateExpression = 169, + TemplateExpression = 171, >TemplateExpression : SyntaxKind - YieldExpression = 170, + YieldExpression = 172, >YieldExpression : SyntaxKind - SpreadElementExpression = 171, + SpreadElementExpression = 173, >SpreadElementExpression : SyntaxKind - OmittedExpression = 172, + OmittedExpression = 174, >OmittedExpression : SyntaxKind - TemplateSpan = 173, + TemplateSpan = 175, >TemplateSpan : SyntaxKind - Block = 174, + Block = 176, >Block : SyntaxKind - VariableStatement = 175, + VariableStatement = 177, >VariableStatement : SyntaxKind - EmptyStatement = 176, + EmptyStatement = 178, >EmptyStatement : SyntaxKind - ExpressionStatement = 177, + ExpressionStatement = 179, >ExpressionStatement : SyntaxKind - IfStatement = 178, + IfStatement = 180, >IfStatement : SyntaxKind - DoStatement = 179, + DoStatement = 181, >DoStatement : SyntaxKind - WhileStatement = 180, + WhileStatement = 182, >WhileStatement : SyntaxKind - ForStatement = 181, + ForStatement = 183, >ForStatement : SyntaxKind - ForInStatement = 182, + ForInStatement = 184, >ForInStatement : SyntaxKind - ForOfStatement = 183, + ForOfStatement = 185, >ForOfStatement : SyntaxKind - ContinueStatement = 184, + ContinueStatement = 186, >ContinueStatement : SyntaxKind - BreakStatement = 185, + BreakStatement = 187, >BreakStatement : SyntaxKind - ReturnStatement = 186, + ReturnStatement = 188, >ReturnStatement : SyntaxKind - WithStatement = 187, + WithStatement = 189, >WithStatement : SyntaxKind - SwitchStatement = 188, + SwitchStatement = 190, >SwitchStatement : SyntaxKind - LabeledStatement = 189, + LabeledStatement = 191, >LabeledStatement : SyntaxKind - ThrowStatement = 190, + ThrowStatement = 192, >ThrowStatement : SyntaxKind - TryStatement = 191, + TryStatement = 193, >TryStatement : SyntaxKind - DebuggerStatement = 192, + DebuggerStatement = 194, >DebuggerStatement : SyntaxKind - VariableDeclaration = 193, + VariableDeclaration = 195, >VariableDeclaration : SyntaxKind - VariableDeclarationList = 194, + VariableDeclarationList = 196, >VariableDeclarationList : SyntaxKind - FunctionDeclaration = 195, + FunctionDeclaration = 197, >FunctionDeclaration : SyntaxKind - ClassDeclaration = 196, + ClassDeclaration = 198, >ClassDeclaration : SyntaxKind - InterfaceDeclaration = 197, + InterfaceDeclaration = 199, >InterfaceDeclaration : SyntaxKind - TypeAliasDeclaration = 198, + TypeAliasDeclaration = 200, >TypeAliasDeclaration : SyntaxKind - EnumDeclaration = 199, + EnumDeclaration = 201, >EnumDeclaration : SyntaxKind - ModuleDeclaration = 200, + ModuleDeclaration = 202, >ModuleDeclaration : SyntaxKind - ModuleBlock = 201, + ModuleBlock = 203, >ModuleBlock : SyntaxKind - CaseBlock = 202, + CaseBlock = 204, >CaseBlock : SyntaxKind - ImportEqualsDeclaration = 203, + ImportEqualsDeclaration = 205, >ImportEqualsDeclaration : SyntaxKind - ImportDeclaration = 204, + ImportDeclaration = 206, >ImportDeclaration : SyntaxKind - ImportClause = 205, + ImportClause = 207, >ImportClause : SyntaxKind - NamespaceImport = 206, + NamespaceImport = 208, >NamespaceImport : SyntaxKind - NamedImports = 207, + NamedImports = 209, >NamedImports : SyntaxKind - ImportSpecifier = 208, + ImportSpecifier = 210, >ImportSpecifier : SyntaxKind - ExportAssignment = 209, + ExportAssignment = 211, >ExportAssignment : SyntaxKind - ExportDeclaration = 210, + ExportDeclaration = 212, >ExportDeclaration : SyntaxKind - NamedExports = 211, + NamedExports = 213, >NamedExports : SyntaxKind - ExportSpecifier = 212, + ExportSpecifier = 214, >ExportSpecifier : SyntaxKind - ExternalModuleReference = 213, + IncompleteDeclaration = 215, +>IncompleteDeclaration : SyntaxKind + + ExternalModuleReference = 216, >ExternalModuleReference : SyntaxKind - CaseClause = 214, + CaseClause = 217, >CaseClause : SyntaxKind - DefaultClause = 215, + DefaultClause = 218, >DefaultClause : SyntaxKind - HeritageClause = 216, + HeritageClause = 219, >HeritageClause : SyntaxKind - CatchClause = 217, + CatchClause = 220, >CatchClause : SyntaxKind - PropertyAssignment = 218, + PropertyAssignment = 221, >PropertyAssignment : SyntaxKind - ShorthandPropertyAssignment = 219, + ShorthandPropertyAssignment = 222, >ShorthandPropertyAssignment : SyntaxKind - EnumMember = 220, + EnumMember = 223, >EnumMember : SyntaxKind - SourceFile = 221, + SourceFile = 224, >SourceFile : SyntaxKind - SyntaxList = 222, + SyntaxList = 225, >SyntaxList : SyntaxKind - Count = 223, + Count = 226, >Count : SyntaxKind - FirstAssignment = 52, + FirstAssignment = 53, >FirstAssignment : SyntaxKind - LastAssignment = 63, + LastAssignment = 64, >LastAssignment : SyntaxKind - FirstReservedWord = 65, + FirstReservedWord = 66, >FirstReservedWord : SyntaxKind - LastReservedWord = 100, + LastReservedWord = 101, >LastReservedWord : SyntaxKind - FirstKeyword = 65, + FirstKeyword = 66, >FirstKeyword : SyntaxKind - LastKeyword = 124, + LastKeyword = 125, >LastKeyword : SyntaxKind - FirstFutureReservedWord = 102, + FirstFutureReservedWord = 103, >FirstFutureReservedWord : SyntaxKind - LastFutureReservedWord = 110, + LastFutureReservedWord = 111, >LastFutureReservedWord : SyntaxKind - FirstTypeNode = 139, + FirstTypeNode = 141, >FirstTypeNode : SyntaxKind - LastTypeNode = 147, + LastTypeNode = 149, >LastTypeNode : SyntaxKind FirstPunctuation = 14, >FirstPunctuation : SyntaxKind - LastPunctuation = 63, + LastPunctuation = 64, >LastPunctuation : SyntaxKind FirstToken = 0, >FirstToken : SyntaxKind - LastToken = 124, + LastToken = 125, >LastToken : SyntaxKind FirstTriviaToken = 2, @@ -1076,10 +1085,10 @@ declare module "typescript" { FirstBinaryOperator = 24, >FirstBinaryOperator : SyntaxKind - LastBinaryOperator = 63, + LastBinaryOperator = 64, >LastBinaryOperator : SyntaxKind - FirstNode = 125, + FirstNode = 126, >FirstNode : SyntaxKind } const enum NodeFlags { @@ -1148,16 +1157,19 @@ declare module "typescript" { GeneratorParameter = 8, >GeneratorParameter : ParserContextFlags - ThisNodeHasError = 16, + Decorator = 16, +>Decorator : ParserContextFlags + + ThisNodeHasError = 32, >ThisNodeHasError : ParserContextFlags - ParserGeneratedFlags = 31, + ParserGeneratedFlags = 63, >ParserGeneratedFlags : ParserContextFlags - ThisNodeOrAnySubNodesHasError = 32, + ThisNodeOrAnySubNodesHasError = 64, >ThisNodeOrAnySubNodesHasError : ParserContextFlags - HasAggregatedChildData = 64, + HasAggregatedChildData = 128, >HasAggregatedChildData : ParserContextFlags } const enum RelationComparisonResult { @@ -1188,6 +1200,11 @@ declare module "typescript" { >parserContextFlags : ParserContextFlags >ParserContextFlags : ParserContextFlags + decorators?: NodeArray; +>decorators : NodeArray +>NodeArray : NodeArray +>Decorator : Decorator + modifiers?: ModifiersArray; >modifiers : ModifiersArray >ModifiersArray : ModifiersArray @@ -1282,6 +1299,18 @@ declare module "typescript" { expression: Expression; >expression : Expression >Expression : Expression + } + interface Decorator extends Node { +>Decorator : Decorator +>Node : Node + + atToken: Node; +>atToken : Node +>Node : Node + + expression: LeftHandSideExpression; +>expression : LeftHandSideExpression +>LeftHandSideExpression : LeftHandSideExpression } interface TypeParameterDeclaration extends Declaration { >TypeParameterDeclaration : TypeParameterDeclaration @@ -1881,10 +1910,18 @@ declare module "typescript" { >ArrayLiteralExpression : ArrayLiteralExpression >PrimaryExpression : PrimaryExpression + openBracketToken: Node; +>openBracketToken : Node +>Node : Node + elements: NodeArray; >elements : NodeArray >NodeArray : NodeArray >Expression : Expression + + closeBracketToken: Node; +>closeBracketToken : Node +>Node : Node } interface SpreadElementExpression extends Expression { >SpreadElementExpression : SpreadElementExpression @@ -1928,9 +1965,17 @@ declare module "typescript" { >expression : LeftHandSideExpression >LeftHandSideExpression : LeftHandSideExpression + openBracketToken: Node; +>openBracketToken : Node +>Node : Node + argumentExpression?: Expression; >argumentExpression : Expression >Expression : Expression + + closeBracketToken: Node; +>closeBracketToken : Node +>Node : Node } interface CallExpression extends LeftHandSideExpression { >CallExpression : CallExpression diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index da8fe979d1700..11fb8bdef9385 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -143,192 +143,195 @@ declare module "typescript" { BarBarToken = 49, QuestionToken = 50, ColonToken = 51, - EqualsToken = 52, - PlusEqualsToken = 53, - MinusEqualsToken = 54, - AsteriskEqualsToken = 55, - SlashEqualsToken = 56, - PercentEqualsToken = 57, - LessThanLessThanEqualsToken = 58, - GreaterThanGreaterThanEqualsToken = 59, - GreaterThanGreaterThanGreaterThanEqualsToken = 60, - AmpersandEqualsToken = 61, - BarEqualsToken = 62, - CaretEqualsToken = 63, - Identifier = 64, - BreakKeyword = 65, - CaseKeyword = 66, - CatchKeyword = 67, - ClassKeyword = 68, - ConstKeyword = 69, - ContinueKeyword = 70, - DebuggerKeyword = 71, - DefaultKeyword = 72, - DeleteKeyword = 73, - DoKeyword = 74, - ElseKeyword = 75, - EnumKeyword = 76, - ExportKeyword = 77, - ExtendsKeyword = 78, - FalseKeyword = 79, - FinallyKeyword = 80, - ForKeyword = 81, - FunctionKeyword = 82, - IfKeyword = 83, - ImportKeyword = 84, - InKeyword = 85, - InstanceOfKeyword = 86, - NewKeyword = 87, - NullKeyword = 88, - ReturnKeyword = 89, - SuperKeyword = 90, - SwitchKeyword = 91, - ThisKeyword = 92, - ThrowKeyword = 93, - TrueKeyword = 94, - TryKeyword = 95, - TypeOfKeyword = 96, - VarKeyword = 97, - VoidKeyword = 98, - WhileKeyword = 99, - WithKeyword = 100, - AsKeyword = 101, - ImplementsKeyword = 102, - InterfaceKeyword = 103, - LetKeyword = 104, - PackageKeyword = 105, - PrivateKeyword = 106, - ProtectedKeyword = 107, - PublicKeyword = 108, - StaticKeyword = 109, - YieldKeyword = 110, - AnyKeyword = 111, - BooleanKeyword = 112, - ConstructorKeyword = 113, - DeclareKeyword = 114, - GetKeyword = 115, - ModuleKeyword = 116, - RequireKeyword = 117, - NumberKeyword = 118, - SetKeyword = 119, - StringKeyword = 120, - SymbolKeyword = 121, - TypeKeyword = 122, - FromKeyword = 123, - OfKeyword = 124, - QualifiedName = 125, - ComputedPropertyName = 126, - TypeParameter = 127, - Parameter = 128, - PropertySignature = 129, - PropertyDeclaration = 130, - MethodSignature = 131, - MethodDeclaration = 132, - Constructor = 133, - GetAccessor = 134, - SetAccessor = 135, - CallSignature = 136, - ConstructSignature = 137, - IndexSignature = 138, - TypeReference = 139, - FunctionType = 140, - ConstructorType = 141, - TypeQuery = 142, - TypeLiteral = 143, - ArrayType = 144, - TupleType = 145, - UnionType = 146, - ParenthesizedType = 147, - ObjectBindingPattern = 148, - ArrayBindingPattern = 149, - BindingElement = 150, - ArrayLiteralExpression = 151, - ObjectLiteralExpression = 152, - PropertyAccessExpression = 153, - ElementAccessExpression = 154, - CallExpression = 155, - NewExpression = 156, - TaggedTemplateExpression = 157, - TypeAssertionExpression = 158, - ParenthesizedExpression = 159, - FunctionExpression = 160, - ArrowFunction = 161, - DeleteExpression = 162, - TypeOfExpression = 163, - VoidExpression = 164, - PrefixUnaryExpression = 165, - PostfixUnaryExpression = 166, - BinaryExpression = 167, - ConditionalExpression = 168, - TemplateExpression = 169, - YieldExpression = 170, - SpreadElementExpression = 171, - OmittedExpression = 172, - TemplateSpan = 173, - Block = 174, - VariableStatement = 175, - EmptyStatement = 176, - ExpressionStatement = 177, - IfStatement = 178, - DoStatement = 179, - WhileStatement = 180, - ForStatement = 181, - ForInStatement = 182, - ForOfStatement = 183, - ContinueStatement = 184, - BreakStatement = 185, - ReturnStatement = 186, - WithStatement = 187, - SwitchStatement = 188, - LabeledStatement = 189, - ThrowStatement = 190, - TryStatement = 191, - DebuggerStatement = 192, - VariableDeclaration = 193, - VariableDeclarationList = 194, - FunctionDeclaration = 195, - ClassDeclaration = 196, - InterfaceDeclaration = 197, - TypeAliasDeclaration = 198, - EnumDeclaration = 199, - ModuleDeclaration = 200, - ModuleBlock = 201, - CaseBlock = 202, - ImportEqualsDeclaration = 203, - ImportDeclaration = 204, - ImportClause = 205, - NamespaceImport = 206, - NamedImports = 207, - ImportSpecifier = 208, - ExportAssignment = 209, - ExportDeclaration = 210, - NamedExports = 211, - ExportSpecifier = 212, - ExternalModuleReference = 213, - CaseClause = 214, - DefaultClause = 215, - HeritageClause = 216, - CatchClause = 217, - PropertyAssignment = 218, - ShorthandPropertyAssignment = 219, - EnumMember = 220, - SourceFile = 221, - SyntaxList = 222, - Count = 223, - FirstAssignment = 52, - LastAssignment = 63, - FirstReservedWord = 65, - LastReservedWord = 100, - FirstKeyword = 65, - LastKeyword = 124, - FirstFutureReservedWord = 102, - LastFutureReservedWord = 110, - FirstTypeNode = 139, - LastTypeNode = 147, + AtToken = 52, + EqualsToken = 53, + PlusEqualsToken = 54, + MinusEqualsToken = 55, + AsteriskEqualsToken = 56, + SlashEqualsToken = 57, + PercentEqualsToken = 58, + LessThanLessThanEqualsToken = 59, + GreaterThanGreaterThanEqualsToken = 60, + GreaterThanGreaterThanGreaterThanEqualsToken = 61, + AmpersandEqualsToken = 62, + BarEqualsToken = 63, + CaretEqualsToken = 64, + Identifier = 65, + BreakKeyword = 66, + CaseKeyword = 67, + CatchKeyword = 68, + ClassKeyword = 69, + ConstKeyword = 70, + ContinueKeyword = 71, + DebuggerKeyword = 72, + DefaultKeyword = 73, + DeleteKeyword = 74, + DoKeyword = 75, + ElseKeyword = 76, + EnumKeyword = 77, + ExportKeyword = 78, + ExtendsKeyword = 79, + FalseKeyword = 80, + FinallyKeyword = 81, + ForKeyword = 82, + FunctionKeyword = 83, + IfKeyword = 84, + ImportKeyword = 85, + InKeyword = 86, + InstanceOfKeyword = 87, + NewKeyword = 88, + NullKeyword = 89, + ReturnKeyword = 90, + SuperKeyword = 91, + SwitchKeyword = 92, + ThisKeyword = 93, + ThrowKeyword = 94, + TrueKeyword = 95, + TryKeyword = 96, + TypeOfKeyword = 97, + VarKeyword = 98, + VoidKeyword = 99, + WhileKeyword = 100, + WithKeyword = 101, + AsKeyword = 102, + ImplementsKeyword = 103, + InterfaceKeyword = 104, + LetKeyword = 105, + PackageKeyword = 106, + PrivateKeyword = 107, + ProtectedKeyword = 108, + PublicKeyword = 109, + StaticKeyword = 110, + YieldKeyword = 111, + AnyKeyword = 112, + BooleanKeyword = 113, + ConstructorKeyword = 114, + DeclareKeyword = 115, + GetKeyword = 116, + ModuleKeyword = 117, + RequireKeyword = 118, + NumberKeyword = 119, + SetKeyword = 120, + StringKeyword = 121, + SymbolKeyword = 122, + TypeKeyword = 123, + FromKeyword = 124, + OfKeyword = 125, + QualifiedName = 126, + ComputedPropertyName = 127, + TypeParameter = 128, + Parameter = 129, + Decorator = 130, + PropertySignature = 131, + PropertyDeclaration = 132, + MethodSignature = 133, + MethodDeclaration = 134, + Constructor = 135, + GetAccessor = 136, + SetAccessor = 137, + CallSignature = 138, + ConstructSignature = 139, + IndexSignature = 140, + TypeReference = 141, + FunctionType = 142, + ConstructorType = 143, + TypeQuery = 144, + TypeLiteral = 145, + ArrayType = 146, + TupleType = 147, + UnionType = 148, + ParenthesizedType = 149, + ObjectBindingPattern = 150, + ArrayBindingPattern = 151, + BindingElement = 152, + ArrayLiteralExpression = 153, + ObjectLiteralExpression = 154, + PropertyAccessExpression = 155, + ElementAccessExpression = 156, + CallExpression = 157, + NewExpression = 158, + TaggedTemplateExpression = 159, + TypeAssertionExpression = 160, + ParenthesizedExpression = 161, + FunctionExpression = 162, + ArrowFunction = 163, + DeleteExpression = 164, + TypeOfExpression = 165, + VoidExpression = 166, + PrefixUnaryExpression = 167, + PostfixUnaryExpression = 168, + BinaryExpression = 169, + ConditionalExpression = 170, + TemplateExpression = 171, + YieldExpression = 172, + SpreadElementExpression = 173, + OmittedExpression = 174, + TemplateSpan = 175, + Block = 176, + VariableStatement = 177, + EmptyStatement = 178, + ExpressionStatement = 179, + IfStatement = 180, + DoStatement = 181, + WhileStatement = 182, + ForStatement = 183, + ForInStatement = 184, + ForOfStatement = 185, + ContinueStatement = 186, + BreakStatement = 187, + ReturnStatement = 188, + WithStatement = 189, + SwitchStatement = 190, + LabeledStatement = 191, + ThrowStatement = 192, + TryStatement = 193, + DebuggerStatement = 194, + VariableDeclaration = 195, + VariableDeclarationList = 196, + FunctionDeclaration = 197, + ClassDeclaration = 198, + InterfaceDeclaration = 199, + TypeAliasDeclaration = 200, + EnumDeclaration = 201, + ModuleDeclaration = 202, + ModuleBlock = 203, + CaseBlock = 204, + ImportEqualsDeclaration = 205, + ImportDeclaration = 206, + ImportClause = 207, + NamespaceImport = 208, + NamedImports = 209, + ImportSpecifier = 210, + ExportAssignment = 211, + ExportDeclaration = 212, + NamedExports = 213, + ExportSpecifier = 214, + IncompleteDeclaration = 215, + ExternalModuleReference = 216, + CaseClause = 217, + DefaultClause = 218, + HeritageClause = 219, + CatchClause = 220, + PropertyAssignment = 221, + ShorthandPropertyAssignment = 222, + EnumMember = 223, + SourceFile = 224, + SyntaxList = 225, + Count = 226, + FirstAssignment = 53, + LastAssignment = 64, + FirstReservedWord = 66, + LastReservedWord = 101, + FirstKeyword = 66, + LastKeyword = 125, + FirstFutureReservedWord = 103, + LastFutureReservedWord = 111, + FirstTypeNode = 141, + LastTypeNode = 149, FirstPunctuation = 14, - LastPunctuation = 63, + LastPunctuation = 64, FirstToken = 0, - LastToken = 124, + LastToken = 125, FirstTriviaToken = 2, LastTriviaToken = 6, FirstLiteralToken = 7, @@ -336,8 +339,8 @@ declare module "typescript" { FirstTemplateToken = 10, LastTemplateToken = 13, FirstBinaryOperator = 24, - LastBinaryOperator = 63, - FirstNode = 125, + LastBinaryOperator = 64, + FirstNode = 126, } const enum NodeFlags { Export = 1, @@ -362,10 +365,11 @@ declare module "typescript" { DisallowIn = 2, Yield = 4, GeneratorParameter = 8, - ThisNodeHasError = 16, - ParserGeneratedFlags = 31, - ThisNodeOrAnySubNodesHasError = 32, - HasAggregatedChildData = 64, + Decorator = 16, + ThisNodeHasError = 32, + ParserGeneratedFlags = 63, + ThisNodeOrAnySubNodesHasError = 64, + HasAggregatedChildData = 128, } const enum RelationComparisonResult { Succeeded = 1, @@ -376,6 +380,7 @@ declare module "typescript" { kind: SyntaxKind; flags: NodeFlags; parserContextFlags?: ParserContextFlags; + decorators?: NodeArray; modifiers?: ModifiersArray; id?: number; parent?: Node; @@ -406,6 +411,10 @@ declare module "typescript" { interface ComputedPropertyName extends Node { expression: Expression; } + interface Decorator extends Node { + atToken: Node; + expression: LeftHandSideExpression; + } interface TypeParameterDeclaration extends Declaration { name: Identifier; constraint?: TypeNode; @@ -608,7 +617,9 @@ declare module "typescript" { expression: Expression; } interface ArrayLiteralExpression extends PrimaryExpression { + openBracketToken: Node; elements: NodeArray; + closeBracketToken: Node; } interface SpreadElementExpression extends Expression { expression: Expression; @@ -623,7 +634,9 @@ declare module "typescript" { } interface ElementAccessExpression extends MemberExpression { expression: LeftHandSideExpression; + openBracketToken: Node; argumentExpression?: Expression; + closeBracketToken: Node; } interface CallExpression extends LeftHandSideExpression { expression: LeftHandSideExpression; diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index b694678d4cb9a..4e56770573af7 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -447,562 +447,571 @@ declare module "typescript" { ColonToken = 51, >ColonToken : SyntaxKind - EqualsToken = 52, + AtToken = 52, +>AtToken : SyntaxKind + + EqualsToken = 53, >EqualsToken : SyntaxKind - PlusEqualsToken = 53, + PlusEqualsToken = 54, >PlusEqualsToken : SyntaxKind - MinusEqualsToken = 54, + MinusEqualsToken = 55, >MinusEqualsToken : SyntaxKind - AsteriskEqualsToken = 55, + AsteriskEqualsToken = 56, >AsteriskEqualsToken : SyntaxKind - SlashEqualsToken = 56, + SlashEqualsToken = 57, >SlashEqualsToken : SyntaxKind - PercentEqualsToken = 57, + PercentEqualsToken = 58, >PercentEqualsToken : SyntaxKind - LessThanLessThanEqualsToken = 58, + LessThanLessThanEqualsToken = 59, >LessThanLessThanEqualsToken : SyntaxKind - GreaterThanGreaterThanEqualsToken = 59, + GreaterThanGreaterThanEqualsToken = 60, >GreaterThanGreaterThanEqualsToken : SyntaxKind - GreaterThanGreaterThanGreaterThanEqualsToken = 60, + GreaterThanGreaterThanGreaterThanEqualsToken = 61, >GreaterThanGreaterThanGreaterThanEqualsToken : SyntaxKind - AmpersandEqualsToken = 61, + AmpersandEqualsToken = 62, >AmpersandEqualsToken : SyntaxKind - BarEqualsToken = 62, + BarEqualsToken = 63, >BarEqualsToken : SyntaxKind - CaretEqualsToken = 63, + CaretEqualsToken = 64, >CaretEqualsToken : SyntaxKind - Identifier = 64, + Identifier = 65, >Identifier : SyntaxKind - BreakKeyword = 65, + BreakKeyword = 66, >BreakKeyword : SyntaxKind - CaseKeyword = 66, + CaseKeyword = 67, >CaseKeyword : SyntaxKind - CatchKeyword = 67, + CatchKeyword = 68, >CatchKeyword : SyntaxKind - ClassKeyword = 68, + ClassKeyword = 69, >ClassKeyword : SyntaxKind - ConstKeyword = 69, + ConstKeyword = 70, >ConstKeyword : SyntaxKind - ContinueKeyword = 70, + ContinueKeyword = 71, >ContinueKeyword : SyntaxKind - DebuggerKeyword = 71, + DebuggerKeyword = 72, >DebuggerKeyword : SyntaxKind - DefaultKeyword = 72, + DefaultKeyword = 73, >DefaultKeyword : SyntaxKind - DeleteKeyword = 73, + DeleteKeyword = 74, >DeleteKeyword : SyntaxKind - DoKeyword = 74, + DoKeyword = 75, >DoKeyword : SyntaxKind - ElseKeyword = 75, + ElseKeyword = 76, >ElseKeyword : SyntaxKind - EnumKeyword = 76, + EnumKeyword = 77, >EnumKeyword : SyntaxKind - ExportKeyword = 77, + ExportKeyword = 78, >ExportKeyword : SyntaxKind - ExtendsKeyword = 78, + ExtendsKeyword = 79, >ExtendsKeyword : SyntaxKind - FalseKeyword = 79, + FalseKeyword = 80, >FalseKeyword : SyntaxKind - FinallyKeyword = 80, + FinallyKeyword = 81, >FinallyKeyword : SyntaxKind - ForKeyword = 81, + ForKeyword = 82, >ForKeyword : SyntaxKind - FunctionKeyword = 82, + FunctionKeyword = 83, >FunctionKeyword : SyntaxKind - IfKeyword = 83, + IfKeyword = 84, >IfKeyword : SyntaxKind - ImportKeyword = 84, + ImportKeyword = 85, >ImportKeyword : SyntaxKind - InKeyword = 85, + InKeyword = 86, >InKeyword : SyntaxKind - InstanceOfKeyword = 86, + InstanceOfKeyword = 87, >InstanceOfKeyword : SyntaxKind - NewKeyword = 87, + NewKeyword = 88, >NewKeyword : SyntaxKind - NullKeyword = 88, + NullKeyword = 89, >NullKeyword : SyntaxKind - ReturnKeyword = 89, + ReturnKeyword = 90, >ReturnKeyword : SyntaxKind - SuperKeyword = 90, + SuperKeyword = 91, >SuperKeyword : SyntaxKind - SwitchKeyword = 91, + SwitchKeyword = 92, >SwitchKeyword : SyntaxKind - ThisKeyword = 92, + ThisKeyword = 93, >ThisKeyword : SyntaxKind - ThrowKeyword = 93, + ThrowKeyword = 94, >ThrowKeyword : SyntaxKind - TrueKeyword = 94, + TrueKeyword = 95, >TrueKeyword : SyntaxKind - TryKeyword = 95, + TryKeyword = 96, >TryKeyword : SyntaxKind - TypeOfKeyword = 96, + TypeOfKeyword = 97, >TypeOfKeyword : SyntaxKind - VarKeyword = 97, + VarKeyword = 98, >VarKeyword : SyntaxKind - VoidKeyword = 98, + VoidKeyword = 99, >VoidKeyword : SyntaxKind - WhileKeyword = 99, + WhileKeyword = 100, >WhileKeyword : SyntaxKind - WithKeyword = 100, + WithKeyword = 101, >WithKeyword : SyntaxKind - AsKeyword = 101, + AsKeyword = 102, >AsKeyword : SyntaxKind - ImplementsKeyword = 102, + ImplementsKeyword = 103, >ImplementsKeyword : SyntaxKind - InterfaceKeyword = 103, + InterfaceKeyword = 104, >InterfaceKeyword : SyntaxKind - LetKeyword = 104, + LetKeyword = 105, >LetKeyword : SyntaxKind - PackageKeyword = 105, + PackageKeyword = 106, >PackageKeyword : SyntaxKind - PrivateKeyword = 106, + PrivateKeyword = 107, >PrivateKeyword : SyntaxKind - ProtectedKeyword = 107, + ProtectedKeyword = 108, >ProtectedKeyword : SyntaxKind - PublicKeyword = 108, + PublicKeyword = 109, >PublicKeyword : SyntaxKind - StaticKeyword = 109, + StaticKeyword = 110, >StaticKeyword : SyntaxKind - YieldKeyword = 110, + YieldKeyword = 111, >YieldKeyword : SyntaxKind - AnyKeyword = 111, + AnyKeyword = 112, >AnyKeyword : SyntaxKind - BooleanKeyword = 112, + BooleanKeyword = 113, >BooleanKeyword : SyntaxKind - ConstructorKeyword = 113, + ConstructorKeyword = 114, >ConstructorKeyword : SyntaxKind - DeclareKeyword = 114, + DeclareKeyword = 115, >DeclareKeyword : SyntaxKind - GetKeyword = 115, + GetKeyword = 116, >GetKeyword : SyntaxKind - ModuleKeyword = 116, + ModuleKeyword = 117, >ModuleKeyword : SyntaxKind - RequireKeyword = 117, + RequireKeyword = 118, >RequireKeyword : SyntaxKind - NumberKeyword = 118, + NumberKeyword = 119, >NumberKeyword : SyntaxKind - SetKeyword = 119, + SetKeyword = 120, >SetKeyword : SyntaxKind - StringKeyword = 120, + StringKeyword = 121, >StringKeyword : SyntaxKind - SymbolKeyword = 121, + SymbolKeyword = 122, >SymbolKeyword : SyntaxKind - TypeKeyword = 122, + TypeKeyword = 123, >TypeKeyword : SyntaxKind - FromKeyword = 123, + FromKeyword = 124, >FromKeyword : SyntaxKind - OfKeyword = 124, + OfKeyword = 125, >OfKeyword : SyntaxKind - QualifiedName = 125, + QualifiedName = 126, >QualifiedName : SyntaxKind - ComputedPropertyName = 126, + ComputedPropertyName = 127, >ComputedPropertyName : SyntaxKind - TypeParameter = 127, + TypeParameter = 128, >TypeParameter : SyntaxKind - Parameter = 128, + Parameter = 129, >Parameter : SyntaxKind - PropertySignature = 129, + Decorator = 130, +>Decorator : SyntaxKind + + PropertySignature = 131, >PropertySignature : SyntaxKind - PropertyDeclaration = 130, + PropertyDeclaration = 132, >PropertyDeclaration : SyntaxKind - MethodSignature = 131, + MethodSignature = 133, >MethodSignature : SyntaxKind - MethodDeclaration = 132, + MethodDeclaration = 134, >MethodDeclaration : SyntaxKind - Constructor = 133, + Constructor = 135, >Constructor : SyntaxKind - GetAccessor = 134, + GetAccessor = 136, >GetAccessor : SyntaxKind - SetAccessor = 135, + SetAccessor = 137, >SetAccessor : SyntaxKind - CallSignature = 136, + CallSignature = 138, >CallSignature : SyntaxKind - ConstructSignature = 137, + ConstructSignature = 139, >ConstructSignature : SyntaxKind - IndexSignature = 138, + IndexSignature = 140, >IndexSignature : SyntaxKind - TypeReference = 139, + TypeReference = 141, >TypeReference : SyntaxKind - FunctionType = 140, + FunctionType = 142, >FunctionType : SyntaxKind - ConstructorType = 141, + ConstructorType = 143, >ConstructorType : SyntaxKind - TypeQuery = 142, + TypeQuery = 144, >TypeQuery : SyntaxKind - TypeLiteral = 143, + TypeLiteral = 145, >TypeLiteral : SyntaxKind - ArrayType = 144, + ArrayType = 146, >ArrayType : SyntaxKind - TupleType = 145, + TupleType = 147, >TupleType : SyntaxKind - UnionType = 146, + UnionType = 148, >UnionType : SyntaxKind - ParenthesizedType = 147, + ParenthesizedType = 149, >ParenthesizedType : SyntaxKind - ObjectBindingPattern = 148, + ObjectBindingPattern = 150, >ObjectBindingPattern : SyntaxKind - ArrayBindingPattern = 149, + ArrayBindingPattern = 151, >ArrayBindingPattern : SyntaxKind - BindingElement = 150, + BindingElement = 152, >BindingElement : SyntaxKind - ArrayLiteralExpression = 151, + ArrayLiteralExpression = 153, >ArrayLiteralExpression : SyntaxKind - ObjectLiteralExpression = 152, + ObjectLiteralExpression = 154, >ObjectLiteralExpression : SyntaxKind - PropertyAccessExpression = 153, + PropertyAccessExpression = 155, >PropertyAccessExpression : SyntaxKind - ElementAccessExpression = 154, + ElementAccessExpression = 156, >ElementAccessExpression : SyntaxKind - CallExpression = 155, + CallExpression = 157, >CallExpression : SyntaxKind - NewExpression = 156, + NewExpression = 158, >NewExpression : SyntaxKind - TaggedTemplateExpression = 157, + TaggedTemplateExpression = 159, >TaggedTemplateExpression : SyntaxKind - TypeAssertionExpression = 158, + TypeAssertionExpression = 160, >TypeAssertionExpression : SyntaxKind - ParenthesizedExpression = 159, + ParenthesizedExpression = 161, >ParenthesizedExpression : SyntaxKind - FunctionExpression = 160, + FunctionExpression = 162, >FunctionExpression : SyntaxKind - ArrowFunction = 161, + ArrowFunction = 163, >ArrowFunction : SyntaxKind - DeleteExpression = 162, + DeleteExpression = 164, >DeleteExpression : SyntaxKind - TypeOfExpression = 163, + TypeOfExpression = 165, >TypeOfExpression : SyntaxKind - VoidExpression = 164, + VoidExpression = 166, >VoidExpression : SyntaxKind - PrefixUnaryExpression = 165, + PrefixUnaryExpression = 167, >PrefixUnaryExpression : SyntaxKind - PostfixUnaryExpression = 166, + PostfixUnaryExpression = 168, >PostfixUnaryExpression : SyntaxKind - BinaryExpression = 167, + BinaryExpression = 169, >BinaryExpression : SyntaxKind - ConditionalExpression = 168, + ConditionalExpression = 170, >ConditionalExpression : SyntaxKind - TemplateExpression = 169, + TemplateExpression = 171, >TemplateExpression : SyntaxKind - YieldExpression = 170, + YieldExpression = 172, >YieldExpression : SyntaxKind - SpreadElementExpression = 171, + SpreadElementExpression = 173, >SpreadElementExpression : SyntaxKind - OmittedExpression = 172, + OmittedExpression = 174, >OmittedExpression : SyntaxKind - TemplateSpan = 173, + TemplateSpan = 175, >TemplateSpan : SyntaxKind - Block = 174, + Block = 176, >Block : SyntaxKind - VariableStatement = 175, + VariableStatement = 177, >VariableStatement : SyntaxKind - EmptyStatement = 176, + EmptyStatement = 178, >EmptyStatement : SyntaxKind - ExpressionStatement = 177, + ExpressionStatement = 179, >ExpressionStatement : SyntaxKind - IfStatement = 178, + IfStatement = 180, >IfStatement : SyntaxKind - DoStatement = 179, + DoStatement = 181, >DoStatement : SyntaxKind - WhileStatement = 180, + WhileStatement = 182, >WhileStatement : SyntaxKind - ForStatement = 181, + ForStatement = 183, >ForStatement : SyntaxKind - ForInStatement = 182, + ForInStatement = 184, >ForInStatement : SyntaxKind - ForOfStatement = 183, + ForOfStatement = 185, >ForOfStatement : SyntaxKind - ContinueStatement = 184, + ContinueStatement = 186, >ContinueStatement : SyntaxKind - BreakStatement = 185, + BreakStatement = 187, >BreakStatement : SyntaxKind - ReturnStatement = 186, + ReturnStatement = 188, >ReturnStatement : SyntaxKind - WithStatement = 187, + WithStatement = 189, >WithStatement : SyntaxKind - SwitchStatement = 188, + SwitchStatement = 190, >SwitchStatement : SyntaxKind - LabeledStatement = 189, + LabeledStatement = 191, >LabeledStatement : SyntaxKind - ThrowStatement = 190, + ThrowStatement = 192, >ThrowStatement : SyntaxKind - TryStatement = 191, + TryStatement = 193, >TryStatement : SyntaxKind - DebuggerStatement = 192, + DebuggerStatement = 194, >DebuggerStatement : SyntaxKind - VariableDeclaration = 193, + VariableDeclaration = 195, >VariableDeclaration : SyntaxKind - VariableDeclarationList = 194, + VariableDeclarationList = 196, >VariableDeclarationList : SyntaxKind - FunctionDeclaration = 195, + FunctionDeclaration = 197, >FunctionDeclaration : SyntaxKind - ClassDeclaration = 196, + ClassDeclaration = 198, >ClassDeclaration : SyntaxKind - InterfaceDeclaration = 197, + InterfaceDeclaration = 199, >InterfaceDeclaration : SyntaxKind - TypeAliasDeclaration = 198, + TypeAliasDeclaration = 200, >TypeAliasDeclaration : SyntaxKind - EnumDeclaration = 199, + EnumDeclaration = 201, >EnumDeclaration : SyntaxKind - ModuleDeclaration = 200, + ModuleDeclaration = 202, >ModuleDeclaration : SyntaxKind - ModuleBlock = 201, + ModuleBlock = 203, >ModuleBlock : SyntaxKind - CaseBlock = 202, + CaseBlock = 204, >CaseBlock : SyntaxKind - ImportEqualsDeclaration = 203, + ImportEqualsDeclaration = 205, >ImportEqualsDeclaration : SyntaxKind - ImportDeclaration = 204, + ImportDeclaration = 206, >ImportDeclaration : SyntaxKind - ImportClause = 205, + ImportClause = 207, >ImportClause : SyntaxKind - NamespaceImport = 206, + NamespaceImport = 208, >NamespaceImport : SyntaxKind - NamedImports = 207, + NamedImports = 209, >NamedImports : SyntaxKind - ImportSpecifier = 208, + ImportSpecifier = 210, >ImportSpecifier : SyntaxKind - ExportAssignment = 209, + ExportAssignment = 211, >ExportAssignment : SyntaxKind - ExportDeclaration = 210, + ExportDeclaration = 212, >ExportDeclaration : SyntaxKind - NamedExports = 211, + NamedExports = 213, >NamedExports : SyntaxKind - ExportSpecifier = 212, + ExportSpecifier = 214, >ExportSpecifier : SyntaxKind - ExternalModuleReference = 213, + IncompleteDeclaration = 215, +>IncompleteDeclaration : SyntaxKind + + ExternalModuleReference = 216, >ExternalModuleReference : SyntaxKind - CaseClause = 214, + CaseClause = 217, >CaseClause : SyntaxKind - DefaultClause = 215, + DefaultClause = 218, >DefaultClause : SyntaxKind - HeritageClause = 216, + HeritageClause = 219, >HeritageClause : SyntaxKind - CatchClause = 217, + CatchClause = 220, >CatchClause : SyntaxKind - PropertyAssignment = 218, + PropertyAssignment = 221, >PropertyAssignment : SyntaxKind - ShorthandPropertyAssignment = 219, + ShorthandPropertyAssignment = 222, >ShorthandPropertyAssignment : SyntaxKind - EnumMember = 220, + EnumMember = 223, >EnumMember : SyntaxKind - SourceFile = 221, + SourceFile = 224, >SourceFile : SyntaxKind - SyntaxList = 222, + SyntaxList = 225, >SyntaxList : SyntaxKind - Count = 223, + Count = 226, >Count : SyntaxKind - FirstAssignment = 52, + FirstAssignment = 53, >FirstAssignment : SyntaxKind - LastAssignment = 63, + LastAssignment = 64, >LastAssignment : SyntaxKind - FirstReservedWord = 65, + FirstReservedWord = 66, >FirstReservedWord : SyntaxKind - LastReservedWord = 100, + LastReservedWord = 101, >LastReservedWord : SyntaxKind - FirstKeyword = 65, + FirstKeyword = 66, >FirstKeyword : SyntaxKind - LastKeyword = 124, + LastKeyword = 125, >LastKeyword : SyntaxKind - FirstFutureReservedWord = 102, + FirstFutureReservedWord = 103, >FirstFutureReservedWord : SyntaxKind - LastFutureReservedWord = 110, + LastFutureReservedWord = 111, >LastFutureReservedWord : SyntaxKind - FirstTypeNode = 139, + FirstTypeNode = 141, >FirstTypeNode : SyntaxKind - LastTypeNode = 147, + LastTypeNode = 149, >LastTypeNode : SyntaxKind FirstPunctuation = 14, >FirstPunctuation : SyntaxKind - LastPunctuation = 63, + LastPunctuation = 64, >LastPunctuation : SyntaxKind FirstToken = 0, >FirstToken : SyntaxKind - LastToken = 124, + LastToken = 125, >LastToken : SyntaxKind FirstTriviaToken = 2, @@ -1026,10 +1035,10 @@ declare module "typescript" { FirstBinaryOperator = 24, >FirstBinaryOperator : SyntaxKind - LastBinaryOperator = 63, + LastBinaryOperator = 64, >LastBinaryOperator : SyntaxKind - FirstNode = 125, + FirstNode = 126, >FirstNode : SyntaxKind } const enum NodeFlags { @@ -1098,16 +1107,19 @@ declare module "typescript" { GeneratorParameter = 8, >GeneratorParameter : ParserContextFlags - ThisNodeHasError = 16, + Decorator = 16, +>Decorator : ParserContextFlags + + ThisNodeHasError = 32, >ThisNodeHasError : ParserContextFlags - ParserGeneratedFlags = 31, + ParserGeneratedFlags = 63, >ParserGeneratedFlags : ParserContextFlags - ThisNodeOrAnySubNodesHasError = 32, + ThisNodeOrAnySubNodesHasError = 64, >ThisNodeOrAnySubNodesHasError : ParserContextFlags - HasAggregatedChildData = 64, + HasAggregatedChildData = 128, >HasAggregatedChildData : ParserContextFlags } const enum RelationComparisonResult { @@ -1138,6 +1150,11 @@ declare module "typescript" { >parserContextFlags : ParserContextFlags >ParserContextFlags : ParserContextFlags + decorators?: NodeArray; +>decorators : NodeArray +>NodeArray : NodeArray +>Decorator : Decorator + modifiers?: ModifiersArray; >modifiers : ModifiersArray >ModifiersArray : ModifiersArray @@ -1232,6 +1249,18 @@ declare module "typescript" { expression: Expression; >expression : Expression >Expression : Expression + } + interface Decorator extends Node { +>Decorator : Decorator +>Node : Node + + atToken: Node; +>atToken : Node +>Node : Node + + expression: LeftHandSideExpression; +>expression : LeftHandSideExpression +>LeftHandSideExpression : LeftHandSideExpression } interface TypeParameterDeclaration extends Declaration { >TypeParameterDeclaration : TypeParameterDeclaration @@ -1831,10 +1860,18 @@ declare module "typescript" { >ArrayLiteralExpression : ArrayLiteralExpression >PrimaryExpression : PrimaryExpression + openBracketToken: Node; +>openBracketToken : Node +>Node : Node + elements: NodeArray; >elements : NodeArray >NodeArray : NodeArray >Expression : Expression + + closeBracketToken: Node; +>closeBracketToken : Node +>Node : Node } interface SpreadElementExpression extends Expression { >SpreadElementExpression : SpreadElementExpression @@ -1878,9 +1915,17 @@ declare module "typescript" { >expression : LeftHandSideExpression >LeftHandSideExpression : LeftHandSideExpression + openBracketToken: Node; +>openBracketToken : Node +>Node : Node + argumentExpression?: Expression; >argumentExpression : Expression >Expression : Expression + + closeBracketToken: Node; +>closeBracketToken : Node +>Node : Node } interface CallExpression extends LeftHandSideExpression { >CallExpression : CallExpression diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index f380994eba888..b9a40c6a197dc 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -180,192 +180,195 @@ declare module "typescript" { BarBarToken = 49, QuestionToken = 50, ColonToken = 51, - EqualsToken = 52, - PlusEqualsToken = 53, - MinusEqualsToken = 54, - AsteriskEqualsToken = 55, - SlashEqualsToken = 56, - PercentEqualsToken = 57, - LessThanLessThanEqualsToken = 58, - GreaterThanGreaterThanEqualsToken = 59, - GreaterThanGreaterThanGreaterThanEqualsToken = 60, - AmpersandEqualsToken = 61, - BarEqualsToken = 62, - CaretEqualsToken = 63, - Identifier = 64, - BreakKeyword = 65, - CaseKeyword = 66, - CatchKeyword = 67, - ClassKeyword = 68, - ConstKeyword = 69, - ContinueKeyword = 70, - DebuggerKeyword = 71, - DefaultKeyword = 72, - DeleteKeyword = 73, - DoKeyword = 74, - ElseKeyword = 75, - EnumKeyword = 76, - ExportKeyword = 77, - ExtendsKeyword = 78, - FalseKeyword = 79, - FinallyKeyword = 80, - ForKeyword = 81, - FunctionKeyword = 82, - IfKeyword = 83, - ImportKeyword = 84, - InKeyword = 85, - InstanceOfKeyword = 86, - NewKeyword = 87, - NullKeyword = 88, - ReturnKeyword = 89, - SuperKeyword = 90, - SwitchKeyword = 91, - ThisKeyword = 92, - ThrowKeyword = 93, - TrueKeyword = 94, - TryKeyword = 95, - TypeOfKeyword = 96, - VarKeyword = 97, - VoidKeyword = 98, - WhileKeyword = 99, - WithKeyword = 100, - AsKeyword = 101, - ImplementsKeyword = 102, - InterfaceKeyword = 103, - LetKeyword = 104, - PackageKeyword = 105, - PrivateKeyword = 106, - ProtectedKeyword = 107, - PublicKeyword = 108, - StaticKeyword = 109, - YieldKeyword = 110, - AnyKeyword = 111, - BooleanKeyword = 112, - ConstructorKeyword = 113, - DeclareKeyword = 114, - GetKeyword = 115, - ModuleKeyword = 116, - RequireKeyword = 117, - NumberKeyword = 118, - SetKeyword = 119, - StringKeyword = 120, - SymbolKeyword = 121, - TypeKeyword = 122, - FromKeyword = 123, - OfKeyword = 124, - QualifiedName = 125, - ComputedPropertyName = 126, - TypeParameter = 127, - Parameter = 128, - PropertySignature = 129, - PropertyDeclaration = 130, - MethodSignature = 131, - MethodDeclaration = 132, - Constructor = 133, - GetAccessor = 134, - SetAccessor = 135, - CallSignature = 136, - ConstructSignature = 137, - IndexSignature = 138, - TypeReference = 139, - FunctionType = 140, - ConstructorType = 141, - TypeQuery = 142, - TypeLiteral = 143, - ArrayType = 144, - TupleType = 145, - UnionType = 146, - ParenthesizedType = 147, - ObjectBindingPattern = 148, - ArrayBindingPattern = 149, - BindingElement = 150, - ArrayLiteralExpression = 151, - ObjectLiteralExpression = 152, - PropertyAccessExpression = 153, - ElementAccessExpression = 154, - CallExpression = 155, - NewExpression = 156, - TaggedTemplateExpression = 157, - TypeAssertionExpression = 158, - ParenthesizedExpression = 159, - FunctionExpression = 160, - ArrowFunction = 161, - DeleteExpression = 162, - TypeOfExpression = 163, - VoidExpression = 164, - PrefixUnaryExpression = 165, - PostfixUnaryExpression = 166, - BinaryExpression = 167, - ConditionalExpression = 168, - TemplateExpression = 169, - YieldExpression = 170, - SpreadElementExpression = 171, - OmittedExpression = 172, - TemplateSpan = 173, - Block = 174, - VariableStatement = 175, - EmptyStatement = 176, - ExpressionStatement = 177, - IfStatement = 178, - DoStatement = 179, - WhileStatement = 180, - ForStatement = 181, - ForInStatement = 182, - ForOfStatement = 183, - ContinueStatement = 184, - BreakStatement = 185, - ReturnStatement = 186, - WithStatement = 187, - SwitchStatement = 188, - LabeledStatement = 189, - ThrowStatement = 190, - TryStatement = 191, - DebuggerStatement = 192, - VariableDeclaration = 193, - VariableDeclarationList = 194, - FunctionDeclaration = 195, - ClassDeclaration = 196, - InterfaceDeclaration = 197, - TypeAliasDeclaration = 198, - EnumDeclaration = 199, - ModuleDeclaration = 200, - ModuleBlock = 201, - CaseBlock = 202, - ImportEqualsDeclaration = 203, - ImportDeclaration = 204, - ImportClause = 205, - NamespaceImport = 206, - NamedImports = 207, - ImportSpecifier = 208, - ExportAssignment = 209, - ExportDeclaration = 210, - NamedExports = 211, - ExportSpecifier = 212, - ExternalModuleReference = 213, - CaseClause = 214, - DefaultClause = 215, - HeritageClause = 216, - CatchClause = 217, - PropertyAssignment = 218, - ShorthandPropertyAssignment = 219, - EnumMember = 220, - SourceFile = 221, - SyntaxList = 222, - Count = 223, - FirstAssignment = 52, - LastAssignment = 63, - FirstReservedWord = 65, - LastReservedWord = 100, - FirstKeyword = 65, - LastKeyword = 124, - FirstFutureReservedWord = 102, - LastFutureReservedWord = 110, - FirstTypeNode = 139, - LastTypeNode = 147, + AtToken = 52, + EqualsToken = 53, + PlusEqualsToken = 54, + MinusEqualsToken = 55, + AsteriskEqualsToken = 56, + SlashEqualsToken = 57, + PercentEqualsToken = 58, + LessThanLessThanEqualsToken = 59, + GreaterThanGreaterThanEqualsToken = 60, + GreaterThanGreaterThanGreaterThanEqualsToken = 61, + AmpersandEqualsToken = 62, + BarEqualsToken = 63, + CaretEqualsToken = 64, + Identifier = 65, + BreakKeyword = 66, + CaseKeyword = 67, + CatchKeyword = 68, + ClassKeyword = 69, + ConstKeyword = 70, + ContinueKeyword = 71, + DebuggerKeyword = 72, + DefaultKeyword = 73, + DeleteKeyword = 74, + DoKeyword = 75, + ElseKeyword = 76, + EnumKeyword = 77, + ExportKeyword = 78, + ExtendsKeyword = 79, + FalseKeyword = 80, + FinallyKeyword = 81, + ForKeyword = 82, + FunctionKeyword = 83, + IfKeyword = 84, + ImportKeyword = 85, + InKeyword = 86, + InstanceOfKeyword = 87, + NewKeyword = 88, + NullKeyword = 89, + ReturnKeyword = 90, + SuperKeyword = 91, + SwitchKeyword = 92, + ThisKeyword = 93, + ThrowKeyword = 94, + TrueKeyword = 95, + TryKeyword = 96, + TypeOfKeyword = 97, + VarKeyword = 98, + VoidKeyword = 99, + WhileKeyword = 100, + WithKeyword = 101, + AsKeyword = 102, + ImplementsKeyword = 103, + InterfaceKeyword = 104, + LetKeyword = 105, + PackageKeyword = 106, + PrivateKeyword = 107, + ProtectedKeyword = 108, + PublicKeyword = 109, + StaticKeyword = 110, + YieldKeyword = 111, + AnyKeyword = 112, + BooleanKeyword = 113, + ConstructorKeyword = 114, + DeclareKeyword = 115, + GetKeyword = 116, + ModuleKeyword = 117, + RequireKeyword = 118, + NumberKeyword = 119, + SetKeyword = 120, + StringKeyword = 121, + SymbolKeyword = 122, + TypeKeyword = 123, + FromKeyword = 124, + OfKeyword = 125, + QualifiedName = 126, + ComputedPropertyName = 127, + TypeParameter = 128, + Parameter = 129, + Decorator = 130, + PropertySignature = 131, + PropertyDeclaration = 132, + MethodSignature = 133, + MethodDeclaration = 134, + Constructor = 135, + GetAccessor = 136, + SetAccessor = 137, + CallSignature = 138, + ConstructSignature = 139, + IndexSignature = 140, + TypeReference = 141, + FunctionType = 142, + ConstructorType = 143, + TypeQuery = 144, + TypeLiteral = 145, + ArrayType = 146, + TupleType = 147, + UnionType = 148, + ParenthesizedType = 149, + ObjectBindingPattern = 150, + ArrayBindingPattern = 151, + BindingElement = 152, + ArrayLiteralExpression = 153, + ObjectLiteralExpression = 154, + PropertyAccessExpression = 155, + ElementAccessExpression = 156, + CallExpression = 157, + NewExpression = 158, + TaggedTemplateExpression = 159, + TypeAssertionExpression = 160, + ParenthesizedExpression = 161, + FunctionExpression = 162, + ArrowFunction = 163, + DeleteExpression = 164, + TypeOfExpression = 165, + VoidExpression = 166, + PrefixUnaryExpression = 167, + PostfixUnaryExpression = 168, + BinaryExpression = 169, + ConditionalExpression = 170, + TemplateExpression = 171, + YieldExpression = 172, + SpreadElementExpression = 173, + OmittedExpression = 174, + TemplateSpan = 175, + Block = 176, + VariableStatement = 177, + EmptyStatement = 178, + ExpressionStatement = 179, + IfStatement = 180, + DoStatement = 181, + WhileStatement = 182, + ForStatement = 183, + ForInStatement = 184, + ForOfStatement = 185, + ContinueStatement = 186, + BreakStatement = 187, + ReturnStatement = 188, + WithStatement = 189, + SwitchStatement = 190, + LabeledStatement = 191, + ThrowStatement = 192, + TryStatement = 193, + DebuggerStatement = 194, + VariableDeclaration = 195, + VariableDeclarationList = 196, + FunctionDeclaration = 197, + ClassDeclaration = 198, + InterfaceDeclaration = 199, + TypeAliasDeclaration = 200, + EnumDeclaration = 201, + ModuleDeclaration = 202, + ModuleBlock = 203, + CaseBlock = 204, + ImportEqualsDeclaration = 205, + ImportDeclaration = 206, + ImportClause = 207, + NamespaceImport = 208, + NamedImports = 209, + ImportSpecifier = 210, + ExportAssignment = 211, + ExportDeclaration = 212, + NamedExports = 213, + ExportSpecifier = 214, + IncompleteDeclaration = 215, + ExternalModuleReference = 216, + CaseClause = 217, + DefaultClause = 218, + HeritageClause = 219, + CatchClause = 220, + PropertyAssignment = 221, + ShorthandPropertyAssignment = 222, + EnumMember = 223, + SourceFile = 224, + SyntaxList = 225, + Count = 226, + FirstAssignment = 53, + LastAssignment = 64, + FirstReservedWord = 66, + LastReservedWord = 101, + FirstKeyword = 66, + LastKeyword = 125, + FirstFutureReservedWord = 103, + LastFutureReservedWord = 111, + FirstTypeNode = 141, + LastTypeNode = 149, FirstPunctuation = 14, - LastPunctuation = 63, + LastPunctuation = 64, FirstToken = 0, - LastToken = 124, + LastToken = 125, FirstTriviaToken = 2, LastTriviaToken = 6, FirstLiteralToken = 7, @@ -373,8 +376,8 @@ declare module "typescript" { FirstTemplateToken = 10, LastTemplateToken = 13, FirstBinaryOperator = 24, - LastBinaryOperator = 63, - FirstNode = 125, + LastBinaryOperator = 64, + FirstNode = 126, } const enum NodeFlags { Export = 1, @@ -399,10 +402,11 @@ declare module "typescript" { DisallowIn = 2, Yield = 4, GeneratorParameter = 8, - ThisNodeHasError = 16, - ParserGeneratedFlags = 31, - ThisNodeOrAnySubNodesHasError = 32, - HasAggregatedChildData = 64, + Decorator = 16, + ThisNodeHasError = 32, + ParserGeneratedFlags = 63, + ThisNodeOrAnySubNodesHasError = 64, + HasAggregatedChildData = 128, } const enum RelationComparisonResult { Succeeded = 1, @@ -413,6 +417,7 @@ declare module "typescript" { kind: SyntaxKind; flags: NodeFlags; parserContextFlags?: ParserContextFlags; + decorators?: NodeArray; modifiers?: ModifiersArray; id?: number; parent?: Node; @@ -443,6 +448,10 @@ declare module "typescript" { interface ComputedPropertyName extends Node { expression: Expression; } + interface Decorator extends Node { + atToken: Node; + expression: LeftHandSideExpression; + } interface TypeParameterDeclaration extends Declaration { name: Identifier; constraint?: TypeNode; @@ -645,7 +654,9 @@ declare module "typescript" { expression: Expression; } interface ArrayLiteralExpression extends PrimaryExpression { + openBracketToken: Node; elements: NodeArray; + closeBracketToken: Node; } interface SpreadElementExpression extends Expression { expression: Expression; @@ -660,7 +671,9 @@ declare module "typescript" { } interface ElementAccessExpression extends MemberExpression { expression: LeftHandSideExpression; + openBracketToken: Node; argumentExpression?: Expression; + closeBracketToken: Node; } interface CallExpression extends LeftHandSideExpression { expression: LeftHandSideExpression; diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index 06329de5c961f..5b52c1522a58f 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -620,562 +620,571 @@ declare module "typescript" { ColonToken = 51, >ColonToken : SyntaxKind - EqualsToken = 52, + AtToken = 52, +>AtToken : SyntaxKind + + EqualsToken = 53, >EqualsToken : SyntaxKind - PlusEqualsToken = 53, + PlusEqualsToken = 54, >PlusEqualsToken : SyntaxKind - MinusEqualsToken = 54, + MinusEqualsToken = 55, >MinusEqualsToken : SyntaxKind - AsteriskEqualsToken = 55, + AsteriskEqualsToken = 56, >AsteriskEqualsToken : SyntaxKind - SlashEqualsToken = 56, + SlashEqualsToken = 57, >SlashEqualsToken : SyntaxKind - PercentEqualsToken = 57, + PercentEqualsToken = 58, >PercentEqualsToken : SyntaxKind - LessThanLessThanEqualsToken = 58, + LessThanLessThanEqualsToken = 59, >LessThanLessThanEqualsToken : SyntaxKind - GreaterThanGreaterThanEqualsToken = 59, + GreaterThanGreaterThanEqualsToken = 60, >GreaterThanGreaterThanEqualsToken : SyntaxKind - GreaterThanGreaterThanGreaterThanEqualsToken = 60, + GreaterThanGreaterThanGreaterThanEqualsToken = 61, >GreaterThanGreaterThanGreaterThanEqualsToken : SyntaxKind - AmpersandEqualsToken = 61, + AmpersandEqualsToken = 62, >AmpersandEqualsToken : SyntaxKind - BarEqualsToken = 62, + BarEqualsToken = 63, >BarEqualsToken : SyntaxKind - CaretEqualsToken = 63, + CaretEqualsToken = 64, >CaretEqualsToken : SyntaxKind - Identifier = 64, + Identifier = 65, >Identifier : SyntaxKind - BreakKeyword = 65, + BreakKeyword = 66, >BreakKeyword : SyntaxKind - CaseKeyword = 66, + CaseKeyword = 67, >CaseKeyword : SyntaxKind - CatchKeyword = 67, + CatchKeyword = 68, >CatchKeyword : SyntaxKind - ClassKeyword = 68, + ClassKeyword = 69, >ClassKeyword : SyntaxKind - ConstKeyword = 69, + ConstKeyword = 70, >ConstKeyword : SyntaxKind - ContinueKeyword = 70, + ContinueKeyword = 71, >ContinueKeyword : SyntaxKind - DebuggerKeyword = 71, + DebuggerKeyword = 72, >DebuggerKeyword : SyntaxKind - DefaultKeyword = 72, + DefaultKeyword = 73, >DefaultKeyword : SyntaxKind - DeleteKeyword = 73, + DeleteKeyword = 74, >DeleteKeyword : SyntaxKind - DoKeyword = 74, + DoKeyword = 75, >DoKeyword : SyntaxKind - ElseKeyword = 75, + ElseKeyword = 76, >ElseKeyword : SyntaxKind - EnumKeyword = 76, + EnumKeyword = 77, >EnumKeyword : SyntaxKind - ExportKeyword = 77, + ExportKeyword = 78, >ExportKeyword : SyntaxKind - ExtendsKeyword = 78, + ExtendsKeyword = 79, >ExtendsKeyword : SyntaxKind - FalseKeyword = 79, + FalseKeyword = 80, >FalseKeyword : SyntaxKind - FinallyKeyword = 80, + FinallyKeyword = 81, >FinallyKeyword : SyntaxKind - ForKeyword = 81, + ForKeyword = 82, >ForKeyword : SyntaxKind - FunctionKeyword = 82, + FunctionKeyword = 83, >FunctionKeyword : SyntaxKind - IfKeyword = 83, + IfKeyword = 84, >IfKeyword : SyntaxKind - ImportKeyword = 84, + ImportKeyword = 85, >ImportKeyword : SyntaxKind - InKeyword = 85, + InKeyword = 86, >InKeyword : SyntaxKind - InstanceOfKeyword = 86, + InstanceOfKeyword = 87, >InstanceOfKeyword : SyntaxKind - NewKeyword = 87, + NewKeyword = 88, >NewKeyword : SyntaxKind - NullKeyword = 88, + NullKeyword = 89, >NullKeyword : SyntaxKind - ReturnKeyword = 89, + ReturnKeyword = 90, >ReturnKeyword : SyntaxKind - SuperKeyword = 90, + SuperKeyword = 91, >SuperKeyword : SyntaxKind - SwitchKeyword = 91, + SwitchKeyword = 92, >SwitchKeyword : SyntaxKind - ThisKeyword = 92, + ThisKeyword = 93, >ThisKeyword : SyntaxKind - ThrowKeyword = 93, + ThrowKeyword = 94, >ThrowKeyword : SyntaxKind - TrueKeyword = 94, + TrueKeyword = 95, >TrueKeyword : SyntaxKind - TryKeyword = 95, + TryKeyword = 96, >TryKeyword : SyntaxKind - TypeOfKeyword = 96, + TypeOfKeyword = 97, >TypeOfKeyword : SyntaxKind - VarKeyword = 97, + VarKeyword = 98, >VarKeyword : SyntaxKind - VoidKeyword = 98, + VoidKeyword = 99, >VoidKeyword : SyntaxKind - WhileKeyword = 99, + WhileKeyword = 100, >WhileKeyword : SyntaxKind - WithKeyword = 100, + WithKeyword = 101, >WithKeyword : SyntaxKind - AsKeyword = 101, + AsKeyword = 102, >AsKeyword : SyntaxKind - ImplementsKeyword = 102, + ImplementsKeyword = 103, >ImplementsKeyword : SyntaxKind - InterfaceKeyword = 103, + InterfaceKeyword = 104, >InterfaceKeyword : SyntaxKind - LetKeyword = 104, + LetKeyword = 105, >LetKeyword : SyntaxKind - PackageKeyword = 105, + PackageKeyword = 106, >PackageKeyword : SyntaxKind - PrivateKeyword = 106, + PrivateKeyword = 107, >PrivateKeyword : SyntaxKind - ProtectedKeyword = 107, + ProtectedKeyword = 108, >ProtectedKeyword : SyntaxKind - PublicKeyword = 108, + PublicKeyword = 109, >PublicKeyword : SyntaxKind - StaticKeyword = 109, + StaticKeyword = 110, >StaticKeyword : SyntaxKind - YieldKeyword = 110, + YieldKeyword = 111, >YieldKeyword : SyntaxKind - AnyKeyword = 111, + AnyKeyword = 112, >AnyKeyword : SyntaxKind - BooleanKeyword = 112, + BooleanKeyword = 113, >BooleanKeyword : SyntaxKind - ConstructorKeyword = 113, + ConstructorKeyword = 114, >ConstructorKeyword : SyntaxKind - DeclareKeyword = 114, + DeclareKeyword = 115, >DeclareKeyword : SyntaxKind - GetKeyword = 115, + GetKeyword = 116, >GetKeyword : SyntaxKind - ModuleKeyword = 116, + ModuleKeyword = 117, >ModuleKeyword : SyntaxKind - RequireKeyword = 117, + RequireKeyword = 118, >RequireKeyword : SyntaxKind - NumberKeyword = 118, + NumberKeyword = 119, >NumberKeyword : SyntaxKind - SetKeyword = 119, + SetKeyword = 120, >SetKeyword : SyntaxKind - StringKeyword = 120, + StringKeyword = 121, >StringKeyword : SyntaxKind - SymbolKeyword = 121, + SymbolKeyword = 122, >SymbolKeyword : SyntaxKind - TypeKeyword = 122, + TypeKeyword = 123, >TypeKeyword : SyntaxKind - FromKeyword = 123, + FromKeyword = 124, >FromKeyword : SyntaxKind - OfKeyword = 124, + OfKeyword = 125, >OfKeyword : SyntaxKind - QualifiedName = 125, + QualifiedName = 126, >QualifiedName : SyntaxKind - ComputedPropertyName = 126, + ComputedPropertyName = 127, >ComputedPropertyName : SyntaxKind - TypeParameter = 127, + TypeParameter = 128, >TypeParameter : SyntaxKind - Parameter = 128, + Parameter = 129, >Parameter : SyntaxKind - PropertySignature = 129, + Decorator = 130, +>Decorator : SyntaxKind + + PropertySignature = 131, >PropertySignature : SyntaxKind - PropertyDeclaration = 130, + PropertyDeclaration = 132, >PropertyDeclaration : SyntaxKind - MethodSignature = 131, + MethodSignature = 133, >MethodSignature : SyntaxKind - MethodDeclaration = 132, + MethodDeclaration = 134, >MethodDeclaration : SyntaxKind - Constructor = 133, + Constructor = 135, >Constructor : SyntaxKind - GetAccessor = 134, + GetAccessor = 136, >GetAccessor : SyntaxKind - SetAccessor = 135, + SetAccessor = 137, >SetAccessor : SyntaxKind - CallSignature = 136, + CallSignature = 138, >CallSignature : SyntaxKind - ConstructSignature = 137, + ConstructSignature = 139, >ConstructSignature : SyntaxKind - IndexSignature = 138, + IndexSignature = 140, >IndexSignature : SyntaxKind - TypeReference = 139, + TypeReference = 141, >TypeReference : SyntaxKind - FunctionType = 140, + FunctionType = 142, >FunctionType : SyntaxKind - ConstructorType = 141, + ConstructorType = 143, >ConstructorType : SyntaxKind - TypeQuery = 142, + TypeQuery = 144, >TypeQuery : SyntaxKind - TypeLiteral = 143, + TypeLiteral = 145, >TypeLiteral : SyntaxKind - ArrayType = 144, + ArrayType = 146, >ArrayType : SyntaxKind - TupleType = 145, + TupleType = 147, >TupleType : SyntaxKind - UnionType = 146, + UnionType = 148, >UnionType : SyntaxKind - ParenthesizedType = 147, + ParenthesizedType = 149, >ParenthesizedType : SyntaxKind - ObjectBindingPattern = 148, + ObjectBindingPattern = 150, >ObjectBindingPattern : SyntaxKind - ArrayBindingPattern = 149, + ArrayBindingPattern = 151, >ArrayBindingPattern : SyntaxKind - BindingElement = 150, + BindingElement = 152, >BindingElement : SyntaxKind - ArrayLiteralExpression = 151, + ArrayLiteralExpression = 153, >ArrayLiteralExpression : SyntaxKind - ObjectLiteralExpression = 152, + ObjectLiteralExpression = 154, >ObjectLiteralExpression : SyntaxKind - PropertyAccessExpression = 153, + PropertyAccessExpression = 155, >PropertyAccessExpression : SyntaxKind - ElementAccessExpression = 154, + ElementAccessExpression = 156, >ElementAccessExpression : SyntaxKind - CallExpression = 155, + CallExpression = 157, >CallExpression : SyntaxKind - NewExpression = 156, + NewExpression = 158, >NewExpression : SyntaxKind - TaggedTemplateExpression = 157, + TaggedTemplateExpression = 159, >TaggedTemplateExpression : SyntaxKind - TypeAssertionExpression = 158, + TypeAssertionExpression = 160, >TypeAssertionExpression : SyntaxKind - ParenthesizedExpression = 159, + ParenthesizedExpression = 161, >ParenthesizedExpression : SyntaxKind - FunctionExpression = 160, + FunctionExpression = 162, >FunctionExpression : SyntaxKind - ArrowFunction = 161, + ArrowFunction = 163, >ArrowFunction : SyntaxKind - DeleteExpression = 162, + DeleteExpression = 164, >DeleteExpression : SyntaxKind - TypeOfExpression = 163, + TypeOfExpression = 165, >TypeOfExpression : SyntaxKind - VoidExpression = 164, + VoidExpression = 166, >VoidExpression : SyntaxKind - PrefixUnaryExpression = 165, + PrefixUnaryExpression = 167, >PrefixUnaryExpression : SyntaxKind - PostfixUnaryExpression = 166, + PostfixUnaryExpression = 168, >PostfixUnaryExpression : SyntaxKind - BinaryExpression = 167, + BinaryExpression = 169, >BinaryExpression : SyntaxKind - ConditionalExpression = 168, + ConditionalExpression = 170, >ConditionalExpression : SyntaxKind - TemplateExpression = 169, + TemplateExpression = 171, >TemplateExpression : SyntaxKind - YieldExpression = 170, + YieldExpression = 172, >YieldExpression : SyntaxKind - SpreadElementExpression = 171, + SpreadElementExpression = 173, >SpreadElementExpression : SyntaxKind - OmittedExpression = 172, + OmittedExpression = 174, >OmittedExpression : SyntaxKind - TemplateSpan = 173, + TemplateSpan = 175, >TemplateSpan : SyntaxKind - Block = 174, + Block = 176, >Block : SyntaxKind - VariableStatement = 175, + VariableStatement = 177, >VariableStatement : SyntaxKind - EmptyStatement = 176, + EmptyStatement = 178, >EmptyStatement : SyntaxKind - ExpressionStatement = 177, + ExpressionStatement = 179, >ExpressionStatement : SyntaxKind - IfStatement = 178, + IfStatement = 180, >IfStatement : SyntaxKind - DoStatement = 179, + DoStatement = 181, >DoStatement : SyntaxKind - WhileStatement = 180, + WhileStatement = 182, >WhileStatement : SyntaxKind - ForStatement = 181, + ForStatement = 183, >ForStatement : SyntaxKind - ForInStatement = 182, + ForInStatement = 184, >ForInStatement : SyntaxKind - ForOfStatement = 183, + ForOfStatement = 185, >ForOfStatement : SyntaxKind - ContinueStatement = 184, + ContinueStatement = 186, >ContinueStatement : SyntaxKind - BreakStatement = 185, + BreakStatement = 187, >BreakStatement : SyntaxKind - ReturnStatement = 186, + ReturnStatement = 188, >ReturnStatement : SyntaxKind - WithStatement = 187, + WithStatement = 189, >WithStatement : SyntaxKind - SwitchStatement = 188, + SwitchStatement = 190, >SwitchStatement : SyntaxKind - LabeledStatement = 189, + LabeledStatement = 191, >LabeledStatement : SyntaxKind - ThrowStatement = 190, + ThrowStatement = 192, >ThrowStatement : SyntaxKind - TryStatement = 191, + TryStatement = 193, >TryStatement : SyntaxKind - DebuggerStatement = 192, + DebuggerStatement = 194, >DebuggerStatement : SyntaxKind - VariableDeclaration = 193, + VariableDeclaration = 195, >VariableDeclaration : SyntaxKind - VariableDeclarationList = 194, + VariableDeclarationList = 196, >VariableDeclarationList : SyntaxKind - FunctionDeclaration = 195, + FunctionDeclaration = 197, >FunctionDeclaration : SyntaxKind - ClassDeclaration = 196, + ClassDeclaration = 198, >ClassDeclaration : SyntaxKind - InterfaceDeclaration = 197, + InterfaceDeclaration = 199, >InterfaceDeclaration : SyntaxKind - TypeAliasDeclaration = 198, + TypeAliasDeclaration = 200, >TypeAliasDeclaration : SyntaxKind - EnumDeclaration = 199, + EnumDeclaration = 201, >EnumDeclaration : SyntaxKind - ModuleDeclaration = 200, + ModuleDeclaration = 202, >ModuleDeclaration : SyntaxKind - ModuleBlock = 201, + ModuleBlock = 203, >ModuleBlock : SyntaxKind - CaseBlock = 202, + CaseBlock = 204, >CaseBlock : SyntaxKind - ImportEqualsDeclaration = 203, + ImportEqualsDeclaration = 205, >ImportEqualsDeclaration : SyntaxKind - ImportDeclaration = 204, + ImportDeclaration = 206, >ImportDeclaration : SyntaxKind - ImportClause = 205, + ImportClause = 207, >ImportClause : SyntaxKind - NamespaceImport = 206, + NamespaceImport = 208, >NamespaceImport : SyntaxKind - NamedImports = 207, + NamedImports = 209, >NamedImports : SyntaxKind - ImportSpecifier = 208, + ImportSpecifier = 210, >ImportSpecifier : SyntaxKind - ExportAssignment = 209, + ExportAssignment = 211, >ExportAssignment : SyntaxKind - ExportDeclaration = 210, + ExportDeclaration = 212, >ExportDeclaration : SyntaxKind - NamedExports = 211, + NamedExports = 213, >NamedExports : SyntaxKind - ExportSpecifier = 212, + ExportSpecifier = 214, >ExportSpecifier : SyntaxKind - ExternalModuleReference = 213, + IncompleteDeclaration = 215, +>IncompleteDeclaration : SyntaxKind + + ExternalModuleReference = 216, >ExternalModuleReference : SyntaxKind - CaseClause = 214, + CaseClause = 217, >CaseClause : SyntaxKind - DefaultClause = 215, + DefaultClause = 218, >DefaultClause : SyntaxKind - HeritageClause = 216, + HeritageClause = 219, >HeritageClause : SyntaxKind - CatchClause = 217, + CatchClause = 220, >CatchClause : SyntaxKind - PropertyAssignment = 218, + PropertyAssignment = 221, >PropertyAssignment : SyntaxKind - ShorthandPropertyAssignment = 219, + ShorthandPropertyAssignment = 222, >ShorthandPropertyAssignment : SyntaxKind - EnumMember = 220, + EnumMember = 223, >EnumMember : SyntaxKind - SourceFile = 221, + SourceFile = 224, >SourceFile : SyntaxKind - SyntaxList = 222, + SyntaxList = 225, >SyntaxList : SyntaxKind - Count = 223, + Count = 226, >Count : SyntaxKind - FirstAssignment = 52, + FirstAssignment = 53, >FirstAssignment : SyntaxKind - LastAssignment = 63, + LastAssignment = 64, >LastAssignment : SyntaxKind - FirstReservedWord = 65, + FirstReservedWord = 66, >FirstReservedWord : SyntaxKind - LastReservedWord = 100, + LastReservedWord = 101, >LastReservedWord : SyntaxKind - FirstKeyword = 65, + FirstKeyword = 66, >FirstKeyword : SyntaxKind - LastKeyword = 124, + LastKeyword = 125, >LastKeyword : SyntaxKind - FirstFutureReservedWord = 102, + FirstFutureReservedWord = 103, >FirstFutureReservedWord : SyntaxKind - LastFutureReservedWord = 110, + LastFutureReservedWord = 111, >LastFutureReservedWord : SyntaxKind - FirstTypeNode = 139, + FirstTypeNode = 141, >FirstTypeNode : SyntaxKind - LastTypeNode = 147, + LastTypeNode = 149, >LastTypeNode : SyntaxKind FirstPunctuation = 14, >FirstPunctuation : SyntaxKind - LastPunctuation = 63, + LastPunctuation = 64, >LastPunctuation : SyntaxKind FirstToken = 0, >FirstToken : SyntaxKind - LastToken = 124, + LastToken = 125, >LastToken : SyntaxKind FirstTriviaToken = 2, @@ -1199,10 +1208,10 @@ declare module "typescript" { FirstBinaryOperator = 24, >FirstBinaryOperator : SyntaxKind - LastBinaryOperator = 63, + LastBinaryOperator = 64, >LastBinaryOperator : SyntaxKind - FirstNode = 125, + FirstNode = 126, >FirstNode : SyntaxKind } const enum NodeFlags { @@ -1271,16 +1280,19 @@ declare module "typescript" { GeneratorParameter = 8, >GeneratorParameter : ParserContextFlags - ThisNodeHasError = 16, + Decorator = 16, +>Decorator : ParserContextFlags + + ThisNodeHasError = 32, >ThisNodeHasError : ParserContextFlags - ParserGeneratedFlags = 31, + ParserGeneratedFlags = 63, >ParserGeneratedFlags : ParserContextFlags - ThisNodeOrAnySubNodesHasError = 32, + ThisNodeOrAnySubNodesHasError = 64, >ThisNodeOrAnySubNodesHasError : ParserContextFlags - HasAggregatedChildData = 64, + HasAggregatedChildData = 128, >HasAggregatedChildData : ParserContextFlags } const enum RelationComparisonResult { @@ -1311,6 +1323,11 @@ declare module "typescript" { >parserContextFlags : ParserContextFlags >ParserContextFlags : ParserContextFlags + decorators?: NodeArray; +>decorators : NodeArray +>NodeArray : NodeArray +>Decorator : Decorator + modifiers?: ModifiersArray; >modifiers : ModifiersArray >ModifiersArray : ModifiersArray @@ -1405,6 +1422,18 @@ declare module "typescript" { expression: Expression; >expression : Expression >Expression : Expression + } + interface Decorator extends Node { +>Decorator : Decorator +>Node : Node + + atToken: Node; +>atToken : Node +>Node : Node + + expression: LeftHandSideExpression; +>expression : LeftHandSideExpression +>LeftHandSideExpression : LeftHandSideExpression } interface TypeParameterDeclaration extends Declaration { >TypeParameterDeclaration : TypeParameterDeclaration @@ -2004,10 +2033,18 @@ declare module "typescript" { >ArrayLiteralExpression : ArrayLiteralExpression >PrimaryExpression : PrimaryExpression + openBracketToken: Node; +>openBracketToken : Node +>Node : Node + elements: NodeArray; >elements : NodeArray >NodeArray : NodeArray >Expression : Expression + + closeBracketToken: Node; +>closeBracketToken : Node +>Node : Node } interface SpreadElementExpression extends Expression { >SpreadElementExpression : SpreadElementExpression @@ -2051,9 +2088,17 @@ declare module "typescript" { >expression : LeftHandSideExpression >LeftHandSideExpression : LeftHandSideExpression + openBracketToken: Node; +>openBracketToken : Node +>Node : Node + argumentExpression?: Expression; >argumentExpression : Expression >Expression : Expression + + closeBracketToken: Node; +>closeBracketToken : Node +>Node : Node } interface CallExpression extends LeftHandSideExpression { >CallExpression : CallExpression From fb10deb49c1412e44ce6c111235aec2f5206ab1d Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 17 Mar 2015 11:02:23 -0700 Subject: [PATCH 135/224] Scanner updates for decorators --- src/compiler/scanner.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index fbcadab8c1d85..19b5d24c3f99e 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -148,6 +148,7 @@ module ts { "&=": SyntaxKind.AmpersandEqualsToken, "|=": SyntaxKind.BarEqualsToken, "^=": SyntaxKind.CaretEqualsToken, + "@": SyntaxKind.AtToken, }; /* @@ -315,6 +316,19 @@ module ts { return computeLineAndCharacterOfPosition(getLineStarts(sourceFile), position); } + export function lineBreakBetween(sourceFile: SourceFile, firstPos: number, secondPos: number): boolean { + var lineStarts = getLineStarts(sourceFile); + var firstLine = binarySearch(lineStarts, firstPos); + var secondLine = binarySearch(lineStarts, secondPos); + if (firstLine < 0) { + firstLine = ~firstLine - 1; + } + if (secondLine < 0) { + secondLine = ~secondLine - 1; + } + return firstLine !== secondLine; + } + let hasOwnProperty = Object.prototype.hasOwnProperty; export function isWhiteSpace(ch: number): boolean { @@ -1247,6 +1261,8 @@ module ts { return pos++, token = SyntaxKind.CloseBraceToken; case CharacterCodes.tilde: return pos++, token = SyntaxKind.TildeToken; + case CharacterCodes.at: + return pos++, token = SyntaxKind.AtToken; case CharacterCodes.backslash: let cookedChar = peekUnicodeEscape(); if (cookedChar >= 0 && isIdentifierStart(cookedChar)) { From 8282a0b9ca689e362134f5e7f2ba1ead3d176864 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 17 Mar 2015 11:18:48 -0700 Subject: [PATCH 136/224] Parser updates for decorators --- src/compiler/parser.ts | 560 +++++++++++++++++++++++++++++++++++------ 1 file changed, 482 insertions(+), 78 deletions(-) diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 9eae67a29b843..57519f6584e28 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -64,7 +64,8 @@ module ts { case SyntaxKind.ShorthandPropertyAssignment: case SyntaxKind.VariableDeclaration: case SyntaxKind.BindingElement: - return visitNodes(cbNodes, node.modifiers) || + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).propertyName) || visitNode(cbNode, (node).dotDotDotToken) || visitNode(cbNode, (node).name) || @@ -76,7 +77,8 @@ module ts { case SyntaxKind.CallSignature: case SyntaxKind.ConstructSignature: case SyntaxKind.IndexSignature: - return visitNodes(cbNodes, node.modifiers) || + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || visitNodes(cbNodes, (node).typeParameters) || visitNodes(cbNodes, (node).parameters) || visitNode(cbNode, (node).type); @@ -88,7 +90,8 @@ module ts { case SyntaxKind.FunctionExpression: case SyntaxKind.FunctionDeclaration: case SyntaxKind.ArrowFunction: - return visitNodes(cbNodes, node.modifiers) || + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).asteriskToken) || visitNode(cbNode, (node).name) || visitNode(cbNode, (node).questionToken) || @@ -116,7 +119,9 @@ module ts { case SyntaxKind.ArrayBindingPattern: return visitNodes(cbNodes, (node).elements); case SyntaxKind.ArrayLiteralExpression: - return visitNodes(cbNodes, (node).elements); + return visitNode(cbNode, (node).openBracketToken) || + visitNodes(cbNodes, (node).elements) || + visitNode(cbNode, (node).closeBracketToken); case SyntaxKind.ObjectLiteralExpression: return visitNodes(cbNodes, (node).properties); case SyntaxKind.PropertyAccessExpression: @@ -125,7 +130,9 @@ module ts { visitNode(cbNode, (node).name); case SyntaxKind.ElementAccessExpression: return visitNode(cbNode, (node).expression) || - visitNode(cbNode, (node).argumentExpression); + visitNode(cbNode, (node).openBracketToken) || + visitNode(cbNode, (node).argumentExpression) || + visitNode(cbNode, (node).closeBracketToken); case SyntaxKind.CallExpression: case SyntaxKind.NewExpression: return visitNode(cbNode, (node).expression) || @@ -171,7 +178,8 @@ module ts { return visitNodes(cbNodes, (node).statements) || visitNode(cbNode, (node).endOfFileToken); case SyntaxKind.VariableStatement: - return visitNodes(cbNodes, node.modifiers) || + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).declarationList); case SyntaxKind.VariableDeclarationList: return visitNodes(cbNodes, (node).declarations); @@ -230,39 +238,49 @@ module ts { case SyntaxKind.CatchClause: return visitNode(cbNode, (node).variableDeclaration) || visitNode(cbNode, (node).block); + case SyntaxKind.Decorator: + return visitNode(cbNode, (node).atToken) || + visitNode(cbNode, (node).expression); case SyntaxKind.ClassDeclaration: - return visitNodes(cbNodes, node.modifiers) || + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).name) || visitNodes(cbNodes, (node).typeParameters) || visitNodes(cbNodes, (node).heritageClauses) || visitNodes(cbNodes, (node).members); case SyntaxKind.InterfaceDeclaration: - return visitNodes(cbNodes, node.modifiers) || + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).name) || visitNodes(cbNodes, (node).typeParameters) || visitNodes(cbNodes, (node).heritageClauses) || visitNodes(cbNodes, (node).members); case SyntaxKind.TypeAliasDeclaration: - return visitNodes(cbNodes, node.modifiers) || + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).name) || visitNode(cbNode, (node).type); case SyntaxKind.EnumDeclaration: - return visitNodes(cbNodes, node.modifiers) || + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).name) || visitNodes(cbNodes, (node).members); case SyntaxKind.EnumMember: return visitNode(cbNode, (node).name) || visitNode(cbNode, (node).initializer); case SyntaxKind.ModuleDeclaration: - return visitNodes(cbNodes, node.modifiers) || + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).name) || visitNode(cbNode, (node).body); case SyntaxKind.ImportEqualsDeclaration: - return visitNodes(cbNodes, node.modifiers) || + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).name) || visitNode(cbNode, (node).moduleReference); case SyntaxKind.ImportDeclaration: - return visitNodes(cbNodes, node.modifiers) || + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).importClause) || visitNode(cbNode, (node).moduleSpecifier); case SyntaxKind.ImportClause: @@ -274,7 +292,8 @@ module ts { case SyntaxKind.NamedExports: return visitNodes(cbNodes, (node).elements); case SyntaxKind.ExportDeclaration: - return visitNodes(cbNodes, node.modifiers) || + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).exportClause) || visitNode(cbNode, (node).moduleSpecifier); case SyntaxKind.ImportSpecifier: @@ -282,7 +301,8 @@ module ts { return visitNode(cbNode, (node).propertyName) || visitNode(cbNode, (node).name); case SyntaxKind.ExportAssignment: - return visitNodes(cbNodes, node.modifiers) || + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers) || visitNode(cbNode, (node).expression) || visitNode(cbNode, (node).type); case SyntaxKind.TemplateExpression: @@ -295,6 +315,9 @@ module ts { return visitNodes(cbNodes, (node).types); case SyntaxKind.ExternalModuleReference: return visitNode(cbNode, (node).expression); + case SyntaxKind.IncompleteDeclaration: + return visitNodes(cbNodes, node.decorators) || + visitNodes(cbNodes, node.modifiers); } } @@ -329,6 +352,12 @@ module ts { Unknown } + interface SignatureResult { + typeParameters?: NodeArray; + parameters?: NodeArray; + type?: TypeNode; + } + function parsingContextErrors(context: ParsingContext): DiagnosticMessage { switch (context) { case ParsingContext.SourceElements: return Diagnostics.Declaration_or_statement_expected; @@ -1130,6 +1159,10 @@ module ts { setContextFlag(val, ParserContextFlags.GeneratorParameter); } + function setDecoratorContext(val: boolean) { + setContextFlag(val, ParserContextFlags.Decorator); + } + function allowInAnd(func: () => T): T { if (contextFlags & ParserContextFlags.DisallowIn) { setDisallowInContext(false); @@ -1178,6 +1211,30 @@ module ts { return func(); } + function doInDecoratorContext(func: () => T): T { + if (contextFlags & ParserContextFlags.Decorator) { + // no need to do anything special if we're already in the [Decorator] context. + return func(); + } + + setDecoratorContext(true); + let result = func(); + setDecoratorContext(false); + return result; + } + + function doOutsideOfDecoratorContext(func: () => T): T { + if (contextFlags & ParserContextFlags.Decorator) { + setDecoratorContext(false); + let result = func(); + setDecoratorContext(true); + return result; + } + + // no need to do anything special if we're not in the [Decorator] context. + return func(); + } + function inYieldContext() { return (contextFlags & ParserContextFlags.Yield) !== 0; } @@ -1194,6 +1251,10 @@ module ts { return (contextFlags & ParserContextFlags.DisallowIn) !== 0; } + function inDecoratorContext() { + return (contextFlags & ParserContextFlags.Decorator) !== 0; + } + function parseErrorAtCurrentToken(message: DiagnosticMessage, arg0?: any): void { let start = scanner.getTokenPos(); let length = scanner.getTextPos() - start; @@ -1386,8 +1447,12 @@ module ts { return node; } - function finishNode(node: T): T { - node.end = scanner.getStartPos(); + function finishNode(node: T, end?: number): T { + if (!(end >= 0)) { + end = scanner.getStartPos(); + } + + node.end = end; if (contextFlags) { node.parserContextFlags = contextFlags; @@ -1404,6 +1469,13 @@ module ts { return node; } + function createMissingNodeAtPosition(pos: number, kind: SyntaxKind, diagnosticMessage: DiagnosticMessage, arg0?: any): Node { + parseErrorAtPosition(pos, 0, diagnosticMessage, arg0); + let result = createNode(kind, pos); + (result).text = ""; + return finishNode(result, pos); + } + function createMissingNode(kind: SyntaxKind, reportAtCurrentPosition: boolean, diagnosticMessage: DiagnosticMessage, arg0?: any): Node { if (reportAtCurrentPosition) { parseErrorAtPosition(scanner.getStartPos(), 0, diagnosticMessage, arg0); @@ -2273,7 +2345,7 @@ module ts { } function isStartOfParameter(): boolean { - return token === SyntaxKind.DotDotDotToken || isIdentifierOrPattern() || isModifier(token); + return token === SyntaxKind.DotDotDotToken || isIdentifierOrPattern() || isModifier(token) || token === SyntaxKind.AtToken; } function setModifiers(node: Node, modifiers: ModifiersArray) { @@ -2285,6 +2357,7 @@ module ts { function parseParameter(): ParameterDeclaration { let node = createNode(SyntaxKind.Parameter); + node.decorators = parseDecorators(); setModifiers(node, parseModifiers()); node.dotDotDotToken = parseOptionalToken(SyntaxKind.DotDotDotToken); @@ -2473,9 +2546,9 @@ module ts { return token === SyntaxKind.ColonToken || token === SyntaxKind.CommaToken || token === SyntaxKind.CloseBracketToken; } - function parseIndexSignatureDeclaration(modifiers: ModifiersArray): IndexSignatureDeclaration { - let fullStart = modifiers ? modifiers.pos : scanner.getStartPos(); + function parseIndexSignatureDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): IndexSignatureDeclaration { let node = createNode(SyntaxKind.IndexSignature, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); node.parameters = parseBracketedList(ParsingContext.Parameters, parseParameter, SyntaxKind.OpenBracketToken, SyntaxKind.CloseBracketToken); node.type = parseTypeAnnotation(); @@ -2552,7 +2625,7 @@ module ts { case SyntaxKind.OpenBracketToken: // Indexer or computed property return isIndexSignature() - ? parseIndexSignatureDeclaration(/*modifiers:*/ undefined) + ? parseIndexSignatureDeclaration(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers:*/ undefined) : parsePropertyOrMethodSignature(); case SyntaxKind.NewKeyword: if (lookAhead(isStartOfConstructSignature)) { @@ -2583,9 +2656,11 @@ module ts { } function parseIndexSignatureWithModifiers() { + let fullStart = scanner.getStartPos(); + let decorators = parseDecorators(); let modifiers = parseModifiers(); return isIndexSignature() - ? parseIndexSignatureDeclaration(modifiers) + ? parseIndexSignatureDeclaration(fullStart, decorators, modifiers) : undefined; } @@ -2841,7 +2916,7 @@ module ts { function isStartOfExpressionStatement(): boolean { // As per the grammar, neither '{' nor 'function' can start an expression statement. - return token !== SyntaxKind.OpenBraceToken && token !== SyntaxKind.FunctionKeyword && isStartOfExpression(); + return token !== SyntaxKind.OpenBraceToken && token !== SyntaxKind.FunctionKeyword && token !== SyntaxKind.AtToken && isStartOfExpression(); } function parseExpression(): Expression { @@ -2849,11 +2924,21 @@ module ts { // AssignmentExpression[in] // Expression[in] , AssignmentExpression[in] + // clear the decorator context when parsing Expression, as it should be unambiguous when parsing a decorator + let saveDecoratorContext = inDecoratorContext(); + if (saveDecoratorContext) { + setDecoratorContext(false); + } + let expr = parseAssignmentExpressionOrHigher(); let operatorToken: Node; while ((operatorToken = parseOptionalToken(SyntaxKind.CommaToken))) { expr = makeBinaryExpression(expr, operatorToken, parseAssignmentExpressionOrHigher()); } + + if (saveDecoratorContext) { + setDecoratorContext(true); + } return expr; } @@ -3500,9 +3585,11 @@ module ts { continue; } - if (parseOptional(SyntaxKind.OpenBracketToken)) { + let openBracketToken = parseOptionalToken(SyntaxKind.OpenBracketToken); + if (openBracketToken) { let indexedAccess = createNode(SyntaxKind.ElementAccessExpression, expression.pos); indexedAccess.expression = expression; + indexedAccess.openBracketToken = openBracketToken; // It's not uncommon for a user to write: "new Type[]". // Check for that common pattern and report a better error message. @@ -3514,7 +3601,7 @@ module ts { } } - parseExpected(SyntaxKind.CloseBracketToken); + indexedAccess.closeBracketToken = parseExpectedToken(SyntaxKind.CloseBracketToken, /*reportAtCurrentPosition*/false, Diagnostics._0_expected, "]"); expression = finishNode(indexedAccess); continue; } @@ -3536,7 +3623,16 @@ module ts { function parseCallExpressionRest(expression: LeftHandSideExpression): LeftHandSideExpression { while (true) { expression = parseMemberExpressionRest(expression); - + if (inDecoratorContext() && + parsingContext === ParsingContext.ClassMembers && + (token === SyntaxKind.LessThanToken || token === SyntaxKind.OpenParenToken) && + (expression.kind === SyntaxKind.ElementAccessExpression || expression.kind === SyntaxKind.Identifier)) { + // TODO(rbuckton): switch to tryParse and reuse the parsed signature information? + let result = lookAhead(isStartOfMethodSignature); + if (result) { + return expression; + } + } if (token === SyntaxKind.LessThanToken) { // See if this is the start of a generic invocation. If so, consume it and // keep checking for postfix expressions. Otherwise, it's just a '<' that's @@ -3566,6 +3662,28 @@ module ts { } } + function isStartOfMethodSignature() { + // try to parse it as a signature, if successful and we are followed by an open brace or semicolon, this is really a method signature + var parameters: NodeArray; + var type: TypeNode; + if (token === SyntaxKind.LessThanToken && !parseTypeParameters()) { + // failed to parse type parameters here, this is not a method + return false; + } + if (token === SyntaxKind.OpenParenToken) { + if (!parseParameterList(/*yieldAndGeneratorParameterContext*/ false, /*requireCompleteParameterList*/ true)) { + // failed to parse a parameter list here, this is not a method + return false; + } + if (token === SyntaxKind.ColonToken || token === SyntaxKind.SemicolonToken || token === SyntaxKind.OpenBraceToken) { + // found a type annotation, semicolon, or open brace, this is a method signature + type = parseTypeAnnotation(); + return true; + } + } + return false; + } + function parseArgumentList() { parseExpected(SyntaxKind.OpenParenToken); let result = parseDelimitedList(ParsingContext.ArgumentExpressions, parseArgumentExpression); @@ -3688,19 +3806,19 @@ module ts { function parseArrayLiteralExpression(): ArrayLiteralExpression { let node = createNode(SyntaxKind.ArrayLiteralExpression); - parseExpected(SyntaxKind.OpenBracketToken); + node.openBracketToken = parseExpectedToken(SyntaxKind.OpenBracketToken, /*reportAtCurrentPosition*/ false, Diagnostics._0_expected, "["); if (scanner.hasPrecedingLineBreak()) node.flags |= NodeFlags.MultiLine; node.elements = parseDelimitedList(ParsingContext.ArrayLiteralMembers, parseArgumentOrArrayLiteralElement); - parseExpected(SyntaxKind.CloseBracketToken); + node.closeBracketToken = parseExpectedToken(SyntaxKind.CloseBracketToken, /*reportAtCurrentPosition*/ false, Diagnostics._0_expected, "]"); return finishNode(node); } - function tryParseAccessorDeclaration(fullStart: number, modifiers: ModifiersArray): AccessorDeclaration { + function tryParseAccessorDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): AccessorDeclaration { if (parseContextualModifier(SyntaxKind.GetKeyword)) { - return parseAccessorDeclaration(SyntaxKind.GetAccessor, fullStart, modifiers); + return parseAccessorDeclaration(SyntaxKind.GetAccessor, fullStart, decorators, modifiers); } else if (parseContextualModifier(SyntaxKind.SetKeyword)) { - return parseAccessorDeclaration(SyntaxKind.SetAccessor, fullStart, modifiers); + return parseAccessorDeclaration(SyntaxKind.SetAccessor, fullStart, decorators, modifiers); } return undefined; @@ -3708,9 +3826,10 @@ module ts { function parseObjectLiteralElement(): ObjectLiteralElement { let fullStart = scanner.getStartPos(); + let decorators = parseDecorators(); let modifiers = parseModifiers(); - let accessor = tryParseAccessorDeclaration(fullStart, modifiers); + let accessor = tryParseAccessorDeclaration(fullStart, decorators, modifiers); if (accessor) { return accessor; } @@ -3723,7 +3842,7 @@ module ts { // Disallowing of optional property assignments happens in the grammar checker. let questionToken = parseOptionalToken(SyntaxKind.QuestionToken); if (asteriskToken || token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) { - return parseMethodDeclaration(fullStart, modifiers, asteriskToken, propertyName, questionToken); + return parseMethodDeclaration(fullStart, decorators, modifiers, asteriskToken, propertyName, questionToken); } // Parse to check if it is short-hand property assignment or normal property assignment @@ -3760,12 +3879,19 @@ module ts { // function * BindingIdentifier[Yield]opt (FormalParameters[Yield, GeneratorParameter]) { GeneratorBody[Yield] } // FunctionExpression: // function BindingIdentifieropt(FormalParameters) { FunctionBody } + let saveDecoratorContext = inDecoratorContext(); + if (saveDecoratorContext) { + setDecoratorContext(false); + } let node = createNode(SyntaxKind.FunctionExpression); parseExpected(SyntaxKind.FunctionKeyword); node.asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); node.name = node.asteriskToken ? doInYieldContext(parseOptionalIdentifier) : parseOptionalIdentifier(); fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext:*/ !!node.asteriskToken, /*requireCompleteParameterList:*/ false, node); node.body = parseFunctionBlock(/*allowYield:*/ !!node.asteriskToken, /* ignoreMissingOpenBrace */ false); + if (saveDecoratorContext) { + setDecoratorContext(true); + } return finishNode(node); } @@ -3802,8 +3928,17 @@ module ts { let savedYieldContext = inYieldContext(); setYieldContext(allowYield); + let saveDecoratorContext = inDecoratorContext(); + if (saveDecoratorContext) { + setDecoratorContext(false); + } + let block = parseBlock(ignoreMissingOpenBrace, /*checkForStrictMode*/ true, diagnosticMessage); + if (saveDecoratorContext) { + setDecoratorContext(true); + } + setYieldContext(savedYieldContext); return block; @@ -4135,9 +4270,9 @@ module ts { case SyntaxKind.VarKeyword: case SyntaxKind.ConstKeyword: // const here should always be parsed as const declaration because of check in 'isStatement' - return parseVariableStatement(scanner.getStartPos(), /*modifiers:*/ undefined); + return parseVariableStatement(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers:*/ undefined); case SyntaxKind.FunctionKeyword: - return parseFunctionDeclaration(scanner.getStartPos(), /*modifiers:*/ undefined); + return parseFunctionDeclaration(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers:*/ undefined); case SyntaxKind.SemicolonToken: return parseEmptyStatement(); case SyntaxKind.IfKeyword: @@ -4170,7 +4305,7 @@ module ts { case SyntaxKind.LetKeyword: // If let follows identifier on the same line, it is declaration parse it as variable statement if (isLetDeclaration()) { - return parseVariableStatement(scanner.getStartPos(), /*modifiers:*/ undefined); + return parseVariableStatement(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers:*/ undefined); } // Else parse it like identifier - fall through default: @@ -4180,7 +4315,9 @@ module ts { // work properly when incrementally parsing as the parser will produce the // same FunctionDeclaraiton or VariableStatement if it has the same text // regardless of whether it is inside a block or not. - if (isModifier(token)) { + // Even though variable statements and function declarations cannot have decorators, + // we parse them here to provide better error recovery. + if (isModifier(token) || token === SyntaxKind.AtToken) { let result = tryParse(parseVariableStatementOrFunctionDeclarationWithModifiers); if (result) { return result; @@ -4193,6 +4330,7 @@ module ts { function parseVariableStatementOrFunctionDeclarationWithModifiers(): FunctionDeclaration | VariableStatement { let start = scanner.getStartPos(); + let decorators = parseDecorators(); let modifiers = parseModifiers(); switch (token) { case SyntaxKind.ConstKeyword: @@ -4200,18 +4338,18 @@ module ts { if (nextTokenIsEnum) { return undefined; } - return parseVariableStatement(start, modifiers); + return parseVariableStatement(start, decorators, modifiers); case SyntaxKind.LetKeyword: if (!isLetDeclaration()) { return undefined; } - return parseVariableStatement(start, modifiers); + return parseVariableStatement(start, decorators, modifiers); case SyntaxKind.VarKeyword: - return parseVariableStatement(start, modifiers); + return parseVariableStatement(start, decorators, modifiers); case SyntaxKind.FunctionKeyword: - return parseFunctionDeclaration(start, modifiers); + return parseFunctionDeclaration(start, decorators, modifiers); } return undefined; @@ -4341,16 +4479,18 @@ module ts { return nextTokenIsIdentifier() && nextToken() === SyntaxKind.CloseParenToken; } - function parseVariableStatement(fullStart: number, modifiers: ModifiersArray): VariableStatement { + function parseVariableStatement(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): VariableStatement { let node = createNode(SyntaxKind.VariableStatement, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); node.declarationList = parseVariableDeclarationList(/*inForStatementInitializer:*/ false); parseSemicolon(); return finishNode(node); } - function parseFunctionDeclaration(fullStart: number, modifiers: ModifiersArray): FunctionDeclaration { + function parseFunctionDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): FunctionDeclaration { let node = createNode(SyntaxKind.FunctionDeclaration, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); parseExpected(SyntaxKind.FunctionKeyword); node.asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); @@ -4360,8 +4500,9 @@ module ts { return finishNode(node); } - function parseConstructorDeclaration(pos: number, modifiers: ModifiersArray): ConstructorDeclaration { + function parseConstructorDeclaration(pos: number, decorators: NodeArray, modifiers: ModifiersArray): ConstructorDeclaration { let node = createNode(SyntaxKind.Constructor, pos); + node.decorators = decorators; setModifiers(node, modifiers); parseExpected(SyntaxKind.ConstructorKeyword); fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext:*/ false, /*requireCompleteParameterList:*/ false, node); @@ -4369,8 +4510,9 @@ module ts { return finishNode(node); } - function parseMethodDeclaration(fullStart: number, modifiers: ModifiersArray, asteriskToken: Node, name: DeclarationName, questionToken: Node, diagnosticMessage?: DiagnosticMessage): MethodDeclaration { + function parseMethodDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray, asteriskToken: Node, name: DeclarationName, questionToken: Node, diagnosticMessage?: DiagnosticMessage): MethodDeclaration { let method = createNode(SyntaxKind.MethodDeclaration, fullStart); + method.decorators = decorators; setModifiers(method, modifiers); method.asteriskToken = asteriskToken; method.name = name; @@ -4380,7 +4522,7 @@ module ts { return finishNode(method); } - function parsePropertyOrMethodDeclaration(fullStart: number, modifiers: ModifiersArray): ClassElement { + function parsePropertyOrMethodDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): ClassElement { let asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); let name = parsePropertyName(); @@ -4388,10 +4530,11 @@ module ts { // report an error in the grammar checker. let questionToken = parseOptionalToken(SyntaxKind.QuestionToken); if (asteriskToken || token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) { - return parseMethodDeclaration(fullStart, modifiers, asteriskToken, name, questionToken, Diagnostics.or_expected); + return parseMethodDeclaration(fullStart, decorators, modifiers, asteriskToken, name, questionToken, Diagnostics.or_expected); } else { let property = createNode(SyntaxKind.PropertyDeclaration, fullStart); + property.decorators = decorators; setModifiers(property, modifiers); property.name = name; property.questionToken = questionToken; @@ -4406,8 +4549,9 @@ module ts { return parseInitializer(/*inParameter*/ false); } - function parseAccessorDeclaration(kind: SyntaxKind, fullStart: number, modifiers: ModifiersArray): AccessorDeclaration { + function parseAccessorDeclaration(kind: SyntaxKind, fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): AccessorDeclaration { let node = createNode(kind, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); node.name = parsePropertyName(); fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext:*/ false, /*requireCompleteParameterList:*/ false, node); @@ -4418,6 +4562,10 @@ module ts { function isClassMemberStart(): boolean { let idToken: SyntaxKind; + if (token === SyntaxKind.AtToken) { + return true; + } + // Eat up all modifiers, but hold on to the last one in case it is actually an identifier. while (isModifier(token)) { idToken = token; @@ -4469,6 +4617,29 @@ module ts { return false; } + function parseDecorators(): NodeArray { + let decorators: NodeArray; + while (true) { + if (token !== SyntaxKind.AtToken) { + break; + } + + if (!decorators) { + decorators = >[]; + decorators.pos = scanner.getStartPos(); + } + + let decorator = createNode(SyntaxKind.Decorator); + decorator.atToken = parseTokenNode(); + decorator.expression = doInDecoratorContext(parseLeftHandSideExpressionOrHigher); + decorators.push(finishNode(decorator)); + } + if (decorators) { + decorators.end = scanner.getStartPos(); + } + return decorators; + } + function parseModifiers(): ModifiersArray { let flags = 0; let modifiers: ModifiersArray; @@ -4494,21 +4665,227 @@ module ts { return modifiers; } + function extractCallExpressionFromDecoratorTail(decorator: Decorator): CallExpression { + // We could have greedily parsed a method signature name as a call expression, so we extract it from the decorator. + let expression = decorator.expression; + if (expression.kind === SyntaxKind.CallExpression) { + decorator.expression = (expression).expression; + decorator.end = decorator.expression.end; + return expression; + } + return undefined; + } + + function extractDeclarationNameFromDecoratorTail(decorator: Decorator): DeclarationName { + let expression = decorator.expression; + let name: DeclarationName; + switch (expression.kind) { + case SyntaxKind.Identifier: + // We could have greedily parsed a property name as an identifier, so + // we extract it from the decorator for a better editor experience: + // @ + // id() {} + // + var end = Math.min(getTokenPosOfNode(decorator.atToken, sourceFile) + 1, decorator.atToken.end); + if (lineBreakBetween(sourceFile, end, getTokenPosOfNode(expression, sourceFile))) { + decorator.expression = createMissingNodeAtPosition(end, SyntaxKind.Identifier, Diagnostics.Expression_expected); + decorator.end = decorator.atToken.end; + return expression; + } + + break; + + case SyntaxKind.ArrayLiteralExpression: + // We could have greedily parsed a computed property name as an array literal expression, so + // we extract it from the decorator for a better editor experience: + // @ + // ["computed"]() {} + // + var end = Math.min(getTokenPosOfNode(decorator.atToken, sourceFile) + 1, decorator.atToken.end); + if (lineBreakBetween(sourceFile, end, getTokenPosOfNode(expression, sourceFile))) { + let arrayExpr = expression; + decorator.expression = createMissingNodeAtPosition(end, SyntaxKind.Identifier, Diagnostics.Expression_expected); + decorator.end = decorator.atToken.end; + + var computedPropertyName = createNode(SyntaxKind.ComputedPropertyName, arrayExpr.pos); + if (arrayExpr.elements.length === 0) { + end = Math.min(getTokenPosOfNode(arrayExpr.openBracketToken, sourceFile) + 1, arrayExpr.openBracketToken.end); + computedPropertyName.expression = createMissingNodeAtPosition(end, SyntaxKind.Identifier, Diagnostics.Expression_expected); + } + else { + let i = arrayExpr.elements.length - 1; + let expr = arrayExpr.elements[i--]; + while (i >= 0) { + var element = arrayExpr.elements[i--]; + var commaExpr = createNode(SyntaxKind.BinaryExpression, element.pos); + commaExpr.operatorToken = finishNode(createNode(SyntaxKind.CommaToken, 0), 0); + commaExpr.left = element; + commaExpr.right = expr; + expr = finishNode(commaExpr, expr.end); + } + computedPropertyName.expression = expr; + } + + return finishNode(computedPropertyName, arrayExpr.end); + } + + break; + + case SyntaxKind.PropertyAccessExpression: + // We could have greedily parsed a property name as a property access, so we extract it from the decorator + // for a better editor experience. + // @expr. + // id() {} + // + let propExpr = expression; + var end = Math.min(getTokenPosOfNode(propExpr.dotToken, sourceFile) + 1, propExpr.dotToken.end); + if (lineBreakBetween(sourceFile, end, getTokenPosOfNode(propExpr.name, sourceFile))) { + name = propExpr.name; + propExpr.name = createMissingNodeAtPosition(end, SyntaxKind.Identifier, Diagnostics.Identifier_expected); + propExpr.end = propExpr.dotToken.end; + decorator.end = propExpr.dotToken.end; + return name; + } + break; + + case SyntaxKind.ElementAccessExpression: + // We could have greedily parsed a computed property name as an element access, so we extract it from the decorator. + // @expr + // ["expr"]() + // + let elementExpr = expression; + decorator.expression = elementExpr.expression; + decorator.end = elementExpr.expression.end; + + var computedPropertyName = createNode(SyntaxKind.ComputedPropertyName, getTokenPosOfNode(elementExpr.argumentExpression, sourceFile)); + computedPropertyName.expression = elementExpr.argumentExpression; + return finishNode(computedPropertyName, elementExpr.end); + } + + return createMissingNodeAtPosition(expression.end, SyntaxKind.Identifier, Diagnostics.Identifier_expected); + } + + function reparseTypeArgumentsAsTypeParameters(typeArguments: NodeArray): NodeArray { + let typeParameters = >[]; + typeParameters.pos = typeArguments.pos; + typeParameters.end = typeArguments.end; + for (let i = 0; i < typeArguments.length; i++) { + let typeArgument = typeArguments[i]; + let typeParameter = createNode(SyntaxKind.TypeParameter, typeArgument.pos); + Debug.assert(typeArgument.kind === SyntaxKind.TypeReference); + let typeReference = typeArgument; + Debug.assert(typeReference.typeName.kind === SyntaxKind.Identifier); + typeParameter.name = typeReference.typeName; + finishNode(typeParameter, typeArgument.end); + typeParameters.push(typeParameter); + } + return typeParameters; + } + + function reparseArgumentsAsParameters(argumentList: NodeArray): NodeArray { + let parameters = >[]; + parameters.pos = argumentList.pos; + parameters.end = argumentList.end; + for (let i = 0; i < argumentList.length; i++) { + let argument = argumentList[i]; + + // TODO: Object literal as object binding + // TODO: Array literal as array binding + let name: Identifier; + let initializer: Expression; + if (argument.kind === SyntaxKind.Identifier) { + name = argument; + } + else if (argument.kind === SyntaxKind.BinaryExpression) { + let binaryExpression = argument; + Debug.assert(binaryExpression.operatorToken.kind === SyntaxKind.EqualsToken); + if (binaryExpression.left.kind === SyntaxKind.Identifier) { + name = binaryExpression.left; + initializer = binaryExpression.right; + } + else { + Debug.fail("Invalid attempt to reclassify expression."); + } + } + else { + Debug.fail("Invalid attempt to reclassify expression."); + } + + let parameter = createNode(SyntaxKind.Parameter, argument.pos); + parameter.name = name; + parameter.initializer = initializer; + finishNode(parameter, argument.end); + parameters.push(parameter); + } + return parameters; + } + + function reparseCallExpressionAsSignature(node: CallExpression, signature: SignatureDeclaration): void { + if (node.typeArguments) { + signature.typeParameters = reparseTypeArgumentsAsTypeParameters(node.typeArguments); + } + signature.parameters = reparseArgumentsAsParameters(node.arguments); + signature.type = parseTypeAnnotation(); + } + + function reparseClassElement(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): ClassElement { + // We may have parsed a decorator that greedily included part of the member as its expression. + let lastDecorator = decorators[decorators.length - 1]; + + // TODO(rbuckton): pull out the call expression or declaration name from the consise body of an arrow function + + // If we parsed a call expression, extract the call expression to reparse as a signature + let callExpression = extractCallExpressionFromDecoratorTail(lastDecorator); + + // Extract the declaration name from the decorator + let name = extractDeclarationNameFromDecoratorTail(lastDecorator); + let questionToken = parseOptionalToken(SyntaxKind.QuestionToken); + decorators.end = lastDecorator.end; + + if (callExpression) { + // Reparse as method + let method = createNode(SyntaxKind.MethodDeclaration, fullStart); + method.decorators = decorators; + setModifiers(method, modifiers); + method.name = name; + method.questionToken = questionToken; + reparseCallExpressionAsSignature(callExpression, method); + method.body = parseFunctionBlockOrSemicolon(/*isGenerator*/ false); + return finishNode(method); + } + else { + if (token === SyntaxKind.OpenParenToken || token === SyntaxKind.LessThanToken) { + return parseMethodDeclaration(fullStart, decorators, modifiers, /*asteriskToken*/ undefined, name, questionToken, Diagnostics.or_expected); + } + + // Reparse as property declaration with a missing name. + let property = createNode(SyntaxKind.PropertyDeclaration, fullStart); + property.decorators = decorators; + setModifiers(property, modifiers); + property.name = name; + property.type = parseTypeAnnotation(); + property.initializer = allowInAnd(parseNonParameterInitializer); + parseSemicolon(); + return finishNode(property); + } + } + function parseClassElement(): ClassElement { let fullStart = getNodePos(); + let decorators = parseDecorators(); let modifiers = parseModifiers(); - let accessor = tryParseAccessorDeclaration(fullStart, modifiers); + let accessor = tryParseAccessorDeclaration(fullStart, decorators, modifiers); if (accessor) { return accessor; } if (token === SyntaxKind.ConstructorKeyword) { - return parseConstructorDeclaration(fullStart, modifiers); + return parseConstructorDeclaration(fullStart, decorators, modifiers); } if (isIndexSignature()) { - return parseIndexSignatureDeclaration(modifiers); + return parseIndexSignatureDeclaration(fullStart, decorators, modifiers); } // It is very important that we check this *after* checking indexers because @@ -4519,14 +4896,18 @@ module ts { token === SyntaxKind.AsteriskToken || token === SyntaxKind.OpenBracketToken) { - return parsePropertyOrMethodDeclaration(fullStart, modifiers); + return parsePropertyOrMethodDeclaration(fullStart, decorators, modifiers); + } + + if (decorators) { + return reparseClassElement(fullStart, decorators, modifiers); } // 'isClassMemberStart' should have hinted not to attempt parsing. Debug.fail("Should not have attempted to parse class member declaration."); } - function parseClassDeclaration(fullStart: number, modifiers: ModifiersArray): ClassDeclaration { + function parseClassDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): ClassDeclaration { // In ES6 specification, All parts of a ClassDeclaration or a ClassExpression are strict mode code let savedStrictModeContext = inStrictModeContext(); if (languageVersion >= ScriptTarget.ES6) { @@ -4534,6 +4915,7 @@ module ts { } var node = createNode(SyntaxKind.ClassDeclaration, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); parseExpected(SyntaxKind.ClassKeyword); node.name = node.flags & NodeFlags.Default ? parseOptionalIdentifier() : parseIdentifier(); @@ -4597,8 +4979,9 @@ module ts { return parseList(ParsingContext.ClassMembers, /*checkForStrictMode*/ false, parseClassElement); } - function parseInterfaceDeclaration(fullStart: number, modifiers: ModifiersArray): InterfaceDeclaration { + function parseInterfaceDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): InterfaceDeclaration { let node = createNode(SyntaxKind.InterfaceDeclaration, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); parseExpected(SyntaxKind.InterfaceKeyword); node.name = parseIdentifier(); @@ -4608,8 +4991,9 @@ module ts { return finishNode(node); } - function parseTypeAliasDeclaration(fullStart: number, modifiers: ModifiersArray): TypeAliasDeclaration { + function parseTypeAliasDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): TypeAliasDeclaration { let node = createNode(SyntaxKind.TypeAliasDeclaration, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); parseExpected(SyntaxKind.TypeKeyword); node.name = parseIdentifier(); @@ -4630,8 +5014,9 @@ module ts { return finishNode(node); } - function parseEnumDeclaration(fullStart: number, modifiers: ModifiersArray): EnumDeclaration { + function parseEnumDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): EnumDeclaration { let node = createNode(SyntaxKind.EnumDeclaration, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); parseExpected(SyntaxKind.EnumKeyword); node.name = parseIdentifier(); @@ -4657,30 +5042,32 @@ module ts { return finishNode(node); } - function parseInternalModuleTail(fullStart: number, modifiers: ModifiersArray, flags: NodeFlags): ModuleDeclaration { + function parseInternalModuleTail(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray, flags: NodeFlags): ModuleDeclaration { let node = createNode(SyntaxKind.ModuleDeclaration, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); node.flags |= flags; node.name = parseIdentifier(); node.body = parseOptional(SyntaxKind.DotToken) - ? parseInternalModuleTail(getNodePos(), /*modifiers:*/undefined, NodeFlags.Export) + ? parseInternalModuleTail(getNodePos(), /*decorators*/ undefined, /*modifiers:*/undefined, NodeFlags.Export) : parseModuleBlock(); return finishNode(node); } - function parseAmbientExternalModuleDeclaration(fullStart: number, modifiers: ModifiersArray): ModuleDeclaration { + function parseAmbientExternalModuleDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): ModuleDeclaration { let node = createNode(SyntaxKind.ModuleDeclaration, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); node.name = parseLiteralNode(/*internName:*/ true); node.body = parseModuleBlock(); return finishNode(node); } - function parseModuleDeclaration(fullStart: number, modifiers: ModifiersArray): ModuleDeclaration { + function parseModuleDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): ModuleDeclaration { parseExpected(SyntaxKind.ModuleKeyword); return token === SyntaxKind.StringLiteral - ? parseAmbientExternalModuleDeclaration(fullStart, modifiers) - : parseInternalModuleTail(fullStart, modifiers, modifiers ? modifiers.flags : 0); + ? parseAmbientExternalModuleDeclaration(fullStart, decorators, modifiers) + : parseInternalModuleTail(fullStart, decorators, modifiers, modifiers ? modifiers.flags : 0); } function isExternalModuleReference() { @@ -4698,7 +5085,7 @@ module ts { token === SyntaxKind.FromKeyword; } - function parseImportDeclarationOrImportEqualsDeclaration(fullStart: number, modifiers: ModifiersArray): ImportEqualsDeclaration | ImportDeclaration { + function parseImportDeclarationOrImportEqualsDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): ImportEqualsDeclaration | ImportDeclaration { parseExpected(SyntaxKind.ImportKeyword); let afterImportPos = scanner.getStartPos(); @@ -4710,6 +5097,7 @@ module ts { // import x = require("mod"); or // import x = M.x; let importEqualsDeclaration = createNode(SyntaxKind.ImportEqualsDeclaration, fullStart); + importEqualsDeclaration.decorators = decorators; setModifiers(importEqualsDeclaration, modifiers); importEqualsDeclaration.name = identifier; parseExpected(SyntaxKind.EqualsToken); @@ -4721,6 +5109,7 @@ module ts { // Import statement let importDeclaration = createNode(SyntaxKind.ImportDeclaration, fullStart); + importDeclaration.decorators = decorators; setModifiers(importDeclaration, modifiers); // ImportDeclaration: @@ -4855,8 +5244,9 @@ module ts { return finishNode(node); } - function parseExportDeclaration(fullStart: number, modifiers: ModifiersArray): ExportDeclaration { + function parseExportDeclaration(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): ExportDeclaration { let node = createNode(SyntaxKind.ExportDeclaration, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); if (parseOptional(SyntaxKind.AsteriskToken)) { parseExpected(SyntaxKind.FromKeyword); @@ -4872,8 +5262,9 @@ module ts { return finishNode(node); } - function parseExportAssignment(fullStart: number, modifiers: ModifiersArray): ExportAssignment { + function parseExportAssignment(fullStart: number, decorators: NodeArray, modifiers: ModifiersArray): ExportAssignment { let node = createNode(SyntaxKind.ExportAssignment, fullStart); + node.decorators = decorators; setModifiers(node, modifiers); if (parseOptional(SyntaxKind.EqualsToken)) { node.isExportEquals = true; @@ -4898,7 +5289,7 @@ module ts { return inStrictModeContext() || lookAhead(nextTokenIsIdentifierOrStartOfDestructuringOnTheSameLine); } - function isDeclarationStart(): boolean { + function isDeclarationStart(followsModifier?: boolean): boolean { switch (token) { case SyntaxKind.VarKeyword: case SyntaxKind.ConstKeyword: @@ -4928,6 +5319,10 @@ module ts { case SyntaxKind.StaticKeyword: // Check for modifier on source element return lookAhead(nextTokenIsDeclarationStart); + case SyntaxKind.AtToken: + // a lookahead here is too costly, and decorators are only valid on a declaration. + // We will assume we are parsing a declaration here and report an error later + return !followsModifier; } } @@ -4954,12 +5349,12 @@ module ts { function nextTokenCanFollowExportKeyword() { nextToken(); return token === SyntaxKind.EqualsToken || token === SyntaxKind.AsteriskToken || - token === SyntaxKind.OpenBraceToken || token === SyntaxKind.DefaultKeyword || isDeclarationStart(); + token === SyntaxKind.OpenBraceToken || token === SyntaxKind.DefaultKeyword || isDeclarationStart(/*followsModifier*/ true); } function nextTokenIsDeclarationStart() { nextToken(); - return isDeclarationStart(); + return isDeclarationStart(/*followsModifier*/ true); } function nextTokenIsAsKeyword() { @@ -4968,14 +5363,15 @@ module ts { function parseDeclaration(): ModuleElement { let fullStart = getNodePos(); + let decorators = parseDecorators(); let modifiers = parseModifiers(); if (token === SyntaxKind.ExportKeyword) { nextToken(); if (token === SyntaxKind.DefaultKeyword || token === SyntaxKind.EqualsToken) { - return parseExportAssignment(fullStart, modifiers); + return parseExportAssignment(fullStart, decorators, modifiers); } if (token === SyntaxKind.AsteriskToken || token === SyntaxKind.OpenBraceToken) { - return parseExportDeclaration(fullStart, modifiers); + return parseExportDeclaration(fullStart, decorators, modifiers); } } @@ -4983,22 +5379,30 @@ module ts { case SyntaxKind.VarKeyword: case SyntaxKind.LetKeyword: case SyntaxKind.ConstKeyword: - return parseVariableStatement(fullStart, modifiers); + return parseVariableStatement(fullStart, decorators, modifiers); case SyntaxKind.FunctionKeyword: - return parseFunctionDeclaration(fullStart, modifiers); + return parseFunctionDeclaration(fullStart, decorators, modifiers); case SyntaxKind.ClassKeyword: - return parseClassDeclaration(fullStart, modifiers); + return parseClassDeclaration(fullStart, decorators, modifiers); case SyntaxKind.InterfaceKeyword: - return parseInterfaceDeclaration(fullStart, modifiers); + return parseInterfaceDeclaration(fullStart, decorators, modifiers); case SyntaxKind.TypeKeyword: - return parseTypeAliasDeclaration(fullStart, modifiers); + return parseTypeAliasDeclaration(fullStart, decorators, modifiers); case SyntaxKind.EnumKeyword: - return parseEnumDeclaration(fullStart, modifiers); + return parseEnumDeclaration(fullStart, decorators, modifiers); case SyntaxKind.ModuleKeyword: - return parseModuleDeclaration(fullStart, modifiers); + return parseModuleDeclaration(fullStart, decorators, modifiers); case SyntaxKind.ImportKeyword: - return parseImportDeclarationOrImportEqualsDeclaration(fullStart, modifiers); + return parseImportDeclarationOrImportEqualsDeclaration(fullStart, decorators, modifiers); default: + if (decorators) { + // We reached this point because we encountered an AtToken and assumed a declaration would + // follow. For recovery and error reporting purposes, return an incomplete declaration. + let node = createNode(SyntaxKind.IncompleteDeclaration, fullStart); + node.decorators = decorators; + setModifiers(node, modifiers); + return finishNode(node); + } Debug.fail("Mismatch between isDeclarationStart and parseDeclaration"); } } From 39001f53959cb68e25273d88df844dd5fb185eb5 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 17 Mar 2015 11:28:19 -0700 Subject: [PATCH 137/224] Checker updates for decorators --- src/compiler/checker.ts | 178 ++++++++++++++++++++++++++++++++++++---- src/compiler/types.ts | 19 +++-- src/lib/core.d.ts | 15 ++++ 3 files changed, 187 insertions(+), 25 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 423c3c316275a..a5565a1063278 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -100,11 +100,18 @@ module ts { let globalIterableType: ObjectType; let anyArrayType: Type; + let globalTypedPropertyDescriptorType: ObjectType; + let globalClassDecoratorType: ObjectType; + let globalClassAnnotationType: ObjectType; + let globalParameterAnnotationType: ObjectType; + let globalPropertyAnnotationType: ObjectType; + let globalPropertyDecoratorType: ObjectType; let tupleTypes: Map = {}; let unionTypes: Map = {}; let stringLiteralTypes: Map = {}; let emitExtends = false; + let emitDecorate = false; let mergedSymbols: Symbol[] = []; let symbolLinks: SymbolLinks[] = []; @@ -311,6 +318,7 @@ module ts { let lastLocation: Node; let propertyWithInvalidInitializer: Node; let errorLocation = location; + let grandparent: Node; loop: while (location) { // Locals of a source file are not in scope (because they get merged into the global symbol table) @@ -376,7 +384,7 @@ module ts { // } // case SyntaxKind.ComputedPropertyName: - let grandparent = location.parent.parent; + grandparent = location.parent.parent; if (grandparent.kind === SyntaxKind.ClassDeclaration || grandparent.kind === SyntaxKind.InterfaceDeclaration) { // A reference to this grandparent's type parameters would be an error if (result = getSymbol(getSymbolOfNode(grandparent).members, name, meaning & SymbolFlags.Type)) { @@ -408,6 +416,26 @@ module ts { break loop; } break; + case SyntaxKind.Decorator: + if (location.parent) { + lastLocation = location; + grandparent = location.parent.parent; + if (location.parent.kind === SyntaxKind.Parameter) { + // Parameter decorators are resolved in the context of their great-grandparent + if (grandparent) { + location = grandparent.parent; + } + else { + break loop; + } + } + else { + // all other decorators are resolved in the context of their grandparent + location = grandparent; + } + continue; + } + break; } lastLocation = location; location = location.parent; @@ -7852,7 +7880,7 @@ module ts { // strict mode FunctionLikeDeclaration or FunctionExpression(13.1) // Grammar checking - checkGrammarModifiers(node) || checkGrammarEvalOrArgumentsInStrictMode(node, node.name); + checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarEvalOrArgumentsInStrictMode(node, node.name); checkVariableLikeDeclaration(node); let func = getContainingFunction(node); @@ -7954,7 +7982,7 @@ module ts { function checkPropertyDeclaration(node: PropertyDeclaration) { // Grammar checking - checkGrammarModifiers(node) || checkGrammarProperty(node) || checkGrammarComputedPropertyName(node.name); + checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarProperty(node) || checkGrammarComputedPropertyName(node.name); checkVariableLikeDeclaration(node); } @@ -8093,6 +8121,10 @@ module ts { checkFunctionLikeDeclaration(node); } + function checkIncompleteDeclaration(node: Declaration) { + error(node, Diagnostics.Declaration_expected); + } + function checkTypeReference(node: TypeReferenceNode) { // Grammar checking checkGrammarTypeArguments(node, node.typeArguments); @@ -8484,6 +8516,70 @@ module ts { } } + function checkDecoratorSignature(node: Decorator, exprType: Type, expectedAnnotationType: Type, parentType?: Type, expectedDecoratorType?: Type, message?: DiagnosticMessage) { + if (checkTypeAssignableTo(exprType, expectedAnnotationType, node) && expectedDecoratorType) { + let signature = getSingleCallSignature(expectedDecoratorType); + if (!signature) { + // if we couldn't get the signature of the decorator function type, it is likely because we are using an out-of-date lib.d.ts + // and we have already reported an error in initializeTypeChecker. + return; + } + + let instantiatedSignature = getSignatureInstantiation(signature, [parentType]); + let instantiatedSignatureType = getOrCreateTypeFromSignature(instantiatedSignature); + checkTypeAssignableTo(exprType, instantiatedSignatureType, node, message); + } + } + + /** Check a decorator */ + function checkDecorator(node: Decorator): void { + let expression: Expression = node.expression; + let exprType = checkExpression(expression); + + switch (node.parent.kind) { + case SyntaxKind.ClassDeclaration: + let classSymbol = getSymbolOfNode(node.parent); + let classType = getTypeOfSymbol(classSymbol); + checkDecoratorSignature(node, exprType, globalClassAnnotationType, classType, globalClassDecoratorType, Diagnostics.Decorators_may_not_change_the_type_of_a_class); + break; + + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + let propertyType = getTypeOfNode(node.parent); + checkDecoratorSignature(node, exprType, globalPropertyAnnotationType, propertyType, globalPropertyDecoratorType, Diagnostics.Decorators_may_not_change_the_type_of_a_member); + break; + + case SyntaxKind.Parameter: + checkDecoratorSignature(node, exprType, globalParameterAnnotationType); + break; + } + } + + /** Check the decorators of a node */ + function checkDecorators(node: Node): void { + if (!node.decorators) { + return; + } + + switch (node.kind) { + case SyntaxKind.ClassDeclaration: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.Parameter: + emitDecorate = true; + break; + + default: + return; + } + + forEach(node.decorators, checkDecorator); + } + function checkFunctionDeclaration(node: FunctionDeclaration): void { if (produceDiagnostics) { checkFunctionLikeDeclaration(node) || @@ -8498,6 +8594,7 @@ module ts { } function checkFunctionLikeDeclaration(node: FunctionLikeDeclaration): void { + checkDecorators(node); checkSignatureDeclaration(node); // Do not use hasDynamicName here, because that returns false for well known symbols. @@ -8780,6 +8877,7 @@ module ts { // Check variable, parameter, or property declaration function checkVariableLikeDeclaration(node: VariableLikeDeclaration) { + checkDecorators(node); checkSourceElement(node.type); // For a computed property, just check the initializer and exit // Do not use hasDynamicName here, because that returns false for well known symbols. @@ -8852,7 +8950,7 @@ module ts { function checkVariableStatement(node: VariableStatement) { // Grammar checking - checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) || checkGrammarModifiers(node) || checkGrammarVariableDeclarationList(node.declarationList) || checkGrammarForDisallowedLetOrConstStatement(node); + checkGrammarDecorators(node) || checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) || checkGrammarModifiers(node) || checkGrammarVariableDeclarationList(node.declarationList) || checkGrammarForDisallowedLetOrConstStatement(node); forEach(node.declarationList.declarations, checkSourceElement); } @@ -9483,7 +9581,7 @@ module ts { function checkClassDeclaration(node: ClassDeclaration) { // Grammar checking checkGrammarClassDeclarationHeritageClauses(node); - + checkDecorators(node); if (node.name) { checkTypeNameIsReserved(node.name, Diagnostics.Class_name_cannot_be_0); checkCollisionWithCapturedThisVariable(node, node.name); @@ -9688,7 +9786,7 @@ module ts { function checkInterfaceDeclaration(node: InterfaceDeclaration) { // Grammar checking - checkGrammarModifiers(node) || checkGrammarInterfaceDeclaration(node); + checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarInterfaceDeclaration(node); checkTypeParameters(node.typeParameters); if (produceDiagnostics) { @@ -9725,7 +9823,7 @@ module ts { function checkTypeAliasDeclaration(node: TypeAliasDeclaration) { // Grammar checking - checkGrammarModifiers(node); + checkGrammarDecorators(node) || checkGrammarModifiers(node); checkTypeNameIsReserved(node.name, Diagnostics.Type_alias_name_cannot_be_0); checkSourceElement(node.type); @@ -9894,7 +9992,7 @@ module ts { } // Grammar checking - checkGrammarModifiers(node) || checkGrammarEnumDeclaration(node); + checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarEnumDeclaration(node); checkTypeNameIsReserved(node.name, Diagnostics.Enum_name_cannot_be_0); checkCollisionWithCapturedThisVariable(node, node.name); @@ -9960,7 +10058,7 @@ module ts { function checkModuleDeclaration(node: ModuleDeclaration) { if (produceDiagnostics) { // Grammar checking - if (!checkGrammarModifiers(node)) { + if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node)) { if (!isInAmbientContext(node) && node.name.kind === SyntaxKind.StringLiteral) { grammarErrorOnNode(node.name, Diagnostics.Only_ambient_modules_can_use_quoted_names); } @@ -10055,7 +10153,7 @@ module ts { } function checkImportDeclaration(node: ImportDeclaration) { - if (!checkGrammarModifiers(node) && (node.flags & NodeFlags.Modifier)) { + if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & NodeFlags.Modifier)) { grammarErrorOnFirstToken(node, Diagnostics.An_import_declaration_cannot_have_modifiers); } if (checkExternalImportOrExportDeclaration(node)) { @@ -10077,7 +10175,7 @@ module ts { } function checkImportEqualsDeclaration(node: ImportEqualsDeclaration) { - checkGrammarModifiers(node); + checkGrammarDecorators(node) || checkGrammarModifiers(node); if (isInternalModuleImportEqualsDeclaration(node) || checkExternalImportOrExportDeclaration(node)) { checkImportBinding(node); if (node.flags & NodeFlags.Export) { @@ -10108,7 +10206,7 @@ module ts { } function checkExportDeclaration(node: ExportDeclaration) { - if (!checkGrammarModifiers(node) && (node.flags & NodeFlags.Modifier)) { + if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & NodeFlags.Modifier)) { grammarErrorOnFirstToken(node, Diagnostics.An_export_declaration_cannot_have_modifiers); } if (!node.moduleSpecifier || checkExternalImportOrExportDeclaration(node)) { @@ -10132,7 +10230,7 @@ module ts { return; } // Grammar checking - if (!checkGrammarModifiers(node) && (node.flags & NodeFlags.Modifier)) { + if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & NodeFlags.Modifier)) { grammarErrorOnFirstToken(node, Diagnostics.An_export_assignment_cannot_have_modifiers); } if (node.expression) { @@ -10232,6 +10330,8 @@ module ts { case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: return checkAccessorDeclaration(node); + case SyntaxKind.IncompleteDeclaration: + return checkIncompleteDeclaration(node); case SyntaxKind.TypeReference: return checkTypeReference(node); case SyntaxKind.TypeQuery: @@ -10436,6 +10536,10 @@ module ts { links.flags |= NodeCheckFlags.EmitExtends; } + if (emitDecorate) { + links.flags |= NodeCheckFlags.EmitDecorate; + } + links.flags |= NodeCheckFlags.TypeChecked; } } @@ -11235,6 +11339,12 @@ module ts { globalNumberType = getGlobalType("Number"); globalBooleanType = getGlobalType("Boolean"); globalRegExpType = getGlobalType("RegExp"); + globalTypedPropertyDescriptorType = getTypeOfGlobalSymbol(getGlobalTypeSymbol("TypedPropertyDescriptor"), 1); + globalClassDecoratorType = getGlobalType("ClassDecorator"); + globalPropertyDecoratorType = getGlobalType("PropertyDecorator"); + globalClassAnnotationType = getGlobalType("ClassAnnotation"); + globalPropertyAnnotationType = getGlobalType("PropertyAnnotation"); + globalParameterAnnotationType = getGlobalType("ParameterAnnotation"); // If we're in ES6 mode, load the TemplateStringsArray. // Otherwise, default to 'unknown' for the purposes of type checking in LS scenarios. @@ -11259,6 +11369,42 @@ module ts { // GRAMMAR CHECKING + function checkGrammarDecorators(node: Node): boolean { + if (!node.decorators) { + return false; + } + + let target = node; + while (target) { + switch (target.kind) { + case SyntaxKind.ClassDeclaration: + return false; + + case SyntaxKind.Constructor: + if (node.kind !== SyntaxKind.Parameter) { + break; + } + + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.Parameter: + target = target.parent; + continue; + + + case SyntaxKind.MethodDeclaration: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + if ((target).body) { + target = target.parent; + continue; + } + break; + } + break; + } + return grammarErrorOnNode(node, Diagnostics.Decorators_are_not_valid_on_this_declaration_type); + } + function checkGrammarModifiers(node: Node): boolean { switch (node.kind) { case SyntaxKind.GetAccessor: @@ -11455,7 +11601,7 @@ module ts { function checkGrammarFunctionLikeDeclaration(node: FunctionLikeDeclaration): boolean { // Prevent cascading error by short-circuit let file = getSourceFileOfNode(node); - return checkGrammarModifiers(node) || checkGrammarTypeParameterList(node, node.typeParameters, file) || + return checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarTypeParameterList(node, node.typeParameters, file) || checkGrammarParameterList(node.parameters) || checkGrammarArrowFunction(node, file); } @@ -11512,7 +11658,7 @@ module ts { function checkGrammarIndexSignature(node: SignatureDeclaration) { // Prevent cascading error by short-circuit - checkGrammarModifiers(node) || checkGrammarIndexSignatureParameters(node) || checkGrammarForIndexSignatureModifier(node); + return checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarIndexSignatureParameters(node) || checkGrammarForIndexSignatureModifier(node); } function checkGrammarForAtLeastOneTypeArgument(node: Node, typeArguments: NodeArray): boolean { @@ -11561,7 +11707,7 @@ module ts { let seenExtendsClause = false; let seenImplementsClause = false; - if (!checkGrammarModifiers(node) && node.heritageClauses) { + if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && node.heritageClauses) { for (let heritageClause of node.heritageClauses) { if (heritageClause.token === SyntaxKind.ExtendsKeyword) { if (seenExtendsClause) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index bdf824504c529..02ca6627b2e0b 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1346,17 +1346,18 @@ module ts { } export const enum NodeCheckFlags { - TypeChecked = 0x00000001, // Node has been type checked - LexicalThis = 0x00000002, // Lexical 'this' reference - CaptureThis = 0x00000004, // Lexical 'this' used in body - EmitExtends = 0x00000008, // Emit __extends - SuperInstance = 0x00000010, // Instance 'super' reference - SuperStatic = 0x00000020, // Static 'super' reference - ContextChecked = 0x00000040, // Contextual types have been assigned + TypeChecked = 0x00000001, // Node has been type checked + LexicalThis = 0x00000002, // Lexical 'this' reference + CaptureThis = 0x00000004, // Lexical 'this' used in body + EmitExtends = 0x00000008, // Emit __extends + SuperInstance = 0x00000010, // Instance 'super' reference + SuperStatic = 0x00000020, // Static 'super' reference + ContextChecked = 0x00000040, // Contextual types have been assigned // Values for enum members have been computed, and any errors have been reported for them. - EnumValuesComputed = 0x00000080, - BlockScopedBindingInLoop = 0x00000100, + EnumValuesComputed = 0x00000080, + BlockScopedBindingInLoop = 0x00000100, + EmitDecorate = 0x00000200, // Emit __decorate } export interface NodeLinks { diff --git a/src/lib/core.d.ts b/src/lib/core.d.ts index 040eb69ae9613..930f5781c918a 100644 --- a/src/lib/core.d.ts +++ b/src/lib/core.d.ts @@ -1155,3 +1155,18 @@ interface ArrayConstructor { } declare var Array: ArrayConstructor; + +interface TypedPropertyDescriptor { + enumerable?: boolean; + configurable?: boolean; + writable?: boolean; + value?: T; + get?: () => T; + set?: (value: T) => void; +} + +interface ClassDecorator { (target: TFunction): TFunction | void; } +interface PropertyDecorator { (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor | void; } +interface ClassAnnotation { (target: Function): void; } +interface PropertyAnnotation { (target: Object, propertyKey: string | symbol, descriptor: PropertyDescriptor): void; } +interface ParameterAnnotation { (target: Function, parameterIndex: number): void; } From bd4d7fc9eedfb905313b173e284eddf95350e7dc Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 17 Mar 2015 13:41:29 -0700 Subject: [PATCH 138/224] Emit for decorators, updated to ES6 classes. --- src/compiler/checker.ts | 24 +++ src/compiler/emitter.ts | 368 +++++++++++++++++++++++++++++++++++--- src/compiler/types.ts | 1 + src/compiler/utilities.ts | 72 ++++++++ 4 files changed, 438 insertions(+), 27 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index a5565a1063278..51f97727ca49d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11267,6 +11267,29 @@ module ts { !hasProperty(getGeneratedNamesForSourceFile(getSourceFile(location)), name); } + function getClassDeclarationVariableId(n: Identifier): number { + Debug.assert(!nodeIsSynthesized(n)); + + let isClassDeclaration = n.parent.kind === SyntaxKind.ClassDeclaration; + + let symbol = + (isClassDeclaration ? getSymbolOfNode(n.parent) : undefined) || + getNodeLinks(n).resolvedSymbol || + resolveName(n, n.text, SymbolFlags.Value | SymbolFlags.Alias, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined); + + symbol = getExportSymbolOfValueSymbolIfExported(symbol); + + let isClass = symbol && (symbol.flags & SymbolFlags.Class) !== 0; + + if (isClass) { + // side-effect of calling this method: + // assign id to symbol if it was not yet set + getSymbolLinks(symbol); + return symbol.id; + } + return undefined; + } + function getBlockScopedVariableId(n: Identifier): number { Debug.assert(!nodeIsSynthesized(n)); @@ -11309,6 +11332,7 @@ module ts { getConstantValue, isUnknownIdentifier, getBlockScopedVariableId, + getClassDeclarationVariableId, }; } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 205f2fe2945ef..e6354a961286a 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -277,20 +277,14 @@ module ts { } } - function getFirstConstructorWithBody(node: ClassDeclaration): ConstructorDeclaration { - return forEach(node.members, member => { - if (member.kind === SyntaxKind.Constructor && nodeIsPresent((member).body)) { - return member; - } - }); - } - function getAllAccessorDeclarations(declarations: NodeArray, accessor: AccessorDeclaration) { let firstAccessor: AccessorDeclaration; + let lastAccessor: AccessorDeclaration; let getAccessor: AccessorDeclaration; let setAccessor: AccessorDeclaration; if (hasDynamicName(accessor)) { firstAccessor = accessor; + lastAccessor = accessor; if (accessor.kind === SyntaxKind.GetAccessor) { getAccessor = accessor; } @@ -312,6 +306,7 @@ module ts { firstAccessor = member; } + lastAccessor = member; if (member.kind === SyntaxKind.GetAccessor && !getAccessor) { getAccessor = member; } @@ -325,6 +320,7 @@ module ts { } return { firstAccessor, + lastAccessor, getAccessor, setAccessor }; @@ -1582,8 +1578,12 @@ module ts { let currentScopeNames: Map; let generatedBlockScopeNames: string[]; + let generatedClassNames: string[]; + let generatedComputedPropertyNames: string[]; + let generatedSetterNames: string[]; let extendsEmitted = false; + let decorateEmitted = false; let tempCount = 0; let tempVariables: Identifier[]; let tempParameters: Identifier[]; @@ -2565,6 +2565,25 @@ module ts { emitLiteral(node); } else if (node.kind === SyntaxKind.ComputedPropertyName) { + if (nodeIsDecorated(node.parent)) { + if (!generatedComputedPropertyNames) { + generatedComputedPropertyNames = []; + } + + let generatedName = generatedComputedPropertyNames[node.id]; + if (generatedName) { + write(generatedName); + return; + } + + let generatedVariable = createTempVariable(node); + generatedName = generatedVariable.text; + recordTempDeclaration(generatedVariable); + generatedComputedPropertyNames[node.id] = generatedName; + write(generatedName); + write(" = "); + } + emit((node).expression); } else { @@ -2623,26 +2642,29 @@ module ts { } } - function getGeneratedNameForIdentifier(node: Identifier): string { - if (nodeIsSynthesized(node) || !generatedBlockScopeNames) { - return undefined; - } - - var variableId = resolver.getBlockScopedVariableId(node) - if (variableId === undefined) { - return undefined; + function getGeneratedNameForIdentifier(node: Identifier, allowGeneratedIdentifiers: boolean): string { + if (!nodeIsSynthesized(node)) { + if (allowGeneratedIdentifiers && generatedBlockScopeNames) { + var variableId = resolver.getBlockScopedVariableId(node) + if (variableId !== undefined) { + return generatedBlockScopeNames[variableId]; + } + } + if (languageVersion >= ScriptTarget.ES6 && generatedClassNames) { + var variableId = resolver.getClassDeclarationVariableId(node); + if (variableId !== undefined) { + return generatedClassNames[variableId]; + } + } } - - return generatedBlockScopeNames[variableId]; + return undefined; } function emitIdentifier(node: Identifier, allowGeneratedIdentifiers: boolean) { - if (allowGeneratedIdentifiers) { - let generatedName = getGeneratedNameForIdentifier(node); - if (generatedName) { - write(generatedName); - return; - } + let generatedName = getGeneratedNameForIdentifier(node, allowGeneratedIdentifiers); + if (generatedName) { + write(generatedName); + return; } if (!node.parent) { write(node.text); @@ -3034,7 +3056,7 @@ module ts { function emitComputedPropertyName(node: ComputedPropertyName) { write("["); - emit(node.expression); + emitExpressionForPropertyName(node); write("]"); } @@ -3065,7 +3087,7 @@ module ts { if (languageVersion < ScriptTarget.ES6) { // Emit identifier as an identifier write(": "); - var generatedName = getGeneratedNameForIdentifier(node.name); + var generatedName = getGeneratedNameForIdentifier(node.name, /*allowGeneratedIdentifiers*/ true); if (generatedName) { write(generatedName); } @@ -4723,6 +4745,23 @@ module ts { emitLeadingComments(accessors.setAccessor); write("set: "); emitStart(accessors.setAccessor); + if (forEach(accessors.setAccessor.parameters, nodeIsDecorated)) { + if (!generatedSetterNames) { + generatedSetterNames = []; + } + + var preferredName: string; + if ((member).name.kind === SyntaxKind.Identifier) { + preferredName = "set_" + ((member).name).text; + } + + let generatedVariable = createTempVariable(node, preferredName); + let generatedName = generatedVariable.text; + recordTempDeclaration(generatedVariable); + generatedSetterNames[accessors.setAccessor.id] = generatedName; + write(generatedName); + write(" = "); + } write("function "); emitSignatureAndBody(accessors.setAccessor); emitEnd(accessors.setAccessor); @@ -4893,6 +4932,15 @@ module ts { tempParameters = saveTempParameters; } + function emitClassDeclaration(node: ClassDeclaration) { + if (languageVersion < ScriptTarget.ES6) { + emitClassDeclarationBelowES6(node); + } + else { + emitClassDeclarationForES6AndHigher(node); + } + } + function emitClassDeclarationForES6AndHigher(node: ClassDeclaration) { if (isES6ModuleMemberDeclaration(node)) { write("export "); @@ -4902,16 +4950,56 @@ module ts { } } + if (nodeOrChildIsDecorated(node)) { + if ((node.flags & NodeFlags.Default) === 0) { + write("let "); + emitDeclarationName(node); + write(" = "); + } + + write("(function() {"); + + var saveTempCount = tempCount; + var saveTempVariables = tempVariables; + var saveTempParameters = tempParameters; + var saveGeneratedComputedPropertyNames = generatedComputedPropertyNames; + var saveGeneratedSetterNames = generatedSetterNames; + tempCount = 0; + tempVariables = undefined; + tempParameters = undefined; + generatedComputedPropertyNames = undefined; + generatedSetterNames = undefined; + + increaseIndent(); + writeLine(); + + if (nodeIsDecorated(node)) { + if (!generatedClassNames) { + generatedClassNames = []; + } + + var generatedName = generateUniqueNameForLocation(node, "_" + node.name.text); + var variableId = resolver.getClassDeclarationVariableId(node.name); + write("let "); + write(generatedName); + write(" = "); + } + } + write("class "); // check if this is an "export default class" as it may not have a name if (node.name || !(node.flags & NodeFlags.Default)) { emitDeclarationName(node); + if (nodeIsDecorated(node)) { + generatedClassNames[variableId] = generatedName; + } } var baseTypeNode = getClassBaseTypeNode(node); if (baseTypeNode) { write(" extends "); emit(baseTypeNode.typeName); } + write(" {"); increaseIndent(); scopeEmitStart(node); @@ -4931,6 +5019,23 @@ module ts { writeLine(); emitMemberAssignments(node, NodeFlags.Static); + if (nodeOrChildIsDecorated(node)) { + writeLine(); + emitDecoratorsOfClass(node); + emitTempDeclarations(/*newLine*/ true); + writeLine(); + tempCount = saveTempCount; + tempVariables = saveTempVariables; + tempParameters = saveTempParameters; + generatedComputedPropertyNames = saveGeneratedComputedPropertyNames; + generatedSetterNames = saveGeneratedSetterNames; + + write("return "); + emitDeclarationName(node); + decreaseIndent(); + writeLine(); + write("})();"); + } // If this is an exported class, but not on the top level (i.e. on an internal // module), export it if (!isES6ModuleMemberDeclaration(node) && (node.flags & NodeFlags.Export)) { @@ -4953,6 +5058,16 @@ module ts { write("_super"); } write(") {"); + let saveTempCount = tempCount; + let saveTempVariables = tempVariables; + let saveTempParameters = tempParameters; + let saveGeneratedComputedPropertyNames = generatedComputedPropertyNames; + let saveGeneratedSetterNames = generatedSetterNames; + tempCount = 0; + tempVariables = undefined; + tempParameters = undefined; + generatedComputedPropertyNames = undefined; + generatedSetterNames = undefined; increaseIndent(); scopeEmitStart(node); if (baseTypeNode) { @@ -4968,6 +5083,14 @@ module ts { emitMemberFunctionsForES5AndLower(node); emitMemberAssignments(node, NodeFlags.Static); writeLine(); + emitDecoratorsOfClass(node); + emitTempDeclarations(/*newLine*/ true); + writeLine(); + tempCount = saveTempCount; + tempVariables = saveTempVariables; + tempParameters = saveTempParameters; + generatedComputedPropertyNames = saveGeneratedComputedPropertyNames; + generatedSetterNames = saveGeneratedSetterNames; emitToken(SyntaxKind.CloseBraceToken, node.members.end, () => { write("return "); emitDeclarationName(node); @@ -5000,6 +5123,172 @@ module ts { } } + function emitTargetOfClassElement(node: ClassDeclaration, member: Node) { + emitDeclarationName(node); + if (!(member.flags & NodeFlags.Static)) { + write(".prototype"); + } + } + + function getDecoratorsOfMember(node: ClassDeclaration, member: ClassElement) { + switch (member.kind) { + case SyntaxKind.MethodDeclaration: + case SyntaxKind.PropertyDeclaration: + return member.decorators; + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + let accessors = getAllAccessorDeclarations(node.members, member); + if (member === accessors.firstAccessor) { + let decorators = accessors.firstAccessor.decorators; + if (member !== accessors.lastAccessor && accessors.lastAccessor.decorators) { + if (decorators) { + return decorators.concat(accessors.lastAccessor.decorators); + } + return accessors.lastAccessor.decorators; + } + return decorators; + } + break; + } + return undefined; + } + + function emitExpressionOfDecorator(node: Decorator) { + let expression = node.expression; + emit(expression); + } + + function emitDecorateStart(decorators: Decorator[]): void { + write("__decorate(["); + let decoratorCount = decorators.length; + for (let i = 0; i < decoratorCount; i++) { + if (i > 0) { + write(", "); + } + let decorator = decorators[i]; + emitStart(decorator); + emitExpressionOfDecorator(decorator); + emitEnd(decorator); + } + write(`], `); + } + + function emitDecoratorsOfParameter(node: FunctionLikeDeclaration, parameter: ParameterDeclaration, parameterIndex: number) { + let decorators = parameter.decorators; + if (!decorators || decorators.length === 0) { + return; + } + + emitStart(node); + emitDecorateStart(decorators); + emitPropertyAccessForMethod(node); + write(", "); + write(String(parameterIndex)); + write(");"); + emitEnd(node); + writeLine(); + } + + function emitPropertyAccessForMethod(node: FunctionLikeDeclaration) { + if (node.parent && node.parent.kind === SyntaxKind.ClassDeclaration) { + if (node.kind === SyntaxKind.Constructor) { + emitDeclarationName(node.parent); + } + else if (node.kind === SyntaxKind.SetAccessor) { + if (generatedSetterNames) { + var generatedName = generatedSetterNames[node.id]; + if (generatedName) { + write(generatedName); + return; + } + } + + write("Object.getOwnPropertyDescriptor("); + emitTargetOfClassElement(node.parent, node); + write(", "); + emitExpressionForPropertyName(node.name); + write(").set"); + } + else { + emitTargetOfClassElement(node.parent, node); + emitMemberAccessForPropertyName(node.name); + } + } + } + + function emitDecoratorsOfParameters(node: FunctionLikeDeclaration) { + forEach(node.parameters, (parameter, parameterIndex) => emitDecoratorsOfParameter(node, parameter, parameterIndex)); + } + + function emitDecoratorsOfMembers(node: ClassDeclaration) { + forEach(node.members, member => emitDecoratorsOfMember(node, member)); + } + + function emitDecoratorsOfMember(node: ClassDeclaration, member: ClassElement) { + switch (member.kind) { + case SyntaxKind.MethodDeclaration: + emitDecoratorsOfParameters(member); + break; + + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + let accessors = getAllAccessorDeclarations(node.members, member); + if (member === accessors.firstAccessor && accessors.setAccessor) { + emitDecoratorsOfParameters(accessors.setAccessor); + } + break; + + case SyntaxKind.PropertyDeclaration: + break; + + default: + return; + } + + let name = member.name; + let decorators = getDecoratorsOfMember(node, member); + if (!decorators || decorators.length === 0) { + return; + } + + if (languageVersion >= ScriptTarget.ES5) { + emitStart(member); + emitDecorateStart(decorators); + emitTargetOfClassElement(node, member); + write(", "); + emitExpressionForPropertyName(name); + write(");"); + emitEnd(member); + writeLine(); + } + } + + function emitDecoratorsOfConstructor(node: ClassDeclaration) { + let constructor = getFirstConstructorWithBody(node); + if (constructor) { + emitDecoratorsOfParameters(constructor); + } + + let decorators = node.decorators; + if (!decorators || decorators.length === 0) { + return; + } + + emitStart(node); + emitDeclarationName(node); + write(" = "); + emitDecorateStart(node.decorators); + emitDeclarationName(node); + write(");"); + emitEnd(node); + writeLine(); + } + + function emitDecoratorsOfClass(node: ClassDeclaration) { + emitDecoratorsOfMembers(node); + emitDecoratorsOfConstructor(node); + } + function emitInterfaceDeclaration(node: InterfaceDeclaration) { emitPinnedOrTripleSlashComments(node); } @@ -5654,6 +5943,17 @@ module ts { return statements.length; } + function writeHelper(text: string): void { + let lines = text.split(/\r\n|\r|\n/g); + for (let i = 0; i < lines.length; ++i) { + let line = lines[i]; + if (line.length) { + writeLine(); + write(line); + } + } + } + function emitSourceFileNode(node: SourceFile) { // Start new file on new line writeLine(); @@ -5680,6 +5980,20 @@ module ts { write("};"); extendsEmitted = true; } + if (!decorateEmitted && resolver.getNodeCheckFlags(node) & NodeCheckFlags.EmitDecorate) { + writeHelper(` +var __decorate = this.__decorate || function (decorators, target, key) { + var kind = key == null ? 0 : typeof key == "number" ? 1 : 2, result = target; + if (kind == 2) result = Object.getOwnPropertyDescriptor(target, typeof key == "symbol" ? key : key = String(key)); + for (var i = decorators.length - 1; i >= 0; --i) { + var decorator = decorators[i]; + result = (kind == 0 ? decorator(result) : kind == 1 ? decorator(target, key) : decorator(target, key, result)) || result; + } + if (kind == 2 && result) Object.defineProperty(target, key, result); + if (kind == 0) return result; +};`); + decorateEmitted = true; + } if (isExternalModule(node)) { if (languageVersion >= ScriptTarget.ES6) { emitES6Module(node, startIndex); @@ -5897,7 +6211,7 @@ module ts { case SyntaxKind.VariableDeclaration: return emitVariableDeclaration(node); case SyntaxKind.ClassDeclaration: - return languageVersion < ScriptTarget.ES6 ? emitClassDeclarationBelowES6(node) : emitClassDeclarationForES6AndHigher(node); + return emitClassDeclaration(node); case SyntaxKind.InterfaceDeclaration: return emitInterfaceDeclaration(node); case SyntaxKind.EnumDeclaration: diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 02ca6627b2e0b..e2eeeeb5917d0 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1233,6 +1233,7 @@ module ts { getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; isUnknownIdentifier(location: Node, name: string): boolean; getBlockScopedVariableId(node: Identifier): number; + getClassDeclarationVariableId(node: Identifier): number; } export const enum SymbolFlags { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 959476df2a647..a48a8fc7f2a5e 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -586,6 +586,78 @@ module ts { return forEach(node.members, getConstructorWithBody); } + export function nodeOrChildIsDecorated(node: Node): boolean { + switch (node.kind) { + case SyntaxKind.ClassDeclaration: + if (node.decorators) { + return true; + } + + return forEach((node).members, nodeOrChildIsDecorated); + + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.Parameter: + if (node.decorators) { + return true; + } + + return false; + + case SyntaxKind.GetAccessor: + if ((node).body && node.decorators) { + return true; + } + + return false; + + case SyntaxKind.MethodDeclaration: + case SyntaxKind.SetAccessor: + if ((node).body && node.decorators) { + return true; + } + + return forEach((node).parameters, nodeOrChildIsDecorated); + } + + return false; + } + + export function nodeIsDecorated(node: Node): boolean { + switch (node.kind) { + case SyntaxKind.ClassDeclaration: + if (node.decorators) { + return true; + } + + return false; + + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.Parameter: + if (node.decorators) { + return true; + } + + return false; + + case SyntaxKind.GetAccessor: + if ((node).body && node.decorators) { + return true; + } + + return false; + + case SyntaxKind.MethodDeclaration: + case SyntaxKind.SetAccessor: + if ((node).body && node.decorators) { + return true; + } + + return false; + } + + return false; + } + export function isExpression(node: Node): boolean { switch (node.kind) { case SyntaxKind.ThisKeyword: From f1e8e611ab9dc3d6af5cbcfe303e82dedd8bc752 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 17 Mar 2015 13:43:29 -0700 Subject: [PATCH 139/224] Updated formatting for decorators --- src/services/formatting/formatting.ts | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/services/formatting/formatting.ts b/src/services/formatting/formatting.ts index 24ddabc2b2b14..02c247bbc31a8 100644 --- a/src/services/formatting/formatting.ts +++ b/src/services/formatting/formatting.ts @@ -419,6 +419,29 @@ module ts.formatting { } } + function getFirstNonDecoratorTokenOfNode(node: Node) { + if (node.modifiers && node.modifiers.length) { + return node.modifiers[0].kind; + } + switch (node.kind) { + case SyntaxKind.ClassDeclaration: return SyntaxKind.ClassKeyword; + case SyntaxKind.InterfaceDeclaration: return SyntaxKind.InterfaceKeyword; + case SyntaxKind.FunctionDeclaration: return SyntaxKind.FunctionKeyword; + case SyntaxKind.EnumDeclaration: return SyntaxKind.EnumDeclaration; + case SyntaxKind.GetAccessor: return SyntaxKind.GetKeyword; + case SyntaxKind.SetAccessor: return SyntaxKind.SetKeyword; + case SyntaxKind.MethodDeclaration: + if ((node).asteriskToken) { + return SyntaxKind.AsteriskToken; + } + // fall-through + + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.Parameter: + return (node).name.kind; + } + } + function getDynamicIndentation(node: Node, nodeStartLine: number, indentation: number, delta: number): DynamicIndentation { return { getIndentationForComment: kind => { @@ -434,6 +457,12 @@ module ts.formatting { return indentation; }, getIndentationForToken: (line, kind) => { + if (nodeStartLine !== line && node.decorators) { + if (kind === getFirstNonDecoratorTokenOfNode(node)) { + // if this token is the first token following the list of decorators, we do not need to indent + return indentation; + } + } switch (kind) { // open and close brace, 'else' and 'while' (in do statement) tokens has indentation of the parent case SyntaxKind.OpenBraceToken: @@ -442,6 +471,7 @@ module ts.formatting { case SyntaxKind.CloseBracketToken: case SyntaxKind.ElseKeyword: case SyntaxKind.WhileKeyword: + case SyntaxKind.AtToken: return indentation; default: // if token line equals to the line of containing node (this is a first token in the node) - use node indentation From 6c32a8bdb0b042422ceba45361eeb9e01672a2b1 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 17 Mar 2015 13:57:58 -0700 Subject: [PATCH 140/224] Updated baselines --- src/compiler/emitter.ts | 9 ++++-- .../baselines/reference/APISample_compile.js | 3 ++ .../reference/APISample_compile.types | 15 +++++++++ tests/baselines/reference/APISample_linter.js | 3 ++ .../reference/APISample_linter.types | 15 +++++++++ .../reference/APISample_transform.js | 3 ++ .../reference/APISample_transform.types | 15 +++++++++ .../baselines/reference/APISample_watcher.js | 3 ++ .../reference/APISample_watcher.types | 15 +++++++++ .../reference/computedPropertyNames23_ES5.js | 2 +- .../reference/computedPropertyNames26_ES5.js | 2 +- .../reference/noDefaultLib.errors.txt | 12 +++++++ .../reference/parser509698.errors.txt | 24 ++++++++++---- ...rserErrorRecovery_ClassElement3.errors.txt | 6 ++-- .../noDefaultLib/amd/noDefaultLib.errors.txt | 28 +++++++++++----- .../noDefaultLib/node/noDefaultLib.errors.txt | 28 +++++++++++----- .../typeCheckTypeArgument.errors.txt | 32 +++++++++++++------ 17 files changed, 175 insertions(+), 40 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index e6354a961286a..4bb029091d2aa 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4952,7 +4952,7 @@ module ts { if (nodeOrChildIsDecorated(node)) { if ((node.flags & NodeFlags.Default) === 0) { - write("let "); + write("var "); emitDeclarationName(node); write(" = "); } @@ -5022,6 +5022,11 @@ module ts { if (nodeOrChildIsDecorated(node)) { writeLine(); emitDecoratorsOfClass(node); + + write("return "); + emitDeclarationName(node); + write(";"); + emitTempDeclarations(/*newLine*/ true); writeLine(); tempCount = saveTempCount; @@ -5030,8 +5035,6 @@ module ts { generatedComputedPropertyNames = saveGeneratedComputedPropertyNames; generatedSetterNames = saveGeneratedSetterNames; - write("return "); - emitDeclarationName(node); decreaseIndent(); writeLine(); write("})();"); diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index 12a0a7c077058..3aa1b0aa148ef 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -965,6 +965,7 @@ declare module "typescript" { getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; isUnknownIdentifier(location: Node, name: string): boolean; getBlockScopedVariableId(node: Identifier): number; + getClassDeclarationVariableId(node: Identifier): number; } const enum SymbolFlags { FunctionScopedVariable = 1, @@ -1070,6 +1071,7 @@ declare module "typescript" { ContextChecked = 64, EnumValuesComputed = 128, BlockScopedBindingInLoop = 256, + EmitDecorate = 512, } interface NodeLinks { resolvedType?: Type; @@ -1458,6 +1460,7 @@ declare module "typescript" { character: number; }; function getLineAndCharacterOfPosition(sourceFile: SourceFile, position: number): LineAndCharacter; + function lineBreakBetween(sourceFile: SourceFile, firstPos: number, secondPos: number): boolean; function isWhiteSpace(ch: number): boolean; function isLineBreak(ch: number): boolean; function isOctalDigit(ch: number): boolean; diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index 0b00bbc191c54..59b08a4781c19 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -3141,6 +3141,11 @@ declare module "typescript" { getBlockScopedVariableId(node: Identifier): number; >getBlockScopedVariableId : (node: Identifier) => number >node : Identifier +>Identifier : Identifier + + getClassDeclarationVariableId(node: Identifier): number; +>getClassDeclarationVariableId : (node: Identifier) => number +>node : Identifier >Identifier : Identifier } const enum SymbolFlags { @@ -3455,6 +3460,9 @@ declare module "typescript" { BlockScopedBindingInLoop = 256, >BlockScopedBindingInLoop : NodeCheckFlags + + EmitDecorate = 512, +>EmitDecorate : NodeCheckFlags } interface NodeLinks { >NodeLinks : NodeLinks @@ -4626,6 +4634,13 @@ declare module "typescript" { >position : number >LineAndCharacter : LineAndCharacter + function lineBreakBetween(sourceFile: SourceFile, firstPos: number, secondPos: number): boolean; +>lineBreakBetween : (sourceFile: SourceFile, firstPos: number, secondPos: number) => boolean +>sourceFile : SourceFile +>SourceFile : SourceFile +>firstPos : number +>secondPos : number + function isWhiteSpace(ch: number): boolean; >isWhiteSpace : (ch: number) => boolean >ch : number diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index c819c0605677c..3a757204be888 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -996,6 +996,7 @@ declare module "typescript" { getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; isUnknownIdentifier(location: Node, name: string): boolean; getBlockScopedVariableId(node: Identifier): number; + getClassDeclarationVariableId(node: Identifier): number; } const enum SymbolFlags { FunctionScopedVariable = 1, @@ -1101,6 +1102,7 @@ declare module "typescript" { ContextChecked = 64, EnumValuesComputed = 128, BlockScopedBindingInLoop = 256, + EmitDecorate = 512, } interface NodeLinks { resolvedType?: Type; @@ -1489,6 +1491,7 @@ declare module "typescript" { character: number; }; function getLineAndCharacterOfPosition(sourceFile: SourceFile, position: number): LineAndCharacter; + function lineBreakBetween(sourceFile: SourceFile, firstPos: number, secondPos: number): boolean; function isWhiteSpace(ch: number): boolean; function isLineBreak(ch: number): boolean; function isOctalDigit(ch: number): boolean; diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index c19778ea49926..c4e2f1ba406ea 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -3287,6 +3287,11 @@ declare module "typescript" { getBlockScopedVariableId(node: Identifier): number; >getBlockScopedVariableId : (node: Identifier) => number >node : Identifier +>Identifier : Identifier + + getClassDeclarationVariableId(node: Identifier): number; +>getClassDeclarationVariableId : (node: Identifier) => number +>node : Identifier >Identifier : Identifier } const enum SymbolFlags { @@ -3601,6 +3606,9 @@ declare module "typescript" { BlockScopedBindingInLoop = 256, >BlockScopedBindingInLoop : NodeCheckFlags + + EmitDecorate = 512, +>EmitDecorate : NodeCheckFlags } interface NodeLinks { >NodeLinks : NodeLinks @@ -4772,6 +4780,13 @@ declare module "typescript" { >position : number >LineAndCharacter : LineAndCharacter + function lineBreakBetween(sourceFile: SourceFile, firstPos: number, secondPos: number): boolean; +>lineBreakBetween : (sourceFile: SourceFile, firstPos: number, secondPos: number) => boolean +>sourceFile : SourceFile +>SourceFile : SourceFile +>firstPos : number +>secondPos : number + function isWhiteSpace(ch: number): boolean; >isWhiteSpace : (ch: number) => boolean >ch : number diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index 11fb8bdef9385..54acd038e43b2 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -997,6 +997,7 @@ declare module "typescript" { getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; isUnknownIdentifier(location: Node, name: string): boolean; getBlockScopedVariableId(node: Identifier): number; + getClassDeclarationVariableId(node: Identifier): number; } const enum SymbolFlags { FunctionScopedVariable = 1, @@ -1102,6 +1103,7 @@ declare module "typescript" { ContextChecked = 64, EnumValuesComputed = 128, BlockScopedBindingInLoop = 256, + EmitDecorate = 512, } interface NodeLinks { resolvedType?: Type; @@ -1490,6 +1492,7 @@ declare module "typescript" { character: number; }; function getLineAndCharacterOfPosition(sourceFile: SourceFile, position: number): LineAndCharacter; + function lineBreakBetween(sourceFile: SourceFile, firstPos: number, secondPos: number): boolean; function isWhiteSpace(ch: number): boolean; function isLineBreak(ch: number): boolean; function isOctalDigit(ch: number): boolean; diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index 4e56770573af7..9d3c6e46cc690 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -3237,6 +3237,11 @@ declare module "typescript" { getBlockScopedVariableId(node: Identifier): number; >getBlockScopedVariableId : (node: Identifier) => number >node : Identifier +>Identifier : Identifier + + getClassDeclarationVariableId(node: Identifier): number; +>getClassDeclarationVariableId : (node: Identifier) => number +>node : Identifier >Identifier : Identifier } const enum SymbolFlags { @@ -3551,6 +3556,9 @@ declare module "typescript" { BlockScopedBindingInLoop = 256, >BlockScopedBindingInLoop : NodeCheckFlags + + EmitDecorate = 512, +>EmitDecorate : NodeCheckFlags } interface NodeLinks { >NodeLinks : NodeLinks @@ -4722,6 +4730,13 @@ declare module "typescript" { >position : number >LineAndCharacter : LineAndCharacter + function lineBreakBetween(sourceFile: SourceFile, firstPos: number, secondPos: number): boolean; +>lineBreakBetween : (sourceFile: SourceFile, firstPos: number, secondPos: number) => boolean +>sourceFile : SourceFile +>SourceFile : SourceFile +>firstPos : number +>secondPos : number + function isWhiteSpace(ch: number): boolean; >isWhiteSpace : (ch: number) => boolean >ch : number diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index b9a40c6a197dc..13fd5a25457eb 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -1034,6 +1034,7 @@ declare module "typescript" { getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; isUnknownIdentifier(location: Node, name: string): boolean; getBlockScopedVariableId(node: Identifier): number; + getClassDeclarationVariableId(node: Identifier): number; } const enum SymbolFlags { FunctionScopedVariable = 1, @@ -1139,6 +1140,7 @@ declare module "typescript" { ContextChecked = 64, EnumValuesComputed = 128, BlockScopedBindingInLoop = 256, + EmitDecorate = 512, } interface NodeLinks { resolvedType?: Type; @@ -1527,6 +1529,7 @@ declare module "typescript" { character: number; }; function getLineAndCharacterOfPosition(sourceFile: SourceFile, position: number): LineAndCharacter; + function lineBreakBetween(sourceFile: SourceFile, firstPos: number, secondPos: number): boolean; function isWhiteSpace(ch: number): boolean; function isLineBreak(ch: number): boolean; function isOctalDigit(ch: number): boolean; diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index 5b52c1522a58f..514a9afe4620c 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -3410,6 +3410,11 @@ declare module "typescript" { getBlockScopedVariableId(node: Identifier): number; >getBlockScopedVariableId : (node: Identifier) => number >node : Identifier +>Identifier : Identifier + + getClassDeclarationVariableId(node: Identifier): number; +>getClassDeclarationVariableId : (node: Identifier) => number +>node : Identifier >Identifier : Identifier } const enum SymbolFlags { @@ -3724,6 +3729,9 @@ declare module "typescript" { BlockScopedBindingInLoop = 256, >BlockScopedBindingInLoop : NodeCheckFlags + + EmitDecorate = 512, +>EmitDecorate : NodeCheckFlags } interface NodeLinks { >NodeLinks : NodeLinks @@ -4895,6 +4903,13 @@ declare module "typescript" { >position : number >LineAndCharacter : LineAndCharacter + function lineBreakBetween(sourceFile: SourceFile, firstPos: number, secondPos: number): boolean; +>lineBreakBetween : (sourceFile: SourceFile, firstPos: number, secondPos: number) => boolean +>sourceFile : SourceFile +>SourceFile : SourceFile +>firstPos : number +>secondPos : number + function isWhiteSpace(ch: number): boolean; >isWhiteSpace : (ch: number) => boolean >ch : number diff --git a/tests/baselines/reference/computedPropertyNames23_ES5.js b/tests/baselines/reference/computedPropertyNames23_ES5.js index c3024a7fbbfde..a9c40ca97371b 100644 --- a/tests/baselines/reference/computedPropertyNames23_ES5.js +++ b/tests/baselines/reference/computedPropertyNames23_ES5.js @@ -19,6 +19,6 @@ var C = (function () { _a[this.bar()] = 1, _a)[0]] = function () { }; + var _a; return C; })(); -var _a; diff --git a/tests/baselines/reference/computedPropertyNames26_ES5.js b/tests/baselines/reference/computedPropertyNames26_ES5.js index 5651ee266c94e..5628215f3dc91 100644 --- a/tests/baselines/reference/computedPropertyNames26_ES5.js +++ b/tests/baselines/reference/computedPropertyNames26_ES5.js @@ -34,6 +34,6 @@ var C = (function (_super) { _a[_super.bar.call(this)] = 1, _a)[0]] = function () { }; + var _a; return C; })(Base); -var _a; diff --git a/tests/baselines/reference/noDefaultLib.errors.txt b/tests/baselines/reference/noDefaultLib.errors.txt index b8f42ba7c331b..d7e58eb31f89a 100644 --- a/tests/baselines/reference/noDefaultLib.errors.txt +++ b/tests/baselines/reference/noDefaultLib.errors.txt @@ -1,9 +1,21 @@ +error TS2318: Cannot find global type 'TypedPropertyDescriptor'. +error TS2318: Cannot find global type 'PropertyDecorator'. +error TS2318: Cannot find global type 'PropertyAnnotation'. +error TS2318: Cannot find global type 'ParameterAnnotation'. error TS2318: Cannot find global type 'IArguments'. +error TS2318: Cannot find global type 'ClassDecorator'. +error TS2318: Cannot find global type 'ClassAnnotation'. error TS2318: Cannot find global type 'Boolean'. tests/cases/compiler/noDefaultLib.ts(4,11): error TS2317: Global type 'Array' must have 1 type parameter(s). +!!! error TS2318: Cannot find global type 'TypedPropertyDescriptor'. +!!! error TS2318: Cannot find global type 'PropertyDecorator'. +!!! error TS2318: Cannot find global type 'PropertyAnnotation'. +!!! error TS2318: Cannot find global type 'ParameterAnnotation'. !!! error TS2318: Cannot find global type 'IArguments'. +!!! error TS2318: Cannot find global type 'ClassDecorator'. +!!! error TS2318: Cannot find global type 'ClassAnnotation'. !!! error TS2318: Cannot find global type 'Boolean'. ==== tests/cases/compiler/noDefaultLib.ts (1 errors) ==== /// diff --git a/tests/baselines/reference/parser509698.errors.txt b/tests/baselines/reference/parser509698.errors.txt index 85485dd65012a..e3dd323ec1018 100644 --- a/tests/baselines/reference/parser509698.errors.txt +++ b/tests/baselines/reference/parser509698.errors.txt @@ -1,21 +1,33 @@ +error TS2318: Cannot find global type 'Object'. +error TS2318: Cannot find global type 'TypedPropertyDescriptor'. +error TS2318: Cannot find global type 'ParameterAnnotation'. +error TS2318: Cannot find global type 'Array'. +error TS2318: Cannot find global type 'ClassAnnotation'. error TS2318: Cannot find global type 'String'. error TS2318: Cannot find global type 'RegExp'. -error TS2318: Cannot find global type 'Object'. +error TS2318: Cannot find global type 'PropertyDecorator'. +error TS2318: Cannot find global type 'PropertyAnnotation'. +error TS2318: Cannot find global type 'ClassDecorator'. +error TS2318: Cannot find global type 'Boolean'. error TS2318: Cannot find global type 'Number'. error TS2318: Cannot find global type 'IArguments'. error TS2318: Cannot find global type 'Function'. -error TS2318: Cannot find global type 'Boolean'. -error TS2318: Cannot find global type 'Array'. +!!! error TS2318: Cannot find global type 'Object'. +!!! error TS2318: Cannot find global type 'TypedPropertyDescriptor'. +!!! error TS2318: Cannot find global type 'ParameterAnnotation'. +!!! error TS2318: Cannot find global type 'Array'. +!!! error TS2318: Cannot find global type 'ClassAnnotation'. !!! error TS2318: Cannot find global type 'String'. !!! error TS2318: Cannot find global type 'RegExp'. -!!! error TS2318: Cannot find global type 'Object'. +!!! error TS2318: Cannot find global type 'PropertyDecorator'. +!!! error TS2318: Cannot find global type 'PropertyAnnotation'. +!!! error TS2318: Cannot find global type 'ClassDecorator'. +!!! error TS2318: Cannot find global type 'Boolean'. !!! error TS2318: Cannot find global type 'Number'. !!! error TS2318: Cannot find global type 'IArguments'. !!! error TS2318: Cannot find global type 'Function'. -!!! error TS2318: Cannot find global type 'Boolean'. -!!! error TS2318: Cannot find global type 'Array'. ==== tests/cases/conformance/parser/ecmascript5/RegressionTests/parser509698.ts (0 errors) ==== ///