From 6ac1bcca08f916e3eeb47e56306b03b826e241d5 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 10 Feb 2015 13:43:05 -0800 Subject: [PATCH 001/159] 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 1ac305cf055..0f309bc3809 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 43d21885c27..b5eb7a1ba0d 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 1cd7df9962e..3cc5067891a 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 00000000000..0464794ea89 --- /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 00000000000..c3d09388916 --- /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 f6610ac5ad2..9495bc1ffbc 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 00000000000..1c75b15c7d1 --- /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 00000000000..2be3f67f1e9 --- /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 70a15a9bc54..d43aac9b638 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 00000000000..8c43a19e409 --- /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 339880ee097..08c21c23644 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 00000000000..8d364f75a9b --- /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/159] 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 0f309bc3809..db174b70596 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 c6daa3b1222..6ee33d5e004 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 1e09de42ec6..d764a68eede 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 00000000000..b63431d5df6 --- /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 00000000000..623a7e8e160 --- /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 2c7785dec6e..f26e9073d2c 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 cb7b669eea1..6ba725f2494 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 00000000000..98a68870833 --- /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 00000000000..3c8461fba2b --- /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 00000000000..3d6dab17785 --- /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 00000000000..3ba19cef9b4 --- /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 9937606c41f..0c831d323d1 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 00000000000..89a5ad7bc2c --- /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 ca00ac3f981..8104fe8b3c0 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 00000000000..1d491ce146a --- /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 00000000000..237fe3649ea --- /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/159] 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 61cf3298fd8..864e9551721 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 db174b70596..60cde0743d0 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 c52499ef994..9a1eba42598 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 e86955b3c96..80a7fccbd28 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 00000000000..7510c8aeb6b --- /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 00000000000..3a68df656fe --- /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 66f8ce0ef92..79cbafeff2f 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 4f96b8a4dfa..217b6e3b178 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 00000000000..dd79b2f1cfa --- /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 00000000000..cd72f35c8bf --- /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 00000000000..982209df189 --- /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 00000000000..36792ece82e --- /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 00000000000..b9461b6caca --- /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 00000000000..fad411f557d --- /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 00000000000..57a77410cb2 --- /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 00000000000..da473fa42a3 --- /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 00000000000..a5abd986ee8 --- /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 00000000000..524860827e6 --- /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 ed34434bd29..0a12e10169b 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 00000000000..3ddf1a4cf52 --- /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 22e66bc95fa..e12a8d032d3 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 00000000000..9976f20f080 --- /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 00000000000..c9e85bbbd65 --- /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 00000000000..950554b971d --- /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 00000000000..2dcb2364660 --- /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 00000000000..a51d70ad50e --- /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/159] 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 60cde0743d0..000c0d0e81f 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 3f69c2d7de9..00000000000 --- 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 d8d1fa8111d..d1e69585ba4 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 00000000000..588940250fe --- /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 00000000000..24e8ee047b8 --- /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 00000000000..9b067ef27a4 --- /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 5fc8e8f9058..1a45788819b 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 a7402bfeb6a..48fb54151ba 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 00000000000..bdf2841ab08 --- /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 00000000000..451e2df15b6 --- /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 00000000000..9783ad4921e --- /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 00000000000..323650fe205 --- /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 dc079cac8f7..2e25d60ce13 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 4cf3046532a..5b211b9fcea 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 c270b9bdd69..6295064b81c 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 5ec91279306..948c033f7de 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 00000000000..86869e052fe --- /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 00000000000..ef6c7ac3221 --- /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 00000000000..1052970fa99 --- /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 00000000000..dfbc8c0be07 --- /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 37424bc7bd8..d0a28bb0c47 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 abd4736fca7..5419ac20928 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 34439fa91c1..00000000000 --- 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 b6d293225fd..e2b5d70b6b3 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 00000000000..03243fc014d --- /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 00000000000..d6aacf0ba40 --- /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 00000000000..628faec6c27 --- /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 00000000000..822249c3b34 --- /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 00000000000..f824dbf71d5 --- /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 dc5b4ab98d6..f5897128226 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 00000000000..85e06b8c99d --- /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 96b277d6640..a0524dd2138 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 00000000000..0db237a9c31 --- /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 00000000000..80bc2a4474e --- /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 bf34687f791..6e42898d1bc 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 3d029e28738..e5d2bfefb39 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 00000000000..6590829e618 --- /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 00000000000..db076b87c9a --- /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 5943fa8bfc4..c58ba286e0a 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 c037d283dfa..e0877bd74c1 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 00000000000..5aaf1e14c34 --- /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 00000000000..0436e8f4cdf --- /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/159] 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 864e9551721..2e4553a4bc0 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 000c0d0e81f..d23b56a0001 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 d50b4bcf335..1f7a8211dfc 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 5c74f2fa688..b9bc5d96d41 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 aebe5ea695a..5146cde791c 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 8b40586e88b..012d635e4c5 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 1bada73385f..4292108fc73 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 74aba68a76c..8a3951bb19b 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 6be348b4131..ab2e05ac052 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 79e2ac39802..36eaccac6a8 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 429a63daed8..99d84a928f8 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 d1e69585ba4..b3c6b71a422 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 24e8ee047b8..34b39cda4b7 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 48fb54151ba..aa10fb6e26f 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 451e2df15b6..765d09fae79 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 323650fe205..2690e7a7f51 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 5b211b9fcea..3613aaf5575 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 948c033f7de..1241140b121 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 86869e052fe..7f67628c18e 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 1052970fa99..00166b1bc41 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 5419ac20928..e8ce8b28875 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 e2b5d70b6b3..0b703f829ca 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 6ee33d5e004..4e53d54893d 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 b63431d5df6..e7d0eae9ca9 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 f26e9073d2c..50a03972cc2 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 9a1eba42598..fe1dc0dbce3 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 7510c8aeb6b..3f0cc2acee8 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 79cbafeff2f..79f94a6c82c 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/159] 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 dd79b2f1cfa..a5820672247 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 982209df189..c1a4b5d5e9e 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 9976f20f080..7a4519c68bb 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 c9e85bbbd65..2f6073f2a1e 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/159] 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 d23b56a0001..63e6e992b35 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 00000000000..a7827a5d56a --- /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 00000000000..62917e5ff36 --- /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 00000000000..08294e57232 --- /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/159] 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 00000000000..45a3f80058c --- /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 00000000000..0239b68194f --- /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 00000000000..70e855810e3 --- /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 00000000000..147c3b42296 --- /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 00000000000..3cb1326cc8b --- /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 00000000000..d1dd565c81b --- /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 00000000000..88597138eb0 --- /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 00000000000..a386a42b524 --- /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 00000000000..20ea4335112 --- /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 00000000000..a3f8dd11c6c --- /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 00000000000..8178cb40cb4 --- /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 00000000000..84f6936d4b0 --- /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 00000000000..3696f8b28c9 --- /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 00000000000..69ed42ca35c --- /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 00000000000..c1fe9993d95 --- /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 00000000000..208f71bcbfe --- /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 00000000000..fef56560dcf --- /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 00000000000..6e3ac5786d1 --- /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 00000000000..ce42814a918 --- /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 00000000000..cafcace08a0 --- /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 00000000000..87494c8a622 --- /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 00000000000..4110270d7dd --- /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 00000000000..f25a3779b99 --- /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 00000000000..8c7ec108538 --- /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/159] 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 00000000000..4e9719892db --- /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 00000000000..62f54168c36 --- /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 00000000000..648868cf001 --- /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 00000000000..3d404658e38 --- /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 00000000000..405fab0de50 --- /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 00000000000..21ddcbc71d6 --- /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 00000000000..4df73e2ed9d --- /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 00000000000..99ad9fd57ab --- /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 00000000000..69b76d79fbb --- /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 00000000000..e40d3893ee2 --- /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 00000000000..91e927428a1 --- /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 00000000000..345d593b143 --- /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 00000000000..6394240a933 --- /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 00000000000..ba036202a52 --- /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 00000000000..4700782b78e --- /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 00000000000..64ae625c892 --- /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 00000000000..1951a8a6b30 --- /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 00000000000..732f7ef7ba0 --- /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 00000000000..1f026af8f34 --- /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 00000000000..95b85e53edc --- /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 00000000000..d83672f3754 --- /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/159] 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 | 432 ++++++++++-------- 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, 381 insertions(+), 248 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 2e4553a4bc0..249113e86f7 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 63e6e992b35..fff78fbb774 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) { - createAndSetNewTextWriterWithSymbolWriter(); - for (var declarationIndent = aliasEmitInfo.indent; declarationIndent; declarationIndent--) { - increaseIndent(); - } - writeImportEqualsDeclaration(aliasToWrite); - aliasEmitInfo.asynchronousOutput = writer.getText(); - } - else { + 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 - aliasEmitInfo.isVisible = true; + moduleElementEmitInfo.isVisible = true; + } + else { + createAndSetNewTextWriterWithSymbolWriter(); + for (var declarationIndent = moduleElementEmitInfo.indent; declarationIndent; declarationIndent--) { + increaseIndent(); + } + + 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 1f7a8211dfc..1999c52e91a 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 b9bc5d96d41..384e458d4ba 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 5146cde791c..b659edba90a 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 012d635e4c5..12dffb8665f 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 4292108fc73..810bbe2aa18 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 8a3951bb19b..2e8e40442d4 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 ab2e05ac052..a4a3e304808 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 36eaccac6a8..18c4a3f70fe 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 99d84a928f8..f338788a8e4 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 00000000000..b41ca177b05 --- /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 00000000000..23176a0abe2 --- /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 00000000000..b246ba32ba4 --- /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/159] 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 aa10fb6e26f..ab7a3e205dd 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 3d404658e38..e2593a5d131 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 3613aaf5575..dd31e82901a 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 147c3b42296..edf84876964 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 fe1dc0dbce3..eb27c096951 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 3f0cc2acee8..5e3ddc43308 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 6394240a933..877ae6fab74 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 79f94a6c82c..fcb88d55b33 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 a5820672247..5e39ae7854d 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 c1a4b5d5e9e..9c383ab3e3b 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 69ed42ca35c..71f4af72178 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 a7827a5d56a..7852d2991bc 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 0464794ea89..9c3066b6fc1 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/159] 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 cccd74e3907..19a2f8121e9 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 6a2338268e8..deb8d92dcef 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 (isBindingPattern(node.name)) { + emitBindingPattern(node.name); } - 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); + 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 00000000000..088bb4e849f --- /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 00000000000..9f6f4c9857d --- /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 00000000000..818b3a6f7a9 --- /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 00000000000..2b40a388e3b --- /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 00000000000..84ab9f242e9 --- /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 00000000000..4852a7e37fb --- /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 00000000000..f19a4a840bf --- /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 00000000000..d6d0fa758d7 --- /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 00000000000..d94da79ad9a --- /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 00000000000..b3c422e4958 --- /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 00000000000..2c14e743039 --- /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 00000000000..cc2094c68f4 --- /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 00000000000..7e5a3d9d2fa --- /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 00000000000..68394686e31 --- /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 00000000000..c907add11f7 --- /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 00000000000..1c75466f0c3 --- /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 00000000000..83785e86f65 --- /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 00000000000..cfe4acc1733 --- /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 00000000000..7b8a70ae8f1 --- /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 00000000000..284cf107782 --- /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 00000000000..fc3dac87ae0 --- /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 00000000000..f116423715a --- /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 00000000000..9cdc6c2ec90 --- /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 00000000000..8f162e33da3 --- /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 00000000000..89e5b65a9d3 --- /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 00000000000..6a65c925465 --- /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 00000000000..f700e68e397 --- /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 00000000000..020a29ba219 --- /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 00000000000..597497feac0 --- /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 00000000000..c3785acd09a --- /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/159] 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 00000000000..e464b96a8bf --- /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 00000000000..fa3cae9478b --- /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 00000000000..987fb67a08b --- /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/159] Dts for export * from "mod" and export { a, b as c,...} [from "mod"] --- src/compiler/checker.ts | 14 ++-- 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, 652 insertions(+), 6 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 db8c9fc832d..b07c578c671 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[] = []; - buildVisibleNodeList(exportSymbol.declarations); - return result; + 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; function buildVisibleNodeList(declarations: Declaration[]) { forEach(declarations, declaration => { diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 9fc10185a04..e94c40cee91 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 00000000000..98d40006854 --- /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 00000000000..7b99a3819e2 --- /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 00000000000..dd83c31b72a --- /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 00000000000..99e8fde9d40 --- /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 00000000000..464839e03a4 --- /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 00000000000..27fc611692d --- /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 00000000000..f987b48aeca --- /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 00000000000..667a021466b --- /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 00000000000..7ac6946aedf --- /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 00000000000..69bb325ec75 --- /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 00000000000..3e412c13a32 --- /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 00000000000..de81cf3f74f --- /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 00000000000..ed2b47c23c4 --- /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 00000000000..ed754e5cacb --- /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 00000000000..a16e2c9e7aa --- /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 00000000000..675f302bcb6 --- /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 00000000000..22a6cef4203 --- /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 00000000000..6361c013367 --- /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/159] 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 13204ab22e8..17e1c82e955 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 c907add11f7..24b16a7742a 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/159] 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 24b16a7742a..c907add11f7 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 667a021466b..8caedfa5ceb 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 de81cf3f74f..c0087dccd94 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 49771928f11..23dfe51c53d 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 3a68df656fe..4a0abe853e0 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 ba036202a52..93bd55716a5 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 012caca48cf..f60644b2621 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/159] 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 9daa87daed4..06aa9fce359 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 a24e69e3005..347ce57034e 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 d9fdb511fa2..4ca0b4cd5f7 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 533843d2947..96df9812bc6 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 afcef6bbb5c..3cd522d3c2c 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 26a77e917d9..04fb5a143c6 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 7bd31c7ae53..a8edb4b1879 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 1ba54d47f1c..1b5cb877d21 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 231831518e6..d559e98dc3e 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 ecce65ba577..03456020c80 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 cb89d242a18..68804694449 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 4704b32d989..fc8d0420842 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 9ef2790b4ce..3572f3ecc41 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 315f7dd237b..95bc0b866c9 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 8a9e6549144..974e9930103 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 40676ef4495..0c30e8d0484 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 ddc2c87dd7a..60ea9af32c2 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 47093cd0852..94b8067ddd7 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 15aa6bcdd91..bbe622b3300 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 153068738d1..5f7048894fa 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 363d2f2a017..e2c9c90d375 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 f78f8990db0..81cfa752f5d 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 710af4edfa7..0bcf2fa3956 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 fffadcbc070..2c41d81cd6a 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 454fddf6fa8..1e56eb8bd9f 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 0dc8e508d45..3662f5d6ddd 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 c8bba8a4f77..7be17f085b0 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 e0c1f33cb4a..fc0323a89aa 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 aebacb88827..ae53d064178 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 af4f1bc1521..cef1d3e424e 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 61722df0fb0..5c71f717bb2 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 7d839e16ffb..a2fff2110b4 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 e104d33e7d3..0b6cb352999 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 c5ca0d5b241..55b08ef8301 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 27821647565..8e54d67238c 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 9c23dcab20d..01cf2efc030 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 5714fb747a6..ee1e1c85c06 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 ac77cc177b8..1276763505e 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 97559f05574..34f1e386a96 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 8ced6f9e595..5b1c6977472 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 2210f189d16..01025ed1806 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 15247ea4225..27cb376cc05 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 b87ab8298a7..0a17b300d3d 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 d7d67f28d50..34fe30a1f1c 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 874c177c4e6..5bf639d9cf1 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 a26bd0670f8..01439854259 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 24f65bc96a9..f56b1f300ed 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 7ded9416c11..1fb7eb65e36 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 eca92215fb6..25aec5a72d8 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 13b6da353b9..e5c9c6d29d4 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 67d9a020bb6..d463073bb81 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 ca13ceba4ae..14cad3cb53b 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 44aa2f90162..a8ecdf2470a 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 8e92cbbbda7..ed2a1f3926a 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 f9f71a3ff98..561461229c7 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 2d177731b95..80a4b88479f 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 e1d79ebeb92..c021eb8d47a 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 b0da96c4b6e..5dc5a475b40 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 902079c04c0..96d9ace576c 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 4c2a7df3c94..1ac82b0a3de 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 0c125b3d8b2..f81af2c4dda 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 ef9192c1c90..8d203e9fd71 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 7b9981d9733..a484e43738f 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 fe6b80292d5..791fc4fbd7f 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 32e1389232d..3db07d878bf 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 b2de46d677f..d7e596d2edc 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 15b9f5f12f6..2a5e4e32b94 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 7acdcc32536..1aabe9cfa2b 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 ca28878daa3..36566033a48 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 29293f880ed..005681b6285 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 96794e3c956..09c0b3ae490 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 590815ffec5..e3e843a45da 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 21411e09ff1..8cabdeabe49 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 1037df1769e..edaebbd38a2 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 a7605dd52bc..90c0d257d61 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 b5c68ea5c16..6400cf26ddc 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 e21dd355322..f2223b197e0 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 3d60e055ede..afd6597869b 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 f050d6f9a55..acd3f4c61b1 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 e4dc73b2403..96e17c6f6e3 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 e81093147e8..b224c22f45e 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 b9bb9e12ced..dfdd0600ed0 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 1feba71212d..dc846900ebb 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 819bf114cec..a0ed1b4f98a 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 40b83d329c1..1ce03d1382a 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 658ebc7e1ca..409df03ef37 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 6a4f1ceabc1..45ecdc4745e 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 89ee1a14833..382cf577713 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 1e9254bb0bb..962346541cc 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 574ef6fa2d0..57b6e8051f8 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 a7580e97ef7..afc1ce23e37 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 a2957cb9582..f4655513bec 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 77458f442df..e33e7811077 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 91dbcae730c..8451a1426a6 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 5185a9b8db8..6d91d8eb838 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 c32cd84ce26..646a3474536 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 adbb9caeada..87057754cab 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 f6b4fd240b2..4d52dbb234c 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 8bd9d128233..3b71eee5e49 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 22946153449..9a49b145954 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 5810ffc0620..a29226fbd1d 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 768e35c1a3b..2ddc7a8dce2 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 8deae79f5e2..4312cb38517 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 0dbe7dfef40..c41f88bc9c2 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 cfe6800fcf5..38e9028297b 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 1ce6036d5ce..39bd1777f6f 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 c3c5ba3a7af..9093787a6fc 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 9dae3ce7ce9..f3b8da0de82 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 54f018fe475..e73e398d437 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 d2f051bf331..11cd8c260b7 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 735c8d3908f..9295ce43b26 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 471787f43ee..b2332345712 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 1627788c6b6..4729c3749b3 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 337aa0989d3..9d8b36ca5ed 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 7d739132a77..7fe3d28278b 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 df4511fb7ad..e1c137f77e4 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 0cf0dd92402..c31a52bff45 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 8e2445d249c..4d040cfe13f 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 388c6250aef..b8286fac713 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 900b610cef4..2e2963b0955 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 7daf873c324..bc070c9655b 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 1d733882800..4cb975c42e4 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 896e888b28f..46ef3807464 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 ec15502afa4..e81a5fd1ecb 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 478ac85651b..d11245b3475 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/159] 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 8908501593c..135cecca730 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 8947314a6f6..fc5479144eb 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/159] 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 fc5479144eb..15b51ea2068 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/159] 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 15b51ea2068..8047d911ca7 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/159] 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 8047d911ca7..db1cdee432c 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/159] 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 00000000000..b7fe4f0cda7 --- /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 00000000000..96e9f25549e --- /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 00000000000..4f57c6345cf --- /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 00000000000..c121f936dbb --- /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 00000000000..5d4a4fff6d6 --- /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 00000000000..4e4673a228f --- /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 00000000000..c443c0f0cfa --- /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 00000000000..38031711378 --- /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 00000000000..b0809ab57b8 --- /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 00000000000..63bec899622 --- /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 00000000000..776d0b45847 --- /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 00000000000..dd97cfc85f3 --- /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 00000000000..18ff3fa424d --- /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 00000000000..458a4bd3328 --- /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 00000000000..7a040649d74 --- /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/159] 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 db1cdee432c..fa3854f1592 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 00000000000..7877c957b29 --- /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 00000000000..359e58a4b32 --- /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 4f57c6345cf..8f65c8f9fdb 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 00000000000..2409ebc0b66 --- /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 00000000000..0f546fa7b86 --- /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 00000000000..389d18d37a3 --- /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 00000000000..f410340b509 --- /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 c443c0f0cfa..fd8a3079f8b 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 38031711378..f26a9f87e6d 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 00000000000..252a44122eb --- /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 00000000000..3017908e576 --- /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 00000000000..179818387da --- /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 00000000000..6f59f8220ad --- /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 b0809ab57b8..00000000000 --- 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 63bec899622..00000000000 --- 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 00000000000..69801d6be12 --- /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 00000000000..8b0feb72d2b --- /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 00000000000..4e2872b4f06 --- /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 00000000000..8081d044e35 --- /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 00000000000..9e06636da7e --- /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 00000000000..c27723e3391 --- /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 00000000000..519af626850 --- /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 458a4bd3328..c5d95bc6cb1 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 00000000000..e1b277fae51 --- /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 00000000000..20c251b2cfa --- /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 7a040649d74..00000000000 --- 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 00000000000..945b2101012 --- /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 00000000000..078356f6f15 --- /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/159] Emit class declaration with static property assignment --- src/compiler/emitter.ts | 13 ++++++++--- ...DeclarationWithPropertyAssignmentInES6.js} | 4 ++-- ...larationWithPropertyAssignmentInES6.types} | 2 +- ...rationWithStaticPropertyAssignmentInES6.js | 23 +++++++++++++++++++ ...ionWithStaticPropertyAssignmentInES6.types | 18 +++++++++++++++ ...DeclarationWithPropertyAssignmentInES6.ts} | 0 ...rationWithStaticPropertyAssignmentInES6.ts | 9 ++++++++ 7 files changed, 63 insertions(+), 6 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 fa3854f1592..d4434c9bf4b 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4677,10 +4677,17 @@ module ts { writeLine(); emitConstructorOfClass(node, baseTypeNode); emitMemberFunctionsAboveES6(node); - writeLine(); - scopeEmitEnd(); decreaseIndent(); - write("}"); + 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 + // 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 8f65c8f9fdb..03fb45b806e 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 c121f936dbb..5e7ebbc167c 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 00000000000..69da64765a3 --- /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 00000000000..6003b85b590 --- /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 00000000000..7ed36bb22a2 --- /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/159] 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 d4434c9bf4b..606bd22f2c9 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 00000000000..11b1de11bf6 --- /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 00000000000..5a6c84389f3 --- /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 00000000000..f3ed5eb95d8 --- /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/159] 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 0d32c605fdc..b97e4a2ea54 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 afcf12fed1b..9f120edbf8a 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 b06a283a876..8937c7a4a98 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 b265f5b5281..88801c8243d 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 3925cdff747..391fbf42384 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 5b88697fd4f..2eb1bcf8bd8 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 23200e50ee4..94aff02b635 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 00000000000..9b354ebf14d --- /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 00000000000..47cfd288632 --- /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 00000000000..7df85a31d75 --- /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/159] 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 9f120edbf8a..f13b863b160 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 8937c7a4a98..fe89b8528e9 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 88801c8243d..56a6cd2b052 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 00000000000..d667423703e --- /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 00000000000..7d603282b0c --- /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 9b354ebf14d..74d102f1865 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 00000000000..f1f2cce9923 --- /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/159] 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 00000000000..98a68870833 --- /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 00000000000..3c8461fba2b --- /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 00000000000..3d6dab17785 --- /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 00000000000..3ba19cef9b4 --- /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 00000000000..a5abd986ee8 --- /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 00000000000..d4b69e8bcf4 --- /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 00000000000..7d3bdcec94c --- /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 00000000000..9dd243ff36d --- /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/159] 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 f13b863b160..a43d2917735 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 00000000000..cd2d5ef6922 --- /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 00000000000..cd72f35c8bf --- /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 00000000000..e896a1a88a1 --- /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 00000000000..332be6074ad --- /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 00000000000..524860827e6 --- /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 00000000000..a2739175770 --- /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 00000000000..16d11d4e19f --- /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/159] 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 fe89b8528e9..8e70828e144 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 56a6cd2b052..86fc37fab2f 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 9b933cacf74..a97da0dac13 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 94aff02b635..a5f5b1d0f24 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 00000000000..f4757b539eb --- /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 e275fc52439..e3453587a12 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 00000000000..b4ca020f566 --- /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 661ab2e7cdd..721df9afe58 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 00000000000..25e64fc72d0 --- /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 00000000000..4f663875ade --- /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 00000000000..b9a5efdfd4a --- /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 00000000000..afbab4d0610 --- /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 00000000000..4214f69eca1 --- /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 d667423703e..32d54110396 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 85390ecce4b..c07a84bb810 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 d8d1fa8111d..630f601fbae 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 bd8714cb86f..c755b8207e7 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 a7402bfeb6a..a79a6665067 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 98371eb9198..851a5189a54 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 5ec91279306..1241140b121 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 74d102f1865..41c3bc0eef4 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 c6daa3b1222..87c9b9fa90f 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 c52499ef994..05ab441a690 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 43d21885c27..2f35122571f 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 1cd7df9962e..3cc5067891a 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 00000000000..111d8fe2030 --- /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 62815911f7f..93910200215 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 00000000000..18cd37c7351 --- /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 00000000000..90768d474d1 --- /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 00000000000..e00768eafd1 --- /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 00000000000..06cf44b4d50 --- /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 00000000000..051c77f808e --- /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 00000000000..31720bddbcb --- /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 00000000000..c9504ef9fcb --- /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 dc5b4ab98d6..9e779e8664d 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 96b277d6640..20f0f122e99 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 3d029e28738..3e2cdd34092 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 9937606c41f..58ef52daf53 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 ed34434bd29..df5de478975 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 e1be293e446..ea1ed5cbff6 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 a836acc1140..26bd9b69153 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 2cc21dad746..9eb3ccba82a 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 70a15a9bc54..0a38cda093c 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 00000000000..33d70cd133f --- /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 00000000000..9521ec6cbdb --- /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 00000000000..616a375d970 --- /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/159] 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 00000000000..030b0d11c7b --- /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 00000000000..765d09fae79 --- /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 00000000000..91d51d5f7ef --- /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 00000000000..15d4c7f2fc9 --- /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 00000000000..bc66ab817ac --- /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 00000000000..7f67628c18e --- /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 00000000000..d6aacf0ba40 --- /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 00000000000..628faec6c27 --- /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 00000000000..a6aaf9f5508 --- /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 00000000000..f824dbf71d5 --- /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 00000000000..b9461b6caca --- /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 00000000000..fad411f557d --- /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 00000000000..57a77410cb2 --- /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 00000000000..da473fa42a3 --- /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 00000000000..a0d88a5cf8c --- /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 00000000000..2be3f67f1e9 --- /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 00000000000..c1ac752426e --- /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 00000000000..a84dab94033 --- /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 00000000000..81113b776b4 --- /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 00000000000..cd1bad83716 --- /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 00000000000..5ab1c743721 --- /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 00000000000..54e30be1e23 --- /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 00000000000..bd507308d8d --- /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 00000000000..22b250435c8 --- /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/159] 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 4b038ab1c4c..7c435176b9c 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 7d603282b0c..4a4e0368bb7 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 765d09fae79..2c234b60ae8 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 1241140b121..a67436de60c 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 7f67628c18e..f2a31d6c662 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 47cfd288632..5195bdc631b 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 f9d8e90f707..4b60b26f88d 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 2f35122571f..99d12a4107e 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 a0d88a5cf8c..c676222ce81 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/159] 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 7c435176b9c..8f79c036dfd 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 2c234b60ae8..bd6d6013c05 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 a67436de60c..3f11e5076ef 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 f2a31d6c662..9872df4ed5a 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 4b60b26f88d..5d80a3d7a8c 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 99d12a4107e..cf0713d4ec5 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 c676222ce81..e63dd4bb53a 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/159] 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 8f79c036dfd..c1e0b24e405 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) { + if (compilerOptions.target >= ScriptTarget.ES6) { + emitES6Module(node, startIndex); + } + else if (compilerOptions.module === ModuleKind.AMD) { emitAMDModule(node, startIndex); } - else if (compilerOptions.module === ModuleKind.CommonJS || compilerOptions.target < ScriptTarget.ES6) { - emitCommonJSModule(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 7acc95ad055..0d70eb86000 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 90768d474d1..fd0c07ecdc4 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/159] 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 a43d2917735..935e82c5bd0 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 c1e0b24e405..84312ef3be3 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 a97da0dac13..d6160e1bee8 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/159] 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 935e82c5bd0..a9b42e31090 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 84312ef3be3..ffdea4c71fb 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 0d70eb86000..6934658920c 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 630f601fbae..53b122a12ca 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 a79a6665067..12f64528164 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 3f11e5076ef..425fc0bd778 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 87c9b9fa90f..86ac02be37a 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 05ab441a690..76627d4aaff 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 5d80a3d7a8c..010e84ed8a4 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 cf0713d4ec5..194ce8f9715 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 111d8fe2030..56c5264c053 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 fd0c07ecdc4..36df01dc237 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 06cf44b4d50..fbcebbd9d0d 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/159] 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 a9b42e31090..1e0976c31a0 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 010e84ed8a4..8c971cc77d2 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/159] 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 ffdea4c71fb..3558c60d66a 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 6934658920c..313ce3db21a 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 53b122a12ca..c7a320b76aa 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 12f64528164..d7196f86eaa 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 425fc0bd778..1ba095221dc 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 86ac02be37a..4f03e9a0ae2 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 76627d4aaff..7993af7fb07 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 8c971cc77d2..81f141b3dd8 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 194ce8f9715..9666409b924 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 00000000000..51df62059a3 --- /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 00000000000..cceb74a5e1e --- /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 00000000000..36633087332 --- /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 00000000000..4b30c89cc81 --- /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 00000000000..aefb8720e9c --- /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 00000000000..a10d8f6cacb --- /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 00000000000..42bf24698a9 --- /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 00000000000..fc5dfc94bd5 --- /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 00000000000..a3ae29fbe6a --- /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/159] 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 3558c60d66a..e4af747950c 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 00000000000..c2cd962408b --- /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 00000000000..c3dcb4095e3 --- /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 51df62059a3..2a11ec638a1 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 36633087332..275fd39579e 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 00000000000..1e3716ac8c2 --- /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 00000000000..c174fe6f8c7 --- /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 aefb8720e9c..11b60555b0d 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 00000000000..99868f6087b --- /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/159] 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 135cecca730..28b3b74b271 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 24ed8ce4e99..a8b41e2159d 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 40f7d55f9f0..489c929821d 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 00000000000..f078365f600 --- /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 00000000000..f7506d7904d --- /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 00000000000..4cd9047581f --- /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/159] 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 e4af747950c..7c367f2f845 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 00000000000..c8096c76c8e --- /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 00000000000..fae819f93b0 --- /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 00000000000..5ec953aca88 --- /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 00000000000..c43a938c9b6 --- /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 00000000000..955fe3ed8d3 --- /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 00000000000..4b856fee009 --- /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 00000000000..c3490093d3e --- /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 00000000000..6dddea09d8a --- /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 00000000000..a0cebde9947 --- /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/159] 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 7c367f2f845..011a09ee64e 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 00000000000..4c1fc33647c --- /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 00000000000..b1252c1e8bc --- /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 00000000000..82eebb1580e --- /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/159] 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 011a09ee64e..b114ffda86c 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 c2cd962408b..00000000000 --- 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 c3dcb4095e3..00000000000 --- 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 56c5264c053..6c2e87fff1d 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 00000000000..5ad7da0e8b2 --- /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 00000000000..09d50c4e542 --- /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 36df01dc237..075cc28e82c 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 fbcebbd9d0d..de66fd0023b 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 00000000000..3b36e53037f --- /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/159] 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 b114ffda86c..7e69d8edb71 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 00000000000..4a1659cb901 --- /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 00000000000..50db69d8edb --- /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 00000000000..24e209a87f6 --- /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/159] 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 7e69d8edb71..af7b0963643 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 00000000000..be58b3ff81e --- /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 00000000000..99e8fde9d40 --- /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 00000000000..9fd8c1c4b33 --- /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 00000000000..99e8fde9d40 --- /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 00000000000..03b49dfbd2a --- /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 00000000000..24b9859e0e8 --- /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 00000000000..ab3087dc621 --- /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 00000000000..c0087dccd94 --- /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 00000000000..ed2b47c23c4 --- /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 00000000000..ed754e5cacb --- /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 00000000000..a16e2c9e7aa --- /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 00000000000..22a6cef4203 --- /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/159] 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 28b3b74b271..689f27af867 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 0d6f002a3da..7658a49bc48 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 00000000000..04ac8b28a8b --- /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 00000000000..2a8d75dde60 --- /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 00000000000..b2517d89657 --- /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 e785f1cdf00..87c0c3701f3 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/159] 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 b7fe4f0cda7..4cf96778f3f 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 96e9f25549e..850a5aa5456 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 252a44122eb..00000000000 --- 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 3017908e576..00000000000 --- 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 179818387da..00000000000 --- 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 6f59f8220ad..00000000000 --- 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 9e06636da7e..e6c71b06740 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 f3ed5eb95d8..c7fd43cb9e2 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 519af626850..9b79d1b003b 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 e1b277fae51..00000000000 --- 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 20c251b2cfa..00000000000 --- 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 00000000000..f78e012bc20 --- /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/159] 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 606bd22f2c9..a0303610a3d 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 00000000000..de100457aa9 --- /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 00000000000..ebb6f26598d --- /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 f78e012bc20..4356fcce2ab 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/159] 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 1e0976c31a0..7911c14e0de 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 af7b0963643..a52daa51237 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 00000000000..3ac92c5d9ea --- /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 00000000000..34fb87fcbb2 --- /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 00000000000..8c07ff12599 --- /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 00000000000..e4c7a59e0e7 --- /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 00000000000..f0c3da6657b --- /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 00000000000..2f4e2b57284 --- /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 00000000000..01576743581 --- /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 00000000000..446bd8e2a31 --- /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 00000000000..6a99726655f --- /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 00000000000..1b9f9d26151 --- /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 00000000000..7a4fdf52e88 --- /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 00000000000..0c3a601308b --- /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 00000000000..89197aca632 --- /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 00000000000..04a34b1e23b --- /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 4a4e0368bb7..113e28108b1 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 00000000000..0eacb0a4995 --- /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 00000000000..59e74fc1257 --- /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 00000000000..3f7996ad9f6 --- /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 00000000000..513cacf05e4 --- /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 00000000000..e0d91043766 --- /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 00000000000..3b056b8d9f9 --- /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 00000000000..fafc5a114f5 --- /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 00000000000..6179bde9613 --- /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 00000000000..2071e56c539 --- /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 00000000000..3cb2fc9b1cd --- /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 00000000000..5785220dfee --- /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 00000000000..81dc168efd0 --- /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 00000000000..713517c87af --- /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 00000000000..d51f8740da0 --- /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 bd6d6013c05..3c8a4080ba7 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 9872df4ed5a..927ed3243e7 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 5195bdc631b..b8e9777a894 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 00000000000..bea07832cd5 --- /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 00000000000..e7ae24f5d87 --- /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 00000000000..772998decef --- /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 00000000000..ef9da753ab0 --- /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 00000000000..2b8a99a3817 --- /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 00000000000..8f34253208e --- /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 00000000000..5016bdb7b1b --- /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 00000000000..3d731753ee4 --- /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 00000000000..7092d15ef52 --- /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 00000000000..ef476210541 --- /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 00000000000..19984bde2a6 --- /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 00000000000..022fbd81233 --- /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 00000000000..1590677d4ce --- /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 00000000000..5dfc98b4c93 --- /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/159] 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 7911c14e0de..033121a99bc 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 8e70828e144..a27e159cdff 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 86fc37fab2f..da5a02e4eea 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 a5f5b1d0f24..3d5319f9a2f 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 41c3bc0eef4..1f30b7002fa 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/159] 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 e325b2033e7..af496db7ded 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 1500a47f197..a8713c50afc 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 d40fcd25ce0..5d3bafc45a7 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 c4121e92251..779e3891766 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 6e444eb23c7..d76385ff9c0 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 7301e087ae1..a893c36c359 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 1f87ae40745..e3d8fa9256e 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 6e6adb2cd45..abe0700f66b 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 17ce175ebdf..088424863e8 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 4f1fc899a89..f24be65ecb9 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 d1dcad98d85..cafe25ed5bc 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 3ef3d7bc0f5..2ce87d5c9ef 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 4bfac42f571..afc61a39fdf 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 c85be654c89..b1124e6c64f 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 e4b53feeac0..36958c9320d 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 00000000000..fa7806a17dd --- /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 00000000000..8adf31a5f18 --- /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 00000000000..2c918954702 --- /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 00000000000..53ca78586cc --- /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 00000000000..326713e059e --- /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 00000000000..069c8385e77 --- /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 00000000000..d7fd24d5be3 --- /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 00000000000..ddb317bd8fc --- /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 00000000000..88a45de2d32 --- /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/159] consider binding elements as always initialized with doing shadow check --- src/compiler/checker.ts | 65 +++++++++++-------- ...ngViaLocalValueOrBindingElement.errors.txt | 28 ++++++++ .../shadowingViaLocalValueOrBindingElement.js | 31 +++++++++ .../shadowingViaLocalValueOrBindingElement.ts | 10 +++ 4 files changed, 107 insertions(+), 27 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 782ffccc0ed..000ee35d21f 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; + // skip block-scoped variables and parameters + if ((getCombinedNodeFlags(node) & NodeFlags.BlockScoped) !== 0 || isParameterDeclaration(node)) { + return; + } - // 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); + // 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; + } - // 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); - } + 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 00000000000..663f83c1ffb --- /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 00000000000..8d6319f5ea7 --- /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 00000000000..9afeb79aa79 --- /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/159] Clean up diagnostic timers and -diagnostic output --- src/compiler/program.ts | 52 +++++++++++++++++++++++------------------ src/compiler/tsc.ts | 39 ++++++++++++------------------- 2 files changed, 44 insertions(+), 47 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 9b933cacf74..eda6833e771 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 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 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 ensureDirectoriesExist(directoryPath: string) { - if (directoryPath.length > getRootLength(directoryPath) && !directoryExists(directoryPath)) { - var parentDirectory = getDirectoryPath(directoryPath); - ensureDirectoriesExist(parentDirectory); - sys.createDirectory(directoryPath); - } - } - 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 e9c5e17c751..3f82d6c8cf5 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/159] 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 8947314a6f6..a592c033c22 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/159] 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 663f83c1ffb..4fc1d47c383 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 8d6319f5ea7..76c4a7ac3a6 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/159] 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 0dacb20ece4..957a3e3630a 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/159] 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 957a3e3630a..44178aed74b 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 c43591911ab..5880dfdce92 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 98571823181..d08d0b3fcc2 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 087c0389d0f..df0c57444b0 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 d43d6220072..fb390d78f8f 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 14eb2936242..90360b5fe61 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 bfe62135a0d..96b54ccd917 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 baa497c95fa..999c81af401 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 ee1fd062515..8a3d2065a23 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 a8b534439d5..f66c818c53d 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/159] 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 44178aed74b..0d29e928e31 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/159] 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 0d29e928e31..21707940a5a 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/159] 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 00000000000..49b2c48fbe2 --- /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 00000000000..c15f22fc974 --- /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 00000000000..170bd711b61 --- /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 00000000000..d6bd1b3b271 --- /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 00000000000..6a7975b4b62 --- /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 00000000000..1b97f04953e --- /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 00000000000..89be3c06c64 --- /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 00000000000..4b5370cfc1c --- /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 00000000000..7efab1f62c5 --- /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 00000000000..61158ae9738 --- /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 00000000000..7ab2502e02c --- /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 00000000000..3eb7d07bc3c --- /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 00000000000..3d8536ab4cf --- /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 00000000000..c05b26fd2fc --- /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 00000000000..f4f001c9f27 --- /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 00000000000..1bf4169624d --- /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 00000000000..8fa501906b8 --- /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 00000000000..a74eb042692 --- /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/159] 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 7f89ff6153b..fc02c3f3eef 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 00000000000..0450903f717 --- /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 00000000000..c98b6a89d4f --- /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 00000000000..316ff92c56c --- /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/159] 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 0dacb20ece4..dae254253ca 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 d40fcd25ce0..556df1565b0 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 c4121e92251..0c00d8c974c 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 fc02c3f3eef..06655b1d822 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 c43591911ab..56820a10924 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 98571823181..316649a35c9 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 087c0389d0f..bf51bb946c0 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 d43d6220072..5f7dc308820 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 14eb2936242..ede73749eb0 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 bfe62135a0d..2d39e9a3c0c 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 baa497c95fa..d9d1482fbc8 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 ee1fd062515..7fa2a92afae 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 a8b534439d5..23f7ffb7148 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 0450903f717..c64d42b7fff 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. + ~~~~~~~~~~~ +!!! 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 c98b6a89d4f..2619b41bf38 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/159] 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 c64d42b7fff..e9f07998504 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 2619b41bf38..122c229d7d9 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 316ff92c56c..f11fed6b478 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/159] 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 dae254253ca..8322bb7c5d3 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 06655b1d822..6b010f584a2 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 56820a10924..49529bed9c6 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 316649a35c9..997bd2bd337 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 bf51bb946c0..d91d860ca8f 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 5f7dc308820..b941acdbc52 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 ede73749eb0..b8701020e03 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 2d39e9a3c0c..baf3f9d8503 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 d9d1482fbc8..d214a6fc959 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 7fa2a92afae..d963aaff481 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 23f7ffb7148..da00b9bf466 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 e9f07998504..e441752338c 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/159] 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 8322bb7c5d3..d0c9ff87140 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/159] 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 d0c9ff87140..df1b70ab6ff 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 6b010f584a2..5756f379685 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 49529bed9c6..25a8ce75245 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 997bd2bd337..6244dc73951 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 d91d860ca8f..43e88c27e41 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 b941acdbc52..fd4649f614d 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 b8701020e03..984b59ca7ee 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 baf3f9d8503..4222e1b2d98 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 d214a6fc959..bea3f1e7231 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 d963aaff481..0928c2cf139 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 da00b9bf466..4498a5538e4 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/159] 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 5756f379685..eb43f774605 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/159] 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 eb43f774605..f996af5f5e4 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/159] 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 df1b70ab6ff..be1b6f943ca 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 e441752338c..fbd9be772fa 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 122c229d7d9..610cbe62c1b 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 f11fed6b478..bd984ba4da0 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/159] 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 689f27af867..feb95b4da16 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 a0303610a3d..96c34ae743d 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 7658a49bc48..5a07b22153d 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/159] 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 be1b6f943ca..03a4ee6d04a 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 f996af5f5e4..27f550778c1 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/159] 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 1ce946493b0..e59996c0781 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/159] 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 96c34ae743d..b3b305dd6c4 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/159] 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 06eaa481dfb..c6463aba733 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 00000000000..a8fe854fa28 --- /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/159] 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 c79ca2f1fd2..66f31790028 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 5d3bafc45a7..e3bb7aa8f43 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 779e3891766..3c8ecadee02 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 fa7806a17dd..472dc0c74c1 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/159] Update baselines --- src/compiler/emitter.ts | 9 +- .../baselines/reference/callWithSpreadES6.js | 37 +++--- .../reference/computedPropertyNames12_ES6.js | 9 +- .../reference/computedPropertyNames13_ES6.js | 49 ++++---- .../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 | 40 +++---- .../emitDefaultParametersMethodES6.js | 37 +++--- .../reference/emitRestParametersMethodES6.js | 30 +++-- 48 files changed, 454 insertions(+), 970 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index b3b305dd6c4..a079994e5c8 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 0becb4c6e3e..d1589d7f6fa 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 5ab6e4c09b3..fd6ccb6e486 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 07aa1673aba..18d81fcec59 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() { +class C { + [s]() { } - 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; -})(); + [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 7a58ad9a80a..b1b2a9bf285 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 70c2e7b451c..1a9141ab13d 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 90f15f6cf2e..96e175976da 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 e9b19202e08..a181a61004e 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 f51f6faed24..c5f6b4e22b1 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 9872605c20e..c88ceb6bc8f 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 f5687952b88..0bae1abdad2 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 12aef633963..8d33db10f71 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 1a600df5040..cc6a0670b21 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 fc53d91e627..4526368de7a 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 54a20a52200..57589dfcaf5 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() { +class Base { +} +class C extends Base { + [(super(), "prop")]() { } - return Base; -})(); -var C = (function (_super) { - __extends(C, _super); - function C() { - _super.apply(this, arguments); - } - 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 09e1b33bf98..bc0e32593de 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 e1e6be51b21..35958b372b0 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 e5fcfaac8f9..4287cb2c4b8 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 c88fa98be5e..cda2a278d47 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 33f5319ded9..777e03bbcac 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 a87f7715d89..198c5e9981e 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 03c503caec4..7fb08d2852d 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 62e2e151cd3..e73d349bcd7 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 5b71326fbc4..573b8fa0c17 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() { +class Foo { +} +class Foo2 { +} +class C { + // Computed properties + get ["get1"]() { + return new Foo; } - return Foo; -})(); -var Foo2 = (function () { - function Foo2() { + set ["set1"](p) { } - return Foo2; -})(); -var C = (function () { - function C() { - } - 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 992035f6865..d62c95e6f8c 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() { +class Foo { +} +class Foo2 { +} +class C { + // Computed properties + get ["get1"]() { + return new Foo; } - return Foo; -})(); -var Foo2 = (function () { - function Foo2() { + set ["set1"](p) { } - return Foo2; -})(); -var C = (function () { - function C() { - } - 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 0fdcdb1d63c..cf1d01873f2 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() { +class Foo { +} +class Foo2 { +} +class C { + // Computed properties + get [1 << 6]() { + return new Foo; } - return Foo; -})(); -var Foo2 = (function () { - function Foo2() { + set [1 << 6](p) { } - return Foo2; -})(); -var C = (function () { - function C() { - } - 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 8e458ad83d7..9afd60b6464 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() { +class Foo { +} +class Foo2 { +} +class C { + // Computed properties + get [1 << 6]() { + return new Foo; } - return Foo; -})(); -var Foo2 = (function () { - function Foo2() { + set [1 << 6](p) { } - return Foo2; -})(); -var C = (function () { - function C() { - } - 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 3df6d6d9744..b9009112347 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 1a9c9ee465b..b5fb9e88001 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 99d28688a29..c4820e0ca98 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 f0c386706a3..5773f892fd5 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 8538088f450..b6114f06bac 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 ba0c228c307..ab9d09834d2 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() { +class Foo { +} +class Foo2 { +} +class C { +} +class D extends C { + // Computed properties + get ["get1"]() { + return new Foo; } - return Foo; -})(); -var Foo2 = (function () { - function Foo2() { + set ["set1"](p) { } - return Foo2; -})(); -var C = (function () { - function C() { - } - return C; -})(); -var D = (function (_super) { - __extends(D, _super); - function D() { - _super.apply(this, arguments); - } - 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 72729054e07..13d46131e92 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() { +class Foo { +} +class Foo2 { +} +class C { + get ["get1"]() { + return new Foo; } - return Foo; -})(); -var Foo2 = (function () { - function Foo2() { +} +class D extends C { + set ["set1"](p) { } - return Foo2; -})(); -var C = (function () { - function C() { - } - 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); - } - 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 23dccc77956..bea5f5211ea 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() { +class Foo { +} +class Foo2 { +} +class C { + get ["get1"]() { + return new Foo; } - return Foo; -})(); -var Foo2 = (function () { - function Foo2() { +} +class D extends C { + set ["set1"](p) { } - return Foo2; -})(); -var C = (function () { - function C() { - } - 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); - } - 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 eb7dab0b660..f234ae0d97e 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 3912113905c..b5e70193b0d 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 264a6a75074..ced0a8d449a 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 c47fcfcad31..3457187e78a 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 df0af71fb02..be0f79edd17 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 f7dc9e17836..749ab99b18b 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 20765a5b2d4..ff47df55493 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 64713447e43..36535c1aa4f 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"]) +1 >Emitted(4, 5) Source(4, 5) + SourceIndex(0) name (C["hello"]) +2 >Emitted(4, 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 > 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 f8fbc47312b..b144b4f83a5 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 5a54e915713..7d3269c6683 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 6da6f53a4fe..cd6334c8568 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 () { - return this.b; - }; - C1.prototype.getC = function () { - return this.c; - }; - return C1; -})(); -var C2 = (function (_super) { - __extends(C2, _super); - function C2() { - _super.apply(this, arguments); } - C2.prototype.doSomethingWithSuperProperties = function () { + getB() { + return this.b; + } + getC() { + return this.c; + } +} +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 bf96e00e375..3981ddcba3c 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 d0a0e2a120c..fba6ed01e67 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/159] 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 | 66 ++++++++++--------- ...efaultBindingFollowedWithNamedImportDts.js | 10 +-- ...aultBindingFollowedWithNamespaceBinding.js | 2 +- 4 files changed, 42 insertions(+), 37 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8f76a4392fc..8bead03a49b 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 67dbb375fdf..363f547477b 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,35 +5262,43 @@ 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) + }; + } } - return { - rootNode: node, - namedImports: importClause.namedBindings, - localName: resolver.getGeneratedNameForNode(node) - }; } - return { - rootNode: node + else { + return { + rootNode: node + }; } } else if (node.kind === SyntaxKind.ExportDeclaration) { @@ -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 15d4c7f2fc9..a6b2c9a1670 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 1ba095221dc..2b24fda0755 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/159] 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 00000000000..34b39cda4b7 --- /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 00000000000..9b067ef27a4 --- /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 00000000000..fc1e1a1925c --- /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 00000000000..ad58abd8125 --- /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 00000000000..00166b1bc41 --- /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 00000000000..dfbc8c0be07 --- /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 00000000000..b82fb1155e9 --- /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 00000000000..3068fb6d39d --- /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 00000000000..3b09108bbfc --- /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 00000000000..708cffca29d --- /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 00000000000..85e06b8c99d --- /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 00000000000..4700782b78e --- /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 00000000000..db076b87c9a --- /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 00000000000..732f7ef7ba0 --- /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 00000000000..1f026af8f34 --- /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/159] 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 65ac7119fb6..958e621c8aa 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 74e34c2b2ae..2b4846ec8be 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 526dc277be7..1cdf72c26ac 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 268ead7ee18..3fb4fac91d6 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 3be876409dc..ae3a9e130f0 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 eefb9339f18..d0f95caa1e2 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 39b1081954b..c098abd2f73 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 5deaad3c2d8..27da28e3b4f 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 d38accb6cd8..886e8dba7c3 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 87bb1fd428d..f5649128c11 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 86c175f861e..2c85a4dc2fd 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 edb6b4c38b2..e048caf1006 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 379b95c5b09..8b44ca03ef4 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 79b1590e12f..69c8ccab727 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 759c7823e63..0ed6caaf81e 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 6773c8a3452..d38c1fa017d 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 f3a75eec137..66097f777c8 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 521b4f3c2a4..568a9f73535 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 cb6dc0e532f..a157d5e2e8e 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/159] 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 5b4e44f11ab..74bcf886461 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 83a380c79e7..97fa4fc992f 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 9f63f86bc18..474ec4a0ffa 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 1cf24a49c7e..d7620d01159 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 0283cb01b79..716bc68b430 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 0c198037093..dec61964252 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 1a1f3f857af..1382d913104 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 b3291ad34e8..3210f6dfed7 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 b5d059dd29f..3d582d80254 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 c932da1e3eb..33c398a6c0e 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 9e98027603d..837ef5837b0 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 f19d05233cb..d4eb6fcafa7 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 57c826cb7ab..ed53a88f957 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 da6afdc6420..759a7754826 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 af151e0efd5..263fdc1041b 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 e8388225dd7..a9db50061b3 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 b544c60da7e..52db43bb9de 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 082c0fe7e65..8a0e3f691b5 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 de7d722227b..b8bcd54487f 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 18551d20c0b..6454d4a983f 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() { +class C { + [Symbol.iterator](x) { + return undefined; } - C.prototype[Symbol.iterator] = function (x) { + [Symbol.iterator](x) { return undefined; - }; - C.prototype[Symbol.iterator] = function (x) { - return undefined; - }; - return C; -})(); + } +} diff --git a/tests/baselines/reference/symbolProperty40.js b/tests/baselines/reference/symbolProperty40.js index 15d8c5c6fba..cf5a3c4396d 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 d26b2c7682a..fd9d58082b6 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 1990f54066c..082e862f0fc 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 fcb1fd3f8e5..fdeb52ca893 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 d4824e79318..a3de33640af 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 d056aba9f56..97b1252b825 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 255fbac0809..1d4a373f03c 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 92429c720c1..7c6886f280b 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 b0dc2b46dba..283c3d0d2c5 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 ea6e6f2c523..027b76f76d1 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 0a668e95509..30c911e8fab 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 b3b9902fcd6..a9a79098424 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 114999dc873..311baf2c187 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 42d19616ce3..b833eecff32 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 f97a1d44a21..e6c8f7299a9 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/159] 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 7877c957b29..8c115b17e9c 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 359e58a4b32..10244bf6170 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 2409ebc0b66..cd217af6a81 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 389d18d37a3..5c64aebd16a 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 f410340b509..a1549be5df4 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 5d4a4fff6d6..55d72a8b8d5 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 fd8a3079f8b..20f58b4274e 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 16d208db5eb..7c3b39b9d86 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 c9c819eefa2..8af17c95815 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 49ff8b35976..9a75f6d573c 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 51b6edcece5..f48a918a6f2 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 d81bc329927..6197ffa2b4f 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 2112f9e7748..5558bebc64e 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 6d06c09bd69..6f513b053c7 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 cd3fc53a5bb..14f50a03ee7 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 22ce6831f00..95ab43743ae 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/159] 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 21707940a5a..bb866c6b8cb 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 5880dfdce92..403c96b239b 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 d08d0b3fcc2..e2c0341d5dd 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 df0c57444b0..12803044f6e 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 fb390d78f8f..265d84ac5b3 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 90360b5fe61..f818edbaf39 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 96b54ccd917..f1da0e2533a 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 999c81af401..6f22fb1ec6a 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 8a3d2065a23..734467a1c59 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 f66c818c53d..37940e9a1f8 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/159] 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 1f27d1e217a..4816bac9fcb 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; - } + let isVariableDeclarationOrBindingElement = + n.parent.kind === SyntaxKind.BindingElement || (n.parent.kind === SyntaxKind.VariableDeclaration && (n.parent).name === n); - // 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 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 54ec39a5b55..86385ab543a 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 00000000000..902a23f5886 --- /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 00000000000..77f16756fdb --- /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 76c4a7ac3a6..594ec1ca18e 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 00000000000..b30ce609775 --- /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/159] 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 86385ab543a..5bf678f5436 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/159] 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 a1290e06956..121b39450a6 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 d24f406c1ad..cea5240003b 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 77408f0a9f8..e7039712734 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 217a0dfc74c..5651ee266c9 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 3457187e78a..c47fcfcad31 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 be0f79edd17..df0af71fb02 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 ff47df55493..9a2dd60999e 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 36535c1aa4f..30493b97347 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 f7506d7904d..e6b7bd5aae2 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 11b1de11bf6..00000000000 --- 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 5a6c84389f3..00000000000 --- 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 69da64765a3..8e0bf3de06b 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 383da7d419f..de47b0b95af 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 17cd2c265ed..4ddcca530f1 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 0cce3af0446..74f3037303e 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 c9866d87884..fe234f8424b 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 2b271099401..1ab547073c6 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 471f96b223d..aeba23e0b6e 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 03f79f6c667..ca1899e03f5 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 198a68633b1..9061bc1ed7c 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 805e56cf830..106726c0f2c 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 ef22eb4638c..779c13b1296 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 bcfc33d0405..179dd79ba17 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 fc721807994..d0489820d0b 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 f6d404135f6..b11a1922383 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 04ac8b28a8b..d109b048085 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 c00d3292f7e..eba480ba810 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 1b9575184f2..dc63d6385d8 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 96e62b626e7..71cf1d352f4 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 0b9467fb26d..8fc0a5be3a5 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 a00cec2e6dd..47670fe14b8 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 03b156af840..f872e95e7e6 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 60fb25dfa20..998f60db914 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 05ced020aff..a100cbf1791 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 2a07155a2f0..cee09fb0ab7 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 1cc06c06780..64239bc1284 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 07e937b3b42..8c647be13c9 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 264a3512075..fd6f376ef2b 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 4322abf44ed..28daf322748 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 487ff4078fd..e5c9512ad2d 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 c37312f0034..cee81ccc3d0 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 5f6381360fc..417e37067d1 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 70ed8b7b073..aa18db09bc6 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 4b79c459663..bab7c3198bd 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 4b62cc0ecd9..3ba028a4a1c 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 d0d7f4dcd52..0d312f79104 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 8d0c6cf3698..7a77c28ef52 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 a36981416df..46ffc65f57c 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 563614e1c8c..4bfe400de53 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 917945193ae..36247ea2a13 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 922e1fb0323..a8b1d564fa8 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 cbc06cd2951..d2aa55fe085 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 9d34b9e3bce..a3061ee1b58 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 6e68d36e346..e55d2942734 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 9ff77cc2c5d..caf72da0b7b 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 8693cf5d0fe..79ae9de95ee 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 0e019b487bb..d4c4e0ed365 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 5c3102cd877..453eb820ddb 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 acc5b4072f5..ab982aa8fdf 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 cd3d9c63e41..259afb1af0f 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 2dc2db1a3d4..2b1a5082617 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 48ae609cdc6..c4ced2a9dcc 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 8af17c95815..599f7393f4b 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 c7fd43cb9e2..00000000000 --- 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 ff94b6c9617..ac9ffd50fd6 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 4b0d794b1a7..3b2f66fe588 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/159] 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 feb95b4da16..05c6e71ef43 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/159] 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 7c9ccfa7854..e3ed6914b67 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 23ef00d6b44..0adda71cac2 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 cc705d64d5e..99176323831 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/159] 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 eed4b259596..efaaafd2e19 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/159] 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 99176323831..012c7ad6ae4 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/159] 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 a079994e5c8..8e53b3e96c4 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 5a07b22153d..48ece8b1b79 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 f078365f600..00000000000 --- 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 00000000000..b23d986f894 --- /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 e55d2942734..6e68d36e346 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 caf72da0b7b..9ff77cc2c5d 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 79ae9de95ee..8693cf5d0fe 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 d4c4e0ed365..0e019b487bb 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/159] 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 8e53b3e96c4..fbaaf2493c7 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 55d72a8b8d5..68ccd1568ed 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 4e4673a228f..83d4fcd0d80 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 00000000000..d82750f276f --- /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 00000000000..65ba8f7d2b9 --- /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 de100457aa9..14f74682c00 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 ebb6f26598d..bb0f7e99939 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 69801d6be12..8dc5b6cddaa 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 8b0feb72d2b..ba515168a5d 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 a3de33640af..1f4aaf73b3c 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 18ff3fa424d..70c0b35763e 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 00000000000..87114db7739 --- /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/159] 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 fbaaf2493c7..196aeabe638 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 87c0c3701f3..422675e9e0a 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/159] 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 522679adb0a..4cae7d0749c 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/159] 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 28e45f92f8f..d95f790c8f5 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 622b28d5f18..506104ff3bc 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 410cce54d17..e2a89b91e33 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 006b09892df..6a4e945ffe7 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 0cb8301be8a..675ccfbfc39 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 246cf6569fc..ff68d4039f5 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 09f2e3223c4..fcccdc4dcd0 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 adb7b568163..1fb0e1d8407 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 5c182d7e6ba..a13ce915920 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 080fec98e2f..07f7519d721 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 be2c226b8d0..87ed0c073f2 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 8061ff0d424..2eb306fd049 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 7fa6478844d..9b947a91d9a 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 00000000000..bf52e453002 --- /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 00000000000..72c65b4576c --- /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 00000000000..95b7ace24d1 --- /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 00000000000..c1841deefad --- /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 00000000000..b6f85522651 --- /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 00000000000..4cc84d09fc6 --- /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 00000000000..dbd0c8b139f --- /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 00000000000..0913a047afa --- /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 00000000000..79307703dee --- /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 00000000000..435ffc3bfda --- /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 00000000000..f0d6a7a6c2a --- /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 00000000000..b78706efdc1 --- /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 00000000000..3e67b0856fc --- /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 00000000000..9e334552e04 --- /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 00000000000..3ce76e2f3b3 --- /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 00000000000..ee691f3bdcf --- /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 00000000000..fceefe32f7d --- /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 00000000000..9daad837f73 --- /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 00000000000..3265753c514 --- /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 00000000000..468486b9bb0 --- /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 00000000000..960c203dcab --- /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/159] 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 b075730df8f..22494407f60 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/159] 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 f951fe49269..3535aaffb27 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 00000000000..1d32fe748ab --- /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 00000000000..30426e3fa4c --- /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 00000000000..0b1b9e3f0cb --- /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/159] 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 888c37f2f85..f1305254455 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 3941f3ee7d3..a975d4322f5 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 633548155e7..fb555196315 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 9a75f6d573c..6165475a500 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/159] 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 f1305254455..29d05519f76 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 fb555196315..9676720fd0f 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 6165475a500..ab930b41580 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/159] 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 d8b7c358a55..0ae29a6ec87 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 f1d0935c132..38ed4cf8442 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 e0ff5293546..70c8eada5b7 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 2a2090c1d87..356d076b9f2 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 b2b1f746a32..a533eca1d67 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/159] 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 29d05519f76..42856a57077 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 00000000000..3d9966be7dd --- /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 00000000000..fa88ab399a3 --- /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 00000000000..532025c4ee6 --- /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 00000000000..6b614926a0a --- /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 00000000000..05943d1c67e --- /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 00000000000..f696cee0aa3 --- /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/159] 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 38ed4cf8442..c0a84e25e24 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 00000000000..980f2383299 --- /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 00000000000..b9a1da7796a --- /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 00000000000..8bfcbe83b72 --- /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 00000000000..e1612dffbb4 --- /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/159] 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/159] 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 c0a84e25e24..36e3f8579df 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/159] 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 36e3f8579df..76a95bcdadc 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/159] 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 76a95bcdadc..0932ad042e7 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/159] 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 00000000000..f2d699f988b --- /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 00000000000..253f58071d9 --- /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 00000000000..ac169d0b17e --- /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 00000000000..a7972b1f48b --- /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 00000000000..a7972b1f48b --- /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 00000000000..08f0083f2f2 --- /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 00000000000..44a47d984ab --- /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 00000000000..0b57a2cb466 --- /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 00000000000..ae76cbf06c9 --- /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 00000000000..3e08fe5975e --- /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 00000000000..3de8b5ec6c3 --- /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 00000000000..3931433e51f --- /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 00000000000..24c2bca72f7 --- /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 00000000000..782a85c908a --- /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 00000000000..da88bc9d0c1 --- /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 00000000000..f2f900ce5d8 --- /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 00000000000..f2346e6bddc --- /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/159] 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 0ae29a6ec87..95a320ac052 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/159] 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 95a320ac052..5d488259a36 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/159] 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 00000000000..79159744b81 --- /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 00000000000..9df03ec10a4 --- /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/159] 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 00000000000..7c9c2a20139 --- /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 00000000000..a2ae8a9da83 --- /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 00000000000..b1a10a4a4b2 --- /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 00000000000..fcc7d070eb7 --- /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 00000000000..7ec3985caf0 --- /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 00000000000..f1aed3ad1a4 --- /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 00000000000..13b9f5787de --- /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 00000000000..5e7d8b30484 --- /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 00000000000..ee0e1e8b90c --- /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 00000000000..cdc4e9effff --- /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 00000000000..a45d98ad4df --- /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 00000000000..4d33d1220f7 --- /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 00000000000..c0c79e94433 --- /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 00000000000..d8b3a0a132f --- /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 00000000000..e56978732c2 --- /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 00000000000..748a334f860 --- /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 00000000000..3ceaff78039 --- /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 00000000000..6968a878a77 --- /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 00000000000..5e8b15941c1 --- /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 00000000000..0171ef96342 --- /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 00000000000..1d0162b600b --- /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 00000000000..1d0162b600b --- /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 00000000000..b0e36b2fb8a --- /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 00000000000..8e1334941ad --- /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 00000000000..412fcd86670 --- /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 00000000000..73a59795396 --- /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 00000000000..4ec5f41df53 --- /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 00000000000..8cded845673 --- /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 00000000000..182694d73d2 --- /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 00000000000..6f49f270250 --- /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 00000000000..888c6eeed0c --- /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 00000000000..15372ccea0d --- /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 00000000000..22821eb1084 --- /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 00000000000..c7f53e0e0df --- /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/159] 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 00000000000..82e4c6e4d15 --- /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/159] 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 888c6eeed0c..a931bed6a4b 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 15372ccea0d..32a9504ebc3 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 22821eb1084..455f122888c 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/159] 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 0932ad042e7..050468cb9da 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 61d7a0736b0..e9d207bddea 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 70c8eada5b7..11337b40e9d 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/159] 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 9df03ec10a4..9fb1182b56e 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/159] 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 82e4c6e4d15..633dc00a941 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/159] 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 5e7d8b30484..690fb583f67 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 ee0e1e8b90c..57af3592d44 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 cdc4e9effff..1e5e6256d6e 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/159] 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 11337b40e9d..cd7d48e7d0a 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/159] 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 0932ad042e7..be21b69f56b 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/159] 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 00000000000..fd2e5664f04 --- /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 00000000000..318730e41a6 --- /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/159] 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 ca047414e59..679a97449ec 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 fd2e5664f04..0667742d4cb 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 00000000000..bb4ef808bff --- /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/159] 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 d86a461dbc3..4f119232476 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/159] 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 00000000000..74f5f4a6409 --- /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/159] 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 305fad1e4a7..572ac835cd4 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 9261174b68f..3fbd9b3313e 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/159] 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 679a97449ec..a53ab212bf2 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 00000000000..fdb67dfc335 --- /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 00000000000..3573c345285 --- /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 00000000000..b9cc01f0a66 --- /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 00000000000..40d90370232 --- /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 00000000000..20e2a5d0663 --- /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 00000000000..d4bbd5992c6 --- /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 00000000000..c7b8f628170 --- /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 00000000000..5fd5c94ee3e --- /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 00000000000..3da8b4fd616 --- /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 00000000000..b1d347211ac --- /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 00000000000..d1cfecbffec --- /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 00000000000..658b0de7dc8 --- /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/159] Delete extra comma --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3fbd9b3313e..c33f2a93ec1 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/159] 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 a53ab212bf2..8758d126f63 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/159] 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 8758d126f63..6147112c909 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 00000000000..59c4922671e --- /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 00000000000..1d6403cfa10 --- /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/159] 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 7cfe69c5620..0bd57740803 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 42856a57077..126ac7a4e69 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/159] 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 95251b81984..f5b9e36f59b 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/159] 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 00000000000..de0f26eb86e --- /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 00000000000..e0ea3abbd38 --- /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 00000000000..35e5efdd304 --- /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 00000000000..e79f428b2b0 --- /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 00000000000..d775371796f --- /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 00000000000..d9195ce5b97 --- /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 00000000000..8b6077e0f8b --- /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 00000000000..473a39a453d --- /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 00000000000..b1186ac7cce --- /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/159] 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 387a57fa7f4..e8f7ef77e52 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 667bc03db2343705c588f5e59b2f8cabde241bfc Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Tue, 17 Mar 2015 15:26:55 -0700 Subject: [PATCH 132/159] Add toolsversion to shim so we can read it from VS. --- src/services/shims.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/services/shims.ts b/src/services/shims.ts index fc47ff95280..8c03e0f07d6 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -833,3 +833,5 @@ module ts { module TypeScript.Services { export var TypeScriptServicesFactory = ts.TypeScriptServicesFactory; } + +let toolsVerions = "1.4.3.0"; From bf16ab75355c1fd6eb6e9cc14fafd7f7e66fb763 Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Tue, 17 Mar 2015 15:52:37 -0700 Subject: [PATCH 133/159] fix typo --- src/services/shims.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/shims.ts b/src/services/shims.ts index 8c03e0f07d6..15e96638dcf 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -834,4 +834,4 @@ module TypeScript.Services { export var TypeScriptServicesFactory = ts.TypeScriptServicesFactory; } -let toolsVerions = "1.4.3.0"; +let toolsVersion = "1.4.3.0"; From 825c301ace0c533e84388fa96e326ac6d97c6139 Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Tue, 17 Mar 2015 16:31:18 -0700 Subject: [PATCH 134/159] We only need the 2 most significant digits. --- src/services/shims.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/shims.ts b/src/services/shims.ts index 15e96638dcf..63e3c9e23ae 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -834,4 +834,4 @@ module TypeScript.Services { export var TypeScriptServicesFactory = ts.TypeScriptServicesFactory; } -let toolsVersion = "1.4.3.0"; +let toolsVersion = "1.4"; From 8afde73e0b7b1fbfbf284cef7f08a9b7d9f4594a Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Tue, 17 Mar 2015 16:34:13 -0700 Subject: [PATCH 135/159] drop interned indentation prefixes if format options has changed --- src/services/formatting/formatting.ts | 14 ++++- src/services/formatting/indentation.ts | 54 ------------------- .../fourslash/formattingChangeSettings.ts | 24 +++++++++ 3 files changed, 36 insertions(+), 56 deletions(-) delete mode 100644 src/services/formatting/indentation.ts create mode 100644 tests/cases/fourslash/formattingChangeSettings.ts diff --git a/src/services/formatting/formatting.ts b/src/services/formatting/formatting.ts index 24ddabc2b2b..23a392d7718 100644 --- a/src/services/formatting/formatting.ts +++ b/src/services/formatting/formatting.ts @@ -1008,10 +1008,20 @@ module ts.formatting { return SyntaxKind.Unknown; } - let internedTabsIndentation: string[]; - let internedSpacesIndentation: string[]; + var internedSizes: { tabSize: number; indentSize: number }; + var internedTabsIndentation: string[]; + var internedSpacesIndentation: string[]; export function getIndentationString(indentation: number, options: FormatCodeOptions): string { + // reset interned strings if FormatCodeOptions were changed + let resetInternedStrings = + !internedSizes || (internedSizes.tabSize !== options.TabSize || internedSizes.indentSize !== options.IndentSize); + + if (resetInternedStrings) { + internedSizes = { tabSize: options.TabSize, indentSize: options.IndentSize }; + internedTabsIndentation = internedSpacesIndentation = undefined; + } + if (!options.ConvertTabsToSpaces) { let tabs = Math.floor(indentation / options.TabSize); let spaces = indentation - tabs * options.TabSize; diff --git a/src/services/formatting/indentation.ts b/src/services/formatting/indentation.ts deleted file mode 100644 index f6f8fc0319f..00000000000 --- a/src/services/formatting/indentation.ts +++ /dev/null @@ -1,54 +0,0 @@ -module ts.formatting { - - var internedTabsIndentation: string[]; - var internedSpacesIndentation: string[]; - - export function getIndentationString(indentation: number, options: FormatCodeOptions): string { - if (!options.ConvertTabsToSpaces) { - var tabs = Math.floor(indentation / options.TabSize); - var spaces = indentation - tabs * options.TabSize; - - var tabString: string; - if (!internedTabsIndentation) { - internedTabsIndentation = []; - } - - if (internedTabsIndentation[tabs] === undefined) { - internedTabsIndentation[tabs] = tabString = repeat('\t', tabs); - } - else { - tabString = internedTabsIndentation[tabs]; - } - - return spaces ? tabString + repeat(" ", spaces) : tabString; - } - else { - var spacesString: string; - var quotient = Math.floor(indentation / options.IndentSize); - var remainder = indentation % options.IndentSize; - if (!internedSpacesIndentation) { - internedSpacesIndentation = []; - } - - if (internedSpacesIndentation[quotient] === undefined) { - spacesString = repeat(" ", options.IndentSize * quotient); - internedSpacesIndentation[quotient] = spacesString; - } - else { - spacesString = internedSpacesIndentation[quotient]; - } - - - return remainder ? spacesString + repeat(" ", remainder) : spacesString; - } - - function repeat(value: string, count: number): string { - var s = ""; - for (var i = 0; i < count; ++i) { - s += value; - } - - return s; - } - } -} \ No newline at end of file diff --git a/tests/cases/fourslash/formattingChangeSettings.ts b/tests/cases/fourslash/formattingChangeSettings.ts new file mode 100644 index 00000000000..190de4c3e92 --- /dev/null +++ b/tests/cases/fourslash/formattingChangeSettings.ts @@ -0,0 +1,24 @@ +/// + +////module M { +/////*1*/var x=1; +////} + +var originalOptions = format.copyFormatOptions(); + +format.document(); + +goTo.marker("1"); +verify.currentLineContentIs(" var x = 1;"); + +var copy = format.copyFormatOptions(); +copy.TabSize = 2; +copy.IndentSize = 2; + +format.setFormatOptions(copy); +format.document(); + +goTo.marker("1"); +verify.currentLineContentIs(" var x = 1;"); + +format.setFormatOptions(originalOptions); \ No newline at end of file From c38e065b6b6bfdf6c715defc4696984c736cdc8c Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Tue, 17 Mar 2015 18:00:40 -0700 Subject: [PATCH 136/159] do not emit non-exported import declarations that don't have import clause --- src/compiler/emitter.ts | 4 ++++ tests/baselines/reference/es6ImportWithoutFromClause.js | 1 - tests/baselines/reference/es6ImportWithoutFromClauseAmd.js | 2 -- tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js | 1 - .../es6ImportWithoutFromClauseNonInstantiatedModule.js | 1 - 5 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index cda43ba511f..1ea1562b587 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -919,6 +919,10 @@ module ts { } function writeImportDeclaration(node: ImportDeclaration) { + if (!node.importClause && !(node.flags & NodeFlags.Export)) { + // do not write non-exported import declarations that don't have import clauses + return; + } emitJsDocComments(node); if (node.flags & NodeFlags.Export) { write("export "); diff --git a/tests/baselines/reference/es6ImportWithoutFromClause.js b/tests/baselines/reference/es6ImportWithoutFromClause.js index cc8509baade..9666409b924 100644 --- a/tests/baselines/reference/es6ImportWithoutFromClause.js +++ b/tests/baselines/reference/es6ImportWithoutFromClause.js @@ -17,4 +17,3 @@ import "es6ImportWithoutFromClause_0"; //// [es6ImportWithoutFromClause_0.d.ts] export declare var a: number; //// [es6ImportWithoutFromClause_1.d.ts] -import "es6ImportWithoutFromClause_0"; diff --git a/tests/baselines/reference/es6ImportWithoutFromClauseAmd.js b/tests/baselines/reference/es6ImportWithoutFromClauseAmd.js index 9c3066b6fc1..7b10da7cc9f 100644 --- a/tests/baselines/reference/es6ImportWithoutFromClauseAmd.js +++ b/tests/baselines/reference/es6ImportWithoutFromClauseAmd.js @@ -33,5 +33,3 @@ 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/es6ImportWithoutFromClauseInEs5.js b/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js index 9495bc1ffbc..aacb936ab36 100644 --- a/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js +++ b/tests/baselines/reference/es6ImportWithoutFromClauseInEs5.js @@ -16,4 +16,3 @@ 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 index 51bb0f3338d..e63dd4bb53a 100644 --- a/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.js +++ b/tests/baselines/reference/es6ImportWithoutFromClauseNonInstantiatedModule.js @@ -17,4 +17,3 @@ import "es6ImportWithoutFromClauseNonInstantiatedModule_0"; export interface i { } //// [es6ImportWithoutFromClauseNonInstantiatedModule_1.d.ts] -import "es6ImportWithoutFromClauseNonInstantiatedModule_0"; From 36b99511c61143ccfc7daef902c2992694e1f248 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 17 Mar 2015 18:34:42 -0700 Subject: [PATCH 137/159] Simplify code for emitting comments. Also, always emit pinned comments, even when the 'removeComments' compiler option is provided. --- src/compiler/emitter.ts | 146 ++++++++++++++++++-------------------- src/compiler/scanner.ts | 21 ++++-- src/compiler/utilities.ts | 14 ++-- 3 files changed, 91 insertions(+), 90 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 205f2fe2945..9f71e8322b5 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1594,25 +1594,12 @@ module ts { /** write emitted output to disk*/ let writeEmittedFiles = writeJavaScriptFile; - /** Emit leading comments of the node */ - let emitLeadingComments = compilerOptions.removeComments ? (node: Node) => { } : emitLeadingDeclarationComments; - - /** Emit Trailing comments of the node */ - let emitTrailingComments = compilerOptions.removeComments ? (node: Node) => { } : emitTrailingDeclarationComments; - - let emitLeadingCommentsOfPosition = compilerOptions.removeComments ? (pos: number) => { } : emitLeadingCommentsOfLocalPosition; - let detachedCommentsInfo: { nodePos: number; detachedCommentEndPos: number }[]; - /** Emit detached comments of the node */ - let emitDetachedComments = compilerOptions.removeComments ? (node: TextRange) => { } : emitDetachedCommentsAtPosition; - let writeComment = writeCommentRange; /** Emit a node */ - let emitNodeWithoutSourceMap = compilerOptions.removeComments ? emitNodeWithoutSourceMapWithoutComments : emitNodeWithoutSourceMapWithComments; let emit = emitNodeWithoutSourceMap; - let emitWithoutComments = emitNodeWithoutSourceMapWithoutComments; /** Called just before starting emit of a node */ let emitStart = function (node: Node) { }; @@ -2091,17 +2078,8 @@ module ts { } } - function emitNodeWithSourceMapWithoutComments(node: Node) { - if (node) { - recordEmitNodeStartSpan(node); - emitNodeWithoutSourceMapWithoutComments(node); - recordEmitNodeEndSpan(node); - } - } - writeEmittedFiles = writeJavaScriptAndSourceMapFile; emit = emitNodeWithSourceMap; - emitWithoutComments = emitNodeWithSourceMapWithoutComments; emitStart = recordEmitNodeStartSpan; emitEnd = recordEmitNodeEndSpan; emitToken = writeTextWithSpanRecord; @@ -4365,7 +4343,7 @@ module ts { function emitFunctionDeclaration(node: FunctionLikeDeclaration) { if (nodeIsMissing(node.body)) { - return emitPinnedOrTripleSlashComments(node); + return emitOnlyPinnedOrTripleSlashComments(node); } if (node.kind !== SyntaxKind.MethodDeclaration && node.kind !== SyntaxKind.MethodSignature) { @@ -4521,10 +4499,7 @@ module ts { write(" "); emitStart(body); write("return "); - - // Don't emit comments on this body. We'll have already taken care of it above - // when we called emitDetachedComments. - emitWithoutComments(body); + emit(body); emitEnd(body); write(";"); emitTempDeclarations(/*newLine*/ false); @@ -4535,10 +4510,7 @@ module ts { writeLine(); emitLeadingComments(node.body); write("return "); - - // Don't emit comments on this body. We'll have already taken care of it above - // when we called emitDetachedComments. - emitWithoutComments(node.body); + emit(body); write(";"); emitTrailingComments(node.body); @@ -4670,7 +4642,7 @@ module ts { forEach(node.members, member => { if (member.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature) { if (!(member).body) { - return emitPinnedOrTripleSlashComments(member); + return emitOnlyPinnedOrTripleSlashComments(member); } writeLine(); @@ -4745,7 +4717,7 @@ module ts { function emitMemberFunctionsForES6AndHigher(node: ClassDeclaration) { for (let member of node.members) { if ((member.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature) && !(member).body) { - emitPinnedOrTripleSlashComments(member); + emitOnlyPinnedOrTripleSlashComments(member); } else if (member.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature || member.kind === SyntaxKind.GetAccessor || member.kind === SyntaxKind.SetAccessor) { writeLine(); @@ -4786,7 +4758,7 @@ module ts { // Emit the constructor overload pinned comments forEach(node.members, member => { if (member.kind === SyntaxKind.Constructor && !(member).body) { - emitPinnedOrTripleSlashComments(member); + emitOnlyPinnedOrTripleSlashComments(member); } // Check if there is any non-static property assignment if (member.kind === SyntaxKind.PropertyDeclaration && (member).initializer && (member.flags & NodeFlags.Static) === 0) { @@ -5001,7 +4973,7 @@ module ts { } function emitInterfaceDeclaration(node: InterfaceDeclaration) { - emitPinnedOrTripleSlashComments(node); + emitOnlyPinnedOrTripleSlashComments(node); } function shouldEmitEnumDeclaration(node: EnumDeclaration) { @@ -5109,7 +5081,7 @@ module ts { let shouldEmit = shouldEmitModuleDeclaration(node); if (!shouldEmit) { - return emitPinnedOrTripleSlashComments(node); + return emitOnlyPinnedOrTripleSlashComments(node); } emitStart(node); @@ -5703,13 +5675,13 @@ module ts { emitLeadingComments(node.endOfFileToken); } - function emitNodeWithoutSourceMapWithComments(node: Node, allowGeneratedIdentifiers?: boolean): void { + function emitNodeWithoutSourceMap(node: Node, allowGeneratedIdentifiers?: boolean): void { if (!node) { return; } if (node.flags & NodeFlags.Ambient) { - return emitPinnedOrTripleSlashComments(node); + return emitOnlyPinnedOrTripleSlashComments(node); } let emitComments = shouldEmitLeadingAndTrailingComments(node); @@ -5724,18 +5696,6 @@ module ts { } } - function emitNodeWithoutSourceMapWithoutComments(node: Node, allowGeneratedIdentifiers?: boolean): void { - if (!node) { - return; - } - - if (node.flags & NodeFlags.Ambient) { - return emitPinnedOrTripleSlashComments(node); - } - - emitJavaScriptWorker(node, allowGeneratedIdentifiers); - } - function shouldEmitLeadingAndTrailingComments(node: Node) { switch (node.kind) { // All of these entities are emitted in a specialized fashion. As such, we allow @@ -5759,6 +5719,17 @@ module ts { return shouldEmitEnumDeclaration(node); } + // If this is the expression body of an arrow function, then we don't want to emit + // comments when we emit the body. It will have been already taken care of when + // we emitted the 'return' statement for the function expression body. + if (node.kind !== SyntaxKind.Block && + node.parent && + node.parent.kind === SyntaxKind.ArrowFunction && + (node.parent).body === node) { + + return false; + } + // Emit comments for everything else. return true; } @@ -5928,7 +5899,8 @@ module ts { function getLeadingCommentsWithoutDetachedComments() { // get the leading comments from detachedPos - let leadingComments = getLeadingCommentRanges(currentSourceFile.text, detachedCommentsInfo[detachedCommentsInfo.length - 1].detachedCommentEndPos); + let leadingComments = getLeadingCommentRanges(currentSourceFile.text, + detachedCommentsInfo[detachedCommentsInfo.length - 1].detachedCommentEndPos); if (detachedCommentsInfo.length - 1) { detachedCommentsInfo.pop(); } @@ -5952,30 +5924,58 @@ module ts { // get the leading comments from the node leadingComments = getLeadingCommentRangesOfNode(node, currentSourceFile); } + return leadingComments; } } } - function emitLeadingDeclarationComments(node: Node) { + function filterCommentsBasedOnOptions(ranges: CommentRange[]): CommentRange[]{ + // If we're removing comments, then we want to strip out all but the pinned or + // triple slash comments. + if (ranges && compilerOptions.removeComments) { + ranges = filter(ranges, isPinnedOrTripleSlashComment); + if (ranges.length === 0) { + return undefined; + } + } + + return ranges; + } + + function emitOnlyPinnedOrTripleSlashComments(node: Node) { + emitLeadingCommentsWorker(node, /*onlyPinnedOrTripleSlashComments:*/ true); + } + + function emitLeadingComments(node: Node) { + return emitLeadingCommentsWorker(node, /*onlyPinnedOrTripleSlashComments:*/ false); + } + + function emitLeadingCommentsWorker(node: Node, onlyPinnedOrTripleSlashComments: boolean) { let leadingComments = getLeadingCommentsToEmit(node); + leadingComments = onlyPinnedOrTripleSlashComments + ? filter(leadingComments, isPinnedOrTripleSlashComment) + : filterCommentsBasedOnOptions(leadingComments); + emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments); + // Leading comments are emitted at /*leading comment1 */space/*leading comment*/space emitComments(currentSourceFile, writer, leadingComments, /*trailingSeparator*/ true, newLine, writeComment); } - function emitTrailingDeclarationComments(node: Node) { + function emitTrailingComments(node: Node) { // Emit the trailing comments only if the parent's end doesn't match if (node.parent) { if (node.parent.kind === SyntaxKind.SourceFile || node.end !== node.parent.end) { - let trailingComments = getTrailingCommentRanges(currentSourceFile.text, node.end); + let trailingComments = filterCommentsBasedOnOptions(getTrailingCommentRanges(currentSourceFile.text, node.end)); + // trailing comments are emitted at space/*trailing comment1 */space/*trailing comment*/ emitComments(currentSourceFile, writer, trailingComments, /*trailingSeparator*/ false, newLine, writeComment); } } } - function emitLeadingCommentsOfLocalPosition(pos: number) { + function emitLeadingCommentsOfPosition(pos: number) { let leadingComments: CommentRange[]; if (hasDetachedComments(pos)) { // get comments without detached comments @@ -5985,12 +5985,15 @@ module ts { // get the leading comments from the node leadingComments = getLeadingCommentRanges(currentSourceFile.text, pos); } + + leadingComments = filterCommentsBasedOnOptions(leadingComments); emitNewLineBeforeLeadingComments(currentSourceFile, writer, { pos: pos, end: pos }, leadingComments); + // Leading comments are emitted at /*leading comment1 */space/*leading comment*/space emitComments(currentSourceFile, writer, leadingComments, /*trailingSeparator*/ true, newLine, writeComment); } - function emitDetachedCommentsAtPosition(node: TextRange) { + function emitDetachedComments(node: TextRange) { let leadingComments = getLeadingCommentRanges(currentSourceFile.text, node.pos); if (leadingComments) { let detachedComments: CommentRange[] = []; @@ -6035,27 +6038,18 @@ module ts { } } - /** Emits /// or pinned which is comment starting with /*! comments */ - function emitPinnedOrTripleSlashComments(node: Node) { - let pinnedComments = ts.filter(getLeadingCommentsToEmit(node), isPinnedOrTripleSlashComment); - - function isPinnedOrTripleSlashComment(comment: CommentRange) { - if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk) { - return currentSourceFile.text.charCodeAt(comment.pos + 2) === CharacterCodes.exclamation; - } - // Verify this is /// comment, but do the regexp match only when we first can find /// in the comment text - // so that we don't end up computing comment string and doing match for all // comments - else if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.slash && - comment.pos + 2 < comment.end && - currentSourceFile.text.charCodeAt(comment.pos + 2) === CharacterCodes.slash && - currentSourceFile.text.substring(comment.pos, comment.end).match(fullTripleSlashReferencePathRegEx)) { - return true; - } + function isPinnedOrTripleSlashComment(comment: CommentRange) { + if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk) { + return currentSourceFile.text.charCodeAt(comment.pos + 2) === CharacterCodes.exclamation; + } + // Verify this is /// comment, but do the regexp match only when we first can find /// in the comment text + // so that we don't end up computing comment string and doing match for all // comments + else if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.slash && + comment.pos + 2 < comment.end && + currentSourceFile.text.charCodeAt(comment.pos + 2) === CharacterCodes.slash && + currentSourceFile.text.substring(comment.pos, comment.end).match(fullTripleSlashReferencePathRegEx)) { + return true; } - - emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, pinnedComments); - // Leading comments are emitted at /*leading comment1 */space/*leading comment*/space - emitComments(currentSourceFile, writer, pinnedComments, /*trailingSeparator*/ true, newLine, writeComment); } } diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index fbcadab8c1d..130fcc07a22 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -455,11 +455,13 @@ module ts { return pos; } - // Extract comments from the given source text starting at the given position. If trailing is false, whitespace is skipped until - // the first line break and comments between that location and the next token are returned. If trailing is true, comments occurring - // between the given position and the next line break are returned. The return value is an array containing a TextRange for each - // comment. Single-line comment ranges include the beginning '//' characters but not the ending line break. Multi-line comment - // ranges include the beginning '/* and ending '*/' characters. The return value is undefined if no comments were found. + // Extract comments from the given source text starting at the given position. If trailing is + // false, whitespace is skipped until the first line break and comments between that location + // and the next token are returned.If trailing is true, comments occurring between the given + // position and the next line break are returned.The return value is an array containing a + // TextRange for each comment. Single-line comment ranges include the beginning '//' characters + // but not the ending line break. Multi - line comment ranges include the beginning '/* and + // ending '*/' characters.The return value is undefined if no comments were found. function getCommentRanges(text: string, pos: number, trailing: boolean): CommentRange[] { let result: CommentRange[]; let collecting = trailing || pos === 0; @@ -467,7 +469,9 @@ module ts { let ch = text.charCodeAt(pos); switch (ch) { case CharacterCodes.carriageReturn: - if (text.charCodeAt(pos + 1) === CharacterCodes.lineFeed) pos++; + if (text.charCodeAt(pos + 1) === CharacterCodes.lineFeed) { + pos++; + } case CharacterCodes.lineFeed: pos++; if (trailing) { @@ -509,7 +513,10 @@ module ts { } } if (collecting) { - if (!result) result = []; + if (!result) { + result = []; + } + result.push({ pos: startPos, end: pos, hasTrailingNewLine: hasTrailingNewLine }); } continue; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 4fce9c928f7..fd7e1304c85 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -361,16 +361,16 @@ module ts { return node.kind === SyntaxKind.ExpressionStatement && (node).expression.kind === SyntaxKind.StringLiteral; } - export function getLeadingCommentRangesOfNode(node: Node, sourceFileOfNode?: SourceFile) { - sourceFileOfNode = sourceFileOfNode || getSourceFileOfNode(node); - + export function getLeadingCommentRangesOfNode(node: Node, sourceFileOfNode: SourceFile) { // If parameter/type parameter, the prev token trailing comments are part of this node too if (node.kind === SyntaxKind.Parameter || node.kind === SyntaxKind.TypeParameter) { // e.g. (/** blah */ a, /** blah */ b); - return concatenate(getTrailingCommentRanges(sourceFileOfNode.text, node.pos), - // e.g.: ( - // /** blah */ a, - // /** blah */ b); + + // e.g.: ( + // /** blah */ a, + // /** blah */ b); + return concatenate( + getTrailingCommentRanges(sourceFileOfNode.text, node.pos), getLeadingCommentRanges(sourceFileOfNode.text, node.pos)); } else { From 9582d7cf283e7c7856a4741a859bd8ac6a3fcb82 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 17 Mar 2015 18:43:39 -0700 Subject: [PATCH 138/159] Add test for pinned comments. --- src/compiler/emitter.ts | 3 +++ tests/baselines/reference/pinnedComments1.js | 14 ++++++++++++++ tests/baselines/reference/pinnedComments1.types | 7 +++++++ tests/cases/compiler/pinnedComments1.ts | 6 ++++++ 4 files changed, 30 insertions(+) create mode 100644 tests/baselines/reference/pinnedComments1.js create mode 100644 tests/baselines/reference/pinnedComments1.types create mode 100644 tests/cases/compiler/pinnedComments1.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 9f71e8322b5..2732d79f25d 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -5953,6 +5953,9 @@ module ts { function emitLeadingCommentsWorker(node: Node, onlyPinnedOrTripleSlashComments: boolean) { let leadingComments = getLeadingCommentsToEmit(node); + + // If the caller only wants pinned or triple slash comments, then always filter + // down to that set. Otherwise, filter based on the current compiler options. leadingComments = onlyPinnedOrTripleSlashComments ? filter(leadingComments, isPinnedOrTripleSlashComment) : filterCommentsBasedOnOptions(leadingComments); diff --git a/tests/baselines/reference/pinnedComments1.js b/tests/baselines/reference/pinnedComments1.js new file mode 100644 index 00000000000..c4b8b41fbd7 --- /dev/null +++ b/tests/baselines/reference/pinnedComments1.js @@ -0,0 +1,14 @@ +//// [pinnedComments1.ts] + +/* unpinned comment */ +/*! pinned comment */ +class C { +} + +//// [pinnedComments1.js] +/*! pinned comment */ +var C = (function () { + function C() { + } + return C; +})(); diff --git a/tests/baselines/reference/pinnedComments1.types b/tests/baselines/reference/pinnedComments1.types new file mode 100644 index 00000000000..d55feb67659 --- /dev/null +++ b/tests/baselines/reference/pinnedComments1.types @@ -0,0 +1,7 @@ +=== tests/cases/compiler/pinnedComments1.ts === + +/* unpinned comment */ +/*! pinned comment */ +class C { +>C : C +} diff --git a/tests/cases/compiler/pinnedComments1.ts b/tests/cases/compiler/pinnedComments1.ts new file mode 100644 index 00000000000..474769e9b20 --- /dev/null +++ b/tests/cases/compiler/pinnedComments1.ts @@ -0,0 +1,6 @@ +// @comments: false + +/* unpinned comment */ +/*! pinned comment */ +class C { +} \ No newline at end of file From 63e4420887ca5a674030dfadff5692ba2e72b976 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 17 Mar 2015 19:13:00 -0700 Subject: [PATCH 139/159] Simplify flow control. --- src/compiler/emitter.ts | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 2732d79f25d..6022b1445bd 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -5719,13 +5719,15 @@ module ts { return shouldEmitEnumDeclaration(node); } - // If this is the expression body of an arrow function, then we don't want to emit - // comments when we emit the body. It will have been already taken care of when - // we emitted the 'return' statement for the function expression body. + // If this is the expression body of an arrow function that we're downleveling, + // then we don't want to emit comments when we emit the body. It will have already + // been taken care of when we emitted the 'return' statement for the function + // expression body. if (node.kind !== SyntaxKind.Block && node.parent && node.parent.kind === SyntaxKind.ArrowFunction && - (node.parent).body === node) { + (node.parent).body === node && + compilerOptions.target <= ScriptTarget.ES5) { return false; } @@ -5930,10 +5932,10 @@ module ts { } } - function filterCommentsBasedOnOptions(ranges: CommentRange[]): CommentRange[]{ + function filterComments(ranges: CommentRange[], onlyPinnedOrTripleSlashComments: boolean): CommentRange[]{ // If we're removing comments, then we want to strip out all but the pinned or // triple slash comments. - if (ranges && compilerOptions.removeComments) { + if (ranges && onlyPinnedOrTripleSlashComments) { ranges = filter(ranges, isPinnedOrTripleSlashComment); if (ranges.length === 0) { return undefined; @@ -5948,17 +5950,13 @@ module ts { } function emitLeadingComments(node: Node) { - return emitLeadingCommentsWorker(node, /*onlyPinnedOrTripleSlashComments:*/ false); + return emitLeadingCommentsWorker(node, /*onlyPinnedOrTripleSlashComments:*/ compilerOptions.removeComments); } function emitLeadingCommentsWorker(node: Node, onlyPinnedOrTripleSlashComments: boolean) { - let leadingComments = getLeadingCommentsToEmit(node); - // If the caller only wants pinned or triple slash comments, then always filter // down to that set. Otherwise, filter based on the current compiler options. - leadingComments = onlyPinnedOrTripleSlashComments - ? filter(leadingComments, isPinnedOrTripleSlashComment) - : filterCommentsBasedOnOptions(leadingComments); + let leadingComments = filterComments(getLeadingCommentsToEmit(node), onlyPinnedOrTripleSlashComments); emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments); @@ -5970,7 +5968,9 @@ module ts { // Emit the trailing comments only if the parent's end doesn't match if (node.parent) { if (node.parent.kind === SyntaxKind.SourceFile || node.end !== node.parent.end) { - let trailingComments = filterCommentsBasedOnOptions(getTrailingCommentRanges(currentSourceFile.text, node.end)); + let trailingComments = filterComments( + getTrailingCommentRanges(currentSourceFile.text, node.end), + /*emitOnlyPinnedOrTripleSlashComments:*/ compilerOptions.removeComments); // trailing comments are emitted at space/*trailing comment1 */space/*trailing comment*/ emitComments(currentSourceFile, writer, trailingComments, /*trailingSeparator*/ false, newLine, writeComment); @@ -5989,7 +5989,7 @@ module ts { leadingComments = getLeadingCommentRanges(currentSourceFile.text, pos); } - leadingComments = filterCommentsBasedOnOptions(leadingComments); + leadingComments = filterComments(leadingComments, compilerOptions.removeComments); emitNewLineBeforeLeadingComments(currentSourceFile, writer, { pos: pos, end: pos }, leadingComments); // Leading comments are emitted at /*leading comment1 */space/*leading comment*/space From 035ad42c302fcfc6d33ad6a096310b09f9989afa Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 17 Mar 2015 19:25:40 -0700 Subject: [PATCH 140/159] Simplify comment emit. --- src/compiler/emitter.ts | 66 ++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 6022b1445bd..8480a758869 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -5568,12 +5568,12 @@ module ts { emitLinesStartingAt(node.statements, startIndex); emitTempDeclarations(/*newLine*/ true); // Emit exportDefault if it exists will happen as part - // or normal statment emit. + // or normal statement emit. } function emitExportAssignment(node: ExportAssignment) { // Only emit exportAssignment/export default if we are in ES6 - // Other modules will handel it diffrentlly + // Other modules will handle it differently if (languageVersion >= ScriptTarget.ES6) { writeLine(); emitStart(node); @@ -5699,7 +5699,7 @@ module ts { function shouldEmitLeadingAndTrailingComments(node: Node) { switch (node.kind) { // All of these entities are emitted in a specialized fashion. As such, we allow - // the specilized methods for each to handle the comments on the nodes. + // the specialized methods for each to handle the comments on the nodes. case SyntaxKind.InterfaceDeclaration: case SyntaxKind.FunctionDeclaration: case SyntaxKind.ImportDeclaration: @@ -5719,7 +5719,7 @@ module ts { return shouldEmitEnumDeclaration(node); } - // If this is the expression body of an arrow function that we're downleveling, + // If this is the expression body of an arrow function that we're down-leveling, // then we don't want to emit comments when we emit the body. It will have already // been taken care of when we emitted the 'return' statement for the function // expression body. @@ -5913,26 +5913,7 @@ module ts { return leadingComments; } - function getLeadingCommentsToEmit(node: Node) { - // Emit the leading comments only if the parent's pos doesn't match because parent should take care of emitting these comments - if (node.parent) { - if (node.parent.kind === SyntaxKind.SourceFile || node.pos !== node.parent.pos) { - let leadingComments: CommentRange[]; - if (hasDetachedComments(node.pos)) { - // get comments without detached comments - leadingComments = getLeadingCommentsWithoutDetachedComments(); - } - else { - // get the leading comments from the node - leadingComments = getLeadingCommentRangesOfNode(node, currentSourceFile); - } - - return leadingComments; - } - } - } - - function filterComments(ranges: CommentRange[], onlyPinnedOrTripleSlashComments: boolean): CommentRange[]{ + function filterComments(ranges: CommentRange[], onlyPinnedOrTripleSlashComments: boolean): CommentRange[] { // If we're removing comments, then we want to strip out all but the pinned or // triple slash comments. if (ranges && onlyPinnedOrTripleSlashComments) { @@ -5945,6 +5926,31 @@ module ts { return ranges; } + function getLeadingCommentsToEmit(node: Node) { + // Emit the leading comments only if the parent's pos doesn't match because parent should take care of emitting these comments + if (node.parent) { + if (node.parent.kind === SyntaxKind.SourceFile || node.pos !== node.parent.pos) { + if (hasDetachedComments(node.pos)) { + // get comments without detached comments + return getLeadingCommentsWithoutDetachedComments(); + } + else { + // get the leading comments from the node + return getLeadingCommentRangesOfNode(node, currentSourceFile); + } + } + } + } + + function getTrailingCommentsToEmit(node: Node) { + // Emit the trailing comments only if the parent's pos doesn't match because parent should take care of emitting these comments + if (node.parent) { + if (node.parent.kind === SyntaxKind.SourceFile || node.end !== node.parent.end) { + return getTrailingCommentRanges(currentSourceFile.text, node.end); + } + } + } + function emitOnlyPinnedOrTripleSlashComments(node: Node) { emitLeadingCommentsWorker(node, /*onlyPinnedOrTripleSlashComments:*/ true); } @@ -5966,16 +5972,10 @@ module ts { function emitTrailingComments(node: Node) { // Emit the trailing comments only if the parent's end doesn't match - if (node.parent) { - if (node.parent.kind === SyntaxKind.SourceFile || node.end !== node.parent.end) { - let trailingComments = filterComments( - getTrailingCommentRanges(currentSourceFile.text, node.end), - /*emitOnlyPinnedOrTripleSlashComments:*/ compilerOptions.removeComments); + var trailingComments = filterComments(getTrailingCommentsToEmit(node), /*onlyPinnedOrTripleSlashComments:*/ compilerOptions.removeComments); - // trailing comments are emitted at space/*trailing comment1 */space/*trailing comment*/ - emitComments(currentSourceFile, writer, trailingComments, /*trailingSeparator*/ false, newLine, writeComment); - } - } + // trailing comments are emitted at space/*trailing comment1 */space/*trailing comment*/ + emitComments(currentSourceFile, writer, trailingComments, /*trailingSeparator*/ false, newLine, writeComment); } function emitLeadingCommentsOfPosition(pos: number) { From 7bcd18fe28282a6650b620dfee085adc46affc6c Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 17 Mar 2015 22:56:45 -0700 Subject: [PATCH 141/159] Fix diagnostic codes. --- .../diagnosticInformationMap.generated.ts | 4 ++-- src/compiler/diagnosticMessages.json | 10 +++++----- .../reference/ES5For-ofTypeCheck10.errors.txt | 4 ++-- .../reference/ES5For-ofTypeCheck12.errors.txt | 4 ++-- ...mitArrowFunctionWhenUsingArguments.errors.txt | 16 ++++++++-------- ...ArrowFunctionWhenUsingArgumentsES6.errors.txt | 16 ++++++++-------- 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index dd26ef281c4..413e7322fbd 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -344,7 +344,8 @@ module ts { Cannot_redeclare_identifier_0_in_catch_clause: { code: 2492, category: DiagnosticCategory.Error, key: "Cannot redeclare identifier '{0}' in catch clause" }, Tuple_type_0_with_length_1_cannot_be_assigned_to_tuple_with_length_2: { code: 2493, category: DiagnosticCategory.Error, key: "Tuple type '{0}' with length '{1}' cannot be assigned to tuple with length '{2}'." }, Using_a_string_in_a_for_of_statement_is_only_supported_in_ECMAScript_5_and_higher: { code: 2494, category: DiagnosticCategory.Error, key: "Using a string in a 'for...of' statement is only supported in ECMAScript 5 and higher." }, - Type_0_is_not_an_array_type_or_a_string_type: { code: 2461, category: DiagnosticCategory.Error, key: "Type '{0}' is not an array type or a string type." }, + Type_0_is_not_an_array_type_or_a_string_type: { code: 2495, category: DiagnosticCategory.Error, key: "Type '{0}' is not an array type or a string type." }, + The_arguments_object_cannot_be_referenced_in_an_arrow_function_Consider_using_a_standard_function_expression: { code: 2496, category: DiagnosticCategory.Error, key: "The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, @@ -491,6 +492,5 @@ module ts { You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library: { code: 8001, category: DiagnosticCategory.Error, key: "You cannot rename elements that are defined in the standard TypeScript library." }, yield_expressions_are_not_currently_supported: { code: 9000, category: DiagnosticCategory.Error, key: "'yield' expressions are not currently supported." }, Generators_are_not_currently_supported: { code: 9001, category: DiagnosticCategory.Error, key: "Generators are not currently supported." }, - The_arguments_object_cannot_be_referenced_in_an_arrow_function_Consider_using_a_standard_function_expression: { code: 9002, category: DiagnosticCategory.Error, key: "The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression." }, }; } \ No newline at end of file diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index e1767fe8de0..db95db99918 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1370,7 +1370,11 @@ }, "Type '{0}' is not an array type or a string type.": { "category": "Error", - "code": 2461 + "code": 2495 + }, + "The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.": { + "category": "Error", + "code": 2496 }, "Import declaration '{0}' is using private name '{1}'.": { @@ -1957,9 +1961,5 @@ "Generators are not currently supported.": { "category": "Error", "code": 9001 - }, - "The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression.": { - "category": "Error", - "code": 9002 } } diff --git a/tests/baselines/reference/ES5For-ofTypeCheck10.errors.txt b/tests/baselines/reference/ES5For-ofTypeCheck10.errors.txt index 9551d0467e9..b762db8a04b 100644 --- a/tests/baselines/reference/ES5For-ofTypeCheck10.errors.txt +++ b/tests/baselines/reference/ES5For-ofTypeCheck10.errors.txt @@ -1,11 +1,11 @@ -tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck10.ts(1,15): error TS2461: Type 'StringIterator' is not an array type or a string type. +tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck10.ts(1,15): error TS2495: Type 'StringIterator' is not an array type or a string type. tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck10.ts(11,6): error TS2304: Cannot find name 'Symbol'. ==== tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck10.ts (2 errors) ==== for (var v of new StringIterator) { } ~~~~~~~~~~~~~~~~~~ -!!! error TS2461: Type 'StringIterator' is not an array type or a string type. +!!! error TS2495: Type 'StringIterator' is not an array type or a string type. // In ES3/5, you cannot for...of over an arbitrary iterable. class StringIterator { diff --git a/tests/baselines/reference/ES5For-ofTypeCheck12.errors.txt b/tests/baselines/reference/ES5For-ofTypeCheck12.errors.txt index b726aaad6c7..67af1f4f401 100644 --- a/tests/baselines/reference/ES5For-ofTypeCheck12.errors.txt +++ b/tests/baselines/reference/ES5For-ofTypeCheck12.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck12.ts(1,17): error TS2461: Type 'number' is not an array type or a string type. +tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck12.ts(1,17): error TS2495: Type 'number' is not an array type or a string type. ==== tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck12.ts (1 errors) ==== for (const v of 0) { } ~ -!!! error TS2461: Type 'number' is not an array type or a string type. \ No newline at end of file +!!! error TS2495: Type 'number' is not an array type or a string type. \ No newline at end of file diff --git a/tests/baselines/reference/emitArrowFunctionWhenUsingArguments.errors.txt b/tests/baselines/reference/emitArrowFunctionWhenUsingArguments.errors.txt index 3a0ab0e597c..2f5ca2a387c 100644 --- a/tests/baselines/reference/emitArrowFunctionWhenUsingArguments.errors.txt +++ b/tests/baselines/reference/emitArrowFunctionWhenUsingArguments.errors.txt @@ -1,21 +1,21 @@ -tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts(2,15): error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. -tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts(7,19): error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. -tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts(13,13): error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. -tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts(19,15): error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts(2,15): error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts(7,19): error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts(13,13): error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts(19,15): error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. ==== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts (4 errors) ==== var a = () => { var arg = arguments[0]; // error ~~~~~~~~~ -!!! error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. } var b = function () { var a = () => { var arg = arguments[0]; // error ~~~~~~~~~ -!!! error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. } } @@ -23,7 +23,7 @@ tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts () => { var arg = arguments[0]; ~~~~~~~~~ -!!! error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. } } @@ -31,7 +31,7 @@ tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArguments.ts foo(() => { var arg = arguments[0]; // error ~~~~~~~~~ -!!! error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. }); function bar() { diff --git a/tests/baselines/reference/emitArrowFunctionWhenUsingArgumentsES6.errors.txt b/tests/baselines/reference/emitArrowFunctionWhenUsingArgumentsES6.errors.txt index f879f11799b..26f204d3ee6 100644 --- a/tests/baselines/reference/emitArrowFunctionWhenUsingArgumentsES6.errors.txt +++ b/tests/baselines/reference/emitArrowFunctionWhenUsingArgumentsES6.errors.txt @@ -1,21 +1,21 @@ -tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6.ts(2,15): error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. -tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6.ts(7,19): error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. -tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6.ts(13,13): error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. -tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6.ts(19,15): error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6.ts(2,15): error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6.ts(7,19): error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6.ts(13,13): error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6.ts(19,15): error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. ==== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6.ts (4 errors) ==== var a = () => { var arg = arguments[0]; // error ~~~~~~~~~ -!!! error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. } var b = function () { var a = () => { var arg = arguments[0]; // error ~~~~~~~~~ -!!! error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. } } @@ -23,7 +23,7 @@ tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6 () => { var arg = arguments[0]; ~~~~~~~~~ -!!! error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. } } @@ -31,7 +31,7 @@ tests/cases/conformance/es6/arrowFunction/emitArrowFunctionWhenUsingArgumentsES6 foo(() => { var arg = arguments[0]; // error ~~~~~~~~~ -!!! error TS9002: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. +!!! error TS2496: The 'arguments' object cannot be referenced in an arrow function. Consider using a standard function expression. }); function bar() { From 34e612c9fcde7621ce067d7cc6168d3099e9b42b Mon Sep 17 00:00:00 2001 From: steveluc Date: Tue, 17 Mar 2015 22:58:12 -0700 Subject: [PATCH 142/159] Add handling of hard tabs in server buffers. Change message protocol to pass locations as line/offset pairs instead of line/column pairs, where offset is a 1-based character offset from the beginning of the line. Offset will be equal to column if the line contains no tabs. If the line contains tabs, offset will be less than or equal to column, depending on how many tabs are before the offset. Also added tab size and indent size to file open message. --- src/server/client.ts | 114 ++++++++++++++++---------------- src/server/editorServices.ts | 86 ++++++++++-------------- src/server/protocol.d.ts | 24 +++---- src/server/session.ts | 124 ++++++++++++++++++----------------- 4 files changed, 167 insertions(+), 181 deletions(-) diff --git a/src/server/client.ts b/src/server/client.ts index c8e7f2fdcb1..07c742db4f8 100644 --- a/src/server/client.ts +++ b/src/server/client.ts @@ -46,21 +46,21 @@ module ts.server { return lineMap; } - private lineColToPosition(fileName: string, lineCol: protocol.Location): number { - return ts.computePositionOfLineAndCharacter(this.getLineMap(fileName), lineCol.line - 1, lineCol.col - 1); + private lineOffsetToPosition(fileName: string, lineOffset: protocol.Location): number { + return ts.computePositionOfLineAndCharacter(this.getLineMap(fileName), lineOffset.line - 1, lineOffset.offset - 1); } - private positionToOneBasedLineCol(fileName: string, position: number): protocol.Location { - var lineCol = ts.computeLineAndCharacterOfPosition(this.getLineMap(fileName), position); + private positionToOneBasedLineOffset(fileName: string, position: number): protocol.Location { + var lineOffset = ts.computeLineAndCharacterOfPosition(this.getLineMap(fileName), position); return { - line: lineCol.line + 1, - col: lineCol.character + 1 + line: lineOffset.line + 1, + offset: lineOffset.character + 1 }; } private convertCodeEditsToTextChange(fileName: string, codeEdit: protocol.CodeEdit): ts.TextChange { - var start = this.lineColToPosition(fileName, codeEdit.start); - var end = this.lineColToPosition(fileName, codeEdit.end); + var start = this.lineOffsetToPosition(fileName, codeEdit.start); + var end = this.lineOffsetToPosition(fileName, codeEdit.end); return { span: ts.createTextSpanFromBounds(start, end), @@ -134,15 +134,15 @@ module ts.server { // clear the line map after an edit this.lineMaps[fileName] = undefined; - var lineCol = this.positionToOneBasedLineCol(fileName, start); - var endLineCol = this.positionToOneBasedLineCol(fileName, end); + var lineOffset = this.positionToOneBasedLineOffset(fileName, start); + var endLineOffset = this.positionToOneBasedLineOffset(fileName, end); var args: protocol.ChangeRequestArgs = { file: fileName, - line: lineCol.line, - col: lineCol.col, - endLine: endLineCol.line, - endCol: endLineCol.col, + line: lineOffset.line, + offset: lineOffset.offset, + endLine: endLineOffset.line, + endOffset: endLineOffset.offset, insertString: newText }; @@ -150,18 +150,18 @@ module ts.server { } getQuickInfoAtPosition(fileName: string, position: number): QuickInfo { - var lineCol = this.positionToOneBasedLineCol(fileName, position); + var lineOffset = this.positionToOneBasedLineOffset(fileName, position); var args: protocol.FileLocationRequestArgs = { file: fileName, - line: lineCol.line, - col: lineCol.col + line: lineOffset.line, + offset: lineOffset.offset }; var request = this.processRequest(CommandNames.Quickinfo, args); var response = this.processResponse(request); - var start = this.lineColToPosition(fileName, response.body.start); - var end = this.lineColToPosition(fileName, response.body.end); + var start = this.lineOffsetToPosition(fileName, response.body.start); + var end = this.lineOffsetToPosition(fileName, response.body.end); return { kind: response.body.kind, @@ -173,11 +173,11 @@ module ts.server { } getCompletionsAtPosition(fileName: string, position: number): CompletionInfo { - var lineCol = this.positionToOneBasedLineCol(fileName, position); + var lineOffset = this.positionToOneBasedLineOffset(fileName, position); var args: protocol.CompletionsRequestArgs = { file: fileName, - line: lineCol.line, - col: lineCol.col, + line: lineOffset.line, + offset: lineOffset.offset, prefix: undefined }; @@ -194,11 +194,11 @@ module ts.server { } getCompletionEntryDetails(fileName: string, position: number, entryName: string): CompletionEntryDetails { - var lineCol = this.positionToOneBasedLineCol(fileName, position); + var lineOffset = this.positionToOneBasedLineOffset(fileName, position); var args: protocol.CompletionDetailsRequestArgs = { file: fileName, - line: lineCol.line, - col: lineCol.col, + line: lineOffset.line, + offset: lineOffset.offset, entryNames: [entryName] }; @@ -219,8 +219,8 @@ module ts.server { return response.body.map(entry => { var fileName = entry.file; - var start = this.lineColToPosition(fileName, entry.start); - var end = this.lineColToPosition(fileName, entry.end); + var start = this.lineOffsetToPosition(fileName, entry.start); + var end = this.lineOffsetToPosition(fileName, entry.end); return { name: entry.name, @@ -237,14 +237,14 @@ module ts.server { } getFormattingEditsForRange(fileName: string, start: number, end: number, options: ts.FormatCodeOptions): ts.TextChange[] { - var startLineCol = this.positionToOneBasedLineCol(fileName, start); - var endLineCol = this.positionToOneBasedLineCol(fileName, end); + var startLineOffset = this.positionToOneBasedLineOffset(fileName, start); + var endLineOffset = this.positionToOneBasedLineOffset(fileName, end); var args: protocol.FormatRequestArgs = { file: fileName, - line: startLineCol.line, - col: startLineCol.col, - endLine: endLineCol.line, - endCol: endLineCol.col, + line: startLineOffset.line, + offset: startLineOffset.offset, + endLine: endLineOffset.line, + endOffset: endLineOffset.offset, }; // TODO: handle FormatCodeOptions @@ -259,11 +259,11 @@ module ts.server { } getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: FormatCodeOptions): ts.TextChange[] { - var lineCol = this.positionToOneBasedLineCol(fileName, position); + var lineOffset = this.positionToOneBasedLineOffset(fileName, position); var args: protocol.FormatOnKeyRequestArgs = { file: fileName, - line: lineCol.line, - col: lineCol.col, + line: lineOffset.line, + offset: lineOffset.offset, key: key }; @@ -275,11 +275,11 @@ module ts.server { } getDefinitionAtPosition(fileName: string, position: number): DefinitionInfo[] { - var lineCol = this.positionToOneBasedLineCol(fileName, position); + var lineOffset = this.positionToOneBasedLineOffset(fileName, position); var args: protocol.FileLocationRequestArgs = { file: fileName, - line: lineCol.line, - col: lineCol.col, + line: lineOffset.line, + offset: lineOffset.offset, }; var request = this.processRequest(CommandNames.Definition, args); @@ -287,8 +287,8 @@ module ts.server { return response.body.map(entry => { var fileName = entry.file; - var start = this.lineColToPosition(fileName, entry.start); - var end = this.lineColToPosition(fileName, entry.end); + var start = this.lineOffsetToPosition(fileName, entry.start); + var end = this.lineOffsetToPosition(fileName, entry.end); return { containerKind: "", containerName: "", @@ -301,11 +301,11 @@ module ts.server { } getReferencesAtPosition(fileName: string, position: number): ReferenceEntry[] { - var lineCol = this.positionToOneBasedLineCol(fileName, position); + var lineOffset = this.positionToOneBasedLineOffset(fileName, position); var args: protocol.FileLocationRequestArgs = { file: fileName, - line: lineCol.line, - col: lineCol.col, + line: lineOffset.line, + offset: lineOffset.offset, }; var request = this.processRequest(CommandNames.References, args); @@ -313,8 +313,8 @@ module ts.server { return response.body.refs.map(entry => { var fileName = entry.file; - var start = this.lineColToPosition(fileName, entry.start); - var end = this.lineColToPosition(fileName, entry.end); + var start = this.lineOffsetToPosition(fileName, entry.start); + var end = this.lineOffsetToPosition(fileName, entry.end); return { fileName: fileName, textSpan: ts.createTextSpanFromBounds(start, end), @@ -340,11 +340,11 @@ module ts.server { } getRenameInfo(fileName: string, position: number, findInStrings?: boolean, findInComments?: boolean): RenameInfo { - var lineCol = this.positionToOneBasedLineCol(fileName, position); + var lineOffset = this.positionToOneBasedLineOffset(fileName, position); var args: protocol.RenameRequestArgs = { file: fileName, - line: lineCol.line, - col: lineCol.col, + line: lineOffset.line, + offset: lineOffset.offset, findInStrings, findInComments }; @@ -355,8 +355,8 @@ module ts.server { response.body.locs.map((entry: protocol.SpanGroup) => { var fileName = entry.file; entry.locs.map((loc: protocol.TextSpan) => { - var start = this.lineColToPosition(fileName, loc.start); - var end = this.lineColToPosition(fileName, loc.end); + var start = this.lineOffsetToPosition(fileName, loc.start); + var end = this.lineOffsetToPosition(fileName, loc.end); locations.push({ textSpan: ts.createTextSpanFromBounds(start, end), fileName: fileName @@ -400,7 +400,7 @@ module ts.server { text: item.text, kind: item.kind, kindModifiers: item.kindModifiers || "", - spans: item.spans.map(span=> createTextSpanFromBounds(this.lineColToPosition(fileName, span.start), this.lineColToPosition(fileName, span.end))), + spans: item.spans.map(span=> createTextSpanFromBounds(this.lineOffsetToPosition(fileName, span.start), this.lineOffsetToPosition(fileName, span.end))), childItems: this.decodeNavigationBarItems(item.childItems, fileName), indent: 0, bolded: false, @@ -444,19 +444,19 @@ module ts.server { } getBraceMatchingAtPosition(fileName: string, position: number): TextSpan[] { - var lineCol = this.positionToOneBasedLineCol(fileName, position); + var lineOffset = this.positionToOneBasedLineOffset(fileName, position); var args: protocol.FileLocationRequestArgs = { file: fileName, - line: lineCol.line, - col: lineCol.col, + line: lineOffset.line, + offset: lineOffset.offset, }; var request = this.processRequest(CommandNames.Brace, args); var response = this.processResponse(request); return response.body.map(entry => { - var start = this.lineColToPosition(fileName, entry.start); - var end = this.lineColToPosition(fileName, entry.end); + var start = this.lineOffsetToPosition(fileName, entry.start); + var end = this.lineOffsetToPosition(fileName, entry.end); return { start: start, length: end - start, diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 4861c2cdfd3..1f9df9b46f0 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -27,9 +27,13 @@ module ts.server { this.svc = ScriptVersionCache.fromString(content); } - setFormatOptions(tabSize: number, indentSize: number) { - this.formatCodeOptions.TabSize = tabSize; - this.formatCodeOptions.IndentSize = indentSize; + setFormatOptions(tabSize?: number, indentSize?: number) { + if (tabSize) { + this.formatCodeOptions.TabSize = tabSize; + } + if (indentSize) { + this.formatCodeOptions.IndentSize = indentSize; + } } close() { @@ -160,15 +164,12 @@ module ts.server { reloadScript(filename: string, tmpfilename: string, cb: () => any) { var script = this.getScriptInfo(filename); if (script) { - script.svc.reloadFromFile(tmpfilename, script.formatCodeOptions.TabSize, cb); + script.svc.reloadFromFile(tmpfilename, cb); } } editScript(filename: string, start: number, end: number, newText: string) { var script = this.getScriptInfo(filename); - if (newText && (newText.length > 0)) { - newText = expandTabs(newText, script.formatCodeOptions.TabSize); - } if (script) { script.editContent(start, end, newText); return; @@ -207,33 +208,33 @@ module ts.server { } else { var nextLineInfo = index.lineNumberToInfo(line + 2); - len = nextLineInfo.col - lineInfo.col; + len = nextLineInfo.offset - lineInfo.offset; } - return ts.createTextSpan(lineInfo.col, len); + return ts.createTextSpan(lineInfo.offset, len); } /** * @param line 1 based index - * @param col 1 based index + * @param offset 1 based index */ - lineColToPosition(filename: string, line: number, col: number): number { + lineOffsetToPosition(filename: string, line: number, offset: number): number { var script: ScriptInfo = this.filenameToScript[filename]; var index = script.snap().index; var lineInfo = index.lineNumberToInfo(line); - // TODO: assert this column is actually on the line - return (lineInfo.col + col - 1); + // TODO: assert this offset is actually on the line + return (lineInfo.offset + offset - 1); } /** * @param line 1-based index - * @param col 1-based index + * @param offset 1-based index */ - positionToLineCol(filename: string, position: number): ILineInfo { + positionToLineOffset(filename: string, position: number): ILineInfo { var script: ScriptInfo = this.filenameToScript[filename]; var index = script.snap().index; - var lineCol = index.charOffsetToLineNumberAndPos(position); - return { line: lineCol.line, col: lineCol.col + 1 }; + var lineOffset = index.charOffsetToLineNumberAndPos(position); + return { line: lineOffset.line, offset: lineOffset.offset + 1 }; } } @@ -372,12 +373,6 @@ module ts.server { hostInfo: string; } - export function expandTabs(text: string, tabSize: number) { - var spaces = generateSpaces(tabSize); - return text.replace(/\t/g, spaces); - } - - export class ProjectService { filenameToScriptInfo: ts.Map = {}; // open, non-configured files in two lists @@ -421,7 +416,7 @@ module ts.server { } else { if (info && (!info.isOpen)) { - info.svc.reloadFromFile(info.fileName, info.formatCodeOptions.TabSize); + info.svc.reloadFromFile(info.fileName); } } } @@ -646,7 +641,7 @@ module ts.server { /** * @param filename is absolute pathname */ - openFile(fileName: string, openedByClient: boolean, tabSize?: number) { + openFile(fileName: string, openedByClient: boolean) { fileName = ts.normalizePath(fileName); var info = ts.lookUp(this.filenameToScriptInfo, fileName); if (!info) { @@ -661,25 +656,11 @@ module ts.server { } if (content !== undefined) { var indentSize: number; - if (!tabSize) { - tabSize = this.hostConfiguration.formatCodeOptions.TabSize; - indentSize = this.hostConfiguration.formatCodeOptions.IndentSize; - } - else { - indentSize = tabSize; - } - if (openedByClient) { - this.log("Expanding tabs for file " + fileName + " with tab size " + tabSize.toString()); - content = expandTabs(content, tabSize); - } info = new ScriptInfo(this.host, fileName, content, openedByClient); this.filenameToScriptInfo[fileName] = info; if (!info.isOpen) { info.fileWatcher = this.host.watchFile(fileName, _ => { this.watchedFileChanged(fileName); }); } - else { - info.setFormatOptions(tabSize, indentSize); - } } } if (info) { @@ -695,9 +676,9 @@ module ts.server { * @param filename is absolute pathname */ - openClientFile(filename: string, tabSize?: number) { + openClientFile(filename: string) { // TODO: tsconfig check - var info = this.openFile(filename, true, tabSize); + var info = this.openFile(filename, true); this.addOpenFile(info); this.printProjects(); return info; @@ -878,7 +859,7 @@ module ts.server { export interface ILineInfo { line: number; - col: number; + offset: number; text?: string; leaf?: LineLeaf; } @@ -1159,9 +1140,8 @@ module ts.server { return this.currentVersion; } - reloadFromFile(filename: string, tabSize: number, cb?: () => any) { + reloadFromFile(filename: string, cb?: () => any) { var content = ts.sys.readFile(filename); - content = expandTabs(content, tabSize); this.reload(content); if (cb) cb(); @@ -1272,7 +1252,7 @@ module ts.server { getLineMapper() { return ((line: number) => { - return this.index.lineNumberToInfo(line).col; + return this.index.lineNumberToInfo(line).offset; }); } @@ -1309,7 +1289,7 @@ module ts.server { else { return { line: lineNumber, - col: this.root.charCount() + offset: this.root.charCount() } } } @@ -1395,7 +1375,7 @@ module ts.server { // check whether last characters deleted are line break var e = pos + deleteLength; var lineInfo = this.charOffsetToLineNumberAndPos(e); - if ((lineInfo && (lineInfo.col == 0))) { + if ((lineInfo && (lineInfo.offset == 0))) { // move range end just past line that will merge with previous line deleteLength += lineInfo.text.length; // store text by appending to end of insertedText @@ -1571,14 +1551,14 @@ module ts.server { if (!childInfo.child) { return { line: lineNumber, - col: charOffset, + offset: charOffset, } } else if (childInfo.childIndex < this.children.length) { if (childInfo.child.isLeaf()) { return { line: childInfo.lineNumber, - col: childInfo.charOffset, + offset: childInfo.charOffset, text: ((childInfo.child)).text, leaf: ((childInfo.child)) }; @@ -1590,7 +1570,7 @@ module ts.server { } else { var lineInfo = this.lineNumberToInfo(this.lineCount(), 0); - return { line: this.lineCount(), col: lineInfo.leaf.charCount() }; + return { line: this.lineCount(), offset: lineInfo.leaf.charCount() }; } } @@ -1599,13 +1579,13 @@ module ts.server { if (!childInfo.child) { return { line: lineNumber, - col: charOffset + offset: charOffset } - } + } else if (childInfo.child.isLeaf()) { return { line: lineNumber, - col: childInfo.charOffset, + offset: childInfo.charOffset, text: ((childInfo.child)).text, leaf: ((childInfo.child)) } diff --git a/src/server/protocol.d.ts b/src/server/protocol.d.ts index a7a0642de2e..d63aa53ba12 100644 --- a/src/server/protocol.d.ts +++ b/src/server/protocol.d.ts @@ -96,7 +96,7 @@ declare module ts.server.protocol { /** * Instances of this interface specify a location in a source file: - * (file, line, col), where line and column are 1-based. + * (file, line, character offset), where line and character offset are 1-based. */ export interface FileLocationRequestArgs extends FileRequestArgs { /** @@ -105,9 +105,9 @@ declare module ts.server.protocol { line: number; /** - * The column for the request (1-based). + * The character offset (on the line) for the request (1-based). */ - col: number; + offset: number; } /** @@ -126,11 +126,11 @@ declare module ts.server.protocol { } /** - * Location in source code expressed as (one-based) line and column. + * Location in source code expressed as (one-based) line and character offset. */ export interface Location { line: number; - col: number; + offset: number; } /** @@ -202,9 +202,9 @@ declare module ts.server.protocol { symbolName: string; /** - * The start column of the symbol (on the line provided by the references request). + * The start character offset of the symbol (on the line provided by the references request). */ - symbolStartCol: number; + symbolStartOffset: number; /** * The full display name of the symbol. @@ -339,6 +339,8 @@ declare module ts.server.protocol { export interface OpenRequestArgs extends FileRequestArgs { /** Initial tab size of file. */ tabSize?: number; + /** Number of spaces to indent during formatting */ + indentSize?: number; } /** @@ -424,9 +426,9 @@ declare module ts.server.protocol { endLine: number; /** - * Last column of range for which to format text in file. + * Character offset on last line of range for which to format text in file. */ - endCol: number; + endOffset: number; } /** @@ -805,7 +807,7 @@ declare module ts.server.protocol { */ export interface ChangeRequestArgs extends FormatRequestArgs { /** - * Optional string to insert at location (file, line, col). + * Optional string to insert at location (file, line, offset). */ insertString?: string; } @@ -829,7 +831,7 @@ declare module ts.server.protocol { /** * Brace matching request; value of command field is "brace". * Return response giving the file locations of matching braces - * found in file at location line, col. + * found in file at location line, offset. */ export interface BraceRequest extends FileLocationRequest { } diff --git a/src/server/session.ts b/src/server/session.ts index d6243e4b7a7..79eefb879da 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -44,7 +44,7 @@ module ts.server { else if (a.file == b.file) { var n = compareNumber(a.start.line, b.start.line); if (n == 0) { - return compareNumber(a.start.col, b.start.col); + return compareNumber(a.start.offset, b.start.offset); } else return n; } @@ -55,8 +55,8 @@ module ts.server { function formatDiag(fileName: string, project: Project, diag: ts.Diagnostic) { return { - start: project.compilerService.host.positionToLineCol(fileName, diag.start), - end: project.compilerService.host.positionToLineCol(fileName, diag.start + diag.length), + start: project.compilerService.host.positionToLineOffset(fileName, diag.start), + end: project.compilerService.host.positionToLineOffset(fileName, diag.start + diag.length), text: ts.flattenDiagnosticMessageText(diag.messageText, "\n") }; } @@ -260,7 +260,7 @@ module ts.server { } } - getDefinition(line: number, col: number, fileName: string): protocol.FileSpan[] { + getDefinition(line: number, offset: number, fileName: string): protocol.FileSpan[] { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); if (!project) { @@ -268,7 +268,7 @@ module ts.server { } var compilerService = project.compilerService; - var position = compilerService.host.lineColToPosition(file, line, col); + var position = compilerService.host.lineOffsetToPosition(file, line, offset); var definitions = compilerService.languageService.getDefinitionAtPosition(file, position); if (!definitions) { @@ -277,12 +277,12 @@ module ts.server { return definitions.map(def => ({ file: def.fileName, - start: compilerService.host.positionToLineCol(def.fileName, def.textSpan.start), - end: compilerService.host.positionToLineCol(def.fileName, ts.textSpanEnd(def.textSpan)) + start: compilerService.host.positionToLineOffset(def.fileName, def.textSpan.start), + end: compilerService.host.positionToLineOffset(def.fileName, ts.textSpanEnd(def.textSpan)) })); } - getRenameLocations(line: number, col: number, fileName: string,findInComments: boolean, findInStrings: boolean): protocol.RenameResponseBody { + getRenameLocations(line: number, offset: number, fileName: string,findInComments: boolean, findInStrings: boolean): protocol.RenameResponseBody { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); if (!project) { @@ -290,7 +290,7 @@ module ts.server { } var compilerService = project.compilerService; - var position = compilerService.host.lineColToPosition(file, line, col); + var position = compilerService.host.lineOffsetToPosition(file, line, offset); var renameInfo = compilerService.languageService.getRenameInfo(file, position); if (!renameInfo) { return undefined; @@ -310,8 +310,8 @@ module ts.server { var bakedRenameLocs = renameLocations.map(location => ({ file: location.fileName, - start: compilerService.host.positionToLineCol(location.fileName, location.textSpan.start), - end: compilerService.host.positionToLineCol(location.fileName, ts.textSpanEnd(location.textSpan)), + start: compilerService.host.positionToLineOffset(location.fileName, location.textSpan.start), + end: compilerService.host.positionToLineOffset(location.fileName, ts.textSpanEnd(location.textSpan)), })).sort((a, b) => { if (a.file < b.file) { return -1; @@ -328,7 +328,7 @@ module ts.server { return -1; } else { - return b.start.col - a.start.col; + return b.start.offset - a.start.offset; } } }).reduce((accum: protocol.SpanGroup[], cur: protocol.FileSpan) => { @@ -350,7 +350,7 @@ module ts.server { return { info: renameInfo, locs: bakedRenameLocs }; } - getReferences(line: number, col: number, fileName: string): protocol.ReferencesResponseBody { + getReferences(line: number, offset: number, fileName: string): protocol.ReferencesResponseBody { // TODO: get all projects for this file; report refs for all projects deleting duplicates // can avoid duplicates by eliminating same ref file from subsequent projects var file = ts.normalizePath(fileName); @@ -360,7 +360,7 @@ module ts.server { } var compilerService = project.compilerService; - var position = compilerService.host.lineColToPosition(file, line, col); + var position = compilerService.host.lineOffsetToPosition(file, line, offset); var references = compilerService.languageService.getReferencesAtPosition(file, position); if (!references) { @@ -374,10 +374,10 @@ module ts.server { var displayString = ts.displayPartsToString(nameInfo.displayParts); var nameSpan = nameInfo.textSpan; - var nameColStart = compilerService.host.positionToLineCol(file, nameSpan.start).col; + var nameColStart = compilerService.host.positionToLineOffset(file, nameSpan.start).offset; var nameText = compilerService.host.getScriptSnapshot(file).getText(nameSpan.start, ts.textSpanEnd(nameSpan)); var bakedRefs: protocol.ReferencesResponseItem[] = references.map((ref) => { - var start = compilerService.host.positionToLineCol(ref.fileName, ref.textSpan.start); + var start = compilerService.host.positionToLineOffset(ref.fileName, ref.textSpan.start); var refLineSpan = compilerService.host.lineToTextSpan(ref.fileName, start.line - 1); var snap = compilerService.host.getScriptSnapshot(ref.fileName); var lineText = snap.getText(refLineSpan.start, ts.textSpanEnd(refLineSpan)).replace(/\r|\n/g, ""); @@ -385,24 +385,27 @@ module ts.server { file: ref.fileName, start: start, lineText: lineText, - end: compilerService.host.positionToLineCol(ref.fileName, ts.textSpanEnd(ref.textSpan)), + end: compilerService.host.positionToLineOffset(ref.fileName, ts.textSpanEnd(ref.textSpan)), isWriteAccess: ref.isWriteAccess }; }).sort(compareFileStart); return { refs: bakedRefs, symbolName: nameText, - symbolStartCol: nameColStart, + symbolStartOffset: nameColStart, symbolDisplayString: displayString }; } - openClientFile(fileName: string, tabSize?: number) { + openClientFile(fileName: string, tabSize?: number, indentSize?: number) { var file = ts.normalizePath(fileName); - this.projectService.openClientFile(file, tabSize); + var info = this.projectService.openClientFile(file); + if (info) { + info.setFormatOptions(tabSize, indentSize); + } } - getQuickInfo(line: number, col: number, fileName: string): protocol.QuickInfoResponseBody { + getQuickInfo(line: number, offset: number, fileName: string): protocol.QuickInfoResponseBody { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); if (!project) { @@ -410,7 +413,7 @@ module ts.server { } var compilerService = project.compilerService; - var position = compilerService.host.lineColToPosition(file, line, col); + var position = compilerService.host.lineOffsetToPosition(file, line, offset); var quickInfo = compilerService.languageService.getQuickInfoAtPosition(file, position); if (!quickInfo) { return undefined; @@ -421,14 +424,14 @@ module ts.server { return { kind: quickInfo.kind, kindModifiers: quickInfo.kindModifiers, - start: compilerService.host.positionToLineCol(file, quickInfo.textSpan.start), - end: compilerService.host.positionToLineCol(file, ts.textSpanEnd(quickInfo.textSpan)), + start: compilerService.host.positionToLineOffset(file, quickInfo.textSpan.start), + end: compilerService.host.positionToLineOffset(file, ts.textSpanEnd(quickInfo.textSpan)), displayString: displayString, documentation: docString, }; } - getFormattingEditsForRange(line: number, col: number, endLine: number, endCol: number, fileName: string): protocol.CodeEdit[] { + getFormattingEditsForRange(line: number, offset: number, endLine: number, endOffset: number, fileName: string): protocol.CodeEdit[] { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); if (!project) { @@ -436,8 +439,8 @@ module ts.server { } var compilerService = project.compilerService; - var startPosition = compilerService.host.lineColToPosition(file, line, col); - var endPosition = compilerService.host.lineColToPosition(file, endLine, endCol); + var startPosition = compilerService.host.lineOffsetToPosition(file, line, offset); + var endPosition = compilerService.host.lineOffsetToPosition(file, endLine, endOffset); // TODO: avoid duplicate code (with formatonkey) var edits = compilerService.languageService.getFormattingEditsForRange(file, startPosition, endPosition, @@ -448,14 +451,14 @@ module ts.server { return edits.map((edit) => { return { - start: compilerService.host.positionToLineCol(file, edit.span.start), - end: compilerService.host.positionToLineCol(file, ts.textSpanEnd(edit.span)), + start: compilerService.host.positionToLineOffset(file, edit.span.start), + end: compilerService.host.positionToLineOffset(file, ts.textSpanEnd(edit.span)), newText: edit.newText ? edit.newText : "" }; }); } - getFormattingEditsAfterKeystroke(line: number, col: number, key: string, fileName: string): protocol.CodeEdit[] { + getFormattingEditsAfterKeystroke(line: number, offset: number, key: string, fileName: string): protocol.CodeEdit[] { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); @@ -464,7 +467,7 @@ module ts.server { } var compilerService = project.compilerService; - var position = compilerService.host.lineColToPosition(file, line, col); + var position = compilerService.host.lineOffsetToPosition(file, line, offset); var formatOptions = this.projectService.getFormatCodeOptions(file); var edits = compilerService.languageService.getFormattingEditsAfterKeystroke(file, position, key, formatOptions); @@ -519,16 +522,16 @@ module ts.server { return edits.map((edit) => { return { - start: compilerService.host.positionToLineCol(file, + start: compilerService.host.positionToLineOffset(file, edit.span.start), - end: compilerService.host.positionToLineCol(file, + end: compilerService.host.positionToLineOffset(file, ts.textSpanEnd(edit.span)), newText: edit.newText ? edit.newText : "" }; }); } - getCompletions(line: number, col: number, prefix: string, fileName: string): protocol.CompletionEntry[] { + getCompletions(line: number, offset: number, prefix: string, fileName: string): protocol.CompletionEntry[] { if (!prefix) { prefix = ""; } @@ -539,7 +542,7 @@ module ts.server { } var compilerService = project.compilerService; - var position = compilerService.host.lineColToPosition(file, line, col); + var position = compilerService.host.lineOffsetToPosition(file, line, offset); var completions = compilerService.languageService.getCompletionsAtPosition(file, position); if (!completions) { @@ -554,7 +557,7 @@ module ts.server { }, []); } - getCompletionEntryDetails(line: number, col: number, + getCompletionEntryDetails(line: number, offset: number, entryNames: string[], fileName: string): protocol.CompletionEntryDetails[] { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); @@ -563,7 +566,7 @@ module ts.server { } var compilerService = project.compilerService; - var position = compilerService.host.lineColToPosition(file, line, col); + var position = compilerService.host.lineOffsetToPosition(file, line, offset); return entryNames.reduce((accum: protocol.CompletionEntryDetails[], entryName: string) => { var details = compilerService.languageService.getCompletionEntryDetails(file, position, entryName); @@ -589,13 +592,13 @@ module ts.server { } } - change(line: number, col: number, endLine: number, endCol: number, insertString: string, fileName: string) { + change(line: number, offset: number, endLine: number, endOffset: number, insertString: string, fileName: string) { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); if (project) { var compilerService = project.compilerService; - var start = compilerService.host.lineColToPosition(file, line, col); - var end = compilerService.host.lineColToPosition(file, endLine, endCol); + var start = compilerService.host.lineOffsetToPosition(file, line, offset); + var end = compilerService.host.lineOffsetToPosition(file, endLine, endOffset); if (start >= 0) { compilerService.host.editScript(file, start, end, insertString); this.changeSeq++; @@ -644,8 +647,8 @@ module ts.server { kind: item.kind, kindModifiers: item.kindModifiers, spans: item.spans.map(span => ({ - start: compilerService.host.positionToLineCol(fileName, span.start), - end: compilerService.host.positionToLineCol(fileName, ts.textSpanEnd(span)) + start: compilerService.host.positionToLineOffset(fileName, span.start), + end: compilerService.host.positionToLineOffset(fileName, ts.textSpanEnd(span)) })), childItems: this.decorateNavigationBarItem(project, fileName, item.childItems) })); @@ -681,8 +684,8 @@ module ts.server { } return navItems.map((navItem) => { - var start = compilerService.host.positionToLineCol(navItem.fileName, navItem.textSpan.start); - var end = compilerService.host.positionToLineCol(navItem.fileName, ts.textSpanEnd(navItem.textSpan)); + var start = compilerService.host.positionToLineOffset(navItem.fileName, navItem.textSpan.start); + var end = compilerService.host.positionToLineOffset(navItem.fileName, ts.textSpanEnd(navItem.textSpan)); var bakedItem: protocol.NavtoItem = { name: navItem.name, kind: navItem.kind, @@ -706,7 +709,7 @@ module ts.server { }); } - getBraceMatching(line: number, col: number, fileName: string): protocol.TextSpan[] { + getBraceMatching(line: number, offset: number, fileName: string): protocol.TextSpan[] { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); @@ -715,7 +718,7 @@ module ts.server { } var compilerService = project.compilerService; - var position = compilerService.host.lineColToPosition(file, line, col); + var position = compilerService.host.lineOffsetToPosition(file, line, offset); var spans = compilerService.languageService.getBraceMatchingAtPosition(file, position); if (!spans) { @@ -723,8 +726,8 @@ module ts.server { } return spans.map(span => ({ - start: compilerService.host.positionToLineCol(file, span.start), - end: compilerService.host.positionToLineCol(file, span.start + span.length) + start: compilerService.host.positionToLineOffset(file, span.start), + end: compilerService.host.positionToLineOffset(file, span.start + span.length) })); } @@ -741,49 +744,50 @@ module ts.server { switch (request.command) { case CommandNames.Definition: { var defArgs = request.arguments; - response = this.getDefinition(defArgs.line, defArgs.col, defArgs.file); + response = this.getDefinition(defArgs.line, defArgs.offset, defArgs.file); break; } case CommandNames.References: { var refArgs = request.arguments; - response = this.getReferences(refArgs.line, refArgs.col, refArgs.file); + response = this.getReferences(refArgs.line, refArgs.offset, refArgs.file); break; } case CommandNames.Rename: { var renameArgs = request.arguments; - response = this.getRenameLocations(renameArgs.line, renameArgs.col, renameArgs.file, renameArgs.findInComments, renameArgs.findInStrings); + response = this.getRenameLocations(renameArgs.line, renameArgs.offset, renameArgs.file, renameArgs.findInComments, renameArgs.findInStrings); break; } case CommandNames.Open: { var openArgs = request.arguments; - this.openClientFile(openArgs.file,openArgs.tabSize); + this.openClientFile(openArgs.file,openArgs.tabSize, openArgs.indentSize); responseRequired = false; break; } case CommandNames.Quickinfo: { var quickinfoArgs = request.arguments; - response = this.getQuickInfo(quickinfoArgs.line, quickinfoArgs.col, quickinfoArgs.file); + response = this.getQuickInfo(quickinfoArgs.line, quickinfoArgs.offset, quickinfoArgs.file); break; } case CommandNames.Format: { var formatArgs = request.arguments; - response = this.getFormattingEditsForRange(formatArgs.line, formatArgs.col, formatArgs.endLine, formatArgs.endCol, formatArgs.file); + response = this.getFormattingEditsForRange(formatArgs.line, formatArgs.offset, formatArgs.endLine, formatArgs.endOffset, formatArgs.file); break; } case CommandNames.Formatonkey: { var formatOnKeyArgs = request.arguments; - response = this.getFormattingEditsAfterKeystroke(formatOnKeyArgs.line, formatOnKeyArgs.col, formatOnKeyArgs.key, formatOnKeyArgs.file); + response = this.getFormattingEditsAfterKeystroke(formatOnKeyArgs.line, formatOnKeyArgs.offset, formatOnKeyArgs.key, formatOnKeyArgs.file); break; } case CommandNames.Completions: { var completionsArgs = request.arguments; - response = this.getCompletions(request.arguments.line, request.arguments.col, completionsArgs.prefix, request.arguments.file); + response = this.getCompletions(completionsArgs.line, completionsArgs.offset, completionsArgs.prefix, completionsArgs.file); break; } case CommandNames.CompletionDetails: { var completionDetailsArgs = request.arguments; - response = this.getCompletionEntryDetails(request.arguments.line, request.arguments.col, completionDetailsArgs.entryNames, - request.arguments.file); + response = + this.getCompletionEntryDetails(completionDetailsArgs.line,completionDetailsArgs.offset, + completionDetailsArgs.entryNames,completionDetailsArgs.file); break; } case CommandNames.Geterr: { @@ -794,7 +798,7 @@ module ts.server { } case CommandNames.Change: { var changeArgs = request.arguments; - this.change(changeArgs.line, changeArgs.col, changeArgs.endLine, changeArgs.endCol, + this.change(changeArgs.line, changeArgs.offset, changeArgs.endLine, changeArgs.endOffset, changeArgs.insertString, changeArgs.file); responseRequired = false; break; @@ -831,7 +835,7 @@ module ts.server { } case CommandNames.Brace: { var braceArguments = request.arguments; - response = this.getBraceMatching(braceArguments.line, braceArguments.col, braceArguments.file); + response = this.getBraceMatching(braceArguments.line, braceArguments.offset, braceArguments.file); break; } case CommandNames.NavBar: { From ec4278972d8cdc949571017b063b7180c0016c3f Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 18 Mar 2015 12:08:09 -0700 Subject: [PATCH 143/159] Addressed CR feedback. --- src/services/services.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/services/services.ts b/src/services/services.ts index f5b9e36f59b..f549bce6bd5 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2618,9 +2618,13 @@ module ts { entries: activeCompletionSession.entries }; + /** + * Finds the first node that "embraces" the position, so that one may + * accurately aggregate locals from the closest containing scope. + */ function getScopeNode(initialToken: Node, position: number, sourceFile: SourceFile) { var scope = initialToken; - while (scope && (isToken(scope) || !positionBelongsToNode(scope, position, sourceFile))) { + while (scope && !positionBelongsToNode(scope, position, sourceFile)) { scope = scope.parent; } return scope; From e82ea7df0f6bc1e6932abf77647241c30fe67b76 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 18 Mar 2015 12:12:57 -0700 Subject: [PATCH 144/159] Added test for completions at beginning of file. --- .../fourslash/completionListAtBeginningOfFile01.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 tests/cases/fourslash/completionListAtBeginningOfFile01.ts diff --git a/tests/cases/fourslash/completionListAtBeginningOfFile01.ts b/tests/cases/fourslash/completionListAtBeginningOfFile01.ts new file mode 100644 index 00000000000..f811fec4c67 --- /dev/null +++ b/tests/cases/fourslash/completionListAtBeginningOfFile01.ts @@ -0,0 +1,13 @@ +/// + +/////*1*/ +////var x = 0, y = 1, z = 2; +////enum E { +//// A, B, C +////} + +goTo.marker("1"); +verify.completionListContains("x"); +verify.completionListContains("y"); +verify.completionListContains("z"); +verify.completionListContains("E"); \ No newline at end of file From ee073e19f08c623e22f51e3bc557d1286d960111 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 18 Mar 2015 12:27:28 -0700 Subject: [PATCH 145/159] Remove space. --- src/services/services.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/services.ts b/src/services/services.ts index f549bce6bd5..067e4580991 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2614,7 +2614,7 @@ module ts { return { isMemberCompletion, isNewIdentifierLocation, - isBuilder : isNewIdentifierDefinitionLocation, // temporary property used to match VS implementation + isBuilder: isNewIdentifierDefinitionLocation, // temporary property used to match VS implementation entries: activeCompletionSession.entries }; From ce3a91c186bafd8ad898693a2a720e42dd343203 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 18 Mar 2015 13:55:09 -0700 Subject: [PATCH 146/159] Added tests for const modifiers. --- ...urrencesConst.ts => getOccurrencesConst01.ts} | 0 tests/cases/fourslash/getOccurrencesConst02.ts | 16 ++++++++++++++++ tests/cases/fourslash/getOccurrencesConst03.ts | 16 ++++++++++++++++ tests/cases/fourslash/getOccurrencesConst04.ts | 12 ++++++++++++ 4 files changed, 44 insertions(+) rename tests/cases/fourslash/{getOccurrencesConst.ts => getOccurrencesConst01.ts} (100%) create mode 100644 tests/cases/fourslash/getOccurrencesConst02.ts create mode 100644 tests/cases/fourslash/getOccurrencesConst03.ts create mode 100644 tests/cases/fourslash/getOccurrencesConst04.ts diff --git a/tests/cases/fourslash/getOccurrencesConst.ts b/tests/cases/fourslash/getOccurrencesConst01.ts similarity index 100% rename from tests/cases/fourslash/getOccurrencesConst.ts rename to tests/cases/fourslash/getOccurrencesConst01.ts diff --git a/tests/cases/fourslash/getOccurrencesConst02.ts b/tests/cases/fourslash/getOccurrencesConst02.ts new file mode 100644 index 00000000000..0dc96fcca6c --- /dev/null +++ b/tests/cases/fourslash/getOccurrencesConst02.ts @@ -0,0 +1,16 @@ +/// + +////module m { +//// declare [|const|] x; +//// declare [|const|] enum E { +//// } +////} +//// +////declare [|const|] x; +////declare [|const|] enum E { +////} + +test.ranges().forEach(range => { + goTo.position(range.start); + verify.occurrencesAtPositionCount(0); +}); \ No newline at end of file diff --git a/tests/cases/fourslash/getOccurrencesConst03.ts b/tests/cases/fourslash/getOccurrencesConst03.ts new file mode 100644 index 00000000000..404ff655044 --- /dev/null +++ b/tests/cases/fourslash/getOccurrencesConst03.ts @@ -0,0 +1,16 @@ +/// + +////module m { +//// export [|const|] x; +//// export [|const|] enum E { +//// } +////} +//// +////export [|const|] x; +////export [|const|] enum E { +////} + +test.ranges().forEach(range => { + goTo.position(range.start); + verify.occurrencesAtPositionCount(0); +}); \ No newline at end of file diff --git a/tests/cases/fourslash/getOccurrencesConst04.ts b/tests/cases/fourslash/getOccurrencesConst04.ts new file mode 100644 index 00000000000..6e4d4d6112c --- /dev/null +++ b/tests/cases/fourslash/getOccurrencesConst04.ts @@ -0,0 +1,12 @@ +/// + +////export const class C { +//// private static [|const|] foo; +//// constructor(public [|const|] foo) { +//// } +////} + +test.ranges().forEach(range => { + goTo.position(range.start); + verify.occurrencesAtPositionCount(0); +}); \ No newline at end of file From 9a507fa5bf97fb0b3f36a224937e7fa170456a06 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 18 Mar 2015 14:06:58 -0700 Subject: [PATCH 147/159] Fixed test. --- tests/cases/fourslash/getOccurrencesConst04.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/cases/fourslash/getOccurrencesConst04.ts b/tests/cases/fourslash/getOccurrencesConst04.ts index 6e4d4d6112c..c7f293450d3 100644 --- a/tests/cases/fourslash/getOccurrencesConst04.ts +++ b/tests/cases/fourslash/getOccurrencesConst04.ts @@ -1,12 +1,12 @@ /// ////export const class C { -//// private static [|const|] foo; -//// constructor(public [|const|] foo) { +//// private static c/*1*/onst foo; +//// constructor(public con/*2*/st foo) { //// } ////} -test.ranges().forEach(range => { - goTo.position(range.start); - verify.occurrencesAtPositionCount(0); -}); \ No newline at end of file +goTo.marker("1"); +verify.occurrencesAtPositionCount(1); +goTo.marker("2"); +verify.occurrencesAtPositionCount(0); \ No newline at end of file From 5cbf667d787a18c09e762c2dbc77eb7e042ae6cd Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 18 Mar 2015 14:07:42 -0700 Subject: [PATCH 148/159] Fixed the contextual check for modifiers to check the original modifier instead of the flags of the node. --- src/services/services.ts | 19 ++++--------------- src/services/utilities.ts | 11 +++++++++++ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 1bf5f6336d4..dbddcc939a1 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -4011,18 +4011,18 @@ module ts { let container = declaration.parent; // Make sure we only highlight the keyword when it makes sense to do so. - if (declaration.flags & NodeFlags.AccessibilityModifier) { + if (isAccessibilityModifier(modifier)) { if (!(container.kind === SyntaxKind.ClassDeclaration || (declaration.kind === SyntaxKind.Parameter && hasKind(container, SyntaxKind.Constructor)))) { return undefined; } } - else if (declaration.flags & NodeFlags.Static) { + else if (modifier === SyntaxKind.StaticKeyword) { if (container.kind !== SyntaxKind.ClassDeclaration) { return undefined; } } - else if (declaration.flags & (NodeFlags.Export | NodeFlags.Ambient)) { + else if (modifier === SyntaxKind.ExportKeyword || modifier === SyntaxKind.DeclareKeyword) { if (!(container.kind === SyntaxKind.ModuleBlock || container.kind === SyntaxKind.SourceFile)) { return undefined; } @@ -4063,7 +4063,7 @@ module ts { default: Debug.fail("Invalid container kind.") } - + forEach(nodes, node => { if (node.modifiers && node.flags & modifierFlag) { forEach(node.modifiers, child => pushKeywordIf(keywords, child, modifier)); @@ -5843,17 +5843,6 @@ module ts { // a string literal, and a template end consisting of '} } `'. let templateStack: SyntaxKind[] = []; - function isAccessibilityModifier(kind: SyntaxKind) { - switch (kind) { - case SyntaxKind.PublicKeyword: - case SyntaxKind.PrivateKeyword: - case SyntaxKind.ProtectedKeyword: - return true; - } - - return false; - } - /** Returns true if 'keyword2' can legally follow 'keyword1' in any language construct. */ function canFollow(keyword1: SyntaxKind, keyword2: SyntaxKind) { if (isAccessibilityModifier(keyword1)) { diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 7671ee3f88d..6f7957cb4ea 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -320,6 +320,17 @@ module ts { && (node.getStart() < position && position < node.getEnd()) || (!!node.isUnterminated && position === node.getEnd()); } + export function isAccessibilityModifier(kind: SyntaxKind) { + switch (kind) { + case SyntaxKind.PublicKeyword: + case SyntaxKind.PrivateKeyword: + case SyntaxKind.ProtectedKeyword: + return true; + } + + return false; + } + export function compareDataObjects(dst: any, src: any): boolean { for (let e in dst) { if (typeof dst[e] === "object") { From 7462915baf4f4dee29be8c89cff5e01b7b338c30 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 18 Mar 2015 14:11:50 -0700 Subject: [PATCH 149/159] Expose setParentNodes on createCompilerHost --- src/compiler/program.ts | 4 ++-- tests/baselines/reference/APISample_compile.js | 2 +- tests/baselines/reference/APISample_compile.types | 5 +++-- tests/baselines/reference/APISample_linter.js | 2 +- tests/baselines/reference/APISample_linter.types | 5 +++-- tests/baselines/reference/APISample_transform.js | 2 +- tests/baselines/reference/APISample_transform.types | 5 +++-- tests/baselines/reference/APISample_watcher.js | 2 +- tests/baselines/reference/APISample_watcher.types | 5 +++-- 9 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 253daff86d3..875c1c43d4c 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -10,7 +10,7 @@ module ts { /** The version of the TypeScript compiler release */ export let version = "1.5.0.0"; - export function createCompilerHost(options: CompilerOptions): CompilerHost { + export function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost { let currentDirectory: string; let existingDirectories: Map = {}; @@ -38,7 +38,7 @@ module ts { } text = ""; } - return text !== undefined ? createSourceFile(fileName, text, languageVersion) : undefined; + return text !== undefined ? createSourceFile(fileName, text, languageVersion, setParentNodes) : undefined; } function directoryExists(directoryPath: string): boolean { diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index 575c2bdaf36..533e0a3512f 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -1472,7 +1472,7 @@ declare module "typescript" { declare module "typescript" { /** The version of the TypeScript compiler release */ let version: string; - function createCompilerHost(options: CompilerOptions): CompilerHost; + function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; function getPreEmitDiagnostics(program: Program): Diagnostic[]; function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program; diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index 336d70aa1a1..1d5260dec2e 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -4714,10 +4714,11 @@ declare module "typescript" { let version: string; >version : string - function createCompilerHost(options: CompilerOptions): CompilerHost; ->createCompilerHost : (options: CompilerOptions) => CompilerHost + function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; +>createCompilerHost : (options: CompilerOptions, setParentNodes?: boolean) => CompilerHost >options : CompilerOptions >CompilerOptions : CompilerOptions +>setParentNodes : boolean >CompilerHost : CompilerHost function getPreEmitDiagnostics(program: Program): Diagnostic[]; diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index e7145e24070..116df90ffa6 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -1503,7 +1503,7 @@ declare module "typescript" { declare module "typescript" { /** The version of the TypeScript compiler release */ let version: string; - function createCompilerHost(options: CompilerOptions): CompilerHost; + function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; function getPreEmitDiagnostics(program: Program): Diagnostic[]; function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program; diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index a40848b9e4c..e277cabf479 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -4860,10 +4860,11 @@ declare module "typescript" { let version: string; >version : string - function createCompilerHost(options: CompilerOptions): CompilerHost; ->createCompilerHost : (options: CompilerOptions) => CompilerHost + function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; +>createCompilerHost : (options: CompilerOptions, setParentNodes?: boolean) => CompilerHost >options : CompilerOptions >CompilerOptions : CompilerOptions +>setParentNodes : boolean >CompilerHost : CompilerHost function getPreEmitDiagnostics(program: Program): Diagnostic[]; diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index da8fe979d17..0879052a239 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -1504,7 +1504,7 @@ declare module "typescript" { declare module "typescript" { /** The version of the TypeScript compiler release */ let version: string; - function createCompilerHost(options: CompilerOptions): CompilerHost; + function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; function getPreEmitDiagnostics(program: Program): Diagnostic[]; function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program; diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index b694678d4cb..ed551e0749a 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -4810,10 +4810,11 @@ declare module "typescript" { let version: string; >version : string - function createCompilerHost(options: CompilerOptions): CompilerHost; ->createCompilerHost : (options: CompilerOptions) => CompilerHost + function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; +>createCompilerHost : (options: CompilerOptions, setParentNodes?: boolean) => CompilerHost >options : CompilerOptions >CompilerOptions : CompilerOptions +>setParentNodes : boolean >CompilerHost : CompilerHost function getPreEmitDiagnostics(program: Program): Diagnostic[]; diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index f380994eba8..a4d88e22b78 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -1541,7 +1541,7 @@ declare module "typescript" { declare module "typescript" { /** The version of the TypeScript compiler release */ let version: string; - function createCompilerHost(options: CompilerOptions): CompilerHost; + function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; function getPreEmitDiagnostics(program: Program): Diagnostic[]; function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string; function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost): Program; diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index 06329de5c96..f73db5f983d 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -4983,10 +4983,11 @@ declare module "typescript" { let version: string; >version : string - function createCompilerHost(options: CompilerOptions): CompilerHost; ->createCompilerHost : (options: CompilerOptions) => CompilerHost + function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost; +>createCompilerHost : (options: CompilerOptions, setParentNodes?: boolean) => CompilerHost >options : CompilerOptions >CompilerOptions : CompilerOptions +>setParentNodes : boolean >CompilerHost : CompilerHost function getPreEmitDiagnostics(program: Program): Diagnostic[]; From 2902aa2ba330c56e18ef418695b18c814dc9019b Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 18 Mar 2015 14:21:17 -0700 Subject: [PATCH 150/159] Added tests. --- ...dProperty.ts => goToDefinitionShorthandProperty01.ts} | 0 .../cases/fourslash/goToDefinitionShorthandProperty02.ts | 9 +++++++++ .../cases/fourslash/goToDefinitionShorthandProperty03.ts | 9 +++++++++ 3 files changed, 18 insertions(+) rename tests/cases/fourslash/{goToDefinitionShorthandProperty.ts => goToDefinitionShorthandProperty01.ts} (100%) create mode 100644 tests/cases/fourslash/goToDefinitionShorthandProperty02.ts create mode 100644 tests/cases/fourslash/goToDefinitionShorthandProperty03.ts diff --git a/tests/cases/fourslash/goToDefinitionShorthandProperty.ts b/tests/cases/fourslash/goToDefinitionShorthandProperty01.ts similarity index 100% rename from tests/cases/fourslash/goToDefinitionShorthandProperty.ts rename to tests/cases/fourslash/goToDefinitionShorthandProperty01.ts diff --git a/tests/cases/fourslash/goToDefinitionShorthandProperty02.ts b/tests/cases/fourslash/goToDefinitionShorthandProperty02.ts new file mode 100644 index 00000000000..033cb1d6bab --- /dev/null +++ b/tests/cases/fourslash/goToDefinitionShorthandProperty02.ts @@ -0,0 +1,9 @@ +/// + +////let x = { +//// f/*1*/oo +////} + +goTo.marker("1"); +goTo.definition(); +verify.not.definitionLocationExists(); \ No newline at end of file diff --git a/tests/cases/fourslash/goToDefinitionShorthandProperty03.ts b/tests/cases/fourslash/goToDefinitionShorthandProperty03.ts new file mode 100644 index 00000000000..5e61c19c7cc --- /dev/null +++ b/tests/cases/fourslash/goToDefinitionShorthandProperty03.ts @@ -0,0 +1,9 @@ +/// + +////let /*def*/x = { +//// /*prop*/x +////} + +goTo.marker("prop"); +goTo.definition(); +verify.caretAtMarker("def"); \ No newline at end of file From 2ad40c25c9778494bd5938e10bb3b50d55e56ec8 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 18 Mar 2015 14:29:02 -0700 Subject: [PATCH 151/159] addressed PR feedback --- src/compiler/checker.ts | 4 +- .../diagnosticInformationMap.generated.ts | 2 +- src/compiler/diagnosticMessages.json | 2 +- src/compiler/emitter.ts | 4 +- src/compiler/types.ts | 2 +- .../baselines/reference/APISample_compile.js | 2 +- .../reference/APISample_compile.types | 4 +- tests/baselines/reference/APISample_linter.js | 2 +- .../reference/APISample_linter.types | 4 +- .../reference/APISample_transform.js | 2 +- .../reference/APISample_transform.types | 4 +- .../baselines/reference/APISample_watcher.js | 2 +- .../reference/APISample_watcher.types | 4 +- .../declarationEmitDefaultExport7.errors.txt | 4 +- .../compiler/es6ImportDefaultBinding.ts.orig | 18 ------- ...aultBindingFollowedWithNamedImport.ts.orig | 34 ------------- ...ultBindingFollowedWithNamedImport1.ts.orig | 24 --------- ...tBindingFollowedWithNamedImportDts.ts.orig | 28 ----------- ...indingFollowedWithNamespaceBinding.ts.orig | 13 ----- ...ndingFollowedWithNamespaceBinding1.ts.orig | 14 ------ ...es6ImportDefaultBindingMergeErrors.ts.orig | 19 ------- ...ortDefaultBindingNoDefaultProperty.ts.orig | 11 ----- .../compiler/es6ImportNameSpaceImport.ts.orig | 17 ------- ...s6ImportNameSpaceImportMergeErrors.ts.orig | 19 ------- ...mportNameSpaceImportNoNamedExports.ts.orig | 13 ----- .../compiler/es6ImportNamedImport.ts.orig | 49 ------------------- ...mportNamedImportInExportAssignment.ts.orig | 13 ----- ...edImportInIndirectExportAssignment.ts.orig | 17 ------- .../es6ImportNamedImportMergeErrors.ts.orig | 23 --------- ...es6ImportNamedImportNoExportMember.ts.orig | 13 ----- ...es6ImportNamedImportNoNamedExports.ts.orig | 14 ------ .../es6ImportWithoutFromClause.ts.orig | 16 ------ ...outFromClauseNonInstantiatedModule.ts.orig | 13 ----- 33 files changed, 21 insertions(+), 389 deletions(-) delete mode 100644 tests/cases/compiler/es6ImportDefaultBinding.ts.orig delete mode 100644 tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport.ts.orig delete mode 100644 tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1.ts.orig delete mode 100644 tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportDts.ts.orig delete mode 100644 tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding.ts.orig delete mode 100644 tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1.ts.orig delete mode 100644 tests/cases/compiler/es6ImportDefaultBindingMergeErrors.ts.orig delete mode 100644 tests/cases/compiler/es6ImportDefaultBindingNoDefaultProperty.ts.orig delete mode 100644 tests/cases/compiler/es6ImportNameSpaceImport.ts.orig delete mode 100644 tests/cases/compiler/es6ImportNameSpaceImportMergeErrors.ts.orig delete mode 100644 tests/cases/compiler/es6ImportNameSpaceImportNoNamedExports.ts.orig delete mode 100644 tests/cases/compiler/es6ImportNamedImport.ts.orig delete mode 100644 tests/cases/compiler/es6ImportNamedImportInExportAssignment.ts.orig delete mode 100644 tests/cases/compiler/es6ImportNamedImportInIndirectExportAssignment.ts.orig delete mode 100644 tests/cases/compiler/es6ImportNamedImportMergeErrors.ts.orig delete mode 100644 tests/cases/compiler/es6ImportNamedImportNoExportMember.ts.orig delete mode 100644 tests/cases/compiler/es6ImportNamedImportNoNamedExports.ts.orig delete mode 100644 tests/cases/compiler/es6ImportWithoutFromClause.ts.orig delete mode 100644 tests/cases/compiler/es6ImportWithoutFromClauseNonInstantiatedModule.ts.orig diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7b200b92fe0..a21cd936ad1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1861,7 +1861,7 @@ module ts { } } - function setDeclarationsOfIdentifierAsVisible(node: Identifier): Node[]{ + function collectLinkedAliases(node: Identifier): Node[]{ var exportSymbol: Symbol; if (node.parent && node.parent.kind === SyntaxKind.ExportAssignment) { exportSymbol = resolveName(node.parent, node.text, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace, Diagnostics.Cannot_find_name_0, node); @@ -11268,7 +11268,7 @@ module ts { isEntityNameVisible, getConstantValue, isUnknownIdentifier, - setDeclarationsOfIdentifierAsVisible, + collectLinkedAliases, getBlockScopedVariableId, }; } diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index feadd63abd7..777639c6b34 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -414,7 +414,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}'." }, + Default_export_of_the_module_has_or_is_using_private_name_0: { code: 4082, 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 fbd9866f967..27275b041da 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1651,7 +1651,7 @@ }, "Default export of the module has or is using private name '{0}'.": { "category": "Error", - "code": 4081 + "code": 4082 }, "Loop contains block-scoped variable '{0}' referenced by a function in the loop. This is only supported in ECMAScript 6 or higher.": { "category": "Error", diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 1ea1562b587..4d077709d2c 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -769,7 +769,7 @@ module ts { // Make all the declarations visible for the export name if (node.expression.kind === SyntaxKind.Identifier) { - let nodes = resolver.setDeclarationsOfIdentifierAsVisible(node.expression); + let nodes = resolver.collectLinkedAliases(node.expression); // write each of these declarations asynchronously writeAsynchronousModuleElements(nodes); @@ -967,7 +967,7 @@ module ts { emitImportOrExportSpecifier(node); // Make all the declarations visible for the export name - let nodes = resolver.setDeclarationsOfIdentifierAsVisible(node.propertyName || node.name); + let nodes = resolver.collectLinkedAliases(node.propertyName || node.name); // write each of these declarations asynchronously writeAsynchronousModuleElements(nodes); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 4209d424555..2f2d6f47f93 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1210,7 +1210,7 @@ module ts { isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; isDeclarationVisible(node: Declaration): boolean; - setDeclarationsOfIdentifierAsVisible(node: Identifier): Node[]; + collectLinkedAliases(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 b3f3b8bbd76..611230cf118 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -945,7 +945,7 @@ declare module "typescript" { isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; isDeclarationVisible(node: Declaration): boolean; - setDeclarationsOfIdentifierAsVisible(node: Identifier): Node[]; + collectLinkedAliases(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 abaaff0dee6..cd924fe677c 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -3039,8 +3039,8 @@ declare module "typescript" { >node : Declaration >Declaration : Declaration - setDeclarationsOfIdentifierAsVisible(node: Identifier): Node[]; ->setDeclarationsOfIdentifierAsVisible : (node: Identifier) => Node[] + collectLinkedAliases(node: Identifier): Node[]; +>collectLinkedAliases : (node: Identifier) => Node[] >node : Identifier >Identifier : Identifier >Node : Node diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index b36e7438145..1ac1ec35da7 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -976,7 +976,7 @@ declare module "typescript" { isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; isDeclarationVisible(node: Declaration): boolean; - setDeclarationsOfIdentifierAsVisible(node: Identifier): Node[]; + collectLinkedAliases(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 019fb66d79f..c993153b7b6 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -3185,8 +3185,8 @@ declare module "typescript" { >node : Declaration >Declaration : Declaration - setDeclarationsOfIdentifierAsVisible(node: Identifier): Node[]; ->setDeclarationsOfIdentifierAsVisible : (node: Identifier) => Node[] + collectLinkedAliases(node: Identifier): Node[]; +>collectLinkedAliases : (node: Identifier) => Node[] >node : Identifier >Identifier : Identifier >Node : Node diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index 83fad82daee..5e8048680a0 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -977,7 +977,7 @@ declare module "typescript" { isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; isDeclarationVisible(node: Declaration): boolean; - setDeclarationsOfIdentifierAsVisible(node: Identifier): Node[]; + collectLinkedAliases(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 fac36eb3891..b34bbdd936e 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -3135,8 +3135,8 @@ declare module "typescript" { >node : Declaration >Declaration : Declaration - setDeclarationsOfIdentifierAsVisible(node: Identifier): Node[]; ->setDeclarationsOfIdentifierAsVisible : (node: Identifier) => Node[] + collectLinkedAliases(node: Identifier): Node[]; +>collectLinkedAliases : (node: Identifier) => Node[] >node : Identifier >Identifier : Identifier >Node : Node diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index 90e8df87203..95803d31906 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -1014,7 +1014,7 @@ declare module "typescript" { isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean; getNodeCheckFlags(node: Node): NodeCheckFlags; isDeclarationVisible(node: Declaration): boolean; - setDeclarationsOfIdentifierAsVisible(node: Identifier): Node[]; + collectLinkedAliases(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 c65b549a4b4..31b762d0484 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -3308,8 +3308,8 @@ declare module "typescript" { >node : Declaration >Declaration : Declaration - setDeclarationsOfIdentifierAsVisible(node: Identifier): Node[]; ->setDeclarationsOfIdentifierAsVisible : (node: Identifier) => Node[] + collectLinkedAliases(node: Identifier): Node[]; +>collectLinkedAliases : (node: Identifier) => Node[] >node : Identifier >Identifier : Identifier >Node : Node diff --git a/tests/baselines/reference/declarationEmitDefaultExport7.errors.txt b/tests/baselines/reference/declarationEmitDefaultExport7.errors.txt index 2fb5bdab12c..f19766cbb00 100644 --- a/tests/baselines/reference/declarationEmitDefaultExport7.errors.txt +++ b/tests/baselines/reference/declarationEmitDefaultExport7.errors.txt @@ -1,9 +1,9 @@ -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,1): error TS4082: Default export of the module has or is using private name 'A'. ==== tests/cases/compiler/declarationEmitDefaultExport7.ts (1 errors) ==== class A {} export default new A(); ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS4081: Default export of the module has or is using private name 'A'. +!!! error TS4082: Default export of the module has or is using private name 'A'. \ No newline at end of file diff --git a/tests/cases/compiler/es6ImportDefaultBinding.ts.orig b/tests/cases/compiler/es6ImportDefaultBinding.ts.orig deleted file mode 100644 index 90ac95e7add..00000000000 --- a/tests/cases/compiler/es6ImportDefaultBinding.ts.orig +++ /dev/null @@ -1,18 +0,0 @@ -// @target: es6 -<<<<<<< HEAD -// @module: commonjs -======= ->>>>>>> master -// @declaration: true - -// @filename: es6ImportDefaultBinding_0.ts -var a = 10; -export = a; - -// @filename: es6ImportDefaultBinding_1.ts -import defaultBinding from "es6ImportDefaultBinding_0"; -<<<<<<< HEAD -var x = defaultBinding; -import defaultBinding2 from "es6ImportDefaultBinding_0"; // elide this import since defaultBinding2 is not used -======= ->>>>>>> master diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport.ts.orig b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport.ts.orig deleted file mode 100644 index 1605ecde578..00000000000 --- a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport.ts.orig +++ /dev/null @@ -1,34 +0,0 @@ -// @target: es6 -<<<<<<< HEAD -// @module: commonjs -======= ->>>>>>> master -// @declaration: true - -// @filename: es6ImportDefaultBindingFollowedWithNamedImport_0.ts -export var a = 10; -export var x = a; -export var m = a; - -// @filename: es6ImportDefaultBindingFollowedWithNamedImport_1.ts -<<<<<<< HEAD -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; -======= -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"; ->>>>>>> master diff --git a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1.ts.orig b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1.ts.orig deleted file mode 100644 index 8c55ca97fe5..00000000000 --- a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport1.ts.orig +++ /dev/null @@ -1,24 +0,0 @@ -// @target: es6 -<<<<<<< HEAD -// @module: commonjs -======= ->>>>>>> master -// @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.orig b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportDts.ts.orig deleted file mode 100644 index a55cc6059d4..00000000000 --- a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImportDts.ts.orig +++ /dev/null @@ -1,28 +0,0 @@ -<<<<<<< HEAD -// @target: es6 -======= ->>>>>>> master -// @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/es6ImportDefaultBindingFollowedWithNamespaceBinding.ts.orig b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding.ts.orig deleted file mode 100644 index dfc2a669e46..00000000000 --- a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding.ts.orig +++ /dev/null @@ -1,13 +0,0 @@ -// @target: es6 -<<<<<<< HEAD -// @module: commonjs -======= ->>>>>>> master -// @declaration: true - -// @filename: es6ImportDefaultBindingFollowedWithNamespaceBinding_0.ts -export var a = 10; - -// @filename: es6ImportDefaultBindingFollowedWithNamespaceBinding_1.ts -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.orig b/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1.ts.orig deleted file mode 100644 index c0acefb4525..00000000000 --- a/tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamespaceBinding1.ts.orig +++ /dev/null @@ -1,14 +0,0 @@ -// @target: es6 -<<<<<<< HEAD -// @module: commonjs -======= ->>>>>>> master -// @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.orig b/tests/cases/compiler/es6ImportDefaultBindingMergeErrors.ts.orig deleted file mode 100644 index 0cff021cae6..00000000000 --- a/tests/cases/compiler/es6ImportDefaultBindingMergeErrors.ts.orig +++ /dev/null @@ -1,19 +0,0 @@ -<<<<<<< HEAD -// @target: es6 -======= ->>>>>>> master -// @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.orig b/tests/cases/compiler/es6ImportDefaultBindingNoDefaultProperty.ts.orig deleted file mode 100644 index 73515821e69..00000000000 --- a/tests/cases/compiler/es6ImportDefaultBindingNoDefaultProperty.ts.orig +++ /dev/null @@ -1,11 +0,0 @@ -<<<<<<< HEAD -// @target: es6 -======= ->>>>>>> master -// @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/es6ImportNameSpaceImport.ts.orig b/tests/cases/compiler/es6ImportNameSpaceImport.ts.orig deleted file mode 100644 index 370696911b3..00000000000 --- a/tests/cases/compiler/es6ImportNameSpaceImport.ts.orig +++ /dev/null @@ -1,17 +0,0 @@ -// @target: es6 -<<<<<<< HEAD -// @module: commonjs -======= ->>>>>>> master -// @declaration: true - -// @filename: es6ImportNameSpaceImport_0.ts -export var a = 10; - -// @filename: es6ImportNameSpaceImport_1.ts -import * as nameSpaceBinding from "es6ImportNameSpaceImport_0"; -<<<<<<< HEAD -var x = nameSpaceBinding.a; -import * as nameSpaceBinding2 from "es6ImportNameSpaceImport_0"; // elide this -======= ->>>>>>> master diff --git a/tests/cases/compiler/es6ImportNameSpaceImportMergeErrors.ts.orig b/tests/cases/compiler/es6ImportNameSpaceImportMergeErrors.ts.orig deleted file mode 100644 index a101a65368c..00000000000 --- a/tests/cases/compiler/es6ImportNameSpaceImportMergeErrors.ts.orig +++ /dev/null @@ -1,19 +0,0 @@ -<<<<<<< HEAD -// @target: es6 -======= -// @target: es5 ->>>>>>> master -// @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.orig b/tests/cases/compiler/es6ImportNameSpaceImportNoNamedExports.ts.orig deleted file mode 100644 index 9a885642788..00000000000 --- a/tests/cases/compiler/es6ImportNameSpaceImportNoNamedExports.ts.orig +++ /dev/null @@ -1,13 +0,0 @@ -<<<<<<< HEAD -// @target: es6 -======= -// @target: es5 ->>>>>>> master -// @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/es6ImportNamedImport.ts.orig b/tests/cases/compiler/es6ImportNamedImport.ts.orig deleted file mode 100644 index d2e1eec5ca7..00000000000 --- a/tests/cases/compiler/es6ImportNamedImport.ts.orig +++ /dev/null @@ -1,49 +0,0 @@ -// @target: es6 -<<<<<<< HEAD -// @module: commonjs -======= ->>>>>>> master -// @declaration: true - -// @filename: es6ImportNamedImport_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: 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"; -<<<<<<< HEAD -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"; -======= -import { a1 as a11, x1 as x11 } from "es6ImportNamedImport_0"; ->>>>>>> master diff --git a/tests/cases/compiler/es6ImportNamedImportInExportAssignment.ts.orig b/tests/cases/compiler/es6ImportNamedImportInExportAssignment.ts.orig deleted file mode 100644 index b5f34c33468..00000000000 --- a/tests/cases/compiler/es6ImportNamedImportInExportAssignment.ts.orig +++ /dev/null @@ -1,13 +0,0 @@ -<<<<<<< HEAD -// @target: es6 -======= ->>>>>>> master -// @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.orig b/tests/cases/compiler/es6ImportNamedImportInIndirectExportAssignment.ts.orig deleted file mode 100644 index 9d21fa7973a..00000000000 --- a/tests/cases/compiler/es6ImportNamedImportInIndirectExportAssignment.ts.orig +++ /dev/null @@ -1,17 +0,0 @@ -<<<<<<< HEAD -// @target: es6 -======= ->>>>>>> master -// @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 diff --git a/tests/cases/compiler/es6ImportNamedImportMergeErrors.ts.orig b/tests/cases/compiler/es6ImportNamedImportMergeErrors.ts.orig deleted file mode 100644 index 833710871d2..00000000000 --- a/tests/cases/compiler/es6ImportNamedImportMergeErrors.ts.orig +++ /dev/null @@ -1,23 +0,0 @@ -<<<<<<< HEAD -// @target: es6 -======= ->>>>>>> master -// @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.orig b/tests/cases/compiler/es6ImportNamedImportNoExportMember.ts.orig deleted file mode 100644 index 999c1d985b3..00000000000 --- a/tests/cases/compiler/es6ImportNamedImportNoExportMember.ts.orig +++ /dev/null @@ -1,13 +0,0 @@ -<<<<<<< HEAD -// @target: es6 -======= ->>>>>>> master -// @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.orig b/tests/cases/compiler/es6ImportNamedImportNoNamedExports.ts.orig deleted file mode 100644 index 3b9e6341229..00000000000 --- a/tests/cases/compiler/es6ImportNamedImportNoNamedExports.ts.orig +++ /dev/null @@ -1,14 +0,0 @@ -<<<<<<< HEAD -// @target: es6 -======= -// @target: es5 ->>>>>>> master -// @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 diff --git a/tests/cases/compiler/es6ImportWithoutFromClause.ts.orig b/tests/cases/compiler/es6ImportWithoutFromClause.ts.orig deleted file mode 100644 index b2c72541d3d..00000000000 --- a/tests/cases/compiler/es6ImportWithoutFromClause.ts.orig +++ /dev/null @@ -1,16 +0,0 @@ -// @target: es6 -<<<<<<< HEAD -// @module: commonjs -======= ->>>>>>> master -// @declaration: true - -// @filename: es6ImportWithoutFromClause_0.ts -export var a = 10; - -// @filename: es6ImportWithoutFromClause_1.ts -<<<<<<< HEAD -import "es6ImportWithoutFromClause_0"; -======= -import "es6ImportWithoutFromClause_0"; ->>>>>>> master diff --git a/tests/cases/compiler/es6ImportWithoutFromClauseNonInstantiatedModule.ts.orig b/tests/cases/compiler/es6ImportWithoutFromClauseNonInstantiatedModule.ts.orig deleted file mode 100644 index 7ffeae2cbaa..00000000000 --- a/tests/cases/compiler/es6ImportWithoutFromClauseNonInstantiatedModule.ts.orig +++ /dev/null @@ -1,13 +0,0 @@ -// @target: es6 -<<<<<<< HEAD -// @module: commonjs -======= ->>>>>>> master -// @declaration: true - -// @filename: es6ImportWithoutFromClauseNonInstantiatedModule_0.ts -export interface i { -} - -// @filename: es6ImportWithoutFromClauseNonInstantiatedModule_1.ts -import "es6ImportWithoutFromClauseNonInstantiatedModule_0"; \ No newline at end of file From 773530c699d6716e0bb7c09e868709d0e19efe3c Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 18 Mar 2015 14:35:36 -0700 Subject: [PATCH 152/159] Fixed test. --- tests/cases/fourslash/goToDefinitionShorthandProperty02.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/cases/fourslash/goToDefinitionShorthandProperty02.ts b/tests/cases/fourslash/goToDefinitionShorthandProperty02.ts index 033cb1d6bab..1f8fe466277 100644 --- a/tests/cases/fourslash/goToDefinitionShorthandProperty02.ts +++ b/tests/cases/fourslash/goToDefinitionShorthandProperty02.ts @@ -5,5 +5,4 @@ ////} goTo.marker("1"); -goTo.definition(); verify.not.definitionLocationExists(); \ No newline at end of file From acd0fdfba5e6ca693e8999dc4c97aab7dc7edddf Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 18 Mar 2015 14:41:45 -0700 Subject: [PATCH 153/159] Fixed issue where goToDef on a shorthand property of an undefined entity would crash. --- src/services/services.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 067e4580991..98ad85ab612 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3492,7 +3492,6 @@ module ts { } } - let result: DefinitionInfo[] = []; // Because name in short-hand property assignment has two different meanings: property name and property value, // using go-to-definition at such position should go to the variable declaration of the property value rather than @@ -3501,16 +3500,19 @@ module ts { // assignment. This case and others are handled by the following code. if (node.parent.kind === SyntaxKind.ShorthandPropertyAssignment) { let shorthandSymbol = typeInfoResolver.getShorthandAssignmentValueSymbol(symbol.valueDeclaration); + if (!shorthandSymbol) { + return []; + } + let shorthandDeclarations = shorthandSymbol.getDeclarations(); let shorthandSymbolKind = getSymbolKind(shorthandSymbol, typeInfoResolver, node); let shorthandSymbolName = typeInfoResolver.symbolToString(shorthandSymbol); let shorthandContainerName = typeInfoResolver.symbolToString(symbol.parent, node); - forEach(shorthandDeclarations, declaration => { - result.push(getDefinitionInfo(declaration, shorthandSymbolKind, shorthandSymbolName, shorthandContainerName)); - }); - return result + return map(shorthandDeclarations, + declaration => getDefinitionInfo(declaration, shorthandSymbolKind, shorthandSymbolName, shorthandContainerName)); } + let result: DefinitionInfo[] = []; let declarations = symbol.getDeclarations(); let symbolName = typeInfoResolver.symbolToString(symbol); // Do not get scoped name, just the name of the symbol let symbolKind = getSymbolKind(symbol, typeInfoResolver, node); From 3b453e68c8b6c7a15b18ea8f917e532989f13123 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 18 Mar 2015 16:03:33 -0700 Subject: [PATCH 154/159] Extended test. --- .../goToDefinitionShorthandProperty03.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/cases/fourslash/goToDefinitionShorthandProperty03.ts b/tests/cases/fourslash/goToDefinitionShorthandProperty03.ts index 5e61c19c7cc..eb21b159f5a 100644 --- a/tests/cases/fourslash/goToDefinitionShorthandProperty03.ts +++ b/tests/cases/fourslash/goToDefinitionShorthandProperty03.ts @@ -1,9 +1,16 @@ /// -////let /*def*/x = { -//// /*prop*/x +////var /*varDef*/x = { +//// /*varProp*/x +////} +////let /*letDef*/y = { +//// /*letProp*/y ////} -goTo.marker("prop"); +goTo.marker("varProp"); goTo.definition(); -verify.caretAtMarker("def"); \ No newline at end of file +verify.caretAtMarker("varDef"); + +goTo.marker("letProp"); +goTo.definition(); +verify.caretAtMarker("letDef"); \ No newline at end of file From 49c4b5ac130491afbab2fd121dd5c98ca40fc016 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 18 Mar 2015 16:37:52 -0700 Subject: [PATCH 155/159] extract declaration emitter to separate file --- Jakefile | 6 +- src/compiler/declarationEmitter.ts | 1466 +++++++++++++++++++++++ src/compiler/emitter.ts | 1775 +--------------------------- src/compiler/utilities.ts | 313 +++++ 4 files changed, 1785 insertions(+), 1775 deletions(-) create mode 100644 src/compiler/declarationEmitter.ts diff --git a/Jakefile b/Jakefile index 3a19812b958..41f417618d7 100644 --- a/Jakefile +++ b/Jakefile @@ -39,6 +39,7 @@ var compilerSources = [ "utilities.ts", "binder.ts", "checker.ts", + "declarationEmitter.ts", "emitter.ts", "program.ts", "commandLineParser.ts", @@ -57,6 +58,7 @@ var servicesSources = [ "utilities.ts", "binder.ts", "checker.ts", + "declarationEmitter.ts", "emitter.ts", "program.ts", "commandLineParser.ts", @@ -65,7 +67,7 @@ var servicesSources = [ return path.join(compilerDirectory, f); }).concat([ "breakpoints.ts", - "navigateTo.ts", + "navigateTo.ts", "navigationBar.ts", "outliningElementsCollector.ts", "patternMatcher.ts", @@ -539,7 +541,7 @@ function cleanTestDirs() { } jake.mkdirP(localRwcBaseline); - jake.mkdirP(localTest262Baseline); + jake.mkdirP(localTest262Baseline); jake.mkdirP(localBaseline); } diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts new file mode 100644 index 00000000000..cf75467e1c5 --- /dev/null +++ b/src/compiler/declarationEmitter.ts @@ -0,0 +1,1466 @@ +/// + +module ts { + + 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; + moduleElementDeclarationEmitInfo: ModuleElementDeclarationEmitInfo[]; + synchronousDeclarationOutput: string; + referencePathsOutput: string; + } + + type GetSymbolAccessibilityDiagnostic = (symbolAccesibilityResult: SymbolAccessiblityResult) => SymbolAccessibilityDiagnostic; + + interface EmitTextWriterWithSymbolWriter extends EmitTextWriter, SymbolWriter { + getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic; + } + + interface SymbolAccessibilityDiagnostic { + errorNode: Node; + diagnosticMessage: DiagnosticMessage; + typeName?: DeclarationName; + } + + export function getDeclarationDiagnostics(host: EmitHost, resolver: EmitResolver, targetSourceFile: SourceFile): Diagnostic[] { + let diagnostics: Diagnostic[] = []; + let jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, host, ".js"); + emitDeclarations(host, resolver, diagnostics, jsFilePath, targetSourceFile); + return diagnostics; + } + + function emitDeclarations(host: EmitHost, resolver: EmitResolver, diagnostics: Diagnostic[], jsFilePath: string, root?: SourceFile): DeclarationEmit { + let newLine = host.getNewLine(); + let compilerOptions = host.getCompilerOptions(); + let languageVersion = compilerOptions.target || ScriptTarget.ES3; + + let write: (s: string) => void; + let writeLine: () => void; + let increaseIndent: () => void; + let decreaseIndent: () => void; + let writeTextOfNode: (sourceFile: SourceFile, node: Node) => void; + + let writer = createAndSetNewTextWriterWithSymbolWriter(); + + let enclosingDeclaration: Node; + let currentSourceFile: SourceFile; + let reportedDeclarationError = false; + let emitJsDocComments = compilerOptions.removeComments ? function (declaration: Node) { } : writeJsDocComments; + let emit = compilerOptions.stripInternal ? stripInternal : emitNode; + + let moduleElementDeclarationEmitInfo: ModuleElementDeclarationEmitInfo[] = []; + let 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 + // and we could be collecting these paths from multiple files into single one with --out option + let referencePathsOutput = ""; + + if (root) { + // Emitting just a single file, so emit references in this file only + if (!compilerOptions.noResolve) { + let addedGlobalFileReference = false; + forEach(root.referencedFiles, fileReference => { + let referencedFile = tryResolveScriptReference(host, root, fileReference); + + // All the references that are not going to be part of same file + if (referencedFile && ((referencedFile.flags & NodeFlags.DeclarationFile) || // This is a declare file reference + shouldEmitToOwnFile(referencedFile, compilerOptions) || // This is referenced file is emitting its own js file + !addedGlobalFileReference)) { // Or the global out file corresponding to this reference was not added + + writeReferencePath(referencedFile); + if (!isExternalModuleOrDeclarationFile(referencedFile)) { + addedGlobalFileReference = true; + } + } + }); + } + + emitSourceFile(root); + + // create asynchronous output for the importDeclarations + if (moduleElementDeclarationEmitInfo.length) { + let oldWriter = writer; + forEach(moduleElementDeclarationEmitInfo, aliasEmitInfo => { + if (aliasEmitInfo.isVisible) { + Debug.assert(aliasEmitInfo.node.kind === SyntaxKind.ImportDeclaration); + createAndSetNewTextWriterWithSymbolWriter(); + Debug.assert(aliasEmitInfo.indent === 0); + writeImportDeclaration(aliasEmitInfo.node); + aliasEmitInfo.asynchronousOutput = writer.getText(); + } + }); + setWriter(oldWriter); + } + } + else { + // Emit references corresponding to this file + let emittedReferencedFiles: SourceFile[] = []; + forEach(host.getSourceFiles(), sourceFile => { + if (!isExternalModuleOrDeclarationFile(sourceFile)) { + // Check what references need to be added + if (!compilerOptions.noResolve) { + forEach(sourceFile.referencedFiles, fileReference => { + let referencedFile = tryResolveScriptReference(host, sourceFile, fileReference); + + // If the reference file is a declaration file or an external module, emit that reference + if (referencedFile && (isExternalModuleOrDeclarationFile(referencedFile) && + !contains(emittedReferencedFiles, referencedFile))) { // If the file reference was not already emitted + + writeReferencePath(referencedFile); + emittedReferencedFiles.push(referencedFile); + } + }); + } + + emitSourceFile(sourceFile); + } + }); + } + + return { + reportedDeclarationError, + moduleElementDeclarationEmitInfo, + synchronousDeclarationOutput: writer.getText(), + referencePathsOutput, + } + + function hasInternalAnnotation(range: CommentRange) { + let text = currentSourceFile.text; + let comment = text.substring(range.pos, range.end); + return comment.indexOf("@internal") >= 0; + } + + function stripInternal(node: Node) { + if (node) { + let leadingCommentRanges = getLeadingCommentRanges(currentSourceFile.text, node.pos); + if (forEach(leadingCommentRanges, hasInternalAnnotation)) { + return; + } + + emitNode(node); + } + } + + function createAndSetNewTextWriterWithSymbolWriter(): EmitTextWriterWithSymbolWriter { + let writer = createTextWriter(newLine); + writer.trackSymbol = trackSymbol; + writer.writeKeyword = writer.write; + writer.writeOperator = writer.write; + writer.writePunctuation = writer.write; + writer.writeSpace = writer.write; + writer.writeStringLiteral = writer.writeLiteral; + writer.writeParameter = writer.write; + writer.writeSymbol = writer.write; + setWriter(writer); + return writer; + } + + function setWriter(newWriter: EmitTextWriterWithSymbolWriter) { + writer = newWriter; + write = newWriter.write; + writeTextOfNode = newWriter.writeTextOfNode; + writeLine = newWriter.writeLine; + increaseIndent = newWriter.increaseIndent; + decreaseIndent = newWriter.decreaseIndent; + } + + function writeAsynchronousModuleElements(nodes: Node[]) { + let oldWriter = writer; + forEach(nodes, declaration => { + let 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; + } + + let 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. + // export function bar(a: foo.Foo) { } + // 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 (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 (let declarationIndent = moduleElementEmitInfo.indent; declarationIndent; declarationIndent--) { + increaseIndent(); + } + + 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(); + } + } + }); + setWriter(oldWriter); + } + + function handleSymbolAccessibilityError(symbolAccesibilityResult: SymbolAccessiblityResult) { + if (symbolAccesibilityResult.accessibility === SymbolAccessibility.Accessible) { + // write the aliases + if (symbolAccesibilityResult && symbolAccesibilityResult.aliasesToMakeVisible) { + writeAsynchronousModuleElements(symbolAccesibilityResult.aliasesToMakeVisible); + } + } + else { + // Report error + reportedDeclarationError = true; + let errorInfo = writer.getSymbolAccessibilityDiagnostic(symbolAccesibilityResult); + if (errorInfo) { + if (errorInfo.typeName) { + diagnostics.push(createDiagnosticForNode(symbolAccesibilityResult.errorNode || errorInfo.errorNode, + errorInfo.diagnosticMessage, + getSourceTextOfNodeFromSourceFile(currentSourceFile, errorInfo.typeName), + symbolAccesibilityResult.errorSymbolName, + symbolAccesibilityResult.errorModuleName)); + } + else { + diagnostics.push(createDiagnosticForNode(symbolAccesibilityResult.errorNode || errorInfo.errorNode, + errorInfo.diagnosticMessage, + symbolAccesibilityResult.errorSymbolName, + symbolAccesibilityResult.errorModuleName)); + } + } + } + } + + function trackSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags) { + handleSymbolAccessibilityError(resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning)); + } + + function writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, type: TypeNode | StringLiteralExpression, getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic) { + writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic; + write(": "); + if (type) { + // Write the type + emitType(type); + } + else { + resolver.writeTypeOfDeclaration(declaration, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer); + } + } + + function writeReturnTypeAtSignature(signature: SignatureDeclaration, getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic) { + writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic; + write(": "); + if (signature.type) { + // Write the type + emitType(signature.type); + } + else { + resolver.writeReturnTypeOfSignatureDeclaration(signature, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer); + } + } + + function emitLines(nodes: Node[]) { + for (let node of nodes) { + emit(node); + } + } + + function emitSeparatedList(nodes: Node[], separator: string, eachNodeEmitFn: (node: Node) => void, canEmitFn?: (node: Node) => boolean) { + let currentWriterPos = writer.getTextPos(); + for (let node of nodes) { + if (!canEmitFn || canEmitFn(node)) { + if (currentWriterPos !== writer.getTextPos()) { + write(separator); + } + currentWriterPos = writer.getTextPos(); + eachNodeEmitFn(node); + } + } + } + + function emitCommaList(nodes: Node[], eachNodeEmitFn: (node: Node) => void, canEmitFn?: (node: Node) => boolean) { + emitSeparatedList(nodes, ", ", eachNodeEmitFn, canEmitFn); + } + + function writeJsDocComments(declaration: Node) { + if (declaration) { + let jsDocComments = getJsDocComments(declaration, currentSourceFile); + emitNewLineBeforeLeadingComments(currentSourceFile, writer, declaration, jsDocComments); + // jsDoc comments are emitted at /*leading comment1 */space/*leading comment*/space + emitComments(currentSourceFile, writer, jsDocComments, /*trailingSeparator*/ true, newLine, writeCommentRange); + } + } + + function emitTypeWithNewGetSymbolAccessibilityDiagnostic(type: TypeNode | EntityName, getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic) { + writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic; + emitType(type); + } + + function emitType(type: TypeNode | StringLiteralExpression | Identifier | QualifiedName) { + switch (type.kind) { + case SyntaxKind.AnyKeyword: + case SyntaxKind.StringKeyword: + case SyntaxKind.NumberKeyword: + case SyntaxKind.BooleanKeyword: + case SyntaxKind.SymbolKeyword: + case SyntaxKind.VoidKeyword: + case SyntaxKind.StringLiteral: + return writeTextOfNode(currentSourceFile, type); + case SyntaxKind.TypeReference: + return emitTypeReference(type); + case SyntaxKind.TypeQuery: + return emitTypeQuery(type); + case SyntaxKind.ArrayType: + return emitArrayType(type); + case SyntaxKind.TupleType: + return emitTupleType(type); + case SyntaxKind.UnionType: + return emitUnionType(type); + case SyntaxKind.ParenthesizedType: + return emitParenType(type); + case SyntaxKind.FunctionType: + case SyntaxKind.ConstructorType: + return emitSignatureDeclarationWithJsDocComments(type); + case SyntaxKind.TypeLiteral: + return emitTypeLiteral(type); + case SyntaxKind.Identifier: + return emitEntityName(type); + case SyntaxKind.QualifiedName: + return emitEntityName(type); + default: + Debug.fail("Unknown type annotation: " + type.kind); + } + + function emitEntityName(entityName: EntityName) { + let visibilityResult = resolver.isEntityNameVisible(entityName, + // Aliases can be written asynchronously so use correct enclosing declaration + entityName.parent.kind === SyntaxKind.ImportEqualsDeclaration ? entityName.parent : enclosingDeclaration); + + handleSymbolAccessibilityError(visibilityResult); + writeEntityName(entityName); + + function writeEntityName(entityName: EntityName) { + if (entityName.kind === SyntaxKind.Identifier) { + writeTextOfNode(currentSourceFile, entityName); + } + else { + let qualifiedName = entityName; + writeEntityName(qualifiedName.left); + write("."); + writeTextOfNode(currentSourceFile, qualifiedName.right); + } + } + } + + function emitTypeReference(type: TypeReferenceNode) { + emitEntityName(type.typeName); + if (type.typeArguments) { + write("<"); + emitCommaList(type.typeArguments, emitType); + write(">"); + } + } + + function emitTypeQuery(type: TypeQueryNode) { + write("typeof "); + emitEntityName(type.exprName); + } + + function emitArrayType(type: ArrayTypeNode) { + emitType(type.elementType); + write("[]"); + } + + function emitTupleType(type: TupleTypeNode) { + write("["); + emitCommaList(type.elementTypes, emitType); + write("]"); + } + + function emitUnionType(type: UnionTypeNode) { + emitSeparatedList(type.types, " | ", emitType); + } + + function emitParenType(type: ParenthesizedTypeNode) { + write("("); + emitType(type.type); + write(")"); + } + + function emitTypeLiteral(type: TypeLiteralNode) { + write("{"); + if (type.members.length) { + writeLine(); + increaseIndent(); + // write members + emitLines(type.members); + decreaseIndent(); + } + write("}"); + } + } + + function emitSourceFile(node: SourceFile) { + currentSourceFile = node; + enclosingDeclaration = node; + emitLines(node.statements); + } + + function emitExportAssignment(node: ExportAssignment) { + write(node.isExportEquals ? "export = " : "export default "); + if (node.expression.kind === SyntaxKind.Identifier) { + writeTextOfNode(currentSourceFile, node.expression); + } + else { + write(": "); + if (node.type) { + emitType(node.type); + } + else { + writer.getSymbolAccessibilityDiagnostic = getDefaultExportAccessibilityDiagnostic; + resolver.writeTypeOfExpression(node.expression, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer); + } + } + write(";"); + writeLine(); + + // Make all the declarations visible for the export name + if (node.expression.kind === SyntaxKind.Identifier) { + let nodes = resolver.collectLinkedAliases(node.expression); + + // write each of these declarations asynchronously + writeAsynchronousModuleElements(nodes); + } + + function getDefaultExportAccessibilityDiagnostic(diagnostic: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { + return { + diagnosticMessage: Diagnostics.Default_export_of_the_module_has_or_is_using_private_name_0, + errorNode: node + }; + } + } + + 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))) { + let isVisible: boolean; + 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 { + if (node.kind === SyntaxKind.ImportDeclaration) { + let 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) { + // If the node is parented in the current source file we need to emit export declare or just export + if (node.parent === currentSourceFile) { + // If the node is exported + if (node.flags & NodeFlags.Export) { + write("export "); + } + + if (node.flags & NodeFlags.Default) { + write("default "); + } + else if (node.kind !== SyntaxKind.InterfaceDeclaration) { + write("declare "); + } + } + } + + function emitClassMemberDeclarationFlags(node: Declaration) { + if (node.flags & NodeFlags.Private) { + write("private "); + } + else if (node.flags & NodeFlags.Protected) { + write("protected "); + } + + if (node.flags & NodeFlags.Static) { + write("static "); + } + } + + 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 + emitJsDocComments(node); + if (node.flags & NodeFlags.Export) { + write("export "); + } + write("import "); + writeTextOfNode(currentSourceFile, node.name); + write(" = "); + if (isInternalModuleImportEqualsDeclaration(node)) { + emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.moduleReference, getImportEntityNameVisibilityError); + write(";"); + } + else { + write("require("); + writeTextOfNode(currentSourceFile, getExternalModuleImportEqualsDeclarationExpression(node)); + write(");"); + } + writer.writeLine(); + + function getImportEntityNameVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { + return { + diagnosticMessage: Diagnostics.Import_declaration_0_is_using_private_name_1, + errorNode: node, + typeName: node.name + }; + } + } + + 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) { + if (!node.importClause && !(node.flags & NodeFlags.Export)) { + // do not write non-exported import declarations that don't have import clauses + return; + } + emitJsDocComments(node); + if (node.flags & NodeFlags.Export) { + write("export "); + } + write("import "); + if (node.importClause) { + let 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 (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); + } + else { + write("{ "); + emitCommaList((node.importClause.namedBindings).elements, emitImportOrExportSpecifier, resolver.isDeclarationVisible); + write(" }"); + } + } + write(" from "); + } + writeTextOfNode(currentSourceFile, node.moduleSpecifier); + write(";"); + writer.writeLine(); + } + + function emitImportOrExportSpecifier(node: ImportOrExportSpecifier) { + if (node.propertyName) { + writeTextOfNode(currentSourceFile, node.propertyName); + write(" as "); + } + writeTextOfNode(currentSourceFile, node.name); + } + + function emitExportSpecifier(node: ExportSpecifier) { + emitImportOrExportSpecifier(node); + + // Make all the declarations visible for the export name + let nodes = resolver.collectLinkedAliases(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); + write("module "); + writeTextOfNode(currentSourceFile, node.name); + while (node.body.kind !== SyntaxKind.ModuleBlock) { + node = node.body; + write("."); + writeTextOfNode(currentSourceFile, node.name); + } + let prevEnclosingDeclaration = enclosingDeclaration; + enclosingDeclaration = node; + write(" {"); + writeLine(); + increaseIndent(); + emitLines((node.body).statements); + decreaseIndent(); + write("}"); + writeLine(); + enclosingDeclaration = prevEnclosingDeclaration; + } + + 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, + errorNode: node.type, + typeName: node.name + }; + } + } + + 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) { + emitJsDocComments(node); + writeTextOfNode(currentSourceFile, node.name); + let enumMemberValue = resolver.getConstantValue(node); + if (enumMemberValue !== undefined) { + write(" = "); + write(enumMemberValue.toString()); + } + write(","); + writeLine(); + } + + function isPrivateMethodTypeParameter(node: TypeParameterDeclaration) { + return node.parent.kind === SyntaxKind.MethodDeclaration && (node.parent.flags & NodeFlags.Private); + } + + function emitTypeParameters(typeParameters: TypeParameterDeclaration[]) { + function emitTypeParameter(node: TypeParameterDeclaration) { + increaseIndent(); + emitJsDocComments(node); + decreaseIndent(); + writeTextOfNode(currentSourceFile, node.name); + // If there is constraint present and this is not a type parameter of the private method emit the constraint + if (node.constraint && !isPrivateMethodTypeParameter(node)) { + write(" extends "); + if (node.parent.kind === SyntaxKind.FunctionType || + node.parent.kind === SyntaxKind.ConstructorType || + (node.parent.parent && node.parent.parent.kind === SyntaxKind.TypeLiteral)) { + Debug.assert(node.parent.kind === SyntaxKind.MethodDeclaration || + node.parent.kind === SyntaxKind.MethodSignature || + node.parent.kind === SyntaxKind.FunctionType || + node.parent.kind === SyntaxKind.ConstructorType || + node.parent.kind === SyntaxKind.CallSignature || + node.parent.kind === SyntaxKind.ConstructSignature); + emitType(node.constraint); + } + else { + emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.constraint, getTypeParameterConstraintVisibilityError); + } + } + + function getTypeParameterConstraintVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { + // Type parameter constraints are named by user so we should always be able to name it + let diagnosticMessage: DiagnosticMessage; + switch (node.parent.kind) { + case SyntaxKind.ClassDeclaration: + diagnosticMessage = Diagnostics.Type_parameter_0_of_exported_class_has_or_is_using_private_name_1; + break; + + case SyntaxKind.InterfaceDeclaration: + diagnosticMessage = Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1; + break; + + case SyntaxKind.ConstructSignature: + diagnosticMessage = Diagnostics.Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1; + break; + + case SyntaxKind.CallSignature: + diagnosticMessage = Diagnostics.Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; + break; + + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: + if (node.parent.flags & NodeFlags.Static) { + diagnosticMessage = Diagnostics.Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1; + } + else if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) { + diagnosticMessage = Diagnostics.Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1; + } + else { + diagnosticMessage = Diagnostics.Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; + } + break; + + case SyntaxKind.FunctionDeclaration: + diagnosticMessage = Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_private_name_1; + break; + + default: + Debug.fail("This is unknown parent for type parameter: " + node.parent.kind); + } + + return { + diagnosticMessage, + errorNode: node, + typeName: node.name + }; + } + } + + if (typeParameters) { + write("<"); + emitCommaList(typeParameters, emitTypeParameter); + write(">"); + } + } + + function emitHeritageClause(typeReferences: TypeReferenceNode[], isImplementsList: boolean) { + if (typeReferences) { + write(isImplementsList ? " implements " : " extends "); + emitCommaList(typeReferences, emitTypeOfTypeReference); + } + + function emitTypeOfTypeReference(node: TypeReferenceNode) { + emitTypeWithNewGetSymbolAccessibilityDiagnostic(node, getHeritageClauseVisibilityError); + + function getHeritageClauseVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { + let diagnosticMessage: DiagnosticMessage; + // Heritage clause is written by user so it can always be named + if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) { + // Class or Interface implemented/extended is inaccessible + diagnosticMessage = isImplementsList ? + Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_private_name_1 : + Diagnostics.Extends_clause_of_exported_class_0_has_or_is_using_private_name_1; + } + else { + // interface is inaccessible + diagnosticMessage = Diagnostics.Extends_clause_of_exported_interface_0_has_or_is_using_private_name_1; + } + + return { + diagnosticMessage, + errorNode: node, + typeName: (node.parent.parent).name + }; + } + } + } + + function writeClassDeclaration(node: ClassDeclaration) { + function emitParameterProperties(constructorDeclaration: ConstructorDeclaration) { + if (constructorDeclaration) { + forEach(constructorDeclaration.parameters, param => { + if (param.flags & NodeFlags.AccessibilityModifier) { + emitPropertyDeclaration(param); + } + }); + } + } + + emitJsDocComments(node); + emitModuleElementDeclarationFlags(node); + write("class "); + writeTextOfNode(currentSourceFile, node.name); + let prevEnclosingDeclaration = enclosingDeclaration; + enclosingDeclaration = node; + emitTypeParameters(node.typeParameters); + let 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 writeInterfaceDeclaration(node: InterfaceDeclaration) { + emitJsDocComments(node); + emitModuleElementDeclarationFlags(node); + write("interface "); + writeTextOfNode(currentSourceFile, node.name); + let 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) { + if (hasDynamicName(node)) { + return; + } + + emitJsDocComments(node); + emitClassMemberDeclarationFlags(node); + emitVariableDeclaration(node); + write(";"); + writeLine(); + } + + 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 (isBindingPattern(node.name)) { + emitBindingPattern(node.name); + } + 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 getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult: SymbolAccessiblityResult) { + if (node.kind === SyntaxKind.VariableDeclaration) { + 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) { + 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) { + 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 + 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 { + let 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 { + let 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) { + // if this is property of type literal, + // or is parameter of method/call/construct/index signature of type literal + // emit only if type is specified + if (node.type) { + write(": "); + emitType(node.type); + } + } + + 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) { + if (hasDynamicName(node)) { + return; + } + + let accessors = getAllAccessorDeclarations((node.parent).members, node); + let accessorWithTypeAnnotation: AccessorDeclaration; + + if (node === accessors.firstAccessor) { + emitJsDocComments(accessors.getAccessor); + emitJsDocComments(accessors.setAccessor); + emitClassMemberDeclarationFlags(node); + writeTextOfNode(currentSourceFile, node.name); + if (!(node.flags & NodeFlags.Private)) { + accessorWithTypeAnnotation = node; + let type = getTypeAnnotationFromAccessor(node); + if (!type) { + // couldn't get type for the first accessor, try the another one + let anotherAccessor = node.kind === SyntaxKind.GetAccessor ? accessors.setAccessor : accessors.getAccessor; + type = getTypeAnnotationFromAccessor(anotherAccessor); + if (type) { + accessorWithTypeAnnotation = anotherAccessor; + } + } + writeTypeOfDeclaration(node, type, getAccessorDeclarationTypeVisibilityError); + } + write(";"); + writeLine(); + } + + function getTypeAnnotationFromAccessor(accessor: AccessorDeclaration): TypeNode | StringLiteralExpression { + if (accessor) { + return accessor.kind === SyntaxKind.GetAccessor + ? accessor.type // Getter - return type + : accessor.parameters.length > 0 + ? accessor.parameters[0].type // Setter parameter type + : undefined; + } + } + + function getAccessorDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { + let diagnosticMessage: DiagnosticMessage; + if (accessorWithTypeAnnotation.kind === SyntaxKind.SetAccessor) { + // Setters have to have type named and cannot infer it so, the type should always be named + if (accessorWithTypeAnnotation.parent.flags & NodeFlags.Static) { + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_private_name_1; + } + else { + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_private_name_1; + } + return { + diagnosticMessage, + errorNode: accessorWithTypeAnnotation.parameters[0], + // TODO(jfreeman): Investigate why we are passing node.name instead of node.parameters[0].name + typeName: accessorWithTypeAnnotation.name + }; + } + else { + if (accessorWithTypeAnnotation.flags & NodeFlags.Static) { + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : + Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : + Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_private_name_0; + } + else { + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : + Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : + Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_private_name_0; + } + return { + diagnosticMessage, + errorNode: accessorWithTypeAnnotation.name, + typeName: undefined + }; + } + } + } + + 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 (!resolver.isImplementationOfOverload(node)) { + emitJsDocComments(node); + if (node.kind === SyntaxKind.FunctionDeclaration) { + emitModuleElementDeclarationFlags(node); + } + else if (node.kind === SyntaxKind.MethodDeclaration) { + emitClassMemberDeclarationFlags(node); + } + if (node.kind === SyntaxKind.FunctionDeclaration) { + write("function "); + writeTextOfNode(currentSourceFile, node.name); + } + else if (node.kind === SyntaxKind.Constructor) { + write("constructor"); + } + else { + writeTextOfNode(currentSourceFile, node.name); + if (hasQuestionToken(node)) { + write("?"); + } + } + emitSignatureDeclaration(node); + } + } + + function emitSignatureDeclarationWithJsDocComments(node: SignatureDeclaration) { + emitJsDocComments(node); + emitSignatureDeclaration(node); + } + + function emitSignatureDeclaration(node: SignatureDeclaration) { + // Construct signature or constructor type write new Signature + if (node.kind === SyntaxKind.ConstructSignature || node.kind === SyntaxKind.ConstructorType) { + write("new "); + } + emitTypeParameters(node.typeParameters); + if (node.kind === SyntaxKind.IndexSignature) { + write("["); + } + else { + write("("); + } + + let prevEnclosingDeclaration = enclosingDeclaration; + enclosingDeclaration = node; + + // Parameters + emitCommaList(node.parameters, emitParameterDeclaration); + + if (node.kind === SyntaxKind.IndexSignature) { + write("]"); + } + else { + write(")"); + } + + // If this is not a constructor and is not private, emit the return type + let isFunctionTypeOrConstructorType = node.kind === SyntaxKind.FunctionType || node.kind === SyntaxKind.ConstructorType; + if (isFunctionTypeOrConstructorType || node.parent.kind === SyntaxKind.TypeLiteral) { + // Emit type literal signature return type only if specified + if (node.type) { + write(isFunctionTypeOrConstructorType ? " => " : ": "); + emitType(node.type); + } + } + else if (node.kind !== SyntaxKind.Constructor && !(node.flags & NodeFlags.Private)) { + writeReturnTypeAtSignature(node, getReturnTypeVisibilityError); + } + + enclosingDeclaration = prevEnclosingDeclaration; + + if (!isFunctionTypeOrConstructorType) { + write(";"); + writeLine(); + } + + function getReturnTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { + let diagnosticMessage: DiagnosticMessage; + switch (node.kind) { + case SyntaxKind.ConstructSignature: + // Interfaces cannot have return types that cannot be named + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : + Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_0; + break; + + case SyntaxKind.CallSignature: + // Interfaces cannot have return types that cannot be named + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : + Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_private_name_0; + break; + + case SyntaxKind.IndexSignature: + // Interfaces cannot have return types that cannot be named + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : + Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_private_name_0; + break; + + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: + if (node.flags & NodeFlags.Static) { + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : + Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : + Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_private_name_0; + } + else if (node.parent.kind === SyntaxKind.ClassDeclaration) { + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : + Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : + Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_private_name_0; + } + else { + // Interfaces cannot have return types that cannot be named + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : + Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_private_name_0; + } + break; + + case SyntaxKind.FunctionDeclaration: + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : + Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_private_module_1 : + Diagnostics.Return_type_of_exported_function_has_or_is_using_private_name_0; + break; + + default: + Debug.fail("This is unknown kind for signature: " + node.kind); + } + + return { + diagnosticMessage, + errorNode: node.name || node, + }; + } + } + + function emitParameterDeclaration(node: ParameterDeclaration) { + increaseIndent(); + emitJsDocComments(node); + if (node.dotDotDotToken) { + write("..."); + } + if (isBindingPattern(node.name)) { + write("_" + indexOf((node.parent).parameters, node)); + } + else { + writeTextOfNode(currentSourceFile, node.name); + } + if (node.initializer || hasQuestionToken(node)) { + write("?"); + } + decreaseIndent(); + + if (node.parent.kind === SyntaxKind.FunctionType || + node.parent.kind === SyntaxKind.ConstructorType || + node.parent.parent.kind === SyntaxKind.TypeLiteral) { + emitTypeOfVariableDeclarationFromTypeLiteral(node); + } + else if (!(node.parent.flags & NodeFlags.Private)) { + writeTypeOfDeclaration(node, node.type, getParameterDeclarationTypeVisibilityError); + } + + function getParameterDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { + let diagnosticMessage: DiagnosticMessage; + switch (node.parent.kind) { + case SyntaxKind.Constructor: + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : + Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_private_name_1; + break; + + case SyntaxKind.ConstructSignature: + // Interfaces cannot have parameter types that cannot be named + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1; + break; + + case SyntaxKind.CallSignature: + // Interfaces cannot have parameter types that cannot be named + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; + break; + + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: + if (node.parent.flags & NodeFlags.Static) { + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : + Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1; + } + else if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) { + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : + Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1; + } + else { + // Interfaces cannot have parameter types that cannot be named + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; + } + break; + + case SyntaxKind.FunctionDeclaration: + diagnosticMessage = symbolAccesibilityResult.errorModuleName ? + symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? + Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : + Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 : + Diagnostics.Parameter_0_of_exported_function_has_or_is_using_private_name_1; + break; + + default: + Debug.fail("This is unknown parent for parameter: " + node.parent.kind); + } + + return { + diagnosticMessage, + errorNode: node, + typeName: node.name + }; + } + } + + function emitNode(node: Node) { + switch (node.kind) { + 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.ExportDeclaration: + return emitExportDeclaration(node); + case SyntaxKind.Constructor: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: + return writeFunctionDeclaration(node); + case SyntaxKind.ConstructSignature: + case SyntaxKind.CallSignature: + case SyntaxKind.IndexSignature: + return emitSignatureDeclarationWithJsDocComments(node); + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + return emitAccessorDeclaration(node); + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: + return emitPropertyDeclaration(node); + case SyntaxKind.EnumMember: + return emitEnumMemberDeclaration(node); + case SyntaxKind.ExportAssignment: + return emitExportAssignment(node); + case SyntaxKind.SourceFile: + return emitSourceFile(node); + } + } + + function writeReferencePath(referencedFile: SourceFile) { + let declFileName = referencedFile.flags & NodeFlags.DeclarationFile + ? referencedFile.fileName // Declaration file, use declaration file name + : shouldEmitToOwnFile(referencedFile, compilerOptions) + ? getOwnEmitOutputFilePath(referencedFile, host, ".d.ts") // Own output file so get the .d.ts file + : removeFileExtension(compilerOptions.out) + ".d.ts";// Global out file + + declFileName = getRelativePathToDirectoryOrUrl( + getDirectoryPath(normalizeSlashes(jsFilePath)), + declFileName, + host.getCurrentDirectory(), + host.getCanonicalFileName, + /*isAbsolutePathAnUrl*/ false); + + referencePathsOutput += "/// " + newLine; + } + } + + // @internal + export function writeDeclarationFile(jsFilePath: string, sourceFile: SourceFile, host: EmitHost, resolver: EmitResolver, diagnostics: Diagnostic[]) { + let emitDeclarationResult = emitDeclarations(host, resolver, diagnostics, jsFilePath, sourceFile); + // 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) { + let declarationOutput = emitDeclarationResult.referencePathsOutput + + getDeclarationOutput(emitDeclarationResult.synchronousDeclarationOutput, emitDeclarationResult.moduleElementDeclarationEmitInfo); + writeFile(host, diagnostics, removeFileExtension(jsFilePath) + ".d.ts", declarationOutput, host.getCompilerOptions().emitBOM); + } + + function getDeclarationOutput(synchronousDeclarationOutput: string, moduleElementDeclarationEmitInfo: ModuleElementDeclarationEmitInfo[]) { + let appliedSyncOutputPos = 0; + let declarationOutput = ""; + // apply asynchronous additions to the synchronous output + forEach(moduleElementDeclarationEmitInfo, aliasEmitInfo => { + if (aliasEmitInfo.asynchronousOutput) { + declarationOutput += synchronousDeclarationOutput.substring(appliedSyncOutputPos, aliasEmitInfo.outputPos); + declarationOutput += getDeclarationOutput(aliasEmitInfo.asynchronousOutput, aliasEmitInfo.subModuleElementDeclarationEmitInfo); + appliedSyncOutputPos = aliasEmitInfo.outputPos; + } + }); + declarationOutput += synchronousDeclarationOutput.substring(appliedSyncOutputPos); + return declarationOutput; + } + } +} \ No newline at end of file diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index a1639ec3f40..e158856a46b 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1,20 +1,7 @@ /// +/// module ts { - interface EmitTextWriter { - write(s: string): void; - writeTextOfNode(sourceFile: SourceFile, node: Node): void; - writeLine(): void; - increaseIndent(): void; - decreaseIndent(): void; - getText(): string; - rawWrite(s: string): void; - writeLiteral(s: string): void; - getTextPos(): number; - getLine(): number; - getColumn(): number; - getIndent(): number; - } interface ExternalImportInfo { rootNode: ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration; @@ -22,1748 +9,16 @@ module ts { namedImports?: NamedImports; } - interface SymbolAccessibilityDiagnostic { - errorNode: Node; - diagnosticMessage: DiagnosticMessage; - typeName?: DeclarationName; - } - // represents one LexicalEnvironment frame to store unique generated names interface ScopeFrame { names: Map; previous: ScopeFrame; } - type GetSymbolAccessibilityDiagnostic = (symbolAccesibilityResult: SymbolAccessiblityResult) => SymbolAccessibilityDiagnostic; - - interface EmitTextWriterWithSymbolWriter extends EmitTextWriter, SymbolWriter { - getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic; - } - - 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; - moduleElementDeclarationEmitInfo: ModuleElementDeclarationEmitInfo[]; - synchronousDeclarationOutput: string; - referencePathsOutput: string; - } - - let indentStrings: string[] = ["", " "]; - export function getIndentString(level: number) { - if (indentStrings[level] === undefined) { - indentStrings[level] = getIndentString(level - 1) + indentStrings[1]; - } - return indentStrings[level]; - } - - function getIndentSize() { - return indentStrings[1].length; - } - - export function shouldEmitToOwnFile(sourceFile: SourceFile, compilerOptions: CompilerOptions): boolean { - if (!isDeclarationFile(sourceFile)) { - if ((isExternalModule(sourceFile) || !compilerOptions.out) && !fileExtensionIs(sourceFile.fileName, ".js")) { - return true; - } - return false; - } - return false; - } - export function isExternalModuleOrDeclarationFile(sourceFile: SourceFile) { return isExternalModule(sourceFile) || isDeclarationFile(sourceFile); } - function createTextWriter(newLine: String): EmitTextWriter { - let output = ""; - let indent = 0; - let lineStart = true; - let lineCount = 0; - let linePos = 0; - - function write(s: string) { - if (s && s.length) { - if (lineStart) { - output += getIndentString(indent); - lineStart = false; - } - output += s; - } - } - - function rawWrite(s: string) { - if (s !== undefined) { - if (lineStart) { - lineStart = false; - } - output += s; - } - } - - function writeLiteral(s: string) { - if (s && s.length) { - write(s); - let lineStartsOfS = computeLineStarts(s); - if (lineStartsOfS.length > 1) { - lineCount = lineCount + lineStartsOfS.length - 1; - linePos = output.length - s.length + lineStartsOfS[lineStartsOfS.length - 1]; - } - } - } - - function writeLine() { - if (!lineStart) { - output += newLine; - lineCount++; - linePos = output.length; - lineStart = true; - } - } - - function writeTextOfNode(sourceFile: SourceFile, node: Node) { - write(getSourceTextOfNodeFromSourceFile(sourceFile, node)); - } - - return { - write, - rawWrite, - writeTextOfNode, - writeLiteral, - writeLine, - increaseIndent: () => indent++, - decreaseIndent: () => indent--, - getIndent: () => indent, - getTextPos: () => output.length, - getLine: () => lineCount + 1, - getColumn: () => lineStart ? indent * getIndentSize() + 1 : output.length - linePos + 1, - getText: () => output, - }; - } - - function getLineOfLocalPosition(currentSourceFile: SourceFile, pos: number) { - return getLineAndCharacterOfPosition(currentSourceFile, pos).line; - } - - function emitNewLineBeforeLeadingComments(currentSourceFile: SourceFile, writer: EmitTextWriter, node: TextRange, leadingComments: CommentRange[]) { - // If the leading comments start on different line than the start of node, write new line - if (leadingComments && leadingComments.length && node.pos !== leadingComments[0].pos && - getLineOfLocalPosition(currentSourceFile, node.pos) !== getLineOfLocalPosition(currentSourceFile, leadingComments[0].pos)) { - writer.writeLine(); - } - } - - function emitComments(currentSourceFile: SourceFile, writer: EmitTextWriter, comments: CommentRange[], trailingSeparator: boolean, newLine: string, - writeComment: (currentSourceFile: SourceFile, writer: EmitTextWriter, comment: CommentRange, newLine: string) => void) { - let emitLeadingSpace = !trailingSeparator; - forEach(comments, comment => { - if (emitLeadingSpace) { - writer.write(" "); - emitLeadingSpace = false; - } - writeComment(currentSourceFile, writer, comment, newLine); - if (comment.hasTrailingNewLine) { - writer.writeLine(); - } - else if (trailingSeparator) { - writer.write(" "); - } - else { - // Emit leading space to separate comment during next comment emit - emitLeadingSpace = true; - } - }); - } - - function writeCommentRange(currentSourceFile: SourceFile, writer: EmitTextWriter, comment: CommentRange, newLine: string){ - if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk) { - let firstCommentLineAndCharacter = getLineAndCharacterOfPosition(currentSourceFile, comment.pos); - let lineCount = getLineStarts(currentSourceFile).length; - let firstCommentLineIndent: number; - for (let pos = comment.pos, currentLine = firstCommentLineAndCharacter.line; pos < comment.end; currentLine++) { - let nextLineStart = (currentLine + 1) === lineCount - ? currentSourceFile.text.length + 1 - : getStartPositionOfLine(currentLine + 1, currentSourceFile); - - if (pos !== comment.pos) { - // If we are not emitting first line, we need to write the spaces to adjust the alignment - if (firstCommentLineIndent === undefined) { - firstCommentLineIndent = calculateIndent(getStartPositionOfLine(firstCommentLineAndCharacter.line, currentSourceFile), comment.pos); - } - - // These are number of spaces writer is going to write at current indent - let currentWriterIndentSpacing = writer.getIndent() * getIndentSize(); - - // Number of spaces we want to be writing - // eg: Assume writer indent - // module m { - // /* starts at character 9 this is line 1 - // * starts at character pos 4 line --1 = 8 - 8 + 3 - // More left indented comment */ --2 = 8 - 8 + 2 - // class c { } - // } - // module m { - // /* this is line 1 -- Assume current writer indent 8 - // * line --3 = 8 - 4 + 5 - // More right indented comment */ --4 = 8 - 4 + 11 - // class c { } - // } - let spacesToEmit = currentWriterIndentSpacing - firstCommentLineIndent + calculateIndent(pos, nextLineStart); - if (spacesToEmit > 0) { - let numberOfSingleSpacesToEmit = spacesToEmit % getIndentSize(); - let indentSizeSpaceString = getIndentString((spacesToEmit - numberOfSingleSpacesToEmit) / getIndentSize()); - - // Write indent size string ( in eg 1: = "", 2: "" , 3: string with 8 spaces 4: string with 12 spaces - writer.rawWrite(indentSizeSpaceString); - - // Emit the single spaces (in eg: 1: 3 spaces, 2: 2 spaces, 3: 1 space, 4: 3 spaces) - while (numberOfSingleSpacesToEmit) { - writer.rawWrite(" "); - numberOfSingleSpacesToEmit--; - } - } - else { - // No spaces to emit write empty string - writer.rawWrite(""); - } - } - - // Write the comment line text - writeTrimmedCurrentLine(pos, nextLineStart); - - pos = nextLineStart; - } - } - else { - // Single line comment of style //.... - writer.write(currentSourceFile.text.substring(comment.pos, comment.end)); - } - - function writeTrimmedCurrentLine(pos: number, nextLineStart: number) { - let end = Math.min(comment.end, nextLineStart - 1); - let currentLineText = currentSourceFile.text.substring(pos, end).replace(/^\s+|\s+$/g, ''); - if (currentLineText) { - // trimmed forward and ending spaces text - writer.write(currentLineText); - if (end !== comment.end) { - writer.writeLine(); - } - } - else { - // Empty string - make sure we write empty line - writer.writeLiteral(newLine); - } - } - - function calculateIndent(pos: number, end: number) { - let currentLineIndent = 0; - for (; pos < end && isWhiteSpace(currentSourceFile.text.charCodeAt(pos)); pos++) { - if (currentSourceFile.text.charCodeAt(pos) === CharacterCodes.tab) { - // Tabs = TabSize = indent size and go to next tabStop - currentLineIndent += getIndentSize() - (currentLineIndent % getIndentSize()); - } - else { - // Single space - currentLineIndent++; - } - } - - return currentLineIndent; - } - } - - 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 getAccessor: AccessorDeclaration; - let setAccessor: AccessorDeclaration; - if (hasDynamicName(accessor)) { - firstAccessor = accessor; - if (accessor.kind === SyntaxKind.GetAccessor) { - getAccessor = accessor; - } - else if (accessor.kind === SyntaxKind.SetAccessor) { - setAccessor = accessor; - } - else { - Debug.fail("Accessor has wrong kind"); - } - } - else { - forEach(declarations, (member: Declaration) => { - if ((member.kind === SyntaxKind.GetAccessor || member.kind === SyntaxKind.SetAccessor) - && (member.flags & NodeFlags.Static) === (accessor.flags & NodeFlags.Static)) { - let memberName = getPropertyNameForPropertyNameNode(member.name); - let accessorName = getPropertyNameForPropertyNameNode(accessor.name); - if (memberName === accessorName) { - if (!firstAccessor) { - firstAccessor = member; - } - - if (member.kind === SyntaxKind.GetAccessor && !getAccessor) { - getAccessor = member; - } - - if (member.kind === SyntaxKind.SetAccessor && !setAccessor) { - setAccessor = member; - } - } - } - }); - } - return { - firstAccessor, - getAccessor, - setAccessor - }; - } - - function getSourceFilePathInNewDir(sourceFile: SourceFile, host: EmitHost, newDirPath: string) { - let sourceFilePath = getNormalizedAbsolutePath(sourceFile.fileName, host.getCurrentDirectory()); - sourceFilePath = sourceFilePath.replace(host.getCommonSourceDirectory(), ""); - return combinePaths(newDirPath, sourceFilePath); - } - - function getOwnEmitOutputFilePath(sourceFile: SourceFile, host: EmitHost, extension: string){ - let compilerOptions = host.getCompilerOptions(); - let emitOutputFilePathWithoutExtension: string; - if (compilerOptions.outDir) { - emitOutputFilePathWithoutExtension = removeFileExtension(getSourceFilePathInNewDir(sourceFile, host, compilerOptions.outDir)); - } - else { - emitOutputFilePathWithoutExtension = removeFileExtension(sourceFile.fileName); - } - - return emitOutputFilePathWithoutExtension + extension; - } - - function writeFile(host: EmitHost, diagnostics: Diagnostic[], fileName: string, data: string, writeByteOrderMark: boolean) { - host.writeFile(fileName, data, writeByteOrderMark, hostErrorMessage => { - diagnostics.push(createCompilerDiagnostic(Diagnostics.Could_not_write_file_0_Colon_1, fileName, hostErrorMessage)); - }); - } - - function emitDeclarations(host: EmitHost, resolver: EmitResolver, diagnostics: Diagnostic[], jsFilePath: string, root?: SourceFile): DeclarationEmit { - let newLine = host.getNewLine(); - let compilerOptions = host.getCompilerOptions(); - let languageVersion = compilerOptions.target || ScriptTarget.ES3; - - let write: (s: string) => void; - let writeLine: () => void; - let increaseIndent: () => void; - let decreaseIndent: () => void; - let writeTextOfNode: (sourceFile: SourceFile, node: Node) => void; - - let writer = createAndSetNewTextWriterWithSymbolWriter(); - - let enclosingDeclaration: Node; - let currentSourceFile: SourceFile; - let reportedDeclarationError = false; - let emitJsDocComments = compilerOptions.removeComments ? function (declaration: Node) { } : writeJsDocComments; - let emit = compilerOptions.stripInternal ? stripInternal : emitNode; - - let moduleElementDeclarationEmitInfo: ModuleElementDeclarationEmitInfo[] = []; - let 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 - // and we could be collecting these paths from multiple files into single one with --out option - let referencePathsOutput = ""; - - if (root) { - // Emitting just a single file, so emit references in this file only - if (!compilerOptions.noResolve) { - let addedGlobalFileReference = false; - forEach(root.referencedFiles, fileReference => { - let referencedFile = tryResolveScriptReference(host, root, fileReference); - - // All the references that are not going to be part of same file - if (referencedFile && ((referencedFile.flags & NodeFlags.DeclarationFile) || // This is a declare file reference - shouldEmitToOwnFile(referencedFile, compilerOptions) || // This is referenced file is emitting its own js file - !addedGlobalFileReference)) { // Or the global out file corresponding to this reference was not added - - writeReferencePath(referencedFile); - if (!isExternalModuleOrDeclarationFile(referencedFile)) { - addedGlobalFileReference = true; - } - } - }); - } - - emitSourceFile(root); - - // create asynchronous output for the importDeclarations - if (moduleElementDeclarationEmitInfo.length) { - let oldWriter = writer; - forEach(moduleElementDeclarationEmitInfo, aliasEmitInfo => { - if (aliasEmitInfo.isVisible) { - Debug.assert(aliasEmitInfo.node.kind === SyntaxKind.ImportDeclaration); - createAndSetNewTextWriterWithSymbolWriter(); - Debug.assert(aliasEmitInfo.indent === 0); - writeImportDeclaration(aliasEmitInfo.node); - aliasEmitInfo.asynchronousOutput = writer.getText(); - } - }); - setWriter(oldWriter); - } - } - else { - // Emit references corresponding to this file - let emittedReferencedFiles: SourceFile[] = []; - forEach(host.getSourceFiles(), sourceFile => { - if (!isExternalModuleOrDeclarationFile(sourceFile)) { - // Check what references need to be added - if (!compilerOptions.noResolve) { - forEach(sourceFile.referencedFiles, fileReference => { - let referencedFile = tryResolveScriptReference(host, sourceFile, fileReference); - - // If the reference file is a declaration file or an external module, emit that reference - if (referencedFile && (isExternalModuleOrDeclarationFile(referencedFile) && - !contains(emittedReferencedFiles, referencedFile))) { // If the file reference was not already emitted - - writeReferencePath(referencedFile); - emittedReferencedFiles.push(referencedFile); - } - }); - } - - emitSourceFile(sourceFile); - } - }); - } - - return { - reportedDeclarationError, - moduleElementDeclarationEmitInfo, - synchronousDeclarationOutput: writer.getText(), - referencePathsOutput, - } - - function hasInternalAnnotation(range: CommentRange) { - let text = currentSourceFile.text; - let comment = text.substring(range.pos, range.end); - return comment.indexOf("@internal") >= 0; - } - - function stripInternal(node: Node) { - if (node) { - let leadingCommentRanges = getLeadingCommentRanges(currentSourceFile.text, node.pos); - if (forEach(leadingCommentRanges, hasInternalAnnotation)) { - return; - } - - emitNode(node); - } - } - - function createAndSetNewTextWriterWithSymbolWriter(): EmitTextWriterWithSymbolWriter { - let writer = createTextWriter(newLine); - writer.trackSymbol = trackSymbol; - writer.writeKeyword = writer.write; - writer.writeOperator = writer.write; - writer.writePunctuation = writer.write; - writer.writeSpace = writer.write; - writer.writeStringLiteral = writer.writeLiteral; - writer.writeParameter = writer.write; - writer.writeSymbol = writer.write; - setWriter(writer); - return writer; - } - - function setWriter(newWriter: EmitTextWriterWithSymbolWriter) { - writer = newWriter; - write = newWriter.write; - writeTextOfNode = newWriter.writeTextOfNode; - writeLine = newWriter.writeLine; - increaseIndent = newWriter.increaseIndent; - decreaseIndent = newWriter.decreaseIndent; - } - - function writeAsynchronousModuleElements(nodes: Node[]) { - let oldWriter = writer; - forEach(nodes, declaration => { - let 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; - } - - let 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. - // export function bar(a: foo.Foo) { } - // 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 (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 (let declarationIndent = moduleElementEmitInfo.indent; declarationIndent; declarationIndent--) { - increaseIndent(); - } - - 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(); - } - } - }); - setWriter(oldWriter); - } - - function handleSymbolAccessibilityError(symbolAccesibilityResult: SymbolAccessiblityResult) { - if (symbolAccesibilityResult.accessibility === SymbolAccessibility.Accessible) { - // write the aliases - if (symbolAccesibilityResult && symbolAccesibilityResult.aliasesToMakeVisible) { - writeAsynchronousModuleElements(symbolAccesibilityResult.aliasesToMakeVisible); - } - } - else { - // Report error - reportedDeclarationError = true; - let errorInfo = writer.getSymbolAccessibilityDiagnostic(symbolAccesibilityResult); - if (errorInfo) { - if (errorInfo.typeName) { - diagnostics.push(createDiagnosticForNode(symbolAccesibilityResult.errorNode || errorInfo.errorNode, - errorInfo.diagnosticMessage, - getSourceTextOfNodeFromSourceFile(currentSourceFile, errorInfo.typeName), - symbolAccesibilityResult.errorSymbolName, - symbolAccesibilityResult.errorModuleName)); - } - else { - diagnostics.push(createDiagnosticForNode(symbolAccesibilityResult.errorNode || errorInfo.errorNode, - errorInfo.diagnosticMessage, - symbolAccesibilityResult.errorSymbolName, - symbolAccesibilityResult.errorModuleName)); - } - } - } - } - - function trackSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags) { - handleSymbolAccessibilityError(resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning)); - } - - function writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, type: TypeNode | StringLiteralExpression, getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic) { - writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic; - write(": "); - if (type) { - // Write the type - emitType(type); - } - else { - resolver.writeTypeOfDeclaration(declaration, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer); - } - } - - function writeReturnTypeAtSignature(signature: SignatureDeclaration, getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic) { - writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic; - write(": "); - if (signature.type) { - // Write the type - emitType(signature.type); - } - else { - resolver.writeReturnTypeOfSignatureDeclaration(signature, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer); - } - } - - function emitLines(nodes: Node[]) { - for (let node of nodes) { - emit(node); - } - } - - function emitSeparatedList(nodes: Node[], separator: string, eachNodeEmitFn: (node: Node) => void, canEmitFn?: (node: Node) => boolean) { - let currentWriterPos = writer.getTextPos(); - for (let node of nodes) { - if (!canEmitFn || canEmitFn(node)) { - if (currentWriterPos !== writer.getTextPos()) { - write(separator); - } - currentWriterPos = writer.getTextPos(); - eachNodeEmitFn(node); - } - } - } - - function emitCommaList(nodes: Node[], eachNodeEmitFn: (node: Node) => void, canEmitFn?: (node: Node) => boolean) { - emitSeparatedList(nodes, ", ", eachNodeEmitFn, canEmitFn); - } - - function writeJsDocComments(declaration: Node) { - if (declaration) { - let jsDocComments = getJsDocComments(declaration, currentSourceFile); - emitNewLineBeforeLeadingComments(currentSourceFile, writer, declaration, jsDocComments); - // jsDoc comments are emitted at /*leading comment1 */space/*leading comment*/space - emitComments(currentSourceFile, writer, jsDocComments, /*trailingSeparator*/ true, newLine, writeCommentRange); - } - } - - function emitTypeWithNewGetSymbolAccessibilityDiagnostic(type: TypeNode | EntityName, getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic) { - writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic; - emitType(type); - } - - function emitType(type: TypeNode | StringLiteralExpression | Identifier | QualifiedName) { - switch (type.kind) { - case SyntaxKind.AnyKeyword: - case SyntaxKind.StringKeyword: - case SyntaxKind.NumberKeyword: - case SyntaxKind.BooleanKeyword: - case SyntaxKind.SymbolKeyword: - case SyntaxKind.VoidKeyword: - case SyntaxKind.StringLiteral: - return writeTextOfNode(currentSourceFile, type); - case SyntaxKind.TypeReference: - return emitTypeReference(type); - case SyntaxKind.TypeQuery: - return emitTypeQuery(type); - case SyntaxKind.ArrayType: - return emitArrayType(type); - case SyntaxKind.TupleType: - return emitTupleType(type); - case SyntaxKind.UnionType: - return emitUnionType(type); - case SyntaxKind.ParenthesizedType: - return emitParenType(type); - case SyntaxKind.FunctionType: - case SyntaxKind.ConstructorType: - return emitSignatureDeclarationWithJsDocComments(type); - case SyntaxKind.TypeLiteral: - return emitTypeLiteral(type); - case SyntaxKind.Identifier: - return emitEntityName(type); - case SyntaxKind.QualifiedName: - return emitEntityName(type); - default: - Debug.fail("Unknown type annotation: " + type.kind); - } - - function emitEntityName(entityName: EntityName) { - let visibilityResult = resolver.isEntityNameVisible(entityName, - // Aliases can be written asynchronously so use correct enclosing declaration - entityName.parent.kind === SyntaxKind.ImportEqualsDeclaration ? entityName.parent : enclosingDeclaration); - - handleSymbolAccessibilityError(visibilityResult); - writeEntityName(entityName); - - function writeEntityName(entityName: EntityName) { - if (entityName.kind === SyntaxKind.Identifier) { - writeTextOfNode(currentSourceFile, entityName); - } - else { - let qualifiedName = entityName; - writeEntityName(qualifiedName.left); - write("."); - writeTextOfNode(currentSourceFile, qualifiedName.right); - } - } - } - - function emitTypeReference(type: TypeReferenceNode) { - emitEntityName(type.typeName); - if (type.typeArguments) { - write("<"); - emitCommaList(type.typeArguments, emitType); - write(">"); - } - } - - function emitTypeQuery(type: TypeQueryNode) { - write("typeof "); - emitEntityName(type.exprName); - } - - function emitArrayType(type: ArrayTypeNode) { - emitType(type.elementType); - write("[]"); - } - - function emitTupleType(type: TupleTypeNode) { - write("["); - emitCommaList(type.elementTypes, emitType); - write("]"); - } - - function emitUnionType(type: UnionTypeNode) { - emitSeparatedList(type.types, " | ", emitType); - } - - function emitParenType(type: ParenthesizedTypeNode) { - write("("); - emitType(type.type); - write(")"); - } - - function emitTypeLiteral(type: TypeLiteralNode) { - write("{"); - if (type.members.length) { - writeLine(); - increaseIndent(); - // write members - emitLines(type.members); - decreaseIndent(); - } - write("}"); - } - } - - function emitSourceFile(node: SourceFile) { - currentSourceFile = node; - enclosingDeclaration = node; - emitLines(node.statements); - } - - function emitExportAssignment(node: ExportAssignment) { - write(node.isExportEquals ? "export = " : "export default "); - if (node.expression.kind === SyntaxKind.Identifier) { - writeTextOfNode(currentSourceFile, node.expression); - } - else { - write(": "); - if (node.type) { - emitType(node.type); - } - else { - writer.getSymbolAccessibilityDiagnostic = getDefaultExportAccessibilityDiagnostic; - resolver.writeTypeOfExpression(node.expression, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer); - } - } - write(";"); - writeLine(); - - // Make all the declarations visible for the export name - if (node.expression.kind === SyntaxKind.Identifier) { - let nodes = resolver.collectLinkedAliases(node.expression); - - // write each of these declarations asynchronously - writeAsynchronousModuleElements(nodes); - } - - function getDefaultExportAccessibilityDiagnostic(diagnostic: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { - return { - diagnosticMessage: Diagnostics.Default_export_of_the_module_has_or_is_using_private_name_0, - errorNode: node - }; - } - } - - 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))) { - let isVisible: boolean; - 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 { - if (node.kind === SyntaxKind.ImportDeclaration) { - let 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) { - // If the node is parented in the current source file we need to emit export declare or just export - if (node.parent === currentSourceFile) { - // If the node is exported - if (node.flags & NodeFlags.Export) { - write("export "); - } - - if (node.flags & NodeFlags.Default) { - write("default "); - } - else if (node.kind !== SyntaxKind.InterfaceDeclaration) { - write("declare "); - } - } - } - - function emitClassMemberDeclarationFlags(node: Declaration) { - if (node.flags & NodeFlags.Private) { - write("private "); - } - else if (node.flags & NodeFlags.Protected) { - write("protected "); - } - - if (node.flags & NodeFlags.Static) { - write("static "); - } - } - - 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 - emitJsDocComments(node); - if (node.flags & NodeFlags.Export) { - write("export "); - } - write("import "); - writeTextOfNode(currentSourceFile, node.name); - write(" = "); - if (isInternalModuleImportEqualsDeclaration(node)) { - emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.moduleReference, getImportEntityNameVisibilityError); - write(";"); - } - else { - write("require("); - writeTextOfNode(currentSourceFile, getExternalModuleImportEqualsDeclarationExpression(node)); - write(");"); - } - writer.writeLine(); - - function getImportEntityNameVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { - return { - diagnosticMessage: Diagnostics.Import_declaration_0_is_using_private_name_1, - errorNode: node, - typeName: node.name - }; - } - } - - 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) { - if (!node.importClause && !(node.flags & NodeFlags.Export)) { - // do not write non-exported import declarations that don't have import clauses - return; - } - emitJsDocComments(node); - if (node.flags & NodeFlags.Export) { - write("export "); - } - write("import "); - if (node.importClause) { - let 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 (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); - } - else { - write("{ "); - emitCommaList((node.importClause.namedBindings).elements, emitImportOrExportSpecifier, resolver.isDeclarationVisible); - write(" }"); - } - } - write(" from "); - } - writeTextOfNode(currentSourceFile, node.moduleSpecifier); - write(";"); - writer.writeLine(); - } - - function emitImportOrExportSpecifier(node: ImportOrExportSpecifier) { - if (node.propertyName) { - writeTextOfNode(currentSourceFile, node.propertyName); - write(" as "); - } - writeTextOfNode(currentSourceFile, node.name); - } - - function emitExportSpecifier(node: ExportSpecifier) { - emitImportOrExportSpecifier(node); - - // Make all the declarations visible for the export name - let nodes = resolver.collectLinkedAliases(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); - write("module "); - writeTextOfNode(currentSourceFile, node.name); - while (node.body.kind !== SyntaxKind.ModuleBlock) { - node = node.body; - write("."); - writeTextOfNode(currentSourceFile, node.name); - } - let prevEnclosingDeclaration = enclosingDeclaration; - enclosingDeclaration = node; - write(" {"); - writeLine(); - increaseIndent(); - emitLines((node.body).statements); - decreaseIndent(); - write("}"); - writeLine(); - enclosingDeclaration = prevEnclosingDeclaration; - } - - 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, - errorNode: node.type, - typeName: node.name - }; - } - } - - 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) { - emitJsDocComments(node); - writeTextOfNode(currentSourceFile, node.name); - let enumMemberValue = resolver.getConstantValue(node); - if (enumMemberValue !== undefined) { - write(" = "); - write(enumMemberValue.toString()); - } - write(","); - writeLine(); - } - - function isPrivateMethodTypeParameter(node: TypeParameterDeclaration) { - return node.parent.kind === SyntaxKind.MethodDeclaration && (node.parent.flags & NodeFlags.Private); - } - - function emitTypeParameters(typeParameters: TypeParameterDeclaration[]) { - function emitTypeParameter(node: TypeParameterDeclaration) { - increaseIndent(); - emitJsDocComments(node); - decreaseIndent(); - writeTextOfNode(currentSourceFile, node.name); - // If there is constraint present and this is not a type parameter of the private method emit the constraint - if (node.constraint && !isPrivateMethodTypeParameter(node)) { - write(" extends "); - if (node.parent.kind === SyntaxKind.FunctionType || - node.parent.kind === SyntaxKind.ConstructorType || - (node.parent.parent && node.parent.parent.kind === SyntaxKind.TypeLiteral)) { - Debug.assert(node.parent.kind === SyntaxKind.MethodDeclaration || - node.parent.kind === SyntaxKind.MethodSignature || - node.parent.kind === SyntaxKind.FunctionType || - node.parent.kind === SyntaxKind.ConstructorType || - node.parent.kind === SyntaxKind.CallSignature || - node.parent.kind === SyntaxKind.ConstructSignature); - emitType(node.constraint); - } - else { - emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.constraint, getTypeParameterConstraintVisibilityError); - } - } - - function getTypeParameterConstraintVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { - // Type parameter constraints are named by user so we should always be able to name it - let diagnosticMessage: DiagnosticMessage; - switch (node.parent.kind) { - case SyntaxKind.ClassDeclaration: - diagnosticMessage = Diagnostics.Type_parameter_0_of_exported_class_has_or_is_using_private_name_1; - break; - - case SyntaxKind.InterfaceDeclaration: - diagnosticMessage = Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1; - break; - - case SyntaxKind.ConstructSignature: - diagnosticMessage = Diagnostics.Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1; - break; - - case SyntaxKind.CallSignature: - diagnosticMessage = Diagnostics.Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; - break; - - case SyntaxKind.MethodDeclaration: - case SyntaxKind.MethodSignature: - if (node.parent.flags & NodeFlags.Static) { - diagnosticMessage = Diagnostics.Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1; - } - else if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) { - diagnosticMessage = Diagnostics.Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1; - } - else { - diagnosticMessage = Diagnostics.Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; - } - break; - - case SyntaxKind.FunctionDeclaration: - diagnosticMessage = Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_private_name_1; - break; - - default: - Debug.fail("This is unknown parent for type parameter: " + node.parent.kind); - } - - return { - diagnosticMessage, - errorNode: node, - typeName: node.name - }; - } - } - - if (typeParameters) { - write("<"); - emitCommaList(typeParameters, emitTypeParameter); - write(">"); - } - } - - function emitHeritageClause(typeReferences: TypeReferenceNode[], isImplementsList: boolean) { - if (typeReferences) { - write(isImplementsList ? " implements " : " extends "); - emitCommaList(typeReferences, emitTypeOfTypeReference); - } - - function emitTypeOfTypeReference(node: TypeReferenceNode) { - emitTypeWithNewGetSymbolAccessibilityDiagnostic(node, getHeritageClauseVisibilityError); - - function getHeritageClauseVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { - let diagnosticMessage: DiagnosticMessage; - // Heritage clause is written by user so it can always be named - if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) { - // Class or Interface implemented/extended is inaccessible - diagnosticMessage = isImplementsList ? - Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_private_name_1 : - Diagnostics.Extends_clause_of_exported_class_0_has_or_is_using_private_name_1; - } - else { - // interface is inaccessible - diagnosticMessage = Diagnostics.Extends_clause_of_exported_interface_0_has_or_is_using_private_name_1; - } - - return { - diagnosticMessage, - errorNode: node, - typeName: (node.parent.parent).name - }; - } - } - } - - function writeClassDeclaration(node: ClassDeclaration) { - function emitParameterProperties(constructorDeclaration: ConstructorDeclaration) { - if (constructorDeclaration) { - forEach(constructorDeclaration.parameters, param => { - if (param.flags & NodeFlags.AccessibilityModifier) { - emitPropertyDeclaration(param); - } - }); - } - } - - emitJsDocComments(node); - emitModuleElementDeclarationFlags(node); - write("class "); - writeTextOfNode(currentSourceFile, node.name); - let prevEnclosingDeclaration = enclosingDeclaration; - enclosingDeclaration = node; - emitTypeParameters(node.typeParameters); - let 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 writeInterfaceDeclaration(node: InterfaceDeclaration) { - emitJsDocComments(node); - emitModuleElementDeclarationFlags(node); - write("interface "); - writeTextOfNode(currentSourceFile, node.name); - let 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) { - if (hasDynamicName(node)) { - return; - } - - emitJsDocComments(node); - emitClassMemberDeclarationFlags(node); - emitVariableDeclaration(node); - write(";"); - writeLine(); - } - - 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 (isBindingPattern(node.name)) { - emitBindingPattern(node.name); - } - 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 getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult: SymbolAccessiblityResult) { - if (node.kind === SyntaxKind.VariableDeclaration) { - 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) { - 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) { - 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 - 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 { - let 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 { - let 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) { - // if this is property of type literal, - // or is parameter of method/call/construct/index signature of type literal - // emit only if type is specified - if (node.type) { - write(": "); - emitType(node.type); - } - } - - 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) { - if (hasDynamicName(node)) { - return; - } - - let accessors = getAllAccessorDeclarations((node.parent).members, node); - let accessorWithTypeAnnotation: AccessorDeclaration; - - if (node === accessors.firstAccessor) { - emitJsDocComments(accessors.getAccessor); - emitJsDocComments(accessors.setAccessor); - emitClassMemberDeclarationFlags(node); - writeTextOfNode(currentSourceFile, node.name); - if (!(node.flags & NodeFlags.Private)) { - accessorWithTypeAnnotation = node; - let type = getTypeAnnotationFromAccessor(node); - if (!type) { - // couldn't get type for the first accessor, try the another one - let anotherAccessor = node.kind === SyntaxKind.GetAccessor ? accessors.setAccessor : accessors.getAccessor; - type = getTypeAnnotationFromAccessor(anotherAccessor); - if (type) { - accessorWithTypeAnnotation = anotherAccessor; - } - } - writeTypeOfDeclaration(node, type, getAccessorDeclarationTypeVisibilityError); - } - write(";"); - writeLine(); - } - - function getTypeAnnotationFromAccessor(accessor: AccessorDeclaration): TypeNode | StringLiteralExpression { - if (accessor) { - return accessor.kind === SyntaxKind.GetAccessor - ? accessor.type // Getter - return type - : accessor.parameters.length > 0 - ? accessor.parameters[0].type // Setter parameter type - : undefined; - } - } - - function getAccessorDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { - let diagnosticMessage: DiagnosticMessage; - if (accessorWithTypeAnnotation.kind === SyntaxKind.SetAccessor) { - // Setters have to have type named and cannot infer it so, the type should always be named - if (accessorWithTypeAnnotation.parent.flags & NodeFlags.Static) { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_private_name_1; - } - else { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_private_name_1; - } - return { - diagnosticMessage, - errorNode: accessorWithTypeAnnotation.parameters[0], - // TODO(jfreeman): Investigate why we are passing node.name instead of node.parameters[0].name - typeName: accessorWithTypeAnnotation.name - }; - } - else { - if (accessorWithTypeAnnotation.flags & NodeFlags.Static) { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : - Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : - Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_private_name_0; - } - else { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : - Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : - Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_private_name_0; - } - return { - diagnosticMessage, - errorNode: accessorWithTypeAnnotation.name, - typeName: undefined - }; - } - } - } - - 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 (!resolver.isImplementationOfOverload(node)) { - emitJsDocComments(node); - if (node.kind === SyntaxKind.FunctionDeclaration) { - emitModuleElementDeclarationFlags(node); - } - else if (node.kind === SyntaxKind.MethodDeclaration) { - emitClassMemberDeclarationFlags(node); - } - if (node.kind === SyntaxKind.FunctionDeclaration) { - write("function "); - writeTextOfNode(currentSourceFile, node.name); - } - else if (node.kind === SyntaxKind.Constructor) { - write("constructor"); - } - else { - writeTextOfNode(currentSourceFile, node.name); - if (hasQuestionToken(node)) { - write("?"); - } - } - emitSignatureDeclaration(node); - } - } - - function emitSignatureDeclarationWithJsDocComments(node: SignatureDeclaration) { - emitJsDocComments(node); - emitSignatureDeclaration(node); - } - - function emitSignatureDeclaration(node: SignatureDeclaration) { - // Construct signature or constructor type write new Signature - if (node.kind === SyntaxKind.ConstructSignature || node.kind === SyntaxKind.ConstructorType) { - write("new "); - } - emitTypeParameters(node.typeParameters); - if (node.kind === SyntaxKind.IndexSignature) { - write("["); - } - else { - write("("); - } - - let prevEnclosingDeclaration = enclosingDeclaration; - enclosingDeclaration = node; - - // Parameters - emitCommaList(node.parameters, emitParameterDeclaration); - - if (node.kind === SyntaxKind.IndexSignature) { - write("]"); - } - else { - write(")"); - } - - // If this is not a constructor and is not private, emit the return type - let isFunctionTypeOrConstructorType = node.kind === SyntaxKind.FunctionType || node.kind === SyntaxKind.ConstructorType; - if (isFunctionTypeOrConstructorType || node.parent.kind === SyntaxKind.TypeLiteral) { - // Emit type literal signature return type only if specified - if (node.type) { - write(isFunctionTypeOrConstructorType ? " => " : ": "); - emitType(node.type); - } - } - else if (node.kind !== SyntaxKind.Constructor && !(node.flags & NodeFlags.Private)) { - writeReturnTypeAtSignature(node, getReturnTypeVisibilityError); - } - - enclosingDeclaration = prevEnclosingDeclaration; - - if (!isFunctionTypeOrConstructorType) { - write(";"); - writeLine(); - } - - function getReturnTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { - let diagnosticMessage: DiagnosticMessage; - switch (node.kind) { - case SyntaxKind.ConstructSignature: - // Interfaces cannot have return types that cannot be named - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : - Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_0; - break; - - case SyntaxKind.CallSignature: - // Interfaces cannot have return types that cannot be named - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : - Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_private_name_0; - break; - - case SyntaxKind.IndexSignature: - // Interfaces cannot have return types that cannot be named - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : - Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_private_name_0; - break; - - case SyntaxKind.MethodDeclaration: - case SyntaxKind.MethodSignature: - if (node.flags & NodeFlags.Static) { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : - Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : - Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_private_name_0; - } - else if (node.parent.kind === SyntaxKind.ClassDeclaration) { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : - Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : - Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_private_name_0; - } - else { - // Interfaces cannot have return types that cannot be named - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : - Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_private_name_0; - } - break; - - case SyntaxKind.FunctionDeclaration: - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : - Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_private_module_1 : - Diagnostics.Return_type_of_exported_function_has_or_is_using_private_name_0; - break; - - default: - Debug.fail("This is unknown kind for signature: " + node.kind); - } - - return { - diagnosticMessage, - errorNode: node.name || node, - }; - } - } - - function emitParameterDeclaration(node: ParameterDeclaration) { - increaseIndent(); - emitJsDocComments(node); - if (node.dotDotDotToken) { - write("..."); - } - if (isBindingPattern(node.name)) { - write("_" + indexOf((node.parent).parameters, node)); - } - else { - writeTextOfNode(currentSourceFile, node.name); - } - if (node.initializer || hasQuestionToken(node)) { - write("?"); - } - decreaseIndent(); - - if (node.parent.kind === SyntaxKind.FunctionType || - node.parent.kind === SyntaxKind.ConstructorType || - node.parent.parent.kind === SyntaxKind.TypeLiteral) { - emitTypeOfVariableDeclarationFromTypeLiteral(node); - } - else if (!(node.parent.flags & NodeFlags.Private)) { - writeTypeOfDeclaration(node, node.type, getParameterDeclarationTypeVisibilityError); - } - - function getParameterDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic { - let diagnosticMessage: DiagnosticMessage; - switch (node.parent.kind) { - case SyntaxKind.Constructor: - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : - Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_private_name_1; - break; - - case SyntaxKind.ConstructSignature: - // Interfaces cannot have parameter types that cannot be named - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1; - break; - - case SyntaxKind.CallSignature: - // Interfaces cannot have parameter types that cannot be named - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1; - break; - - case SyntaxKind.MethodDeclaration: - case SyntaxKind.MethodSignature: - if (node.parent.flags & NodeFlags.Static) { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : - Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1; - } - else if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) { - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : - Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1; - } - else { - // Interfaces cannot have parameter types that cannot be named - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1; - } - break; - - case SyntaxKind.FunctionDeclaration: - diagnosticMessage = symbolAccesibilityResult.errorModuleName ? - symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ? - Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : - Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 : - Diagnostics.Parameter_0_of_exported_function_has_or_is_using_private_name_1; - break; - - default: - Debug.fail("This is unknown parent for parameter: " + node.parent.kind); - } - - return { - diagnosticMessage, - errorNode: node, - typeName: node.name - }; - } - } - - function emitNode(node: Node) { - switch (node.kind) { - 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.ExportDeclaration: - return emitExportDeclaration(node); - case SyntaxKind.Constructor: - case SyntaxKind.MethodDeclaration: - case SyntaxKind.MethodSignature: - return writeFunctionDeclaration(node); - case SyntaxKind.ConstructSignature: - case SyntaxKind.CallSignature: - case SyntaxKind.IndexSignature: - return emitSignatureDeclarationWithJsDocComments(node); - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - return emitAccessorDeclaration(node); - case SyntaxKind.PropertyDeclaration: - case SyntaxKind.PropertySignature: - return emitPropertyDeclaration(node); - case SyntaxKind.EnumMember: - return emitEnumMemberDeclaration(node); - case SyntaxKind.ExportAssignment: - return emitExportAssignment(node); - case SyntaxKind.SourceFile: - return emitSourceFile(node); - } - } - - function writeReferencePath(referencedFile: SourceFile) { - let declFileName = referencedFile.flags & NodeFlags.DeclarationFile - ? referencedFile.fileName // Declaration file, use declaration file name - : shouldEmitToOwnFile(referencedFile, compilerOptions) - ? getOwnEmitOutputFilePath(referencedFile, host, ".d.ts") // Own output file so get the .d.ts file - : removeFileExtension(compilerOptions.out) + ".d.ts";// Global out file - - declFileName = getRelativePathToDirectoryOrUrl( - getDirectoryPath(normalizeSlashes(jsFilePath)), - declFileName, - host.getCurrentDirectory(), - host.getCanonicalFileName, - /*isAbsolutePathAnUrl*/ false); - - referencePathsOutput += "/// " + newLine; - } - } - - export function getDeclarationDiagnostics(host: EmitHost, resolver: EmitResolver, targetSourceFile: SourceFile): Diagnostic[] { - let diagnostics: Diagnostic[] = []; - let jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, host, ".js"); - emitDeclarations(host, resolver, diagnostics, jsFilePath, targetSourceFile); - return diagnostics; - } - // @internal // targetSourceFile is when users only want one file in entire project to be emitted. This is used in compileOnSave feature export function emitFiles(resolver: EmitResolver, host: EmitHost, targetSourceFile: SourceFile): EmitResult { @@ -6297,37 +4552,11 @@ module ts { } } - function writeDeclarationFile(jsFilePath: string, sourceFile: SourceFile) { - let emitDeclarationResult = emitDeclarations(host, resolver, diagnostics, jsFilePath, sourceFile); - // 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) { - let declarationOutput = emitDeclarationResult.referencePathsOutput - + getDeclarationOutput(emitDeclarationResult.synchronousDeclarationOutput, emitDeclarationResult.moduleElementDeclarationEmitInfo); - writeFile(host, diagnostics, removeFileExtension(jsFilePath) + ".d.ts", declarationOutput, compilerOptions.emitBOM); - } - - function getDeclarationOutput(synchronousDeclarationOutput: string, moduleElementDeclarationEmitInfo: ModuleElementDeclarationEmitInfo[]) { - let appliedSyncOutputPos = 0; - let declarationOutput = ""; - // apply asynchronous additions to the synchronous output - forEach(moduleElementDeclarationEmitInfo, aliasEmitInfo => { - if (aliasEmitInfo.asynchronousOutput) { - declarationOutput += synchronousDeclarationOutput.substring(appliedSyncOutputPos, aliasEmitInfo.outputPos); - declarationOutput += getDeclarationOutput(aliasEmitInfo.asynchronousOutput, aliasEmitInfo.subModuleElementDeclarationEmitInfo); - appliedSyncOutputPos = aliasEmitInfo.outputPos; - } - }); - declarationOutput += synchronousDeclarationOutput.substring(appliedSyncOutputPos); - return declarationOutput; - } - } - function emitFile(jsFilePath: string, sourceFile?: SourceFile) { emitJavaScript(jsFilePath, sourceFile); if (compilerOptions.declaration) { - writeDeclarationFile(jsFilePath, sourceFile); + writeDeclarationFile(jsFilePath, sourceFile, host, resolver, diagnostics); } } } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index fd7e1304c85..bdd23f82746 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1364,4 +1364,317 @@ module ts { s.replace(nonAsciiCharacters, c => get16BitUnicodeEscapeSequence(c.charCodeAt(0))) : s; } + + export interface EmitTextWriter { + write(s: string): void; + writeTextOfNode(sourceFile: SourceFile, node: Node): void; + writeLine(): void; + increaseIndent(): void; + decreaseIndent(): void; + getText(): string; + rawWrite(s: string): void; + writeLiteral(s: string): void; + getTextPos(): number; + getLine(): number; + getColumn(): number; + getIndent(): number; + } + + let indentStrings: string[] = ["", " "]; + export function getIndentString(level: number) { + if (indentStrings[level] === undefined) { + indentStrings[level] = getIndentString(level - 1) + indentStrings[1]; + } + return indentStrings[level]; + } + + export function getIndentSize() { + return indentStrings[1].length; + } + + export function createTextWriter(newLine: String): EmitTextWriter { + let output = ""; + let indent = 0; + let lineStart = true; + let lineCount = 0; + let linePos = 0; + + function write(s: string) { + if (s && s.length) { + if (lineStart) { + output += getIndentString(indent); + lineStart = false; + } + output += s; + } + } + + function rawWrite(s: string) { + if (s !== undefined) { + if (lineStart) { + lineStart = false; + } + output += s; + } + } + + function writeLiteral(s: string) { + if (s && s.length) { + write(s); + let lineStartsOfS = computeLineStarts(s); + if (lineStartsOfS.length > 1) { + lineCount = lineCount + lineStartsOfS.length - 1; + linePos = output.length - s.length + lineStartsOfS[lineStartsOfS.length - 1]; + } + } + } + + function writeLine() { + if (!lineStart) { + output += newLine; + lineCount++; + linePos = output.length; + lineStart = true; + } + } + + function writeTextOfNode(sourceFile: SourceFile, node: Node) { + write(getSourceTextOfNodeFromSourceFile(sourceFile, node)); + } + + return { + write, + rawWrite, + writeTextOfNode, + writeLiteral, + writeLine, + increaseIndent: () => indent++, + decreaseIndent: () => indent--, + getIndent: () => indent, + getTextPos: () => output.length, + getLine: () => lineCount + 1, + getColumn: () => lineStart ? indent * getIndentSize() + 1 : output.length - linePos + 1, + getText: () => output, + }; + } + + export function getOwnEmitOutputFilePath(sourceFile: SourceFile, host: EmitHost, extension: string) { + let compilerOptions = host.getCompilerOptions(); + let emitOutputFilePathWithoutExtension: string; + if (compilerOptions.outDir) { + emitOutputFilePathWithoutExtension = removeFileExtension(getSourceFilePathInNewDir(sourceFile, host, compilerOptions.outDir)); + } + else { + emitOutputFilePathWithoutExtension = removeFileExtension(sourceFile.fileName); + } + + return emitOutputFilePathWithoutExtension + extension; + } + + export function getSourceFilePathInNewDir(sourceFile: SourceFile, host: EmitHost, newDirPath: string) { + let sourceFilePath = getNormalizedAbsolutePath(sourceFile.fileName, host.getCurrentDirectory()); + sourceFilePath = sourceFilePath.replace(host.getCommonSourceDirectory(), ""); + return combinePaths(newDirPath, sourceFilePath); + } + + export function writeFile(host: EmitHost, diagnostics: Diagnostic[], fileName: string, data: string, writeByteOrderMark: boolean) { + host.writeFile(fileName, data, writeByteOrderMark, hostErrorMessage => { + diagnostics.push(createCompilerDiagnostic(Diagnostics.Could_not_write_file_0_Colon_1, fileName, hostErrorMessage)); + }); + } + + export function getLineOfLocalPosition(currentSourceFile: SourceFile, pos: number) { + return getLineAndCharacterOfPosition(currentSourceFile, pos).line; + } + + export function getFirstConstructorWithBody(node: ClassDeclaration): ConstructorDeclaration { + return forEach(node.members, member => { + if (member.kind === SyntaxKind.Constructor && nodeIsPresent((member).body)) { + return member; + } + }); + } + + export function shouldEmitToOwnFile(sourceFile: SourceFile, compilerOptions: CompilerOptions): boolean { + if (!isDeclarationFile(sourceFile)) { + if ((isExternalModule(sourceFile) || !compilerOptions.out) && !fileExtensionIs(sourceFile.fileName, ".js")) { + return true; + } + return false; + } + return false; + } + + export function getAllAccessorDeclarations(declarations: NodeArray, accessor: AccessorDeclaration) { + let firstAccessor: AccessorDeclaration; + let getAccessor: AccessorDeclaration; + let setAccessor: AccessorDeclaration; + if (hasDynamicName(accessor)) { + firstAccessor = accessor; + if (accessor.kind === SyntaxKind.GetAccessor) { + getAccessor = accessor; + } + else if (accessor.kind === SyntaxKind.SetAccessor) { + setAccessor = accessor; + } + else { + Debug.fail("Accessor has wrong kind"); + } + } + else { + forEach(declarations, (member: Declaration) => { + if ((member.kind === SyntaxKind.GetAccessor || member.kind === SyntaxKind.SetAccessor) + && (member.flags & NodeFlags.Static) === (accessor.flags & NodeFlags.Static)) { + let memberName = getPropertyNameForPropertyNameNode(member.name); + let accessorName = getPropertyNameForPropertyNameNode(accessor.name); + if (memberName === accessorName) { + if (!firstAccessor) { + firstAccessor = member; + } + + if (member.kind === SyntaxKind.GetAccessor && !getAccessor) { + getAccessor = member; + } + + if (member.kind === SyntaxKind.SetAccessor && !setAccessor) { + setAccessor = member; + } + } + } + }); + } + return { + firstAccessor, + getAccessor, + setAccessor + }; + } + + export function emitNewLineBeforeLeadingComments(currentSourceFile: SourceFile, writer: EmitTextWriter, node: TextRange, leadingComments: CommentRange[]) { + // If the leading comments start on different line than the start of node, write new line + if (leadingComments && leadingComments.length && node.pos !== leadingComments[0].pos && + getLineOfLocalPosition(currentSourceFile, node.pos) !== getLineOfLocalPosition(currentSourceFile, leadingComments[0].pos)) { + writer.writeLine(); + } + } + + export function emitComments(currentSourceFile: SourceFile, writer: EmitTextWriter, comments: CommentRange[], trailingSeparator: boolean, newLine: string, + writeComment: (currentSourceFile: SourceFile, writer: EmitTextWriter, comment: CommentRange, newLine: string) => void) { + let emitLeadingSpace = !trailingSeparator; + forEach(comments, comment => { + if (emitLeadingSpace) { + writer.write(" "); + emitLeadingSpace = false; + } + writeComment(currentSourceFile, writer, comment, newLine); + if (comment.hasTrailingNewLine) { + writer.writeLine(); + } + else if (trailingSeparator) { + writer.write(" "); + } + else { + // Emit leading space to separate comment during next comment emit + emitLeadingSpace = true; + } + }); + } + + export function writeCommentRange(currentSourceFile: SourceFile, writer: EmitTextWriter, comment: CommentRange, newLine: string) { + if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk) { + let firstCommentLineAndCharacter = getLineAndCharacterOfPosition(currentSourceFile, comment.pos); + let lineCount = getLineStarts(currentSourceFile).length; + let firstCommentLineIndent: number; + for (let pos = comment.pos, currentLine = firstCommentLineAndCharacter.line; pos < comment.end; currentLine++) { + let nextLineStart = (currentLine + 1) === lineCount + ? currentSourceFile.text.length + 1 + : getStartPositionOfLine(currentLine + 1, currentSourceFile); + + if (pos !== comment.pos) { + // If we are not emitting first line, we need to write the spaces to adjust the alignment + if (firstCommentLineIndent === undefined) { + firstCommentLineIndent = calculateIndent(getStartPositionOfLine(firstCommentLineAndCharacter.line, currentSourceFile), comment.pos); + } + + // These are number of spaces writer is going to write at current indent + let currentWriterIndentSpacing = writer.getIndent() * getIndentSize(); + + // Number of spaces we want to be writing + // eg: Assume writer indent + // module m { + // /* starts at character 9 this is line 1 + // * starts at character pos 4 line --1 = 8 - 8 + 3 + // More left indented comment */ --2 = 8 - 8 + 2 + // class c { } + // } + // module m { + // /* this is line 1 -- Assume current writer indent 8 + // * line --3 = 8 - 4 + 5 + // More right indented comment */ --4 = 8 - 4 + 11 + // class c { } + // } + let spacesToEmit = currentWriterIndentSpacing - firstCommentLineIndent + calculateIndent(pos, nextLineStart); + if (spacesToEmit > 0) { + let numberOfSingleSpacesToEmit = spacesToEmit % getIndentSize(); + let indentSizeSpaceString = getIndentString((spacesToEmit - numberOfSingleSpacesToEmit) / getIndentSize()); + + // Write indent size string ( in eg 1: = "", 2: "" , 3: string with 8 spaces 4: string with 12 spaces + writer.rawWrite(indentSizeSpaceString); + + // Emit the single spaces (in eg: 1: 3 spaces, 2: 2 spaces, 3: 1 space, 4: 3 spaces) + while (numberOfSingleSpacesToEmit) { + writer.rawWrite(" "); + numberOfSingleSpacesToEmit--; + } + } + else { + // No spaces to emit write empty string + writer.rawWrite(""); + } + } + + // Write the comment line text + writeTrimmedCurrentLine(pos, nextLineStart); + + pos = nextLineStart; + } + } + else { + // Single line comment of style //.... + writer.write(currentSourceFile.text.substring(comment.pos, comment.end)); + } + + function writeTrimmedCurrentLine(pos: number, nextLineStart: number) { + let end = Math.min(comment.end, nextLineStart - 1); + let currentLineText = currentSourceFile.text.substring(pos, end).replace(/^\s+|\s+$/g, ''); + if (currentLineText) { + // trimmed forward and ending spaces text + writer.write(currentLineText); + if (end !== comment.end) { + writer.writeLine(); + } + } + else { + // Empty string - make sure we write empty line + writer.writeLiteral(newLine); + } + } + + function calculateIndent(pos: number, end: number) { + let currentLineIndent = 0; + for (; pos < end && isWhiteSpace(currentSourceFile.text.charCodeAt(pos)); pos++) { + if (currentSourceFile.text.charCodeAt(pos) === CharacterCodes.tab) { + // Tabs = TabSize = indent size and go to next tabStop + currentLineIndent += getIndentSize() - (currentLineIndent % getIndentSize()); + } + else { + // Single space + currentLineIndent++; + } + } + + return currentLineIndent; + } + } + } From 59338ed566ae75f07dfac8f1f08c4448a1416e3a Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Wed, 18 Mar 2015 17:23:40 -0700 Subject: [PATCH 156/159] Add libraryTargets to prereqs of instrumenter --- Jakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jakefile b/Jakefile index 41f417618d7..dd09085800c 100644 --- a/Jakefile +++ b/Jakefile @@ -720,7 +720,7 @@ file(loggedIOJsPath, [builtLocalDirectory, loggedIOpath], function() { var instrumenterPath = harnessDirectory + 'instrumenter.ts'; var instrumenterJsPath = builtLocalDirectory + 'instrumenter.js'; -compileFile(instrumenterJsPath, [instrumenterPath], [tscFile, instrumenterPath], [], /*useBuiltCompiler*/ true); +compileFile(instrumenterJsPath, [instrumenterPath], [tscFile, instrumenterPath].concat(libraryTargets), [], /*useBuiltCompiler*/ true); desc("Builds an instrumented tsc.js"); task('tsc-instrumented', [loggedIOJsPath, instrumenterJsPath, tscFile], function() { From 85d71b28835db3601e14ea12e1fd31738aac8de7 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 19 Mar 2015 16:55:07 -0700 Subject: [PATCH 157/159] No emit should happen if there are declaration errors and noEmitOnErrors is specified. --- src/compiler/core.ts | 6 ++++-- src/compiler/program.ts | 21 ++++++++++++++----- src/compiler/types.ts | 10 ++++----- src/services/services.ts | 1 - .../baselines/reference/APISample_compile.js | 10 ++++----- .../reference/APISample_compile.types | 10 ++++----- tests/baselines/reference/APISample_linter.js | 10 ++++----- .../reference/APISample_linter.types | 10 ++++----- .../reference/APISample_transform.js | 10 ++++----- .../reference/APISample_transform.types | 10 ++++----- .../baselines/reference/APISample_watcher.js | 10 ++++----- .../reference/APISample_watcher.types | 10 ++++----- 12 files changed, 65 insertions(+), 53 deletions(-) diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 27fc152f534..5433557bf84 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -122,8 +122,10 @@ module ts { } export function addRange(to: T[], from: T[]): void { - for (let v of from) { - to.push(v); + if (to && from) { + for (let v of from) { + to.push(v); + } } } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 875c1c43d4c..73e50ca096b 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -87,6 +87,11 @@ module ts { export function getPreEmitDiagnostics(program: Program): Diagnostic[] { let diagnostics = program.getSyntacticDiagnostics().concat(program.getGlobalDiagnostics()).concat(program.getSemanticDiagnostics()); + + if (program.getCompilerOptions().declaration) { + diagnostics.concat(program.getDeclarationDiagnostics()); + } + return sortAndDeduplicateDiagnostics(diagnostics); } @@ -178,11 +183,6 @@ module ts { return noDiagnosticsTypeChecker || (noDiagnosticsTypeChecker = createTypeChecker(program, /*produceDiagnostics:*/ false)); } - function getDeclarationDiagnostics(targetSourceFile: SourceFile): Diagnostic[] { - let resolver = getDiagnosticsProducingTypeChecker().getEmitResolver(targetSourceFile); - return ts.getDeclarationDiagnostics(getEmitHost(), resolver, targetSourceFile); - } - function emit(sourceFile?: SourceFile, writeFileCallback?: WriteFileCallback): EmitResult { // If the noEmitOnError flag is set, then check if we have any errors so far. If so, // immediately bail out. @@ -232,6 +232,10 @@ module ts { return getDiagnosticsHelper(sourceFile, getSemanticDiagnosticsForFile); } + function getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[] { + return getDiagnosticsHelper(sourceFile, getDeclarationDiagnosticsForFile); + } + function getSyntacticDiagnosticsForFile(sourceFile: SourceFile): Diagnostic[] { return sourceFile.parseDiagnostics; } @@ -247,6 +251,13 @@ module ts { return bindDiagnostics.concat(checkDiagnostics).concat(programDiagnostics); } + function getDeclarationDiagnosticsForFile(sourceFile: SourceFile): Diagnostic[] { + if (!isDeclarationFile(sourceFile)) { + let resolver = getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile); + return ts.getDeclarationDiagnostics(getEmitHost(), resolver, sourceFile); + } + } + function getGlobalDiagnostics(): Diagnostic[] { let typeChecker = getDiagnosticsProducingTypeChecker(); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 2f2d6f47f93..6d0b1309a72 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1005,14 +1005,14 @@ module ts { getSourceFiles(): SourceFile[]; /** - * 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 + * 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. * * 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 - * will be invoked when writing the javascript and declaration files. + * used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter + * will be invoked when writing the JavaScript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; diff --git a/src/services/services.ts b/src/services/services.ts index 058d4ffdd5e..5ff7c578aa0 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -4914,7 +4914,6 @@ module ts { synchronizeHostData(); let sourceFile = getValidSourceFile(fileName); - let outputFiles: OutputFile[] = []; function writeFile(fileName: string, data: string, writeByteOrderMark: boolean) { diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index e86cb092676..b8f4c7cdd13 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -801,14 +801,14 @@ declare module "typescript" { interface Program extends ScriptReferenceHost { getSourceFiles(): SourceFile[]; /** - * 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 + * 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. * * 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 - * will be invoked when writing the javascript and declaration files. + * used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter + * will be invoked when writing the JavaScript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index 9c62212cab1..e1d9aa58961 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -2440,14 +2440,14 @@ declare module "typescript" { >SourceFile : SourceFile /** - * 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 + * 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. * * 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 - * will be invoked when writing the javascript and declaration files. + * used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter + * will be invoked when writing the JavaScript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; >emit : (targetSourceFile?: SourceFile, writeFile?: WriteFileCallback) => EmitResult diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index daa6eedd29a..4e3af8d1be0 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -832,14 +832,14 @@ declare module "typescript" { interface Program extends ScriptReferenceHost { getSourceFiles(): SourceFile[]; /** - * 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 + * 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. * * 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 - * will be invoked when writing the javascript and declaration files. + * used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter + * will be invoked when writing the JavaScript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index 1250130ae5f..7cf542f0b40 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -2586,14 +2586,14 @@ declare module "typescript" { >SourceFile : SourceFile /** - * 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 + * 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. * * 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 - * will be invoked when writing the javascript and declaration files. + * used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter + * will be invoked when writing the JavaScript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; >emit : (targetSourceFile?: SourceFile, writeFile?: WriteFileCallback) => EmitResult diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index b4f0501d719..261ad5b25f6 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -833,14 +833,14 @@ declare module "typescript" { interface Program extends ScriptReferenceHost { getSourceFiles(): SourceFile[]; /** - * 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 + * 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. * * 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 - * will be invoked when writing the javascript and declaration files. + * used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter + * will be invoked when writing the JavaScript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index 4d5767785da..eb4c7ab122f 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -2536,14 +2536,14 @@ declare module "typescript" { >SourceFile : SourceFile /** - * 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 + * 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. * * 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 - * will be invoked when writing the javascript and declaration files. + * used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter + * will be invoked when writing the JavaScript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; >emit : (targetSourceFile?: SourceFile, writeFile?: WriteFileCallback) => EmitResult diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index 3e9d0bee5fc..a821bc5011d 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -870,14 +870,14 @@ declare module "typescript" { interface Program extends ScriptReferenceHost { getSourceFiles(): SourceFile[]; /** - * 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 + * 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. * * 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 - * will be invoked when writing the javascript and declaration files. + * used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter + * will be invoked when writing the JavaScript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[]; diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index 341ff13eac0..47e5a0147fd 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -2709,14 +2709,14 @@ declare module "typescript" { >SourceFile : SourceFile /** - * 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 + * 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. * * 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 - * will be invoked when writing the javascript and declaration files. + * used for writing the JavaScript and declaration files. Otherwise, the writeFile parameter + * will be invoked when writing the JavaScript and declaration files. */ emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult; >emit : (targetSourceFile?: SourceFile, writeFile?: WriteFileCallback) => EmitResult From 791a0e4e391636b427ebb4bbc31f3512950ebadd Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 19 Mar 2015 21:12:25 -0700 Subject: [PATCH 158/159] Don't actually emit declarations when we just want the diagnostics for them. --- src/compiler/program.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 73e50ca096b..a4c3a65f29c 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -254,7 +254,9 @@ module ts { function getDeclarationDiagnosticsForFile(sourceFile: SourceFile): Diagnostic[] { if (!isDeclarationFile(sourceFile)) { let resolver = getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile); - return ts.getDeclarationDiagnostics(getEmitHost(), resolver, sourceFile); + // Don't actually write any files since we're just getting diagnostics. + var writeFile: WriteFileCallback = () => { }; + return ts.getDeclarationDiagnostics(getEmitHost(writeFile), resolver, sourceFile); } } From 9ae0815e21ced877f094cf7f99021216a3d252ce Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 20 Mar 2015 16:49:21 -0700 Subject: [PATCH 159/159] Treat 0x0085 as whitespace, not as a line terminator. This matches ES5 and ES6. --- src/compiler/scanner.ts | 33 +++- .../baselines/reference/fileWithNextLine1.js | 9 ++ .../reference/fileWithNextLine1.types | 6 + .../baselines/reference/fileWithNextLine2.js | 9 ++ .../reference/fileWithNextLine2.types | 6 + .../reference/fileWithNextLine3.errors.txt | 9 ++ .../baselines/reference/fileWithNextLine3.js | 9 ++ .../reference/sourceMap-LineBreaks.js.map | 2 +- .../sourceMap-LineBreaks.sourcemap.txt | 150 +++++++++--------- .../reference/sourceMap-LineBreaks.types | 12 +- tests/cases/compiler/fileWithNextLine1.ts | 3 + tests/cases/compiler/fileWithNextLine2.ts | 3 + tests/cases/compiler/fileWithNextLine3.ts | 3 + 13 files changed, 167 insertions(+), 87 deletions(-) create mode 100644 tests/baselines/reference/fileWithNextLine1.js create mode 100644 tests/baselines/reference/fileWithNextLine1.types create mode 100644 tests/baselines/reference/fileWithNextLine2.js create mode 100644 tests/baselines/reference/fileWithNextLine2.types create mode 100644 tests/baselines/reference/fileWithNextLine3.errors.txt create mode 100644 tests/baselines/reference/fileWithNextLine3.js create mode 100644 tests/cases/compiler/fileWithNextLine1.ts create mode 100644 tests/cases/compiler/fileWithNextLine2.ts create mode 100644 tests/cases/compiler/fileWithNextLine3.ts diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index 130fcc07a22..9e5e65db935 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -318,13 +318,38 @@ module ts { let hasOwnProperty = Object.prototype.hasOwnProperty; export function isWhiteSpace(ch: number): boolean { - return ch === CharacterCodes.space || ch === CharacterCodes.tab || ch === CharacterCodes.verticalTab || ch === CharacterCodes.formFeed || - ch === CharacterCodes.nonBreakingSpace || ch === CharacterCodes.ogham || ch >= CharacterCodes.enQuad && ch <= CharacterCodes.zeroWidthSpace || - ch === CharacterCodes.narrowNoBreakSpace || ch === CharacterCodes.mathematicalSpace || ch === CharacterCodes.ideographicSpace || ch === CharacterCodes.byteOrderMark; + // Note: nextLine is in the Zs space, and should be considered to be a whitespace. + // It is explicitly not a line-break as it isn't in the exact set specified by EcmaScript. + return ch === CharacterCodes.space || + ch === CharacterCodes.tab || + ch === CharacterCodes.verticalTab || + ch === CharacterCodes.formFeed || + ch === CharacterCodes.nonBreakingSpace || + ch === CharacterCodes.nextLine || + ch === CharacterCodes.ogham || + ch >= CharacterCodes.enQuad && ch <= CharacterCodes.zeroWidthSpace || + ch === CharacterCodes.narrowNoBreakSpace || + ch === CharacterCodes.mathematicalSpace || + ch === CharacterCodes.ideographicSpace || + ch === CharacterCodes.byteOrderMark; } export function isLineBreak(ch: number): boolean { - return ch === CharacterCodes.lineFeed || ch === CharacterCodes.carriageReturn || ch === CharacterCodes.lineSeparator || ch === CharacterCodes.paragraphSeparator || ch === CharacterCodes.nextLine; + // ES5 7.3: + // The ECMAScript line terminator characters are listed in Table 3. + // Table 3 — Line Terminator Characters + // Code Unit Value Name Formal Name + // \u000A Line Feed + // \u000D Carriage Return + // \u2028 Line separator + // \u2029 Paragraph separator + // Only the characters in Table 3 are treated as line terminators. Other new line or line + // breaking characters are treated as white space but not as line terminators. + + return ch === CharacterCodes.lineFeed || + ch === CharacterCodes.carriageReturn || + ch === CharacterCodes.lineSeparator || + ch === CharacterCodes.paragraphSeparator; } function isDigit(ch: number): boolean { diff --git a/tests/baselines/reference/fileWithNextLine1.js b/tests/baselines/reference/fileWithNextLine1.js new file mode 100644 index 00000000000..a89c5b3e207 --- /dev/null +++ b/tests/baselines/reference/fileWithNextLine1.js @@ -0,0 +1,9 @@ +//// [fileWithNextLine1.ts] +// Note: there is a nextline (0x85) in the string +// 0. It should be counted as a space and should not cause an error. +var v = 'Â…'; + +//// [fileWithNextLine1.js] +// Note: there is a nextline (0x85) in the string +// 0. It should be counted as a space and should not cause an error. +var v = 'Â…'; diff --git a/tests/baselines/reference/fileWithNextLine1.types b/tests/baselines/reference/fileWithNextLine1.types new file mode 100644 index 00000000000..721b3d6fb10 --- /dev/null +++ b/tests/baselines/reference/fileWithNextLine1.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/fileWithNextLine1.ts === +// Note: there is a nextline (0x85) in the string +// 0. It should be counted as a space and should not cause an error. +var v = 'Â…'; +>v : string + diff --git a/tests/baselines/reference/fileWithNextLine2.js b/tests/baselines/reference/fileWithNextLine2.js new file mode 100644 index 00000000000..439b9bd42f9 --- /dev/null +++ b/tests/baselines/reference/fileWithNextLine2.js @@ -0,0 +1,9 @@ +//// [fileWithNextLine2.ts] +// Note: there is a nextline (0x85) char between the = and the 0. +// it should be treated like a space +var v =Â…0; + +//// [fileWithNextLine2.js] +// Note: there is a nextline (0x85) char between the = and the 0. +// it should be treated like a space +var v = 0; diff --git a/tests/baselines/reference/fileWithNextLine2.types b/tests/baselines/reference/fileWithNextLine2.types new file mode 100644 index 00000000000..8a6de1a4b2f --- /dev/null +++ b/tests/baselines/reference/fileWithNextLine2.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/fileWithNextLine2.ts === +// Note: there is a nextline (0x85) char between the = and the 0. +// it should be treated like a space +var v =Â…0; +>v : number + diff --git a/tests/baselines/reference/fileWithNextLine3.errors.txt b/tests/baselines/reference/fileWithNextLine3.errors.txt new file mode 100644 index 00000000000..647ec722549 --- /dev/null +++ b/tests/baselines/reference/fileWithNextLine3.errors.txt @@ -0,0 +1,9 @@ +tests/cases/compiler/fileWithNextLine3.ts(3,1): error TS1108: A 'return' statement can only be used within a function body. + + +==== tests/cases/compiler/fileWithNextLine3.ts (1 errors) ==== + // Note: there is a nextline (0x85) between the return and the + // 0. It should be counted as a space and should not trigger ASI + returnÂ…0; + ~~~~~~ +!!! error TS1108: A 'return' statement can only be used within a function body. \ No newline at end of file diff --git a/tests/baselines/reference/fileWithNextLine3.js b/tests/baselines/reference/fileWithNextLine3.js new file mode 100644 index 00000000000..c1d4204bcae --- /dev/null +++ b/tests/baselines/reference/fileWithNextLine3.js @@ -0,0 +1,9 @@ +//// [fileWithNextLine3.ts] +// Note: there is a nextline (0x85) between the return and the +// 0. It should be counted as a space and should not trigger ASI +returnÂ…0; + +//// [fileWithNextLine3.js] +// Note: there is a nextline (0x85) between the return and the +// 0. It should be counted as a space and should not trigger ASI +return 0; diff --git a/tests/baselines/reference/sourceMap-LineBreaks.js.map b/tests/baselines/reference/sourceMap-LineBreaks.js.map index 59f3381d355..7726aa00eaf 100644 --- a/tests/baselines/reference/sourceMap-LineBreaks.js.map +++ b/tests/baselines/reference/sourceMap-LineBreaks.js.map @@ -1,2 +1,2 @@ //// [sourceMap-LineBreaks.js.map] -{"version":3,"file":"sourceMap-LineBreaks.js","sourceRoot":"","sources":["sourceMap-LineBreaks.ts"],"names":[],"mappings":"AAAA,IAAI,qBAAqB,GAAG,EAAE,CAAC;AAC/B,IAAI,0BAA0B,GAAG,EAAE,CAAC;AACpC,IAAI,gBAAgB,GAAG,CAAC,CAAC;AACzB,IAAI,gBAAgB,GAAG,CAAC,CAAC;AACzB,IAAI,8BAA8B,GAAG,CAAC,CAAC;AACvC,IAAI,sBAAsB,GAAG,CAAC,CAAC;AAC/B,IAAI,8BAA8B,GAAG,CAAC,CAAC;AAEvC,IAAI,sCAAsC,GAAG,CAAC,CAAC;AAE/C,IAAI,yBAAyB,GAAG;OACzB,CAAC;AACR,IAAI,uCAAuC,GAAG;OACvC,CAAC;AACR,IAAI,+BAA+B,GAAG;OAC/B,CAAC;AAER,IAAI,8BAA8B,GAAG;OAC9B,CAAC;AACR,IAAI,mCAAmC,GAAG;OACnC,CAAC;AACR,IAAI,yBAAyB,GAAG;OACzB,CAAC"} \ No newline at end of file +{"version":3,"file":"sourceMap-LineBreaks.js","sourceRoot":"","sources":["sourceMap-LineBreaks.ts"],"names":[],"mappings":"AAAA,IAAI,qBAAqB,GAAG,EAAE,CAAC;AAC/B,IAAI,0BAA0B,GAAG,EAAE,CAAC;AACpC,IAAI,gBAAgB,GAAG,CAAC,CAAC;AAAC,IAAI,gBAAgB,GAAG,CAAC,CAAC;AACnD,IAAI,8BAA8B,GAAG,CAAC,CAAC;AACvC,IAAI,sBAAsB,GAAG,CAAC,CAAC;AAC/B,IAAI,8BAA8B,GAAG,CAAC,CAAC;AAEvC,IAAI,sCAAsC,GAAG,CAAC,CAAC;AAE/C,IAAI,yBAAyB,GAAG;OACzB,CAAC;AACR,IAAI,uCAAuC,GAAG;OACvC,CAAC;AACR,IAAI,+BAA+B,GAAG;OAC/B,CAAC;AAER,IAAI,8BAA8B,GAAG;OAC9B,CAAC;AACR,IAAI,mCAAmC,GAAG;OACnC,CAAC;AACR,IAAI,yBAAyB,GAAG,gBAAgB,CAAC"} \ No newline at end of file diff --git a/tests/baselines/reference/sourceMap-LineBreaks.sourcemap.txt b/tests/baselines/reference/sourceMap-LineBreaks.sourcemap.txt index 5cda2ad1f82..413853250b6 100644 --- a/tests/baselines/reference/sourceMap-LineBreaks.sourcemap.txt +++ b/tests/baselines/reference/sourceMap-LineBreaks.sourcemap.txt @@ -78,18 +78,18 @@ sourceFile:sourceMap-LineBreaks.ts 5 > ^ 6 > ^ 7 > ^^^^^^^^^^^^^^^-> -1->Â… > +1->Â… 2 >var 3 > endsWithLineFeed 4 > = 5 > 1 6 > ; -1->Emitted(4, 1) Source(4, 1) + SourceIndex(0) -2 >Emitted(4, 5) Source(4, 5) + SourceIndex(0) -3 >Emitted(4, 21) Source(4, 21) + SourceIndex(0) -4 >Emitted(4, 24) Source(4, 24) + SourceIndex(0) -5 >Emitted(4, 25) Source(4, 25) + SourceIndex(0) -6 >Emitted(4, 26) Source(4, 26) + SourceIndex(0) +1->Emitted(4, 1) Source(3, 27) + SourceIndex(0) +2 >Emitted(4, 5) Source(3, 31) + SourceIndex(0) +3 >Emitted(4, 21) Source(3, 47) + SourceIndex(0) +4 >Emitted(4, 24) Source(3, 50) + SourceIndex(0) +5 >Emitted(4, 25) Source(3, 51) + SourceIndex(0) +6 >Emitted(4, 26) Source(3, 52) + SourceIndex(0) --- >>>var endsWithCarriageReturnLineFeed = 1; 1-> @@ -105,12 +105,12 @@ sourceFile:sourceMap-LineBreaks.ts 4 > = 5 > 1 6 > ; -1->Emitted(5, 1) Source(5, 1) + SourceIndex(0) -2 >Emitted(5, 5) Source(5, 5) + SourceIndex(0) -3 >Emitted(5, 35) Source(5, 35) + SourceIndex(0) -4 >Emitted(5, 38) Source(5, 38) + SourceIndex(0) -5 >Emitted(5, 39) Source(5, 39) + SourceIndex(0) -6 >Emitted(5, 40) Source(5, 40) + SourceIndex(0) +1->Emitted(5, 1) Source(4, 1) + SourceIndex(0) +2 >Emitted(5, 5) Source(4, 5) + SourceIndex(0) +3 >Emitted(5, 35) Source(4, 35) + SourceIndex(0) +4 >Emitted(5, 38) Source(4, 38) + SourceIndex(0) +5 >Emitted(5, 39) Source(4, 39) + SourceIndex(0) +6 >Emitted(5, 40) Source(4, 40) + SourceIndex(0) --- >>>var endsWithCarriageReturn = 1; 1 > @@ -127,12 +127,12 @@ sourceFile:sourceMap-LineBreaks.ts 4 > = 5 > 1 6 > ; -1 >Emitted(6, 1) Source(6, 1) + SourceIndex(0) -2 >Emitted(6, 5) Source(6, 5) + SourceIndex(0) -3 >Emitted(6, 27) Source(6, 27) + SourceIndex(0) -4 >Emitted(6, 30) Source(6, 30) + SourceIndex(0) -5 >Emitted(6, 31) Source(6, 31) + SourceIndex(0) -6 >Emitted(6, 32) Source(6, 32) + SourceIndex(0) +1 >Emitted(6, 1) Source(5, 1) + SourceIndex(0) +2 >Emitted(6, 5) Source(5, 5) + SourceIndex(0) +3 >Emitted(6, 27) Source(5, 27) + SourceIndex(0) +4 >Emitted(6, 30) Source(5, 30) + SourceIndex(0) +5 >Emitted(6, 31) Source(5, 31) + SourceIndex(0) +6 >Emitted(6, 32) Source(5, 32) + SourceIndex(0) --- >>>var endsWithLineFeedCarriageReturn = 1; 1-> @@ -148,12 +148,12 @@ sourceFile:sourceMap-LineBreaks.ts 4 > = 5 > 1 6 > ; -1->Emitted(7, 1) Source(7, 1) + SourceIndex(0) -2 >Emitted(7, 5) Source(7, 5) + SourceIndex(0) -3 >Emitted(7, 35) Source(7, 35) + SourceIndex(0) -4 >Emitted(7, 38) Source(7, 38) + SourceIndex(0) -5 >Emitted(7, 39) Source(7, 39) + SourceIndex(0) -6 >Emitted(7, 40) Source(7, 40) + SourceIndex(0) +1->Emitted(7, 1) Source(6, 1) + SourceIndex(0) +2 >Emitted(7, 5) Source(6, 5) + SourceIndex(0) +3 >Emitted(7, 35) Source(6, 35) + SourceIndex(0) +4 >Emitted(7, 38) Source(6, 38) + SourceIndex(0) +5 >Emitted(7, 39) Source(6, 39) + SourceIndex(0) +6 >Emitted(7, 40) Source(6, 40) + SourceIndex(0) --- >>>var endsWithLineFeedCarriageReturnLineFeed = 1; 1-> @@ -169,12 +169,12 @@ sourceFile:sourceMap-LineBreaks.ts 4 > = 5 > 1 6 > ; -1->Emitted(8, 1) Source(9, 1) + SourceIndex(0) -2 >Emitted(8, 5) Source(9, 5) + SourceIndex(0) -3 >Emitted(8, 43) Source(9, 43) + SourceIndex(0) -4 >Emitted(8, 46) Source(9, 46) + SourceIndex(0) -5 >Emitted(8, 47) Source(9, 47) + SourceIndex(0) -6 >Emitted(8, 48) Source(9, 48) + SourceIndex(0) +1->Emitted(8, 1) Source(8, 1) + SourceIndex(0) +2 >Emitted(8, 5) Source(8, 5) + SourceIndex(0) +3 >Emitted(8, 43) Source(8, 43) + SourceIndex(0) +4 >Emitted(8, 46) Source(8, 46) + SourceIndex(0) +5 >Emitted(8, 47) Source(8, 47) + SourceIndex(0) +6 >Emitted(8, 48) Source(8, 48) + SourceIndex(0) --- >>>var stringLiteralWithLineFeed = "line 1\ 1 > @@ -187,10 +187,10 @@ sourceFile:sourceMap-LineBreaks.ts 2 >var 3 > stringLiteralWithLineFeed 4 > = -1 >Emitted(9, 1) Source(11, 1) + SourceIndex(0) -2 >Emitted(9, 5) Source(11, 5) + SourceIndex(0) -3 >Emitted(9, 30) Source(11, 30) + SourceIndex(0) -4 >Emitted(9, 33) Source(11, 33) + SourceIndex(0) +1 >Emitted(9, 1) Source(10, 1) + SourceIndex(0) +2 >Emitted(9, 5) Source(10, 5) + SourceIndex(0) +3 >Emitted(9, 30) Source(10, 30) + SourceIndex(0) +4 >Emitted(9, 33) Source(10, 33) + SourceIndex(0) --- >>>line 2"; 1 >^^^^^^^ @@ -199,8 +199,8 @@ sourceFile:sourceMap-LineBreaks.ts 1 >"line 1\ >line 2" 2 > ; -1 >Emitted(10, 8) Source(12, 8) + SourceIndex(0) -2 >Emitted(10, 9) Source(12, 9) + SourceIndex(0) +1 >Emitted(10, 8) Source(11, 8) + SourceIndex(0) +2 >Emitted(10, 9) Source(11, 9) + SourceIndex(0) --- >>>var stringLiteralWithCarriageReturnLineFeed = "line 1\ 1-> @@ -212,10 +212,10 @@ sourceFile:sourceMap-LineBreaks.ts 2 >var 3 > stringLiteralWithCarriageReturnLineFeed 4 > = -1->Emitted(11, 1) Source(13, 1) + SourceIndex(0) -2 >Emitted(11, 5) Source(13, 5) + SourceIndex(0) -3 >Emitted(11, 44) Source(13, 44) + SourceIndex(0) -4 >Emitted(11, 47) Source(13, 47) + SourceIndex(0) +1->Emitted(11, 1) Source(12, 1) + SourceIndex(0) +2 >Emitted(11, 5) Source(12, 5) + SourceIndex(0) +3 >Emitted(11, 44) Source(12, 44) + SourceIndex(0) +4 >Emitted(11, 47) Source(12, 47) + SourceIndex(0) --- >>>line 2"; 1 >^^^^^^^ @@ -224,8 +224,8 @@ sourceFile:sourceMap-LineBreaks.ts 1 >"line 1\ >line 2" 2 > ; -1 >Emitted(12, 8) Source(14, 8) + SourceIndex(0) -2 >Emitted(12, 9) Source(14, 9) + SourceIndex(0) +1 >Emitted(12, 8) Source(13, 8) + SourceIndex(0) +2 >Emitted(12, 9) Source(13, 9) + SourceIndex(0) --- >>>var stringLiteralWithCarriageReturn = "line 1\ 1-> 2 >^^^^ @@ -236,10 +236,10 @@ sourceFile:sourceMap-LineBreaks.ts 2 >var 3 > stringLiteralWithCarriageReturn 4 > = -1->Emitted(13, 1) Source(15, 1) + SourceIndex(0) -2 >Emitted(13, 5) Source(15, 5) + SourceIndex(0) -3 >Emitted(13, 36) Source(15, 36) + SourceIndex(0) -4 >Emitted(13, 39) Source(15, 39) + SourceIndex(0) +1->Emitted(13, 1) Source(14, 1) + SourceIndex(0) +2 >Emitted(13, 5) Source(14, 5) + SourceIndex(0) +3 >Emitted(13, 36) Source(14, 36) + SourceIndex(0) +4 >Emitted(13, 39) Source(14, 39) + SourceIndex(0) --- >>>line 2"; 1 >^^^^^^^ @@ -247,8 +247,8 @@ sourceFile:sourceMap-LineBreaks.ts 3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 >"line 1\ >line 2" 2 > ; -1 >Emitted(14, 8) Source(16, 8) + SourceIndex(0) -2 >Emitted(14, 9) Source(16, 9) + SourceIndex(0) +1 >Emitted(14, 8) Source(15, 8) + SourceIndex(0) +2 >Emitted(14, 9) Source(15, 9) + SourceIndex(0) --- >>>var stringLiteralWithLineSeparator = "line 1\
1-> 2 >^^^^ @@ -260,10 +260,10 @@ sourceFile:sourceMap-LineBreaks.ts 2 >var 3 > stringLiteralWithLineSeparator 4 > = -1->Emitted(15, 1) Source(18, 1) + SourceIndex(0) -2 >Emitted(15, 5) Source(18, 5) + SourceIndex(0) -3 >Emitted(15, 35) Source(18, 35) + SourceIndex(0) -4 >Emitted(15, 38) Source(18, 38) + SourceIndex(0) +1->Emitted(15, 1) Source(17, 1) + SourceIndex(0) +2 >Emitted(15, 5) Source(17, 5) + SourceIndex(0) +3 >Emitted(15, 35) Source(17, 35) + SourceIndex(0) +4 >Emitted(15, 38) Source(17, 38) + SourceIndex(0) --- >>>line 2"; 1 >^^^^^^^ @@ -271,8 +271,8 @@ sourceFile:sourceMap-LineBreaks.ts 3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 >"line 1\
 >line 2" 2 > ; -1 >Emitted(16, 8) Source(19, 8) + SourceIndex(0) -2 >Emitted(16, 9) Source(19, 9) + SourceIndex(0) +1 >Emitted(16, 8) Source(18, 8) + SourceIndex(0) +2 >Emitted(16, 9) Source(18, 9) + SourceIndex(0) --- >>>var stringLiteralWithParagraphSeparator = "line 1\
1-> 2 >^^^^ @@ -282,40 +282,38 @@ sourceFile:sourceMap-LineBreaks.ts 2 >var 3 > stringLiteralWithParagraphSeparator 4 > = -1->Emitted(17, 1) Source(20, 1) + SourceIndex(0) -2 >Emitted(17, 5) Source(20, 5) + SourceIndex(0) -3 >Emitted(17, 40) Source(20, 40) + SourceIndex(0) -4 >Emitted(17, 43) Source(20, 43) + SourceIndex(0) +1->Emitted(17, 1) Source(19, 1) + SourceIndex(0) +2 >Emitted(17, 5) Source(19, 5) + SourceIndex(0) +3 >Emitted(17, 40) Source(19, 40) + SourceIndex(0) +4 >Emitted(17, 43) Source(19, 43) + SourceIndex(0) --- >>>line 2"; 1 >^^^^^^^ 2 > ^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 >"line 1\
 >line 2" 2 > ; -1 >Emitted(18, 8) Source(21, 8) + SourceIndex(0) -2 >Emitted(18, 9) Source(21, 9) + SourceIndex(0) +1 >Emitted(18, 8) Source(20, 8) + SourceIndex(0) +2 >Emitted(18, 9) Source(20, 9) + SourceIndex(0) --- ->>>var stringLiteralWithNextLine = "line 1\Â…1-> +>>>var stringLiteralWithNextLine = "line 1\Â…line 2"; +1-> 2 >^^^^ 3 > ^^^^^^^^^^^^^^^^^^^^^^^^^ 4 > ^^^ +5 > ^^^^^^^^^^^^^^^^ +6 > ^ 1->
 > 2 >var 3 > stringLiteralWithNextLine 4 > = -1->Emitted(19, 1) Source(22, 1) + SourceIndex(0) -2 >Emitted(19, 5) Source(22, 5) + SourceIndex(0) -3 >Emitted(19, 30) Source(22, 30) + SourceIndex(0) -4 >Emitted(19, 33) Source(22, 33) + SourceIndex(0) ---- ->>>line 2"; -1 >^^^^^^^ -2 > ^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 >"line 1\Â… >line 2" -2 > ; -1 >Emitted(20, 8) Source(23, 8) + SourceIndex(0) -2 >Emitted(20, 9) Source(23, 9) + SourceIndex(0) +5 > "line 1\Â…line 2" +6 > ; +1->Emitted(19, 1) Source(21, 1) + SourceIndex(0) +2 >Emitted(19, 5) Source(21, 5) + SourceIndex(0) +3 >Emitted(19, 30) Source(21, 30) + SourceIndex(0) +4 >Emitted(19, 33) Source(21, 33) + SourceIndex(0) +5 >Emitted(19, 49) Source(21, 49) + SourceIndex(0) +6 >Emitted(19, 50) Source(21, 50) + SourceIndex(0) --- >>>//# sourceMappingURL=sourceMap-LineBreaks.js.map \ No newline at end of file diff --git a/tests/baselines/reference/sourceMap-LineBreaks.types b/tests/baselines/reference/sourceMap-LineBreaks.types index 6e5456e8f9f..cc2eebc973d 100644 --- a/tests/baselines/reference/sourceMap-LineBreaks.types +++ b/tests/baselines/reference/sourceMap-LineBreaks.types @@ -7,24 +7,24 @@ var endsWithCarriageReturnLineFeed = 1; var endsWithCarriageReturn = 1; var endsWithLineFeedCarriageReturn = 1; >endsWithNextLine : number - - var endsWithLineFeedCarriageReturnLineFeed = 1; >endsWithLineFeed : number + var endsWithLineFeedCarriageReturnLineFeed = 1; >endsWithCarriageReturnLineFeed : number -var stringLiteralWithLineFeed = "line 1\ >endsWithCarriageReturn : number -line 2"; +var stringLiteralWithLineFeed = "line 1\ >endsWithLineFeedCarriageReturn : number -var stringLiteralWithCarriageReturnLineFeed = "line 1\ line 2"; +var stringLiteralWithCarriageReturnLineFeed = "line 1\ >endsWithLineFeedCarriageReturnLineFeed : number +line 2"; var stringLiteralWithCarriageReturn = "line 1\ line 2"; - >stringLiteralWithLineFeed : string var stringLiteralWithLineSeparator = "line 1\
line 2";
var stringLiteralWithParagraphSeparator = "line 1\
line 2";
var stringLiteralWithNextLine = "line 1\Â…line 2"; +>stringLiteralWithCarriageReturnLineFeed : string + diff --git a/tests/cases/compiler/fileWithNextLine1.ts b/tests/cases/compiler/fileWithNextLine1.ts new file mode 100644 index 00000000000..4126c2c868b --- /dev/null +++ b/tests/cases/compiler/fileWithNextLine1.ts @@ -0,0 +1,3 @@ +// Note: there is a nextline (0x85) in the string +// 0. It should be counted as a space and should not cause an error. +var v = 'Â…'; \ No newline at end of file diff --git a/tests/cases/compiler/fileWithNextLine2.ts b/tests/cases/compiler/fileWithNextLine2.ts new file mode 100644 index 00000000000..cc5a3863b78 --- /dev/null +++ b/tests/cases/compiler/fileWithNextLine2.ts @@ -0,0 +1,3 @@ +// Note: there is a nextline (0x85) char between the = and the 0. +// it should be treated like a space +var v =Â…0; \ No newline at end of file diff --git a/tests/cases/compiler/fileWithNextLine3.ts b/tests/cases/compiler/fileWithNextLine3.ts new file mode 100644 index 00000000000..5177230848e --- /dev/null +++ b/tests/cases/compiler/fileWithNextLine3.ts @@ -0,0 +1,3 @@ +// Note: there is a nextline (0x85) between the return and the +// 0. It should be counted as a space and should not trigger ASI +returnÂ…0; \ No newline at end of file