From 73e22ed9c2e8776eb3bebb0f3a6990d3bbad129a Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 7 Apr 2015 22:54:06 -0700 Subject: [PATCH 001/194] Add convertToBase64 method --- Jakefile | 3 +- src/compiler/utilities.ts | 77 ++++++++++++++++++++++++ tests/cases/unittests/convertToBase64.ts | 33 ++++++++++ 3 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 tests/cases/unittests/convertToBase64.ts diff --git a/Jakefile b/Jakefile index 2efd973a021..0712b8414ba 100644 --- a/Jakefile +++ b/Jakefile @@ -145,7 +145,8 @@ var harnessSources = [ "services/documentRegistry.ts", "services/preProcessFile.ts", "services/patternMatcher.ts", - "versionCache.ts" + "versionCache.ts", + "convertToBase64.ts" ].map(function (f) { return path.join(unittestsDirectory, f); })).concat([ diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index e3efd12de0a..f475ea75053 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1815,4 +1815,81 @@ module ts { export function getLocalSymbolForExportDefault(symbol: Symbol) { return symbol && symbol.valueDeclaration && (symbol.valueDeclaration.flags & NodeFlags.Default) ? symbol.valueDeclaration.localSymbol : undefined; } + + /** + * Replace each instance of non-ascii characters by one, two, three, or four escape sequences + * representing the UTF-8 encoding of the character, and return the expanded char code list. + */ + function getExpandedCharCodes(input: string): number[] { + let output: number[] = []; + let length = input.length; + let leadSurrogate: number = undefined; + + for (let i = 0; i < length; i++) { + let charCode = input.charCodeAt(i); + + // handel utf8 + if (charCode < 0x80) { + output.push(charCode); + } + else if (charCode < 0x800) { + output.push((charCode >> 6) | 0B11000000); + output.push((charCode & 0B00111111) | 0B10000000); + } + else if (charCode < 0x10000) { + output.push((charCode >> 12) | 0B11100000); + output.push(((charCode >> 6) & 0B00111111) | 0B10000000); + output.push((charCode & 0B00111111) | 0B10000000); + } + else if (charCode < 0x20000) { + output.push((charCode >> 18) | 0B11110000); + output.push(((charCode >> 12) & 0B00111111) | 0B10000000); + output.push(((charCode >> 6) & 0B00111111) | 0B10000000); + output.push((charCode & 0B00111111) | 0B10000000); + } + else { + Debug.assert(false, "Unexpected code point"); + } + } + + return output; + } + + const base64Digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; + + /** + * Converts a string to a base-64 encoded ASCII string. + */ + export function convertToBase64(input: string): string { + var result = ""; + let charCodes = getExpandedCharCodes(input); + let i = 0; + let length = charCodes.length; + let byte1: number, byte2: number, byte3: number, byte4: number; + + while (i < length) { + // Convert every 6-bits in the input 3 character points + // into a base64 digit + byte1 = charCodes[i] >> 2; + byte2 = (charCodes[i] & 0B00000011) << 4 | charCodes[i + 1] >> 4; + byte3 = (charCodes[i + 1] & 0B00001111) << 2 | charCodes[i + 2] >> 6; + byte4 = charCodes[i + 2] & 0B00111111; + + // We are out of characters in the input, set the extra + // digits to 64 (padding character). + if (i + 1 >= length) { + byte3 = byte4 = 64; + } + else if (i + 2 >= length) { + byte4 = 64; + } + + // Write to the ouput + result += base64Digits.charAt(byte1) + base64Digits.charAt(byte2) + base64Digits.charAt(byte3) + base64Digits.charAt(byte4); + + i += 3; + } + + return result; + } } diff --git a/tests/cases/unittests/convertToBase64.ts b/tests/cases/unittests/convertToBase64.ts new file mode 100644 index 00000000000..96c082ae789 --- /dev/null +++ b/tests/cases/unittests/convertToBase64.ts @@ -0,0 +1,33 @@ +/// + +module ts { + describe('convertToBase64', () => { + function runTest(input: string): void { + var actual = ts.convertToBase64(input); + var expected = new Buffer(input).toString("base64"); + assert.equal(actual, expected, "Encoded string using convertToBase64 does not match buffer.toString('base64')"); + } + + it("Converts ASCII charaters correctelly", () => { + runTest(" !\"#$ %&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"); + }); + + it("Converts escape sequences correctelly", () => { + runTest("\t\n\r\\\"\'\u0062"); + }); + + it("Converts simple unicode characters correctelly", () => { + runTest("ΠΣ ٵپ औठ ⺐⺠"); + }); + + it("Converts simple code snippit correctelly", () => { + runTest(`/// +var x: string = "string"; +console.log(x);`); + }); + + it("Converts simple code snippit with unicode characters correctelly", () => { + runTest(`var Π = 3.1415; console.log(Π);`); + }); + }); +} From a998abb153be952397a80fd96c1a2018acc388c2 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 8 Apr 2015 00:14:23 -0700 Subject: [PATCH 002/194] Add inlineSourceMap option --- src/compiler/commandLineParser.ts | 4 ++ .../diagnosticInformationMap.generated.ts | 4 ++ src/compiler/diagnosticMessages.json | 19 ++++- src/compiler/emitter.ts | 55 +++++++++----- src/compiler/program.ts | 15 ++++ src/compiler/types.ts | 1 + src/harness/compilerRunner.ts | 13 ++-- src/harness/harness.ts | 10 ++- .../reference/inlineSourceMap.errors.txt | 9 +++ tests/baselines/reference/inlineSourceMap.js | 9 +++ .../reference/inlineSourceMap.sourcemap.txt | 61 ++++++++++++++++ .../reference/inlineSourceMap2.errors.txt | 19 +++++ tests/baselines/reference/inlineSourceMap2.js | 12 ++++ .../reference/inlineSourceMap2.sourcemap.txt | 71 +++++++++++++++++++ tests/cases/compiler/inlineSourceMap.ts | 5 ++ tests/cases/compiler/inlineSourceMap2.ts | 11 +++ 16 files changed, 294 insertions(+), 24 deletions(-) create mode 100644 tests/baselines/reference/inlineSourceMap.errors.txt create mode 100644 tests/baselines/reference/inlineSourceMap.js create mode 100644 tests/baselines/reference/inlineSourceMap.sourcemap.txt create mode 100644 tests/baselines/reference/inlineSourceMap2.errors.txt create mode 100644 tests/baselines/reference/inlineSourceMap2.js create mode 100644 tests/baselines/reference/inlineSourceMap2.sourcemap.txt create mode 100644 tests/cases/compiler/inlineSourceMap.ts create mode 100644 tests/cases/compiler/inlineSourceMap2.ts diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 48817798d81..af4a44204e3 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -30,6 +30,10 @@ module ts { type: "boolean", description: Diagnostics.Print_this_message, }, + { + name: "inlineSourceMap", + type: "boolean", + }, { name: "listFiles", type: "boolean", diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index b4380f4d2de..380cd7378f8 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -445,6 +445,10 @@ module ts { Option_noEmitOnError_cannot_be_specified_with_option_separateCompilation: { code: 5045, category: DiagnosticCategory.Error, key: "Option 'noEmitOnError' cannot be specified with option 'separateCompilation'." }, Option_out_cannot_be_specified_with_option_separateCompilation: { code: 5046, category: DiagnosticCategory.Error, key: "Option 'out' cannot be specified with option 'separateCompilation'." }, Option_separateCompilation_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher: { code: 5047, category: DiagnosticCategory.Error, key: "Option 'separateCompilation' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher." }, + Option_sourceMap_cannot_be_specified_with_option_inlineSourceMap: { code: 5048, category: DiagnosticCategory.Error, key: "Option 'sourceMap' cannot be specified with option 'inlineSourceMap'." }, + Option_sourceRoot_cannot_be_specified_with_option_inlineSourceMap: { code: 5049, category: DiagnosticCategory.Error, key: "Option 'sourceRoot' cannot be specified with option 'inlineSourceMap'." }, + Option_mapRoot_cannot_be_specified_with_option_inlineSourceMap: { code: 5050, category: DiagnosticCategory.Error, key: "Option 'mapRoot' cannot be specified with option 'inlineSourceMap'." }, + Option_out_cannot_be_specified_with_option_inlineSourceMap: { code: 5051, category: DiagnosticCategory.Error, key: "Option 'out' cannot be specified with option 'inlineSourceMap'." }, Concatenate_and_emit_output_to_single_file: { code: 6001, category: DiagnosticCategory.Message, key: "Concatenate and emit output to single file." }, Generates_corresponding_d_ts_file: { code: 6002, category: DiagnosticCategory.Message, key: "Generates corresponding '.d.ts' file." }, Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations: { code: 6003, category: DiagnosticCategory.Message, key: "Specifies the location where debugger should locate map files instead of generated locations." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index fe349b78343..65382ab7f04 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -661,7 +661,7 @@ }, "Invalid use of '{0}'. Class definitions are automatically in strict mode.": { "category": "Error", - "code": 1210 + "code": 1210 }, "A class declaration without the 'default' modifier must have a name": { "category": "Error", @@ -1772,6 +1772,23 @@ "category": "Error", "code": 5047 }, + "Option 'sourceMap' cannot be specified with option 'inlineSourceMap'.": { + "category": "Error", + "code": 5048 + }, + "Option 'sourceRoot' cannot be specified with option 'inlineSourceMap'.": { + "category": "Error", + "code": 5049 + }, + "Option 'mapRoot' cannot be specified with option 'inlineSourceMap'.": { + "category": "Error", + "code": 5050 + }, + "Option 'out' cannot be specified with option 'inlineSourceMap'.": { + "category": "Error", + "code": 5051 + }, + "Concatenate and emit output to single file.": { "category": "Message", "code": 6001 diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 43db3e69cd7..28848a1af78 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -52,7 +52,7 @@ var __param = this.__param || function(index, decorator) { return function (targ let compilerOptions = host.getCompilerOptions(); let languageVersion = compilerOptions.target || ScriptTarget.ES3; - let sourceMapDataList: SourceMapData[] = compilerOptions.sourceMap ? [] : undefined; + let sourceMapDataList: SourceMapData[] = compilerOptions.sourceMap || compilerOptions.inlineSourceMap ? [] : undefined; let diagnostics: Diagnostic[] = []; let newLine = host.getNewLine(); @@ -169,7 +169,7 @@ var __param = this.__param || function(index, decorator) { return function (targ /** Sourcemap data that will get encoded */ let sourceMapData: SourceMapData; - if (compilerOptions.sourceMap) { + if (compilerOptions.sourceMap || compilerOptions.inlineSourceMap) { initializeEmitterWithSourceMaps(); } @@ -564,19 +564,25 @@ var __param = this.__param || function(index, decorator) { return function (targ recordSourceMapSpan(comment.end); } - function serializeSourceMapContents(version: number, file: string, sourceRoot: string, sources: string[], names: string[], mappings: string) { + function serializeSourceMapContents(version: number, file: string, sourceRoot: string, sources: string[], names: string[], mappings: string, sourcesContent?: string[]) { if (typeof JSON !== "undefined") { - return JSON.stringify({ - version: version, - file: file, - sourceRoot: sourceRoot, - sources: sources, - names: names, - mappings: mappings - }); + let map: any = { + version, + file, + sourceRoot, + sources, + names, + mappings + }; + + if (sourcesContent !== undefined) { + map.sourcesContent = sourcesContent; + } + + return JSON.stringify(map); } - return "{\"version\":" + version + ",\"file\":\"" + escapeString(file) + "\",\"sourceRoot\":\"" + escapeString(sourceRoot) + "\",\"sources\":[" + serializeStringArray(sources) + "],\"names\":[" + serializeStringArray(names) + "],\"mappings\":\"" + escapeString(mappings) + "\"}"; + return "{\"version\":" + version + ",\"file\":\"" + escapeString(file) + "\",\"sourceRoot\":\"" + escapeString(sourceRoot) + "\",\"sources\":[" + serializeStringArray(sources) + "],\"names\":[" + serializeStringArray(names) + "],\"mappings\":\"" + escapeString(mappings) + "\" " + (sourcesContent !== undefined ? ",\"sourcesContent\":[" + serializeStringArray(sourcesContent) + "]" : "") + "}"; function serializeStringArray(list: string[]): string { let output = ""; @@ -591,19 +597,34 @@ var __param = this.__param || function(index, decorator) { return function (targ } function writeJavaScriptAndSourceMapFile(emitOutput: string, writeByteOrderMark: boolean) { - // Write source map file encodeLastRecordedSourceMapSpan(); - writeFile(host, diagnostics, sourceMapData.sourceMapFilePath, serializeSourceMapContents( + + let fileContents = compilerOptions.inlineSourceMap ? [currentSourceFile.text] : undefined; + let sourceMapText = serializeSourceMapContents( 3, sourceMapData.sourceMapFile, sourceMapData.sourceMapSourceRoot, sourceMapData.sourceMapSources, sourceMapData.sourceMapNames, - sourceMapData.sourceMapMappings), /*writeByteOrderMark*/ false); + sourceMapData.sourceMapMappings, + fileContents); + sourceMapDataList.push(sourceMapData); + let sourceMapUrl: string; + if (compilerOptions.inlineSourceMap) { + // Encode the sourceMap into the sourceMap url + let base64SourceMapText = convertToBase64(sourceMapText); + sourceMapUrl = `//# sourceMappingURL=data:application/json;base64,${base64SourceMapText}`; + } + else { + // Write source map file + writeFile(host, diagnostics, sourceMapData.sourceMapFilePath, sourceMapText, /*writeByteOrderMark*/ false); + sourceMapUrl = `//# sourceMappingURL=${sourceMapData.jsSourceMappingURL}`; + } + // Write sourcemap url to the js file and write the js file - writeJavaScriptFile(emitOutput + "//# sourceMappingURL=" + sourceMapData.jsSourceMappingURL, writeByteOrderMark); + writeJavaScriptFile(emitOutput + sourceMapUrl, writeByteOrderMark); } // Initialize source map data @@ -861,7 +882,7 @@ var __param = this.__param || function(index, decorator) { return function (targ function emitLiteral(node: LiteralExpression) { let text = getLiteralText(node); - if (compilerOptions.sourceMap && (node.kind === SyntaxKind.StringLiteral || isTemplateLiteralKind(node.kind))) { + if ((compilerOptions.sourceMap || compilerOptions.inlineSourceMap) && (node.kind === SyntaxKind.StringLiteral || isTemplateLiteralKind(node.kind))) { writer.writeLiteral(text); } // For versions below ES6, emit binary & octal literals in their canonical decimal form. diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 69faeda2db0..8bf9d049b8d 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -472,6 +472,21 @@ module ts { } } + if (options.inlineSourceMap) { + if (options.sourceMap) { + diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_sourceMap_cannot_be_specified_with_option_inlineSourceMap)); + } + if (options.mapRoot) { + diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_mapRoot_cannot_be_specified_with_option_inlineSourceMap)); + } + if (options.sourceRoot) { + diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_sourceRoot_cannot_be_specified_with_option_inlineSourceMap)); + } + if (options.out) { + diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_out_cannot_be_specified_with_option_inlineSourceMap)); + } + } + if (!options.sourceMap && (options.mapRoot || options.sourceRoot)) { // Error to specify --mapRoot or --sourceRoot without mapSourceFiles if (options.mapRoot) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 74777057963..8bddb943892 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1587,6 +1587,7 @@ module ts { diagnostics?: boolean; emitBOM?: boolean; help?: boolean; + inlineSourceMap?: boolean; listFiles?: boolean; locale?: string; mapRoot?: string; diff --git a/src/harness/compilerRunner.ts b/src/harness/compilerRunner.ts index d4dd8e31258..8b4e60f8f60 100644 --- a/src/harness/compilerRunner.ts +++ b/src/harness/compilerRunner.ts @@ -159,7 +159,7 @@ class CompilerBaselineRunner extends RunnerBase { // Source maps? it('Correct sourcemap content for ' + fileName, () => { - if (options.sourceMap) { + if (options.sourceMap || options.inlineSourceMap) { Harness.Baseline.runBaseline('Correct sourcemap content for ' + fileName, justName.replace(/\.ts$/, '.sourcemap.txt'), () => { var record = result.getSourceMapRecord(); if (options.noEmitOnError && result.errors.length !== 0 && record === undefined) { @@ -228,11 +228,14 @@ class CompilerBaselineRunner extends RunnerBase { }); it('Correct Sourcemap output for ' + fileName, () => { - if (options.sourceMap) { - if (result.sourceMaps.length !== result.files.length) { - throw new Error('Number of sourcemap files should be same as js files.'); - } + if (options.sourceMap && result.sourceMaps.length !== result.files.length) { + throw new Error('Number of sourcemap files should be same as js files.'); + } + else if (options.inlineSourceMap && result.sourceMaps.length > 0) { + throw new Error('No sourcemap files should be generated if inlineSourceMaps was set.'); + } + if (options.sourceMap) { Harness.Baseline.runBaseline('Correct Sourcemap output for ' + fileName, justName.replace(/\.ts/, '.js.map'), () => { if (options.noEmitOnError && result.errors.length !== 0 && result.sourceMaps.length === 0) { // We need to return null here or the runBaseLine will actually create a empty file. diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 784d8312d69..bef3c38cc01 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -1016,6 +1016,10 @@ module Harness { options.sourceRoot = setting.value; break; + case 'maproot': + options.mapRoot = setting.value; + break; + case 'sourcemap': options.sourceMap = !!setting.value; break; @@ -1069,6 +1073,10 @@ module Harness { includeBuiltFiles.push({ unitName: builtFileName, content: normalizeLineEndings(IO.readFile(builtFileName), newLine) }); break; + case 'inlinesourcemap': + options.inlineSourceMap = setting.value === 'true'; + break; + default: throw new Error('Unsupported compiler setting ' + setting.flag); } @@ -1465,7 +1473,7 @@ module Harness { "noimplicitany", "noresolve", "newline", "newlines", "emitbom", "errortruncation", "usecasesensitivefilenames", "preserveconstenums", "includebuiltfile", "suppressimplicitanyindexerrors", "stripinternal", - "separatecompilation"]; + "separatecompilation", "inlinesourcemap", "maproot", "sourceroot"]; function extractCompilerSettings(content: string): CompilerSetting[] { diff --git a/tests/baselines/reference/inlineSourceMap.errors.txt b/tests/baselines/reference/inlineSourceMap.errors.txt new file mode 100644 index 00000000000..8d92d6a161d --- /dev/null +++ b/tests/baselines/reference/inlineSourceMap.errors.txt @@ -0,0 +1,9 @@ +tests/cases/compiler/inlineSourceMap.ts(3,1): error TS2304: Cannot find name 'console'. + + +==== tests/cases/compiler/inlineSourceMap.ts (1 errors) ==== + + var x = 0; + console.log(x); + ~~~~~~~ +!!! error TS2304: Cannot find name 'console'. \ No newline at end of file diff --git a/tests/baselines/reference/inlineSourceMap.js b/tests/baselines/reference/inlineSourceMap.js new file mode 100644 index 00000000000..da0f6de96d3 --- /dev/null +++ b/tests/baselines/reference/inlineSourceMap.js @@ -0,0 +1,9 @@ +//// [inlineSourceMap.ts] + +var x = 0; +console.log(x); + +//// [inlineSourceMap.js] +var x = 0; +console.log(x); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5saW5lU291cmNlTWFwLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiaW5saW5lU291cmNlTWFwLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLElBQUksQ0FBQyxHQUFHLENBQUMsQ0FBQztBQUNWLE9BQU8sQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFDLENBQUMiLCJzb3VyY2VzQ29udGVudCI6WyJcbnZhciB4ID0gMDtcbmNvbnNvbGUubG9nKHgpOyJdfQ== \ No newline at end of file diff --git a/tests/baselines/reference/inlineSourceMap.sourcemap.txt b/tests/baselines/reference/inlineSourceMap.sourcemap.txt new file mode 100644 index 00000000000..e344ecc43ab --- /dev/null +++ b/tests/baselines/reference/inlineSourceMap.sourcemap.txt @@ -0,0 +1,61 @@ +=================================================================== +JsFile: inlineSourceMap.js +mapUrl: inlineSourceMap.js.map +sourceRoot: +sources: inlineSourceMap.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/inlineSourceMap.js +sourceFile:inlineSourceMap.ts +------------------------------------------------------------------- +>>>var x = 0; +1 > +2 >^^^^ +3 > ^ +4 > ^^^ +5 > ^ +6 > ^ +7 > ^^^^^^-> +1 > + > +2 >var +3 > x +4 > = +5 > 0 +6 > ; +1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) +2 >Emitted(1, 5) Source(2, 5) + SourceIndex(0) +3 >Emitted(1, 6) Source(2, 6) + SourceIndex(0) +4 >Emitted(1, 9) Source(2, 9) + SourceIndex(0) +5 >Emitted(1, 10) Source(2, 10) + SourceIndex(0) +6 >Emitted(1, 11) Source(2, 11) + SourceIndex(0) +--- +>>>console.log(x); +1-> +2 >^^^^^^^ +3 > ^ +4 > ^^^ +5 > ^ +6 > ^ +7 > ^ +8 > ^ +9 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1-> + > +2 >console +3 > . +4 > log +5 > ( +6 > x +7 > ) +8 > ; +1->Emitted(2, 1) Source(3, 1) + SourceIndex(0) +2 >Emitted(2, 8) Source(3, 8) + SourceIndex(0) +3 >Emitted(2, 9) Source(3, 9) + SourceIndex(0) +4 >Emitted(2, 12) Source(3, 12) + SourceIndex(0) +5 >Emitted(2, 13) Source(3, 13) + SourceIndex(0) +6 >Emitted(2, 14) Source(3, 14) + SourceIndex(0) +7 >Emitted(2, 15) Source(3, 15) + SourceIndex(0) +8 >Emitted(2, 16) Source(3, 16) + SourceIndex(0) +--- +>>>//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5saW5lU291cmNlTWFwLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiaW5saW5lU291cmNlTWFwLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLElBQUksQ0FBQyxHQUFHLENBQUMsQ0FBQztBQUNWLE9BQU8sQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFDLENBQUMiLCJzb3VyY2VzQ29udGVudCI6WyJcbnZhciB4ID0gMDtcbmNvbnNvbGUubG9nKHgpOyJdfQ== \ No newline at end of file diff --git a/tests/baselines/reference/inlineSourceMap2.errors.txt b/tests/baselines/reference/inlineSourceMap2.errors.txt new file mode 100644 index 00000000000..f35aabd8fa6 --- /dev/null +++ b/tests/baselines/reference/inlineSourceMap2.errors.txt @@ -0,0 +1,19 @@ +error TS5051: Option 'out' cannot be specified with option 'inlineSourceMap'. +error TS5050: Option 'mapRoot' cannot be specified with option 'inlineSourceMap'. +error TS5049: Option 'sourceRoot' cannot be specified with option 'inlineSourceMap'. +error TS5048: Option 'sourceMap' cannot be specified with option 'inlineSourceMap'. +tests/cases/compiler/inlineSourceMap2.ts(5,1): error TS2304: Cannot find name 'console'. + + +!!! error TS5051: Option 'out' cannot be specified with option 'inlineSourceMap'. +!!! error TS5050: Option 'mapRoot' cannot be specified with option 'inlineSourceMap'. +!!! error TS5049: Option 'sourceRoot' cannot be specified with option 'inlineSourceMap'. +!!! error TS5048: Option 'sourceMap' cannot be specified with option 'inlineSourceMap'. +==== tests/cases/compiler/inlineSourceMap2.ts (1 errors) ==== + + // configuration errors + + var x = 0; + console.log(x); + ~~~~~~~ +!!! error TS2304: Cannot find name 'console'. \ No newline at end of file diff --git a/tests/baselines/reference/inlineSourceMap2.js b/tests/baselines/reference/inlineSourceMap2.js new file mode 100644 index 00000000000..679b480af3e --- /dev/null +++ b/tests/baselines/reference/inlineSourceMap2.js @@ -0,0 +1,12 @@ +//// [inlineSourceMap2.ts] + +// configuration errors + +var x = 0; +console.log(x); + +//// [outfile.js] +// configuration errors +var x = 0; +console.log(x); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib3V0ZmlsZS5qcyIsInNvdXJjZVJvb3QiOiJmaWxlOi8vL2ZvbGRlci8iLCJzb3VyY2VzIjpbImlubGluZVNvdXJjZU1hcDIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsdUJBQXVCO0FBRXZCLElBQUksQ0FBQyxHQUFHLENBQUMsQ0FBQztBQUNWLE9BQU8sQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFDLENBQUMiLCJzb3VyY2VzQ29udGVudCI6WyJcbi8vIGNvbmZpZ3VyYXRpb24gZXJyb3JzXG5cbnZhciB4ID0gMDtcbmNvbnNvbGUubG9nKHgpOyJdfQ== \ No newline at end of file diff --git a/tests/baselines/reference/inlineSourceMap2.sourcemap.txt b/tests/baselines/reference/inlineSourceMap2.sourcemap.txt new file mode 100644 index 00000000000..3994efe82bf --- /dev/null +++ b/tests/baselines/reference/inlineSourceMap2.sourcemap.txt @@ -0,0 +1,71 @@ +=================================================================== +JsFile: outfile.js +mapUrl: file:///folder/outfile.js.map +sourceRoot: file:///folder/ +sources: inlineSourceMap2.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:outfile.js +sourceFile:inlineSourceMap2.ts +------------------------------------------------------------------- +>>>// configuration errors +1 > +2 >^^^^^^^^^^^^^^^^^^^^^^^ +1 > + > +2 >// configuration errors +1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) +2 >Emitted(1, 24) Source(2, 24) + SourceIndex(0) +--- +>>>var x = 0; +1 > +2 >^^^^ +3 > ^ +4 > ^^^ +5 > ^ +6 > ^ +7 > ^^^^^^-> +1 > + > + > +2 >var +3 > x +4 > = +5 > 0 +6 > ; +1 >Emitted(2, 1) Source(4, 1) + SourceIndex(0) +2 >Emitted(2, 5) Source(4, 5) + SourceIndex(0) +3 >Emitted(2, 6) Source(4, 6) + SourceIndex(0) +4 >Emitted(2, 9) Source(4, 9) + SourceIndex(0) +5 >Emitted(2, 10) Source(4, 10) + SourceIndex(0) +6 >Emitted(2, 11) Source(4, 11) + SourceIndex(0) +--- +>>>console.log(x); +1-> +2 >^^^^^^^ +3 > ^ +4 > ^^^ +5 > ^ +6 > ^ +7 > ^ +8 > ^ +9 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1-> + > +2 >console +3 > . +4 > log +5 > ( +6 > x +7 > ) +8 > ; +1->Emitted(3, 1) Source(5, 1) + SourceIndex(0) +2 >Emitted(3, 8) Source(5, 8) + SourceIndex(0) +3 >Emitted(3, 9) Source(5, 9) + SourceIndex(0) +4 >Emitted(3, 12) Source(5, 12) + SourceIndex(0) +5 >Emitted(3, 13) Source(5, 13) + SourceIndex(0) +6 >Emitted(3, 14) Source(5, 14) + SourceIndex(0) +7 >Emitted(3, 15) Source(5, 15) + SourceIndex(0) +8 >Emitted(3, 16) Source(5, 16) + SourceIndex(0) +--- +>>>//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib3V0ZmlsZS5qcyIsInNvdXJjZVJvb3QiOiJmaWxlOi8vL2ZvbGRlci8iLCJzb3VyY2VzIjpbImlubGluZVNvdXJjZU1hcDIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsdUJBQXVCO0FBRXZCLElBQUksQ0FBQyxHQUFHLENBQUMsQ0FBQztBQUNWLE9BQU8sQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFDLENBQUMiLCJzb3VyY2VzQ29udGVudCI6WyJcbi8vIGNvbmZpZ3VyYXRpb24gZXJyb3JzXG5cbnZhciB4ID0gMDtcbmNvbnNvbGUubG9nKHgpOyJdfQ== \ No newline at end of file diff --git a/tests/cases/compiler/inlineSourceMap.ts b/tests/cases/compiler/inlineSourceMap.ts new file mode 100644 index 00000000000..35e9845ba58 --- /dev/null +++ b/tests/cases/compiler/inlineSourceMap.ts @@ -0,0 +1,5 @@ +// @target: ES3 +// @inlinesourcemap: true + +var x = 0; +console.log(x); \ No newline at end of file diff --git a/tests/cases/compiler/inlineSourceMap2.ts b/tests/cases/compiler/inlineSourceMap2.ts new file mode 100644 index 00000000000..1d426f17736 --- /dev/null +++ b/tests/cases/compiler/inlineSourceMap2.ts @@ -0,0 +1,11 @@ +// @target: ES3 +// @sourcemap: true +// @maproot: file:///folder +// @sourceroot: file:///folder +// @out: outfile.js +// @inlinesourcemap: true + +// configuration errors + +var x = 0; +console.log(x); \ No newline at end of file From cacf34a4c26de32e054762606a6ee5a42ced3683 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 9 Apr 2015 16:55:42 -0700 Subject: [PATCH 003/194] Check for inlineSoruceMaps first --- src/harness/compilerRunner.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/harness/compilerRunner.ts b/src/harness/compilerRunner.ts index 8b4e60f8f60..2845feb75b6 100644 --- a/src/harness/compilerRunner.ts +++ b/src/harness/compilerRunner.ts @@ -228,14 +228,17 @@ class CompilerBaselineRunner extends RunnerBase { }); it('Correct Sourcemap output for ' + fileName, () => { - if (options.sourceMap && result.sourceMaps.length !== result.files.length) { - throw new Error('Number of sourcemap files should be same as js files.'); - } - else if (options.inlineSourceMap && result.sourceMaps.length > 0) { - throw new Error('No sourcemap files should be generated if inlineSourceMaps was set.'); + if (options.inlineSourceMap) { + if (result.sourceMaps.length > 0) { + throw new Error('No sourcemap files should be generated if inlineSourceMaps was set.'); + } + return null; } + else if (options.sourceMap) { + if (result.sourceMaps.length !== result.files.length) { + throw new Error('Number of sourcemap files should be same as js files.'); + } - if (options.sourceMap) { Harness.Baseline.runBaseline('Correct Sourcemap output for ' + fileName, justName.replace(/\.ts/, '.js.map'), () => { if (options.noEmitOnError && result.errors.length !== 0 && result.sourceMaps.length === 0) { // We need to return null here or the runBaseLine will actually create a empty file. From e8fcf8fa2a201949ecfb489de972a635ab2cb3c9 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Fri, 10 Apr 2015 12:10:38 -0700 Subject: [PATCH 004/194] initial support for system module --- src/compiler/checker.ts | 18 +- src/compiler/commandLineParser.ts | 7 +- .../diagnosticInformationMap.generated.ts | 7 +- src/compiler/diagnosticMessages.json | 10 +- src/compiler/emitter.ts | 362 ++++++++++++++++-- src/compiler/program.ts | 2 +- src/compiler/types.ts | 1 + src/compiler/utilities.ts | 16 + 8 files changed, 366 insertions(+), 57 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ea86b2b9b04..bee917a2cb6 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10616,9 +10616,15 @@ module ts { checkExternalModuleExports(container); - 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); + if (node.isExportEquals) { + 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); + } + else if (compilerOptions.module === ModuleKind.System) { + // system modules does not support export assignment + grammarErrorOnNode(node, Diagnostics.Export_assignment_is_not_supported_with_module_flag_is_system); + } } } @@ -11432,9 +11438,11 @@ module ts { function getExportNameSubstitution(symbol: Symbol, location: Node, getGeneratedNameForNode: (Node: Node) => string): string { if (isExternalModuleSymbol(symbol.parent)) { - // If this is es6 or higher, just use the name of the export + // 1. If this is es6 or higher, just use the name of the export // no need to qualify it. - if (languageVersion >= ScriptTarget.ES6) { + // 2. export mechanism for System modules is different from CJS\AMD + // and it does not need qualifications for exports + if (languageVersion >= ScriptTarget.ES6 || compilerOptions.module === ModuleKind.System) { return undefined; } return "exports." + unescapeIdentifier(symbol.name); diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 48817798d81..201aaf743ae 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -50,11 +50,12 @@ module ts { shortName: "m", type: { "commonjs": ModuleKind.CommonJS, - "amd": ModuleKind.AMD + "amd": ModuleKind.AMD, + "system": ModuleKind.System, }, - description: Diagnostics.Specify_module_code_generation_Colon_commonjs_or_amd, + description: Diagnostics.Specify_module_code_generation_Colon_commonjs_system_or_amd, paramType: Diagnostics.KIND, - error: Diagnostics.Argument_for_module_option_must_be_commonjs_or_amd + error: Diagnostics.Argument_for_module_option_must_be_commonjs_system_or_amd }, { name: "noEmit", diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 5062be5ed46..b18b59377b0 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -161,7 +161,7 @@ module ts { A_type_annotation_on_an_export_statement_is_only_allowed_in_an_ambient_external_module_declaration: { code: 1201, category: DiagnosticCategory.Error, key: "A type annotation on an export statement is only allowed in an ambient external module declaration." }, Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_or_import_d_from_mod_instead: { code: 1202, category: DiagnosticCategory.Error, key: "Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * as ns from \"mod\"', 'import {a} from \"mod\"' or 'import d from \"mod\"' instead." }, Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_export_default_instead: { code: 1203, category: DiagnosticCategory.Error, key: "Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead." }, - Cannot_compile_external_modules_into_amd_or_commonjs_when_targeting_es6_or_higher: { code: 1204, category: DiagnosticCategory.Error, key: "Cannot compile external modules into amd or commonjs when targeting es6 or higher." }, + Cannot_compile_external_modules_into_amd_system_or_commonjs_when_targeting_es6_or_higher: { code: 1204, category: DiagnosticCategory.Error, key: "Cannot compile external modules into amd, system or commonjs when targeting es6 or higher." }, Decorators_are_only_available_when_targeting_ECMAScript_5_and_higher: { code: 1205, category: DiagnosticCategory.Error, key: "Decorators are only available when targeting ECMAScript 5 and higher." }, Decorators_are_not_valid_here: { code: 1206, category: DiagnosticCategory.Error, key: "Decorators are not valid here." }, Decorators_cannot_be_applied_to_multiple_get_Slashset_accessors_of_the_same_name: { code: 1207, category: DiagnosticCategory.Error, key: "Decorators cannot be applied to multiple get/set accessors of the same name." }, @@ -169,6 +169,7 @@ module ts { Ambient_const_enums_are_not_allowed_when_the_separateCompilation_flag_is_provided: { code: 1209, category: DiagnosticCategory.Error, key: "Ambient const enums are not allowed when the '--separateCompilation' flag is provided." }, Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode: { code: 1210, category: DiagnosticCategory.Error, key: "Invalid use of '{0}'. Class definitions are automatically in strict mode." }, A_class_declaration_without_the_default_modifier_must_have_a_name: { code: 1211, category: DiagnosticCategory.Error, key: "A class declaration without the 'default' modifier must have a name" }, + Export_assignment_is_not_supported_with_module_flag_is_system: { code: 1212, category: DiagnosticCategory.Error, key: "Export assignment is not supported with '--module' flag is 'system'." }, 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." }, @@ -456,7 +457,7 @@ module ts { Do_not_emit_comments_to_output: { code: 6009, category: DiagnosticCategory.Message, key: "Do not emit comments to output." }, Do_not_emit_outputs: { code: 6010, category: DiagnosticCategory.Message, key: "Do not emit outputs." }, Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental: { code: 6015, category: DiagnosticCategory.Message, key: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES6' (experimental)" }, - Specify_module_code_generation_Colon_commonjs_or_amd: { code: 6016, category: DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs' or 'amd'" }, + Specify_module_code_generation_Colon_commonjs_system_or_amd: { code: 6016, category: DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs', 'system' or 'amd'" }, Print_this_message: { code: 6017, category: DiagnosticCategory.Message, key: "Print this message." }, Print_the_compiler_s_version: { code: 6019, category: DiagnosticCategory.Message, key: "Print the compiler's version." }, Compile_the_project_in_the_given_directory: { code: 6020, category: DiagnosticCategory.Message, key: "Compile the project in the given directory." }, @@ -477,7 +478,7 @@ module ts { Generates_corresponding_map_file: { code: 6043, category: DiagnosticCategory.Message, key: "Generates corresponding '.map' file." }, Compiler_option_0_expects_an_argument: { code: 6044, category: DiagnosticCategory.Error, key: "Compiler option '{0}' expects an argument." }, Unterminated_quoted_string_in_response_file_0: { code: 6045, category: DiagnosticCategory.Error, key: "Unterminated quoted string in response file '{0}'." }, - Argument_for_module_option_must_be_commonjs_or_amd: { code: 6046, category: DiagnosticCategory.Error, key: "Argument for '--module' option must be 'commonjs' or 'amd'." }, + Argument_for_module_option_must_be_commonjs_system_or_amd: { code: 6046, category: DiagnosticCategory.Error, key: "Argument for '--module' option must be 'commonjs', 'system' or 'amd'." }, Argument_for_target_option_must_be_es3_es5_or_es6: { code: 6047, category: DiagnosticCategory.Error, key: "Argument for '--target' option must be 'es3', 'es5', or 'es6'." }, Locale_must_be_of_the_form_language_or_language_territory_For_example_0_or_1: { code: 6048, category: DiagnosticCategory.Error, key: "Locale must be of the form or -. For example '{0}' or '{1}'." }, Unsupported_locale_0: { code: 6049, category: DiagnosticCategory.Error, key: "Unsupported locale '{0}'." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 4476b0cad4a..cf7e60fa311 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -635,7 +635,7 @@ "category": "Error", "code": 1203 }, - "Cannot compile external modules into amd or commonjs when targeting es6 or higher.": { + "Cannot compile external modules into amd, system or commonjs when targeting es6 or higher.": { "category": "Error", "code": 1204 }, @@ -667,6 +667,10 @@ "category": "Error", "code": 1211 }, + "Export assignment is not supported with '--module' flag is 'system'.": { + "category": "Error", + "code": 1212 + }, "Duplicate identifier '{0}'.": { "category": "Error", "code": 2300 @@ -1816,7 +1820,7 @@ "category": "Message", "code": 6015 }, - "Specify module code generation: 'commonjs' or 'amd'": { + "Specify module code generation: 'commonjs', 'system' or 'amd'": { "category": "Message", "code": 6016 }, @@ -1900,7 +1904,7 @@ "category": "Error", "code": 6045 }, - "Argument for '--module' option must be 'commonjs' or 'amd'.": { + "Argument for '--module' option must be 'commonjs', 'system' or 'amd'.": { "category": "Error", "code": 6046 }, diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 940edf04191..77f9c9a7f3b 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -117,6 +117,7 @@ var __param = this.__param || function(index, decorator) { return function (targ let decreaseIndent = writer.decreaseIndent; let currentSourceFile: SourceFile; + let exportFunctionForFile: string; let generatedNameSet: Map = {}; let nodeToGeneratedName: string[] = []; @@ -191,6 +192,7 @@ var __param = this.__param || function(index, decorator) { return function (targ function emitSourceFile(sourceFile: SourceFile): void { currentSourceFile = sourceFile; + exportFunctionForFile = undefined; emit(sourceFile); } @@ -1136,7 +1138,7 @@ var __param = this.__param || function(index, decorator) { return function (targ if (!computedPropertyNamesToGeneratedNames) { computedPropertyNamesToGeneratedNames = []; } - + let generatedName = computedPropertyNamesToGeneratedNames[getNodeId(node)]; if (generatedName) { // we have already generated a variable for this node, write that value instead. @@ -1584,7 +1586,7 @@ var __param = this.__param || function(index, decorator) { return function (targ result.name = name; return result; - } + } function createElementAccessExpression(expression: LeftHandSideExpression, argumentExpression: Expression): ElementAccessExpression { let result = createSynthesizedNode(SyntaxKind.ElementAccessExpression); @@ -2060,6 +2062,10 @@ var __param = this.__param || function(index, decorator) { return function (targ } function emitStartOfVariableDeclarationList(decl: Node, startPos?: number): void { + if (currentFileIsEmittedAsSystemModule() && isSourceFileLevelDeclaration(decl)) { + Debug.assert(compilerOptions.module === ModuleKind.System); + return; + } let tokenKind = SyntaxKind.VarKeyword; if (decl && languageVersion >= ScriptTarget.ES6) { if (isLet(decl)) { @@ -2072,6 +2078,7 @@ var __param = this.__param || function(index, decorator) { return function (targ if (startPos !== undefined) { emitToken(tokenKind, startPos); + write(" ") } else { switch (tokenKind) { @@ -2093,7 +2100,6 @@ var __param = this.__param || function(index, decorator) { return function (targ let variableDeclarationList = node.initializer; let declarations = variableDeclarationList.declarations; emitStartOfVariableDeclarationList(declarations[0], endPos); - write(" "); emitCommaList(declarations); } else if (node.initializer) { @@ -2120,7 +2126,6 @@ var __param = this.__param || function(index, decorator) { return function (targ if (variableDeclarationList.declarations.length >= 1) { let decl = variableDeclarationList.declarations[0]; emitStartOfVariableDeclarationList(decl, endPos); - write(" "); emit(decl); } } @@ -2415,7 +2420,7 @@ var __param = this.__param || function(index, decorator) { return function (targ write(getGeneratedNameForNode(container)); write("."); } - else if (languageVersion < ScriptTarget.ES6) { + else if (languageVersion < ScriptTarget.ES6 && compilerOptions.module !== ModuleKind.System) { write("exports."); } } @@ -2435,14 +2440,28 @@ var __param = this.__param || function(index, decorator) { return function (targ if (node.flags & NodeFlags.Export) { writeLine(); emitStart(node); - if (node.flags & NodeFlags.Default) { - write("exports.default"); + if (compilerOptions.module === ModuleKind.System) { + write(`${exportFunctionForFile}("`); + if (node.flags & NodeFlags.Default) { + write("default"); + } + else { + emitNodeWithoutSourceMap(node.name); + } + write(`", `); + emitDeclarationName(node); + write(")") } else { - emitModuleMemberName(node); + if (node.flags & NodeFlags.Default) { + write("exports.default"); + } + else { + emitModuleMemberName(node); + } + write(" = "); + emitDeclarationName(node); } - write(" = "); - emitDeclarationName(node); emitEnd(node); write(";"); } @@ -2453,12 +2472,21 @@ var __param = this.__param || function(index, decorator) { return function (targ for (let specifier of exportSpecifiers[name.text]) { writeLine(); emitStart(specifier.name); - emitContainingModuleName(specifier); - write("."); - emitNodeWithoutSourceMap(specifier.name); - emitEnd(specifier.name); - write(" = "); - emitExpressionIdentifier(name); + if (compilerOptions.module === ModuleKind.System) { + write(`${exportFunctionForFile}("`); + emitNodeWithoutSourceMap(specifier.name); + write(`", `); + emitExpressionIdentifier(name); + write(")") + } + else { + emitContainingModuleName(specifier); + write("."); + emitNodeWithoutSourceMap(specifier.name); + emitEnd(specifier.name); + write(" = "); + emitExpressionIdentifier(name); + } write(";"); } } @@ -2477,7 +2505,18 @@ var __param = this.__param || function(index, decorator) { return function (targ let emitCount = 0; // An exported declaration is actually emitted as an assignment (to a property on the module object), so // temporary variables in an exported declaration need to have real declarations elsewhere - let isDeclaration = (root.kind === SyntaxKind.VariableDeclaration && !(getCombinedNodeFlags(root) & NodeFlags.Export)) || root.kind === SyntaxKind.Parameter; + // Also temporary variables should be explicitly allocated for source level declarations when module target is system + // because actual variable declarations are hoisted + let canDefineTempVariablesInplace = false; + if (root.kind === SyntaxKind.VariableDeclaration) { + let isExported = getCombinedNodeFlags(root) & NodeFlags.Export; + let isSourceLevelForSystemModuleKind = currentFileIsEmittedAsSystemModule() && isSourceFileLevelDeclaration(root); + canDefineTempVariablesInplace = !isExported && !isSourceLevelForSystemModuleKind; + } + else if (root.kind === SyntaxKind.Parameter) { + canDefineTempVariablesInplace = true; + } + if (root.kind === SyntaxKind.BinaryExpression) { emitAssignmentExpression(root); } @@ -2508,7 +2547,7 @@ var __param = this.__param || function(index, decorator) { return function (targ // as the location for determining uniqueness of the variable we are about to // generate. let identifier = createTempVariable(TempFlags.Auto); - if (!isDeclaration) { + if (!canDefineTempVariablesInplace) { recordTempDeclaration(identifier); } emitAssignment(identifier, expr); @@ -2788,6 +2827,10 @@ var __param = this.__param || function(index, decorator) { return function (targ if (resolver.resolvesToSomeValue(parent, (node).text)) { let variableId = resolver.getBlockScopedVariableId(node); + if (blockScopedVariableToGeneratedName && blockScopedVariableToGeneratedName[variableId]) { + // already renamed + return; + } if (!blockScopedVariableToGeneratedName) { blockScopedVariableToGeneratedName = []; } @@ -4418,6 +4461,8 @@ var __param = this.__param || function(index, decorator) { return function (targ } function emitExportDeclaration(node: ExportDeclaration) { + Debug.assert(compilerOptions.module !== ModuleKind.System); + if (languageVersion < ScriptTarget.ES6) { if (node.moduleSpecifier && (!node.exportClause || resolver.isValueAliasDeclaration(node))) { emitStart(node); @@ -4523,9 +4568,16 @@ var __param = this.__param || function(index, decorator) { return function (targ else { writeLine(); emitStart(node); - emitContainingModuleName(node); - write(".default = "); - emit(node.expression); + if (compilerOptions.module === ModuleKind.System) { + write(`${exportFunctionForFile}("default",`); + emit(node.expression); + write(")"); + } + else { + emitContainingModuleName(node); + write(".default = "); + emit(node.expression); + } write(";"); emitEnd(node); } @@ -4611,6 +4663,248 @@ var __param = this.__param || function(index, decorator) { return function (targ } } + function writeModuleNamesForExternalImports(startWithComma: boolean): void { + let started = startWithComma; + for (let importNode of externalImports) { + if (started) { + write(", "); + } + else { + started = true; + } + let moduleName = getExternalModuleName(importNode); + if (moduleName.kind === SyntaxKind.StringLiteral) { + emitLiteral(moduleName); + } + else { + write("\"\""); + } + } + } + + function writeLocalNameForExternalImport(importNode: ImportDeclaration | ExportDeclaration | ImportEqualsDeclaration): void { + let namespaceDeclaration = getNamespaceDeclarationNode(importNode); + if (namespaceDeclaration && !isDefaultImport(importNode)) { + emit(namespaceDeclaration.name); + } + else { + write(getGeneratedNameForNode(importNode)); + } + } + + function writeLocalNamesForExternalImports(startWithComma: boolean): void { + let started = startWithComma; + for (let importNode of externalImports) { + + if (started) { + write(", "); + } + else { + started = true; + } + + writeLocalNameForExternalImport(importNode); + } + + } + + function emitVariableDeclarationsForImports(): void { + if (externalImports.length === 0) { + return; + } + + writeLine(); + let started = false; + for (let importNode of externalImports) { + if (importNode.kind === SyntaxKind.ExportDeclaration) { + continue; + } + + if (!started) { + write("var "); + started = true; + } + else { + write(", "); + } + writeLocalNameForExternalImport(importNode); + } + + if (started) { + write(";"); + } + } + + function hoistTopLevelVariableAndFunctionDeclarations(node: SourceFile): void { + let hoistedLocals: Identifier[]; + let hoistedFunctionDeclarations: FunctionDeclaration[]; + + visit(node); + + if (hoistedLocals) { + writeLine(); + write("var "); + for (let i = 0; i < hoistedLocals.length; ++i) { + let local = hoistedLocals[i]; + if (i !== 0) { + write(", "); + } + emit(local); + } + write(";") + } + + if (hoistedFunctionDeclarations) { + for (let f of hoistedFunctionDeclarations) { + writeLine(); + emit(f); + } + } + + function visit(node: Node): void { + if (node.kind === SyntaxKind.FunctionDeclaration) { + (hoistedFunctionDeclarations || (hoistedFunctionDeclarations = [])).push(node); + return; + } + + if (node.kind === SyntaxKind.VariableDeclaration || node.kind === SyntaxKind.BindingElement) { + let name = (node).name; + if (name.kind === SyntaxKind.Identifier) { + renameNonTopLevelLetAndConst(name); + (hoistedLocals || (hoistedLocals = [])).push(name); + } + else { + forEachChild(name, visit); + } + return; + } + + if (isBindingPattern(node)) { + forEach((node).elements, visit); + return; + } + + if (!isDeclaration(node)) { + forEachChild(node, visit); + } + } + } + + function currentFileIsEmittedAsSystemModule(): boolean { + return exportFunctionForFile !== undefined; + } + + function emitSystemModuleBody(node: SourceFile, startIndex: number): void { + emitVariableDeclarationsForImports(); + writeLine(); + hoistTopLevelVariableAndFunctionDeclarations(node); + writeLine(); + write("return {"); + increaseIndent(); + writeLine(); + emitSetters(); + writeLine(); + emitExecute(node, startIndex); + decreaseIndent(); + writeLine(); + write("}"); // return + } + + function emitSetters() { + write("setters:[") + let setterParameterName = makeUniqueName("v"); + for (let i = 0; i < externalImports.length; ++i) { + if (i !== 0) { + write(","); + } + + writeLine(); + increaseIndent(); + write(`function (${setterParameterName}) {`); + let importNode = externalImports[i]; + + switch (importNode.kind) { + case SyntaxKind.ImportDeclaration: + if (!(importNode).importClause) { + break; + } + // fall-through + case SyntaxKind.ImportEqualsDeclaration: + increaseIndent(); + writeLine(); + writeLocalNameForExternalImport(importNode); + write(` = ${setterParameterName}`); + writeLine(); + decreaseIndent(); + break; + case SyntaxKind.ExportDeclaration: + increaseIndent(); + + if ((importNode).exportClause) { + for (let e of (importNode).exportClause.elements) { + writeLine(); + write(`${exportFunctionForFile}("`); + emitNodeWithoutSourceMap(e.name); + write(`", ${setterParameterName}["`); + emitNodeWithoutSourceMap(e.propertyName || e.name); + write(`"];`); + } + } + else { + writeLine(); + // export * from + write(`for (var n in ${setterParameterName}) ${exportFunctionForFile}(n, ${setterParameterName}[n]);`); + } + + writeLine(); + decreaseIndent(); + break; + } + + write("}") + decreaseIndent(); + } + write("],"); + } + + function emitExecute(node: SourceFile, startIndex: number) { + write("execute: function() {"); + increaseIndent(); + writeLine(); + for (let i = startIndex; i < node.statements.length; ++i) { + let statement = node.statements[i]; + switch (statement.kind) { + case SyntaxKind.ExportDeclaration: + case SyntaxKind.ImportDeclaration: + case SyntaxKind.ImportEqualsDeclaration: + case SyntaxKind.FunctionDeclaration: + continue; + } + writeLine(); + emit(statement); + } + decreaseIndent(); + writeLine(); + write("}") // execute + emitTempDeclarations(/*newLine*/ true); + } + + function emitSystemModule(node: SourceFile, startIndex: number): void { + collectExternalModuleInfo(node); + Debug.assert(!exportFunctionForFile); + exportFunctionForFile = makeUniqueName("exports"); + write("System.register(["); + writeModuleNamesForExternalImports(/*startWithComma*/ false); + write(`], function(${exportFunctionForFile}) {`); + writeLine(); + increaseIndent(); + emitCaptureThisForNodeIfNecessary(node); + emitSystemModuleBody(node, startIndex); + decreaseIndent(); + writeLine(); + write("});"); + } + function emitAMDModule(node: SourceFile, startIndex: number) { collectExternalModuleInfo(node); writeLine(); @@ -4620,32 +4914,14 @@ var __param = this.__param || function(index, decorator) { return function (targ write("\"" + node.amdModuleName + "\", "); } write("[\"require\", \"exports\""); - for (let importNode of externalImports) { - write(", "); - let moduleName = getExternalModuleName(importNode); - if (moduleName.kind === SyntaxKind.StringLiteral) { - emitLiteral(moduleName); - } - else { - write("\"\""); - } - } + writeModuleNamesForExternalImports(/*startWithComma*/ true); for (let amdDependency of node.amdDependencies) { let text = "\"" + amdDependency.path + "\""; write(", "); write(text); } write("], function (require, exports"); - for (let importNode of externalImports) { - write(", "); - let namespaceDeclaration = getNamespaceDeclarationNode(importNode); - if (namespaceDeclaration && !isDefaultImport(importNode)) { - emit(namespaceDeclaration.name); - } - else { - write(getGeneratedNameForNode(importNode)); - } - } + writeLocalNamesForExternalImports(/*startWithComma*/ true); for (let amdDependency of node.amdDependencies) { if (amdDependency.name) { write(", "); @@ -4757,7 +5033,9 @@ var __param = this.__param || function(index, decorator) { return function (targ else if (compilerOptions.module === ModuleKind.AMD) { emitAMDModule(node, startIndex); } - else { + else if (compilerOptions.module === ModuleKind.System) { + emitSystemModule(node, startIndex); + } else { emitCommonJSModule(node, startIndex); } } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 69faeda2db0..b3dc9ea9b8d 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -505,7 +505,7 @@ module ts { // Cannot specify module gen target when in es6 or above if (options.module && languageVersion >= ScriptTarget.ES6) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_compile_external_modules_into_amd_or_commonjs_when_targeting_es6_or_higher)); + diagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_compile_external_modules_into_amd_system_or_commonjs_when_targeting_es6_or_higher)); } // there has to be common source directory if user specified --outdir || --sourceRoot diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 34eb86440f4..b855294d83f 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1619,6 +1619,7 @@ module ts { None = 0, CommonJS = 1, AMD = 2, + System = 3, } export interface LineAndCharacter { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 0826e7748aa..b3917473543 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -189,6 +189,22 @@ module ts { return getSourceTextOfNodeFromSourceFile(getSourceFileOfNode(node), node); } + /* @internal */ + export function isSourceFileLevelDeclaration(node: Node): boolean { + let current = node; + while (current) { + if (current.kind === SyntaxKind.SourceFile) { + return true; + } + else if (isFunctionLike(current) || current.kind === SyntaxKind.ModuleBlock) { + return false; + } + else { + current = current.parent; + } + } + } + // Add an extra underscore to identifiers that start with two underscores to avoid issues with magic names like '__proto__' export function escapeIdentifier(identifier: string): string { return identifier.length >= 2 && identifier.charCodeAt(0) === CharacterCodes._ && identifier.charCodeAt(1) === CharacterCodes._ ? "_" + identifier : identifier; From 50496ccd978de5ce74b1e29d2b1afaddc94bbe18 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Fri, 10 Apr 2015 12:12:25 -0700 Subject: [PATCH 005/194] added system module kind to harness --- src/harness/harness.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 784d8312d69..10ee82a8441 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -959,6 +959,8 @@ module Harness { options.module = ts.ModuleKind.AMD; } else if (setting.value.toLowerCase() === 'commonjs') { options.module = ts.ModuleKind.CommonJS; + } else if (setting.value.toLowerCase() === 'system') { + options.module = ts.ModuleKind.System; } else if (setting.value.toLowerCase() === 'unspecified') { options.module = ts.ModuleKind.None; } else { From 83fcca81a8625de02c1823c36e779556824a2a43 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Fri, 10 Apr 2015 12:31:10 -0700 Subject: [PATCH 006/194] emit publish of exported values in variable declarations --- src/compiler/emitter.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 77f9c9a7f3b..721ae4e76bd 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2740,7 +2740,6 @@ var __param = this.__param || function(index, decorator) { return function (targ } else { renameNonTopLevelLetAndConst(node.name); - emitModuleMemberName(node); let initializer = node.initializer; if (!initializer && languageVersion < ScriptTarget.ES6) { @@ -2763,7 +2762,21 @@ var __param = this.__param || function(index, decorator) { return function (targ } } + let publishExportedValue = + currentFileIsEmittedAsSystemModule() && (getCombinedNodeFlags(node) & NodeFlags.Export) && isSourceFileLevelDeclaration(node); + + if (publishExportedValue) { + write(`${exportFunctionForFile}("`); + emitNodeWithoutSourceMap(node.name); + write(`", `); + } + + emitModuleMemberName(node); emitOptional(" = ", initializer); + + if (publishExportedValue) { + write(")") + } } } From 7102b1d76a4ad981ad4a03773ef75ae3e3935571 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Fri, 10 Apr 2015 20:29:20 -0700 Subject: [PATCH 007/194] emit publish of exported values in assignment expressions --- src/compiler/checker.ts | 13 +++++++++++++ src/compiler/emitter.ts | 21 +++++++++++++++++++++ src/compiler/types.ts | 1 + 3 files changed, 35 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index bee917a2cb6..9594339a266 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11803,6 +11803,18 @@ module ts { return !!resolveName(location, name, SymbolFlags.Value, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined); } + function getReferencedValueDeclaration(reference: Identifier): Declaration { + Debug.assert(!nodeIsSynthesized(reference)); + let symbol = + getNodeLinks(reference).resolvedSymbol || + resolveName(reference, reference.text, SymbolFlags.Value | SymbolFlags.Alias, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined); + + if (!symbol) { + return undefined; + } + return symbol.flags & SymbolFlags.Export ? symbol.exportSymbol.valueDeclaration : symbol.valueDeclaration + } + function getBlockScopedVariableId(n: Identifier): number { Debug.assert(!nodeIsSynthesized(n)); @@ -11861,6 +11873,7 @@ module ts { resolvesToSomeValue, collectLinkedAliases, getBlockScopedVariableId, + getReferencedValueDeclaration, serializeTypeOfNode, serializeParameterTypesOfNode, serializeReturnTypeOfNode, diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 721ae4e76bd..d3f3acc09da 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1930,12 +1930,33 @@ var __param = this.__param || function(index, decorator) { return function (targ emitDestructuring(node, node.parent.kind === SyntaxKind.ExpressionStatement); } else { + let emitPublishOfExportedValue = false; + + if (currentFileIsEmittedAsSystemModule() && + node.left.kind === SyntaxKind.Identifier && + node.operatorToken.kind >= SyntaxKind.FirstAssignment && + node.operatorToken.kind <= SyntaxKind.LastAssignment) { + + let referencedDecl = resolver.getReferencedValueDeclaration(node.left); + if (referencedDecl && (getCombinedNodeFlags(referencedDecl) & NodeFlags.Export) && isSourceFileLevelDeclaration(referencedDecl)) { + emitPublishOfExportedValue = true; + } + } + + if (emitPublishOfExportedValue) { + write(`${exportFunctionForFile}("`); + emitNodeWithoutSourceMap(node.left); + write(`", `); + } emit(node.left); let indentedBeforeOperator = indentIfOnDifferentLines(node, node.left, node.operatorToken, node.operatorToken.kind !== SyntaxKind.CommaToken ? " " : undefined); write(tokenToString(node.operatorToken.kind)); let indentedAfterOperator = indentIfOnDifferentLines(node, node.operatorToken, node.right, " "); emit(node.right); decreaseIndentIf(indentedBeforeOperator, indentedAfterOperator); + if (emitPublishOfExportedValue) { + write(")"); + } } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index b855294d83f..e28f55eb4f8 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1256,6 +1256,7 @@ module ts { getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; resolvesToSomeValue(location: Node, name: string): boolean; getBlockScopedVariableId(node: Identifier): number; + getReferencedValueDeclaration(reference: Identifier): Node; serializeTypeOfNode(node: Node, getGeneratedNameForNode: (Node: Node) => string): string | string[]; serializeParameterTypesOfNode(node: Node, getGeneratedNameForNode: (Node: Node) => string): (string | string[])[]; serializeReturnTypeOfNode(node: Node, getGeneratedNameForNode: (Node: Node) => string): string | string[]; From 7bced682103fa3cc3bc08abd9442d230291b4db3 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Sat, 11 Apr 2015 03:59:03 -0700 Subject: [PATCH 008/194] emit publish of exported values in prefix/postfix unary expressions --- src/compiler/emitter.ts | 46 ++++++++++++++++++++++++++++++++++++----- src/compiler/types.ts | 2 +- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index d3f3acc09da..0fe6ec3697f 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1893,7 +1893,23 @@ var __param = this.__param || function(index, decorator) { return function (targ emit(node.expression); } + function shouldEmitPublishOfExportedValue(node: PrefixUnaryExpression | PostfixUnaryExpression): boolean { + if (!currentFileIsEmittedAsSystemModule() || node.operand.kind !== SyntaxKind.Identifier) { + return false; + } + + return isExportedSourceLevelDeclaration(resolver.getReferencedValueDeclaration(node.operand)); + } + function emitPrefixUnaryExpression(node: PrefixUnaryExpression) { + const emitPublishOfExportedValue = shouldEmitPublishOfExportedValue(node); + + if (emitPublishOfExportedValue) { + write(`${exportFunctionForFile}("`); + emitNodeWithoutSourceMap(node.operand); + write(`", `); + } + write(tokenToString(node.operator)); // In some cases, we need to emit a space between the operator and the operand. One obvious case // is when the operator is an identifier, like delete or typeof. We also need to do this for plus @@ -1917,11 +1933,35 @@ var __param = this.__param || function(index, decorator) { return function (targ } } emit(node.operand); + + if (emitPublishOfExportedValue) { + write(")"); + } } function emitPostfixUnaryExpression(node: PostfixUnaryExpression) { + const emitPublishOfExportedValue = shouldEmitPublishOfExportedValue(node); + if (emitPublishOfExportedValue) { + write(`${exportFunctionForFile}("`); + emitNodeWithoutSourceMap(node.operand); + write(`", `); + } + emit(node.operand); write(tokenToString(node.operator)); + + if (emitPublishOfExportedValue) { + write("), "); + emitNodeWithoutSourceMap(node.operand); + write(node.operator === SyntaxKind.PlusPlusToken ? " - 1" : " + 1"); + } + } + + function isExportedSourceLevelDeclaration(decl: Declaration): boolean { + if (!decl) { + return false; + } + return (getCombinedNodeFlags(decl) & NodeFlags.Export) && isSourceFileLevelDeclaration(decl); } function emitBinaryExpression(node: BinaryExpression) { @@ -1936,11 +1976,7 @@ var __param = this.__param || function(index, decorator) { return function (targ node.left.kind === SyntaxKind.Identifier && node.operatorToken.kind >= SyntaxKind.FirstAssignment && node.operatorToken.kind <= SyntaxKind.LastAssignment) { - - let referencedDecl = resolver.getReferencedValueDeclaration(node.left); - if (referencedDecl && (getCombinedNodeFlags(referencedDecl) & NodeFlags.Export) && isSourceFileLevelDeclaration(referencedDecl)) { - emitPublishOfExportedValue = true; - } + emitPublishOfExportedValue = isExportedSourceLevelDeclaration(resolver.getReferencedValueDeclaration(node.left)); } if (emitPublishOfExportedValue) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index e28f55eb4f8..bd670309f6b 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1256,7 +1256,7 @@ module ts { getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; resolvesToSomeValue(location: Node, name: string): boolean; getBlockScopedVariableId(node: Identifier): number; - getReferencedValueDeclaration(reference: Identifier): Node; + getReferencedValueDeclaration(reference: Identifier): Declaration; serializeTypeOfNode(node: Node, getGeneratedNameForNode: (Node: Node) => string): string | string[]; serializeParameterTypesOfNode(node: Node, getGeneratedNameForNode: (Node: Node) => string): (string | string[])[]; serializeReturnTypeOfNode(node: Node, getGeneratedNameForNode: (Node: Node) => string): string | string[]; From 8c80792fe24be2df99ba5313f4b3665b05d4b046 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Sat, 11 Apr 2015 04:58:39 -0700 Subject: [PATCH 009/194] emit publish of exported values in destructuring --- src/compiler/emitter.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 0fe6ec3697f..fcac5c9c2df 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2588,14 +2588,35 @@ var __param = this.__param || function(index, decorator) { return function (targ } renameNonTopLevelLetAndConst(name); - if (name.parent && (name.parent.kind === SyntaxKind.VariableDeclaration || name.parent.kind === SyntaxKind.BindingElement)) { + + const isVariableDeclarationOrBindingElement = + name.parent && (name.parent.kind === SyntaxKind.VariableDeclaration || name.parent.kind === SyntaxKind.BindingElement); + + let emitPublishOfExportedValue = false; + if (currentFileIsEmittedAsSystemModule() && !nodeIsSynthesized(name)) { + let nodeToCheck = isVariableDeclarationOrBindingElement ? name.parent : resolver.getReferencedValueDeclaration(name); + emitPublishOfExportedValue = nodeToCheck && (getCombinedNodeFlags(nodeToCheck) & NodeFlags.Export) && isSourceFileLevelDeclaration(nodeToCheck); + } + + if (emitPublishOfExportedValue) { + write(`${exportFunctionForFile}("`); + emitNodeWithoutSourceMap(name); + write(`", `); + } + + if (isVariableDeclarationOrBindingElement) { emitModuleMemberName(name.parent); } else { emit(name); } + write(" = "); emit(value); + + if (emitPublishOfExportedValue) { + write(")"); + } } function ensureIdentifier(expr: Expression): Expression { From 442addecf570e5229a65179183dd3cd8178d9246 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Sat, 11 Apr 2015 06:14:19 -0700 Subject: [PATCH 010/194] hoist source level class declarations, fix error message --- src/compiler/checker.ts | 2 +- .../diagnosticInformationMap.generated.ts | 2 +- src/compiler/diagnosticMessages.json | 2 +- src/compiler/emitter.ts | 27 ++++++++++++++----- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 9594339a266..b839b2dbda6 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10623,7 +10623,7 @@ module ts { } else if (compilerOptions.module === ModuleKind.System) { // system modules does not support export assignment - grammarErrorOnNode(node, Diagnostics.Export_assignment_is_not_supported_with_module_flag_is_system); + grammarErrorOnNode(node, Diagnostics.Export_assignment_is_not_supported_when_module_flag_is_system); } } } diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index b18b59377b0..fd86522a9d3 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -169,7 +169,7 @@ module ts { Ambient_const_enums_are_not_allowed_when_the_separateCompilation_flag_is_provided: { code: 1209, category: DiagnosticCategory.Error, key: "Ambient const enums are not allowed when the '--separateCompilation' flag is provided." }, Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode: { code: 1210, category: DiagnosticCategory.Error, key: "Invalid use of '{0}'. Class definitions are automatically in strict mode." }, A_class_declaration_without_the_default_modifier_must_have_a_name: { code: 1211, category: DiagnosticCategory.Error, key: "A class declaration without the 'default' modifier must have a name" }, - Export_assignment_is_not_supported_with_module_flag_is_system: { code: 1212, category: DiagnosticCategory.Error, key: "Export assignment is not supported with '--module' flag is 'system'." }, + Export_assignment_is_not_supported_when_module_flag_is_system: { code: 1212, category: DiagnosticCategory.Error, key: "Export assignment is not supported when '--module' flag is 'system'." }, 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 cf7e60fa311..2ea5ac6f545 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -667,7 +667,7 @@ "category": "Error", "code": 1211 }, - "Export assignment is not supported with '--module' flag is 'system'.": { + "Export assignment is not supported when '--module' flag is 'system'.": { "category": "Error", "code": 1212 }, diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index fcac5c9c2df..f2e8d0160a4 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3818,7 +3818,9 @@ var __param = this.__param || function(index, decorator) { return function (targ function emitClassLikeDeclarationBelowES6(node: ClassLikeDeclaration) { if (node.kind === SyntaxKind.ClassDeclaration) { - write("var "); + if (!currentFileIsEmittedAsSystemModule() || !isSourceFileLevelDeclaration(node)) { + write("var "); + } emitDeclarationName(node); write(" = "); } @@ -4827,20 +4829,25 @@ var __param = this.__param || function(index, decorator) { return function (targ } function hoistTopLevelVariableAndFunctionDeclarations(node: SourceFile): void { - let hoistedLocals: Identifier[]; + let hoistedVars: (Identifier | ClassDeclaration)[]; let hoistedFunctionDeclarations: FunctionDeclaration[]; visit(node); - if (hoistedLocals) { + if (hoistedVars) { writeLine(); write("var "); - for (let i = 0; i < hoistedLocals.length; ++i) { - let local = hoistedLocals[i]; + for (let i = 0; i < hoistedVars.length; ++i) { + let local = hoistedVars[i]; if (i !== 0) { write(", "); } - emit(local); + if (local.kind === SyntaxKind.ClassDeclaration) { + emitDeclarationName(local); + } + else { + emit(local); + } } write(";") } @@ -4858,11 +4865,17 @@ var __param = this.__param || function(index, decorator) { return function (targ return; } + if (node.kind === SyntaxKind.ClassDeclaration) { + // TODO: rename block scoped classes + (hoistedVars || (hoistedVars = [])).push(node); + return; + } + if (node.kind === SyntaxKind.VariableDeclaration || node.kind === SyntaxKind.BindingElement) { let name = (node).name; if (name.kind === SyntaxKind.Identifier) { renameNonTopLevelLetAndConst(name); - (hoistedLocals || (hoistedLocals = [])).push(name); + (hoistedVars || (hoistedVars = [])).push(name); } else { forEachChild(name, visit); From a281cad4926a1201479f9b555accfa2c5a082fa3 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Sat, 11 Apr 2015 06:33:09 -0700 Subject: [PATCH 011/194] hoist source level module declarations --- src/compiler/emitter.ts | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index f2e8d0160a4..7ce201699bc 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4327,15 +4327,18 @@ var __param = this.__param || function(index, decorator) { return function (targ return emitOnlyPinnedOrTripleSlashComments(node); } - emitStart(node); - if (isES6ExportedDeclaration(node)) { - write("export "); + let hoistedInDeclarationScope = currentFileIsEmittedAsSystemModule() && isSourceFileLevelDeclaration(node) + if (!hoistedInDeclarationScope) { + emitStart(node); + if (isES6ExportedDeclaration(node)) { + write("export "); + } + write("var "); + emit(node.name); + write(";"); + emitEnd(node); + writeLine(); } - write("var "); - emit(node.name); - write(";"); - emitEnd(node); - writeLine(); emitStart(node); write("(function ("); emitStart(node.name); @@ -4378,6 +4381,14 @@ var __param = this.__param || function(index, decorator) { return function (targ write(" = {}));"); emitEnd(node); if (!isES6ExportedDeclaration(node) && node.name.kind === SyntaxKind.Identifier && node.parent === currentSourceFile) { + if (currentFileIsEmittedAsSystemModule() && node.flags & NodeFlags.Export) { + writeLine(); + write(`${exportFunctionForFile}("`); + emitDeclarationName(node); + write(`", `); + emitDeclarationName(node); + write(")"); + } emitExportMemberAssignments(node.name); } } @@ -4829,7 +4840,7 @@ var __param = this.__param || function(index, decorator) { return function (targ } function hoistTopLevelVariableAndFunctionDeclarations(node: SourceFile): void { - let hoistedVars: (Identifier | ClassDeclaration)[]; + let hoistedVars: (Identifier | ClassDeclaration | ModuleDeclaration)[]; let hoistedFunctionDeclarations: FunctionDeclaration[]; visit(node); @@ -4842,7 +4853,7 @@ var __param = this.__param || function(index, decorator) { return function (targ if (i !== 0) { write(", "); } - if (local.kind === SyntaxKind.ClassDeclaration) { + if (local.kind === SyntaxKind.ClassDeclaration || local.kind === SyntaxKind.ModuleDeclaration) { emitDeclarationName(local); } else { @@ -4871,6 +4882,11 @@ var __param = this.__param || function(index, decorator) { return function (targ return; } + if (node.kind === SyntaxKind.ModuleDeclaration && shouldEmitModuleDeclaration(node)) { + (hoistedVars || (hoistedVars = [])).push(node); + return; + } + if (node.kind === SyntaxKind.VariableDeclaration || node.kind === SyntaxKind.BindingElement) { let name = (node).name; if (name.kind === SyntaxKind.Identifier) { From e2ba13eb1732239dcd48dab94ca0d3c7446e53f4 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Sat, 11 Apr 2015 08:23:25 -0700 Subject: [PATCH 012/194] do not emit original variable statement if it was hoisted and all variable declarations are non-initialized --- src/compiler/emitter.ts | 70 +++++++++++++++++++++++++++++++---------- 1 file changed, 54 insertions(+), 16 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 7ce201699bc..746d755e0ac 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1893,7 +1893,7 @@ var __param = this.__param || function(index, decorator) { return function (targ emit(node.expression); } - function shouldEmitPublishOfExportedValue(node: PrefixUnaryExpression | PostfixUnaryExpression): boolean { + function shouldEmitPublishOfExportedValueForUnaryExpressions(node: PrefixUnaryExpression | PostfixUnaryExpression): boolean { if (!currentFileIsEmittedAsSystemModule() || node.operand.kind !== SyntaxKind.Identifier) { return false; } @@ -1902,7 +1902,7 @@ var __param = this.__param || function(index, decorator) { return function (targ } function emitPrefixUnaryExpression(node: PrefixUnaryExpression) { - const emitPublishOfExportedValue = shouldEmitPublishOfExportedValue(node); + const emitPublishOfExportedValue = shouldEmitPublishOfExportedValueForUnaryExpressions(node); if (emitPublishOfExportedValue) { write(`${exportFunctionForFile}("`); @@ -1940,7 +1940,7 @@ var __param = this.__param || function(index, decorator) { return function (targ } function emitPostfixUnaryExpression(node: PostfixUnaryExpression) { - const emitPublishOfExportedValue = shouldEmitPublishOfExportedValue(node); + const emitPublishOfExportedValue = shouldEmitPublishOfExportedValueForUnaryExpressions(node); if (emitPublishOfExportedValue) { write(`${exportFunctionForFile}("`); emitNodeWithoutSourceMap(node.operand); @@ -2118,10 +2118,10 @@ var __param = this.__param || function(index, decorator) { return function (targ emitEmbeddedStatement(node.statement); } - function emitStartOfVariableDeclarationList(decl: Node, startPos?: number): void { + function emitStartOfVariableDeclarationList(decl: Node, startPos?: number): boolean { if (currentFileIsEmittedAsSystemModule() && isSourceFileLevelDeclaration(decl)) { Debug.assert(compilerOptions.module === ModuleKind.System); - return; + return false; } let tokenKind = SyntaxKind.VarKeyword; if (decl && languageVersion >= ScriptTarget.ES6) { @@ -2140,13 +2140,38 @@ var __param = this.__param || function(index, decorator) { return function (targ else { switch (tokenKind) { case SyntaxKind.VarKeyword: - return write("var "); + write("var "); + break; case SyntaxKind.LetKeyword: - return write("let "); + write("let "); + break; case SyntaxKind.ConstKeyword: - return write("const "); + write("const "); + break; } } + + return true; + } + + function emitVariableDeclarationListSkippingUninitializedEntries(list: VariableDeclarationList): boolean { + let started = false; + for (let decl of list.declarations) { + if (!decl.initializer) { + continue; + } + + if (!started) { + started = true; + } + else { + write(", "); + } + + emit(decl); + } + + return started; } function emitForStatement(node: ForStatement) { @@ -2156,8 +2181,13 @@ var __param = this.__param || function(index, decorator) { return function (targ if (node.initializer && node.initializer.kind === SyntaxKind.VariableDeclarationList) { let variableDeclarationList = node.initializer; let declarations = variableDeclarationList.declarations; - emitStartOfVariableDeclarationList(declarations[0], endPos); - emitCommaList(declarations); + let startIsEmitted = emitStartOfVariableDeclarationList(declarations[0], endPos); + if (startIsEmitted) { + emitCommaList(declarations); + } + else { + emitVariableDeclarationListSkippingUninitializedEntries(variableDeclarationList); + } } else if (node.initializer) { emit(node.initializer); @@ -2938,16 +2968,25 @@ var __param = this.__param || function(index, decorator) { return function (targ } function emitVariableStatement(node: VariableStatement) { + let startIsEmitted = true; if (!(node.flags & NodeFlags.Export)) { - emitStartOfVariableDeclarationList(node.declarationList); + startIsEmitted = emitStartOfVariableDeclarationList(node.declarationList); } else if (isES6ExportedDeclaration(node)) { // Exported ES6 module member write("export "); - emitStartOfVariableDeclarationList(node.declarationList); + startIsEmitted = emitStartOfVariableDeclarationList(node.declarationList); + } + if (startIsEmitted) { + emitCommaList(node.declarationList.declarations); + write(";"); + } + else { + let atLeastOneItem = emitVariableDeclarationListSkippingUninitializedEntries(node.declarationList); + if (atLeastOneItem) { + write(";"); + } } - emitCommaList(node.declarationList.declarations); - write(";"); if (languageVersion < ScriptTarget.ES6 && node.parent === currentSourceFile) { forEach(node.declarationList.declarations, emitExportVariableAssignments); } @@ -4799,7 +4838,6 @@ var __param = this.__param || function(index, decorator) { return function (targ function writeLocalNamesForExternalImports(startWithComma: boolean): void { let started = startWithComma; for (let importNode of externalImports) { - if (started) { write(", "); } @@ -4854,7 +4892,7 @@ var __param = this.__param || function(index, decorator) { return function (targ write(", "); } if (local.kind === SyntaxKind.ClassDeclaration || local.kind === SyntaxKind.ModuleDeclaration) { - emitDeclarationName(local); + emitDeclarationName(local); } else { emit(local); From e622c8ec348a793acd8c3f30ab092e2aca33d237 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Sat, 11 Apr 2015 08:50:11 -0700 Subject: [PATCH 013/194] added tests --- .../constDeclarations-access5.errors.txt | 4 +- tests/baselines/reference/es6-amd.errors.txt | 4 +- .../reference/es6-declaration-amd.errors.txt | 4 +- .../reference/es6-sourcemap-amd.errors.txt | 4 +- ...tBindingFollowedWithNamedImport.errors.txt | 4 +- .../es6ImportNameSpaceImport.errors.txt | 4 +- .../reference/es6ImportNamedImport.errors.txt | 4 +- ...rtNamedImportInExportAssignment.errors.txt | 4 +- ...es6ModuleWithModuleGenTargetAmd.errors.txt | 4 +- ...duleWithModuleGenTargetCommonjs.errors.txt | 4 +- .../reference/systemModule1.errors.txt | 7 ++ tests/baselines/reference/systemModule1.js | 6 ++ .../reference/systemModule2.errors.txt | 9 ++ tests/baselines/reference/systemModule2.js | 15 +++ tests/baselines/reference/systemModule3.js | 69 ++++++++++++++ tests/baselines/reference/systemModule3.types | 19 ++++ tests/baselines/reference/systemModule4.js | 16 ++++ tests/baselines/reference/systemModule4.types | 8 ++ tests/baselines/reference/systemModule5.js | 15 +++ tests/baselines/reference/systemModule5.types | 5 + tests/baselines/reference/systemModule6.js | 26 +++++ tests/baselines/reference/systemModule6.types | 13 +++ tests/baselines/reference/systemModule7.js | 26 +++++ tests/baselines/reference/systemModule7.types | 17 ++++ tests/baselines/reference/systemModule8.js | 59 ++++++++++++ tests/baselines/reference/systemModule8.types | 94 +++++++++++++++++++ .../reference/systemModule9.errors.txt | 41 ++++++++ tests/baselines/reference/systemModule9.js | 60 ++++++++++++ tests/cases/compiler/systemModule1.ts | 4 + tests/cases/compiler/systemModule2.ts | 4 + tests/cases/compiler/systemModule3.ts | 17 ++++ tests/cases/compiler/systemModule4.ts | 4 + tests/cases/compiler/systemModule5.ts | 3 + tests/cases/compiler/systemModule6.ts | 6 ++ tests/cases/compiler/systemModule7.ts | 11 +++ tests/cases/compiler/systemModule8.ts | 25 +++++ tests/cases/compiler/systemModule9.ts | 22 +++++ 37 files changed, 621 insertions(+), 20 deletions(-) create mode 100644 tests/baselines/reference/systemModule1.errors.txt create mode 100644 tests/baselines/reference/systemModule1.js create mode 100644 tests/baselines/reference/systemModule2.errors.txt create mode 100644 tests/baselines/reference/systemModule2.js create mode 100644 tests/baselines/reference/systemModule3.js create mode 100644 tests/baselines/reference/systemModule3.types create mode 100644 tests/baselines/reference/systemModule4.js create mode 100644 tests/baselines/reference/systemModule4.types create mode 100644 tests/baselines/reference/systemModule5.js create mode 100644 tests/baselines/reference/systemModule5.types create mode 100644 tests/baselines/reference/systemModule6.js create mode 100644 tests/baselines/reference/systemModule6.types create mode 100644 tests/baselines/reference/systemModule7.js create mode 100644 tests/baselines/reference/systemModule7.types create mode 100644 tests/baselines/reference/systemModule8.js create mode 100644 tests/baselines/reference/systemModule8.types create mode 100644 tests/baselines/reference/systemModule9.errors.txt create mode 100644 tests/baselines/reference/systemModule9.js create mode 100644 tests/cases/compiler/systemModule1.ts create mode 100644 tests/cases/compiler/systemModule2.ts create mode 100644 tests/cases/compiler/systemModule3.ts create mode 100644 tests/cases/compiler/systemModule4.ts create mode 100644 tests/cases/compiler/systemModule5.ts create mode 100644 tests/cases/compiler/systemModule6.ts create mode 100644 tests/cases/compiler/systemModule7.ts create mode 100644 tests/cases/compiler/systemModule8.ts create mode 100644 tests/cases/compiler/systemModule9.ts diff --git a/tests/baselines/reference/constDeclarations-access5.errors.txt b/tests/baselines/reference/constDeclarations-access5.errors.txt index a098b0e72c6..bd72ef271aa 100644 --- a/tests/baselines/reference/constDeclarations-access5.errors.txt +++ b/tests/baselines/reference/constDeclarations-access5.errors.txt @@ -1,4 +1,4 @@ -error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +error TS1204: Cannot compile external modules into amd, system or commonjs when targeting es6 or higher. tests/cases/compiler/constDeclarations_access_2.ts(2,1): error TS1202: 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. @@ -20,7 +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 TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +!!! error TS1204: Cannot compile external modules into amd, system 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/es6-amd.errors.txt b/tests/baselines/reference/es6-amd.errors.txt index cb1ef4b1287..96586f4a924 100644 --- a/tests/baselines/reference/es6-amd.errors.txt +++ b/tests/baselines/reference/es6-amd.errors.txt @@ -1,7 +1,7 @@ -error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +error TS1204: Cannot compile external modules into amd, system or commonjs when targeting es6 or higher. -!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +!!! error TS1204: Cannot compile external modules into amd, system or commonjs when targeting es6 or higher. ==== tests/cases/compiler/es6-amd.ts (0 errors) ==== class A diff --git a/tests/baselines/reference/es6-declaration-amd.errors.txt b/tests/baselines/reference/es6-declaration-amd.errors.txt index 18319504dc9..97a7b14bf1b 100644 --- a/tests/baselines/reference/es6-declaration-amd.errors.txt +++ b/tests/baselines/reference/es6-declaration-amd.errors.txt @@ -1,7 +1,7 @@ -error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +error TS1204: Cannot compile external modules into amd, system or commonjs when targeting es6 or higher. -!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +!!! error TS1204: Cannot compile external modules into amd, system or commonjs when targeting es6 or higher. ==== tests/cases/compiler/es6-declaration-amd.ts (0 errors) ==== class A diff --git a/tests/baselines/reference/es6-sourcemap-amd.errors.txt b/tests/baselines/reference/es6-sourcemap-amd.errors.txt index 24a83f8ee12..3aaec19fd6c 100644 --- a/tests/baselines/reference/es6-sourcemap-amd.errors.txt +++ b/tests/baselines/reference/es6-sourcemap-amd.errors.txt @@ -1,7 +1,7 @@ -error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +error TS1204: Cannot compile external modules into amd, system or commonjs when targeting es6 or higher. -!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +!!! error TS1204: Cannot compile external modules into amd, system or commonjs when targeting es6 or higher. ==== tests/cases/compiler/es6-sourcemap-amd.ts (0 errors) ==== class A diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt index 34bb303a571..ae2d14a726d 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt @@ -1,7 +1,7 @@ -error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +error TS1204: Cannot compile external modules into amd, system or commonjs when targeting es6 or higher. -!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +!!! error TS1204: Cannot compile external modules into amd, system or commonjs when targeting es6 or higher. ==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0.ts (0 errors) ==== export var a = 10; diff --git a/tests/baselines/reference/es6ImportNameSpaceImport.errors.txt b/tests/baselines/reference/es6ImportNameSpaceImport.errors.txt index 635bb955c00..a0dc5977cdd 100644 --- a/tests/baselines/reference/es6ImportNameSpaceImport.errors.txt +++ b/tests/baselines/reference/es6ImportNameSpaceImport.errors.txt @@ -1,7 +1,7 @@ -error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +error TS1204: Cannot compile external modules into amd, system or commonjs when targeting es6 or higher. -!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +!!! error TS1204: Cannot compile external modules into amd, system or commonjs when targeting es6 or higher. ==== tests/cases/compiler/es6ImportNameSpaceImport_0.ts (0 errors) ==== export var a = 10; diff --git a/tests/baselines/reference/es6ImportNamedImport.errors.txt b/tests/baselines/reference/es6ImportNamedImport.errors.txt index 5723b5c20d4..256c37821ee 100644 --- a/tests/baselines/reference/es6ImportNamedImport.errors.txt +++ b/tests/baselines/reference/es6ImportNamedImport.errors.txt @@ -1,7 +1,7 @@ -error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +error TS1204: Cannot compile external modules into amd, system or commonjs when targeting es6 or higher. -!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +!!! error TS1204: Cannot compile external modules into amd, system or commonjs when targeting es6 or higher. ==== tests/cases/compiler/es6ImportNamedImport_0.ts (0 errors) ==== export var a = 10; diff --git a/tests/baselines/reference/es6ImportNamedImportInExportAssignment.errors.txt b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.errors.txt index 41d3f160938..edf136e4068 100644 --- a/tests/baselines/reference/es6ImportNamedImportInExportAssignment.errors.txt +++ b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.errors.txt @@ -1,8 +1,8 @@ -error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +error TS1204: Cannot compile external modules into amd, system or commonjs when targeting es6 or higher. tests/cases/compiler/es6ImportNamedImportInExportAssignment_1.ts(2,1): error TS1203: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. -!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +!!! error TS1204: Cannot compile external modules into amd, system or commonjs when targeting es6 or higher. ==== tests/cases/compiler/es6ImportNamedImportInExportAssignment_0.ts (0 errors) ==== export var a = 10; diff --git a/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.errors.txt b/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.errors.txt index bbe0d8b78b6..d664263e57e 100644 --- a/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.errors.txt +++ b/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.errors.txt @@ -1,7 +1,7 @@ -error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +error TS1204: Cannot compile external modules into amd, system or commonjs when targeting es6 or higher. -!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +!!! error TS1204: Cannot compile external modules into amd, system or commonjs when targeting es6 or higher. ==== tests/cases/compiler/es6ModuleWithModuleGenTargetAmd.ts (0 errors) ==== export class A { diff --git a/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.errors.txt b/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.errors.txt index 87f53cb7810..f8bff2323b2 100644 --- a/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.errors.txt +++ b/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.errors.txt @@ -1,7 +1,7 @@ -error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +error TS1204: Cannot compile external modules into amd, system or commonjs when targeting es6 or higher. -!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +!!! error TS1204: Cannot compile external modules into amd, system or commonjs when targeting es6 or higher. ==== tests/cases/compiler/es6ModuleWithModuleGenTargetCommonjs.ts (0 errors) ==== export class A { diff --git a/tests/baselines/reference/systemModule1.errors.txt b/tests/baselines/reference/systemModule1.errors.txt new file mode 100644 index 00000000000..d83b8d047c3 --- /dev/null +++ b/tests/baselines/reference/systemModule1.errors.txt @@ -0,0 +1,7 @@ +error TS1204: Cannot compile external modules into amd, system or commonjs when targeting es6 or higher. + + +!!! error TS1204: Cannot compile external modules into amd, system or commonjs when targeting es6 or higher. +==== tests/cases/compiler/systemModule1.ts (0 errors) ==== + + export var x = 1; \ No newline at end of file diff --git a/tests/baselines/reference/systemModule1.js b/tests/baselines/reference/systemModule1.js new file mode 100644 index 00000000000..9731106471c --- /dev/null +++ b/tests/baselines/reference/systemModule1.js @@ -0,0 +1,6 @@ +//// [systemModule1.ts] + +export var x = 1; + +//// [systemModule1.js] +export var x = 1; diff --git a/tests/baselines/reference/systemModule2.errors.txt b/tests/baselines/reference/systemModule2.errors.txt new file mode 100644 index 00000000000..0ce216b73d9 --- /dev/null +++ b/tests/baselines/reference/systemModule2.errors.txt @@ -0,0 +1,9 @@ +tests/cases/compiler/systemModule2.ts(3,1): error TS1212: Export assignment is not supported when '--module' flag is 'system'. + + +==== tests/cases/compiler/systemModule2.ts (1 errors) ==== + + var x = 1; + export = x; + ~~~~~~~~~~~ +!!! error TS1212: Export assignment is not supported when '--module' flag is 'system'. \ No newline at end of file diff --git a/tests/baselines/reference/systemModule2.js b/tests/baselines/reference/systemModule2.js new file mode 100644 index 00000000000..cc0a3cc2916 --- /dev/null +++ b/tests/baselines/reference/systemModule2.js @@ -0,0 +1,15 @@ +//// [systemModule2.ts] + +var x = 1; +export = x; + +//// [systemModule2.js] +System.register([], function(exports_1) { + var x; + return { + setters:[], + execute: function() { + x = 1; + } + } +}); diff --git a/tests/baselines/reference/systemModule3.js b/tests/baselines/reference/systemModule3.js new file mode 100644 index 00000000000..885e86e442a --- /dev/null +++ b/tests/baselines/reference/systemModule3.js @@ -0,0 +1,69 @@ +//// [tests/cases/compiler/systemModule3.ts] //// + +//// [file1.ts] + + +export default function() {} + +//// [file2.ts] + +export default function f() {} + +//// [file3.ts] + +export default class C {} + +//// [file4.ts] + +export default class {} + +//// [file1.js] +System.register([], function(exports_1) { + function default_1() { } + exports_1("default", default_1); + return { + setters:[], + execute: function() { + } + } +}); +//// [file2.js] +System.register([], function(exports_1) { + function f() { } + exports_1("default", f); + return { + setters:[], + execute: function() { + } + } +}); +//// [file3.js] +System.register([], function(exports_1) { + var C; + return { + setters:[], + execute: function() { + C = (function () { + function C() { + } + return C; + })(); + exports_1("default", C); + } + } +}); +//// [file4.js] +System.register([], function(exports_1) { + var default_1; + return { + setters:[], + execute: function() { + default_1 = (function () { + function default_1() { + } + return default_1; + })(); + exports_1("default", default_1); + } + } +}); diff --git a/tests/baselines/reference/systemModule3.types b/tests/baselines/reference/systemModule3.types new file mode 100644 index 00000000000..4448588b74c --- /dev/null +++ b/tests/baselines/reference/systemModule3.types @@ -0,0 +1,19 @@ +=== tests/cases/compiler/file1.ts === + +No type information for this code. +No type information for this code.export default function() {} +No type information for this code. +No type information for this code.=== tests/cases/compiler/file2.ts === + +export default function f() {} +>f : () => void + +=== tests/cases/compiler/file3.ts === + +export default class C {} +>C : C + +=== tests/cases/compiler/file4.ts === + +No type information for this code.export default class {} +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/systemModule4.js b/tests/baselines/reference/systemModule4.js new file mode 100644 index 00000000000..0b045b620ff --- /dev/null +++ b/tests/baselines/reference/systemModule4.js @@ -0,0 +1,16 @@ +//// [systemModule4.ts] + +export var x = 1; +export var y; + +//// [systemModule4.js] +System.register([], function(exports_1) { + var x, y; + return { + setters:[], + execute: function() { + exports_1("x", x = 1); + exports_1("y", y); + } + } +}); diff --git a/tests/baselines/reference/systemModule4.types b/tests/baselines/reference/systemModule4.types new file mode 100644 index 00000000000..17216d20e32 --- /dev/null +++ b/tests/baselines/reference/systemModule4.types @@ -0,0 +1,8 @@ +=== tests/cases/compiler/systemModule4.ts === + +export var x = 1; +>x : number + +export var y; +>y : any + diff --git a/tests/baselines/reference/systemModule5.js b/tests/baselines/reference/systemModule5.js new file mode 100644 index 00000000000..4d9aadb3566 --- /dev/null +++ b/tests/baselines/reference/systemModule5.js @@ -0,0 +1,15 @@ +//// [systemModule5.ts] + +export function foo() {} + + +//// [systemModule5.js] +System.register([], function(exports_1) { + function foo() { } + exports_1("foo", foo); + return { + setters:[], + execute: function() { + } + } +}); diff --git a/tests/baselines/reference/systemModule5.types b/tests/baselines/reference/systemModule5.types new file mode 100644 index 00000000000..0061f002801 --- /dev/null +++ b/tests/baselines/reference/systemModule5.types @@ -0,0 +1,5 @@ +=== tests/cases/compiler/systemModule5.ts === + +export function foo() {} +>foo : () => void + diff --git a/tests/baselines/reference/systemModule6.js b/tests/baselines/reference/systemModule6.js new file mode 100644 index 00000000000..d36535f6761 --- /dev/null +++ b/tests/baselines/reference/systemModule6.js @@ -0,0 +1,26 @@ +//// [systemModule6.ts] + +export class C {} +function foo() { + new C(); +} + + +//// [systemModule6.js] +System.register([], function(exports_1) { + var C; + function foo() { + new C(); + } + return { + setters:[], + execute: function() { + C = (function () { + function C() { + } + return C; + })(); + exports_1("C", C); + } + } +}); diff --git a/tests/baselines/reference/systemModule6.types b/tests/baselines/reference/systemModule6.types new file mode 100644 index 00000000000..cc8a97c066e --- /dev/null +++ b/tests/baselines/reference/systemModule6.types @@ -0,0 +1,13 @@ +=== tests/cases/compiler/systemModule6.ts === + +export class C {} +>C : C + +function foo() { +>foo : () => void + + new C(); +>new C() : C +>C : typeof C +} + diff --git a/tests/baselines/reference/systemModule7.js b/tests/baselines/reference/systemModule7.js new file mode 100644 index 00000000000..85dd42da87d --- /dev/null +++ b/tests/baselines/reference/systemModule7.js @@ -0,0 +1,26 @@ +//// [systemModule7.ts] + +// filename: instantiatedModule.ts +export module M { + var x = 1; +} + +// filename: nonInstantiatedModule.ts +export module M { + interface I {} +} + +//// [systemModule7.js] +System.register([], function(exports_1) { + var M; + return { + setters:[], + execute: function() { + // filename: instantiatedModule.ts + (function (M) { + var x = 1; + })(M = M || (M = {})); + exports_1("M", M) + } + } +}); diff --git a/tests/baselines/reference/systemModule7.types b/tests/baselines/reference/systemModule7.types new file mode 100644 index 00000000000..e1b6bd04613 --- /dev/null +++ b/tests/baselines/reference/systemModule7.types @@ -0,0 +1,17 @@ +=== tests/cases/compiler/systemModule7.ts === + +// filename: instantiatedModule.ts +export module M { +>M : typeof M + + var x = 1; +>x : number +} + +// filename: nonInstantiatedModule.ts +export module M { +>M : typeof M + + interface I {} +>I : I +} diff --git a/tests/baselines/reference/systemModule8.js b/tests/baselines/reference/systemModule8.js new file mode 100644 index 00000000000..45b25d8f98d --- /dev/null +++ b/tests/baselines/reference/systemModule8.js @@ -0,0 +1,59 @@ +//// [systemModule8.ts] + +export var x; +x = 1; +x++; +x--; +++x; +--x; +x += 1; +x -= 1; +x *= 1; +x /= 1; +x |= 1; +x &= 1; +for (x = 5;;x++) {} +for (x = 8;;x--) {} + +for (let x = 50;;) {} +function foo() { + x = 100; +} + +export let [y] = [1]; +export const {a: z0, b: {c: z1}} = {a: true, b: {c: "123"}}; +for ([x] of [[1]]) {} + +//// [systemModule8.js] +System.register([], function(exports_1) { + var x, x_1, y, z0, z1; + function foo() { + exports_1("x", x = 100); + } + return { + setters:[], + execute: function() { + exports_1("x", x); + exports_1("x", x = 1); + exports_1("x", x++), x - 1; + exports_1("x", x--), x + 1; + exports_1("x", ++x); + exports_1("x", --x); + exports_1("x", x += 1); + exports_1("x", x -= 1); + exports_1("x", x *= 1); + exports_1("x", x /= 1); + exports_1("x", x |= 1); + exports_1("x", x &= 1); + for (exports_1("x", x = 5);; exports_1("x", x++), x - 1) { } + for (exports_1("x", x = 8);; exports_1("x", x--), x + 1) { } + for (x_1 = 50;;) { } + exports_1("y", y = ([1])[0]); + _a = { a: true, b: { c: "123" } }, exports_1("z0", z0 = _a.a), exports_1("z1", z1 = _a.b.c); + for (var _i = 0, _b = [[1]]; _i < _b.length; _i++) { + exports_1("x", x = _b[_i][0]); + } + } + var _a; + } +}); diff --git a/tests/baselines/reference/systemModule8.types b/tests/baselines/reference/systemModule8.types new file mode 100644 index 00000000000..3bbc09b2721 --- /dev/null +++ b/tests/baselines/reference/systemModule8.types @@ -0,0 +1,94 @@ +=== tests/cases/compiler/systemModule8.ts === + +export var x; +>x : any + +x = 1; +>x = 1 : number +>x : any + +x++; +>x++ : number +>x : any + +x--; +>x-- : number +>x : any + +++x; +>++x : number +>x : any + +--x; +>--x : number +>x : any + +x += 1; +>x += 1 : any +>x : any + +x -= 1; +>x -= 1 : number +>x : any + +x *= 1; +>x *= 1 : number +>x : any + +x /= 1; +>x /= 1 : number +>x : any + +x |= 1; +>x |= 1 : number +>x : any + +x &= 1; +>x &= 1 : number +>x : any + +for (x = 5;;x++) {} +>x = 5 : number +>x : any +>x++ : number +>x : any + +for (x = 8;;x--) {} +>x = 8 : number +>x : any +>x-- : number +>x : any + +for (let x = 50;;) {} +>x : number + +function foo() { +>foo : () => void + + x = 100; +>x = 100 : number +>x : any +} + +export let [y] = [1]; +>y : number +>[1] : [number] + +export const {a: z0, b: {c: z1}} = {a: true, b: {c: "123"}}; +>a : unknown +>z0 : boolean +>b : unknown +>c : unknown +>z1 : string +>{a: true, b: {c: "123"}} : { a: boolean; b: { c: string; }; } +>a : boolean +>b : { c: string; } +>{c: "123"} : { c: string; } +>c : string + +for ([x] of [[1]]) {} +>[x] : any[] +>x : any +>[[1]] : number[][] +>[1] : number[] + diff --git a/tests/baselines/reference/systemModule9.errors.txt b/tests/baselines/reference/systemModule9.errors.txt new file mode 100644 index 00000000000..4a536d2a55b --- /dev/null +++ b/tests/baselines/reference/systemModule9.errors.txt @@ -0,0 +1,41 @@ +tests/cases/compiler/systemModule9.ts(2,21): error TS2307: Cannot find external module 'file1'. +tests/cases/compiler/systemModule9.ts(3,25): error TS2307: Cannot find external module 'file2'. +tests/cases/compiler/systemModule9.ts(4,15): error TS2307: Cannot find external module 'file3'. +tests/cases/compiler/systemModule9.ts(5,25): error TS2307: Cannot find external module 'file4'. +tests/cases/compiler/systemModule9.ts(6,22): error TS2307: Cannot find external module 'file5'. +tests/cases/compiler/systemModule9.ts(16,15): error TS2307: Cannot find external module 'file6'. + + +==== tests/cases/compiler/systemModule9.ts (6 errors) ==== + + import * as ns from 'file1'; + ~~~~~~~ +!!! error TS2307: Cannot find external module 'file1'. + import {a, b as c} from 'file2'; + ~~~~~~~ +!!! error TS2307: Cannot find external module 'file2'. + import d from 'file3' + ~~~~~~~ +!!! error TS2307: Cannot find external module 'file3'. + import e, * as ns2 from 'file4'; + ~~~~~~~ +!!! error TS2307: Cannot find external module 'file4'. + import ns3 = require('file5'); + ~~~~~~~ +!!! error TS2307: Cannot find external module 'file5'. + + ns.f(); + a(); + c(); + d(); + e(); + ns2.f(); + ns3.f(); + + export * from 'file6'; + ~~~~~~~ +!!! error TS2307: Cannot find external module 'file6'. + + var x, y = true; + export {x}; + export {y as z}; \ No newline at end of file diff --git a/tests/baselines/reference/systemModule9.js b/tests/baselines/reference/systemModule9.js new file mode 100644 index 00000000000..10654721726 --- /dev/null +++ b/tests/baselines/reference/systemModule9.js @@ -0,0 +1,60 @@ +//// [systemModule9.ts] + +import * as ns from 'file1'; +import {a, b as c} from 'file2'; +import d from 'file3' +import e, * as ns2 from 'file4'; +import ns3 = require('file5'); + +ns.f(); +a(); +c(); +d(); +e(); +ns2.f(); +ns3.f(); + +export * from 'file6'; + +var x, y = true; +export {x}; +export {y as z}; + +//// [systemModule9.js] +System.register(['file1', 'file2', 'file3', 'file4', 'file5', 'file6'], function(exports_1) { + var ns, file2_1, file3_1, file4_1, ns3; + var x, y; + return { + setters:[ + function (v_1) { + ns = v_1 + }, + function (v_1) { + file2_1 = v_1 + }, + function (v_1) { + file3_1 = v_1 + }, + function (v_1) { + file4_1 = v_1 + }, + function (v_1) { + ns3 = v_1 + }, + function (v_1) { + for (var n in v_1) exports_1(n, v_1[n]); + }], + execute: function() { + ns.f(); + file2_1.a(); + file2_1.b(); + file3_1.default(); + file4_1.default(); + ns2.f(); + ns3.f(); + y = true; + exports_1("x", x); + exports_1("z", y); + } + } +}); diff --git a/tests/cases/compiler/systemModule1.ts b/tests/cases/compiler/systemModule1.ts new file mode 100644 index 00000000000..cec8c07e7fc --- /dev/null +++ b/tests/cases/compiler/systemModule1.ts @@ -0,0 +1,4 @@ +// @target: es6 +// @module: system + +export var x = 1; \ No newline at end of file diff --git a/tests/cases/compiler/systemModule2.ts b/tests/cases/compiler/systemModule2.ts new file mode 100644 index 00000000000..13e965a657c --- /dev/null +++ b/tests/cases/compiler/systemModule2.ts @@ -0,0 +1,4 @@ +// @module: system + +var x = 1; +export = x; \ No newline at end of file diff --git a/tests/cases/compiler/systemModule3.ts b/tests/cases/compiler/systemModule3.ts new file mode 100644 index 00000000000..2c33e2ac131 --- /dev/null +++ b/tests/cases/compiler/systemModule3.ts @@ -0,0 +1,17 @@ +// @module: system + +// @filename: file1.ts + +export default function() {} + +// @filename: file2.ts + +export default function f() {} + +// @filename: file3.ts + +export default class C {} + +// @filename: file4.ts + +export default class {} \ No newline at end of file diff --git a/tests/cases/compiler/systemModule4.ts b/tests/cases/compiler/systemModule4.ts new file mode 100644 index 00000000000..2dc46ee68e5 --- /dev/null +++ b/tests/cases/compiler/systemModule4.ts @@ -0,0 +1,4 @@ +// @module: system + +export var x = 1; +export var y; \ No newline at end of file diff --git a/tests/cases/compiler/systemModule5.ts b/tests/cases/compiler/systemModule5.ts new file mode 100644 index 00000000000..c30eefa978a --- /dev/null +++ b/tests/cases/compiler/systemModule5.ts @@ -0,0 +1,3 @@ +// @module: system + +export function foo() {} diff --git a/tests/cases/compiler/systemModule6.ts b/tests/cases/compiler/systemModule6.ts new file mode 100644 index 00000000000..1d1801e37c7 --- /dev/null +++ b/tests/cases/compiler/systemModule6.ts @@ -0,0 +1,6 @@ +// @module: system + +export class C {} +function foo() { + new C(); +} diff --git a/tests/cases/compiler/systemModule7.ts b/tests/cases/compiler/systemModule7.ts new file mode 100644 index 00000000000..bb22822d0d1 --- /dev/null +++ b/tests/cases/compiler/systemModule7.ts @@ -0,0 +1,11 @@ +// @module: system + +// filename: instantiatedModule.ts +export module M { + var x = 1; +} + +// filename: nonInstantiatedModule.ts +export module M { + interface I {} +} \ No newline at end of file diff --git a/tests/cases/compiler/systemModule8.ts b/tests/cases/compiler/systemModule8.ts new file mode 100644 index 00000000000..2185b1c0500 --- /dev/null +++ b/tests/cases/compiler/systemModule8.ts @@ -0,0 +1,25 @@ +// @module: system + +export var x; +x = 1; +x++; +x--; +++x; +--x; +x += 1; +x -= 1; +x *= 1; +x /= 1; +x |= 1; +x &= 1; +for (x = 5;;x++) {} +for (x = 8;;x--) {} + +for (let x = 50;;) {} +function foo() { + x = 100; +} + +export let [y] = [1]; +export const {a: z0, b: {c: z1}} = {a: true, b: {c: "123"}}; +for ([x] of [[1]]) {} \ No newline at end of file diff --git a/tests/cases/compiler/systemModule9.ts b/tests/cases/compiler/systemModule9.ts new file mode 100644 index 00000000000..b11256a674d --- /dev/null +++ b/tests/cases/compiler/systemModule9.ts @@ -0,0 +1,22 @@ +// @module: system +// @separateCompilation: true + +import * as ns from 'file1'; +import {a, b as c} from 'file2'; +import d from 'file3' +import e, * as ns2 from 'file4'; +import ns3 = require('file5'); + +ns.f(); +a(); +c(); +d(); +e(); +ns2.f(); +ns3.f(); + +export * from 'file6'; + +var x, y = true; +export {x}; +export {y as z}; \ No newline at end of file From 5039b4becbb72e2c9693b898541f3e329d01e2c8 Mon Sep 17 00:00:00 2001 From: Yui T Date: Sun, 12 Apr 2015 16:03:16 -0700 Subject: [PATCH 014/194] Conformance test for 3.8.2.2 and 6.4 --- ...structuringParameterDeclaration.errors.txt | 37 ++++++++ .../destructuringParameterDeclaration.js | 58 ++++++++++++ ...tructuringParameterDeclaration1.errors.txt | 48 ++++++++++ .../destructuringParameterDeclaration1.js | 86 +++++++++++++++++ ...cturingParameterDeclaration1ES6.errors.txt | 48 ++++++++++ .../destructuringParameterDeclaration1ES6.js | 39 ++++++++ ...tructuringParameterDeclaration2.errors.txt | 56 +++++++++++ .../destructuringParameterDeclaration2.js | 65 +++++++++++++ ...cturingParameterDeclaration2ES6.errors.txt | 56 +++++++++++ .../destructuringParameterDeclaration2ES6.js | 42 +++++++++ .../destructuringParameterDeclaration3.js | 51 ++++++++++ .../destructuringParameterDeclaration3.types | 92 +++++++++++++++++++ .../destructuringParameterDeclaration3ES6.js | 45 +++++++++ ...estructuringParameterDeclaration3ES6.types | 92 +++++++++++++++++++ ...ucturingParameterDeclarationES6.errors.txt | 37 ++++++++ .../destructuringParameterDeclarationES6.js | 44 +++++++++ .../destructuringParameterDeclaration.ts | 19 ++++ .../destructuringParameterDeclaration1.ts | 21 +++++ .../destructuringParameterDeclaration1ES6.ts | 22 +++++ .../destructuringParameterDeclaration2.ts | 19 ++++ .../destructuringParameterDeclaration2ES6.ts | 20 ++++ .../destructuringParameterDeclaration3.ts | 23 +++++ .../destructuringParameterDeclaration3ES6.ts | 24 +++++ .../destructuringParameterDeclarationES6.ts | 20 ++++ 24 files changed, 1064 insertions(+) create mode 100644 tests/baselines/reference/destructuringParameterDeclaration.errors.txt create mode 100644 tests/baselines/reference/destructuringParameterDeclaration.js create mode 100644 tests/baselines/reference/destructuringParameterDeclaration1.errors.txt create mode 100644 tests/baselines/reference/destructuringParameterDeclaration1.js create mode 100644 tests/baselines/reference/destructuringParameterDeclaration1ES6.errors.txt create mode 100644 tests/baselines/reference/destructuringParameterDeclaration1ES6.js create mode 100644 tests/baselines/reference/destructuringParameterDeclaration2.errors.txt create mode 100644 tests/baselines/reference/destructuringParameterDeclaration2.js create mode 100644 tests/baselines/reference/destructuringParameterDeclaration2ES6.errors.txt create mode 100644 tests/baselines/reference/destructuringParameterDeclaration2ES6.js create mode 100644 tests/baselines/reference/destructuringParameterDeclaration3.js create mode 100644 tests/baselines/reference/destructuringParameterDeclaration3.types create mode 100644 tests/baselines/reference/destructuringParameterDeclaration3ES6.js create mode 100644 tests/baselines/reference/destructuringParameterDeclaration3ES6.types create mode 100644 tests/baselines/reference/destructuringParameterDeclarationES6.errors.txt create mode 100644 tests/baselines/reference/destructuringParameterDeclarationES6.js create mode 100644 tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES6.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringParameterDeclarationES6.ts diff --git a/tests/baselines/reference/destructuringParameterDeclaration.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration.errors.txt new file mode 100644 index 00000000000..643305a0167 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration.errors.txt @@ -0,0 +1,37 @@ +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration.ts(17,1): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration.ts(18,4): error TS2345: Argument of type '{}' is not assignable to parameter of type '{ z: number; }'. + Property 'z' is missing in type '{}'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration.ts(19,14): error TS2300: Duplicate identifier 'z'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration.ts(19,18): error TS2300: Duplicate identifier 'z'. + + +==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration.ts (4 errors) ==== + enum Foo { a } + function a({x, a}: { x: number, a: number }) { } + function a1({z: {x, y: {j}}}) { } + function a2({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } + function a3({z} = {z:10}) { } + function a4({z=10}) { } + function a6({b}: { b: number|string|boolean } = { b: "hello" }) { } + a2(); + a2({ z: { x: "hello" , y: { j: Foo.a } }}); + a3(); + a3({ z: Foo.a }); + a4({}); + a6({ b: 10 }); + a6({ b: true }); + + // error + a4(); + ~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + a3({}); + ~~ +!!! error TS2345: Argument of type '{}' is not assignable to parameter of type '{ z: number; }'. +!!! error TS2345: Property 'z' is missing in type '{}'. + function a5([z], z: number) { } + ~ +!!! error TS2300: Duplicate identifier 'z'. + ~ +!!! error TS2300: Duplicate identifier 'z'. + \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterDeclaration.js b/tests/baselines/reference/destructuringParameterDeclaration.js new file mode 100644 index 00000000000..da979430ff3 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration.js @@ -0,0 +1,58 @@ +//// [destructuringParameterDeclaration.ts] +enum Foo { a } +function a({x, a}: { x: number, a: number }) { } +function a1({z: {x, y: {j}}}) { } +function a2({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } +function a3({z} = {z:10}) { } +function a4({z=10}) { } +function a6({b}: { b: number|string|boolean } = { b: "hello" }) { } +a2(); +a2({ z: { x: "hello" , y: { j: Foo.a } }}); +a3(); +a3({ z: Foo.a }); +a4({}); +a6({ b: 10 }); +a6({ b: true }); + +// error +a4(); +a3({}); +function a5([z], z: number) { } + + +//// [destructuringParameterDeclaration.js] +var Foo; +(function (Foo) { + Foo[Foo["a"] = 0] = "a"; +})(Foo || (Foo = {})); +function a(_a) { + var x = _a.x, a = _a.a; +} +function a1(_a) { + var _b = _a.z, x = _b.x, j = _b.y.j; +} +function a2(_a) { + var _b = (_a === void 0 ? { z: { x: "hi", y: { j: 1 } } } : _a).z, x = _b.x, j = _b.y.j; +} +function a3(_a) { + var z = (_a === void 0 ? { z: 10 } : _a).z; +} +function a4(_a) { + var _b = _a.z, z = _b === void 0 ? 10 : _b; +} +function a6(_a) { + var b = (_a === void 0 ? { b: "hello" } : _a).b; +} +a2(); +a2({ z: { x: "hello", y: { j: Foo.a } } }); +a3(); +a3({ z: Foo.a }); +a4({}); +a6({ b: 10 }); +a6({ b: true }); +// error +a4(); +a3({}); +function a5(_a, z) { + var z = _a[0]; +} diff --git a/tests/baselines/reference/destructuringParameterDeclaration1.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration1.errors.txt new file mode 100644 index 00000000000..2651be05038 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration1.errors.txt @@ -0,0 +1,48 @@ +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(5,16): error TS1048: A rest parameter cannot have an initializer. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(11,13): error TS2370: A rest parameter must be of an array type. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(12,18): error TS1047: A rest parameter cannot be optional. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(13,17): error TS1048: A rest parameter cannot have an initializer. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(16,19): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string | number'. + Type 'boolean' is not assignable to type 'number'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(21,4): error TS2345: Argument of type 'string | boolean' is not assignable to parameter of type 'string | number'. + Type 'boolean' is not assignable to type 'string | number'. + Type 'boolean' is not assignable to type 'number'. + + +==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts (6 errors) ==== + type arrayString = Array + type someArray = Array | number[]; + type stringOrNumArray = Array; + + function a3(...x = [1,2,3]) { } + ~ +!!! error TS1048: A rest parameter cannot have an initializer. + function a4(...x: (number|string)[]) { } + function a5(...a) { } + function a6(...a: Array) { } + function a7(...a: arrayString) { } + function a8(...a: stringOrNumArray) { } + function a9(...a: someArray) { } + ~~~~~~~~~~~~~~~ +!!! error TS2370: A rest parameter must be of an array type. + function a10(...b?) { } + ~ +!!! error TS1047: A rest parameter cannot be optional. + function a11(...b = [1,2,3]) { } + ~ +!!! error TS1048: A rest parameter cannot have an initializer. + + + a4(1, 2, "hello", true); + ~~~~ +!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string | number'. +!!! error TS2345: Type 'boolean' is not assignable to type 'number'. + var array = [1, 2, 3]; + var array2 = [true, false, "hello"]; + a5([...array]); + a4(...array); + a4(...array2); + ~~~~~~~~~ +!!! error TS2345: Argument of type 'string | boolean' is not assignable to parameter of type 'string | number'. +!!! error TS2345: Type 'boolean' is not assignable to type 'string | number'. +!!! error TS2345: Type 'boolean' is not assignable to type 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterDeclaration1.js b/tests/baselines/reference/destructuringParameterDeclaration1.js new file mode 100644 index 00000000000..37967ddb441 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration1.js @@ -0,0 +1,86 @@ +//// [destructuringParameterDeclaration1.ts] +type arrayString = Array +type someArray = Array | number[]; +type stringOrNumArray = Array; + +function a3(...x = [1,2,3]) { } +function a4(...x: (number|string)[]) { } +function a5(...a) { } +function a6(...a: Array) { } +function a7(...a: arrayString) { } +function a8(...a: stringOrNumArray) { } +function a9(...a: someArray) { } +function a10(...b?) { } +function a11(...b = [1,2,3]) { } + + +a4(1, 2, "hello", true); +var array = [1, 2, 3]; +var array2 = [true, false, "hello"]; +a5([...array]); +a4(...array); +a4(...array2); + +//// [destructuringParameterDeclaration1.js] +function a3() { + if (x === void 0) { x = [1, 2, 3]; } + var x = []; + for (var _i = 0; _i < arguments.length; _i++) { + x[_i - 0] = arguments[_i]; + } +} +function a4() { + var x = []; + for (var _i = 0; _i < arguments.length; _i++) { + x[_i - 0] = arguments[_i]; + } +} +function a5() { + var a = []; + for (var _i = 0; _i < arguments.length; _i++) { + a[_i - 0] = arguments[_i]; + } +} +function a6() { + var a = []; + for (var _i = 0; _i < arguments.length; _i++) { + a[_i - 0] = arguments[_i]; + } +} +function a7() { + var a = []; + for (var _i = 0; _i < arguments.length; _i++) { + a[_i - 0] = arguments[_i]; + } +} +function a8() { + var a = []; + for (var _i = 0; _i < arguments.length; _i++) { + a[_i - 0] = arguments[_i]; + } +} +function a9() { + var a = []; + for (var _i = 0; _i < arguments.length; _i++) { + a[_i - 0] = arguments[_i]; + } +} +function a10() { + var b = []; + for (var _i = 0; _i < arguments.length; _i++) { + b[_i - 0] = arguments[_i]; + } +} +function a11() { + if (b === void 0) { b = [1, 2, 3]; } + var b = []; + for (var _i = 0; _i < arguments.length; _i++) { + b[_i - 0] = arguments[_i]; + } +} +a4(1, 2, "hello", true); +var array = [1, 2, 3]; +var array2 = [true, false, "hello"]; +a5(array); +a4.apply(void 0, array); +a4.apply(void 0, array2); diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES6.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration1ES6.errors.txt new file mode 100644 index 00000000000..786571c88a5 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration1ES6.errors.txt @@ -0,0 +1,48 @@ +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts(5,16): error TS1048: A rest parameter cannot have an initializer. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts(11,13): error TS2370: A rest parameter must be of an array type. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts(12,18): error TS1047: A rest parameter cannot be optional. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts(13,17): error TS1048: A rest parameter cannot have an initializer. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts(16,19): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string | number'. + Type 'boolean' is not assignable to type 'number'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts(21,4): error TS2345: Argument of type 'string | boolean' is not assignable to parameter of type 'string | number'. + Type 'boolean' is not assignable to type 'string | number'. + Type 'boolean' is not assignable to type 'number'. + + +==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts (6 errors) ==== + type arrayString = Array + type someArray = Array | number[]; + type stringOrNumArray = Array; + + function a3(...x = [1,2,3]) { } + ~ +!!! error TS1048: A rest parameter cannot have an initializer. + function a4(...x: (number|string)[]) { } + function a5(...a) { } + function a6(...a: Array) { } + function a7(...a: arrayString) { } + function a8(...a: stringOrNumArray) { } + function a9(...a: someArray) { } + ~~~~~~~~~~~~~~~ +!!! error TS2370: A rest parameter must be of an array type. + function a10(...b?) { } + ~ +!!! error TS1047: A rest parameter cannot be optional. + function a11(...b = [1,2,3]) { } + ~ +!!! error TS1048: A rest parameter cannot have an initializer. + + + a4(1, 2, "hello", true); + ~~~~ +!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string | number'. +!!! error TS2345: Type 'boolean' is not assignable to type 'number'. + var array = [1, 2, 3]; + var array2 = [true, false, "hello"]; + a5([...array]); + a4(...array); + a4(...array2); + ~~~~~~~~~ +!!! error TS2345: Argument of type 'string | boolean' is not assignable to parameter of type 'string | number'. +!!! error TS2345: Type 'boolean' is not assignable to type 'string | number'. +!!! error TS2345: Type 'boolean' is not assignable to type 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES6.js b/tests/baselines/reference/destructuringParameterDeclaration1ES6.js new file mode 100644 index 00000000000..779f5495f56 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration1ES6.js @@ -0,0 +1,39 @@ +//// [destructuringParameterDeclaration1ES6.ts] +type arrayString = Array +type someArray = Array | number[]; +type stringOrNumArray = Array; + +function a3(...x = [1,2,3]) { } +function a4(...x: (number|string)[]) { } +function a5(...a) { } +function a6(...a: Array) { } +function a7(...a: arrayString) { } +function a8(...a: stringOrNumArray) { } +function a9(...a: someArray) { } +function a10(...b?) { } +function a11(...b = [1,2,3]) { } + + +a4(1, 2, "hello", true); +var array = [1, 2, 3]; +var array2 = [true, false, "hello"]; +a5([...array]); +a4(...array); +a4(...array2); + +//// [destructuringParameterDeclaration1ES6.js] +function a3(...x = [1, 2, 3]) { } +function a4(...x) { } +function a5(...a) { } +function a6(...a) { } +function a7(...a) { } +function a8(...a) { } +function a9(...a) { } +function a10(...b) { } +function a11(...b = [1, 2, 3]) { } +a4(1, 2, "hello", true); +var array = [1, 2, 3]; +var array2 = [true, false, "hello"]; +a5([...array]); +a4(...array); +a4(...array2); diff --git a/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt new file mode 100644 index 00000000000..afe984cc031 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt @@ -0,0 +1,56 @@ +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(6,14): error TS1181: Array element destructuring pattern expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(6,19): error TS1005: '(' expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(6,21): error TS1109: Expression expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(6,24): error TS1005: '(' expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(6,26): error TS2304: Cannot find name 'public'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(6,32): error TS1005: ';' expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(6,33): error TS1128: Declaration or statement expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(7,16): error TS1003: Identifier expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(7,21): error TS1005: '(' expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(9,13): error TS2370: A rest parameter must be of an array type. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(12,24): error TS1005: ',' expected. + + +==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts (11 errors) ==== + "use strict" + function a({while}) { } + function a1({public}) { } + function a2({public: x}) { } + function a3({while: y}) { } + function a4([while, for, public]){ } + ~~~~~ +!!! error TS1181: Array element destructuring pattern expected. + ~ +!!! error TS1005: '(' expected. + ~~~ +!!! error TS1109: Expression expected. + ~ +!!! error TS1005: '(' expected. + ~~~~~~ +!!! error TS2304: Cannot find name 'public'. + ~ +!!! error TS1005: ';' expected. + ~ +!!! error TS1128: Declaration or statement expected. + function a5(...while) { } + ~~~~~ +!!! error TS1003: Identifier expected. + ~ +!!! error TS1005: '(' expected. + function a6(...public) { } + function a7(...a: string) { } + ~~~~~~~~~~~~ +!!! error TS2370: A rest parameter must be of an array type. + + class C { + constructor(public ...a) { } + ~~~ +!!! error TS1005: ',' expected. + } + + + a2({ public: 1 }); + a3({ while: 1 }); + a({ while: 1 }); + + \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterDeclaration2.js b/tests/baselines/reference/destructuringParameterDeclaration2.js new file mode 100644 index 00000000000..ba6d7548442 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration2.js @@ -0,0 +1,65 @@ +//// [destructuringParameterDeclaration2.ts] +"use strict" +function a({while}) { } +function a1({public}) { } +function a2({public: x}) { } +function a3({while: y}) { } +function a4([while, for, public]){ } +function a5(...while) { } +function a6(...public) { } +function a7(...a: string) { } + +class C { + constructor(public ...a) { } +} + + +a2({ public: 1 }); +a3({ while: 1 }); +a({ while: 1 }); + + + +//// [destructuringParameterDeclaration2.js] +"use strict"; +function a(_a) { + var while = _a.while; +} +function a1(_a) { + var public = _a.public; +} +function a2(_a) { + var x = _a.public; +} +function a3(_a) { + var y = _a.while; +} +while (, ) + for (, public; ; ) + ; +{ } +while () { } +function a6() { + var public = []; + for (var _i = 0; _i < arguments.length; _i++) { + public[_i - 0] = arguments[_i]; + } +} +function a7() { + var a = []; + for (var _i = 0; _i < arguments.length; _i++) { + a[_i - 0] = arguments[_i]; + } +} +var C = (function () { + function C(public) { + var a = []; + for (var _i = 1; _i < arguments.length; _i++) { + a[_i - 1] = arguments[_i]; + } + } + return C; +})(); +a2({ public: 1 }); +a3({ while: 1 }); +a({ while: 1 }); diff --git a/tests/baselines/reference/destructuringParameterDeclaration2ES6.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration2ES6.errors.txt new file mode 100644 index 00000000000..762a0e1dd8a --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration2ES6.errors.txt @@ -0,0 +1,56 @@ +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(6,14): error TS1181: Array element destructuring pattern expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(6,19): error TS1005: '(' expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(6,21): error TS1109: Expression expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(6,24): error TS1005: '(' expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(6,26): error TS2304: Cannot find name 'public'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(6,32): error TS1005: ';' expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(6,33): error TS1128: Declaration or statement expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(7,16): error TS1003: Identifier expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(7,21): error TS1005: '(' expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(9,13): error TS2370: A rest parameter must be of an array type. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(12,24): error TS1005: ',' expected. + + +==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts (11 errors) ==== + "use strict" + function a({while}) { } + function a1({public}) { } + function a2({public: x}) { } + function a3({while: y}) { } + function a4([while, for, public]){ } + ~~~~~ +!!! error TS1181: Array element destructuring pattern expected. + ~ +!!! error TS1005: '(' expected. + ~~~ +!!! error TS1109: Expression expected. + ~ +!!! error TS1005: '(' expected. + ~~~~~~ +!!! error TS2304: Cannot find name 'public'. + ~ +!!! error TS1005: ';' expected. + ~ +!!! error TS1128: Declaration or statement expected. + function a5(...while) { } + ~~~~~ +!!! error TS1003: Identifier expected. + ~ +!!! error TS1005: '(' expected. + function a6(...public) { } + function a7(...a: string) { } + ~~~~~~~~~~~~ +!!! error TS2370: A rest parameter must be of an array type. + + class C { + constructor(public ...a) { } + ~~~ +!!! error TS1005: ',' expected. + } + + + a2({ public: 1 }); + a3({ while: 1 }); + a({ while: 1 }); + + \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterDeclaration2ES6.js b/tests/baselines/reference/destructuringParameterDeclaration2ES6.js new file mode 100644 index 00000000000..6e86aa2c001 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration2ES6.js @@ -0,0 +1,42 @@ +//// [destructuringParameterDeclaration2ES6.ts] +"use strict" +function a({while}) { } +function a1({public}) { } +function a2({public: x}) { } +function a3({while: y}) { } +function a4([while, for, public]){ } +function a5(...while) { } +function a6(...public) { } +function a7(...a: string) { } + +class C { + constructor(public ...a) { } +} + + +a2({ public: 1 }); +a3({ while: 1 }); +a({ while: 1 }); + + + +//// [destructuringParameterDeclaration2ES6.js] +"use strict"; +function a({ while }) { } +function a1({ public }) { } +function a2({ public: x }) { } +function a3({ while: y }) { } +while (, ) + for (, public; ; ) + ; +{ } +while () { } +function a6(...public) { } +function a7(...a) { } +class C { + constructor(public, ...a) { + } +} +a2({ public: 1 }); +a3({ while: 1 }); +a({ while: 1 }); diff --git a/tests/baselines/reference/destructuringParameterDeclaration3.js b/tests/baselines/reference/destructuringParameterDeclaration3.js new file mode 100644 index 00000000000..82d1404881c --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration3.js @@ -0,0 +1,51 @@ +//// [destructuringParameterDeclaration3.ts] +function a([x, [y, z], [[j]]]) { + return [x, y, z, j]; +} + +function a1([...x]) { + return [x]; +} + +function a2({public} = { "public": "1" }) { + return public; +} + +function a3({x: { y, z}, j: {k: {a}} }) { + return [y, z, a]; +} + +function a4({x: { y, z}, j: {k: {a}} } = { x: { y: 1, z: 1 }, j: { k: { a: "hello" } } }): (number| string) [] { + return [y, z, a]; +} + +function a5({x: { y, z}, j: {k: {a}} }): (number| string) [] { + return [y, z, a]; +} + + +//// [destructuringParameterDeclaration3.js] +function a(_a) { + var x = _a[0], _b = _a[1], y = _b[0], z = _b[1], j = _a[2][0][0]; + return [x, y, z, j]; +} +function a1(_a) { + var x = _a.slice(0); + return [x]; +} +function a2(_a) { + var public = (_a === void 0 ? { "public": "1" } : _a).public; + return public; +} +function a3(_a) { + var _b = _a.x, y = _b.y, z = _b.z, a = _a.j.k.a; + return [y, z, a]; +} +function a4(_a) { + var _b = _a === void 0 ? { x: { y: 1, z: 1 }, j: { k: { a: "hello" } } } : _a, _c = _b.x, y = _c.y, z = _c.z, a = _b.j.k.a; + return [y, z, a]; +} +function a5(_a) { + var _b = _a.x, y = _b.y, z = _b.z, a = _a.j.k.a; + return [y, z, a]; +} diff --git a/tests/baselines/reference/destructuringParameterDeclaration3.types b/tests/baselines/reference/destructuringParameterDeclaration3.types new file mode 100644 index 00000000000..41835d9e456 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration3.types @@ -0,0 +1,92 @@ +=== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts === +function a([x, [y, z], [[j]]]) { +>a : ([x, [y, z], [[j]]]: [any, [any, any], [[any]]]) => any[] +>x : any +>y : any +>z : any +>j : any + + return [x, y, z, j]; +>[x, y, z, j] : any[] +>x : any +>y : any +>z : any +>j : any +} + +function a1([...x]) { +>a1 : ([...x]: any[]) => any[][] +>x : any[] + + return [x]; +>[x] : any[][] +>x : any[] +} + +function a2({public} = { "public": "1" }) { +>a2 : ({public}?: { "public": string; }) => string +>public : string +>{ "public": "1" } : { "public": string; } + + return public; +>public : string +} + +function a3({x: { y, z}, j: {k: {a}} }) { +>a3 : ({x: { y, z}, j: {k: {a}} }: { x: { y: any; z: any; }; j: { k: { a: any; }; }; }) => any[] +>x : unknown +>y : any +>z : any +>j : unknown +>k : unknown +>a : any + + return [y, z, a]; +>[y, z, a] : any[] +>y : any +>z : any +>a : any +} + +function a4({x: { y, z}, j: {k: {a}} } = { x: { y: 1, z: 1 }, j: { k: { a: "hello" } } }): (number| string) [] { +>a4 : ({x: { y, z}, j: {k: {a}} }?: { x: { y: number; z: number; }; j: { k: { a: string; }; }; }) => (string | number)[] +>x : unknown +>y : number +>z : number +>j : unknown +>k : unknown +>a : string +>{ x: { y: 1, z: 1 }, j: { k: { a: "hello" } } } : { x: { y: number; z: number; }; j: { k: { a: string; }; }; } +>x : { y: number; z: number; } +>{ y: 1, z: 1 } : { y: number; z: number; } +>y : number +>z : number +>j : { k: { a: string; }; } +>{ k: { a: "hello" } } : { k: { a: string; }; } +>k : { a: string; } +>{ a: "hello" } : { a: string; } +>a : string + + return [y, z, a]; +>[y, z, a] : (string | number)[] +>y : number +>z : number +>a : string +} + +function a5({x: { y, z}, j: {k: {a}} }): (number| string) [] { +>a5 : ({x: { y, z}, j: {k: {a}} }: { x: { y: any; z: any; }; j: { k: { a: any; }; }; }) => (string | number)[] +>x : unknown +>y : any +>z : any +>j : unknown +>k : unknown +>a : any + + return [y, z, a]; +>[y, z, a] : any[] +>y : any +>z : any +>a : any +} + diff --git a/tests/baselines/reference/destructuringParameterDeclaration3ES6.js b/tests/baselines/reference/destructuringParameterDeclaration3ES6.js new file mode 100644 index 00000000000..e129140f3f2 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration3ES6.js @@ -0,0 +1,45 @@ +//// [destructuringParameterDeclaration3ES6.ts] +function a([x, [y, z], [[j]]]) { + return [x, y, z, j]; +} + +function a1([...x]) { + return [x]; +} + +function a2({public} = { "public": "1" }) { + return public; +} + +function a3({x: { y, z}, j: {k: {a}} }) { + return [y, z, a]; +} + +function a4({x: { y, z}, j: {k: {a}} } = { x: { y: 1, z: 1 }, j: { k: { a: "hello" } } }): (number| string) [] { + return [y, z, a]; +} + +function a5({x: { y, z}, j: {k: {a}} }): (number| string) [] { + return [y, z, a]; +} + + +//// [destructuringParameterDeclaration3ES6.js] +function a([x, [y, z], [[j]]]) { + return [x, y, z, j]; +} +function a1([...x]) { + return [x]; +} +function a2({ public } = { "public": "1" }) { + return public; +} +function a3({ x: { y, z }, j: { k: { a } } }) { + return [y, z, a]; +} +function a4({ x: { y, z }, j: { k: { a } } } = { x: { y: 1, z: 1 }, j: { k: { a: "hello" } } }) { + return [y, z, a]; +} +function a5({ x: { y, z }, j: { k: { a } } }) { + return [y, z, a]; +} diff --git a/tests/baselines/reference/destructuringParameterDeclaration3ES6.types b/tests/baselines/reference/destructuringParameterDeclaration3ES6.types new file mode 100644 index 00000000000..01c67e1e547 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration3ES6.types @@ -0,0 +1,92 @@ +=== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES6.ts === +function a([x, [y, z], [[j]]]) { +>a : ([x, [y, z], [[j]]]: [any, [any, any], [[any]]]) => any[] +>x : any +>y : any +>z : any +>j : any + + return [x, y, z, j]; +>[x, y, z, j] : any[] +>x : any +>y : any +>z : any +>j : any +} + +function a1([...x]) { +>a1 : ([...x]: Iterable) => any[][] +>x : any[] + + return [x]; +>[x] : any[][] +>x : any[] +} + +function a2({public} = { "public": "1" }) { +>a2 : ({public}?: { "public": string; }) => string +>public : string +>{ "public": "1" } : { "public": string; } + + return public; +>public : string +} + +function a3({x: { y, z}, j: {k: {a}} }) { +>a3 : ({x: { y, z}, j: {k: {a}} }: { x: { y: any; z: any; }; j: { k: { a: any; }; }; }) => any[] +>x : unknown +>y : any +>z : any +>j : unknown +>k : unknown +>a : any + + return [y, z, a]; +>[y, z, a] : any[] +>y : any +>z : any +>a : any +} + +function a4({x: { y, z}, j: {k: {a}} } = { x: { y: 1, z: 1 }, j: { k: { a: "hello" } } }): (number| string) [] { +>a4 : ({x: { y, z}, j: {k: {a}} }?: { x: { y: number; z: number; }; j: { k: { a: string; }; }; }) => (string | number)[] +>x : unknown +>y : number +>z : number +>j : unknown +>k : unknown +>a : string +>{ x: { y: 1, z: 1 }, j: { k: { a: "hello" } } } : { x: { y: number; z: number; }; j: { k: { a: string; }; }; } +>x : { y: number; z: number; } +>{ y: 1, z: 1 } : { y: number; z: number; } +>y : number +>z : number +>j : { k: { a: string; }; } +>{ k: { a: "hello" } } : { k: { a: string; }; } +>k : { a: string; } +>{ a: "hello" } : { a: string; } +>a : string + + return [y, z, a]; +>[y, z, a] : (string | number)[] +>y : number +>z : number +>a : string +} + +function a5({x: { y, z}, j: {k: {a}} }): (number| string) [] { +>a5 : ({x: { y, z}, j: {k: {a}} }: { x: { y: any; z: any; }; j: { k: { a: any; }; }; }) => (string | number)[] +>x : unknown +>y : any +>z : any +>j : unknown +>k : unknown +>a : any + + return [y, z, a]; +>[y, z, a] : any[] +>y : any +>z : any +>a : any +} + diff --git a/tests/baselines/reference/destructuringParameterDeclarationES6.errors.txt b/tests/baselines/reference/destructuringParameterDeclarationES6.errors.txt new file mode 100644 index 00000000000..21cd9f36c0f --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclarationES6.errors.txt @@ -0,0 +1,37 @@ +tests/cases/conformance/es6/destructuring/destructuringParameterDeclarationES6.ts(17,1): error TS2346: Supplied parameters do not match any signature of call target. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclarationES6.ts(18,4): error TS2345: Argument of type '{}' is not assignable to parameter of type '{ z: number; }'. + Property 'z' is missing in type '{}'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclarationES6.ts(19,14): error TS2300: Duplicate identifier 'z'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclarationES6.ts(19,18): error TS2300: Duplicate identifier 'z'. + + +==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclarationES6.ts (4 errors) ==== + enum Foo { a } + function a({x, a}: { x: number, a: number }) { } + function a1({z: {x, y: {j}}}) { } + function a2({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } + function a3({z} = {z:10}) { } + function a4({z=10}) { } + function a6({b}: { b: number|string|boolean } = { b: "hello" }) { } + a2(); + a2({ z: { x: "hello" , y: { j: Foo.a } }}); + a3(); + a3({ z: Foo.a }); + a4({}); + a6({ b: 10 }); + a6({ b: true }); + + // error + a4(); + ~~~~ +!!! error TS2346: Supplied parameters do not match any signature of call target. + a3({}); + ~~ +!!! error TS2345: Argument of type '{}' is not assignable to parameter of type '{ z: number; }'. +!!! error TS2345: Property 'z' is missing in type '{}'. + function a5([z], z: number) { } + ~ +!!! error TS2300: Duplicate identifier 'z'. + ~ +!!! error TS2300: Duplicate identifier 'z'. + \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterDeclarationES6.js b/tests/baselines/reference/destructuringParameterDeclarationES6.js new file mode 100644 index 00000000000..7a4c929003d --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclarationES6.js @@ -0,0 +1,44 @@ +//// [destructuringParameterDeclarationES6.ts] +enum Foo { a } +function a({x, a}: { x: number, a: number }) { } +function a1({z: {x, y: {j}}}) { } +function a2({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } +function a3({z} = {z:10}) { } +function a4({z=10}) { } +function a6({b}: { b: number|string|boolean } = { b: "hello" }) { } +a2(); +a2({ z: { x: "hello" , y: { j: Foo.a } }}); +a3(); +a3({ z: Foo.a }); +a4({}); +a6({ b: 10 }); +a6({ b: true }); + +// error +a4(); +a3({}); +function a5([z], z: number) { } + + +//// [destructuringParameterDeclarationES6.js] +var Foo; +(function (Foo) { + Foo[Foo["a"] = 0] = "a"; +})(Foo || (Foo = {})); +function a({ x, a }) { } +function a1({ z: { x, y: { j } } }) { } +function a2({ z: { x, y: { j } } } = { z: { x: "hi", y: { j: 1 } } }) { } +function a3({ z } = { z: 10 }) { } +function a4({ z = 10 }) { } +function a6({ b } = { b: "hello" }) { } +a2(); +a2({ z: { x: "hello", y: { j: Foo.a } } }); +a3(); +a3({ z: Foo.a }); +a4({}); +a6({ b: 10 }); +a6({ b: true }); +// error +a4(); +a3({}); +function a5([z], z) { } diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration.ts new file mode 100644 index 00000000000..c840dba2d2b --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration.ts @@ -0,0 +1,19 @@ +enum Foo { a } +function a({x, a}: { x: number, a: number }) { } +function a1({z: {x, y: {j}}}) { } +function a2({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } +function a3({z} = {z:10}) { } +function a4({z=10}) { } +function a6({b}: { b: number|string|boolean } = { b: "hello" }) { } +a2(); +a2({ z: { x: "hello" , y: { j: Foo.a } }}); +a3(); +a3({ z: Foo.a }); +a4({}); +a6({ b: 10 }); +a6({ b: true }); + +// error +a4(); +a3({}); +function a5([z], z: number) { } diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts new file mode 100644 index 00000000000..6e9579926dd --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts @@ -0,0 +1,21 @@ +type arrayString = Array +type someArray = Array | number[]; +type stringOrNumArray = Array; + +function a3(...x = [1,2,3]) { } +function a4(...x: (number|string)[]) { } +function a5(...a) { } +function a6(...a: Array) { } +function a7(...a: arrayString) { } +function a8(...a: stringOrNumArray) { } +function a9(...a: someArray) { } +function a10(...b?) { } +function a11(...b = [1,2,3]) { } + + +a4(1, 2, "hello", true); +var array = [1, 2, 3]; +var array2 = [true, false, "hello"]; +a5([...array]); +a4(...array); +a4(...array2); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts new file mode 100644 index 00000000000..1441226e061 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts @@ -0,0 +1,22 @@ +// @target: es6 +type arrayString = Array +type someArray = Array | number[]; +type stringOrNumArray = Array; + +function a3(...x = [1,2,3]) { } +function a4(...x: (number|string)[]) { } +function a5(...a) { } +function a6(...a: Array) { } +function a7(...a: arrayString) { } +function a8(...a: stringOrNumArray) { } +function a9(...a: someArray) { } +function a10(...b?) { } +function a11(...b = [1,2,3]) { } + + +a4(1, 2, "hello", true); +var array = [1, 2, 3]; +var array2 = [true, false, "hello"]; +a5([...array]); +a4(...array); +a4(...array2); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts new file mode 100644 index 00000000000..59763c95902 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts @@ -0,0 +1,19 @@ +"use strict" +function a({while}) { } +function a1({public}) { } +function a2({public: x}) { } +function a3({while: y}) { } +function a4([while, for, public]){ } +function a5(...while) { } +function a6(...public) { } +function a7(...a: string) { } + +class C { + constructor(public ...a) { } +} + + +a2({ public: 1 }); +a3({ while: 1 }); +a({ while: 1 }); + diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts new file mode 100644 index 00000000000..e50a455d824 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts @@ -0,0 +1,20 @@ +//@target: es6 +"use strict" +function a({while}) { } +function a1({public}) { } +function a2({public: x}) { } +function a3({while: y}) { } +function a4([while, for, public]){ } +function a5(...while) { } +function a6(...public) { } +function a7(...a: string) { } + +class C { + constructor(public ...a) { } +} + + +a2({ public: 1 }); +a3({ while: 1 }); +a({ while: 1 }); + diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts new file mode 100644 index 00000000000..96fc87c6c86 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts @@ -0,0 +1,23 @@ +function a([x, [y, z], [[j]]]) { + return [x, y, z, j]; +} + +function a1([...x]) { + return [x]; +} + +function a2({public} = { "public": "1" }) { + return public; +} + +function a3({x: { y, z}, j: {k: {a}} }) { + return [y, z, a]; +} + +function a4({x: { y, z}, j: {k: {a}} } = { x: { y: 1, z: 1 }, j: { k: { a: "hello" } } }): (number| string) [] { + return [y, z, a]; +} + +function a5({x: { y, z}, j: {k: {a}} }): (number| string) [] { + return [y, z, a]; +} diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES6.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES6.ts new file mode 100644 index 00000000000..7c50917ebe5 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES6.ts @@ -0,0 +1,24 @@ +// @target: es6 +function a([x, [y, z], [[j]]]) { + return [x, y, z, j]; +} + +function a1([...x]) { + return [x]; +} + +function a2({public} = { "public": "1" }) { + return public; +} + +function a3({x: { y, z}, j: {k: {a}} }) { + return [y, z, a]; +} + +function a4({x: { y, z}, j: {k: {a}} } = { x: { y: 1, z: 1 }, j: { k: { a: "hello" } } }): (number| string) [] { + return [y, z, a]; +} + +function a5({x: { y, z}, j: {k: {a}} }): (number| string) [] { + return [y, z, a]; +} diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclarationES6.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclarationES6.ts new file mode 100644 index 00000000000..0d359421851 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclarationES6.ts @@ -0,0 +1,20 @@ +//@target: es6 +enum Foo { a } +function a({x, a}: { x: number, a: number }) { } +function a1({z: {x, y: {j}}}) { } +function a2({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } +function a3({z} = {z:10}) { } +function a4({z=10}) { } +function a6({b}: { b: number|string|boolean } = { b: "hello" }) { } +a2(); +a2({ z: { x: "hello" , y: { j: Foo.a } }}); +a3(); +a3({ z: Foo.a }); +a4({}); +a6({ b: 10 }); +a6({ b: true }); + +// error +a4(); +a3({}); +function a5([z], z: number) { } From 3e7d6a06f2211c26b91d3612333cfe2d42d4c8a5 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 13 Apr 2015 01:32:16 -0700 Subject: [PATCH 015/194] code cleanup --- src/compiler/checker.ts | 5 +-- src/compiler/emitter.ts | 87 +++++++++++++++++++++------------------ src/compiler/utilities.ts | 16 ------- 3 files changed, 49 insertions(+), 59 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7376b8195f4..a0dfe0c9500 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11792,10 +11792,7 @@ module ts { getNodeLinks(reference).resolvedSymbol || resolveName(reference, reference.text, SymbolFlags.Value | SymbolFlags.Alias, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined); - if (!symbol) { - return undefined; - } - return symbol.flags & SymbolFlags.Export ? symbol.exportSymbol.valueDeclaration : symbol.valueDeclaration + return symbol && getExportSymbolOfValueSymbolIfExported(symbol).valueDeclaration; } function getBlockScopedVariableId(n: Identifier): number { diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 29880a1d700..6a25e714893 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1909,18 +1909,23 @@ var __param = this.__param || function(index, decorator) { return function (targ emit(node.expression); } - function shouldEmitPublishOfExportedValueForUnaryExpressions(node: PrefixUnaryExpression | PostfixUnaryExpression): boolean { - if (!currentFileIsEmittedAsSystemModule() || node.operand.kind !== SyntaxKind.Identifier) { + function isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node: Node): boolean { + if (!isCurrentFileSystemExternalModule() || node.kind !== SyntaxKind.Identifier || nodeIsSynthesized(node)) { return false; } - return isExportedSourceLevelDeclaration(resolver.getReferencedValueDeclaration(node.operand)); + const isVariableDeclarationOrBindingElement = + node.parent && (node.parent.kind === SyntaxKind.VariableDeclaration || node.parent.kind === SyntaxKind.BindingElement); + + const targetDeclaration = isVariableDeclarationOrBindingElement ? node.parent : resolver.getReferencedValueDeclaration(node); + + return isSourceFileLevelDeclarationInSystemExternalModule(targetDeclaration, /*isExported*/ true); } function emitPrefixUnaryExpression(node: PrefixUnaryExpression) { - const emitPublishOfExportedValue = shouldEmitPublishOfExportedValueForUnaryExpressions(node); + const exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.operand); - if (emitPublishOfExportedValue) { + if (exportChanged) { write(`${exportFunctionForFile}("`); emitNodeWithoutSourceMap(node.operand); write(`", `); @@ -1950,14 +1955,14 @@ var __param = this.__param || function(index, decorator) { return function (targ } emit(node.operand); - if (emitPublishOfExportedValue) { + if (exportChanged) { write(")"); } } function emitPostfixUnaryExpression(node: PostfixUnaryExpression) { - const emitPublishOfExportedValue = shouldEmitPublishOfExportedValueForUnaryExpressions(node); - if (emitPublishOfExportedValue) { + const exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.operand); + if (exportChanged) { write(`${exportFunctionForFile}("`); emitNodeWithoutSourceMap(node.operand); write(`", `); @@ -1966,18 +1971,30 @@ var __param = this.__param || function(index, decorator) { return function (targ emit(node.operand); write(tokenToString(node.operator)); - if (emitPublishOfExportedValue) { + if (exportChanged) { write("), "); emitNodeWithoutSourceMap(node.operand); write(node.operator === SyntaxKind.PlusPlusToken ? " - 1" : " + 1"); } } - function isExportedSourceLevelDeclaration(decl: Declaration): boolean { - if (!decl) { + function isSourceFileLevelDeclarationInSystemExternalModule(node: Node, isExported: boolean): boolean { + if (!node || languageVersion >= ScriptTarget.ES6 || !isCurrentFileSystemExternalModule()) { return false; } - return (getCombinedNodeFlags(decl) & NodeFlags.Export) && isSourceFileLevelDeclaration(decl); + + let current: Node = node; + while (current) { + if (current.kind === SyntaxKind.SourceFile) { + return !isExported || ((getCombinedNodeFlags(node) & NodeFlags.Export) !== 0) + } + else if (isFunctionLike(current) || current.kind === SyntaxKind.ModuleBlock) { + return false; + } + else { + current = current.parent; + } + } } function emitBinaryExpression(node: BinaryExpression) { @@ -1986,14 +2003,10 @@ var __param = this.__param || function(index, decorator) { return function (targ emitDestructuring(node, node.parent.kind === SyntaxKind.ExpressionStatement); } else { - let emitPublishOfExportedValue = false; - - if (currentFileIsEmittedAsSystemModule() && - node.left.kind === SyntaxKind.Identifier && - node.operatorToken.kind >= SyntaxKind.FirstAssignment && - node.operatorToken.kind <= SyntaxKind.LastAssignment) { - emitPublishOfExportedValue = isExportedSourceLevelDeclaration(resolver.getReferencedValueDeclaration(node.left)); - } + const emitPublishOfExportedValue = + node.operatorToken.kind <= SyntaxKind.LastAssignment && + node.operatorToken.kind <= SyntaxKind.LastAssignment && + isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.left); if (emitPublishOfExportedValue) { write(`${exportFunctionForFile}("`); @@ -2135,10 +2148,10 @@ var __param = this.__param || function(index, decorator) { return function (targ } function emitStartOfVariableDeclarationList(decl: Node, startPos?: number): boolean { - if (currentFileIsEmittedAsSystemModule() && isSourceFileLevelDeclaration(decl)) { - Debug.assert(compilerOptions.module === ModuleKind.System); + if (isSourceFileLevelDeclarationInSystemExternalModule(decl, /*isExported*/ false)) { return false; } + let tokenKind = SyntaxKind.VarKeyword; if (decl && languageVersion >= ScriptTarget.ES6) { if (isLet(decl)) { @@ -2606,6 +2619,7 @@ var __param = this.__param || function(index, decorator) { return function (targ value?: Expression, lowestNonSynthesizedAncestor?: Node) { let emitCount = 0; + // An exported declaration is actually emitted as an assignment (to a property on the module object), so // temporary variables in an exported declaration need to have real declarations elsewhere // Also temporary variables should be explicitly allocated for source level declarations when module target is system @@ -2613,7 +2627,7 @@ var __param = this.__param || function(index, decorator) { return function (targ let canDefineTempVariablesInplace = false; if (root.kind === SyntaxKind.VariableDeclaration) { let isExported = getCombinedNodeFlags(root) & NodeFlags.Export; - let isSourceLevelForSystemModuleKind = currentFileIsEmittedAsSystemModule() && isSourceFileLevelDeclaration(root); + let isSourceLevelForSystemModuleKind = isSourceFileLevelDeclarationInSystemExternalModule(root, /*isExported*/ false); canDefineTempVariablesInplace = !isExported && !isSourceLevelForSystemModuleKind; } else if (root.kind === SyntaxKind.Parameter) { @@ -2638,13 +2652,9 @@ var __param = this.__param || function(index, decorator) { return function (targ const isVariableDeclarationOrBindingElement = name.parent && (name.parent.kind === SyntaxKind.VariableDeclaration || name.parent.kind === SyntaxKind.BindingElement); - let emitPublishOfExportedValue = false; - if (currentFileIsEmittedAsSystemModule() && !nodeIsSynthesized(name)) { - let nodeToCheck = isVariableDeclarationOrBindingElement ? name.parent : resolver.getReferencedValueDeclaration(name); - emitPublishOfExportedValue = nodeToCheck && (getCombinedNodeFlags(nodeToCheck) & NodeFlags.Export) && isSourceFileLevelDeclaration(nodeToCheck); - } + let exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(name); - if (emitPublishOfExportedValue) { + if (exportChanged) { write(`${exportFunctionForFile}("`); emitNodeWithoutSourceMap(name); write(`", `); @@ -2660,7 +2670,7 @@ var __param = this.__param || function(index, decorator) { return function (targ write(" = "); emit(value); - if (emitPublishOfExportedValue) { + if (exportChanged) { write(")"); } } @@ -2886,10 +2896,9 @@ var __param = this.__param || function(index, decorator) { return function (targ } } - let publishExportedValue = - currentFileIsEmittedAsSystemModule() && (getCombinedNodeFlags(node) & NodeFlags.Export) && isSourceFileLevelDeclaration(node); + let exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.name); - if (publishExportedValue) { + if (exportChanged) { write(`${exportFunctionForFile}("`); emitNodeWithoutSourceMap(node.name); write(`", `); @@ -2898,7 +2907,7 @@ var __param = this.__param || function(index, decorator) { return function (targ emitModuleMemberName(node); emitOptional(" = ", initializer); - if (publishExportedValue) { + if (exportChanged) { write(")") } } @@ -3881,7 +3890,7 @@ var __param = this.__param || function(index, decorator) { return function (targ function emitClassLikeDeclarationBelowES6(node: ClassLikeDeclaration) { if (node.kind === SyntaxKind.ClassDeclaration) { - if (!currentFileIsEmittedAsSystemModule() || !isSourceFileLevelDeclaration(node)) { + if (!isSourceFileLevelDeclarationInSystemExternalModule(node, /*isExported*/ false)) { write("var "); } emitDeclarationName(node); @@ -4390,7 +4399,7 @@ var __param = this.__param || function(index, decorator) { return function (targ return emitOnlyPinnedOrTripleSlashComments(node); } - let hoistedInDeclarationScope = currentFileIsEmittedAsSystemModule() && isSourceFileLevelDeclaration(node) + let hoistedInDeclarationScope = isSourceFileLevelDeclarationInSystemExternalModule(node, /*isExported*/ false); if (!hoistedInDeclarationScope) { emitStart(node); if (isES6ExportedDeclaration(node)) { @@ -4444,7 +4453,7 @@ var __param = this.__param || function(index, decorator) { return function (targ write(" = {}));"); emitEnd(node); if (!isES6ExportedDeclaration(node) && node.name.kind === SyntaxKind.Identifier && node.parent === currentSourceFile) { - if (currentFileIsEmittedAsSystemModule() && node.flags & NodeFlags.Export) { + if (compilerOptions.module === ModuleKind.System && (node.flags & NodeFlags.Export)) { writeLine(); write(`${exportFunctionForFile}("`); emitDeclarationName(node); @@ -4972,8 +4981,8 @@ var __param = this.__param || function(index, decorator) { return function (targ } } - function currentFileIsEmittedAsSystemModule(): boolean { - return exportFunctionForFile !== undefined; + function isCurrentFileSystemExternalModule() { + return compilerOptions.module === ModuleKind.System && isExternalModule(currentSourceFile); } function emitSystemModuleBody(node: SourceFile, startIndex: number): void { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 25d01eb8102..b0c50fc7f66 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -190,22 +190,6 @@ module ts { return getSourceTextOfNodeFromSourceFile(getSourceFileOfNode(node), node); } - /* @internal */ - export function isSourceFileLevelDeclaration(node: Node): boolean { - let current = node; - while (current) { - if (current.kind === SyntaxKind.SourceFile) { - return true; - } - else if (isFunctionLike(current) || current.kind === SyntaxKind.ModuleBlock) { - return false; - } - else { - current = current.parent; - } - } - } - // Add an extra underscore to identifiers that start with two underscores to avoid issues with magic names like '__proto__' export function escapeIdentifier(identifier: string): string { return identifier.length >= 2 && identifier.charCodeAt(0) === CharacterCodes._ && identifier.charCodeAt(1) === CharacterCodes._ ? "_" + identifier : identifier; From 0c84acd8ef9eda7340bda436debfbc73b3fe77fd Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 13 Apr 2015 12:14:32 -0700 Subject: [PATCH 016/194] add missing closing paren in emitted code --- src/compiler/emitter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 6a25e714893..2d028f058f4 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -5038,7 +5038,7 @@ var __param = this.__param || function(index, decorator) { return function (targ emitNodeWithoutSourceMap(e.name); write(`", ${setterParameterName}["`); emitNodeWithoutSourceMap(e.propertyName || e.name); - write(`"];`); + write(`"]);`); } } else { From b29077a19baee97a8d86e2c7851953569652918e Mon Sep 17 00:00:00 2001 From: Yui T Date: Mon, 13 Apr 2015 12:57:50 -0700 Subject: [PATCH 017/194] Add destructuring parameter with generic --- ...tructuringParameterDeclaration4.errors.txt | 27 +++++++++ .../destructuringParameterDeclaration4.js | 58 +++++++++++++++++++ .../destructuringParameterDeclaration4.ts | 18 ++++++ 3 files changed, 103 insertions(+) create mode 100644 tests/baselines/reference/destructuringParameterDeclaration4.errors.txt create mode 100644 tests/baselines/reference/destructuringParameterDeclaration4.js create mode 100644 tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts diff --git a/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt new file mode 100644 index 00000000000..cf4b15d1271 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt @@ -0,0 +1,27 @@ +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(15,1): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. + Type argument candidate 'string' is not a valid type argument because it is not a supertype of candidate 'number'. + + +==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts (1 errors) ==== + interface F { } + class C implements F{ + } + function foo(...a: T[]) { } + function foo1(...a: T[]) { } + function bar({x} = { x: new C() }) { } + function baz({x}: { x: F }) { } + function baz1({x}: { x: C }) { } + function baz2({x}: { x: C }) { } + + var obj = new C(); + baz1({ x: obj }); + baz({ x: new C() }); + baz({ x: {} }); + foo("hello", 1, 2); + ~~~ +!!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. +!!! error TS2453: Type argument candidate 'string' is not a valid type argument because it is not a supertype of candidate 'number'. + foo("hello", 1, 2); + foo("hello", "world"); + + \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterDeclaration4.js b/tests/baselines/reference/destructuringParameterDeclaration4.js new file mode 100644 index 00000000000..3f83402dffa --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration4.js @@ -0,0 +1,58 @@ +//// [destructuringParameterDeclaration4.ts] +interface F { } +class C implements F{ +} +function foo(...a: T[]) { } +function foo1(...a: T[]) { } +function bar({x} = { x: new C() }) { } +function baz({x}: { x: F }) { } +function baz1({x}: { x: C }) { } +function baz2({x}: { x: C }) { } + +var obj = new C(); +baz1({ x: obj }); +baz({ x: new C() }); +baz({ x: {} }); +foo("hello", 1, 2); +foo("hello", 1, 2); +foo("hello", "world"); + + + +//// [destructuringParameterDeclaration4.js] +var C = (function () { + function C() { + } + return C; +})(); +function foo() { + var a = []; + for (var _i = 0; _i < arguments.length; _i++) { + a[_i - 0] = arguments[_i]; + } +} +function foo1() { + var a = []; + for (var _i = 0; _i < arguments.length; _i++) { + a[_i - 0] = arguments[_i]; + } +} +function bar(_a) { + var x = (_a === void 0 ? { x: new C() } : _a).x; +} +function baz(_a) { + var x = _a.x; +} +function baz1(_a) { + var x = _a.x; +} +function baz2(_a) { + var x = _a.x; +} +var obj = new C(); +baz1({ x: obj }); +baz({ x: new C() }); +baz({ x: {} }); +foo("hello", 1, 2); +foo("hello", 1, 2); +foo("hello", "world"); diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts new file mode 100644 index 00000000000..b59c539d672 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts @@ -0,0 +1,18 @@ +interface F { } +class C implements F{ +} +function foo(...a: T[]) { } +function foo1(...a: T[]) { } +function bar({x} = { x: new C() }) { } +function baz({x}: { x: F }) { } +function baz1({x}: { x: C }) { } +function baz2({x}: { x: C }) { } + +var obj = new C(); +baz1({ x: obj }); +baz({ x: new C() }); +baz({ x: {} }); +foo("hello", 1, 2); +foo("hello", 1, 2); +foo("hello", "world"); + From 5d2897d67f8d9586a1c233d95df7cc298e2529d3 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 13 Apr 2015 13:00:00 -0700 Subject: [PATCH 018/194] export imported aliases --- src/compiler/emitter.ts | 24 ++++++++++++++ .../reference/systemModule10.errors.txt | 18 +++++++++++ tests/baselines/reference/systemModule10.js | 32 +++++++++++++++++++ tests/cases/compiler/systemModule10.ts | 11 +++++++ 4 files changed, 85 insertions(+) create mode 100644 tests/baselines/reference/systemModule10.errors.txt create mode 100644 tests/baselines/reference/systemModule10.js create mode 100644 tests/cases/compiler/systemModule10.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 2d028f058f4..98074d26493 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -5026,6 +5026,30 @@ var __param = this.__param || function(index, decorator) { return function (targ writeLocalNameForExternalImport(importNode); write(` = ${setterParameterName}`); writeLine(); + + let defaultName = + importNode.kind === SyntaxKind.ImportDeclaration + ? (importNode).importClause.name + : (importNode).name; + if (defaultName) { + emitExportMemberAssignments(defaultName); + writeLine(); + } + + if (importNode.kind === SyntaxKind.ImportDeclaration && (importNode).importClause.namedBindings) { + if ((importNode).importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { + emitExportMemberAssignments(((importNode).importClause.namedBindings).name); + writeLine(); + } + else { + for (let element of ((importNode).importClause.namedBindings).elements) { + emitExportMemberAssignments(element.name || element.propertyName); + writeLine() + } + } + } + + decreaseIndent(); break; case SyntaxKind.ExportDeclaration: diff --git a/tests/baselines/reference/systemModule10.errors.txt b/tests/baselines/reference/systemModule10.errors.txt new file mode 100644 index 00000000000..9be815836aa --- /dev/null +++ b/tests/baselines/reference/systemModule10.errors.txt @@ -0,0 +1,18 @@ +tests/cases/compiler/systemModule10.ts(2,20): error TS2307: Cannot find external module 'file1'. +tests/cases/compiler/systemModule10.ts(3,21): error TS2307: Cannot find external module 'file2'. + + +==== tests/cases/compiler/systemModule10.ts (2 errors) ==== + + import n, {x} from 'file1' + ~~~~~~~ +!!! error TS2307: Cannot find external module 'file1'. + import n2 = require('file2'); + ~~~~~~~ +!!! error TS2307: Cannot find external module 'file2'. + export {x} + export {x as y} + export {n} + export {n as n1} + export {n2} + export {n2 as n3} \ No newline at end of file diff --git a/tests/baselines/reference/systemModule10.js b/tests/baselines/reference/systemModule10.js new file mode 100644 index 00000000000..c5c95e05f9b --- /dev/null +++ b/tests/baselines/reference/systemModule10.js @@ -0,0 +1,32 @@ +//// [systemModule10.ts] + +import n, {x} from 'file1' +import n2 = require('file2'); +export {x} +export {x as y} +export {n} +export {n as n1} +export {n2} +export {n2 as n3} + +//// [systemModule10.js] +System.register(['file1', 'file2'], function(exports_1) { + var file1_1, n2; + return { + setters:[ + function (v_1) { + file1_1 = v_1 + exports_1("n", file1_1.default); + exports_1("n1", file1_1.default); + exports_1("x", file1_1.x); + exports_1("y", file1_1.x); + }, + function (v_1) { + n2 = v_1 + exports_1("n2", n2); + exports_1("n3", n2); + }], + execute: function() { + } + } +}); diff --git a/tests/cases/compiler/systemModule10.ts b/tests/cases/compiler/systemModule10.ts new file mode 100644 index 00000000000..49e99fb1c63 --- /dev/null +++ b/tests/cases/compiler/systemModule10.ts @@ -0,0 +1,11 @@ +// @module: system +// @separateCompilation: true + +import n, {x} from 'file1' +import n2 = require('file2'); +export {x} +export {x as y} +export {n} +export {n as n1} +export {n2} +export {n2 as n3} \ No newline at end of file From d475170321b3c0c77d33f0766e1af9ec2e7451fa Mon Sep 17 00:00:00 2001 From: Yui T Date: Mon, 13 Apr 2015 16:16:04 -0700 Subject: [PATCH 019/194] Conformance test for update in section 4.6 --- .../reference/arrayLiterals2.errors.txt | 60 ++++++++++++++++ tests/baselines/reference/arrayLiterals2.js | 60 ++++++++++++++++ .../reference/arrayLiterals2ES6.errors.txt | 60 ++++++++++++++++ .../baselines/reference/arrayLiterals2ES6.js | 60 ++++++++++++++++ .../reference/arrayLiterals3.errors.txt | 62 ++++++++++++++++ tests/baselines/reference/arrayLiterals3.js | 70 +++++++++++++++++++ .../reference/arrayLiterals3ES6.errors.txt | 52 ++++++++++++++ .../baselines/reference/arrayLiterals3ES6.js | 62 ++++++++++++++++ .../reference/arrayLiterals4.errors.txt | 31 ++++++++ tests/baselines/reference/arrayLiterals4.js | 16 +++++ .../reference/arrayLiterals5.errors.txt | 46 ++++++++++++ tests/baselines/reference/arrayLiterals5.js | 19 +++++ .../arrayLiterals/arrayLiterals2.ts | 32 +++++++++ .../arrayLiterals/arrayLiterals2ES6.ts | 33 +++++++++ .../arrayLiterals/arrayLiterals3.ts | 42 +++++++++++ .../arrayLiterals/arrayLiterals3ES6.ts | 39 +++++++++++ .../arrayLiterals/arrayLiterals4.ts | 6 ++ .../arrayLiterals/arrayLiterals5.ts | 3 + 18 files changed, 753 insertions(+) create mode 100644 tests/baselines/reference/arrayLiterals2.errors.txt create mode 100644 tests/baselines/reference/arrayLiterals2.js create mode 100644 tests/baselines/reference/arrayLiterals2ES6.errors.txt create mode 100644 tests/baselines/reference/arrayLiterals2ES6.js create mode 100644 tests/baselines/reference/arrayLiterals3.errors.txt create mode 100644 tests/baselines/reference/arrayLiterals3.js create mode 100644 tests/baselines/reference/arrayLiterals3ES6.errors.txt create mode 100644 tests/baselines/reference/arrayLiterals3ES6.js create mode 100644 tests/baselines/reference/arrayLiterals4.errors.txt create mode 100644 tests/baselines/reference/arrayLiterals4.js create mode 100644 tests/baselines/reference/arrayLiterals5.errors.txt create mode 100644 tests/baselines/reference/arrayLiterals5.js create mode 100644 tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2.ts create mode 100644 tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2ES6.ts create mode 100644 tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts create mode 100644 tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3ES6.ts create mode 100644 tests/cases/conformance/expressions/arrayLiterals/arrayLiterals4.ts create mode 100644 tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts diff --git a/tests/baselines/reference/arrayLiterals2.errors.txt b/tests/baselines/reference/arrayLiterals2.errors.txt new file mode 100644 index 00000000000..149d9a4747c --- /dev/null +++ b/tests/baselines/reference/arrayLiterals2.errors.txt @@ -0,0 +1,60 @@ +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2.ts(23,5): error TS2322: Type '(string[] | number[])[]' is not assignable to type 'tup'. + Property '0' is missing in type '(string[] | number[])[]'. +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2.ts(24,5): error TS2322: Type 'number[]' is not assignable to type '[number, number, number]'. + Property '0' is missing in type 'number[]'. +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2.ts(27,5): error TS2322: Type '(string | number)[]' is not assignable to type 'myArray'. + Types of property 'push' are incompatible. + Type '(...items: (string | number)[]) => number' is not assignable to type '(...items: Number[]) => number'. + Types of parameters 'items' and 'items' are incompatible. + Type 'string | number' is not assignable to type 'Number'. + Type 'string' is not assignable to type 'Number'. + Property 'toFixed' is missing in type 'String'. + + +==== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2.ts (3 errors) ==== + var a = [2,3,4] + var a1 = ["hello", "world"] + var a2 = [undefined, null, undefined]; + var a3 = [] + var a4: number[] = [...a3]; + var a5: number[] = []; + + var b = [, , , ...a,"hello"]; + var c = [() => 1,]; + var d = [...c,,]; + var e = [,,...d]; + var g = [[1, 2, "hello"], ["string", true]]; + var h = [...g]; + var i: [number[], string[]] = [[1, 2, 3],["hello", "string"]]; + var j = [...i]; + var k:Array = [...i]; + interface tup { + 0: number[]|string[]; + 1: number[]|string[]; + } + interface myArray extends Array {} + interface myArray2 extends Array {} + var l: tup = [...i]; // error + ~ +!!! error TS2322: Type '(string[] | number[])[]' is not assignable to type 'tup'. +!!! error TS2322: Property '0' is missing in type '(string[] | number[])[]'. + var m: [number, number, number] = [...a]; // error + ~ +!!! error TS2322: Type 'number[]' is not assignable to type '[number, number, number]'. +!!! error TS2322: Property '0' is missing in type 'number[]'. + var n: number[] = [...a]; + var o: myArray = [...a]; + var p: myArray = [...a, ...a1]; // error + ~ +!!! error TS2322: Type '(string | number)[]' is not assignable to type 'myArray'. +!!! error TS2322: Types of property 'push' are incompatible. +!!! error TS2322: Type '(...items: (string | number)[]) => number' is not assignable to type '(...items: Number[]) => number'. +!!! error TS2322: Types of parameters 'items' and 'items' are incompatible. +!!! error TS2322: Type 'string | number' is not assignable to type 'Number'. +!!! error TS2322: Type 'string' is not assignable to type 'Number'. +!!! error TS2322: Property 'toFixed' is missing in type 'String'. + var q: myArray2 = [...a, ...a1]; + var r = [...a2]; + var r1 = [...a3]; + var r2 = [...a4]; + var r3:number[][] = [[...a4]]; \ No newline at end of file diff --git a/tests/baselines/reference/arrayLiterals2.js b/tests/baselines/reference/arrayLiterals2.js new file mode 100644 index 00000000000..42cfb13c96a --- /dev/null +++ b/tests/baselines/reference/arrayLiterals2.js @@ -0,0 +1,60 @@ +//// [arrayLiterals2.ts] +var a = [2,3,4] +var a1 = ["hello", "world"] +var a2 = [undefined, null, undefined]; +var a3 = [] +var a4: number[] = [...a3]; +var a5: number[] = []; + +var b = [, , , ...a,"hello"]; +var c = [() => 1,]; +var d = [...c,,]; +var e = [,,...d]; +var g = [[1, 2, "hello"], ["string", true]]; +var h = [...g]; +var i: [number[], string[]] = [[1, 2, 3],["hello", "string"]]; +var j = [...i]; +var k:Array = [...i]; +interface tup { + 0: number[]|string[]; + 1: number[]|string[]; +} +interface myArray extends Array {} +interface myArray2 extends Array {} +var l: tup = [...i]; // error +var m: [number, number, number] = [...a]; // error +var n: number[] = [...a]; +var o: myArray = [...a]; +var p: myArray = [...a, ...a1]; // error +var q: myArray2 = [...a, ...a1]; +var r = [...a2]; +var r1 = [...a3]; +var r2 = [...a4]; +var r3:number[][] = [[...a4]]; + +//// [arrayLiterals2.js] +var a = [2, 3, 4]; +var a1 = ["hello", "world"]; +var a2 = [undefined, null, undefined]; +var a3 = []; +var a4 = a3; +var a5 = []; +var b = [, , ].concat(a, ["hello"]); +var c = [function () { return 1; },]; +var d = c.concat([,]); +var e = [, ].concat(d); +var g = [[1, 2, "hello"], ["string", true]]; +var h = g; +var i = [[1, 2, 3], ["hello", "string"]]; +var j = i; +var k = i; +var l = i; // error +var m = a; // error +var n = a; +var o = a; +var p = a.concat(a1); // error +var q = a.concat(a1); +var r = a2; +var r1 = a3; +var r2 = a4; +var r3 = [a4]; diff --git a/tests/baselines/reference/arrayLiterals2ES6.errors.txt b/tests/baselines/reference/arrayLiterals2ES6.errors.txt new file mode 100644 index 00000000000..bb3247ec453 --- /dev/null +++ b/tests/baselines/reference/arrayLiterals2ES6.errors.txt @@ -0,0 +1,60 @@ +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2ES6.ts(23,5): error TS2322: Type '(string[] | number[])[]' is not assignable to type 'tup'. + Property '0' is missing in type '(string[] | number[])[]'. +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2ES6.ts(24,5): error TS2322: Type 'number[]' is not assignable to type '[number, number, number]'. + Property '0' is missing in type 'number[]'. +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2ES6.ts(27,5): error TS2322: Type '(string | number)[]' is not assignable to type 'myArray'. + Types of property 'push' are incompatible. + Type '(...items: (string | number)[]) => number' is not assignable to type '(...items: Number[]) => number'. + Types of parameters 'items' and 'items' are incompatible. + Type 'string | number' is not assignable to type 'Number'. + Type 'string' is not assignable to type 'Number'. + Property 'toFixed' is missing in type 'String'. + + +==== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2ES6.ts (3 errors) ==== + var a = [2,3,4] + var a1 = ["hello", "world"] + var a2 = [undefined, null, undefined]; + var a3 = [] + var a4: number[] = [...a3]; + var a5: number[] = []; + + var b = [, , , ...a,"hello"]; + var c = [() => 1,]; + var d = [...c,,]; + var e = [,,...d]; + var g = [[1, 2, "hello"], ["string", true]]; + var h = [...g]; + var i: [number[], string[]] = [[1, 2, 3],["hello", "string"]]; + var j = [...i]; + var k:Array = [...i]; + interface tup { + 0: number[]|string[]; + 1: number[]|string[]; + } + interface myArray extends Array {} + interface myArray2 extends Array {} + var l: tup = [...i]; // error + ~ +!!! error TS2322: Type '(string[] | number[])[]' is not assignable to type 'tup'. +!!! error TS2322: Property '0' is missing in type '(string[] | number[])[]'. + var m: [number, number, number] = [...a]; // error + ~ +!!! error TS2322: Type 'number[]' is not assignable to type '[number, number, number]'. +!!! error TS2322: Property '0' is missing in type 'number[]'. + var n: number[] = [...a]; + var o: myArray = [...a]; + var p: myArray = [...a, ...a1]; // error + ~ +!!! error TS2322: Type '(string | number)[]' is not assignable to type 'myArray'. +!!! error TS2322: Types of property 'push' are incompatible. +!!! error TS2322: Type '(...items: (string | number)[]) => number' is not assignable to type '(...items: Number[]) => number'. +!!! error TS2322: Types of parameters 'items' and 'items' are incompatible. +!!! error TS2322: Type 'string | number' is not assignable to type 'Number'. +!!! error TS2322: Type 'string' is not assignable to type 'Number'. +!!! error TS2322: Property 'toFixed' is missing in type 'String'. + var q: myArray2 = [...a, ...a1]; + var r = [...a2]; + var r1 = [...a3]; + var r2 = [...a4]; + var r3:number[][] = [[...a4]]; \ No newline at end of file diff --git a/tests/baselines/reference/arrayLiterals2ES6.js b/tests/baselines/reference/arrayLiterals2ES6.js new file mode 100644 index 00000000000..8cdecdd3be4 --- /dev/null +++ b/tests/baselines/reference/arrayLiterals2ES6.js @@ -0,0 +1,60 @@ +//// [arrayLiterals2ES6.ts] +var a = [2,3,4] +var a1 = ["hello", "world"] +var a2 = [undefined, null, undefined]; +var a3 = [] +var a4: number[] = [...a3]; +var a5: number[] = []; + +var b = [, , , ...a,"hello"]; +var c = [() => 1,]; +var d = [...c,,]; +var e = [,,...d]; +var g = [[1, 2, "hello"], ["string", true]]; +var h = [...g]; +var i: [number[], string[]] = [[1, 2, 3],["hello", "string"]]; +var j = [...i]; +var k:Array = [...i]; +interface tup { + 0: number[]|string[]; + 1: number[]|string[]; +} +interface myArray extends Array {} +interface myArray2 extends Array {} +var l: tup = [...i]; // error +var m: [number, number, number] = [...a]; // error +var n: number[] = [...a]; +var o: myArray = [...a]; +var p: myArray = [...a, ...a1]; // error +var q: myArray2 = [...a, ...a1]; +var r = [...a2]; +var r1 = [...a3]; +var r2 = [...a4]; +var r3:number[][] = [[...a4]]; + +//// [arrayLiterals2ES6.js] +var a = [2, 3, 4]; +var a1 = ["hello", "world"]; +var a2 = [undefined, null, undefined]; +var a3 = []; +var a4 = [...a3]; +var a5 = []; +var b = [, , , ...a, "hello"]; +var c = [() => 1,]; +var d = [...c, ,]; +var e = [, , ...d]; +var g = [[1, 2, "hello"], ["string", true]]; +var h = [...g]; +var i = [[1, 2, 3], ["hello", "string"]]; +var j = [...i]; +var k = [...i]; +var l = [...i]; // error +var m = [...a]; // error +var n = [...a]; +var o = [...a]; +var p = [...a, ...a1]; // error +var q = [...a, ...a1]; +var r = [...a2]; +var r1 = [...a3]; +var r2 = [...a4]; +var r3 = [[...a4]]; diff --git a/tests/baselines/reference/arrayLiterals3.errors.txt b/tests/baselines/reference/arrayLiterals3.errors.txt new file mode 100644 index 00000000000..35bedb54854 --- /dev/null +++ b/tests/baselines/reference/arrayLiterals3.errors.txt @@ -0,0 +1,62 @@ +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(8,5): error TS2322: Type '[number, number, string, boolean]' is not assignable to type '[number, number]'. + Types of property 'pop' are incompatible. + Type '() => string | number | boolean' is not assignable to type '() => number'. + Type 'string | number | boolean' is not assignable to type 'number'. + Type 'string' is not assignable to type 'number'. +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(35,6): error TS2461: Type 'string | number[]' is not an array type. +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(40,16): error TS2461: Type 'IArguments' is not an array type. + + +==== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts (3 errors) ==== + interface I0 extends Array { + 0: number; + 1: number; + 2: string; + 3: boolean; + } + var [a, b]: [number, number] = [1, 2]; + var [a1, b1]: [number, number] = [1, 2, "string", true]; // error + ~~~~~~~~ +!!! error TS2322: Type '[number, number, string, boolean]' is not assignable to type '[number, number]'. +!!! error TS2322: Types of property 'pop' are incompatible. +!!! error TS2322: Type '() => string | number | boolean' is not assignable to type '() => number'. +!!! error TS2322: Type 'string | number | boolean' is not assignable to type 'number'. +!!! error TS2322: Type 'string' is not assignable to type 'number'. + var [a2, b2]: (number| string)[] = [1, 2, 3, "string"]; + var [c1, c2, c3]: I0 = [10, 11, "string", true]; + interface I extends Array{ + 0: string|number; + 1: string|number; + 2: string|number; + } + interface I2 extends Array { + 0: number; + 1: number; + 2: string|number; + } + var tup: [number, number, string] = [1, 2, "world"]; + var [c, d, e]: I = tup; + var [f, g]: I2 = tup; + var h1: string| number; + var [f1, g1,h1]: I2 = tup; + h1 = g1; + + var arr1 = [1, 2, 3]; + var arr2 = [true, false, true]; + var arr3 = [true] + var [[foo1, foo2, foo3], [boo1, boo2, boo3]] = [[...arr1], [...arr2]]; + var [bar1, bar2, bar3, bar1, bar2, bar3] = [...arr1, ...arr2]; + var [bar1, bar2, bar3, bar1, bar2] = [...arr1, ...arr3]; + var [[r, s], t] = [[...arr1], "hello"]; + var [[r1, s1], t1] = [[...arr1], ...["hello"]]; // error + ~~~~~~~~ +!!! error TS2461: Type 'string | number[]' is not an array type. + var [x] = [...["word"]]; + var [...y] = [...["word"]]; + var z = [...[...["word"]]]; + function foobar() { + return [...arguments]; + ~~~~~~~~~ +!!! error TS2461: Type 'IArguments' is not an array type. + } + var [...as] = [[, , , , ]]; \ No newline at end of file diff --git a/tests/baselines/reference/arrayLiterals3.js b/tests/baselines/reference/arrayLiterals3.js new file mode 100644 index 00000000000..6ad064e20da --- /dev/null +++ b/tests/baselines/reference/arrayLiterals3.js @@ -0,0 +1,70 @@ +//// [arrayLiterals3.ts] +interface I0 extends Array { + 0: number; + 1: number; + 2: string; + 3: boolean; +} +var [a, b]: [number, number] = [1, 2]; +var [a1, b1]: [number, number] = [1, 2, "string", true]; // error +var [a2, b2]: (number| string)[] = [1, 2, 3, "string"]; +var [c1, c2, c3]: I0 = [10, 11, "string", true]; +interface I extends Array{ + 0: string|number; + 1: string|number; + 2: string|number; +} +interface I2 extends Array { + 0: number; + 1: number; + 2: string|number; +} +var tup: [number, number, string] = [1, 2, "world"]; +var [c, d, e]: I = tup; +var [f, g]: I2 = tup; +var h1: string| number; +var [f1, g1,h1]: I2 = tup; +h1 = g1; + +var arr1 = [1, 2, 3]; +var arr2 = [true, false, true]; +var arr3 = [true] +var [[foo1, foo2, foo3], [boo1, boo2, boo3]] = [[...arr1], [...arr2]]; +var [bar1, bar2, bar3, bar1, bar2, bar3] = [...arr1, ...arr2]; +var [bar1, bar2, bar3, bar1, bar2] = [...arr1, ...arr3]; +var [[r, s], t] = [[...arr1], "hello"]; +var [[r1, s1], t1] = [[...arr1], ...["hello"]]; // error +var [x] = [...["word"]]; +var [...y] = [...["word"]]; +var z = [...[...["word"]]]; +function foobar() { + return [...arguments]; +} +var [...as] = [[, , , , ]]; + +//// [arrayLiterals3.js] +var _a = [1, 2], a = _a[0], b = _a[1]; +var _b = [1, 2, "string", true], a1 = _b[0], b1 = _b[1]; // error +var _c = [1, 2, 3, "string"], a2 = _c[0], b2 = _c[1]; +var _d = [10, 11, "string", true], c1 = _d[0], c2 = _d[1], c3 = _d[2]; +var tup = [1, 2, "world"]; +var c = tup[0], d = tup[1], e = tup[2]; +var f = tup[0], g = tup[1]; +var h1; +var f1 = tup[0], g1 = tup[1], h1 = tup[2]; +h1 = g1; +var arr1 = [1, 2, 3]; +var arr2 = [true, false, true]; +var arr3 = [true]; +var _e = [arr1, arr2], _f = _e[0], foo1 = _f[0], foo2 = _f[1], foo3 = _f[2], _g = _e[1], boo1 = _g[0], boo2 = _g[1], boo3 = _g[2]; +var _h = arr1.concat(arr2), bar1 = _h[0], bar2 = _h[1], bar3 = _h[2], bar1 = _h[3], bar2 = _h[4], bar3 = _h[5]; +var _j = arr1.concat(arr3), bar1 = _j[0], bar2 = _j[1], bar3 = _j[2], bar1 = _j[3], bar2 = _j[4]; +var _k = [arr1, "hello"], _l = _k[0], r = _l[0], s = _l[1], t = _k[1]; +var _m = [arr1].concat(["hello"]), _o = _m[0], r1 = _o[0], s1 = _o[1], t1 = _m[1]; // error +var x = (["word"])[0]; +var _p = ["word"], y = _p.slice(0); +var z = ["word"]; +function foobar() { + return arguments; +} +var _q = [[, , , ,]], as = _q.slice(0); diff --git a/tests/baselines/reference/arrayLiterals3ES6.errors.txt b/tests/baselines/reference/arrayLiterals3ES6.errors.txt new file mode 100644 index 00000000000..1490a0fbcfa --- /dev/null +++ b/tests/baselines/reference/arrayLiterals3ES6.errors.txt @@ -0,0 +1,52 @@ +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3ES6.ts(8,5): error TS2322: Type '[number, number, string, boolean]' is not assignable to type '[number, number]'. + Types of property 'pop' are incompatible. + Type '() => string | number | boolean' is not assignable to type '() => number'. + Type 'string | number | boolean' is not assignable to type 'number'. + Type 'string' is not assignable to type 'number'. + + +==== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3ES6.ts (1 errors) ==== + interface I0 extends Array { + 0: number; + 1: number; + 2: string; + 3: boolean; + } + var [a, b]: [number, number] = [1, 2]; + var [a1, b1]: [number, number] = [1, 2, "string", true]; // error + ~~~~~~~~ +!!! error TS2322: Type '[number, number, string, boolean]' is not assignable to type '[number, number]'. +!!! error TS2322: Types of property 'pop' are incompatible. +!!! error TS2322: Type '() => string | number | boolean' is not assignable to type '() => number'. +!!! error TS2322: Type 'string | number | boolean' is not assignable to type 'number'. +!!! error TS2322: Type 'string' is not assignable to type 'number'. + var [a2, b2]: (number| string)[] = [1, 2, 3, "string"]; + var [c1, c2, c3]: I0 = [10, 11, "string", true]; + interface I extends Array{ + 0: string|number; + 1: string|number; + 2: string|number; + } + interface I2 extends Array { + 0: number; + 1: number; + 2: string|number; + } + var tup: [number, number, string] = [1, 2, "world"]; + var [c, d, e]: I = tup; + var [f, g]: I2 = tup; + var h1: string| number; + var [f1, g1,h1]: I2 = tup; + h1 = g1; + + var arr1 = [1, 2, 3]; + var arr2 = [true, false, true]; + var arr3 = [true] + var [[foo1, foo2, foo3], [boo1, boo2, boo3]] = [[...arr1], [...arr2]]; + var [bar1, bar2, bar3, bar1, bar2, bar3] = [...arr1, ...arr2]; + var [bar1, bar2, bar3, bar1, bar2] = [...arr1, ...arr3]; + var [[r, s], t] = [[...arr1], "hello"]; + var [[r1, s1], t1] = [[...arr1], ...["hello"]]; // error + var [x] = [...["word"]]; + var [...y] = [...["word"]]; + var z = [...[...["word"]]]; \ No newline at end of file diff --git a/tests/baselines/reference/arrayLiterals3ES6.js b/tests/baselines/reference/arrayLiterals3ES6.js new file mode 100644 index 00000000000..f685ea9c719 --- /dev/null +++ b/tests/baselines/reference/arrayLiterals3ES6.js @@ -0,0 +1,62 @@ +//// [arrayLiterals3ES6.ts] +interface I0 extends Array { + 0: number; + 1: number; + 2: string; + 3: boolean; +} +var [a, b]: [number, number] = [1, 2]; +var [a1, b1]: [number, number] = [1, 2, "string", true]; // error +var [a2, b2]: (number| string)[] = [1, 2, 3, "string"]; +var [c1, c2, c3]: I0 = [10, 11, "string", true]; +interface I extends Array{ + 0: string|number; + 1: string|number; + 2: string|number; +} +interface I2 extends Array { + 0: number; + 1: number; + 2: string|number; +} +var tup: [number, number, string] = [1, 2, "world"]; +var [c, d, e]: I = tup; +var [f, g]: I2 = tup; +var h1: string| number; +var [f1, g1,h1]: I2 = tup; +h1 = g1; + +var arr1 = [1, 2, 3]; +var arr2 = [true, false, true]; +var arr3 = [true] +var [[foo1, foo2, foo3], [boo1, boo2, boo3]] = [[...arr1], [...arr2]]; +var [bar1, bar2, bar3, bar1, bar2, bar3] = [...arr1, ...arr2]; +var [bar1, bar2, bar3, bar1, bar2] = [...arr1, ...arr3]; +var [[r, s], t] = [[...arr1], "hello"]; +var [[r1, s1], t1] = [[...arr1], ...["hello"]]; // error +var [x] = [...["word"]]; +var [...y] = [...["word"]]; +var z = [...[...["word"]]]; + +//// [arrayLiterals3ES6.js] +var [a, b] = [1, 2]; +var [a1, b1] = [1, 2, "string", true]; // error +var [a2, b2] = [1, 2, 3, "string"]; +var [c1, c2, c3] = [10, 11, "string", true]; +var tup = [1, 2, "world"]; +var [c, d, e] = tup; +var [f, g] = tup; +var h1; +var [f1, g1, h1] = tup; +h1 = g1; +var arr1 = [1, 2, 3]; +var arr2 = [true, false, true]; +var arr3 = [true]; +var [[foo1, foo2, foo3], [boo1, boo2, boo3]] = [[...arr1], [...arr2]]; +var [bar1, bar2, bar3, bar1, bar2, bar3] = [...arr1, ...arr2]; +var [bar1, bar2, bar3, bar1, bar2] = [...arr1, ...arr3]; +var [[r, s], t] = [[...arr1], "hello"]; +var [[r1, s1], t1] = [[...arr1], ...["hello"]]; // error +var [x] = [...["word"]]; +var [...y] = [...["word"]]; +var z = [...[...["word"]]]; diff --git a/tests/baselines/reference/arrayLiterals4.errors.txt b/tests/baselines/reference/arrayLiterals4.errors.txt new file mode 100644 index 00000000000..5fc0fe2c51e --- /dev/null +++ b/tests/baselines/reference/arrayLiterals4.errors.txt @@ -0,0 +1,31 @@ +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals4.ts(2,6): error TS1212: Identifier expected. 'public' is a reserved word in strict mode +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals4.ts(2,14): error TS1212: Identifier expected. 'static' is a reserved word in strict mode +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals4.ts(3,5): error TS1212: Identifier expected. 'protected' is a reserved word in strict mode +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals4.ts(4,21): error TS1212: Identifier expected. 'protected' is a reserved word in strict mode +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals4.ts(5,7): error TS1212: Identifier expected. 'public' is a reserved word in strict mode +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals4.ts(5,15): error TS1212: Identifier expected. 'package' is a reserved word in strict mode +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals4.ts(6,9): error TS1212: Identifier expected. 'implements' is a reserved word in strict mode + + +==== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals4.ts (7 errors) ==== + "use strict" + var [public, static] = [1, 23, ]; + ~~~~~~ +!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode + ~~~~~~ +!!! error TS1212: Identifier expected. 'static' is a reserved word in strict mode + var protected = [1, 2, 3]; + ~~~~~~~~~ +!!! error TS1212: Identifier expected. 'protected' is a reserved word in strict mode + var [a, b, c] = [...protected]; + ~~~~~~~~~ +!!! error TS1212: Identifier expected. 'protected' is a reserved word in strict mode + var [[public, package]] = [[1, [2, 3]]]; + ~~~~~~ +!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode + ~~~~~~~ +!!! error TS1212: Identifier expected. 'package' is a reserved word in strict mode + var [...implements] = [[]]; + ~~~~~~~~~~ +!!! error TS1212: Identifier expected. 'implements' is a reserved word in strict mode + \ No newline at end of file diff --git a/tests/baselines/reference/arrayLiterals4.js b/tests/baselines/reference/arrayLiterals4.js new file mode 100644 index 00000000000..28c7fb10306 --- /dev/null +++ b/tests/baselines/reference/arrayLiterals4.js @@ -0,0 +1,16 @@ +//// [arrayLiterals4.ts] +"use strict" +var [public, static] = [1, 23, ]; +var protected = [1, 2, 3]; +var [a, b, c] = [...protected]; +var [[public, package]] = [[1, [2, 3]]]; +var [...implements] = [[]]; + + +//// [arrayLiterals4.js] +"use strict"; +var _a = [1, 23,], public = _a[0], static = _a[1]; +var protected = [1, 2, 3]; +var _b = protected, a = _b[0], b = _b[1], c = _b[2]; +var _c = ([[1, [2, 3]]])[0], public = _c[0], package = _c[1]; +var _d = [[]], implements = _d.slice(0); diff --git a/tests/baselines/reference/arrayLiterals5.errors.txt b/tests/baselines/reference/arrayLiterals5.errors.txt new file mode 100644 index 00000000000..ee928841b6a --- /dev/null +++ b/tests/baselines/reference/arrayLiterals5.errors.txt @@ -0,0 +1,46 @@ +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts(1,6): error TS1181: Array element destructuring pattern expected. +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts(1,11): error TS1005: '(' expected. +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts(1,13): error TS1109: Expression expected. +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts(1,16): error TS1005: '(' expected. +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts(1,18): error TS1128: Declaration or statement expected. +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts(2,6): error TS1181: Array element destructuring pattern expected. +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts(2,9): error TS1005: '(' expected. +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts(2,11): error TS2304: Cannot find name 'as'. +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts(2,13): error TS1005: ';' expected. +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts(2,15): error TS1128: Declaration or statement expected. +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts(3,9): error TS1003: Identifier expected. +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts(3,14): error TS1003: Identifier expected. +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts(3,16): error TS1128: Declaration or statement expected. + + +==== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts (13 errors) ==== + var [while, for] = [1, 3, ]; + ~~~~~ +!!! error TS1181: Array element destructuring pattern expected. + ~ +!!! error TS1005: '(' expected. + ~~~ +!!! error TS1109: Expression expected. + ~ +!!! error TS1005: '(' expected. + ~ +!!! error TS1128: Declaration or statement expected. + var [for, as] = [, , , , ]; + ~~~ +!!! error TS1181: Array element destructuring pattern expected. + ~ +!!! error TS1005: '(' expected. + ~~ +!!! error TS2304: Cannot find name 'as'. + ~ +!!! error TS1005: ';' expected. + ~ +!!! error TS1128: Declaration or statement expected. + var [...break] = [...["hello"]]; + ~~~~~ +!!! error TS1003: Identifier expected. + ~ +!!! error TS1003: Identifier expected. + ~ +!!! error TS1128: Declaration or statement expected. + \ No newline at end of file diff --git a/tests/baselines/reference/arrayLiterals5.js b/tests/baselines/reference/arrayLiterals5.js new file mode 100644 index 00000000000..faf4bb6fa70 --- /dev/null +++ b/tests/baselines/reference/arrayLiterals5.js @@ -0,0 +1,19 @@ +//// [arrayLiterals5.ts] +var [while, for] = [1, 3, ]; +var [for, as] = [, , , , ]; +var [...break] = [...["hello"]]; + + +//// [arrayLiterals5.js] +var _a = void 0; +while (, ) + for (; ; ) + ; +[1, 3,]; +var _b = void 0; +for (, as; ; ) + ; +[, , , ,]; +var _c = void 0, = _c.slice(0); +break ; +["hello"]; diff --git a/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2.ts b/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2.ts new file mode 100644 index 00000000000..6b6807e1d33 --- /dev/null +++ b/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2.ts @@ -0,0 +1,32 @@ +var a = [2,3,4] +var a1 = ["hello", "world"] +var a2 = [undefined, null, undefined]; +var a3 = [] +var a4: number[] = [...a3]; +var a5: number[] = []; + +var b = [, , , ...a,"hello"]; +var c = [() => 1,]; +var d = [...c,,]; +var e = [,,...d]; +var g = [[1, 2, "hello"], ["string", true]]; +var h = [...g]; +var i: [number[], string[]] = [[1, 2, 3],["hello", "string"]]; +var j = [...i]; +var k:Array = [...i]; +interface tup { + 0: number[]|string[]; + 1: number[]|string[]; +} +interface myArray extends Array {} +interface myArray2 extends Array {} +var l: tup = [...i]; // error +var m: [number, number, number] = [...a]; // error +var n: number[] = [...a]; +var o: myArray = [...a]; +var p: myArray = [...a, ...a1]; // error +var q: myArray2 = [...a, ...a1]; +var r = [...a2]; +var r1 = [...a3]; +var r2 = [...a4]; +var r3:number[][] = [[...a4]]; \ No newline at end of file diff --git a/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2ES6.ts b/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2ES6.ts new file mode 100644 index 00000000000..5a32af531e1 --- /dev/null +++ b/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2ES6.ts @@ -0,0 +1,33 @@ +// @target:es6 +var a = [2,3,4] +var a1 = ["hello", "world"] +var a2 = [undefined, null, undefined]; +var a3 = [] +var a4: number[] = [...a3]; +var a5: number[] = []; + +var b = [, , , ...a,"hello"]; +var c = [() => 1,]; +var d = [...c,,]; +var e = [,,...d]; +var g = [[1, 2, "hello"], ["string", true]]; +var h = [...g]; +var i: [number[], string[]] = [[1, 2, 3],["hello", "string"]]; +var j = [...i]; +var k:Array = [...i]; +interface tup { + 0: number[]|string[]; + 1: number[]|string[]; +} +interface myArray extends Array {} +interface myArray2 extends Array {} +var l: tup = [...i]; // error +var m: [number, number, number] = [...a]; // error +var n: number[] = [...a]; +var o: myArray = [...a]; +var p: myArray = [...a, ...a1]; // error +var q: myArray2 = [...a, ...a1]; +var r = [...a2]; +var r1 = [...a3]; +var r2 = [...a4]; +var r3:number[][] = [[...a4]]; \ No newline at end of file diff --git a/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts b/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts new file mode 100644 index 00000000000..1a173d59d92 --- /dev/null +++ b/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts @@ -0,0 +1,42 @@ +interface I0 extends Array { + 0: number; + 1: number; + 2: string; + 3: boolean; +} +var [a, b]: [number, number] = [1, 2]; +var [a1, b1]: [number, number] = [1, 2, "string", true]; // error +var [a2, b2]: (number| string)[] = [1, 2, 3, "string"]; +var [c1, c2, c3]: I0 = [10, 11, "string", true]; +interface I extends Array{ + 0: string|number; + 1: string|number; + 2: string|number; +} +interface I2 extends Array { + 0: number; + 1: number; + 2: string|number; +} +var tup: [number, number, string] = [1, 2, "world"]; +var [c, d, e]: I = tup; +var [f, g]: I2 = tup; +var h1: string| number; +var [f1, g1,h1]: I2 = tup; +h1 = g1; + +var arr1 = [1, 2, 3]; +var arr2 = [true, false, true]; +var arr3 = [true] +var [[foo1, foo2, foo3], [boo1, boo2, boo3]] = [[...arr1], [...arr2]]; +var [bar1, bar2, bar3, bar1, bar2, bar3] = [...arr1, ...arr2]; +var [bar1, bar2, bar3, bar1, bar2] = [...arr1, ...arr3]; +var [[r, s], t] = [[...arr1], "hello"]; +var [[r1, s1], t1] = [[...arr1], ...["hello"]]; // error +var [x] = [...["word"]]; +var [...y] = [...["word"]]; +var z = [...[...["word"]]]; +function foobar() { + return [...arguments]; +} +var [...as] = [[, , , , ]]; \ No newline at end of file diff --git a/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3ES6.ts b/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3ES6.ts new file mode 100644 index 00000000000..817d27f0f92 --- /dev/null +++ b/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3ES6.ts @@ -0,0 +1,39 @@ +// @target:es6 +interface I0 extends Array { + 0: number; + 1: number; + 2: string; + 3: boolean; +} +var [a, b]: [number, number] = [1, 2]; +var [a1, b1]: [number, number] = [1, 2, "string", true]; // error +var [a2, b2]: (number| string)[] = [1, 2, 3, "string"]; +var [c1, c2, c3]: I0 = [10, 11, "string", true]; +interface I extends Array{ + 0: string|number; + 1: string|number; + 2: string|number; +} +interface I2 extends Array { + 0: number; + 1: number; + 2: string|number; +} +var tup: [number, number, string] = [1, 2, "world"]; +var [c, d, e]: I = tup; +var [f, g]: I2 = tup; +var h1: string| number; +var [f1, g1,h1]: I2 = tup; +h1 = g1; + +var arr1 = [1, 2, 3]; +var arr2 = [true, false, true]; +var arr3 = [true] +var [[foo1, foo2, foo3], [boo1, boo2, boo3]] = [[...arr1], [...arr2]]; +var [bar1, bar2, bar3, bar1, bar2, bar3] = [...arr1, ...arr2]; +var [bar1, bar2, bar3, bar1, bar2] = [...arr1, ...arr3]; +var [[r, s], t] = [[...arr1], "hello"]; +var [[r1, s1], t1] = [[...arr1], ...["hello"]]; // error +var [x] = [...["word"]]; +var [...y] = [...["word"]]; +var z = [...[...["word"]]]; \ No newline at end of file diff --git a/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals4.ts b/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals4.ts new file mode 100644 index 00000000000..28319903b7c --- /dev/null +++ b/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals4.ts @@ -0,0 +1,6 @@ +"use strict" +var [public, static] = [1, 23, ]; +var protected = [1, 2, 3]; +var [a, b, c] = [...protected]; +var [[public, package]] = [[1, [2, 3]]]; +var [...implements] = [[]]; diff --git a/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts b/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts new file mode 100644 index 00000000000..2429037b4a8 --- /dev/null +++ b/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts @@ -0,0 +1,3 @@ +var [while, for] = [1, 3, ]; +var [for, as] = [, , , , ]; +var [...break] = [...["hello"]]; From 0feebd44b38edd67af960c24cd9f341fcbc100d9 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 13 Apr 2015 21:32:27 -0700 Subject: [PATCH 020/194] publish exported postfix operators as 'E("", ++x) - 1' and 'E("", --x) + 1' --- src/compiler/emitter.ts | 24 ++++++++++++------- tests/baselines/reference/systemModule8.js | 12 ++++++---- tests/baselines/reference/systemModule8.types | 12 ++++++++++ tests/cases/compiler/systemModule8.ts | 2 ++ 4 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 98074d26493..941bc973837 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1963,18 +1963,24 @@ var __param = this.__param || function(index, decorator) { return function (targ function emitPostfixUnaryExpression(node: PostfixUnaryExpression) { const exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.operand); if (exportChanged) { - write(`${exportFunctionForFile}("`); + // emit 'x++' as '(export('x', ++x) - 1)' and 'x--' as '(export('x', --x) + 1)' + write(`(${exportFunctionForFile}("`); emitNodeWithoutSourceMap(node.operand); write(`", `); + + write(tokenToString(node.operator)); + emit(node.operand); + + if (node.operator === SyntaxKind.PlusPlusToken) { + write(") - 1)"); + } + else { + write(") + 1)"); + } } - - emit(node.operand); - write(tokenToString(node.operator)); - - if (exportChanged) { - write("), "); - emitNodeWithoutSourceMap(node.operand); - write(node.operator === SyntaxKind.PlusPlusToken ? " - 1" : " + 1"); + else { + emit(node.operand); + write(tokenToString(node.operator)); } } diff --git a/tests/baselines/reference/systemModule8.js b/tests/baselines/reference/systemModule8.js index 45b25d8f98d..e4c0e12aae3 100644 --- a/tests/baselines/reference/systemModule8.js +++ b/tests/baselines/reference/systemModule8.js @@ -14,6 +14,8 @@ x |= 1; x &= 1; for (x = 5;;x++) {} for (x = 8;;x--) {} +for (x = 15;;++x) {} +for (x = 18;;--x) {} for (let x = 50;;) {} function foo() { @@ -35,8 +37,8 @@ System.register([], function(exports_1) { execute: function() { exports_1("x", x); exports_1("x", x = 1); - exports_1("x", x++), x - 1; - exports_1("x", x--), x + 1; + (exports_1("x", ++x) - 1); + (exports_1("x", --x) + 1); exports_1("x", ++x); exports_1("x", --x); exports_1("x", x += 1); @@ -45,8 +47,10 @@ System.register([], function(exports_1) { exports_1("x", x /= 1); exports_1("x", x |= 1); exports_1("x", x &= 1); - for (exports_1("x", x = 5);; exports_1("x", x++), x - 1) { } - for (exports_1("x", x = 8);; exports_1("x", x--), x + 1) { } + for (exports_1("x", x = 5);; (exports_1("x", ++x) - 1)) { } + for (exports_1("x", x = 8);; (exports_1("x", --x) + 1)) { } + for (exports_1("x", x = 15);; exports_1("x", ++x)) { } + for (exports_1("x", x = 18);; exports_1("x", --x)) { } for (x_1 = 50;;) { } exports_1("y", y = ([1])[0]); _a = { a: true, b: { c: "123" } }, exports_1("z0", z0 = _a.a), exports_1("z1", z1 = _a.b.c); diff --git a/tests/baselines/reference/systemModule8.types b/tests/baselines/reference/systemModule8.types index 3bbc09b2721..cd192662078 100644 --- a/tests/baselines/reference/systemModule8.types +++ b/tests/baselines/reference/systemModule8.types @@ -59,6 +59,18 @@ for (x = 8;;x--) {} >x-- : number >x : any +for (x = 15;;++x) {} +>x = 15 : number +>x : any +>++x : number +>x : any + +for (x = 18;;--x) {} +>x = 18 : number +>x : any +>--x : number +>x : any + for (let x = 50;;) {} >x : number diff --git a/tests/cases/compiler/systemModule8.ts b/tests/cases/compiler/systemModule8.ts index 2185b1c0500..fb75c43df56 100644 --- a/tests/cases/compiler/systemModule8.ts +++ b/tests/cases/compiler/systemModule8.ts @@ -14,6 +14,8 @@ x |= 1; x &= 1; for (x = 5;;x++) {} for (x = 8;;x--) {} +for (x = 15;;++x) {} +for (x = 18;;--x) {} for (let x = 50;;) {} function foo() { From a689b9df38a3fd2d024b23db4eb8f48e83a17a97 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 14 Apr 2015 10:26:47 -0700 Subject: [PATCH 021/194] Conformance test for update incontextual type in function expression --- .../functionExpressionContextualTyping.js | 76 ++++++++ .../functionExpressionContextualTyping.types | 167 ++++++++++++++++++ ...tionExpressionContextualTyping1.errors.txt | 36 ++++ .../functionExpressionContextualTyping1.js | 36 ++++ .../functionExpressionContextualTyping.ts | 32 ++++ .../functionExpressionContextualTyping1.ts | 14 ++ 6 files changed, 361 insertions(+) create mode 100644 tests/baselines/reference/functionExpressionContextualTyping.js create mode 100644 tests/baselines/reference/functionExpressionContextualTyping.types create mode 100644 tests/baselines/reference/functionExpressionContextualTyping1.errors.txt create mode 100644 tests/baselines/reference/functionExpressionContextualTyping1.js create mode 100644 tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping.ts create mode 100644 tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts diff --git a/tests/baselines/reference/functionExpressionContextualTyping.js b/tests/baselines/reference/functionExpressionContextualTyping.js new file mode 100644 index 00000000000..a0ca1a928ce --- /dev/null +++ b/tests/baselines/reference/functionExpressionContextualTyping.js @@ -0,0 +1,76 @@ +//// [functionExpressionContextualTyping.ts] +enum E { red, blue } + +var g0: (n: number, s:string) => number; +var g: ((s: string, w: boolean) => void) | ((n: number) => number); +var g1: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); + +g1 = (j, m) => { } // Per spec, no contextual signature can be extracted in this case. +g = (k, h=true) => { k.toLowerCase() }; +g = (k) => { k.toLowerCase() }; +g = (i) => { + i.toExponential(); + return i; +}; // Per spec, no contextual signature can be extracted in this case. + +var h: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); +h = (k, h) => { }; + +var i: typeof g0 | ((n: number, s: string) => string); +i = (foo, bar) => { return foo + 1; } +i = (foo, bar) => { return "hello"; } +var j: (name: string, num: number, boo: boolean) => void; +j = (name, number) => { }; + +var k: (n: E) => string = (number = 1) => { return "hello"; }; +var k1: (n: {}) => string = (number = 1) => { return "hello"; }; +class C { + constructor() { + var k: ((j: T, k: U) => (T|U)[]) | ((j: number,k :U) => number[]) = (j, k) => { + return [j, k]; + } // Per spec, no contextual signature can be extracted in this case. + } +} + +//// [functionExpressionContextualTyping.js] +var E; +(function (E) { + E[E["red"] = 0] = "red"; + E[E["blue"] = 1] = "blue"; +})(E || (E = {})); +var g0; +var g; +var g1; +g1 = function (j, m) { }; // Per spec, no contextual signature can be extracted in this case. +g = function (k, h) { + if (h === void 0) { h = true; } + k.toLowerCase(); +}; +g = function (k) { k.toLowerCase(); }; +g = function (i) { + i.toExponential(); + return i; +}; // Per spec, no contextual signature can be extracted in this case. +var h; +h = function (k, h) { }; +var i; +i = function (foo, bar) { return foo + 1; }; +i = function (foo, bar) { return "hello"; }; +var j; +j = function (name, number) { }; +var k = function (number) { + if (number === void 0) { number = 1; } + return "hello"; +}; +var k1 = function (number) { + if (number === void 0) { number = 1; } + return "hello"; +}; +var C = (function () { + function C() { + var k = function (j, k) { + return [j, k]; + }; // Per spec, no contextual signature can be extracted in this case. + } + return C; +})(); diff --git a/tests/baselines/reference/functionExpressionContextualTyping.types b/tests/baselines/reference/functionExpressionContextualTyping.types new file mode 100644 index 00000000000..f6ef4c836ec --- /dev/null +++ b/tests/baselines/reference/functionExpressionContextualTyping.types @@ -0,0 +1,167 @@ +=== tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping.ts === +enum E { red, blue } +>E : E, Symbol(E, Decl(functionExpressionContextualTyping.ts, 0, 0)) +>red : E, Symbol(E.red, Decl(functionExpressionContextualTyping.ts, 0, 8)) +>blue : E, Symbol(E.blue, Decl(functionExpressionContextualTyping.ts, 0, 13)) + +var g0: (n: number, s:string) => number; +>g0 : (n: number, s: string) => number, Symbol(g0, Decl(functionExpressionContextualTyping.ts, 2, 3)) +>n : number, Symbol(n, Decl(functionExpressionContextualTyping.ts, 2, 9)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 2, 19)) + +var g: ((s: string, w: boolean) => void) | ((n: number) => number); +>g : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(g, Decl(functionExpressionContextualTyping.ts, 3, 3)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 3, 9)) +>w : boolean, Symbol(w, Decl(functionExpressionContextualTyping.ts, 3, 19)) +>n : number, Symbol(n, Decl(functionExpressionContextualTyping.ts, 3, 45)) + +var g1: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); +>g1 : ((s: string, w: boolean) => void) | ((s: string, w: number) => string), Symbol(g1, Decl(functionExpressionContextualTyping.ts, 4, 3)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 4, 10)) +>w : boolean, Symbol(w, Decl(functionExpressionContextualTyping.ts, 4, 20)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 4, 46)) +>w : number, Symbol(w, Decl(functionExpressionContextualTyping.ts, 4, 56)) + +g1 = (j, m) => { } // Per spec, no contextual signature can be extracted in this case. +>g1 = (j, m) => { } : (j: any, m: any) => void +>g1 : ((s: string, w: boolean) => void) | ((s: string, w: number) => string), Symbol(g1, Decl(functionExpressionContextualTyping.ts, 4, 3)) +>(j, m) => { } : (j: any, m: any) => void +>j : any, Symbol(j, Decl(functionExpressionContextualTyping.ts, 6, 6)) +>m : any, Symbol(m, Decl(functionExpressionContextualTyping.ts, 6, 8)) + +g = (k, h=true) => { k.toLowerCase() }; +>g = (k, h=true) => { k.toLowerCase() } : (k: any, h?: boolean) => void +>g : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(g, Decl(functionExpressionContextualTyping.ts, 3, 3)) +>(k, h=true) => { k.toLowerCase() } : (k: any, h?: boolean) => void +>k : any, Symbol(k, Decl(functionExpressionContextualTyping.ts, 7, 5)) +>h : boolean, Symbol(h, Decl(functionExpressionContextualTyping.ts, 7, 7)) +>true : boolean +>k.toLowerCase() : any +>k.toLowerCase : any +>k : any, Symbol(k, Decl(functionExpressionContextualTyping.ts, 7, 5)) +>toLowerCase : any + +g = (k) => { k.toLowerCase() }; +>g = (k) => { k.toLowerCase() } : (k: any) => void +>g : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(g, Decl(functionExpressionContextualTyping.ts, 3, 3)) +>(k) => { k.toLowerCase() } : (k: any) => void +>k : any, Symbol(k, Decl(functionExpressionContextualTyping.ts, 8, 5)) +>k.toLowerCase() : any +>k.toLowerCase : any +>k : any, Symbol(k, Decl(functionExpressionContextualTyping.ts, 8, 5)) +>toLowerCase : any + +g = (i) => { +>g = (i) => { i.toExponential(); return i;} : (i: any) => any +>g : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(g, Decl(functionExpressionContextualTyping.ts, 3, 3)) +>(i) => { i.toExponential(); return i;} : (i: any) => any +>i : any, Symbol(i, Decl(functionExpressionContextualTyping.ts, 9, 5)) + + i.toExponential(); +>i.toExponential() : any +>i.toExponential : any +>i : any, Symbol(i, Decl(functionExpressionContextualTyping.ts, 9, 5)) +>toExponential : any + + return i; +>i : any, Symbol(i, Decl(functionExpressionContextualTyping.ts, 9, 5)) + +}; // Per spec, no contextual signature can be extracted in this case. + +var h: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); +>h : ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string), Symbol(h, Decl(functionExpressionContextualTyping.ts, 14, 3)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 14, 9)) +>w : boolean, Symbol(w, Decl(functionExpressionContextualTyping.ts, 14, 19)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 14, 45)) +>w : boolean, Symbol(w, Decl(functionExpressionContextualTyping.ts, 14, 55)) + +h = (k, h) => { }; +>h = (k, h) => { } : (k: string, h: boolean) => void +>h : ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string), Symbol(h, Decl(functionExpressionContextualTyping.ts, 14, 3)) +>(k, h) => { } : (k: string, h: boolean) => void +>k : string, Symbol(k, Decl(functionExpressionContextualTyping.ts, 15, 5)) +>h : boolean, Symbol(h, Decl(functionExpressionContextualTyping.ts, 15, 7)) + +var i: typeof g0 | ((n: number, s: string) => string); +>i : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(i, Decl(functionExpressionContextualTyping.ts, 17, 3)) +>g0 : (n: number, s: string) => number, Symbol(g0, Decl(functionExpressionContextualTyping.ts, 2, 3)) +>n : number, Symbol(n, Decl(functionExpressionContextualTyping.ts, 17, 21)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 17, 31)) + +i = (foo, bar) => { return foo + 1; } +>i = (foo, bar) => { return foo + 1; } : (foo: number, bar: string) => number +>i : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(i, Decl(functionExpressionContextualTyping.ts, 17, 3)) +>(foo, bar) => { return foo + 1; } : (foo: number, bar: string) => number +>foo : number, Symbol(foo, Decl(functionExpressionContextualTyping.ts, 18, 5)) +>bar : string, Symbol(bar, Decl(functionExpressionContextualTyping.ts, 18, 9)) +>foo + 1 : number +>foo : number, Symbol(foo, Decl(functionExpressionContextualTyping.ts, 18, 5)) +>1 : number + +i = (foo, bar) => { return "hello"; } +>i = (foo, bar) => { return "hello"; } : (foo: number, bar: string) => string +>i : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(i, Decl(functionExpressionContextualTyping.ts, 17, 3)) +>(foo, bar) => { return "hello"; } : (foo: number, bar: string) => string +>foo : number, Symbol(foo, Decl(functionExpressionContextualTyping.ts, 19, 5)) +>bar : string, Symbol(bar, Decl(functionExpressionContextualTyping.ts, 19, 9)) +>"hello" : string + +var j: (name: string, num: number, boo: boolean) => void; +>j : (name: string, num: number, boo: boolean) => void, Symbol(j, Decl(functionExpressionContextualTyping.ts, 20, 3)) +>name : string, Symbol(name, Decl(functionExpressionContextualTyping.ts, 20, 8)) +>num : number, Symbol(num, Decl(functionExpressionContextualTyping.ts, 20, 21)) +>boo : boolean, Symbol(boo, Decl(functionExpressionContextualTyping.ts, 20, 34)) + +j = (name, number) => { }; +>j = (name, number) => { } : (name: string, number: number) => void +>j : (name: string, num: number, boo: boolean) => void, Symbol(j, Decl(functionExpressionContextualTyping.ts, 20, 3)) +>(name, number) => { } : (name: string, number: number) => void +>name : string, Symbol(name, Decl(functionExpressionContextualTyping.ts, 21, 5)) +>number : number, Symbol(number, Decl(functionExpressionContextualTyping.ts, 21, 10)) + +var k: (n: E) => string = (number = 1) => { return "hello"; }; +>k : (n: E) => string, Symbol(k, Decl(functionExpressionContextualTyping.ts, 23, 3)) +>n : E, Symbol(n, Decl(functionExpressionContextualTyping.ts, 23, 8)) +>E : E, Symbol(E, Decl(functionExpressionContextualTyping.ts, 0, 0)) +>(number = 1) => { return "hello"; } : (number?: E) => string +>number : E, Symbol(number, Decl(functionExpressionContextualTyping.ts, 23, 27)) +>1 : number +>"hello" : string + +var k1: (n: {}) => string = (number = 1) => { return "hello"; }; +>k1 : (n: {}) => string, Symbol(k1, Decl(functionExpressionContextualTyping.ts, 24, 3)) +>n : {}, Symbol(n, Decl(functionExpressionContextualTyping.ts, 24, 9)) +>(number = 1) => { return "hello"; } : (number?: {}) => string +>number : {}, Symbol(number, Decl(functionExpressionContextualTyping.ts, 24, 29)) +>1 : number +>"hello" : string + +class C { +>C : C, Symbol(C, Decl(functionExpressionContextualTyping.ts, 24, 64)) +>T : T, Symbol(T, Decl(functionExpressionContextualTyping.ts, 25, 8)) +>U : U, Symbol(U, Decl(functionExpressionContextualTyping.ts, 25, 10)) + + constructor() { + var k: ((j: T, k: U) => (T|U)[]) | ((j: number,k :U) => number[]) = (j, k) => { +>k : ((j: T, k: U) => (T | U)[]) | ((j: number, k: U) => number[]), Symbol(k, Decl(functionExpressionContextualTyping.ts, 27, 11)) +>j : T, Symbol(j, Decl(functionExpressionContextualTyping.ts, 27, 17)) +>T : T, Symbol(T, Decl(functionExpressionContextualTyping.ts, 25, 8)) +>k : U, Symbol(k, Decl(functionExpressionContextualTyping.ts, 27, 22)) +>U : U, Symbol(U, Decl(functionExpressionContextualTyping.ts, 25, 10)) +>T : T, Symbol(T, Decl(functionExpressionContextualTyping.ts, 25, 8)) +>U : U, Symbol(U, Decl(functionExpressionContextualTyping.ts, 25, 10)) +>j : number, Symbol(j, Decl(functionExpressionContextualTyping.ts, 27, 45)) +>k : U, Symbol(k, Decl(functionExpressionContextualTyping.ts, 27, 55)) +>U : U, Symbol(U, Decl(functionExpressionContextualTyping.ts, 25, 10)) +>(j, k) => { return [j, k]; } : (j: any, k: any) => any[] +>j : any, Symbol(j, Decl(functionExpressionContextualTyping.ts, 27, 77)) +>k : any, Symbol(k, Decl(functionExpressionContextualTyping.ts, 27, 79)) + + return [j, k]; +>[j, k] : any[] +>j : any, Symbol(j, Decl(functionExpressionContextualTyping.ts, 27, 77)) +>k : any, Symbol(k, Decl(functionExpressionContextualTyping.ts, 27, 79)) + + } // Per spec, no contextual signature can be extracted in this case. + } +} diff --git a/tests/baselines/reference/functionExpressionContextualTyping1.errors.txt b/tests/baselines/reference/functionExpressionContextualTyping1.errors.txt new file mode 100644 index 00000000000..fa69806ca3a --- /dev/null +++ b/tests/baselines/reference/functionExpressionContextualTyping1.errors.txt @@ -0,0 +1,36 @@ +tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts(3,1): error TS2322: Type '(foo: number, bar: string) => boolean' is not assignable to type '((n: number, s: string) => number) | ((n: number, s: string) => string)'. + Type '(foo: number, bar: string) => boolean' is not assignable to type '(n: number, s: string) => string'. + Type 'boolean' is not assignable to type 'string'. +tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts(5,7): error TS2300: Duplicate identifier 'C'. +tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts(8,7): error TS2300: Duplicate identifier 'C'. +tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts(10,43): error TS2322: Type 'number' is not assignable to type 'T'. +tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts(10,50): error TS2322: Type 'number' is not assignable to type 'U'. + + +==== tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts (5 errors) ==== + var g0: (n: number, s: string) => number + var i: typeof g0 | ((n: number, s: string) => string); + i = (foo, bar) => { return true; } + ~ +!!! error TS2322: Type '(foo: number, bar: string) => boolean' is not assignable to type '((n: number, s: string) => number) | ((n: number, s: string) => string)'. +!!! error TS2322: Type '(foo: number, bar: string) => boolean' is not assignable to type '(n: number, s: string) => string'. +!!! error TS2322: Type 'boolean' is not assignable to type 'string'. + + class C { } + ~ +!!! error TS2300: Duplicate identifier 'C'. + + var j: (c: C) => number = (j) => { return 1; } + class C { + ~ +!!! error TS2300: Duplicate identifier 'C'. + constructor() { + var k: (j: T, k: U) => (T|U)[] = (j = 1, k = 0) => { + ~~~~~ +!!! error TS2322: Type 'number' is not assignable to type 'T'. + ~~~~~ +!!! error TS2322: Type 'number' is not assignable to type 'U'. + return [j, k]; + } + } + } \ No newline at end of file diff --git a/tests/baselines/reference/functionExpressionContextualTyping1.js b/tests/baselines/reference/functionExpressionContextualTyping1.js new file mode 100644 index 00000000000..f0331c84070 --- /dev/null +++ b/tests/baselines/reference/functionExpressionContextualTyping1.js @@ -0,0 +1,36 @@ +//// [functionExpressionContextualTyping1.ts] +var g0: (n: number, s: string) => number +var i: typeof g0 | ((n: number, s: string) => string); +i = (foo, bar) => { return true; } + +class C { } + +var j: (c: C) => number = (j) => { return 1; } +class C { + constructor() { + var k: (j: T, k: U) => (T|U)[] = (j = 1, k = 0) => { + return [j, k]; + } + } +} + +//// [functionExpressionContextualTyping1.js] +var g0; +var i; +i = function (foo, bar) { return true; }; +var C = (function () { + function C() { + } + return C; +})(); +var j = function (j) { return 1; }; +var C = (function () { + function C() { + var k = function (j, k) { + if (j === void 0) { j = 1; } + if (k === void 0) { k = 0; } + return [j, k]; + }; + } + return C; +})(); diff --git a/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping.ts b/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping.ts new file mode 100644 index 00000000000..1ede1c3fa72 --- /dev/null +++ b/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping.ts @@ -0,0 +1,32 @@ +enum E { red, blue } + +var g0: (n: number, s:string) => number; +var g: ((s: string, w: boolean) => void) | ((n: number) => number); +var g1: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); + +g1 = (j, m) => { } // Per spec, no contextual signature can be extracted in this case. +g = (k, h=true) => { k.toLowerCase() }; +g = (k) => { k.toLowerCase() }; +g = (i) => { + i.toExponential(); + return i; +}; // Per spec, no contextual signature can be extracted in this case. + +var h: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); +h = (k, h) => { }; + +var i: typeof g0 | ((n: number, s: string) => string); +i = (foo, bar) => { return foo + 1; } +i = (foo, bar) => { return "hello"; } +var j: (name: string, num: number, boo: boolean) => void; +j = (name, number) => { }; + +var k: (n: E) => string = (number = 1) => { return "hello"; }; +var k1: (n: {}) => string = (number = 1) => { return "hello"; }; +class C { + constructor() { + var k: ((j: T, k: U) => (T|U)[]) | ((j: number,k :U) => number[]) = (j, k) => { + return [j, k]; + } // Per spec, no contextual signature can be extracted in this case. + } +} \ No newline at end of file diff --git a/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts b/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts new file mode 100644 index 00000000000..d22fff7e138 --- /dev/null +++ b/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts @@ -0,0 +1,14 @@ +var g0: (n: number, s: string) => number +var i: typeof g0 | ((n: number, s: string) => string); +i = (foo, bar) => { return true; } + +class C { } + +var j: (c: C) => number = (j) => { return 1; } +class C { + constructor() { + var k: (j: T, k: U) => (T|U)[] = (j = 1, k = 0) => { + return [j, k]; + } + } +} \ No newline at end of file From 85af749239f1c73e1f8d934bba7f9bdaafe7809e Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 14 Apr 2015 12:55:54 -0700 Subject: [PATCH 022/194] Change file name to be more consistent --- .../functionExpressionContextualTyping.js | 76 -------- .../functionExpressionContextualTyping.types | 167 ------------------ ...tionExpressionContextualTyping1.errors.txt | 36 ---- .../functionExpressionContextualTyping.ts | 32 ---- .../functionExpressionContextualTyping1.ts | 32 +++- 5 files changed, 25 insertions(+), 318 deletions(-) delete mode 100644 tests/baselines/reference/functionExpressionContextualTyping.js delete mode 100644 tests/baselines/reference/functionExpressionContextualTyping.types delete mode 100644 tests/baselines/reference/functionExpressionContextualTyping1.errors.txt delete mode 100644 tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping.ts diff --git a/tests/baselines/reference/functionExpressionContextualTyping.js b/tests/baselines/reference/functionExpressionContextualTyping.js deleted file mode 100644 index a0ca1a928ce..00000000000 --- a/tests/baselines/reference/functionExpressionContextualTyping.js +++ /dev/null @@ -1,76 +0,0 @@ -//// [functionExpressionContextualTyping.ts] -enum E { red, blue } - -var g0: (n: number, s:string) => number; -var g: ((s: string, w: boolean) => void) | ((n: number) => number); -var g1: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); - -g1 = (j, m) => { } // Per spec, no contextual signature can be extracted in this case. -g = (k, h=true) => { k.toLowerCase() }; -g = (k) => { k.toLowerCase() }; -g = (i) => { - i.toExponential(); - return i; -}; // Per spec, no contextual signature can be extracted in this case. - -var h: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); -h = (k, h) => { }; - -var i: typeof g0 | ((n: number, s: string) => string); -i = (foo, bar) => { return foo + 1; } -i = (foo, bar) => { return "hello"; } -var j: (name: string, num: number, boo: boolean) => void; -j = (name, number) => { }; - -var k: (n: E) => string = (number = 1) => { return "hello"; }; -var k1: (n: {}) => string = (number = 1) => { return "hello"; }; -class C { - constructor() { - var k: ((j: T, k: U) => (T|U)[]) | ((j: number,k :U) => number[]) = (j, k) => { - return [j, k]; - } // Per spec, no contextual signature can be extracted in this case. - } -} - -//// [functionExpressionContextualTyping.js] -var E; -(function (E) { - E[E["red"] = 0] = "red"; - E[E["blue"] = 1] = "blue"; -})(E || (E = {})); -var g0; -var g; -var g1; -g1 = function (j, m) { }; // Per spec, no contextual signature can be extracted in this case. -g = function (k, h) { - if (h === void 0) { h = true; } - k.toLowerCase(); -}; -g = function (k) { k.toLowerCase(); }; -g = function (i) { - i.toExponential(); - return i; -}; // Per spec, no contextual signature can be extracted in this case. -var h; -h = function (k, h) { }; -var i; -i = function (foo, bar) { return foo + 1; }; -i = function (foo, bar) { return "hello"; }; -var j; -j = function (name, number) { }; -var k = function (number) { - if (number === void 0) { number = 1; } - return "hello"; -}; -var k1 = function (number) { - if (number === void 0) { number = 1; } - return "hello"; -}; -var C = (function () { - function C() { - var k = function (j, k) { - return [j, k]; - }; // Per spec, no contextual signature can be extracted in this case. - } - return C; -})(); diff --git a/tests/baselines/reference/functionExpressionContextualTyping.types b/tests/baselines/reference/functionExpressionContextualTyping.types deleted file mode 100644 index f6ef4c836ec..00000000000 --- a/tests/baselines/reference/functionExpressionContextualTyping.types +++ /dev/null @@ -1,167 +0,0 @@ -=== tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping.ts === -enum E { red, blue } ->E : E, Symbol(E, Decl(functionExpressionContextualTyping.ts, 0, 0)) ->red : E, Symbol(E.red, Decl(functionExpressionContextualTyping.ts, 0, 8)) ->blue : E, Symbol(E.blue, Decl(functionExpressionContextualTyping.ts, 0, 13)) - -var g0: (n: number, s:string) => number; ->g0 : (n: number, s: string) => number, Symbol(g0, Decl(functionExpressionContextualTyping.ts, 2, 3)) ->n : number, Symbol(n, Decl(functionExpressionContextualTyping.ts, 2, 9)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 2, 19)) - -var g: ((s: string, w: boolean) => void) | ((n: number) => number); ->g : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(g, Decl(functionExpressionContextualTyping.ts, 3, 3)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 3, 9)) ->w : boolean, Symbol(w, Decl(functionExpressionContextualTyping.ts, 3, 19)) ->n : number, Symbol(n, Decl(functionExpressionContextualTyping.ts, 3, 45)) - -var g1: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); ->g1 : ((s: string, w: boolean) => void) | ((s: string, w: number) => string), Symbol(g1, Decl(functionExpressionContextualTyping.ts, 4, 3)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 4, 10)) ->w : boolean, Symbol(w, Decl(functionExpressionContextualTyping.ts, 4, 20)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 4, 46)) ->w : number, Symbol(w, Decl(functionExpressionContextualTyping.ts, 4, 56)) - -g1 = (j, m) => { } // Per spec, no contextual signature can be extracted in this case. ->g1 = (j, m) => { } : (j: any, m: any) => void ->g1 : ((s: string, w: boolean) => void) | ((s: string, w: number) => string), Symbol(g1, Decl(functionExpressionContextualTyping.ts, 4, 3)) ->(j, m) => { } : (j: any, m: any) => void ->j : any, Symbol(j, Decl(functionExpressionContextualTyping.ts, 6, 6)) ->m : any, Symbol(m, Decl(functionExpressionContextualTyping.ts, 6, 8)) - -g = (k, h=true) => { k.toLowerCase() }; ->g = (k, h=true) => { k.toLowerCase() } : (k: any, h?: boolean) => void ->g : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(g, Decl(functionExpressionContextualTyping.ts, 3, 3)) ->(k, h=true) => { k.toLowerCase() } : (k: any, h?: boolean) => void ->k : any, Symbol(k, Decl(functionExpressionContextualTyping.ts, 7, 5)) ->h : boolean, Symbol(h, Decl(functionExpressionContextualTyping.ts, 7, 7)) ->true : boolean ->k.toLowerCase() : any ->k.toLowerCase : any ->k : any, Symbol(k, Decl(functionExpressionContextualTyping.ts, 7, 5)) ->toLowerCase : any - -g = (k) => { k.toLowerCase() }; ->g = (k) => { k.toLowerCase() } : (k: any) => void ->g : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(g, Decl(functionExpressionContextualTyping.ts, 3, 3)) ->(k) => { k.toLowerCase() } : (k: any) => void ->k : any, Symbol(k, Decl(functionExpressionContextualTyping.ts, 8, 5)) ->k.toLowerCase() : any ->k.toLowerCase : any ->k : any, Symbol(k, Decl(functionExpressionContextualTyping.ts, 8, 5)) ->toLowerCase : any - -g = (i) => { ->g = (i) => { i.toExponential(); return i;} : (i: any) => any ->g : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(g, Decl(functionExpressionContextualTyping.ts, 3, 3)) ->(i) => { i.toExponential(); return i;} : (i: any) => any ->i : any, Symbol(i, Decl(functionExpressionContextualTyping.ts, 9, 5)) - - i.toExponential(); ->i.toExponential() : any ->i.toExponential : any ->i : any, Symbol(i, Decl(functionExpressionContextualTyping.ts, 9, 5)) ->toExponential : any - - return i; ->i : any, Symbol(i, Decl(functionExpressionContextualTyping.ts, 9, 5)) - -}; // Per spec, no contextual signature can be extracted in this case. - -var h: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); ->h : ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string), Symbol(h, Decl(functionExpressionContextualTyping.ts, 14, 3)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 14, 9)) ->w : boolean, Symbol(w, Decl(functionExpressionContextualTyping.ts, 14, 19)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 14, 45)) ->w : boolean, Symbol(w, Decl(functionExpressionContextualTyping.ts, 14, 55)) - -h = (k, h) => { }; ->h = (k, h) => { } : (k: string, h: boolean) => void ->h : ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string), Symbol(h, Decl(functionExpressionContextualTyping.ts, 14, 3)) ->(k, h) => { } : (k: string, h: boolean) => void ->k : string, Symbol(k, Decl(functionExpressionContextualTyping.ts, 15, 5)) ->h : boolean, Symbol(h, Decl(functionExpressionContextualTyping.ts, 15, 7)) - -var i: typeof g0 | ((n: number, s: string) => string); ->i : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(i, Decl(functionExpressionContextualTyping.ts, 17, 3)) ->g0 : (n: number, s: string) => number, Symbol(g0, Decl(functionExpressionContextualTyping.ts, 2, 3)) ->n : number, Symbol(n, Decl(functionExpressionContextualTyping.ts, 17, 21)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 17, 31)) - -i = (foo, bar) => { return foo + 1; } ->i = (foo, bar) => { return foo + 1; } : (foo: number, bar: string) => number ->i : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(i, Decl(functionExpressionContextualTyping.ts, 17, 3)) ->(foo, bar) => { return foo + 1; } : (foo: number, bar: string) => number ->foo : number, Symbol(foo, Decl(functionExpressionContextualTyping.ts, 18, 5)) ->bar : string, Symbol(bar, Decl(functionExpressionContextualTyping.ts, 18, 9)) ->foo + 1 : number ->foo : number, Symbol(foo, Decl(functionExpressionContextualTyping.ts, 18, 5)) ->1 : number - -i = (foo, bar) => { return "hello"; } ->i = (foo, bar) => { return "hello"; } : (foo: number, bar: string) => string ->i : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(i, Decl(functionExpressionContextualTyping.ts, 17, 3)) ->(foo, bar) => { return "hello"; } : (foo: number, bar: string) => string ->foo : number, Symbol(foo, Decl(functionExpressionContextualTyping.ts, 19, 5)) ->bar : string, Symbol(bar, Decl(functionExpressionContextualTyping.ts, 19, 9)) ->"hello" : string - -var j: (name: string, num: number, boo: boolean) => void; ->j : (name: string, num: number, boo: boolean) => void, Symbol(j, Decl(functionExpressionContextualTyping.ts, 20, 3)) ->name : string, Symbol(name, Decl(functionExpressionContextualTyping.ts, 20, 8)) ->num : number, Symbol(num, Decl(functionExpressionContextualTyping.ts, 20, 21)) ->boo : boolean, Symbol(boo, Decl(functionExpressionContextualTyping.ts, 20, 34)) - -j = (name, number) => { }; ->j = (name, number) => { } : (name: string, number: number) => void ->j : (name: string, num: number, boo: boolean) => void, Symbol(j, Decl(functionExpressionContextualTyping.ts, 20, 3)) ->(name, number) => { } : (name: string, number: number) => void ->name : string, Symbol(name, Decl(functionExpressionContextualTyping.ts, 21, 5)) ->number : number, Symbol(number, Decl(functionExpressionContextualTyping.ts, 21, 10)) - -var k: (n: E) => string = (number = 1) => { return "hello"; }; ->k : (n: E) => string, Symbol(k, Decl(functionExpressionContextualTyping.ts, 23, 3)) ->n : E, Symbol(n, Decl(functionExpressionContextualTyping.ts, 23, 8)) ->E : E, Symbol(E, Decl(functionExpressionContextualTyping.ts, 0, 0)) ->(number = 1) => { return "hello"; } : (number?: E) => string ->number : E, Symbol(number, Decl(functionExpressionContextualTyping.ts, 23, 27)) ->1 : number ->"hello" : string - -var k1: (n: {}) => string = (number = 1) => { return "hello"; }; ->k1 : (n: {}) => string, Symbol(k1, Decl(functionExpressionContextualTyping.ts, 24, 3)) ->n : {}, Symbol(n, Decl(functionExpressionContextualTyping.ts, 24, 9)) ->(number = 1) => { return "hello"; } : (number?: {}) => string ->number : {}, Symbol(number, Decl(functionExpressionContextualTyping.ts, 24, 29)) ->1 : number ->"hello" : string - -class C { ->C : C, Symbol(C, Decl(functionExpressionContextualTyping.ts, 24, 64)) ->T : T, Symbol(T, Decl(functionExpressionContextualTyping.ts, 25, 8)) ->U : U, Symbol(U, Decl(functionExpressionContextualTyping.ts, 25, 10)) - - constructor() { - var k: ((j: T, k: U) => (T|U)[]) | ((j: number,k :U) => number[]) = (j, k) => { ->k : ((j: T, k: U) => (T | U)[]) | ((j: number, k: U) => number[]), Symbol(k, Decl(functionExpressionContextualTyping.ts, 27, 11)) ->j : T, Symbol(j, Decl(functionExpressionContextualTyping.ts, 27, 17)) ->T : T, Symbol(T, Decl(functionExpressionContextualTyping.ts, 25, 8)) ->k : U, Symbol(k, Decl(functionExpressionContextualTyping.ts, 27, 22)) ->U : U, Symbol(U, Decl(functionExpressionContextualTyping.ts, 25, 10)) ->T : T, Symbol(T, Decl(functionExpressionContextualTyping.ts, 25, 8)) ->U : U, Symbol(U, Decl(functionExpressionContextualTyping.ts, 25, 10)) ->j : number, Symbol(j, Decl(functionExpressionContextualTyping.ts, 27, 45)) ->k : U, Symbol(k, Decl(functionExpressionContextualTyping.ts, 27, 55)) ->U : U, Symbol(U, Decl(functionExpressionContextualTyping.ts, 25, 10)) ->(j, k) => { return [j, k]; } : (j: any, k: any) => any[] ->j : any, Symbol(j, Decl(functionExpressionContextualTyping.ts, 27, 77)) ->k : any, Symbol(k, Decl(functionExpressionContextualTyping.ts, 27, 79)) - - return [j, k]; ->[j, k] : any[] ->j : any, Symbol(j, Decl(functionExpressionContextualTyping.ts, 27, 77)) ->k : any, Symbol(k, Decl(functionExpressionContextualTyping.ts, 27, 79)) - - } // Per spec, no contextual signature can be extracted in this case. - } -} diff --git a/tests/baselines/reference/functionExpressionContextualTyping1.errors.txt b/tests/baselines/reference/functionExpressionContextualTyping1.errors.txt deleted file mode 100644 index fa69806ca3a..00000000000 --- a/tests/baselines/reference/functionExpressionContextualTyping1.errors.txt +++ /dev/null @@ -1,36 +0,0 @@ -tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts(3,1): error TS2322: Type '(foo: number, bar: string) => boolean' is not assignable to type '((n: number, s: string) => number) | ((n: number, s: string) => string)'. - Type '(foo: number, bar: string) => boolean' is not assignable to type '(n: number, s: string) => string'. - Type 'boolean' is not assignable to type 'string'. -tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts(5,7): error TS2300: Duplicate identifier 'C'. -tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts(8,7): error TS2300: Duplicate identifier 'C'. -tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts(10,43): error TS2322: Type 'number' is not assignable to type 'T'. -tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts(10,50): error TS2322: Type 'number' is not assignable to type 'U'. - - -==== tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts (5 errors) ==== - var g0: (n: number, s: string) => number - var i: typeof g0 | ((n: number, s: string) => string); - i = (foo, bar) => { return true; } - ~ -!!! error TS2322: Type '(foo: number, bar: string) => boolean' is not assignable to type '((n: number, s: string) => number) | ((n: number, s: string) => string)'. -!!! error TS2322: Type '(foo: number, bar: string) => boolean' is not assignable to type '(n: number, s: string) => string'. -!!! error TS2322: Type 'boolean' is not assignable to type 'string'. - - class C { } - ~ -!!! error TS2300: Duplicate identifier 'C'. - - var j: (c: C) => number = (j) => { return 1; } - class C { - ~ -!!! error TS2300: Duplicate identifier 'C'. - constructor() { - var k: (j: T, k: U) => (T|U)[] = (j = 1, k = 0) => { - ~~~~~ -!!! error TS2322: Type 'number' is not assignable to type 'T'. - ~~~~~ -!!! error TS2322: Type 'number' is not assignable to type 'U'. - return [j, k]; - } - } - } \ No newline at end of file diff --git a/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping.ts b/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping.ts deleted file mode 100644 index 1ede1c3fa72..00000000000 --- a/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping.ts +++ /dev/null @@ -1,32 +0,0 @@ -enum E { red, blue } - -var g0: (n: number, s:string) => number; -var g: ((s: string, w: boolean) => void) | ((n: number) => number); -var g1: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); - -g1 = (j, m) => { } // Per spec, no contextual signature can be extracted in this case. -g = (k, h=true) => { k.toLowerCase() }; -g = (k) => { k.toLowerCase() }; -g = (i) => { - i.toExponential(); - return i; -}; // Per spec, no contextual signature can be extracted in this case. - -var h: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); -h = (k, h) => { }; - -var i: typeof g0 | ((n: number, s: string) => string); -i = (foo, bar) => { return foo + 1; } -i = (foo, bar) => { return "hello"; } -var j: (name: string, num: number, boo: boolean) => void; -j = (name, number) => { }; - -var k: (n: E) => string = (number = 1) => { return "hello"; }; -var k1: (n: {}) => string = (number = 1) => { return "hello"; }; -class C { - constructor() { - var k: ((j: T, k: U) => (T|U)[]) | ((j: number,k :U) => number[]) = (j, k) => { - return [j, k]; - } // Per spec, no contextual signature can be extracted in this case. - } -} \ No newline at end of file diff --git a/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts b/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts index d22fff7e138..1ede1c3fa72 100644 --- a/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts +++ b/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts @@ -1,14 +1,32 @@ -var g0: (n: number, s: string) => number +enum E { red, blue } + +var g0: (n: number, s:string) => number; +var g: ((s: string, w: boolean) => void) | ((n: number) => number); +var g1: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); + +g1 = (j, m) => { } // Per spec, no contextual signature can be extracted in this case. +g = (k, h=true) => { k.toLowerCase() }; +g = (k) => { k.toLowerCase() }; +g = (i) => { + i.toExponential(); + return i; +}; // Per spec, no contextual signature can be extracted in this case. + +var h: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); +h = (k, h) => { }; + var i: typeof g0 | ((n: number, s: string) => string); -i = (foo, bar) => { return true; } +i = (foo, bar) => { return foo + 1; } +i = (foo, bar) => { return "hello"; } +var j: (name: string, num: number, boo: boolean) => void; +j = (name, number) => { }; -class C { } - -var j: (c: C) => number = (j) => { return 1; } +var k: (n: E) => string = (number = 1) => { return "hello"; }; +var k1: (n: {}) => string = (number = 1) => { return "hello"; }; class C { constructor() { - var k: (j: T, k: U) => (T|U)[] = (j = 1, k = 0) => { + var k: ((j: T, k: U) => (T|U)[]) | ((j: number,k :U) => number[]) = (j, k) => { return [j, k]; - } + } // Per spec, no contextual signature can be extracted in this case. } } \ No newline at end of file From 496e23881b852c62d3ea564b470211ef220511fb Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 14 Apr 2015 12:55:54 -0700 Subject: [PATCH 023/194] Change file name to be more consistent --- .../functionExpressionContextualTyping.js | 76 -------- .../functionExpressionContextualTyping.types | 167 ------------------ ...tionExpressionContextualTyping1.errors.txt | 36 ---- .../functionExpressionContextualTyping.ts | 32 ---- .../functionExpressionContextualTyping1.ts | 32 +++- .../functionExpressionContextualTyping2.ts | 14 ++ 6 files changed, 39 insertions(+), 318 deletions(-) delete mode 100644 tests/baselines/reference/functionExpressionContextualTyping.js delete mode 100644 tests/baselines/reference/functionExpressionContextualTyping.types delete mode 100644 tests/baselines/reference/functionExpressionContextualTyping1.errors.txt delete mode 100644 tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping.ts create mode 100644 tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts diff --git a/tests/baselines/reference/functionExpressionContextualTyping.js b/tests/baselines/reference/functionExpressionContextualTyping.js deleted file mode 100644 index a0ca1a928ce..00000000000 --- a/tests/baselines/reference/functionExpressionContextualTyping.js +++ /dev/null @@ -1,76 +0,0 @@ -//// [functionExpressionContextualTyping.ts] -enum E { red, blue } - -var g0: (n: number, s:string) => number; -var g: ((s: string, w: boolean) => void) | ((n: number) => number); -var g1: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); - -g1 = (j, m) => { } // Per spec, no contextual signature can be extracted in this case. -g = (k, h=true) => { k.toLowerCase() }; -g = (k) => { k.toLowerCase() }; -g = (i) => { - i.toExponential(); - return i; -}; // Per spec, no contextual signature can be extracted in this case. - -var h: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); -h = (k, h) => { }; - -var i: typeof g0 | ((n: number, s: string) => string); -i = (foo, bar) => { return foo + 1; } -i = (foo, bar) => { return "hello"; } -var j: (name: string, num: number, boo: boolean) => void; -j = (name, number) => { }; - -var k: (n: E) => string = (number = 1) => { return "hello"; }; -var k1: (n: {}) => string = (number = 1) => { return "hello"; }; -class C { - constructor() { - var k: ((j: T, k: U) => (T|U)[]) | ((j: number,k :U) => number[]) = (j, k) => { - return [j, k]; - } // Per spec, no contextual signature can be extracted in this case. - } -} - -//// [functionExpressionContextualTyping.js] -var E; -(function (E) { - E[E["red"] = 0] = "red"; - E[E["blue"] = 1] = "blue"; -})(E || (E = {})); -var g0; -var g; -var g1; -g1 = function (j, m) { }; // Per spec, no contextual signature can be extracted in this case. -g = function (k, h) { - if (h === void 0) { h = true; } - k.toLowerCase(); -}; -g = function (k) { k.toLowerCase(); }; -g = function (i) { - i.toExponential(); - return i; -}; // Per spec, no contextual signature can be extracted in this case. -var h; -h = function (k, h) { }; -var i; -i = function (foo, bar) { return foo + 1; }; -i = function (foo, bar) { return "hello"; }; -var j; -j = function (name, number) { }; -var k = function (number) { - if (number === void 0) { number = 1; } - return "hello"; -}; -var k1 = function (number) { - if (number === void 0) { number = 1; } - return "hello"; -}; -var C = (function () { - function C() { - var k = function (j, k) { - return [j, k]; - }; // Per spec, no contextual signature can be extracted in this case. - } - return C; -})(); diff --git a/tests/baselines/reference/functionExpressionContextualTyping.types b/tests/baselines/reference/functionExpressionContextualTyping.types deleted file mode 100644 index f6ef4c836ec..00000000000 --- a/tests/baselines/reference/functionExpressionContextualTyping.types +++ /dev/null @@ -1,167 +0,0 @@ -=== tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping.ts === -enum E { red, blue } ->E : E, Symbol(E, Decl(functionExpressionContextualTyping.ts, 0, 0)) ->red : E, Symbol(E.red, Decl(functionExpressionContextualTyping.ts, 0, 8)) ->blue : E, Symbol(E.blue, Decl(functionExpressionContextualTyping.ts, 0, 13)) - -var g0: (n: number, s:string) => number; ->g0 : (n: number, s: string) => number, Symbol(g0, Decl(functionExpressionContextualTyping.ts, 2, 3)) ->n : number, Symbol(n, Decl(functionExpressionContextualTyping.ts, 2, 9)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 2, 19)) - -var g: ((s: string, w: boolean) => void) | ((n: number) => number); ->g : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(g, Decl(functionExpressionContextualTyping.ts, 3, 3)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 3, 9)) ->w : boolean, Symbol(w, Decl(functionExpressionContextualTyping.ts, 3, 19)) ->n : number, Symbol(n, Decl(functionExpressionContextualTyping.ts, 3, 45)) - -var g1: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); ->g1 : ((s: string, w: boolean) => void) | ((s: string, w: number) => string), Symbol(g1, Decl(functionExpressionContextualTyping.ts, 4, 3)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 4, 10)) ->w : boolean, Symbol(w, Decl(functionExpressionContextualTyping.ts, 4, 20)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 4, 46)) ->w : number, Symbol(w, Decl(functionExpressionContextualTyping.ts, 4, 56)) - -g1 = (j, m) => { } // Per spec, no contextual signature can be extracted in this case. ->g1 = (j, m) => { } : (j: any, m: any) => void ->g1 : ((s: string, w: boolean) => void) | ((s: string, w: number) => string), Symbol(g1, Decl(functionExpressionContextualTyping.ts, 4, 3)) ->(j, m) => { } : (j: any, m: any) => void ->j : any, Symbol(j, Decl(functionExpressionContextualTyping.ts, 6, 6)) ->m : any, Symbol(m, Decl(functionExpressionContextualTyping.ts, 6, 8)) - -g = (k, h=true) => { k.toLowerCase() }; ->g = (k, h=true) => { k.toLowerCase() } : (k: any, h?: boolean) => void ->g : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(g, Decl(functionExpressionContextualTyping.ts, 3, 3)) ->(k, h=true) => { k.toLowerCase() } : (k: any, h?: boolean) => void ->k : any, Symbol(k, Decl(functionExpressionContextualTyping.ts, 7, 5)) ->h : boolean, Symbol(h, Decl(functionExpressionContextualTyping.ts, 7, 7)) ->true : boolean ->k.toLowerCase() : any ->k.toLowerCase : any ->k : any, Symbol(k, Decl(functionExpressionContextualTyping.ts, 7, 5)) ->toLowerCase : any - -g = (k) => { k.toLowerCase() }; ->g = (k) => { k.toLowerCase() } : (k: any) => void ->g : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(g, Decl(functionExpressionContextualTyping.ts, 3, 3)) ->(k) => { k.toLowerCase() } : (k: any) => void ->k : any, Symbol(k, Decl(functionExpressionContextualTyping.ts, 8, 5)) ->k.toLowerCase() : any ->k.toLowerCase : any ->k : any, Symbol(k, Decl(functionExpressionContextualTyping.ts, 8, 5)) ->toLowerCase : any - -g = (i) => { ->g = (i) => { i.toExponential(); return i;} : (i: any) => any ->g : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(g, Decl(functionExpressionContextualTyping.ts, 3, 3)) ->(i) => { i.toExponential(); return i;} : (i: any) => any ->i : any, Symbol(i, Decl(functionExpressionContextualTyping.ts, 9, 5)) - - i.toExponential(); ->i.toExponential() : any ->i.toExponential : any ->i : any, Symbol(i, Decl(functionExpressionContextualTyping.ts, 9, 5)) ->toExponential : any - - return i; ->i : any, Symbol(i, Decl(functionExpressionContextualTyping.ts, 9, 5)) - -}; // Per spec, no contextual signature can be extracted in this case. - -var h: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); ->h : ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string), Symbol(h, Decl(functionExpressionContextualTyping.ts, 14, 3)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 14, 9)) ->w : boolean, Symbol(w, Decl(functionExpressionContextualTyping.ts, 14, 19)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 14, 45)) ->w : boolean, Symbol(w, Decl(functionExpressionContextualTyping.ts, 14, 55)) - -h = (k, h) => { }; ->h = (k, h) => { } : (k: string, h: boolean) => void ->h : ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string), Symbol(h, Decl(functionExpressionContextualTyping.ts, 14, 3)) ->(k, h) => { } : (k: string, h: boolean) => void ->k : string, Symbol(k, Decl(functionExpressionContextualTyping.ts, 15, 5)) ->h : boolean, Symbol(h, Decl(functionExpressionContextualTyping.ts, 15, 7)) - -var i: typeof g0 | ((n: number, s: string) => string); ->i : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(i, Decl(functionExpressionContextualTyping.ts, 17, 3)) ->g0 : (n: number, s: string) => number, Symbol(g0, Decl(functionExpressionContextualTyping.ts, 2, 3)) ->n : number, Symbol(n, Decl(functionExpressionContextualTyping.ts, 17, 21)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 17, 31)) - -i = (foo, bar) => { return foo + 1; } ->i = (foo, bar) => { return foo + 1; } : (foo: number, bar: string) => number ->i : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(i, Decl(functionExpressionContextualTyping.ts, 17, 3)) ->(foo, bar) => { return foo + 1; } : (foo: number, bar: string) => number ->foo : number, Symbol(foo, Decl(functionExpressionContextualTyping.ts, 18, 5)) ->bar : string, Symbol(bar, Decl(functionExpressionContextualTyping.ts, 18, 9)) ->foo + 1 : number ->foo : number, Symbol(foo, Decl(functionExpressionContextualTyping.ts, 18, 5)) ->1 : number - -i = (foo, bar) => { return "hello"; } ->i = (foo, bar) => { return "hello"; } : (foo: number, bar: string) => string ->i : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(i, Decl(functionExpressionContextualTyping.ts, 17, 3)) ->(foo, bar) => { return "hello"; } : (foo: number, bar: string) => string ->foo : number, Symbol(foo, Decl(functionExpressionContextualTyping.ts, 19, 5)) ->bar : string, Symbol(bar, Decl(functionExpressionContextualTyping.ts, 19, 9)) ->"hello" : string - -var j: (name: string, num: number, boo: boolean) => void; ->j : (name: string, num: number, boo: boolean) => void, Symbol(j, Decl(functionExpressionContextualTyping.ts, 20, 3)) ->name : string, Symbol(name, Decl(functionExpressionContextualTyping.ts, 20, 8)) ->num : number, Symbol(num, Decl(functionExpressionContextualTyping.ts, 20, 21)) ->boo : boolean, Symbol(boo, Decl(functionExpressionContextualTyping.ts, 20, 34)) - -j = (name, number) => { }; ->j = (name, number) => { } : (name: string, number: number) => void ->j : (name: string, num: number, boo: boolean) => void, Symbol(j, Decl(functionExpressionContextualTyping.ts, 20, 3)) ->(name, number) => { } : (name: string, number: number) => void ->name : string, Symbol(name, Decl(functionExpressionContextualTyping.ts, 21, 5)) ->number : number, Symbol(number, Decl(functionExpressionContextualTyping.ts, 21, 10)) - -var k: (n: E) => string = (number = 1) => { return "hello"; }; ->k : (n: E) => string, Symbol(k, Decl(functionExpressionContextualTyping.ts, 23, 3)) ->n : E, Symbol(n, Decl(functionExpressionContextualTyping.ts, 23, 8)) ->E : E, Symbol(E, Decl(functionExpressionContextualTyping.ts, 0, 0)) ->(number = 1) => { return "hello"; } : (number?: E) => string ->number : E, Symbol(number, Decl(functionExpressionContextualTyping.ts, 23, 27)) ->1 : number ->"hello" : string - -var k1: (n: {}) => string = (number = 1) => { return "hello"; }; ->k1 : (n: {}) => string, Symbol(k1, Decl(functionExpressionContextualTyping.ts, 24, 3)) ->n : {}, Symbol(n, Decl(functionExpressionContextualTyping.ts, 24, 9)) ->(number = 1) => { return "hello"; } : (number?: {}) => string ->number : {}, Symbol(number, Decl(functionExpressionContextualTyping.ts, 24, 29)) ->1 : number ->"hello" : string - -class C { ->C : C, Symbol(C, Decl(functionExpressionContextualTyping.ts, 24, 64)) ->T : T, Symbol(T, Decl(functionExpressionContextualTyping.ts, 25, 8)) ->U : U, Symbol(U, Decl(functionExpressionContextualTyping.ts, 25, 10)) - - constructor() { - var k: ((j: T, k: U) => (T|U)[]) | ((j: number,k :U) => number[]) = (j, k) => { ->k : ((j: T, k: U) => (T | U)[]) | ((j: number, k: U) => number[]), Symbol(k, Decl(functionExpressionContextualTyping.ts, 27, 11)) ->j : T, Symbol(j, Decl(functionExpressionContextualTyping.ts, 27, 17)) ->T : T, Symbol(T, Decl(functionExpressionContextualTyping.ts, 25, 8)) ->k : U, Symbol(k, Decl(functionExpressionContextualTyping.ts, 27, 22)) ->U : U, Symbol(U, Decl(functionExpressionContextualTyping.ts, 25, 10)) ->T : T, Symbol(T, Decl(functionExpressionContextualTyping.ts, 25, 8)) ->U : U, Symbol(U, Decl(functionExpressionContextualTyping.ts, 25, 10)) ->j : number, Symbol(j, Decl(functionExpressionContextualTyping.ts, 27, 45)) ->k : U, Symbol(k, Decl(functionExpressionContextualTyping.ts, 27, 55)) ->U : U, Symbol(U, Decl(functionExpressionContextualTyping.ts, 25, 10)) ->(j, k) => { return [j, k]; } : (j: any, k: any) => any[] ->j : any, Symbol(j, Decl(functionExpressionContextualTyping.ts, 27, 77)) ->k : any, Symbol(k, Decl(functionExpressionContextualTyping.ts, 27, 79)) - - return [j, k]; ->[j, k] : any[] ->j : any, Symbol(j, Decl(functionExpressionContextualTyping.ts, 27, 77)) ->k : any, Symbol(k, Decl(functionExpressionContextualTyping.ts, 27, 79)) - - } // Per spec, no contextual signature can be extracted in this case. - } -} diff --git a/tests/baselines/reference/functionExpressionContextualTyping1.errors.txt b/tests/baselines/reference/functionExpressionContextualTyping1.errors.txt deleted file mode 100644 index fa69806ca3a..00000000000 --- a/tests/baselines/reference/functionExpressionContextualTyping1.errors.txt +++ /dev/null @@ -1,36 +0,0 @@ -tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts(3,1): error TS2322: Type '(foo: number, bar: string) => boolean' is not assignable to type '((n: number, s: string) => number) | ((n: number, s: string) => string)'. - Type '(foo: number, bar: string) => boolean' is not assignable to type '(n: number, s: string) => string'. - Type 'boolean' is not assignable to type 'string'. -tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts(5,7): error TS2300: Duplicate identifier 'C'. -tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts(8,7): error TS2300: Duplicate identifier 'C'. -tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts(10,43): error TS2322: Type 'number' is not assignable to type 'T'. -tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts(10,50): error TS2322: Type 'number' is not assignable to type 'U'. - - -==== tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts (5 errors) ==== - var g0: (n: number, s: string) => number - var i: typeof g0 | ((n: number, s: string) => string); - i = (foo, bar) => { return true; } - ~ -!!! error TS2322: Type '(foo: number, bar: string) => boolean' is not assignable to type '((n: number, s: string) => number) | ((n: number, s: string) => string)'. -!!! error TS2322: Type '(foo: number, bar: string) => boolean' is not assignable to type '(n: number, s: string) => string'. -!!! error TS2322: Type 'boolean' is not assignable to type 'string'. - - class C { } - ~ -!!! error TS2300: Duplicate identifier 'C'. - - var j: (c: C) => number = (j) => { return 1; } - class C { - ~ -!!! error TS2300: Duplicate identifier 'C'. - constructor() { - var k: (j: T, k: U) => (T|U)[] = (j = 1, k = 0) => { - ~~~~~ -!!! error TS2322: Type 'number' is not assignable to type 'T'. - ~~~~~ -!!! error TS2322: Type 'number' is not assignable to type 'U'. - return [j, k]; - } - } - } \ No newline at end of file diff --git a/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping.ts b/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping.ts deleted file mode 100644 index 1ede1c3fa72..00000000000 --- a/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping.ts +++ /dev/null @@ -1,32 +0,0 @@ -enum E { red, blue } - -var g0: (n: number, s:string) => number; -var g: ((s: string, w: boolean) => void) | ((n: number) => number); -var g1: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); - -g1 = (j, m) => { } // Per spec, no contextual signature can be extracted in this case. -g = (k, h=true) => { k.toLowerCase() }; -g = (k) => { k.toLowerCase() }; -g = (i) => { - i.toExponential(); - return i; -}; // Per spec, no contextual signature can be extracted in this case. - -var h: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); -h = (k, h) => { }; - -var i: typeof g0 | ((n: number, s: string) => string); -i = (foo, bar) => { return foo + 1; } -i = (foo, bar) => { return "hello"; } -var j: (name: string, num: number, boo: boolean) => void; -j = (name, number) => { }; - -var k: (n: E) => string = (number = 1) => { return "hello"; }; -var k1: (n: {}) => string = (number = 1) => { return "hello"; }; -class C { - constructor() { - var k: ((j: T, k: U) => (T|U)[]) | ((j: number,k :U) => number[]) = (j, k) => { - return [j, k]; - } // Per spec, no contextual signature can be extracted in this case. - } -} \ No newline at end of file diff --git a/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts b/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts index d22fff7e138..1ede1c3fa72 100644 --- a/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts +++ b/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts @@ -1,14 +1,32 @@ -var g0: (n: number, s: string) => number +enum E { red, blue } + +var g0: (n: number, s:string) => number; +var g: ((s: string, w: boolean) => void) | ((n: number) => number); +var g1: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); + +g1 = (j, m) => { } // Per spec, no contextual signature can be extracted in this case. +g = (k, h=true) => { k.toLowerCase() }; +g = (k) => { k.toLowerCase() }; +g = (i) => { + i.toExponential(); + return i; +}; // Per spec, no contextual signature can be extracted in this case. + +var h: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); +h = (k, h) => { }; + var i: typeof g0 | ((n: number, s: string) => string); -i = (foo, bar) => { return true; } +i = (foo, bar) => { return foo + 1; } +i = (foo, bar) => { return "hello"; } +var j: (name: string, num: number, boo: boolean) => void; +j = (name, number) => { }; -class C { } - -var j: (c: C) => number = (j) => { return 1; } +var k: (n: E) => string = (number = 1) => { return "hello"; }; +var k1: (n: {}) => string = (number = 1) => { return "hello"; }; class C { constructor() { - var k: (j: T, k: U) => (T|U)[] = (j = 1, k = 0) => { + var k: ((j: T, k: U) => (T|U)[]) | ((j: number,k :U) => number[]) = (j, k) => { return [j, k]; - } + } // Per spec, no contextual signature can be extracted in this case. } } \ No newline at end of file diff --git a/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts b/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts new file mode 100644 index 00000000000..d22fff7e138 --- /dev/null +++ b/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts @@ -0,0 +1,14 @@ +var g0: (n: number, s: string) => number +var i: typeof g0 | ((n: number, s: string) => string); +i = (foo, bar) => { return true; } + +class C { } + +var j: (c: C) => number = (j) => { return 1; } +class C { + constructor() { + var k: (j: T, k: U) => (T|U)[] = (j = 1, k = 0) => { + return [j, k]; + } + } +} \ No newline at end of file From 5ac12cfbc0c8464dfa8487a521afe4af9720fbe3 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 14 Apr 2015 13:05:29 -0700 Subject: [PATCH 024/194] Update test filenames --- .../functionExpressionContextualTyping1.js | 74 ++++++-- .../functionExpressionContextualTyping1.types | 167 ++++++++++++++++++ ...tionExpressionContextualTyping2.errors.txt | 36 ++++ .../functionExpressionContextualTyping2.js | 36 ++++ 4 files changed, 296 insertions(+), 17 deletions(-) create mode 100644 tests/baselines/reference/functionExpressionContextualTyping1.types create mode 100644 tests/baselines/reference/functionExpressionContextualTyping2.errors.txt create mode 100644 tests/baselines/reference/functionExpressionContextualTyping2.js diff --git a/tests/baselines/reference/functionExpressionContextualTyping1.js b/tests/baselines/reference/functionExpressionContextualTyping1.js index f0331c84070..6e528a5aedc 100644 --- a/tests/baselines/reference/functionExpressionContextualTyping1.js +++ b/tests/baselines/reference/functionExpressionContextualTyping1.js @@ -1,36 +1,76 @@ //// [functionExpressionContextualTyping1.ts] -var g0: (n: number, s: string) => number +enum E { red, blue } + +var g0: (n: number, s:string) => number; +var g: ((s: string, w: boolean) => void) | ((n: number) => number); +var g1: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); + +g1 = (j, m) => { } // Per spec, no contextual signature can be extracted in this case. +g = (k, h=true) => { k.toLowerCase() }; +g = (k) => { k.toLowerCase() }; +g = (i) => { + i.toExponential(); + return i; +}; // Per spec, no contextual signature can be extracted in this case. + +var h: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); +h = (k, h) => { }; + var i: typeof g0 | ((n: number, s: string) => string); -i = (foo, bar) => { return true; } +i = (foo, bar) => { return foo + 1; } +i = (foo, bar) => { return "hello"; } +var j: (name: string, num: number, boo: boolean) => void; +j = (name, number) => { }; -class C { } - -var j: (c: C) => number = (j) => { return 1; } +var k: (n: E) => string = (number = 1) => { return "hello"; }; +var k1: (n: {}) => string = (number = 1) => { return "hello"; }; class C { constructor() { - var k: (j: T, k: U) => (T|U)[] = (j = 1, k = 0) => { + var k: ((j: T, k: U) => (T|U)[]) | ((j: number,k :U) => number[]) = (j, k) => { return [j, k]; - } + } // Per spec, no contextual signature can be extracted in this case. } } //// [functionExpressionContextualTyping1.js] +var E; +(function (E) { + E[E["red"] = 0] = "red"; + E[E["blue"] = 1] = "blue"; +})(E || (E = {})); var g0; +var g; +var g1; +g1 = function (j, m) { }; // Per spec, no contextual signature can be extracted in this case. +g = function (k, h) { + if (h === void 0) { h = true; } + k.toLowerCase(); +}; +g = function (k) { k.toLowerCase(); }; +g = function (i) { + i.toExponential(); + return i; +}; // Per spec, no contextual signature can be extracted in this case. +var h; +h = function (k, h) { }; var i; -i = function (foo, bar) { return true; }; -var C = (function () { - function C() { - } - return C; -})(); -var j = function (j) { return 1; }; +i = function (foo, bar) { return foo + 1; }; +i = function (foo, bar) { return "hello"; }; +var j; +j = function (name, number) { }; +var k = function (number) { + if (number === void 0) { number = 1; } + return "hello"; +}; +var k1 = function (number) { + if (number === void 0) { number = 1; } + return "hello"; +}; var C = (function () { function C() { var k = function (j, k) { - if (j === void 0) { j = 1; } - if (k === void 0) { k = 0; } return [j, k]; - }; + }; // Per spec, no contextual signature can be extracted in this case. } return C; })(); diff --git a/tests/baselines/reference/functionExpressionContextualTyping1.types b/tests/baselines/reference/functionExpressionContextualTyping1.types new file mode 100644 index 00000000000..3a1ce95bb99 --- /dev/null +++ b/tests/baselines/reference/functionExpressionContextualTyping1.types @@ -0,0 +1,167 @@ +=== tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts === +enum E { red, blue } +>E : E, Symbol(E, Decl(functionExpressionContextualTyping1.ts, 0, 0)) +>red : E, Symbol(E.red, Decl(functionExpressionContextualTyping1.ts, 0, 8)) +>blue : E, Symbol(E.blue, Decl(functionExpressionContextualTyping1.ts, 0, 13)) + +var g0: (n: number, s:string) => number; +>g0 : (n: number, s: string) => number, Symbol(g0, Decl(functionExpressionContextualTyping1.ts, 2, 3)) +>n : number, Symbol(n, Decl(functionExpressionContextualTyping1.ts, 2, 9)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 2, 19)) + +var g: ((s: string, w: boolean) => void) | ((n: number) => number); +>g : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(g, Decl(functionExpressionContextualTyping1.ts, 3, 3)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 3, 9)) +>w : boolean, Symbol(w, Decl(functionExpressionContextualTyping1.ts, 3, 19)) +>n : number, Symbol(n, Decl(functionExpressionContextualTyping1.ts, 3, 45)) + +var g1: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); +>g1 : ((s: string, w: boolean) => void) | ((s: string, w: number) => string), Symbol(g1, Decl(functionExpressionContextualTyping1.ts, 4, 3)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 4, 10)) +>w : boolean, Symbol(w, Decl(functionExpressionContextualTyping1.ts, 4, 20)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 4, 46)) +>w : number, Symbol(w, Decl(functionExpressionContextualTyping1.ts, 4, 56)) + +g1 = (j, m) => { } // Per spec, no contextual signature can be extracted in this case. +>g1 = (j, m) => { } : (j: any, m: any) => void +>g1 : ((s: string, w: boolean) => void) | ((s: string, w: number) => string), Symbol(g1, Decl(functionExpressionContextualTyping1.ts, 4, 3)) +>(j, m) => { } : (j: any, m: any) => void +>j : any, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 6, 6)) +>m : any, Symbol(m, Decl(functionExpressionContextualTyping1.ts, 6, 8)) + +g = (k, h=true) => { k.toLowerCase() }; +>g = (k, h=true) => { k.toLowerCase() } : (k: any, h?: boolean) => void +>g : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(g, Decl(functionExpressionContextualTyping1.ts, 3, 3)) +>(k, h=true) => { k.toLowerCase() } : (k: any, h?: boolean) => void +>k : any, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 7, 5)) +>h : boolean, Symbol(h, Decl(functionExpressionContextualTyping1.ts, 7, 7)) +>true : boolean +>k.toLowerCase() : any +>k.toLowerCase : any +>k : any, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 7, 5)) +>toLowerCase : any + +g = (k) => { k.toLowerCase() }; +>g = (k) => { k.toLowerCase() } : (k: any) => void +>g : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(g, Decl(functionExpressionContextualTyping1.ts, 3, 3)) +>(k) => { k.toLowerCase() } : (k: any) => void +>k : any, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 8, 5)) +>k.toLowerCase() : any +>k.toLowerCase : any +>k : any, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 8, 5)) +>toLowerCase : any + +g = (i) => { +>g = (i) => { i.toExponential(); return i;} : (i: any) => any +>g : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(g, Decl(functionExpressionContextualTyping1.ts, 3, 3)) +>(i) => { i.toExponential(); return i;} : (i: any) => any +>i : any, Symbol(i, Decl(functionExpressionContextualTyping1.ts, 9, 5)) + + i.toExponential(); +>i.toExponential() : any +>i.toExponential : any +>i : any, Symbol(i, Decl(functionExpressionContextualTyping1.ts, 9, 5)) +>toExponential : any + + return i; +>i : any, Symbol(i, Decl(functionExpressionContextualTyping1.ts, 9, 5)) + +}; // Per spec, no contextual signature can be extracted in this case. + +var h: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); +>h : ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string), Symbol(h, Decl(functionExpressionContextualTyping1.ts, 14, 3)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 14, 9)) +>w : boolean, Symbol(w, Decl(functionExpressionContextualTyping1.ts, 14, 19)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 14, 45)) +>w : boolean, Symbol(w, Decl(functionExpressionContextualTyping1.ts, 14, 55)) + +h = (k, h) => { }; +>h = (k, h) => { } : (k: string, h: boolean) => void +>h : ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string), Symbol(h, Decl(functionExpressionContextualTyping1.ts, 14, 3)) +>(k, h) => { } : (k: string, h: boolean) => void +>k : string, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 15, 5)) +>h : boolean, Symbol(h, Decl(functionExpressionContextualTyping1.ts, 15, 7)) + +var i: typeof g0 | ((n: number, s: string) => string); +>i : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(i, Decl(functionExpressionContextualTyping1.ts, 17, 3)) +>g0 : (n: number, s: string) => number, Symbol(g0, Decl(functionExpressionContextualTyping1.ts, 2, 3)) +>n : number, Symbol(n, Decl(functionExpressionContextualTyping1.ts, 17, 21)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 17, 31)) + +i = (foo, bar) => { return foo + 1; } +>i = (foo, bar) => { return foo + 1; } : (foo: number, bar: string) => number +>i : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(i, Decl(functionExpressionContextualTyping1.ts, 17, 3)) +>(foo, bar) => { return foo + 1; } : (foo: number, bar: string) => number +>foo : number, Symbol(foo, Decl(functionExpressionContextualTyping1.ts, 18, 5)) +>bar : string, Symbol(bar, Decl(functionExpressionContextualTyping1.ts, 18, 9)) +>foo + 1 : number +>foo : number, Symbol(foo, Decl(functionExpressionContextualTyping1.ts, 18, 5)) +>1 : number + +i = (foo, bar) => { return "hello"; } +>i = (foo, bar) => { return "hello"; } : (foo: number, bar: string) => string +>i : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(i, Decl(functionExpressionContextualTyping1.ts, 17, 3)) +>(foo, bar) => { return "hello"; } : (foo: number, bar: string) => string +>foo : number, Symbol(foo, Decl(functionExpressionContextualTyping1.ts, 19, 5)) +>bar : string, Symbol(bar, Decl(functionExpressionContextualTyping1.ts, 19, 9)) +>"hello" : string + +var j: (name: string, num: number, boo: boolean) => void; +>j : (name: string, num: number, boo: boolean) => void, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 20, 3)) +>name : string, Symbol(name, Decl(functionExpressionContextualTyping1.ts, 20, 8)) +>num : number, Symbol(num, Decl(functionExpressionContextualTyping1.ts, 20, 21)) +>boo : boolean, Symbol(boo, Decl(functionExpressionContextualTyping1.ts, 20, 34)) + +j = (name, number) => { }; +>j = (name, number) => { } : (name: string, number: number) => void +>j : (name: string, num: number, boo: boolean) => void, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 20, 3)) +>(name, number) => { } : (name: string, number: number) => void +>name : string, Symbol(name, Decl(functionExpressionContextualTyping1.ts, 21, 5)) +>number : number, Symbol(number, Decl(functionExpressionContextualTyping1.ts, 21, 10)) + +var k: (n: E) => string = (number = 1) => { return "hello"; }; +>k : (n: E) => string, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 23, 3)) +>n : E, Symbol(n, Decl(functionExpressionContextualTyping1.ts, 23, 8)) +>E : E, Symbol(E, Decl(functionExpressionContextualTyping1.ts, 0, 0)) +>(number = 1) => { return "hello"; } : (number?: E) => string +>number : E, Symbol(number, Decl(functionExpressionContextualTyping1.ts, 23, 27)) +>1 : number +>"hello" : string + +var k1: (n: {}) => string = (number = 1) => { return "hello"; }; +>k1 : (n: {}) => string, Symbol(k1, Decl(functionExpressionContextualTyping1.ts, 24, 3)) +>n : {}, Symbol(n, Decl(functionExpressionContextualTyping1.ts, 24, 9)) +>(number = 1) => { return "hello"; } : (number?: {}) => string +>number : {}, Symbol(number, Decl(functionExpressionContextualTyping1.ts, 24, 29)) +>1 : number +>"hello" : string + +class C { +>C : C, Symbol(C, Decl(functionExpressionContextualTyping1.ts, 24, 64)) +>T : T, Symbol(T, Decl(functionExpressionContextualTyping1.ts, 25, 8)) +>U : U, Symbol(U, Decl(functionExpressionContextualTyping1.ts, 25, 10)) + + constructor() { + var k: ((j: T, k: U) => (T|U)[]) | ((j: number,k :U) => number[]) = (j, k) => { +>k : ((j: T, k: U) => (T | U)[]) | ((j: number, k: U) => number[]), Symbol(k, Decl(functionExpressionContextualTyping1.ts, 27, 11)) +>j : T, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 27, 17)) +>T : T, Symbol(T, Decl(functionExpressionContextualTyping1.ts, 25, 8)) +>k : U, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 27, 22)) +>U : U, Symbol(U, Decl(functionExpressionContextualTyping1.ts, 25, 10)) +>T : T, Symbol(T, Decl(functionExpressionContextualTyping1.ts, 25, 8)) +>U : U, Symbol(U, Decl(functionExpressionContextualTyping1.ts, 25, 10)) +>j : number, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 27, 45)) +>k : U, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 27, 55)) +>U : U, Symbol(U, Decl(functionExpressionContextualTyping1.ts, 25, 10)) +>(j, k) => { return [j, k]; } : (j: any, k: any) => any[] +>j : any, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 27, 77)) +>k : any, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 27, 79)) + + return [j, k]; +>[j, k] : any[] +>j : any, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 27, 77)) +>k : any, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 27, 79)) + + } // Per spec, no contextual signature can be extracted in this case. + } +} diff --git a/tests/baselines/reference/functionExpressionContextualTyping2.errors.txt b/tests/baselines/reference/functionExpressionContextualTyping2.errors.txt new file mode 100644 index 00000000000..d9622c50e42 --- /dev/null +++ b/tests/baselines/reference/functionExpressionContextualTyping2.errors.txt @@ -0,0 +1,36 @@ +tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts(3,1): error TS2322: Type '(foo: number, bar: string) => boolean' is not assignable to type '((n: number, s: string) => number) | ((n: number, s: string) => string)'. + Type '(foo: number, bar: string) => boolean' is not assignable to type '(n: number, s: string) => string'. + Type 'boolean' is not assignable to type 'string'. +tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts(5,7): error TS2300: Duplicate identifier 'C'. +tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts(8,7): error TS2300: Duplicate identifier 'C'. +tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts(10,43): error TS2322: Type 'number' is not assignable to type 'T'. +tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts(10,50): error TS2322: Type 'number' is not assignable to type 'U'. + + +==== tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts (5 errors) ==== + var g0: (n: number, s: string) => number + var i: typeof g0 | ((n: number, s: string) => string); + i = (foo, bar) => { return true; } + ~ +!!! error TS2322: Type '(foo: number, bar: string) => boolean' is not assignable to type '((n: number, s: string) => number) | ((n: number, s: string) => string)'. +!!! error TS2322: Type '(foo: number, bar: string) => boolean' is not assignable to type '(n: number, s: string) => string'. +!!! error TS2322: Type 'boolean' is not assignable to type 'string'. + + class C { } + ~ +!!! error TS2300: Duplicate identifier 'C'. + + var j: (c: C) => number = (j) => { return 1; } + class C { + ~ +!!! error TS2300: Duplicate identifier 'C'. + constructor() { + var k: (j: T, k: U) => (T|U)[] = (j = 1, k = 0) => { + ~~~~~ +!!! error TS2322: Type 'number' is not assignable to type 'T'. + ~~~~~ +!!! error TS2322: Type 'number' is not assignable to type 'U'. + return [j, k]; + } + } + } \ No newline at end of file diff --git a/tests/baselines/reference/functionExpressionContextualTyping2.js b/tests/baselines/reference/functionExpressionContextualTyping2.js new file mode 100644 index 00000000000..87d3e1ed9ef --- /dev/null +++ b/tests/baselines/reference/functionExpressionContextualTyping2.js @@ -0,0 +1,36 @@ +//// [functionExpressionContextualTyping2.ts] +var g0: (n: number, s: string) => number +var i: typeof g0 | ((n: number, s: string) => string); +i = (foo, bar) => { return true; } + +class C { } + +var j: (c: C) => number = (j) => { return 1; } +class C { + constructor() { + var k: (j: T, k: U) => (T|U)[] = (j = 1, k = 0) => { + return [j, k]; + } + } +} + +//// [functionExpressionContextualTyping2.js] +var g0; +var i; +i = function (foo, bar) { return true; }; +var C = (function () { + function C() { + } + return C; +})(); +var j = function (j) { return 1; }; +var C = (function () { + function C() { + var k = function (j, k) { + if (j === void 0) { j = 1; } + if (k === void 0) { k = 0; } + return [j, k]; + }; + } + return C; +})(); From 1d793f4c5e9ab398854ca168b7921b0940c281da Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 14 Apr 2015 23:44:14 -0700 Subject: [PATCH 025/194] Destructuring assignment and variable declaration --- ...turingArrayBindingPatternAndAssignment1.js | 41 ++++++ ...ingArrayBindingPatternAndAssignment1.types | 133 ++++++++++++++++++ ...turingArrayBindingPatternAndAssignment2.js | 25 ++++ ...ingArrayBindingPatternAndAssignment2.types | 41 ++++++ ...rayBindingPatternAndAssignment3.errors.txt | 51 +++++++ ...turingArrayBindingPatternAndAssignment3.js | 41 ++++++ ...uringObjectBindingPatternAndAssignment1.js | 27 ++++ ...ngObjectBindingPatternAndAssignment1.types | 87 ++++++++++++ ...uringObjectBindingPatternAndAssignment2.js | 76 ++++++++++ ...ngObjectBindingPatternAndAssignment2.types | 116 +++++++++++++++ ...ectBindingPatternAndAssignment3.errors.txt | 42 ++++++ ...uringObjectBindingPatternAndAssignment3.js | 23 +++ ...ectBindingPatternAndAssignment4.errors.txt | 37 +++++ ...uringObjectBindingPatternAndAssignment4.js | 37 +++++ ...ariableDeclarationAndAssignment.errors.txt | 15 ++ ...cturingVariableDeclarationAndAssignment.js | 9 ++ ...turingArrayBindingPatternAndAssignment1.ts | 22 +++ ...turingArrayBindingPatternAndAssignment2.ts | 13 ++ ...turingArrayBindingPatternAndAssignment3.ts | 23 +++ ...uringObjectBindingPatternAndAssignment1.ts | 12 ++ ...uringObjectBindingPatternAndAssignment2.ts | 46 ++++++ ...uringObjectBindingPatternAndAssignment3.ts | 10 ++ ...uringObjectBindingPatternAndAssignment4.ts | 23 +++ ...cturingVariableDeclarationAndAssignment.ts | 3 + 24 files changed, 953 insertions(+) create mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1.js create mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1.types create mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.js create mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.types create mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment3.errors.txt create mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment3.js create mode 100644 tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1.js create mode 100644 tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1.types create mode 100644 tests/baselines/reference/destructuringObjectBindingPatternAndAssignment2.js create mode 100644 tests/baselines/reference/destructuringObjectBindingPatternAndAssignment2.types create mode 100644 tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt create mode 100644 tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.js create mode 100644 tests/baselines/reference/destructuringObjectBindingPatternAndAssignment4.errors.txt create mode 100644 tests/baselines/reference/destructuringObjectBindingPatternAndAssignment4.js create mode 100644 tests/baselines/reference/destructuringVariableDeclarationAndAssignment.errors.txt create mode 100644 tests/baselines/reference/destructuringVariableDeclarationAndAssignment.js create mode 100644 tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment2.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment4.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringVariableDeclarationAndAssignment.ts diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1.js b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1.js new file mode 100644 index 00000000000..f6c84b011d0 --- /dev/null +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1.js @@ -0,0 +1,41 @@ +//// [destructuringArrayBindingPatternAndAssignment1.ts] +var [p0,p1, p2] : any = [2, 3, 4]; +var [a, b, c]: [number, number, string] = [1, 2, "string"]; +var [d, e]: any = undefined; +var [f = false, g = 1]: any = undefined; +g = 10; +f = true; + +var [x] = [] +var [[[y]], [[[[z]]]]] = [[[]], [[[[]]]]] +var [[w], m]: [[string|number], boolean] = [[1], true]; +interface J extends Array { + 2: number; +} + +var [, w1] = [1, 2, 3]; +var [,,, w2] = [1, 2, 3, 4]; +var [,,, w2] = [1, 2, 3, 4]; +var [,,,...w3] = [1, 2, 3, 4, "hello"]; + +var [r, s, ...t] = [1, 2, "string"]; +var [r1, s1, t1] = [1, 2, "string"]; + + + +//// [destructuringArrayBindingPatternAndAssignment1.js] +var _a = [2, 3, 4], p0 = _a[0], p1 = _a[1], p2 = _a[2]; +var _b = [1, 2, "string"], a = _b[0], b = _b[1], c = _b[2]; +var d = undefined[0], e = undefined[1]; +var _c = undefined[0], f = _c === void 0 ? false : _c, _d = undefined[1], g = _d === void 0 ? 1 : _d; +g = 10; +f = true; +var x = ([])[0]; +var _e = [[[]], [[[[]]]]], y = _e[0][0][0], z = _e[1][0][0][0][0]; +var _f = [[1], true], w = _f[0][0], m = _f[1]; +var _g = [1, 2, 3], w1 = _g[1]; +var _h = [1, 2, 3, 4], w2 = _h[3]; +var _j = [1, 2, 3, 4], w2 = _j[3]; +var _k = [1, 2, 3, 4, "hello"], w3 = _k.slice(3); +var _l = [1, 2, "string"], r = _l[0], s = _l[1], t = _l.slice(2); +var _m = [1, 2, "string"], r1 = _m[0], s1 = _m[1], t1 = _m[2]; diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1.types new file mode 100644 index 00000000000..f4abb8953f6 --- /dev/null +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1.types @@ -0,0 +1,133 @@ +=== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1.ts === +var [p0,p1, p2] : any = [2, 3, 4]; +>p0 : any, Symbol(p0, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 0, 5)) +>p1 : any, Symbol(p1, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 0, 8)) +>p2 : any, Symbol(p2, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 0, 11)) +>[2, 3, 4] : number[] +>2 : number +>3 : number +>4 : number + +var [a, b, c]: [number, number, string] = [1, 2, "string"]; +>a : number, Symbol(a, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 1, 5)) +>b : number, Symbol(b, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 1, 7)) +>c : string, Symbol(c, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 1, 10)) +>[1, 2, "string"] : [number, number, string] +>1 : number +>2 : number +>"string" : string + +var [d, e]: any = undefined; +>d : any, Symbol(d, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 2, 5)) +>e : any, Symbol(e, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 2, 7)) +>undefined : undefined, Symbol(undefined) + +var [f = false, g = 1]: any = undefined; +>f : boolean, Symbol(f, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 3, 5)) +>false : boolean +>g : number, Symbol(g, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 3, 15)) +>1 : number +>undefined : undefined, Symbol(undefined) + +g = 10; +>g = 10 : number +>g : number, Symbol(g, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 3, 15)) +>10 : number + +f = true; +>f = true : boolean +>f : boolean, Symbol(f, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 3, 5)) +>true : boolean + +var [x] = [] +>x : any, Symbol(x, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 7, 5)) +>[] : undefined[] + +var [[[y]], [[[[z]]]]] = [[[]], [[[[]]]]] +>y : any, Symbol(y, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 8, 7)) +>z : any, Symbol(z, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 8, 16)) +>[[[]], [[[[]]]]] : [[undefined[]], [[[undefined[]]]]] +>[[]] : [undefined[]] +>[] : undefined[] +>[[[[]]]] : [[[undefined[]]]] +>[[[]]] : [[undefined[]]] +>[[]] : [undefined[]] +>[] : undefined[] + +var [[w], m]: [[string|number], boolean] = [[1], true]; +>w : string | number, Symbol(w, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 9, 6)) +>m : boolean, Symbol(m, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 9, 9)) +>[[1], true] : [[number], boolean] +>[1] : [number] +>1 : number +>true : boolean + +interface J extends Array { +>J : J, Symbol(J, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 9, 55)) +>Array : T[], Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11)) +>Number : Number, Symbol(Number, Decl(lib.d.ts, 456, 40), Decl(lib.d.ts, 518, 11)) + + 2: number; +} + +var [, w1] = [1, 2, 3]; +> : undefined +>w1 : number, Symbol(w1, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 14, 6)) +>[1, 2, 3] : [number, number, number] +>1 : number +>2 : number +>3 : number + +var [,,, w2] = [1, 2, 3, 4]; +> : undefined +> : undefined +> : undefined +>w2 : number, Symbol(w2, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 15, 8), Decl(destructuringArrayBindingPatternAndAssignment1.ts, 16, 8)) +>[1, 2, 3, 4] : [number, number, number, number] +>1 : number +>2 : number +>3 : number +>4 : number + +var [,,, w2] = [1, 2, 3, 4]; +> : undefined +> : undefined +> : undefined +>w2 : number, Symbol(w2, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 15, 8), Decl(destructuringArrayBindingPatternAndAssignment1.ts, 16, 8)) +>[1, 2, 3, 4] : [number, number, number, number] +>1 : number +>2 : number +>3 : number +>4 : number + +var [,,,...w3] = [1, 2, 3, 4, "hello"]; +> : undefined +> : undefined +> : undefined +>w3 : (string | number)[], Symbol(w3, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 17, 8)) +>[1, 2, 3, 4, "hello"] : (string | number)[] +>1 : number +>2 : number +>3 : number +>4 : number +>"hello" : string + +var [r, s, ...t] = [1, 2, "string"]; +>r : string | number, Symbol(r, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 19, 5)) +>s : string | number, Symbol(s, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 19, 7)) +>t : (string | number)[], Symbol(t, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 19, 10)) +>[1, 2, "string"] : (string | number)[] +>1 : number +>2 : number +>"string" : string + +var [r1, s1, t1] = [1, 2, "string"]; +>r1 : number, Symbol(r1, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 20, 5)) +>s1 : number, Symbol(s1, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 20, 8)) +>t1 : string, Symbol(t1, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 20, 12)) +>[1, 2, "string"] : [number, number, string] +>1 : number +>2 : number +>"string" : string + + diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.js b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.js new file mode 100644 index 00000000000..67cfaef96d6 --- /dev/null +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.js @@ -0,0 +1,25 @@ +//// [destructuringArrayBindingPatternAndAssignment2.ts] +function foo() { + return [1, 2, 3]; +} +interface J extends Array { + 2: number; +} + +function bar(): J { + return <[number, number, number]>[1, 2, 3]; +} + +var [j, k] = foo(); +var [...p] = foo(); + + +//// [destructuringArrayBindingPatternAndAssignment2.js] +function foo() { + return [1, 2, 3]; +} +function bar() { + return [1, 2, 3]; +} +var _a = foo(), j = _a[0], k = _a[1]; +var _b = foo(), p = _b.slice(0); diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.types new file mode 100644 index 00000000000..f6b40e5fc95 --- /dev/null +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.types @@ -0,0 +1,41 @@ +=== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts === +function foo() { +>foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 0, 0)) + + return [1, 2, 3]; +>[1, 2, 3] : number[] +>1 : number +>2 : number +>3 : number +} +interface J extends Array { +>J : J, Symbol(J, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 2, 1)) +>Array : T[], Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11)) +>Number : Number, Symbol(Number, Decl(lib.d.ts, 456, 40), Decl(lib.d.ts, 518, 11)) + + 2: number; +} + +function bar(): J { +>bar : () => J, Symbol(bar, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 5, 1)) +>J : J, Symbol(J, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 2, 1)) + + return <[number, number, number]>[1, 2, 3]; +><[number, number, number]>[1, 2, 3] : [number, number, number] +>[1, 2, 3] : [number, number, number] +>1 : number +>2 : number +>3 : number +} + +var [j, k] = foo(); +>j : number, Symbol(j, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 11, 5)) +>k : number, Symbol(k, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 11, 7)) +>foo() : number[] +>foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 0, 0)) + +var [...p] = foo(); +>p : number[], Symbol(p, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 12, 5)) +>foo() : number[] +>foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 0, 0)) + diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment3.errors.txt b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment3.errors.txt new file mode 100644 index 00000000000..8cb1d9eb8c2 --- /dev/null +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment3.errors.txt @@ -0,0 +1,51 @@ +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts(19,5): error TS2322: Type 'undefined[]' is not assignable to type 'H'. + Property '0' is missing in type 'undefined[]'. +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts(19,5): error TS2461: Type 'H' is not an array type. +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts(20,6): error TS2461: Type 'undefined' is not an array type. +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts(20,13): error TS2461: Type 'undefined' is not an array type. +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts(21,13): error TS2462: A rest element must be last in an array destructuring pattern +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts(22,6): error TS2322: Type 'string' is not assignable to type 'Number'. + Property 'toFixed' is missing in type 'String'. +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts(23,5): error TS2461: Type '{}' is not an array type. + + +==== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts (7 errors) ==== + interface H { + 0: number, + 1: string + } + interface J extends Array { + 2: number; + } + + function bar(): J { + return <[number, number, number]>[1, 2, 3]; + } + + function gg(idx: number) { + return { + [idx]: true + } + } + + var [h, g, i]: H = []; + ~~~~~~~~~ +!!! error TS2322: Type 'undefined[]' is not assignable to type 'H'. +!!! error TS2322: Property '0' is missing in type 'undefined[]'. + ~~~~~~~~~ +!!! error TS2461: Type 'H' is not an array type. + var [[[y]], [[[[z]]]]] = [] + ~~~~~ +!!! error TS2461: Type 'undefined' is not an array type. + ~~~~~~~~~ +!!! error TS2461: Type 'undefined' is not an array type. + var [, , ...w4, , ] = [] + ~~ +!!! error TS2462: A rest element must be last in an array destructuring pattern + var [a = "string", b, c] = bar(); + ~ +!!! error TS2322: Type 'string' is not assignable to type 'Number'. +!!! error TS2322: Property 'toFixed' is missing in type 'String'. + var [r, s, t] = gg(1); + ~~~~~~~~~ +!!! error TS2461: Type '{}' is not an array type. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment3.js b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment3.js new file mode 100644 index 00000000000..ad5d1c5c051 --- /dev/null +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment3.js @@ -0,0 +1,41 @@ +//// [destructuringArrayBindingPatternAndAssignment3.ts] +interface H { + 0: number, + 1: string +} +interface J extends Array { + 2: number; +} + +function bar(): J { + return <[number, number, number]>[1, 2, 3]; +} + +function gg(idx: number) { + return { + [idx]: true + } +} + +var [h, g, i]: H = []; +var [[[y]], [[[[z]]]]] = [] +var [, , ...w4, , ] = [] +var [a = "string", b, c] = bar(); +var [r, s, t] = gg(1); + +//// [destructuringArrayBindingPatternAndAssignment3.js] +function bar() { + return [1, 2, 3]; +} +function gg(idx) { + return (_a = {}, + _a[idx] = true, + _a + ); + var _a; +} +var _a = [], h = _a[0], g = _a[1], i = _a[2]; +var _b = [], y = _b[0][0][0], z = _b[1][0][0][0][0]; +var _c = []; +var _d = bar(), _e = _d[0], a = _e === void 0 ? "string" : _e, b = _d[1], c = _d[2]; +var _f = gg(1), r = _f[0], s = _f[1], t = _f[2]; diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1.js b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1.js new file mode 100644 index 00000000000..375cfd8f573 --- /dev/null +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1.js @@ -0,0 +1,27 @@ +//// [destructuringObjectBindingPatternAndAssignment1.ts] +var c = 0; +var { a, } = { a:1, }; +var { b: { c } } = { b: { c } }; +var { b1: { c1 } = { c1: "string" } } = { b1: { c1: "world" } }; +var { d1 }: any = undefined; +var { e1 }: any = {}; +var { f: {f1} = { f1: "string" } }: any = {}; +var { f2: {f21} = { f21: "string" } }: any = undefined; +var { e1: {e2} = { e2: "string" } }: any|{ e1: { e2 } } = undefined; +var { e2: {e3} = { e3: "string" } }: any|{ e2: { e3 } } = {}; +var {g = 1}: any = { g: 100000 }; +var {1: x} = { 1: "string" }; + +//// [destructuringObjectBindingPatternAndAssignment1.js] +var c = 0; +var a = ({ a: 1 }).a; +var c = ({ b: { c: c } }).b.c; +var _a = ({ b1: { c1: "world" } }).b1, c1 = (_a === void 0 ? { c1: "string" } : _a).c1; +var d1 = undefined.d1; +var e1 = ({}).e1; +var _b = ({}).f, f1 = (_b === void 0 ? { f1: "string" } : _b).f1; +var _c = undefined.f2, f21 = (_c === void 0 ? { f21: "string" } : _c).f21; +var _d = undefined.e1, e2 = (_d === void 0 ? { e2: "string" } : _d).e2; +var _e = ({}).e2, e3 = (_e === void 0 ? { e3: "string" } : _e).e3; +var _f = ({ g: 100000 }).g, g = _f === void 0 ? 1 : _f; +var x = ({ 1: "string" })[1]; diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1.types b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1.types new file mode 100644 index 00000000000..46fbe3a9630 --- /dev/null +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1.types @@ -0,0 +1,87 @@ +=== tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1.ts === +var c = 0; +>c : number, Symbol(c, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 0, 3), Decl(destructuringObjectBindingPatternAndAssignment1.ts, 2, 10)) +>0 : number + +var { a, } = { a:1, }; +>a : number, Symbol(a, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 1, 5)) +>{ a:1, } : { a: number; } +>a : number, Symbol(a, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 1, 14)) +>1 : number + +var { b: { c } } = { b: { c } }; +>b : any +>c : number, Symbol(c, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 0, 3), Decl(destructuringObjectBindingPatternAndAssignment1.ts, 2, 10)) +>{ b: { c } } : { b: { c: number; }; } +>b : { c: number; }, Symbol(b, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 2, 21)) +>{ c } : { c: number; } +>c : number, Symbol(c, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 2, 26)) + +var { b1: { c1 } = { c1: "string" } } = { b1: { c1: "world" } }; +>b1 : any +>c1 : string, Symbol(c1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 3, 11)) +>{ c1: "string" } : { c1: string; } +>c1 : string, Symbol(c1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 3, 20)) +>"string" : string +>{ b1: { c1: "world" } } : { b1: { c1: string; }; } +>b1 : { c1: string; }, Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 3, 42)) +>{ c1: "world" } : { c1: string; } +>c1 : string, Symbol(c1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 3, 48)) +>"world" : string + +var { d1 }: any = undefined; +>d1 : any, Symbol(d1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 4, 5)) +>undefined : undefined, Symbol(undefined) + +var { e1 }: any = {}; +>e1 : any, Symbol(e1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 5, 5)) +>{} : {} + +var { f: {f1} = { f1: "string" } }: any = {}; +>f : any +>f1 : string, Symbol(f1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 6, 10)) +>{ f1: "string" } : { f1: string; } +>f1 : string, Symbol(f1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 6, 17)) +>"string" : string +>{} : {} + +var { f2: {f21} = { f21: "string" } }: any = undefined; +>f2 : any +>f21 : string, Symbol(f21, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 7, 11)) +>{ f21: "string" } : { f21: string; } +>f21 : string, Symbol(f21, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 7, 19)) +>"string" : string +>undefined : undefined, Symbol(undefined) + +var { e1: {e2} = { e2: "string" } }: any|{ e1: { e2 } } = undefined; +>e1 : any +>e2 : string, Symbol(e2, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 8, 11)) +>{ e2: "string" } : { e2: string; } +>e2 : string, Symbol(e2, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 8, 18)) +>"string" : string +>e1 : { e2: any; }, Symbol(e1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 8, 42)) +>e2 : any, Symbol(e2, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 8, 48)) +>undefined : undefined, Symbol(undefined) + +var { e2: {e3} = { e3: "string" } }: any|{ e2: { e3 } } = {}; +>e2 : any +>e3 : string, Symbol(e3, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 9, 11)) +>{ e3: "string" } : { e3: string; } +>e3 : string, Symbol(e3, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 9, 18)) +>"string" : string +>e2 : { e3: any; }, Symbol(e2, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 9, 42)) +>e3 : any, Symbol(e3, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 9, 48)) +>{} : {} + +var {g = 1}: any = { g: 100000 }; +>g : number, Symbol(g, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 10, 5)) +>1 : number +>{ g: 100000 } : { g: number; } +>g : number, Symbol(g, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 10, 20)) +>100000 : number + +var {1: x} = { 1: "string" }; +>x : string, Symbol(x, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 11, 5)) +>{ 1: "string" } : { 1: string; } +>"string" : string + diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment2.js b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment2.js new file mode 100644 index 00000000000..32ce0ab0c31 --- /dev/null +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment2.js @@ -0,0 +1,76 @@ +//// [destructuringObjectBindingPatternAndAssignment2.ts] +interface I { + j: number; + [str: string]: number; +} +interface J { + [str: string]: number; +} +function zz() { + return { + "cat": "dog", + } +} + +function zz1(): J { + return { + "cat": 1, + } +} + +function yy() { + return {} +} + +var {j}: I| J = { j: 1000 }; +var {cat} = zz(); +var {"cat":cart} = zz(); + +var {can}: J = {}; +var {can1}: J = zz1(); + + +function f() { + var { z }: { z: number } = { z }; +} + +interface K { + [idx: number]: boolean +} + +var {1: boo}: K = { 1: true }; +var {1: boo1}: K = { }; + +function bar(): K { + return { }; +} +var {1: baz} = bar(); + +//// [destructuringObjectBindingPatternAndAssignment2.js] +function zz() { + return { + "cat": "dog" + }; +} +function zz1() { + return { + "cat": 1 + }; +} +function yy() { + return {}; +} +var j = ({ j: 1000 }).j; +var cat = (zz()).cat; +var cart = (zz())["cat"]; +var can = ({}).can; +var can1 = (zz1()).can1; +function f() { + var z = ({ z: z }).z; +} +var boo = ({ 1: true })[1]; +var boo1 = ({})[1]; +function bar() { + return {}; +} +var baz = (bar())[1]; diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment2.types b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment2.types new file mode 100644 index 00000000000..a46f2406601 --- /dev/null +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment2.types @@ -0,0 +1,116 @@ +=== tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment2.ts === +interface I { +>I : I, Symbol(I, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 0, 0)) + + j: number; +>j : number, Symbol(j, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 0, 13)) + + [str: string]: number; +>str : string, Symbol(str, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 2, 5)) +} +interface J { +>J : J, Symbol(J, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 3, 1)) + + [str: string]: number; +>str : string, Symbol(str, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 5, 5)) +} +function zz() { +>zz : () => { "cat": string; }, Symbol(zz, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 6, 1)) + + return { +>{ "cat": "dog", } : { "cat": string; } + + "cat": "dog", +>"dog" : string + } +} + +function zz1(): J { +>zz1 : () => J, Symbol(zz1, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 11, 1)) +>J : J, Symbol(J, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 3, 1)) + + return { +>{ "cat": 1, } : { [x: string]: number; "cat": number; } + + "cat": 1, +>1 : number + } +} + +function yy() { +>yy : () => {}, Symbol(yy, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 17, 1)) + + return {} +>{} : {} +} + +var {j}: I| J = { j: 1000 }; +>j : number, Symbol(j, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 23, 5)) +>I : I, Symbol(I, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 0, 0)) +>J : J, Symbol(J, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 3, 1)) +>{ j: 1000 } : { [x: string]: number; j: number; } +>j : number, Symbol(j, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 23, 17)) +>1000 : number + +var {cat} = zz(); +>cat : string, Symbol(cat, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 24, 5)) +>zz() : { "cat": string; } +>zz : () => { "cat": string; }, Symbol(zz, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 6, 1)) + +var {"cat":cart} = zz(); +>cart : string, Symbol(cart, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 25, 5)) +>zz() : { "cat": string; } +>zz : () => { "cat": string; }, Symbol(zz, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 6, 1)) + +var {can}: J = {}; +>can : number, Symbol(can, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 27, 5)) +>J : J, Symbol(J, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 3, 1)) +>{} : { [x: string]: undefined; } + +var {can1}: J = zz1(); +>can1 : number, Symbol(can1, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 28, 5)) +>J : J, Symbol(J, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 3, 1)) +>zz1() : J +>zz1 : () => J, Symbol(zz1, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 11, 1)) + + +function f() { +>f : () => void, Symbol(f, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 28, 22)) + + var { z }: { z: number } = { z }; +>z : number, Symbol(z, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 32, 9)) +>z : number, Symbol(z, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 32, 16)) +>{ z } : { z: number; } +>z : number, Symbol(z, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 32, 32)) +} + +interface K { +>K : K, Symbol(K, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 33, 1)) + + [idx: number]: boolean +>idx : number, Symbol(idx, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 36, 5)) +} + +var {1: boo}: K = { 1: true }; +>boo : boolean, Symbol(boo, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 39, 5)) +>K : K, Symbol(K, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 33, 1)) +>{ 1: true } : { [x: number]: boolean; 1: boolean; } +>true : boolean + +var {1: boo1}: K = { }; +>boo1 : boolean, Symbol(boo1, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 40, 5)) +>K : K, Symbol(K, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 33, 1)) +>{ } : { [x: number]: undefined; } + +function bar(): K { +>bar : () => K, Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 40, 23)) +>K : K, Symbol(K, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 33, 1)) + + return { }; +>{ } : { [x: number]: undefined; } +} +var {1: baz} = bar(); +>baz : boolean, Symbol(baz, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 45, 5)) +>bar() : K +>bar : () => K, Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 40, 23)) + diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt new file mode 100644 index 00000000000..de4dcee1bf2 --- /dev/null +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt @@ -0,0 +1,42 @@ +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(1,7): error TS1005: ',' expected. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(2,5): error TS2322: Type '{ i: number; }' is not assignable to type 'string | number'. + Type '{ i: number; }' is not assignable to type 'number'. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(2,6): error TS2459: Type 'string | number' has no property 'i' and no string index signature. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(3,6): error TS2459: Type 'string | number | {}' has no property 'i1' and no string index signature. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(4,12): error TS2459: Type '{ f212: string; }' has no property 'f21' and no string index signature. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(5,54): error TS2304: Cannot find name 'c'. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(7,7): error TS1180: Property destructuring pattern expected. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(10,7): error TS1005: ':' expected. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(10,15): error TS1005: ':' expected. + + +==== tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts (9 errors) ==== + var {h?} = { h?: 1 }; + ~ +!!! error TS1005: ',' expected. + var {i}: string | number = { i: 2 }; + ~~~ +!!! error TS2322: Type '{ i: number; }' is not assignable to type 'string | number'. +!!! error TS2322: Type '{ i: number; }' is not assignable to type 'number'. + ~ +!!! error TS2459: Type 'string | number' has no property 'i' and no string index signature. + var {i1}: string | number| {} = { i1: 2 }; + ~~ +!!! error TS2459: Type 'string | number | {}' has no property 'i1' and no string index signature. + var { f2: {f21} = { f212: "string" } }: any = undefined; + ~~~ +!!! error TS2459: Type '{ f212: string; }' has no property 'f21' and no string index signature. + var { b1: { c1 } = { c1: "string" } } = { b1: { c1: c } }; + ~ +!!! error TS2304: Cannot find name 'c'. + var { d }: any; + var { ...d1 } = { + ~~~ +!!! error TS1180: Property destructuring pattern expected. + a: 1, b: 1, d1: 9, e: 10 + } + var {1} = { 1 }; + ~ +!!! error TS1005: ':' expected. + ~ +!!! error TS1005: ':' expected. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.js b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.js new file mode 100644 index 00000000000..d53afcbb97c --- /dev/null +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.js @@ -0,0 +1,23 @@ +//// [destructuringObjectBindingPatternAndAssignment3.ts] +var {h?} = { h?: 1 }; +var {i}: string | number = { i: 2 }; +var {i1}: string | number| {} = { i1: 2 }; +var { f2: {f21} = { f212: "string" } }: any = undefined; +var { b1: { c1 } = { c1: "string" } } = { b1: { c1: c } }; +var { d }: any; +var { ...d1 } = { + a: 1, b: 1, d1: 9, e: 10 +} +var {1} = { 1 }; + +//// [destructuringObjectBindingPatternAndAssignment3.js] +var h = ({ h: 1 }).h; +var i = ({ i: 2 }).i; +var i1 = ({ i1: 2 }).i1; +var _a = undefined.f2, f21 = (_a === void 0 ? { f212: "string" } : _a).f21; +var _b = ({ b1: { c1: c } }).b1, c1 = (_b === void 0 ? { c1: "string" } : _b).c1; +var d = (void 0).d; +var d1 = ({ + a: 1, b: 1, d1: 9, e: 10 +}).d1; +var = ({ 1: })[1]; diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment4.errors.txt b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment4.errors.txt new file mode 100644 index 00000000000..f0b7977a443 --- /dev/null +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment4.errors.txt @@ -0,0 +1,37 @@ +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment4.ts(7,6): error TS2459: Type 'K | K1' has no property 'k' and no string index signature. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment4.ts(12,6): error TS2459: Type '{}' has no property '2' and no string index signature. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment4.ts(23,5): error TS2322: Type '{ "cat": string; }' is not assignable to type 'J'. + Index signature is missing in type '{ "cat": string; }'. + + +==== tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment4.ts (3 errors) ==== + interface K { + [str: string]: string; + } + interface K1 { + k: string; + } + var {k}: K|K1 = { k: "string" }; + ~ +!!! error TS2459: Type 'K | K1' has no property 'k' and no string index signature. + + function barn() { + return {}; + } + var {2: baz1} = barn() + ~ +!!! error TS2459: Type '{}' has no property '2' and no string index signature. + + interface J { + [str: string]: number; + } + function zz() { + return { + "cat": "dog" + } + } + + var {"can": can}: J = zz(); + ~~~~~~~~~~~~ +!!! error TS2322: Type '{ "cat": string; }' is not assignable to type 'J'. +!!! error TS2322: Index signature is missing in type '{ "cat": string; }'. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment4.js b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment4.js new file mode 100644 index 00000000000..7abf9f3b845 --- /dev/null +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment4.js @@ -0,0 +1,37 @@ +//// [destructuringObjectBindingPatternAndAssignment4.ts] +interface K { + [str: string]: string; +} +interface K1 { + k: string; +} +var {k}: K|K1 = { k: "string" }; + +function barn() { + return {}; +} +var {2: baz1} = barn() + +interface J { + [str: string]: number; +} +function zz() { + return { + "cat": "dog" + } +} + +var {"can": can}: J = zz(); + +//// [destructuringObjectBindingPatternAndAssignment4.js] +var k = ({ k: "string" }).k; +function barn() { + return {}; +} +var baz1 = (barn())[2]; +function zz() { + return { + "cat": "dog" + }; +} +var can = (zz())["can"]; diff --git a/tests/baselines/reference/destructuringVariableDeclarationAndAssignment.errors.txt b/tests/baselines/reference/destructuringVariableDeclarationAndAssignment.errors.txt new file mode 100644 index 00000000000..a455ee862c4 --- /dev/null +++ b/tests/baselines/reference/destructuringVariableDeclarationAndAssignment.errors.txt @@ -0,0 +1,15 @@ +tests/cases/conformance/es6/destructuring/destructuringVariableDeclarationAndAssignment.ts(3,23): error TS2459: Type 'number | { b12: number; b42: number; }' has no property 'b12' and no string index signature. +tests/cases/conformance/es6/destructuring/destructuringVariableDeclarationAndAssignment.ts(3,33): error TS2459: Type 'number | { b12: number; b42: number; }' has no property 'b42' and no string index signature. +tests/cases/conformance/es6/destructuring/destructuringVariableDeclarationAndAssignment.ts(3,44): error TS2403: Subsequent variable declarations must have the same type. Variable 'c' must be of type 'number', but here has type '(number | { b12: number; b42: number; })[]'. + + +==== tests/cases/conformance/es6/destructuring/destructuringVariableDeclarationAndAssignment.ts (3 errors) ==== + var {o: [a1, a2, a3 = { b1: 1000, b4: 200 }]} = { o: [1, 2, { b1: 4, b4: 0 }] }; + var {o0: [c, d, { e: e1, f }, , ]} = { o0: [1, 2, { e: 4, f: 0 }] }; + var {o1: [a11, a21, { b12: b22, b42 },, ...c]} = { o1: [1, 2, { b12: 4, b42: 0 }] }; + ~~~ +!!! error TS2459: Type 'number | { b12: number; b42: number; }' has no property 'b12' and no string index signature. + ~~~ +!!! error TS2459: Type 'number | { b12: number; b42: number; }' has no property 'b42' and no string index signature. + ~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'c' must be of type 'number', but here has type '(number | { b12: number; b42: number; })[]'. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringVariableDeclarationAndAssignment.js b/tests/baselines/reference/destructuringVariableDeclarationAndAssignment.js new file mode 100644 index 00000000000..b089d2ab4fb --- /dev/null +++ b/tests/baselines/reference/destructuringVariableDeclarationAndAssignment.js @@ -0,0 +1,9 @@ +//// [destructuringVariableDeclarationAndAssignment.ts] +var {o: [a1, a2, a3 = { b1: 1000, b4: 200 }]} = { o: [1, 2, { b1: 4, b4: 0 }] }; +var {o0: [c, d, { e: e1, f }, , ]} = { o0: [1, 2, { e: 4, f: 0 }] }; +var {o1: [a11, a21, { b12: b22, b42 },, ...c]} = { o1: [1, 2, { b12: 4, b42: 0 }] }; + +//// [destructuringVariableDeclarationAndAssignment.js] +var _a = ({ o: [1, 2, { b1: 4, b4: 0 }] }).o, a1 = _a[0], a2 = _a[1], _b = _a[2], a3 = _b === void 0 ? { b1: 1000, b4: 200 } : _b; +var _c = ({ o0: [1, 2, { e: 4, f: 0 }] }).o0, c = _c[0], d = _c[1], _d = _c[2], e1 = _d.e, f = _d.f; +var _e = ({ o1: [1, 2, { b12: 4, b42: 0 }] }).o1, a11 = _e[0], a21 = _e[1], _f = _e[2], b22 = _f.b12, b42 = _f.b42, c = _e.slice(4); diff --git a/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1.ts b/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1.ts new file mode 100644 index 00000000000..4e6c46d2674 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1.ts @@ -0,0 +1,22 @@ +var [p0,p1, p2] : any = [2, 3, 4]; +var [a, b, c]: [number, number, string] = [1, 2, "string"]; +var [d, e]: any = undefined; +var [f = false, g = 1]: any = undefined; +g = 10; +f = true; + +var [x] = [] +var [[[y]], [[[[z]]]]] = [[[]], [[[[]]]]] +var [[w], m]: [[string|number], boolean] = [[1], true]; +interface J extends Array { + 2: number; +} + +var [, w1] = [1, 2, 3]; +var [,,, w2] = [1, 2, 3, 4]; +var [,,, w2] = [1, 2, 3, 4]; +var [,,,...w3] = [1, 2, 3, 4, "hello"]; + +var [r, s, ...t] = [1, 2, "string"]; +var [r1, s1, t1] = [1, 2, "string"]; + diff --git a/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts b/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts new file mode 100644 index 00000000000..3b094541d30 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts @@ -0,0 +1,13 @@ +function foo() { + return [1, 2, 3]; +} +interface J extends Array { + 2: number; +} + +function bar(): J { + return <[number, number, number]>[1, 2, 3]; +} + +var [j, k] = foo(); +var [...p] = foo(); diff --git a/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts b/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts new file mode 100644 index 00000000000..43f8c3546df --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts @@ -0,0 +1,23 @@ +interface H { + 0: number, + 1: string +} +interface J extends Array { + 2: number; +} + +function bar(): J { + return <[number, number, number]>[1, 2, 3]; +} + +function gg(idx: number) { + return { + [idx]: true + } +} + +var [h, g, i]: H = []; +var [[[y]], [[[[z]]]]] = [] +var [, , ...w4, , ] = [] +var [a = "string", b, c] = bar(); +var [r, s, t] = gg(1); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1.ts b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1.ts new file mode 100644 index 00000000000..f15541aaf90 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1.ts @@ -0,0 +1,12 @@ +var c = 0; +var { a, } = { a:1, }; +var { b: { c } } = { b: { c } }; +var { b1: { c1 } = { c1: "string" } } = { b1: { c1: "world" } }; +var { d1 }: any = undefined; +var { e1 }: any = {}; +var { f: {f1} = { f1: "string" } }: any = {}; +var { f2: {f21} = { f21: "string" } }: any = undefined; +var { e1: {e2} = { e2: "string" } }: any|{ e1: { e2 } } = undefined; +var { e2: {e3} = { e3: "string" } }: any|{ e2: { e3 } } = {}; +var {g = 1}: any = { g: 100000 }; +var {1: x} = { 1: "string" }; \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment2.ts b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment2.ts new file mode 100644 index 00000000000..026c901dbe7 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment2.ts @@ -0,0 +1,46 @@ +interface I { + j: number; + [str: string]: number; +} +interface J { + [str: string]: number; +} +function zz() { + return { + "cat": "dog", + } +} + +function zz1(): J { + return { + "cat": 1, + } +} + +function yy() { + return {} +} + +var {j}: I| J = { j: 1000 }; +var {cat} = zz(); +var {"cat":cart} = zz(); + +var {can}: J = {}; +var {can1}: J = zz1(); + + +function f() { + var { z }: { z: number } = { z }; +} + +interface K { + [idx: number]: boolean +} + +var {1: boo}: K = { 1: true }; +var {1: boo1}: K = { }; + +function bar(): K { + return { }; +} +var {1: baz} = bar(); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts new file mode 100644 index 00000000000..524728dc9d6 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts @@ -0,0 +1,10 @@ +var {h?} = { h?: 1 }; +var {i}: string | number = { i: 2 }; +var {i1}: string | number| {} = { i1: 2 }; +var { f2: {f21} = { f212: "string" } }: any = undefined; +var { b1: { c1 } = { c1: "string" } } = { b1: { c1: c } }; +var { d }: any; +var { ...d1 } = { + a: 1, b: 1, d1: 9, e: 10 +} +var {1} = { 1 }; \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment4.ts b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment4.ts new file mode 100644 index 00000000000..3cb7ae06581 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment4.ts @@ -0,0 +1,23 @@ +interface K { + [str: string]: string; +} +interface K1 { + k: string; +} +var {k}: K|K1 = { k: "string" }; + +function barn() { + return {}; +} +var {2: baz1} = barn() + +interface J { + [str: string]: number; +} +function zz() { + return { + "cat": "dog" + } +} + +var {"can": can}: J = zz(); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringVariableDeclarationAndAssignment.ts b/tests/cases/conformance/es6/destructuring/destructuringVariableDeclarationAndAssignment.ts new file mode 100644 index 00000000000..a3377dfb8f3 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringVariableDeclarationAndAssignment.ts @@ -0,0 +1,3 @@ +var {o: [a1, a2, a3 = { b1: 1000, b4: 200 }]} = { o: [1, 2, { b1: 4, b4: 0 }] }; +var {o0: [c, d, { e: e1, f }, , ]} = { o0: [1, 2, { e: 4, f: 0 }] }; +var {o1: [a11, a21, { b12: b22, b42 },, ...c]} = { o1: [1, 2, { b12: 4, b42: 0 }] }; \ No newline at end of file From 8899d5f056e807d7a2f0c172978dd9a9bada68da Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 15 Apr 2015 16:55:59 -0700 Subject: [PATCH 026/194] Add additional tests for typeguard for class or object property --- .../typeGuardsOnClassProperty.errors.txt | 37 +++++++++++++ .../reference/typeGuardsOnClassProperty.js | 54 +++++++++++++++++++ .../typeGuards/typeGuardsOnClassProperty.ts | 28 ++++++++++ 3 files changed, 119 insertions(+) create mode 100644 tests/baselines/reference/typeGuardsOnClassProperty.errors.txt create mode 100644 tests/baselines/reference/typeGuardsOnClassProperty.js create mode 100644 tests/cases/conformance/expressions/typeGuards/typeGuardsOnClassProperty.ts diff --git a/tests/baselines/reference/typeGuardsOnClassProperty.errors.txt b/tests/baselines/reference/typeGuardsOnClassProperty.errors.txt new file mode 100644 index 00000000000..7d56c9a2049 --- /dev/null +++ b/tests/baselines/reference/typeGuardsOnClassProperty.errors.txt @@ -0,0 +1,37 @@ +tests/cases/conformance/expressions/typeGuards/typeGuardsOnClassProperty.ts(14,71): error TS2339: Property 'join' does not exist on type 'string | string[]'. +tests/cases/conformance/expressions/typeGuards/typeGuardsOnClassProperty.ts(26,44): error TS2339: Property 'toLowerCase' does not exist on type 'string | number'. + + +==== tests/cases/conformance/expressions/typeGuards/typeGuardsOnClassProperty.ts (2 errors) ==== + // Note that type guards affect types of variables and parameters only and + // have no effect on members of objects such as properties. + + // Note that the class's property must be copied to a local variable for + // the type guard to have an affect + class D { + data: string | string[]; + getData() { + var data = this.data; + return typeof data === "string" ? data : data.join(" "); + } + + getData1() { + return typeof this.data === "string" ? this.data : this. data.join(" "); + ~~~~ +!!! error TS2339: Property 'join' does not exist on type 'string | string[]'. + } + } + + var o: { + prop1: number|string; + prop2: boolean|string; + } = { + prop1: "string" , + prop2: true + } + + if (typeof o.prop1 === "string" && o.prop1.toLowerCase()) {} + ~~~~~~~~~~~ +!!! error TS2339: Property 'toLowerCase' does not exist on type 'string | number'. + var prop1 = o.prop1; + if (typeof prop1 === "string" && prop1.toLocaleLowerCase()) { } \ No newline at end of file diff --git a/tests/baselines/reference/typeGuardsOnClassProperty.js b/tests/baselines/reference/typeGuardsOnClassProperty.js new file mode 100644 index 00000000000..5edecd36b86 --- /dev/null +++ b/tests/baselines/reference/typeGuardsOnClassProperty.js @@ -0,0 +1,54 @@ +//// [typeGuardsOnClassProperty.ts] +// Note that type guards affect types of variables and parameters only and +// have no effect on members of objects such as properties. + +// Note that the class's property must be copied to a local variable for +// the type guard to have an affect +class D { + data: string | string[]; + getData() { + var data = this.data; + return typeof data === "string" ? data : data.join(" "); + } + + getData1() { + return typeof this.data === "string" ? this.data : this. data.join(" "); + } +} + +var o: { + prop1: number|string; + prop2: boolean|string; +} = { + prop1: "string" , + prop2: true + } + +if (typeof o.prop1 === "string" && o.prop1.toLowerCase()) {} +var prop1 = o.prop1; +if (typeof prop1 === "string" && prop1.toLocaleLowerCase()) { } + +//// [typeGuardsOnClassProperty.js] +// Note that type guards affect types of variables and parameters only and +// have no effect on members of objects such as properties. +// Note that the class's property must be copied to a local variable for +// the type guard to have an affect +var D = (function () { + function D() { + } + D.prototype.getData = function () { + var data = this.data; + return typeof data === "string" ? data : data.join(" "); + }; + D.prototype.getData1 = function () { + return typeof this.data === "string" ? this.data : this.data.join(" "); + }; + return D; +})(); +var o = { + prop1: "string", + prop2: true +}; +if (typeof o.prop1 === "string" && o.prop1.toLowerCase()) { } +var prop1 = o.prop1; +if (typeof prop1 === "string" && prop1.toLocaleLowerCase()) { } diff --git a/tests/cases/conformance/expressions/typeGuards/typeGuardsOnClassProperty.ts b/tests/cases/conformance/expressions/typeGuards/typeGuardsOnClassProperty.ts new file mode 100644 index 00000000000..20a0bf8242a --- /dev/null +++ b/tests/cases/conformance/expressions/typeGuards/typeGuardsOnClassProperty.ts @@ -0,0 +1,28 @@ +// Note that type guards affect types of variables and parameters only and +// have no effect on members of objects such as properties. + +// Note that the class's property must be copied to a local variable for +// the type guard to have an affect +class D { + data: string | string[]; + getData() { + var data = this.data; + return typeof data === "string" ? data : data.join(" "); + } + + getData1() { + return typeof this.data === "string" ? this.data : this. data.join(" "); + } +} + +var o: { + prop1: number|string; + prop2: boolean|string; +} = { + prop1: "string" , + prop2: true + } + +if (typeof o.prop1 === "string" && o.prop1.toLowerCase()) {} +var prop1 = o.prop1; +if (typeof prop1 === "string" && prop1.toLocaleLowerCase()) { } \ No newline at end of file From ae4297930fae74dbce101a48144c063975cdb55f Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 15 Apr 2015 18:12:39 -0700 Subject: [PATCH 027/194] Add conformance tests for const enum --- tests/baselines/reference/constEnum1.js | 34 +++++++ tests/baselines/reference/constEnum1.types | 54 ++++++++++++ .../baselines/reference/constEnum2.errors.txt | 29 ++++++ tests/baselines/reference/constEnum2.js | 32 +++++++ .../reference/constEnumPropertyAccess1.js | 67 ++++++++++++++ .../reference/constEnumPropertyAccess1.types | 88 +++++++++++++++++++ .../constEnumPropertyAccess2.errors.txt | 35 ++++++++ .../reference/constEnumPropertyAccess2.js | 46 ++++++++++ .../conformance/constEnums/constEnum1.ts | 16 ++++ .../conformance/constEnums/constEnum2.ts | 15 ++++ .../constEnums/constEnumPropertyAccess1.ts | 32 +++++++ .../constEnums/constEnumPropertyAccess2.ts | 20 +++++ 12 files changed, 468 insertions(+) create mode 100644 tests/baselines/reference/constEnum1.js create mode 100644 tests/baselines/reference/constEnum1.types create mode 100644 tests/baselines/reference/constEnum2.errors.txt create mode 100644 tests/baselines/reference/constEnum2.js create mode 100644 tests/baselines/reference/constEnumPropertyAccess1.js create mode 100644 tests/baselines/reference/constEnumPropertyAccess1.types create mode 100644 tests/baselines/reference/constEnumPropertyAccess2.errors.txt create mode 100644 tests/baselines/reference/constEnumPropertyAccess2.js create mode 100644 tests/cases/conformance/constEnums/constEnum1.ts create mode 100644 tests/cases/conformance/constEnums/constEnum2.ts create mode 100644 tests/cases/conformance/constEnums/constEnumPropertyAccess1.ts create mode 100644 tests/cases/conformance/constEnums/constEnumPropertyAccess2.ts diff --git a/tests/baselines/reference/constEnum1.js b/tests/baselines/reference/constEnum1.js new file mode 100644 index 00000000000..d5ccede3ff1 --- /dev/null +++ b/tests/baselines/reference/constEnum1.js @@ -0,0 +1,34 @@ +//// [constEnum1.ts] + +// An enum declaration that specifies a const modifier is a constant enum declaration. +// In a constant enum declaration, all members must have constant values and +// it is an error for a member declaration to specify an expression that isn't classified as a constant enum expression. + +const enum E { + a = 10, + b = a, + c = (a+1), + e, + d = ~e, + f = a << 2 >> 1, + g = a << 2 >>> 1, + h = a | b +} + +//// [constEnum1.js] +// An enum declaration that specifies a const modifier is a constant enum declaration. +// In a constant enum declaration, all members must have constant values and +// it is an error for a member declaration to specify an expression that isn't classified as a constant enum expression. + + +//// [constEnum1.d.ts] +declare const enum E { + a = 10, + b = 10, + c = 11, + e = 12, + d = -13, + f = 20, + g = 20, + h = 10, +} diff --git a/tests/baselines/reference/constEnum1.types b/tests/baselines/reference/constEnum1.types new file mode 100644 index 00000000000..ef0e64d4377 --- /dev/null +++ b/tests/baselines/reference/constEnum1.types @@ -0,0 +1,54 @@ +=== tests/cases/conformance/constEnums/constEnum1.ts === + +// An enum declaration that specifies a const modifier is a constant enum declaration. +// In a constant enum declaration, all members must have constant values and +// it is an error for a member declaration to specify an expression that isn't classified as a constant enum expression. + +const enum E { +>E : E, Symbol(E, Decl(constEnum1.ts, 0, 0)) + + a = 10, +>a : E, Symbol(E.a, Decl(constEnum1.ts, 5, 14)) +>10 : number + + b = a, +>b : E, Symbol(E.b, Decl(constEnum1.ts, 6, 11)) +>a : E, Symbol(E.a, Decl(constEnum1.ts, 5, 14)) + + c = (a+1), +>c : E, Symbol(E.c, Decl(constEnum1.ts, 7, 10)) +>(a+1) : number +>a+1 : number +>a : E, Symbol(E.a, Decl(constEnum1.ts, 5, 14)) +>1 : number + + e, +>e : E, Symbol(E.e, Decl(constEnum1.ts, 8, 14)) + + d = ~e, +>d : E, Symbol(E.d, Decl(constEnum1.ts, 9, 6)) +>~e : number +>e : E, Symbol(E.e, Decl(constEnum1.ts, 8, 14)) + + f = a << 2 >> 1, +>f : E, Symbol(E.f, Decl(constEnum1.ts, 10, 11)) +>a << 2 >> 1 : number +>a << 2 : number +>a : E, Symbol(E.a, Decl(constEnum1.ts, 5, 14)) +>2 : number +>1 : number + + g = a << 2 >>> 1, +>g : E, Symbol(E.g, Decl(constEnum1.ts, 11, 20)) +>a << 2 >>> 1 : number +>a << 2 : number +>a : E, Symbol(E.a, Decl(constEnum1.ts, 5, 14)) +>2 : number +>1 : number + + h = a | b +>h : E, Symbol(E.h, Decl(constEnum1.ts, 12, 21)) +>a | b : number +>a : E, Symbol(E.a, Decl(constEnum1.ts, 5, 14)) +>b : E, Symbol(E.b, Decl(constEnum1.ts, 6, 11)) +} diff --git a/tests/baselines/reference/constEnum2.errors.txt b/tests/baselines/reference/constEnum2.errors.txt new file mode 100644 index 00000000000..f0cac0c2f5d --- /dev/null +++ b/tests/baselines/reference/constEnum2.errors.txt @@ -0,0 +1,29 @@ +tests/cases/conformance/constEnums/constEnum2.ts(11,9): error TS2474: In 'const' enum declarations member initializer must be constant expression. +tests/cases/conformance/constEnums/constEnum2.ts(12,9): error TS2474: In 'const' enum declarations member initializer must be constant expression. +tests/cases/conformance/constEnums/constEnum2.ts(13,5): error TS1005: ',' expected. +tests/cases/conformance/constEnums/constEnum2.ts(13,9): error TS2474: In 'const' enum declarations member initializer must be constant expression. + + +==== tests/cases/conformance/constEnums/constEnum2.ts (4 errors) ==== + + // An enum declaration that specifies a const modifier is a constant enum declaration. + // In a constant enum declaration, all members must have constant values and + // it is an error for a member declaration to specify an expression that isn't classified as a constant enum expression. + + // Error : not a constant enum expression + + const CONST = 9000 % 2; + const enum D { + d = 10, + e = 199 * Math.floor(Math.random() * 1000), + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2474: In 'const' enum declarations member initializer must be constant expression. + f = d - (100 * Math.floor(Math.random() % 8)) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2474: In 'const' enum declarations member initializer must be constant expression. + g = CONST, + ~ +!!! error TS1005: ',' expected. + ~~~~~ +!!! error TS2474: In 'const' enum declarations member initializer must be constant expression. + } \ No newline at end of file diff --git a/tests/baselines/reference/constEnum2.js b/tests/baselines/reference/constEnum2.js new file mode 100644 index 00000000000..c0c640b87fd --- /dev/null +++ b/tests/baselines/reference/constEnum2.js @@ -0,0 +1,32 @@ +//// [constEnum2.ts] + +// An enum declaration that specifies a const modifier is a constant enum declaration. +// In a constant enum declaration, all members must have constant values and +// it is an error for a member declaration to specify an expression that isn't classified as a constant enum expression. + +// Error : not a constant enum expression + +const CONST = 9000 % 2; +const enum D { + d = 10, + e = 199 * Math.floor(Math.random() * 1000), + f = d - (100 * Math.floor(Math.random() % 8)) + g = CONST, +} + +//// [constEnum2.js] +// An enum declaration that specifies a const modifier is a constant enum declaration. +// In a constant enum declaration, all members must have constant values and +// it is an error for a member declaration to specify an expression that isn't classified as a constant enum expression. +// Error : not a constant enum expression +var CONST = 9000 % 2; + + +//// [constEnum2.d.ts] +declare const CONST: number; +declare const enum D { + d = 10, + e, + f, + g, +} diff --git a/tests/baselines/reference/constEnumPropertyAccess1.js b/tests/baselines/reference/constEnumPropertyAccess1.js new file mode 100644 index 00000000000..114f1e1928e --- /dev/null +++ b/tests/baselines/reference/constEnumPropertyAccess1.js @@ -0,0 +1,67 @@ +//// [constEnumPropertyAccess1.ts] + +// constant enum declarations are completely erased in the emitted JavaScript code. +// it is an error to reference a constant enum object in any other context +// than a property access that selects one of the enum's members + +const enum G { + A = 1, + B = 2, + C = A + B, + D = A * 2 +} + +var o: { + [idx: number]: boolean +} = { + 1: true + }; + +var a = G.A; +var a1 = G["A"]; +var g = o[G.A]; + +class C { + [G.A]() { } + get [G.B]() { + return true; + } + set [G.B](x: number) { } +} + + + +//// [constEnumPropertyAccess1.js] +// constant enum declarations are completely erased in the emitted JavaScript code. +// it is an error to reference a constant enum object in any other context +// than a property access that selects one of the enum's members +var o = { + 1: true +}; +var a = 1 /* A */; +var a1 = 1 /* "A" */; +var g = o[1 /* A */]; +class C { + [1 /* A */]() { } + get [2 /* B */]() { + return true; + } + set [2 /* B */](x) { } +} + + +//// [constEnumPropertyAccess1.d.ts] +declare const enum G { + A = 1, + B = 2, + C = 3, + D = 2, +} +declare var o: { + [idx: number]: boolean; +}; +declare var a: G; +declare var a1: G; +declare var g: boolean; +declare class C { +} diff --git a/tests/baselines/reference/constEnumPropertyAccess1.types b/tests/baselines/reference/constEnumPropertyAccess1.types new file mode 100644 index 00000000000..bf0c727f1c0 --- /dev/null +++ b/tests/baselines/reference/constEnumPropertyAccess1.types @@ -0,0 +1,88 @@ +=== tests/cases/conformance/constEnums/constEnumPropertyAccess1.ts === + +// constant enum declarations are completely erased in the emitted JavaScript code. +// it is an error to reference a constant enum object in any other context +// than a property access that selects one of the enum's members + +const enum G { +>G : G, Symbol(G, Decl(constEnumPropertyAccess1.ts, 0, 0)) + + A = 1, +>A : G, Symbol(G.A, Decl(constEnumPropertyAccess1.ts, 5, 14)) +>1 : number + + B = 2, +>B : G, Symbol(G.B, Decl(constEnumPropertyAccess1.ts, 6, 10)) +>2 : number + + C = A + B, +>C : G, Symbol(G.C, Decl(constEnumPropertyAccess1.ts, 7, 10)) +>A + B : number +>A : G, Symbol(G.A, Decl(constEnumPropertyAccess1.ts, 5, 14)) +>B : G, Symbol(G.B, Decl(constEnumPropertyAccess1.ts, 6, 10)) + + D = A * 2 +>D : G, Symbol(G.D, Decl(constEnumPropertyAccess1.ts, 8, 14)) +>A * 2 : number +>A : G, Symbol(G.A, Decl(constEnumPropertyAccess1.ts, 5, 14)) +>2 : number +} + +var o: { +>o : { [idx: number]: boolean; }, Symbol(o, Decl(constEnumPropertyAccess1.ts, 12, 3)) + + [idx: number]: boolean +>idx : number, Symbol(idx, Decl(constEnumPropertyAccess1.ts, 13, 5)) + +} = { +>{ 1: true } : { [x: number]: boolean; 1: boolean; } + + 1: true +>true : boolean + + }; + +var a = G.A; +>a : G, Symbol(a, Decl(constEnumPropertyAccess1.ts, 18, 3)) +>G.A : G, Symbol(G.A, Decl(constEnumPropertyAccess1.ts, 5, 14)) +>G : typeof G, Symbol(G, Decl(constEnumPropertyAccess1.ts, 0, 0)) +>A : G, Symbol(G.A, Decl(constEnumPropertyAccess1.ts, 5, 14)) + +var a1 = G["A"]; +>a1 : G, Symbol(a1, Decl(constEnumPropertyAccess1.ts, 19, 3)) +>G["A"] : G +>G : typeof G, Symbol(G, Decl(constEnumPropertyAccess1.ts, 0, 0)) +>"A" : string, Symbol(G.A, Decl(constEnumPropertyAccess1.ts, 5, 14)) + +var g = o[G.A]; +>g : boolean, Symbol(g, Decl(constEnumPropertyAccess1.ts, 20, 3)) +>o[G.A] : boolean +>o : { [idx: number]: boolean; }, Symbol(o, Decl(constEnumPropertyAccess1.ts, 12, 3)) +>G.A : G, Symbol(G.A, Decl(constEnumPropertyAccess1.ts, 5, 14)) +>G : typeof G, Symbol(G, Decl(constEnumPropertyAccess1.ts, 0, 0)) +>A : G, Symbol(G.A, Decl(constEnumPropertyAccess1.ts, 5, 14)) + +class C { +>C : C, Symbol(C, Decl(constEnumPropertyAccess1.ts, 20, 15)) + + [G.A]() { } +>G.A : G, Symbol(G.A, Decl(constEnumPropertyAccess1.ts, 5, 14)) +>G : typeof G, Symbol(G, Decl(constEnumPropertyAccess1.ts, 0, 0)) +>A : G, Symbol(G.A, Decl(constEnumPropertyAccess1.ts, 5, 14)) + + get [G.B]() { +>G.B : G, Symbol(G.B, Decl(constEnumPropertyAccess1.ts, 6, 10)) +>G : typeof G, Symbol(G, Decl(constEnumPropertyAccess1.ts, 0, 0)) +>B : G, Symbol(G.B, Decl(constEnumPropertyAccess1.ts, 6, 10)) + + return true; +>true : boolean + } + set [G.B](x: number) { } +>G.B : G, Symbol(G.B, Decl(constEnumPropertyAccess1.ts, 6, 10)) +>G : typeof G, Symbol(G, Decl(constEnumPropertyAccess1.ts, 0, 0)) +>B : G, Symbol(G.B, Decl(constEnumPropertyAccess1.ts, 6, 10)) +>x : number, Symbol(x, Decl(constEnumPropertyAccess1.ts, 27, 14)) +} + + diff --git a/tests/baselines/reference/constEnumPropertyAccess2.errors.txt b/tests/baselines/reference/constEnumPropertyAccess2.errors.txt new file mode 100644 index 00000000000..19b273faffa --- /dev/null +++ b/tests/baselines/reference/constEnumPropertyAccess2.errors.txt @@ -0,0 +1,35 @@ +tests/cases/conformance/constEnums/constEnumPropertyAccess2.ts(14,9): error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment. +tests/cases/conformance/constEnums/constEnumPropertyAccess2.ts(15,12): error TS2476: A const enum member can only be accessed using a string literal. +tests/cases/conformance/constEnums/constEnumPropertyAccess2.ts(17,1): error TS2322: Type 'string' is not assignable to type 'G'. +tests/cases/conformance/constEnums/constEnumPropertyAccess2.ts(19,1): error TS2364: Invalid left-hand side of assignment expression. + + +==== tests/cases/conformance/constEnums/constEnumPropertyAccess2.ts (4 errors) ==== + + // constant enum declarations are completely erased in the emitted JavaScript code. + // it is an error to reference a constant enum object in any other context + // than a property access that selects one of the enum's members + + const enum G { + A = 1, + B = 2, + C = A + B, + D = A * 2 + } + + // Error from referring constant enum in any other context than a property access + var z = G; + ~ +!!! error TS2475: 'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment. + var z1 = G[G.A]; + ~~~ +!!! error TS2476: A const enum member can only be accessed using a string literal. + var g: G; + g = "string"; + ~ +!!! error TS2322: Type 'string' is not assignable to type 'G'. + function foo(x: G) { } + G.B = 3; + ~~~ +!!! error TS2364: Invalid left-hand side of assignment expression. + \ No newline at end of file diff --git a/tests/baselines/reference/constEnumPropertyAccess2.js b/tests/baselines/reference/constEnumPropertyAccess2.js new file mode 100644 index 00000000000..46a1d918b94 --- /dev/null +++ b/tests/baselines/reference/constEnumPropertyAccess2.js @@ -0,0 +1,46 @@ +//// [constEnumPropertyAccess2.ts] + +// constant enum declarations are completely erased in the emitted JavaScript code. +// it is an error to reference a constant enum object in any other context +// than a property access that selects one of the enum's members + +const enum G { + A = 1, + B = 2, + C = A + B, + D = A * 2 +} + +// Error from referring constant enum in any other context than a property access +var z = G; +var z1 = G[G.A]; +var g: G; +g = "string"; +function foo(x: G) { } +G.B = 3; + + +//// [constEnumPropertyAccess2.js] +// constant enum declarations are completely erased in the emitted JavaScript code. +// it is an error to reference a constant enum object in any other context +// than a property access that selects one of the enum's members +// Error from referring constant enum in any other context than a property access +var z = G; +var z1 = G[1 /* A */]; +var g; +g = "string"; +function foo(x) { } +2 /* B */ = 3; + + +//// [constEnumPropertyAccess2.d.ts] +declare const enum G { + A = 1, + B = 2, + C = 3, + D = 2, +} +declare var z: typeof G; +declare var z1: any; +declare var g: G; +declare function foo(x: G): void; diff --git a/tests/cases/conformance/constEnums/constEnum1.ts b/tests/cases/conformance/constEnums/constEnum1.ts new file mode 100644 index 00000000000..6bf59b772e9 --- /dev/null +++ b/tests/cases/conformance/constEnums/constEnum1.ts @@ -0,0 +1,16 @@ +// @declaration: true + +// An enum declaration that specifies a const modifier is a constant enum declaration. +// In a constant enum declaration, all members must have constant values and +// it is an error for a member declaration to specify an expression that isn't classified as a constant enum expression. + +const enum E { + a = 10, + b = a, + c = (a+1), + e, + d = ~e, + f = a << 2 >> 1, + g = a << 2 >>> 1, + h = a | b +} \ No newline at end of file diff --git a/tests/cases/conformance/constEnums/constEnum2.ts b/tests/cases/conformance/constEnums/constEnum2.ts new file mode 100644 index 00000000000..a90e83d6c43 --- /dev/null +++ b/tests/cases/conformance/constEnums/constEnum2.ts @@ -0,0 +1,15 @@ +// @declaration: true + +// An enum declaration that specifies a const modifier is a constant enum declaration. +// In a constant enum declaration, all members must have constant values and +// it is an error for a member declaration to specify an expression that isn't classified as a constant enum expression. + +// Error : not a constant enum expression + +const CONST = 9000 % 2; +const enum D { + d = 10, + e = 199 * Math.floor(Math.random() * 1000), + f = d - (100 * Math.floor(Math.random() % 8)) + g = CONST, +} \ No newline at end of file diff --git a/tests/cases/conformance/constEnums/constEnumPropertyAccess1.ts b/tests/cases/conformance/constEnums/constEnumPropertyAccess1.ts new file mode 100644 index 00000000000..bf1b277e3b5 --- /dev/null +++ b/tests/cases/conformance/constEnums/constEnumPropertyAccess1.ts @@ -0,0 +1,32 @@ +// @declaration: true +// @target: es6 + +// constant enum declarations are completely erased in the emitted JavaScript code. +// it is an error to reference a constant enum object in any other context +// than a property access that selects one of the enum's members + +const enum G { + A = 1, + B = 2, + C = A + B, + D = A * 2 +} + +var o: { + [idx: number]: boolean +} = { + 1: true + }; + +var a = G.A; +var a1 = G["A"]; +var g = o[G.A]; + +class C { + [G.A]() { } + get [G.B]() { + return true; + } + set [G.B](x: number) { } +} + diff --git a/tests/cases/conformance/constEnums/constEnumPropertyAccess2.ts b/tests/cases/conformance/constEnums/constEnumPropertyAccess2.ts new file mode 100644 index 00000000000..229f034269b --- /dev/null +++ b/tests/cases/conformance/constEnums/constEnumPropertyAccess2.ts @@ -0,0 +1,20 @@ +// @declaration: true + +// constant enum declarations are completely erased in the emitted JavaScript code. +// it is an error to reference a constant enum object in any other context +// than a property access that selects one of the enum's members + +const enum G { + A = 1, + B = 2, + C = A + B, + D = A * 2 +} + +// Error from referring constant enum in any other context than a property access +var z = G; +var z1 = G[G.A]; +var g: G; +g = "string"; +function foo(x: G) { } +G.B = 3; From 48b9a51370099b778535a5a42715eb08e471b661 Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 15 Apr 2015 23:25:32 -0700 Subject: [PATCH 028/194] Add conformance test for ambient enum declaration --- .../ambientEnumDeclaration1.errors.txt | 24 +++++++++++++++++++ .../reference/ambientEnumDeclaration1.js | 13 ++++++++++ .../reference/ambientEnumDeclaration2.js | 17 +++++++++++++ .../reference/ambientEnumDeclaration2.types | 23 ++++++++++++++++++ .../ambient/ambientEnumDeclaration1.ts | 9 +++++++ .../ambient/ambientEnumDeclaration2.ts | 12 ++++++++++ 6 files changed, 98 insertions(+) create mode 100644 tests/baselines/reference/ambientEnumDeclaration1.errors.txt create mode 100644 tests/baselines/reference/ambientEnumDeclaration1.js create mode 100644 tests/baselines/reference/ambientEnumDeclaration2.js create mode 100644 tests/baselines/reference/ambientEnumDeclaration2.types create mode 100644 tests/cases/conformance/ambient/ambientEnumDeclaration1.ts create mode 100644 tests/cases/conformance/ambient/ambientEnumDeclaration2.ts diff --git a/tests/baselines/reference/ambientEnumDeclaration1.errors.txt b/tests/baselines/reference/ambientEnumDeclaration1.errors.txt new file mode 100644 index 00000000000..419f7e184ac --- /dev/null +++ b/tests/baselines/reference/ambientEnumDeclaration1.errors.txt @@ -0,0 +1,24 @@ +tests/cases/conformance/ambient/ambientEnumDeclaration1.ts(5,5): error TS1066: Ambient enum elements can only have integer literal initializers. +tests/cases/conformance/ambient/ambientEnumDeclaration1.ts(6,5): error TS1066: Ambient enum elements can only have integer literal initializers. +tests/cases/conformance/ambient/ambientEnumDeclaration1.ts(7,5): error TS1066: Ambient enum elements can only have integer literal initializers. +tests/cases/conformance/ambient/ambientEnumDeclaration1.ts(8,5): error TS1066: Ambient enum elements can only have integer literal initializers. + + +==== tests/cases/conformance/ambient/ambientEnumDeclaration1.ts (4 errors) ==== + // In ambient enum declarations, all values specified in enum member declarations must be classified as constant enum expressions. + + declare enum E { + a = 10, + b = 10 + 1, + ~ +!!! error TS1066: Ambient enum elements can only have integer literal initializers. + c = b, + ~ +!!! error TS1066: Ambient enum elements can only have integer literal initializers. + d = (c) + 1, + ~ +!!! error TS1066: Ambient enum elements can only have integer literal initializers. + e = 10 << 2 * 8, + ~ +!!! error TS1066: Ambient enum elements can only have integer literal initializers. + } \ No newline at end of file diff --git a/tests/baselines/reference/ambientEnumDeclaration1.js b/tests/baselines/reference/ambientEnumDeclaration1.js new file mode 100644 index 00000000000..dcdb100e906 --- /dev/null +++ b/tests/baselines/reference/ambientEnumDeclaration1.js @@ -0,0 +1,13 @@ +//// [ambientEnumDeclaration1.ts] +// In ambient enum declarations, all values specified in enum member declarations must be classified as constant enum expressions. + +declare enum E { + a = 10, + b = 10 + 1, + c = b, + d = (c) + 1, + e = 10 << 2 * 8, +} + +//// [ambientEnumDeclaration1.js] +// In ambient enum declarations, all values specified in enum member declarations must be classified as constant enum expressions. diff --git a/tests/baselines/reference/ambientEnumDeclaration2.js b/tests/baselines/reference/ambientEnumDeclaration2.js new file mode 100644 index 00000000000..8ef6facfe6d --- /dev/null +++ b/tests/baselines/reference/ambientEnumDeclaration2.js @@ -0,0 +1,17 @@ +//// [ambientEnumDeclaration2.ts] +// In ambient enum declarations that specify no const modifier, enum member declarations +// that omit a value are considered computed members (as opposed to having auto- incremented values assigned). + +declare enum E { + a, // E.a + b, // E.b +} + +declare const enum E1 { + a, // E.a = 0 + b, // E.b = 1 +} + +//// [ambientEnumDeclaration2.js] +// In ambient enum declarations that specify no const modifier, enum member declarations +// that omit a value are considered computed members (as opposed to having auto- incremented values assigned). diff --git a/tests/baselines/reference/ambientEnumDeclaration2.types b/tests/baselines/reference/ambientEnumDeclaration2.types new file mode 100644 index 00000000000..2c87066b7fa --- /dev/null +++ b/tests/baselines/reference/ambientEnumDeclaration2.types @@ -0,0 +1,23 @@ +=== tests/cases/conformance/ambient/ambientEnumDeclaration2.ts === +// In ambient enum declarations that specify no const modifier, enum member declarations +// that omit a value are considered computed members (as opposed to having auto- incremented values assigned). + +declare enum E { +>E : E, Symbol(E, Decl(ambientEnumDeclaration2.ts, 0, 0)) + + a, // E.a +>a : E, Symbol(E.a, Decl(ambientEnumDeclaration2.ts, 3, 16)) + + b, // E.b +>b : E, Symbol(E.b, Decl(ambientEnumDeclaration2.ts, 4, 6)) +} + +declare const enum E1 { +>E1 : E1, Symbol(E1, Decl(ambientEnumDeclaration2.ts, 6, 1)) + + a, // E.a = 0 +>a : E1, Symbol(E1.a, Decl(ambientEnumDeclaration2.ts, 8, 23)) + + b, // E.b = 1 +>b : E1, Symbol(E1.b, Decl(ambientEnumDeclaration2.ts, 9, 6)) +} diff --git a/tests/cases/conformance/ambient/ambientEnumDeclaration1.ts b/tests/cases/conformance/ambient/ambientEnumDeclaration1.ts new file mode 100644 index 00000000000..9cafe943d13 --- /dev/null +++ b/tests/cases/conformance/ambient/ambientEnumDeclaration1.ts @@ -0,0 +1,9 @@ +// In ambient enum declarations, all values specified in enum member declarations must be classified as constant enum expressions. + +declare enum E { + a = 10, + b = 10 + 1, + c = b, + d = (c) + 1, + e = 10 << 2 * 8, +} \ No newline at end of file diff --git a/tests/cases/conformance/ambient/ambientEnumDeclaration2.ts b/tests/cases/conformance/ambient/ambientEnumDeclaration2.ts new file mode 100644 index 00000000000..dd6e1a1605e --- /dev/null +++ b/tests/cases/conformance/ambient/ambientEnumDeclaration2.ts @@ -0,0 +1,12 @@ +// In ambient enum declarations that specify no const modifier, enum member declarations +// that omit a value are considered computed members (as opposed to having auto- incremented values assigned). + +declare enum E { + a, // E.a + b, // E.b +} + +declare const enum E1 { + a, // E.a = 0 + b, // E.b = 1 +} \ No newline at end of file From 2499b3ebd562846e8986e5ed1aa0247135a9a95e Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 16 Apr 2015 10:21:49 -0700 Subject: [PATCH 029/194] Organize test files and add spec description in the comment --- .../diagnosticInformationMap.generated.ts | 1 - ...structuringParameterDeclaration.errors.txt | 37 --- .../destructuringParameterDeclaration.js | 58 ---- ...tructuringParameterDeclaration1.errors.txt | 265 ++++++++++++--- .../destructuringParameterDeclaration1.js | 305 ++++++++++++++---- ...cturingParameterDeclaration1ES6.errors.txt | 48 --- .../destructuringParameterDeclaration1ES6.js | 39 --- ...tructuringParameterDeclaration2.errors.txt | 149 ++++++--- .../destructuringParameterDeclaration2.js | 191 ++++++++--- .../destructuringParameterDeclaration2ES6.js | 42 --- ...ructuringParameterDeclaration3.errors.txt} | 46 ++- .../destructuringParameterDeclaration3.js | 80 +++-- .../destructuringParameterDeclaration3.types | 92 ------ .../destructuringParameterDeclaration3ES6.js | 45 --- ...estructuringParameterDeclaration3ES6.types | 92 ------ ...tructuringParameterDeclaration4.errors.txt | 93 ++++-- .../destructuringParameterDeclaration4.js | 137 +++++--- ...ucturingParameterDeclarationES6.errors.txt | 37 --- .../destructuringParameterDeclarationES6.js | 44 --- .../destructuringParameterDeclaration.ts | 19 -- .../destructuringParameterDeclaration1.ts | 121 +++++-- .../destructuringParameterDeclaration1ES6.ts | 22 -- .../destructuringParameterDeclaration2.ts | 68 +++- .../destructuringParameterDeclaration2ES6.ts | 20 -- .../destructuringParameterDeclaration3.ts | 35 +- .../destructuringParameterDeclaration3ES6.ts | 24 -- .../destructuringParameterDeclaration4.ts | 61 +++- .../destructuringParameterDeclarationES6.ts | 20 -- 28 files changed, 1171 insertions(+), 1020 deletions(-) delete mode 100644 tests/baselines/reference/destructuringParameterDeclaration.errors.txt delete mode 100644 tests/baselines/reference/destructuringParameterDeclaration.js delete mode 100644 tests/baselines/reference/destructuringParameterDeclaration1ES6.errors.txt delete mode 100644 tests/baselines/reference/destructuringParameterDeclaration1ES6.js delete mode 100644 tests/baselines/reference/destructuringParameterDeclaration2ES6.js rename tests/baselines/reference/{destructuringParameterDeclaration2ES6.errors.txt => destructuringParameterDeclaration3.errors.txt} (60%) delete mode 100644 tests/baselines/reference/destructuringParameterDeclaration3.types delete mode 100644 tests/baselines/reference/destructuringParameterDeclaration3ES6.js delete mode 100644 tests/baselines/reference/destructuringParameterDeclaration3ES6.types delete mode 100644 tests/baselines/reference/destructuringParameterDeclarationES6.errors.txt delete mode 100644 tests/baselines/reference/destructuringParameterDeclarationES6.js delete mode 100644 tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration.ts delete mode 100644 tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts delete mode 100644 tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts delete mode 100644 tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES6.ts delete mode 100644 tests/cases/conformance/es6/destructuring/destructuringParameterDeclarationES6.ts diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 0271ac73105..6e956889b49 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -1,6 +1,5 @@ // /// -/* @internal */ module ts { export var Diagnostics = { Unterminated_string_literal: { code: 1002, category: DiagnosticCategory.Error, key: "Unterminated string literal." }, diff --git a/tests/baselines/reference/destructuringParameterDeclaration.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration.errors.txt deleted file mode 100644 index 643305a0167..00000000000 --- a/tests/baselines/reference/destructuringParameterDeclaration.errors.txt +++ /dev/null @@ -1,37 +0,0 @@ -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration.ts(17,1): error TS2346: Supplied parameters do not match any signature of call target. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration.ts(18,4): error TS2345: Argument of type '{}' is not assignable to parameter of type '{ z: number; }'. - Property 'z' is missing in type '{}'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration.ts(19,14): error TS2300: Duplicate identifier 'z'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration.ts(19,18): error TS2300: Duplicate identifier 'z'. - - -==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration.ts (4 errors) ==== - enum Foo { a } - function a({x, a}: { x: number, a: number }) { } - function a1({z: {x, y: {j}}}) { } - function a2({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } - function a3({z} = {z:10}) { } - function a4({z=10}) { } - function a6({b}: { b: number|string|boolean } = { b: "hello" }) { } - a2(); - a2({ z: { x: "hello" , y: { j: Foo.a } }}); - a3(); - a3({ z: Foo.a }); - a4({}); - a6({ b: 10 }); - a6({ b: true }); - - // error - a4(); - ~~~~ -!!! error TS2346: Supplied parameters do not match any signature of call target. - a3({}); - ~~ -!!! error TS2345: Argument of type '{}' is not assignable to parameter of type '{ z: number; }'. -!!! error TS2345: Property 'z' is missing in type '{}'. - function a5([z], z: number) { } - ~ -!!! error TS2300: Duplicate identifier 'z'. - ~ -!!! error TS2300: Duplicate identifier 'z'. - \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterDeclaration.js b/tests/baselines/reference/destructuringParameterDeclaration.js deleted file mode 100644 index da979430ff3..00000000000 --- a/tests/baselines/reference/destructuringParameterDeclaration.js +++ /dev/null @@ -1,58 +0,0 @@ -//// [destructuringParameterDeclaration.ts] -enum Foo { a } -function a({x, a}: { x: number, a: number }) { } -function a1({z: {x, y: {j}}}) { } -function a2({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } -function a3({z} = {z:10}) { } -function a4({z=10}) { } -function a6({b}: { b: number|string|boolean } = { b: "hello" }) { } -a2(); -a2({ z: { x: "hello" , y: { j: Foo.a } }}); -a3(); -a3({ z: Foo.a }); -a4({}); -a6({ b: 10 }); -a6({ b: true }); - -// error -a4(); -a3({}); -function a5([z], z: number) { } - - -//// [destructuringParameterDeclaration.js] -var Foo; -(function (Foo) { - Foo[Foo["a"] = 0] = "a"; -})(Foo || (Foo = {})); -function a(_a) { - var x = _a.x, a = _a.a; -} -function a1(_a) { - var _b = _a.z, x = _b.x, j = _b.y.j; -} -function a2(_a) { - var _b = (_a === void 0 ? { z: { x: "hi", y: { j: 1 } } } : _a).z, x = _b.x, j = _b.y.j; -} -function a3(_a) { - var z = (_a === void 0 ? { z: 10 } : _a).z; -} -function a4(_a) { - var _b = _a.z, z = _b === void 0 ? 10 : _b; -} -function a6(_a) { - var b = (_a === void 0 ? { b: "hello" } : _a).b; -} -a2(); -a2({ z: { x: "hello", y: { j: Foo.a } } }); -a3(); -a3({ z: Foo.a }); -a4({}); -a6({ b: 10 }); -a6({ b: true }); -// error -a4(); -a3({}); -function a5(_a, z) { - var z = _a[0]; -} diff --git a/tests/baselines/reference/destructuringParameterDeclaration1.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration1.errors.txt index 2651be05038..cc0e8167d1c 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration1.errors.txt +++ b/tests/baselines/reference/destructuringParameterDeclaration1.errors.txt @@ -1,48 +1,233 @@ -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(5,16): error TS1048: A rest parameter cannot have an initializer. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(11,13): error TS2370: A rest parameter must be of an array type. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(12,18): error TS1047: A rest parameter cannot be optional. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(13,17): error TS1048: A rest parameter cannot have an initializer. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(16,19): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string | number'. - Type 'boolean' is not assignable to type 'number'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(21,4): error TS2345: Argument of type 'string | boolean' is not assignable to parameter of type 'string | number'. - Type 'boolean' is not assignable to type 'string | number'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(7,10): error TS2393: Duplicate function implementation. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(10,10): error TS2393: Duplicate function implementation. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(14,4): error TS2345: Argument of type '(string | number | string[][])[]' is not assignable to parameter of type '{ x: number; a: number; }'. + Property 'x' is missing in type '(string | number | string[][])[]'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(14,29): error TS1005: ',' expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(15,4): error TS2345: Argument of type '(string | number | string[][])[]' is not assignable to parameter of type '{ x: number; a: number; }'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(28,8): error TS2371: A parameter initializer is only allowed in a function or constructor implementation. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(28,16): error TS2371: A parameter initializer is only allowed in a function or constructor implementation. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(35,14): error TS2345: Argument of type '{ x: string; y: boolean; }' is not assignable to parameter of type '{ x: number; y: any; }'. + Types of property 'x' are incompatible. + Type 'string' is not assignable to type 'number'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(44,14): error TS2300: Duplicate identifier 'z'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(44,18): error TS2300: Duplicate identifier 'z'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(50,4): error TS2345: Argument of type '{ z: number; }' is not assignable to parameter of type '{ z: { x: any; y: { j: any; }; }; }'. + Types of property 'z' are incompatible. + Type 'number' is not assignable to type '{ x: any; y: { j: any; }; }'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(52,4): error TS2345: Argument of type '{}' is not assignable to parameter of type '{ z: number; }'. + Property 'z' is missing in type '{}'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(53,4): error TS2345: Argument of type '{ z: boolean; }' is not assignable to parameter of type '{ z: number; }'. + Types of property 'z' are incompatible. Type 'boolean' is not assignable to type 'number'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(59,4): error TS2345: Argument of type '{ z: boolean; }' is not assignable to parameter of type '{ z?: number; }'. + Types of property 'z' are incompatible. + Type 'boolean' is not assignable to type 'number'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(62,4): error TS2345: Argument of type '{ b: boolean; }' is not assignable to parameter of type '{ b: string | number; }'. + Types of property 'b' are incompatible. + Type 'boolean' is not assignable to type 'string | number'. + Type 'boolean' is not assignable to type 'number'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(66,4): error TS2345: Argument of type '[number, number, boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'. + Types of property '2' are incompatible. + Type 'boolean' is not assignable to type '[[any]]'. + Property '0' is missing in type 'Boolean'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(68,4): error TS2345: Argument of type '[number, number, [[string]]]' is not assignable to parameter of type '[any, any, [[number]]]'. + Types of property '2' are incompatible. + Type '[[string]]' is not assignable to type '[[number]]'. + Types of property '0' are incompatible. + Type '[string]' is not assignable to type '[number]'. + Types of property '0' are incompatible. + Type 'string' is not assignable to type 'number'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(73,10): error TS2393: Duplicate function implementation. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(74,10): error TS2393: Duplicate function implementation. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(75,13): error TS2463: A binding pattern parameter cannot be optional in an implementation signature. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(76,13): error TS2463: A binding pattern parameter cannot be optional in an implementation signature. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(97,7): error TS2420: Class 'C4' incorrectly implements interface 'F2'. + Types of property 'd4' are incompatible. + Type '({x, y, c}: { x: any; y: any; c: any; }) => void' is not assignable to type '({x, y, z}?: { x: any; y: any; z: any; }) => any'. + Types of parameters '__0' and '__0' are incompatible. + Type '{ x: any; y: any; c: any; }' is not assignable to type '{ x: any; y: any; z: any; }'. + Property 'z' is missing in type '{ x: any; y: any; c: any; }'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(98,8): error TS2463: A binding pattern parameter cannot be optional in an implementation signature. -==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts (6 errors) ==== - type arrayString = Array - type someArray = Array | number[]; - type stringOrNumArray = Array; +==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts (23 errors) ==== + // A parameter declaration may specify either an identifier or a binding pattern. + // The identifiers specified in parameter declarations and binding patterns + // in a parameter list must be unique within that parameter list. - function a3(...x = [1,2,3]) { } - ~ -!!! error TS1048: A rest parameter cannot have an initializer. - function a4(...x: (number|string)[]) { } - function a5(...a) { } - function a6(...a: Array) { } - function a7(...a: arrayString) { } - function a8(...a: stringOrNumArray) { } - function a9(...a: someArray) { } - ~~~~~~~~~~~~~~~ -!!! error TS2370: A rest parameter must be of an array type. - function a10(...b?) { } + // If the declaration includes a type annotation, the parameter is of that type + function a0(x: number, y: string, z: boolean) { } + function a1([a, b, [[c]]]: [number, number, string[][]]) { } + ~~ +!!! error TS2393: Duplicate function implementation. + function a2(o: { x: number, a: number }) { } + function a3({j, k, l: {m, n}, q: [a, b, c]}: { j: number, k: string, l: { m: boolean, n: number }, q: (number|string)[] }) { }; + function a1({x, a}: { x: number, a: number }) { } + ~~ +!!! error TS2393: Duplicate function implementation. + + a1([1, 2, [["world"]]]); + a1([1, 2, [["world"]], 3]); + a1([1, "string", [["world"]]); // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(string | number | string[][])[]' is not assignable to parameter of type '{ x: number; a: number; }'. +!!! error TS2345: Property 'x' is missing in type '(string | number | string[][])[]'. + ~ +!!! error TS1005: ',' expected. + a1([1, 2, [["world"]], "string"]); // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(string | number | string[][])[]' is not assignable to parameter of type '{ x: number; a: number; }'. + + + // If the declaration includes an initializer expression (which is permitted only + // when the parameter list occurs in conjunction with a function body), + // the parameter type is the widened form (section 3.11) of the type of the initializer expression. + + function b1(z = 10, y = 60, u = () => true) { } + function b2(z = [undefined, null]) { }; + function b3(z = null, o = { x: 0, y: undefined }) { } + function b4({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } + + interface F1 { + b5(z = 10, [[a, b], d, {u}] = [[1, 2], "string", { u: false }]); // Error, no function body + ~~~~~~ +!!! error TS2371: A parameter initializer is only allowed in a function or constructor implementation. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2371: A parameter initializer is only allowed in a function or constructor implementation. + b6(z, y, [, a, b], {p, m: { q, r}}); + } + + b2([1, 2, 3]); // z is widen to the type any[] + b3("string", { x: 200, y: "string" }); + b3("string", { x: 200, y: true }); + b3("string", { x: "string", y: true }); // Error + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ x: string; y: boolean; }' is not assignable to parameter of type '{ x: number; y: any; }'. +!!! error TS2345: Types of property 'x' are incompatible. +!!! error TS2345: Type 'string' is not assignable to type 'number'. + + + // If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3) + enum Foo { a } + function c0({z: {x, y: {j}}}) { } + function c1({z} = { z: 10 }) { } + function c2({z = 10}) { } + function c3({b}: { b: number|string} = { b: "hello" }) { } + function c4([z], z: number) { } // Duplicate identifier + ~ +!!! error TS2300: Duplicate identifier 'z'. ~ -!!! error TS1047: A rest parameter cannot be optional. - function a11(...b = [1,2,3]) { } - ~ -!!! error TS1048: A rest parameter cannot have an initializer. +!!! error TS2300: Duplicate identifier 'z'. + function c5([a, b, [[c]]]) { } + function c6([a, b, [[c=1]]]) { } + c0({z : { x: 1, y: { j: "world" } }}); // Implied type is { z: {x: any, y: {j: any}} } + c0({z : { x: "string", y: { j: true } }}); // Implied type is { z: {x: any, y: {j: any}} } + c0({z : 1}); // Error, implied type is { z: {x: any, y: {j: any}} } + ~~~~~~~ +!!! error TS2345: Argument of type '{ z: number; }' is not assignable to parameter of type '{ z: { x: any; y: { j: any; }; }; }'. +!!! error TS2345: Types of property 'z' are incompatible. +!!! error TS2345: Type 'number' is not assignable to type '{ x: any; y: { j: any; }; }'. - a4(1, 2, "hello", true); - ~~~~ -!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string | number'. -!!! error TS2345: Type 'boolean' is not assignable to type 'number'. - var array = [1, 2, 3]; - var array2 = [true, false, "hello"]; - a5([...array]); - a4(...array); - a4(...array2); + c1({}); // Error, implied type is {z:number}? + ~~ +!!! error TS2345: Argument of type '{}' is not assignable to parameter of type '{ z: number; }'. +!!! error TS2345: Property 'z' is missing in type '{}'. + c1({ z: true }); // Error, implied type is {z:number}? + ~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ z: boolean; }' is not assignable to parameter of type '{ z: number; }'. +!!! error TS2345: Types of property 'z' are incompatible. +!!! error TS2345: Type 'boolean' is not assignable to type 'number'. + c1(); // Implied type is {z:number}? + c1({ z: 1 }) // Implied type is {z:number}? + + c2({}); // Implied type is {z?: number} + c2({z:1}); // Implied type is {z?: number} + c2({z:false}); // Error, implied type is {z?: number} ~~~~~~~~~ -!!! error TS2345: Argument of type 'string | boolean' is not assignable to parameter of type 'string | number'. -!!! error TS2345: Type 'boolean' is not assignable to type 'string | number'. -!!! error TS2345: Type 'boolean' is not assignable to type 'number'. \ No newline at end of file +!!! error TS2345: Argument of type '{ z: boolean; }' is not assignable to parameter of type '{ z?: number; }'. +!!! error TS2345: Types of property 'z' are incompatible. +!!! error TS2345: Type 'boolean' is not assignable to type 'number'. + + c3({ b: 1 }); // Implied type is { b: number|string }. + c3({ b: true }); // Error, implied type is { b: number|string }. + ~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ b: boolean; }' is not assignable to parameter of type '{ b: string | number; }'. +!!! error TS2345: Types of property 'b' are incompatible. +!!! error TS2345: Type 'boolean' is not assignable to type 'string | number'. +!!! error TS2345: Type 'boolean' is not assignable to type 'number'. + + c5([1, 2, [["string"]]]); // Implied type is is [any, any, [[any]]] + c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]] + c5([1, 2, false, true]); // Error, implied type is [any, any, [[any]]] + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '[number, number, boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'. +!!! error TS2345: Types of property '2' are incompatible. +!!! error TS2345: Type 'boolean' is not assignable to type '[[any]]'. +!!! error TS2345: Property '0' is missing in type 'Boolean'. + + c6([1, 2, [["string"]]]); // Error, implied type is [any, any, [[number]]] // Use initializer + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '[number, number, [[string]]]' is not assignable to parameter of type '[any, any, [[number]]]'. +!!! error TS2345: Types of property '2' are incompatible. +!!! error TS2345: Type '[[string]]' is not assignable to type '[[number]]'. +!!! error TS2345: Types of property '0' are incompatible. +!!! error TS2345: Type '[string]' is not assignable to type '[number]'. +!!! error TS2345: Types of property '0' are incompatible. +!!! error TS2345: Type 'string' is not assignable to type 'number'. + + // A parameter can be marked optional by following its name or binding pattern with a question mark (?) + // or by including an initializer. + + function d0(x?) { } + ~~ +!!! error TS2393: Duplicate function implementation. + function d0(x = 10) { } + ~~ +!!! error TS2393: Duplicate function implementation. + function d1([a, b, c]?) { } + ~~~~~~~~~~ +!!! error TS2463: A binding pattern parameter cannot be optional in an implementation signature. + function d2({x, y, z}?) { } + ~~~~~~~~~~ +!!! error TS2463: A binding pattern parameter cannot be optional in an implementation signature. + + interface F2 { + d3([a, b, c]?); + d4({x, y, z}?); + e0([a, b, c]); + } + + class C2 implements F2 { + constructor() { } + d3() { } + d4() { } + e0([a, b, c]) { } + } + + class C3 implements F2 { + d3([a, b, c]) { } + d4({x, y, z}) { } + e0([a, b, c]) { } + } + + class C4 implements F2 { + ~~ +!!! error TS2420: Class 'C4' incorrectly implements interface 'F2'. +!!! error TS2420: Types of property 'd4' are incompatible. +!!! error TS2420: Type '({x, y, c}: { x: any; y: any; c: any; }) => void' is not assignable to type '({x, y, z}?: { x: any; y: any; z: any; }) => any'. +!!! error TS2420: Types of parameters '__0' and '__0' are incompatible. +!!! error TS2420: Type '{ x: any; y: any; c: any; }' is not assignable to type '{ x: any; y: any; z: any; }'. +!!! error TS2420: Property 'z' is missing in type '{ x: any; y: any; c: any; }'. + d3([a, b, c]?) { } + ~~~~~~~~~~ +!!! error TS2463: A binding pattern parameter cannot be optional in an implementation signature. + d4({x, y, c}) { } + e0([a, b, q]) { } + } + + function d5({x, y} = { x: 1, y: 2 }) { } + d5(); // Parameter is optional as its declaration included an initializer + + + \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterDeclaration1.js b/tests/baselines/reference/destructuringParameterDeclaration1.js index 37967ddb441..d8963511838 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration1.js +++ b/tests/baselines/reference/destructuringParameterDeclaration1.js @@ -1,86 +1,249 @@ //// [destructuringParameterDeclaration1.ts] -type arrayString = Array -type someArray = Array | number[]; -type stringOrNumArray = Array; +// A parameter declaration may specify either an identifier or a binding pattern. +// The identifiers specified in parameter declarations and binding patterns +// in a parameter list must be unique within that parameter list. -function a3(...x = [1,2,3]) { } -function a4(...x: (number|string)[]) { } -function a5(...a) { } -function a6(...a: Array) { } -function a7(...a: arrayString) { } -function a8(...a: stringOrNumArray) { } -function a9(...a: someArray) { } -function a10(...b?) { } -function a11(...b = [1,2,3]) { } +// If the declaration includes a type annotation, the parameter is of that type +function a0(x: number, y: string, z: boolean) { } +function a1([a, b, [[c]]]: [number, number, string[][]]) { } +function a2(o: { x: number, a: number }) { } +function a3({j, k, l: {m, n}, q: [a, b, c]}: { j: number, k: string, l: { m: boolean, n: number }, q: (number|string)[] }) { }; +function a1({x, a}: { x: number, a: number }) { } + +a1([1, 2, [["world"]]]); +a1([1, 2, [["world"]], 3]); +a1([1, "string", [["world"]]); // Error +a1([1, 2, [["world"]], "string"]); // Error -a4(1, 2, "hello", true); -var array = [1, 2, 3]; -var array2 = [true, false, "hello"]; -a5([...array]); -a4(...array); -a4(...array2); +// If the declaration includes an initializer expression (which is permitted only +// when the parameter list occurs in conjunction with a function body), +// the parameter type is the widened form (section 3.11) of the type of the initializer expression. + +function b1(z = 10, y = 60, u = () => true) { } +function b2(z = [undefined, null]) { }; +function b3(z = null, o = { x: 0, y: undefined }) { } +function b4({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } + +interface F1 { + b5(z = 10, [[a, b], d, {u}] = [[1, 2], "string", { u: false }]); // Error, no function body + b6(z, y, [, a, b], {p, m: { q, r}}); +} + +b2([1, 2, 3]); // z is widen to the type any[] +b3("string", { x: 200, y: "string" }); +b3("string", { x: 200, y: true }); +b3("string", { x: "string", y: true }); // Error + + +// If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3) +enum Foo { a } +function c0({z: {x, y: {j}}}) { } +function c1({z} = { z: 10 }) { } +function c2({z = 10}) { } +function c3({b}: { b: number|string} = { b: "hello" }) { } +function c4([z], z: number) { } // Duplicate identifier +function c5([a, b, [[c]]]) { } +function c6([a, b, [[c=1]]]) { } + +c0({z : { x: 1, y: { j: "world" } }}); // Implied type is { z: {x: any, y: {j: any}} } +c0({z : { x: "string", y: { j: true } }}); // Implied type is { z: {x: any, y: {j: any}} } +c0({z : 1}); // Error, implied type is { z: {x: any, y: {j: any}} } + +c1({}); // Error, implied type is {z:number}? +c1({ z: true }); // Error, implied type is {z:number}? +c1(); // Implied type is {z:number}? +c1({ z: 1 }) // Implied type is {z:number}? + +c2({}); // Implied type is {z?: number} +c2({z:1}); // Implied type is {z?: number} +c2({z:false}); // Error, implied type is {z?: number} + +c3({ b: 1 }); // Implied type is { b: number|string }. +c3({ b: true }); // Error, implied type is { b: number|string }. + +c5([1, 2, [["string"]]]); // Implied type is is [any, any, [[any]]] +c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]] +c5([1, 2, false, true]); // Error, implied type is [any, any, [[any]]] + +c6([1, 2, [["string"]]]); // Error, implied type is [any, any, [[number]]] // Use initializer + +// A parameter can be marked optional by following its name or binding pattern with a question mark (?) +// or by including an initializer. + +function d0(x?) { } +function d0(x = 10) { } +function d1([a, b, c]?) { } +function d2({x, y, z}?) { } + +interface F2 { + d3([a, b, c]?); + d4({x, y, z}?); + e0([a, b, c]); +} + +class C2 implements F2 { + constructor() { } + d3() { } + d4() { } + e0([a, b, c]) { } +} + +class C3 implements F2 { + d3([a, b, c]) { } + d4({x, y, z}) { } + e0([a, b, c]) { } +} + +class C4 implements F2 { + d3([a, b, c]?) { } + d4({x, y, c}) { } + e0([a, b, q]) { } +} + +function d5({x, y} = { x: 1, y: 2 }) { } +d5(); // Parameter is optional as its declaration included an initializer + + + //// [destructuringParameterDeclaration1.js] -function a3() { - if (x === void 0) { x = [1, 2, 3]; } - var x = []; - for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; - } +// A parameter declaration may specify either an identifier or a binding pattern. +// The identifiers specified in parameter declarations and binding patterns +// in a parameter list must be unique within that parameter list. +// If the declaration includes a type annotation, the parameter is of that type +function a0(x, y, z) { } +function a1(_a) { + var a = _a[0], b = _a[1], c = _a[2][0][0]; } -function a4() { - var x = []; - for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; - } +function a2(o) { } +function a3(_a) { + var j = _a.j, k = _a.k, _b = _a.l, m = _b.m, n = _b.n, _c = _a.q, a = _c[0], b = _c[1], c = _c[2]; } -function a5() { - var a = []; - for (var _i = 0; _i < arguments.length; _i++) { - a[_i - 0] = arguments[_i]; - } +; +function a1(_a) { + var x = _a.x, a = _a.a; } -function a6() { - var a = []; - for (var _i = 0; _i < arguments.length; _i++) { - a[_i - 0] = arguments[_i]; - } +a1([1, 2, [["world"]]]); +a1([1, 2, [["world"]], 3]); +a1([1, "string", [["world"]]]); // Error +a1([1, 2, [["world"]], "string"]); // Error +// If the declaration includes an initializer expression (which is permitted only +// when the parameter list occurs in conjunction with a function body), +// the parameter type is the widened form (section 3.11) of the type of the initializer expression. +function b1(z, y, u) { + if (z === void 0) { z = 10; } + if (y === void 0) { y = 60; } + if (u === void 0) { u = function () { return true; }; } } -function a7() { - var a = []; - for (var _i = 0; _i < arguments.length; _i++) { - a[_i - 0] = arguments[_i]; - } +function b2(z) { + if (z === void 0) { z = [undefined, null]; } } -function a8() { - var a = []; - for (var _i = 0; _i < arguments.length; _i++) { - a[_i - 0] = arguments[_i]; - } +; +function b3(z, o) { + if (z === void 0) { z = null; } + if (o === void 0) { o = { x: 0, y: undefined }; } } -function a9() { - var a = []; - for (var _i = 0; _i < arguments.length; _i++) { - a[_i - 0] = arguments[_i]; - } +function b4(_a) { + var _b = (_a === void 0 ? { z: { x: "hi", y: { j: 1 } } } : _a).z, x = _b.x, j = _b.y.j; } -function a10() { - var b = []; - for (var _i = 0; _i < arguments.length; _i++) { - b[_i - 0] = arguments[_i]; - } +b2([1, 2, 3]); // z is widen to the type any[] +b3("string", { x: 200, y: "string" }); +b3("string", { x: 200, y: true }); +b3("string", { x: "string", y: true }); // Error +// If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3) +var Foo; +(function (Foo) { + Foo[Foo["a"] = 0] = "a"; +})(Foo || (Foo = {})); +function c0(_a) { + var _b = _a.z, x = _b.x, j = _b.y.j; } -function a11() { - if (b === void 0) { b = [1, 2, 3]; } - var b = []; - for (var _i = 0; _i < arguments.length; _i++) { - b[_i - 0] = arguments[_i]; - } +function c1(_a) { + var z = (_a === void 0 ? { z: 10 } : _a).z; } -a4(1, 2, "hello", true); -var array = [1, 2, 3]; -var array2 = [true, false, "hello"]; -a5(array); -a4.apply(void 0, array); -a4.apply(void 0, array2); +function c2(_a) { + var _b = _a.z, z = _b === void 0 ? 10 : _b; +} +function c3(_a) { + var b = (_a === void 0 ? { b: "hello" } : _a).b; +} +function c4(_a, z) { + var z = _a[0]; +} // Duplicate identifier +function c5(_a) { + var a = _a[0], b = _a[1], c = _a[2][0][0]; +} +function c6(_a) { + var a = _a[0], b = _a[1], _b = _a[2][0][0], c = _b === void 0 ? 1 : _b; +} +c0({ z: { x: 1, y: { j: "world" } } }); // Implied type is { z: {x: any, y: {j: any}} } +c0({ z: { x: "string", y: { j: true } } }); // Implied type is { z: {x: any, y: {j: any}} } +c0({ z: 1 }); // Error, implied type is { z: {x: any, y: {j: any}} } +c1({}); // Error, implied type is {z:number}? +c1({ z: true }); // Error, implied type is {z:number}? +c1(); // Implied type is {z:number}? +c1({ z: 1 }); // Implied type is {z:number}? +c2({}); // Implied type is {z?: number} +c2({ z: 1 }); // Implied type is {z?: number} +c2({ z: false }); // Error, implied type is {z?: number} +c3({ b: 1 }); // Implied type is { b: number|string }. +c3({ b: true }); // Error, implied type is { b: number|string }. +c5([1, 2, [["string"]]]); // Implied type is is [any, any, [[any]]] +c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]] +c5([1, 2, false, true]); // Error, implied type is [any, any, [[any]]] +c6([1, 2, [["string"]]]); // Error, implied type is [any, any, [[number]]] // Use initializer +// A parameter can be marked optional by following its name or binding pattern with a question mark (?) +// or by including an initializer. +function d0(x) { } +function d0(x) { + if (x === void 0) { x = 10; } +} +function d1(_a) { + var a = _a[0], b = _a[1], c = _a[2]; +} +function d2(_a) { + var x = _a.x, y = _a.y, z = _a.z; +} +var C2 = (function () { + function C2() { + } + C2.prototype.d3 = function () { }; + C2.prototype.d4 = function () { }; + C2.prototype.e0 = function (_a) { + var a = _a[0], b = _a[1], c = _a[2]; + }; + return C2; +})(); +var C3 = (function () { + function C3() { + } + C3.prototype.d3 = function (_a) { + var a = _a[0], b = _a[1], c = _a[2]; + }; + C3.prototype.d4 = function (_a) { + var x = _a.x, y = _a.y, z = _a.z; + }; + C3.prototype.e0 = function (_a) { + var a = _a[0], b = _a[1], c = _a[2]; + }; + return C3; +})(); +var C4 = (function () { + function C4() { + } + C4.prototype.d3 = function (_a) { + var a = _a[0], b = _a[1], c = _a[2]; + }; + C4.prototype.d4 = function (_a) { + var x = _a.x, y = _a.y, c = _a.c; + }; + C4.prototype.e0 = function (_a) { + var a = _a[0], b = _a[1], q = _a[2]; + }; + return C4; +})(); +function d5(_a) { + var _b = _a === void 0 ? { x: 1, y: 2 } : _a, x = _b.x, y = _b.y; +} +d5(); // Parameter is optional as its declaration included an initializer diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES6.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration1ES6.errors.txt deleted file mode 100644 index 786571c88a5..00000000000 --- a/tests/baselines/reference/destructuringParameterDeclaration1ES6.errors.txt +++ /dev/null @@ -1,48 +0,0 @@ -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts(5,16): error TS1048: A rest parameter cannot have an initializer. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts(11,13): error TS2370: A rest parameter must be of an array type. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts(12,18): error TS1047: A rest parameter cannot be optional. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts(13,17): error TS1048: A rest parameter cannot have an initializer. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts(16,19): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string | number'. - Type 'boolean' is not assignable to type 'number'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts(21,4): error TS2345: Argument of type 'string | boolean' is not assignable to parameter of type 'string | number'. - Type 'boolean' is not assignable to type 'string | number'. - Type 'boolean' is not assignable to type 'number'. - - -==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts (6 errors) ==== - type arrayString = Array - type someArray = Array | number[]; - type stringOrNumArray = Array; - - function a3(...x = [1,2,3]) { } - ~ -!!! error TS1048: A rest parameter cannot have an initializer. - function a4(...x: (number|string)[]) { } - function a5(...a) { } - function a6(...a: Array) { } - function a7(...a: arrayString) { } - function a8(...a: stringOrNumArray) { } - function a9(...a: someArray) { } - ~~~~~~~~~~~~~~~ -!!! error TS2370: A rest parameter must be of an array type. - function a10(...b?) { } - ~ -!!! error TS1047: A rest parameter cannot be optional. - function a11(...b = [1,2,3]) { } - ~ -!!! error TS1048: A rest parameter cannot have an initializer. - - - a4(1, 2, "hello", true); - ~~~~ -!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string | number'. -!!! error TS2345: Type 'boolean' is not assignable to type 'number'. - var array = [1, 2, 3]; - var array2 = [true, false, "hello"]; - a5([...array]); - a4(...array); - a4(...array2); - ~~~~~~~~~ -!!! error TS2345: Argument of type 'string | boolean' is not assignable to parameter of type 'string | number'. -!!! error TS2345: Type 'boolean' is not assignable to type 'string | number'. -!!! error TS2345: Type 'boolean' is not assignable to type 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES6.js b/tests/baselines/reference/destructuringParameterDeclaration1ES6.js deleted file mode 100644 index 779f5495f56..00000000000 --- a/tests/baselines/reference/destructuringParameterDeclaration1ES6.js +++ /dev/null @@ -1,39 +0,0 @@ -//// [destructuringParameterDeclaration1ES6.ts] -type arrayString = Array -type someArray = Array | number[]; -type stringOrNumArray = Array; - -function a3(...x = [1,2,3]) { } -function a4(...x: (number|string)[]) { } -function a5(...a) { } -function a6(...a: Array) { } -function a7(...a: arrayString) { } -function a8(...a: stringOrNumArray) { } -function a9(...a: someArray) { } -function a10(...b?) { } -function a11(...b = [1,2,3]) { } - - -a4(1, 2, "hello", true); -var array = [1, 2, 3]; -var array2 = [true, false, "hello"]; -a5([...array]); -a4(...array); -a4(...array2); - -//// [destructuringParameterDeclaration1ES6.js] -function a3(...x = [1, 2, 3]) { } -function a4(...x) { } -function a5(...a) { } -function a6(...a) { } -function a7(...a) { } -function a8(...a) { } -function a9(...a) { } -function a10(...b) { } -function a11(...b = [1, 2, 3]) { } -a4(1, 2, "hello", true); -var array = [1, 2, 3]; -var array2 = [true, false, "hello"]; -a5([...array]); -a4(...array); -a4(...array2); diff --git a/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt index afe984cc031..314c1aafee6 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt +++ b/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt @@ -1,56 +1,117 @@ -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(6,14): error TS1181: Array element destructuring pattern expected. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(6,19): error TS1005: '(' expected. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(6,21): error TS1109: Expression expected. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(6,24): error TS1005: '(' expected. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(6,26): error TS2304: Cannot find name 'public'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(6,32): error TS1005: ';' expected. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(6,33): error TS1128: Declaration or statement expected. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(7,16): error TS1003: Identifier expected. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(7,21): error TS1005: '(' expected. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(9,13): error TS2370: A rest parameter must be of an array type. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(12,24): error TS1005: ',' expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(11,13): error TS2370: A rest parameter must be of an array type. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(17,13): error TS2370: A rest parameter must be of an array type. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(25,19): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string | number'. + Type 'boolean' is not assignable to type 'number'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(30,4): error TS2345: Argument of type 'string | boolean' is not assignable to parameter of type 'string | number'. + Type 'boolean' is not assignable to type 'string | number'. + Type 'boolean' is not assignable to type 'number'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(33,4): error TS2345: Argument of type '[number, number, string, boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'. + Types of property '2' are incompatible. + Type 'string' is not assignable to type '[[any]]'. + Property '0' is missing in type 'String'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(34,4): error TS2345: Argument of type '[number, number]' is not assignable to parameter of type '[any, any, [[any]]]'. + Property '2' is missing in type '[number, number]'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(41,5): error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'. + Type 'string | number' is not assignable to type 'number'. + Type 'string' is not assignable to type 'number'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(45,24): error TS1005: ',' expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(50,1): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. + Type argument candidate 'string' is not a valid type argument because it is not a supertype of candidate 'number'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(59,1): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. + Type argument candidate 'number' is not a valid type argument because it is not a supertype of candidate 'string'. -==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts (11 errors) ==== - "use strict" - function a({while}) { } - function a1({public}) { } - function a2({public: x}) { } - function a3({while: y}) { } - function a4([while, for, public]){ } - ~~~~~ -!!! error TS1181: Array element destructuring pattern expected. - ~ -!!! error TS1005: '(' expected. - ~~~ -!!! error TS1109: Expression expected. - ~ -!!! error TS1005: '(' expected. - ~~~~~~ -!!! error TS2304: Cannot find name 'public'. - ~ -!!! error TS1005: ';' expected. - ~ -!!! error TS1128: Declaration or statement expected. - function a5(...while) { } - ~~~~~ -!!! error TS1003: Identifier expected. - ~ -!!! error TS1005: '(' expected. - function a6(...public) { } - function a7(...a: string) { } - ~~~~~~~~~~~~ +==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts (10 errors) ==== + // If the parameter is a rest parameter, the parameter type is any[] + // A type annotation for a rest parameter must denote an array type. + + // RestParameter: + // ... Identifier TypeAnnotation(opt) + + type arrayString = Array + type someArray = Array | number[]; + type stringOrNumArray = Array; + + function a0(...x: [number, number, string]) { } // Error, rest parameter must be array type + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2370: A rest parameter must be of an array type. + function a1(...x: (number|string)[]) { } + function a2(...a) { } + function a3(...a: Array) { } + function a4(...a: arrayString) { } + function a5(...a: stringOrNumArray) { } + function a6(...a: someArray) { } // Error, rest parameter must be array type + ~~~~~~~~~~~~~~~ +!!! error TS2370: A rest parameter must be of an array type. + function a7(...b?) { } // Error, can't be optional + function a8(...b = [1,2,3]) { } // Error, can't have initializer + function a9([a, b, [[c]]]) { } + function a10([a, b, [[c]], ...x]) { } + function a11([a, b, c, ...x]: number[]) { } + + + a1(1, 2, "hello", true); // Error, parameter type is (number|string)[] + ~~~~ +!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string | number'. +!!! error TS2345: Type 'boolean' is not assignable to type 'number'. + var array = [1, 2, 3]; + var array2 = [true, false, "hello"]; + a2([...array]); + a1(...array); + a1(...array2); // Error parameter type is (number|string)[] + ~~~~~~~~~ +!!! error TS2345: Argument of type 'string | boolean' is not assignable to parameter of type 'string | number'. +!!! error TS2345: Type 'boolean' is not assignable to type 'string | number'. +!!! error TS2345: Type 'boolean' is not assignable to type 'number'. + + a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]] + a9([1, 2, "string", false, true]); // Error, parameter type is [any, any, [[any]]] + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '[number, number, string, boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'. +!!! error TS2345: Types of property '2' are incompatible. +!!! error TS2345: Type 'string' is not assignable to type '[[any]]'. +!!! error TS2345: Property '0' is missing in type 'String'. + a9([1, 2]); // Error, parameter type is [any, any, [[any]]] + ~~~~~~ +!!! error TS2345: Argument of type '[number, number]' is not assignable to parameter of type '[any, any, [[any]]]'. +!!! error TS2345: Property '2' is missing in type '[number, number]'. + + a10([1, 2, [["string"]], false, true]); // Parameter type is any[] + a10([1, 2, 3, false, true]); // Parameter type is any[] + a10([1, 2]); // Parameter type is any[] + + a11([1, 2]); // Parameter type is number[] + a11([1, 2, "string"]); // Error, parameter type is number[] + ~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'. +!!! error TS2345: Type 'string | number' is not assignable to type 'number'. +!!! error TS2345: Type 'string' is not assignable to type 'number'. + class C { - constructor(public ...a) { } + constructor(public ...a) { } // Rest parameter can't have accessibilityModifier ~~~ !!! error TS1005: ',' expected. } + // Rest parameter with generic + function foo(...a: T[]) { } + foo("hello", 1, 2); // Error + ~~~ +!!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. +!!! error TS2453: Type argument candidate 'string' is not a valid type argument because it is not a supertype of candidate 'number'. + foo("hello", 1, 2); + foo("hello", "world"); + + enum E { a, b } + const enum E1 { a, b } + function foo1(...a: T[]) { } + foo1(1, 2, 3, E.a); + foo1(1, 2, 3, E1.a, E.b); + foo1(1, 2, "string", E1.a, E.b); // Error + ~~~~ +!!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. +!!! error TS2453: Type argument candidate 'number' is not a valid type argument because it is not a supertype of candidate 'string'. - a2({ public: 1 }); - a3({ while: 1 }); - a({ while: 1 }); \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterDeclaration2.js b/tests/baselines/reference/destructuringParameterDeclaration2.js index ba6d7548442..11bda7049e2 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration2.js +++ b/tests/baselines/reference/destructuringParameterDeclaration2.js @@ -1,65 +1,178 @@ //// [destructuringParameterDeclaration2.ts] -"use strict" -function a({while}) { } -function a1({public}) { } -function a2({public: x}) { } -function a3({while: y}) { } -function a4([while, for, public]){ } -function a5(...while) { } -function a6(...public) { } -function a7(...a: string) { } +// If the parameter is a rest parameter, the parameter type is any[] +// A type annotation for a rest parameter must denote an array type. + +// RestParameter: +// ... Identifier TypeAnnotation(opt) + +type arrayString = Array +type someArray = Array | number[]; +type stringOrNumArray = Array; + +function a0(...x: [number, number, string]) { } // Error, rest parameter must be array type +function a1(...x: (number|string)[]) { } +function a2(...a) { } +function a3(...a: Array) { } +function a4(...a: arrayString) { } +function a5(...a: stringOrNumArray) { } +function a6(...a: someArray) { } // Error, rest parameter must be array type +function a7(...b?) { } // Error, can't be optional +function a8(...b = [1,2,3]) { } // Error, can't have initializer +function a9([a, b, [[c]]]) { } +function a10([a, b, [[c]], ...x]) { } +function a11([a, b, c, ...x]: number[]) { } + + +a1(1, 2, "hello", true); // Error, parameter type is (number|string)[] +var array = [1, 2, 3]; +var array2 = [true, false, "hello"]; +a2([...array]); +a1(...array); +a1(...array2); // Error parameter type is (number|string)[] + +a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]] +a9([1, 2, "string", false, true]); // Error, parameter type is [any, any, [[any]]] +a9([1, 2]); // Error, parameter type is [any, any, [[any]]] + +a10([1, 2, [["string"]], false, true]); // Parameter type is any[] +a10([1, 2, 3, false, true]); // Parameter type is any[] +a10([1, 2]); // Parameter type is any[] + +a11([1, 2]); // Parameter type is number[] +a11([1, 2, "string"]); // Error, parameter type is number[] + class C { - constructor(public ...a) { } + constructor(public ...a) { } // Rest parameter can't have accessibilityModifier } +// Rest parameter with generic +function foo(...a: T[]) { } +foo("hello", 1, 2); // Error +foo("hello", 1, 2); +foo("hello", "world"); + +enum E { a, b } +const enum E1 { a, b } +function foo1(...a: T[]) { } +foo1(1, 2, 3, E.a); +foo1(1, 2, 3, E1.a, E.b); +foo1(1, 2, "string", E1.a, E.b); // Error -a2({ public: 1 }); -a3({ while: 1 }); -a({ while: 1 }); //// [destructuringParameterDeclaration2.js] -"use strict"; -function a(_a) { - var while = _a.while; -} -function a1(_a) { - var public = _a.public; -} -function a2(_a) { - var x = _a.public; -} -function a3(_a) { - var y = _a.while; -} -while (, ) - for (, public; ; ) - ; -{ } -while () { } -function a6() { - var public = []; +// If the parameter is a rest parameter, the parameter type is any[] +// A type annotation for a rest parameter must denote an array type. +function a0() { + var x = []; for (var _i = 0; _i < arguments.length; _i++) { - public[_i - 0] = arguments[_i]; + x[_i - 0] = arguments[_i]; + } +} // Error, rest parameter must be array type +function a1() { + var x = []; + for (var _i = 0; _i < arguments.length; _i++) { + x[_i - 0] = arguments[_i]; } } -function a7() { +function a2() { var a = []; for (var _i = 0; _i < arguments.length; _i++) { a[_i - 0] = arguments[_i]; } } +function a3() { + var a = []; + for (var _i = 0; _i < arguments.length; _i++) { + a[_i - 0] = arguments[_i]; + } +} +function a4() { + var a = []; + for (var _i = 0; _i < arguments.length; _i++) { + a[_i - 0] = arguments[_i]; + } +} +function a5() { + var a = []; + for (var _i = 0; _i < arguments.length; _i++) { + a[_i - 0] = arguments[_i]; + } +} +function a6() { + var a = []; + for (var _i = 0; _i < arguments.length; _i++) { + a[_i - 0] = arguments[_i]; + } +} // Error, rest parameter must be array type +function a7() { + var b = []; + for (var _i = 0; _i < arguments.length; _i++) { + b[_i - 0] = arguments[_i]; + } +} // Error, can't be optional +function a8() { + if (b === void 0) { b = [1, 2, 3]; } + var b = []; + for (var _i = 0; _i < arguments.length; _i++) { + b[_i - 0] = arguments[_i]; + } +} // Error, can't have initializer +function a9(_a) { + var a = _a[0], b = _a[1], c = _a[2][0][0]; +} +function a10(_a) { + var a = _a[0], b = _a[1], c = _a[2][0][0], x = _a.slice(3); +} +function a11(_a) { + var a = _a[0], b = _a[1], c = _a[2], x = _a.slice(3); +} +a1(1, 2, "hello", true); // Error, parameter type is (number|string)[] +var array = [1, 2, 3]; +var array2 = [true, false, "hello"]; +a2(array); +a1.apply(void 0, array); +a1.apply(void 0, array2); // Error parameter type is (number|string)[] +a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]] +a9([1, 2, "string", false, true]); // Error, parameter type is [any, any, [[any]]] +a9([1, 2]); // Error, parameter type is [any, any, [[any]]] +a10([1, 2, [["string"]], false, true]); // Parameter type is any[] +a10([1, 2, 3, false, true]); // Parameter type is any[] +a10([1, 2]); // Parameter type is any[] +a11([1, 2]); // Parameter type is number[] +a11([1, 2, "string"]); // Error, parameter type is number[] var C = (function () { function C(public) { var a = []; for (var _i = 1; _i < arguments.length; _i++) { a[_i - 1] = arguments[_i]; } - } + } // Rest parameter can't have accessibilityModifier return C; })(); -a2({ public: 1 }); -a3({ while: 1 }); -a({ while: 1 }); +// Rest parameter with generic +function foo() { + var a = []; + for (var _i = 0; _i < arguments.length; _i++) { + a[_i - 0] = arguments[_i]; + } +} +foo("hello", 1, 2); // Error +foo("hello", 1, 2); +foo("hello", "world"); +var E; +(function (E) { + E[E["a"] = 0] = "a"; + E[E["b"] = 1] = "b"; +})(E || (E = {})); +function foo1() { + var a = []; + for (var _i = 0; _i < arguments.length; _i++) { + a[_i - 0] = arguments[_i]; + } +} +foo1(1, 2, 3, E.a); +foo1(1, 2, 3, 0 /* a */, E.b); +foo1(1, 2, "string", 0 /* a */, E.b); // Error diff --git a/tests/baselines/reference/destructuringParameterDeclaration2ES6.js b/tests/baselines/reference/destructuringParameterDeclaration2ES6.js deleted file mode 100644 index 6e86aa2c001..00000000000 --- a/tests/baselines/reference/destructuringParameterDeclaration2ES6.js +++ /dev/null @@ -1,42 +0,0 @@ -//// [destructuringParameterDeclaration2ES6.ts] -"use strict" -function a({while}) { } -function a1({public}) { } -function a2({public: x}) { } -function a3({while: y}) { } -function a4([while, for, public]){ } -function a5(...while) { } -function a6(...public) { } -function a7(...a: string) { } - -class C { - constructor(public ...a) { } -} - - -a2({ public: 1 }); -a3({ while: 1 }); -a({ while: 1 }); - - - -//// [destructuringParameterDeclaration2ES6.js] -"use strict"; -function a({ while }) { } -function a1({ public }) { } -function a2({ public: x }) { } -function a3({ while: y }) { } -while (, ) - for (, public; ; ) - ; -{ } -while () { } -function a6(...public) { } -function a7(...a) { } -class C { - constructor(public, ...a) { - } -} -a2({ public: 1 }); -a3({ while: 1 }); -a({ while: 1 }); diff --git a/tests/baselines/reference/destructuringParameterDeclaration2ES6.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration3.errors.txt similarity index 60% rename from tests/baselines/reference/destructuringParameterDeclaration2ES6.errors.txt rename to tests/baselines/reference/destructuringParameterDeclaration3.errors.txt index 762a0e1dd8a..57777582731 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration2ES6.errors.txt +++ b/tests/baselines/reference/destructuringParameterDeclaration3.errors.txt @@ -1,22 +1,24 @@ -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(6,14): error TS1181: Array element destructuring pattern expected. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(6,19): error TS1005: '(' expected. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(6,21): error TS1109: Expression expected. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(6,24): error TS1005: '(' expected. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(6,26): error TS2304: Cannot find name 'public'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(6,32): error TS1005: ';' expected. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(6,33): error TS1128: Declaration or statement expected. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(7,16): error TS1003: Identifier expected. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(7,21): error TS1005: '(' expected. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(9,13): error TS2370: A rest parameter must be of an array type. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts(12,24): error TS1005: ',' expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts(9,14): error TS1181: Array element destructuring pattern expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts(9,19): error TS1005: '(' expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts(9,21): error TS1109: Expression expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts(9,24): error TS1005: '(' expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts(9,26): error TS2304: Cannot find name 'public'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts(9,32): error TS1005: ';' expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts(9,33): error TS1128: Declaration or statement expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts(10,16): error TS1003: Identifier expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts(10,21): error TS1005: '(' expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts(12,13): error TS2370: A rest parameter must be of an array type. -==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts (11 errors) ==== +==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts (10 errors) ==== + // A parameter declaration may specify either an identifier or a binding pattern. + + // Reserved words are not allowed to be used as an identifier in parameter declaration "use strict" + + // Error function a({while}) { } function a1({public}) { } - function a2({public: x}) { } - function a3({while: y}) { } function a4([while, for, public]){ } ~~~~~ !!! error TS1181: Array element destructuring pattern expected. @@ -41,16 +43,12 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6. function a7(...a: string) { } ~~~~~~~~~~~~ !!! error TS2370: A rest parameter must be of an array type. - - class C { - constructor(public ...a) { } - ~~~ -!!! error TS1005: ',' expected. - } - - - a2({ public: 1 }); - a3({ while: 1 }); a({ while: 1 }); + // No Error + function b1({public: x}) { } + function b2({while: y}) { } + b1({ public: 1 }); + b2({ while: 1 }); + \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterDeclaration3.js b/tests/baselines/reference/destructuringParameterDeclaration3.js index 82d1404881c..a1abb86bd63 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration3.js +++ b/tests/baselines/reference/destructuringParameterDeclaration3.js @@ -1,51 +1,61 @@ //// [destructuringParameterDeclaration3.ts] -function a([x, [y, z], [[j]]]) { - return [x, y, z, j]; -} +// A parameter declaration may specify either an identifier or a binding pattern. -function a1([...x]) { - return [x]; -} +// Reserved words are not allowed to be used as an identifier in parameter declaration +"use strict" -function a2({public} = { "public": "1" }) { - return public; -} +// Error +function a({while}) { } +function a1({public}) { } +function a4([while, for, public]){ } +function a5(...while) { } +function a6(...public) { } +function a7(...a: string) { } +a({ while: 1 }); -function a3({x: { y, z}, j: {k: {a}} }) { - return [y, z, a]; -} +// No Error +function b1({public: x}) { } +function b2({while: y}) { } +b1({ public: 1 }); +b2({ while: 1 }); -function a4({x: { y, z}, j: {k: {a}} } = { x: { y: 1, z: 1 }, j: { k: { a: "hello" } } }): (number| string) [] { - return [y, z, a]; -} - -function a5({x: { y, z}, j: {k: {a}} }): (number| string) [] { - return [y, z, a]; -} //// [destructuringParameterDeclaration3.js] +// A parameter declaration may specify either an identifier or a binding pattern. +// Reserved words are not allowed to be used as an identifier in parameter declaration +"use strict"; +// Error function a(_a) { - var x = _a[0], _b = _a[1], y = _b[0], z = _b[1], j = _a[2][0][0]; - return [x, y, z, j]; + var while = _a.while; } function a1(_a) { - var x = _a.slice(0); - return [x]; + var public = _a.public; } -function a2(_a) { - var public = (_a === void 0 ? { "public": "1" } : _a).public; - return public; +while (, ) + for (, public; ; ) + ; +{ } +while () { } +function a6() { + var public = []; + for (var _i = 0; _i < arguments.length; _i++) { + public[_i - 0] = arguments[_i]; + } } -function a3(_a) { - var _b = _a.x, y = _b.y, z = _b.z, a = _a.j.k.a; - return [y, z, a]; +function a7() { + var a = []; + for (var _i = 0; _i < arguments.length; _i++) { + a[_i - 0] = arguments[_i]; + } } -function a4(_a) { - var _b = _a === void 0 ? { x: { y: 1, z: 1 }, j: { k: { a: "hello" } } } : _a, _c = _b.x, y = _c.y, z = _c.z, a = _b.j.k.a; - return [y, z, a]; +a({ while: 1 }); +// No Error +function b1(_a) { + var x = _a.public; } -function a5(_a) { - var _b = _a.x, y = _b.y, z = _b.z, a = _a.j.k.a; - return [y, z, a]; +function b2(_a) { + var y = _a.while; } +b1({ public: 1 }); +b2({ while: 1 }); diff --git a/tests/baselines/reference/destructuringParameterDeclaration3.types b/tests/baselines/reference/destructuringParameterDeclaration3.types deleted file mode 100644 index 41835d9e456..00000000000 --- a/tests/baselines/reference/destructuringParameterDeclaration3.types +++ /dev/null @@ -1,92 +0,0 @@ -=== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts === -function a([x, [y, z], [[j]]]) { ->a : ([x, [y, z], [[j]]]: [any, [any, any], [[any]]]) => any[] ->x : any ->y : any ->z : any ->j : any - - return [x, y, z, j]; ->[x, y, z, j] : any[] ->x : any ->y : any ->z : any ->j : any -} - -function a1([...x]) { ->a1 : ([...x]: any[]) => any[][] ->x : any[] - - return [x]; ->[x] : any[][] ->x : any[] -} - -function a2({public} = { "public": "1" }) { ->a2 : ({public}?: { "public": string; }) => string ->public : string ->{ "public": "1" } : { "public": string; } - - return public; ->public : string -} - -function a3({x: { y, z}, j: {k: {a}} }) { ->a3 : ({x: { y, z}, j: {k: {a}} }: { x: { y: any; z: any; }; j: { k: { a: any; }; }; }) => any[] ->x : unknown ->y : any ->z : any ->j : unknown ->k : unknown ->a : any - - return [y, z, a]; ->[y, z, a] : any[] ->y : any ->z : any ->a : any -} - -function a4({x: { y, z}, j: {k: {a}} } = { x: { y: 1, z: 1 }, j: { k: { a: "hello" } } }): (number| string) [] { ->a4 : ({x: { y, z}, j: {k: {a}} }?: { x: { y: number; z: number; }; j: { k: { a: string; }; }; }) => (string | number)[] ->x : unknown ->y : number ->z : number ->j : unknown ->k : unknown ->a : string ->{ x: { y: 1, z: 1 }, j: { k: { a: "hello" } } } : { x: { y: number; z: number; }; j: { k: { a: string; }; }; } ->x : { y: number; z: number; } ->{ y: 1, z: 1 } : { y: number; z: number; } ->y : number ->z : number ->j : { k: { a: string; }; } ->{ k: { a: "hello" } } : { k: { a: string; }; } ->k : { a: string; } ->{ a: "hello" } : { a: string; } ->a : string - - return [y, z, a]; ->[y, z, a] : (string | number)[] ->y : number ->z : number ->a : string -} - -function a5({x: { y, z}, j: {k: {a}} }): (number| string) [] { ->a5 : ({x: { y, z}, j: {k: {a}} }: { x: { y: any; z: any; }; j: { k: { a: any; }; }; }) => (string | number)[] ->x : unknown ->y : any ->z : any ->j : unknown ->k : unknown ->a : any - - return [y, z, a]; ->[y, z, a] : any[] ->y : any ->z : any ->a : any -} - diff --git a/tests/baselines/reference/destructuringParameterDeclaration3ES6.js b/tests/baselines/reference/destructuringParameterDeclaration3ES6.js deleted file mode 100644 index e129140f3f2..00000000000 --- a/tests/baselines/reference/destructuringParameterDeclaration3ES6.js +++ /dev/null @@ -1,45 +0,0 @@ -//// [destructuringParameterDeclaration3ES6.ts] -function a([x, [y, z], [[j]]]) { - return [x, y, z, j]; -} - -function a1([...x]) { - return [x]; -} - -function a2({public} = { "public": "1" }) { - return public; -} - -function a3({x: { y, z}, j: {k: {a}} }) { - return [y, z, a]; -} - -function a4({x: { y, z}, j: {k: {a}} } = { x: { y: 1, z: 1 }, j: { k: { a: "hello" } } }): (number| string) [] { - return [y, z, a]; -} - -function a5({x: { y, z}, j: {k: {a}} }): (number| string) [] { - return [y, z, a]; -} - - -//// [destructuringParameterDeclaration3ES6.js] -function a([x, [y, z], [[j]]]) { - return [x, y, z, j]; -} -function a1([...x]) { - return [x]; -} -function a2({ public } = { "public": "1" }) { - return public; -} -function a3({ x: { y, z }, j: { k: { a } } }) { - return [y, z, a]; -} -function a4({ x: { y, z }, j: { k: { a } } } = { x: { y: 1, z: 1 }, j: { k: { a: "hello" } } }) { - return [y, z, a]; -} -function a5({ x: { y, z }, j: { k: { a } } }) { - return [y, z, a]; -} diff --git a/tests/baselines/reference/destructuringParameterDeclaration3ES6.types b/tests/baselines/reference/destructuringParameterDeclaration3ES6.types deleted file mode 100644 index 01c67e1e547..00000000000 --- a/tests/baselines/reference/destructuringParameterDeclaration3ES6.types +++ /dev/null @@ -1,92 +0,0 @@ -=== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES6.ts === -function a([x, [y, z], [[j]]]) { ->a : ([x, [y, z], [[j]]]: [any, [any, any], [[any]]]) => any[] ->x : any ->y : any ->z : any ->j : any - - return [x, y, z, j]; ->[x, y, z, j] : any[] ->x : any ->y : any ->z : any ->j : any -} - -function a1([...x]) { ->a1 : ([...x]: Iterable) => any[][] ->x : any[] - - return [x]; ->[x] : any[][] ->x : any[] -} - -function a2({public} = { "public": "1" }) { ->a2 : ({public}?: { "public": string; }) => string ->public : string ->{ "public": "1" } : { "public": string; } - - return public; ->public : string -} - -function a3({x: { y, z}, j: {k: {a}} }) { ->a3 : ({x: { y, z}, j: {k: {a}} }: { x: { y: any; z: any; }; j: { k: { a: any; }; }; }) => any[] ->x : unknown ->y : any ->z : any ->j : unknown ->k : unknown ->a : any - - return [y, z, a]; ->[y, z, a] : any[] ->y : any ->z : any ->a : any -} - -function a4({x: { y, z}, j: {k: {a}} } = { x: { y: 1, z: 1 }, j: { k: { a: "hello" } } }): (number| string) [] { ->a4 : ({x: { y, z}, j: {k: {a}} }?: { x: { y: number; z: number; }; j: { k: { a: string; }; }; }) => (string | number)[] ->x : unknown ->y : number ->z : number ->j : unknown ->k : unknown ->a : string ->{ x: { y: 1, z: 1 }, j: { k: { a: "hello" } } } : { x: { y: number; z: number; }; j: { k: { a: string; }; }; } ->x : { y: number; z: number; } ->{ y: 1, z: 1 } : { y: number; z: number; } ->y : number ->z : number ->j : { k: { a: string; }; } ->{ k: { a: "hello" } } : { k: { a: string; }; } ->k : { a: string; } ->{ a: "hello" } : { a: string; } ->a : string - - return [y, z, a]; ->[y, z, a] : (string | number)[] ->y : number ->z : number ->a : string -} - -function a5({x: { y, z}, j: {k: {a}} }): (number| string) [] { ->a5 : ({x: { y, z}, j: {k: {a}} }: { x: { y: any; z: any; }; j: { k: { a: any; }; }; }) => (string | number)[] ->x : unknown ->y : any ->z : any ->j : unknown ->k : unknown ->a : any - - return [y, z, a]; ->[y, z, a] : any[] ->y : any ->z : any ->a : any -} - diff --git a/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt index cf4b15d1271..d5d0888e632 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt +++ b/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt @@ -1,27 +1,78 @@ -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(15,1): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. - Type argument candidate 'string' is not a valid type argument because it is not a supertype of candidate 'number'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(46,4): error TS2345: Argument of type '{ y: Class; }' is not assignable to parameter of type '{ y: D; }'. + Types of property 'y' are incompatible. + Type 'Class' is not assignable to type 'D'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(47,4): error TS2345: Argument of type '{}' is not assignable to parameter of type '{ y: D; }'. + Property 'y' is missing in type '{}'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(48,4): error TS2345: Argument of type '{ y: number; }' is not assignable to parameter of type '{ y: D; }'. + Types of property 'y' are incompatible. + Type 'number' is not assignable to type 'D'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(49,4): error TS2345: Argument of type '{ y: string; }' is not assignable to parameter of type '{ y: D; }'. + Types of property 'y' are incompatible. + Type 'string' is not assignable to type 'D'. -==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts (1 errors) ==== +==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts (4 errors) ==== + // Parameter with generic interface F { } - class C implements F{ + class Class implements F { + constructor() { } } - function foo(...a: T[]) { } - function foo1(...a: T[]) { } - function bar({x} = { x: new C() }) { } - function baz({x}: { x: F }) { } - function baz1({x}: { x: C }) { } - function baz2({x}: { x: C }) { } - var obj = new C(); - baz1({ x: obj }); - baz({ x: new C() }); - baz({ x: {} }); - foo("hello", 1, 2); - ~~~ -!!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. -!!! error TS2453: Type argument candidate 'string' is not a valid type argument because it is not a supertype of candidate 'number'. - foo("hello", 1, 2); - foo("hello", "world"); + class SubClass extends Class { + foo: boolean; + constructor() { super(); } + } - \ No newline at end of file + class D implements F { + foo: boolean + constructor() { } + } + + class SubD extends D { + bar: number + constructor() { + super(); + } + } + + + function d0({x} = { x: new Class() }) { } + function d1({x}: { x: F }) { } + function d2({x}: { x: Class }) { } + function d3({y}: { y: D }) { } + function d4({y} = { y: new D() }) { } + + var obj = new Class(); + d0({ x: 1 }); + d0({ x: {} }); + d0({ x: "string" }); + + d1({ x: new Class() }); + d1({ x: {} }); + d1({ x: "string" }); + + d2({ x: new SubClass() }); + d2({ x: {} }); + + d3({ y: new SubD() }); + d3({ y: new SubClass() }); + // Error + d3({ y: new Class() }); + ~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ y: Class; }' is not assignable to parameter of type '{ y: D; }'. +!!! error TS2345: Types of property 'y' are incompatible. +!!! error TS2345: Type 'Class' is not assignable to type 'D'. + d3({}); + ~~ +!!! error TS2345: Argument of type '{}' is not assignable to parameter of type '{ y: D; }'. +!!! error TS2345: Property 'y' is missing in type '{}'. + d3({ y: 1 }); + ~~~~~~~~ +!!! error TS2345: Argument of type '{ y: number; }' is not assignable to parameter of type '{ y: D; }'. +!!! error TS2345: Types of property 'y' are incompatible. +!!! error TS2345: Type 'number' is not assignable to type 'D'. + d3({ y: "world" }); + ~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ y: string; }' is not assignable to parameter of type '{ y: D; }'. +!!! error TS2345: Types of property 'y' are incompatible. +!!! error TS2345: Type 'string' is not assignable to type 'D'. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterDeclaration4.js b/tests/baselines/reference/destructuringParameterDeclaration4.js index 3f83402dffa..3eb0b3f8c19 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration4.js +++ b/tests/baselines/reference/destructuringParameterDeclaration4.js @@ -1,58 +1,113 @@ //// [destructuringParameterDeclaration4.ts] +// Parameter with generic interface F { } -class C implements F{ +class Class implements F { + constructor() { } } -function foo(...a: T[]) { } -function foo1(...a: T[]) { } -function bar({x} = { x: new C() }) { } -function baz({x}: { x: F }) { } -function baz1({x}: { x: C }) { } -function baz2({x}: { x: C }) { } -var obj = new C(); -baz1({ x: obj }); -baz({ x: new C() }); -baz({ x: {} }); -foo("hello", 1, 2); -foo("hello", 1, 2); -foo("hello", "world"); +class SubClass extends Class { + foo: boolean; + constructor() { super(); } +} - +class D implements F { + foo: boolean + constructor() { } +} + +class SubD extends D { + bar: number + constructor() { + super(); + } +} + + +function d0({x} = { x: new Class() }) { } +function d1({x}: { x: F }) { } +function d2({x}: { x: Class }) { } +function d3({y}: { y: D }) { } +function d4({y} = { y: new D() }) { } + +var obj = new Class(); +d0({ x: 1 }); +d0({ x: {} }); +d0({ x: "string" }); + +d1({ x: new Class() }); +d1({ x: {} }); +d1({ x: "string" }); + +d2({ x: new SubClass() }); +d2({ x: {} }); + +d3({ y: new SubD() }); +d3({ y: new SubClass() }); +// Error +d3({ y: new Class() }); +d3({}); +d3({ y: 1 }); +d3({ y: "world" }); //// [destructuringParameterDeclaration4.js] -var C = (function () { - function C() { +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 Class = (function () { + function Class() { } - return C; + return Class; })(); -function foo() { - var a = []; - for (var _i = 0; _i < arguments.length; _i++) { - a[_i - 0] = arguments[_i]; +var SubClass = (function (_super) { + __extends(SubClass, _super); + function SubClass() { + _super.call(this); } -} -function foo1() { - var a = []; - for (var _i = 0; _i < arguments.length; _i++) { - a[_i - 0] = arguments[_i]; + return SubClass; +})(Class); +var D = (function () { + function D() { } + return D; +})(); +var SubD = (function (_super) { + __extends(SubD, _super); + function SubD() { + _super.call(this); + } + return SubD; +})(D); +function d0(_a) { + var x = (_a === void 0 ? { x: new Class() } : _a).x; } -function bar(_a) { - var x = (_a === void 0 ? { x: new C() } : _a).x; -} -function baz(_a) { +function d1(_a) { var x = _a.x; } -function baz1(_a) { +function d2(_a) { var x = _a.x; } -function baz2(_a) { - var x = _a.x; +function d3(_a) { + var y = _a.y; } -var obj = new C(); -baz1({ x: obj }); -baz({ x: new C() }); -baz({ x: {} }); -foo("hello", 1, 2); -foo("hello", 1, 2); -foo("hello", "world"); +function d4(_a) { + var y = (_a === void 0 ? { y: new D() } : _a).y; +} +var obj = new Class(); +d0({ x: 1 }); +d0({ x: {} }); +d0({ x: "string" }); +d1({ x: new Class() }); +d1({ x: {} }); +d1({ x: "string" }); +d2({ x: new SubClass() }); +d2({ x: {} }); +d3({ y: new SubD() }); +d3({ y: new SubClass() }); +// Error +d3({ y: new Class() }); +d3({}); +d3({ y: 1 }); +d3({ y: "world" }); diff --git a/tests/baselines/reference/destructuringParameterDeclarationES6.errors.txt b/tests/baselines/reference/destructuringParameterDeclarationES6.errors.txt deleted file mode 100644 index 21cd9f36c0f..00000000000 --- a/tests/baselines/reference/destructuringParameterDeclarationES6.errors.txt +++ /dev/null @@ -1,37 +0,0 @@ -tests/cases/conformance/es6/destructuring/destructuringParameterDeclarationES6.ts(17,1): error TS2346: Supplied parameters do not match any signature of call target. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclarationES6.ts(18,4): error TS2345: Argument of type '{}' is not assignable to parameter of type '{ z: number; }'. - Property 'z' is missing in type '{}'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclarationES6.ts(19,14): error TS2300: Duplicate identifier 'z'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclarationES6.ts(19,18): error TS2300: Duplicate identifier 'z'. - - -==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclarationES6.ts (4 errors) ==== - enum Foo { a } - function a({x, a}: { x: number, a: number }) { } - function a1({z: {x, y: {j}}}) { } - function a2({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } - function a3({z} = {z:10}) { } - function a4({z=10}) { } - function a6({b}: { b: number|string|boolean } = { b: "hello" }) { } - a2(); - a2({ z: { x: "hello" , y: { j: Foo.a } }}); - a3(); - a3({ z: Foo.a }); - a4({}); - a6({ b: 10 }); - a6({ b: true }); - - // error - a4(); - ~~~~ -!!! error TS2346: Supplied parameters do not match any signature of call target. - a3({}); - ~~ -!!! error TS2345: Argument of type '{}' is not assignable to parameter of type '{ z: number; }'. -!!! error TS2345: Property 'z' is missing in type '{}'. - function a5([z], z: number) { } - ~ -!!! error TS2300: Duplicate identifier 'z'. - ~ -!!! error TS2300: Duplicate identifier 'z'. - \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterDeclarationES6.js b/tests/baselines/reference/destructuringParameterDeclarationES6.js deleted file mode 100644 index 7a4c929003d..00000000000 --- a/tests/baselines/reference/destructuringParameterDeclarationES6.js +++ /dev/null @@ -1,44 +0,0 @@ -//// [destructuringParameterDeclarationES6.ts] -enum Foo { a } -function a({x, a}: { x: number, a: number }) { } -function a1({z: {x, y: {j}}}) { } -function a2({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } -function a3({z} = {z:10}) { } -function a4({z=10}) { } -function a6({b}: { b: number|string|boolean } = { b: "hello" }) { } -a2(); -a2({ z: { x: "hello" , y: { j: Foo.a } }}); -a3(); -a3({ z: Foo.a }); -a4({}); -a6({ b: 10 }); -a6({ b: true }); - -// error -a4(); -a3({}); -function a5([z], z: number) { } - - -//// [destructuringParameterDeclarationES6.js] -var Foo; -(function (Foo) { - Foo[Foo["a"] = 0] = "a"; -})(Foo || (Foo = {})); -function a({ x, a }) { } -function a1({ z: { x, y: { j } } }) { } -function a2({ z: { x, y: { j } } } = { z: { x: "hi", y: { j: 1 } } }) { } -function a3({ z } = { z: 10 }) { } -function a4({ z = 10 }) { } -function a6({ b } = { b: "hello" }) { } -a2(); -a2({ z: { x: "hello", y: { j: Foo.a } } }); -a3(); -a3({ z: Foo.a }); -a4({}); -a6({ b: 10 }); -a6({ b: true }); -// error -a4(); -a3({}); -function a5([z], z) { } diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration.ts deleted file mode 100644 index c840dba2d2b..00000000000 --- a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration.ts +++ /dev/null @@ -1,19 +0,0 @@ -enum Foo { a } -function a({x, a}: { x: number, a: number }) { } -function a1({z: {x, y: {j}}}) { } -function a2({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } -function a3({z} = {z:10}) { } -function a4({z=10}) { } -function a6({b}: { b: number|string|boolean } = { b: "hello" }) { } -a2(); -a2({ z: { x: "hello" , y: { j: Foo.a } }}); -a3(); -a3({ z: Foo.a }); -a4({}); -a6({ b: 10 }); -a6({ b: true }); - -// error -a4(); -a3({}); -function a5([z], z: number) { } diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts index 6e9579926dd..027d11b8c2f 100644 --- a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts @@ -1,21 +1,106 @@ -type arrayString = Array -type someArray = Array | number[]; -type stringOrNumArray = Array; +// A parameter declaration may specify either an identifier or a binding pattern. +// The identifiers specified in parameter declarations and binding patterns +// in a parameter list must be unique within that parameter list. -function a3(...x = [1,2,3]) { } -function a4(...x: (number|string)[]) { } -function a5(...a) { } -function a6(...a: Array) { } -function a7(...a: arrayString) { } -function a8(...a: stringOrNumArray) { } -function a9(...a: someArray) { } -function a10(...b?) { } -function a11(...b = [1,2,3]) { } +// If the declaration includes a type annotation, the parameter is of that type +function a0(x: number, y: string, z: boolean) { } +function a1([a, b, [[c]]]: [number, number, string[][]]) { } +function a2(o: { x: number, a: number }) { } +function a3({j, k, l: {m, n}, q: [a, b, c]}: { j: number, k: string, l: { m: boolean, n: number }, q: (number|string)[] }) { }; +function a1({x, a}: { x: number, a: number }) { } + +a1([1, 2, [["world"]]]); +a1([1, 2, [["world"]], 3]); +a1([1, "string", [["world"]]); // Error +a1([1, 2, [["world"]], "string"]); // Error + + +// If the declaration includes an initializer expression (which is permitted only +// when the parameter list occurs in conjunction with a function body), +// the parameter type is the widened form (section 3.11) of the type of the initializer expression. + +function b1(z = 10, y = 60, u = () => true) { } +function b2(z = [undefined, null]) { }; +function b3(z = null, o = { x: 0, y: undefined }) { } +function b4({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } + +interface F1 { + b5(z = 10, [[a, b], d, {u}] = [[1, 2], "string", { u: false }]); // Error, no function body + b6(z, y, [, a, b], {p, m: { q, r}}); +} + +b2([1, 2, 3]); // z is widen to the type any[] +b3("string", { x: 200, y: "string" }); +b3("string", { x: 200, y: true }); +b3("string", { x: "string", y: true }); // Error + + +// If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3) +enum Foo { a } +function c0({z: {x, y: {j}}}) { } +function c1({z} = { z: 10 }) { } +function c2({z = 10}) { } +function c3({b}: { b: number|string} = { b: "hello" }) { } +function c4([z], z: number) { } // Duplicate identifier +function c5([a, b, [[c]]]) { } +function c6([a, b, [[c=1]]]) { } + +c0({z : { x: 1, y: { j: "world" } }}); // Implied type is { z: {x: any, y: {j: any}} } +c0({z : { x: "string", y: { j: true } }}); // Implied type is { z: {x: any, y: {j: any}} } +c0({z : 1}); // Error, implied type is { z: {x: any, y: {j: any}} } + +c1({}); // Error, implied type is {z:number}? +c1({ z: true }); // Error, implied type is {z:number}? +c1(); // Implied type is {z:number}? +c1({ z: 1 }) // Implied type is {z:number}? + +c2({}); // Implied type is {z?: number} +c2({z:1}); // Implied type is {z?: number} +c2({z:false}); // Error, implied type is {z?: number} + +c3({ b: 1 }); // Implied type is { b: number|string }. +c3({ b: true }); // Error, implied type is { b: number|string }. + +c5([1, 2, [["string"]]]); // Implied type is is [any, any, [[any]]] +c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]] +c5([1, 2, false, true]); // Error, implied type is [any, any, [[any]]] + +c6([1, 2, [["string"]]]); // Error, implied type is [any, any, [[number]]] // Use initializer + +// A parameter can be marked optional by following its name or binding pattern with a question mark (?) +// or by including an initializer. + +function d0(x?) { } +function d0(x = 10) { } +function d1([a, b, c]?) { } +function d2({x, y, z}?) { } + +interface F2 { + d3([a, b, c]?); + d4({x, y, z}?); + e0([a, b, c]); +} + +class C2 implements F2 { + constructor() { } + d3() { } + d4() { } + e0([a, b, c]) { } +} + +class C3 implements F2 { + d3([a, b, c]) { } + d4({x, y, z}) { } + e0([a, b, c]) { } +} + +class C4 implements F2 { + d3([a, b, c]?) { } + d4({x, y, c}) { } + e0([a, b, q]) { } +} + +function d5({x, y} = { x: 1, y: 2 }) { } +d5(); // Parameter is optional as its declaration included an initializer -a4(1, 2, "hello", true); -var array = [1, 2, 3]; -var array2 = [true, false, "hello"]; -a5([...array]); -a4(...array); -a4(...array2); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts deleted file mode 100644 index 1441226e061..00000000000 --- a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts +++ /dev/null @@ -1,22 +0,0 @@ -// @target: es6 -type arrayString = Array -type someArray = Array | number[]; -type stringOrNumArray = Array; - -function a3(...x = [1,2,3]) { } -function a4(...x: (number|string)[]) { } -function a5(...a) { } -function a6(...a: Array) { } -function a7(...a: arrayString) { } -function a8(...a: stringOrNumArray) { } -function a9(...a: someArray) { } -function a10(...b?) { } -function a11(...b = [1,2,3]) { } - - -a4(1, 2, "hello", true); -var array = [1, 2, 3]; -var array2 = [true, false, "hello"]; -a5([...array]); -a4(...array); -a4(...array2); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts index 59763c95902..5a775eb69c9 100644 --- a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts @@ -1,19 +1,61 @@ -"use strict" -function a({while}) { } -function a1({public}) { } -function a2({public: x}) { } -function a3({while: y}) { } -function a4([while, for, public]){ } -function a5(...while) { } -function a6(...public) { } -function a7(...a: string) { } +// If the parameter is a rest parameter, the parameter type is any[] +// A type annotation for a rest parameter must denote an array type. + +// RestParameter: +// ... Identifier TypeAnnotation(opt) + +type arrayString = Array +type someArray = Array | number[]; +type stringOrNumArray = Array; + +function a0(...x: [number, number, string]) { } // Error, rest parameter must be array type +function a1(...x: (number|string)[]) { } +function a2(...a) { } +function a3(...a: Array) { } +function a4(...a: arrayString) { } +function a5(...a: stringOrNumArray) { } +function a6(...a: someArray) { } // Error, rest parameter must be array type +function a7(...b?) { } // Error, can't be optional +function a8(...b = [1,2,3]) { } // Error, can't have initializer +function a9([a, b, [[c]]]) { } +function a10([a, b, [[c]], ...x]) { } +function a11([a, b, c, ...x]: number[]) { } + + +a1(1, 2, "hello", true); // Error, parameter type is (number|string)[] +var array = [1, 2, 3]; +var array2 = [true, false, "hello"]; +a2([...array]); +a1(...array); +a1(...array2); // Error parameter type is (number|string)[] + +a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]] +a9([1, 2, "string", false, true]); // Error, parameter type is [any, any, [[any]]] +a9([1, 2]); // Error, parameter type is [any, any, [[any]]] + +a10([1, 2, [["string"]], false, true]); // Parameter type is any[] +a10([1, 2, 3, false, true]); // Parameter type is any[] +a10([1, 2]); // Parameter type is any[] + +a11([1, 2]); // Parameter type is number[] +a11([1, 2, "string"]); // Error, parameter type is number[] + class C { - constructor(public ...a) { } + constructor(public ...a) { } // Rest parameter can't have accessibilityModifier } +// Rest parameter with generic +function foo(...a: T[]) { } +foo("hello", 1, 2); // Error +foo("hello", 1, 2); +foo("hello", "world"); + +enum E { a, b } +const enum E1 { a, b } +function foo1(...a: T[]) { } +foo1(1, 2, 3, E.a); +foo1(1, 2, 3, E1.a, E.b); +foo1(1, 2, "string", E1.a, E.b); // Error -a2({ public: 1 }); -a3({ while: 1 }); -a({ while: 1 }); diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts deleted file mode 100644 index e50a455d824..00000000000 --- a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts +++ /dev/null @@ -1,20 +0,0 @@ -//@target: es6 -"use strict" -function a({while}) { } -function a1({public}) { } -function a2({public: x}) { } -function a3({while: y}) { } -function a4([while, for, public]){ } -function a5(...while) { } -function a6(...public) { } -function a7(...a: string) { } - -class C { - constructor(public ...a) { } -} - - -a2({ public: 1 }); -a3({ while: 1 }); -a({ while: 1 }); - diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts index 96fc87c6c86..c583b750fef 100644 --- a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts @@ -1,23 +1,20 @@ -function a([x, [y, z], [[j]]]) { - return [x, y, z, j]; -} +// A parameter declaration may specify either an identifier or a binding pattern. -function a1([...x]) { - return [x]; -} +// Reserved words are not allowed to be used as an identifier in parameter declaration +"use strict" -function a2({public} = { "public": "1" }) { - return public; -} +// Error +function a({while}) { } +function a1({public}) { } +function a4([while, for, public]){ } +function a5(...while) { } +function a6(...public) { } +function a7(...a: string) { } +a({ while: 1 }); -function a3({x: { y, z}, j: {k: {a}} }) { - return [y, z, a]; -} +// No Error +function b1({public: x}) { } +function b2({while: y}) { } +b1({ public: 1 }); +b2({ while: 1 }); -function a4({x: { y, z}, j: {k: {a}} } = { x: { y: 1, z: 1 }, j: { k: { a: "hello" } } }): (number| string) [] { - return [y, z, a]; -} - -function a5({x: { y, z}, j: {k: {a}} }): (number| string) [] { - return [y, z, a]; -} diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES6.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES6.ts deleted file mode 100644 index 7c50917ebe5..00000000000 --- a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES6.ts +++ /dev/null @@ -1,24 +0,0 @@ -// @target: es6 -function a([x, [y, z], [[j]]]) { - return [x, y, z, j]; -} - -function a1([...x]) { - return [x]; -} - -function a2({public} = { "public": "1" }) { - return public; -} - -function a3({x: { y, z}, j: {k: {a}} }) { - return [y, z, a]; -} - -function a4({x: { y, z}, j: {k: {a}} } = { x: { y: 1, z: 1 }, j: { k: { a: "hello" } } }): (number| string) [] { - return [y, z, a]; -} - -function a5({x: { y, z}, j: {k: {a}} }): (number| string) [] { - return [y, z, a]; -} diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts index b59c539d672..4f0f52d3065 100644 --- a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts @@ -1,18 +1,49 @@ -interface F { } -class C implements F{ +// Parameter with generic +interface F { } +class Class implements F { + constructor() { } } -function foo(...a: T[]) { } -function foo1(...a: T[]) { } -function bar({x} = { x: new C() }) { } -function baz({x}: { x: F }) { } -function baz1({x}: { x: C }) { } -function baz2({x}: { x: C }) { } -var obj = new C(); -baz1({ x: obj }); -baz({ x: new C() }); -baz({ x: {} }); -foo("hello", 1, 2); -foo("hello", 1, 2); -foo("hello", "world"); +class SubClass extends Class { + foo: boolean; + constructor() { super(); } +} +class D implements F { + foo: boolean + constructor() { } +} + +class SubD extends D { + bar: number + constructor() { + super(); + } +} + + +function d0({x} = { x: new Class() }) { } +function d1({x}: { x: F }) { } +function d2({x}: { x: Class }) { } +function d3({y}: { y: D }) { } +function d4({y} = { y: new D() }) { } + +var obj = new Class(); +d0({ x: 1 }); +d0({ x: {} }); +d0({ x: "string" }); + +d1({ x: new Class() }); +d1({ x: {} }); +d1({ x: "string" }); + +d2({ x: new SubClass() }); +d2({ x: {} }); + +d3({ y: new SubD() }); +d3({ y: new SubClass() }); +// Error +d3({ y: new Class() }); +d3({}); +d3({ y: 1 }); +d3({ y: "world" }); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclarationES6.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclarationES6.ts deleted file mode 100644 index 0d359421851..00000000000 --- a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclarationES6.ts +++ /dev/null @@ -1,20 +0,0 @@ -//@target: es6 -enum Foo { a } -function a({x, a}: { x: number, a: number }) { } -function a1({z: {x, y: {j}}}) { } -function a2({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } -function a3({z} = {z:10}) { } -function a4({z=10}) { } -function a6({b}: { b: number|string|boolean } = { b: "hello" }) { } -a2(); -a2({ z: { x: "hello" , y: { j: Foo.a } }}); -a3(); -a3({ z: Foo.a }); -a4({}); -a6({ b: 10 }); -a6({ b: true }); - -// error -a4(); -a3({}); -function a5([z], z: number) { } From 614469462ad6931b0d540aad6e8d7bd1d74b9b31 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 16 Apr 2015 13:35:56 -0700 Subject: [PATCH 030/194] Update tests files with more conformance from section 6.4 --- ...tructuringParameterDeclaration1.errors.txt | 129 +++--- .../destructuringParameterDeclaration1.js | 98 +++-- .../destructuringParameterDeclaration1ES6.js | 169 ++++++++ ...estructuringParameterDeclaration1ES6.types | 378 ++++++++++++++++++ ...tructuringParameterDeclaration2.errors.txt | 2 +- .../destructuringParameterDeclaration2.js | 4 +- .../destructuringParameterDeclaration2ES6.js | 81 ++++ ...estructuringParameterDeclaration2ES6.types | 170 ++++++++ .../destructuringParameterDeclaration1.ts | 43 +- .../destructuringParameterDeclaration1ES6.ts | 99 +++++ .../destructuringParameterDeclaration2.ts | 2 +- .../destructuringParameterDeclaration2ES6.ts | 47 +++ 12 files changed, 1129 insertions(+), 93 deletions(-) create mode 100644 tests/baselines/reference/destructuringParameterDeclaration1ES6.js create mode 100644 tests/baselines/reference/destructuringParameterDeclaration1ES6.types create mode 100644 tests/baselines/reference/destructuringParameterDeclaration2ES6.js create mode 100644 tests/baselines/reference/destructuringParameterDeclaration2ES6.types create mode 100644 tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts diff --git a/tests/baselines/reference/destructuringParameterDeclaration1.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration1.errors.txt index cc0e8167d1c..078895d07b0 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration1.errors.txt +++ b/tests/baselines/reference/destructuringParameterDeclaration1.errors.txt @@ -1,53 +1,65 @@ -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(7,10): error TS2393: Duplicate function implementation. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(10,10): error TS2393: Duplicate function implementation. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(14,4): error TS2345: Argument of type '(string | number | string[][])[]' is not assignable to parameter of type '{ x: number; a: number; }'. - Property 'x' is missing in type '(string | number | string[][])[]'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(14,29): error TS1005: ',' expected. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(15,4): error TS2345: Argument of type '(string | number | string[][])[]' is not assignable to parameter of type '{ x: number; a: number; }'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(28,8): error TS2371: A parameter initializer is only allowed in a function or constructor implementation. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(28,16): error TS2371: A parameter initializer is only allowed in a function or constructor implementation. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(35,14): error TS2345: Argument of type '{ x: string; y: boolean; }' is not assignable to parameter of type '{ x: number; y: any; }'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(13,4): error TS2345: Argument of type '[number, string, string[][]]' is not assignable to parameter of type '[number, number, string[][]]'. + Types of property '1' are incompatible. + Type 'string' is not assignable to type 'number'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(13,29): error TS1005: ',' expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(14,4): error TS2345: Argument of type '[number, number, string[][], string]' is not assignable to parameter of type '[number, number, string[][]]'. + Types of property 'pop' are incompatible. + Type '() => string | number | string[][]' is not assignable to type '() => number | string[][]'. + Type 'string | number | string[][]' is not assignable to type 'number | string[][]'. + Type 'string' is not assignable to type 'number | string[][]'. + Type 'string' is not assignable to type 'string[][]'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(26,8): error TS2371: A parameter initializer is only allowed in a function or constructor implementation. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(26,16): error TS2371: A parameter initializer is only allowed in a function or constructor implementation. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(36,14): error TS2345: Argument of type '{ x: string; y: boolean; }' is not assignable to parameter of type '{ x: number; y: any; }'. Types of property 'x' are incompatible. Type 'string' is not assignable to type 'number'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(44,14): error TS2300: Duplicate identifier 'z'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(44,18): error TS2300: Duplicate identifier 'z'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(50,4): error TS2345: Argument of type '{ z: number; }' is not assignable to parameter of type '{ z: { x: any; y: { j: any; }; }; }'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(37,4): error TS2345: Argument of type '[string, number, number]' is not assignable to parameter of type '[undefined, null, undefined]'. + Types of property '0' are incompatible. + Type 'string' is not assignable to type 'undefined'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(38,4): error TS2345: Argument of type '[[string], number, [[boolean, boolean]]]' is not assignable to parameter of type '[[undefined], undefined, [[undefined, undefined]]]'. + Types of property '0' are incompatible. + Type '[string]' is not assignable to type '[undefined]'. + Types of property '0' are incompatible. + Type 'string' is not assignable to type 'undefined'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(47,14): error TS2300: Duplicate identifier 'z'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(47,18): error TS2300: Duplicate identifier 'z'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(53,4): error TS2345: Argument of type '{ z: number; }' is not assignable to parameter of type '{ z: { x: any; y: { j: any; }; }; }'. Types of property 'z' are incompatible. Type 'number' is not assignable to type '{ x: any; y: { j: any; }; }'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(52,4): error TS2345: Argument of type '{}' is not assignable to parameter of type '{ z: number; }'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(55,4): error TS2345: Argument of type '{}' is not assignable to parameter of type '{ z: number; }'. Property 'z' is missing in type '{}'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(53,4): error TS2345: Argument of type '{ z: boolean; }' is not assignable to parameter of type '{ z: number; }'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(56,4): error TS2345: Argument of type '{ z: boolean; }' is not assignable to parameter of type '{ z: number; }'. Types of property 'z' are incompatible. Type 'boolean' is not assignable to type 'number'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(59,4): error TS2345: Argument of type '{ z: boolean; }' is not assignable to parameter of type '{ z?: number; }'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(62,4): error TS2345: Argument of type '{ z: boolean; }' is not assignable to parameter of type '{ z?: number; }'. Types of property 'z' are incompatible. Type 'boolean' is not assignable to type 'number'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(62,4): error TS2345: Argument of type '{ b: boolean; }' is not assignable to parameter of type '{ b: string | number; }'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(65,4): error TS2345: Argument of type '{ b: boolean; }' is not assignable to parameter of type '{ b: string | number; }'. Types of property 'b' are incompatible. Type 'boolean' is not assignable to type 'string | number'. Type 'boolean' is not assignable to type 'number'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(66,4): error TS2345: Argument of type '[number, number, boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(69,4): error TS2345: Argument of type '[number, number, boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'. Types of property '2' are incompatible. Type 'boolean' is not assignable to type '[[any]]'. Property '0' is missing in type 'Boolean'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(68,4): error TS2345: Argument of type '[number, number, [[string]]]' is not assignable to parameter of type '[any, any, [[number]]]'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(71,4): error TS2345: Argument of type '[number, number, [[string]]]' is not assignable to parameter of type '[any, any, [[number]]]'. Types of property '2' are incompatible. Type '[[string]]' is not assignable to type '[[number]]'. Types of property '0' are incompatible. Type '[string]' is not assignable to type '[number]'. Types of property '0' are incompatible. Type 'string' is not assignable to type 'number'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(73,10): error TS2393: Duplicate function implementation. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(74,10): error TS2393: Duplicate function implementation. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(75,13): error TS2463: A binding pattern parameter cannot be optional in an implementation signature. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(76,13): error TS2463: A binding pattern parameter cannot be optional in an implementation signature. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(97,7): error TS2420: Class 'C4' incorrectly implements interface 'F2'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(76,10): error TS2393: Duplicate function implementation. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(77,10): error TS2393: Duplicate function implementation. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(78,13): error TS2463: A binding pattern parameter cannot be optional in an implementation signature. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(79,13): error TS2463: A binding pattern parameter cannot be optional in an implementation signature. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(100,7): error TS2420: Class 'C4' incorrectly implements interface 'F2'. Types of property 'd4' are incompatible. Type '({x, y, c}: { x: any; y: any; c: any; }) => void' is not assignable to type '({x, y, z}?: { x: any; y: any; z: any; }) => any'. Types of parameters '__0' and '__0' are incompatible. Type '{ x: any; y: any; c: any; }' is not assignable to type '{ x: any; y: any; z: any; }'. Property 'z' is missing in type '{ x: any; y: any; c: any; }'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(98,8): error TS2463: A binding pattern parameter cannot be optional in an implementation signature. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(101,8): error TS2463: A binding pattern parameter cannot be optional in an implementation signature. ==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts (23 errors) ==== @@ -56,55 +68,70 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts( // in a parameter list must be unique within that parameter list. // If the declaration includes a type annotation, the parameter is of that type - function a0(x: number, y: string, z: boolean) { } function a1([a, b, [[c]]]: [number, number, string[][]]) { } - ~~ -!!! error TS2393: Duplicate function implementation. function a2(o: { x: number, a: number }) { } function a3({j, k, l: {m, n}, q: [a, b, c]}: { j: number, k: string, l: { m: boolean, n: number }, q: (number|string)[] }) { }; - function a1({x, a}: { x: number, a: number }) { } - ~~ -!!! error TS2393: Duplicate function implementation. + function a4({x, a}: { x: number, a: number }) { } a1([1, 2, [["world"]]]); a1([1, 2, [["world"]], 3]); a1([1, "string", [["world"]]); // Error ~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(string | number | string[][])[]' is not assignable to parameter of type '{ x: number; a: number; }'. -!!! error TS2345: Property 'x' is missing in type '(string | number | string[][])[]'. +!!! error TS2345: Argument of type '[number, string, string[][]]' is not assignable to parameter of type '[number, number, string[][]]'. +!!! error TS2345: Types of property '1' are incompatible. +!!! error TS2345: Type 'string' is not assignable to type 'number'. ~ !!! error TS1005: ',' expected. a1([1, 2, [["world"]], "string"]); // Error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(string | number | string[][])[]' is not assignable to parameter of type '{ x: number; a: number; }'. +!!! error TS2345: Argument of type '[number, number, string[][], string]' is not assignable to parameter of type '[number, number, string[][]]'. +!!! error TS2345: Types of property 'pop' are incompatible. +!!! error TS2345: Type '() => string | number | string[][]' is not assignable to type '() => number | string[][]'. +!!! error TS2345: Type 'string | number | string[][]' is not assignable to type 'number | string[][]'. +!!! error TS2345: Type 'string' is not assignable to type 'number | string[][]'. +!!! error TS2345: Type 'string' is not assignable to type 'string[][]'. // If the declaration includes an initializer expression (which is permitted only // when the parameter list occurs in conjunction with a function body), // the parameter type is the widened form (section 3.11) of the type of the initializer expression. - function b1(z = 10, y = 60, u = () => true) { } - function b2(z = [undefined, null]) { }; - function b3(z = null, o = { x: 0, y: undefined }) { } - function b4({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } + function b1(z = [undefined, null]) { }; + function b2(z = null, o = { x: 0, y: undefined }) { } + function b3({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } interface F1 { - b5(z = 10, [[a, b], d, {u}] = [[1, 2], "string", { u: false }]); // Error, no function body + b4(z = 10, [[a, b], d, {u}] = [[1, 2], "string", { u: false }]); // Error, no function body ~~~~~~ !!! error TS2371: A parameter initializer is only allowed in a function or constructor implementation. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2371: A parameter initializer is only allowed in a function or constructor implementation. - b6(z, y, [, a, b], {p, m: { q, r}}); + b5(z, y, [, a, b], {p, m: { q, r}}); } - b2([1, 2, 3]); // z is widen to the type any[] - b3("string", { x: 200, y: "string" }); - b3("string", { x: 200, y: true }); - b3("string", { x: "string", y: true }); // Error + function b6([a, z, y] = [undefined, null, undefined]) { } + function b7([[a], b, [[c, d]]] = [[undefined], undefined, [[undefined, undefined]]]) { } + + b1([1, 2, 3]); // z is widen to the type any[] + b2("string", { x: 200, y: "string" }); + b2("string", { x: 200, y: true }); + b2("string", { x: "string", y: true }); // Error ~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '{ x: string; y: boolean; }' is not assignable to parameter of type '{ x: number; y: any; }'. !!! error TS2345: Types of property 'x' are incompatible. !!! error TS2345: Type 'string' is not assignable to type 'number'. + b6(["string", 1, 2]); // Shouldn't be an error + ~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '[string, number, number]' is not assignable to parameter of type '[undefined, null, undefined]'. +!!! error TS2345: Types of property '0' are incompatible. +!!! error TS2345: Type 'string' is not assignable to type 'undefined'. + b7([["string"], 1, [[true, false]]]); // Shouldn't be an error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '[[string], number, [[boolean, boolean]]]' is not assignable to parameter of type '[[undefined], undefined, [[undefined, undefined]]]'. +!!! error TS2345: Types of property '0' are incompatible. +!!! error TS2345: Type '[string]' is not assignable to type '[undefined]'. +!!! error TS2345: Types of property '0' are incompatible. +!!! error TS2345: Type 'string' is not assignable to type 'undefined'. // If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3) @@ -185,10 +212,10 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts( function d0(x = 10) { } ~~ !!! error TS2393: Duplicate function implementation. - function d1([a, b, c]?) { } + function d1([a, b, c]?) { } // Error, binding pattern can't be optional in implementation signature ~~~~~~~~~~ !!! error TS2463: A binding pattern parameter cannot be optional in an implementation signature. - function d2({x, y, z}?) { } + function d2({x, y, z}?) { } // Error, binding pattern can't be optional in implementation signature ~~~~~~~~~~ !!! error TS2463: A binding pattern parameter cannot be optional in an implementation signature. @@ -229,5 +256,17 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts( function d5({x, y} = { x: 1, y: 2 }) { } d5(); // Parameter is optional as its declaration included an initializer + // Destructuring parameter declarations do not permit type annotations on the individual binding patterns, + // as such annotations would conflict with the already established meaning of colons in object literals. + // Type annotations must instead be written on the top- level parameter declaration + + function e1({x: number}) { } // x has type any NOT number + function e2({x}: { x: number }) { } // x is type number + function e3({x}: { x?: number }) { } // x is an optional with type number + function e4({x: [number,string,any] }) { } // x has type [any, any, any] + function e5({x: [a, b, c]}: { x: [number, number, number] }) { } // x has type [any, any, any] + + function e6({x: [number, number, number]}) { } // should be an error, duplicate identifier; + \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterDeclaration1.js b/tests/baselines/reference/destructuringParameterDeclaration1.js index d8963511838..0d8590ae50a 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration1.js +++ b/tests/baselines/reference/destructuringParameterDeclaration1.js @@ -4,11 +4,10 @@ // in a parameter list must be unique within that parameter list. // If the declaration includes a type annotation, the parameter is of that type -function a0(x: number, y: string, z: boolean) { } function a1([a, b, [[c]]]: [number, number, string[][]]) { } function a2(o: { x: number, a: number }) { } function a3({j, k, l: {m, n}, q: [a, b, c]}: { j: number, k: string, l: { m: boolean, n: number }, q: (number|string)[] }) { }; -function a1({x, a}: { x: number, a: number }) { } +function a4({x, a}: { x: number, a: number }) { } a1([1, 2, [["world"]]]); a1([1, 2, [["world"]], 3]); @@ -20,20 +19,24 @@ a1([1, 2, [["world"]], "string"]); // Error // when the parameter list occurs in conjunction with a function body), // the parameter type is the widened form (section 3.11) of the type of the initializer expression. -function b1(z = 10, y = 60, u = () => true) { } -function b2(z = [undefined, null]) { }; -function b3(z = null, o = { x: 0, y: undefined }) { } -function b4({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } +function b1(z = [undefined, null]) { }; +function b2(z = null, o = { x: 0, y: undefined }) { } +function b3({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } interface F1 { - b5(z = 10, [[a, b], d, {u}] = [[1, 2], "string", { u: false }]); // Error, no function body - b6(z, y, [, a, b], {p, m: { q, r}}); + b4(z = 10, [[a, b], d, {u}] = [[1, 2], "string", { u: false }]); // Error, no function body + b5(z, y, [, a, b], {p, m: { q, r}}); } -b2([1, 2, 3]); // z is widen to the type any[] -b3("string", { x: 200, y: "string" }); -b3("string", { x: 200, y: true }); -b3("string", { x: "string", y: true }); // Error +function b6([a, z, y] = [undefined, null, undefined]) { } +function b7([[a], b, [[c, d]]] = [[undefined], undefined, [[undefined, undefined]]]) { } + +b1([1, 2, 3]); // z is widen to the type any[] +b2("string", { x: 200, y: "string" }); +b2("string", { x: 200, y: true }); +b2("string", { x: "string", y: true }); // Error +b6(["string", 1, 2]); // Shouldn't be an error +b7([["string"], 1, [[true, false]]]); // Shouldn't be an error // If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3) @@ -73,8 +76,8 @@ c6([1, 2, [["string"]]]); // Error, implied type is [any, any, [[number]]] // function d0(x?) { } function d0(x = 10) { } -function d1([a, b, c]?) { } -function d2({x, y, z}?) { } +function d1([a, b, c]?) { } // Error, binding pattern can't be optional in implementation signature +function d2({x, y, z}?) { } // Error, binding pattern can't be optional in implementation signature interface F2 { d3([a, b, c]?); @@ -104,6 +107,18 @@ class C4 implements F2 { function d5({x, y} = { x: 1, y: 2 }) { } d5(); // Parameter is optional as its declaration included an initializer +// Destructuring parameter declarations do not permit type annotations on the individual binding patterns, +// as such annotations would conflict with the already established meaning of colons in object literals. +// Type annotations must instead be written on the top- level parameter declaration + +function e1({x: number}) { } // x has type any NOT number +function e2({x}: { x: number }) { } // x is type number +function e3({x}: { x?: number }) { } // x is an optional with type number +function e4({x: [number,string,any] }) { } // x has type [any, any, any] +function e5({x: [a, b, c]}: { x: [number, number, number] }) { } // x has type [any, any, any] + +function e6({x: [number, number, number]}) { } // should be an error, duplicate identifier; + @@ -112,7 +127,6 @@ d5(); // Parameter is optional as its declaration included an initializer // The identifiers specified in parameter declarations and binding patterns // in a parameter list must be unique within that parameter list. // If the declaration includes a type annotation, the parameter is of that type -function a0(x, y, z) { } function a1(_a) { var a = _a[0], b = _a[1], c = _a[2][0][0]; } @@ -121,7 +135,7 @@ function a3(_a) { var j = _a.j, k = _a.k, _b = _a.l, m = _b.m, n = _b.n, _c = _a.q, a = _c[0], b = _c[1], c = _c[2]; } ; -function a1(_a) { +function a4(_a) { var x = _a.x, a = _a.a; } a1([1, 2, [["world"]]]); @@ -131,26 +145,29 @@ a1([1, 2, [["world"]], "string"]); // Error // If the declaration includes an initializer expression (which is permitted only // when the parameter list occurs in conjunction with a function body), // the parameter type is the widened form (section 3.11) of the type of the initializer expression. -function b1(z, y, u) { - if (z === void 0) { z = 10; } - if (y === void 0) { y = 60; } - if (u === void 0) { u = function () { return true; }; } -} -function b2(z) { +function b1(z) { if (z === void 0) { z = [undefined, null]; } } ; -function b3(z, o) { +function b2(z, o) { if (z === void 0) { z = null; } if (o === void 0) { o = { x: 0, y: undefined }; } } -function b4(_a) { +function b3(_a) { var _b = (_a === void 0 ? { z: { x: "hi", y: { j: 1 } } } : _a).z, x = _b.x, j = _b.y.j; } -b2([1, 2, 3]); // z is widen to the type any[] -b3("string", { x: 200, y: "string" }); -b3("string", { x: 200, y: true }); -b3("string", { x: "string", y: true }); // Error +function b6(_a) { + var _b = _a === void 0 ? [undefined, null, undefined] : _a, a = _b[0], z = _b[1], y = _b[2]; +} +function b7(_a) { + var _b = _a === void 0 ? [[undefined], undefined, [[undefined, undefined]]] : _a, a = _b[0][0], b = _b[1], _c = _b[2][0], c = _c[0], d = _c[1]; +} +b1([1, 2, 3]); // z is widen to the type any[] +b2("string", { x: 200, y: "string" }); +b2("string", { x: 200, y: true }); +b2("string", { x: "string", y: true }); // Error +b6(["string", 1, 2]); // Shouldn't be an error +b7([["string"], 1, [[true, false]]]); // Shouldn't be an error // If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3) var Foo; (function (Foo) { @@ -201,10 +218,10 @@ function d0(x) { } function d1(_a) { var a = _a[0], b = _a[1], c = _a[2]; -} +} // Error, binding pattern can't be optional in implementation signature function d2(_a) { var x = _a.x, y = _a.y, z = _a.z; -} +} // Error, binding pattern can't be optional in implementation signature var C2 = (function () { function C2() { } @@ -247,3 +264,24 @@ function d5(_a) { var _b = _a === void 0 ? { x: 1, y: 2 } : _a, x = _b.x, y = _b.y; } d5(); // Parameter is optional as its declaration included an initializer +// Destructuring parameter declarations do not permit type annotations on the individual binding patterns, +// as such annotations would conflict with the already established meaning of colons in object literals. +// Type annotations must instead be written on the top- level parameter declaration +function e1(_a) { + var number = _a.x; +} // x has type any NOT number +function e2(_a) { + var x = _a.x; +} // x is type number +function e3(_a) { + var x = _a.x; +} // x is an optional with type number +function e4(_a) { + var _b = _a.x, number = _b[0], string = _b[1], any = _b[2]; +} // x has type [any, any, any] +function e5(_a) { + var _b = _a.x, a = _b[0], b = _b[1], c = _b[2]; +} // x has type [any, any, any] +function e6(_a) { + var _b = _a.x, number = _b[0], number = _b[1], number = _b[2]; +} // should be an error, duplicate identifier; diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES6.js b/tests/baselines/reference/destructuringParameterDeclaration1ES6.js new file mode 100644 index 00000000000..6310a8f638e --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration1ES6.js @@ -0,0 +1,169 @@ +//// [destructuringParameterDeclaration1ES6.ts] +// Conformance for emitting ES6 + +// A parameter declaration may specify either an identifier or a binding pattern. +// The identifiers specified in parameter declarations and binding patterns +// in a parameter list must be unique within that parameter list. + +// If the declaration includes a type annotation, the parameter is of that type +function a1([a, b, [[c]]]: [number, number, string[][]]) { } +function a2(o: { x: number, a: number }) { } +function a3({j, k, l: {m, n}, q: [a, b, c]}: { j: number, k: string, l: { m: boolean, n: number }, q: (number|string)[] }) { }; +function a4({x, a}: { x: number, a: number }) { } + +a1([1, 2, [["world"]]]); +a1([1, 2, [["world"]], 3]); + + +// If the declaration includes an initializer expression (which is permitted only +// when the parameter list occurs in conjunction with a function body), +// the parameter type is the widened form (section 3.11) of the type of the initializer expression. + +function b1(z = [undefined, null]) { }; +function b2(z = null, o = { x: 0, y: undefined }) { } +function b3({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } + +interface F1 { + b5(z, y, [, a, b], {p, m: { q, r}}); +} + +function b6([a, z, y] = [undefined, null, undefined]) { } +function b7([[a], b, [[c, d]]] = [[undefined], undefined, [[undefined, undefined]]]) { } + +b1([1, 2, 3]); // z is widen to the type any[] +b2("string", { x: 200, y: "string" }); +b2("string", { x: 200, y: true }); + + +// If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3) +enum Foo { a } +function c0({z: {x, y: {j}}}) { } +function c1({z} = { z: 10 }) { } +function c2({z = 10}) { } +function c3({b}: { b: number|string} = { b: "hello" }) { } +function c5([a, b, [[c]]]) { } +function c6([a, b, [[c=1]]]) { } + +c0({z : { x: 1, y: { j: "world" } }}); // Implied type is { z: {x: any, y: {j: any}} } +c0({z : { x: "string", y: { j: true } }}); // Implied type is { z: {x: any, y: {j: any}} } + +c1(); // Implied type is {z:number}? +c1({ z: 1 }) // Implied type is {z:number}? + +c2({}); // Implied type is {z?: number} +c2({z:1}); // Implied type is {z?: number} + +c3({ b: 1 }); // Implied type is { b: number|string }. + +c5([1, 2, [["string"]]]); // Implied type is is [any, any, [[any]]] +c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]] + + +// A parameter can be marked optional by following its name or binding pattern with a question mark (?) +// or by including an initializer. + +interface F2 { + d3([a, b, c]?); + d4({x, y, z}?); + e0([a, b, c]); +} + +class C2 implements F2 { + constructor() { } + d3() { } + d4() { } + e0([a, b, c]) { } +} + +class C3 implements F2 { + d3([a, b, c]) { } + d4({x, y, z}) { } + e0([a, b, c]) { } +} + +function d5({x, y} = { x: 1, y: 2 }) { } +d5(); // Parameter is optional as its declaration included an initializer + +// Destructuring parameter declarations do not permit type annotations on the individual binding patterns, +// as such annotations would conflict with the already established meaning of colons in object literals. +// Type annotations must instead be written on the top- level parameter declaration + +function e1({x: number}) { } // x has type any NOT number +function e2({x}: { x: number }) { } // x is type number +function e3({x}: { x?: number }) { } // x is an optional with type number +function e4({x: [number,string,any] }) { } // x has type [any, any, any] +function e5({x: [a, b, c]}: { x: [number, number, number] }) { } // x has type [any, any, any] + +function e6({x: [number, number, number]}) { } // should be an error, duplicate identifier; + + + + +//// [destructuringParameterDeclaration1ES6.js] +// Conformance for emitting ES6 +// A parameter declaration may specify either an identifier or a binding pattern. +// The identifiers specified in parameter declarations and binding patterns +// in a parameter list must be unique within that parameter list. +// If the declaration includes a type annotation, the parameter is of that type +function a1([a, b, [[c]]]) { } +function a2(o) { } +function a3({ j, k, l: { m, n }, q: [a, b, c] }) { } +; +function a4({ x, a }) { } +a1([1, 2, [["world"]]]); +a1([1, 2, [["world"]], 3]); +// If the declaration includes an initializer expression (which is permitted only +// when the parameter list occurs in conjunction with a function body), +// the parameter type is the widened form (section 3.11) of the type of the initializer expression. +function b1(z = [undefined, null]) { } +; +function b2(z = null, o = { x: 0, y: undefined }) { } +function b3({ z: { x, y: { j } } } = { z: { x: "hi", y: { j: 1 } } }) { } +function b6([a, z, y] = [undefined, null, undefined]) { } +function b7([[a], b, [[c, d]]] = [[undefined], undefined, [[undefined, undefined]]]) { } +b1([1, 2, 3]); // z is widen to the type any[] +b2("string", { x: 200, y: "string" }); +b2("string", { x: 200, y: true }); +// If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3) +var Foo; +(function (Foo) { + Foo[Foo["a"] = 0] = "a"; +})(Foo || (Foo = {})); +function c0({ z: { x, y: { j } } }) { } +function c1({ z } = { z: 10 }) { } +function c2({ z = 10 }) { } +function c3({ b } = { b: "hello" }) { } +function c5([a, b, [[c]]]) { } +function c6([a, b, [[c = 1]]]) { } +c0({ z: { x: 1, y: { j: "world" } } }); // Implied type is { z: {x: any, y: {j: any}} } +c0({ z: { x: "string", y: { j: true } } }); // Implied type is { z: {x: any, y: {j: any}} } +c1(); // Implied type is {z:number}? +c1({ z: 1 }); // Implied type is {z:number}? +c2({}); // Implied type is {z?: number} +c2({ z: 1 }); // Implied type is {z?: number} +c3({ b: 1 }); // Implied type is { b: number|string }. +c5([1, 2, [["string"]]]); // Implied type is is [any, any, [[any]]] +c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]] +class C2 { + constructor() { + } + d3() { } + d4() { } + e0([a, b, c]) { } +} +class C3 { + d3([a, b, c]) { } + d4({ x, y, z }) { } + e0([a, b, c]) { } +} +function d5({ x, y } = { x: 1, y: 2 }) { } +d5(); // Parameter is optional as its declaration included an initializer +// Destructuring parameter declarations do not permit type annotations on the individual binding patterns, +// as such annotations would conflict with the already established meaning of colons in object literals. +// Type annotations must instead be written on the top- level parameter declaration +function e1({ x: number }) { } // x has type any NOT number +function e2({ x }) { } // x is type number +function e3({ x }) { } // x is an optional with type number +function e4({ x: [number, string, any] }) { } // x has type [any, any, any] +function e5({ x: [a, b, c] }) { } // x has type [any, any, any] +function e6({ x: [number, number, number] }) { } // should be an error, duplicate identifier; diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES6.types b/tests/baselines/reference/destructuringParameterDeclaration1ES6.types new file mode 100644 index 00000000000..ed77f2dc92b --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration1ES6.types @@ -0,0 +1,378 @@ +=== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts === +// Conformance for emitting ES6 + +// A parameter declaration may specify either an identifier or a binding pattern. +// The identifiers specified in parameter declarations and binding patterns +// in a parameter list must be unique within that parameter list. + +// If the declaration includes a type annotation, the parameter is of that type +function a1([a, b, [[c]]]: [number, number, string[][]]) { } +>a1 : ([a, b, [[c]]]: [number, number, string[][]]) => void +>a : number +>b : number +>c : string + +function a2(o: { x: number, a: number }) { } +>a2 : (o: { x: number; a: number; }) => void +>o : { x: number; a: number; } +>x : number +>a : number + +function a3({j, k, l: {m, n}, q: [a, b, c]}: { j: number, k: string, l: { m: boolean, n: number }, q: (number|string)[] }) { }; +>a3 : ({j, k, l: {m, n}, q: [a, b, c]}: { j: number; k: string; l: { m: boolean; n: number; }; q: (string | number)[]; }) => void +>j : number +>k : string +>l : unknown +>m : boolean +>n : number +>q : unknown +>a : string | number +>b : string | number +>c : string | number +>j : number +>k : string +>l : { m: boolean; n: number; } +>m : boolean +>n : number +>q : (string | number)[] + +function a4({x, a}: { x: number, a: number }) { } +>a4 : ({x, a}: { x: number; a: number; }) => void +>x : number +>a : number +>x : number +>a : number + +a1([1, 2, [["world"]]]); +>a1([1, 2, [["world"]]]) : void +>a1 : ([a, b, [[c]]]: [number, number, string[][]]) => void +>[1, 2, [["world"]]] : [number, number, string[][]] +>[["world"]] : string[][] +>["world"] : string[] + +a1([1, 2, [["world"]], 3]); +>a1([1, 2, [["world"]], 3]) : void +>a1 : ([a, b, [[c]]]: [number, number, string[][]]) => void +>[1, 2, [["world"]], 3] : [number, number, string[][], number] +>[["world"]] : string[][] +>["world"] : string[] + + +// If the declaration includes an initializer expression (which is permitted only +// when the parameter list occurs in conjunction with a function body), +// the parameter type is the widened form (section 3.11) of the type of the initializer expression. + +function b1(z = [undefined, null]) { }; +>b1 : (z?: any[]) => void +>z : any[] +>[undefined, null] : null[] +>undefined : undefined + +function b2(z = null, o = { x: 0, y: undefined }) { } +>b2 : (z?: any, o?: { x: number; y: any; }) => void +>z : any +>o : { x: number; y: any; } +>{ x: 0, y: undefined } : { x: number; y: undefined; } +>x : number +>y : undefined +>undefined : undefined + +function b3({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } +>b3 : ({z: {x, y: {j}}}?: { z: { x: string; y: { j: number; }; }; }) => void +>z : unknown +>x : string +>y : unknown +>j : number +>{ z: { x: "hi", y: { j: 1 } } } : { z: { x: string; y: { j: number; }; }; } +>z : { x: string; y: { j: number; }; } +>{ x: "hi", y: { j: 1 } } : { x: string; y: { j: number; }; } +>x : string +>y : { j: number; } +>{ j: 1 } : { j: number; } +>j : number + +interface F1 { +>F1 : F1 + + b5(z, y, [, a, b], {p, m: { q, r}}); +>b5 : (z: any, y: any, [, a, b]: [any, any, any], {p, m: { q, r}}: { p: any; m: { q: any; r: any; }; }) => any +>z : any +>y : any +>a : any +>b : any +>p : any +>m : unknown +>q : any +>r : any +} + +function b6([a, z, y] = [undefined, null, undefined]) { } +>b6 : ([a, z, y]?: [undefined, null, undefined]) => void +>a : any +>z : any +>y : any +>[undefined, null, undefined] : [undefined, null, undefined] +>undefined : undefined +>undefined : undefined + +function b7([[a], b, [[c, d]]] = [[undefined], undefined, [[undefined, undefined]]]) { } +>b7 : ([[a], b, [[c, d]]]?: [[undefined], undefined, [[undefined, undefined]]]) => void +>a : any +>b : any +>c : any +>d : any +>[[undefined], undefined, [[undefined, undefined]]] : [[undefined], undefined, [[undefined, undefined]]] +>[undefined] : [undefined] +>undefined : undefined +>undefined : undefined +>[[undefined, undefined]] : [[undefined, undefined]] +>[undefined, undefined] : [undefined, undefined] +>undefined : undefined +>undefined : undefined + +b1([1, 2, 3]); // z is widen to the type any[] +>b1([1, 2, 3]) : void +>b1 : (z?: any[]) => void +>[1, 2, 3] : number[] + +b2("string", { x: 200, y: "string" }); +>b2("string", { x: 200, y: "string" }) : void +>b2 : (z?: any, o?: { x: number; y: any; }) => void +>{ x: 200, y: "string" } : { x: number; y: string; } +>x : number +>y : string + +b2("string", { x: 200, y: true }); +>b2("string", { x: 200, y: true }) : void +>b2 : (z?: any, o?: { x: number; y: any; }) => void +>{ x: 200, y: true } : { x: number; y: boolean; } +>x : number +>y : boolean + + +// If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3) +enum Foo { a } +>Foo : Foo +>a : Foo + +function c0({z: {x, y: {j}}}) { } +>c0 : ({z: {x, y: {j}}}: { z: { x: any; y: { j: any; }; }; }) => void +>z : unknown +>x : any +>y : unknown +>j : any + +function c1({z} = { z: 10 }) { } +>c1 : ({z}?: { z: number; }) => void +>z : number +>{ z: 10 } : { z: number; } +>z : number + +function c2({z = 10}) { } +>c2 : ({z = 10}: { z?: number; }) => void +>z : number + +function c3({b}: { b: number|string} = { b: "hello" }) { } +>c3 : ({b}?: { b: string | number; }) => void +>b : string | number +>b : string | number +>{ b: "hello" } : { b: string; } +>b : string + +function c5([a, b, [[c]]]) { } +>c5 : ([a, b, [[c]]]: [any, any, [[any]]]) => void +>a : any +>b : any +>c : any + +function c6([a, b, [[c=1]]]) { } +>c6 : ([a, b, [[c=1]]]: [any, any, [[number]]]) => void +>a : any +>b : any +>c : number + +c0({z : { x: 1, y: { j: "world" } }}); // Implied type is { z: {x: any, y: {j: any}} } +>c0({z : { x: 1, y: { j: "world" } }}) : void +>c0 : ({z: {x, y: {j}}}: { z: { x: any; y: { j: any; }; }; }) => void +>{z : { x: 1, y: { j: "world" } }} : { z: { x: number; y: { j: string; }; }; } +>z : { x: number; y: { j: string; }; } +>{ x: 1, y: { j: "world" } } : { x: number; y: { j: string; }; } +>x : number +>y : { j: string; } +>{ j: "world" } : { j: string; } +>j : string + +c0({z : { x: "string", y: { j: true } }}); // Implied type is { z: {x: any, y: {j: any}} } +>c0({z : { x: "string", y: { j: true } }}) : void +>c0 : ({z: {x, y: {j}}}: { z: { x: any; y: { j: any; }; }; }) => void +>{z : { x: "string", y: { j: true } }} : { z: { x: string; y: { j: boolean; }; }; } +>z : { x: string; y: { j: boolean; }; } +>{ x: "string", y: { j: true } } : { x: string; y: { j: boolean; }; } +>x : string +>y : { j: boolean; } +>{ j: true } : { j: boolean; } +>j : boolean + +c1(); // Implied type is {z:number}? +>c1() : void +>c1 : ({z}?: { z: number; }) => void + +c1({ z: 1 }) // Implied type is {z:number}? +>c1({ z: 1 }) : void +>c1 : ({z}?: { z: number; }) => void +>{ z: 1 } : { z: number; } +>z : number + +c2({}); // Implied type is {z?: number} +>c2({}) : void +>c2 : ({z = 10}: { z?: number; }) => void +>{} : {} + +c2({z:1}); // Implied type is {z?: number} +>c2({z:1}) : void +>c2 : ({z = 10}: { z?: number; }) => void +>{z:1} : { z: number; } +>z : number + +c3({ b: 1 }); // Implied type is { b: number|string }. +>c3({ b: 1 }) : void +>c3 : ({b}?: { b: string | number; }) => void +>{ b: 1 } : { b: number; } +>b : number + +c5([1, 2, [["string"]]]); // Implied type is is [any, any, [[any]]] +>c5([1, 2, [["string"]]]) : void +>c5 : ([a, b, [[c]]]: [any, any, [[any]]]) => void +>[1, 2, [["string"]]] : [number, number, [[string]]] +>[["string"]] : [[string]] +>["string"] : [string] + +c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]] +>c5([1, 2, [["string"]], false, true]) : void +>c5 : ([a, b, [[c]]]: [any, any, [[any]]]) => void +>[1, 2, [["string"]], false, true] : [number, number, [[string]], boolean, boolean] +>[["string"]] : [[string]] +>["string"] : [string] + + +// A parameter can be marked optional by following its name or binding pattern with a question mark (?) +// or by including an initializer. + +interface F2 { +>F2 : F2 + + d3([a, b, c]?); +>d3 : ([a, b, c]?: [any, any, any]) => any +>a : any +>b : any +>c : any + + d4({x, y, z}?); +>d4 : ({x, y, z}?: { x: any; y: any; z: any; }) => any +>x : any +>y : any +>z : any + + e0([a, b, c]); +>e0 : ([a, b, c]: [any, any, any]) => any +>a : any +>b : any +>c : any +} + +class C2 implements F2 { +>C2 : C2 +>F2 : F2 + + constructor() { } + d3() { } +>d3 : () => void + + d4() { } +>d4 : () => void + + e0([a, b, c]) { } +>e0 : ([a, b, c]: [any, any, any]) => void +>a : any +>b : any +>c : any +} + +class C3 implements F2 { +>C3 : C3 +>F2 : F2 + + d3([a, b, c]) { } +>d3 : ([a, b, c]: [any, any, any]) => void +>a : any +>b : any +>c : any + + d4({x, y, z}) { } +>d4 : ({x, y, z}: { x: any; y: any; z: any; }) => void +>x : any +>y : any +>z : any + + e0([a, b, c]) { } +>e0 : ([a, b, c]: [any, any, any]) => void +>a : any +>b : any +>c : any +} + +function d5({x, y} = { x: 1, y: 2 }) { } +>d5 : ({x, y}?: { x: number; y: number; }) => void +>x : number +>y : number +>{ x: 1, y: 2 } : { x: number; y: number; } +>x : number +>y : number + +d5(); // Parameter is optional as its declaration included an initializer +>d5() : void +>d5 : ({x, y}?: { x: number; y: number; }) => void + +// Destructuring parameter declarations do not permit type annotations on the individual binding patterns, +// as such annotations would conflict with the already established meaning of colons in object literals. +// Type annotations must instead be written on the top- level parameter declaration + +function e1({x: number}) { } // x has type any NOT number +>e1 : ({x: number}: { x: any; }) => void +>x : unknown +>number : any + +function e2({x}: { x: number }) { } // x is type number +>e2 : ({x}: { x: number; }) => void +>x : number +>x : number + +function e3({x}: { x?: number }) { } // x is an optional with type number +>e3 : ({x}: { x?: number; }) => void +>x : number +>x : number + +function e4({x: [number,string,any] }) { } // x has type [any, any, any] +>e4 : ({x: [number,string,any] }: { x: [any, any, any]; }) => void +>x : unknown +>number : any +>string : any +>any : any + +function e5({x: [a, b, c]}: { x: [number, number, number] }) { } // x has type [any, any, any] +>e5 : ({x: [a, b, c]}: { x: [number, number, number]; }) => void +>x : unknown +>a : number +>b : number +>c : number +>x : [number, number, number] + +function e6({x: [number, number, number]}) { } // should be an error, duplicate identifier; +>e6 : ({x: [number, number, number]}: { x: [any, any, any]; }) => void +>x : unknown +>number : any +>number : any +>number : any + + + diff --git a/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt index 314c1aafee6..60f85604559 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt +++ b/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt @@ -89,7 +89,7 @@ tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts( class C { - constructor(public ...a) { } // Rest parameter can't have accessibilityModifier + constructor(public ...a) { } // Error, rest parameter can't have accessibilityModifier ~~~ !!! error TS1005: ',' expected. } diff --git a/tests/baselines/reference/destructuringParameterDeclaration2.js b/tests/baselines/reference/destructuringParameterDeclaration2.js index 11bda7049e2..187966c3597 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration2.js +++ b/tests/baselines/reference/destructuringParameterDeclaration2.js @@ -43,7 +43,7 @@ a11([1, 2, "string"]); // Error, parameter type is number[] class C { - constructor(public ...a) { } // Rest parameter can't have accessibilityModifier + constructor(public ...a) { } // Error, rest parameter can't have accessibilityModifier } // Rest parameter with generic @@ -149,7 +149,7 @@ var C = (function () { for (var _i = 1; _i < arguments.length; _i++) { a[_i - 1] = arguments[_i]; } - } // Rest parameter can't have accessibilityModifier + } // Error, rest parameter can't have accessibilityModifier return C; })(); // Rest parameter with generic diff --git a/tests/baselines/reference/destructuringParameterDeclaration2ES6.js b/tests/baselines/reference/destructuringParameterDeclaration2ES6.js new file mode 100644 index 00000000000..903384c7b42 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration2ES6.js @@ -0,0 +1,81 @@ +//// [destructuringParameterDeclaration2ES6.ts] + +// If the parameter is a rest parameter, the parameter type is any[] +// A type annotation for a rest parameter must denote an array type. + +// RestParameter: +// ... Identifier TypeAnnotation(opt) + +type arrayString = Array +type someArray = Array | number[]; +type stringOrNumArray = Array; + +function a1(...x: (number|string)[]) { } +function a2(...a) { } +function a3(...a: Array) { } +function a4(...a: arrayString) { } +function a5(...a: stringOrNumArray) { } +function a9([a, b, [[c]]]) { } +function a10([a, b, [[c]], ...x]) { } +function a11([a, b, c, ...x]: number[]) { } + + +var array = [1, 2, 3]; +var array2 = [true, false, "hello"]; +a2([...array]); +a1(...array); + +a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]] + +a10([1, 2, [["string"]], false, true]); // Parameter type is any[] +a10([1, 2, 3, false, true]); // Parameter type is any[] +a10([1, 2]); // Parameter type is any[] + +a11([1, 2]); // Parameter type is number[] + +// Rest parameter with generic +function foo(...a: T[]) { } +foo("hello", 1, 2); +foo("hello", "world"); + +enum E { a, b } +const enum E1 { a, b } +function foo1(...a: T[]) { } +foo1(1, 2, 3, E.a); +foo1(1, 2, 3, E1.a, E.b); + + + + +//// [destructuringParameterDeclaration2ES6.js] +// If the parameter is a rest parameter, the parameter type is any[] +// A type annotation for a rest parameter must denote an array type. +function a1(...x) { } +function a2(...a) { } +function a3(...a) { } +function a4(...a) { } +function a5(...a) { } +function a9([a, b, [[c]]]) { } +function a10([a, b, [[c]], ...x]) { } +function a11([a, b, c, ...x]) { } +var array = [1, 2, 3]; +var array2 = [true, false, "hello"]; +a2([...array]); +a1(...array); +a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]] +a10([1, 2, [["string"]], false, true]); // Parameter type is any[] +a10([1, 2, 3, false, true]); // Parameter type is any[] +a10([1, 2]); // Parameter type is any[] +a11([1, 2]); // Parameter type is number[] +// Rest parameter with generic +function foo(...a) { } +foo("hello", 1, 2); +foo("hello", "world"); +var E; +(function (E) { + E[E["a"] = 0] = "a"; + E[E["b"] = 1] = "b"; +})(E || (E = {})); +function foo1(...a) { } +foo1(1, 2, 3, E.a); +foo1(1, 2, 3, 0 /* a */, E.b); diff --git a/tests/baselines/reference/destructuringParameterDeclaration2ES6.types b/tests/baselines/reference/destructuringParameterDeclaration2ES6.types new file mode 100644 index 00000000000..6215728fefb --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration2ES6.types @@ -0,0 +1,170 @@ +=== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts === + +// If the parameter is a rest parameter, the parameter type is any[] +// A type annotation for a rest parameter must denote an array type. + +// RestParameter: +// ... Identifier TypeAnnotation(opt) + +type arrayString = Array +>arrayString : String[] +>Array : T[] +>String : String + +type someArray = Array | number[]; +>someArray : number[] | String[] +>Array : T[] +>String : String + +type stringOrNumArray = Array; +>stringOrNumArray : (String | Number)[] +>Array : T[] +>String : String +>Number : Number + +function a1(...x: (number|string)[]) { } +>a1 : (...x: (string | number)[]) => void +>x : (string | number)[] + +function a2(...a) { } +>a2 : (...a: any[]) => void +>a : any[] + +function a3(...a: Array) { } +>a3 : (...a: String[]) => void +>a : String[] +>Array : T[] +>String : String + +function a4(...a: arrayString) { } +>a4 : (...a: String[]) => void +>a : String[] +>arrayString : String[] + +function a5(...a: stringOrNumArray) { } +>a5 : (...a: (String | Number)[]) => void +>a : (String | Number)[] +>stringOrNumArray : (String | Number)[] + +function a9([a, b, [[c]]]) { } +>a9 : ([a, b, [[c]]]: [any, any, [[any]]]) => void +>a : any +>b : any +>c : any + +function a10([a, b, [[c]], ...x]) { } +>a10 : ([a, b, [[c]], ...x]: Iterable) => void +>a : any +>b : any +>c : any +>x : any[] + +function a11([a, b, c, ...x]: number[]) { } +>a11 : ([a, b, c, ...x]: number[]) => void +>a : number +>b : number +>c : number +>x : number[] + + +var array = [1, 2, 3]; +>array : number[] +>[1, 2, 3] : number[] + +var array2 = [true, false, "hello"]; +>array2 : (string | boolean)[] +>[true, false, "hello"] : (string | boolean)[] + +a2([...array]); +>a2([...array]) : void +>a2 : (...a: any[]) => void +>[...array] : number[] +>...array : number +>array : number[] + +a1(...array); +>a1(...array) : void +>a1 : (...x: (string | number)[]) => void +>...array : number +>array : number[] + +a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]] +>a9([1, 2, [["string"]], false, true]) : void +>a9 : ([a, b, [[c]]]: [any, any, [[any]]]) => void +>[1, 2, [["string"]], false, true] : [number, number, [[string]], boolean, boolean] +>[["string"]] : [[string]] +>["string"] : [string] + +a10([1, 2, [["string"]], false, true]); // Parameter type is any[] +>a10([1, 2, [["string"]], false, true]) : void +>a10 : ([a, b, [[c]], ...x]: Iterable) => void +>[1, 2, [["string"]], false, true] : (number | boolean | string[][])[] +>[["string"]] : string[][] +>["string"] : string[] + +a10([1, 2, 3, false, true]); // Parameter type is any[] +>a10([1, 2, 3, false, true]) : void +>a10 : ([a, b, [[c]], ...x]: Iterable) => void +>[1, 2, 3, false, true] : (number | boolean)[] + +a10([1, 2]); // Parameter type is any[] +>a10([1, 2]) : void +>a10 : ([a, b, [[c]], ...x]: Iterable) => void +>[1, 2] : number[] + +a11([1, 2]); // Parameter type is number[] +>a11([1, 2]) : void +>a11 : ([a, b, c, ...x]: number[]) => void +>[1, 2] : number[] + +// Rest parameter with generic +function foo(...a: T[]) { } +>foo : (...a: T[]) => void +>T : T +>a : T[] +>T : T + +foo("hello", 1, 2); +>foo("hello", 1, 2) : void +>foo : (...a: T[]) => void + +foo("hello", "world"); +>foo("hello", "world") : void +>foo : (...a: T[]) => void + +enum E { a, b } +>E : E +>a : E +>b : E + +const enum E1 { a, b } +>E1 : E1 +>a : E1 +>b : E1 + +function foo1(...a: T[]) { } +>foo1 : (...a: T[]) => void +>T : T +>Number : Number +>a : T[] +>T : T + +foo1(1, 2, 3, E.a); +>foo1(1, 2, 3, E.a) : void +>foo1 : (...a: T[]) => void +>E.a : E +>E : typeof E +>a : E + +foo1(1, 2, 3, E1.a, E.b); +>foo1(1, 2, 3, E1.a, E.b) : void +>foo1 : (...a: T[]) => void +>E1.a : E1 +>E1 : typeof E1 +>a : E1 +>E.b : E +>E : typeof E +>b : E + + + diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts index 027d11b8c2f..a36e679751c 100644 --- a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts @@ -3,11 +3,10 @@ // in a parameter list must be unique within that parameter list. // If the declaration includes a type annotation, the parameter is of that type -function a0(x: number, y: string, z: boolean) { } function a1([a, b, [[c]]]: [number, number, string[][]]) { } function a2(o: { x: number, a: number }) { } function a3({j, k, l: {m, n}, q: [a, b, c]}: { j: number, k: string, l: { m: boolean, n: number }, q: (number|string)[] }) { }; -function a1({x, a}: { x: number, a: number }) { } +function a4({x, a}: { x: number, a: number }) { } a1([1, 2, [["world"]]]); a1([1, 2, [["world"]], 3]); @@ -19,20 +18,24 @@ a1([1, 2, [["world"]], "string"]); // Error // when the parameter list occurs in conjunction with a function body), // the parameter type is the widened form (section 3.11) of the type of the initializer expression. -function b1(z = 10, y = 60, u = () => true) { } -function b2(z = [undefined, null]) { }; -function b3(z = null, o = { x: 0, y: undefined }) { } -function b4({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } +function b1(z = [undefined, null]) { }; +function b2(z = null, o = { x: 0, y: undefined }) { } +function b3({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } interface F1 { - b5(z = 10, [[a, b], d, {u}] = [[1, 2], "string", { u: false }]); // Error, no function body - b6(z, y, [, a, b], {p, m: { q, r}}); + b4(z = 10, [[a, b], d, {u}] = [[1, 2], "string", { u: false }]); // Error, no function body + b5(z, y, [, a, b], {p, m: { q, r}}); } -b2([1, 2, 3]); // z is widen to the type any[] -b3("string", { x: 200, y: "string" }); -b3("string", { x: 200, y: true }); -b3("string", { x: "string", y: true }); // Error +function b6([a, z, y] = [undefined, null, undefined]) { } +function b7([[a], b, [[c, d]]] = [[undefined], undefined, [[undefined, undefined]]]) { } + +b1([1, 2, 3]); // z is widen to the type any[] +b2("string", { x: 200, y: "string" }); +b2("string", { x: 200, y: true }); +b2("string", { x: "string", y: true }); // Error +b6(["string", 1, 2]); // Shouldn't be an error +b7([["string"], 1, [[true, false]]]); // Shouldn't be an error // If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3) @@ -72,8 +75,8 @@ c6([1, 2, [["string"]]]); // Error, implied type is [any, any, [[number]]] // function d0(x?) { } function d0(x = 10) { } -function d1([a, b, c]?) { } -function d2({x, y, z}?) { } +function d1([a, b, c]?) { } // Error, binding pattern can't be optional in implementation signature +function d2({x, y, z}?) { } // Error, binding pattern can't be optional in implementation signature interface F2 { d3([a, b, c]?); @@ -103,4 +106,16 @@ class C4 implements F2 { function d5({x, y} = { x: 1, y: 2 }) { } d5(); // Parameter is optional as its declaration included an initializer +// Destructuring parameter declarations do not permit type annotations on the individual binding patterns, +// as such annotations would conflict with the already established meaning of colons in object literals. +// Type annotations must instead be written on the top- level parameter declaration + +function e1({x: number}) { } // x has type any NOT number +function e2({x}: { x: number }) { } // x is type number +function e3({x}: { x?: number }) { } // x is an optional with type number +function e4({x: [number,string,any] }) { } // x has type [any, any, any] +function e5({x: [a, b, c]}: { x: [number, number, number] }) { } // x has type [any, any, any] + +function e6({x: [number, number, number]}) { } // should be an error, duplicate identifier; + diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts new file mode 100644 index 00000000000..58d69729b98 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts @@ -0,0 +1,99 @@ +// Conformance for emitting ES6 +// @target: es6 + +// A parameter declaration may specify either an identifier or a binding pattern. +// The identifiers specified in parameter declarations and binding patterns +// in a parameter list must be unique within that parameter list. + +// If the declaration includes a type annotation, the parameter is of that type +function a1([a, b, [[c]]]: [number, number, string[][]]) { } +function a2(o: { x: number, a: number }) { } +function a3({j, k, l: {m, n}, q: [a, b, c]}: { j: number, k: string, l: { m: boolean, n: number }, q: (number|string)[] }) { }; +function a4({x, a}: { x: number, a: number }) { } + +a1([1, 2, [["world"]]]); +a1([1, 2, [["world"]], 3]); + + +// If the declaration includes an initializer expression (which is permitted only +// when the parameter list occurs in conjunction with a function body), +// the parameter type is the widened form (section 3.11) of the type of the initializer expression. + +function b1(z = [undefined, null]) { }; +function b2(z = null, o = { x: 0, y: undefined }) { } +function b3({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } + +interface F1 { + b5(z, y, [, a, b], {p, m: { q, r}}); +} + +function b6([a, z, y] = [undefined, null, undefined]) { } +function b7([[a], b, [[c, d]]] = [[undefined], undefined, [[undefined, undefined]]]) { } + +b1([1, 2, 3]); // z is widen to the type any[] +b2("string", { x: 200, y: "string" }); +b2("string", { x: 200, y: true }); + + +// If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3) +enum Foo { a } +function c0({z: {x, y: {j}}}) { } +function c1({z} = { z: 10 }) { } +function c2({z = 10}) { } +function c3({b}: { b: number|string} = { b: "hello" }) { } +function c5([a, b, [[c]]]) { } +function c6([a, b, [[c=1]]]) { } + +c0({z : { x: 1, y: { j: "world" } }}); // Implied type is { z: {x: any, y: {j: any}} } +c0({z : { x: "string", y: { j: true } }}); // Implied type is { z: {x: any, y: {j: any}} } + +c1(); // Implied type is {z:number}? +c1({ z: 1 }) // Implied type is {z:number}? + +c2({}); // Implied type is {z?: number} +c2({z:1}); // Implied type is {z?: number} + +c3({ b: 1 }); // Implied type is { b: number|string }. + +c5([1, 2, [["string"]]]); // Implied type is is [any, any, [[any]]] +c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]] + + +// A parameter can be marked optional by following its name or binding pattern with a question mark (?) +// or by including an initializer. + +interface F2 { + d3([a, b, c]?); + d4({x, y, z}?); + e0([a, b, c]); +} + +class C2 implements F2 { + constructor() { } + d3() { } + d4() { } + e0([a, b, c]) { } +} + +class C3 implements F2 { + d3([a, b, c]) { } + d4({x, y, z}) { } + e0([a, b, c]) { } +} + +function d5({x, y} = { x: 1, y: 2 }) { } +d5(); // Parameter is optional as its declaration included an initializer + +// Destructuring parameter declarations do not permit type annotations on the individual binding patterns, +// as such annotations would conflict with the already established meaning of colons in object literals. +// Type annotations must instead be written on the top- level parameter declaration + +function e1({x: number}) { } // x has type any NOT number +function e2({x}: { x: number }) { } // x is type number +function e3({x}: { x?: number }) { } // x is an optional with type number +function e4({x: [number,string,any] }) { } // x has type [any, any, any] +function e5({x: [a, b, c]}: { x: [number, number, number] }) { } // x has type [any, any, any] + +function e6({x: [number, number, number]}) { } // should be an error, duplicate identifier; + + diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts index 5a775eb69c9..b764e4f286c 100644 --- a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts @@ -42,7 +42,7 @@ a11([1, 2, "string"]); // Error, parameter type is number[] class C { - constructor(public ...a) { } // Rest parameter can't have accessibilityModifier + constructor(public ...a) { } // Error, rest parameter can't have accessibilityModifier } // Rest parameter with generic diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts new file mode 100644 index 00000000000..59b08013a2a --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts @@ -0,0 +1,47 @@ +// @target: es6 + +// If the parameter is a rest parameter, the parameter type is any[] +// A type annotation for a rest parameter must denote an array type. + +// RestParameter: +// ... Identifier TypeAnnotation(opt) + +type arrayString = Array +type someArray = Array | number[]; +type stringOrNumArray = Array; + +function a1(...x: (number|string)[]) { } +function a2(...a) { } +function a3(...a: Array) { } +function a4(...a: arrayString) { } +function a5(...a: stringOrNumArray) { } +function a9([a, b, [[c]]]) { } +function a10([a, b, [[c]], ...x]) { } +function a11([a, b, c, ...x]: number[]) { } + + +var array = [1, 2, 3]; +var array2 = [true, false, "hello"]; +a2([...array]); +a1(...array); + +a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]] + +a10([1, 2, [["string"]], false, true]); // Parameter type is any[] +a10([1, 2, 3, false, true]); // Parameter type is any[] +a10([1, 2]); // Parameter type is any[] + +a11([1, 2]); // Parameter type is number[] + +// Rest parameter with generic +function foo(...a: T[]) { } +foo("hello", 1, 2); +foo("hello", "world"); + +enum E { a, b } +const enum E1 { a, b } +function foo1(...a: T[]) { } +foo1(1, 2, 3, E.a); +foo1(1, 2, 3, E1.a, E.b); + + From 55f9aba85581e96d12e1c6d32d46ce148f4a1d34 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 16 Apr 2015 14:32:23 -0700 Subject: [PATCH 031/194] Move tests with errors to separate file --- ... destructuringParameterDeclaration1ES5.ts} | 25 ---- .../destructuringParameterDeclaration2.ts | 110 +++++++++--------- ... destructuringParameterDeclaration3ES5.ts} | 3 +- .../destructuringParameterDeclaration3ES6.ts | 46 ++++++++ .../destructuringParameterDeclaration4.ts | 77 +++++------- .../destructuringParameterDeclaration5.ts | 50 ++++++++ ... => destructuringParameterDeclaration6.ts} | 0 7 files changed, 187 insertions(+), 124 deletions(-) rename tests/cases/conformance/es6/destructuring/{destructuringParameterDeclaration1.ts => destructuringParameterDeclaration1ES5.ts} (73%) rename tests/cases/conformance/es6/destructuring/{destructuringParameterDeclaration2ES6.ts => destructuringParameterDeclaration3ES5.ts} (91%) create mode 100644 tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES6.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration5.ts rename tests/cases/conformance/es6/destructuring/{destructuringParameterDeclaration3.ts => destructuringParameterDeclaration6.ts} (100%) diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5.ts similarity index 73% rename from tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts rename to tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5.ts index a36e679751c..01f3cda52bf 100644 --- a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5.ts @@ -10,9 +10,6 @@ function a4({x, a}: { x: number, a: number }) { } a1([1, 2, [["world"]]]); a1([1, 2, [["world"]], 3]); -a1([1, "string", [["world"]]); // Error -a1([1, 2, [["world"]], "string"]); // Error - // If the declaration includes an initializer expression (which is permitted only // when the parameter list occurs in conjunction with a function body), @@ -23,7 +20,6 @@ function b2(z = null, o = { x: 0, y: undefined }) { } function b3({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } interface F1 { - b4(z = 10, [[a, b], d, {u}] = [[1, 2], "string", { u: false }]); // Error, no function body b5(z, y, [, a, b], {p, m: { q, r}}); } @@ -33,7 +29,6 @@ function b7([[a], b, [[c, d]]] = [[undefined], undefined, [[undefined, undefined b1([1, 2, 3]); // z is widen to the type any[] b2("string", { x: 200, y: "string" }); b2("string", { x: 200, y: true }); -b2("string", { x: "string", y: true }); // Error b6(["string", 1, 2]); // Shouldn't be an error b7([["string"], 1, [[true, false]]]); // Shouldn't be an error @@ -44,39 +39,28 @@ function c0({z: {x, y: {j}}}) { } function c1({z} = { z: 10 }) { } function c2({z = 10}) { } function c3({b}: { b: number|string} = { b: "hello" }) { } -function c4([z], z: number) { } // Duplicate identifier function c5([a, b, [[c]]]) { } function c6([a, b, [[c=1]]]) { } c0({z : { x: 1, y: { j: "world" } }}); // Implied type is { z: {x: any, y: {j: any}} } c0({z : { x: "string", y: { j: true } }}); // Implied type is { z: {x: any, y: {j: any}} } -c0({z : 1}); // Error, implied type is { z: {x: any, y: {j: any}} } -c1({}); // Error, implied type is {z:number}? -c1({ z: true }); // Error, implied type is {z:number}? c1(); // Implied type is {z:number}? c1({ z: 1 }) // Implied type is {z:number}? c2({}); // Implied type is {z?: number} c2({z:1}); // Implied type is {z?: number} -c2({z:false}); // Error, implied type is {z?: number} c3({ b: 1 }); // Implied type is { b: number|string }. -c3({ b: true }); // Error, implied type is { b: number|string }. c5([1, 2, [["string"]]]); // Implied type is is [any, any, [[any]]] c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]] -c5([1, 2, false, true]); // Error, implied type is [any, any, [[any]]] - -c6([1, 2, [["string"]]]); // Error, implied type is [any, any, [[number]]] // Use initializer // A parameter can be marked optional by following its name or binding pattern with a question mark (?) // or by including an initializer. function d0(x?) { } function d0(x = 10) { } -function d1([a, b, c]?) { } // Error, binding pattern can't be optional in implementation signature -function d2({x, y, z}?) { } // Error, binding pattern can't be optional in implementation signature interface F2 { d3([a, b, c]?); @@ -97,11 +81,6 @@ class C3 implements F2 { e0([a, b, c]) { } } -class C4 implements F2 { - d3([a, b, c]?) { } - d4({x, y, c}) { } - e0([a, b, q]) { } -} function d5({x, y} = { x: 1, y: 2 }) { } d5(); // Parameter is optional as its declaration included an initializer @@ -115,7 +94,3 @@ function e2({x}: { x: number }) { } // x is type number function e3({x}: { x?: number }) { } // x is an optional with type number function e4({x: [number,string,any] }) { } // x has type [any, any, any] function e5({x: [a, b, c]}: { x: [number, number, number] }) { } // x has type [any, any, any] - -function e6({x: [number, number, number]}) { } // should be an error, duplicate identifier; - - diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts index b764e4f286c..19f508c0625 100644 --- a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts @@ -1,61 +1,67 @@ -// If the parameter is a rest parameter, the parameter type is any[] -// A type annotation for a rest parameter must denote an array type. +// A parameter declaration may specify either an identifier or a binding pattern. +// The identifiers specified in parameter declarations and binding patterns +// in a parameter list must be unique within that parameter list. -// RestParameter: -// ... Identifier TypeAnnotation(opt) - -type arrayString = Array -type someArray = Array | number[]; -type stringOrNumArray = Array; - -function a0(...x: [number, number, string]) { } // Error, rest parameter must be array type -function a1(...x: (number|string)[]) { } -function a2(...a) { } -function a3(...a: Array) { } -function a4(...a: arrayString) { } -function a5(...a: stringOrNumArray) { } -function a6(...a: someArray) { } // Error, rest parameter must be array type -function a7(...b?) { } // Error, can't be optional -function a8(...b = [1,2,3]) { } // Error, can't have initializer -function a9([a, b, [[c]]]) { } -function a10([a, b, [[c]], ...x]) { } -function a11([a, b, c, ...x]: number[]) { } +// If the declaration includes a type annotation, the parameter is of that type +function a0([a, b, [[c]]]: [number, number, string[][]]) { } +a0([1, "string", [["world"]]); // Error +a0([1, 2, [["world"]], "string"]); // Error -a1(1, 2, "hello", true); // Error, parameter type is (number|string)[] -var array = [1, 2, 3]; -var array2 = [true, false, "hello"]; -a2([...array]); -a1(...array); -a1(...array2); // Error parameter type is (number|string)[] +// If the declaration includes an initializer expression (which is permitted only +// when the parameter list occurs in conjunction with a function body), +// the parameter type is the widened form (section 3.11) of the type of the initializer expression. -a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]] -a9([1, 2, "string", false, true]); // Error, parameter type is [any, any, [[any]]] -a9([1, 2]); // Error, parameter type is [any, any, [[any]]] - -a10([1, 2, [["string"]], false, true]); // Parameter type is any[] -a10([1, 2, 3, false, true]); // Parameter type is any[] -a10([1, 2]); // Parameter type is any[] - -a11([1, 2]); // Parameter type is number[] -a11([1, 2, "string"]); // Error, parameter type is number[] - - -class C { - constructor(public ...a) { } // Error, rest parameter can't have accessibilityModifier +interface F1 { + b0(z = 10, [[a, b], d, {u}] = [[1, 2], "string", { u: false }]); // Error, no function body } -// Rest parameter with generic -function foo(...a: T[]) { } -foo("hello", 1, 2); // Error -foo("hello", 1, 2); -foo("hello", "world"); +function b1(z = null, o = { x: 0, y: undefined }) { } +function b2([a, z, y] = [undefined, null, undefined]) { } +function b3([[a], b, [[c, d]]] = [[undefined], undefined, [[undefined, undefined]]]) { } -enum E { a, b } -const enum E1 { a, b } -function foo1(...a: T[]) { } -foo1(1, 2, 3, E.a); -foo1(1, 2, 3, E1.a, E.b); -foo1(1, 2, "string", E1.a, E.b); // Error +b1("string", { x: "string", y: true }); // Error + +// If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3) +function c0({z: {x, y: {j}}}) { } +function c1({z} = { z: 10 }) { } +function c2({z = 10}) { } +function c3({b}: { b: number|string } = { b: "hello" }) { } +function c4([z], z: number) { } // Error Duplicate identifier +function c5([a, b, [[c]]]) { } +function c6([a, b, [[c = 1]]]) { } + +c0({ z: 1 }); // Error, implied type is { z: {x: any, y: {j: any}} } +c1({}); // Error, implied type is {z:number}? +c1({ z: true }); // Error, implied type is {z:number}? +c2({ z: false }); // Error, implied type is {z?: number} +c3({ b: true }); // Error, implied type is { b: number|string }. +c5([1, 2, false, true]); // Error, implied type is [any, any, [[any]]] +c6([1, 2, [["string"]]]); // Error, implied type is [any, any, [[number]]] // Use initializer + +// A parameter can be marked optional by following its name or binding pattern with a question mark (?) +// or by including an initializer. Initializers (including binding property or element initializers) are +// permitted only when the parameter list occurs in conjunction with a function body + +function d1([a, b, c]?) { } // Error, binding pattern can't be optional in implementation signature +function d2({x, y, z}?) { } // Error, binding pattern can't be optional in implementation signature + +interface F2 { + d3([a, b, c]?); + d4({x, y, z}?); + e0([a, b, c]); +} + +class C4 implements F2 { + d3([a, b, c]?) { } // Error, binding pattern can't be optional in implementation signature + d4({x, y, c}) { } + e0([a, b, q]) { } +} + +// Destructuring parameter declarations do not permit type annotations on the individual binding patterns, +// as such annotations would conflict with the already established meaning of colons in object literals. +// Type annotations must instead be written on the top- level parameter declaration + +function e0({x: [number, number, number]}) { } // should be an error, duplicate identifier; diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5.ts similarity index 91% rename from tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts rename to tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5.ts index 59b08013a2a..6eab2225e03 100644 --- a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5.ts @@ -30,8 +30,7 @@ a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]] a10([1, 2, [["string"]], false, true]); // Parameter type is any[] a10([1, 2, 3, false, true]); // Parameter type is any[] a10([1, 2]); // Parameter type is any[] - -a11([1, 2]); // Parameter type is number[] +a11([1, 2]); // Parameter type is number[] // Rest parameter with generic function foo(...a: T[]) { } diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES6.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES6.ts new file mode 100644 index 00000000000..6eab2225e03 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES6.ts @@ -0,0 +1,46 @@ +// @target: es6 + +// If the parameter is a rest parameter, the parameter type is any[] +// A type annotation for a rest parameter must denote an array type. + +// RestParameter: +// ... Identifier TypeAnnotation(opt) + +type arrayString = Array +type someArray = Array | number[]; +type stringOrNumArray = Array; + +function a1(...x: (number|string)[]) { } +function a2(...a) { } +function a3(...a: Array) { } +function a4(...a: arrayString) { } +function a5(...a: stringOrNumArray) { } +function a9([a, b, [[c]]]) { } +function a10([a, b, [[c]], ...x]) { } +function a11([a, b, c, ...x]: number[]) { } + + +var array = [1, 2, 3]; +var array2 = [true, false, "hello"]; +a2([...array]); +a1(...array); + +a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]] + +a10([1, 2, [["string"]], false, true]); // Parameter type is any[] +a10([1, 2, 3, false, true]); // Parameter type is any[] +a10([1, 2]); // Parameter type is any[] +a11([1, 2]); // Parameter type is number[] + +// Rest parameter with generic +function foo(...a: T[]) { } +foo("hello", 1, 2); +foo("hello", "world"); + +enum E { a, b } +const enum E1 { a, b } +function foo1(...a: T[]) { } +foo1(1, 2, 3, E.a); +foo1(1, 2, 3, E1.a, E.b); + + diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts index 4f0f52d3065..02fc84b380a 100644 --- a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts @@ -1,49 +1,36 @@ -// Parameter with generic -interface F { } -class Class implements F { - constructor() { } +// If the parameter is a rest parameter, the parameter type is any[] +// A type annotation for a rest parameter must denote an array type. + +// RestParameter: +// ... Identifier TypeAnnotation(opt) + +type arrayString = Array +type someArray = Array | number[]; +type stringOrNumArray = Array; + +function a0(...x: [number, number, string]) { } // Error, rest parameter must be array type +function a1(...x: (number|string)[]) { } +function a2(...a: someArray) { } // Error, rest parameter must be array type +function a3(...b?) { } // Error, can't be optional +function a4(...b = [1,2,3]) { } // Error, can't have initializer +function a5([a, b, [[c]]]) { } +function a6([a, b, c, ...x]: number[]) { } + + +a1(1, 2, "hello", true); // Error, parameter type is (number|string)[] +a1(...array2); // Error parameter type is (number|string)[] +a5([1, 2, "string", false, true]); // Error, parameter type is [any, any, [[any]]] +a5([1, 2]); // Error, parameter type is [any, any, [[any]]] +a6([1, 2, "string"]); // Error, parameter type is number[] + + +var temp = [1, 2, 3]; +class C { + constructor(public ...temp) { } // Error, rest parameter can't have accessibilityModifier } -class SubClass extends Class { - foo: boolean; - constructor() { super(); } -} - -class D implements F { - foo: boolean - constructor() { } -} - -class SubD extends D { - bar: number - constructor() { - super(); - } -} +// Rest parameter with generic +function foo1(...a: T[]) { } +foo1(1, 2, "string", E1.a, E.b); // Error -function d0({x} = { x: new Class() }) { } -function d1({x}: { x: F }) { } -function d2({x}: { x: Class }) { } -function d3({y}: { y: D }) { } -function d4({y} = { y: new D() }) { } - -var obj = new Class(); -d0({ x: 1 }); -d0({ x: {} }); -d0({ x: "string" }); - -d1({ x: new Class() }); -d1({ x: {} }); -d1({ x: "string" }); - -d2({ x: new SubClass() }); -d2({ x: {} }); - -d3({ y: new SubD() }); -d3({ y: new SubClass() }); -// Error -d3({ y: new Class() }); -d3({}); -d3({ y: 1 }); -d3({ y: "world" }); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration5.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration5.ts new file mode 100644 index 00000000000..c4fcffed491 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration5.ts @@ -0,0 +1,50 @@ +// Parameter Declaration with generic + +interface F { } +class Class implements F { + constructor() { } +} + +class SubClass extends Class { + foo: boolean; + constructor() { super(); } +} + +class D implements F { + foo: boolean + constructor() { } +} + +class SubD extends D { + bar: number + constructor() { + super(); + } +} + + +function d0({x} = { x: new Class() }) { } +function d1({x}: { x: F }) { } +function d2({x}: { x: Class }) { } +function d3({y}: { y: D }) { } +function d4({y} = { y: new D() }) { } + +var obj = new Class(); +d0({ x: 1 }); +d0({ x: {} }); +d0({ x: "string" }); + +d1({ x: new Class() }); +d1({ x: {} }); +d1({ x: "string" }); + +d2({ x: new SubClass() }); +d2({ x: {} }); + +d3({ y: new SubD() }); +d3({ y: new SubClass() }); +// Error +d3({ y: new Class() }); +d3({}); +d3({ y: 1 }); +d3({ y: "world" }); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts b/tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration6.ts similarity index 100% rename from tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts rename to tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration6.ts From bda1f59d7b04bee5ac585e63bbf3ffff3247cfe2 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 16 Apr 2015 14:39:02 -0700 Subject: [PATCH 032/194] Include property in union type only if all underlying properties are public --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e9430a058f8..630d108c0e9 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2945,7 +2945,7 @@ module ts { let type = getApparentType(current); if (type !== unknownType) { let prop = getPropertyOfType(type, name); - if (!prop) { + if (!prop || getDeclarationFlagsFromSymbol(prop) & (NodeFlags.Private | NodeFlags.Protected)) { return undefined; } if (!props) { From 845b618b42084585525b80be2c0266ddee007a1a Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 16 Apr 2015 14:41:19 -0700 Subject: [PATCH 033/194] Add spec description to the test file and move tests that generate errors to separate file --- .../reference/arrayLiterals2.errors.txt | 60 ------ tests/baselines/reference/arrayLiterals2.js | 60 ------ .../baselines/reference/arrayLiterals2ES5.js | 104 ++++++++++ .../reference/arrayLiterals2ES5.types | 184 ++++++++++++++++++ .../reference/arrayLiterals2ES6.errors.txt | 60 ------ .../baselines/reference/arrayLiterals2ES6.js | 150 ++++++++------ .../reference/arrayLiterals2ES6.types | 172 ++++++++++++++++ .../reference/arrayLiterals3.errors.txt | 120 +++++++----- tests/baselines/reference/arrayLiterals3.js | 120 ++++++------ .../reference/arrayLiterals3ES6.errors.txt | 52 ----- .../baselines/reference/arrayLiterals3ES6.js | 62 ------ .../reference/arrayLiterals4.errors.txt | 31 --- tests/baselines/reference/arrayLiterals4.js | 16 -- .../reference/arrayLiterals5.errors.txt | 46 ----- tests/baselines/reference/arrayLiterals5.js | 19 -- .../arrayLiterals/arrayLiterals2.ts | 32 --- .../arrayLiterals/arrayLiterals2ES5.ts | 56 ++++++ .../arrayLiterals/arrayLiterals2ES6.ts | 84 +++++--- .../arrayLiterals/arrayLiterals3.ts | 72 +++---- .../arrayLiterals/arrayLiterals3ES6.ts | 39 ---- .../arrayLiterals/arrayLiterals4.ts | 6 - .../arrayLiterals/arrayLiterals5.ts | 3 - 22 files changed, 823 insertions(+), 725 deletions(-) delete mode 100644 tests/baselines/reference/arrayLiterals2.errors.txt delete mode 100644 tests/baselines/reference/arrayLiterals2.js create mode 100644 tests/baselines/reference/arrayLiterals2ES5.js create mode 100644 tests/baselines/reference/arrayLiterals2ES5.types delete mode 100644 tests/baselines/reference/arrayLiterals2ES6.errors.txt create mode 100644 tests/baselines/reference/arrayLiterals2ES6.types delete mode 100644 tests/baselines/reference/arrayLiterals3ES6.errors.txt delete mode 100644 tests/baselines/reference/arrayLiterals3ES6.js delete mode 100644 tests/baselines/reference/arrayLiterals4.errors.txt delete mode 100644 tests/baselines/reference/arrayLiterals4.js delete mode 100644 tests/baselines/reference/arrayLiterals5.errors.txt delete mode 100644 tests/baselines/reference/arrayLiterals5.js delete mode 100644 tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2.ts create mode 100644 tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2ES5.ts delete mode 100644 tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3ES6.ts delete mode 100644 tests/cases/conformance/expressions/arrayLiterals/arrayLiterals4.ts delete mode 100644 tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts diff --git a/tests/baselines/reference/arrayLiterals2.errors.txt b/tests/baselines/reference/arrayLiterals2.errors.txt deleted file mode 100644 index 149d9a4747c..00000000000 --- a/tests/baselines/reference/arrayLiterals2.errors.txt +++ /dev/null @@ -1,60 +0,0 @@ -tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2.ts(23,5): error TS2322: Type '(string[] | number[])[]' is not assignable to type 'tup'. - Property '0' is missing in type '(string[] | number[])[]'. -tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2.ts(24,5): error TS2322: Type 'number[]' is not assignable to type '[number, number, number]'. - Property '0' is missing in type 'number[]'. -tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2.ts(27,5): error TS2322: Type '(string | number)[]' is not assignable to type 'myArray'. - Types of property 'push' are incompatible. - Type '(...items: (string | number)[]) => number' is not assignable to type '(...items: Number[]) => number'. - Types of parameters 'items' and 'items' are incompatible. - Type 'string | number' is not assignable to type 'Number'. - Type 'string' is not assignable to type 'Number'. - Property 'toFixed' is missing in type 'String'. - - -==== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2.ts (3 errors) ==== - var a = [2,3,4] - var a1 = ["hello", "world"] - var a2 = [undefined, null, undefined]; - var a3 = [] - var a4: number[] = [...a3]; - var a5: number[] = []; - - var b = [, , , ...a,"hello"]; - var c = [() => 1,]; - var d = [...c,,]; - var e = [,,...d]; - var g = [[1, 2, "hello"], ["string", true]]; - var h = [...g]; - var i: [number[], string[]] = [[1, 2, 3],["hello", "string"]]; - var j = [...i]; - var k:Array = [...i]; - interface tup { - 0: number[]|string[]; - 1: number[]|string[]; - } - interface myArray extends Array {} - interface myArray2 extends Array {} - var l: tup = [...i]; // error - ~ -!!! error TS2322: Type '(string[] | number[])[]' is not assignable to type 'tup'. -!!! error TS2322: Property '0' is missing in type '(string[] | number[])[]'. - var m: [number, number, number] = [...a]; // error - ~ -!!! error TS2322: Type 'number[]' is not assignable to type '[number, number, number]'. -!!! error TS2322: Property '0' is missing in type 'number[]'. - var n: number[] = [...a]; - var o: myArray = [...a]; - var p: myArray = [...a, ...a1]; // error - ~ -!!! error TS2322: Type '(string | number)[]' is not assignable to type 'myArray'. -!!! error TS2322: Types of property 'push' are incompatible. -!!! error TS2322: Type '(...items: (string | number)[]) => number' is not assignable to type '(...items: Number[]) => number'. -!!! error TS2322: Types of parameters 'items' and 'items' are incompatible. -!!! error TS2322: Type 'string | number' is not assignable to type 'Number'. -!!! error TS2322: Type 'string' is not assignable to type 'Number'. -!!! error TS2322: Property 'toFixed' is missing in type 'String'. - var q: myArray2 = [...a, ...a1]; - var r = [...a2]; - var r1 = [...a3]; - var r2 = [...a4]; - var r3:number[][] = [[...a4]]; \ No newline at end of file diff --git a/tests/baselines/reference/arrayLiterals2.js b/tests/baselines/reference/arrayLiterals2.js deleted file mode 100644 index 42cfb13c96a..00000000000 --- a/tests/baselines/reference/arrayLiterals2.js +++ /dev/null @@ -1,60 +0,0 @@ -//// [arrayLiterals2.ts] -var a = [2,3,4] -var a1 = ["hello", "world"] -var a2 = [undefined, null, undefined]; -var a3 = [] -var a4: number[] = [...a3]; -var a5: number[] = []; - -var b = [, , , ...a,"hello"]; -var c = [() => 1,]; -var d = [...c,,]; -var e = [,,...d]; -var g = [[1, 2, "hello"], ["string", true]]; -var h = [...g]; -var i: [number[], string[]] = [[1, 2, 3],["hello", "string"]]; -var j = [...i]; -var k:Array = [...i]; -interface tup { - 0: number[]|string[]; - 1: number[]|string[]; -} -interface myArray extends Array {} -interface myArray2 extends Array {} -var l: tup = [...i]; // error -var m: [number, number, number] = [...a]; // error -var n: number[] = [...a]; -var o: myArray = [...a]; -var p: myArray = [...a, ...a1]; // error -var q: myArray2 = [...a, ...a1]; -var r = [...a2]; -var r1 = [...a3]; -var r2 = [...a4]; -var r3:number[][] = [[...a4]]; - -//// [arrayLiterals2.js] -var a = [2, 3, 4]; -var a1 = ["hello", "world"]; -var a2 = [undefined, null, undefined]; -var a3 = []; -var a4 = a3; -var a5 = []; -var b = [, , ].concat(a, ["hello"]); -var c = [function () { return 1; },]; -var d = c.concat([,]); -var e = [, ].concat(d); -var g = [[1, 2, "hello"], ["string", true]]; -var h = g; -var i = [[1, 2, 3], ["hello", "string"]]; -var j = i; -var k = i; -var l = i; // error -var m = a; // error -var n = a; -var o = a; -var p = a.concat(a1); // error -var q = a.concat(a1); -var r = a2; -var r1 = a3; -var r2 = a4; -var r3 = [a4]; diff --git a/tests/baselines/reference/arrayLiterals2ES5.js b/tests/baselines/reference/arrayLiterals2ES5.js new file mode 100644 index 00000000000..0ff82e90970 --- /dev/null +++ b/tests/baselines/reference/arrayLiterals2ES5.js @@ -0,0 +1,104 @@ +//// [arrayLiterals2ES5.ts] +// ElementList: ( Modified ) +// Elisionopt AssignmentExpression +// Elisionopt SpreadElement +// ElementList, Elisionopt AssignmentExpression +// ElementList, Elisionopt SpreadElement + +// SpreadElement: +// ... AssignmentExpression + +var a0 = [,, 2, 3, 4] +var a1 = ["hello", "world"] +var a2 = [, , , ...a0, "hello"]; +var a3 = [,, ...a0] +var a4 = [() => 1, ]; +var a5 = [...a0, , ] + +// Each element expression in a non-empty array literal is processed as follows: +// - If the array literal contains no spread elements, and if the array literal is contextually typed (section 4.19) +// by a type T and T has a property with the numeric name N, where N is the index of the element expression in the array literal, +// the element expression is contextually typed by the type of that property. + +// The resulting type an array literal expression is determined as follows: +// - If the array literal contains no spread elements and is contextually typed by a tuple-like type, +// the resulting type is a tuple type constructed from the types of the element expressions. + +var b0: [any, any, any] = [undefined, null, undefined]; +var b1: [number[], string[]] = [[1, 2, 3], ["hello", "string"]]; + +// The resulting type an array literal expression is determined as follows: +// - If the array literal contains no spread elements and is an array assignment pattern in a destructuring assignment (section 4.17.1), +// the resulting type is a tuple type constructed from the types of the element expressions. + +var [c0, c1] = [1, 2]; // tuple type [number, number] +var [c2, c3] = [1, 2, true]; // tuple type [number, number, boolean] + +// The resulting type an array literal expression is determined as follows: +// - the resulting type is an array type with an element type that is the union of the types of the +// non - spread element expressions and the numeric index signature types of the spread element expressions +var temp = ["s", "t", "r"]; +var temp1 = [1, 2, 3]; +var temp2: [number[], string[]] = [[1, 2, 3], ["hello", "string"]]; +var temp3 = [undefined, null, undefined]; +var temp4 = []; + +interface myArray extends Array { } +interface myArray2 extends Array { } +var d0 = [1, true, ...temp,]; // has type (string|number|boolean)[] +var d1 = [...temp]; // has type string[] +var d2: number[] = [...temp1]; +var d3: myArray = [...temp1]; +var d4: myArray2 = [...temp, ...temp1]; +var d5 = [...temp3]; +var d6 = [...temp4]; +var d7 = [...[...temp1]]; +var d8: number[][] = [[...temp1]] +var d9 = [[...temp1], ...["hello"]]; + +//// [arrayLiterals2ES5.js] +// ElementList: ( Modified ) +// Elisionopt AssignmentExpression +// Elisionopt SpreadElement +// ElementList, Elisionopt AssignmentExpression +// ElementList, Elisionopt SpreadElement +// SpreadElement: +// ... AssignmentExpression +var a0 = [, , 2, 3, 4]; +var a1 = ["hello", "world"]; +var a2 = [, , ].concat(a0, ["hello"]); +var a3 = [, ].concat(a0); +var a4 = [function () { return 1; },]; +var a5 = a0.concat([,]); +// Each element expression in a non-empty array literal is processed as follows: +// - If the array literal contains no spread elements, and if the array literal is contextually typed (section 4.19) +// by a type T and T has a property with the numeric name N, where N is the index of the element expression in the array literal, +// the element expression is contextually typed by the type of that property. +// The resulting type an array literal expression is determined as follows: +// - If the array literal contains no spread elements and is contextually typed by a tuple-like type, +// the resulting type is a tuple type constructed from the types of the element expressions. +var b0 = [undefined, null, undefined]; +var b1 = [[1, 2, 3], ["hello", "string"]]; +// The resulting type an array literal expression is determined as follows: +// - If the array literal contains no spread elements and is an array assignment pattern in a destructuring assignment (section 4.17.1), +// the resulting type is a tuple type constructed from the types of the element expressions. +var _a = [1, 2], c0 = _a[0], c1 = _a[1]; // tuple type [number, number] +var _b = [1, 2, true], c2 = _b[0], c3 = _b[1]; // tuple type [number, number, boolean] +// The resulting type an array literal expression is determined as follows: +// - the resulting type is an array type with an element type that is the union of the types of the +// non - spread element expressions and the numeric index signature types of the spread element expressions +var temp = ["s", "t", "r"]; +var temp1 = [1, 2, 3]; +var temp2 = [[1, 2, 3], ["hello", "string"]]; +var temp3 = [undefined, null, undefined]; +var temp4 = []; +var d0 = [1, true].concat(temp); // has type (string|number|boolean)[] +var d1 = temp; // has type string[] +var d2 = temp1; +var d3 = temp1; +var d4 = temp.concat(temp1); +var d5 = temp3; +var d6 = temp4; +var d7 = temp1; +var d8 = [temp1]; +var d9 = [temp1].concat(["hello"]); diff --git a/tests/baselines/reference/arrayLiterals2ES5.types b/tests/baselines/reference/arrayLiterals2ES5.types new file mode 100644 index 00000000000..cd55e4ea514 --- /dev/null +++ b/tests/baselines/reference/arrayLiterals2ES5.types @@ -0,0 +1,184 @@ +=== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2ES5.ts === +// ElementList: ( Modified ) +// Elisionopt AssignmentExpression +// Elisionopt SpreadElement +// ElementList, Elisionopt AssignmentExpression +// ElementList, Elisionopt SpreadElement + +// SpreadElement: +// ... AssignmentExpression + +var a0 = [,, 2, 3, 4] +>a0 : number[] +>[,, 2, 3, 4] : number[] + +var a1 = ["hello", "world"] +>a1 : string[] +>["hello", "world"] : string[] + +var a2 = [, , , ...a0, "hello"]; +>a2 : (string | number)[] +>[, , , ...a0, "hello"] : (string | number)[] +>...a0 : number +>a0 : number[] + +var a3 = [,, ...a0] +>a3 : number[] +>[,, ...a0] : number[] +>...a0 : number +>a0 : number[] + +var a4 = [() => 1, ]; +>a4 : (() => number)[] +>[() => 1, ] : (() => number)[] +>() => 1 : () => number + +var a5 = [...a0, , ] +>a5 : number[] +>[...a0, , ] : number[] +>...a0 : number +>a0 : number[] + +// Each element expression in a non-empty array literal is processed as follows: +// - If the array literal contains no spread elements, and if the array literal is contextually typed (section 4.19) +// by a type T and T has a property with the numeric name N, where N is the index of the element expression in the array literal, +// the element expression is contextually typed by the type of that property. + +// The resulting type an array literal expression is determined as follows: +// - If the array literal contains no spread elements and is contextually typed by a tuple-like type, +// the resulting type is a tuple type constructed from the types of the element expressions. + +var b0: [any, any, any] = [undefined, null, undefined]; +>b0 : [any, any, any] +>[undefined, null, undefined] : [undefined, null, undefined] +>undefined : undefined +>undefined : undefined + +var b1: [number[], string[]] = [[1, 2, 3], ["hello", "string"]]; +>b1 : [number[], string[]] +>[[1, 2, 3], ["hello", "string"]] : [number[], string[]] +>[1, 2, 3] : number[] +>["hello", "string"] : string[] + +// The resulting type an array literal expression is determined as follows: +// - If the array literal contains no spread elements and is an array assignment pattern in a destructuring assignment (section 4.17.1), +// the resulting type is a tuple type constructed from the types of the element expressions. + +var [c0, c1] = [1, 2]; // tuple type [number, number] +>c0 : number +>c1 : number +>[1, 2] : [number, number] + +var [c2, c3] = [1, 2, true]; // tuple type [number, number, boolean] +>c2 : number +>c3 : number +>[1, 2, true] : [number, number, boolean] + +// The resulting type an array literal expression is determined as follows: +// - the resulting type is an array type with an element type that is the union of the types of the +// non - spread element expressions and the numeric index signature types of the spread element expressions +var temp = ["s", "t", "r"]; +>temp : string[] +>["s", "t", "r"] : string[] + +var temp1 = [1, 2, 3]; +>temp1 : number[] +>[1, 2, 3] : number[] + +var temp2: [number[], string[]] = [[1, 2, 3], ["hello", "string"]]; +>temp2 : [number[], string[]] +>[[1, 2, 3], ["hello", "string"]] : [number[], string[]] +>[1, 2, 3] : number[] +>["hello", "string"] : string[] + +var temp3 = [undefined, null, undefined]; +>temp3 : any[] +>[undefined, null, undefined] : null[] +>undefined : undefined +>undefined : undefined + +var temp4 = []; +>temp4 : any[] +>[] : undefined[] + +interface myArray extends Array { } +>myArray : myArray +>Array : T[] +>Number : Number + +interface myArray2 extends Array { } +>myArray2 : myArray2 +>Array : T[] +>Number : Number +>String : String + +var d0 = [1, true, ...temp,]; // has type (string|number|boolean)[] +>d0 : (string | number | boolean)[] +>[1, true, ...temp,] : (string | number | boolean)[] +>...temp : string +>temp : string[] + +var d1 = [...temp]; // has type string[] +>d1 : string[] +>[...temp] : string[] +>...temp : string +>temp : string[] + +var d2: number[] = [...temp1]; +>d2 : number[] +>[...temp1] : number[] +>...temp1 : number +>temp1 : number[] + +var d3: myArray = [...temp1]; +>d3 : myArray +>myArray : myArray +>[...temp1] : number[] +>...temp1 : number +>temp1 : number[] + +var d4: myArray2 = [...temp, ...temp1]; +>d4 : myArray2 +>myArray2 : myArray2 +>[...temp, ...temp1] : (string | number)[] +>...temp : string +>temp : string[] +>...temp1 : number +>temp1 : number[] + +var d5 = [...temp3]; +>d5 : any[] +>[...temp3] : any[] +>...temp3 : any +>temp3 : any[] + +var d6 = [...temp4]; +>d6 : any[] +>[...temp4] : any[] +>...temp4 : any +>temp4 : any[] + +var d7 = [...[...temp1]]; +>d7 : number[] +>[...[...temp1]] : number[] +>...[...temp1] : number +>[...temp1] : number[] +>...temp1 : number +>temp1 : number[] + +var d8: number[][] = [[...temp1]] +>d8 : number[][] +>[[...temp1]] : number[][] +>[...temp1] : number[] +>...temp1 : number +>temp1 : number[] + +var d9 = [[...temp1], ...["hello"]]; +>d9 : (string | number[])[] +>[[...temp1], ...["hello"]] : (string | number[])[] +>[...temp1] : number[] +>...temp1 : number +>temp1 : number[] +>...["hello"] : string +>["hello"] : string[] + diff --git a/tests/baselines/reference/arrayLiterals2ES6.errors.txt b/tests/baselines/reference/arrayLiterals2ES6.errors.txt deleted file mode 100644 index bb3247ec453..00000000000 --- a/tests/baselines/reference/arrayLiterals2ES6.errors.txt +++ /dev/null @@ -1,60 +0,0 @@ -tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2ES6.ts(23,5): error TS2322: Type '(string[] | number[])[]' is not assignable to type 'tup'. - Property '0' is missing in type '(string[] | number[])[]'. -tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2ES6.ts(24,5): error TS2322: Type 'number[]' is not assignable to type '[number, number, number]'. - Property '0' is missing in type 'number[]'. -tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2ES6.ts(27,5): error TS2322: Type '(string | number)[]' is not assignable to type 'myArray'. - Types of property 'push' are incompatible. - Type '(...items: (string | number)[]) => number' is not assignable to type '(...items: Number[]) => number'. - Types of parameters 'items' and 'items' are incompatible. - Type 'string | number' is not assignable to type 'Number'. - Type 'string' is not assignable to type 'Number'. - Property 'toFixed' is missing in type 'String'. - - -==== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2ES6.ts (3 errors) ==== - var a = [2,3,4] - var a1 = ["hello", "world"] - var a2 = [undefined, null, undefined]; - var a3 = [] - var a4: number[] = [...a3]; - var a5: number[] = []; - - var b = [, , , ...a,"hello"]; - var c = [() => 1,]; - var d = [...c,,]; - var e = [,,...d]; - var g = [[1, 2, "hello"], ["string", true]]; - var h = [...g]; - var i: [number[], string[]] = [[1, 2, 3],["hello", "string"]]; - var j = [...i]; - var k:Array = [...i]; - interface tup { - 0: number[]|string[]; - 1: number[]|string[]; - } - interface myArray extends Array {} - interface myArray2 extends Array {} - var l: tup = [...i]; // error - ~ -!!! error TS2322: Type '(string[] | number[])[]' is not assignable to type 'tup'. -!!! error TS2322: Property '0' is missing in type '(string[] | number[])[]'. - var m: [number, number, number] = [...a]; // error - ~ -!!! error TS2322: Type 'number[]' is not assignable to type '[number, number, number]'. -!!! error TS2322: Property '0' is missing in type 'number[]'. - var n: number[] = [...a]; - var o: myArray = [...a]; - var p: myArray = [...a, ...a1]; // error - ~ -!!! error TS2322: Type '(string | number)[]' is not assignable to type 'myArray'. -!!! error TS2322: Types of property 'push' are incompatible. -!!! error TS2322: Type '(...items: (string | number)[]) => number' is not assignable to type '(...items: Number[]) => number'. -!!! error TS2322: Types of parameters 'items' and 'items' are incompatible. -!!! error TS2322: Type 'string | number' is not assignable to type 'Number'. -!!! error TS2322: Type 'string' is not assignable to type 'Number'. -!!! error TS2322: Property 'toFixed' is missing in type 'String'. - var q: myArray2 = [...a, ...a1]; - var r = [...a2]; - var r1 = [...a3]; - var r2 = [...a4]; - var r3:number[][] = [[...a4]]; \ No newline at end of file diff --git a/tests/baselines/reference/arrayLiterals2ES6.js b/tests/baselines/reference/arrayLiterals2ES6.js index 8cdecdd3be4..cb6bf2684e8 100644 --- a/tests/baselines/reference/arrayLiterals2ES6.js +++ b/tests/baselines/reference/arrayLiterals2ES6.js @@ -1,60 +1,100 @@ //// [arrayLiterals2ES6.ts] -var a = [2,3,4] -var a1 = ["hello", "world"] -var a2 = [undefined, null, undefined]; -var a3 = [] -var a4: number[] = [...a3]; -var a5: number[] = []; +// ElementList: ( Modified ) +// Elisionopt AssignmentExpression +// Elisionopt SpreadElement +// ElementList, Elisionopt AssignmentExpression +// ElementList, Elisionopt SpreadElement -var b = [, , , ...a,"hello"]; -var c = [() => 1,]; -var d = [...c,,]; -var e = [,,...d]; -var g = [[1, 2, "hello"], ["string", true]]; -var h = [...g]; -var i: [number[], string[]] = [[1, 2, 3],["hello", "string"]]; -var j = [...i]; -var k:Array = [...i]; -interface tup { - 0: number[]|string[]; - 1: number[]|string[]; -} -interface myArray extends Array {} -interface myArray2 extends Array {} -var l: tup = [...i]; // error -var m: [number, number, number] = [...a]; // error -var n: number[] = [...a]; -var o: myArray = [...a]; -var p: myArray = [...a, ...a1]; // error -var q: myArray2 = [...a, ...a1]; -var r = [...a2]; -var r1 = [...a3]; -var r2 = [...a4]; -var r3:number[][] = [[...a4]]; +// SpreadElement: +// ... AssignmentExpression + +var a0 = [, , 2, 3, 4] +var a1 = ["hello", "world"] +var a2 = [, , , ...a0, "hello"]; +var a3 = [, , ...a0] +var a4 = [() => 1, ]; +var a5 = [...a0, , ] + +// Each element expression in a non-empty array literal is processed as follows: +// - If the array literal contains no spread elements, and if the array literal is contextually typed (section 4.19) +// by a type T and T has a property with the numeric name N, where N is the index of the element expression in the array literal, +// the element expression is contextually typed by the type of that property. + +// The resulting type an array literal expression is determined as follows: +// - If the array literal contains no spread elements and is contextually typed by a tuple-like type, +// the resulting type is a tuple type constructed from the types of the element expressions. + +var b0: [any, any, any] = [undefined, null, undefined]; +var b1: [number[], string[]] = [[1, 2, 3], ["hello", "string"]]; + +// The resulting type an array literal expression is determined as follows: +// - If the array literal contains no spread elements and is an array assignment pattern in a destructuring assignment (section 4.17.1), +// the resulting type is a tuple type constructed from the types of the element expressions. + +var [c0, c1] = [1, 2]; // tuple type [number, number] +var [c2, c3] = [1, 2, true]; // tuple type [number, number, boolean] + +// The resulting type an array literal expression is determined as follows: +// - the resulting type is an array type with an element type that is the union of the types of the +// non - spread element expressions and the numeric index signature types of the spread element expressions +var temp = ["s", "t", "r"]; +var temp1 = [1, 2, 3]; +var temp2: [number[], string[]] = [[1, 2, 3], ["hello", "string"]]; + +interface myArray extends Array { } +interface myArray2 extends Array { } +var d0 = [1, true, ...temp, ]; // has type (string|number|boolean)[] +var d1 = [...temp]; // has type string[] +var d2: number[] = [...temp1]; +var d3: myArray = [...temp1]; +var d4: myArray2 = [...temp, ...temp1]; +var d5 = [...a2]; +var d6 = [...a3]; +var d7 = [...a4]; +var d8: number[][] = [[...temp1]] +var d9 = [[...temp1], ...["hello"]]; //// [arrayLiterals2ES6.js] -var a = [2, 3, 4]; +// ElementList: ( Modified ) +// Elisionopt AssignmentExpression +// Elisionopt SpreadElement +// ElementList, Elisionopt AssignmentExpression +// ElementList, Elisionopt SpreadElement +// SpreadElement: +// ... AssignmentExpression +var a0 = [, , 2, 3, 4]; var a1 = ["hello", "world"]; -var a2 = [undefined, null, undefined]; -var a3 = []; -var a4 = [...a3]; -var a5 = []; -var b = [, , , ...a, "hello"]; -var c = [() => 1,]; -var d = [...c, ,]; -var e = [, , ...d]; -var g = [[1, 2, "hello"], ["string", true]]; -var h = [...g]; -var i = [[1, 2, 3], ["hello", "string"]]; -var j = [...i]; -var k = [...i]; -var l = [...i]; // error -var m = [...a]; // error -var n = [...a]; -var o = [...a]; -var p = [...a, ...a1]; // error -var q = [...a, ...a1]; -var r = [...a2]; -var r1 = [...a3]; -var r2 = [...a4]; -var r3 = [[...a4]]; +var a2 = [, , , ...a0, "hello"]; +var a3 = [, , ...a0]; +var a4 = [() => 1,]; +var a5 = [...a0, ,]; +// Each element expression in a non-empty array literal is processed as follows: +// - If the array literal contains no spread elements, and if the array literal is contextually typed (section 4.19) +// by a type T and T has a property with the numeric name N, where N is the index of the element expression in the array literal, +// the element expression is contextually typed by the type of that property. +// The resulting type an array literal expression is determined as follows: +// - If the array literal contains no spread elements and is contextually typed by a tuple-like type, +// the resulting type is a tuple type constructed from the types of the element expressions. +var b0 = [undefined, null, undefined]; +var b1 = [[1, 2, 3], ["hello", "string"]]; +// The resulting type an array literal expression is determined as follows: +// - If the array literal contains no spread elements and is an array assignment pattern in a destructuring assignment (section 4.17.1), +// the resulting type is a tuple type constructed from the types of the element expressions. +var [c0, c1] = [1, 2]; // tuple type [number, number] +var [c2, c3] = [1, 2, true]; // tuple type [number, number, boolean] +// The resulting type an array literal expression is determined as follows: +// - the resulting type is an array type with an element type that is the union of the types of the +// non - spread element expressions and the numeric index signature types of the spread element expressions +var temp = ["s", "t", "r"]; +var temp1 = [1, 2, 3]; +var temp2 = [[1, 2, 3], ["hello", "string"]]; +var d0 = [1, true, ...temp,]; // has type (string|number|boolean)[] +var d1 = [...temp]; // has type string[] +var d2 = [...temp1]; +var d3 = [...temp1]; +var d4 = [...temp, ...temp1]; +var d5 = [...a2]; +var d6 = [...a3]; +var d7 = [...a4]; +var d8 = [[...temp1]]; +var d9 = [[...temp1], ...["hello"]]; diff --git a/tests/baselines/reference/arrayLiterals2ES6.types b/tests/baselines/reference/arrayLiterals2ES6.types new file mode 100644 index 00000000000..0ae1487d190 --- /dev/null +++ b/tests/baselines/reference/arrayLiterals2ES6.types @@ -0,0 +1,172 @@ +=== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2ES6.ts === +// ElementList: ( Modified ) +// Elisionopt AssignmentExpression +// Elisionopt SpreadElement +// ElementList, Elisionopt AssignmentExpression +// ElementList, Elisionopt SpreadElement + +// SpreadElement: +// ... AssignmentExpression + +var a0 = [, , 2, 3, 4] +>a0 : number[] +>[, , 2, 3, 4] : number[] + +var a1 = ["hello", "world"] +>a1 : string[] +>["hello", "world"] : string[] + +var a2 = [, , , ...a0, "hello"]; +>a2 : (string | number)[] +>[, , , ...a0, "hello"] : (string | number)[] +>...a0 : number +>a0 : number[] + +var a3 = [, , ...a0] +>a3 : number[] +>[, , ...a0] : number[] +>...a0 : number +>a0 : number[] + +var a4 = [() => 1, ]; +>a4 : (() => number)[] +>[() => 1, ] : (() => number)[] +>() => 1 : () => number + +var a5 = [...a0, , ] +>a5 : number[] +>[...a0, , ] : number[] +>...a0 : number +>a0 : number[] + +// Each element expression in a non-empty array literal is processed as follows: +// - If the array literal contains no spread elements, and if the array literal is contextually typed (section 4.19) +// by a type T and T has a property with the numeric name N, where N is the index of the element expression in the array literal, +// the element expression is contextually typed by the type of that property. + +// The resulting type an array literal expression is determined as follows: +// - If the array literal contains no spread elements and is contextually typed by a tuple-like type, +// the resulting type is a tuple type constructed from the types of the element expressions. + +var b0: [any, any, any] = [undefined, null, undefined]; +>b0 : [any, any, any] +>[undefined, null, undefined] : [undefined, null, undefined] +>undefined : undefined +>undefined : undefined + +var b1: [number[], string[]] = [[1, 2, 3], ["hello", "string"]]; +>b1 : [number[], string[]] +>[[1, 2, 3], ["hello", "string"]] : [number[], string[]] +>[1, 2, 3] : number[] +>["hello", "string"] : string[] + +// The resulting type an array literal expression is determined as follows: +// - If the array literal contains no spread elements and is an array assignment pattern in a destructuring assignment (section 4.17.1), +// the resulting type is a tuple type constructed from the types of the element expressions. + +var [c0, c1] = [1, 2]; // tuple type [number, number] +>c0 : number +>c1 : number +>[1, 2] : [number, number] + +var [c2, c3] = [1, 2, true]; // tuple type [number, number, boolean] +>c2 : number +>c3 : number +>[1, 2, true] : [number, number, boolean] + +// The resulting type an array literal expression is determined as follows: +// - the resulting type is an array type with an element type that is the union of the types of the +// non - spread element expressions and the numeric index signature types of the spread element expressions +var temp = ["s", "t", "r"]; +>temp : string[] +>["s", "t", "r"] : string[] + +var temp1 = [1, 2, 3]; +>temp1 : number[] +>[1, 2, 3] : number[] + +var temp2: [number[], string[]] = [[1, 2, 3], ["hello", "string"]]; +>temp2 : [number[], string[]] +>[[1, 2, 3], ["hello", "string"]] : [number[], string[]] +>[1, 2, 3] : number[] +>["hello", "string"] : string[] + +interface myArray extends Array { } +>myArray : myArray +>Array : T[] +>Number : Number + +interface myArray2 extends Array { } +>myArray2 : myArray2 +>Array : T[] +>Number : Number +>String : String + +var d0 = [1, true, ...temp, ]; // has type (string|number|boolean)[] +>d0 : (string | number | boolean)[] +>[1, true, ...temp, ] : (string | number | boolean)[] +>...temp : string +>temp : string[] + +var d1 = [...temp]; // has type string[] +>d1 : string[] +>[...temp] : string[] +>...temp : string +>temp : string[] + +var d2: number[] = [...temp1]; +>d2 : number[] +>[...temp1] : number[] +>...temp1 : number +>temp1 : number[] + +var d3: myArray = [...temp1]; +>d3 : myArray +>myArray : myArray +>[...temp1] : number[] +>...temp1 : number +>temp1 : number[] + +var d4: myArray2 = [...temp, ...temp1]; +>d4 : myArray2 +>myArray2 : myArray2 +>[...temp, ...temp1] : (string | number)[] +>...temp : string +>temp : string[] +>...temp1 : number +>temp1 : number[] + +var d5 = [...a2]; +>d5 : (string | number)[] +>[...a2] : (string | number)[] +>...a2 : string | number +>a2 : (string | number)[] + +var d6 = [...a3]; +>d6 : number[] +>[...a3] : number[] +>...a3 : number +>a3 : number[] + +var d7 = [...a4]; +>d7 : (() => number)[] +>[...a4] : (() => number)[] +>...a4 : () => number +>a4 : (() => number)[] + +var d8: number[][] = [[...temp1]] +>d8 : number[][] +>[[...temp1]] : number[][] +>[...temp1] : number[] +>...temp1 : number +>temp1 : number[] + +var d9 = [[...temp1], ...["hello"]]; +>d9 : (string | number[])[] +>[[...temp1], ...["hello"]] : (string | number[])[] +>[...temp1] : number[] +>...temp1 : number +>temp1 : number[] +>...["hello"] : string +>["hello"] : string[] + diff --git a/tests/baselines/reference/arrayLiterals3.errors.txt b/tests/baselines/reference/arrayLiterals3.errors.txt index 35bedb54854..74cfdb165d7 100644 --- a/tests/baselines/reference/arrayLiterals3.errors.txt +++ b/tests/baselines/reference/arrayLiterals3.errors.txt @@ -1,62 +1,86 @@ -tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(8,5): error TS2322: Type '[number, number, string, boolean]' is not assignable to type '[number, number]'. +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(10,5): error TS2322: Type 'undefined[]' is not assignable to type '[any, any, any]'. + Property '0' is missing in type 'undefined[]'. +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(11,5): error TS2322: Type '[string, number, boolean]' is not assignable to type '[boolean, string, number]'. + Types of property '0' are incompatible. + Type 'string' is not assignable to type 'boolean'. +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(17,5): error TS2322: Type '[number, number, string, boolean]' is not assignable to type '[number, number]'. Types of property 'pop' are incompatible. Type '() => string | number | boolean' is not assignable to type '() => number'. Type 'string | number | boolean' is not assignable to type 'number'. Type 'string' is not assignable to type 'number'. -tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(35,6): error TS2461: Type 'string | number[]' is not an array type. -tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(40,16): error TS2461: Type 'IArguments' is not an array type. +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(32,5): error TS2322: Type '(string[] | number[])[]' is not assignable to type 'tup'. + Property '0' is missing in type '(string[] | number[])[]'. +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(33,5): error TS2322: Type 'number[]' is not assignable to type '[number, number, number]'. + Property '0' is missing in type 'number[]'. +tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts(34,5): error TS2322: Type '(string | number)[]' is not assignable to type 'myArray'. + Types of property 'push' are incompatible. + Type '(...items: (string | number)[]) => number' is not assignable to type '(...items: Number[]) => number'. + Types of parameters 'items' and 'items' are incompatible. + Type 'string | number' is not assignable to type 'Number'. + Type 'string' is not assignable to type 'Number'. + Property 'toFixed' is missing in type 'String'. -==== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts (3 errors) ==== - interface I0 extends Array { - 0: number; - 1: number; - 2: string; - 3: boolean; - } - var [a, b]: [number, number] = [1, 2]; - var [a1, b1]: [number, number] = [1, 2, "string", true]; // error +==== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts (6 errors) ==== + // Each element expression in a non-empty array literal is processed as follows: + // - If the array literal contains no spread elements, and if the array literal is contextually typed (section 4.19) + // by a type T and T has a property with the numeric name N, where N is the index of the element expression in the array literal, + // the element expression is contextually typed by the type of that property. + + // The resulting type an array literal expression is determined as follows: + // - If the array literal contains no spread elements and is contextually typed by a tuple-like type, + // the resulting type is a tuple type constructed from the types of the element expressions. + + var a0: [any, any, any] = []; // Error + ~~ +!!! error TS2322: Type 'undefined[]' is not assignable to type '[any, any, any]'. +!!! error TS2322: Property '0' is missing in type 'undefined[]'. + var a1: [boolean, string, number] = ["string", 1, true]; // Error + ~~ +!!! error TS2322: Type '[string, number, boolean]' is not assignable to type '[boolean, string, number]'. +!!! error TS2322: Types of property '0' are incompatible. +!!! error TS2322: Type 'string' is not assignable to type 'boolean'. + + // The resulting type an array literal expression is determined as follows: + // - If the array literal contains no spread elements and is an array assignment pattern in a destructuring assignment (section 4.17.1), + // the resulting type is a tuple type constructed from the types of the element expressions. + + var [b1, b2]: [number, number] = [1, 2, "string", true]; ~~~~~~~~ !!! error TS2322: Type '[number, number, string, boolean]' is not assignable to type '[number, number]'. !!! error TS2322: Types of property 'pop' are incompatible. !!! error TS2322: Type '() => string | number | boolean' is not assignable to type '() => number'. !!! error TS2322: Type 'string | number | boolean' is not assignable to type 'number'. !!! error TS2322: Type 'string' is not assignable to type 'number'. - var [a2, b2]: (number| string)[] = [1, 2, 3, "string"]; - var [c1, c2, c3]: I0 = [10, 11, "string", true]; - interface I extends Array{ - 0: string|number; - 1: string|number; - 2: string|number; - } - interface I2 extends Array { - 0: number; - 1: number; - 2: string|number; - } - var tup: [number, number, string] = [1, 2, "world"]; - var [c, d, e]: I = tup; - var [f, g]: I2 = tup; - var h1: string| number; - var [f1, g1,h1]: I2 = tup; - h1 = g1; - var arr1 = [1, 2, 3]; - var arr2 = [true, false, true]; - var arr3 = [true] - var [[foo1, foo2, foo3], [boo1, boo2, boo3]] = [[...arr1], [...arr2]]; - var [bar1, bar2, bar3, bar1, bar2, bar3] = [...arr1, ...arr2]; - var [bar1, bar2, bar3, bar1, bar2] = [...arr1, ...arr3]; - var [[r, s], t] = [[...arr1], "hello"]; - var [[r1, s1], t1] = [[...arr1], ...["hello"]]; // error - ~~~~~~~~ -!!! error TS2461: Type 'string | number[]' is not an array type. - var [x] = [...["word"]]; - var [...y] = [...["word"]]; - var z = [...[...["word"]]]; - function foobar() { - return [...arguments]; - ~~~~~~~~~ -!!! error TS2461: Type 'IArguments' is not an array type. + // The resulting type an array literal expression is determined as follows: + // - the resulting type is an array type with an element type that is the union of the types of the + // non - spread element expressions and the numeric index signature types of the spread element expressions + var temp = ["s", "t", "r"]; + var temp1 = [1, 2, 3]; + var temp2: [number[], string[]] = [[1, 2, 3], ["hello", "string"]]; + + interface tup { + 0: number[]|string[]; + 1: number[]|string[]; } - var [...as] = [[, , , , ]]; \ No newline at end of file + interface myArray extends Array { } + interface myArray2 extends Array { } + var c0: tup = [...temp2]; // Error + ~~ +!!! error TS2322: Type '(string[] | number[])[]' is not assignable to type 'tup'. +!!! error TS2322: Property '0' is missing in type '(string[] | number[])[]'. + var c1: [number, number, number] = [...temp1]; // Error cannot assign number[] to [number, number, number] + ~~ +!!! error TS2322: Type 'number[]' is not assignable to type '[number, number, number]'. +!!! error TS2322: Property '0' is missing in type 'number[]'. + var c2: myArray = [...temp1, ...temp]; // Error cannot assign (number|string)[] to number[] + ~~ +!!! error TS2322: Type '(string | number)[]' is not assignable to type 'myArray'. +!!! error TS2322: Types of property 'push' are incompatible. +!!! error TS2322: Type '(...items: (string | number)[]) => number' is not assignable to type '(...items: Number[]) => number'. +!!! error TS2322: Types of parameters 'items' and 'items' are incompatible. +!!! error TS2322: Type 'string | number' is not assignable to type 'Number'. +!!! error TS2322: Type 'string' is not assignable to type 'Number'. +!!! error TS2322: Property 'toFixed' is missing in type 'String'. + \ No newline at end of file diff --git a/tests/baselines/reference/arrayLiterals3.js b/tests/baselines/reference/arrayLiterals3.js index 6ad064e20da..091c6148068 100644 --- a/tests/baselines/reference/arrayLiterals3.js +++ b/tests/baselines/reference/arrayLiterals3.js @@ -1,70 +1,60 @@ //// [arrayLiterals3.ts] -interface I0 extends Array { - 0: number; - 1: number; - 2: string; - 3: boolean; -} -var [a, b]: [number, number] = [1, 2]; -var [a1, b1]: [number, number] = [1, 2, "string", true]; // error -var [a2, b2]: (number| string)[] = [1, 2, 3, "string"]; -var [c1, c2, c3]: I0 = [10, 11, "string", true]; -interface I extends Array{ - 0: string|number; - 1: string|number; - 2: string|number; -} -interface I2 extends Array { - 0: number; - 1: number; - 2: string|number; -} -var tup: [number, number, string] = [1, 2, "world"]; -var [c, d, e]: I = tup; -var [f, g]: I2 = tup; -var h1: string| number; -var [f1, g1,h1]: I2 = tup; -h1 = g1; +// Each element expression in a non-empty array literal is processed as follows: +// - If the array literal contains no spread elements, and if the array literal is contextually typed (section 4.19) +// by a type T and T has a property with the numeric name N, where N is the index of the element expression in the array literal, +// the element expression is contextually typed by the type of that property. -var arr1 = [1, 2, 3]; -var arr2 = [true, false, true]; -var arr3 = [true] -var [[foo1, foo2, foo3], [boo1, boo2, boo3]] = [[...arr1], [...arr2]]; -var [bar1, bar2, bar3, bar1, bar2, bar3] = [...arr1, ...arr2]; -var [bar1, bar2, bar3, bar1, bar2] = [...arr1, ...arr3]; -var [[r, s], t] = [[...arr1], "hello"]; -var [[r1, s1], t1] = [[...arr1], ...["hello"]]; // error -var [x] = [...["word"]]; -var [...y] = [...["word"]]; -var z = [...[...["word"]]]; -function foobar() { - return [...arguments]; +// The resulting type an array literal expression is determined as follows: +// - If the array literal contains no spread elements and is contextually typed by a tuple-like type, +// the resulting type is a tuple type constructed from the types of the element expressions. + +var a0: [any, any, any] = []; // Error +var a1: [boolean, string, number] = ["string", 1, true]; // Error + +// The resulting type an array literal expression is determined as follows: +// - If the array literal contains no spread elements and is an array assignment pattern in a destructuring assignment (section 4.17.1), +// the resulting type is a tuple type constructed from the types of the element expressions. + +var [b1, b2]: [number, number] = [1, 2, "string", true]; + +// The resulting type an array literal expression is determined as follows: +// - the resulting type is an array type with an element type that is the union of the types of the +// non - spread element expressions and the numeric index signature types of the spread element expressions +var temp = ["s", "t", "r"]; +var temp1 = [1, 2, 3]; +var temp2: [number[], string[]] = [[1, 2, 3], ["hello", "string"]]; + +interface tup { + 0: number[]|string[]; + 1: number[]|string[]; } -var [...as] = [[, , , , ]]; +interface myArray extends Array { } +interface myArray2 extends Array { } +var c0: tup = [...temp2]; // Error +var c1: [number, number, number] = [...temp1]; // Error cannot assign number[] to [number, number, number] +var c2: myArray = [...temp1, ...temp]; // Error cannot assign (number|string)[] to number[] + //// [arrayLiterals3.js] -var _a = [1, 2], a = _a[0], b = _a[1]; -var _b = [1, 2, "string", true], a1 = _b[0], b1 = _b[1]; // error -var _c = [1, 2, 3, "string"], a2 = _c[0], b2 = _c[1]; -var _d = [10, 11, "string", true], c1 = _d[0], c2 = _d[1], c3 = _d[2]; -var tup = [1, 2, "world"]; -var c = tup[0], d = tup[1], e = tup[2]; -var f = tup[0], g = tup[1]; -var h1; -var f1 = tup[0], g1 = tup[1], h1 = tup[2]; -h1 = g1; -var arr1 = [1, 2, 3]; -var arr2 = [true, false, true]; -var arr3 = [true]; -var _e = [arr1, arr2], _f = _e[0], foo1 = _f[0], foo2 = _f[1], foo3 = _f[2], _g = _e[1], boo1 = _g[0], boo2 = _g[1], boo3 = _g[2]; -var _h = arr1.concat(arr2), bar1 = _h[0], bar2 = _h[1], bar3 = _h[2], bar1 = _h[3], bar2 = _h[4], bar3 = _h[5]; -var _j = arr1.concat(arr3), bar1 = _j[0], bar2 = _j[1], bar3 = _j[2], bar1 = _j[3], bar2 = _j[4]; -var _k = [arr1, "hello"], _l = _k[0], r = _l[0], s = _l[1], t = _k[1]; -var _m = [arr1].concat(["hello"]), _o = _m[0], r1 = _o[0], s1 = _o[1], t1 = _m[1]; // error -var x = (["word"])[0]; -var _p = ["word"], y = _p.slice(0); -var z = ["word"]; -function foobar() { - return arguments; -} -var _q = [[, , , ,]], as = _q.slice(0); +// Each element expression in a non-empty array literal is processed as follows: +// - If the array literal contains no spread elements, and if the array literal is contextually typed (section 4.19) +// by a type T and T has a property with the numeric name N, where N is the index of the element expression in the array literal, +// the element expression is contextually typed by the type of that property. +// The resulting type an array literal expression is determined as follows: +// - If the array literal contains no spread elements and is contextually typed by a tuple-like type, +// the resulting type is a tuple type constructed from the types of the element expressions. +var a0 = []; // Error +var a1 = ["string", 1, true]; // Error +// The resulting type an array literal expression is determined as follows: +// - If the array literal contains no spread elements and is an array assignment pattern in a destructuring assignment (section 4.17.1), +// the resulting type is a tuple type constructed from the types of the element expressions. +var _a = [1, 2, "string", true], b1 = _a[0], b2 = _a[1]; +// The resulting type an array literal expression is determined as follows: +// - the resulting type is an array type with an element type that is the union of the types of the +// non - spread element expressions and the numeric index signature types of the spread element expressions +var temp = ["s", "t", "r"]; +var temp1 = [1, 2, 3]; +var temp2 = [[1, 2, 3], ["hello", "string"]]; +var c0 = temp2; // Error +var c1 = temp1; // Error cannot assign number[] to [number, number, number] +var c2 = temp1.concat(temp); // Error cannot assign (number|string)[] to number[] diff --git a/tests/baselines/reference/arrayLiterals3ES6.errors.txt b/tests/baselines/reference/arrayLiterals3ES6.errors.txt deleted file mode 100644 index 1490a0fbcfa..00000000000 --- a/tests/baselines/reference/arrayLiterals3ES6.errors.txt +++ /dev/null @@ -1,52 +0,0 @@ -tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3ES6.ts(8,5): error TS2322: Type '[number, number, string, boolean]' is not assignable to type '[number, number]'. - Types of property 'pop' are incompatible. - Type '() => string | number | boolean' is not assignable to type '() => number'. - Type 'string | number | boolean' is not assignable to type 'number'. - Type 'string' is not assignable to type 'number'. - - -==== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3ES6.ts (1 errors) ==== - interface I0 extends Array { - 0: number; - 1: number; - 2: string; - 3: boolean; - } - var [a, b]: [number, number] = [1, 2]; - var [a1, b1]: [number, number] = [1, 2, "string", true]; // error - ~~~~~~~~ -!!! error TS2322: Type '[number, number, string, boolean]' is not assignable to type '[number, number]'. -!!! error TS2322: Types of property 'pop' are incompatible. -!!! error TS2322: Type '() => string | number | boolean' is not assignable to type '() => number'. -!!! error TS2322: Type 'string | number | boolean' is not assignable to type 'number'. -!!! error TS2322: Type 'string' is not assignable to type 'number'. - var [a2, b2]: (number| string)[] = [1, 2, 3, "string"]; - var [c1, c2, c3]: I0 = [10, 11, "string", true]; - interface I extends Array{ - 0: string|number; - 1: string|number; - 2: string|number; - } - interface I2 extends Array { - 0: number; - 1: number; - 2: string|number; - } - var tup: [number, number, string] = [1, 2, "world"]; - var [c, d, e]: I = tup; - var [f, g]: I2 = tup; - var h1: string| number; - var [f1, g1,h1]: I2 = tup; - h1 = g1; - - var arr1 = [1, 2, 3]; - var arr2 = [true, false, true]; - var arr3 = [true] - var [[foo1, foo2, foo3], [boo1, boo2, boo3]] = [[...arr1], [...arr2]]; - var [bar1, bar2, bar3, bar1, bar2, bar3] = [...arr1, ...arr2]; - var [bar1, bar2, bar3, bar1, bar2] = [...arr1, ...arr3]; - var [[r, s], t] = [[...arr1], "hello"]; - var [[r1, s1], t1] = [[...arr1], ...["hello"]]; // error - var [x] = [...["word"]]; - var [...y] = [...["word"]]; - var z = [...[...["word"]]]; \ No newline at end of file diff --git a/tests/baselines/reference/arrayLiterals3ES6.js b/tests/baselines/reference/arrayLiterals3ES6.js deleted file mode 100644 index f685ea9c719..00000000000 --- a/tests/baselines/reference/arrayLiterals3ES6.js +++ /dev/null @@ -1,62 +0,0 @@ -//// [arrayLiterals3ES6.ts] -interface I0 extends Array { - 0: number; - 1: number; - 2: string; - 3: boolean; -} -var [a, b]: [number, number] = [1, 2]; -var [a1, b1]: [number, number] = [1, 2, "string", true]; // error -var [a2, b2]: (number| string)[] = [1, 2, 3, "string"]; -var [c1, c2, c3]: I0 = [10, 11, "string", true]; -interface I extends Array{ - 0: string|number; - 1: string|number; - 2: string|number; -} -interface I2 extends Array { - 0: number; - 1: number; - 2: string|number; -} -var tup: [number, number, string] = [1, 2, "world"]; -var [c, d, e]: I = tup; -var [f, g]: I2 = tup; -var h1: string| number; -var [f1, g1,h1]: I2 = tup; -h1 = g1; - -var arr1 = [1, 2, 3]; -var arr2 = [true, false, true]; -var arr3 = [true] -var [[foo1, foo2, foo3], [boo1, boo2, boo3]] = [[...arr1], [...arr2]]; -var [bar1, bar2, bar3, bar1, bar2, bar3] = [...arr1, ...arr2]; -var [bar1, bar2, bar3, bar1, bar2] = [...arr1, ...arr3]; -var [[r, s], t] = [[...arr1], "hello"]; -var [[r1, s1], t1] = [[...arr1], ...["hello"]]; // error -var [x] = [...["word"]]; -var [...y] = [...["word"]]; -var z = [...[...["word"]]]; - -//// [arrayLiterals3ES6.js] -var [a, b] = [1, 2]; -var [a1, b1] = [1, 2, "string", true]; // error -var [a2, b2] = [1, 2, 3, "string"]; -var [c1, c2, c3] = [10, 11, "string", true]; -var tup = [1, 2, "world"]; -var [c, d, e] = tup; -var [f, g] = tup; -var h1; -var [f1, g1, h1] = tup; -h1 = g1; -var arr1 = [1, 2, 3]; -var arr2 = [true, false, true]; -var arr3 = [true]; -var [[foo1, foo2, foo3], [boo1, boo2, boo3]] = [[...arr1], [...arr2]]; -var [bar1, bar2, bar3, bar1, bar2, bar3] = [...arr1, ...arr2]; -var [bar1, bar2, bar3, bar1, bar2] = [...arr1, ...arr3]; -var [[r, s], t] = [[...arr1], "hello"]; -var [[r1, s1], t1] = [[...arr1], ...["hello"]]; // error -var [x] = [...["word"]]; -var [...y] = [...["word"]]; -var z = [...[...["word"]]]; diff --git a/tests/baselines/reference/arrayLiterals4.errors.txt b/tests/baselines/reference/arrayLiterals4.errors.txt deleted file mode 100644 index 5fc0fe2c51e..00000000000 --- a/tests/baselines/reference/arrayLiterals4.errors.txt +++ /dev/null @@ -1,31 +0,0 @@ -tests/cases/conformance/expressions/arrayLiterals/arrayLiterals4.ts(2,6): error TS1212: Identifier expected. 'public' is a reserved word in strict mode -tests/cases/conformance/expressions/arrayLiterals/arrayLiterals4.ts(2,14): error TS1212: Identifier expected. 'static' is a reserved word in strict mode -tests/cases/conformance/expressions/arrayLiterals/arrayLiterals4.ts(3,5): error TS1212: Identifier expected. 'protected' is a reserved word in strict mode -tests/cases/conformance/expressions/arrayLiterals/arrayLiterals4.ts(4,21): error TS1212: Identifier expected. 'protected' is a reserved word in strict mode -tests/cases/conformance/expressions/arrayLiterals/arrayLiterals4.ts(5,7): error TS1212: Identifier expected. 'public' is a reserved word in strict mode -tests/cases/conformance/expressions/arrayLiterals/arrayLiterals4.ts(5,15): error TS1212: Identifier expected. 'package' is a reserved word in strict mode -tests/cases/conformance/expressions/arrayLiterals/arrayLiterals4.ts(6,9): error TS1212: Identifier expected. 'implements' is a reserved word in strict mode - - -==== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals4.ts (7 errors) ==== - "use strict" - var [public, static] = [1, 23, ]; - ~~~~~~ -!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode - ~~~~~~ -!!! error TS1212: Identifier expected. 'static' is a reserved word in strict mode - var protected = [1, 2, 3]; - ~~~~~~~~~ -!!! error TS1212: Identifier expected. 'protected' is a reserved word in strict mode - var [a, b, c] = [...protected]; - ~~~~~~~~~ -!!! error TS1212: Identifier expected. 'protected' is a reserved word in strict mode - var [[public, package]] = [[1, [2, 3]]]; - ~~~~~~ -!!! error TS1212: Identifier expected. 'public' is a reserved word in strict mode - ~~~~~~~ -!!! error TS1212: Identifier expected. 'package' is a reserved word in strict mode - var [...implements] = [[]]; - ~~~~~~~~~~ -!!! error TS1212: Identifier expected. 'implements' is a reserved word in strict mode - \ No newline at end of file diff --git a/tests/baselines/reference/arrayLiterals4.js b/tests/baselines/reference/arrayLiterals4.js deleted file mode 100644 index 28c7fb10306..00000000000 --- a/tests/baselines/reference/arrayLiterals4.js +++ /dev/null @@ -1,16 +0,0 @@ -//// [arrayLiterals4.ts] -"use strict" -var [public, static] = [1, 23, ]; -var protected = [1, 2, 3]; -var [a, b, c] = [...protected]; -var [[public, package]] = [[1, [2, 3]]]; -var [...implements] = [[]]; - - -//// [arrayLiterals4.js] -"use strict"; -var _a = [1, 23,], public = _a[0], static = _a[1]; -var protected = [1, 2, 3]; -var _b = protected, a = _b[0], b = _b[1], c = _b[2]; -var _c = ([[1, [2, 3]]])[0], public = _c[0], package = _c[1]; -var _d = [[]], implements = _d.slice(0); diff --git a/tests/baselines/reference/arrayLiterals5.errors.txt b/tests/baselines/reference/arrayLiterals5.errors.txt deleted file mode 100644 index ee928841b6a..00000000000 --- a/tests/baselines/reference/arrayLiterals5.errors.txt +++ /dev/null @@ -1,46 +0,0 @@ -tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts(1,6): error TS1181: Array element destructuring pattern expected. -tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts(1,11): error TS1005: '(' expected. -tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts(1,13): error TS1109: Expression expected. -tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts(1,16): error TS1005: '(' expected. -tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts(1,18): error TS1128: Declaration or statement expected. -tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts(2,6): error TS1181: Array element destructuring pattern expected. -tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts(2,9): error TS1005: '(' expected. -tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts(2,11): error TS2304: Cannot find name 'as'. -tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts(2,13): error TS1005: ';' expected. -tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts(2,15): error TS1128: Declaration or statement expected. -tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts(3,9): error TS1003: Identifier expected. -tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts(3,14): error TS1003: Identifier expected. -tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts(3,16): error TS1128: Declaration or statement expected. - - -==== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts (13 errors) ==== - var [while, for] = [1, 3, ]; - ~~~~~ -!!! error TS1181: Array element destructuring pattern expected. - ~ -!!! error TS1005: '(' expected. - ~~~ -!!! error TS1109: Expression expected. - ~ -!!! error TS1005: '(' expected. - ~ -!!! error TS1128: Declaration or statement expected. - var [for, as] = [, , , , ]; - ~~~ -!!! error TS1181: Array element destructuring pattern expected. - ~ -!!! error TS1005: '(' expected. - ~~ -!!! error TS2304: Cannot find name 'as'. - ~ -!!! error TS1005: ';' expected. - ~ -!!! error TS1128: Declaration or statement expected. - var [...break] = [...["hello"]]; - ~~~~~ -!!! error TS1003: Identifier expected. - ~ -!!! error TS1003: Identifier expected. - ~ -!!! error TS1128: Declaration or statement expected. - \ No newline at end of file diff --git a/tests/baselines/reference/arrayLiterals5.js b/tests/baselines/reference/arrayLiterals5.js deleted file mode 100644 index faf4bb6fa70..00000000000 --- a/tests/baselines/reference/arrayLiterals5.js +++ /dev/null @@ -1,19 +0,0 @@ -//// [arrayLiterals5.ts] -var [while, for] = [1, 3, ]; -var [for, as] = [, , , , ]; -var [...break] = [...["hello"]]; - - -//// [arrayLiterals5.js] -var _a = void 0; -while (, ) - for (; ; ) - ; -[1, 3,]; -var _b = void 0; -for (, as; ; ) - ; -[, , , ,]; -var _c = void 0, = _c.slice(0); -break ; -["hello"]; diff --git a/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2.ts b/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2.ts deleted file mode 100644 index 6b6807e1d33..00000000000 --- a/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2.ts +++ /dev/null @@ -1,32 +0,0 @@ -var a = [2,3,4] -var a1 = ["hello", "world"] -var a2 = [undefined, null, undefined]; -var a3 = [] -var a4: number[] = [...a3]; -var a5: number[] = []; - -var b = [, , , ...a,"hello"]; -var c = [() => 1,]; -var d = [...c,,]; -var e = [,,...d]; -var g = [[1, 2, "hello"], ["string", true]]; -var h = [...g]; -var i: [number[], string[]] = [[1, 2, 3],["hello", "string"]]; -var j = [...i]; -var k:Array = [...i]; -interface tup { - 0: number[]|string[]; - 1: number[]|string[]; -} -interface myArray extends Array {} -interface myArray2 extends Array {} -var l: tup = [...i]; // error -var m: [number, number, number] = [...a]; // error -var n: number[] = [...a]; -var o: myArray = [...a]; -var p: myArray = [...a, ...a1]; // error -var q: myArray2 = [...a, ...a1]; -var r = [...a2]; -var r1 = [...a3]; -var r2 = [...a4]; -var r3:number[][] = [[...a4]]; \ No newline at end of file diff --git a/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2ES5.ts b/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2ES5.ts new file mode 100644 index 00000000000..34c77288f3f --- /dev/null +++ b/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2ES5.ts @@ -0,0 +1,56 @@ +// ElementList: ( Modified ) +// Elisionopt AssignmentExpression +// Elisionopt SpreadElement +// ElementList, Elisionopt AssignmentExpression +// ElementList, Elisionopt SpreadElement + +// SpreadElement: +// ... AssignmentExpression + +var a0 = [,, 2, 3, 4] +var a1 = ["hello", "world"] +var a2 = [, , , ...a0, "hello"]; +var a3 = [,, ...a0] +var a4 = [() => 1, ]; +var a5 = [...a0, , ] + +// Each element expression in a non-empty array literal is processed as follows: +// - If the array literal contains no spread elements, and if the array literal is contextually typed (section 4.19) +// by a type T and T has a property with the numeric name N, where N is the index of the element expression in the array literal, +// the element expression is contextually typed by the type of that property. + +// The resulting type an array literal expression is determined as follows: +// - If the array literal contains no spread elements and is contextually typed by a tuple-like type, +// the resulting type is a tuple type constructed from the types of the element expressions. + +var b0: [any, any, any] = [undefined, null, undefined]; +var b1: [number[], string[]] = [[1, 2, 3], ["hello", "string"]]; + +// The resulting type an array literal expression is determined as follows: +// - If the array literal contains no spread elements and is an array assignment pattern in a destructuring assignment (section 4.17.1), +// the resulting type is a tuple type constructed from the types of the element expressions. + +var [c0, c1] = [1, 2]; // tuple type [number, number] +var [c2, c3] = [1, 2, true]; // tuple type [number, number, boolean] + +// The resulting type an array literal expression is determined as follows: +// - the resulting type is an array type with an element type that is the union of the types of the +// non - spread element expressions and the numeric index signature types of the spread element expressions +var temp = ["s", "t", "r"]; +var temp1 = [1, 2, 3]; +var temp2: [number[], string[]] = [[1, 2, 3], ["hello", "string"]]; +var temp3 = [undefined, null, undefined]; +var temp4 = []; + +interface myArray extends Array { } +interface myArray2 extends Array { } +var d0 = [1, true, ...temp,]; // has type (string|number|boolean)[] +var d1 = [...temp]; // has type string[] +var d2: number[] = [...temp1]; +var d3: myArray = [...temp1]; +var d4: myArray2 = [...temp, ...temp1]; +var d5 = [...temp3]; +var d6 = [...temp4]; +var d7 = [...[...temp1]]; +var d8: number[][] = [[...temp1]] +var d9 = [[...temp1], ...["hello"]]; \ No newline at end of file diff --git a/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2ES6.ts b/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2ES6.ts index 5a32af531e1..1a4e11e31eb 100644 --- a/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2ES6.ts +++ b/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2ES6.ts @@ -1,33 +1,55 @@ // @target:es6 -var a = [2,3,4] -var a1 = ["hello", "world"] -var a2 = [undefined, null, undefined]; -var a3 = [] -var a4: number[] = [...a3]; -var a5: number[] = []; +// ElementList: ( Modified ) +// Elisionopt AssignmentExpression +// Elisionopt SpreadElement +// ElementList, Elisionopt AssignmentExpression +// ElementList, Elisionopt SpreadElement -var b = [, , , ...a,"hello"]; -var c = [() => 1,]; -var d = [...c,,]; -var e = [,,...d]; -var g = [[1, 2, "hello"], ["string", true]]; -var h = [...g]; -var i: [number[], string[]] = [[1, 2, 3],["hello", "string"]]; -var j = [...i]; -var k:Array = [...i]; -interface tup { - 0: number[]|string[]; - 1: number[]|string[]; -} -interface myArray extends Array {} -interface myArray2 extends Array {} -var l: tup = [...i]; // error -var m: [number, number, number] = [...a]; // error -var n: number[] = [...a]; -var o: myArray = [...a]; -var p: myArray = [...a, ...a1]; // error -var q: myArray2 = [...a, ...a1]; -var r = [...a2]; -var r1 = [...a3]; -var r2 = [...a4]; -var r3:number[][] = [[...a4]]; \ No newline at end of file +// SpreadElement: +// ... AssignmentExpression + +var a0 = [, , 2, 3, 4] +var a1 = ["hello", "world"] +var a2 = [, , , ...a0, "hello"]; +var a3 = [, , ...a0] +var a4 = [() => 1, ]; +var a5 = [...a0, , ] + +// Each element expression in a non-empty array literal is processed as follows: +// - If the array literal contains no spread elements, and if the array literal is contextually typed (section 4.19) +// by a type T and T has a property with the numeric name N, where N is the index of the element expression in the array literal, +// the element expression is contextually typed by the type of that property. + +// The resulting type an array literal expression is determined as follows: +// - If the array literal contains no spread elements and is contextually typed by a tuple-like type, +// the resulting type is a tuple type constructed from the types of the element expressions. + +var b0: [any, any, any] = [undefined, null, undefined]; +var b1: [number[], string[]] = [[1, 2, 3], ["hello", "string"]]; + +// The resulting type an array literal expression is determined as follows: +// - If the array literal contains no spread elements and is an array assignment pattern in a destructuring assignment (section 4.17.1), +// the resulting type is a tuple type constructed from the types of the element expressions. + +var [c0, c1] = [1, 2]; // tuple type [number, number] +var [c2, c3] = [1, 2, true]; // tuple type [number, number, boolean] + +// The resulting type an array literal expression is determined as follows: +// - the resulting type is an array type with an element type that is the union of the types of the +// non - spread element expressions and the numeric index signature types of the spread element expressions +var temp = ["s", "t", "r"]; +var temp1 = [1, 2, 3]; +var temp2: [number[], string[]] = [[1, 2, 3], ["hello", "string"]]; + +interface myArray extends Array { } +interface myArray2 extends Array { } +var d0 = [1, true, ...temp, ]; // has type (string|number|boolean)[] +var d1 = [...temp]; // has type string[] +var d2: number[] = [...temp1]; +var d3: myArray = [...temp1]; +var d4: myArray2 = [...temp, ...temp1]; +var d5 = [...a2]; +var d6 = [...a3]; +var d7 = [...a4]; +var d8: number[][] = [[...temp1]] +var d9 = [[...temp1], ...["hello"]]; \ No newline at end of file diff --git a/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts b/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts index 1a173d59d92..fd07347f503 100644 --- a/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts +++ b/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3.ts @@ -1,42 +1,34 @@ -interface I0 extends Array { - 0: number; - 1: number; - 2: string; - 3: boolean; -} -var [a, b]: [number, number] = [1, 2]; -var [a1, b1]: [number, number] = [1, 2, "string", true]; // error -var [a2, b2]: (number| string)[] = [1, 2, 3, "string"]; -var [c1, c2, c3]: I0 = [10, 11, "string", true]; -interface I extends Array{ - 0: string|number; - 1: string|number; - 2: string|number; -} -interface I2 extends Array { - 0: number; - 1: number; - 2: string|number; -} -var tup: [number, number, string] = [1, 2, "world"]; -var [c, d, e]: I = tup; -var [f, g]: I2 = tup; -var h1: string| number; -var [f1, g1,h1]: I2 = tup; -h1 = g1; +// Each element expression in a non-empty array literal is processed as follows: +// - If the array literal contains no spread elements, and if the array literal is contextually typed (section 4.19) +// by a type T and T has a property with the numeric name N, where N is the index of the element expression in the array literal, +// the element expression is contextually typed by the type of that property. -var arr1 = [1, 2, 3]; -var arr2 = [true, false, true]; -var arr3 = [true] -var [[foo1, foo2, foo3], [boo1, boo2, boo3]] = [[...arr1], [...arr2]]; -var [bar1, bar2, bar3, bar1, bar2, bar3] = [...arr1, ...arr2]; -var [bar1, bar2, bar3, bar1, bar2] = [...arr1, ...arr3]; -var [[r, s], t] = [[...arr1], "hello"]; -var [[r1, s1], t1] = [[...arr1], ...["hello"]]; // error -var [x] = [...["word"]]; -var [...y] = [...["word"]]; -var z = [...[...["word"]]]; -function foobar() { - return [...arguments]; +// The resulting type an array literal expression is determined as follows: +// - If the array literal contains no spread elements and is contextually typed by a tuple-like type, +// the resulting type is a tuple type constructed from the types of the element expressions. + +var a0: [any, any, any] = []; // Error +var a1: [boolean, string, number] = ["string", 1, true]; // Error + +// The resulting type an array literal expression is determined as follows: +// - If the array literal contains no spread elements and is an array assignment pattern in a destructuring assignment (section 4.17.1), +// the resulting type is a tuple type constructed from the types of the element expressions. + +var [b1, b2]: [number, number] = [1, 2, "string", true]; + +// The resulting type an array literal expression is determined as follows: +// - the resulting type is an array type with an element type that is the union of the types of the +// non - spread element expressions and the numeric index signature types of the spread element expressions +var temp = ["s", "t", "r"]; +var temp1 = [1, 2, 3]; +var temp2: [number[], string[]] = [[1, 2, 3], ["hello", "string"]]; + +interface tup { + 0: number[]|string[]; + 1: number[]|string[]; } -var [...as] = [[, , , , ]]; \ No newline at end of file +interface myArray extends Array { } +interface myArray2 extends Array { } +var c0: tup = [...temp2]; // Error +var c1: [number, number, number] = [...temp1]; // Error cannot assign number[] to [number, number, number] +var c2: myArray = [...temp1, ...temp]; // Error cannot assign (number|string)[] to number[] diff --git a/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3ES6.ts b/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3ES6.ts deleted file mode 100644 index 817d27f0f92..00000000000 --- a/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals3ES6.ts +++ /dev/null @@ -1,39 +0,0 @@ -// @target:es6 -interface I0 extends Array { - 0: number; - 1: number; - 2: string; - 3: boolean; -} -var [a, b]: [number, number] = [1, 2]; -var [a1, b1]: [number, number] = [1, 2, "string", true]; // error -var [a2, b2]: (number| string)[] = [1, 2, 3, "string"]; -var [c1, c2, c3]: I0 = [10, 11, "string", true]; -interface I extends Array{ - 0: string|number; - 1: string|number; - 2: string|number; -} -interface I2 extends Array { - 0: number; - 1: number; - 2: string|number; -} -var tup: [number, number, string] = [1, 2, "world"]; -var [c, d, e]: I = tup; -var [f, g]: I2 = tup; -var h1: string| number; -var [f1, g1,h1]: I2 = tup; -h1 = g1; - -var arr1 = [1, 2, 3]; -var arr2 = [true, false, true]; -var arr3 = [true] -var [[foo1, foo2, foo3], [boo1, boo2, boo3]] = [[...arr1], [...arr2]]; -var [bar1, bar2, bar3, bar1, bar2, bar3] = [...arr1, ...arr2]; -var [bar1, bar2, bar3, bar1, bar2] = [...arr1, ...arr3]; -var [[r, s], t] = [[...arr1], "hello"]; -var [[r1, s1], t1] = [[...arr1], ...["hello"]]; // error -var [x] = [...["word"]]; -var [...y] = [...["word"]]; -var z = [...[...["word"]]]; \ No newline at end of file diff --git a/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals4.ts b/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals4.ts deleted file mode 100644 index 28319903b7c..00000000000 --- a/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals4.ts +++ /dev/null @@ -1,6 +0,0 @@ -"use strict" -var [public, static] = [1, 23, ]; -var protected = [1, 2, 3]; -var [a, b, c] = [...protected]; -var [[public, package]] = [[1, [2, 3]]]; -var [...implements] = [[]]; diff --git a/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts b/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts deleted file mode 100644 index 2429037b4a8..00000000000 --- a/tests/cases/conformance/expressions/arrayLiterals/arrayLiterals5.ts +++ /dev/null @@ -1,3 +0,0 @@ -var [while, for] = [1, 3, ]; -var [for, as] = [, , , , ]; -var [...break] = [...["hello"]]; From 0e0cac8ce0fff920e7f423f8846146c2887ebe11 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 16 Apr 2015 14:41:33 -0700 Subject: [PATCH 034/194] Adding test --- .../unionTypePropertyAccessibility.errors.txt | 87 +++++++++++++++ .../unionTypePropertyAccessibility.js | 101 ++++++++++++++++++ .../union/unionTypePropertyAccessibility.ts | 47 ++++++++ 3 files changed, 235 insertions(+) create mode 100644 tests/baselines/reference/unionTypePropertyAccessibility.errors.txt create mode 100644 tests/baselines/reference/unionTypePropertyAccessibility.js create mode 100644 tests/cases/conformance/types/union/unionTypePropertyAccessibility.ts diff --git a/tests/baselines/reference/unionTypePropertyAccessibility.errors.txt b/tests/baselines/reference/unionTypePropertyAccessibility.errors.txt new file mode 100644 index 00000000000..ab60674ddc6 --- /dev/null +++ b/tests/baselines/reference/unionTypePropertyAccessibility.errors.txt @@ -0,0 +1,87 @@ +tests/cases/conformance/types/union/unionTypePropertyAccessibility.ts(35,1): error TS2445: Property 'member' is protected and only accessible within class 'Protected' and its subclasses. +tests/cases/conformance/types/union/unionTypePropertyAccessibility.ts(36,1): error TS2341: Property 'member' is private and only accessible within class 'Private'. +tests/cases/conformance/types/union/unionTypePropertyAccessibility.ts(38,4): error TS2339: Property 'member' does not exist on type 'Default | Protected'. +tests/cases/conformance/types/union/unionTypePropertyAccessibility.ts(39,4): error TS2339: Property 'member' does not exist on type 'Default | Private'. +tests/cases/conformance/types/union/unionTypePropertyAccessibility.ts(40,4): error TS2339: Property 'member' does not exist on type 'Public | Protected'. +tests/cases/conformance/types/union/unionTypePropertyAccessibility.ts(41,4): error TS2339: Property 'member' does not exist on type 'Public | Private'. +tests/cases/conformance/types/union/unionTypePropertyAccessibility.ts(42,5): error TS2339: Property 'member' does not exist on type 'Protected | Private'. +tests/cases/conformance/types/union/unionTypePropertyAccessibility.ts(43,5): error TS2339: Property 'member' does not exist on type 'Default | Public | Protected'. +tests/cases/conformance/types/union/unionTypePropertyAccessibility.ts(44,5): error TS2339: Property 'member' does not exist on type 'Default | Public | Private'. +tests/cases/conformance/types/union/unionTypePropertyAccessibility.ts(45,5): error TS2339: Property 'member' does not exist on type 'Default | Protected | Private'. +tests/cases/conformance/types/union/unionTypePropertyAccessibility.ts(46,5): error TS2339: Property 'member' does not exist on type 'Public | Protected | Private'. +tests/cases/conformance/types/union/unionTypePropertyAccessibility.ts(47,5): error TS2339: Property 'member' does not exist on type 'Default | Public | Protected | Private'. + + +==== tests/cases/conformance/types/union/unionTypePropertyAccessibility.ts (12 errors) ==== + class Default { + member: string; + } + + class Public { + public member: string; + } + + class Protected { + protected member: string; + } + + class Private { + private member: number; + } + + var v1: Default; + var v2: Public; + var v3: Protected; + var v4: Private; + var v5: Default | Public; + var v6: Default | Protected; + var v7: Default | Private; + var v8: Public | Protected; + var v9: Public | Private; + var v10: Protected | Private; + var v11: Default | Public | Protected; + var v12: Default | Public | Private; + var v13: Default | Protected | Private; + var v14: Public | Private | Protected; + var v15: Default | Public | Private | Protected; + + v1.member; + v2.member; + v3.member; + ~~~~~~~~~ +!!! error TS2445: Property 'member' is protected and only accessible within class 'Protected' and its subclasses. + v4.member; + ~~~~~~~~~ +!!! error TS2341: Property 'member' is private and only accessible within class 'Private'. + v5.member; + v6.member; + ~~~~~~ +!!! error TS2339: Property 'member' does not exist on type 'Default | Protected'. + v7.member; + ~~~~~~ +!!! error TS2339: Property 'member' does not exist on type 'Default | Private'. + v8.member; + ~~~~~~ +!!! error TS2339: Property 'member' does not exist on type 'Public | Protected'. + v9.member; + ~~~~~~ +!!! error TS2339: Property 'member' does not exist on type 'Public | Private'. + v10.member; + ~~~~~~ +!!! error TS2339: Property 'member' does not exist on type 'Protected | Private'. + v11.member; + ~~~~~~ +!!! error TS2339: Property 'member' does not exist on type 'Default | Public | Protected'. + v12.member; + ~~~~~~ +!!! error TS2339: Property 'member' does not exist on type 'Default | Public | Private'. + v13.member; + ~~~~~~ +!!! error TS2339: Property 'member' does not exist on type 'Default | Protected | Private'. + v14.member; + ~~~~~~ +!!! error TS2339: Property 'member' does not exist on type 'Public | Protected | Private'. + v15.member; + ~~~~~~ +!!! error TS2339: Property 'member' does not exist on type 'Default | Public | Protected | Private'. + \ No newline at end of file diff --git a/tests/baselines/reference/unionTypePropertyAccessibility.js b/tests/baselines/reference/unionTypePropertyAccessibility.js new file mode 100644 index 00000000000..3c5c4b42fee --- /dev/null +++ b/tests/baselines/reference/unionTypePropertyAccessibility.js @@ -0,0 +1,101 @@ +//// [unionTypePropertyAccessibility.ts] +class Default { + member: string; +} + +class Public { + public member: string; +} + +class Protected { + protected member: string; +} + +class Private { + private member: number; +} + +var v1: Default; +var v2: Public; +var v3: Protected; +var v4: Private; +var v5: Default | Public; +var v6: Default | Protected; +var v7: Default | Private; +var v8: Public | Protected; +var v9: Public | Private; +var v10: Protected | Private; +var v11: Default | Public | Protected; +var v12: Default | Public | Private; +var v13: Default | Protected | Private; +var v14: Public | Private | Protected; +var v15: Default | Public | Private | Protected; + +v1.member; +v2.member; +v3.member; +v4.member; +v5.member; +v6.member; +v7.member; +v8.member; +v9.member; +v10.member; +v11.member; +v12.member; +v13.member; +v14.member; +v15.member; + + +//// [unionTypePropertyAccessibility.js] +var Default = (function () { + function Default() { + } + return Default; +})(); +var Public = (function () { + function Public() { + } + return Public; +})(); +var Protected = (function () { + function Protected() { + } + return Protected; +})(); +var Private = (function () { + function Private() { + } + return Private; +})(); +var v1; +var v2; +var v3; +var v4; +var v5; +var v6; +var v7; +var v8; +var v9; +var v10; +var v11; +var v12; +var v13; +var v14; +var v15; +v1.member; +v2.member; +v3.member; +v4.member; +v5.member; +v6.member; +v7.member; +v8.member; +v9.member; +v10.member; +v11.member; +v12.member; +v13.member; +v14.member; +v15.member; diff --git a/tests/cases/conformance/types/union/unionTypePropertyAccessibility.ts b/tests/cases/conformance/types/union/unionTypePropertyAccessibility.ts new file mode 100644 index 00000000000..531ffe96e83 --- /dev/null +++ b/tests/cases/conformance/types/union/unionTypePropertyAccessibility.ts @@ -0,0 +1,47 @@ +class Default { + member: string; +} + +class Public { + public member: string; +} + +class Protected { + protected member: string; +} + +class Private { + private member: number; +} + +var v1: Default; +var v2: Public; +var v3: Protected; +var v4: Private; +var v5: Default | Public; +var v6: Default | Protected; +var v7: Default | Private; +var v8: Public | Protected; +var v9: Public | Private; +var v10: Protected | Private; +var v11: Default | Public | Protected; +var v12: Default | Public | Private; +var v13: Default | Protected | Private; +var v14: Public | Private | Protected; +var v15: Default | Public | Private | Protected; + +v1.member; +v2.member; +v3.member; +v4.member; +v5.member; +v6.member; +v7.member; +v8.member; +v9.member; +v10.member; +v11.member; +v12.member; +v13.member; +v14.member; +v15.member; From 3a15b3f7f4701b0e095ff237af168a648cd8031b Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 16 Apr 2015 14:53:19 -0700 Subject: [PATCH 035/194] Move error test cases into separate files --- .../diagnosticInformationMap.generated.ts | 1 + ...tructuringParameterDeclaration1.errors.txt | 272 --------------- ...cturingParameterDeclaration1ES5.errors.txt | 124 +++++++ ... destructuringParameterDeclaration1ES5.js} | 65 +--- ...tructuringParameterDeclaration1ES6.symbols | 314 ++++++++++++++++++ ...estructuringParameterDeclaration1ES6.types | 66 +++- ...tructuringParameterDeclaration2.errors.txt | 287 ++++++++++------ .../destructuringParameterDeclaration2.js | 291 ++++++++-------- ... destructuringParameterDeclaration3ES5.js} | 7 +- ...tructuringParameterDeclaration3ES5.symbols | 145 ++++++++ ...structuringParameterDeclaration3ES5.types} | 40 ++- .../destructuringParameterDeclaration3ES6.js | 80 +++++ ...tructuringParameterDeclaration3ES6.symbols | 145 ++++++++ ...estructuringParameterDeclaration3ES6.types | 206 ++++++++++++ ...tructuringParameterDeclaration4.errors.txt | 150 +++++---- .../destructuringParameterDeclaration4.js | 192 +++++------ ...tructuringParameterDeclaration5.errors.txt | 79 +++++ .../destructuringParameterDeclaration5.js | 115 +++++++ ...ructuringParameterDeclaration6.errors.txt} | 22 +- ... => destructuringParameterDeclaration6.js} | 4 +- 20 files changed, 1801 insertions(+), 804 deletions(-) delete mode 100644 tests/baselines/reference/destructuringParameterDeclaration1.errors.txt create mode 100644 tests/baselines/reference/destructuringParameterDeclaration1ES5.errors.txt rename tests/baselines/reference/{destructuringParameterDeclaration1.js => destructuringParameterDeclaration1ES5.js} (74%) create mode 100644 tests/baselines/reference/destructuringParameterDeclaration1ES6.symbols rename tests/baselines/reference/{destructuringParameterDeclaration2ES6.js => destructuringParameterDeclaration3ES5.js} (91%) create mode 100644 tests/baselines/reference/destructuringParameterDeclaration3ES5.symbols rename tests/baselines/reference/{destructuringParameterDeclaration2ES6.types => destructuringParameterDeclaration3ES5.types} (82%) create mode 100644 tests/baselines/reference/destructuringParameterDeclaration3ES6.js create mode 100644 tests/baselines/reference/destructuringParameterDeclaration3ES6.symbols create mode 100644 tests/baselines/reference/destructuringParameterDeclaration3ES6.types create mode 100644 tests/baselines/reference/destructuringParameterDeclaration5.errors.txt create mode 100644 tests/baselines/reference/destructuringParameterDeclaration5.js rename tests/baselines/reference/{destructuringParameterDeclaration3.errors.txt => destructuringParameterDeclaration6.errors.txt} (75%) rename tests/baselines/reference/{destructuringParameterDeclaration3.js => destructuringParameterDeclaration6.js} (90%) diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 79a5a696ef4..f3e9c325da6 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -1,5 +1,6 @@ // /// +/* @internal */ module ts { export var Diagnostics = { Unterminated_string_literal: { code: 1002, category: DiagnosticCategory.Error, key: "Unterminated string literal." }, diff --git a/tests/baselines/reference/destructuringParameterDeclaration1.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration1.errors.txt deleted file mode 100644 index 078895d07b0..00000000000 --- a/tests/baselines/reference/destructuringParameterDeclaration1.errors.txt +++ /dev/null @@ -1,272 +0,0 @@ -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(13,4): error TS2345: Argument of type '[number, string, string[][]]' is not assignable to parameter of type '[number, number, string[][]]'. - Types of property '1' are incompatible. - Type 'string' is not assignable to type 'number'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(13,29): error TS1005: ',' expected. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(14,4): error TS2345: Argument of type '[number, number, string[][], string]' is not assignable to parameter of type '[number, number, string[][]]'. - Types of property 'pop' are incompatible. - Type '() => string | number | string[][]' is not assignable to type '() => number | string[][]'. - Type 'string | number | string[][]' is not assignable to type 'number | string[][]'. - Type 'string' is not assignable to type 'number | string[][]'. - Type 'string' is not assignable to type 'string[][]'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(26,8): error TS2371: A parameter initializer is only allowed in a function or constructor implementation. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(26,16): error TS2371: A parameter initializer is only allowed in a function or constructor implementation. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(36,14): error TS2345: Argument of type '{ x: string; y: boolean; }' is not assignable to parameter of type '{ x: number; y: any; }'. - Types of property 'x' are incompatible. - Type 'string' is not assignable to type 'number'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(37,4): error TS2345: Argument of type '[string, number, number]' is not assignable to parameter of type '[undefined, null, undefined]'. - Types of property '0' are incompatible. - Type 'string' is not assignable to type 'undefined'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(38,4): error TS2345: Argument of type '[[string], number, [[boolean, boolean]]]' is not assignable to parameter of type '[[undefined], undefined, [[undefined, undefined]]]'. - Types of property '0' are incompatible. - Type '[string]' is not assignable to type '[undefined]'. - Types of property '0' are incompatible. - Type 'string' is not assignable to type 'undefined'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(47,14): error TS2300: Duplicate identifier 'z'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(47,18): error TS2300: Duplicate identifier 'z'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(53,4): error TS2345: Argument of type '{ z: number; }' is not assignable to parameter of type '{ z: { x: any; y: { j: any; }; }; }'. - Types of property 'z' are incompatible. - Type 'number' is not assignable to type '{ x: any; y: { j: any; }; }'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(55,4): error TS2345: Argument of type '{}' is not assignable to parameter of type '{ z: number; }'. - Property 'z' is missing in type '{}'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(56,4): error TS2345: Argument of type '{ z: boolean; }' is not assignable to parameter of type '{ z: number; }'. - Types of property 'z' are incompatible. - Type 'boolean' is not assignable to type 'number'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(62,4): error TS2345: Argument of type '{ z: boolean; }' is not assignable to parameter of type '{ z?: number; }'. - Types of property 'z' are incompatible. - Type 'boolean' is not assignable to type 'number'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(65,4): error TS2345: Argument of type '{ b: boolean; }' is not assignable to parameter of type '{ b: string | number; }'. - Types of property 'b' are incompatible. - Type 'boolean' is not assignable to type 'string | number'. - Type 'boolean' is not assignable to type 'number'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(69,4): error TS2345: Argument of type '[number, number, boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'. - Types of property '2' are incompatible. - Type 'boolean' is not assignable to type '[[any]]'. - Property '0' is missing in type 'Boolean'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(71,4): error TS2345: Argument of type '[number, number, [[string]]]' is not assignable to parameter of type '[any, any, [[number]]]'. - Types of property '2' are incompatible. - Type '[[string]]' is not assignable to type '[[number]]'. - Types of property '0' are incompatible. - Type '[string]' is not assignable to type '[number]'. - Types of property '0' are incompatible. - Type 'string' is not assignable to type 'number'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(76,10): error TS2393: Duplicate function implementation. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(77,10): error TS2393: Duplicate function implementation. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(78,13): error TS2463: A binding pattern parameter cannot be optional in an implementation signature. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(79,13): error TS2463: A binding pattern parameter cannot be optional in an implementation signature. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(100,7): error TS2420: Class 'C4' incorrectly implements interface 'F2'. - Types of property 'd4' are incompatible. - Type '({x, y, c}: { x: any; y: any; c: any; }) => void' is not assignable to type '({x, y, z}?: { x: any; y: any; z: any; }) => any'. - Types of parameters '__0' and '__0' are incompatible. - Type '{ x: any; y: any; c: any; }' is not assignable to type '{ x: any; y: any; z: any; }'. - Property 'z' is missing in type '{ x: any; y: any; c: any; }'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts(101,8): error TS2463: A binding pattern parameter cannot be optional in an implementation signature. - - -==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1.ts (23 errors) ==== - // A parameter declaration may specify either an identifier or a binding pattern. - // The identifiers specified in parameter declarations and binding patterns - // in a parameter list must be unique within that parameter list. - - // If the declaration includes a type annotation, the parameter is of that type - function a1([a, b, [[c]]]: [number, number, string[][]]) { } - function a2(o: { x: number, a: number }) { } - function a3({j, k, l: {m, n}, q: [a, b, c]}: { j: number, k: string, l: { m: boolean, n: number }, q: (number|string)[] }) { }; - function a4({x, a}: { x: number, a: number }) { } - - a1([1, 2, [["world"]]]); - a1([1, 2, [["world"]], 3]); - a1([1, "string", [["world"]]); // Error - ~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '[number, string, string[][]]' is not assignable to parameter of type '[number, number, string[][]]'. -!!! error TS2345: Types of property '1' are incompatible. -!!! error TS2345: Type 'string' is not assignable to type 'number'. - ~ -!!! error TS1005: ',' expected. - a1([1, 2, [["world"]], "string"]); // Error - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '[number, number, string[][], string]' is not assignable to parameter of type '[number, number, string[][]]'. -!!! error TS2345: Types of property 'pop' are incompatible. -!!! error TS2345: Type '() => string | number | string[][]' is not assignable to type '() => number | string[][]'. -!!! error TS2345: Type 'string | number | string[][]' is not assignable to type 'number | string[][]'. -!!! error TS2345: Type 'string' is not assignable to type 'number | string[][]'. -!!! error TS2345: Type 'string' is not assignable to type 'string[][]'. - - - // If the declaration includes an initializer expression (which is permitted only - // when the parameter list occurs in conjunction with a function body), - // the parameter type is the widened form (section 3.11) of the type of the initializer expression. - - function b1(z = [undefined, null]) { }; - function b2(z = null, o = { x: 0, y: undefined }) { } - function b3({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } - - interface F1 { - b4(z = 10, [[a, b], d, {u}] = [[1, 2], "string", { u: false }]); // Error, no function body - ~~~~~~ -!!! error TS2371: A parameter initializer is only allowed in a function or constructor implementation. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2371: A parameter initializer is only allowed in a function or constructor implementation. - b5(z, y, [, a, b], {p, m: { q, r}}); - } - - function b6([a, z, y] = [undefined, null, undefined]) { } - function b7([[a], b, [[c, d]]] = [[undefined], undefined, [[undefined, undefined]]]) { } - - b1([1, 2, 3]); // z is widen to the type any[] - b2("string", { x: 200, y: "string" }); - b2("string", { x: 200, y: true }); - b2("string", { x: "string", y: true }); // Error - ~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '{ x: string; y: boolean; }' is not assignable to parameter of type '{ x: number; y: any; }'. -!!! error TS2345: Types of property 'x' are incompatible. -!!! error TS2345: Type 'string' is not assignable to type 'number'. - b6(["string", 1, 2]); // Shouldn't be an error - ~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '[string, number, number]' is not assignable to parameter of type '[undefined, null, undefined]'. -!!! error TS2345: Types of property '0' are incompatible. -!!! error TS2345: Type 'string' is not assignable to type 'undefined'. - b7([["string"], 1, [[true, false]]]); // Shouldn't be an error - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '[[string], number, [[boolean, boolean]]]' is not assignable to parameter of type '[[undefined], undefined, [[undefined, undefined]]]'. -!!! error TS2345: Types of property '0' are incompatible. -!!! error TS2345: Type '[string]' is not assignable to type '[undefined]'. -!!! error TS2345: Types of property '0' are incompatible. -!!! error TS2345: Type 'string' is not assignable to type 'undefined'. - - - // If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3) - enum Foo { a } - function c0({z: {x, y: {j}}}) { } - function c1({z} = { z: 10 }) { } - function c2({z = 10}) { } - function c3({b}: { b: number|string} = { b: "hello" }) { } - function c4([z], z: number) { } // Duplicate identifier - ~ -!!! error TS2300: Duplicate identifier 'z'. - ~ -!!! error TS2300: Duplicate identifier 'z'. - function c5([a, b, [[c]]]) { } - function c6([a, b, [[c=1]]]) { } - - c0({z : { x: 1, y: { j: "world" } }}); // Implied type is { z: {x: any, y: {j: any}} } - c0({z : { x: "string", y: { j: true } }}); // Implied type is { z: {x: any, y: {j: any}} } - c0({z : 1}); // Error, implied type is { z: {x: any, y: {j: any}} } - ~~~~~~~ -!!! error TS2345: Argument of type '{ z: number; }' is not assignable to parameter of type '{ z: { x: any; y: { j: any; }; }; }'. -!!! error TS2345: Types of property 'z' are incompatible. -!!! error TS2345: Type 'number' is not assignable to type '{ x: any; y: { j: any; }; }'. - - c1({}); // Error, implied type is {z:number}? - ~~ -!!! error TS2345: Argument of type '{}' is not assignable to parameter of type '{ z: number; }'. -!!! error TS2345: Property 'z' is missing in type '{}'. - c1({ z: true }); // Error, implied type is {z:number}? - ~~~~~~~~~~~ -!!! error TS2345: Argument of type '{ z: boolean; }' is not assignable to parameter of type '{ z: number; }'. -!!! error TS2345: Types of property 'z' are incompatible. -!!! error TS2345: Type 'boolean' is not assignable to type 'number'. - c1(); // Implied type is {z:number}? - c1({ z: 1 }) // Implied type is {z:number}? - - c2({}); // Implied type is {z?: number} - c2({z:1}); // Implied type is {z?: number} - c2({z:false}); // Error, implied type is {z?: number} - ~~~~~~~~~ -!!! error TS2345: Argument of type '{ z: boolean; }' is not assignable to parameter of type '{ z?: number; }'. -!!! error TS2345: Types of property 'z' are incompatible. -!!! error TS2345: Type 'boolean' is not assignable to type 'number'. - - c3({ b: 1 }); // Implied type is { b: number|string }. - c3({ b: true }); // Error, implied type is { b: number|string }. - ~~~~~~~~~~~ -!!! error TS2345: Argument of type '{ b: boolean; }' is not assignable to parameter of type '{ b: string | number; }'. -!!! error TS2345: Types of property 'b' are incompatible. -!!! error TS2345: Type 'boolean' is not assignable to type 'string | number'. -!!! error TS2345: Type 'boolean' is not assignable to type 'number'. - - c5([1, 2, [["string"]]]); // Implied type is is [any, any, [[any]]] - c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]] - c5([1, 2, false, true]); // Error, implied type is [any, any, [[any]]] - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '[number, number, boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'. -!!! error TS2345: Types of property '2' are incompatible. -!!! error TS2345: Type 'boolean' is not assignable to type '[[any]]'. -!!! error TS2345: Property '0' is missing in type 'Boolean'. - - c6([1, 2, [["string"]]]); // Error, implied type is [any, any, [[number]]] // Use initializer - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '[number, number, [[string]]]' is not assignable to parameter of type '[any, any, [[number]]]'. -!!! error TS2345: Types of property '2' are incompatible. -!!! error TS2345: Type '[[string]]' is not assignable to type '[[number]]'. -!!! error TS2345: Types of property '0' are incompatible. -!!! error TS2345: Type '[string]' is not assignable to type '[number]'. -!!! error TS2345: Types of property '0' are incompatible. -!!! error TS2345: Type 'string' is not assignable to type 'number'. - - // A parameter can be marked optional by following its name or binding pattern with a question mark (?) - // or by including an initializer. - - function d0(x?) { } - ~~ -!!! error TS2393: Duplicate function implementation. - function d0(x = 10) { } - ~~ -!!! error TS2393: Duplicate function implementation. - function d1([a, b, c]?) { } // Error, binding pattern can't be optional in implementation signature - ~~~~~~~~~~ -!!! error TS2463: A binding pattern parameter cannot be optional in an implementation signature. - function d2({x, y, z}?) { } // Error, binding pattern can't be optional in implementation signature - ~~~~~~~~~~ -!!! error TS2463: A binding pattern parameter cannot be optional in an implementation signature. - - interface F2 { - d3([a, b, c]?); - d4({x, y, z}?); - e0([a, b, c]); - } - - class C2 implements F2 { - constructor() { } - d3() { } - d4() { } - e0([a, b, c]) { } - } - - class C3 implements F2 { - d3([a, b, c]) { } - d4({x, y, z}) { } - e0([a, b, c]) { } - } - - class C4 implements F2 { - ~~ -!!! error TS2420: Class 'C4' incorrectly implements interface 'F2'. -!!! error TS2420: Types of property 'd4' are incompatible. -!!! error TS2420: Type '({x, y, c}: { x: any; y: any; c: any; }) => void' is not assignable to type '({x, y, z}?: { x: any; y: any; z: any; }) => any'. -!!! error TS2420: Types of parameters '__0' and '__0' are incompatible. -!!! error TS2420: Type '{ x: any; y: any; c: any; }' is not assignable to type '{ x: any; y: any; z: any; }'. -!!! error TS2420: Property 'z' is missing in type '{ x: any; y: any; c: any; }'. - d3([a, b, c]?) { } - ~~~~~~~~~~ -!!! error TS2463: A binding pattern parameter cannot be optional in an implementation signature. - d4({x, y, c}) { } - e0([a, b, q]) { } - } - - function d5({x, y} = { x: 1, y: 2 }) { } - d5(); // Parameter is optional as its declaration included an initializer - - // Destructuring parameter declarations do not permit type annotations on the individual binding patterns, - // as such annotations would conflict with the already established meaning of colons in object literals. - // Type annotations must instead be written on the top- level parameter declaration - - function e1({x: number}) { } // x has type any NOT number - function e2({x}: { x: number }) { } // x is type number - function e3({x}: { x?: number }) { } // x is an optional with type number - function e4({x: [number,string,any] }) { } // x has type [any, any, any] - function e5({x: [a, b, c]}: { x: [number, number, number] }) { } // x has type [any, any, any] - - function e6({x: [number, number, number]}) { } // should be an error, duplicate identifier; - - - \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES5.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration1ES5.errors.txt new file mode 100644 index 00000000000..269d2b5640d --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration1ES5.errors.txt @@ -0,0 +1,124 @@ +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5.ts(32,4): error TS2345: Argument of type '[string, number, number]' is not assignable to parameter of type '[undefined, null, undefined]'. + Types of property '0' are incompatible. + Type 'string' is not assignable to type 'undefined'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5.ts(33,4): error TS2345: Argument of type '[[string], number, [[boolean, boolean]]]' is not assignable to parameter of type '[[undefined], undefined, [[undefined, undefined]]]'. + Types of property '0' are incompatible. + Type '[string]' is not assignable to type '[undefined]'. + Types of property '0' are incompatible. + Type 'string' is not assignable to type 'undefined'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5.ts(62,10): error TS2393: Duplicate function implementation. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5.ts(63,10): error TS2393: Duplicate function implementation. + + +==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES5.ts (4 errors) ==== + // A parameter declaration may specify either an identifier or a binding pattern. + // The identifiers specified in parameter declarations and binding patterns + // in a parameter list must be unique within that parameter list. + + // If the declaration includes a type annotation, the parameter is of that type + function a1([a, b, [[c]]]: [number, number, string[][]]) { } + function a2(o: { x: number, a: number }) { } + function a3({j, k, l: {m, n}, q: [a, b, c]}: { j: number, k: string, l: { m: boolean, n: number }, q: (number|string)[] }) { }; + function a4({x, a}: { x: number, a: number }) { } + + a1([1, 2, [["world"]]]); + a1([1, 2, [["world"]], 3]); + + // If the declaration includes an initializer expression (which is permitted only + // when the parameter list occurs in conjunction with a function body), + // the parameter type is the widened form (section 3.11) of the type of the initializer expression. + + function b1(z = [undefined, null]) { }; + function b2(z = null, o = { x: 0, y: undefined }) { } + function b3({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } + + interface F1 { + b5(z, y, [, a, b], {p, m: { q, r}}); + } + + function b6([a, z, y] = [undefined, null, undefined]) { } + function b7([[a], b, [[c, d]]] = [[undefined], undefined, [[undefined, undefined]]]) { } + + b1([1, 2, 3]); // z is widen to the type any[] + b2("string", { x: 200, y: "string" }); + b2("string", { x: 200, y: true }); + b6(["string", 1, 2]); // Shouldn't be an error + ~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '[string, number, number]' is not assignable to parameter of type '[undefined, null, undefined]'. +!!! error TS2345: Types of property '0' are incompatible. +!!! error TS2345: Type 'string' is not assignable to type 'undefined'. + b7([["string"], 1, [[true, false]]]); // Shouldn't be an error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '[[string], number, [[boolean, boolean]]]' is not assignable to parameter of type '[[undefined], undefined, [[undefined, undefined]]]'. +!!! error TS2345: Types of property '0' are incompatible. +!!! error TS2345: Type '[string]' is not assignable to type '[undefined]'. +!!! error TS2345: Types of property '0' are incompatible. +!!! error TS2345: Type 'string' is not assignable to type 'undefined'. + + + // If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3) + enum Foo { a } + function c0({z: {x, y: {j}}}) { } + function c1({z} = { z: 10 }) { } + function c2({z = 10}) { } + function c3({b}: { b: number|string} = { b: "hello" }) { } + function c5([a, b, [[c]]]) { } + function c6([a, b, [[c=1]]]) { } + + c0({z : { x: 1, y: { j: "world" } }}); // Implied type is { z: {x: any, y: {j: any}} } + c0({z : { x: "string", y: { j: true } }}); // Implied type is { z: {x: any, y: {j: any}} } + + c1(); // Implied type is {z:number}? + c1({ z: 1 }) // Implied type is {z:number}? + + c2({}); // Implied type is {z?: number} + c2({z:1}); // Implied type is {z?: number} + + c3({ b: 1 }); // Implied type is { b: number|string }. + + c5([1, 2, [["string"]]]); // Implied type is is [any, any, [[any]]] + c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]] + + // A parameter can be marked optional by following its name or binding pattern with a question mark (?) + // or by including an initializer. + + function d0(x?) { } + ~~ +!!! error TS2393: Duplicate function implementation. + function d0(x = 10) { } + ~~ +!!! error TS2393: Duplicate function implementation. + + interface F2 { + d3([a, b, c]?); + d4({x, y, z}?); + e0([a, b, c]); + } + + class C2 implements F2 { + constructor() { } + d3() { } + d4() { } + e0([a, b, c]) { } + } + + class C3 implements F2 { + d3([a, b, c]) { } + d4({x, y, z}) { } + e0([a, b, c]) { } + } + + + function d5({x, y} = { x: 1, y: 2 }) { } + d5(); // Parameter is optional as its declaration included an initializer + + // Destructuring parameter declarations do not permit type annotations on the individual binding patterns, + // as such annotations would conflict with the already established meaning of colons in object literals. + // Type annotations must instead be written on the top- level parameter declaration + + function e1({x: number}) { } // x has type any NOT number + function e2({x}: { x: number }) { } // x is type number + function e3({x}: { x?: number }) { } // x is an optional with type number + function e4({x: [number,string,any] }) { } // x has type [any, any, any] + function e5({x: [a, b, c]}: { x: [number, number, number] }) { } // x has type [any, any, any] + \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterDeclaration1.js b/tests/baselines/reference/destructuringParameterDeclaration1ES5.js similarity index 74% rename from tests/baselines/reference/destructuringParameterDeclaration1.js rename to tests/baselines/reference/destructuringParameterDeclaration1ES5.js index 0d8590ae50a..9a5b4eb8156 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration1.js +++ b/tests/baselines/reference/destructuringParameterDeclaration1ES5.js @@ -1,4 +1,4 @@ -//// [destructuringParameterDeclaration1.ts] +//// [destructuringParameterDeclaration1ES5.ts] // A parameter declaration may specify either an identifier or a binding pattern. // The identifiers specified in parameter declarations and binding patterns // in a parameter list must be unique within that parameter list. @@ -11,9 +11,6 @@ function a4({x, a}: { x: number, a: number }) { } a1([1, 2, [["world"]]]); a1([1, 2, [["world"]], 3]); -a1([1, "string", [["world"]]); // Error -a1([1, 2, [["world"]], "string"]); // Error - // If the declaration includes an initializer expression (which is permitted only // when the parameter list occurs in conjunction with a function body), @@ -24,7 +21,6 @@ function b2(z = null, o = { x: 0, y: undefined }) { } function b3({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } interface F1 { - b4(z = 10, [[a, b], d, {u}] = [[1, 2], "string", { u: false }]); // Error, no function body b5(z, y, [, a, b], {p, m: { q, r}}); } @@ -34,7 +30,6 @@ function b7([[a], b, [[c, d]]] = [[undefined], undefined, [[undefined, undefined b1([1, 2, 3]); // z is widen to the type any[] b2("string", { x: 200, y: "string" }); b2("string", { x: 200, y: true }); -b2("string", { x: "string", y: true }); // Error b6(["string", 1, 2]); // Shouldn't be an error b7([["string"], 1, [[true, false]]]); // Shouldn't be an error @@ -45,39 +40,28 @@ function c0({z: {x, y: {j}}}) { } function c1({z} = { z: 10 }) { } function c2({z = 10}) { } function c3({b}: { b: number|string} = { b: "hello" }) { } -function c4([z], z: number) { } // Duplicate identifier function c5([a, b, [[c]]]) { } function c6([a, b, [[c=1]]]) { } c0({z : { x: 1, y: { j: "world" } }}); // Implied type is { z: {x: any, y: {j: any}} } c0({z : { x: "string", y: { j: true } }}); // Implied type is { z: {x: any, y: {j: any}} } -c0({z : 1}); // Error, implied type is { z: {x: any, y: {j: any}} } -c1({}); // Error, implied type is {z:number}? -c1({ z: true }); // Error, implied type is {z:number}? c1(); // Implied type is {z:number}? c1({ z: 1 }) // Implied type is {z:number}? c2({}); // Implied type is {z?: number} c2({z:1}); // Implied type is {z?: number} -c2({z:false}); // Error, implied type is {z?: number} c3({ b: 1 }); // Implied type is { b: number|string }. -c3({ b: true }); // Error, implied type is { b: number|string }. c5([1, 2, [["string"]]]); // Implied type is is [any, any, [[any]]] c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]] -c5([1, 2, false, true]); // Error, implied type is [any, any, [[any]]] - -c6([1, 2, [["string"]]]); // Error, implied type is [any, any, [[number]]] // Use initializer // A parameter can be marked optional by following its name or binding pattern with a question mark (?) // or by including an initializer. function d0(x?) { } function d0(x = 10) { } -function d1([a, b, c]?) { } // Error, binding pattern can't be optional in implementation signature -function d2({x, y, z}?) { } // Error, binding pattern can't be optional in implementation signature interface F2 { d3([a, b, c]?); @@ -98,11 +82,6 @@ class C3 implements F2 { e0([a, b, c]) { } } -class C4 implements F2 { - d3([a, b, c]?) { } - d4({x, y, c}) { } - e0([a, b, q]) { } -} function d5({x, y} = { x: 1, y: 2 }) { } d5(); // Parameter is optional as its declaration included an initializer @@ -116,13 +95,9 @@ function e2({x}: { x: number }) { } // x is type number function e3({x}: { x?: number }) { } // x is an optional with type number function e4({x: [number,string,any] }) { } // x has type [any, any, any] function e5({x: [a, b, c]}: { x: [number, number, number] }) { } // x has type [any, any, any] - -function e6({x: [number, number, number]}) { } // should be an error, duplicate identifier; - - -//// [destructuringParameterDeclaration1.js] +//// [destructuringParameterDeclaration1ES5.js] // A parameter declaration may specify either an identifier or a binding pattern. // The identifiers specified in parameter declarations and binding patterns // in a parameter list must be unique within that parameter list. @@ -140,8 +115,6 @@ function a4(_a) { } a1([1, 2, [["world"]]]); a1([1, 2, [["world"]], 3]); -a1([1, "string", [["world"]]]); // Error -a1([1, 2, [["world"]], "string"]); // Error // If the declaration includes an initializer expression (which is permitted only // when the parameter list occurs in conjunction with a function body), // the parameter type is the widened form (section 3.11) of the type of the initializer expression. @@ -165,7 +138,6 @@ function b7(_a) { b1([1, 2, 3]); // z is widen to the type any[] b2("string", { x: 200, y: "string" }); b2("string", { x: 200, y: true }); -b2("string", { x: "string", y: true }); // Error b6(["string", 1, 2]); // Shouldn't be an error b7([["string"], 1, [[true, false]]]); // Shouldn't be an error // If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3) @@ -185,9 +157,6 @@ function c2(_a) { function c3(_a) { var b = (_a === void 0 ? { b: "hello" } : _a).b; } -function c4(_a, z) { - var z = _a[0]; -} // Duplicate identifier function c5(_a) { var a = _a[0], b = _a[1], c = _a[2][0][0]; } @@ -196,32 +165,19 @@ function c6(_a) { } c0({ z: { x: 1, y: { j: "world" } } }); // Implied type is { z: {x: any, y: {j: any}} } c0({ z: { x: "string", y: { j: true } } }); // Implied type is { z: {x: any, y: {j: any}} } -c0({ z: 1 }); // Error, implied type is { z: {x: any, y: {j: any}} } -c1({}); // Error, implied type is {z:number}? -c1({ z: true }); // Error, implied type is {z:number}? c1(); // Implied type is {z:number}? c1({ z: 1 }); // Implied type is {z:number}? c2({}); // Implied type is {z?: number} c2({ z: 1 }); // Implied type is {z?: number} -c2({ z: false }); // Error, implied type is {z?: number} c3({ b: 1 }); // Implied type is { b: number|string }. -c3({ b: true }); // Error, implied type is { b: number|string }. c5([1, 2, [["string"]]]); // Implied type is is [any, any, [[any]]] c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]] -c5([1, 2, false, true]); // Error, implied type is [any, any, [[any]]] -c6([1, 2, [["string"]]]); // Error, implied type is [any, any, [[number]]] // Use initializer // A parameter can be marked optional by following its name or binding pattern with a question mark (?) // or by including an initializer. function d0(x) { } function d0(x) { if (x === void 0) { x = 10; } } -function d1(_a) { - var a = _a[0], b = _a[1], c = _a[2]; -} // Error, binding pattern can't be optional in implementation signature -function d2(_a) { - var x = _a.x, y = _a.y, z = _a.z; -} // Error, binding pattern can't be optional in implementation signature var C2 = (function () { function C2() { } @@ -246,20 +202,6 @@ var C3 = (function () { }; return C3; })(); -var C4 = (function () { - function C4() { - } - C4.prototype.d3 = function (_a) { - var a = _a[0], b = _a[1], c = _a[2]; - }; - C4.prototype.d4 = function (_a) { - var x = _a.x, y = _a.y, c = _a.c; - }; - C4.prototype.e0 = function (_a) { - var a = _a[0], b = _a[1], q = _a[2]; - }; - return C4; -})(); function d5(_a) { var _b = _a === void 0 ? { x: 1, y: 2 } : _a, x = _b.x, y = _b.y; } @@ -282,6 +224,3 @@ function e4(_a) { function e5(_a) { var _b = _a.x, a = _b[0], b = _b[1], c = _b[2]; } // x has type [any, any, any] -function e6(_a) { - var _b = _a.x, number = _b[0], number = _b[1], number = _b[2]; -} // should be an error, duplicate identifier; diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES6.symbols b/tests/baselines/reference/destructuringParameterDeclaration1ES6.symbols new file mode 100644 index 00000000000..3267d4470db --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration1ES6.symbols @@ -0,0 +1,314 @@ +=== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration1ES6.ts === +// Conformance for emitting ES6 + +// A parameter declaration may specify either an identifier or a binding pattern. +// The identifiers specified in parameter declarations and binding patterns +// in a parameter list must be unique within that parameter list. + +// If the declaration includes a type annotation, the parameter is of that type +function a1([a, b, [[c]]]: [number, number, string[][]]) { } +>a1 : Symbol(a1, Decl(destructuringParameterDeclaration1ES6.ts, 0, 0)) +>a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 7, 13)) +>b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 7, 15)) +>c : Symbol(c, Decl(destructuringParameterDeclaration1ES6.ts, 7, 21)) + +function a2(o: { x: number, a: number }) { } +>a2 : Symbol(a2, Decl(destructuringParameterDeclaration1ES6.ts, 7, 60)) +>o : Symbol(o, Decl(destructuringParameterDeclaration1ES6.ts, 8, 12)) +>x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 8, 16)) +>a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 8, 27)) + +function a3({j, k, l: {m, n}, q: [a, b, c]}: { j: number, k: string, l: { m: boolean, n: number }, q: (number|string)[] }) { }; +>a3 : Symbol(a3, Decl(destructuringParameterDeclaration1ES6.ts, 8, 44)) +>j : Symbol(j, Decl(destructuringParameterDeclaration1ES6.ts, 9, 13)) +>k : Symbol(k, Decl(destructuringParameterDeclaration1ES6.ts, 9, 15)) +>m : Symbol(m, Decl(destructuringParameterDeclaration1ES6.ts, 9, 23)) +>n : Symbol(n, Decl(destructuringParameterDeclaration1ES6.ts, 9, 25)) +>a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 9, 34)) +>b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 9, 36)) +>c : Symbol(c, Decl(destructuringParameterDeclaration1ES6.ts, 9, 39)) +>j : Symbol(j, Decl(destructuringParameterDeclaration1ES6.ts, 9, 46)) +>k : Symbol(k, Decl(destructuringParameterDeclaration1ES6.ts, 9, 57)) +>l : Symbol(l, Decl(destructuringParameterDeclaration1ES6.ts, 9, 68)) +>m : Symbol(m, Decl(destructuringParameterDeclaration1ES6.ts, 9, 73)) +>n : Symbol(n, Decl(destructuringParameterDeclaration1ES6.ts, 9, 85)) +>q : Symbol(q, Decl(destructuringParameterDeclaration1ES6.ts, 9, 98)) + +function a4({x, a}: { x: number, a: number }) { } +>a4 : Symbol(a4, Decl(destructuringParameterDeclaration1ES6.ts, 9, 127)) +>x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 10, 13)) +>a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 10, 15)) +>x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 10, 21)) +>a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 10, 32)) + +a1([1, 2, [["world"]]]); +>a1 : Symbol(a1, Decl(destructuringParameterDeclaration1ES6.ts, 0, 0)) + +a1([1, 2, [["world"]], 3]); +>a1 : Symbol(a1, Decl(destructuringParameterDeclaration1ES6.ts, 0, 0)) + + +// If the declaration includes an initializer expression (which is permitted only +// when the parameter list occurs in conjunction with a function body), +// the parameter type is the widened form (section 3.11) of the type of the initializer expression. + +function b1(z = [undefined, null]) { }; +>b1 : Symbol(b1, Decl(destructuringParameterDeclaration1ES6.ts, 13, 27)) +>z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 20, 12)) +>undefined : Symbol(undefined) + +function b2(z = null, o = { x: 0, y: undefined }) { } +>b2 : Symbol(b2, Decl(destructuringParameterDeclaration1ES6.ts, 20, 39)) +>z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 21, 12)) +>o : Symbol(o, Decl(destructuringParameterDeclaration1ES6.ts, 21, 21)) +>x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 21, 27)) +>y : Symbol(y, Decl(destructuringParameterDeclaration1ES6.ts, 21, 33)) +>undefined : Symbol(undefined) + +function b3({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } +>b3 : Symbol(b3, Decl(destructuringParameterDeclaration1ES6.ts, 21, 53)) +>x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 22, 17)) +>j : Symbol(j, Decl(destructuringParameterDeclaration1ES6.ts, 22, 24)) +>z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 22, 32)) +>x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 22, 37)) +>y : Symbol(y, Decl(destructuringParameterDeclaration1ES6.ts, 22, 46)) +>j : Symbol(j, Decl(destructuringParameterDeclaration1ES6.ts, 22, 51)) + +interface F1 { +>F1 : Symbol(F1, Decl(destructuringParameterDeclaration1ES6.ts, 22, 67)) + + b5(z, y, [, a, b], {p, m: { q, r}}); +>b5 : Symbol(b5, Decl(destructuringParameterDeclaration1ES6.ts, 24, 14)) +>z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 25, 7)) +>y : Symbol(y, Decl(destructuringParameterDeclaration1ES6.ts, 25, 9)) +>a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 25, 15)) +>b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 25, 18)) +>p : Symbol(p, Decl(destructuringParameterDeclaration1ES6.ts, 25, 24)) +>q : Symbol(q, Decl(destructuringParameterDeclaration1ES6.ts, 25, 31)) +>r : Symbol(r, Decl(destructuringParameterDeclaration1ES6.ts, 25, 34)) +} + +function b6([a, z, y] = [undefined, null, undefined]) { } +>b6 : Symbol(b6, Decl(destructuringParameterDeclaration1ES6.ts, 26, 1)) +>a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 28, 13)) +>z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 28, 15)) +>y : Symbol(y, Decl(destructuringParameterDeclaration1ES6.ts, 28, 18)) +>undefined : Symbol(undefined) +>undefined : Symbol(undefined) + +function b7([[a], b, [[c, d]]] = [[undefined], undefined, [[undefined, undefined]]]) { } +>b7 : Symbol(b7, Decl(destructuringParameterDeclaration1ES6.ts, 28, 57)) +>a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 29, 14)) +>b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 29, 17)) +>c : Symbol(c, Decl(destructuringParameterDeclaration1ES6.ts, 29, 23)) +>d : Symbol(d, Decl(destructuringParameterDeclaration1ES6.ts, 29, 25)) +>undefined : Symbol(undefined) +>undefined : Symbol(undefined) +>undefined : Symbol(undefined) +>undefined : Symbol(undefined) + +b1([1, 2, 3]); // z is widen to the type any[] +>b1 : Symbol(b1, Decl(destructuringParameterDeclaration1ES6.ts, 13, 27)) + +b2("string", { x: 200, y: "string" }); +>b2 : Symbol(b2, Decl(destructuringParameterDeclaration1ES6.ts, 20, 39)) +>x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 32, 14)) +>y : Symbol(y, Decl(destructuringParameterDeclaration1ES6.ts, 32, 22)) + +b2("string", { x: 200, y: true }); +>b2 : Symbol(b2, Decl(destructuringParameterDeclaration1ES6.ts, 20, 39)) +>x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 33, 14)) +>y : Symbol(y, Decl(destructuringParameterDeclaration1ES6.ts, 33, 22)) + + +// If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3) +enum Foo { a } +>Foo : Symbol(Foo, Decl(destructuringParameterDeclaration1ES6.ts, 33, 34)) +>a : Symbol(Foo.a, Decl(destructuringParameterDeclaration1ES6.ts, 37, 10)) + +function c0({z: {x, y: {j}}}) { } +>c0 : Symbol(c0, Decl(destructuringParameterDeclaration1ES6.ts, 37, 14)) +>x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 38, 17)) +>j : Symbol(j, Decl(destructuringParameterDeclaration1ES6.ts, 38, 24)) + +function c1({z} = { z: 10 }) { } +>c1 : Symbol(c1, Decl(destructuringParameterDeclaration1ES6.ts, 38, 33)) +>z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 39, 13)) +>z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 39, 19)) + +function c2({z = 10}) { } +>c2 : Symbol(c2, Decl(destructuringParameterDeclaration1ES6.ts, 39, 32)) +>z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 40, 13)) + +function c3({b}: { b: number|string} = { b: "hello" }) { } +>c3 : Symbol(c3, Decl(destructuringParameterDeclaration1ES6.ts, 40, 25)) +>b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 41, 13)) +>b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 41, 18)) +>b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 41, 40)) + +function c5([a, b, [[c]]]) { } +>c5 : Symbol(c5, Decl(destructuringParameterDeclaration1ES6.ts, 41, 58)) +>a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 42, 13)) +>b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 42, 15)) +>c : Symbol(c, Decl(destructuringParameterDeclaration1ES6.ts, 42, 21)) + +function c6([a, b, [[c=1]]]) { } +>c6 : Symbol(c6, Decl(destructuringParameterDeclaration1ES6.ts, 42, 30)) +>a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 43, 13)) +>b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 43, 15)) +>c : Symbol(c, Decl(destructuringParameterDeclaration1ES6.ts, 43, 21)) + +c0({z : { x: 1, y: { j: "world" } }}); // Implied type is { z: {x: any, y: {j: any}} } +>c0 : Symbol(c0, Decl(destructuringParameterDeclaration1ES6.ts, 37, 14)) +>z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 45, 4)) +>x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 45, 9)) +>y : Symbol(y, Decl(destructuringParameterDeclaration1ES6.ts, 45, 15)) +>j : Symbol(j, Decl(destructuringParameterDeclaration1ES6.ts, 45, 20)) + +c0({z : { x: "string", y: { j: true } }}); // Implied type is { z: {x: any, y: {j: any}} } +>c0 : Symbol(c0, Decl(destructuringParameterDeclaration1ES6.ts, 37, 14)) +>z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 46, 4)) +>x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 46, 9)) +>y : Symbol(y, Decl(destructuringParameterDeclaration1ES6.ts, 46, 22)) +>j : Symbol(j, Decl(destructuringParameterDeclaration1ES6.ts, 46, 27)) + +c1(); // Implied type is {z:number}? +>c1 : Symbol(c1, Decl(destructuringParameterDeclaration1ES6.ts, 38, 33)) + +c1({ z: 1 }) // Implied type is {z:number}? +>c1 : Symbol(c1, Decl(destructuringParameterDeclaration1ES6.ts, 38, 33)) +>z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 49, 4)) + +c2({}); // Implied type is {z?: number} +>c2 : Symbol(c2, Decl(destructuringParameterDeclaration1ES6.ts, 39, 32)) + +c2({z:1}); // Implied type is {z?: number} +>c2 : Symbol(c2, Decl(destructuringParameterDeclaration1ES6.ts, 39, 32)) +>z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 52, 4)) + +c3({ b: 1 }); // Implied type is { b: number|string }. +>c3 : Symbol(c3, Decl(destructuringParameterDeclaration1ES6.ts, 40, 25)) +>b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 54, 4)) + +c5([1, 2, [["string"]]]); // Implied type is is [any, any, [[any]]] +>c5 : Symbol(c5, Decl(destructuringParameterDeclaration1ES6.ts, 41, 58)) + +c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]] +>c5 : Symbol(c5, Decl(destructuringParameterDeclaration1ES6.ts, 41, 58)) + + +// A parameter can be marked optional by following its name or binding pattern with a question mark (?) +// or by including an initializer. + +interface F2 { +>F2 : Symbol(F2, Decl(destructuringParameterDeclaration1ES6.ts, 57, 38)) + + d3([a, b, c]?); +>d3 : Symbol(d3, Decl(destructuringParameterDeclaration1ES6.ts, 63, 14)) +>a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 64, 8)) +>b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 64, 10)) +>c : Symbol(c, Decl(destructuringParameterDeclaration1ES6.ts, 64, 13)) + + d4({x, y, z}?); +>d4 : Symbol(d4, Decl(destructuringParameterDeclaration1ES6.ts, 64, 19)) +>x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 65, 8)) +>y : Symbol(y, Decl(destructuringParameterDeclaration1ES6.ts, 65, 10)) +>z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 65, 13)) + + e0([a, b, c]); +>e0 : Symbol(e0, Decl(destructuringParameterDeclaration1ES6.ts, 65, 19)) +>a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 66, 8)) +>b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 66, 10)) +>c : Symbol(c, Decl(destructuringParameterDeclaration1ES6.ts, 66, 13)) +} + +class C2 implements F2 { +>C2 : Symbol(C2, Decl(destructuringParameterDeclaration1ES6.ts, 67, 1)) +>F2 : Symbol(F2, Decl(destructuringParameterDeclaration1ES6.ts, 57, 38)) + + constructor() { } + d3() { } +>d3 : Symbol(d3, Decl(destructuringParameterDeclaration1ES6.ts, 70, 21)) + + d4() { } +>d4 : Symbol(d4, Decl(destructuringParameterDeclaration1ES6.ts, 71, 12)) + + e0([a, b, c]) { } +>e0 : Symbol(e0, Decl(destructuringParameterDeclaration1ES6.ts, 72, 12)) +>a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 73, 8)) +>b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 73, 10)) +>c : Symbol(c, Decl(destructuringParameterDeclaration1ES6.ts, 73, 13)) +} + +class C3 implements F2 { +>C3 : Symbol(C3, Decl(destructuringParameterDeclaration1ES6.ts, 74, 1)) +>F2 : Symbol(F2, Decl(destructuringParameterDeclaration1ES6.ts, 57, 38)) + + d3([a, b, c]) { } +>d3 : Symbol(d3, Decl(destructuringParameterDeclaration1ES6.ts, 76, 24)) +>a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 77, 8)) +>b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 77, 10)) +>c : Symbol(c, Decl(destructuringParameterDeclaration1ES6.ts, 77, 13)) + + d4({x, y, z}) { } +>d4 : Symbol(d4, Decl(destructuringParameterDeclaration1ES6.ts, 77, 21)) +>x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 78, 8)) +>y : Symbol(y, Decl(destructuringParameterDeclaration1ES6.ts, 78, 10)) +>z : Symbol(z, Decl(destructuringParameterDeclaration1ES6.ts, 78, 13)) + + e0([a, b, c]) { } +>e0 : Symbol(e0, Decl(destructuringParameterDeclaration1ES6.ts, 78, 21)) +>a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 79, 8)) +>b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 79, 10)) +>c : Symbol(c, Decl(destructuringParameterDeclaration1ES6.ts, 79, 13)) +} + +function d5({x, y} = { x: 1, y: 2 }) { } +>d5 : Symbol(d5, Decl(destructuringParameterDeclaration1ES6.ts, 80, 1)) +>x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 82, 13)) +>y : Symbol(y, Decl(destructuringParameterDeclaration1ES6.ts, 82, 15)) +>x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 82, 22)) +>y : Symbol(y, Decl(destructuringParameterDeclaration1ES6.ts, 82, 28)) + +d5(); // Parameter is optional as its declaration included an initializer +>d5 : Symbol(d5, Decl(destructuringParameterDeclaration1ES6.ts, 80, 1)) + +// Destructuring parameter declarations do not permit type annotations on the individual binding patterns, +// as such annotations would conflict with the already established meaning of colons in object literals. +// Type annotations must instead be written on the top- level parameter declaration + +function e1({x: number}) { } // x has type any NOT number +>e1 : Symbol(e1, Decl(destructuringParameterDeclaration1ES6.ts, 83, 5)) +>number : Symbol(number, Decl(destructuringParameterDeclaration1ES6.ts, 89, 13)) + +function e2({x}: { x: number }) { } // x is type number +>e2 : Symbol(e2, Decl(destructuringParameterDeclaration1ES6.ts, 89, 28)) +>x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 90, 13)) +>x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 90, 18)) + +function e3({x}: { x?: number }) { } // x is an optional with type number +>e3 : Symbol(e3, Decl(destructuringParameterDeclaration1ES6.ts, 90, 35)) +>x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 91, 13)) +>x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 91, 18)) + +function e4({x: [number,string,any] }) { } // x has type [any, any, any] +>e4 : Symbol(e4, Decl(destructuringParameterDeclaration1ES6.ts, 91, 36)) +>number : Symbol(number, Decl(destructuringParameterDeclaration1ES6.ts, 92, 17)) +>string : Symbol(string, Decl(destructuringParameterDeclaration1ES6.ts, 92, 24)) +>any : Symbol(any, Decl(destructuringParameterDeclaration1ES6.ts, 92, 31)) + +function e5({x: [a, b, c]}: { x: [number, number, number] }) { } // x has type [any, any, any] +>e5 : Symbol(e5, Decl(destructuringParameterDeclaration1ES6.ts, 92, 42)) +>a : Symbol(a, Decl(destructuringParameterDeclaration1ES6.ts, 93, 17)) +>b : Symbol(b, Decl(destructuringParameterDeclaration1ES6.ts, 93, 19)) +>c : Symbol(c, Decl(destructuringParameterDeclaration1ES6.ts, 93, 22)) +>x : Symbol(x, Decl(destructuringParameterDeclaration1ES6.ts, 93, 29)) + +function e6({x: [number, number, number]}) { } // should be an error, duplicate identifier; +>e6 : Symbol(e6, Decl(destructuringParameterDeclaration1ES6.ts, 93, 64)) +>number : Symbol(number, Decl(destructuringParameterDeclaration1ES6.ts, 95, 17), Decl(destructuringParameterDeclaration1ES6.ts, 95, 24), Decl(destructuringParameterDeclaration1ES6.ts, 95, 32)) +>number : Symbol(number, Decl(destructuringParameterDeclaration1ES6.ts, 95, 17), Decl(destructuringParameterDeclaration1ES6.ts, 95, 24), Decl(destructuringParameterDeclaration1ES6.ts, 95, 32)) +>number : Symbol(number, Decl(destructuringParameterDeclaration1ES6.ts, 95, 17), Decl(destructuringParameterDeclaration1ES6.ts, 95, 24), Decl(destructuringParameterDeclaration1ES6.ts, 95, 32)) + + + diff --git a/tests/baselines/reference/destructuringParameterDeclaration1ES6.types b/tests/baselines/reference/destructuringParameterDeclaration1ES6.types index ed77f2dc92b..9395fa49b5b 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration1ES6.types +++ b/tests/baselines/reference/destructuringParameterDeclaration1ES6.types @@ -22,10 +22,10 @@ function a3({j, k, l: {m, n}, q: [a, b, c]}: { j: number, k: string, l: { m: boo >a3 : ({j, k, l: {m, n}, q: [a, b, c]}: { j: number; k: string; l: { m: boolean; n: number; }; q: (string | number)[]; }) => void >j : number >k : string ->l : unknown +>l : any >m : boolean >n : number ->q : unknown +>q : any >a : string | number >b : string | number >c : string | number @@ -47,15 +47,22 @@ a1([1, 2, [["world"]]]); >a1([1, 2, [["world"]]]) : void >a1 : ([a, b, [[c]]]: [number, number, string[][]]) => void >[1, 2, [["world"]]] : [number, number, string[][]] +>1 : number +>2 : number >[["world"]] : string[][] >["world"] : string[] +>"world" : string a1([1, 2, [["world"]], 3]); >a1([1, 2, [["world"]], 3]) : void >a1 : ([a, b, [[c]]]: [number, number, string[][]]) => void >[1, 2, [["world"]], 3] : [number, number, string[][], number] +>1 : number +>2 : number >[["world"]] : string[][] >["world"] : string[] +>"world" : string +>3 : number // If the declaration includes an initializer expression (which is permitted only @@ -67,29 +74,34 @@ function b1(z = [undefined, null]) { }; >z : any[] >[undefined, null] : null[] >undefined : undefined +>null : null function b2(z = null, o = { x: 0, y: undefined }) { } >b2 : (z?: any, o?: { x: number; y: any; }) => void >z : any +>null : null >o : { x: number; y: any; } >{ x: 0, y: undefined } : { x: number; y: undefined; } >x : number +>0 : number >y : undefined >undefined : undefined function b3({z: {x, y: {j}}} = { z: { x: "hi", y: { j: 1 } } }) { } >b3 : ({z: {x, y: {j}}}?: { z: { x: string; y: { j: number; }; }; }) => void ->z : unknown +>z : any >x : string ->y : unknown +>y : any >j : number >{ z: { x: "hi", y: { j: 1 } } } : { z: { x: string; y: { j: number; }; }; } >z : { x: string; y: { j: number; }; } >{ x: "hi", y: { j: 1 } } : { x: string; y: { j: number; }; } >x : string +>"hi" : string >y : { j: number; } >{ j: 1 } : { j: number; } >j : number +>1 : number interface F1 { >F1 : F1 @@ -98,10 +110,11 @@ interface F1 { >b5 : (z: any, y: any, [, a, b]: [any, any, any], {p, m: { q, r}}: { p: any; m: { q: any; r: any; }; }) => any >z : any >y : any +> : undefined >a : any >b : any >p : any ->m : unknown +>m : any >q : any >r : any } @@ -113,6 +126,7 @@ function b6([a, z, y] = [undefined, null, undefined]) { } >y : any >[undefined, null, undefined] : [undefined, null, undefined] >undefined : undefined +>null : null >undefined : undefined function b7([[a], b, [[c, d]]] = [[undefined], undefined, [[undefined, undefined]]]) { } @@ -134,20 +148,29 @@ b1([1, 2, 3]); // z is widen to the type any[] >b1([1, 2, 3]) : void >b1 : (z?: any[]) => void >[1, 2, 3] : number[] +>1 : number +>2 : number +>3 : number b2("string", { x: 200, y: "string" }); >b2("string", { x: 200, y: "string" }) : void >b2 : (z?: any, o?: { x: number; y: any; }) => void +>"string" : string >{ x: 200, y: "string" } : { x: number; y: string; } >x : number +>200 : number >y : string +>"string" : string b2("string", { x: 200, y: true }); >b2("string", { x: 200, y: true }) : void >b2 : (z?: any, o?: { x: number; y: any; }) => void +>"string" : string >{ x: 200, y: true } : { x: number; y: boolean; } >x : number +>200 : number >y : boolean +>true : boolean // If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3) @@ -157,9 +180,9 @@ enum Foo { a } function c0({z: {x, y: {j}}}) { } >c0 : ({z: {x, y: {j}}}: { z: { x: any; y: { j: any; }; }; }) => void ->z : unknown +>z : any >x : any ->y : unknown +>y : any >j : any function c1({z} = { z: 10 }) { } @@ -167,10 +190,12 @@ function c1({z} = { z: 10 }) { } >z : number >{ z: 10 } : { z: number; } >z : number +>10 : number function c2({z = 10}) { } >c2 : ({z = 10}: { z?: number; }) => void >z : number +>10 : number function c3({b}: { b: number|string} = { b: "hello" }) { } >c3 : ({b}?: { b: string | number; }) => void @@ -178,6 +203,7 @@ function c3({b}: { b: number|string} = { b: "hello" }) { } >b : string | number >{ b: "hello" } : { b: string; } >b : string +>"hello" : string function c5([a, b, [[c]]]) { } >c5 : ([a, b, [[c]]]: [any, any, [[any]]]) => void @@ -190,6 +216,7 @@ function c6([a, b, [[c=1]]]) { } >a : any >b : any >c : number +>1 : number c0({z : { x: 1, y: { j: "world" } }}); // Implied type is { z: {x: any, y: {j: any}} } >c0({z : { x: 1, y: { j: "world" } }}) : void @@ -198,9 +225,11 @@ c0({z : { x: 1, y: { j: "world" } }}); // Implied type is { z: {x: any, y: >z : { x: number; y: { j: string; }; } >{ x: 1, y: { j: "world" } } : { x: number; y: { j: string; }; } >x : number +>1 : number >y : { j: string; } >{ j: "world" } : { j: string; } >j : string +>"world" : string c0({z : { x: "string", y: { j: true } }}); // Implied type is { z: {x: any, y: {j: any}} } >c0({z : { x: "string", y: { j: true } }}) : void @@ -209,9 +238,11 @@ c0({z : { x: "string", y: { j: true } }}); // Implied type is { z: {x: any, y: >z : { x: string; y: { j: boolean; }; } >{ x: "string", y: { j: true } } : { x: string; y: { j: boolean; }; } >x : string +>"string" : string >y : { j: boolean; } >{ j: true } : { j: boolean; } >j : boolean +>true : boolean c1(); // Implied type is {z:number}? >c1() : void @@ -222,6 +253,7 @@ c1({ z: 1 }) // Implied type is {z:number}? >c1 : ({z}?: { z: number; }) => void >{ z: 1 } : { z: number; } >z : number +>1 : number c2({}); // Implied type is {z?: number} >c2({}) : void @@ -233,26 +265,36 @@ c2({z:1}); // Implied type is {z?: number} >c2 : ({z = 10}: { z?: number; }) => void >{z:1} : { z: number; } >z : number +>1 : number c3({ b: 1 }); // Implied type is { b: number|string }. >c3({ b: 1 }) : void >c3 : ({b}?: { b: string | number; }) => void >{ b: 1 } : { b: number; } >b : number +>1 : number c5([1, 2, [["string"]]]); // Implied type is is [any, any, [[any]]] >c5([1, 2, [["string"]]]) : void >c5 : ([a, b, [[c]]]: [any, any, [[any]]]) => void >[1, 2, [["string"]]] : [number, number, [[string]]] +>1 : number +>2 : number >[["string"]] : [[string]] >["string"] : [string] +>"string" : string c5([1, 2, [["string"]], false, true]); // Implied type is is [any, any, [[any]]] >c5([1, 2, [["string"]], false, true]) : void >c5 : ([a, b, [[c]]]: [any, any, [[any]]]) => void >[1, 2, [["string"]], false, true] : [number, number, [[string]], boolean, boolean] +>1 : number +>2 : number >[["string"]] : [[string]] >["string"] : [string] +>"string" : string +>false : boolean +>true : boolean // A parameter can be marked optional by following its name or binding pattern with a question mark (?) @@ -327,7 +369,9 @@ function d5({x, y} = { x: 1, y: 2 }) { } >y : number >{ x: 1, y: 2 } : { x: number; y: number; } >x : number +>1 : number >y : number +>2 : number d5(); // Parameter is optional as its declaration included an initializer >d5() : void @@ -339,7 +383,7 @@ d5(); // Parameter is optional as its declaration included an initializer function e1({x: number}) { } // x has type any NOT number >e1 : ({x: number}: { x: any; }) => void ->x : unknown +>x : any >number : any function e2({x}: { x: number }) { } // x is type number @@ -354,14 +398,14 @@ function e3({x}: { x?: number }) { } // x is an optional with type number function e4({x: [number,string,any] }) { } // x has type [any, any, any] >e4 : ({x: [number,string,any] }: { x: [any, any, any]; }) => void ->x : unknown +>x : any >number : any >string : any >any : any function e5({x: [a, b, c]}: { x: [number, number, number] }) { } // x has type [any, any, any] >e5 : ({x: [a, b, c]}: { x: [number, number, number]; }) => void ->x : unknown +>x : any >a : number >b : number >c : number @@ -369,7 +413,7 @@ function e5({x: [a, b, c]}: { x: [number, number, number] }) { } // x has type function e6({x: [number, number, number]}) { } // should be an error, duplicate identifier; >e6 : ({x: [number, number, number]}: { x: [any, any, any]; }) => void ->x : unknown +>x : any >number : any >number : any >number : any diff --git a/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt index 60f85604559..11af7b0d17c 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt +++ b/tests/baselines/reference/destructuringParameterDeclaration2.errors.txt @@ -1,117 +1,194 @@ -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(11,13): error TS2370: A rest parameter must be of an array type. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(17,13): error TS2370: A rest parameter must be of an array type. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(25,19): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string | number'. - Type 'boolean' is not assignable to type 'number'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(30,4): error TS2345: Argument of type 'string | boolean' is not assignable to parameter of type 'string | number'. - Type 'boolean' is not assignable to type 'string | number'. - Type 'boolean' is not assignable to type 'number'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(33,4): error TS2345: Argument of type '[number, number, string, boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'. - Types of property '2' are incompatible. - Type 'string' is not assignable to type '[[any]]'. - Property '0' is missing in type 'String'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(34,4): error TS2345: Argument of type '[number, number]' is not assignable to parameter of type '[any, any, [[any]]]'. - Property '2' is missing in type '[number, number]'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(41,5): error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'. - Type 'string | number' is not assignable to type 'number'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(7,4): error TS2345: Argument of type '[number, string, string[][]]' is not assignable to parameter of type '[number, number, string[][]]'. + Types of property '1' are incompatible. Type 'string' is not assignable to type 'number'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(45,24): error TS1005: ',' expected. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(50,1): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. - Type argument candidate 'string' is not a valid type argument because it is not a supertype of candidate 'number'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(59,1): error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. - Type argument candidate 'number' is not a valid type argument because it is not a supertype of candidate 'string'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(7,29): error TS1005: ',' expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(8,4): error TS2345: Argument of type '[number, number, string[][], string]' is not assignable to parameter of type '[number, number, string[][]]'. + Types of property 'pop' are incompatible. + Type '() => string | number | string[][]' is not assignable to type '() => number | string[][]'. + Type 'string | number | string[][]' is not assignable to type 'number | string[][]'. + Type 'string' is not assignable to type 'number | string[][]'. + Type 'string' is not assignable to type 'string[][]'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(16,8): error TS2371: A parameter initializer is only allowed in a function or constructor implementation. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(16,16): error TS2371: A parameter initializer is only allowed in a function or constructor implementation. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(23,14): error TS2345: Argument of type '{ x: string; y: boolean; }' is not assignable to parameter of type '{ x: number; y: any; }'. + Types of property 'x' are incompatible. + Type 'string' is not assignable to type 'number'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(30,14): error TS2300: Duplicate identifier 'z'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(30,18): error TS2300: Duplicate identifier 'z'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(34,4): error TS2345: Argument of type '{ z: number; }' is not assignable to parameter of type '{ z: { x: any; y: { j: any; }; }; }'. + Types of property 'z' are incompatible. + Type 'number' is not assignable to type '{ x: any; y: { j: any; }; }'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(35,4): error TS2345: Argument of type '{}' is not assignable to parameter of type '{ z: number; }'. + Property 'z' is missing in type '{}'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(36,4): error TS2345: Argument of type '{ z: boolean; }' is not assignable to parameter of type '{ z: number; }'. + Types of property 'z' are incompatible. + Type 'boolean' is not assignable to type 'number'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(37,4): error TS2345: Argument of type '{ z: boolean; }' is not assignable to parameter of type '{ z?: number; }'. + Types of property 'z' are incompatible. + Type 'boolean' is not assignable to type 'number'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(38,4): error TS2345: Argument of type '{ b: boolean; }' is not assignable to parameter of type '{ b: string | number; }'. + Types of property 'b' are incompatible. + Type 'boolean' is not assignable to type 'string | number'. + Type 'boolean' is not assignable to type 'number'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(39,4): error TS2345: Argument of type '[number, number, boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'. + Types of property '2' are incompatible. + Type 'boolean' is not assignable to type '[[any]]'. + Property '0' is missing in type 'Boolean'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(40,4): error TS2345: Argument of type '[number, number, [[string]]]' is not assignable to parameter of type '[any, any, [[number]]]'. + Types of property '2' are incompatible. + Type '[[string]]' is not assignable to type '[[number]]'. + Types of property '0' are incompatible. + Type '[string]' is not assignable to type '[number]'. + Types of property '0' are incompatible. + Type 'string' is not assignable to type 'number'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(46,13): error TS2463: A binding pattern parameter cannot be optional in an implementation signature. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(47,13): error TS2463: A binding pattern parameter cannot be optional in an implementation signature. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(55,7): error TS2420: Class 'C4' incorrectly implements interface 'F2'. + Types of property 'd4' are incompatible. + Type '({x, y, c}: { x: any; y: any; c: any; }) => void' is not assignable to type '({x, y, z}?: { x: any; y: any; z: any; }) => any'. + Types of parameters '__0' and '__0' are incompatible. + Type '{ x: any; y: any; c: any; }' is not assignable to type '{ x: any; y: any; z: any; }'. + Property 'z' is missing in type '{ x: any; y: any; c: any; }'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts(56,8): error TS2463: A binding pattern parameter cannot be optional in an implementation signature. -==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts (10 errors) ==== - // If the parameter is a rest parameter, the parameter type is any[] - // A type annotation for a rest parameter must denote an array type. +==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2.ts (19 errors) ==== + // A parameter declaration may specify either an identifier or a binding pattern. + // The identifiers specified in parameter declarations and binding patterns + // in a parameter list must be unique within that parameter list. - // RestParameter: - // ... Identifier TypeAnnotation(opt) - - type arrayString = Array - type someArray = Array | number[]; - type stringOrNumArray = Array; - - function a0(...x: [number, number, string]) { } // Error, rest parameter must be array type - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2370: A rest parameter must be of an array type. - function a1(...x: (number|string)[]) { } - function a2(...a) { } - function a3(...a: Array) { } - function a4(...a: arrayString) { } - function a5(...a: stringOrNumArray) { } - function a6(...a: someArray) { } // Error, rest parameter must be array type - ~~~~~~~~~~~~~~~ -!!! error TS2370: A rest parameter must be of an array type. - function a7(...b?) { } // Error, can't be optional - function a8(...b = [1,2,3]) { } // Error, can't have initializer - function a9([a, b, [[c]]]) { } - function a10([a, b, [[c]], ...x]) { } - function a11([a, b, c, ...x]: number[]) { } - - - a1(1, 2, "hello", true); // Error, parameter type is (number|string)[] - ~~~~ -!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string | number'. -!!! error TS2345: Type 'boolean' is not assignable to type 'number'. - var array = [1, 2, 3]; - var array2 = [true, false, "hello"]; - a2([...array]); - a1(...array); - a1(...array2); // Error parameter type is (number|string)[] - ~~~~~~~~~ -!!! error TS2345: Argument of type 'string | boolean' is not assignable to parameter of type 'string | number'. -!!! error TS2345: Type 'boolean' is not assignable to type 'string | number'. -!!! error TS2345: Type 'boolean' is not assignable to type 'number'. - - a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]] - a9([1, 2, "string", false, true]); // Error, parameter type is [any, any, [[any]]] - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '[number, number, string, boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'. -!!! error TS2345: Types of property '2' are incompatible. -!!! error TS2345: Type 'string' is not assignable to type '[[any]]'. -!!! error TS2345: Property '0' is missing in type 'String'. - a9([1, 2]); // Error, parameter type is [any, any, [[any]]] - ~~~~~~ -!!! error TS2345: Argument of type '[number, number]' is not assignable to parameter of type '[any, any, [[any]]]'. -!!! error TS2345: Property '2' is missing in type '[number, number]'. - - a10([1, 2, [["string"]], false, true]); // Parameter type is any[] - a10([1, 2, 3, false, true]); // Parameter type is any[] - a10([1, 2]); // Parameter type is any[] - - a11([1, 2]); // Parameter type is number[] - a11([1, 2, "string"]); // Error, parameter type is number[] - ~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'. -!!! error TS2345: Type 'string | number' is not assignable to type 'number'. + // If the declaration includes a type annotation, the parameter is of that type + function a0([a, b, [[c]]]: [number, number, string[][]]) { } + a0([1, "string", [["world"]]); // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '[number, string, string[][]]' is not assignable to parameter of type '[number, number, string[][]]'. +!!! error TS2345: Types of property '1' are incompatible. !!! error TS2345: Type 'string' is not assignable to type 'number'. - - - class C { - constructor(public ...a) { } // Error, rest parameter can't have accessibilityModifier - ~~~ + ~ !!! error TS1005: ',' expected. + a0([1, 2, [["world"]], "string"]); // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '[number, number, string[][], string]' is not assignable to parameter of type '[number, number, string[][]]'. +!!! error TS2345: Types of property 'pop' are incompatible. +!!! error TS2345: Type '() => string | number | string[][]' is not assignable to type '() => number | string[][]'. +!!! error TS2345: Type 'string | number | string[][]' is not assignable to type 'number | string[][]'. +!!! error TS2345: Type 'string' is not assignable to type 'number | string[][]'. +!!! error TS2345: Type 'string' is not assignable to type 'string[][]'. + + + // If the declaration includes an initializer expression (which is permitted only + // when the parameter list occurs in conjunction with a function body), + // the parameter type is the widened form (section 3.11) of the type of the initializer expression. + + interface F1 { + b0(z = 10, [[a, b], d, {u}] = [[1, 2], "string", { u: false }]); // Error, no function body + ~~~~~~ +!!! error TS2371: A parameter initializer is only allowed in a function or constructor implementation. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2371: A parameter initializer is only allowed in a function or constructor implementation. } - // Rest parameter with generic - function foo(...a: T[]) { } - foo("hello", 1, 2); // Error - ~~~ -!!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. -!!! error TS2453: Type argument candidate 'string' is not a valid type argument because it is not a supertype of candidate 'number'. - foo("hello", 1, 2); - foo("hello", "world"); + function b1(z = null, o = { x: 0, y: undefined }) { } + function b2([a, z, y] = [undefined, null, undefined]) { } + function b3([[a], b, [[c, d]]] = [[undefined], undefined, [[undefined, undefined]]]) { } - enum E { a, b } - const enum E1 { a, b } - function foo1(...a: T[]) { } - foo1(1, 2, 3, E.a); - foo1(1, 2, 3, E1.a, E.b); - foo1(1, 2, "string", E1.a, E.b); // Error - ~~~~ -!!! error TS2453: The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly. -!!! error TS2453: Type argument candidate 'number' is not a valid type argument because it is not a supertype of candidate 'string'. + b1("string", { x: "string", y: true }); // Error + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ x: string; y: boolean; }' is not assignable to parameter of type '{ x: number; y: any; }'. +!!! error TS2345: Types of property 'x' are incompatible. +!!! error TS2345: Type 'string' is not assignable to type 'number'. + + // If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3) + function c0({z: {x, y: {j}}}) { } + function c1({z} = { z: 10 }) { } + function c2({z = 10}) { } + function c3({b}: { b: number|string } = { b: "hello" }) { } + function c4([z], z: number) { } // Error Duplicate identifier + ~ +!!! error TS2300: Duplicate identifier 'z'. + ~ +!!! error TS2300: Duplicate identifier 'z'. + function c5([a, b, [[c]]]) { } + function c6([a, b, [[c = 1]]]) { } + + c0({ z: 1 }); // Error, implied type is { z: {x: any, y: {j: any}} } + ~~~~~~~~ +!!! error TS2345: Argument of type '{ z: number; }' is not assignable to parameter of type '{ z: { x: any; y: { j: any; }; }; }'. +!!! error TS2345: Types of property 'z' are incompatible. +!!! error TS2345: Type 'number' is not assignable to type '{ x: any; y: { j: any; }; }'. + c1({}); // Error, implied type is {z:number}? + ~~ +!!! error TS2345: Argument of type '{}' is not assignable to parameter of type '{ z: number; }'. +!!! error TS2345: Property 'z' is missing in type '{}'. + c1({ z: true }); // Error, implied type is {z:number}? + ~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ z: boolean; }' is not assignable to parameter of type '{ z: number; }'. +!!! error TS2345: Types of property 'z' are incompatible. +!!! error TS2345: Type 'boolean' is not assignable to type 'number'. + c2({ z: false }); // Error, implied type is {z?: number} + ~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ z: boolean; }' is not assignable to parameter of type '{ z?: number; }'. +!!! error TS2345: Types of property 'z' are incompatible. +!!! error TS2345: Type 'boolean' is not assignable to type 'number'. + c3({ b: true }); // Error, implied type is { b: number|string }. + ~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ b: boolean; }' is not assignable to parameter of type '{ b: string | number; }'. +!!! error TS2345: Types of property 'b' are incompatible. +!!! error TS2345: Type 'boolean' is not assignable to type 'string | number'. +!!! error TS2345: Type 'boolean' is not assignable to type 'number'. + c5([1, 2, false, true]); // Error, implied type is [any, any, [[any]]] + ~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '[number, number, boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'. +!!! error TS2345: Types of property '2' are incompatible. +!!! error TS2345: Type 'boolean' is not assignable to type '[[any]]'. +!!! error TS2345: Property '0' is missing in type 'Boolean'. + c6([1, 2, [["string"]]]); // Error, implied type is [any, any, [[number]]] // Use initializer + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '[number, number, [[string]]]' is not assignable to parameter of type '[any, any, [[number]]]'. +!!! error TS2345: Types of property '2' are incompatible. +!!! error TS2345: Type '[[string]]' is not assignable to type '[[number]]'. +!!! error TS2345: Types of property '0' are incompatible. +!!! error TS2345: Type '[string]' is not assignable to type '[number]'. +!!! error TS2345: Types of property '0' are incompatible. +!!! error TS2345: Type 'string' is not assignable to type 'number'. + + // A parameter can be marked optional by following its name or binding pattern with a question mark (?) + // or by including an initializer. Initializers (including binding property or element initializers) are + // permitted only when the parameter list occurs in conjunction with a function body + + function d1([a, b, c]?) { } // Error, binding pattern can't be optional in implementation signature + ~~~~~~~~~~ +!!! error TS2463: A binding pattern parameter cannot be optional in an implementation signature. + function d2({x, y, z}?) { } // Error, binding pattern can't be optional in implementation signature + ~~~~~~~~~~ +!!! error TS2463: A binding pattern parameter cannot be optional in an implementation signature. + + interface F2 { + d3([a, b, c]?); + d4({x, y, z}?); + e0([a, b, c]); + } + + class C4 implements F2 { + ~~ +!!! error TS2420: Class 'C4' incorrectly implements interface 'F2'. +!!! error TS2420: Types of property 'd4' are incompatible. +!!! error TS2420: Type '({x, y, c}: { x: any; y: any; c: any; }) => void' is not assignable to type '({x, y, z}?: { x: any; y: any; z: any; }) => any'. +!!! error TS2420: Types of parameters '__0' and '__0' are incompatible. +!!! error TS2420: Type '{ x: any; y: any; c: any; }' is not assignable to type '{ x: any; y: any; z: any; }'. +!!! error TS2420: Property 'z' is missing in type '{ x: any; y: any; c: any; }'. + d3([a, b, c]?) { } // Error, binding pattern can't be optional in implementation signature + ~~~~~~~~~~ +!!! error TS2463: A binding pattern parameter cannot be optional in an implementation signature. + d4({x, y, c}) { } + e0([a, b, q]) { } + } + + // Destructuring parameter declarations do not permit type annotations on the individual binding patterns, + // as such annotations would conflict with the already established meaning of colons in object literals. + // Type annotations must instead be written on the top- level parameter declaration + + function e0({x: [number, number, number]}) { } // should be an error, duplicate identifier; \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterDeclaration2.js b/tests/baselines/reference/destructuringParameterDeclaration2.js index 187966c3597..8033ff7eeae 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration2.js +++ b/tests/baselines/reference/destructuringParameterDeclaration2.js @@ -1,178 +1,149 @@ //// [destructuringParameterDeclaration2.ts] -// If the parameter is a rest parameter, the parameter type is any[] -// A type annotation for a rest parameter must denote an array type. +// A parameter declaration may specify either an identifier or a binding pattern. +// The identifiers specified in parameter declarations and binding patterns +// in a parameter list must be unique within that parameter list. -// RestParameter: -// ... Identifier TypeAnnotation(opt) - -type arrayString = Array -type someArray = Array | number[]; -type stringOrNumArray = Array; - -function a0(...x: [number, number, string]) { } // Error, rest parameter must be array type -function a1(...x: (number|string)[]) { } -function a2(...a) { } -function a3(...a: Array) { } -function a4(...a: arrayString) { } -function a5(...a: stringOrNumArray) { } -function a6(...a: someArray) { } // Error, rest parameter must be array type -function a7(...b?) { } // Error, can't be optional -function a8(...b = [1,2,3]) { } // Error, can't have initializer -function a9([a, b, [[c]]]) { } -function a10([a, b, [[c]], ...x]) { } -function a11([a, b, c, ...x]: number[]) { } +// If the declaration includes a type annotation, the parameter is of that type +function a0([a, b, [[c]]]: [number, number, string[][]]) { } +a0([1, "string", [["world"]]); // Error +a0([1, 2, [["world"]], "string"]); // Error -a1(1, 2, "hello", true); // Error, parameter type is (number|string)[] -var array = [1, 2, 3]; -var array2 = [true, false, "hello"]; -a2([...array]); -a1(...array); -a1(...array2); // Error parameter type is (number|string)[] +// If the declaration includes an initializer expression (which is permitted only +// when the parameter list occurs in conjunction with a function body), +// the parameter type is the widened form (section 3.11) of the type of the initializer expression. -a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]] -a9([1, 2, "string", false, true]); // Error, parameter type is [any, any, [[any]]] -a9([1, 2]); // Error, parameter type is [any, any, [[any]]] - -a10([1, 2, [["string"]], false, true]); // Parameter type is any[] -a10([1, 2, 3, false, true]); // Parameter type is any[] -a10([1, 2]); // Parameter type is any[] - -a11([1, 2]); // Parameter type is number[] -a11([1, 2, "string"]); // Error, parameter type is number[] - - -class C { - constructor(public ...a) { } // Error, rest parameter can't have accessibilityModifier +interface F1 { + b0(z = 10, [[a, b], d, {u}] = [[1, 2], "string", { u: false }]); // Error, no function body } -// Rest parameter with generic -function foo(...a: T[]) { } -foo("hello", 1, 2); // Error -foo("hello", 1, 2); -foo("hello", "world"); +function b1(z = null, o = { x: 0, y: undefined }) { } +function b2([a, z, y] = [undefined, null, undefined]) { } +function b3([[a], b, [[c, d]]] = [[undefined], undefined, [[undefined, undefined]]]) { } -enum E { a, b } -const enum E1 { a, b } -function foo1(...a: T[]) { } -foo1(1, 2, 3, E.a); -foo1(1, 2, 3, E1.a, E.b); -foo1(1, 2, "string", E1.a, E.b); // Error +b1("string", { x: "string", y: true }); // Error + +// If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3) +function c0({z: {x, y: {j}}}) { } +function c1({z} = { z: 10 }) { } +function c2({z = 10}) { } +function c3({b}: { b: number|string } = { b: "hello" }) { } +function c4([z], z: number) { } // Error Duplicate identifier +function c5([a, b, [[c]]]) { } +function c6([a, b, [[c = 1]]]) { } + +c0({ z: 1 }); // Error, implied type is { z: {x: any, y: {j: any}} } +c1({}); // Error, implied type is {z:number}? +c1({ z: true }); // Error, implied type is {z:number}? +c2({ z: false }); // Error, implied type is {z?: number} +c3({ b: true }); // Error, implied type is { b: number|string }. +c5([1, 2, false, true]); // Error, implied type is [any, any, [[any]]] +c6([1, 2, [["string"]]]); // Error, implied type is [any, any, [[number]]] // Use initializer + +// A parameter can be marked optional by following its name or binding pattern with a question mark (?) +// or by including an initializer. Initializers (including binding property or element initializers) are +// permitted only when the parameter list occurs in conjunction with a function body + +function d1([a, b, c]?) { } // Error, binding pattern can't be optional in implementation signature +function d2({x, y, z}?) { } // Error, binding pattern can't be optional in implementation signature + +interface F2 { + d3([a, b, c]?); + d4({x, y, z}?); + e0([a, b, c]); +} + +class C4 implements F2 { + d3([a, b, c]?) { } // Error, binding pattern can't be optional in implementation signature + d4({x, y, c}) { } + e0([a, b, q]) { } +} + +// Destructuring parameter declarations do not permit type annotations on the individual binding patterns, +// as such annotations would conflict with the already established meaning of colons in object literals. +// Type annotations must instead be written on the top- level parameter declaration + +function e0({x: [number, number, number]}) { } // should be an error, duplicate identifier; //// [destructuringParameterDeclaration2.js] -// If the parameter is a rest parameter, the parameter type is any[] -// A type annotation for a rest parameter must denote an array type. -function a0() { - var x = []; - for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; - } -} // Error, rest parameter must be array type -function a1() { - var x = []; - for (var _i = 0; _i < arguments.length; _i++) { - x[_i - 0] = arguments[_i]; - } -} -function a2() { - var a = []; - for (var _i = 0; _i < arguments.length; _i++) { - a[_i - 0] = arguments[_i]; - } -} -function a3() { - var a = []; - for (var _i = 0; _i < arguments.length; _i++) { - a[_i - 0] = arguments[_i]; - } -} -function a4() { - var a = []; - for (var _i = 0; _i < arguments.length; _i++) { - a[_i - 0] = arguments[_i]; - } -} -function a5() { - var a = []; - for (var _i = 0; _i < arguments.length; _i++) { - a[_i - 0] = arguments[_i]; - } -} -function a6() { - var a = []; - for (var _i = 0; _i < arguments.length; _i++) { - a[_i - 0] = arguments[_i]; - } -} // Error, rest parameter must be array type -function a7() { - var b = []; - for (var _i = 0; _i < arguments.length; _i++) { - b[_i - 0] = arguments[_i]; - } -} // Error, can't be optional -function a8() { - if (b === void 0) { b = [1, 2, 3]; } - var b = []; - for (var _i = 0; _i < arguments.length; _i++) { - b[_i - 0] = arguments[_i]; - } -} // Error, can't have initializer -function a9(_a) { +// A parameter declaration may specify either an identifier or a binding pattern. +// The identifiers specified in parameter declarations and binding patterns +// in a parameter list must be unique within that parameter list. +// If the declaration includes a type annotation, the parameter is of that type +function a0(_a) { var a = _a[0], b = _a[1], c = _a[2][0][0]; } -function a10(_a) { - var a = _a[0], b = _a[1], c = _a[2][0][0], x = _a.slice(3); +a0([1, "string", [["world"]]]); // Error +a0([1, 2, [["world"]], "string"]); // Error +function b1(z, o) { + if (z === void 0) { z = null; } + if (o === void 0) { o = { x: 0, y: undefined }; } } -function a11(_a) { - var a = _a[0], b = _a[1], c = _a[2], x = _a.slice(3); +function b2(_a) { + var _b = _a === void 0 ? [undefined, null, undefined] : _a, a = _b[0], z = _b[1], y = _b[2]; } -a1(1, 2, "hello", true); // Error, parameter type is (number|string)[] -var array = [1, 2, 3]; -var array2 = [true, false, "hello"]; -a2(array); -a1.apply(void 0, array); -a1.apply(void 0, array2); // Error parameter type is (number|string)[] -a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]] -a9([1, 2, "string", false, true]); // Error, parameter type is [any, any, [[any]]] -a9([1, 2]); // Error, parameter type is [any, any, [[any]]] -a10([1, 2, [["string"]], false, true]); // Parameter type is any[] -a10([1, 2, 3, false, true]); // Parameter type is any[] -a10([1, 2]); // Parameter type is any[] -a11([1, 2]); // Parameter type is number[] -a11([1, 2, "string"]); // Error, parameter type is number[] -var C = (function () { - function C(public) { - var a = []; - for (var _i = 1; _i < arguments.length; _i++) { - a[_i - 1] = arguments[_i]; - } - } // Error, rest parameter can't have accessibilityModifier - return C; +function b3(_a) { + var _b = _a === void 0 ? [[undefined], undefined, [[undefined, undefined]]] : _a, a = _b[0][0], b = _b[1], _c = _b[2][0], c = _c[0], d = _c[1]; +} +b1("string", { x: "string", y: true }); // Error +// If the declaration specifies a binding pattern, the parameter type is the implied type of that binding pattern (section 5.1.3) +function c0(_a) { + var _b = _a.z, x = _b.x, j = _b.y.j; +} +function c1(_a) { + var z = (_a === void 0 ? { z: 10 } : _a).z; +} +function c2(_a) { + var _b = _a.z, z = _b === void 0 ? 10 : _b; +} +function c3(_a) { + var b = (_a === void 0 ? { b: "hello" } : _a).b; +} +function c4(_a, z) { + var z = _a[0]; +} // Error Duplicate identifier +function c5(_a) { + var a = _a[0], b = _a[1], c = _a[2][0][0]; +} +function c6(_a) { + var a = _a[0], b = _a[1], _b = _a[2][0][0], c = _b === void 0 ? 1 : _b; +} +c0({ z: 1 }); // Error, implied type is { z: {x: any, y: {j: any}} } +c1({}); // Error, implied type is {z:number}? +c1({ z: true }); // Error, implied type is {z:number}? +c2({ z: false }); // Error, implied type is {z?: number} +c3({ b: true }); // Error, implied type is { b: number|string }. +c5([1, 2, false, true]); // Error, implied type is [any, any, [[any]]] +c6([1, 2, [["string"]]]); // Error, implied type is [any, any, [[number]]] // Use initializer +// A parameter can be marked optional by following its name or binding pattern with a question mark (?) +// or by including an initializer. Initializers (including binding property or element initializers) are +// permitted only when the parameter list occurs in conjunction with a function body +function d1(_a) { + var a = _a[0], b = _a[1], c = _a[2]; +} // Error, binding pattern can't be optional in implementation signature +function d2(_a) { + var x = _a.x, y = _a.y, z = _a.z; +} // Error, binding pattern can't be optional in implementation signature +var C4 = (function () { + function C4() { + } + C4.prototype.d3 = function (_a) { + var a = _a[0], b = _a[1], c = _a[2]; + }; // Error, binding pattern can't be optional in implementation signature + C4.prototype.d4 = function (_a) { + var x = _a.x, y = _a.y, c = _a.c; + }; + C4.prototype.e0 = function (_a) { + var a = _a[0], b = _a[1], q = _a[2]; + }; + return C4; })(); -// Rest parameter with generic -function foo() { - var a = []; - for (var _i = 0; _i < arguments.length; _i++) { - a[_i - 0] = arguments[_i]; - } -} -foo("hello", 1, 2); // Error -foo("hello", 1, 2); -foo("hello", "world"); -var E; -(function (E) { - E[E["a"] = 0] = "a"; - E[E["b"] = 1] = "b"; -})(E || (E = {})); -function foo1() { - var a = []; - for (var _i = 0; _i < arguments.length; _i++) { - a[_i - 0] = arguments[_i]; - } -} -foo1(1, 2, 3, E.a); -foo1(1, 2, 3, 0 /* a */, E.b); -foo1(1, 2, "string", 0 /* a */, E.b); // Error +// Destructuring parameter declarations do not permit type annotations on the individual binding patterns, +// as such annotations would conflict with the already established meaning of colons in object literals. +// Type annotations must instead be written on the top- level parameter declaration +function e0(_a) { + var _b = _a.x, number = _b[0], number = _b[1], number = _b[2]; +} // should be an error, duplicate identifier; diff --git a/tests/baselines/reference/destructuringParameterDeclaration2ES6.js b/tests/baselines/reference/destructuringParameterDeclaration3ES5.js similarity index 91% rename from tests/baselines/reference/destructuringParameterDeclaration2ES6.js rename to tests/baselines/reference/destructuringParameterDeclaration3ES5.js index 903384c7b42..5dea671ee1a 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration2ES6.js +++ b/tests/baselines/reference/destructuringParameterDeclaration3ES5.js @@ -1,4 +1,4 @@ -//// [destructuringParameterDeclaration2ES6.ts] +//// [destructuringParameterDeclaration3ES5.ts] // If the parameter is a rest parameter, the parameter type is any[] // A type annotation for a rest parameter must denote an array type. @@ -30,8 +30,7 @@ a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]] a10([1, 2, [["string"]], false, true]); // Parameter type is any[] a10([1, 2, 3, false, true]); // Parameter type is any[] a10([1, 2]); // Parameter type is any[] - -a11([1, 2]); // Parameter type is number[] +a11([1, 2]); // Parameter type is number[] // Rest parameter with generic function foo(...a: T[]) { } @@ -47,7 +46,7 @@ foo1(1, 2, 3, E1.a, E.b); -//// [destructuringParameterDeclaration2ES6.js] +//// [destructuringParameterDeclaration3ES5.js] // If the parameter is a rest parameter, the parameter type is any[] // A type annotation for a rest parameter must denote an array type. function a1(...x) { } diff --git a/tests/baselines/reference/destructuringParameterDeclaration3ES5.symbols b/tests/baselines/reference/destructuringParameterDeclaration3ES5.symbols new file mode 100644 index 00000000000..066be7f9e78 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration3ES5.symbols @@ -0,0 +1,145 @@ +=== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5.ts === + +// If the parameter is a rest parameter, the parameter type is any[] +// A type annotation for a rest parameter must denote an array type. + +// RestParameter: +// ... Identifier TypeAnnotation(opt) + +type arrayString = Array +>arrayString : Symbol(arrayString, Decl(destructuringParameterDeclaration3ES5.ts, 0, 0)) +>Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11), Decl(lib.d.ts, 1409, 1)) +>String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11), Decl(lib.d.ts, 1508, 1)) + +type someArray = Array | number[]; +>someArray : Symbol(someArray, Decl(destructuringParameterDeclaration3ES5.ts, 7, 32)) +>Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11), Decl(lib.d.ts, 1409, 1)) +>String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11), Decl(lib.d.ts, 1508, 1)) + +type stringOrNumArray = Array; +>stringOrNumArray : Symbol(stringOrNumArray, Decl(destructuringParameterDeclaration3ES5.ts, 8, 42)) +>Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11), Decl(lib.d.ts, 1409, 1)) +>String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11), Decl(lib.d.ts, 1508, 1)) +>Number : Symbol(Number, Decl(lib.d.ts, 456, 40), Decl(lib.d.ts, 518, 11)) + +function a1(...x: (number|string)[]) { } +>a1 : Symbol(a1, Decl(destructuringParameterDeclaration3ES5.ts, 9, 45)) +>x : Symbol(x, Decl(destructuringParameterDeclaration3ES5.ts, 11, 12)) + +function a2(...a) { } +>a2 : Symbol(a2, Decl(destructuringParameterDeclaration3ES5.ts, 11, 40)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES5.ts, 12, 12)) + +function a3(...a: Array) { } +>a3 : Symbol(a3, Decl(destructuringParameterDeclaration3ES5.ts, 12, 21)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES5.ts, 13, 12)) +>Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11), Decl(lib.d.ts, 1409, 1)) +>String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11), Decl(lib.d.ts, 1508, 1)) + +function a4(...a: arrayString) { } +>a4 : Symbol(a4, Decl(destructuringParameterDeclaration3ES5.ts, 13, 36)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES5.ts, 14, 12)) +>arrayString : Symbol(arrayString, Decl(destructuringParameterDeclaration3ES5.ts, 0, 0)) + +function a5(...a: stringOrNumArray) { } +>a5 : Symbol(a5, Decl(destructuringParameterDeclaration3ES5.ts, 14, 34)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES5.ts, 15, 12)) +>stringOrNumArray : Symbol(stringOrNumArray, Decl(destructuringParameterDeclaration3ES5.ts, 8, 42)) + +function a9([a, b, [[c]]]) { } +>a9 : Symbol(a9, Decl(destructuringParameterDeclaration3ES5.ts, 15, 39)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES5.ts, 16, 13)) +>b : Symbol(b, Decl(destructuringParameterDeclaration3ES5.ts, 16, 15)) +>c : Symbol(c, Decl(destructuringParameterDeclaration3ES5.ts, 16, 21)) + +function a10([a, b, [[c]], ...x]) { } +>a10 : Symbol(a10, Decl(destructuringParameterDeclaration3ES5.ts, 16, 30)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES5.ts, 17, 14)) +>b : Symbol(b, Decl(destructuringParameterDeclaration3ES5.ts, 17, 16)) +>c : Symbol(c, Decl(destructuringParameterDeclaration3ES5.ts, 17, 22)) +>x : Symbol(x, Decl(destructuringParameterDeclaration3ES5.ts, 17, 26)) + +function a11([a, b, c, ...x]: number[]) { } +>a11 : Symbol(a11, Decl(destructuringParameterDeclaration3ES5.ts, 17, 37)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES5.ts, 18, 14)) +>b : Symbol(b, Decl(destructuringParameterDeclaration3ES5.ts, 18, 16)) +>c : Symbol(c, Decl(destructuringParameterDeclaration3ES5.ts, 18, 19)) +>x : Symbol(x, Decl(destructuringParameterDeclaration3ES5.ts, 18, 22)) + + +var array = [1, 2, 3]; +>array : Symbol(array, Decl(destructuringParameterDeclaration3ES5.ts, 21, 3)) + +var array2 = [true, false, "hello"]; +>array2 : Symbol(array2, Decl(destructuringParameterDeclaration3ES5.ts, 22, 3)) + +a2([...array]); +>a2 : Symbol(a2, Decl(destructuringParameterDeclaration3ES5.ts, 11, 40)) +>array : Symbol(array, Decl(destructuringParameterDeclaration3ES5.ts, 21, 3)) + +a1(...array); +>a1 : Symbol(a1, Decl(destructuringParameterDeclaration3ES5.ts, 9, 45)) +>array : Symbol(array, Decl(destructuringParameterDeclaration3ES5.ts, 21, 3)) + +a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]] +>a9 : Symbol(a9, Decl(destructuringParameterDeclaration3ES5.ts, 15, 39)) + +a10([1, 2, [["string"]], false, true]); // Parameter type is any[] +>a10 : Symbol(a10, Decl(destructuringParameterDeclaration3ES5.ts, 16, 30)) + +a10([1, 2, 3, false, true]); // Parameter type is any[] +>a10 : Symbol(a10, Decl(destructuringParameterDeclaration3ES5.ts, 16, 30)) + +a10([1, 2]); // Parameter type is any[] +>a10 : Symbol(a10, Decl(destructuringParameterDeclaration3ES5.ts, 16, 30)) + +a11([1, 2]); // Parameter type is number[] +>a11 : Symbol(a11, Decl(destructuringParameterDeclaration3ES5.ts, 17, 37)) + +// Rest parameter with generic +function foo(...a: T[]) { } +>foo : Symbol(foo, Decl(destructuringParameterDeclaration3ES5.ts, 31, 12)) +>T : Symbol(T, Decl(destructuringParameterDeclaration3ES5.ts, 34, 13)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES5.ts, 34, 16)) +>T : Symbol(T, Decl(destructuringParameterDeclaration3ES5.ts, 34, 13)) + +foo("hello", 1, 2); +>foo : Symbol(foo, Decl(destructuringParameterDeclaration3ES5.ts, 31, 12)) + +foo("hello", "world"); +>foo : Symbol(foo, Decl(destructuringParameterDeclaration3ES5.ts, 31, 12)) + +enum E { a, b } +>E : Symbol(E, Decl(destructuringParameterDeclaration3ES5.ts, 36, 22)) +>a : Symbol(E.a, Decl(destructuringParameterDeclaration3ES5.ts, 38, 8)) +>b : Symbol(E.b, Decl(destructuringParameterDeclaration3ES5.ts, 38, 11)) + +const enum E1 { a, b } +>E1 : Symbol(E1, Decl(destructuringParameterDeclaration3ES5.ts, 38, 15)) +>a : Symbol(E1.a, Decl(destructuringParameterDeclaration3ES5.ts, 39, 15)) +>b : Symbol(E1.b, Decl(destructuringParameterDeclaration3ES5.ts, 39, 18)) + +function foo1(...a: T[]) { } +>foo1 : Symbol(foo1, Decl(destructuringParameterDeclaration3ES5.ts, 39, 22)) +>T : Symbol(T, Decl(destructuringParameterDeclaration3ES5.ts, 40, 14)) +>Number : Symbol(Number, Decl(lib.d.ts, 456, 40), Decl(lib.d.ts, 518, 11)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES5.ts, 40, 32)) +>T : Symbol(T, Decl(destructuringParameterDeclaration3ES5.ts, 40, 14)) + +foo1(1, 2, 3, E.a); +>foo1 : Symbol(foo1, Decl(destructuringParameterDeclaration3ES5.ts, 39, 22)) +>E.a : Symbol(E.a, Decl(destructuringParameterDeclaration3ES5.ts, 38, 8)) +>E : Symbol(E, Decl(destructuringParameterDeclaration3ES5.ts, 36, 22)) +>a : Symbol(E.a, Decl(destructuringParameterDeclaration3ES5.ts, 38, 8)) + +foo1(1, 2, 3, E1.a, E.b); +>foo1 : Symbol(foo1, Decl(destructuringParameterDeclaration3ES5.ts, 39, 22)) +>E1.a : Symbol(E1.a, Decl(destructuringParameterDeclaration3ES5.ts, 39, 15)) +>E1 : Symbol(E1, Decl(destructuringParameterDeclaration3ES5.ts, 38, 15)) +>a : Symbol(E1.a, Decl(destructuringParameterDeclaration3ES5.ts, 39, 15)) +>E.b : Symbol(E.b, Decl(destructuringParameterDeclaration3ES5.ts, 38, 11)) +>E : Symbol(E, Decl(destructuringParameterDeclaration3ES5.ts, 36, 22)) +>b : Symbol(E.b, Decl(destructuringParameterDeclaration3ES5.ts, 38, 11)) + + + diff --git a/tests/baselines/reference/destructuringParameterDeclaration2ES6.types b/tests/baselines/reference/destructuringParameterDeclaration3ES5.types similarity index 82% rename from tests/baselines/reference/destructuringParameterDeclaration2ES6.types rename to tests/baselines/reference/destructuringParameterDeclaration3ES5.types index 6215728fefb..64bede3e2de 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration2ES6.types +++ b/tests/baselines/reference/destructuringParameterDeclaration3ES5.types @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration2ES6.ts === +=== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES5.ts === // If the parameter is a rest parameter, the parameter type is any[] // A type annotation for a rest parameter must denote an array type. @@ -70,10 +70,16 @@ function a11([a, b, c, ...x]: number[]) { } var array = [1, 2, 3]; >array : number[] >[1, 2, 3] : number[] +>1 : number +>2 : number +>3 : number var array2 = [true, false, "hello"]; >array2 : (string | boolean)[] >[true, false, "hello"] : (string | boolean)[] +>true : boolean +>false : boolean +>"hello" : string a2([...array]); >a2([...array]) : void @@ -92,30 +98,49 @@ a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]] >a9([1, 2, [["string"]], false, true]) : void >a9 : ([a, b, [[c]]]: [any, any, [[any]]]) => void >[1, 2, [["string"]], false, true] : [number, number, [[string]], boolean, boolean] +>1 : number +>2 : number >[["string"]] : [[string]] >["string"] : [string] +>"string" : string +>false : boolean +>true : boolean a10([1, 2, [["string"]], false, true]); // Parameter type is any[] >a10([1, 2, [["string"]], false, true]) : void >a10 : ([a, b, [[c]], ...x]: Iterable) => void >[1, 2, [["string"]], false, true] : (number | boolean | string[][])[] +>1 : number +>2 : number >[["string"]] : string[][] >["string"] : string[] +>"string" : string +>false : boolean +>true : boolean a10([1, 2, 3, false, true]); // Parameter type is any[] >a10([1, 2, 3, false, true]) : void >a10 : ([a, b, [[c]], ...x]: Iterable) => void >[1, 2, 3, false, true] : (number | boolean)[] +>1 : number +>2 : number +>3 : number +>false : boolean +>true : boolean a10([1, 2]); // Parameter type is any[] >a10([1, 2]) : void >a10 : ([a, b, [[c]], ...x]: Iterable) => void >[1, 2] : number[] +>1 : number +>2 : number -a11([1, 2]); // Parameter type is number[] +a11([1, 2]); // Parameter type is number[] >a11([1, 2]) : void >a11 : ([a, b, c, ...x]: number[]) => void >[1, 2] : number[] +>1 : number +>2 : number // Rest parameter with generic function foo(...a: T[]) { } @@ -127,10 +152,15 @@ function foo(...a: T[]) { } foo("hello", 1, 2); >foo("hello", 1, 2) : void >foo : (...a: T[]) => void +>"hello" : string +>1 : number +>2 : number foo("hello", "world"); >foo("hello", "world") : void >foo : (...a: T[]) => void +>"hello" : string +>"world" : string enum E { a, b } >E : E @@ -152,6 +182,9 @@ function foo1(...a: T[]) { } foo1(1, 2, 3, E.a); >foo1(1, 2, 3, E.a) : void >foo1 : (...a: T[]) => void +>1 : number +>2 : number +>3 : number >E.a : E >E : typeof E >a : E @@ -159,6 +192,9 @@ foo1(1, 2, 3, E.a); foo1(1, 2, 3, E1.a, E.b); >foo1(1, 2, 3, E1.a, E.b) : void >foo1 : (...a: T[]) => void +>1 : number +>2 : number +>3 : number >E1.a : E1 >E1 : typeof E1 >a : E1 diff --git a/tests/baselines/reference/destructuringParameterDeclaration3ES6.js b/tests/baselines/reference/destructuringParameterDeclaration3ES6.js new file mode 100644 index 00000000000..5893168bf93 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration3ES6.js @@ -0,0 +1,80 @@ +//// [destructuringParameterDeclaration3ES6.ts] + +// If the parameter is a rest parameter, the parameter type is any[] +// A type annotation for a rest parameter must denote an array type. + +// RestParameter: +// ... Identifier TypeAnnotation(opt) + +type arrayString = Array +type someArray = Array | number[]; +type stringOrNumArray = Array; + +function a1(...x: (number|string)[]) { } +function a2(...a) { } +function a3(...a: Array) { } +function a4(...a: arrayString) { } +function a5(...a: stringOrNumArray) { } +function a9([a, b, [[c]]]) { } +function a10([a, b, [[c]], ...x]) { } +function a11([a, b, c, ...x]: number[]) { } + + +var array = [1, 2, 3]; +var array2 = [true, false, "hello"]; +a2([...array]); +a1(...array); + +a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]] + +a10([1, 2, [["string"]], false, true]); // Parameter type is any[] +a10([1, 2, 3, false, true]); // Parameter type is any[] +a10([1, 2]); // Parameter type is any[] +a11([1, 2]); // Parameter type is number[] + +// Rest parameter with generic +function foo(...a: T[]) { } +foo("hello", 1, 2); +foo("hello", "world"); + +enum E { a, b } +const enum E1 { a, b } +function foo1(...a: T[]) { } +foo1(1, 2, 3, E.a); +foo1(1, 2, 3, E1.a, E.b); + + + + +//// [destructuringParameterDeclaration3ES6.js] +// If the parameter is a rest parameter, the parameter type is any[] +// A type annotation for a rest parameter must denote an array type. +function a1(...x) { } +function a2(...a) { } +function a3(...a) { } +function a4(...a) { } +function a5(...a) { } +function a9([a, b, [[c]]]) { } +function a10([a, b, [[c]], ...x]) { } +function a11([a, b, c, ...x]) { } +var array = [1, 2, 3]; +var array2 = [true, false, "hello"]; +a2([...array]); +a1(...array); +a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]] +a10([1, 2, [["string"]], false, true]); // Parameter type is any[] +a10([1, 2, 3, false, true]); // Parameter type is any[] +a10([1, 2]); // Parameter type is any[] +a11([1, 2]); // Parameter type is number[] +// Rest parameter with generic +function foo(...a) { } +foo("hello", 1, 2); +foo("hello", "world"); +var E; +(function (E) { + E[E["a"] = 0] = "a"; + E[E["b"] = 1] = "b"; +})(E || (E = {})); +function foo1(...a) { } +foo1(1, 2, 3, E.a); +foo1(1, 2, 3, 0 /* a */, E.b); diff --git a/tests/baselines/reference/destructuringParameterDeclaration3ES6.symbols b/tests/baselines/reference/destructuringParameterDeclaration3ES6.symbols new file mode 100644 index 00000000000..8e93a257033 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration3ES6.symbols @@ -0,0 +1,145 @@ +=== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES6.ts === + +// If the parameter is a rest parameter, the parameter type is any[] +// A type annotation for a rest parameter must denote an array type. + +// RestParameter: +// ... Identifier TypeAnnotation(opt) + +type arrayString = Array +>arrayString : Symbol(arrayString, Decl(destructuringParameterDeclaration3ES6.ts, 0, 0)) +>Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11), Decl(lib.d.ts, 1409, 1)) +>String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11), Decl(lib.d.ts, 1508, 1)) + +type someArray = Array | number[]; +>someArray : Symbol(someArray, Decl(destructuringParameterDeclaration3ES6.ts, 7, 32)) +>Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11), Decl(lib.d.ts, 1409, 1)) +>String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11), Decl(lib.d.ts, 1508, 1)) + +type stringOrNumArray = Array; +>stringOrNumArray : Symbol(stringOrNumArray, Decl(destructuringParameterDeclaration3ES6.ts, 8, 42)) +>Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11), Decl(lib.d.ts, 1409, 1)) +>String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11), Decl(lib.d.ts, 1508, 1)) +>Number : Symbol(Number, Decl(lib.d.ts, 456, 40), Decl(lib.d.ts, 518, 11)) + +function a1(...x: (number|string)[]) { } +>a1 : Symbol(a1, Decl(destructuringParameterDeclaration3ES6.ts, 9, 45)) +>x : Symbol(x, Decl(destructuringParameterDeclaration3ES6.ts, 11, 12)) + +function a2(...a) { } +>a2 : Symbol(a2, Decl(destructuringParameterDeclaration3ES6.ts, 11, 40)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES6.ts, 12, 12)) + +function a3(...a: Array) { } +>a3 : Symbol(a3, Decl(destructuringParameterDeclaration3ES6.ts, 12, 21)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES6.ts, 13, 12)) +>Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11), Decl(lib.d.ts, 1409, 1)) +>String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11), Decl(lib.d.ts, 1508, 1)) + +function a4(...a: arrayString) { } +>a4 : Symbol(a4, Decl(destructuringParameterDeclaration3ES6.ts, 13, 36)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES6.ts, 14, 12)) +>arrayString : Symbol(arrayString, Decl(destructuringParameterDeclaration3ES6.ts, 0, 0)) + +function a5(...a: stringOrNumArray) { } +>a5 : Symbol(a5, Decl(destructuringParameterDeclaration3ES6.ts, 14, 34)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES6.ts, 15, 12)) +>stringOrNumArray : Symbol(stringOrNumArray, Decl(destructuringParameterDeclaration3ES6.ts, 8, 42)) + +function a9([a, b, [[c]]]) { } +>a9 : Symbol(a9, Decl(destructuringParameterDeclaration3ES6.ts, 15, 39)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES6.ts, 16, 13)) +>b : Symbol(b, Decl(destructuringParameterDeclaration3ES6.ts, 16, 15)) +>c : Symbol(c, Decl(destructuringParameterDeclaration3ES6.ts, 16, 21)) + +function a10([a, b, [[c]], ...x]) { } +>a10 : Symbol(a10, Decl(destructuringParameterDeclaration3ES6.ts, 16, 30)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES6.ts, 17, 14)) +>b : Symbol(b, Decl(destructuringParameterDeclaration3ES6.ts, 17, 16)) +>c : Symbol(c, Decl(destructuringParameterDeclaration3ES6.ts, 17, 22)) +>x : Symbol(x, Decl(destructuringParameterDeclaration3ES6.ts, 17, 26)) + +function a11([a, b, c, ...x]: number[]) { } +>a11 : Symbol(a11, Decl(destructuringParameterDeclaration3ES6.ts, 17, 37)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES6.ts, 18, 14)) +>b : Symbol(b, Decl(destructuringParameterDeclaration3ES6.ts, 18, 16)) +>c : Symbol(c, Decl(destructuringParameterDeclaration3ES6.ts, 18, 19)) +>x : Symbol(x, Decl(destructuringParameterDeclaration3ES6.ts, 18, 22)) + + +var array = [1, 2, 3]; +>array : Symbol(array, Decl(destructuringParameterDeclaration3ES6.ts, 21, 3)) + +var array2 = [true, false, "hello"]; +>array2 : Symbol(array2, Decl(destructuringParameterDeclaration3ES6.ts, 22, 3)) + +a2([...array]); +>a2 : Symbol(a2, Decl(destructuringParameterDeclaration3ES6.ts, 11, 40)) +>array : Symbol(array, Decl(destructuringParameterDeclaration3ES6.ts, 21, 3)) + +a1(...array); +>a1 : Symbol(a1, Decl(destructuringParameterDeclaration3ES6.ts, 9, 45)) +>array : Symbol(array, Decl(destructuringParameterDeclaration3ES6.ts, 21, 3)) + +a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]] +>a9 : Symbol(a9, Decl(destructuringParameterDeclaration3ES6.ts, 15, 39)) + +a10([1, 2, [["string"]], false, true]); // Parameter type is any[] +>a10 : Symbol(a10, Decl(destructuringParameterDeclaration3ES6.ts, 16, 30)) + +a10([1, 2, 3, false, true]); // Parameter type is any[] +>a10 : Symbol(a10, Decl(destructuringParameterDeclaration3ES6.ts, 16, 30)) + +a10([1, 2]); // Parameter type is any[] +>a10 : Symbol(a10, Decl(destructuringParameterDeclaration3ES6.ts, 16, 30)) + +a11([1, 2]); // Parameter type is number[] +>a11 : Symbol(a11, Decl(destructuringParameterDeclaration3ES6.ts, 17, 37)) + +// Rest parameter with generic +function foo(...a: T[]) { } +>foo : Symbol(foo, Decl(destructuringParameterDeclaration3ES6.ts, 31, 12)) +>T : Symbol(T, Decl(destructuringParameterDeclaration3ES6.ts, 34, 13)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES6.ts, 34, 16)) +>T : Symbol(T, Decl(destructuringParameterDeclaration3ES6.ts, 34, 13)) + +foo("hello", 1, 2); +>foo : Symbol(foo, Decl(destructuringParameterDeclaration3ES6.ts, 31, 12)) + +foo("hello", "world"); +>foo : Symbol(foo, Decl(destructuringParameterDeclaration3ES6.ts, 31, 12)) + +enum E { a, b } +>E : Symbol(E, Decl(destructuringParameterDeclaration3ES6.ts, 36, 22)) +>a : Symbol(E.a, Decl(destructuringParameterDeclaration3ES6.ts, 38, 8)) +>b : Symbol(E.b, Decl(destructuringParameterDeclaration3ES6.ts, 38, 11)) + +const enum E1 { a, b } +>E1 : Symbol(E1, Decl(destructuringParameterDeclaration3ES6.ts, 38, 15)) +>a : Symbol(E1.a, Decl(destructuringParameterDeclaration3ES6.ts, 39, 15)) +>b : Symbol(E1.b, Decl(destructuringParameterDeclaration3ES6.ts, 39, 18)) + +function foo1(...a: T[]) { } +>foo1 : Symbol(foo1, Decl(destructuringParameterDeclaration3ES6.ts, 39, 22)) +>T : Symbol(T, Decl(destructuringParameterDeclaration3ES6.ts, 40, 14)) +>Number : Symbol(Number, Decl(lib.d.ts, 456, 40), Decl(lib.d.ts, 518, 11)) +>a : Symbol(a, Decl(destructuringParameterDeclaration3ES6.ts, 40, 32)) +>T : Symbol(T, Decl(destructuringParameterDeclaration3ES6.ts, 40, 14)) + +foo1(1, 2, 3, E.a); +>foo1 : Symbol(foo1, Decl(destructuringParameterDeclaration3ES6.ts, 39, 22)) +>E.a : Symbol(E.a, Decl(destructuringParameterDeclaration3ES6.ts, 38, 8)) +>E : Symbol(E, Decl(destructuringParameterDeclaration3ES6.ts, 36, 22)) +>a : Symbol(E.a, Decl(destructuringParameterDeclaration3ES6.ts, 38, 8)) + +foo1(1, 2, 3, E1.a, E.b); +>foo1 : Symbol(foo1, Decl(destructuringParameterDeclaration3ES6.ts, 39, 22)) +>E1.a : Symbol(E1.a, Decl(destructuringParameterDeclaration3ES6.ts, 39, 15)) +>E1 : Symbol(E1, Decl(destructuringParameterDeclaration3ES6.ts, 38, 15)) +>a : Symbol(E1.a, Decl(destructuringParameterDeclaration3ES6.ts, 39, 15)) +>E.b : Symbol(E.b, Decl(destructuringParameterDeclaration3ES6.ts, 38, 11)) +>E : Symbol(E, Decl(destructuringParameterDeclaration3ES6.ts, 36, 22)) +>b : Symbol(E.b, Decl(destructuringParameterDeclaration3ES6.ts, 38, 11)) + + + diff --git a/tests/baselines/reference/destructuringParameterDeclaration3ES6.types b/tests/baselines/reference/destructuringParameterDeclaration3ES6.types new file mode 100644 index 00000000000..aea7b2ae15a --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration3ES6.types @@ -0,0 +1,206 @@ +=== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3ES6.ts === + +// If the parameter is a rest parameter, the parameter type is any[] +// A type annotation for a rest parameter must denote an array type. + +// RestParameter: +// ... Identifier TypeAnnotation(opt) + +type arrayString = Array +>arrayString : String[] +>Array : T[] +>String : String + +type someArray = Array | number[]; +>someArray : number[] | String[] +>Array : T[] +>String : String + +type stringOrNumArray = Array; +>stringOrNumArray : (String | Number)[] +>Array : T[] +>String : String +>Number : Number + +function a1(...x: (number|string)[]) { } +>a1 : (...x: (string | number)[]) => void +>x : (string | number)[] + +function a2(...a) { } +>a2 : (...a: any[]) => void +>a : any[] + +function a3(...a: Array) { } +>a3 : (...a: String[]) => void +>a : String[] +>Array : T[] +>String : String + +function a4(...a: arrayString) { } +>a4 : (...a: String[]) => void +>a : String[] +>arrayString : String[] + +function a5(...a: stringOrNumArray) { } +>a5 : (...a: (String | Number)[]) => void +>a : (String | Number)[] +>stringOrNumArray : (String | Number)[] + +function a9([a, b, [[c]]]) { } +>a9 : ([a, b, [[c]]]: [any, any, [[any]]]) => void +>a : any +>b : any +>c : any + +function a10([a, b, [[c]], ...x]) { } +>a10 : ([a, b, [[c]], ...x]: Iterable) => void +>a : any +>b : any +>c : any +>x : any[] + +function a11([a, b, c, ...x]: number[]) { } +>a11 : ([a, b, c, ...x]: number[]) => void +>a : number +>b : number +>c : number +>x : number[] + + +var array = [1, 2, 3]; +>array : number[] +>[1, 2, 3] : number[] +>1 : number +>2 : number +>3 : number + +var array2 = [true, false, "hello"]; +>array2 : (string | boolean)[] +>[true, false, "hello"] : (string | boolean)[] +>true : boolean +>false : boolean +>"hello" : string + +a2([...array]); +>a2([...array]) : void +>a2 : (...a: any[]) => void +>[...array] : number[] +>...array : number +>array : number[] + +a1(...array); +>a1(...array) : void +>a1 : (...x: (string | number)[]) => void +>...array : number +>array : number[] + +a9([1, 2, [["string"]], false, true]); // Parameter type is [any, any, [[any]]] +>a9([1, 2, [["string"]], false, true]) : void +>a9 : ([a, b, [[c]]]: [any, any, [[any]]]) => void +>[1, 2, [["string"]], false, true] : [number, number, [[string]], boolean, boolean] +>1 : number +>2 : number +>[["string"]] : [[string]] +>["string"] : [string] +>"string" : string +>false : boolean +>true : boolean + +a10([1, 2, [["string"]], false, true]); // Parameter type is any[] +>a10([1, 2, [["string"]], false, true]) : void +>a10 : ([a, b, [[c]], ...x]: Iterable) => void +>[1, 2, [["string"]], false, true] : (number | boolean | string[][])[] +>1 : number +>2 : number +>[["string"]] : string[][] +>["string"] : string[] +>"string" : string +>false : boolean +>true : boolean + +a10([1, 2, 3, false, true]); // Parameter type is any[] +>a10([1, 2, 3, false, true]) : void +>a10 : ([a, b, [[c]], ...x]: Iterable) => void +>[1, 2, 3, false, true] : (number | boolean)[] +>1 : number +>2 : number +>3 : number +>false : boolean +>true : boolean + +a10([1, 2]); // Parameter type is any[] +>a10([1, 2]) : void +>a10 : ([a, b, [[c]], ...x]: Iterable) => void +>[1, 2] : number[] +>1 : number +>2 : number + +a11([1, 2]); // Parameter type is number[] +>a11([1, 2]) : void +>a11 : ([a, b, c, ...x]: number[]) => void +>[1, 2] : number[] +>1 : number +>2 : number + +// Rest parameter with generic +function foo(...a: T[]) { } +>foo : (...a: T[]) => void +>T : T +>a : T[] +>T : T + +foo("hello", 1, 2); +>foo("hello", 1, 2) : void +>foo : (...a: T[]) => void +>"hello" : string +>1 : number +>2 : number + +foo("hello", "world"); +>foo("hello", "world") : void +>foo : (...a: T[]) => void +>"hello" : string +>"world" : string + +enum E { a, b } +>E : E +>a : E +>b : E + +const enum E1 { a, b } +>E1 : E1 +>a : E1 +>b : E1 + +function foo1(...a: T[]) { } +>foo1 : (...a: T[]) => void +>T : T +>Number : Number +>a : T[] +>T : T + +foo1(1, 2, 3, E.a); +>foo1(1, 2, 3, E.a) : void +>foo1 : (...a: T[]) => void +>1 : number +>2 : number +>3 : number +>E.a : E +>E : typeof E +>a : E + +foo1(1, 2, 3, E1.a, E.b); +>foo1(1, 2, 3, E1.a, E.b) : void +>foo1 : (...a: T[]) => void +>1 : number +>2 : number +>3 : number +>E1.a : E1 +>E1 : typeof E1 +>a : E1 +>E.b : E +>E : typeof E +>b : E + + + diff --git a/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt index d5d0888e632..707fb005a80 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt +++ b/tests/baselines/reference/destructuringParameterDeclaration4.errors.txt @@ -1,78 +1,84 @@ -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(46,4): error TS2345: Argument of type '{ y: Class; }' is not assignable to parameter of type '{ y: D; }'. - Types of property 'y' are incompatible. - Type 'Class' is not assignable to type 'D'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(47,4): error TS2345: Argument of type '{}' is not assignable to parameter of type '{ y: D; }'. - Property 'y' is missing in type '{}'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(48,4): error TS2345: Argument of type '{ y: number; }' is not assignable to parameter of type '{ y: D; }'. - Types of property 'y' are incompatible. - Type 'number' is not assignable to type 'D'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(49,4): error TS2345: Argument of type '{ y: string; }' is not assignable to parameter of type '{ y: D; }'. - Types of property 'y' are incompatible. - Type 'string' is not assignable to type 'D'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(11,13): error TS2370: A rest parameter must be of an array type. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(13,13): error TS2370: A rest parameter must be of an array type. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(20,19): error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string | number'. + Type 'boolean' is not assignable to type 'number'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(21,7): error TS2304: Cannot find name 'array2'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(22,4): error TS2345: Argument of type '[number, number, string, boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'. + Types of property '2' are incompatible. + Type 'string' is not assignable to type '[[any]]'. + Property '0' is missing in type 'String'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(23,4): error TS2345: Argument of type '[number, number]' is not assignable to parameter of type '[any, any, [[any]]]'. + Property '2' is missing in type '[number, number]'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(24,4): error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'. + Type 'string | number' is not assignable to type 'number'. + Type 'string' is not assignable to type 'number'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(29,24): error TS1005: ',' expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(34,22): error TS2304: Cannot find name 'E1'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts(34,28): error TS2304: Cannot find name 'E'. -==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts (4 errors) ==== - // Parameter with generic - interface F { } - class Class implements F { - constructor() { } +==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration4.ts (10 errors) ==== + // If the parameter is a rest parameter, the parameter type is any[] + // A type annotation for a rest parameter must denote an array type. + + // RestParameter: + // ... Identifier TypeAnnotation(opt) + + type arrayString = Array + type someArray = Array | number[]; + type stringOrNumArray = Array; + + function a0(...x: [number, number, string]) { } // Error, rest parameter must be array type + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2370: A rest parameter must be of an array type. + function a1(...x: (number|string)[]) { } + function a2(...a: someArray) { } // Error, rest parameter must be array type + ~~~~~~~~~~~~~~~ +!!! error TS2370: A rest parameter must be of an array type. + function a3(...b?) { } // Error, can't be optional + function a4(...b = [1,2,3]) { } // Error, can't have initializer + function a5([a, b, [[c]]]) { } + function a6([a, b, c, ...x]: number[]) { } + + + a1(1, 2, "hello", true); // Error, parameter type is (number|string)[] + ~~~~ +!!! error TS2345: Argument of type 'boolean' is not assignable to parameter of type 'string | number'. +!!! error TS2345: Type 'boolean' is not assignable to type 'number'. + a1(...array2); // Error parameter type is (number|string)[] + ~~~~~~ +!!! error TS2304: Cannot find name 'array2'. + a5([1, 2, "string", false, true]); // Error, parameter type is [any, any, [[any]]] + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '[number, number, string, boolean, boolean]' is not assignable to parameter of type '[any, any, [[any]]]'. +!!! error TS2345: Types of property '2' are incompatible. +!!! error TS2345: Type 'string' is not assignable to type '[[any]]'. +!!! error TS2345: Property '0' is missing in type 'String'. + a5([1, 2]); // Error, parameter type is [any, any, [[any]]] + ~~~~~~ +!!! error TS2345: Argument of type '[number, number]' is not assignable to parameter of type '[any, any, [[any]]]'. +!!! error TS2345: Property '2' is missing in type '[number, number]'. + a6([1, 2, "string"]); // Error, parameter type is number[] + ~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'. +!!! error TS2345: Type 'string | number' is not assignable to type 'number'. +!!! error TS2345: Type 'string' is not assignable to type 'number'. + + + var temp = [1, 2, 3]; + class C { + constructor(public ...temp) { } // Error, rest parameter can't have accessibilityModifier + ~~~ +!!! error TS1005: ',' expected. } - class SubClass extends Class { - foo: boolean; - constructor() { super(); } - } - - class D implements F { - foo: boolean - constructor() { } - } - - class SubD extends D { - bar: number - constructor() { - super(); - } - } + // Rest parameter with generic + function foo1(...a: T[]) { } + foo1(1, 2, "string", E1.a, E.b); // Error + ~~ +!!! error TS2304: Cannot find name 'E1'. + ~ +!!! error TS2304: Cannot find name 'E'. - function d0({x} = { x: new Class() }) { } - function d1({x}: { x: F }) { } - function d2({x}: { x: Class }) { } - function d3({y}: { y: D }) { } - function d4({y} = { y: new D() }) { } - - var obj = new Class(); - d0({ x: 1 }); - d0({ x: {} }); - d0({ x: "string" }); - - d1({ x: new Class() }); - d1({ x: {} }); - d1({ x: "string" }); - - d2({ x: new SubClass() }); - d2({ x: {} }); - - d3({ y: new SubD() }); - d3({ y: new SubClass() }); - // Error - d3({ y: new Class() }); - ~~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '{ y: Class; }' is not assignable to parameter of type '{ y: D; }'. -!!! error TS2345: Types of property 'y' are incompatible. -!!! error TS2345: Type 'Class' is not assignable to type 'D'. - d3({}); - ~~ -!!! error TS2345: Argument of type '{}' is not assignable to parameter of type '{ y: D; }'. -!!! error TS2345: Property 'y' is missing in type '{}'. - d3({ y: 1 }); - ~~~~~~~~ -!!! error TS2345: Argument of type '{ y: number; }' is not assignable to parameter of type '{ y: D; }'. -!!! error TS2345: Types of property 'y' are incompatible. -!!! error TS2345: Type 'number' is not assignable to type 'D'. - d3({ y: "world" }); - ~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '{ y: string; }' is not assignable to parameter of type '{ y: D; }'. -!!! error TS2345: Types of property 'y' are incompatible. -!!! error TS2345: Type 'string' is not assignable to type 'D'. \ No newline at end of file + \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterDeclaration4.js b/tests/baselines/reference/destructuringParameterDeclaration4.js index 3eb0b3f8c19..adc5264e1ff 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration4.js +++ b/tests/baselines/reference/destructuringParameterDeclaration4.js @@ -1,113 +1,101 @@ //// [destructuringParameterDeclaration4.ts] -// Parameter with generic -interface F { } -class Class implements F { - constructor() { } +// If the parameter is a rest parameter, the parameter type is any[] +// A type annotation for a rest parameter must denote an array type. + +// RestParameter: +// ... Identifier TypeAnnotation(opt) + +type arrayString = Array +type someArray = Array | number[]; +type stringOrNumArray = Array; + +function a0(...x: [number, number, string]) { } // Error, rest parameter must be array type +function a1(...x: (number|string)[]) { } +function a2(...a: someArray) { } // Error, rest parameter must be array type +function a3(...b?) { } // Error, can't be optional +function a4(...b = [1,2,3]) { } // Error, can't have initializer +function a5([a, b, [[c]]]) { } +function a6([a, b, c, ...x]: number[]) { } + + +a1(1, 2, "hello", true); // Error, parameter type is (number|string)[] +a1(...array2); // Error parameter type is (number|string)[] +a5([1, 2, "string", false, true]); // Error, parameter type is [any, any, [[any]]] +a5([1, 2]); // Error, parameter type is [any, any, [[any]]] +a6([1, 2, "string"]); // Error, parameter type is number[] + + +var temp = [1, 2, 3]; +class C { + constructor(public ...temp) { } // Error, rest parameter can't have accessibilityModifier } -class SubClass extends Class { - foo: boolean; - constructor() { super(); } -} - -class D implements F { - foo: boolean - constructor() { } -} - -class SubD extends D { - bar: number - constructor() { - super(); - } -} +// Rest parameter with generic +function foo1(...a: T[]) { } +foo1(1, 2, "string", E1.a, E.b); // Error -function d0({x} = { x: new Class() }) { } -function d1({x}: { x: F }) { } -function d2({x}: { x: Class }) { } -function d3({y}: { y: D }) { } -function d4({y} = { y: new D() }) { } - -var obj = new Class(); -d0({ x: 1 }); -d0({ x: {} }); -d0({ x: "string" }); - -d1({ x: new Class() }); -d1({ x: {} }); -d1({ x: "string" }); - -d2({ x: new SubClass() }); -d2({ x: {} }); - -d3({ y: new SubD() }); -d3({ y: new SubClass() }); -// Error -d3({ y: new Class() }); -d3({}); -d3({ y: 1 }); -d3({ y: "world" }); + //// [destructuringParameterDeclaration4.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 Class = (function () { - function Class() { +// If the parameter is a rest parameter, the parameter type is any[] +// A type annotation for a rest parameter must denote an array type. +function a0() { + var x = []; + for (var _i = 0; _i < arguments.length; _i++) { + x[_i - 0] = arguments[_i]; } - return Class; +} // Error, rest parameter must be array type +function a1() { + var x = []; + for (var _i = 0; _i < arguments.length; _i++) { + x[_i - 0] = arguments[_i]; + } +} +function a2() { + var a = []; + for (var _i = 0; _i < arguments.length; _i++) { + a[_i - 0] = arguments[_i]; + } +} // Error, rest parameter must be array type +function a3() { + var b = []; + for (var _i = 0; _i < arguments.length; _i++) { + b[_i - 0] = arguments[_i]; + } +} // Error, can't be optional +function a4() { + var b = []; + for (var _i = 0; _i < arguments.length; _i++) { + b[_i - 0] = arguments[_i]; + } +} // Error, can't have initializer +function a5(_a) { + var a = _a[0], b = _a[1], c = _a[2][0][0]; +} +function a6(_a) { + var a = _a[0], b = _a[1], c = _a[2], x = _a.slice(3); +} +a1(1, 2, "hello", true); // Error, parameter type is (number|string)[] +a1.apply(void 0, array2); // Error parameter type is (number|string)[] +a5([1, 2, "string", false, true]); // Error, parameter type is [any, any, [[any]]] +a5([1, 2]); // Error, parameter type is [any, any, [[any]]] +a6([1, 2, "string"]); // Error, parameter type is number[] +var temp = [1, 2, 3]; +var C = (function () { + function C(public) { + var temp = []; + for (var _i = 1; _i < arguments.length; _i++) { + temp[_i - 1] = arguments[_i]; + } + } // Error, rest parameter can't have accessibilityModifier + return C; })(); -var SubClass = (function (_super) { - __extends(SubClass, _super); - function SubClass() { - _super.call(this); +// Rest parameter with generic +function foo1() { + var a = []; + for (var _i = 0; _i < arguments.length; _i++) { + a[_i - 0] = arguments[_i]; } - return SubClass; -})(Class); -var D = (function () { - function D() { - } - return D; -})(); -var SubD = (function (_super) { - __extends(SubD, _super); - function SubD() { - _super.call(this); - } - return SubD; -})(D); -function d0(_a) { - var x = (_a === void 0 ? { x: new Class() } : _a).x; } -function d1(_a) { - var x = _a.x; -} -function d2(_a) { - var x = _a.x; -} -function d3(_a) { - var y = _a.y; -} -function d4(_a) { - var y = (_a === void 0 ? { y: new D() } : _a).y; -} -var obj = new Class(); -d0({ x: 1 }); -d0({ x: {} }); -d0({ x: "string" }); -d1({ x: new Class() }); -d1({ x: {} }); -d1({ x: "string" }); -d2({ x: new SubClass() }); -d2({ x: {} }); -d3({ y: new SubD() }); -d3({ y: new SubClass() }); -// Error -d3({ y: new Class() }); -d3({}); -d3({ y: 1 }); -d3({ y: "world" }); +foo1(1, 2, "string", E1.a, E.b); // Error diff --git a/tests/baselines/reference/destructuringParameterDeclaration5.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration5.errors.txt new file mode 100644 index 00000000000..c60e2b75c37 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration5.errors.txt @@ -0,0 +1,79 @@ +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration5.ts(47,4): error TS2345: Argument of type '{ y: Class; }' is not assignable to parameter of type '{ y: D; }'. + Types of property 'y' are incompatible. + Type 'Class' is not assignable to type 'D'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration5.ts(48,4): error TS2345: Argument of type '{}' is not assignable to parameter of type '{ y: D; }'. + Property 'y' is missing in type '{}'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration5.ts(49,4): error TS2345: Argument of type '{ y: number; }' is not assignable to parameter of type '{ y: D; }'. + Types of property 'y' are incompatible. + Type 'number' is not assignable to type 'D'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration5.ts(50,4): error TS2345: Argument of type '{ y: string; }' is not assignable to parameter of type '{ y: D; }'. + Types of property 'y' are incompatible. + Type 'string' is not assignable to type 'D'. + + +==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration5.ts (4 errors) ==== + // Parameter Declaration with generic + + interface F { } + class Class implements F { + constructor() { } + } + + class SubClass extends Class { + foo: boolean; + constructor() { super(); } + } + + class D implements F { + foo: boolean + constructor() { } + } + + class SubD extends D { + bar: number + constructor() { + super(); + } + } + + + function d0({x} = { x: new Class() }) { } + function d1({x}: { x: F }) { } + function d2({x}: { x: Class }) { } + function d3({y}: { y: D }) { } + function d4({y} = { y: new D() }) { } + + var obj = new Class(); + d0({ x: 1 }); + d0({ x: {} }); + d0({ x: "string" }); + + d1({ x: new Class() }); + d1({ x: {} }); + d1({ x: "string" }); + + d2({ x: new SubClass() }); + d2({ x: {} }); + + d3({ y: new SubD() }); + d3({ y: new SubClass() }); + // Error + d3({ y: new Class() }); + ~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ y: Class; }' is not assignable to parameter of type '{ y: D; }'. +!!! error TS2345: Types of property 'y' are incompatible. +!!! error TS2345: Type 'Class' is not assignable to type 'D'. + d3({}); + ~~ +!!! error TS2345: Argument of type '{}' is not assignable to parameter of type '{ y: D; }'. +!!! error TS2345: Property 'y' is missing in type '{}'. + d3({ y: 1 }); + ~~~~~~~~ +!!! error TS2345: Argument of type '{ y: number; }' is not assignable to parameter of type '{ y: D; }'. +!!! error TS2345: Types of property 'y' are incompatible. +!!! error TS2345: Type 'number' is not assignable to type 'D'. + d3({ y: "world" }); + ~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '{ y: string; }' is not assignable to parameter of type '{ y: D; }'. +!!! error TS2345: Types of property 'y' are incompatible. +!!! error TS2345: Type 'string' is not assignable to type 'D'. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringParameterDeclaration5.js b/tests/baselines/reference/destructuringParameterDeclaration5.js new file mode 100644 index 00000000000..2dea8224c65 --- /dev/null +++ b/tests/baselines/reference/destructuringParameterDeclaration5.js @@ -0,0 +1,115 @@ +//// [destructuringParameterDeclaration5.ts] +// Parameter Declaration with generic + +interface F { } +class Class implements F { + constructor() { } +} + +class SubClass extends Class { + foo: boolean; + constructor() { super(); } +} + +class D implements F { + foo: boolean + constructor() { } +} + +class SubD extends D { + bar: number + constructor() { + super(); + } +} + + +function d0({x} = { x: new Class() }) { } +function d1({x}: { x: F }) { } +function d2({x}: { x: Class }) { } +function d3({y}: { y: D }) { } +function d4({y} = { y: new D() }) { } + +var obj = new Class(); +d0({ x: 1 }); +d0({ x: {} }); +d0({ x: "string" }); + +d1({ x: new Class() }); +d1({ x: {} }); +d1({ x: "string" }); + +d2({ x: new SubClass() }); +d2({ x: {} }); + +d3({ y: new SubD() }); +d3({ y: new SubClass() }); +// Error +d3({ y: new Class() }); +d3({}); +d3({ y: 1 }); +d3({ y: "world" }); + +//// [destructuringParameterDeclaration5.js] +// Parameter Declaration with generic +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 Class = (function () { + function Class() { + } + return Class; +})(); +var SubClass = (function (_super) { + __extends(SubClass, _super); + function SubClass() { + _super.call(this); + } + return SubClass; +})(Class); +var D = (function () { + function D() { + } + return D; +})(); +var SubD = (function (_super) { + __extends(SubD, _super); + function SubD() { + _super.call(this); + } + return SubD; +})(D); +function d0(_a) { + var x = (_a === void 0 ? { x: new Class() } : _a).x; +} +function d1(_a) { + var x = _a.x; +} +function d2(_a) { + var x = _a.x; +} +function d3(_a) { + var y = _a.y; +} +function d4(_a) { + var y = (_a === void 0 ? { y: new D() } : _a).y; +} +var obj = new Class(); +d0({ x: 1 }); +d0({ x: {} }); +d0({ x: "string" }); +d1({ x: new Class() }); +d1({ x: {} }); +d1({ x: "string" }); +d2({ x: new SubClass() }); +d2({ x: {} }); +d3({ y: new SubD() }); +d3({ y: new SubClass() }); +// Error +d3({ y: new Class() }); +d3({}); +d3({ y: 1 }); +d3({ y: "world" }); diff --git a/tests/baselines/reference/destructuringParameterDeclaration3.errors.txt b/tests/baselines/reference/destructuringParameterDeclaration6.errors.txt similarity index 75% rename from tests/baselines/reference/destructuringParameterDeclaration3.errors.txt rename to tests/baselines/reference/destructuringParameterDeclaration6.errors.txt index 57777582731..e96f279b7e9 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration3.errors.txt +++ b/tests/baselines/reference/destructuringParameterDeclaration6.errors.txt @@ -1,16 +1,16 @@ -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts(9,14): error TS1181: Array element destructuring pattern expected. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts(9,19): error TS1005: '(' expected. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts(9,21): error TS1109: Expression expected. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts(9,24): error TS1005: '(' expected. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts(9,26): error TS2304: Cannot find name 'public'. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts(9,32): error TS1005: ';' expected. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts(9,33): error TS1128: Declaration or statement expected. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts(10,16): error TS1003: Identifier expected. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts(10,21): error TS1005: '(' expected. -tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts(12,13): error TS2370: A rest parameter must be of an array type. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration6.ts(9,14): error TS1181: Array element destructuring pattern expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration6.ts(9,19): error TS1005: '(' expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration6.ts(9,21): error TS1109: Expression expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration6.ts(9,24): error TS1005: '(' expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration6.ts(9,26): error TS2304: Cannot find name 'public'. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration6.ts(9,32): error TS1005: ';' expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration6.ts(9,33): error TS1128: Declaration or statement expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration6.ts(10,16): error TS1003: Identifier expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration6.ts(10,21): error TS1005: '(' expected. +tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration6.ts(12,13): error TS2370: A rest parameter must be of an array type. -==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration3.ts (10 errors) ==== +==== tests/cases/conformance/es6/destructuring/destructuringParameterDeclaration6.ts (10 errors) ==== // A parameter declaration may specify either an identifier or a binding pattern. // Reserved words are not allowed to be used as an identifier in parameter declaration diff --git a/tests/baselines/reference/destructuringParameterDeclaration3.js b/tests/baselines/reference/destructuringParameterDeclaration6.js similarity index 90% rename from tests/baselines/reference/destructuringParameterDeclaration3.js rename to tests/baselines/reference/destructuringParameterDeclaration6.js index a1abb86bd63..ff6662c4e86 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration3.js +++ b/tests/baselines/reference/destructuringParameterDeclaration6.js @@ -1,4 +1,4 @@ -//// [destructuringParameterDeclaration3.ts] +//// [destructuringParameterDeclaration6.ts] // A parameter declaration may specify either an identifier or a binding pattern. // Reserved words are not allowed to be used as an identifier in parameter declaration @@ -21,7 +21,7 @@ b2({ while: 1 }); -//// [destructuringParameterDeclaration3.js] +//// [destructuringParameterDeclaration6.js] // A parameter declaration may specify either an identifier or a binding pattern. // Reserved words are not allowed to be used as an identifier in parameter declaration "use strict"; From 6d9c1f4c4ae7820b9c69caee21ba6bf6cb237ae4 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 16 Apr 2015 15:39:12 -0700 Subject: [PATCH 036/194] Add spec description into tests --- .../functionExpressionContextualTyping1.js | 132 +++++--- .../functionExpressionContextualTyping1.types | 301 ++++++++++-------- ...tionExpressionContextualTyping2.errors.txt | 45 +-- .../functionExpressionContextualTyping2.js | 52 ++- .../functionExpressionContextualTyping1.ts | 64 ++-- .../functionExpressionContextualTyping2.ts | 23 +- 6 files changed, 347 insertions(+), 270 deletions(-) diff --git a/tests/baselines/reference/functionExpressionContextualTyping1.js b/tests/baselines/reference/functionExpressionContextualTyping1.js index 6e528a5aedc..8d60572b30f 100644 --- a/tests/baselines/reference/functionExpressionContextualTyping1.js +++ b/tests/baselines/reference/functionExpressionContextualTyping1.js @@ -1,29 +1,53 @@ //// [functionExpressionContextualTyping1.ts] +// When a function expression with no type parameters and no parameter type annotations +// is contextually typed (section 4.19) by a type T and a contextual signature S can be extracted from T + enum E { red, blue } -var g0: (n: number, s:string) => number; -var g: ((s: string, w: boolean) => void) | ((n: number) => number); -var g1: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); +// A contextual signature S is extracted from a function type T as follows: +// If T is a function type with exactly one call signature, and if that call signature is non- generic, S is that signature. -g1 = (j, m) => { } // Per spec, no contextual signature can be extracted in this case. -g = (k, h=true) => { k.toLowerCase() }; -g = (k) => { k.toLowerCase() }; -g = (i) => { +var a0: (n: number, s: string) => number = (num, str) => { + num.toExponential(); + return 0; +} + +class Class { + foo() { } +} + +var a1: (c: Class) => number = (a1) => { + a1.foo(); + return 1; +} + +// A contextual signature S is extracted from a function type T as follows: +// If T is a union type, let U be the set of element types in T that have call signatures. +// If each type in U has exactly one call signature and that call signature is non- generic, +// and if all of the signatures are identical ignoring return types, +// then S is a signature with the same parameters and a union of the return types. +var b1: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); +b1 = (k, h) => { }; +var b2: typeof a0 | ((n: number, s: string) => string); +b2 = (foo, bar) => { return foo + 1; } +b2 = (foo, bar) => { return "hello"; } +var b3: (name: string, num: number, boo: boolean) => void; +b3 = (name, number) => { }; + +var b4: (n: E) => string = (number = 1) => { return "hello"; }; +var b5: (n: {}) => string = (number = "string") => { return "hello"; }; + +// A contextual signature S is extracted from a function type T as follows: +// Otherwise, no contextual signature can be extracted from T and S is undefined. +var b6: ((s: string, w: boolean) => void) | ((n: number) => number); +var b7: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); +b6 = (k) => { k.toLowerCase() }; +b6 = (i) => { i.toExponential(); return i; -}; // Per spec, no contextual signature can be extracted in this case. +}; // Per spec, no contextual signature can be extracted in this case. (Otherwise clause) +b7 = (j, m) => { }; // Per spec, no contextual signature can be extracted in this case. (Otherwise clause) -var h: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); -h = (k, h) => { }; - -var i: typeof g0 | ((n: number, s: string) => string); -i = (foo, bar) => { return foo + 1; } -i = (foo, bar) => { return "hello"; } -var j: (name: string, num: number, boo: boolean) => void; -j = (name, number) => { }; - -var k: (n: E) => string = (number = 1) => { return "hello"; }; -var k1: (n: {}) => string = (number = 1) => { return "hello"; }; class C { constructor() { var k: ((j: T, k: U) => (T|U)[]) | ((j: number,k :U) => number[]) = (j, k) => { @@ -33,39 +57,59 @@ class C { } //// [functionExpressionContextualTyping1.js] +// When a function expression with no type parameters and no parameter type annotations +// is contextually typed (section 4.19) by a type T and a contextual signature S can be extracted from T var E; (function (E) { E[E["red"] = 0] = "red"; E[E["blue"] = 1] = "blue"; })(E || (E = {})); -var g0; -var g; -var g1; -g1 = function (j, m) { }; // Per spec, no contextual signature can be extracted in this case. -g = function (k, h) { - if (h === void 0) { h = true; } - k.toLowerCase(); +// A contextual signature S is extracted from a function type T as follows: +// If T is a function type with exactly one call signature, and if that call signature is non- generic, S is that signature. +var a0 = function (num, str) { + num.toExponential(); + return 0; }; -g = function (k) { k.toLowerCase(); }; -g = function (i) { +var Class = (function () { + function Class() { + } + Class.prototype.foo = function () { }; + return Class; +})(); +var a1 = function (a1) { + a1.foo(); + return 1; +}; +// A contextual signature S is extracted from a function type T as follows: +// If T is a union type, let U be the set of element types in T that have call signatures. +// If each type in U has exactly one call signature and that call signature is non- generic, +// and if all of the signatures are identical ignoring return types, +// then S is a signature with the same parameters and a union of the return types. +var b1; +b1 = function (k, h) { }; +var b2; +b2 = function (foo, bar) { return foo + 1; }; +b2 = function (foo, bar) { return "hello"; }; +var b3; +b3 = function (name, number) { }; +var b4 = function (number) { + if (number === void 0) { number = 1; } + return "hello"; +}; +var b5 = function (number) { + if (number === void 0) { number = "string"; } + return "hello"; +}; +// A contextual signature S is extracted from a function type T as follows: +// Otherwise, no contextual signature can be extracted from T and S is undefined. +var b6; +var b7; +b6 = function (k) { k.toLowerCase(); }; +b6 = function (i) { i.toExponential(); return i; -}; // Per spec, no contextual signature can be extracted in this case. -var h; -h = function (k, h) { }; -var i; -i = function (foo, bar) { return foo + 1; }; -i = function (foo, bar) { return "hello"; }; -var j; -j = function (name, number) { }; -var k = function (number) { - if (number === void 0) { number = 1; } - return "hello"; -}; -var k1 = function (number) { - if (number === void 0) { number = 1; } - return "hello"; -}; +}; // Per spec, no contextual signature can be extracted in this case. (Otherwise clause) +b7 = function (j, m) { }; // Per spec, no contextual signature can be extracted in this case. (Otherwise clause) var C = (function () { function C() { var k = function (j, k) { diff --git a/tests/baselines/reference/functionExpressionContextualTyping1.types b/tests/baselines/reference/functionExpressionContextualTyping1.types index 3a1ce95bb99..f7f04d5ed0f 100644 --- a/tests/baselines/reference/functionExpressionContextualTyping1.types +++ b/tests/baselines/reference/functionExpressionContextualTyping1.types @@ -1,166 +1,205 @@ === tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts === +// When a function expression with no type parameters and no parameter type annotations +// is contextually typed (section 4.19) by a type T and a contextual signature S can be extracted from T + enum E { red, blue } >E : E, Symbol(E, Decl(functionExpressionContextualTyping1.ts, 0, 0)) ->red : E, Symbol(E.red, Decl(functionExpressionContextualTyping1.ts, 0, 8)) ->blue : E, Symbol(E.blue, Decl(functionExpressionContextualTyping1.ts, 0, 13)) +>red : E, Symbol(E.red, Decl(functionExpressionContextualTyping1.ts, 3, 8)) +>blue : E, Symbol(E.blue, Decl(functionExpressionContextualTyping1.ts, 3, 13)) -var g0: (n: number, s:string) => number; ->g0 : (n: number, s: string) => number, Symbol(g0, Decl(functionExpressionContextualTyping1.ts, 2, 3)) ->n : number, Symbol(n, Decl(functionExpressionContextualTyping1.ts, 2, 9)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 2, 19)) +// A contextual signature S is extracted from a function type T as follows: +// If T is a function type with exactly one call signature, and if that call signature is non- generic, S is that signature. -var g: ((s: string, w: boolean) => void) | ((n: number) => number); ->g : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(g, Decl(functionExpressionContextualTyping1.ts, 3, 3)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 3, 9)) ->w : boolean, Symbol(w, Decl(functionExpressionContextualTyping1.ts, 3, 19)) ->n : number, Symbol(n, Decl(functionExpressionContextualTyping1.ts, 3, 45)) +var a0: (n: number, s: string) => number = (num, str) => { +>a0 : (n: number, s: string) => number, Symbol(a0, Decl(functionExpressionContextualTyping1.ts, 8, 3)) +>n : number, Symbol(n, Decl(functionExpressionContextualTyping1.ts, 8, 9)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 8, 19)) +>(num, str) => { num.toExponential(); return 0;} : (num: number, str: string) => number +>num : number, Symbol(num, Decl(functionExpressionContextualTyping1.ts, 8, 44)) +>str : string, Symbol(str, Decl(functionExpressionContextualTyping1.ts, 8, 48)) -var g1: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); ->g1 : ((s: string, w: boolean) => void) | ((s: string, w: number) => string), Symbol(g1, Decl(functionExpressionContextualTyping1.ts, 4, 3)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 4, 10)) ->w : boolean, Symbol(w, Decl(functionExpressionContextualTyping1.ts, 4, 20)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 4, 46)) ->w : number, Symbol(w, Decl(functionExpressionContextualTyping1.ts, 4, 56)) + num.toExponential(); +>num.toExponential() : string +>num.toExponential : (fractionDigits?: number) => string, Symbol(Number.toExponential, Decl(lib.d.ts, 469, 45)) +>num : number, Symbol(num, Decl(functionExpressionContextualTyping1.ts, 8, 44)) +>toExponential : (fractionDigits?: number) => string, Symbol(Number.toExponential, Decl(lib.d.ts, 469, 45)) -g1 = (j, m) => { } // Per spec, no contextual signature can be extracted in this case. ->g1 = (j, m) => { } : (j: any, m: any) => void ->g1 : ((s: string, w: boolean) => void) | ((s: string, w: number) => string), Symbol(g1, Decl(functionExpressionContextualTyping1.ts, 4, 3)) ->(j, m) => { } : (j: any, m: any) => void ->j : any, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 6, 6)) ->m : any, Symbol(m, Decl(functionExpressionContextualTyping1.ts, 6, 8)) + return 0; +>0 : number +} -g = (k, h=true) => { k.toLowerCase() }; ->g = (k, h=true) => { k.toLowerCase() } : (k: any, h?: boolean) => void ->g : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(g, Decl(functionExpressionContextualTyping1.ts, 3, 3)) ->(k, h=true) => { k.toLowerCase() } : (k: any, h?: boolean) => void ->k : any, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 7, 5)) ->h : boolean, Symbol(h, Decl(functionExpressionContextualTyping1.ts, 7, 7)) ->true : boolean ->k.toLowerCase() : any ->k.toLowerCase : any ->k : any, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 7, 5)) ->toLowerCase : any +class Class { +>Class : Class, Symbol(Class, Decl(functionExpressionContextualTyping1.ts, 11, 1)) +>T : T, Symbol(T, Decl(functionExpressionContextualTyping1.ts, 13, 12)) -g = (k) => { k.toLowerCase() }; ->g = (k) => { k.toLowerCase() } : (k: any) => void ->g : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(g, Decl(functionExpressionContextualTyping1.ts, 3, 3)) + foo() { } +>foo : () => void, Symbol(foo, Decl(functionExpressionContextualTyping1.ts, 13, 16)) +} + +var a1: (c: Class) => number = (a1) => { +>a1 : (c: Class) => number, Symbol(a1, Decl(functionExpressionContextualTyping1.ts, 17, 3)) +>c : Class, Symbol(c, Decl(functionExpressionContextualTyping1.ts, 17, 9)) +>Class : Class, Symbol(Class, Decl(functionExpressionContextualTyping1.ts, 11, 1)) +>Number : Number, Symbol(Number, Decl(lib.d.ts, 456, 40), Decl(lib.d.ts, 518, 11)) +>(a1) => { a1.foo(); return 1;} : (a1: Class) => number +>a1 : Class, Symbol(a1, Decl(functionExpressionContextualTyping1.ts, 17, 40)) + + a1.foo(); +>a1.foo() : void +>a1.foo : () => void, Symbol(Class.foo, Decl(functionExpressionContextualTyping1.ts, 13, 16)) +>a1 : Class, Symbol(a1, Decl(functionExpressionContextualTyping1.ts, 17, 40)) +>foo : () => void, Symbol(Class.foo, Decl(functionExpressionContextualTyping1.ts, 13, 16)) + + return 1; +>1 : number +} + +// A contextual signature S is extracted from a function type T as follows: +// If T is a union type, let U be the set of element types in T that have call signatures. +// If each type in U has exactly one call signature and that call signature is non- generic, +// and if all of the signatures are identical ignoring return types, +// then S is a signature with the same parameters and a union of the return types. +var b1: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); +>b1 : ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string), Symbol(b1, Decl(functionExpressionContextualTyping1.ts, 27, 3)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 27, 10)) +>w : boolean, Symbol(w, Decl(functionExpressionContextualTyping1.ts, 27, 20)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 27, 46)) +>w : boolean, Symbol(w, Decl(functionExpressionContextualTyping1.ts, 27, 56)) + +b1 = (k, h) => { }; +>b1 = (k, h) => { } : (k: string, h: boolean) => void +>b1 : ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string), Symbol(b1, Decl(functionExpressionContextualTyping1.ts, 27, 3)) +>(k, h) => { } : (k: string, h: boolean) => void +>k : string, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 28, 6)) +>h : boolean, Symbol(h, Decl(functionExpressionContextualTyping1.ts, 28, 8)) + +var b2: typeof a0 | ((n: number, s: string) => string); +>b2 : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(b2, Decl(functionExpressionContextualTyping1.ts, 29, 3)) +>a0 : (n: number, s: string) => number, Symbol(a0, Decl(functionExpressionContextualTyping1.ts, 8, 3)) +>n : number, Symbol(n, Decl(functionExpressionContextualTyping1.ts, 29, 22)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 29, 32)) + +b2 = (foo, bar) => { return foo + 1; } +>b2 = (foo, bar) => { return foo + 1; } : (foo: number, bar: string) => number +>b2 : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(b2, Decl(functionExpressionContextualTyping1.ts, 29, 3)) +>(foo, bar) => { return foo + 1; } : (foo: number, bar: string) => number +>foo : number, Symbol(foo, Decl(functionExpressionContextualTyping1.ts, 30, 6)) +>bar : string, Symbol(bar, Decl(functionExpressionContextualTyping1.ts, 30, 10)) +>foo + 1 : number +>foo : number, Symbol(foo, Decl(functionExpressionContextualTyping1.ts, 30, 6)) +>1 : number + +b2 = (foo, bar) => { return "hello"; } +>b2 = (foo, bar) => { return "hello"; } : (foo: number, bar: string) => string +>b2 : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(b2, Decl(functionExpressionContextualTyping1.ts, 29, 3)) +>(foo, bar) => { return "hello"; } : (foo: number, bar: string) => string +>foo : number, Symbol(foo, Decl(functionExpressionContextualTyping1.ts, 31, 6)) +>bar : string, Symbol(bar, Decl(functionExpressionContextualTyping1.ts, 31, 10)) +>"hello" : string + +var b3: (name: string, num: number, boo: boolean) => void; +>b3 : (name: string, num: number, boo: boolean) => void, Symbol(b3, Decl(functionExpressionContextualTyping1.ts, 32, 3)) +>name : string, Symbol(name, Decl(functionExpressionContextualTyping1.ts, 32, 9)) +>num : number, Symbol(num, Decl(functionExpressionContextualTyping1.ts, 32, 22)) +>boo : boolean, Symbol(boo, Decl(functionExpressionContextualTyping1.ts, 32, 35)) + +b3 = (name, number) => { }; +>b3 = (name, number) => { } : (name: string, number: number) => void +>b3 : (name: string, num: number, boo: boolean) => void, Symbol(b3, Decl(functionExpressionContextualTyping1.ts, 32, 3)) +>(name, number) => { } : (name: string, number: number) => void +>name : string, Symbol(name, Decl(functionExpressionContextualTyping1.ts, 33, 6)) +>number : number, Symbol(number, Decl(functionExpressionContextualTyping1.ts, 33, 11)) + +var b4: (n: E) => string = (number = 1) => { return "hello"; }; +>b4 : (n: E) => string, Symbol(b4, Decl(functionExpressionContextualTyping1.ts, 35, 3)) +>n : E, Symbol(n, Decl(functionExpressionContextualTyping1.ts, 35, 9)) +>E : E, Symbol(E, Decl(functionExpressionContextualTyping1.ts, 0, 0)) +>(number = 1) => { return "hello"; } : (number?: E) => string +>number : E, Symbol(number, Decl(functionExpressionContextualTyping1.ts, 35, 28)) +>1 : number +>"hello" : string + +var b5: (n: {}) => string = (number = "string") => { return "hello"; }; +>b5 : (n: {}) => string, Symbol(b5, Decl(functionExpressionContextualTyping1.ts, 36, 3)) +>n : {}, Symbol(n, Decl(functionExpressionContextualTyping1.ts, 36, 9)) +>(number = "string") => { return "hello"; } : (number?: {}) => string +>number : {}, Symbol(number, Decl(functionExpressionContextualTyping1.ts, 36, 29)) +>"string" : string +>"hello" : string + +// A contextual signature S is extracted from a function type T as follows: +// Otherwise, no contextual signature can be extracted from T and S is undefined. +var b6: ((s: string, w: boolean) => void) | ((n: number) => number); +>b6 : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(b6, Decl(functionExpressionContextualTyping1.ts, 40, 3)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 40, 10)) +>w : boolean, Symbol(w, Decl(functionExpressionContextualTyping1.ts, 40, 20)) +>n : number, Symbol(n, Decl(functionExpressionContextualTyping1.ts, 40, 46)) + +var b7: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); +>b7 : ((s: string, w: boolean) => void) | ((s: string, w: number) => string), Symbol(b7, Decl(functionExpressionContextualTyping1.ts, 41, 3)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 41, 10)) +>w : boolean, Symbol(w, Decl(functionExpressionContextualTyping1.ts, 41, 20)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 41, 46)) +>w : number, Symbol(w, Decl(functionExpressionContextualTyping1.ts, 41, 56)) + +b6 = (k) => { k.toLowerCase() }; +>b6 = (k) => { k.toLowerCase() } : (k: any) => void +>b6 : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(b6, Decl(functionExpressionContextualTyping1.ts, 40, 3)) >(k) => { k.toLowerCase() } : (k: any) => void ->k : any, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 8, 5)) +>k : any, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 42, 6)) >k.toLowerCase() : any >k.toLowerCase : any ->k : any, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 8, 5)) +>k : any, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 42, 6)) >toLowerCase : any -g = (i) => { ->g = (i) => { i.toExponential(); return i;} : (i: any) => any ->g : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(g, Decl(functionExpressionContextualTyping1.ts, 3, 3)) +b6 = (i) => { +>b6 = (i) => { i.toExponential(); return i;} : (i: any) => any +>b6 : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(b6, Decl(functionExpressionContextualTyping1.ts, 40, 3)) >(i) => { i.toExponential(); return i;} : (i: any) => any ->i : any, Symbol(i, Decl(functionExpressionContextualTyping1.ts, 9, 5)) +>i : any, Symbol(i, Decl(functionExpressionContextualTyping1.ts, 43, 6)) i.toExponential(); >i.toExponential() : any >i.toExponential : any ->i : any, Symbol(i, Decl(functionExpressionContextualTyping1.ts, 9, 5)) +>i : any, Symbol(i, Decl(functionExpressionContextualTyping1.ts, 43, 6)) >toExponential : any return i; ->i : any, Symbol(i, Decl(functionExpressionContextualTyping1.ts, 9, 5)) +>i : any, Symbol(i, Decl(functionExpressionContextualTyping1.ts, 43, 6)) -}; // Per spec, no contextual signature can be extracted in this case. - -var h: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); ->h : ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string), Symbol(h, Decl(functionExpressionContextualTyping1.ts, 14, 3)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 14, 9)) ->w : boolean, Symbol(w, Decl(functionExpressionContextualTyping1.ts, 14, 19)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 14, 45)) ->w : boolean, Symbol(w, Decl(functionExpressionContextualTyping1.ts, 14, 55)) - -h = (k, h) => { }; ->h = (k, h) => { } : (k: string, h: boolean) => void ->h : ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string), Symbol(h, Decl(functionExpressionContextualTyping1.ts, 14, 3)) ->(k, h) => { } : (k: string, h: boolean) => void ->k : string, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 15, 5)) ->h : boolean, Symbol(h, Decl(functionExpressionContextualTyping1.ts, 15, 7)) - -var i: typeof g0 | ((n: number, s: string) => string); ->i : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(i, Decl(functionExpressionContextualTyping1.ts, 17, 3)) ->g0 : (n: number, s: string) => number, Symbol(g0, Decl(functionExpressionContextualTyping1.ts, 2, 3)) ->n : number, Symbol(n, Decl(functionExpressionContextualTyping1.ts, 17, 21)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 17, 31)) - -i = (foo, bar) => { return foo + 1; } ->i = (foo, bar) => { return foo + 1; } : (foo: number, bar: string) => number ->i : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(i, Decl(functionExpressionContextualTyping1.ts, 17, 3)) ->(foo, bar) => { return foo + 1; } : (foo: number, bar: string) => number ->foo : number, Symbol(foo, Decl(functionExpressionContextualTyping1.ts, 18, 5)) ->bar : string, Symbol(bar, Decl(functionExpressionContextualTyping1.ts, 18, 9)) ->foo + 1 : number ->foo : number, Symbol(foo, Decl(functionExpressionContextualTyping1.ts, 18, 5)) ->1 : number - -i = (foo, bar) => { return "hello"; } ->i = (foo, bar) => { return "hello"; } : (foo: number, bar: string) => string ->i : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(i, Decl(functionExpressionContextualTyping1.ts, 17, 3)) ->(foo, bar) => { return "hello"; } : (foo: number, bar: string) => string ->foo : number, Symbol(foo, Decl(functionExpressionContextualTyping1.ts, 19, 5)) ->bar : string, Symbol(bar, Decl(functionExpressionContextualTyping1.ts, 19, 9)) ->"hello" : string - -var j: (name: string, num: number, boo: boolean) => void; ->j : (name: string, num: number, boo: boolean) => void, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 20, 3)) ->name : string, Symbol(name, Decl(functionExpressionContextualTyping1.ts, 20, 8)) ->num : number, Symbol(num, Decl(functionExpressionContextualTyping1.ts, 20, 21)) ->boo : boolean, Symbol(boo, Decl(functionExpressionContextualTyping1.ts, 20, 34)) - -j = (name, number) => { }; ->j = (name, number) => { } : (name: string, number: number) => void ->j : (name: string, num: number, boo: boolean) => void, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 20, 3)) ->(name, number) => { } : (name: string, number: number) => void ->name : string, Symbol(name, Decl(functionExpressionContextualTyping1.ts, 21, 5)) ->number : number, Symbol(number, Decl(functionExpressionContextualTyping1.ts, 21, 10)) - -var k: (n: E) => string = (number = 1) => { return "hello"; }; ->k : (n: E) => string, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 23, 3)) ->n : E, Symbol(n, Decl(functionExpressionContextualTyping1.ts, 23, 8)) ->E : E, Symbol(E, Decl(functionExpressionContextualTyping1.ts, 0, 0)) ->(number = 1) => { return "hello"; } : (number?: E) => string ->number : E, Symbol(number, Decl(functionExpressionContextualTyping1.ts, 23, 27)) ->1 : number ->"hello" : string - -var k1: (n: {}) => string = (number = 1) => { return "hello"; }; ->k1 : (n: {}) => string, Symbol(k1, Decl(functionExpressionContextualTyping1.ts, 24, 3)) ->n : {}, Symbol(n, Decl(functionExpressionContextualTyping1.ts, 24, 9)) ->(number = 1) => { return "hello"; } : (number?: {}) => string ->number : {}, Symbol(number, Decl(functionExpressionContextualTyping1.ts, 24, 29)) ->1 : number ->"hello" : string +}; // Per spec, no contextual signature can be extracted in this case. (Otherwise clause) +b7 = (j, m) => { }; // Per spec, no contextual signature can be extracted in this case. (Otherwise clause) +>b7 = (j, m) => { } : (j: any, m: any) => void +>b7 : ((s: string, w: boolean) => void) | ((s: string, w: number) => string), Symbol(b7, Decl(functionExpressionContextualTyping1.ts, 41, 3)) +>(j, m) => { } : (j: any, m: any) => void +>j : any, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 47, 6)) +>m : any, Symbol(m, Decl(functionExpressionContextualTyping1.ts, 47, 8)) class C { ->C : C, Symbol(C, Decl(functionExpressionContextualTyping1.ts, 24, 64)) ->T : T, Symbol(T, Decl(functionExpressionContextualTyping1.ts, 25, 8)) ->U : U, Symbol(U, Decl(functionExpressionContextualTyping1.ts, 25, 10)) +>C : C, Symbol(C, Decl(functionExpressionContextualTyping1.ts, 47, 19)) +>T : T, Symbol(T, Decl(functionExpressionContextualTyping1.ts, 49, 8)) +>U : U, Symbol(U, Decl(functionExpressionContextualTyping1.ts, 49, 10)) constructor() { var k: ((j: T, k: U) => (T|U)[]) | ((j: number,k :U) => number[]) = (j, k) => { ->k : ((j: T, k: U) => (T | U)[]) | ((j: number, k: U) => number[]), Symbol(k, Decl(functionExpressionContextualTyping1.ts, 27, 11)) ->j : T, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 27, 17)) ->T : T, Symbol(T, Decl(functionExpressionContextualTyping1.ts, 25, 8)) ->k : U, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 27, 22)) ->U : U, Symbol(U, Decl(functionExpressionContextualTyping1.ts, 25, 10)) ->T : T, Symbol(T, Decl(functionExpressionContextualTyping1.ts, 25, 8)) ->U : U, Symbol(U, Decl(functionExpressionContextualTyping1.ts, 25, 10)) ->j : number, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 27, 45)) ->k : U, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 27, 55)) ->U : U, Symbol(U, Decl(functionExpressionContextualTyping1.ts, 25, 10)) +>k : ((j: T, k: U) => (T | U)[]) | ((j: number, k: U) => number[]), Symbol(k, Decl(functionExpressionContextualTyping1.ts, 51, 11)) +>j : T, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 51, 17)) +>T : T, Symbol(T, Decl(functionExpressionContextualTyping1.ts, 49, 8)) +>k : U, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 51, 22)) +>U : U, Symbol(U, Decl(functionExpressionContextualTyping1.ts, 49, 10)) +>T : T, Symbol(T, Decl(functionExpressionContextualTyping1.ts, 49, 8)) +>U : U, Symbol(U, Decl(functionExpressionContextualTyping1.ts, 49, 10)) +>j : number, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 51, 45)) +>k : U, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 51, 55)) +>U : U, Symbol(U, Decl(functionExpressionContextualTyping1.ts, 49, 10)) >(j, k) => { return [j, k]; } : (j: any, k: any) => any[] ->j : any, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 27, 77)) ->k : any, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 27, 79)) +>j : any, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 51, 77)) +>k : any, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 51, 79)) return [j, k]; >[j, k] : any[] ->j : any, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 27, 77)) ->k : any, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 27, 79)) +>j : any, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 51, 77)) +>k : any, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 51, 79)) } // Per spec, no contextual signature can be extracted in this case. } diff --git a/tests/baselines/reference/functionExpressionContextualTyping2.errors.txt b/tests/baselines/reference/functionExpressionContextualTyping2.errors.txt index d9622c50e42..6a3a7998f09 100644 --- a/tests/baselines/reference/functionExpressionContextualTyping2.errors.txt +++ b/tests/baselines/reference/functionExpressionContextualTyping2.errors.txt @@ -1,36 +1,21 @@ -tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts(3,1): error TS2322: Type '(foo: number, bar: string) => boolean' is not assignable to type '((n: number, s: string) => number) | ((n: number, s: string) => string)'. +tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts(11,1): error TS2322: Type '(foo: number, bar: string) => boolean' is not assignable to type '((n: number, s: string) => number) | ((n: number, s: string) => string)'. Type '(foo: number, bar: string) => boolean' is not assignable to type '(n: number, s: string) => string'. Type 'boolean' is not assignable to type 'string'. -tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts(5,7): error TS2300: Duplicate identifier 'C'. -tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts(8,7): error TS2300: Duplicate identifier 'C'. -tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts(10,43): error TS2322: Type 'number' is not assignable to type 'T'. -tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts(10,50): error TS2322: Type 'number' is not assignable to type 'U'. -==== tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts (5 errors) ==== - var g0: (n: number, s: string) => number - var i: typeof g0 | ((n: number, s: string) => string); - i = (foo, bar) => { return true; } - ~ +==== tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts (1 errors) ==== + // A contextual signature S is extracted from a function type T as follows: + // If T is a function type with exactly one call signature, and if that call signature is non- generic, S is that signature. + // If T is a union type, let U be the set of element types in T that have call signatures. + // If each type in U has exactly one call signature and that call signature is non- generic, + // and if all of the signatures are identical ignoring return types, then S is a signature + // with the same parameters and a union of the return types. + // Otherwise, no contextual signature can be extracted from T and S is undefined. + + var a0: (n: number, s: string) => number + var a1: typeof a0 | ((n: number, s: string) => string); + a1 = (foo, bar) => { return true; } // Error + ~~ !!! error TS2322: Type '(foo: number, bar: string) => boolean' is not assignable to type '((n: number, s: string) => number) | ((n: number, s: string) => string)'. !!! error TS2322: Type '(foo: number, bar: string) => boolean' is not assignable to type '(n: number, s: string) => string'. -!!! error TS2322: Type 'boolean' is not assignable to type 'string'. - - class C { } - ~ -!!! error TS2300: Duplicate identifier 'C'. - - var j: (c: C) => number = (j) => { return 1; } - class C { - ~ -!!! error TS2300: Duplicate identifier 'C'. - constructor() { - var k: (j: T, k: U) => (T|U)[] = (j = 1, k = 0) => { - ~~~~~ -!!! error TS2322: Type 'number' is not assignable to type 'T'. - ~~~~~ -!!! error TS2322: Type 'number' is not assignable to type 'U'. - return [j, k]; - } - } - } \ No newline at end of file +!!! error TS2322: Type 'boolean' is not assignable to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/functionExpressionContextualTyping2.js b/tests/baselines/reference/functionExpressionContextualTyping2.js index 87d3e1ed9ef..dae30a79036 100644 --- a/tests/baselines/reference/functionExpressionContextualTyping2.js +++ b/tests/baselines/reference/functionExpressionContextualTyping2.js @@ -1,36 +1,24 @@ //// [functionExpressionContextualTyping2.ts] -var g0: (n: number, s: string) => number -var i: typeof g0 | ((n: number, s: string) => string); -i = (foo, bar) => { return true; } +// A contextual signature S is extracted from a function type T as follows: +// If T is a function type with exactly one call signature, and if that call signature is non- generic, S is that signature. +// If T is a union type, let U be the set of element types in T that have call signatures. +// If each type in U has exactly one call signature and that call signature is non- generic, +// and if all of the signatures are identical ignoring return types, then S is a signature +// with the same parameters and a union of the return types. +// Otherwise, no contextual signature can be extracted from T and S is undefined. -class C { } - -var j: (c: C) => number = (j) => { return 1; } -class C { - constructor() { - var k: (j: T, k: U) => (T|U)[] = (j = 1, k = 0) => { - return [j, k]; - } - } -} +var a0: (n: number, s: string) => number +var a1: typeof a0 | ((n: number, s: string) => string); +a1 = (foo, bar) => { return true; } // Error //// [functionExpressionContextualTyping2.js] -var g0; -var i; -i = function (foo, bar) { return true; }; -var C = (function () { - function C() { - } - return C; -})(); -var j = function (j) { return 1; }; -var C = (function () { - function C() { - var k = function (j, k) { - if (j === void 0) { j = 1; } - if (k === void 0) { k = 0; } - return [j, k]; - }; - } - return C; -})(); +// A contextual signature S is extracted from a function type T as follows: +// If T is a function type with exactly one call signature, and if that call signature is non- generic, S is that signature. +// If T is a union type, let U be the set of element types in T that have call signatures. +// If each type in U has exactly one call signature and that call signature is non- generic, +// and if all of the signatures are identical ignoring return types, then S is a signature +// with the same parameters and a union of the return types. +// Otherwise, no contextual signature can be extracted from T and S is undefined. +var a0; +var a1; +a1 = function (foo, bar) { return true; }; // Error diff --git a/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts b/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts index 1ede1c3fa72..ea8e60cb5b9 100644 --- a/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts +++ b/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts @@ -1,28 +1,52 @@ -enum E { red, blue } +// When a function expression with no type parameters and no parameter type annotations +// is contextually typed (section 4.19) by a type T and a contextual signature S can be extracted from T -var g0: (n: number, s:string) => number; -var g: ((s: string, w: boolean) => void) | ((n: number) => number); -var g1: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); +enum E { red, blue } -g1 = (j, m) => { } // Per spec, no contextual signature can be extracted in this case. -g = (k, h=true) => { k.toLowerCase() }; -g = (k) => { k.toLowerCase() }; -g = (i) => { +// A contextual signature S is extracted from a function type T as follows: +// If T is a function type with exactly one call signature, and if that call signature is non- generic, S is that signature. + +var a0: (n: number, s: string) => number = (num, str) => { + num.toExponential(); + return 0; +} + +class Class { + foo() { } +} + +var a1: (c: Class) => number = (a1) => { + a1.foo(); + return 1; +} + +// A contextual signature S is extracted from a function type T as follows: +// If T is a union type, let U be the set of element types in T that have call signatures. +// If each type in U has exactly one call signature and that call signature is non- generic, +// and if all of the signatures are identical ignoring return types, +// then S is a signature with the same parameters and a union of the return types. +var b1: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); +b1 = (k, h) => { }; +var b2: typeof a0 | ((n: number, s: string) => string); +b2 = (foo, bar) => { return foo + 1; } +b2 = (foo, bar) => { return "hello"; } +var b3: (name: string, num: number, boo: boolean) => void; +b3 = (name, number) => { }; + +var b4: (n: E) => string = (number = 1) => { return "hello"; }; +var b5: (n: {}) => string = (number = "string") => { return "hello"; }; + +// A contextual signature S is extracted from a function type T as follows: +// Otherwise, no contextual signature can be extracted from T and S is undefined. +var b6: ((s: string, w: boolean) => void) | ((n: number) => number); +var b7: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); +b6 = (k) => { k.toLowerCase() }; +b6 = (i) => { i.toExponential(); return i; -}; // Per spec, no contextual signature can be extracted in this case. +}; // Per spec, no contextual signature can be extracted in this case. (Otherwise clause) +b7 = (j, m) => { }; // Per spec, no contextual signature can be extracted in this case. (Otherwise clause) -var h: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); -h = (k, h) => { }; - -var i: typeof g0 | ((n: number, s: string) => string); -i = (foo, bar) => { return foo + 1; } -i = (foo, bar) => { return "hello"; } -var j: (name: string, num: number, boo: boolean) => void; -j = (name, number) => { }; - -var k: (n: E) => string = (number = 1) => { return "hello"; }; -var k1: (n: {}) => string = (number = 1) => { return "hello"; }; class C { constructor() { var k: ((j: T, k: U) => (T|U)[]) | ((j: number,k :U) => number[]) = (j, k) => { diff --git a/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts b/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts index d22fff7e138..1b88c1a8cfb 100644 --- a/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts +++ b/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts @@ -1,14 +1,11 @@ -var g0: (n: number, s: string) => number -var i: typeof g0 | ((n: number, s: string) => string); -i = (foo, bar) => { return true; } +// A contextual signature S is extracted from a function type T as follows: +// If T is a function type with exactly one call signature, and if that call signature is non- generic, S is that signature. +// If T is a union type, let U be the set of element types in T that have call signatures. +// If each type in U has exactly one call signature and that call signature is non- generic, +// and if all of the signatures are identical ignoring return types, then S is a signature +// with the same parameters and a union of the return types. +// Otherwise, no contextual signature can be extracted from T and S is undefined. -class C { } - -var j: (c: C) => number = (j) => { return 1; } -class C { - constructor() { - var k: (j: T, k: U) => (T|U)[] = (j = 1, k = 0) => { - return [j, k]; - } - } -} \ No newline at end of file +var a0: (n: number, s: string) => number +var a1: typeof a0 | ((n: number, s: string) => string); +a1 = (foo, bar) => { return true; } // Error \ No newline at end of file From 1266b0d1d4c19b9d997c38ba404ae0cc4b78c483 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 16 Apr 2015 15:52:20 -0700 Subject: [PATCH 037/194] Update baselines from merge master --- .../functionExpressionContextualTyping1.types | 182 +++++++++--------- 1 file changed, 91 insertions(+), 91 deletions(-) diff --git a/tests/baselines/reference/functionExpressionContextualTyping1.types b/tests/baselines/reference/functionExpressionContextualTyping1.types index f7f04d5ed0f..61d16bf6a4f 100644 --- a/tests/baselines/reference/functionExpressionContextualTyping1.types +++ b/tests/baselines/reference/functionExpressionContextualTyping1.types @@ -3,52 +3,52 @@ // is contextually typed (section 4.19) by a type T and a contextual signature S can be extracted from T enum E { red, blue } ->E : E, Symbol(E, Decl(functionExpressionContextualTyping1.ts, 0, 0)) ->red : E, Symbol(E.red, Decl(functionExpressionContextualTyping1.ts, 3, 8)) ->blue : E, Symbol(E.blue, Decl(functionExpressionContextualTyping1.ts, 3, 13)) +>E : E +>red : E +>blue : E // A contextual signature S is extracted from a function type T as follows: // If T is a function type with exactly one call signature, and if that call signature is non- generic, S is that signature. var a0: (n: number, s: string) => number = (num, str) => { ->a0 : (n: number, s: string) => number, Symbol(a0, Decl(functionExpressionContextualTyping1.ts, 8, 3)) ->n : number, Symbol(n, Decl(functionExpressionContextualTyping1.ts, 8, 9)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 8, 19)) +>a0 : (n: number, s: string) => number +>n : number +>s : string >(num, str) => { num.toExponential(); return 0;} : (num: number, str: string) => number ->num : number, Symbol(num, Decl(functionExpressionContextualTyping1.ts, 8, 44)) ->str : string, Symbol(str, Decl(functionExpressionContextualTyping1.ts, 8, 48)) +>num : number +>str : string num.toExponential(); >num.toExponential() : string ->num.toExponential : (fractionDigits?: number) => string, Symbol(Number.toExponential, Decl(lib.d.ts, 469, 45)) ->num : number, Symbol(num, Decl(functionExpressionContextualTyping1.ts, 8, 44)) ->toExponential : (fractionDigits?: number) => string, Symbol(Number.toExponential, Decl(lib.d.ts, 469, 45)) +>num.toExponential : (fractionDigits?: number) => string +>num : number +>toExponential : (fractionDigits?: number) => string return 0; >0 : number } class Class { ->Class : Class, Symbol(Class, Decl(functionExpressionContextualTyping1.ts, 11, 1)) ->T : T, Symbol(T, Decl(functionExpressionContextualTyping1.ts, 13, 12)) +>Class : Class +>T : T foo() { } ->foo : () => void, Symbol(foo, Decl(functionExpressionContextualTyping1.ts, 13, 16)) +>foo : () => void } var a1: (c: Class) => number = (a1) => { ->a1 : (c: Class) => number, Symbol(a1, Decl(functionExpressionContextualTyping1.ts, 17, 3)) ->c : Class, Symbol(c, Decl(functionExpressionContextualTyping1.ts, 17, 9)) ->Class : Class, Symbol(Class, Decl(functionExpressionContextualTyping1.ts, 11, 1)) ->Number : Number, Symbol(Number, Decl(lib.d.ts, 456, 40), Decl(lib.d.ts, 518, 11)) +>a1 : (c: Class) => number +>c : Class +>Class : Class +>Number : Number >(a1) => { a1.foo(); return 1;} : (a1: Class) => number ->a1 : Class, Symbol(a1, Decl(functionExpressionContextualTyping1.ts, 17, 40)) +>a1 : Class a1.foo(); >a1.foo() : void ->a1.foo : () => void, Symbol(Class.foo, Decl(functionExpressionContextualTyping1.ts, 13, 16)) ->a1 : Class, Symbol(a1, Decl(functionExpressionContextualTyping1.ts, 17, 40)) ->foo : () => void, Symbol(Class.foo, Decl(functionExpressionContextualTyping1.ts, 13, 16)) +>a1.foo : () => void +>a1 : Class +>foo : () => void return 1; >1 : number @@ -60,146 +60,146 @@ var a1: (c: Class) => number = (a1) => { // and if all of the signatures are identical ignoring return types, // then S is a signature with the same parameters and a union of the return types. var b1: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); ->b1 : ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string), Symbol(b1, Decl(functionExpressionContextualTyping1.ts, 27, 3)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 27, 10)) ->w : boolean, Symbol(w, Decl(functionExpressionContextualTyping1.ts, 27, 20)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 27, 46)) ->w : boolean, Symbol(w, Decl(functionExpressionContextualTyping1.ts, 27, 56)) +>b1 : ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string) +>s : string +>w : boolean +>s : string +>w : boolean b1 = (k, h) => { }; >b1 = (k, h) => { } : (k: string, h: boolean) => void ->b1 : ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string), Symbol(b1, Decl(functionExpressionContextualTyping1.ts, 27, 3)) +>b1 : ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string) >(k, h) => { } : (k: string, h: boolean) => void ->k : string, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 28, 6)) ->h : boolean, Symbol(h, Decl(functionExpressionContextualTyping1.ts, 28, 8)) +>k : string +>h : boolean var b2: typeof a0 | ((n: number, s: string) => string); ->b2 : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(b2, Decl(functionExpressionContextualTyping1.ts, 29, 3)) ->a0 : (n: number, s: string) => number, Symbol(a0, Decl(functionExpressionContextualTyping1.ts, 8, 3)) ->n : number, Symbol(n, Decl(functionExpressionContextualTyping1.ts, 29, 22)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 29, 32)) +>b2 : ((n: number, s: string) => number) | ((n: number, s: string) => string) +>a0 : (n: number, s: string) => number +>n : number +>s : string b2 = (foo, bar) => { return foo + 1; } >b2 = (foo, bar) => { return foo + 1; } : (foo: number, bar: string) => number ->b2 : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(b2, Decl(functionExpressionContextualTyping1.ts, 29, 3)) +>b2 : ((n: number, s: string) => number) | ((n: number, s: string) => string) >(foo, bar) => { return foo + 1; } : (foo: number, bar: string) => number ->foo : number, Symbol(foo, Decl(functionExpressionContextualTyping1.ts, 30, 6)) ->bar : string, Symbol(bar, Decl(functionExpressionContextualTyping1.ts, 30, 10)) +>foo : number +>bar : string >foo + 1 : number ->foo : number, Symbol(foo, Decl(functionExpressionContextualTyping1.ts, 30, 6)) +>foo : number >1 : number b2 = (foo, bar) => { return "hello"; } >b2 = (foo, bar) => { return "hello"; } : (foo: number, bar: string) => string ->b2 : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(b2, Decl(functionExpressionContextualTyping1.ts, 29, 3)) +>b2 : ((n: number, s: string) => number) | ((n: number, s: string) => string) >(foo, bar) => { return "hello"; } : (foo: number, bar: string) => string ->foo : number, Symbol(foo, Decl(functionExpressionContextualTyping1.ts, 31, 6)) ->bar : string, Symbol(bar, Decl(functionExpressionContextualTyping1.ts, 31, 10)) +>foo : number +>bar : string >"hello" : string var b3: (name: string, num: number, boo: boolean) => void; ->b3 : (name: string, num: number, boo: boolean) => void, Symbol(b3, Decl(functionExpressionContextualTyping1.ts, 32, 3)) ->name : string, Symbol(name, Decl(functionExpressionContextualTyping1.ts, 32, 9)) ->num : number, Symbol(num, Decl(functionExpressionContextualTyping1.ts, 32, 22)) ->boo : boolean, Symbol(boo, Decl(functionExpressionContextualTyping1.ts, 32, 35)) +>b3 : (name: string, num: number, boo: boolean) => void +>name : string +>num : number +>boo : boolean b3 = (name, number) => { }; >b3 = (name, number) => { } : (name: string, number: number) => void ->b3 : (name: string, num: number, boo: boolean) => void, Symbol(b3, Decl(functionExpressionContextualTyping1.ts, 32, 3)) +>b3 : (name: string, num: number, boo: boolean) => void >(name, number) => { } : (name: string, number: number) => void ->name : string, Symbol(name, Decl(functionExpressionContextualTyping1.ts, 33, 6)) ->number : number, Symbol(number, Decl(functionExpressionContextualTyping1.ts, 33, 11)) +>name : string +>number : number var b4: (n: E) => string = (number = 1) => { return "hello"; }; ->b4 : (n: E) => string, Symbol(b4, Decl(functionExpressionContextualTyping1.ts, 35, 3)) ->n : E, Symbol(n, Decl(functionExpressionContextualTyping1.ts, 35, 9)) ->E : E, Symbol(E, Decl(functionExpressionContextualTyping1.ts, 0, 0)) +>b4 : (n: E) => string +>n : E +>E : E >(number = 1) => { return "hello"; } : (number?: E) => string ->number : E, Symbol(number, Decl(functionExpressionContextualTyping1.ts, 35, 28)) +>number : E >1 : number >"hello" : string var b5: (n: {}) => string = (number = "string") => { return "hello"; }; ->b5 : (n: {}) => string, Symbol(b5, Decl(functionExpressionContextualTyping1.ts, 36, 3)) ->n : {}, Symbol(n, Decl(functionExpressionContextualTyping1.ts, 36, 9)) +>b5 : (n: {}) => string +>n : {} >(number = "string") => { return "hello"; } : (number?: {}) => string ->number : {}, Symbol(number, Decl(functionExpressionContextualTyping1.ts, 36, 29)) +>number : {} >"string" : string >"hello" : string // A contextual signature S is extracted from a function type T as follows: // Otherwise, no contextual signature can be extracted from T and S is undefined. var b6: ((s: string, w: boolean) => void) | ((n: number) => number); ->b6 : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(b6, Decl(functionExpressionContextualTyping1.ts, 40, 3)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 40, 10)) ->w : boolean, Symbol(w, Decl(functionExpressionContextualTyping1.ts, 40, 20)) ->n : number, Symbol(n, Decl(functionExpressionContextualTyping1.ts, 40, 46)) +>b6 : ((s: string, w: boolean) => void) | ((n: number) => number) +>s : string +>w : boolean +>n : number var b7: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); ->b7 : ((s: string, w: boolean) => void) | ((s: string, w: number) => string), Symbol(b7, Decl(functionExpressionContextualTyping1.ts, 41, 3)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 41, 10)) ->w : boolean, Symbol(w, Decl(functionExpressionContextualTyping1.ts, 41, 20)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 41, 46)) ->w : number, Symbol(w, Decl(functionExpressionContextualTyping1.ts, 41, 56)) +>b7 : ((s: string, w: boolean) => void) | ((s: string, w: number) => string) +>s : string +>w : boolean +>s : string +>w : number b6 = (k) => { k.toLowerCase() }; >b6 = (k) => { k.toLowerCase() } : (k: any) => void ->b6 : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(b6, Decl(functionExpressionContextualTyping1.ts, 40, 3)) +>b6 : ((s: string, w: boolean) => void) | ((n: number) => number) >(k) => { k.toLowerCase() } : (k: any) => void ->k : any, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 42, 6)) +>k : any >k.toLowerCase() : any >k.toLowerCase : any ->k : any, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 42, 6)) +>k : any >toLowerCase : any b6 = (i) => { >b6 = (i) => { i.toExponential(); return i;} : (i: any) => any ->b6 : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(b6, Decl(functionExpressionContextualTyping1.ts, 40, 3)) +>b6 : ((s: string, w: boolean) => void) | ((n: number) => number) >(i) => { i.toExponential(); return i;} : (i: any) => any ->i : any, Symbol(i, Decl(functionExpressionContextualTyping1.ts, 43, 6)) +>i : any i.toExponential(); >i.toExponential() : any >i.toExponential : any ->i : any, Symbol(i, Decl(functionExpressionContextualTyping1.ts, 43, 6)) +>i : any >toExponential : any return i; ->i : any, Symbol(i, Decl(functionExpressionContextualTyping1.ts, 43, 6)) +>i : any }; // Per spec, no contextual signature can be extracted in this case. (Otherwise clause) b7 = (j, m) => { }; // Per spec, no contextual signature can be extracted in this case. (Otherwise clause) >b7 = (j, m) => { } : (j: any, m: any) => void ->b7 : ((s: string, w: boolean) => void) | ((s: string, w: number) => string), Symbol(b7, Decl(functionExpressionContextualTyping1.ts, 41, 3)) +>b7 : ((s: string, w: boolean) => void) | ((s: string, w: number) => string) >(j, m) => { } : (j: any, m: any) => void ->j : any, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 47, 6)) ->m : any, Symbol(m, Decl(functionExpressionContextualTyping1.ts, 47, 8)) +>j : any +>m : any class C { ->C : C, Symbol(C, Decl(functionExpressionContextualTyping1.ts, 47, 19)) ->T : T, Symbol(T, Decl(functionExpressionContextualTyping1.ts, 49, 8)) ->U : U, Symbol(U, Decl(functionExpressionContextualTyping1.ts, 49, 10)) +>C : C +>T : T +>U : U constructor() { var k: ((j: T, k: U) => (T|U)[]) | ((j: number,k :U) => number[]) = (j, k) => { ->k : ((j: T, k: U) => (T | U)[]) | ((j: number, k: U) => number[]), Symbol(k, Decl(functionExpressionContextualTyping1.ts, 51, 11)) ->j : T, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 51, 17)) ->T : T, Symbol(T, Decl(functionExpressionContextualTyping1.ts, 49, 8)) ->k : U, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 51, 22)) ->U : U, Symbol(U, Decl(functionExpressionContextualTyping1.ts, 49, 10)) ->T : T, Symbol(T, Decl(functionExpressionContextualTyping1.ts, 49, 8)) ->U : U, Symbol(U, Decl(functionExpressionContextualTyping1.ts, 49, 10)) ->j : number, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 51, 45)) ->k : U, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 51, 55)) ->U : U, Symbol(U, Decl(functionExpressionContextualTyping1.ts, 49, 10)) +>k : ((j: T, k: U) => (T | U)[]) | ((j: number, k: U) => number[]) +>j : T +>T : T +>k : U +>U : U +>T : T +>U : U +>j : number +>k : U +>U : U >(j, k) => { return [j, k]; } : (j: any, k: any) => any[] ->j : any, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 51, 77)) ->k : any, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 51, 79)) +>j : any +>k : any return [j, k]; >[j, k] : any[] ->j : any, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 51, 77)) ->k : any, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 51, 79)) +>j : any +>k : any } // Per spec, no contextual signature can be extracted in this case. } From 94ed1d894206f444435ba03879607d541f7eb6b8 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 16 Apr 2015 16:03:09 -0700 Subject: [PATCH 038/194] update baselines from merge master --- ...unctionExpressionContextualTyping1.symbols | 169 ++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100644 tests/baselines/reference/functionExpressionContextualTyping1.symbols diff --git a/tests/baselines/reference/functionExpressionContextualTyping1.symbols b/tests/baselines/reference/functionExpressionContextualTyping1.symbols new file mode 100644 index 00000000000..6182e4bb9a8 --- /dev/null +++ b/tests/baselines/reference/functionExpressionContextualTyping1.symbols @@ -0,0 +1,169 @@ +=== tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts === +// When a function expression with no type parameters and no parameter type annotations +// is contextually typed (section 4.19) by a type T and a contextual signature S can be extracted from T + +enum E { red, blue } +>E : Symbol(E, Decl(functionExpressionContextualTyping1.ts, 0, 0)) +>red : Symbol(E.red, Decl(functionExpressionContextualTyping1.ts, 3, 8)) +>blue : Symbol(E.blue, Decl(functionExpressionContextualTyping1.ts, 3, 13)) + +// A contextual signature S is extracted from a function type T as follows: +// If T is a function type with exactly one call signature, and if that call signature is non- generic, S is that signature. + +var a0: (n: number, s: string) => number = (num, str) => { +>a0 : Symbol(a0, Decl(functionExpressionContextualTyping1.ts, 8, 3)) +>n : Symbol(n, Decl(functionExpressionContextualTyping1.ts, 8, 9)) +>s : Symbol(s, Decl(functionExpressionContextualTyping1.ts, 8, 19)) +>num : Symbol(num, Decl(functionExpressionContextualTyping1.ts, 8, 44)) +>str : Symbol(str, Decl(functionExpressionContextualTyping1.ts, 8, 48)) + + num.toExponential(); +>num.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, 469, 45)) +>num : Symbol(num, Decl(functionExpressionContextualTyping1.ts, 8, 44)) +>toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, 469, 45)) + + return 0; +} + +class Class { +>Class : Symbol(Class, Decl(functionExpressionContextualTyping1.ts, 11, 1)) +>T : Symbol(T, Decl(functionExpressionContextualTyping1.ts, 13, 12)) + + foo() { } +>foo : Symbol(foo, Decl(functionExpressionContextualTyping1.ts, 13, 16)) +} + +var a1: (c: Class) => number = (a1) => { +>a1 : Symbol(a1, Decl(functionExpressionContextualTyping1.ts, 17, 3)) +>c : Symbol(c, Decl(functionExpressionContextualTyping1.ts, 17, 9)) +>Class : Symbol(Class, Decl(functionExpressionContextualTyping1.ts, 11, 1)) +>Number : Symbol(Number, Decl(lib.d.ts, 456, 40), Decl(lib.d.ts, 518, 11)) +>a1 : Symbol(a1, Decl(functionExpressionContextualTyping1.ts, 17, 40)) + + a1.foo(); +>a1.foo : Symbol(Class.foo, Decl(functionExpressionContextualTyping1.ts, 13, 16)) +>a1 : Symbol(a1, Decl(functionExpressionContextualTyping1.ts, 17, 40)) +>foo : Symbol(Class.foo, Decl(functionExpressionContextualTyping1.ts, 13, 16)) + + return 1; +} + +// A contextual signature S is extracted from a function type T as follows: +// If T is a union type, let U be the set of element types in T that have call signatures. +// If each type in U has exactly one call signature and that call signature is non- generic, +// and if all of the signatures are identical ignoring return types, +// then S is a signature with the same parameters and a union of the return types. +var b1: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); +>b1 : Symbol(b1, Decl(functionExpressionContextualTyping1.ts, 27, 3)) +>s : Symbol(s, Decl(functionExpressionContextualTyping1.ts, 27, 10)) +>w : Symbol(w, Decl(functionExpressionContextualTyping1.ts, 27, 20)) +>s : Symbol(s, Decl(functionExpressionContextualTyping1.ts, 27, 46)) +>w : Symbol(w, Decl(functionExpressionContextualTyping1.ts, 27, 56)) + +b1 = (k, h) => { }; +>b1 : Symbol(b1, Decl(functionExpressionContextualTyping1.ts, 27, 3)) +>k : Symbol(k, Decl(functionExpressionContextualTyping1.ts, 28, 6)) +>h : Symbol(h, Decl(functionExpressionContextualTyping1.ts, 28, 8)) + +var b2: typeof a0 | ((n: number, s: string) => string); +>b2 : Symbol(b2, Decl(functionExpressionContextualTyping1.ts, 29, 3)) +>a0 : Symbol(a0, Decl(functionExpressionContextualTyping1.ts, 8, 3)) +>n : Symbol(n, Decl(functionExpressionContextualTyping1.ts, 29, 22)) +>s : Symbol(s, Decl(functionExpressionContextualTyping1.ts, 29, 32)) + +b2 = (foo, bar) => { return foo + 1; } +>b2 : Symbol(b2, Decl(functionExpressionContextualTyping1.ts, 29, 3)) +>foo : Symbol(foo, Decl(functionExpressionContextualTyping1.ts, 30, 6)) +>bar : Symbol(bar, Decl(functionExpressionContextualTyping1.ts, 30, 10)) +>foo : Symbol(foo, Decl(functionExpressionContextualTyping1.ts, 30, 6)) + +b2 = (foo, bar) => { return "hello"; } +>b2 : Symbol(b2, Decl(functionExpressionContextualTyping1.ts, 29, 3)) +>foo : Symbol(foo, Decl(functionExpressionContextualTyping1.ts, 31, 6)) +>bar : Symbol(bar, Decl(functionExpressionContextualTyping1.ts, 31, 10)) + +var b3: (name: string, num: number, boo: boolean) => void; +>b3 : Symbol(b3, Decl(functionExpressionContextualTyping1.ts, 32, 3)) +>name : Symbol(name, Decl(functionExpressionContextualTyping1.ts, 32, 9)) +>num : Symbol(num, Decl(functionExpressionContextualTyping1.ts, 32, 22)) +>boo : Symbol(boo, Decl(functionExpressionContextualTyping1.ts, 32, 35)) + +b3 = (name, number) => { }; +>b3 : Symbol(b3, Decl(functionExpressionContextualTyping1.ts, 32, 3)) +>name : Symbol(name, Decl(functionExpressionContextualTyping1.ts, 33, 6)) +>number : Symbol(number, Decl(functionExpressionContextualTyping1.ts, 33, 11)) + +var b4: (n: E) => string = (number = 1) => { return "hello"; }; +>b4 : Symbol(b4, Decl(functionExpressionContextualTyping1.ts, 35, 3)) +>n : Symbol(n, Decl(functionExpressionContextualTyping1.ts, 35, 9)) +>E : Symbol(E, Decl(functionExpressionContextualTyping1.ts, 0, 0)) +>number : Symbol(number, Decl(functionExpressionContextualTyping1.ts, 35, 28)) + +var b5: (n: {}) => string = (number = "string") => { return "hello"; }; +>b5 : Symbol(b5, Decl(functionExpressionContextualTyping1.ts, 36, 3)) +>n : Symbol(n, Decl(functionExpressionContextualTyping1.ts, 36, 9)) +>number : Symbol(number, Decl(functionExpressionContextualTyping1.ts, 36, 29)) + +// A contextual signature S is extracted from a function type T as follows: +// Otherwise, no contextual signature can be extracted from T and S is undefined. +var b6: ((s: string, w: boolean) => void) | ((n: number) => number); +>b6 : Symbol(b6, Decl(functionExpressionContextualTyping1.ts, 40, 3)) +>s : Symbol(s, Decl(functionExpressionContextualTyping1.ts, 40, 10)) +>w : Symbol(w, Decl(functionExpressionContextualTyping1.ts, 40, 20)) +>n : Symbol(n, Decl(functionExpressionContextualTyping1.ts, 40, 46)) + +var b7: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); +>b7 : Symbol(b7, Decl(functionExpressionContextualTyping1.ts, 41, 3)) +>s : Symbol(s, Decl(functionExpressionContextualTyping1.ts, 41, 10)) +>w : Symbol(w, Decl(functionExpressionContextualTyping1.ts, 41, 20)) +>s : Symbol(s, Decl(functionExpressionContextualTyping1.ts, 41, 46)) +>w : Symbol(w, Decl(functionExpressionContextualTyping1.ts, 41, 56)) + +b6 = (k) => { k.toLowerCase() }; +>b6 : Symbol(b6, Decl(functionExpressionContextualTyping1.ts, 40, 3)) +>k : Symbol(k, Decl(functionExpressionContextualTyping1.ts, 42, 6)) +>k : Symbol(k, Decl(functionExpressionContextualTyping1.ts, 42, 6)) + +b6 = (i) => { +>b6 : Symbol(b6, Decl(functionExpressionContextualTyping1.ts, 40, 3)) +>i : Symbol(i, Decl(functionExpressionContextualTyping1.ts, 43, 6)) + + i.toExponential(); +>i : Symbol(i, Decl(functionExpressionContextualTyping1.ts, 43, 6)) + + return i; +>i : Symbol(i, Decl(functionExpressionContextualTyping1.ts, 43, 6)) + +}; // Per spec, no contextual signature can be extracted in this case. (Otherwise clause) +b7 = (j, m) => { }; // Per spec, no contextual signature can be extracted in this case. (Otherwise clause) +>b7 : Symbol(b7, Decl(functionExpressionContextualTyping1.ts, 41, 3)) +>j : Symbol(j, Decl(functionExpressionContextualTyping1.ts, 47, 6)) +>m : Symbol(m, Decl(functionExpressionContextualTyping1.ts, 47, 8)) + +class C { +>C : Symbol(C, Decl(functionExpressionContextualTyping1.ts, 47, 19)) +>T : Symbol(T, Decl(functionExpressionContextualTyping1.ts, 49, 8)) +>U : Symbol(U, Decl(functionExpressionContextualTyping1.ts, 49, 10)) + + constructor() { + var k: ((j: T, k: U) => (T|U)[]) | ((j: number,k :U) => number[]) = (j, k) => { +>k : Symbol(k, Decl(functionExpressionContextualTyping1.ts, 51, 11)) +>j : Symbol(j, Decl(functionExpressionContextualTyping1.ts, 51, 17)) +>T : Symbol(T, Decl(functionExpressionContextualTyping1.ts, 49, 8)) +>k : Symbol(k, Decl(functionExpressionContextualTyping1.ts, 51, 22)) +>U : Symbol(U, Decl(functionExpressionContextualTyping1.ts, 49, 10)) +>T : Symbol(T, Decl(functionExpressionContextualTyping1.ts, 49, 8)) +>U : Symbol(U, Decl(functionExpressionContextualTyping1.ts, 49, 10)) +>j : Symbol(j, Decl(functionExpressionContextualTyping1.ts, 51, 45)) +>k : Symbol(k, Decl(functionExpressionContextualTyping1.ts, 51, 55)) +>U : Symbol(U, Decl(functionExpressionContextualTyping1.ts, 49, 10)) +>j : Symbol(j, Decl(functionExpressionContextualTyping1.ts, 51, 77)) +>k : Symbol(k, Decl(functionExpressionContextualTyping1.ts, 51, 79)) + + return [j, k]; +>j : Symbol(j, Decl(functionExpressionContextualTyping1.ts, 51, 77)) +>k : Symbol(k, Decl(functionExpressionContextualTyping1.ts, 51, 79)) + + } // Per spec, no contextual signature can be extracted in this case. + } +} From db3705f5d65b51653e9bb7eddb5566de0acf8989 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 16 Apr 2015 16:17:28 -0700 Subject: [PATCH 039/194] Update baselines from merge master --- .../reference/arrayLiterals2ES5.symbols | 134 ++++++++++++++++++ .../reference/arrayLiterals2ES5.types | 41 ++++++ .../reference/arrayLiterals2ES6.symbols | 126 ++++++++++++++++ .../reference/arrayLiterals2ES6.types | 40 ++++++ 4 files changed, 341 insertions(+) create mode 100644 tests/baselines/reference/arrayLiterals2ES5.symbols create mode 100644 tests/baselines/reference/arrayLiterals2ES6.symbols diff --git a/tests/baselines/reference/arrayLiterals2ES5.symbols b/tests/baselines/reference/arrayLiterals2ES5.symbols new file mode 100644 index 00000000000..c69b79de272 --- /dev/null +++ b/tests/baselines/reference/arrayLiterals2ES5.symbols @@ -0,0 +1,134 @@ +=== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2ES5.ts === +// ElementList: ( Modified ) +// Elisionopt AssignmentExpression +// Elisionopt SpreadElement +// ElementList, Elisionopt AssignmentExpression +// ElementList, Elisionopt SpreadElement + +// SpreadElement: +// ... AssignmentExpression + +var a0 = [,, 2, 3, 4] +>a0 : Symbol(a0, Decl(arrayLiterals2ES5.ts, 9, 3)) + +var a1 = ["hello", "world"] +>a1 : Symbol(a1, Decl(arrayLiterals2ES5.ts, 10, 3)) + +var a2 = [, , , ...a0, "hello"]; +>a2 : Symbol(a2, Decl(arrayLiterals2ES5.ts, 11, 3)) +>a0 : Symbol(a0, Decl(arrayLiterals2ES5.ts, 9, 3)) + +var a3 = [,, ...a0] +>a3 : Symbol(a3, Decl(arrayLiterals2ES5.ts, 12, 3)) +>a0 : Symbol(a0, Decl(arrayLiterals2ES5.ts, 9, 3)) + +var a4 = [() => 1, ]; +>a4 : Symbol(a4, Decl(arrayLiterals2ES5.ts, 13, 3)) + +var a5 = [...a0, , ] +>a5 : Symbol(a5, Decl(arrayLiterals2ES5.ts, 14, 3)) +>a0 : Symbol(a0, Decl(arrayLiterals2ES5.ts, 9, 3)) + +// Each element expression in a non-empty array literal is processed as follows: +// - If the array literal contains no spread elements, and if the array literal is contextually typed (section 4.19) +// by a type T and T has a property with the numeric name N, where N is the index of the element expression in the array literal, +// the element expression is contextually typed by the type of that property. + +// The resulting type an array literal expression is determined as follows: +// - If the array literal contains no spread elements and is contextually typed by a tuple-like type, +// the resulting type is a tuple type constructed from the types of the element expressions. + +var b0: [any, any, any] = [undefined, null, undefined]; +>b0 : Symbol(b0, Decl(arrayLiterals2ES5.ts, 25, 3)) +>undefined : Symbol(undefined) +>undefined : Symbol(undefined) + +var b1: [number[], string[]] = [[1, 2, 3], ["hello", "string"]]; +>b1 : Symbol(b1, Decl(arrayLiterals2ES5.ts, 26, 3)) + +// The resulting type an array literal expression is determined as follows: +// - If the array literal contains no spread elements and is an array assignment pattern in a destructuring assignment (section 4.17.1), +// the resulting type is a tuple type constructed from the types of the element expressions. + +var [c0, c1] = [1, 2]; // tuple type [number, number] +>c0 : Symbol(c0, Decl(arrayLiterals2ES5.ts, 32, 5)) +>c1 : Symbol(c1, Decl(arrayLiterals2ES5.ts, 32, 8)) + +var [c2, c3] = [1, 2, true]; // tuple type [number, number, boolean] +>c2 : Symbol(c2, Decl(arrayLiterals2ES5.ts, 33, 5)) +>c3 : Symbol(c3, Decl(arrayLiterals2ES5.ts, 33, 8)) + +// The resulting type an array literal expression is determined as follows: +// - the resulting type is an array type with an element type that is the union of the types of the +// non - spread element expressions and the numeric index signature types of the spread element expressions +var temp = ["s", "t", "r"]; +>temp : Symbol(temp, Decl(arrayLiterals2ES5.ts, 38, 3)) + +var temp1 = [1, 2, 3]; +>temp1 : Symbol(temp1, Decl(arrayLiterals2ES5.ts, 39, 3)) + +var temp2: [number[], string[]] = [[1, 2, 3], ["hello", "string"]]; +>temp2 : Symbol(temp2, Decl(arrayLiterals2ES5.ts, 40, 3)) + +var temp3 = [undefined, null, undefined]; +>temp3 : Symbol(temp3, Decl(arrayLiterals2ES5.ts, 41, 3)) +>undefined : Symbol(undefined) +>undefined : Symbol(undefined) + +var temp4 = []; +>temp4 : Symbol(temp4, Decl(arrayLiterals2ES5.ts, 42, 3)) + +interface myArray extends Array { } +>myArray : Symbol(myArray, Decl(arrayLiterals2ES5.ts, 42, 15)) +>Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11)) +>Number : Symbol(Number, Decl(lib.d.ts, 456, 40), Decl(lib.d.ts, 518, 11)) + +interface myArray2 extends Array { } +>myArray2 : Symbol(myArray2, Decl(arrayLiterals2ES5.ts, 44, 43)) +>Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11)) +>Number : Symbol(Number, Decl(lib.d.ts, 456, 40), Decl(lib.d.ts, 518, 11)) +>String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11)) + +var d0 = [1, true, ...temp,]; // has type (string|number|boolean)[] +>d0 : Symbol(d0, Decl(arrayLiterals2ES5.ts, 46, 3)) +>temp : Symbol(temp, Decl(arrayLiterals2ES5.ts, 38, 3)) + +var d1 = [...temp]; // has type string[] +>d1 : Symbol(d1, Decl(arrayLiterals2ES5.ts, 47, 3)) +>temp : Symbol(temp, Decl(arrayLiterals2ES5.ts, 38, 3)) + +var d2: number[] = [...temp1]; +>d2 : Symbol(d2, Decl(arrayLiterals2ES5.ts, 48, 3)) +>temp1 : Symbol(temp1, Decl(arrayLiterals2ES5.ts, 39, 3)) + +var d3: myArray = [...temp1]; +>d3 : Symbol(d3, Decl(arrayLiterals2ES5.ts, 49, 3)) +>myArray : Symbol(myArray, Decl(arrayLiterals2ES5.ts, 42, 15)) +>temp1 : Symbol(temp1, Decl(arrayLiterals2ES5.ts, 39, 3)) + +var d4: myArray2 = [...temp, ...temp1]; +>d4 : Symbol(d4, Decl(arrayLiterals2ES5.ts, 50, 3)) +>myArray2 : Symbol(myArray2, Decl(arrayLiterals2ES5.ts, 44, 43)) +>temp : Symbol(temp, Decl(arrayLiterals2ES5.ts, 38, 3)) +>temp1 : Symbol(temp1, Decl(arrayLiterals2ES5.ts, 39, 3)) + +var d5 = [...temp3]; +>d5 : Symbol(d5, Decl(arrayLiterals2ES5.ts, 51, 3)) +>temp3 : Symbol(temp3, Decl(arrayLiterals2ES5.ts, 41, 3)) + +var d6 = [...temp4]; +>d6 : Symbol(d6, Decl(arrayLiterals2ES5.ts, 52, 3)) +>temp4 : Symbol(temp4, Decl(arrayLiterals2ES5.ts, 42, 3)) + +var d7 = [...[...temp1]]; +>d7 : Symbol(d7, Decl(arrayLiterals2ES5.ts, 53, 3)) +>temp1 : Symbol(temp1, Decl(arrayLiterals2ES5.ts, 39, 3)) + +var d8: number[][] = [[...temp1]] +>d8 : Symbol(d8, Decl(arrayLiterals2ES5.ts, 54, 3)) +>temp1 : Symbol(temp1, Decl(arrayLiterals2ES5.ts, 39, 3)) + +var d9 = [[...temp1], ...["hello"]]; +>d9 : Symbol(d9, Decl(arrayLiterals2ES5.ts, 55, 3)) +>temp1 : Symbol(temp1, Decl(arrayLiterals2ES5.ts, 39, 3)) + diff --git a/tests/baselines/reference/arrayLiterals2ES5.types b/tests/baselines/reference/arrayLiterals2ES5.types index cd55e4ea514..6eae997f465 100644 --- a/tests/baselines/reference/arrayLiterals2ES5.types +++ b/tests/baselines/reference/arrayLiterals2ES5.types @@ -11,20 +11,33 @@ var a0 = [,, 2, 3, 4] >a0 : number[] >[,, 2, 3, 4] : number[] +> : undefined +> : undefined +>2 : number +>3 : number +>4 : number var a1 = ["hello", "world"] >a1 : string[] >["hello", "world"] : string[] +>"hello" : string +>"world" : string var a2 = [, , , ...a0, "hello"]; >a2 : (string | number)[] >[, , , ...a0, "hello"] : (string | number)[] +> : undefined +> : undefined +> : undefined >...a0 : number >a0 : number[] +>"hello" : string var a3 = [,, ...a0] >a3 : number[] >[,, ...a0] : number[] +> : undefined +> : undefined >...a0 : number >a0 : number[] @@ -32,12 +45,14 @@ var a4 = [() => 1, ]; >a4 : (() => number)[] >[() => 1, ] : (() => number)[] >() => 1 : () => number +>1 : number var a5 = [...a0, , ] >a5 : number[] >[...a0, , ] : number[] >...a0 : number >a0 : number[] +> : undefined // Each element expression in a non-empty array literal is processed as follows: // - If the array literal contains no spread elements, and if the array literal is contextually typed (section 4.19) @@ -52,13 +67,19 @@ var b0: [any, any, any] = [undefined, null, undefined]; >b0 : [any, any, any] >[undefined, null, undefined] : [undefined, null, undefined] >undefined : undefined +>null : null >undefined : undefined var b1: [number[], string[]] = [[1, 2, 3], ["hello", "string"]]; >b1 : [number[], string[]] >[[1, 2, 3], ["hello", "string"]] : [number[], string[]] >[1, 2, 3] : number[] +>1 : number +>2 : number +>3 : number >["hello", "string"] : string[] +>"hello" : string +>"string" : string // The resulting type an array literal expression is determined as follows: // - If the array literal contains no spread elements and is an array assignment pattern in a destructuring assignment (section 4.17.1), @@ -68,11 +89,16 @@ var [c0, c1] = [1, 2]; // tuple type [number, number] >c0 : number >c1 : number >[1, 2] : [number, number] +>1 : number +>2 : number var [c2, c3] = [1, 2, true]; // tuple type [number, number, boolean] >c2 : number >c3 : number >[1, 2, true] : [number, number, boolean] +>1 : number +>2 : number +>true : boolean // The resulting type an array literal expression is determined as follows: // - the resulting type is an array type with an element type that is the union of the types of the @@ -80,21 +106,33 @@ var [c2, c3] = [1, 2, true]; // tuple type [number, number, boolean] var temp = ["s", "t", "r"]; >temp : string[] >["s", "t", "r"] : string[] +>"s" : string +>"t" : string +>"r" : string var temp1 = [1, 2, 3]; >temp1 : number[] >[1, 2, 3] : number[] +>1 : number +>2 : number +>3 : number var temp2: [number[], string[]] = [[1, 2, 3], ["hello", "string"]]; >temp2 : [number[], string[]] >[[1, 2, 3], ["hello", "string"]] : [number[], string[]] >[1, 2, 3] : number[] +>1 : number +>2 : number +>3 : number >["hello", "string"] : string[] +>"hello" : string +>"string" : string var temp3 = [undefined, null, undefined]; >temp3 : any[] >[undefined, null, undefined] : null[] >undefined : undefined +>null : null >undefined : undefined var temp4 = []; @@ -115,6 +153,8 @@ interface myArray2 extends Array { } var d0 = [1, true, ...temp,]; // has type (string|number|boolean)[] >d0 : (string | number | boolean)[] >[1, true, ...temp,] : (string | number | boolean)[] +>1 : number +>true : boolean >...temp : string >temp : string[] @@ -181,4 +221,5 @@ var d9 = [[...temp1], ...["hello"]]; >temp1 : number[] >...["hello"] : string >["hello"] : string[] +>"hello" : string diff --git a/tests/baselines/reference/arrayLiterals2ES6.symbols b/tests/baselines/reference/arrayLiterals2ES6.symbols new file mode 100644 index 00000000000..6367bd99f55 --- /dev/null +++ b/tests/baselines/reference/arrayLiterals2ES6.symbols @@ -0,0 +1,126 @@ +=== tests/cases/conformance/expressions/arrayLiterals/arrayLiterals2ES6.ts === +// ElementList: ( Modified ) +// Elisionopt AssignmentExpression +// Elisionopt SpreadElement +// ElementList, Elisionopt AssignmentExpression +// ElementList, Elisionopt SpreadElement + +// SpreadElement: +// ... AssignmentExpression + +var a0 = [, , 2, 3, 4] +>a0 : Symbol(a0, Decl(arrayLiterals2ES6.ts, 9, 3)) + +var a1 = ["hello", "world"] +>a1 : Symbol(a1, Decl(arrayLiterals2ES6.ts, 10, 3)) + +var a2 = [, , , ...a0, "hello"]; +>a2 : Symbol(a2, Decl(arrayLiterals2ES6.ts, 11, 3)) +>a0 : Symbol(a0, Decl(arrayLiterals2ES6.ts, 9, 3)) + +var a3 = [, , ...a0] +>a3 : Symbol(a3, Decl(arrayLiterals2ES6.ts, 12, 3)) +>a0 : Symbol(a0, Decl(arrayLiterals2ES6.ts, 9, 3)) + +var a4 = [() => 1, ]; +>a4 : Symbol(a4, Decl(arrayLiterals2ES6.ts, 13, 3)) + +var a5 = [...a0, , ] +>a5 : Symbol(a5, Decl(arrayLiterals2ES6.ts, 14, 3)) +>a0 : Symbol(a0, Decl(arrayLiterals2ES6.ts, 9, 3)) + +// Each element expression in a non-empty array literal is processed as follows: +// - If the array literal contains no spread elements, and if the array literal is contextually typed (section 4.19) +// by a type T and T has a property with the numeric name N, where N is the index of the element expression in the array literal, +// the element expression is contextually typed by the type of that property. + +// The resulting type an array literal expression is determined as follows: +// - If the array literal contains no spread elements and is contextually typed by a tuple-like type, +// the resulting type is a tuple type constructed from the types of the element expressions. + +var b0: [any, any, any] = [undefined, null, undefined]; +>b0 : Symbol(b0, Decl(arrayLiterals2ES6.ts, 25, 3)) +>undefined : Symbol(undefined) +>undefined : Symbol(undefined) + +var b1: [number[], string[]] = [[1, 2, 3], ["hello", "string"]]; +>b1 : Symbol(b1, Decl(arrayLiterals2ES6.ts, 26, 3)) + +// The resulting type an array literal expression is determined as follows: +// - If the array literal contains no spread elements and is an array assignment pattern in a destructuring assignment (section 4.17.1), +// the resulting type is a tuple type constructed from the types of the element expressions. + +var [c0, c1] = [1, 2]; // tuple type [number, number] +>c0 : Symbol(c0, Decl(arrayLiterals2ES6.ts, 32, 5)) +>c1 : Symbol(c1, Decl(arrayLiterals2ES6.ts, 32, 8)) + +var [c2, c3] = [1, 2, true]; // tuple type [number, number, boolean] +>c2 : Symbol(c2, Decl(arrayLiterals2ES6.ts, 33, 5)) +>c3 : Symbol(c3, Decl(arrayLiterals2ES6.ts, 33, 8)) + +// The resulting type an array literal expression is determined as follows: +// - the resulting type is an array type with an element type that is the union of the types of the +// non - spread element expressions and the numeric index signature types of the spread element expressions +var temp = ["s", "t", "r"]; +>temp : Symbol(temp, Decl(arrayLiterals2ES6.ts, 38, 3)) + +var temp1 = [1, 2, 3]; +>temp1 : Symbol(temp1, Decl(arrayLiterals2ES6.ts, 39, 3)) + +var temp2: [number[], string[]] = [[1, 2, 3], ["hello", "string"]]; +>temp2 : Symbol(temp2, Decl(arrayLiterals2ES6.ts, 40, 3)) + +interface myArray extends Array { } +>myArray : Symbol(myArray, Decl(arrayLiterals2ES6.ts, 40, 67)) +>Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11), Decl(lib.d.ts, 1409, 1)) +>Number : Symbol(Number, Decl(lib.d.ts, 456, 40), Decl(lib.d.ts, 518, 11)) + +interface myArray2 extends Array { } +>myArray2 : Symbol(myArray2, Decl(arrayLiterals2ES6.ts, 42, 43)) +>Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11), Decl(lib.d.ts, 1409, 1)) +>Number : Symbol(Number, Decl(lib.d.ts, 456, 40), Decl(lib.d.ts, 518, 11)) +>String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11), Decl(lib.d.ts, 1508, 1)) + +var d0 = [1, true, ...temp, ]; // has type (string|number|boolean)[] +>d0 : Symbol(d0, Decl(arrayLiterals2ES6.ts, 44, 3)) +>temp : Symbol(temp, Decl(arrayLiterals2ES6.ts, 38, 3)) + +var d1 = [...temp]; // has type string[] +>d1 : Symbol(d1, Decl(arrayLiterals2ES6.ts, 45, 3)) +>temp : Symbol(temp, Decl(arrayLiterals2ES6.ts, 38, 3)) + +var d2: number[] = [...temp1]; +>d2 : Symbol(d2, Decl(arrayLiterals2ES6.ts, 46, 3)) +>temp1 : Symbol(temp1, Decl(arrayLiterals2ES6.ts, 39, 3)) + +var d3: myArray = [...temp1]; +>d3 : Symbol(d3, Decl(arrayLiterals2ES6.ts, 47, 3)) +>myArray : Symbol(myArray, Decl(arrayLiterals2ES6.ts, 40, 67)) +>temp1 : Symbol(temp1, Decl(arrayLiterals2ES6.ts, 39, 3)) + +var d4: myArray2 = [...temp, ...temp1]; +>d4 : Symbol(d4, Decl(arrayLiterals2ES6.ts, 48, 3)) +>myArray2 : Symbol(myArray2, Decl(arrayLiterals2ES6.ts, 42, 43)) +>temp : Symbol(temp, Decl(arrayLiterals2ES6.ts, 38, 3)) +>temp1 : Symbol(temp1, Decl(arrayLiterals2ES6.ts, 39, 3)) + +var d5 = [...a2]; +>d5 : Symbol(d5, Decl(arrayLiterals2ES6.ts, 49, 3)) +>a2 : Symbol(a2, Decl(arrayLiterals2ES6.ts, 11, 3)) + +var d6 = [...a3]; +>d6 : Symbol(d6, Decl(arrayLiterals2ES6.ts, 50, 3)) +>a3 : Symbol(a3, Decl(arrayLiterals2ES6.ts, 12, 3)) + +var d7 = [...a4]; +>d7 : Symbol(d7, Decl(arrayLiterals2ES6.ts, 51, 3)) +>a4 : Symbol(a4, Decl(arrayLiterals2ES6.ts, 13, 3)) + +var d8: number[][] = [[...temp1]] +>d8 : Symbol(d8, Decl(arrayLiterals2ES6.ts, 52, 3)) +>temp1 : Symbol(temp1, Decl(arrayLiterals2ES6.ts, 39, 3)) + +var d9 = [[...temp1], ...["hello"]]; +>d9 : Symbol(d9, Decl(arrayLiterals2ES6.ts, 53, 3)) +>temp1 : Symbol(temp1, Decl(arrayLiterals2ES6.ts, 39, 3)) + diff --git a/tests/baselines/reference/arrayLiterals2ES6.types b/tests/baselines/reference/arrayLiterals2ES6.types index 0ae1487d190..f05b0ca9282 100644 --- a/tests/baselines/reference/arrayLiterals2ES6.types +++ b/tests/baselines/reference/arrayLiterals2ES6.types @@ -11,20 +11,33 @@ var a0 = [, , 2, 3, 4] >a0 : number[] >[, , 2, 3, 4] : number[] +> : undefined +> : undefined +>2 : number +>3 : number +>4 : number var a1 = ["hello", "world"] >a1 : string[] >["hello", "world"] : string[] +>"hello" : string +>"world" : string var a2 = [, , , ...a0, "hello"]; >a2 : (string | number)[] >[, , , ...a0, "hello"] : (string | number)[] +> : undefined +> : undefined +> : undefined >...a0 : number >a0 : number[] +>"hello" : string var a3 = [, , ...a0] >a3 : number[] >[, , ...a0] : number[] +> : undefined +> : undefined >...a0 : number >a0 : number[] @@ -32,12 +45,14 @@ var a4 = [() => 1, ]; >a4 : (() => number)[] >[() => 1, ] : (() => number)[] >() => 1 : () => number +>1 : number var a5 = [...a0, , ] >a5 : number[] >[...a0, , ] : number[] >...a0 : number >a0 : number[] +> : undefined // Each element expression in a non-empty array literal is processed as follows: // - If the array literal contains no spread elements, and if the array literal is contextually typed (section 4.19) @@ -52,13 +67,19 @@ var b0: [any, any, any] = [undefined, null, undefined]; >b0 : [any, any, any] >[undefined, null, undefined] : [undefined, null, undefined] >undefined : undefined +>null : null >undefined : undefined var b1: [number[], string[]] = [[1, 2, 3], ["hello", "string"]]; >b1 : [number[], string[]] >[[1, 2, 3], ["hello", "string"]] : [number[], string[]] >[1, 2, 3] : number[] +>1 : number +>2 : number +>3 : number >["hello", "string"] : string[] +>"hello" : string +>"string" : string // The resulting type an array literal expression is determined as follows: // - If the array literal contains no spread elements and is an array assignment pattern in a destructuring assignment (section 4.17.1), @@ -68,11 +89,16 @@ var [c0, c1] = [1, 2]; // tuple type [number, number] >c0 : number >c1 : number >[1, 2] : [number, number] +>1 : number +>2 : number var [c2, c3] = [1, 2, true]; // tuple type [number, number, boolean] >c2 : number >c3 : number >[1, 2, true] : [number, number, boolean] +>1 : number +>2 : number +>true : boolean // The resulting type an array literal expression is determined as follows: // - the resulting type is an array type with an element type that is the union of the types of the @@ -80,16 +106,27 @@ var [c2, c3] = [1, 2, true]; // tuple type [number, number, boolean] var temp = ["s", "t", "r"]; >temp : string[] >["s", "t", "r"] : string[] +>"s" : string +>"t" : string +>"r" : string var temp1 = [1, 2, 3]; >temp1 : number[] >[1, 2, 3] : number[] +>1 : number +>2 : number +>3 : number var temp2: [number[], string[]] = [[1, 2, 3], ["hello", "string"]]; >temp2 : [number[], string[]] >[[1, 2, 3], ["hello", "string"]] : [number[], string[]] >[1, 2, 3] : number[] +>1 : number +>2 : number +>3 : number >["hello", "string"] : string[] +>"hello" : string +>"string" : string interface myArray extends Array { } >myArray : myArray @@ -105,6 +142,8 @@ interface myArray2 extends Array { } var d0 = [1, true, ...temp, ]; // has type (string|number|boolean)[] >d0 : (string | number | boolean)[] >[1, true, ...temp, ] : (string | number | boolean)[] +>1 : number +>true : boolean >...temp : string >temp : string[] @@ -169,4 +208,5 @@ var d9 = [[...temp1], ...["hello"]]; >temp1 : number[] >...["hello"] : string >["hello"] : string[] +>"hello" : string From 31da11656edfb4f168f4317f5893d973e9d7ea9b Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 16 Apr 2015 18:53:16 -0700 Subject: [PATCH 040/194] Add spec description --- ...turingArrayBindingPatternAndAssignment1.js | 41 ---- ...ingArrayBindingPatternAndAssignment1.types | 133 ------------ ...ingArrayBindingPatternAndAssignment1ES5.js | 100 +++++++++ ...ArrayBindingPatternAndAssignment1ES5.types | 177 ++++++++++++++++ ...ingArrayBindingPatternAndAssignment1ES6.js | 99 +++++++++ ...ArrayBindingPatternAndAssignment1ES6.types | 177 ++++++++++++++++ ...rayBindingPatternAndAssignment2.errors.txt | 71 +++++++ ...turingArrayBindingPatternAndAssignment2.js | 59 ++++-- ...ingArrayBindingPatternAndAssignment2.types | 41 ---- ...rayBindingPatternAndAssignment3.errors.txt | 51 ----- ...turingArrayBindingPatternAndAssignment3.js | 41 ---- ...uringObjectBindingPatternAndAssignment1.js | 27 --- ...ngObjectBindingPatternAndAssignment1.types | 87 -------- ...ngObjectBindingPatternAndAssignment1ES5.js | 90 ++++++++ ...bjectBindingPatternAndAssignment1ES5.types | 133 ++++++++++++ ...ngObjectBindingPatternAndAssignment1ES6.js | 90 ++++++++ ...bjectBindingPatternAndAssignment1ES6.types | 133 ++++++++++++ ...uringObjectBindingPatternAndAssignment2.js | 76 ------- ...ngObjectBindingPatternAndAssignment2.types | 116 ---------- ...ectBindingPatternAndAssignment3.errors.txt | 26 +-- ...uringObjectBindingPatternAndAssignment3.js | 10 +- ...ectBindingPatternAndAssignment4.errors.txt | 37 ---- ...uringObjectBindingPatternAndAssignment4.js | 37 ---- .../destructuringVariableDeclaration1ES5.js | 77 +++++++ ...destructuringVariableDeclaration1ES5.types | 200 ++++++++++++++++++ .../destructuringVariableDeclaration1ES6.js | 77 +++++++ ...destructuringVariableDeclaration1ES6.types | 200 ++++++++++++++++++ ...structuringVariableDeclaration2.errors.txt | 62 ++++++ .../destructuringVariableDeclaration2.js | 38 ++++ ...ariableDeclarationAndAssignment.errors.txt | 15 -- ...cturingVariableDeclarationAndAssignment.js | 9 - ...turingArrayBindingPatternAndAssignment1.ts | 22 -- ...ingArrayBindingPatternAndAssignment1ES5.ts | 52 +++++ ...ingArrayBindingPatternAndAssignment1ES6.ts | 53 +++++ ...turingArrayBindingPatternAndAssignment2.ts | 33 ++- ...turingArrayBindingPatternAndAssignment3.ts | 23 -- ...uringObjectBindingPatternAndAssignment1.ts | 12 -- ...ngObjectBindingPatternAndAssignment1ES5.ts | 54 +++++ ...ngObjectBindingPatternAndAssignment1ES6.ts | 55 +++++ ...uringObjectBindingPatternAndAssignment2.ts | 46 ---- ...uringObjectBindingPatternAndAssignment3.ts | 8 +- ...uringObjectBindingPatternAndAssignment4.ts | 23 -- .../destructuringVariableDeclaration1ES5.ts | 40 ++++ .../destructuringVariableDeclaration1ES6.ts | 41 ++++ .../destructuringVariableDeclaration2.ts | 19 ++ ...cturingVariableDeclarationAndAssignment.ts | 3 - 46 files changed, 2134 insertions(+), 880 deletions(-) delete mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1.js delete mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1.types create mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.js create mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types create mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.js create mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types create mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt delete mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.types delete mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment3.errors.txt delete mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment3.js delete mode 100644 tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1.js delete mode 100644 tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1.types create mode 100644 tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.js create mode 100644 tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.types create mode 100644 tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.js create mode 100644 tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.types delete mode 100644 tests/baselines/reference/destructuringObjectBindingPatternAndAssignment2.js delete mode 100644 tests/baselines/reference/destructuringObjectBindingPatternAndAssignment2.types delete mode 100644 tests/baselines/reference/destructuringObjectBindingPatternAndAssignment4.errors.txt delete mode 100644 tests/baselines/reference/destructuringObjectBindingPatternAndAssignment4.js create mode 100644 tests/baselines/reference/destructuringVariableDeclaration1ES5.js create mode 100644 tests/baselines/reference/destructuringVariableDeclaration1ES5.types create mode 100644 tests/baselines/reference/destructuringVariableDeclaration1ES6.js create mode 100644 tests/baselines/reference/destructuringVariableDeclaration1ES6.types create mode 100644 tests/baselines/reference/destructuringVariableDeclaration2.errors.txt create mode 100644 tests/baselines/reference/destructuringVariableDeclaration2.js delete mode 100644 tests/baselines/reference/destructuringVariableDeclarationAndAssignment.errors.txt delete mode 100644 tests/baselines/reference/destructuringVariableDeclarationAndAssignment.js delete mode 100644 tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.ts delete mode 100644 tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts delete mode 100644 tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1ES5.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1ES6.ts delete mode 100644 tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment2.ts delete mode 100644 tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment4.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration1ES5.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration1ES6.ts create mode 100644 tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration2.ts delete mode 100644 tests/cases/conformance/es6/destructuring/destructuringVariableDeclarationAndAssignment.ts diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1.js b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1.js deleted file mode 100644 index f6c84b011d0..00000000000 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1.js +++ /dev/null @@ -1,41 +0,0 @@ -//// [destructuringArrayBindingPatternAndAssignment1.ts] -var [p0,p1, p2] : any = [2, 3, 4]; -var [a, b, c]: [number, number, string] = [1, 2, "string"]; -var [d, e]: any = undefined; -var [f = false, g = 1]: any = undefined; -g = 10; -f = true; - -var [x] = [] -var [[[y]], [[[[z]]]]] = [[[]], [[[[]]]]] -var [[w], m]: [[string|number], boolean] = [[1], true]; -interface J extends Array { - 2: number; -} - -var [, w1] = [1, 2, 3]; -var [,,, w2] = [1, 2, 3, 4]; -var [,,, w2] = [1, 2, 3, 4]; -var [,,,...w3] = [1, 2, 3, 4, "hello"]; - -var [r, s, ...t] = [1, 2, "string"]; -var [r1, s1, t1] = [1, 2, "string"]; - - - -//// [destructuringArrayBindingPatternAndAssignment1.js] -var _a = [2, 3, 4], p0 = _a[0], p1 = _a[1], p2 = _a[2]; -var _b = [1, 2, "string"], a = _b[0], b = _b[1], c = _b[2]; -var d = undefined[0], e = undefined[1]; -var _c = undefined[0], f = _c === void 0 ? false : _c, _d = undefined[1], g = _d === void 0 ? 1 : _d; -g = 10; -f = true; -var x = ([])[0]; -var _e = [[[]], [[[[]]]]], y = _e[0][0][0], z = _e[1][0][0][0][0]; -var _f = [[1], true], w = _f[0][0], m = _f[1]; -var _g = [1, 2, 3], w1 = _g[1]; -var _h = [1, 2, 3, 4], w2 = _h[3]; -var _j = [1, 2, 3, 4], w2 = _j[3]; -var _k = [1, 2, 3, 4, "hello"], w3 = _k.slice(3); -var _l = [1, 2, "string"], r = _l[0], s = _l[1], t = _l.slice(2); -var _m = [1, 2, "string"], r1 = _m[0], s1 = _m[1], t1 = _m[2]; diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1.types deleted file mode 100644 index f4abb8953f6..00000000000 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1.types +++ /dev/null @@ -1,133 +0,0 @@ -=== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1.ts === -var [p0,p1, p2] : any = [2, 3, 4]; ->p0 : any, Symbol(p0, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 0, 5)) ->p1 : any, Symbol(p1, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 0, 8)) ->p2 : any, Symbol(p2, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 0, 11)) ->[2, 3, 4] : number[] ->2 : number ->3 : number ->4 : number - -var [a, b, c]: [number, number, string] = [1, 2, "string"]; ->a : number, Symbol(a, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 1, 5)) ->b : number, Symbol(b, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 1, 7)) ->c : string, Symbol(c, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 1, 10)) ->[1, 2, "string"] : [number, number, string] ->1 : number ->2 : number ->"string" : string - -var [d, e]: any = undefined; ->d : any, Symbol(d, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 2, 5)) ->e : any, Symbol(e, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 2, 7)) ->undefined : undefined, Symbol(undefined) - -var [f = false, g = 1]: any = undefined; ->f : boolean, Symbol(f, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 3, 5)) ->false : boolean ->g : number, Symbol(g, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 3, 15)) ->1 : number ->undefined : undefined, Symbol(undefined) - -g = 10; ->g = 10 : number ->g : number, Symbol(g, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 3, 15)) ->10 : number - -f = true; ->f = true : boolean ->f : boolean, Symbol(f, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 3, 5)) ->true : boolean - -var [x] = [] ->x : any, Symbol(x, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 7, 5)) ->[] : undefined[] - -var [[[y]], [[[[z]]]]] = [[[]], [[[[]]]]] ->y : any, Symbol(y, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 8, 7)) ->z : any, Symbol(z, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 8, 16)) ->[[[]], [[[[]]]]] : [[undefined[]], [[[undefined[]]]]] ->[[]] : [undefined[]] ->[] : undefined[] ->[[[[]]]] : [[[undefined[]]]] ->[[[]]] : [[undefined[]]] ->[[]] : [undefined[]] ->[] : undefined[] - -var [[w], m]: [[string|number], boolean] = [[1], true]; ->w : string | number, Symbol(w, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 9, 6)) ->m : boolean, Symbol(m, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 9, 9)) ->[[1], true] : [[number], boolean] ->[1] : [number] ->1 : number ->true : boolean - -interface J extends Array { ->J : J, Symbol(J, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 9, 55)) ->Array : T[], Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11)) ->Number : Number, Symbol(Number, Decl(lib.d.ts, 456, 40), Decl(lib.d.ts, 518, 11)) - - 2: number; -} - -var [, w1] = [1, 2, 3]; -> : undefined ->w1 : number, Symbol(w1, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 14, 6)) ->[1, 2, 3] : [number, number, number] ->1 : number ->2 : number ->3 : number - -var [,,, w2] = [1, 2, 3, 4]; -> : undefined -> : undefined -> : undefined ->w2 : number, Symbol(w2, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 15, 8), Decl(destructuringArrayBindingPatternAndAssignment1.ts, 16, 8)) ->[1, 2, 3, 4] : [number, number, number, number] ->1 : number ->2 : number ->3 : number ->4 : number - -var [,,, w2] = [1, 2, 3, 4]; -> : undefined -> : undefined -> : undefined ->w2 : number, Symbol(w2, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 15, 8), Decl(destructuringArrayBindingPatternAndAssignment1.ts, 16, 8)) ->[1, 2, 3, 4] : [number, number, number, number] ->1 : number ->2 : number ->3 : number ->4 : number - -var [,,,...w3] = [1, 2, 3, 4, "hello"]; -> : undefined -> : undefined -> : undefined ->w3 : (string | number)[], Symbol(w3, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 17, 8)) ->[1, 2, 3, 4, "hello"] : (string | number)[] ->1 : number ->2 : number ->3 : number ->4 : number ->"hello" : string - -var [r, s, ...t] = [1, 2, "string"]; ->r : string | number, Symbol(r, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 19, 5)) ->s : string | number, Symbol(s, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 19, 7)) ->t : (string | number)[], Symbol(t, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 19, 10)) ->[1, 2, "string"] : (string | number)[] ->1 : number ->2 : number ->"string" : string - -var [r1, s1, t1] = [1, 2, "string"]; ->r1 : number, Symbol(r1, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 20, 5)) ->s1 : number, Symbol(s1, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 20, 8)) ->t1 : string, Symbol(t1, Decl(destructuringArrayBindingPatternAndAssignment1.ts, 20, 12)) ->[1, 2, "string"] : [number, number, string] ->1 : number ->2 : number ->"string" : string - - diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.js b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.js new file mode 100644 index 00000000000..6a94b0d2a7f --- /dev/null +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.js @@ -0,0 +1,100 @@ +//// [destructuringArrayBindingPatternAndAssignment1ES5.ts] +/* AssignmentPattern: + * ObjectAssignmentPattern + * ArrayAssignmentPattern + * ArrayAssignmentPattern: + * [Elision AssignmentRestElementopt ] + * [AssignmentElementList] + * [AssignmentElementList, Elision AssignmentRestElementopt ] + * AssignmentElementList: + * Elision AssignmentElement + * AssignmentElementList, Elisionopt AssignmentElement + * AssignmentElement: + * LeftHandSideExpression Initialiseropt + * AssignmentPattern Initialiseropt + * AssignmentRestElement: + * ... LeftHandSideExpression + */ + +// In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left. +// An expression of type S is considered assignable to an assignment target V if one of the following is true + +// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, +// S is the type Any, or + +var [a0, a1]: any = undefined; +var [a2 = false, a3 = 1]: any = undefined; + +// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, +// S is a tuple- like type (section 3.3.3) with a property named N of a type that is assignable to the target given in E, +// where N is the numeric index of E in the array assignment pattern, or +var [b0, b1, b2] = [2, 3, 4]; +var [b3, b4, b5]: [number, number, string] = [1, 2, "string"]; + +function foo() { + return [1, 2, 3]; +} + +var [b6, b7] = foo(); +var [...b8] = foo(); + +// S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E. +var temp = [1,2,3] +var [c0, c1] = [...temp]; +var [c2] = []; +var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] +var [[c5], c6]: [[string|number], boolean] = [[1], true]; +var [, c7] = [1, 2, 3]; +var [,,, c8] = [1, 2, 3, 4]; +var [,,, c9] = [1, 2, 3, 4]; +var [,,,...c10] = [1, 2, 3, 4, "hello"]; +var [c11, c12, ...c13] = [1, 2, "string"]; +var [c14, c15, c16] = [1, 2, "string"]; + + + +//// [destructuringArrayBindingPatternAndAssignment1ES5.js] +/* AssignmentPattern: + * ObjectAssignmentPattern + * ArrayAssignmentPattern + * ArrayAssignmentPattern: + * [Elision AssignmentRestElementopt ] + * [AssignmentElementList] + * [AssignmentElementList, Elision AssignmentRestElementopt ] + * AssignmentElementList: + * Elision AssignmentElement + * AssignmentElementList, Elisionopt AssignmentElement + * AssignmentElement: + * LeftHandSideExpression Initialiseropt + * AssignmentPattern Initialiseropt + * AssignmentRestElement: + * ... LeftHandSideExpression + */ +// In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left. +// An expression of type S is considered assignable to an assignment target V if one of the following is true +// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, +// S is the type Any, or +var a0 = undefined[0], a1 = undefined[1]; +var _a = undefined[0], a2 = _a === void 0 ? false : _a, _b = undefined[1], a3 = _b === void 0 ? 1 : _b; +// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, +// S is a tuple- like type (section 3.3.3) with a property named N of a type that is assignable to the target given in E, +// where N is the numeric index of E in the array assignment pattern, or +var _c = [2, 3, 4], b0 = _c[0], b1 = _c[1], b2 = _c[2]; +var _d = [1, 2, "string"], b3 = _d[0], b4 = _d[1], b5 = _d[2]; +function foo() { + return [1, 2, 3]; +} +var _e = foo(), b6 = _e[0], b7 = _e[1]; +var _f = foo(), b8 = _f.slice(0); +// S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E. +var temp = [1, 2, 3]; +var _g = temp, c0 = _g[0], c1 = _g[1]; +var c2 = ([])[0]; +var _h = [[[]], [[[[]]]]], c3 = _h[0][0][0], c4 = _h[1][0][0][0][0]; +var _j = [[1], true], c5 = _j[0][0], c6 = _j[1]; +var _k = [1, 2, 3], c7 = _k[1]; +var _l = [1, 2, 3, 4], c8 = _l[3]; +var _m = [1, 2, 3, 4], c9 = _m[3]; +var _o = [1, 2, 3, 4, "hello"], c10 = _o.slice(3); +var _p = [1, 2, "string"], c11 = _p[0], c12 = _p[1], c13 = _p.slice(2); +var _q = [1, 2, "string"], c14 = _q[0], c15 = _q[1], c16 = _q[2]; diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types new file mode 100644 index 00000000000..6508581d899 --- /dev/null +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types @@ -0,0 +1,177 @@ +=== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts === +/* AssignmentPattern: + * ObjectAssignmentPattern + * ArrayAssignmentPattern + * ArrayAssignmentPattern: + * [Elision AssignmentRestElementopt ] + * [AssignmentElementList] + * [AssignmentElementList, Elision AssignmentRestElementopt ] + * AssignmentElementList: + * Elision AssignmentElement + * AssignmentElementList, Elisionopt AssignmentElement + * AssignmentElement: + * LeftHandSideExpression Initialiseropt + * AssignmentPattern Initialiseropt + * AssignmentRestElement: + * ... LeftHandSideExpression + */ + +// In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left. +// An expression of type S is considered assignable to an assignment target V if one of the following is true + +// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, +// S is the type Any, or + +var [a0, a1]: any = undefined; +>a0 : any, Symbol(a0, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 23, 5)) +>a1 : any, Symbol(a1, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 23, 8)) +>undefined : undefined, Symbol(undefined) + +var [a2 = false, a3 = 1]: any = undefined; +>a2 : boolean, Symbol(a2, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 24, 5)) +>false : boolean +>a3 : number, Symbol(a3, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 24, 16)) +>1 : number +>undefined : undefined, Symbol(undefined) + +// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, +// S is a tuple- like type (section 3.3.3) with a property named N of a type that is assignable to the target given in E, +// where N is the numeric index of E in the array assignment pattern, or +var [b0, b1, b2] = [2, 3, 4]; +>b0 : number, Symbol(b0, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 29, 5)) +>b1 : number, Symbol(b1, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 29, 8)) +>b2 : number, Symbol(b2, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 29, 12)) +>[2, 3, 4] : [number, number, number] +>2 : number +>3 : number +>4 : number + +var [b3, b4, b5]: [number, number, string] = [1, 2, "string"]; +>b3 : number, Symbol(b3, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 5)) +>b4 : number, Symbol(b4, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 8)) +>b5 : string, Symbol(b5, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 12)) +>[1, 2, "string"] : [number, number, string] +>1 : number +>2 : number +>"string" : string + +function foo() { +>foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 62)) + + return [1, 2, 3]; +>[1, 2, 3] : number[] +>1 : number +>2 : number +>3 : number +} + +var [b6, b7] = foo(); +>b6 : number, Symbol(b6, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 36, 5)) +>b7 : number, Symbol(b7, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 36, 8)) +>foo() : number[] +>foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 62)) + +var [...b8] = foo(); +>b8 : number[], Symbol(b8, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 37, 5)) +>foo() : number[] +>foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 62)) + +// S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E. +var temp = [1,2,3] +>temp : number[], Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 40, 3)) +>[1,2,3] : number[] +>1 : number +>2 : number +>3 : number + +var [c0, c1] = [...temp]; +>c0 : number, Symbol(c0, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 41, 5)) +>c1 : number, Symbol(c1, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 41, 8)) +>[...temp] : number[] +>...temp : number +>temp : number[], Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 40, 3)) + +var [c2] = []; +>c2 : any, Symbol(c2, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 42, 5)) +>[] : undefined[] + +var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] +>c3 : any, Symbol(c3, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 43, 7)) +>c4 : any, Symbol(c4, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 43, 17)) +>[[[]], [[[[]]]]] : [[undefined[]], [[[undefined[]]]]] +>[[]] : [undefined[]] +>[] : undefined[] +>[[[[]]]] : [[[undefined[]]]] +>[[[]]] : [[undefined[]]] +>[[]] : [undefined[]] +>[] : undefined[] + +var [[c5], c6]: [[string|number], boolean] = [[1], true]; +>c5 : string | number, Symbol(c5, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 44, 6)) +>c6 : boolean, Symbol(c6, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 44, 10)) +>[[1], true] : [[number], boolean] +>[1] : [number] +>1 : number +>true : boolean + +var [, c7] = [1, 2, 3]; +> : undefined +>c7 : number, Symbol(c7, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 45, 6)) +>[1, 2, 3] : [number, number, number] +>1 : number +>2 : number +>3 : number + +var [,,, c8] = [1, 2, 3, 4]; +> : undefined +> : undefined +> : undefined +>c8 : number, Symbol(c8, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 46, 8)) +>[1, 2, 3, 4] : [number, number, number, number] +>1 : number +>2 : number +>3 : number +>4 : number + +var [,,, c9] = [1, 2, 3, 4]; +> : undefined +> : undefined +> : undefined +>c9 : number, Symbol(c9, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 47, 8)) +>[1, 2, 3, 4] : [number, number, number, number] +>1 : number +>2 : number +>3 : number +>4 : number + +var [,,,...c10] = [1, 2, 3, 4, "hello"]; +> : undefined +> : undefined +> : undefined +>c10 : (string | number)[], Symbol(c10, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 48, 8)) +>[1, 2, 3, 4, "hello"] : (string | number)[] +>1 : number +>2 : number +>3 : number +>4 : number +>"hello" : string + +var [c11, c12, ...c13] = [1, 2, "string"]; +>c11 : string | number, Symbol(c11, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 49, 5)) +>c12 : string | number, Symbol(c12, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 49, 9)) +>c13 : (string | number)[], Symbol(c13, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 49, 14)) +>[1, 2, "string"] : (string | number)[] +>1 : number +>2 : number +>"string" : string + +var [c14, c15, c16] = [1, 2, "string"]; +>c14 : number, Symbol(c14, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 50, 5)) +>c15 : number, Symbol(c15, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 50, 9)) +>c16 : string, Symbol(c16, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 50, 14)) +>[1, 2, "string"] : [number, number, string] +>1 : number +>2 : number +>"string" : string + + diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.js b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.js new file mode 100644 index 00000000000..d3a5c9ff5aa --- /dev/null +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.js @@ -0,0 +1,99 @@ +//// [destructuringArrayBindingPatternAndAssignment1ES6.ts] + +/* AssignmentPattern: + * ObjectAssignmentPattern + * ArrayAssignmentPattern + * ArrayAssignmentPattern: + * [Elision AssignmentRestElementopt ] + * [AssignmentElementList] + * [AssignmentElementList, Elision AssignmentRestElementopt ] + * AssignmentElementList: + * Elision AssignmentElement + * AssignmentElementList, Elisionopt AssignmentElement + * AssignmentElement: + * LeftHandSideExpression Initialiseropt + * AssignmentPattern Initialiseropt + * AssignmentRestElement: + * ... LeftHandSideExpression + */ + +// In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left. +// An expression of type S is considered assignable to an assignment target V if one of the following is true + +// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, +// S is the type Any, or + +var [a0, a1]: any = undefined; +var [a2 = false, a3 = 1]: any = undefined; + +// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, +// S is a tuple- like type (section 3.3.3) with a property named N of a type that is assignable to the target given in E, +// where N is the numeric index of E in the array assignment pattern, or +var [b0, b1, b2] = [2, 3, 4]; +var [b3, b4, b5]: [number, number, string] = [1, 2, "string"]; + +function foo() { + return [1, 2, 3]; +} + +var [b6, b7] = foo(); +var [...b8] = foo(); + +// S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E. +var temp = [1,2,3] +var [c0, c1] = [...temp]; +var [c2] = []; +var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] +var [[c5], c6]: [[string|number], boolean] = [[1], true]; +var [, c7] = [1, 2, 3]; +var [,,, c8] = [1, 2, 3, 4]; +var [,,, c9] = [1, 2, 3, 4]; +var [,,,...c10] = [1, 2, 3, 4, "hello"]; +var [c11, c12, ...c13] = [1, 2, "string"]; +var [c14, c15, c16] = [1, 2, "string"]; + +//// [destructuringArrayBindingPatternAndAssignment1ES6.js] +/* AssignmentPattern: + * ObjectAssignmentPattern + * ArrayAssignmentPattern + * ArrayAssignmentPattern: + * [Elision AssignmentRestElementopt ] + * [AssignmentElementList] + * [AssignmentElementList, Elision AssignmentRestElementopt ] + * AssignmentElementList: + * Elision AssignmentElement + * AssignmentElementList, Elisionopt AssignmentElement + * AssignmentElement: + * LeftHandSideExpression Initialiseropt + * AssignmentPattern Initialiseropt + * AssignmentRestElement: + * ... LeftHandSideExpression + */ +// In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left. +// An expression of type S is considered assignable to an assignment target V if one of the following is true +// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, +// S is the type Any, or +var [a0, a1] = undefined; +var [a2 = false, a3 = 1] = undefined; +// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, +// S is a tuple- like type (section 3.3.3) with a property named N of a type that is assignable to the target given in E, +// where N is the numeric index of E in the array assignment pattern, or +var [b0, b1, b2] = [2, 3, 4]; +var [b3, b4, b5] = [1, 2, "string"]; +function foo() { + return [1, 2, 3]; +} +var [b6, b7] = foo(); +var [...b8] = foo(); +// S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E. +var temp = [1, 2, 3]; +var [c0, c1] = [...temp]; +var [c2] = []; +var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]]; +var [[c5], c6] = [[1], true]; +var [, c7] = [1, 2, 3]; +var [, , , c8] = [1, 2, 3, 4]; +var [, , , c9] = [1, 2, 3, 4]; +var [, , , ...c10] = [1, 2, 3, 4, "hello"]; +var [c11, c12, ...c13] = [1, 2, "string"]; +var [c14, c15, c16] = [1, 2, "string"]; diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types new file mode 100644 index 00000000000..4c999c9468a --- /dev/null +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types @@ -0,0 +1,177 @@ +=== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.ts === + +/* AssignmentPattern: + * ObjectAssignmentPattern + * ArrayAssignmentPattern + * ArrayAssignmentPattern: + * [Elision AssignmentRestElementopt ] + * [AssignmentElementList] + * [AssignmentElementList, Elision AssignmentRestElementopt ] + * AssignmentElementList: + * Elision AssignmentElement + * AssignmentElementList, Elisionopt AssignmentElement + * AssignmentElement: + * LeftHandSideExpression Initialiseropt + * AssignmentPattern Initialiseropt + * AssignmentRestElement: + * ... LeftHandSideExpression + */ + +// In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left. +// An expression of type S is considered assignable to an assignment target V if one of the following is true + +// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, +// S is the type Any, or + +var [a0, a1]: any = undefined; +>a0 : any, Symbol(a0, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 24, 5)) +>a1 : any, Symbol(a1, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 24, 8)) +>undefined : undefined, Symbol(undefined) + +var [a2 = false, a3 = 1]: any = undefined; +>a2 : boolean, Symbol(a2, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 25, 5)) +>false : boolean +>a3 : number, Symbol(a3, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 25, 16)) +>1 : number +>undefined : undefined, Symbol(undefined) + +// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, +// S is a tuple- like type (section 3.3.3) with a property named N of a type that is assignable to the target given in E, +// where N is the numeric index of E in the array assignment pattern, or +var [b0, b1, b2] = [2, 3, 4]; +>b0 : number, Symbol(b0, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 30, 5)) +>b1 : number, Symbol(b1, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 30, 8)) +>b2 : number, Symbol(b2, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 30, 12)) +>[2, 3, 4] : [number, number, number] +>2 : number +>3 : number +>4 : number + +var [b3, b4, b5]: [number, number, string] = [1, 2, "string"]; +>b3 : number, Symbol(b3, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 5)) +>b4 : number, Symbol(b4, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 8)) +>b5 : string, Symbol(b5, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 12)) +>[1, 2, "string"] : [number, number, string] +>1 : number +>2 : number +>"string" : string + +function foo() { +>foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 62)) + + return [1, 2, 3]; +>[1, 2, 3] : number[] +>1 : number +>2 : number +>3 : number +} + +var [b6, b7] = foo(); +>b6 : number, Symbol(b6, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 37, 5)) +>b7 : number, Symbol(b7, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 37, 8)) +>foo() : number[] +>foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 62)) + +var [...b8] = foo(); +>b8 : number[], Symbol(b8, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 38, 5)) +>foo() : number[] +>foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 62)) + +// S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E. +var temp = [1,2,3] +>temp : number[], Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 41, 3)) +>[1,2,3] : number[] +>1 : number +>2 : number +>3 : number + +var [c0, c1] = [...temp]; +>c0 : number, Symbol(c0, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 42, 5)) +>c1 : number, Symbol(c1, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 42, 8)) +>[...temp] : number[] +>...temp : number +>temp : number[], Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 41, 3)) + +var [c2] = []; +>c2 : any, Symbol(c2, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 43, 5)) +>[] : undefined[] + +var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] +>c3 : any, Symbol(c3, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 44, 7)) +>c4 : any, Symbol(c4, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 44, 17)) +>[[[]], [[[[]]]]] : [[undefined[]], [[[undefined[]]]]] +>[[]] : [undefined[]] +>[] : undefined[] +>[[[[]]]] : [[[undefined[]]]] +>[[[]]] : [[undefined[]]] +>[[]] : [undefined[]] +>[] : undefined[] + +var [[c5], c6]: [[string|number], boolean] = [[1], true]; +>c5 : string | number, Symbol(c5, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 45, 6)) +>c6 : boolean, Symbol(c6, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 45, 10)) +>[[1], true] : [[number], boolean] +>[1] : [number] +>1 : number +>true : boolean + +var [, c7] = [1, 2, 3]; +> : undefined +>c7 : number, Symbol(c7, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 46, 6)) +>[1, 2, 3] : [number, number, number] +>1 : number +>2 : number +>3 : number + +var [,,, c8] = [1, 2, 3, 4]; +> : undefined +> : undefined +> : undefined +>c8 : number, Symbol(c8, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 47, 8)) +>[1, 2, 3, 4] : [number, number, number, number] +>1 : number +>2 : number +>3 : number +>4 : number + +var [,,, c9] = [1, 2, 3, 4]; +> : undefined +> : undefined +> : undefined +>c9 : number, Symbol(c9, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 48, 8)) +>[1, 2, 3, 4] : [number, number, number, number] +>1 : number +>2 : number +>3 : number +>4 : number + +var [,,,...c10] = [1, 2, 3, 4, "hello"]; +> : undefined +> : undefined +> : undefined +>c10 : (string | number)[], Symbol(c10, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 49, 8)) +>[1, 2, 3, 4, "hello"] : (string | number)[] +>1 : number +>2 : number +>3 : number +>4 : number +>"hello" : string + +var [c11, c12, ...c13] = [1, 2, "string"]; +>c11 : string | number, Symbol(c11, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 50, 5)) +>c12 : string | number, Symbol(c12, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 50, 9)) +>c13 : (string | number)[], Symbol(c13, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 50, 14)) +>[1, 2, "string"] : (string | number)[] +>1 : number +>2 : number +>"string" : string + +var [c14, c15, c16] = [1, 2, "string"]; +>c14 : number, Symbol(c14, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 51, 5)) +>c15 : number, Symbol(c15, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 51, 9)) +>c16 : string, Symbol(c16, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 51, 14)) +>[1, 2, "string"] : [number, number, string] +>1 : number +>2 : number +>"string" : string + diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt new file mode 100644 index 00000000000..a2e5cb7e17c --- /dev/null +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.errors.txt @@ -0,0 +1,71 @@ +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(3,6): error TS2461: Type 'undefined' is not an array type. +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(3,12): error TS2461: Type 'undefined' is not an array type. +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(4,5): error TS2461: Type 'undefined' is not an array type. +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(9,5): error TS2322: Type '[number, number, string]' is not assignable to type '[number, boolean, string]'. + Types of property '1' are incompatible. + Type 'number' is not assignable to type 'boolean'. +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(17,6): error TS2322: Type 'string' is not assignable to type 'Number'. + Property 'toFixed' is missing in type 'String'. +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(22,5): error TS2322: Type 'number[]' is not assignable to type '[number, number]'. + Property '0' is missing in type 'number[]'. +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(23,5): error TS2322: Type 'number[]' is not assignable to type '[string, string]'. + Property '0' is missing in type 'number[]'. +tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts(34,5): error TS2461: Type 'F' is not an array type. + + +==== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts (8 errors) ==== + // V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, + // S is the type Any, or + var [[a0], [[a1]]] = [] // Error + ~~~~ +!!! error TS2461: Type 'undefined' is not an array type. + ~~~~~~ +!!! error TS2461: Type 'undefined' is not an array type. + var [[a2], [[a3]]] = undefined // Error + ~~~~~~~~~~~~~~ +!!! error TS2461: Type 'undefined' is not an array type. + + // V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, + // S is a tuple- like type (section 3.3.3) with a property named N of a type that is assignable to the target given in E, + // where N is the numeric index of E in the array assignment pattern, or + var [b0, b1, b2]: [number, boolean, string] = [1, 2, "string"]; // Error + ~~~~~~~~~~~~ +!!! error TS2322: Type '[number, number, string]' is not assignable to type '[number, boolean, string]'. +!!! error TS2322: Types of property '1' are incompatible. +!!! error TS2322: Type 'number' is not assignable to type 'boolean'. + interface J extends Array { + 2: number; + } + + function bar(): J { + return <[number, number, number]>[1, 2, 3]; + } + var [b3 = "string", b4, b5] = bar(); // Error + ~~ +!!! error TS2322: Type 'string' is not assignable to type 'Number'. +!!! error TS2322: Property 'toFixed' is missing in type 'String'. + + // V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, + // S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E. + var temp = [1, 2, 3] + var [c0, c1]: [number, number] = [...temp]; // Error + ~~~~~~~~ +!!! error TS2322: Type 'number[]' is not assignable to type '[number, number]'. +!!! error TS2322: Property '0' is missing in type 'number[]'. + var [c2, c3]: [string, string] = [...temp]; // Error + ~~~~~~~~ +!!! error TS2322: Type 'number[]' is not assignable to type '[string, string]'. +!!! error TS2322: Property '0' is missing in type 'number[]'. + + interface F { + [idx: number]: boolean + } + + function foo(idx: number): F { + return { + 2: true + } + } + var [c4, c5, c6] = foo(1); // Error + ~~~~~~~~~~~~ +!!! error TS2461: Type 'F' is not an array type. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.js b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.js index 67cfaef96d6..fdbf47fd970 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.js +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.js @@ -1,25 +1,60 @@ //// [destructuringArrayBindingPatternAndAssignment2.ts] -function foo() { - return [1, 2, 3]; -} +// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, +// S is the type Any, or +var [[a0], [[a1]]] = [] // Error +var [[a2], [[a3]]] = undefined // Error + +// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, +// S is a tuple- like type (section 3.3.3) with a property named N of a type that is assignable to the target given in E, +// where N is the numeric index of E in the array assignment pattern, or +var [b0, b1, b2]: [number, boolean, string] = [1, 2, "string"]; // Error interface J extends Array { 2: number; } function bar(): J { - return <[number, number, number]>[1, 2, 3]; + return <[number, number, number]>[1, 2, 3]; +} +var [b3 = "string", b4, b5] = bar(); // Error + +// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, +// S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E. +var temp = [1, 2, 3] +var [c0, c1]: [number, number] = [...temp]; // Error +var [c2, c3]: [string, string] = [...temp]; // Error + +interface F { + [idx: number]: boolean } -var [j, k] = foo(); -var [...p] = foo(); - +function foo(idx: number): F { + return { + 2: true + } +} +var [c4, c5, c6] = foo(1); // Error //// [destructuringArrayBindingPatternAndAssignment2.js] -function foo() { - return [1, 2, 3]; -} +// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, +// S is the type Any, or +var _a = [], a0 = _a[0][0], a1 = _a[1][0][0]; // Error +var a2 = undefined[0][0], a3 = undefined[1][0][0]; // Error +// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, +// S is a tuple- like type (section 3.3.3) with a property named N of a type that is assignable to the target given in E, +// where N is the numeric index of E in the array assignment pattern, or +var _b = [1, 2, "string"], b0 = _b[0], b1 = _b[1], b2 = _b[2]; // Error function bar() { return [1, 2, 3]; } -var _a = foo(), j = _a[0], k = _a[1]; -var _b = foo(), p = _b.slice(0); +var _c = bar(), _d = _c[0], b3 = _d === void 0 ? "string" : _d, b4 = _c[1], b5 = _c[2]; // Error +// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, +// S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E. +var temp = [1, 2, 3]; +var _e = temp, c0 = _e[0], c1 = _e[1]; // Error +var _f = temp, c2 = _f[0], c3 = _f[1]; // Error +function foo(idx) { + return { + 2: true + }; +} +var _g = foo(1), c4 = _g[0], c5 = _g[1], c6 = _g[2]; // Error diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.types deleted file mode 100644 index f6b40e5fc95..00000000000 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment2.types +++ /dev/null @@ -1,41 +0,0 @@ -=== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts === -function foo() { ->foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 0, 0)) - - return [1, 2, 3]; ->[1, 2, 3] : number[] ->1 : number ->2 : number ->3 : number -} -interface J extends Array { ->J : J, Symbol(J, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 2, 1)) ->Array : T[], Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11)) ->Number : Number, Symbol(Number, Decl(lib.d.ts, 456, 40), Decl(lib.d.ts, 518, 11)) - - 2: number; -} - -function bar(): J { ->bar : () => J, Symbol(bar, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 5, 1)) ->J : J, Symbol(J, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 2, 1)) - - return <[number, number, number]>[1, 2, 3]; -><[number, number, number]>[1, 2, 3] : [number, number, number] ->[1, 2, 3] : [number, number, number] ->1 : number ->2 : number ->3 : number -} - -var [j, k] = foo(); ->j : number, Symbol(j, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 11, 5)) ->k : number, Symbol(k, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 11, 7)) ->foo() : number[] ->foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 0, 0)) - -var [...p] = foo(); ->p : number[], Symbol(p, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 12, 5)) ->foo() : number[] ->foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment2.ts, 0, 0)) - diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment3.errors.txt b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment3.errors.txt deleted file mode 100644 index 8cb1d9eb8c2..00000000000 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment3.errors.txt +++ /dev/null @@ -1,51 +0,0 @@ -tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts(19,5): error TS2322: Type 'undefined[]' is not assignable to type 'H'. - Property '0' is missing in type 'undefined[]'. -tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts(19,5): error TS2461: Type 'H' is not an array type. -tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts(20,6): error TS2461: Type 'undefined' is not an array type. -tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts(20,13): error TS2461: Type 'undefined' is not an array type. -tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts(21,13): error TS2462: A rest element must be last in an array destructuring pattern -tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts(22,6): error TS2322: Type 'string' is not assignable to type 'Number'. - Property 'toFixed' is missing in type 'String'. -tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts(23,5): error TS2461: Type '{}' is not an array type. - - -==== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts (7 errors) ==== - interface H { - 0: number, - 1: string - } - interface J extends Array { - 2: number; - } - - function bar(): J { - return <[number, number, number]>[1, 2, 3]; - } - - function gg(idx: number) { - return { - [idx]: true - } - } - - var [h, g, i]: H = []; - ~~~~~~~~~ -!!! error TS2322: Type 'undefined[]' is not assignable to type 'H'. -!!! error TS2322: Property '0' is missing in type 'undefined[]'. - ~~~~~~~~~ -!!! error TS2461: Type 'H' is not an array type. - var [[[y]], [[[[z]]]]] = [] - ~~~~~ -!!! error TS2461: Type 'undefined' is not an array type. - ~~~~~~~~~ -!!! error TS2461: Type 'undefined' is not an array type. - var [, , ...w4, , ] = [] - ~~ -!!! error TS2462: A rest element must be last in an array destructuring pattern - var [a = "string", b, c] = bar(); - ~ -!!! error TS2322: Type 'string' is not assignable to type 'Number'. -!!! error TS2322: Property 'toFixed' is missing in type 'String'. - var [r, s, t] = gg(1); - ~~~~~~~~~ -!!! error TS2461: Type '{}' is not an array type. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment3.js b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment3.js deleted file mode 100644 index ad5d1c5c051..00000000000 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment3.js +++ /dev/null @@ -1,41 +0,0 @@ -//// [destructuringArrayBindingPatternAndAssignment3.ts] -interface H { - 0: number, - 1: string -} -interface J extends Array { - 2: number; -} - -function bar(): J { - return <[number, number, number]>[1, 2, 3]; -} - -function gg(idx: number) { - return { - [idx]: true - } -} - -var [h, g, i]: H = []; -var [[[y]], [[[[z]]]]] = [] -var [, , ...w4, , ] = [] -var [a = "string", b, c] = bar(); -var [r, s, t] = gg(1); - -//// [destructuringArrayBindingPatternAndAssignment3.js] -function bar() { - return [1, 2, 3]; -} -function gg(idx) { - return (_a = {}, - _a[idx] = true, - _a - ); - var _a; -} -var _a = [], h = _a[0], g = _a[1], i = _a[2]; -var _b = [], y = _b[0][0][0], z = _b[1][0][0][0][0]; -var _c = []; -var _d = bar(), _e = _d[0], a = _e === void 0 ? "string" : _e, b = _d[1], c = _d[2]; -var _f = gg(1), r = _f[0], s = _f[1], t = _f[2]; diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1.js b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1.js deleted file mode 100644 index 375cfd8f573..00000000000 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1.js +++ /dev/null @@ -1,27 +0,0 @@ -//// [destructuringObjectBindingPatternAndAssignment1.ts] -var c = 0; -var { a, } = { a:1, }; -var { b: { c } } = { b: { c } }; -var { b1: { c1 } = { c1: "string" } } = { b1: { c1: "world" } }; -var { d1 }: any = undefined; -var { e1 }: any = {}; -var { f: {f1} = { f1: "string" } }: any = {}; -var { f2: {f21} = { f21: "string" } }: any = undefined; -var { e1: {e2} = { e2: "string" } }: any|{ e1: { e2 } } = undefined; -var { e2: {e3} = { e3: "string" } }: any|{ e2: { e3 } } = {}; -var {g = 1}: any = { g: 100000 }; -var {1: x} = { 1: "string" }; - -//// [destructuringObjectBindingPatternAndAssignment1.js] -var c = 0; -var a = ({ a: 1 }).a; -var c = ({ b: { c: c } }).b.c; -var _a = ({ b1: { c1: "world" } }).b1, c1 = (_a === void 0 ? { c1: "string" } : _a).c1; -var d1 = undefined.d1; -var e1 = ({}).e1; -var _b = ({}).f, f1 = (_b === void 0 ? { f1: "string" } : _b).f1; -var _c = undefined.f2, f21 = (_c === void 0 ? { f21: "string" } : _c).f21; -var _d = undefined.e1, e2 = (_d === void 0 ? { e2: "string" } : _d).e2; -var _e = ({}).e2, e3 = (_e === void 0 ? { e3: "string" } : _e).e3; -var _f = ({ g: 100000 }).g, g = _f === void 0 ? 1 : _f; -var x = ({ 1: "string" })[1]; diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1.types b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1.types deleted file mode 100644 index 46fbe3a9630..00000000000 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1.types +++ /dev/null @@ -1,87 +0,0 @@ -=== tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1.ts === -var c = 0; ->c : number, Symbol(c, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 0, 3), Decl(destructuringObjectBindingPatternAndAssignment1.ts, 2, 10)) ->0 : number - -var { a, } = { a:1, }; ->a : number, Symbol(a, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 1, 5)) ->{ a:1, } : { a: number; } ->a : number, Symbol(a, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 1, 14)) ->1 : number - -var { b: { c } } = { b: { c } }; ->b : any ->c : number, Symbol(c, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 0, 3), Decl(destructuringObjectBindingPatternAndAssignment1.ts, 2, 10)) ->{ b: { c } } : { b: { c: number; }; } ->b : { c: number; }, Symbol(b, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 2, 21)) ->{ c } : { c: number; } ->c : number, Symbol(c, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 2, 26)) - -var { b1: { c1 } = { c1: "string" } } = { b1: { c1: "world" } }; ->b1 : any ->c1 : string, Symbol(c1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 3, 11)) ->{ c1: "string" } : { c1: string; } ->c1 : string, Symbol(c1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 3, 20)) ->"string" : string ->{ b1: { c1: "world" } } : { b1: { c1: string; }; } ->b1 : { c1: string; }, Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 3, 42)) ->{ c1: "world" } : { c1: string; } ->c1 : string, Symbol(c1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 3, 48)) ->"world" : string - -var { d1 }: any = undefined; ->d1 : any, Symbol(d1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 4, 5)) ->undefined : undefined, Symbol(undefined) - -var { e1 }: any = {}; ->e1 : any, Symbol(e1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 5, 5)) ->{} : {} - -var { f: {f1} = { f1: "string" } }: any = {}; ->f : any ->f1 : string, Symbol(f1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 6, 10)) ->{ f1: "string" } : { f1: string; } ->f1 : string, Symbol(f1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 6, 17)) ->"string" : string ->{} : {} - -var { f2: {f21} = { f21: "string" } }: any = undefined; ->f2 : any ->f21 : string, Symbol(f21, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 7, 11)) ->{ f21: "string" } : { f21: string; } ->f21 : string, Symbol(f21, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 7, 19)) ->"string" : string ->undefined : undefined, Symbol(undefined) - -var { e1: {e2} = { e2: "string" } }: any|{ e1: { e2 } } = undefined; ->e1 : any ->e2 : string, Symbol(e2, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 8, 11)) ->{ e2: "string" } : { e2: string; } ->e2 : string, Symbol(e2, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 8, 18)) ->"string" : string ->e1 : { e2: any; }, Symbol(e1, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 8, 42)) ->e2 : any, Symbol(e2, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 8, 48)) ->undefined : undefined, Symbol(undefined) - -var { e2: {e3} = { e3: "string" } }: any|{ e2: { e3 } } = {}; ->e2 : any ->e3 : string, Symbol(e3, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 9, 11)) ->{ e3: "string" } : { e3: string; } ->e3 : string, Symbol(e3, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 9, 18)) ->"string" : string ->e2 : { e3: any; }, Symbol(e2, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 9, 42)) ->e3 : any, Symbol(e3, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 9, 48)) ->{} : {} - -var {g = 1}: any = { g: 100000 }; ->g : number, Symbol(g, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 10, 5)) ->1 : number ->{ g: 100000 } : { g: number; } ->g : number, Symbol(g, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 10, 20)) ->100000 : number - -var {1: x} = { 1: "string" }; ->x : string, Symbol(x, Decl(destructuringObjectBindingPatternAndAssignment1.ts, 11, 5)) ->{ 1: "string" } : { 1: string; } ->"string" : string - diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.js b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.js new file mode 100644 index 00000000000..2b12c2a54aa --- /dev/null +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.js @@ -0,0 +1,90 @@ +//// [destructuringObjectBindingPatternAndAssignment1ES5.ts] +// In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left. +// An expression of type S is considered assignable to an assignment target V if one of the following is true + +// V is an object assignment pattern and, for each assignment property P in V, +// S is the type Any, or +var { a1 }: any = undefined; +var { a2 }: any = {}; + +// V is an object assignment pattern and, for each assignment property P in V, +// S has an apparent property with the property name specified in +// P of a type that is assignable to the target given in P, or +var { b1, } = { b1:1, }; +var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } }; +var {1: b3} = { 1: "string" }; +var {b4 = 1}: any = { b4: 100000 }; +var {b5: { b52 } } = { b5: { b52 } }; + +// V is an object assignment pattern and, for each assignment property P in V, +// P specifies a numeric property name and S has a numeric index signature +// of a type that is assignable to the target given in P, or + +interface F { + [idx: number]: boolean; +} + +function foo(): F { + return { + 1: true + }; +} + +function bar(): F { + return { + 2: true + }; +} +var {1: c0} = foo(); +var {1: c1} = bar(); + +// V is an object assignment pattern and, for each assignment property P in V, +// S has a string index signature of a type that is assignable to the target given in P + +interface F1 { + [str: string]: number; +} + +function foo1(): F1 { + return { + "prop1": 2 + } +} + +var {"prop1": d1} = foo1(); +var {"prop2": d1} = foo1(); + +//// [destructuringObjectBindingPatternAndAssignment1ES5.js] +// In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left. +// An expression of type S is considered assignable to an assignment target V if one of the following is true +// V is an object assignment pattern and, for each assignment property P in V, +// S is the type Any, or +var a1 = undefined.a1; +var a2 = ({}).a2; +// V is an object assignment pattern and, for each assignment property P in V, +// S has an apparent property with the property name specified in +// P of a type that is assignable to the target given in P, or +var b1 = ({ b1: 1 }).b1; +var _a = ({ b2: { b21: "world" } }).b2, b21 = (_a === void 0 ? { b21: "string" } : _a).b21; +var b3 = ({ 1: "string" })[1]; +var _b = ({ b4: 100000 }).b4, b4 = _b === void 0 ? 1 : _b; +var b52 = ({ b5: { b52: b52 } }).b5.b52; +function foo() { + return { + 1: true + }; +} +function bar() { + return { + 2: true + }; +} +var c0 = (foo())[1]; +var c1 = (bar())[1]; +function foo1() { + return { + "prop1": 2 + }; +} +var d1 = (foo1())["prop1"]; +var d1 = (foo1())["prop2"]; diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.types b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.types new file mode 100644 index 00000000000..3642f6c6abe --- /dev/null +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.types @@ -0,0 +1,133 @@ +=== tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1ES5.ts === +// In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left. +// An expression of type S is considered assignable to an assignment target V if one of the following is true + +// V is an object assignment pattern and, for each assignment property P in V, +// S is the type Any, or +var { a1 }: any = undefined; +>a1 : any, Symbol(a1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 5, 5)) +>undefined : undefined, Symbol(undefined) + +var { a2 }: any = {}; +>a2 : any, Symbol(a2, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 6, 5)) +>{} : {} + +// V is an object assignment pattern and, for each assignment property P in V, +// S has an apparent property with the property name specified in +// P of a type that is assignable to the target given in P, or +var { b1, } = { b1:1, }; +>b1 : number, Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 11, 5)) +>{ b1:1, } : { b1: number; } +>b1 : number, Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 11, 15)) +>1 : number + +var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } }; +>b2 : any +>b21 : string, Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 12, 11)) +>{ b21: "string" } : { b21: string; } +>b21 : string, Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 12, 21)) +>"string" : string +>{ b2: { b21: "world" } } : { b2: { b21: string; }; } +>b2 : { b21: string; }, Symbol(b2, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 12, 44)) +>{ b21: "world" } : { b21: string; } +>b21 : string, Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 12, 50)) +>"world" : string + +var {1: b3} = { 1: "string" }; +>b3 : string, Symbol(b3, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 13, 5)) +>{ 1: "string" } : { 1: string; } +>"string" : string + +var {b4 = 1}: any = { b4: 100000 }; +>b4 : number, Symbol(b4, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 14, 5)) +>1 : number +>{ b4: 100000 } : { b4: number; } +>b4 : number, Symbol(b4, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 14, 21)) +>100000 : number + +var {b5: { b52 } } = { b5: { b52 } }; +>b5 : any +>b52 : any, Symbol(b52, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 10)) +>{ b5: { b52 } } : { b5: { b52: any; }; } +>b5 : { b52: any; }, Symbol(b5, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 23)) +>{ b52 } : { b52: any; } +>b52 : any, Symbol(b52, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 29)) + +// V is an object assignment pattern and, for each assignment property P in V, +// P specifies a numeric property name and S has a numeric index signature +// of a type that is assignable to the target given in P, or + +interface F { +>F : F, Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 38)) + + [idx: number]: boolean; +>idx : number, Symbol(idx, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 22, 5)) +} + +function foo(): F { +>foo : () => F, Symbol(foo, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 23, 1)) +>F : F, Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 38)) + + return { +>{ 1: true } : { [x: number]: boolean; 1: boolean; } + + 1: true +>true : boolean + + }; +} + +function bar(): F { +>bar : () => F, Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 29, 1)) +>F : F, Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 38)) + + return { +>{ 2: true } : { [x: number]: boolean; 2: boolean; } + + 2: true +>true : boolean + + }; +} +var {1: c0} = foo(); +>c0 : boolean, Symbol(c0, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 36, 5)) +>foo() : F +>foo : () => F, Symbol(foo, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 23, 1)) + +var {1: c1} = bar(); +>c1 : boolean, Symbol(c1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 37, 5)) +>bar() : F +>bar : () => F, Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 29, 1)) + +// V is an object assignment pattern and, for each assignment property P in V, +// S has a string index signature of a type that is assignable to the target given in P + +interface F1 { +>F1 : F1, Symbol(F1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 37, 20)) + + [str: string]: number; +>str : string, Symbol(str, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 43, 5)) +} + +function foo1(): F1 { +>foo1 : () => F1, Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 44, 1)) +>F1 : F1, Symbol(F1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 37, 20)) + + return { +>{ "prop1": 2 } : { [x: string]: number; "prop1": number; } + + "prop1": 2 +>2 : number + } +} + +var {"prop1": d1} = foo1(); +>d1 : number, Symbol(d1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 52, 5), Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 53, 5)) +>foo1() : F1 +>foo1 : () => F1, Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 44, 1)) + +var {"prop2": d1} = foo1(); +>d1 : number, Symbol(d1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 52, 5), Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 53, 5)) +>foo1() : F1 +>foo1 : () => F1, Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 44, 1)) + diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.js b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.js new file mode 100644 index 00000000000..0173645d8a3 --- /dev/null +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.js @@ -0,0 +1,90 @@ +//// [destructuringObjectBindingPatternAndAssignment1ES6.ts] +// In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left. +// An expression of type S is considered assignable to an assignment target V if one of the following is true + +// V is an object assignment pattern and, for each assignment property P in V, +// S is the type Any, or +var { a1 }: any = undefined; +var { a2 }: any = {}; + +// V is an object assignment pattern and, for each assignment property P in V, +// S has an apparent property with the property name specified in +// P of a type that is assignable to the target given in P, or +var { b1, } = { b1:1, }; +var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } }; +var {1: b3} = { 1: "string" }; +var {b4 = 1}: any = { b4: 100000 }; +var {b5: { b52 } } = { b5: { b52 } }; + +// V is an object assignment pattern and, for each assignment property P in V, +// P specifies a numeric property name and S has a numeric index signature +// of a type that is assignable to the target given in P, or + +interface F { + [idx: number]: boolean; +} + +function foo(): F { + return { + 1: true + }; +} + +function bar(): F { + return { + 2: true + }; +} +var {1: c0} = foo(); +var {1: c1} = bar(); + +// V is an object assignment pattern and, for each assignment property P in V, +// S has a string index signature of a type that is assignable to the target given in P + +interface F1 { + [str: string]: number; +} + +function foo1(): F1 { + return { + "prop1": 2 + } +} + +var {"prop1": d1} = foo1(); +var {"prop2": d1} = foo1(); + +//// [destructuringObjectBindingPatternAndAssignment1ES6.js] +// In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left. +// An expression of type S is considered assignable to an assignment target V if one of the following is true +// V is an object assignment pattern and, for each assignment property P in V, +// S is the type Any, or +var { a1 } = undefined; +var { a2 } = {}; +// V is an object assignment pattern and, for each assignment property P in V, +// S has an apparent property with the property name specified in +// P of a type that is assignable to the target given in P, or +var { b1, } = { b1: 1, }; +var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } }; +var { 1: b3 } = { 1: "string" }; +var { b4 = 1 } = { b4: 100000 }; +var { b5: { b52 } } = { b5: { b52 } }; +function foo() { + return { + 1: true + }; +} +function bar() { + return { + 2: true + }; +} +var { 1: c0 } = foo(); +var { 1: c1 } = bar(); +function foo1() { + return { + "prop1": 2 + }; +} +var { "prop1": d1 } = foo1(); +var { "prop2": d1 } = foo1(); diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.types b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.types new file mode 100644 index 00000000000..afb24e6331d --- /dev/null +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.types @@ -0,0 +1,133 @@ +=== tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1ES6.ts === +// In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left. +// An expression of type S is considered assignable to an assignment target V if one of the following is true + +// V is an object assignment pattern and, for each assignment property P in V, +// S is the type Any, or +var { a1 }: any = undefined; +>a1 : any, Symbol(a1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 5, 5)) +>undefined : undefined, Symbol(undefined) + +var { a2 }: any = {}; +>a2 : any, Symbol(a2, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 6, 5)) +>{} : {} + +// V is an object assignment pattern and, for each assignment property P in V, +// S has an apparent property with the property name specified in +// P of a type that is assignable to the target given in P, or +var { b1, } = { b1:1, }; +>b1 : number, Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 11, 5)) +>{ b1:1, } : { b1: number; } +>b1 : number, Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 11, 15)) +>1 : number + +var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } }; +>b2 : any +>b21 : string, Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 11)) +>{ b21: "string" } : { b21: string; } +>b21 : string, Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 21)) +>"string" : string +>{ b2: { b21: "world" } } : { b2: { b21: string; }; } +>b2 : { b21: string; }, Symbol(b2, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 44)) +>{ b21: "world" } : { b21: string; } +>b21 : string, Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 50)) +>"world" : string + +var {1: b3} = { 1: "string" }; +>b3 : string, Symbol(b3, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 13, 5)) +>{ 1: "string" } : { 1: string; } +>"string" : string + +var {b4 = 1}: any = { b4: 100000 }; +>b4 : number, Symbol(b4, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 14, 5)) +>1 : number +>{ b4: 100000 } : { b4: number; } +>b4 : number, Symbol(b4, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 14, 21)) +>100000 : number + +var {b5: { b52 } } = { b5: { b52 } }; +>b5 : any +>b52 : any, Symbol(b52, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 10)) +>{ b5: { b52 } } : { b5: { b52: any; }; } +>b5 : { b52: any; }, Symbol(b5, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 23)) +>{ b52 } : { b52: any; } +>b52 : any, Symbol(b52, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 29)) + +// V is an object assignment pattern and, for each assignment property P in V, +// P specifies a numeric property name and S has a numeric index signature +// of a type that is assignable to the target given in P, or + +interface F { +>F : F, Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 38)) + + [idx: number]: boolean; +>idx : number, Symbol(idx, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 22, 5)) +} + +function foo(): F { +>foo : () => F, Symbol(foo, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 23, 1)) +>F : F, Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 38)) + + return { +>{ 1: true } : { [x: number]: boolean; 1: boolean; } + + 1: true +>true : boolean + + }; +} + +function bar(): F { +>bar : () => F, Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 29, 1)) +>F : F, Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 38)) + + return { +>{ 2: true } : { [x: number]: boolean; 2: boolean; } + + 2: true +>true : boolean + + }; +} +var {1: c0} = foo(); +>c0 : boolean, Symbol(c0, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 36, 5)) +>foo() : F +>foo : () => F, Symbol(foo, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 23, 1)) + +var {1: c1} = bar(); +>c1 : boolean, Symbol(c1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 37, 5)) +>bar() : F +>bar : () => F, Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 29, 1)) + +// V is an object assignment pattern and, for each assignment property P in V, +// S has a string index signature of a type that is assignable to the target given in P + +interface F1 { +>F1 : F1, Symbol(F1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 37, 20)) + + [str: string]: number; +>str : string, Symbol(str, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 43, 5)) +} + +function foo1(): F1 { +>foo1 : () => F1, Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 44, 1)) +>F1 : F1, Symbol(F1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 37, 20)) + + return { +>{ "prop1": 2 } : { [x: string]: number; "prop1": number; } + + "prop1": 2 +>2 : number + } +} + +var {"prop1": d1} = foo1(); +>d1 : number, Symbol(d1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 52, 5), Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 53, 5)) +>foo1() : F1 +>foo1 : () => F1, Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 44, 1)) + +var {"prop2": d1} = foo1(); +>d1 : number, Symbol(d1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 52, 5), Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 53, 5)) +>foo1() : F1 +>foo1 : () => F1, Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 44, 1)) + diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment2.js b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment2.js deleted file mode 100644 index 32ce0ab0c31..00000000000 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment2.js +++ /dev/null @@ -1,76 +0,0 @@ -//// [destructuringObjectBindingPatternAndAssignment2.ts] -interface I { - j: number; - [str: string]: number; -} -interface J { - [str: string]: number; -} -function zz() { - return { - "cat": "dog", - } -} - -function zz1(): J { - return { - "cat": 1, - } -} - -function yy() { - return {} -} - -var {j}: I| J = { j: 1000 }; -var {cat} = zz(); -var {"cat":cart} = zz(); - -var {can}: J = {}; -var {can1}: J = zz1(); - - -function f() { - var { z }: { z: number } = { z }; -} - -interface K { - [idx: number]: boolean -} - -var {1: boo}: K = { 1: true }; -var {1: boo1}: K = { }; - -function bar(): K { - return { }; -} -var {1: baz} = bar(); - -//// [destructuringObjectBindingPatternAndAssignment2.js] -function zz() { - return { - "cat": "dog" - }; -} -function zz1() { - return { - "cat": 1 - }; -} -function yy() { - return {}; -} -var j = ({ j: 1000 }).j; -var cat = (zz()).cat; -var cart = (zz())["cat"]; -var can = ({}).can; -var can1 = (zz1()).can1; -function f() { - var z = ({ z: z }).z; -} -var boo = ({ 1: true })[1]; -var boo1 = ({})[1]; -function bar() { - return {}; -} -var baz = (bar())[1]; diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment2.types b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment2.types deleted file mode 100644 index a46f2406601..00000000000 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment2.types +++ /dev/null @@ -1,116 +0,0 @@ -=== tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment2.ts === -interface I { ->I : I, Symbol(I, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 0, 0)) - - j: number; ->j : number, Symbol(j, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 0, 13)) - - [str: string]: number; ->str : string, Symbol(str, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 2, 5)) -} -interface J { ->J : J, Symbol(J, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 3, 1)) - - [str: string]: number; ->str : string, Symbol(str, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 5, 5)) -} -function zz() { ->zz : () => { "cat": string; }, Symbol(zz, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 6, 1)) - - return { ->{ "cat": "dog", } : { "cat": string; } - - "cat": "dog", ->"dog" : string - } -} - -function zz1(): J { ->zz1 : () => J, Symbol(zz1, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 11, 1)) ->J : J, Symbol(J, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 3, 1)) - - return { ->{ "cat": 1, } : { [x: string]: number; "cat": number; } - - "cat": 1, ->1 : number - } -} - -function yy() { ->yy : () => {}, Symbol(yy, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 17, 1)) - - return {} ->{} : {} -} - -var {j}: I| J = { j: 1000 }; ->j : number, Symbol(j, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 23, 5)) ->I : I, Symbol(I, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 0, 0)) ->J : J, Symbol(J, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 3, 1)) ->{ j: 1000 } : { [x: string]: number; j: number; } ->j : number, Symbol(j, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 23, 17)) ->1000 : number - -var {cat} = zz(); ->cat : string, Symbol(cat, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 24, 5)) ->zz() : { "cat": string; } ->zz : () => { "cat": string; }, Symbol(zz, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 6, 1)) - -var {"cat":cart} = zz(); ->cart : string, Symbol(cart, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 25, 5)) ->zz() : { "cat": string; } ->zz : () => { "cat": string; }, Symbol(zz, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 6, 1)) - -var {can}: J = {}; ->can : number, Symbol(can, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 27, 5)) ->J : J, Symbol(J, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 3, 1)) ->{} : { [x: string]: undefined; } - -var {can1}: J = zz1(); ->can1 : number, Symbol(can1, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 28, 5)) ->J : J, Symbol(J, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 3, 1)) ->zz1() : J ->zz1 : () => J, Symbol(zz1, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 11, 1)) - - -function f() { ->f : () => void, Symbol(f, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 28, 22)) - - var { z }: { z: number } = { z }; ->z : number, Symbol(z, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 32, 9)) ->z : number, Symbol(z, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 32, 16)) ->{ z } : { z: number; } ->z : number, Symbol(z, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 32, 32)) -} - -interface K { ->K : K, Symbol(K, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 33, 1)) - - [idx: number]: boolean ->idx : number, Symbol(idx, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 36, 5)) -} - -var {1: boo}: K = { 1: true }; ->boo : boolean, Symbol(boo, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 39, 5)) ->K : K, Symbol(K, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 33, 1)) ->{ 1: true } : { [x: number]: boolean; 1: boolean; } ->true : boolean - -var {1: boo1}: K = { }; ->boo1 : boolean, Symbol(boo1, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 40, 5)) ->K : K, Symbol(K, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 33, 1)) ->{ } : { [x: number]: undefined; } - -function bar(): K { ->bar : () => K, Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 40, 23)) ->K : K, Symbol(K, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 33, 1)) - - return { }; ->{ } : { [x: number]: undefined; } -} -var {1: baz} = bar(); ->baz : boolean, Symbol(baz, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 45, 5)) ->bar() : K ->bar : () => K, Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment2.ts, 40, 23)) - diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt index de4dcee1bf2..9025f24f992 100644 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.errors.txt @@ -1,16 +1,17 @@ -tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(1,7): error TS1005: ',' expected. -tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(2,5): error TS2322: Type '{ i: number; }' is not assignable to type 'string | number'. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(2,7): error TS1005: ',' expected. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(3,5): error TS2322: Type '{ i: number; }' is not assignable to type 'string | number'. Type '{ i: number; }' is not assignable to type 'number'. -tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(2,6): error TS2459: Type 'string | number' has no property 'i' and no string index signature. -tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(3,6): error TS2459: Type 'string | number | {}' has no property 'i1' and no string index signature. -tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(4,12): error TS2459: Type '{ f212: string; }' has no property 'f21' and no string index signature. -tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(5,54): error TS2304: Cannot find name 'c'. -tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(7,7): error TS1180: Property destructuring pattern expected. -tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(10,7): error TS1005: ':' expected. -tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(10,15): error TS1005: ':' expected. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(3,6): error TS2459: Type 'string | number' has no property 'i' and no string index signature. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(4,6): error TS2459: Type 'string | number | {}' has no property 'i1' and no string index signature. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(5,12): error TS2459: Type '{ f212: string; }' has no property 'f21' and no string index signature. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(6,7): error TS1180: Property destructuring pattern expected. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(9,7): error TS1005: ':' expected. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(9,15): error TS1005: ':' expected. +tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts(10,12): error TS1005: ':' expected. ==== tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts (9 errors) ==== + // Error var {h?} = { h?: 1 }; ~ !!! error TS1005: ',' expected. @@ -26,10 +27,6 @@ tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAs var { f2: {f21} = { f212: "string" } }: any = undefined; ~~~ !!! error TS2459: Type '{ f212: string; }' has no property 'f21' and no string index signature. - var { b1: { c1 } = { c1: "string" } } = { b1: { c1: c } }; - ~ -!!! error TS2304: Cannot find name 'c'. - var { d }: any; var { ...d1 } = { ~~~ !!! error TS1180: Property destructuring pattern expected. @@ -39,4 +36,7 @@ tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAs ~ !!! error TS1005: ':' expected. ~ +!!! error TS1005: ':' expected. + var {"prop"} = { "prop": 1 }; + ~ !!! error TS1005: ':' expected. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.js b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.js index d53afcbb97c..3c617ec9b82 100644 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.js +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.js @@ -1,23 +1,23 @@ //// [destructuringObjectBindingPatternAndAssignment3.ts] +// Error var {h?} = { h?: 1 }; var {i}: string | number = { i: 2 }; var {i1}: string | number| {} = { i1: 2 }; var { f2: {f21} = { f212: "string" } }: any = undefined; -var { b1: { c1 } = { c1: "string" } } = { b1: { c1: c } }; -var { d }: any; var { ...d1 } = { a: 1, b: 1, d1: 9, e: 10 } -var {1} = { 1 }; +var {1} = { 1 }; +var {"prop"} = { "prop": 1 }; //// [destructuringObjectBindingPatternAndAssignment3.js] +// Error var h = ({ h: 1 }).h; var i = ({ i: 2 }).i; var i1 = ({ i1: 2 }).i1; var _a = undefined.f2, f21 = (_a === void 0 ? { f212: "string" } : _a).f21; -var _b = ({ b1: { c1: c } }).b1, c1 = (_b === void 0 ? { c1: "string" } : _b).c1; -var d = (void 0).d; var d1 = ({ a: 1, b: 1, d1: 9, e: 10 }).d1; var = ({ 1: })[1]; +var = ({ "prop": 1 })["prop"]; diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment4.errors.txt b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment4.errors.txt deleted file mode 100644 index f0b7977a443..00000000000 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment4.errors.txt +++ /dev/null @@ -1,37 +0,0 @@ -tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment4.ts(7,6): error TS2459: Type 'K | K1' has no property 'k' and no string index signature. -tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment4.ts(12,6): error TS2459: Type '{}' has no property '2' and no string index signature. -tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment4.ts(23,5): error TS2322: Type '{ "cat": string; }' is not assignable to type 'J'. - Index signature is missing in type '{ "cat": string; }'. - - -==== tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment4.ts (3 errors) ==== - interface K { - [str: string]: string; - } - interface K1 { - k: string; - } - var {k}: K|K1 = { k: "string" }; - ~ -!!! error TS2459: Type 'K | K1' has no property 'k' and no string index signature. - - function barn() { - return {}; - } - var {2: baz1} = barn() - ~ -!!! error TS2459: Type '{}' has no property '2' and no string index signature. - - interface J { - [str: string]: number; - } - function zz() { - return { - "cat": "dog" - } - } - - var {"can": can}: J = zz(); - ~~~~~~~~~~~~ -!!! error TS2322: Type '{ "cat": string; }' is not assignable to type 'J'. -!!! error TS2322: Index signature is missing in type '{ "cat": string; }'. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment4.js b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment4.js deleted file mode 100644 index 7abf9f3b845..00000000000 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment4.js +++ /dev/null @@ -1,37 +0,0 @@ -//// [destructuringObjectBindingPatternAndAssignment4.ts] -interface K { - [str: string]: string; -} -interface K1 { - k: string; -} -var {k}: K|K1 = { k: "string" }; - -function barn() { - return {}; -} -var {2: baz1} = barn() - -interface J { - [str: string]: number; -} -function zz() { - return { - "cat": "dog" - } -} - -var {"can": can}: J = zz(); - -//// [destructuringObjectBindingPatternAndAssignment4.js] -var k = ({ k: "string" }).k; -function barn() { - return {}; -} -var baz1 = (barn())[2]; -function zz() { - return { - "cat": "dog" - }; -} -var can = (zz())["can"]; diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES5.js b/tests/baselines/reference/destructuringVariableDeclaration1ES5.js new file mode 100644 index 00000000000..2d1f0c101b1 --- /dev/null +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES5.js @@ -0,0 +1,77 @@ +//// [destructuringVariableDeclaration1ES5.ts] +// The type T associated with a destructuring variable declaration is determined as follows: +// If the declaration includes a type annotation, T is that type. +var {a1, a2}: { a1: number, a2: string } = { a1: 10, a2: "world" } +var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [["hello"]], true]; + +// The type T associated with a destructuring variable declaration is determined as follows: +// Otherwise, if the declaration includes an initializer expression, T is the type of that initializer expression. +var { b1: { b11 } = { b11: "string" } } = { b1: { b11: "world" } }; +var temp = { t1: true, t2: "false" }; +var [b2 = 3, b3 = true, b4 = temp] = [3, false, { t1: false, t2: "hello" }]; +var [b5 = 3, b6 = true, b7 = temp] = [undefined, undefined, undefined]; + +// The type T associated with a binding element is determined as follows: +// If the binding element is a rest element, T is an array type with +// an element type E, where E is the type of the numeric index signature of S. +var [...c1] = [1,2,3]; +var [...c2] = [1,2,3, "string"]; + +// The type T associated with a binding element is determined as follows: +// Otherwise, if S is a tuple- like type (section 3.3.3): +// Let N be the zero-based index of the binding element in the array binding pattern. +// If S has a property with the numerical name N, T is the type of that property. +var [d1,d2] = [1,"string"] + +// The type T associated with a binding element is determined as follows: +// Otherwise, if S is a tuple- like type (section 3.3.3): +// Otherwise, if S has a numeric index signature, T is the type of the numeric index signature. +var temp1 = [true, false, true] +var [d3, d4] = [1, "string", ...temp1]; + +// Combining both forms of destructuring, +var {e: [e1, e2, e3 = { b1: 1000, b4: 200 }]} = { e: [1, 2, { b1: 4, b4: 0 }] }; +var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; + +// When a destructuring variable declaration, binding property, or binding element specifies +// an initializer expression, the type of the initializer expression is required to be assignable +// to the widened form of the type associated with the destructuring variable declaration, binding property, or binding element. +var {g: {g1 = [undefined, null]}}: { g: { g1: any[] } } = { g: { g1: [1, 2] } }; +var {h: {h1 = [undefined, null]}}: { h: { h1: number[] } } = { h: { h1: [1, 2] } }; + + + +//// [destructuringVariableDeclaration1ES5.js] +// The type T associated with a destructuring variable declaration is determined as follows: +// If the declaration includes a type annotation, T is that type. +var _a = { a1: 10, a2: "world" }, a1 = _a.a1, a2 = _a.a2; +var _b = [1, [["hello"]], true], a3 = _b[0], a4 = _b[1][0][0], a5 = _b[2]; +// The type T associated with a destructuring variable declaration is determined as follows: +// Otherwise, if the declaration includes an initializer expression, T is the type of that initializer expression. +var _c = ({ b1: { b11: "world" } }).b1, b11 = (_c === void 0 ? { b11: "string" } : _c).b11; +var temp = { t1: true, t2: "false" }; +var _d = [3, false, { t1: false, t2: "hello" }], _e = _d[0], b2 = _e === void 0 ? 3 : _e, _f = _d[1], b3 = _f === void 0 ? true : _f, _g = _d[2], b4 = _g === void 0 ? temp : _g; +var _h = [undefined, undefined, undefined], _j = _h[0], b5 = _j === void 0 ? 3 : _j, _k = _h[1], b6 = _k === void 0 ? true : _k, _l = _h[2], b7 = _l === void 0 ? temp : _l; +// The type T associated with a binding element is determined as follows: +// If the binding element is a rest element, T is an array type with +// an element type E, where E is the type of the numeric index signature of S. +var _m = [1, 2, 3], c1 = _m.slice(0); +var _o = [1, 2, 3, "string"], c2 = _o.slice(0); +// The type T associated with a binding element is determined as follows: +// Otherwise, if S is a tuple- like type (section 3.3.3): +// Let N be the zero-based index of the binding element in the array binding pattern. +// If S has a property with the numerical name N, T is the type of that property. +var _p = [1, "string"], d1 = _p[0], d2 = _p[1]; +// The type T associated with a binding element is determined as follows: +// Otherwise, if S is a tuple- like type (section 3.3.3): +// Otherwise, if S has a numeric index signature, T is the type of the numeric index signature. +var temp1 = [true, false, true]; +var _q = [1, "string"].concat(temp1), d3 = _q[0], d4 = _q[1]; +// Combining both forms of destructuring, +var _r = ({ e: [1, 2, { b1: 4, b4: 0 }] }).e, e1 = _r[0], e2 = _r[1], _s = _r[2], e3 = _s === void 0 ? { b1: 1000, b4: 200 } : _s; +var _t = ({ f: [1, 2, { f3: 4, f5: 0 }] }).f, f1 = _t[0], f2 = _t[1], _u = _t[2], f4 = _u.f3, f5 = _u.f5; +// When a destructuring variable declaration, binding property, or binding element specifies +// an initializer expression, the type of the initializer expression is required to be assignable +// to the widened form of the type associated with the destructuring variable declaration, binding property, or binding element. +var _v = ({ g: { g1: [1, 2] } }).g.g1, g1 = _v === void 0 ? [undefined, null] : _v; +var _w = ({ h: { h1: [1, 2] } }).h.h1, h1 = _w === void 0 ? [undefined, null] : _w; diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES5.types b/tests/baselines/reference/destructuringVariableDeclaration1ES5.types new file mode 100644 index 00000000000..18966569d35 --- /dev/null +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES5.types @@ -0,0 +1,200 @@ +=== tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration1ES5.ts === +// The type T associated with a destructuring variable declaration is determined as follows: +// If the declaration includes a type annotation, T is that type. +var {a1, a2}: { a1: number, a2: string } = { a1: 10, a2: "world" } +>a1 : number, Symbol(a1, Decl(destructuringVariableDeclaration1ES5.ts, 2, 5)) +>a2 : string, Symbol(a2, Decl(destructuringVariableDeclaration1ES5.ts, 2, 8)) +>a1 : number, Symbol(a1, Decl(destructuringVariableDeclaration1ES5.ts, 2, 15)) +>a2 : string, Symbol(a2, Decl(destructuringVariableDeclaration1ES5.ts, 2, 27)) +>{ a1: 10, a2: "world" } : { a1: number; a2: string; } +>a1 : number, Symbol(a1, Decl(destructuringVariableDeclaration1ES5.ts, 2, 44)) +>10 : number +>a2 : string, Symbol(a2, Decl(destructuringVariableDeclaration1ES5.ts, 2, 52)) +>"world" : string + +var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [["hello"]], true]; +>a3 : number, Symbol(a3, Decl(destructuringVariableDeclaration1ES5.ts, 3, 5)) +>a4 : string, Symbol(a4, Decl(destructuringVariableDeclaration1ES5.ts, 3, 11)) +>a5 : boolean, Symbol(a5, Decl(destructuringVariableDeclaration1ES5.ts, 3, 16)) +>[1, [["hello"]], true] : [number, [[string]], boolean] +>1 : number +>[["hello"]] : [[string]] +>["hello"] : [string] +>"hello" : string +>true : boolean + +// The type T associated with a destructuring variable declaration is determined as follows: +// Otherwise, if the declaration includes an initializer expression, T is the type of that initializer expression. +var { b1: { b11 } = { b11: "string" } } = { b1: { b11: "world" } }; +>b1 : any +>b11 : string, Symbol(b11, Decl(destructuringVariableDeclaration1ES5.ts, 7, 11)) +>{ b11: "string" } : { b11: string; } +>b11 : string, Symbol(b11, Decl(destructuringVariableDeclaration1ES5.ts, 7, 21)) +>"string" : string +>{ b1: { b11: "world" } } : { b1: { b11: string; }; } +>b1 : { b11: string; }, Symbol(b1, Decl(destructuringVariableDeclaration1ES5.ts, 7, 44)) +>{ b11: "world" } : { b11: string; } +>b11 : string, Symbol(b11, Decl(destructuringVariableDeclaration1ES5.ts, 7, 50)) +>"world" : string + +var temp = { t1: true, t2: "false" }; +>temp : { t1: boolean; t2: string; }, Symbol(temp, Decl(destructuringVariableDeclaration1ES5.ts, 8, 3)) +>{ t1: true, t2: "false" } : { t1: boolean; t2: string; } +>t1 : boolean, Symbol(t1, Decl(destructuringVariableDeclaration1ES5.ts, 8, 12)) +>true : boolean +>t2 : string, Symbol(t2, Decl(destructuringVariableDeclaration1ES5.ts, 8, 22)) +>"false" : string + +var [b2 = 3, b3 = true, b4 = temp] = [3, false, { t1: false, t2: "hello" }]; +>b2 : number, Symbol(b2, Decl(destructuringVariableDeclaration1ES5.ts, 9, 5)) +>3 : number +>b3 : boolean, Symbol(b3, Decl(destructuringVariableDeclaration1ES5.ts, 9, 12)) +>true : boolean +>b4 : { t1: boolean; t2: string; }, Symbol(b4, Decl(destructuringVariableDeclaration1ES5.ts, 9, 23)) +>temp : { t1: boolean; t2: string; }, Symbol(temp, Decl(destructuringVariableDeclaration1ES5.ts, 8, 3)) +>[3, false, { t1: false, t2: "hello" }] : [number, boolean, { t1: boolean; t2: string; }] +>3 : number +>false : boolean +>{ t1: false, t2: "hello" } : { t1: boolean; t2: string; } +>t1 : boolean, Symbol(t1, Decl(destructuringVariableDeclaration1ES5.ts, 9, 49)) +>false : boolean +>t2 : string, Symbol(t2, Decl(destructuringVariableDeclaration1ES5.ts, 9, 60)) +>"hello" : string + +var [b5 = 3, b6 = true, b7 = temp] = [undefined, undefined, undefined]; +>b5 : any, Symbol(b5, Decl(destructuringVariableDeclaration1ES5.ts, 10, 5)) +>3 : number +>b6 : any, Symbol(b6, Decl(destructuringVariableDeclaration1ES5.ts, 10, 12)) +>true : boolean +>b7 : any, Symbol(b7, Decl(destructuringVariableDeclaration1ES5.ts, 10, 23)) +>temp : { t1: boolean; t2: string; }, Symbol(temp, Decl(destructuringVariableDeclaration1ES5.ts, 8, 3)) +>[undefined, undefined, undefined] : [undefined, undefined, undefined] +>undefined : undefined, Symbol(undefined) +>undefined : undefined, Symbol(undefined) +>undefined : undefined, Symbol(undefined) + +// The type T associated with a binding element is determined as follows: +// If the binding element is a rest element, T is an array type with +// an element type E, where E is the type of the numeric index signature of S. +var [...c1] = [1,2,3]; +>c1 : number[], Symbol(c1, Decl(destructuringVariableDeclaration1ES5.ts, 15, 5)) +>[1,2,3] : number[] +>1 : number +>2 : number +>3 : number + +var [...c2] = [1,2,3, "string"]; +>c2 : (string | number)[], Symbol(c2, Decl(destructuringVariableDeclaration1ES5.ts, 16, 5)) +>[1,2,3, "string"] : (string | number)[] +>1 : number +>2 : number +>3 : number +>"string" : string + +// The type T associated with a binding element is determined as follows: +// Otherwise, if S is a tuple- like type (section 3.3.3): +// Let N be the zero-based index of the binding element in the array binding pattern. +// If S has a property with the numerical name N, T is the type of that property. +var [d1,d2] = [1,"string"] +>d1 : number, Symbol(d1, Decl(destructuringVariableDeclaration1ES5.ts, 22, 5)) +>d2 : string, Symbol(d2, Decl(destructuringVariableDeclaration1ES5.ts, 22, 8)) +>[1,"string"] : [number, string] +>1 : number +>"string" : string + +// The type T associated with a binding element is determined as follows: +// Otherwise, if S is a tuple- like type (section 3.3.3): +// Otherwise, if S has a numeric index signature, T is the type of the numeric index signature. +var temp1 = [true, false, true] +>temp1 : boolean[], Symbol(temp1, Decl(destructuringVariableDeclaration1ES5.ts, 27, 3)) +>[true, false, true] : boolean[] +>true : boolean +>false : boolean +>true : boolean + +var [d3, d4] = [1, "string", ...temp1]; +>d3 : string | number | boolean, Symbol(d3, Decl(destructuringVariableDeclaration1ES5.ts, 28, 5)) +>d4 : string | number | boolean, Symbol(d4, Decl(destructuringVariableDeclaration1ES5.ts, 28, 8)) +>[1, "string", ...temp1] : (string | number | boolean)[] +>1 : number +>"string" : string +>...temp1 : boolean +>temp1 : boolean[], Symbol(temp1, Decl(destructuringVariableDeclaration1ES5.ts, 27, 3)) + +// Combining both forms of destructuring, +var {e: [e1, e2, e3 = { b1: 1000, b4: 200 }]} = { e: [1, 2, { b1: 4, b4: 0 }] }; +>e : any +>e1 : number, Symbol(e1, Decl(destructuringVariableDeclaration1ES5.ts, 31, 9)) +>e2 : number, Symbol(e2, Decl(destructuringVariableDeclaration1ES5.ts, 31, 12)) +>e3 : { b1: number; b4: number; }, Symbol(e3, Decl(destructuringVariableDeclaration1ES5.ts, 31, 16)) +>{ b1: 1000, b4: 200 } : { b1: number; b4: number; } +>b1 : number, Symbol(b1, Decl(destructuringVariableDeclaration1ES5.ts, 31, 23)) +>1000 : number +>b4 : number, Symbol(b4, Decl(destructuringVariableDeclaration1ES5.ts, 31, 33)) +>200 : number +>{ e: [1, 2, { b1: 4, b4: 0 }] } : { e: [number, number, { b1: number; b4: number; }]; } +>e : [number, number, { b1: number; b4: number; }], Symbol(e, Decl(destructuringVariableDeclaration1ES5.ts, 31, 49)) +>[1, 2, { b1: 4, b4: 0 }] : [number, number, { b1: number; b4: number; }] +>1 : number +>2 : number +>{ b1: 4, b4: 0 } : { b1: number; b4: number; } +>b1 : number, Symbol(b1, Decl(destructuringVariableDeclaration1ES5.ts, 31, 61)) +>4 : number +>b4 : number, Symbol(b4, Decl(destructuringVariableDeclaration1ES5.ts, 31, 68)) +>0 : number + +var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; +>f : any +>f1 : number, Symbol(f1, Decl(destructuringVariableDeclaration1ES5.ts, 32, 9)) +>f2 : number, Symbol(f2, Decl(destructuringVariableDeclaration1ES5.ts, 32, 12)) +>f3 : any +>f4 : number, Symbol(f4, Decl(destructuringVariableDeclaration1ES5.ts, 32, 18)) +>f5 : number, Symbol(f5, Decl(destructuringVariableDeclaration1ES5.ts, 32, 26)) +> : undefined +>{ f: [1, 2, { f3: 4, f5: 0 }] } : { f: [number, number, { f3: number; f5: number; }]; } +>f : [number, number, { f3: number; f5: number; }], Symbol(f, Decl(destructuringVariableDeclaration1ES5.ts, 32, 41)) +>[1, 2, { f3: 4, f5: 0 }] : [number, number, { f3: number; f5: number; }] +>1 : number +>2 : number +>{ f3: 4, f5: 0 } : { f3: number; f5: number; } +>f3 : number, Symbol(f3, Decl(destructuringVariableDeclaration1ES5.ts, 32, 53)) +>4 : number +>f5 : number, Symbol(f5, Decl(destructuringVariableDeclaration1ES5.ts, 32, 60)) +>0 : number + +// When a destructuring variable declaration, binding property, or binding element specifies +// an initializer expression, the type of the initializer expression is required to be assignable +// to the widened form of the type associated with the destructuring variable declaration, binding property, or binding element. +var {g: {g1 = [undefined, null]}}: { g: { g1: any[] } } = { g: { g1: [1, 2] } }; +>g : any +>g1 : any[], Symbol(g1, Decl(destructuringVariableDeclaration1ES5.ts, 37, 9)) +>[undefined, null] : null[] +>undefined : undefined, Symbol(undefined) +>null : null +>g : { g1: any[]; }, Symbol(g, Decl(destructuringVariableDeclaration1ES5.ts, 37, 36)) +>g1 : any[], Symbol(g1, Decl(destructuringVariableDeclaration1ES5.ts, 37, 41)) +>{ g: { g1: [1, 2] } } : { g: { g1: number[]; }; } +>g : { g1: number[]; }, Symbol(g, Decl(destructuringVariableDeclaration1ES5.ts, 37, 59)) +>{ g1: [1, 2] } : { g1: number[]; } +>g1 : number[], Symbol(g1, Decl(destructuringVariableDeclaration1ES5.ts, 37, 64)) +>[1, 2] : number[] +>1 : number +>2 : number + +var {h: {h1 = [undefined, null]}}: { h: { h1: number[] } } = { h: { h1: [1, 2] } }; +>h : any +>h1 : number[], Symbol(h1, Decl(destructuringVariableDeclaration1ES5.ts, 38, 9)) +>[undefined, null] : null[] +>undefined : undefined, Symbol(undefined) +>null : null +>h : { h1: number[]; }, Symbol(h, Decl(destructuringVariableDeclaration1ES5.ts, 38, 36)) +>h1 : number[], Symbol(h1, Decl(destructuringVariableDeclaration1ES5.ts, 38, 41)) +>{ h: { h1: [1, 2] } } : { h: { h1: number[]; }; } +>h : { h1: number[]; }, Symbol(h, Decl(destructuringVariableDeclaration1ES5.ts, 38, 62)) +>{ h1: [1, 2] } : { h1: number[]; } +>h1 : number[], Symbol(h1, Decl(destructuringVariableDeclaration1ES5.ts, 38, 67)) +>[1, 2] : number[] +>1 : number +>2 : number + + diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES6.js b/tests/baselines/reference/destructuringVariableDeclaration1ES6.js new file mode 100644 index 00000000000..53b888471a1 --- /dev/null +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES6.js @@ -0,0 +1,77 @@ +//// [destructuringVariableDeclaration1ES6.ts] +// The type T associated with a destructuring variable declaration is determined as follows: +// If the declaration includes a type annotation, T is that type. +var {a1, a2}: { a1: number, a2: string } = { a1: 10, a2: "world" } +var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [["hello"]], true]; + +// The type T associated with a destructuring variable declaration is determined as follows: +// Otherwise, if the declaration includes an initializer expression, T is the type of that initializer expression. +var { b1: { b11 } = { b11: "string" } } = { b1: { b11: "world" } }; +var temp = { t1: true, t2: "false" }; +var [b2 = 3, b3 = true, b4 = temp] = [3, false, { t1: false, t2: "hello" }]; +var [b5 = 3, b6 = true, b7 = temp] = [undefined, undefined, undefined]; + +// The type T associated with a binding element is determined as follows: +// If the binding element is a rest element, T is an array type with +// an element type E, where E is the type of the numeric index signature of S. +var [...c1] = [1,2,3]; +var [...c2] = [1,2,3, "string"]; + +// The type T associated with a binding element is determined as follows: +// Otherwise, if S is a tuple- like type (section 3.3.3): +// Let N be the zero-based index of the binding element in the array binding pattern. +// If S has a property with the numerical name N, T is the type of that property. +var [d1,d2] = [1,"string"] + +// The type T associated with a binding element is determined as follows: +// Otherwise, if S is a tuple- like type (section 3.3.3): +// Otherwise, if S has a numeric index signature, T is the type of the numeric index signature. +var temp1 = [true, false, true] +var [d3, d4] = [1, "string", ...temp1]; + +// Combining both forms of destructuring, +var {e: [e1, e2, e3 = { b1: 1000, b4: 200 }]} = { e: [1, 2, { b1: 4, b4: 0 }] }; +var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; + +// When a destructuring variable declaration, binding property, or binding element specifies +// an initializer expression, the type of the initializer expression is required to be assignable +// to the widened form of the type associated with the destructuring variable declaration, binding property, or binding element. +var {g: {g1 = [undefined, null]}}: { g: { g1: any[] } } = { g: { g1: [1, 2] } }; +var {h: {h1 = [undefined, null]}}: { h: { h1: number[] } } = { h: { h1: [1, 2] } }; + + + +//// [destructuringVariableDeclaration1ES6.js] +// The type T associated with a destructuring variable declaration is determined as follows: +// If the declaration includes a type annotation, T is that type. +var { a1, a2 } = { a1: 10, a2: "world" }; +var [a3, [[a4]], a5] = [1, [["hello"]], true]; +// The type T associated with a destructuring variable declaration is determined as follows: +// Otherwise, if the declaration includes an initializer expression, T is the type of that initializer expression. +var { b1: { b11 } = { b11: "string" } } = { b1: { b11: "world" } }; +var temp = { t1: true, t2: "false" }; +var [b2 = 3, b3 = true, b4 = temp] = [3, false, { t1: false, t2: "hello" }]; +var [b5 = 3, b6 = true, b7 = temp] = [undefined, undefined, undefined]; +// The type T associated with a binding element is determined as follows: +// If the binding element is a rest element, T is an array type with +// an element type E, where E is the type of the numeric index signature of S. +var [...c1] = [1, 2, 3]; +var [...c2] = [1, 2, 3, "string"]; +// The type T associated with a binding element is determined as follows: +// Otherwise, if S is a tuple- like type (section 3.3.3): +// Let N be the zero-based index of the binding element in the array binding pattern. +// If S has a property with the numerical name N, T is the type of that property. +var [d1, d2] = [1, "string"]; +// The type T associated with a binding element is determined as follows: +// Otherwise, if S is a tuple- like type (section 3.3.3): +// Otherwise, if S has a numeric index signature, T is the type of the numeric index signature. +var temp1 = [true, false, true]; +var [d3, d4] = [1, "string", ...temp1]; +// Combining both forms of destructuring, +var { e: [e1, e2, e3 = { b1: 1000, b4: 200 }] } = { e: [1, 2, { b1: 4, b4: 0 }] }; +var { f: [f1, f2, { f3: f4, f5 }, ,] } = { f: [1, 2, { f3: 4, f5: 0 }] }; +// When a destructuring variable declaration, binding property, or binding element specifies +// an initializer expression, the type of the initializer expression is required to be assignable +// to the widened form of the type associated with the destructuring variable declaration, binding property, or binding element. +var { g: { g1 = [undefined, null] } } = { g: { g1: [1, 2] } }; +var { h: { h1 = [undefined, null] } } = { h: { h1: [1, 2] } }; diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES6.types b/tests/baselines/reference/destructuringVariableDeclaration1ES6.types new file mode 100644 index 00000000000..71e08134e66 --- /dev/null +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES6.types @@ -0,0 +1,200 @@ +=== tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration1ES6.ts === +// The type T associated with a destructuring variable declaration is determined as follows: +// If the declaration includes a type annotation, T is that type. +var {a1, a2}: { a1: number, a2: string } = { a1: 10, a2: "world" } +>a1 : number, Symbol(a1, Decl(destructuringVariableDeclaration1ES6.ts, 2, 5)) +>a2 : string, Symbol(a2, Decl(destructuringVariableDeclaration1ES6.ts, 2, 8)) +>a1 : number, Symbol(a1, Decl(destructuringVariableDeclaration1ES6.ts, 2, 15)) +>a2 : string, Symbol(a2, Decl(destructuringVariableDeclaration1ES6.ts, 2, 27)) +>{ a1: 10, a2: "world" } : { a1: number; a2: string; } +>a1 : number, Symbol(a1, Decl(destructuringVariableDeclaration1ES6.ts, 2, 44)) +>10 : number +>a2 : string, Symbol(a2, Decl(destructuringVariableDeclaration1ES6.ts, 2, 52)) +>"world" : string + +var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [["hello"]], true]; +>a3 : number, Symbol(a3, Decl(destructuringVariableDeclaration1ES6.ts, 3, 5)) +>a4 : string, Symbol(a4, Decl(destructuringVariableDeclaration1ES6.ts, 3, 11)) +>a5 : boolean, Symbol(a5, Decl(destructuringVariableDeclaration1ES6.ts, 3, 16)) +>[1, [["hello"]], true] : [number, [[string]], boolean] +>1 : number +>[["hello"]] : [[string]] +>["hello"] : [string] +>"hello" : string +>true : boolean + +// The type T associated with a destructuring variable declaration is determined as follows: +// Otherwise, if the declaration includes an initializer expression, T is the type of that initializer expression. +var { b1: { b11 } = { b11: "string" } } = { b1: { b11: "world" } }; +>b1 : any +>b11 : string, Symbol(b11, Decl(destructuringVariableDeclaration1ES6.ts, 7, 11)) +>{ b11: "string" } : { b11: string; } +>b11 : string, Symbol(b11, Decl(destructuringVariableDeclaration1ES6.ts, 7, 21)) +>"string" : string +>{ b1: { b11: "world" } } : { b1: { b11: string; }; } +>b1 : { b11: string; }, Symbol(b1, Decl(destructuringVariableDeclaration1ES6.ts, 7, 44)) +>{ b11: "world" } : { b11: string; } +>b11 : string, Symbol(b11, Decl(destructuringVariableDeclaration1ES6.ts, 7, 50)) +>"world" : string + +var temp = { t1: true, t2: "false" }; +>temp : { t1: boolean; t2: string; }, Symbol(temp, Decl(destructuringVariableDeclaration1ES6.ts, 8, 3)) +>{ t1: true, t2: "false" } : { t1: boolean; t2: string; } +>t1 : boolean, Symbol(t1, Decl(destructuringVariableDeclaration1ES6.ts, 8, 12)) +>true : boolean +>t2 : string, Symbol(t2, Decl(destructuringVariableDeclaration1ES6.ts, 8, 22)) +>"false" : string + +var [b2 = 3, b3 = true, b4 = temp] = [3, false, { t1: false, t2: "hello" }]; +>b2 : number, Symbol(b2, Decl(destructuringVariableDeclaration1ES6.ts, 9, 5)) +>3 : number +>b3 : boolean, Symbol(b3, Decl(destructuringVariableDeclaration1ES6.ts, 9, 12)) +>true : boolean +>b4 : { t1: boolean; t2: string; }, Symbol(b4, Decl(destructuringVariableDeclaration1ES6.ts, 9, 23)) +>temp : { t1: boolean; t2: string; }, Symbol(temp, Decl(destructuringVariableDeclaration1ES6.ts, 8, 3)) +>[3, false, { t1: false, t2: "hello" }] : [number, boolean, { t1: boolean; t2: string; }] +>3 : number +>false : boolean +>{ t1: false, t2: "hello" } : { t1: boolean; t2: string; } +>t1 : boolean, Symbol(t1, Decl(destructuringVariableDeclaration1ES6.ts, 9, 49)) +>false : boolean +>t2 : string, Symbol(t2, Decl(destructuringVariableDeclaration1ES6.ts, 9, 60)) +>"hello" : string + +var [b5 = 3, b6 = true, b7 = temp] = [undefined, undefined, undefined]; +>b5 : any, Symbol(b5, Decl(destructuringVariableDeclaration1ES6.ts, 10, 5)) +>3 : number +>b6 : any, Symbol(b6, Decl(destructuringVariableDeclaration1ES6.ts, 10, 12)) +>true : boolean +>b7 : any, Symbol(b7, Decl(destructuringVariableDeclaration1ES6.ts, 10, 23)) +>temp : { t1: boolean; t2: string; }, Symbol(temp, Decl(destructuringVariableDeclaration1ES6.ts, 8, 3)) +>[undefined, undefined, undefined] : [undefined, undefined, undefined] +>undefined : undefined, Symbol(undefined) +>undefined : undefined, Symbol(undefined) +>undefined : undefined, Symbol(undefined) + +// The type T associated with a binding element is determined as follows: +// If the binding element is a rest element, T is an array type with +// an element type E, where E is the type of the numeric index signature of S. +var [...c1] = [1,2,3]; +>c1 : number[], Symbol(c1, Decl(destructuringVariableDeclaration1ES6.ts, 15, 5)) +>[1,2,3] : number[] +>1 : number +>2 : number +>3 : number + +var [...c2] = [1,2,3, "string"]; +>c2 : (string | number)[], Symbol(c2, Decl(destructuringVariableDeclaration1ES6.ts, 16, 5)) +>[1,2,3, "string"] : (string | number)[] +>1 : number +>2 : number +>3 : number +>"string" : string + +// The type T associated with a binding element is determined as follows: +// Otherwise, if S is a tuple- like type (section 3.3.3): +// Let N be the zero-based index of the binding element in the array binding pattern. +// If S has a property with the numerical name N, T is the type of that property. +var [d1,d2] = [1,"string"] +>d1 : number, Symbol(d1, Decl(destructuringVariableDeclaration1ES6.ts, 22, 5)) +>d2 : string, Symbol(d2, Decl(destructuringVariableDeclaration1ES6.ts, 22, 8)) +>[1,"string"] : [number, string] +>1 : number +>"string" : string + +// The type T associated with a binding element is determined as follows: +// Otherwise, if S is a tuple- like type (section 3.3.3): +// Otherwise, if S has a numeric index signature, T is the type of the numeric index signature. +var temp1 = [true, false, true] +>temp1 : boolean[], Symbol(temp1, Decl(destructuringVariableDeclaration1ES6.ts, 27, 3)) +>[true, false, true] : boolean[] +>true : boolean +>false : boolean +>true : boolean + +var [d3, d4] = [1, "string", ...temp1]; +>d3 : string | number | boolean, Symbol(d3, Decl(destructuringVariableDeclaration1ES6.ts, 28, 5)) +>d4 : string | number | boolean, Symbol(d4, Decl(destructuringVariableDeclaration1ES6.ts, 28, 8)) +>[1, "string", ...temp1] : (string | number | boolean)[] +>1 : number +>"string" : string +>...temp1 : boolean +>temp1 : boolean[], Symbol(temp1, Decl(destructuringVariableDeclaration1ES6.ts, 27, 3)) + +// Combining both forms of destructuring, +var {e: [e1, e2, e3 = { b1: 1000, b4: 200 }]} = { e: [1, 2, { b1: 4, b4: 0 }] }; +>e : any +>e1 : number, Symbol(e1, Decl(destructuringVariableDeclaration1ES6.ts, 31, 9)) +>e2 : number, Symbol(e2, Decl(destructuringVariableDeclaration1ES6.ts, 31, 12)) +>e3 : { b1: number; b4: number; }, Symbol(e3, Decl(destructuringVariableDeclaration1ES6.ts, 31, 16)) +>{ b1: 1000, b4: 200 } : { b1: number; b4: number; } +>b1 : number, Symbol(b1, Decl(destructuringVariableDeclaration1ES6.ts, 31, 23)) +>1000 : number +>b4 : number, Symbol(b4, Decl(destructuringVariableDeclaration1ES6.ts, 31, 33)) +>200 : number +>{ e: [1, 2, { b1: 4, b4: 0 }] } : { e: [number, number, { b1: number; b4: number; }]; } +>e : [number, number, { b1: number; b4: number; }], Symbol(e, Decl(destructuringVariableDeclaration1ES6.ts, 31, 49)) +>[1, 2, { b1: 4, b4: 0 }] : [number, number, { b1: number; b4: number; }] +>1 : number +>2 : number +>{ b1: 4, b4: 0 } : { b1: number; b4: number; } +>b1 : number, Symbol(b1, Decl(destructuringVariableDeclaration1ES6.ts, 31, 61)) +>4 : number +>b4 : number, Symbol(b4, Decl(destructuringVariableDeclaration1ES6.ts, 31, 68)) +>0 : number + +var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; +>f : any +>f1 : number, Symbol(f1, Decl(destructuringVariableDeclaration1ES6.ts, 32, 9)) +>f2 : number, Symbol(f2, Decl(destructuringVariableDeclaration1ES6.ts, 32, 12)) +>f3 : any +>f4 : number, Symbol(f4, Decl(destructuringVariableDeclaration1ES6.ts, 32, 18)) +>f5 : number, Symbol(f5, Decl(destructuringVariableDeclaration1ES6.ts, 32, 26)) +> : undefined +>{ f: [1, 2, { f3: 4, f5: 0 }] } : { f: [number, number, { f3: number; f5: number; }]; } +>f : [number, number, { f3: number; f5: number; }], Symbol(f, Decl(destructuringVariableDeclaration1ES6.ts, 32, 41)) +>[1, 2, { f3: 4, f5: 0 }] : [number, number, { f3: number; f5: number; }] +>1 : number +>2 : number +>{ f3: 4, f5: 0 } : { f3: number; f5: number; } +>f3 : number, Symbol(f3, Decl(destructuringVariableDeclaration1ES6.ts, 32, 53)) +>4 : number +>f5 : number, Symbol(f5, Decl(destructuringVariableDeclaration1ES6.ts, 32, 60)) +>0 : number + +// When a destructuring variable declaration, binding property, or binding element specifies +// an initializer expression, the type of the initializer expression is required to be assignable +// to the widened form of the type associated with the destructuring variable declaration, binding property, or binding element. +var {g: {g1 = [undefined, null]}}: { g: { g1: any[] } } = { g: { g1: [1, 2] } }; +>g : any +>g1 : any[], Symbol(g1, Decl(destructuringVariableDeclaration1ES6.ts, 37, 9)) +>[undefined, null] : null[] +>undefined : undefined, Symbol(undefined) +>null : null +>g : { g1: any[]; }, Symbol(g, Decl(destructuringVariableDeclaration1ES6.ts, 37, 36)) +>g1 : any[], Symbol(g1, Decl(destructuringVariableDeclaration1ES6.ts, 37, 41)) +>{ g: { g1: [1, 2] } } : { g: { g1: number[]; }; } +>g : { g1: number[]; }, Symbol(g, Decl(destructuringVariableDeclaration1ES6.ts, 37, 59)) +>{ g1: [1, 2] } : { g1: number[]; } +>g1 : number[], Symbol(g1, Decl(destructuringVariableDeclaration1ES6.ts, 37, 64)) +>[1, 2] : number[] +>1 : number +>2 : number + +var {h: {h1 = [undefined, null]}}: { h: { h1: number[] } } = { h: { h1: [1, 2] } }; +>h : any +>h1 : number[], Symbol(h1, Decl(destructuringVariableDeclaration1ES6.ts, 38, 9)) +>[undefined, null] : null[] +>undefined : undefined, Symbol(undefined) +>null : null +>h : { h1: number[]; }, Symbol(h, Decl(destructuringVariableDeclaration1ES6.ts, 38, 36)) +>h1 : number[], Symbol(h1, Decl(destructuringVariableDeclaration1ES6.ts, 38, 41)) +>{ h: { h1: [1, 2] } } : { h: { h1: number[]; }; } +>h : { h1: number[]; }, Symbol(h, Decl(destructuringVariableDeclaration1ES6.ts, 38, 62)) +>{ h1: [1, 2] } : { h1: number[]; } +>h1 : number[], Symbol(h1, Decl(destructuringVariableDeclaration1ES6.ts, 38, 67)) +>[1, 2] : number[] +>1 : number +>2 : number + + diff --git a/tests/baselines/reference/destructuringVariableDeclaration2.errors.txt b/tests/baselines/reference/destructuringVariableDeclaration2.errors.txt new file mode 100644 index 00000000000..1a655837743 --- /dev/null +++ b/tests/baselines/reference/destructuringVariableDeclaration2.errors.txt @@ -0,0 +1,62 @@ +tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration2.ts(3,5): error TS2322: Type '{ a1: boolean; a2: number; }' is not assignable to type '{ a1: number; a2: string; }'. + Types of property 'a1' are incompatible. + Type 'boolean' is not assignable to type 'number'. +tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration2.ts(4,5): error TS2322: Type '[number, [[boolean]], boolean]' is not assignable to type '[number, [[string]], boolean]'. + Types of property '1' are incompatible. + Type '[[boolean]]' is not assignable to type '[[string]]'. + Types of property '0' are incompatible. + Type '[boolean]' is not assignable to type '[string]'. + Types of property '0' are incompatible. + Type 'boolean' is not assignable to type 'string'. +tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration2.ts(9,25): error TS2322: Type '{ t1: boolean; t2: string; }' is not assignable to type '{ t1: boolean; t2: number; }'. + Types of property 't2' are incompatible. + Type 'string' is not assignable to type 'number'. +tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration2.ts(14,16): error TS2459: Type 'number | { c3: number; c5: number; }' has no property 'c3' and no string index signature. +tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration2.ts(14,24): error TS2459: Type 'number | { c3: number; c5: number; }' has no property 'c5' and no string index signature. +tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration2.ts(19,10): error TS2322: Type 'string[]' is not assignable to type 'number[]'. + Type 'string' is not assignable to type 'number'. + + +==== tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration2.ts (6 errors) ==== + // The type T associated with a destructuring variable declaration is determined as follows: + // If the declaration includes a type annotation, T is that type. + var {a1, a2}: { a1: number, a2: string } = { a1: true, a2: 1 } // Error + ~~~~~~~~ +!!! error TS2322: Type '{ a1: boolean; a2: number; }' is not assignable to type '{ a1: number; a2: string; }'. +!!! error TS2322: Types of property 'a1' are incompatible. +!!! error TS2322: Type 'boolean' is not assignable to type 'number'. + var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [[false]], true]; // Error + ~~~~~~~~~~~~~~~~ +!!! error TS2322: Type '[number, [[boolean]], boolean]' is not assignable to type '[number, [[string]], boolean]'. +!!! error TS2322: Types of property '1' are incompatible. +!!! error TS2322: Type '[[boolean]]' is not assignable to type '[[string]]'. +!!! error TS2322: Types of property '0' are incompatible. +!!! error TS2322: Type '[boolean]' is not assignable to type '[string]'. +!!! error TS2322: Types of property '0' are incompatible. +!!! error TS2322: Type 'boolean' is not assignable to type 'string'. + + // The type T associated with a destructuring variable declaration is determined as follows: + // Otherwise, if the declaration includes an initializer expression, T is the type of that initializer expression. + var temp = { t1: true, t2: "false" }; + var [b0 = 3, b1 = true, b2 = temp] = [3, false, { t1: false, t2: 5}]; // Error + ~~ +!!! error TS2322: Type '{ t1: boolean; t2: string; }' is not assignable to type '{ t1: boolean; t2: number; }'. +!!! error TS2322: Types of property 't2' are incompatible. +!!! error TS2322: Type 'string' is not assignable to type 'number'. + + // The type T associated with a binding element is determined as follows: + // If the binding element is a rest element, T is an array type with + // an element type E, where E is the type of the numeric index signature of S. + var [c1, c2, { c3: c4, c5 }, , ...c6] = [1, 2, { c3: 4, c5: 0 }]; // Error + ~~ +!!! error TS2459: Type 'number | { c3: number; c5: number; }' has no property 'c3' and no string index signature. + ~~ +!!! error TS2459: Type 'number | { c3: number; c5: number; }' has no property 'c5' and no string index signature. + + // When a destructuring variable declaration, binding property, or binding element specifies + // an initializer expression, the type of the initializer expression is required to be assignable + // to the widened form of the type associated with the destructuring variable declaration, binding property, or binding element. + var {d: {d1 = ["string", null]}}: { d: { d1: number[] } } = { d: { d1: [1, 2] } }; // Error + ~~ +!!! error TS2322: Type 'string[]' is not assignable to type 'number[]'. +!!! error TS2322: Type 'string' is not assignable to type 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringVariableDeclaration2.js b/tests/baselines/reference/destructuringVariableDeclaration2.js new file mode 100644 index 00000000000..b3d4152892a --- /dev/null +++ b/tests/baselines/reference/destructuringVariableDeclaration2.js @@ -0,0 +1,38 @@ +//// [destructuringVariableDeclaration2.ts] +// The type T associated with a destructuring variable declaration is determined as follows: +// If the declaration includes a type annotation, T is that type. +var {a1, a2}: { a1: number, a2: string } = { a1: true, a2: 1 } // Error +var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [[false]], true]; // Error + +// The type T associated with a destructuring variable declaration is determined as follows: +// Otherwise, if the declaration includes an initializer expression, T is the type of that initializer expression. +var temp = { t1: true, t2: "false" }; +var [b0 = 3, b1 = true, b2 = temp] = [3, false, { t1: false, t2: 5}]; // Error + +// The type T associated with a binding element is determined as follows: +// If the binding element is a rest element, T is an array type with +// an element type E, where E is the type of the numeric index signature of S. +var [c1, c2, { c3: c4, c5 }, , ...c6] = [1, 2, { c3: 4, c5: 0 }]; // Error + +// When a destructuring variable declaration, binding property, or binding element specifies +// an initializer expression, the type of the initializer expression is required to be assignable +// to the widened form of the type associated with the destructuring variable declaration, binding property, or binding element. +var {d: {d1 = ["string", null]}}: { d: { d1: number[] } } = { d: { d1: [1, 2] } }; // Error + +//// [destructuringVariableDeclaration2.js] +// The type T associated with a destructuring variable declaration is determined as follows: +// If the declaration includes a type annotation, T is that type. +var _a = { a1: true, a2: 1 }, a1 = _a.a1, a2 = _a.a2; // Error +var _b = [1, [[false]], true], a3 = _b[0], a4 = _b[1][0][0], a5 = _b[2]; // Error +// The type T associated with a destructuring variable declaration is determined as follows: +// Otherwise, if the declaration includes an initializer expression, T is the type of that initializer expression. +var temp = { t1: true, t2: "false" }; +var _c = [3, false, { t1: false, t2: 5 }], _d = _c[0], b0 = _d === void 0 ? 3 : _d, _e = _c[1], b1 = _e === void 0 ? true : _e, _f = _c[2], b2 = _f === void 0 ? temp : _f; // Error +// The type T associated with a binding element is determined as follows: +// If the binding element is a rest element, T is an array type with +// an element type E, where E is the type of the numeric index signature of S. +var _g = [1, 2, { c3: 4, c5: 0 }], c1 = _g[0], c2 = _g[1], _h = _g[2], c4 = _h.c3, c5 = _h.c5, c6 = _g.slice(4); // Error +// When a destructuring variable declaration, binding property, or binding element specifies +// an initializer expression, the type of the initializer expression is required to be assignable +// to the widened form of the type associated with the destructuring variable declaration, binding property, or binding element. +var _j = ({ d: { d1: [1, 2] } }).d.d1, d1 = _j === void 0 ? ["string", null] : _j; // Error diff --git a/tests/baselines/reference/destructuringVariableDeclarationAndAssignment.errors.txt b/tests/baselines/reference/destructuringVariableDeclarationAndAssignment.errors.txt deleted file mode 100644 index a455ee862c4..00000000000 --- a/tests/baselines/reference/destructuringVariableDeclarationAndAssignment.errors.txt +++ /dev/null @@ -1,15 +0,0 @@ -tests/cases/conformance/es6/destructuring/destructuringVariableDeclarationAndAssignment.ts(3,23): error TS2459: Type 'number | { b12: number; b42: number; }' has no property 'b12' and no string index signature. -tests/cases/conformance/es6/destructuring/destructuringVariableDeclarationAndAssignment.ts(3,33): error TS2459: Type 'number | { b12: number; b42: number; }' has no property 'b42' and no string index signature. -tests/cases/conformance/es6/destructuring/destructuringVariableDeclarationAndAssignment.ts(3,44): error TS2403: Subsequent variable declarations must have the same type. Variable 'c' must be of type 'number', but here has type '(number | { b12: number; b42: number; })[]'. - - -==== tests/cases/conformance/es6/destructuring/destructuringVariableDeclarationAndAssignment.ts (3 errors) ==== - var {o: [a1, a2, a3 = { b1: 1000, b4: 200 }]} = { o: [1, 2, { b1: 4, b4: 0 }] }; - var {o0: [c, d, { e: e1, f }, , ]} = { o0: [1, 2, { e: 4, f: 0 }] }; - var {o1: [a11, a21, { b12: b22, b42 },, ...c]} = { o1: [1, 2, { b12: 4, b42: 0 }] }; - ~~~ -!!! error TS2459: Type 'number | { b12: number; b42: number; }' has no property 'b12' and no string index signature. - ~~~ -!!! error TS2459: Type 'number | { b12: number; b42: number; }' has no property 'b42' and no string index signature. - ~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'c' must be of type 'number', but here has type '(number | { b12: number; b42: number; })[]'. \ No newline at end of file diff --git a/tests/baselines/reference/destructuringVariableDeclarationAndAssignment.js b/tests/baselines/reference/destructuringVariableDeclarationAndAssignment.js deleted file mode 100644 index b089d2ab4fb..00000000000 --- a/tests/baselines/reference/destructuringVariableDeclarationAndAssignment.js +++ /dev/null @@ -1,9 +0,0 @@ -//// [destructuringVariableDeclarationAndAssignment.ts] -var {o: [a1, a2, a3 = { b1: 1000, b4: 200 }]} = { o: [1, 2, { b1: 4, b4: 0 }] }; -var {o0: [c, d, { e: e1, f }, , ]} = { o0: [1, 2, { e: 4, f: 0 }] }; -var {o1: [a11, a21, { b12: b22, b42 },, ...c]} = { o1: [1, 2, { b12: 4, b42: 0 }] }; - -//// [destructuringVariableDeclarationAndAssignment.js] -var _a = ({ o: [1, 2, { b1: 4, b4: 0 }] }).o, a1 = _a[0], a2 = _a[1], _b = _a[2], a3 = _b === void 0 ? { b1: 1000, b4: 200 } : _b; -var _c = ({ o0: [1, 2, { e: 4, f: 0 }] }).o0, c = _c[0], d = _c[1], _d = _c[2], e1 = _d.e, f = _d.f; -var _e = ({ o1: [1, 2, { b12: 4, b42: 0 }] }).o1, a11 = _e[0], a21 = _e[1], _f = _e[2], b22 = _f.b12, b42 = _f.b42, c = _e.slice(4); diff --git a/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1.ts b/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1.ts deleted file mode 100644 index 4e6c46d2674..00000000000 --- a/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1.ts +++ /dev/null @@ -1,22 +0,0 @@ -var [p0,p1, p2] : any = [2, 3, 4]; -var [a, b, c]: [number, number, string] = [1, 2, "string"]; -var [d, e]: any = undefined; -var [f = false, g = 1]: any = undefined; -g = 10; -f = true; - -var [x] = [] -var [[[y]], [[[[z]]]]] = [[[]], [[[[]]]]] -var [[w], m]: [[string|number], boolean] = [[1], true]; -interface J extends Array { - 2: number; -} - -var [, w1] = [1, 2, 3]; -var [,,, w2] = [1, 2, 3, 4]; -var [,,, w2] = [1, 2, 3, 4]; -var [,,,...w3] = [1, 2, 3, 4, "hello"]; - -var [r, s, ...t] = [1, 2, "string"]; -var [r1, s1, t1] = [1, 2, "string"]; - diff --git a/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts b/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts new file mode 100644 index 00000000000..5b594e3cada --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts @@ -0,0 +1,52 @@ +/* AssignmentPattern: + * ObjectAssignmentPattern + * ArrayAssignmentPattern + * ArrayAssignmentPattern: + * [Elision AssignmentRestElementopt ] + * [AssignmentElementList] + * [AssignmentElementList, Elision AssignmentRestElementopt ] + * AssignmentElementList: + * Elision AssignmentElement + * AssignmentElementList, Elisionopt AssignmentElement + * AssignmentElement: + * LeftHandSideExpression Initialiseropt + * AssignmentPattern Initialiseropt + * AssignmentRestElement: + * ... LeftHandSideExpression + */ + +// In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left. +// An expression of type S is considered assignable to an assignment target V if one of the following is true + +// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, +// S is the type Any, or + +var [a0, a1]: any = undefined; +var [a2 = false, a3 = 1]: any = undefined; + +// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, +// S is a tuple- like type (section 3.3.3) with a property named N of a type that is assignable to the target given in E, +// where N is the numeric index of E in the array assignment pattern, or +var [b0, b1, b2] = [2, 3, 4]; +var [b3, b4, b5]: [number, number, string] = [1, 2, "string"]; + +function foo() { + return [1, 2, 3]; +} + +var [b6, b7] = foo(); +var [...b8] = foo(); + +// S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E. +var temp = [1,2,3] +var [c0, c1] = [...temp]; +var [c2] = []; +var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] +var [[c5], c6]: [[string|number], boolean] = [[1], true]; +var [, c7] = [1, 2, 3]; +var [,,, c8] = [1, 2, 3, 4]; +var [,,, c9] = [1, 2, 3, 4]; +var [,,,...c10] = [1, 2, 3, 4, "hello"]; +var [c11, c12, ...c13] = [1, 2, "string"]; +var [c14, c15, c16] = [1, 2, "string"]; + diff --git a/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.ts b/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.ts new file mode 100644 index 00000000000..9b631706bfd --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.ts @@ -0,0 +1,53 @@ +// @target: es6 + +/* AssignmentPattern: + * ObjectAssignmentPattern + * ArrayAssignmentPattern + * ArrayAssignmentPattern: + * [Elision AssignmentRestElementopt ] + * [AssignmentElementList] + * [AssignmentElementList, Elision AssignmentRestElementopt ] + * AssignmentElementList: + * Elision AssignmentElement + * AssignmentElementList, Elisionopt AssignmentElement + * AssignmentElement: + * LeftHandSideExpression Initialiseropt + * AssignmentPattern Initialiseropt + * AssignmentRestElement: + * ... LeftHandSideExpression + */ + +// In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left. +// An expression of type S is considered assignable to an assignment target V if one of the following is true + +// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, +// S is the type Any, or + +var [a0, a1]: any = undefined; +var [a2 = false, a3 = 1]: any = undefined; + +// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, +// S is a tuple- like type (section 3.3.3) with a property named N of a type that is assignable to the target given in E, +// where N is the numeric index of E in the array assignment pattern, or +var [b0, b1, b2] = [2, 3, 4]; +var [b3, b4, b5]: [number, number, string] = [1, 2, "string"]; + +function foo() { + return [1, 2, 3]; +} + +var [b6, b7] = foo(); +var [...b8] = foo(); + +// S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E. +var temp = [1,2,3] +var [c0, c1] = [...temp]; +var [c2] = []; +var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] +var [[c5], c6]: [[string|number], boolean] = [[1], true]; +var [, c7] = [1, 2, 3]; +var [,,, c8] = [1, 2, 3, 4]; +var [,,, c9] = [1, 2, 3, 4]; +var [,,,...c10] = [1, 2, 3, 4, "hello"]; +var [c11, c12, ...c13] = [1, 2, "string"]; +var [c14, c15, c16] = [1, 2, "string"]; \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts b/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts index 3b094541d30..bc5a2da176b 100644 --- a/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts +++ b/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment2.ts @@ -1,13 +1,34 @@ -function foo() { - return [1, 2, 3]; -} +// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, +// S is the type Any, or +var [[a0], [[a1]]] = [] // Error +var [[a2], [[a3]]] = undefined // Error + +// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, +// S is a tuple- like type (section 3.3.3) with a property named N of a type that is assignable to the target given in E, +// where N is the numeric index of E in the array assignment pattern, or +var [b0, b1, b2]: [number, boolean, string] = [1, 2, "string"]; // Error interface J extends Array { 2: number; } function bar(): J { - return <[number, number, number]>[1, 2, 3]; + return <[number, number, number]>[1, 2, 3]; +} +var [b3 = "string", b4, b5] = bar(); // Error + +// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, +// S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E. +var temp = [1, 2, 3] +var [c0, c1]: [number, number] = [...temp]; // Error +var [c2, c3]: [string, string] = [...temp]; // Error + +interface F { + [idx: number]: boolean } -var [j, k] = foo(); -var [...p] = foo(); +function foo(idx: number): F { + return { + 2: true + } +} +var [c4, c5, c6] = foo(1); // Error \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts b/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts deleted file mode 100644 index 43f8c3546df..00000000000 --- a/tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment3.ts +++ /dev/null @@ -1,23 +0,0 @@ -interface H { - 0: number, - 1: string -} -interface J extends Array { - 2: number; -} - -function bar(): J { - return <[number, number, number]>[1, 2, 3]; -} - -function gg(idx: number) { - return { - [idx]: true - } -} - -var [h, g, i]: H = []; -var [[[y]], [[[[z]]]]] = [] -var [, , ...w4, , ] = [] -var [a = "string", b, c] = bar(); -var [r, s, t] = gg(1); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1.ts b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1.ts deleted file mode 100644 index f15541aaf90..00000000000 --- a/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1.ts +++ /dev/null @@ -1,12 +0,0 @@ -var c = 0; -var { a, } = { a:1, }; -var { b: { c } } = { b: { c } }; -var { b1: { c1 } = { c1: "string" } } = { b1: { c1: "world" } }; -var { d1 }: any = undefined; -var { e1 }: any = {}; -var { f: {f1} = { f1: "string" } }: any = {}; -var { f2: {f21} = { f21: "string" } }: any = undefined; -var { e1: {e2} = { e2: "string" } }: any|{ e1: { e2 } } = undefined; -var { e2: {e3} = { e3: "string" } }: any|{ e2: { e3 } } = {}; -var {g = 1}: any = { g: 100000 }; -var {1: x} = { 1: "string" }; \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1ES5.ts b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1ES5.ts new file mode 100644 index 00000000000..e25a11ba5b0 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1ES5.ts @@ -0,0 +1,54 @@ +// In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left. +// An expression of type S is considered assignable to an assignment target V if one of the following is true + +// V is an object assignment pattern and, for each assignment property P in V, +// S is the type Any, or +var { a1 }: any = undefined; +var { a2 }: any = {}; + +// V is an object assignment pattern and, for each assignment property P in V, +// S has an apparent property with the property name specified in +// P of a type that is assignable to the target given in P, or +var { b1, } = { b1:1, }; +var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } }; +var {1: b3} = { 1: "string" }; +var {b4 = 1}: any = { b4: 100000 }; +var {b5: { b52 } } = { b5: { b52 } }; + +// V is an object assignment pattern and, for each assignment property P in V, +// P specifies a numeric property name and S has a numeric index signature +// of a type that is assignable to the target given in P, or + +interface F { + [idx: number]: boolean; +} + +function foo(): F { + return { + 1: true + }; +} + +function bar(): F { + return { + 2: true + }; +} +var {1: c0} = foo(); +var {1: c1} = bar(); + +// V is an object assignment pattern and, for each assignment property P in V, +// S has a string index signature of a type that is assignable to the target given in P + +interface F1 { + [str: string]: number; +} + +function foo1(): F1 { + return { + "prop1": 2 + } +} + +var {"prop1": d1} = foo1(); +var {"prop2": d1} = foo1(); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1ES6.ts b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1ES6.ts new file mode 100644 index 00000000000..a99b48d75da --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1ES6.ts @@ -0,0 +1,55 @@ +// @target: es6 +// In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left. +// An expression of type S is considered assignable to an assignment target V if one of the following is true + +// V is an object assignment pattern and, for each assignment property P in V, +// S is the type Any, or +var { a1 }: any = undefined; +var { a2 }: any = {}; + +// V is an object assignment pattern and, for each assignment property P in V, +// S has an apparent property with the property name specified in +// P of a type that is assignable to the target given in P, or +var { b1, } = { b1:1, }; +var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } }; +var {1: b3} = { 1: "string" }; +var {b4 = 1}: any = { b4: 100000 }; +var {b5: { b52 } } = { b5: { b52 } }; + +// V is an object assignment pattern and, for each assignment property P in V, +// P specifies a numeric property name and S has a numeric index signature +// of a type that is assignable to the target given in P, or + +interface F { + [idx: number]: boolean; +} + +function foo(): F { + return { + 1: true + }; +} + +function bar(): F { + return { + 2: true + }; +} +var {1: c0} = foo(); +var {1: c1} = bar(); + +// V is an object assignment pattern and, for each assignment property P in V, +// S has a string index signature of a type that is assignable to the target given in P + +interface F1 { + [str: string]: number; +} + +function foo1(): F1 { + return { + "prop1": 2 + } +} + +var {"prop1": d1} = foo1(); +var {"prop2": d1} = foo1(); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment2.ts b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment2.ts deleted file mode 100644 index 026c901dbe7..00000000000 --- a/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment2.ts +++ /dev/null @@ -1,46 +0,0 @@ -interface I { - j: number; - [str: string]: number; -} -interface J { - [str: string]: number; -} -function zz() { - return { - "cat": "dog", - } -} - -function zz1(): J { - return { - "cat": 1, - } -} - -function yy() { - return {} -} - -var {j}: I| J = { j: 1000 }; -var {cat} = zz(); -var {"cat":cart} = zz(); - -var {can}: J = {}; -var {can1}: J = zz1(); - - -function f() { - var { z }: { z: number } = { z }; -} - -interface K { - [idx: number]: boolean -} - -var {1: boo}: K = { 1: true }; -var {1: boo1}: K = { }; - -function bar(): K { - return { }; -} -var {1: baz} = bar(); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts index 524728dc9d6..2b3192bc9a2 100644 --- a/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts +++ b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment3.ts @@ -1,10 +1,10 @@ -var {h?} = { h?: 1 }; +// Error +var {h?} = { h?: 1 }; var {i}: string | number = { i: 2 }; var {i1}: string | number| {} = { i1: 2 }; var { f2: {f21} = { f212: "string" } }: any = undefined; -var { b1: { c1 } = { c1: "string" } } = { b1: { c1: c } }; -var { d }: any; var { ...d1 } = { a: 1, b: 1, d1: 9, e: 10 } -var {1} = { 1 }; \ No newline at end of file +var {1} = { 1 }; +var {"prop"} = { "prop": 1 }; \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment4.ts b/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment4.ts deleted file mode 100644 index 3cb7ae06581..00000000000 --- a/tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment4.ts +++ /dev/null @@ -1,23 +0,0 @@ -interface K { - [str: string]: string; -} -interface K1 { - k: string; -} -var {k}: K|K1 = { k: "string" }; - -function barn() { - return {}; -} -var {2: baz1} = barn() - -interface J { - [str: string]: number; -} -function zz() { - return { - "cat": "dog" - } -} - -var {"can": can}: J = zz(); \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration1ES5.ts b/tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration1ES5.ts new file mode 100644 index 00000000000..6121c00a784 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration1ES5.ts @@ -0,0 +1,40 @@ +// The type T associated with a destructuring variable declaration is determined as follows: +// If the declaration includes a type annotation, T is that type. +var {a1, a2}: { a1: number, a2: string } = { a1: 10, a2: "world" } +var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [["hello"]], true]; + +// The type T associated with a destructuring variable declaration is determined as follows: +// Otherwise, if the declaration includes an initializer expression, T is the type of that initializer expression. +var { b1: { b11 } = { b11: "string" } } = { b1: { b11: "world" } }; +var temp = { t1: true, t2: "false" }; +var [b2 = 3, b3 = true, b4 = temp] = [3, false, { t1: false, t2: "hello" }]; +var [b5 = 3, b6 = true, b7 = temp] = [undefined, undefined, undefined]; + +// The type T associated with a binding element is determined as follows: +// If the binding element is a rest element, T is an array type with +// an element type E, where E is the type of the numeric index signature of S. +var [...c1] = [1,2,3]; +var [...c2] = [1,2,3, "string"]; + +// The type T associated with a binding element is determined as follows: +// Otherwise, if S is a tuple- like type (section 3.3.3): +// Let N be the zero-based index of the binding element in the array binding pattern. +// If S has a property with the numerical name N, T is the type of that property. +var [d1,d2] = [1,"string"] + +// The type T associated with a binding element is determined as follows: +// Otherwise, if S is a tuple- like type (section 3.3.3): +// Otherwise, if S has a numeric index signature, T is the type of the numeric index signature. +var temp1 = [true, false, true] +var [d3, d4] = [1, "string", ...temp1]; + +// Combining both forms of destructuring, +var {e: [e1, e2, e3 = { b1: 1000, b4: 200 }]} = { e: [1, 2, { b1: 4, b4: 0 }] }; +var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; + +// When a destructuring variable declaration, binding property, or binding element specifies +// an initializer expression, the type of the initializer expression is required to be assignable +// to the widened form of the type associated with the destructuring variable declaration, binding property, or binding element. +var {g: {g1 = [undefined, null]}}: { g: { g1: any[] } } = { g: { g1: [1, 2] } }; +var {h: {h1 = [undefined, null]}}: { h: { h1: number[] } } = { h: { h1: [1, 2] } }; + diff --git a/tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration1ES6.ts b/tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration1ES6.ts new file mode 100644 index 00000000000..dee06e000ce --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration1ES6.ts @@ -0,0 +1,41 @@ +// @target: es6 +// The type T associated with a destructuring variable declaration is determined as follows: +// If the declaration includes a type annotation, T is that type. +var {a1, a2}: { a1: number, a2: string } = { a1: 10, a2: "world" } +var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [["hello"]], true]; + +// The type T associated with a destructuring variable declaration is determined as follows: +// Otherwise, if the declaration includes an initializer expression, T is the type of that initializer expression. +var { b1: { b11 } = { b11: "string" } } = { b1: { b11: "world" } }; +var temp = { t1: true, t2: "false" }; +var [b2 = 3, b3 = true, b4 = temp] = [3, false, { t1: false, t2: "hello" }]; +var [b5 = 3, b6 = true, b7 = temp] = [undefined, undefined, undefined]; + +// The type T associated with a binding element is determined as follows: +// If the binding element is a rest element, T is an array type with +// an element type E, where E is the type of the numeric index signature of S. +var [...c1] = [1,2,3]; +var [...c2] = [1,2,3, "string"]; + +// The type T associated with a binding element is determined as follows: +// Otherwise, if S is a tuple- like type (section 3.3.3): +// Let N be the zero-based index of the binding element in the array binding pattern. +// If S has a property with the numerical name N, T is the type of that property. +var [d1,d2] = [1,"string"] + +// The type T associated with a binding element is determined as follows: +// Otherwise, if S is a tuple- like type (section 3.3.3): +// Otherwise, if S has a numeric index signature, T is the type of the numeric index signature. +var temp1 = [true, false, true] +var [d3, d4] = [1, "string", ...temp1]; + +// Combining both forms of destructuring, +var {e: [e1, e2, e3 = { b1: 1000, b4: 200 }]} = { e: [1, 2, { b1: 4, b4: 0 }] }; +var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; + +// When a destructuring variable declaration, binding property, or binding element specifies +// an initializer expression, the type of the initializer expression is required to be assignable +// to the widened form of the type associated with the destructuring variable declaration, binding property, or binding element. +var {g: {g1 = [undefined, null]}}: { g: { g1: any[] } } = { g: { g1: [1, 2] } }; +var {h: {h1 = [undefined, null]}}: { h: { h1: number[] } } = { h: { h1: [1, 2] } }; + diff --git a/tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration2.ts b/tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration2.ts new file mode 100644 index 00000000000..8ffd3bddd58 --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration2.ts @@ -0,0 +1,19 @@ +// The type T associated with a destructuring variable declaration is determined as follows: +// If the declaration includes a type annotation, T is that type. +var {a1, a2}: { a1: number, a2: string } = { a1: true, a2: 1 } // Error +var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [[false]], true]; // Error + +// The type T associated with a destructuring variable declaration is determined as follows: +// Otherwise, if the declaration includes an initializer expression, T is the type of that initializer expression. +var temp = { t1: true, t2: "false" }; +var [b0 = 3, b1 = true, b2 = temp] = [3, false, { t1: false, t2: 5}]; // Error + +// The type T associated with a binding element is determined as follows: +// If the binding element is a rest element, T is an array type with +// an element type E, where E is the type of the numeric index signature of S. +var [c1, c2, { c3: c4, c5 }, , ...c6] = [1, 2, { c3: 4, c5: 0 }]; // Error + +// When a destructuring variable declaration, binding property, or binding element specifies +// an initializer expression, the type of the initializer expression is required to be assignable +// to the widened form of the type associated with the destructuring variable declaration, binding property, or binding element. +var {d: {d1 = ["string", null]}}: { d: { d1: number[] } } = { d: { d1: [1, 2] } }; // Error \ No newline at end of file diff --git a/tests/cases/conformance/es6/destructuring/destructuringVariableDeclarationAndAssignment.ts b/tests/cases/conformance/es6/destructuring/destructuringVariableDeclarationAndAssignment.ts deleted file mode 100644 index a3377dfb8f3..00000000000 --- a/tests/cases/conformance/es6/destructuring/destructuringVariableDeclarationAndAssignment.ts +++ /dev/null @@ -1,3 +0,0 @@ -var {o: [a1, a2, a3 = { b1: 1000, b4: 200 }]} = { o: [1, 2, { b1: 4, b4: 0 }] }; -var {o0: [c, d, { e: e1, f }, , ]} = { o0: [1, 2, { e: 4, f: 0 }] }; -var {o1: [a11, a21, { b12: b22, b42 },, ...c]} = { o1: [1, 2, { b12: 4, b42: 0 }] }; \ No newline at end of file From 5ba01f3149c748dea0e295e51b77351447778fc3 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 16 Apr 2015 19:20:08 -0700 Subject: [PATCH 041/194] Update baselines from merging master --- ...ingArrayBindingPatternAndAssignment1ES5.js | 22 +-- ...rayBindingPatternAndAssignment1ES5.symbols | 105 ++++++++++++++ ...ArrayBindingPatternAndAssignment1ES5.types | 74 +++++----- ...rayBindingPatternAndAssignment1ES6.symbols | 105 ++++++++++++++ ...ArrayBindingPatternAndAssignment1ES6.types | 74 +++++----- ...ngObjectBindingPatternAndAssignment1ES5.js | 20 +-- ...ectBindingPatternAndAssignment1ES5.symbols | 101 ++++++++++++++ ...bjectBindingPatternAndAssignment1ES5.types | 66 ++++----- ...ectBindingPatternAndAssignment1ES6.symbols | 101 ++++++++++++++ ...bjectBindingPatternAndAssignment1ES6.types | 66 ++++----- ...uringObjectBindingPatternAndAssignment3.js | 14 +- .../destructuringVariableDeclaration1ES5.js | 18 +-- ...structuringVariableDeclaration1ES5.symbols | 114 ++++++++++++++++ ...destructuringVariableDeclaration1ES5.types | 128 +++++++++--------- ...structuringVariableDeclaration1ES6.symbols | 114 ++++++++++++++++ ...destructuringVariableDeclaration1ES6.types | 128 +++++++++--------- .../destructuringVariableDeclaration2.js | 2 +- 17 files changed, 946 insertions(+), 306 deletions(-) create mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.symbols create mode 100644 tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.symbols create mode 100644 tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.symbols create mode 100644 tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.symbols create mode 100644 tests/baselines/reference/destructuringVariableDeclaration1ES5.symbols create mode 100644 tests/baselines/reference/destructuringVariableDeclaration1ES6.symbols diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.js b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.js index 6a94b0d2a7f..bf71064264a 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.js +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.js @@ -85,16 +85,16 @@ function foo() { return [1, 2, 3]; } var _e = foo(), b6 = _e[0], b7 = _e[1]; -var _f = foo(), b8 = _f.slice(0); +var b8 = foo().slice(0); // S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E. var temp = [1, 2, 3]; -var _g = temp, c0 = _g[0], c1 = _g[1]; -var c2 = ([])[0]; -var _h = [[[]], [[[[]]]]], c3 = _h[0][0][0], c4 = _h[1][0][0][0][0]; -var _j = [[1], true], c5 = _j[0][0], c6 = _j[1]; -var _k = [1, 2, 3], c7 = _k[1]; -var _l = [1, 2, 3, 4], c8 = _l[3]; -var _m = [1, 2, 3, 4], c9 = _m[3]; -var _o = [1, 2, 3, 4, "hello"], c10 = _o.slice(3); -var _p = [1, 2, "string"], c11 = _p[0], c12 = _p[1], c13 = _p.slice(2); -var _q = [1, 2, "string"], c14 = _q[0], c15 = _q[1], c16 = _q[2]; +var _f = temp, c0 = _f[0], c1 = _f[1]; +var c2 = [][0]; +var _g = [[[]], [[[[]]]]], c3 = _g[0][0][0], c4 = _g[1][0][0][0][0]; +var _h = [[1], true], c5 = _h[0][0], c6 = _h[1]; +var _j = [1, 2, 3], c7 = _j[1]; +var _k = [1, 2, 3, 4], c8 = _k[3]; +var _l = [1, 2, 3, 4], c9 = _l[3]; +var _m = [1, 2, 3, 4, "hello"], c10 = _m.slice(3); +var _o = [1, 2, "string"], c11 = _o[0], c12 = _o[1], c13 = _o.slice(2); +var _p = [1, 2, "string"], c14 = _p[0], c15 = _p[1], c16 = _p[2]; diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.symbols b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.symbols new file mode 100644 index 00000000000..d8e319f4120 --- /dev/null +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.symbols @@ -0,0 +1,105 @@ +=== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES5.ts === +/* AssignmentPattern: + * ObjectAssignmentPattern + * ArrayAssignmentPattern + * ArrayAssignmentPattern: + * [Elision AssignmentRestElementopt ] + * [AssignmentElementList] + * [AssignmentElementList, Elision AssignmentRestElementopt ] + * AssignmentElementList: + * Elision AssignmentElement + * AssignmentElementList, Elisionopt AssignmentElement + * AssignmentElement: + * LeftHandSideExpression Initialiseropt + * AssignmentPattern Initialiseropt + * AssignmentRestElement: + * ... LeftHandSideExpression + */ + +// In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left. +// An expression of type S is considered assignable to an assignment target V if one of the following is true + +// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, +// S is the type Any, or + +var [a0, a1]: any = undefined; +>a0 : Symbol(a0, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 23, 5)) +>a1 : Symbol(a1, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 23, 8)) +>undefined : Symbol(undefined) + +var [a2 = false, a3 = 1]: any = undefined; +>a2 : Symbol(a2, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 24, 5)) +>a3 : Symbol(a3, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 24, 16)) +>undefined : Symbol(undefined) + +// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, +// S is a tuple- like type (section 3.3.3) with a property named N of a type that is assignable to the target given in E, +// where N is the numeric index of E in the array assignment pattern, or +var [b0, b1, b2] = [2, 3, 4]; +>b0 : Symbol(b0, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 29, 5)) +>b1 : Symbol(b1, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 29, 8)) +>b2 : Symbol(b2, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 29, 12)) + +var [b3, b4, b5]: [number, number, string] = [1, 2, "string"]; +>b3 : Symbol(b3, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 5)) +>b4 : Symbol(b4, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 8)) +>b5 : Symbol(b5, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 12)) + +function foo() { +>foo : Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 62)) + + return [1, 2, 3]; +} + +var [b6, b7] = foo(); +>b6 : Symbol(b6, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 36, 5)) +>b7 : Symbol(b7, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 36, 8)) +>foo : Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 62)) + +var [...b8] = foo(); +>b8 : Symbol(b8, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 37, 5)) +>foo : Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 62)) + +// S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E. +var temp = [1,2,3] +>temp : Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 40, 3)) + +var [c0, c1] = [...temp]; +>c0 : Symbol(c0, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 41, 5)) +>c1 : Symbol(c1, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 41, 8)) +>temp : Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 40, 3)) + +var [c2] = []; +>c2 : Symbol(c2, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 42, 5)) + +var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] +>c3 : Symbol(c3, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 43, 7)) +>c4 : Symbol(c4, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 43, 17)) + +var [[c5], c6]: [[string|number], boolean] = [[1], true]; +>c5 : Symbol(c5, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 44, 6)) +>c6 : Symbol(c6, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 44, 10)) + +var [, c7] = [1, 2, 3]; +>c7 : Symbol(c7, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 45, 6)) + +var [,,, c8] = [1, 2, 3, 4]; +>c8 : Symbol(c8, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 46, 8)) + +var [,,, c9] = [1, 2, 3, 4]; +>c9 : Symbol(c9, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 47, 8)) + +var [,,,...c10] = [1, 2, 3, 4, "hello"]; +>c10 : Symbol(c10, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 48, 8)) + +var [c11, c12, ...c13] = [1, 2, "string"]; +>c11 : Symbol(c11, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 49, 5)) +>c12 : Symbol(c12, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 49, 9)) +>c13 : Symbol(c13, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 49, 14)) + +var [c14, c15, c16] = [1, 2, "string"]; +>c14 : Symbol(c14, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 50, 5)) +>c15 : Symbol(c15, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 50, 9)) +>c16 : Symbol(c16, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 50, 14)) + + diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types index 6508581d899..bde9c867e2b 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES5.types @@ -23,40 +23,40 @@ // S is the type Any, or var [a0, a1]: any = undefined; ->a0 : any, Symbol(a0, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 23, 5)) ->a1 : any, Symbol(a1, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 23, 8)) ->undefined : undefined, Symbol(undefined) +>a0 : any +>a1 : any +>undefined : undefined var [a2 = false, a3 = 1]: any = undefined; ->a2 : boolean, Symbol(a2, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 24, 5)) +>a2 : boolean >false : boolean ->a3 : number, Symbol(a3, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 24, 16)) +>a3 : number >1 : number ->undefined : undefined, Symbol(undefined) +>undefined : undefined // V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, // S is a tuple- like type (section 3.3.3) with a property named N of a type that is assignable to the target given in E, // where N is the numeric index of E in the array assignment pattern, or var [b0, b1, b2] = [2, 3, 4]; ->b0 : number, Symbol(b0, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 29, 5)) ->b1 : number, Symbol(b1, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 29, 8)) ->b2 : number, Symbol(b2, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 29, 12)) +>b0 : number +>b1 : number +>b2 : number >[2, 3, 4] : [number, number, number] >2 : number >3 : number >4 : number var [b3, b4, b5]: [number, number, string] = [1, 2, "string"]; ->b3 : number, Symbol(b3, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 5)) ->b4 : number, Symbol(b4, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 8)) ->b5 : string, Symbol(b5, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 12)) +>b3 : number +>b4 : number +>b5 : string >[1, 2, "string"] : [number, number, string] >1 : number >2 : number >"string" : string function foo() { ->foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 62)) +>foo : () => number[] return [1, 2, 3]; >[1, 2, 3] : number[] @@ -66,38 +66,38 @@ function foo() { } var [b6, b7] = foo(); ->b6 : number, Symbol(b6, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 36, 5)) ->b7 : number, Symbol(b7, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 36, 8)) +>b6 : number +>b7 : number >foo() : number[] ->foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 62)) +>foo : () => number[] var [...b8] = foo(); ->b8 : number[], Symbol(b8, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 37, 5)) +>b8 : number[] >foo() : number[] ->foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 30, 62)) +>foo : () => number[] // S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E. var temp = [1,2,3] ->temp : number[], Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 40, 3)) +>temp : number[] >[1,2,3] : number[] >1 : number >2 : number >3 : number var [c0, c1] = [...temp]; ->c0 : number, Symbol(c0, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 41, 5)) ->c1 : number, Symbol(c1, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 41, 8)) +>c0 : number +>c1 : number >[...temp] : number[] >...temp : number ->temp : number[], Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 40, 3)) +>temp : number[] var [c2] = []; ->c2 : any, Symbol(c2, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 42, 5)) +>c2 : any >[] : undefined[] var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] ->c3 : any, Symbol(c3, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 43, 7)) ->c4 : any, Symbol(c4, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 43, 17)) +>c3 : any +>c4 : any >[[[]], [[[[]]]]] : [[undefined[]], [[[undefined[]]]]] >[[]] : [undefined[]] >[] : undefined[] @@ -107,8 +107,8 @@ var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] >[] : undefined[] var [[c5], c6]: [[string|number], boolean] = [[1], true]; ->c5 : string | number, Symbol(c5, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 44, 6)) ->c6 : boolean, Symbol(c6, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 44, 10)) +>c5 : string | number +>c6 : boolean >[[1], true] : [[number], boolean] >[1] : [number] >1 : number @@ -116,7 +116,7 @@ var [[c5], c6]: [[string|number], boolean] = [[1], true]; var [, c7] = [1, 2, 3]; > : undefined ->c7 : number, Symbol(c7, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 45, 6)) +>c7 : number >[1, 2, 3] : [number, number, number] >1 : number >2 : number @@ -126,7 +126,7 @@ var [,,, c8] = [1, 2, 3, 4]; > : undefined > : undefined > : undefined ->c8 : number, Symbol(c8, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 46, 8)) +>c8 : number >[1, 2, 3, 4] : [number, number, number, number] >1 : number >2 : number @@ -137,7 +137,7 @@ var [,,, c9] = [1, 2, 3, 4]; > : undefined > : undefined > : undefined ->c9 : number, Symbol(c9, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 47, 8)) +>c9 : number >[1, 2, 3, 4] : [number, number, number, number] >1 : number >2 : number @@ -148,7 +148,7 @@ var [,,,...c10] = [1, 2, 3, 4, "hello"]; > : undefined > : undefined > : undefined ->c10 : (string | number)[], Symbol(c10, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 48, 8)) +>c10 : (string | number)[] >[1, 2, 3, 4, "hello"] : (string | number)[] >1 : number >2 : number @@ -157,18 +157,18 @@ var [,,,...c10] = [1, 2, 3, 4, "hello"]; >"hello" : string var [c11, c12, ...c13] = [1, 2, "string"]; ->c11 : string | number, Symbol(c11, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 49, 5)) ->c12 : string | number, Symbol(c12, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 49, 9)) ->c13 : (string | number)[], Symbol(c13, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 49, 14)) +>c11 : string | number +>c12 : string | number +>c13 : (string | number)[] >[1, 2, "string"] : (string | number)[] >1 : number >2 : number >"string" : string var [c14, c15, c16] = [1, 2, "string"]; ->c14 : number, Symbol(c14, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 50, 5)) ->c15 : number, Symbol(c15, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 50, 9)) ->c16 : string, Symbol(c16, Decl(destructuringArrayBindingPatternAndAssignment1ES5.ts, 50, 14)) +>c14 : number +>c15 : number +>c16 : string >[1, 2, "string"] : [number, number, string] >1 : number >2 : number diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.symbols b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.symbols new file mode 100644 index 00000000000..33f9b4e88be --- /dev/null +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.symbols @@ -0,0 +1,105 @@ +=== tests/cases/conformance/es6/destructuring/destructuringArrayBindingPatternAndAssignment1ES6.ts === + +/* AssignmentPattern: + * ObjectAssignmentPattern + * ArrayAssignmentPattern + * ArrayAssignmentPattern: + * [Elision AssignmentRestElementopt ] + * [AssignmentElementList] + * [AssignmentElementList, Elision AssignmentRestElementopt ] + * AssignmentElementList: + * Elision AssignmentElement + * AssignmentElementList, Elisionopt AssignmentElement + * AssignmentElement: + * LeftHandSideExpression Initialiseropt + * AssignmentPattern Initialiseropt + * AssignmentRestElement: + * ... LeftHandSideExpression + */ + +// In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left. +// An expression of type S is considered assignable to an assignment target V if one of the following is true + +// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, +// S is the type Any, or + +var [a0, a1]: any = undefined; +>a0 : Symbol(a0, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 24, 5)) +>a1 : Symbol(a1, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 24, 8)) +>undefined : Symbol(undefined) + +var [a2 = false, a3 = 1]: any = undefined; +>a2 : Symbol(a2, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 25, 5)) +>a3 : Symbol(a3, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 25, 16)) +>undefined : Symbol(undefined) + +// V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, +// S is a tuple- like type (section 3.3.3) with a property named N of a type that is assignable to the target given in E, +// where N is the numeric index of E in the array assignment pattern, or +var [b0, b1, b2] = [2, 3, 4]; +>b0 : Symbol(b0, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 30, 5)) +>b1 : Symbol(b1, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 30, 8)) +>b2 : Symbol(b2, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 30, 12)) + +var [b3, b4, b5]: [number, number, string] = [1, 2, "string"]; +>b3 : Symbol(b3, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 5)) +>b4 : Symbol(b4, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 8)) +>b5 : Symbol(b5, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 12)) + +function foo() { +>foo : Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 62)) + + return [1, 2, 3]; +} + +var [b6, b7] = foo(); +>b6 : Symbol(b6, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 37, 5)) +>b7 : Symbol(b7, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 37, 8)) +>foo : Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 62)) + +var [...b8] = foo(); +>b8 : Symbol(b8, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 38, 5)) +>foo : Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 62)) + +// S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E. +var temp = [1,2,3] +>temp : Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 41, 3)) + +var [c0, c1] = [...temp]; +>c0 : Symbol(c0, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 42, 5)) +>c1 : Symbol(c1, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 42, 8)) +>temp : Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 41, 3)) + +var [c2] = []; +>c2 : Symbol(c2, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 43, 5)) + +var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] +>c3 : Symbol(c3, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 44, 7)) +>c4 : Symbol(c4, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 44, 17)) + +var [[c5], c6]: [[string|number], boolean] = [[1], true]; +>c5 : Symbol(c5, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 45, 6)) +>c6 : Symbol(c6, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 45, 10)) + +var [, c7] = [1, 2, 3]; +>c7 : Symbol(c7, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 46, 6)) + +var [,,, c8] = [1, 2, 3, 4]; +>c8 : Symbol(c8, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 47, 8)) + +var [,,, c9] = [1, 2, 3, 4]; +>c9 : Symbol(c9, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 48, 8)) + +var [,,,...c10] = [1, 2, 3, 4, "hello"]; +>c10 : Symbol(c10, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 49, 8)) + +var [c11, c12, ...c13] = [1, 2, "string"]; +>c11 : Symbol(c11, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 50, 5)) +>c12 : Symbol(c12, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 50, 9)) +>c13 : Symbol(c13, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 50, 14)) + +var [c14, c15, c16] = [1, 2, "string"]; +>c14 : Symbol(c14, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 51, 5)) +>c15 : Symbol(c15, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 51, 9)) +>c16 : Symbol(c16, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 51, 14)) + diff --git a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types index 4c999c9468a..2d5d82c5efe 100644 --- a/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types +++ b/tests/baselines/reference/destructuringArrayBindingPatternAndAssignment1ES6.types @@ -24,40 +24,40 @@ // S is the type Any, or var [a0, a1]: any = undefined; ->a0 : any, Symbol(a0, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 24, 5)) ->a1 : any, Symbol(a1, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 24, 8)) ->undefined : undefined, Symbol(undefined) +>a0 : any +>a1 : any +>undefined : undefined var [a2 = false, a3 = 1]: any = undefined; ->a2 : boolean, Symbol(a2, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 25, 5)) +>a2 : boolean >false : boolean ->a3 : number, Symbol(a3, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 25, 16)) +>a3 : number >1 : number ->undefined : undefined, Symbol(undefined) +>undefined : undefined // V is an array assignment pattern, S is the type Any or an array-like type (section 3.3.2), and, for each assignment element E in V, // S is a tuple- like type (section 3.3.3) with a property named N of a type that is assignable to the target given in E, // where N is the numeric index of E in the array assignment pattern, or var [b0, b1, b2] = [2, 3, 4]; ->b0 : number, Symbol(b0, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 30, 5)) ->b1 : number, Symbol(b1, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 30, 8)) ->b2 : number, Symbol(b2, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 30, 12)) +>b0 : number +>b1 : number +>b2 : number >[2, 3, 4] : [number, number, number] >2 : number >3 : number >4 : number var [b3, b4, b5]: [number, number, string] = [1, 2, "string"]; ->b3 : number, Symbol(b3, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 5)) ->b4 : number, Symbol(b4, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 8)) ->b5 : string, Symbol(b5, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 12)) +>b3 : number +>b4 : number +>b5 : string >[1, 2, "string"] : [number, number, string] >1 : number >2 : number >"string" : string function foo() { ->foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 62)) +>foo : () => number[] return [1, 2, 3]; >[1, 2, 3] : number[] @@ -67,38 +67,38 @@ function foo() { } var [b6, b7] = foo(); ->b6 : number, Symbol(b6, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 37, 5)) ->b7 : number, Symbol(b7, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 37, 8)) +>b6 : number +>b7 : number >foo() : number[] ->foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 62)) +>foo : () => number[] var [...b8] = foo(); ->b8 : number[], Symbol(b8, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 38, 5)) +>b8 : number[] >foo() : number[] ->foo : () => number[], Symbol(foo, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 31, 62)) +>foo : () => number[] // S is not a tuple- like type and the numeric index signature type of S is assignable to the target given in E. var temp = [1,2,3] ->temp : number[], Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 41, 3)) +>temp : number[] >[1,2,3] : number[] >1 : number >2 : number >3 : number var [c0, c1] = [...temp]; ->c0 : number, Symbol(c0, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 42, 5)) ->c1 : number, Symbol(c1, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 42, 8)) +>c0 : number +>c1 : number >[...temp] : number[] >...temp : number ->temp : number[], Symbol(temp, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 41, 3)) +>temp : number[] var [c2] = []; ->c2 : any, Symbol(c2, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 43, 5)) +>c2 : any >[] : undefined[] var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] ->c3 : any, Symbol(c3, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 44, 7)) ->c4 : any, Symbol(c4, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 44, 17)) +>c3 : any +>c4 : any >[[[]], [[[[]]]]] : [[undefined[]], [[[undefined[]]]]] >[[]] : [undefined[]] >[] : undefined[] @@ -108,8 +108,8 @@ var [[[c3]], [[[[c4]]]]] = [[[]], [[[[]]]]] >[] : undefined[] var [[c5], c6]: [[string|number], boolean] = [[1], true]; ->c5 : string | number, Symbol(c5, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 45, 6)) ->c6 : boolean, Symbol(c6, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 45, 10)) +>c5 : string | number +>c6 : boolean >[[1], true] : [[number], boolean] >[1] : [number] >1 : number @@ -117,7 +117,7 @@ var [[c5], c6]: [[string|number], boolean] = [[1], true]; var [, c7] = [1, 2, 3]; > : undefined ->c7 : number, Symbol(c7, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 46, 6)) +>c7 : number >[1, 2, 3] : [number, number, number] >1 : number >2 : number @@ -127,7 +127,7 @@ var [,,, c8] = [1, 2, 3, 4]; > : undefined > : undefined > : undefined ->c8 : number, Symbol(c8, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 47, 8)) +>c8 : number >[1, 2, 3, 4] : [number, number, number, number] >1 : number >2 : number @@ -138,7 +138,7 @@ var [,,, c9] = [1, 2, 3, 4]; > : undefined > : undefined > : undefined ->c9 : number, Symbol(c9, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 48, 8)) +>c9 : number >[1, 2, 3, 4] : [number, number, number, number] >1 : number >2 : number @@ -149,7 +149,7 @@ var [,,,...c10] = [1, 2, 3, 4, "hello"]; > : undefined > : undefined > : undefined ->c10 : (string | number)[], Symbol(c10, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 49, 8)) +>c10 : (string | number)[] >[1, 2, 3, 4, "hello"] : (string | number)[] >1 : number >2 : number @@ -158,18 +158,18 @@ var [,,,...c10] = [1, 2, 3, 4, "hello"]; >"hello" : string var [c11, c12, ...c13] = [1, 2, "string"]; ->c11 : string | number, Symbol(c11, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 50, 5)) ->c12 : string | number, Symbol(c12, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 50, 9)) ->c13 : (string | number)[], Symbol(c13, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 50, 14)) +>c11 : string | number +>c12 : string | number +>c13 : (string | number)[] >[1, 2, "string"] : (string | number)[] >1 : number >2 : number >"string" : string var [c14, c15, c16] = [1, 2, "string"]; ->c14 : number, Symbol(c14, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 51, 5)) ->c15 : number, Symbol(c15, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 51, 9)) ->c16 : string, Symbol(c16, Decl(destructuringArrayBindingPatternAndAssignment1ES6.ts, 51, 14)) +>c14 : number +>c15 : number +>c16 : string >[1, 2, "string"] : [number, number, string] >1 : number >2 : number diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.js b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.js index 2b12c2a54aa..f201b17deda 100644 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.js +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.js @@ -60,15 +60,15 @@ var {"prop2": d1} = foo1(); // V is an object assignment pattern and, for each assignment property P in V, // S is the type Any, or var a1 = undefined.a1; -var a2 = ({}).a2; +var a2 = {}.a2; // V is an object assignment pattern and, for each assignment property P in V, // S has an apparent property with the property name specified in // P of a type that is assignable to the target given in P, or -var b1 = ({ b1: 1 }).b1; -var _a = ({ b2: { b21: "world" } }).b2, b21 = (_a === void 0 ? { b21: "string" } : _a).b21; -var b3 = ({ 1: "string" })[1]; -var _b = ({ b4: 100000 }).b4, b4 = _b === void 0 ? 1 : _b; -var b52 = ({ b5: { b52: b52 } }).b5.b52; +var b1 = { b1: 1 }.b1; +var _a = { b2: { b21: "world" } }.b2, b21 = (_a === void 0 ? { b21: "string" } : _a).b21; +var b3 = { 1: "string" }[1]; +var _b = { b4: 100000 }.b4, b4 = _b === void 0 ? 1 : _b; +var b52 = { b5: { b52: b52 } }.b5.b52; function foo() { return { 1: true @@ -79,12 +79,12 @@ function bar() { 2: true }; } -var c0 = (foo())[1]; -var c1 = (bar())[1]; +var c0 = foo()[1]; +var c1 = bar()[1]; function foo1() { return { "prop1": 2 }; } -var d1 = (foo1())["prop1"]; -var d1 = (foo1())["prop2"]; +var d1 = foo1()["prop1"]; +var d1 = foo1()["prop2"]; diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.symbols b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.symbols new file mode 100644 index 00000000000..017a7f71e61 --- /dev/null +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.symbols @@ -0,0 +1,101 @@ +=== tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1ES5.ts === +// In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left. +// An expression of type S is considered assignable to an assignment target V if one of the following is true + +// V is an object assignment pattern and, for each assignment property P in V, +// S is the type Any, or +var { a1 }: any = undefined; +>a1 : Symbol(a1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 5, 5)) +>undefined : Symbol(undefined) + +var { a2 }: any = {}; +>a2 : Symbol(a2, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 6, 5)) + +// V is an object assignment pattern and, for each assignment property P in V, +// S has an apparent property with the property name specified in +// P of a type that is assignable to the target given in P, or +var { b1, } = { b1:1, }; +>b1 : Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 11, 5)) +>b1 : Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 11, 15)) + +var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } }; +>b21 : Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 12, 11)) +>b21 : Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 12, 21)) +>b2 : Symbol(b2, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 12, 44)) +>b21 : Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 12, 50)) + +var {1: b3} = { 1: "string" }; +>b3 : Symbol(b3, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 13, 5)) + +var {b4 = 1}: any = { b4: 100000 }; +>b4 : Symbol(b4, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 14, 5)) +>b4 : Symbol(b4, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 14, 21)) + +var {b5: { b52 } } = { b5: { b52 } }; +>b52 : Symbol(b52, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 10)) +>b5 : Symbol(b5, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 23)) +>b52 : Symbol(b52, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 29)) + +// V is an object assignment pattern and, for each assignment property P in V, +// P specifies a numeric property name and S has a numeric index signature +// of a type that is assignable to the target given in P, or + +interface F { +>F : Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 38)) + + [idx: number]: boolean; +>idx : Symbol(idx, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 22, 5)) +} + +function foo(): F { +>foo : Symbol(foo, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 23, 1)) +>F : Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 38)) + + return { + 1: true + }; +} + +function bar(): F { +>bar : Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 29, 1)) +>F : Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 38)) + + return { + 2: true + }; +} +var {1: c0} = foo(); +>c0 : Symbol(c0, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 36, 5)) +>foo : Symbol(foo, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 23, 1)) + +var {1: c1} = bar(); +>c1 : Symbol(c1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 37, 5)) +>bar : Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 29, 1)) + +// V is an object assignment pattern and, for each assignment property P in V, +// S has a string index signature of a type that is assignable to the target given in P + +interface F1 { +>F1 : Symbol(F1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 37, 20)) + + [str: string]: number; +>str : Symbol(str, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 43, 5)) +} + +function foo1(): F1 { +>foo1 : Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 44, 1)) +>F1 : Symbol(F1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 37, 20)) + + return { + "prop1": 2 + } +} + +var {"prop1": d1} = foo1(); +>d1 : Symbol(d1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 52, 5), Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 53, 5)) +>foo1 : Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 44, 1)) + +var {"prop2": d1} = foo1(); +>d1 : Symbol(d1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 52, 5), Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 53, 5)) +>foo1 : Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 44, 1)) + diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.types b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.types index 3642f6c6abe..f44adab359f 100644 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.types +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES5.types @@ -5,68 +5,68 @@ // V is an object assignment pattern and, for each assignment property P in V, // S is the type Any, or var { a1 }: any = undefined; ->a1 : any, Symbol(a1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 5, 5)) ->undefined : undefined, Symbol(undefined) +>a1 : any +>undefined : undefined var { a2 }: any = {}; ->a2 : any, Symbol(a2, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 6, 5)) +>a2 : any >{} : {} // V is an object assignment pattern and, for each assignment property P in V, // S has an apparent property with the property name specified in // P of a type that is assignable to the target given in P, or var { b1, } = { b1:1, }; ->b1 : number, Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 11, 5)) +>b1 : number >{ b1:1, } : { b1: number; } ->b1 : number, Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 11, 15)) +>b1 : number >1 : number var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } }; >b2 : any ->b21 : string, Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 12, 11)) +>b21 : string >{ b21: "string" } : { b21: string; } ->b21 : string, Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 12, 21)) +>b21 : string >"string" : string >{ b2: { b21: "world" } } : { b2: { b21: string; }; } ->b2 : { b21: string; }, Symbol(b2, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 12, 44)) +>b2 : { b21: string; } >{ b21: "world" } : { b21: string; } ->b21 : string, Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 12, 50)) +>b21 : string >"world" : string var {1: b3} = { 1: "string" }; ->b3 : string, Symbol(b3, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 13, 5)) +>b3 : string >{ 1: "string" } : { 1: string; } >"string" : string var {b4 = 1}: any = { b4: 100000 }; ->b4 : number, Symbol(b4, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 14, 5)) +>b4 : number >1 : number >{ b4: 100000 } : { b4: number; } ->b4 : number, Symbol(b4, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 14, 21)) +>b4 : number >100000 : number var {b5: { b52 } } = { b5: { b52 } }; >b5 : any ->b52 : any, Symbol(b52, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 10)) +>b52 : any >{ b5: { b52 } } : { b5: { b52: any; }; } ->b5 : { b52: any; }, Symbol(b5, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 23)) +>b5 : { b52: any; } >{ b52 } : { b52: any; } ->b52 : any, Symbol(b52, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 29)) +>b52 : any // V is an object assignment pattern and, for each assignment property P in V, // P specifies a numeric property name and S has a numeric index signature // of a type that is assignable to the target given in P, or interface F { ->F : F, Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 38)) +>F : F [idx: number]: boolean; ->idx : number, Symbol(idx, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 22, 5)) +>idx : number } function foo(): F { ->foo : () => F, Symbol(foo, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 23, 1)) ->F : F, Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 38)) +>foo : () => F +>F : F return { >{ 1: true } : { [x: number]: boolean; 1: boolean; } @@ -78,8 +78,8 @@ function foo(): F { } function bar(): F { ->bar : () => F, Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 29, 1)) ->F : F, Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 15, 38)) +>bar : () => F +>F : F return { >{ 2: true } : { [x: number]: boolean; 2: boolean; } @@ -90,28 +90,28 @@ function bar(): F { }; } var {1: c0} = foo(); ->c0 : boolean, Symbol(c0, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 36, 5)) +>c0 : boolean >foo() : F ->foo : () => F, Symbol(foo, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 23, 1)) +>foo : () => F var {1: c1} = bar(); ->c1 : boolean, Symbol(c1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 37, 5)) +>c1 : boolean >bar() : F ->bar : () => F, Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 29, 1)) +>bar : () => F // V is an object assignment pattern and, for each assignment property P in V, // S has a string index signature of a type that is assignable to the target given in P interface F1 { ->F1 : F1, Symbol(F1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 37, 20)) +>F1 : F1 [str: string]: number; ->str : string, Symbol(str, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 43, 5)) +>str : string } function foo1(): F1 { ->foo1 : () => F1, Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 44, 1)) ->F1 : F1, Symbol(F1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 37, 20)) +>foo1 : () => F1 +>F1 : F1 return { >{ "prop1": 2 } : { [x: string]: number; "prop1": number; } @@ -122,12 +122,12 @@ function foo1(): F1 { } var {"prop1": d1} = foo1(); ->d1 : number, Symbol(d1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 52, 5), Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 53, 5)) +>d1 : number >foo1() : F1 ->foo1 : () => F1, Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 44, 1)) +>foo1 : () => F1 var {"prop2": d1} = foo1(); ->d1 : number, Symbol(d1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 52, 5), Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 53, 5)) +>d1 : number >foo1() : F1 ->foo1 : () => F1, Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES5.ts, 44, 1)) +>foo1 : () => F1 diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.symbols b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.symbols new file mode 100644 index 00000000000..11289210ee4 --- /dev/null +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.symbols @@ -0,0 +1,101 @@ +=== tests/cases/conformance/es6/destructuring/destructuringObjectBindingPatternAndAssignment1ES6.ts === +// In a destructuring assignment expression, the type of the expression on the right must be assignable to the assignment target on the left. +// An expression of type S is considered assignable to an assignment target V if one of the following is true + +// V is an object assignment pattern and, for each assignment property P in V, +// S is the type Any, or +var { a1 }: any = undefined; +>a1 : Symbol(a1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 5, 5)) +>undefined : Symbol(undefined) + +var { a2 }: any = {}; +>a2 : Symbol(a2, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 6, 5)) + +// V is an object assignment pattern and, for each assignment property P in V, +// S has an apparent property with the property name specified in +// P of a type that is assignable to the target given in P, or +var { b1, } = { b1:1, }; +>b1 : Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 11, 5)) +>b1 : Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 11, 15)) + +var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } }; +>b21 : Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 11)) +>b21 : Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 21)) +>b2 : Symbol(b2, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 44)) +>b21 : Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 50)) + +var {1: b3} = { 1: "string" }; +>b3 : Symbol(b3, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 13, 5)) + +var {b4 = 1}: any = { b4: 100000 }; +>b4 : Symbol(b4, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 14, 5)) +>b4 : Symbol(b4, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 14, 21)) + +var {b5: { b52 } } = { b5: { b52 } }; +>b52 : Symbol(b52, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 10)) +>b5 : Symbol(b5, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 23)) +>b52 : Symbol(b52, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 29)) + +// V is an object assignment pattern and, for each assignment property P in V, +// P specifies a numeric property name and S has a numeric index signature +// of a type that is assignable to the target given in P, or + +interface F { +>F : Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 38)) + + [idx: number]: boolean; +>idx : Symbol(idx, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 22, 5)) +} + +function foo(): F { +>foo : Symbol(foo, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 23, 1)) +>F : Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 38)) + + return { + 1: true + }; +} + +function bar(): F { +>bar : Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 29, 1)) +>F : Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 38)) + + return { + 2: true + }; +} +var {1: c0} = foo(); +>c0 : Symbol(c0, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 36, 5)) +>foo : Symbol(foo, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 23, 1)) + +var {1: c1} = bar(); +>c1 : Symbol(c1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 37, 5)) +>bar : Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 29, 1)) + +// V is an object assignment pattern and, for each assignment property P in V, +// S has a string index signature of a type that is assignable to the target given in P + +interface F1 { +>F1 : Symbol(F1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 37, 20)) + + [str: string]: number; +>str : Symbol(str, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 43, 5)) +} + +function foo1(): F1 { +>foo1 : Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 44, 1)) +>F1 : Symbol(F1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 37, 20)) + + return { + "prop1": 2 + } +} + +var {"prop1": d1} = foo1(); +>d1 : Symbol(d1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 52, 5), Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 53, 5)) +>foo1 : Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 44, 1)) + +var {"prop2": d1} = foo1(); +>d1 : Symbol(d1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 52, 5), Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 53, 5)) +>foo1 : Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 44, 1)) + diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.types b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.types index afb24e6331d..47d4474b63e 100644 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.types +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment1ES6.types @@ -5,68 +5,68 @@ // V is an object assignment pattern and, for each assignment property P in V, // S is the type Any, or var { a1 }: any = undefined; ->a1 : any, Symbol(a1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 5, 5)) ->undefined : undefined, Symbol(undefined) +>a1 : any +>undefined : undefined var { a2 }: any = {}; ->a2 : any, Symbol(a2, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 6, 5)) +>a2 : any >{} : {} // V is an object assignment pattern and, for each assignment property P in V, // S has an apparent property with the property name specified in // P of a type that is assignable to the target given in P, or var { b1, } = { b1:1, }; ->b1 : number, Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 11, 5)) +>b1 : number >{ b1:1, } : { b1: number; } ->b1 : number, Symbol(b1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 11, 15)) +>b1 : number >1 : number var { b2: { b21 } = { b21: "string" } } = { b2: { b21: "world" } }; >b2 : any ->b21 : string, Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 11)) +>b21 : string >{ b21: "string" } : { b21: string; } ->b21 : string, Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 21)) +>b21 : string >"string" : string >{ b2: { b21: "world" } } : { b2: { b21: string; }; } ->b2 : { b21: string; }, Symbol(b2, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 44)) +>b2 : { b21: string; } >{ b21: "world" } : { b21: string; } ->b21 : string, Symbol(b21, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 12, 50)) +>b21 : string >"world" : string var {1: b3} = { 1: "string" }; ->b3 : string, Symbol(b3, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 13, 5)) +>b3 : string >{ 1: "string" } : { 1: string; } >"string" : string var {b4 = 1}: any = { b4: 100000 }; ->b4 : number, Symbol(b4, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 14, 5)) +>b4 : number >1 : number >{ b4: 100000 } : { b4: number; } ->b4 : number, Symbol(b4, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 14, 21)) +>b4 : number >100000 : number var {b5: { b52 } } = { b5: { b52 } }; >b5 : any ->b52 : any, Symbol(b52, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 10)) +>b52 : any >{ b5: { b52 } } : { b5: { b52: any; }; } ->b5 : { b52: any; }, Symbol(b5, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 23)) +>b5 : { b52: any; } >{ b52 } : { b52: any; } ->b52 : any, Symbol(b52, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 29)) +>b52 : any // V is an object assignment pattern and, for each assignment property P in V, // P specifies a numeric property name and S has a numeric index signature // of a type that is assignable to the target given in P, or interface F { ->F : F, Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 38)) +>F : F [idx: number]: boolean; ->idx : number, Symbol(idx, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 22, 5)) +>idx : number } function foo(): F { ->foo : () => F, Symbol(foo, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 23, 1)) ->F : F, Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 38)) +>foo : () => F +>F : F return { >{ 1: true } : { [x: number]: boolean; 1: boolean; } @@ -78,8 +78,8 @@ function foo(): F { } function bar(): F { ->bar : () => F, Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 29, 1)) ->F : F, Symbol(F, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 15, 38)) +>bar : () => F +>F : F return { >{ 2: true } : { [x: number]: boolean; 2: boolean; } @@ -90,28 +90,28 @@ function bar(): F { }; } var {1: c0} = foo(); ->c0 : boolean, Symbol(c0, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 36, 5)) +>c0 : boolean >foo() : F ->foo : () => F, Symbol(foo, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 23, 1)) +>foo : () => F var {1: c1} = bar(); ->c1 : boolean, Symbol(c1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 37, 5)) +>c1 : boolean >bar() : F ->bar : () => F, Symbol(bar, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 29, 1)) +>bar : () => F // V is an object assignment pattern and, for each assignment property P in V, // S has a string index signature of a type that is assignable to the target given in P interface F1 { ->F1 : F1, Symbol(F1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 37, 20)) +>F1 : F1 [str: string]: number; ->str : string, Symbol(str, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 43, 5)) +>str : string } function foo1(): F1 { ->foo1 : () => F1, Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 44, 1)) ->F1 : F1, Symbol(F1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 37, 20)) +>foo1 : () => F1 +>F1 : F1 return { >{ "prop1": 2 } : { [x: string]: number; "prop1": number; } @@ -122,12 +122,12 @@ function foo1(): F1 { } var {"prop1": d1} = foo1(); ->d1 : number, Symbol(d1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 52, 5), Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 53, 5)) +>d1 : number >foo1() : F1 ->foo1 : () => F1, Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 44, 1)) +>foo1 : () => F1 var {"prop2": d1} = foo1(); ->d1 : number, Symbol(d1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 52, 5), Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 53, 5)) +>d1 : number >foo1() : F1 ->foo1 : () => F1, Symbol(foo1, Decl(destructuringObjectBindingPatternAndAssignment1ES6.ts, 44, 1)) +>foo1 : () => F1 diff --git a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.js b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.js index 3c617ec9b82..77288e6a542 100644 --- a/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.js +++ b/tests/baselines/reference/destructuringObjectBindingPatternAndAssignment3.js @@ -12,12 +12,12 @@ var {"prop"} = { "prop": 1 }; //// [destructuringObjectBindingPatternAndAssignment3.js] // Error -var h = ({ h: 1 }).h; -var i = ({ i: 2 }).i; -var i1 = ({ i1: 2 }).i1; +var h = { h: 1 }.h; +var i = { i: 2 }.i; +var i1 = { i1: 2 }.i1; var _a = undefined.f2, f21 = (_a === void 0 ? { f212: "string" } : _a).f21; -var d1 = ({ +var d1 = { a: 1, b: 1, d1: 9, e: 10 -}).d1; -var = ({ 1: })[1]; -var = ({ "prop": 1 })["prop"]; +}.d1; +var = { 1: }[1]; +var = { "prop": 1 }["prop"]; diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES5.js b/tests/baselines/reference/destructuringVariableDeclaration1ES5.js index 2d1f0c101b1..6d731538d18 100644 --- a/tests/baselines/reference/destructuringVariableDeclaration1ES5.js +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES5.js @@ -48,30 +48,30 @@ var _a = { a1: 10, a2: "world" }, a1 = _a.a1, a2 = _a.a2; var _b = [1, [["hello"]], true], a3 = _b[0], a4 = _b[1][0][0], a5 = _b[2]; // The type T associated with a destructuring variable declaration is determined as follows: // Otherwise, if the declaration includes an initializer expression, T is the type of that initializer expression. -var _c = ({ b1: { b11: "world" } }).b1, b11 = (_c === void 0 ? { b11: "string" } : _c).b11; +var _c = { b1: { b11: "world" } }.b1, b11 = (_c === void 0 ? { b11: "string" } : _c).b11; var temp = { t1: true, t2: "false" }; var _d = [3, false, { t1: false, t2: "hello" }], _e = _d[0], b2 = _e === void 0 ? 3 : _e, _f = _d[1], b3 = _f === void 0 ? true : _f, _g = _d[2], b4 = _g === void 0 ? temp : _g; var _h = [undefined, undefined, undefined], _j = _h[0], b5 = _j === void 0 ? 3 : _j, _k = _h[1], b6 = _k === void 0 ? true : _k, _l = _h[2], b7 = _l === void 0 ? temp : _l; // The type T associated with a binding element is determined as follows: // If the binding element is a rest element, T is an array type with // an element type E, where E is the type of the numeric index signature of S. -var _m = [1, 2, 3], c1 = _m.slice(0); -var _o = [1, 2, 3, "string"], c2 = _o.slice(0); +var c1 = [1, 2, 3].slice(0); +var c2 = [1, 2, 3, "string"].slice(0); // The type T associated with a binding element is determined as follows: // Otherwise, if S is a tuple- like type (section 3.3.3): // Let N be the zero-based index of the binding element in the array binding pattern. // If S has a property with the numerical name N, T is the type of that property. -var _p = [1, "string"], d1 = _p[0], d2 = _p[1]; +var _m = [1, "string"], d1 = _m[0], d2 = _m[1]; // The type T associated with a binding element is determined as follows: // Otherwise, if S is a tuple- like type (section 3.3.3): // Otherwise, if S has a numeric index signature, T is the type of the numeric index signature. var temp1 = [true, false, true]; -var _q = [1, "string"].concat(temp1), d3 = _q[0], d4 = _q[1]; +var _o = [1, "string"].concat(temp1), d3 = _o[0], d4 = _o[1]; // Combining both forms of destructuring, -var _r = ({ e: [1, 2, { b1: 4, b4: 0 }] }).e, e1 = _r[0], e2 = _r[1], _s = _r[2], e3 = _s === void 0 ? { b1: 1000, b4: 200 } : _s; -var _t = ({ f: [1, 2, { f3: 4, f5: 0 }] }).f, f1 = _t[0], f2 = _t[1], _u = _t[2], f4 = _u.f3, f5 = _u.f5; +var _p = { e: [1, 2, { b1: 4, b4: 0 }] }.e, e1 = _p[0], e2 = _p[1], _q = _p[2], e3 = _q === void 0 ? { b1: 1000, b4: 200 } : _q; +var _r = { f: [1, 2, { f3: 4, f5: 0 }] }.f, f1 = _r[0], f2 = _r[1], _s = _r[2], f4 = _s.f3, f5 = _s.f5; // When a destructuring variable declaration, binding property, or binding element specifies // an initializer expression, the type of the initializer expression is required to be assignable // to the widened form of the type associated with the destructuring variable declaration, binding property, or binding element. -var _v = ({ g: { g1: [1, 2] } }).g.g1, g1 = _v === void 0 ? [undefined, null] : _v; -var _w = ({ h: { h1: [1, 2] } }).h.h1, h1 = _w === void 0 ? [undefined, null] : _w; +var _t = { g: { g1: [1, 2] } }.g.g1, g1 = _t === void 0 ? [undefined, null] : _t; +var _u = { h: { h1: [1, 2] } }.h.h1, h1 = _u === void 0 ? [undefined, null] : _u; diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES5.symbols b/tests/baselines/reference/destructuringVariableDeclaration1ES5.symbols new file mode 100644 index 00000000000..2a2f2a358ca --- /dev/null +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES5.symbols @@ -0,0 +1,114 @@ +=== tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration1ES5.ts === +// The type T associated with a destructuring variable declaration is determined as follows: +// If the declaration includes a type annotation, T is that type. +var {a1, a2}: { a1: number, a2: string } = { a1: 10, a2: "world" } +>a1 : Symbol(a1, Decl(destructuringVariableDeclaration1ES5.ts, 2, 5)) +>a2 : Symbol(a2, Decl(destructuringVariableDeclaration1ES5.ts, 2, 8)) +>a1 : Symbol(a1, Decl(destructuringVariableDeclaration1ES5.ts, 2, 15)) +>a2 : Symbol(a2, Decl(destructuringVariableDeclaration1ES5.ts, 2, 27)) +>a1 : Symbol(a1, Decl(destructuringVariableDeclaration1ES5.ts, 2, 44)) +>a2 : Symbol(a2, Decl(destructuringVariableDeclaration1ES5.ts, 2, 52)) + +var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [["hello"]], true]; +>a3 : Symbol(a3, Decl(destructuringVariableDeclaration1ES5.ts, 3, 5)) +>a4 : Symbol(a4, Decl(destructuringVariableDeclaration1ES5.ts, 3, 11)) +>a5 : Symbol(a5, Decl(destructuringVariableDeclaration1ES5.ts, 3, 16)) + +// The type T associated with a destructuring variable declaration is determined as follows: +// Otherwise, if the declaration includes an initializer expression, T is the type of that initializer expression. +var { b1: { b11 } = { b11: "string" } } = { b1: { b11: "world" } }; +>b11 : Symbol(b11, Decl(destructuringVariableDeclaration1ES5.ts, 7, 11)) +>b11 : Symbol(b11, Decl(destructuringVariableDeclaration1ES5.ts, 7, 21)) +>b1 : Symbol(b1, Decl(destructuringVariableDeclaration1ES5.ts, 7, 44)) +>b11 : Symbol(b11, Decl(destructuringVariableDeclaration1ES5.ts, 7, 50)) + +var temp = { t1: true, t2: "false" }; +>temp : Symbol(temp, Decl(destructuringVariableDeclaration1ES5.ts, 8, 3)) +>t1 : Symbol(t1, Decl(destructuringVariableDeclaration1ES5.ts, 8, 12)) +>t2 : Symbol(t2, Decl(destructuringVariableDeclaration1ES5.ts, 8, 22)) + +var [b2 = 3, b3 = true, b4 = temp] = [3, false, { t1: false, t2: "hello" }]; +>b2 : Symbol(b2, Decl(destructuringVariableDeclaration1ES5.ts, 9, 5)) +>b3 : Symbol(b3, Decl(destructuringVariableDeclaration1ES5.ts, 9, 12)) +>b4 : Symbol(b4, Decl(destructuringVariableDeclaration1ES5.ts, 9, 23)) +>temp : Symbol(temp, Decl(destructuringVariableDeclaration1ES5.ts, 8, 3)) +>t1 : Symbol(t1, Decl(destructuringVariableDeclaration1ES5.ts, 9, 49)) +>t2 : Symbol(t2, Decl(destructuringVariableDeclaration1ES5.ts, 9, 60)) + +var [b5 = 3, b6 = true, b7 = temp] = [undefined, undefined, undefined]; +>b5 : Symbol(b5, Decl(destructuringVariableDeclaration1ES5.ts, 10, 5)) +>b6 : Symbol(b6, Decl(destructuringVariableDeclaration1ES5.ts, 10, 12)) +>b7 : Symbol(b7, Decl(destructuringVariableDeclaration1ES5.ts, 10, 23)) +>temp : Symbol(temp, Decl(destructuringVariableDeclaration1ES5.ts, 8, 3)) +>undefined : Symbol(undefined) +>undefined : Symbol(undefined) +>undefined : Symbol(undefined) + +// The type T associated with a binding element is determined as follows: +// If the binding element is a rest element, T is an array type with +// an element type E, where E is the type of the numeric index signature of S. +var [...c1] = [1,2,3]; +>c1 : Symbol(c1, Decl(destructuringVariableDeclaration1ES5.ts, 15, 5)) + +var [...c2] = [1,2,3, "string"]; +>c2 : Symbol(c2, Decl(destructuringVariableDeclaration1ES5.ts, 16, 5)) + +// The type T associated with a binding element is determined as follows: +// Otherwise, if S is a tuple- like type (section 3.3.3): +// Let N be the zero-based index of the binding element in the array binding pattern. +// If S has a property with the numerical name N, T is the type of that property. +var [d1,d2] = [1,"string"] +>d1 : Symbol(d1, Decl(destructuringVariableDeclaration1ES5.ts, 22, 5)) +>d2 : Symbol(d2, Decl(destructuringVariableDeclaration1ES5.ts, 22, 8)) + +// The type T associated with a binding element is determined as follows: +// Otherwise, if S is a tuple- like type (section 3.3.3): +// Otherwise, if S has a numeric index signature, T is the type of the numeric index signature. +var temp1 = [true, false, true] +>temp1 : Symbol(temp1, Decl(destructuringVariableDeclaration1ES5.ts, 27, 3)) + +var [d3, d4] = [1, "string", ...temp1]; +>d3 : Symbol(d3, Decl(destructuringVariableDeclaration1ES5.ts, 28, 5)) +>d4 : Symbol(d4, Decl(destructuringVariableDeclaration1ES5.ts, 28, 8)) +>temp1 : Symbol(temp1, Decl(destructuringVariableDeclaration1ES5.ts, 27, 3)) + +// Combining both forms of destructuring, +var {e: [e1, e2, e3 = { b1: 1000, b4: 200 }]} = { e: [1, 2, { b1: 4, b4: 0 }] }; +>e1 : Symbol(e1, Decl(destructuringVariableDeclaration1ES5.ts, 31, 9)) +>e2 : Symbol(e2, Decl(destructuringVariableDeclaration1ES5.ts, 31, 12)) +>e3 : Symbol(e3, Decl(destructuringVariableDeclaration1ES5.ts, 31, 16)) +>b1 : Symbol(b1, Decl(destructuringVariableDeclaration1ES5.ts, 31, 23)) +>b4 : Symbol(b4, Decl(destructuringVariableDeclaration1ES5.ts, 31, 33)) +>e : Symbol(e, Decl(destructuringVariableDeclaration1ES5.ts, 31, 49)) +>b1 : Symbol(b1, Decl(destructuringVariableDeclaration1ES5.ts, 31, 61)) +>b4 : Symbol(b4, Decl(destructuringVariableDeclaration1ES5.ts, 31, 68)) + +var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; +>f1 : Symbol(f1, Decl(destructuringVariableDeclaration1ES5.ts, 32, 9)) +>f2 : Symbol(f2, Decl(destructuringVariableDeclaration1ES5.ts, 32, 12)) +>f4 : Symbol(f4, Decl(destructuringVariableDeclaration1ES5.ts, 32, 18)) +>f5 : Symbol(f5, Decl(destructuringVariableDeclaration1ES5.ts, 32, 26)) +>f : Symbol(f, Decl(destructuringVariableDeclaration1ES5.ts, 32, 41)) +>f3 : Symbol(f3, Decl(destructuringVariableDeclaration1ES5.ts, 32, 53)) +>f5 : Symbol(f5, Decl(destructuringVariableDeclaration1ES5.ts, 32, 60)) + +// When a destructuring variable declaration, binding property, or binding element specifies +// an initializer expression, the type of the initializer expression is required to be assignable +// to the widened form of the type associated with the destructuring variable declaration, binding property, or binding element. +var {g: {g1 = [undefined, null]}}: { g: { g1: any[] } } = { g: { g1: [1, 2] } }; +>g1 : Symbol(g1, Decl(destructuringVariableDeclaration1ES5.ts, 37, 9)) +>undefined : Symbol(undefined) +>g : Symbol(g, Decl(destructuringVariableDeclaration1ES5.ts, 37, 36)) +>g1 : Symbol(g1, Decl(destructuringVariableDeclaration1ES5.ts, 37, 41)) +>g : Symbol(g, Decl(destructuringVariableDeclaration1ES5.ts, 37, 59)) +>g1 : Symbol(g1, Decl(destructuringVariableDeclaration1ES5.ts, 37, 64)) + +var {h: {h1 = [undefined, null]}}: { h: { h1: number[] } } = { h: { h1: [1, 2] } }; +>h1 : Symbol(h1, Decl(destructuringVariableDeclaration1ES5.ts, 38, 9)) +>undefined : Symbol(undefined) +>h : Symbol(h, Decl(destructuringVariableDeclaration1ES5.ts, 38, 36)) +>h1 : Symbol(h1, Decl(destructuringVariableDeclaration1ES5.ts, 38, 41)) +>h : Symbol(h, Decl(destructuringVariableDeclaration1ES5.ts, 38, 62)) +>h1 : Symbol(h1, Decl(destructuringVariableDeclaration1ES5.ts, 38, 67)) + + diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES5.types b/tests/baselines/reference/destructuringVariableDeclaration1ES5.types index 18966569d35..ef3507f0f8b 100644 --- a/tests/baselines/reference/destructuringVariableDeclaration1ES5.types +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES5.types @@ -2,20 +2,20 @@ // The type T associated with a destructuring variable declaration is determined as follows: // If the declaration includes a type annotation, T is that type. var {a1, a2}: { a1: number, a2: string } = { a1: 10, a2: "world" } ->a1 : number, Symbol(a1, Decl(destructuringVariableDeclaration1ES5.ts, 2, 5)) ->a2 : string, Symbol(a2, Decl(destructuringVariableDeclaration1ES5.ts, 2, 8)) ->a1 : number, Symbol(a1, Decl(destructuringVariableDeclaration1ES5.ts, 2, 15)) ->a2 : string, Symbol(a2, Decl(destructuringVariableDeclaration1ES5.ts, 2, 27)) +>a1 : number +>a2 : string +>a1 : number +>a2 : string >{ a1: 10, a2: "world" } : { a1: number; a2: string; } ->a1 : number, Symbol(a1, Decl(destructuringVariableDeclaration1ES5.ts, 2, 44)) +>a1 : number >10 : number ->a2 : string, Symbol(a2, Decl(destructuringVariableDeclaration1ES5.ts, 2, 52)) +>a2 : string >"world" : string var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [["hello"]], true]; ->a3 : number, Symbol(a3, Decl(destructuringVariableDeclaration1ES5.ts, 3, 5)) ->a4 : string, Symbol(a4, Decl(destructuringVariableDeclaration1ES5.ts, 3, 11)) ->a5 : boolean, Symbol(a5, Decl(destructuringVariableDeclaration1ES5.ts, 3, 16)) +>a3 : number +>a4 : string +>a5 : boolean >[1, [["hello"]], true] : [number, [[string]], boolean] >1 : number >[["hello"]] : [[string]] @@ -27,64 +27,64 @@ var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [["hello"]], true]; // Otherwise, if the declaration includes an initializer expression, T is the type of that initializer expression. var { b1: { b11 } = { b11: "string" } } = { b1: { b11: "world" } }; >b1 : any ->b11 : string, Symbol(b11, Decl(destructuringVariableDeclaration1ES5.ts, 7, 11)) +>b11 : string >{ b11: "string" } : { b11: string; } ->b11 : string, Symbol(b11, Decl(destructuringVariableDeclaration1ES5.ts, 7, 21)) +>b11 : string >"string" : string >{ b1: { b11: "world" } } : { b1: { b11: string; }; } ->b1 : { b11: string; }, Symbol(b1, Decl(destructuringVariableDeclaration1ES5.ts, 7, 44)) +>b1 : { b11: string; } >{ b11: "world" } : { b11: string; } ->b11 : string, Symbol(b11, Decl(destructuringVariableDeclaration1ES5.ts, 7, 50)) +>b11 : string >"world" : string var temp = { t1: true, t2: "false" }; ->temp : { t1: boolean; t2: string; }, Symbol(temp, Decl(destructuringVariableDeclaration1ES5.ts, 8, 3)) +>temp : { t1: boolean; t2: string; } >{ t1: true, t2: "false" } : { t1: boolean; t2: string; } ->t1 : boolean, Symbol(t1, Decl(destructuringVariableDeclaration1ES5.ts, 8, 12)) +>t1 : boolean >true : boolean ->t2 : string, Symbol(t2, Decl(destructuringVariableDeclaration1ES5.ts, 8, 22)) +>t2 : string >"false" : string var [b2 = 3, b3 = true, b4 = temp] = [3, false, { t1: false, t2: "hello" }]; ->b2 : number, Symbol(b2, Decl(destructuringVariableDeclaration1ES5.ts, 9, 5)) +>b2 : number >3 : number ->b3 : boolean, Symbol(b3, Decl(destructuringVariableDeclaration1ES5.ts, 9, 12)) +>b3 : boolean >true : boolean ->b4 : { t1: boolean; t2: string; }, Symbol(b4, Decl(destructuringVariableDeclaration1ES5.ts, 9, 23)) ->temp : { t1: boolean; t2: string; }, Symbol(temp, Decl(destructuringVariableDeclaration1ES5.ts, 8, 3)) +>b4 : { t1: boolean; t2: string; } +>temp : { t1: boolean; t2: string; } >[3, false, { t1: false, t2: "hello" }] : [number, boolean, { t1: boolean; t2: string; }] >3 : number >false : boolean >{ t1: false, t2: "hello" } : { t1: boolean; t2: string; } ->t1 : boolean, Symbol(t1, Decl(destructuringVariableDeclaration1ES5.ts, 9, 49)) +>t1 : boolean >false : boolean ->t2 : string, Symbol(t2, Decl(destructuringVariableDeclaration1ES5.ts, 9, 60)) +>t2 : string >"hello" : string var [b5 = 3, b6 = true, b7 = temp] = [undefined, undefined, undefined]; ->b5 : any, Symbol(b5, Decl(destructuringVariableDeclaration1ES5.ts, 10, 5)) +>b5 : any >3 : number ->b6 : any, Symbol(b6, Decl(destructuringVariableDeclaration1ES5.ts, 10, 12)) +>b6 : any >true : boolean ->b7 : any, Symbol(b7, Decl(destructuringVariableDeclaration1ES5.ts, 10, 23)) ->temp : { t1: boolean; t2: string; }, Symbol(temp, Decl(destructuringVariableDeclaration1ES5.ts, 8, 3)) +>b7 : any +>temp : { t1: boolean; t2: string; } >[undefined, undefined, undefined] : [undefined, undefined, undefined] ->undefined : undefined, Symbol(undefined) ->undefined : undefined, Symbol(undefined) ->undefined : undefined, Symbol(undefined) +>undefined : undefined +>undefined : undefined +>undefined : undefined // The type T associated with a binding element is determined as follows: // If the binding element is a rest element, T is an array type with // an element type E, where E is the type of the numeric index signature of S. var [...c1] = [1,2,3]; ->c1 : number[], Symbol(c1, Decl(destructuringVariableDeclaration1ES5.ts, 15, 5)) +>c1 : number[] >[1,2,3] : number[] >1 : number >2 : number >3 : number var [...c2] = [1,2,3, "string"]; ->c2 : (string | number)[], Symbol(c2, Decl(destructuringVariableDeclaration1ES5.ts, 16, 5)) +>c2 : (string | number)[] >[1,2,3, "string"] : (string | number)[] >1 : number >2 : number @@ -96,8 +96,8 @@ var [...c2] = [1,2,3, "string"]; // Let N be the zero-based index of the binding element in the array binding pattern. // If S has a property with the numerical name N, T is the type of that property. var [d1,d2] = [1,"string"] ->d1 : number, Symbol(d1, Decl(destructuringVariableDeclaration1ES5.ts, 22, 5)) ->d2 : string, Symbol(d2, Decl(destructuringVariableDeclaration1ES5.ts, 22, 8)) +>d1 : number +>d2 : string >[1,"string"] : [number, string] >1 : number >"string" : string @@ -106,60 +106,60 @@ var [d1,d2] = [1,"string"] // Otherwise, if S is a tuple- like type (section 3.3.3): // Otherwise, if S has a numeric index signature, T is the type of the numeric index signature. var temp1 = [true, false, true] ->temp1 : boolean[], Symbol(temp1, Decl(destructuringVariableDeclaration1ES5.ts, 27, 3)) +>temp1 : boolean[] >[true, false, true] : boolean[] >true : boolean >false : boolean >true : boolean var [d3, d4] = [1, "string", ...temp1]; ->d3 : string | number | boolean, Symbol(d3, Decl(destructuringVariableDeclaration1ES5.ts, 28, 5)) ->d4 : string | number | boolean, Symbol(d4, Decl(destructuringVariableDeclaration1ES5.ts, 28, 8)) +>d3 : string | number | boolean +>d4 : string | number | boolean >[1, "string", ...temp1] : (string | number | boolean)[] >1 : number >"string" : string >...temp1 : boolean ->temp1 : boolean[], Symbol(temp1, Decl(destructuringVariableDeclaration1ES5.ts, 27, 3)) +>temp1 : boolean[] // Combining both forms of destructuring, var {e: [e1, e2, e3 = { b1: 1000, b4: 200 }]} = { e: [1, 2, { b1: 4, b4: 0 }] }; >e : any ->e1 : number, Symbol(e1, Decl(destructuringVariableDeclaration1ES5.ts, 31, 9)) ->e2 : number, Symbol(e2, Decl(destructuringVariableDeclaration1ES5.ts, 31, 12)) ->e3 : { b1: number; b4: number; }, Symbol(e3, Decl(destructuringVariableDeclaration1ES5.ts, 31, 16)) +>e1 : number +>e2 : number +>e3 : { b1: number; b4: number; } >{ b1: 1000, b4: 200 } : { b1: number; b4: number; } ->b1 : number, Symbol(b1, Decl(destructuringVariableDeclaration1ES5.ts, 31, 23)) +>b1 : number >1000 : number ->b4 : number, Symbol(b4, Decl(destructuringVariableDeclaration1ES5.ts, 31, 33)) +>b4 : number >200 : number >{ e: [1, 2, { b1: 4, b4: 0 }] } : { e: [number, number, { b1: number; b4: number; }]; } ->e : [number, number, { b1: number; b4: number; }], Symbol(e, Decl(destructuringVariableDeclaration1ES5.ts, 31, 49)) +>e : [number, number, { b1: number; b4: number; }] >[1, 2, { b1: 4, b4: 0 }] : [number, number, { b1: number; b4: number; }] >1 : number >2 : number >{ b1: 4, b4: 0 } : { b1: number; b4: number; } ->b1 : number, Symbol(b1, Decl(destructuringVariableDeclaration1ES5.ts, 31, 61)) +>b1 : number >4 : number ->b4 : number, Symbol(b4, Decl(destructuringVariableDeclaration1ES5.ts, 31, 68)) +>b4 : number >0 : number var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; >f : any ->f1 : number, Symbol(f1, Decl(destructuringVariableDeclaration1ES5.ts, 32, 9)) ->f2 : number, Symbol(f2, Decl(destructuringVariableDeclaration1ES5.ts, 32, 12)) +>f1 : number +>f2 : number >f3 : any ->f4 : number, Symbol(f4, Decl(destructuringVariableDeclaration1ES5.ts, 32, 18)) ->f5 : number, Symbol(f5, Decl(destructuringVariableDeclaration1ES5.ts, 32, 26)) +>f4 : number +>f5 : number > : undefined >{ f: [1, 2, { f3: 4, f5: 0 }] } : { f: [number, number, { f3: number; f5: number; }]; } ->f : [number, number, { f3: number; f5: number; }], Symbol(f, Decl(destructuringVariableDeclaration1ES5.ts, 32, 41)) +>f : [number, number, { f3: number; f5: number; }] >[1, 2, { f3: 4, f5: 0 }] : [number, number, { f3: number; f5: number; }] >1 : number >2 : number >{ f3: 4, f5: 0 } : { f3: number; f5: number; } ->f3 : number, Symbol(f3, Decl(destructuringVariableDeclaration1ES5.ts, 32, 53)) +>f3 : number >4 : number ->f5 : number, Symbol(f5, Decl(destructuringVariableDeclaration1ES5.ts, 32, 60)) +>f5 : number >0 : number // When a destructuring variable declaration, binding property, or binding element specifies @@ -167,32 +167,32 @@ var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; // to the widened form of the type associated with the destructuring variable declaration, binding property, or binding element. var {g: {g1 = [undefined, null]}}: { g: { g1: any[] } } = { g: { g1: [1, 2] } }; >g : any ->g1 : any[], Symbol(g1, Decl(destructuringVariableDeclaration1ES5.ts, 37, 9)) +>g1 : any[] >[undefined, null] : null[] ->undefined : undefined, Symbol(undefined) +>undefined : undefined >null : null ->g : { g1: any[]; }, Symbol(g, Decl(destructuringVariableDeclaration1ES5.ts, 37, 36)) ->g1 : any[], Symbol(g1, Decl(destructuringVariableDeclaration1ES5.ts, 37, 41)) +>g : { g1: any[]; } +>g1 : any[] >{ g: { g1: [1, 2] } } : { g: { g1: number[]; }; } ->g : { g1: number[]; }, Symbol(g, Decl(destructuringVariableDeclaration1ES5.ts, 37, 59)) +>g : { g1: number[]; } >{ g1: [1, 2] } : { g1: number[]; } ->g1 : number[], Symbol(g1, Decl(destructuringVariableDeclaration1ES5.ts, 37, 64)) +>g1 : number[] >[1, 2] : number[] >1 : number >2 : number var {h: {h1 = [undefined, null]}}: { h: { h1: number[] } } = { h: { h1: [1, 2] } }; >h : any ->h1 : number[], Symbol(h1, Decl(destructuringVariableDeclaration1ES5.ts, 38, 9)) +>h1 : number[] >[undefined, null] : null[] ->undefined : undefined, Symbol(undefined) +>undefined : undefined >null : null ->h : { h1: number[]; }, Symbol(h, Decl(destructuringVariableDeclaration1ES5.ts, 38, 36)) ->h1 : number[], Symbol(h1, Decl(destructuringVariableDeclaration1ES5.ts, 38, 41)) +>h : { h1: number[]; } +>h1 : number[] >{ h: { h1: [1, 2] } } : { h: { h1: number[]; }; } ->h : { h1: number[]; }, Symbol(h, Decl(destructuringVariableDeclaration1ES5.ts, 38, 62)) +>h : { h1: number[]; } >{ h1: [1, 2] } : { h1: number[]; } ->h1 : number[], Symbol(h1, Decl(destructuringVariableDeclaration1ES5.ts, 38, 67)) +>h1 : number[] >[1, 2] : number[] >1 : number >2 : number diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES6.symbols b/tests/baselines/reference/destructuringVariableDeclaration1ES6.symbols new file mode 100644 index 00000000000..0350ff35251 --- /dev/null +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES6.symbols @@ -0,0 +1,114 @@ +=== tests/cases/conformance/es6/destructuring/destructuringVariableDeclaration1ES6.ts === +// The type T associated with a destructuring variable declaration is determined as follows: +// If the declaration includes a type annotation, T is that type. +var {a1, a2}: { a1: number, a2: string } = { a1: 10, a2: "world" } +>a1 : Symbol(a1, Decl(destructuringVariableDeclaration1ES6.ts, 2, 5)) +>a2 : Symbol(a2, Decl(destructuringVariableDeclaration1ES6.ts, 2, 8)) +>a1 : Symbol(a1, Decl(destructuringVariableDeclaration1ES6.ts, 2, 15)) +>a2 : Symbol(a2, Decl(destructuringVariableDeclaration1ES6.ts, 2, 27)) +>a1 : Symbol(a1, Decl(destructuringVariableDeclaration1ES6.ts, 2, 44)) +>a2 : Symbol(a2, Decl(destructuringVariableDeclaration1ES6.ts, 2, 52)) + +var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [["hello"]], true]; +>a3 : Symbol(a3, Decl(destructuringVariableDeclaration1ES6.ts, 3, 5)) +>a4 : Symbol(a4, Decl(destructuringVariableDeclaration1ES6.ts, 3, 11)) +>a5 : Symbol(a5, Decl(destructuringVariableDeclaration1ES6.ts, 3, 16)) + +// The type T associated with a destructuring variable declaration is determined as follows: +// Otherwise, if the declaration includes an initializer expression, T is the type of that initializer expression. +var { b1: { b11 } = { b11: "string" } } = { b1: { b11: "world" } }; +>b11 : Symbol(b11, Decl(destructuringVariableDeclaration1ES6.ts, 7, 11)) +>b11 : Symbol(b11, Decl(destructuringVariableDeclaration1ES6.ts, 7, 21)) +>b1 : Symbol(b1, Decl(destructuringVariableDeclaration1ES6.ts, 7, 44)) +>b11 : Symbol(b11, Decl(destructuringVariableDeclaration1ES6.ts, 7, 50)) + +var temp = { t1: true, t2: "false" }; +>temp : Symbol(temp, Decl(destructuringVariableDeclaration1ES6.ts, 8, 3)) +>t1 : Symbol(t1, Decl(destructuringVariableDeclaration1ES6.ts, 8, 12)) +>t2 : Symbol(t2, Decl(destructuringVariableDeclaration1ES6.ts, 8, 22)) + +var [b2 = 3, b3 = true, b4 = temp] = [3, false, { t1: false, t2: "hello" }]; +>b2 : Symbol(b2, Decl(destructuringVariableDeclaration1ES6.ts, 9, 5)) +>b3 : Symbol(b3, Decl(destructuringVariableDeclaration1ES6.ts, 9, 12)) +>b4 : Symbol(b4, Decl(destructuringVariableDeclaration1ES6.ts, 9, 23)) +>temp : Symbol(temp, Decl(destructuringVariableDeclaration1ES6.ts, 8, 3)) +>t1 : Symbol(t1, Decl(destructuringVariableDeclaration1ES6.ts, 9, 49)) +>t2 : Symbol(t2, Decl(destructuringVariableDeclaration1ES6.ts, 9, 60)) + +var [b5 = 3, b6 = true, b7 = temp] = [undefined, undefined, undefined]; +>b5 : Symbol(b5, Decl(destructuringVariableDeclaration1ES6.ts, 10, 5)) +>b6 : Symbol(b6, Decl(destructuringVariableDeclaration1ES6.ts, 10, 12)) +>b7 : Symbol(b7, Decl(destructuringVariableDeclaration1ES6.ts, 10, 23)) +>temp : Symbol(temp, Decl(destructuringVariableDeclaration1ES6.ts, 8, 3)) +>undefined : Symbol(undefined) +>undefined : Symbol(undefined) +>undefined : Symbol(undefined) + +// The type T associated with a binding element is determined as follows: +// If the binding element is a rest element, T is an array type with +// an element type E, where E is the type of the numeric index signature of S. +var [...c1] = [1,2,3]; +>c1 : Symbol(c1, Decl(destructuringVariableDeclaration1ES6.ts, 15, 5)) + +var [...c2] = [1,2,3, "string"]; +>c2 : Symbol(c2, Decl(destructuringVariableDeclaration1ES6.ts, 16, 5)) + +// The type T associated with a binding element is determined as follows: +// Otherwise, if S is a tuple- like type (section 3.3.3): +// Let N be the zero-based index of the binding element in the array binding pattern. +// If S has a property with the numerical name N, T is the type of that property. +var [d1,d2] = [1,"string"] +>d1 : Symbol(d1, Decl(destructuringVariableDeclaration1ES6.ts, 22, 5)) +>d2 : Symbol(d2, Decl(destructuringVariableDeclaration1ES6.ts, 22, 8)) + +// The type T associated with a binding element is determined as follows: +// Otherwise, if S is a tuple- like type (section 3.3.3): +// Otherwise, if S has a numeric index signature, T is the type of the numeric index signature. +var temp1 = [true, false, true] +>temp1 : Symbol(temp1, Decl(destructuringVariableDeclaration1ES6.ts, 27, 3)) + +var [d3, d4] = [1, "string", ...temp1]; +>d3 : Symbol(d3, Decl(destructuringVariableDeclaration1ES6.ts, 28, 5)) +>d4 : Symbol(d4, Decl(destructuringVariableDeclaration1ES6.ts, 28, 8)) +>temp1 : Symbol(temp1, Decl(destructuringVariableDeclaration1ES6.ts, 27, 3)) + +// Combining both forms of destructuring, +var {e: [e1, e2, e3 = { b1: 1000, b4: 200 }]} = { e: [1, 2, { b1: 4, b4: 0 }] }; +>e1 : Symbol(e1, Decl(destructuringVariableDeclaration1ES6.ts, 31, 9)) +>e2 : Symbol(e2, Decl(destructuringVariableDeclaration1ES6.ts, 31, 12)) +>e3 : Symbol(e3, Decl(destructuringVariableDeclaration1ES6.ts, 31, 16)) +>b1 : Symbol(b1, Decl(destructuringVariableDeclaration1ES6.ts, 31, 23)) +>b4 : Symbol(b4, Decl(destructuringVariableDeclaration1ES6.ts, 31, 33)) +>e : Symbol(e, Decl(destructuringVariableDeclaration1ES6.ts, 31, 49)) +>b1 : Symbol(b1, Decl(destructuringVariableDeclaration1ES6.ts, 31, 61)) +>b4 : Symbol(b4, Decl(destructuringVariableDeclaration1ES6.ts, 31, 68)) + +var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; +>f1 : Symbol(f1, Decl(destructuringVariableDeclaration1ES6.ts, 32, 9)) +>f2 : Symbol(f2, Decl(destructuringVariableDeclaration1ES6.ts, 32, 12)) +>f4 : Symbol(f4, Decl(destructuringVariableDeclaration1ES6.ts, 32, 18)) +>f5 : Symbol(f5, Decl(destructuringVariableDeclaration1ES6.ts, 32, 26)) +>f : Symbol(f, Decl(destructuringVariableDeclaration1ES6.ts, 32, 41)) +>f3 : Symbol(f3, Decl(destructuringVariableDeclaration1ES6.ts, 32, 53)) +>f5 : Symbol(f5, Decl(destructuringVariableDeclaration1ES6.ts, 32, 60)) + +// When a destructuring variable declaration, binding property, or binding element specifies +// an initializer expression, the type of the initializer expression is required to be assignable +// to the widened form of the type associated with the destructuring variable declaration, binding property, or binding element. +var {g: {g1 = [undefined, null]}}: { g: { g1: any[] } } = { g: { g1: [1, 2] } }; +>g1 : Symbol(g1, Decl(destructuringVariableDeclaration1ES6.ts, 37, 9)) +>undefined : Symbol(undefined) +>g : Symbol(g, Decl(destructuringVariableDeclaration1ES6.ts, 37, 36)) +>g1 : Symbol(g1, Decl(destructuringVariableDeclaration1ES6.ts, 37, 41)) +>g : Symbol(g, Decl(destructuringVariableDeclaration1ES6.ts, 37, 59)) +>g1 : Symbol(g1, Decl(destructuringVariableDeclaration1ES6.ts, 37, 64)) + +var {h: {h1 = [undefined, null]}}: { h: { h1: number[] } } = { h: { h1: [1, 2] } }; +>h1 : Symbol(h1, Decl(destructuringVariableDeclaration1ES6.ts, 38, 9)) +>undefined : Symbol(undefined) +>h : Symbol(h, Decl(destructuringVariableDeclaration1ES6.ts, 38, 36)) +>h1 : Symbol(h1, Decl(destructuringVariableDeclaration1ES6.ts, 38, 41)) +>h : Symbol(h, Decl(destructuringVariableDeclaration1ES6.ts, 38, 62)) +>h1 : Symbol(h1, Decl(destructuringVariableDeclaration1ES6.ts, 38, 67)) + + diff --git a/tests/baselines/reference/destructuringVariableDeclaration1ES6.types b/tests/baselines/reference/destructuringVariableDeclaration1ES6.types index 71e08134e66..d62574c28f0 100644 --- a/tests/baselines/reference/destructuringVariableDeclaration1ES6.types +++ b/tests/baselines/reference/destructuringVariableDeclaration1ES6.types @@ -2,20 +2,20 @@ // The type T associated with a destructuring variable declaration is determined as follows: // If the declaration includes a type annotation, T is that type. var {a1, a2}: { a1: number, a2: string } = { a1: 10, a2: "world" } ->a1 : number, Symbol(a1, Decl(destructuringVariableDeclaration1ES6.ts, 2, 5)) ->a2 : string, Symbol(a2, Decl(destructuringVariableDeclaration1ES6.ts, 2, 8)) ->a1 : number, Symbol(a1, Decl(destructuringVariableDeclaration1ES6.ts, 2, 15)) ->a2 : string, Symbol(a2, Decl(destructuringVariableDeclaration1ES6.ts, 2, 27)) +>a1 : number +>a2 : string +>a1 : number +>a2 : string >{ a1: 10, a2: "world" } : { a1: number; a2: string; } ->a1 : number, Symbol(a1, Decl(destructuringVariableDeclaration1ES6.ts, 2, 44)) +>a1 : number >10 : number ->a2 : string, Symbol(a2, Decl(destructuringVariableDeclaration1ES6.ts, 2, 52)) +>a2 : string >"world" : string var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [["hello"]], true]; ->a3 : number, Symbol(a3, Decl(destructuringVariableDeclaration1ES6.ts, 3, 5)) ->a4 : string, Symbol(a4, Decl(destructuringVariableDeclaration1ES6.ts, 3, 11)) ->a5 : boolean, Symbol(a5, Decl(destructuringVariableDeclaration1ES6.ts, 3, 16)) +>a3 : number +>a4 : string +>a5 : boolean >[1, [["hello"]], true] : [number, [[string]], boolean] >1 : number >[["hello"]] : [[string]] @@ -27,64 +27,64 @@ var [a3, [[a4]], a5]: [number, [[string]], boolean] = [1, [["hello"]], true]; // Otherwise, if the declaration includes an initializer expression, T is the type of that initializer expression. var { b1: { b11 } = { b11: "string" } } = { b1: { b11: "world" } }; >b1 : any ->b11 : string, Symbol(b11, Decl(destructuringVariableDeclaration1ES6.ts, 7, 11)) +>b11 : string >{ b11: "string" } : { b11: string; } ->b11 : string, Symbol(b11, Decl(destructuringVariableDeclaration1ES6.ts, 7, 21)) +>b11 : string >"string" : string >{ b1: { b11: "world" } } : { b1: { b11: string; }; } ->b1 : { b11: string; }, Symbol(b1, Decl(destructuringVariableDeclaration1ES6.ts, 7, 44)) +>b1 : { b11: string; } >{ b11: "world" } : { b11: string; } ->b11 : string, Symbol(b11, Decl(destructuringVariableDeclaration1ES6.ts, 7, 50)) +>b11 : string >"world" : string var temp = { t1: true, t2: "false" }; ->temp : { t1: boolean; t2: string; }, Symbol(temp, Decl(destructuringVariableDeclaration1ES6.ts, 8, 3)) +>temp : { t1: boolean; t2: string; } >{ t1: true, t2: "false" } : { t1: boolean; t2: string; } ->t1 : boolean, Symbol(t1, Decl(destructuringVariableDeclaration1ES6.ts, 8, 12)) +>t1 : boolean >true : boolean ->t2 : string, Symbol(t2, Decl(destructuringVariableDeclaration1ES6.ts, 8, 22)) +>t2 : string >"false" : string var [b2 = 3, b3 = true, b4 = temp] = [3, false, { t1: false, t2: "hello" }]; ->b2 : number, Symbol(b2, Decl(destructuringVariableDeclaration1ES6.ts, 9, 5)) +>b2 : number >3 : number ->b3 : boolean, Symbol(b3, Decl(destructuringVariableDeclaration1ES6.ts, 9, 12)) +>b3 : boolean >true : boolean ->b4 : { t1: boolean; t2: string; }, Symbol(b4, Decl(destructuringVariableDeclaration1ES6.ts, 9, 23)) ->temp : { t1: boolean; t2: string; }, Symbol(temp, Decl(destructuringVariableDeclaration1ES6.ts, 8, 3)) +>b4 : { t1: boolean; t2: string; } +>temp : { t1: boolean; t2: string; } >[3, false, { t1: false, t2: "hello" }] : [number, boolean, { t1: boolean; t2: string; }] >3 : number >false : boolean >{ t1: false, t2: "hello" } : { t1: boolean; t2: string; } ->t1 : boolean, Symbol(t1, Decl(destructuringVariableDeclaration1ES6.ts, 9, 49)) +>t1 : boolean >false : boolean ->t2 : string, Symbol(t2, Decl(destructuringVariableDeclaration1ES6.ts, 9, 60)) +>t2 : string >"hello" : string var [b5 = 3, b6 = true, b7 = temp] = [undefined, undefined, undefined]; ->b5 : any, Symbol(b5, Decl(destructuringVariableDeclaration1ES6.ts, 10, 5)) +>b5 : any >3 : number ->b6 : any, Symbol(b6, Decl(destructuringVariableDeclaration1ES6.ts, 10, 12)) +>b6 : any >true : boolean ->b7 : any, Symbol(b7, Decl(destructuringVariableDeclaration1ES6.ts, 10, 23)) ->temp : { t1: boolean; t2: string; }, Symbol(temp, Decl(destructuringVariableDeclaration1ES6.ts, 8, 3)) +>b7 : any +>temp : { t1: boolean; t2: string; } >[undefined, undefined, undefined] : [undefined, undefined, undefined] ->undefined : undefined, Symbol(undefined) ->undefined : undefined, Symbol(undefined) ->undefined : undefined, Symbol(undefined) +>undefined : undefined +>undefined : undefined +>undefined : undefined // The type T associated with a binding element is determined as follows: // If the binding element is a rest element, T is an array type with // an element type E, where E is the type of the numeric index signature of S. var [...c1] = [1,2,3]; ->c1 : number[], Symbol(c1, Decl(destructuringVariableDeclaration1ES6.ts, 15, 5)) +>c1 : number[] >[1,2,3] : number[] >1 : number >2 : number >3 : number var [...c2] = [1,2,3, "string"]; ->c2 : (string | number)[], Symbol(c2, Decl(destructuringVariableDeclaration1ES6.ts, 16, 5)) +>c2 : (string | number)[] >[1,2,3, "string"] : (string | number)[] >1 : number >2 : number @@ -96,8 +96,8 @@ var [...c2] = [1,2,3, "string"]; // Let N be the zero-based index of the binding element in the array binding pattern. // If S has a property with the numerical name N, T is the type of that property. var [d1,d2] = [1,"string"] ->d1 : number, Symbol(d1, Decl(destructuringVariableDeclaration1ES6.ts, 22, 5)) ->d2 : string, Symbol(d2, Decl(destructuringVariableDeclaration1ES6.ts, 22, 8)) +>d1 : number +>d2 : string >[1,"string"] : [number, string] >1 : number >"string" : string @@ -106,60 +106,60 @@ var [d1,d2] = [1,"string"] // Otherwise, if S is a tuple- like type (section 3.3.3): // Otherwise, if S has a numeric index signature, T is the type of the numeric index signature. var temp1 = [true, false, true] ->temp1 : boolean[], Symbol(temp1, Decl(destructuringVariableDeclaration1ES6.ts, 27, 3)) +>temp1 : boolean[] >[true, false, true] : boolean[] >true : boolean >false : boolean >true : boolean var [d3, d4] = [1, "string", ...temp1]; ->d3 : string | number | boolean, Symbol(d3, Decl(destructuringVariableDeclaration1ES6.ts, 28, 5)) ->d4 : string | number | boolean, Symbol(d4, Decl(destructuringVariableDeclaration1ES6.ts, 28, 8)) +>d3 : string | number | boolean +>d4 : string | number | boolean >[1, "string", ...temp1] : (string | number | boolean)[] >1 : number >"string" : string >...temp1 : boolean ->temp1 : boolean[], Symbol(temp1, Decl(destructuringVariableDeclaration1ES6.ts, 27, 3)) +>temp1 : boolean[] // Combining both forms of destructuring, var {e: [e1, e2, e3 = { b1: 1000, b4: 200 }]} = { e: [1, 2, { b1: 4, b4: 0 }] }; >e : any ->e1 : number, Symbol(e1, Decl(destructuringVariableDeclaration1ES6.ts, 31, 9)) ->e2 : number, Symbol(e2, Decl(destructuringVariableDeclaration1ES6.ts, 31, 12)) ->e3 : { b1: number; b4: number; }, Symbol(e3, Decl(destructuringVariableDeclaration1ES6.ts, 31, 16)) +>e1 : number +>e2 : number +>e3 : { b1: number; b4: number; } >{ b1: 1000, b4: 200 } : { b1: number; b4: number; } ->b1 : number, Symbol(b1, Decl(destructuringVariableDeclaration1ES6.ts, 31, 23)) +>b1 : number >1000 : number ->b4 : number, Symbol(b4, Decl(destructuringVariableDeclaration1ES6.ts, 31, 33)) +>b4 : number >200 : number >{ e: [1, 2, { b1: 4, b4: 0 }] } : { e: [number, number, { b1: number; b4: number; }]; } ->e : [number, number, { b1: number; b4: number; }], Symbol(e, Decl(destructuringVariableDeclaration1ES6.ts, 31, 49)) +>e : [number, number, { b1: number; b4: number; }] >[1, 2, { b1: 4, b4: 0 }] : [number, number, { b1: number; b4: number; }] >1 : number >2 : number >{ b1: 4, b4: 0 } : { b1: number; b4: number; } ->b1 : number, Symbol(b1, Decl(destructuringVariableDeclaration1ES6.ts, 31, 61)) +>b1 : number >4 : number ->b4 : number, Symbol(b4, Decl(destructuringVariableDeclaration1ES6.ts, 31, 68)) +>b4 : number >0 : number var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; >f : any ->f1 : number, Symbol(f1, Decl(destructuringVariableDeclaration1ES6.ts, 32, 9)) ->f2 : number, Symbol(f2, Decl(destructuringVariableDeclaration1ES6.ts, 32, 12)) +>f1 : number +>f2 : number >f3 : any ->f4 : number, Symbol(f4, Decl(destructuringVariableDeclaration1ES6.ts, 32, 18)) ->f5 : number, Symbol(f5, Decl(destructuringVariableDeclaration1ES6.ts, 32, 26)) +>f4 : number +>f5 : number > : undefined >{ f: [1, 2, { f3: 4, f5: 0 }] } : { f: [number, number, { f3: number; f5: number; }]; } ->f : [number, number, { f3: number; f5: number; }], Symbol(f, Decl(destructuringVariableDeclaration1ES6.ts, 32, 41)) +>f : [number, number, { f3: number; f5: number; }] >[1, 2, { f3: 4, f5: 0 }] : [number, number, { f3: number; f5: number; }] >1 : number >2 : number >{ f3: 4, f5: 0 } : { f3: number; f5: number; } ->f3 : number, Symbol(f3, Decl(destructuringVariableDeclaration1ES6.ts, 32, 53)) +>f3 : number >4 : number ->f5 : number, Symbol(f5, Decl(destructuringVariableDeclaration1ES6.ts, 32, 60)) +>f5 : number >0 : number // When a destructuring variable declaration, binding property, or binding element specifies @@ -167,32 +167,32 @@ var {f: [f1, f2, { f3: f4, f5 }, , ]} = { f: [1, 2, { f3: 4, f5: 0 }] }; // to the widened form of the type associated with the destructuring variable declaration, binding property, or binding element. var {g: {g1 = [undefined, null]}}: { g: { g1: any[] } } = { g: { g1: [1, 2] } }; >g : any ->g1 : any[], Symbol(g1, Decl(destructuringVariableDeclaration1ES6.ts, 37, 9)) +>g1 : any[] >[undefined, null] : null[] ->undefined : undefined, Symbol(undefined) +>undefined : undefined >null : null ->g : { g1: any[]; }, Symbol(g, Decl(destructuringVariableDeclaration1ES6.ts, 37, 36)) ->g1 : any[], Symbol(g1, Decl(destructuringVariableDeclaration1ES6.ts, 37, 41)) +>g : { g1: any[]; } +>g1 : any[] >{ g: { g1: [1, 2] } } : { g: { g1: number[]; }; } ->g : { g1: number[]; }, Symbol(g, Decl(destructuringVariableDeclaration1ES6.ts, 37, 59)) +>g : { g1: number[]; } >{ g1: [1, 2] } : { g1: number[]; } ->g1 : number[], Symbol(g1, Decl(destructuringVariableDeclaration1ES6.ts, 37, 64)) +>g1 : number[] >[1, 2] : number[] >1 : number >2 : number var {h: {h1 = [undefined, null]}}: { h: { h1: number[] } } = { h: { h1: [1, 2] } }; >h : any ->h1 : number[], Symbol(h1, Decl(destructuringVariableDeclaration1ES6.ts, 38, 9)) +>h1 : number[] >[undefined, null] : null[] ->undefined : undefined, Symbol(undefined) +>undefined : undefined >null : null ->h : { h1: number[]; }, Symbol(h, Decl(destructuringVariableDeclaration1ES6.ts, 38, 36)) ->h1 : number[], Symbol(h1, Decl(destructuringVariableDeclaration1ES6.ts, 38, 41)) +>h : { h1: number[]; } +>h1 : number[] >{ h: { h1: [1, 2] } } : { h: { h1: number[]; }; } ->h : { h1: number[]; }, Symbol(h, Decl(destructuringVariableDeclaration1ES6.ts, 38, 62)) +>h : { h1: number[]; } >{ h1: [1, 2] } : { h1: number[]; } ->h1 : number[], Symbol(h1, Decl(destructuringVariableDeclaration1ES6.ts, 38, 67)) +>h1 : number[] >[1, 2] : number[] >1 : number >2 : number diff --git a/tests/baselines/reference/destructuringVariableDeclaration2.js b/tests/baselines/reference/destructuringVariableDeclaration2.js index b3d4152892a..a4fadd850d7 100644 --- a/tests/baselines/reference/destructuringVariableDeclaration2.js +++ b/tests/baselines/reference/destructuringVariableDeclaration2.js @@ -35,4 +35,4 @@ var _g = [1, 2, { c3: 4, c5: 0 }], c1 = _g[0], c2 = _g[1], _h = _g[2], c4 = _h.c // When a destructuring variable declaration, binding property, or binding element specifies // an initializer expression, the type of the initializer expression is required to be assignable // to the widened form of the type associated with the destructuring variable declaration, binding property, or binding element. -var _j = ({ d: { d1: [1, 2] } }).d.d1, d1 = _j === void 0 ? ["string", null] : _j; // Error +var _j = { d: { d1: [1, 2] } }.d.d1, d1 = _j === void 0 ? ["string", null] : _j; // Error From d94027b146b34a1f8564ad20735c1df63554f604 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 16 Apr 2015 20:01:29 -0700 Subject: [PATCH 042/194] Add conformance tests for arugment expression, getSetAccessor, arrayLiteralExpression --- ...umentExpressionContextualTyping.errors.txt | 38 ++++++++++ .../argumentExpressionContextualTyping.js | 40 ++++++++++ ...teralExpressionContextualTyping.errors.txt | 34 +++++++++ .../arrayLiteralExpressionContextualTyping.js | 31 ++++++++ .../getSetAccessorContextualTyping.errors.txt | 31 ++++++++ .../getSetAccessorContextualTyping.js | 68 +++++++++++++++++ .../objectLiteralContextualTyping.js | 10 ++- .../objectLiteralContextualTyping.symbols | 75 ++++++++++--------- .../objectLiteralContextualTyping.types | 5 +- .../argumentExpressionContextualTyping.ts | 18 +++++ .../arrayLiteralExpressionContextualTyping.ts | 14 ++++ .../getSetAccessorContextualTyping.ts | 26 +++++++ .../objectLiteralContextualTyping.ts | 5 +- 13 files changed, 355 insertions(+), 40 deletions(-) create mode 100644 tests/baselines/reference/argumentExpressionContextualTyping.errors.txt create mode 100644 tests/baselines/reference/argumentExpressionContextualTyping.js create mode 100644 tests/baselines/reference/arrayLiteralExpressionContextualTyping.errors.txt create mode 100644 tests/baselines/reference/arrayLiteralExpressionContextualTyping.js create mode 100644 tests/baselines/reference/getSetAccessorContextualTyping.errors.txt create mode 100644 tests/baselines/reference/getSetAccessorContextualTyping.js create mode 100644 tests/cases/conformance/expressions/contextualTyping/argumentExpressionContextualTyping.ts create mode 100644 tests/cases/conformance/expressions/contextualTyping/arrayLiteralExpressionContextualTyping.ts create mode 100644 tests/cases/conformance/expressions/contextualTyping/getSetAccessorContextualTyping.ts diff --git a/tests/baselines/reference/argumentExpressionContextualTyping.errors.txt b/tests/baselines/reference/argumentExpressionContextualTyping.errors.txt new file mode 100644 index 00000000000..c1bac0fb1ff --- /dev/null +++ b/tests/baselines/reference/argumentExpressionContextualTyping.errors.txt @@ -0,0 +1,38 @@ +tests/cases/conformance/expressions/contextualTyping/argumentExpressionContextualTyping.ts(16,5): error TS2345: Argument of type '(string | number | boolean)[]' is not assignable to parameter of type '[string, number, boolean]'. + Property '0' is missing in type '(string | number | boolean)[]'. +tests/cases/conformance/expressions/contextualTyping/argumentExpressionContextualTyping.ts(17,5): error TS2345: Argument of type '(string | number | boolean)[]' is not assignable to parameter of type '[string, number, boolean]'. +tests/cases/conformance/expressions/contextualTyping/argumentExpressionContextualTyping.ts(18,5): error TS2345: Argument of type '{ x: (string | number)[]; y: { c: boolean; d: string; e: number; }; }' is not assignable to parameter of type '{ x: [any, any]; y: { c: any; d: any; e: any; }; }'. + Types of property 'x' are incompatible. + Type '(string | number)[]' is not assignable to type '[any, any]'. + Property '0' is missing in type '(string | number)[]'. + + +==== tests/cases/conformance/expressions/contextualTyping/argumentExpressionContextualTyping.ts (3 errors) ==== + // In a typed function call, argument expressions are contextually typed by their corresponding parameter types. + function foo({x: [a, b], y: {c, d, e}}) { } + function bar({x: [a, b = 10], y: {c, d, e = { f:1 }}}) { } + function baz(x: [string, number, boolean]) { } + + var o = { x: ["string", 1], y: { c: true, d: "world", e: 3 } }; + var o1: { x: [string, number], y: { c: boolean, d: string, e: number } } = { x: ["string", 1], y: { c: true, d: "world", e: 3 } }; + foo(o1); // Not error since x has contextual type of tuple namely [string, number] + foo({ x: ["string", 1], y: { c: true, d: "world", e: 3 } }); // Not error + + var array = ["string", 1, true]; + var tuple: [string, number, boolean] = ["string", 1, true]; + baz(tuple); + baz(["string", 1, true]); + + baz(array); // Error + ~~~~~ +!!! error TS2345: Argument of type '(string | number | boolean)[]' is not assignable to parameter of type '[string, number, boolean]'. +!!! error TS2345: Property '0' is missing in type '(string | number | boolean)[]'. + baz(["string", 1, true, ...array]); // Error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(string | number | boolean)[]' is not assignable to parameter of type '[string, number, boolean]'. + foo(o); // Error because x has an array type namely (string|number)[] + ~ +!!! error TS2345: Argument of type '{ x: (string | number)[]; y: { c: boolean; d: string; e: number; }; }' is not assignable to parameter of type '{ x: [any, any]; y: { c: any; d: any; e: any; }; }'. +!!! error TS2345: Types of property 'x' are incompatible. +!!! error TS2345: Type '(string | number)[]' is not assignable to type '[any, any]'. +!!! error TS2345: Property '0' is missing in type '(string | number)[]'. \ No newline at end of file diff --git a/tests/baselines/reference/argumentExpressionContextualTyping.js b/tests/baselines/reference/argumentExpressionContextualTyping.js new file mode 100644 index 00000000000..d3383612327 --- /dev/null +++ b/tests/baselines/reference/argumentExpressionContextualTyping.js @@ -0,0 +1,40 @@ +//// [argumentExpressionContextualTyping.ts] +// In a typed function call, argument expressions are contextually typed by their corresponding parameter types. +function foo({x: [a, b], y: {c, d, e}}) { } +function bar({x: [a, b = 10], y: {c, d, e = { f:1 }}}) { } +function baz(x: [string, number, boolean]) { } + +var o = { x: ["string", 1], y: { c: true, d: "world", e: 3 } }; +var o1: { x: [string, number], y: { c: boolean, d: string, e: number } } = { x: ["string", 1], y: { c: true, d: "world", e: 3 } }; +foo(o1); // Not error since x has contextual type of tuple namely [string, number] +foo({ x: ["string", 1], y: { c: true, d: "world", e: 3 } }); // Not error + +var array = ["string", 1, true]; +var tuple: [string, number, boolean] = ["string", 1, true]; +baz(tuple); +baz(["string", 1, true]); + +baz(array); // Error +baz(["string", 1, true, ...array]); // Error +foo(o); // Error because x has an array type namely (string|number)[] + +//// [argumentExpressionContextualTyping.js] +// In a typed function call, argument expressions are contextually typed by their corresponding parameter types. +function foo(_a) { + var _b = _a.x, a = _b[0], b = _b[1], _c = _a.y, c = _c.c, d = _c.d, e = _c.e; +} +function bar(_a) { + var _b = _a.x, a = _b[0], _c = _b[1], b = _c === void 0 ? 10 : _c, _d = _a.y, c = _d.c, d = _d.d, _e = _d.e, e = _e === void 0 ? { f: 1 } : _e; +} +function baz(x) { } +var o = { x: ["string", 1], y: { c: true, d: "world", e: 3 } }; +var o1 = { x: ["string", 1], y: { c: true, d: "world", e: 3 } }; +foo(o1); // Not error since x has contextual type of tuple namely [string, number] +foo({ x: ["string", 1], y: { c: true, d: "world", e: 3 } }); // Not error +var array = ["string", 1, true]; +var tuple = ["string", 1, true]; +baz(tuple); +baz(["string", 1, true]); +baz(array); // Error +baz(["string", 1, true].concat(array)); // Error +foo(o); // Error because x has an array type namely (string|number)[] diff --git a/tests/baselines/reference/arrayLiteralExpressionContextualTyping.errors.txt b/tests/baselines/reference/arrayLiteralExpressionContextualTyping.errors.txt new file mode 100644 index 00000000000..3e9777aea7c --- /dev/null +++ b/tests/baselines/reference/arrayLiteralExpressionContextualTyping.errors.txt @@ -0,0 +1,34 @@ +tests/cases/conformance/expressions/contextualTyping/arrayLiteralExpressionContextualTyping.ts(8,5): error TS2322: Type '[number, number, number, string]' is not assignable to type '[number, number, number]'. + Types of property 'pop' are incompatible. + Type '() => string | number' is not assignable to type '() => number'. + Type 'string | number' is not assignable to type 'number'. + Type 'string' is not assignable to type 'number'. +tests/cases/conformance/expressions/contextualTyping/arrayLiteralExpressionContextualTyping.ts(14,5): error TS2322: Type 'number[]' is not assignable to type '[number, number, number]'. + Property '0' is missing in type 'number[]'. + + +==== tests/cases/conformance/expressions/contextualTyping/arrayLiteralExpressionContextualTyping.ts (2 errors) ==== + // In a contextually typed array literal expression containing no spread elements, an element expression at index N is contextually typed by + // the type of the property with the numeric name N in the contextual type, if any, or otherwise + // the numeric index type of the contextual type, if any. + var array = [1, 2, 3]; + var array1 = [true, 2, 3]; // Contextual type by the numeric index type of the contextual type + var tup: [number, number, number] = [1, 2, 3, 4]; + var tup1: [number|string, number|string, number|string] = [1, 2, 3, "string"]; + var tup2: [number, number, number] = [1, 2, 3, "string"]; // Error + ~~~~ +!!! error TS2322: Type '[number, number, number, string]' is not assignable to type '[number, number, number]'. +!!! error TS2322: Types of property 'pop' are incompatible. +!!! error TS2322: Type '() => string | number' is not assignable to type '() => number'. +!!! error TS2322: Type 'string | number' is not assignable to type 'number'. +!!! error TS2322: Type 'string' is not assignable to type 'number'. + + // In a contextually typed array literal expression containing one or more spread elements, + // an element expression at index N is contextually typed by the numeric index type of the contextual type, if any. + var spr = [1, 2, 3, ...array]; + var spr1 = [1, 2, 3, ...tup]; + var spr2:[number, number, number] = [1, 2, 3, ...tup]; // Error + ~~~~ +!!! error TS2322: Type 'number[]' is not assignable to type '[number, number, number]'. +!!! error TS2322: Property '0' is missing in type 'number[]'. + \ No newline at end of file diff --git a/tests/baselines/reference/arrayLiteralExpressionContextualTyping.js b/tests/baselines/reference/arrayLiteralExpressionContextualTyping.js new file mode 100644 index 00000000000..852a632f361 --- /dev/null +++ b/tests/baselines/reference/arrayLiteralExpressionContextualTyping.js @@ -0,0 +1,31 @@ +//// [arrayLiteralExpressionContextualTyping.ts] +// In a contextually typed array literal expression containing no spread elements, an element expression at index N is contextually typed by +// the type of the property with the numeric name N in the contextual type, if any, or otherwise +// the numeric index type of the contextual type, if any. +var array = [1, 2, 3]; +var array1 = [true, 2, 3]; // Contextual type by the numeric index type of the contextual type +var tup: [number, number, number] = [1, 2, 3, 4]; +var tup1: [number|string, number|string, number|string] = [1, 2, 3, "string"]; +var tup2: [number, number, number] = [1, 2, 3, "string"]; // Error + +// In a contextually typed array literal expression containing one or more spread elements, +// an element expression at index N is contextually typed by the numeric index type of the contextual type, if any. +var spr = [1, 2, 3, ...array]; +var spr1 = [1, 2, 3, ...tup]; +var spr2:[number, number, number] = [1, 2, 3, ...tup]; // Error + + +//// [arrayLiteralExpressionContextualTyping.js] +// In a contextually typed array literal expression containing no spread elements, an element expression at index N is contextually typed by +// the type of the property with the numeric name N in the contextual type, if any, or otherwise +// the numeric index type of the contextual type, if any. +var array = [1, 2, 3]; +var array1 = [true, 2, 3]; // Contextual type by the numeric index type of the contextual type +var tup = [1, 2, 3, 4]; +var tup1 = [1, 2, 3, "string"]; +var tup2 = [1, 2, 3, "string"]; // Error +// In a contextually typed array literal expression containing one or more spread elements, +// an element expression at index N is contextually typed by the numeric index type of the contextual type, if any. +var spr = [1, 2, 3].concat(array); +var spr1 = [1, 2, 3].concat(tup); +var spr2 = [1, 2, 3].concat(tup); // Error diff --git a/tests/baselines/reference/getSetAccessorContextualTyping.errors.txt b/tests/baselines/reference/getSetAccessorContextualTyping.errors.txt new file mode 100644 index 00000000000..5b076b078c5 --- /dev/null +++ b/tests/baselines/reference/getSetAccessorContextualTyping.errors.txt @@ -0,0 +1,31 @@ +tests/cases/conformance/expressions/contextualTyping/getSetAccessorContextualTyping.ts(8,16): error TS2322: Type 'string' is not assignable to type 'number'. + + +==== tests/cases/conformance/expressions/contextualTyping/getSetAccessorContextualTyping.ts (1 errors) ==== + // In the body of a get accessor with no return type annotation, + // if a matching set accessor exists and that set accessor has a parameter type annotation, + // return expressions are contextually typed by the type given in the set accessor's parameter type annotation. + + class C { + set X(x: number) { } + get X() { + return "string"; // Error; get contextual type by set accessor parameter type annotation + ~~~~~~~~ +!!! error TS2322: Type 'string' is not assignable to type 'number'. + } + + set Y(y) { } + get Y() { + return true; + } + + set W(w) { } + get W(): boolean { + return true; + } + + set Z(z: number) { } + get Z() { + return 1; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/getSetAccessorContextualTyping.js b/tests/baselines/reference/getSetAccessorContextualTyping.js new file mode 100644 index 00000000000..d1415e1d4e7 --- /dev/null +++ b/tests/baselines/reference/getSetAccessorContextualTyping.js @@ -0,0 +1,68 @@ +//// [getSetAccessorContextualTyping.ts] +// In the body of a get accessor with no return type annotation, +// if a matching set accessor exists and that set accessor has a parameter type annotation, +// return expressions are contextually typed by the type given in the set accessor's parameter type annotation. + +class C { + set X(x: number) { } + get X() { + return "string"; // Error; get contextual type by set accessor parameter type annotation + } + + set Y(y) { } + get Y() { + return true; + } + + set W(w) { } + get W(): boolean { + return true; + } + + set Z(z: number) { } + get Z() { + return 1; + } +} + +//// [getSetAccessorContextualTyping.js] +// In the body of a get accessor with no return type annotation, +// if a matching set accessor exists and that set accessor has a parameter type annotation, +// return expressions are contextually typed by the type given in the set accessor's parameter type annotation. +var C = (function () { + function C() { + } + Object.defineProperty(C.prototype, "X", { + get: function () { + return "string"; // Error; get contextual type by set accessor parameter type annotation + }, + set: function (x) { }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, "Y", { + get: function () { + return true; + }, + set: function (y) { }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, "W", { + get: function () { + return true; + }, + set: function (w) { }, + enumerable: true, + configurable: true + }); + Object.defineProperty(C.prototype, "Z", { + get: function () { + return 1; + }, + set: function (z) { }, + enumerable: true, + configurable: true + }); + return C; +})(); diff --git a/tests/baselines/reference/objectLiteralContextualTyping.js b/tests/baselines/reference/objectLiteralContextualTyping.js index 48686042754..52a2db3d0c8 100644 --- a/tests/baselines/reference/objectLiteralContextualTyping.js +++ b/tests/baselines/reference/objectLiteralContextualTyping.js @@ -1,5 +1,8 @@ //// [objectLiteralContextualTyping.ts] -// Tests related to #1774 +// In a contextually typed object literal, each property value expression is contextually typed by +// the type of the property with a matching name in the contextual type, if any, or otherwise +// for a numerically named property, the numeric index type of the contextual type, if any, or otherwise +// the string index type of the contextual type, if any. interface Item { name: string; @@ -28,7 +31,10 @@ var b: {}; //// [objectLiteralContextualTyping.js] -// Tests related to #1774 +// In a contextually typed object literal, each property value expression is contextually typed by +// the type of the property with a matching name in the contextual type, if any, or otherwise +// for a numerically named property, the numeric index type of the contextual type, if any, or otherwise +// the string index type of the contextual type, if any. var x = foo({ name: "Sprocket" }); var x; var y = foo({ name: "Sprocket", description: "Bumpy wheel" }); diff --git a/tests/baselines/reference/objectLiteralContextualTyping.symbols b/tests/baselines/reference/objectLiteralContextualTyping.symbols index 6e8f2e5f333..23a468eac3f 100644 --- a/tests/baselines/reference/objectLiteralContextualTyping.symbols +++ b/tests/baselines/reference/objectLiteralContextualTyping.symbols @@ -1,71 +1,74 @@ === tests/cases/conformance/expressions/contextualTyping/objectLiteralContextualTyping.ts === -// Tests related to #1774 +// In a contextually typed object literal, each property value expression is contextually typed by +// the type of the property with a matching name in the contextual type, if any, or otherwise +// for a numerically named property, the numeric index type of the contextual type, if any, or otherwise +// the string index type of the contextual type, if any. interface Item { >Item : Symbol(Item, Decl(objectLiteralContextualTyping.ts, 0, 0)) name: string; ->name : Symbol(name, Decl(objectLiteralContextualTyping.ts, 2, 16)) +>name : Symbol(name, Decl(objectLiteralContextualTyping.ts, 5, 16)) description?: string; ->description : Symbol(description, Decl(objectLiteralContextualTyping.ts, 3, 17)) +>description : Symbol(description, Decl(objectLiteralContextualTyping.ts, 6, 17)) } declare function foo(item: Item): string; ->foo : Symbol(foo, Decl(objectLiteralContextualTyping.ts, 5, 1), Decl(objectLiteralContextualTyping.ts, 7, 41)) ->item : Symbol(item, Decl(objectLiteralContextualTyping.ts, 7, 21)) +>foo : Symbol(foo, Decl(objectLiteralContextualTyping.ts, 8, 1), Decl(objectLiteralContextualTyping.ts, 10, 41)) +>item : Symbol(item, Decl(objectLiteralContextualTyping.ts, 10, 21)) >Item : Symbol(Item, Decl(objectLiteralContextualTyping.ts, 0, 0)) declare function foo(item: any): number; ->foo : Symbol(foo, Decl(objectLiteralContextualTyping.ts, 5, 1), Decl(objectLiteralContextualTyping.ts, 7, 41)) ->item : Symbol(item, Decl(objectLiteralContextualTyping.ts, 8, 21)) +>foo : Symbol(foo, Decl(objectLiteralContextualTyping.ts, 8, 1), Decl(objectLiteralContextualTyping.ts, 10, 41)) +>item : Symbol(item, Decl(objectLiteralContextualTyping.ts, 11, 21)) var x = foo({ name: "Sprocket" }); ->x : Symbol(x, Decl(objectLiteralContextualTyping.ts, 10, 3), Decl(objectLiteralContextualTyping.ts, 11, 3)) ->foo : Symbol(foo, Decl(objectLiteralContextualTyping.ts, 5, 1), Decl(objectLiteralContextualTyping.ts, 7, 41)) ->name : Symbol(name, Decl(objectLiteralContextualTyping.ts, 10, 13)) +>x : Symbol(x, Decl(objectLiteralContextualTyping.ts, 13, 3), Decl(objectLiteralContextualTyping.ts, 14, 3)) +>foo : Symbol(foo, Decl(objectLiteralContextualTyping.ts, 8, 1), Decl(objectLiteralContextualTyping.ts, 10, 41)) +>name : Symbol(name, Decl(objectLiteralContextualTyping.ts, 13, 13)) var x: string; ->x : Symbol(x, Decl(objectLiteralContextualTyping.ts, 10, 3), Decl(objectLiteralContextualTyping.ts, 11, 3)) +>x : Symbol(x, Decl(objectLiteralContextualTyping.ts, 13, 3), Decl(objectLiteralContextualTyping.ts, 14, 3)) var y = foo({ name: "Sprocket", description: "Bumpy wheel" }); ->y : Symbol(y, Decl(objectLiteralContextualTyping.ts, 13, 3), Decl(objectLiteralContextualTyping.ts, 14, 3)) ->foo : Symbol(foo, Decl(objectLiteralContextualTyping.ts, 5, 1), Decl(objectLiteralContextualTyping.ts, 7, 41)) ->name : Symbol(name, Decl(objectLiteralContextualTyping.ts, 13, 13)) ->description : Symbol(description, Decl(objectLiteralContextualTyping.ts, 13, 31)) - -var y: string; ->y : Symbol(y, Decl(objectLiteralContextualTyping.ts, 13, 3), Decl(objectLiteralContextualTyping.ts, 14, 3)) - -var z = foo({ name: "Sprocket", description: false }); ->z : Symbol(z, Decl(objectLiteralContextualTyping.ts, 16, 3), Decl(objectLiteralContextualTyping.ts, 17, 3)) ->foo : Symbol(foo, Decl(objectLiteralContextualTyping.ts, 5, 1), Decl(objectLiteralContextualTyping.ts, 7, 41)) +>y : Symbol(y, Decl(objectLiteralContextualTyping.ts, 16, 3), Decl(objectLiteralContextualTyping.ts, 17, 3)) +>foo : Symbol(foo, Decl(objectLiteralContextualTyping.ts, 8, 1), Decl(objectLiteralContextualTyping.ts, 10, 41)) >name : Symbol(name, Decl(objectLiteralContextualTyping.ts, 16, 13)) >description : Symbol(description, Decl(objectLiteralContextualTyping.ts, 16, 31)) +var y: string; +>y : Symbol(y, Decl(objectLiteralContextualTyping.ts, 16, 3), Decl(objectLiteralContextualTyping.ts, 17, 3)) + +var z = foo({ name: "Sprocket", description: false }); +>z : Symbol(z, Decl(objectLiteralContextualTyping.ts, 19, 3), Decl(objectLiteralContextualTyping.ts, 20, 3)) +>foo : Symbol(foo, Decl(objectLiteralContextualTyping.ts, 8, 1), Decl(objectLiteralContextualTyping.ts, 10, 41)) +>name : Symbol(name, Decl(objectLiteralContextualTyping.ts, 19, 13)) +>description : Symbol(description, Decl(objectLiteralContextualTyping.ts, 19, 31)) + var z: number; ->z : Symbol(z, Decl(objectLiteralContextualTyping.ts, 16, 3), Decl(objectLiteralContextualTyping.ts, 17, 3)) +>z : Symbol(z, Decl(objectLiteralContextualTyping.ts, 19, 3), Decl(objectLiteralContextualTyping.ts, 20, 3)) var w = foo({ a: 10 }); ->w : Symbol(w, Decl(objectLiteralContextualTyping.ts, 19, 3), Decl(objectLiteralContextualTyping.ts, 20, 3)) ->foo : Symbol(foo, Decl(objectLiteralContextualTyping.ts, 5, 1), Decl(objectLiteralContextualTyping.ts, 7, 41)) ->a : Symbol(a, Decl(objectLiteralContextualTyping.ts, 19, 13)) +>w : Symbol(w, Decl(objectLiteralContextualTyping.ts, 22, 3), Decl(objectLiteralContextualTyping.ts, 23, 3)) +>foo : Symbol(foo, Decl(objectLiteralContextualTyping.ts, 8, 1), Decl(objectLiteralContextualTyping.ts, 10, 41)) +>a : Symbol(a, Decl(objectLiteralContextualTyping.ts, 22, 13)) var w: number; ->w : Symbol(w, Decl(objectLiteralContextualTyping.ts, 19, 3), Decl(objectLiteralContextualTyping.ts, 20, 3)) +>w : Symbol(w, Decl(objectLiteralContextualTyping.ts, 22, 3), Decl(objectLiteralContextualTyping.ts, 23, 3)) declare function bar(param: { x?: T }): T; ->bar : Symbol(bar, Decl(objectLiteralContextualTyping.ts, 20, 14)) ->T : Symbol(T, Decl(objectLiteralContextualTyping.ts, 22, 21)) ->param : Symbol(param, Decl(objectLiteralContextualTyping.ts, 22, 24)) ->x : Symbol(x, Decl(objectLiteralContextualTyping.ts, 22, 32)) ->T : Symbol(T, Decl(objectLiteralContextualTyping.ts, 22, 21)) ->T : Symbol(T, Decl(objectLiteralContextualTyping.ts, 22, 21)) +>bar : Symbol(bar, Decl(objectLiteralContextualTyping.ts, 23, 14)) +>T : Symbol(T, Decl(objectLiteralContextualTyping.ts, 25, 21)) +>param : Symbol(param, Decl(objectLiteralContextualTyping.ts, 25, 24)) +>x : Symbol(x, Decl(objectLiteralContextualTyping.ts, 25, 32)) +>T : Symbol(T, Decl(objectLiteralContextualTyping.ts, 25, 21)) +>T : Symbol(T, Decl(objectLiteralContextualTyping.ts, 25, 21)) var b = bar({}); ->b : Symbol(b, Decl(objectLiteralContextualTyping.ts, 24, 3), Decl(objectLiteralContextualTyping.ts, 25, 3)) ->bar : Symbol(bar, Decl(objectLiteralContextualTyping.ts, 20, 14)) +>b : Symbol(b, Decl(objectLiteralContextualTyping.ts, 27, 3), Decl(objectLiteralContextualTyping.ts, 28, 3)) +>bar : Symbol(bar, Decl(objectLiteralContextualTyping.ts, 23, 14)) var b: {}; ->b : Symbol(b, Decl(objectLiteralContextualTyping.ts, 24, 3), Decl(objectLiteralContextualTyping.ts, 25, 3)) +>b : Symbol(b, Decl(objectLiteralContextualTyping.ts, 27, 3), Decl(objectLiteralContextualTyping.ts, 28, 3)) diff --git a/tests/baselines/reference/objectLiteralContextualTyping.types b/tests/baselines/reference/objectLiteralContextualTyping.types index 7668b01d32c..8100b7a5446 100644 --- a/tests/baselines/reference/objectLiteralContextualTyping.types +++ b/tests/baselines/reference/objectLiteralContextualTyping.types @@ -1,5 +1,8 @@ === tests/cases/conformance/expressions/contextualTyping/objectLiteralContextualTyping.ts === -// Tests related to #1774 +// In a contextually typed object literal, each property value expression is contextually typed by +// the type of the property with a matching name in the contextual type, if any, or otherwise +// for a numerically named property, the numeric index type of the contextual type, if any, or otherwise +// the string index type of the contextual type, if any. interface Item { >Item : Item diff --git a/tests/cases/conformance/expressions/contextualTyping/argumentExpressionContextualTyping.ts b/tests/cases/conformance/expressions/contextualTyping/argumentExpressionContextualTyping.ts new file mode 100644 index 00000000000..a6ee88c1076 --- /dev/null +++ b/tests/cases/conformance/expressions/contextualTyping/argumentExpressionContextualTyping.ts @@ -0,0 +1,18 @@ +// In a typed function call, argument expressions are contextually typed by their corresponding parameter types. +function foo({x: [a, b], y: {c, d, e}}) { } +function bar({x: [a, b = 10], y: {c, d, e = { f:1 }}}) { } +function baz(x: [string, number, boolean]) { } + +var o = { x: ["string", 1], y: { c: true, d: "world", e: 3 } }; +var o1: { x: [string, number], y: { c: boolean, d: string, e: number } } = { x: ["string", 1], y: { c: true, d: "world", e: 3 } }; +foo(o1); // Not error since x has contextual type of tuple namely [string, number] +foo({ x: ["string", 1], y: { c: true, d: "world", e: 3 } }); // Not error + +var array = ["string", 1, true]; +var tuple: [string, number, boolean] = ["string", 1, true]; +baz(tuple); +baz(["string", 1, true]); + +baz(array); // Error +baz(["string", 1, true, ...array]); // Error +foo(o); // Error because x has an array type namely (string|number)[] \ No newline at end of file diff --git a/tests/cases/conformance/expressions/contextualTyping/arrayLiteralExpressionContextualTyping.ts b/tests/cases/conformance/expressions/contextualTyping/arrayLiteralExpressionContextualTyping.ts new file mode 100644 index 00000000000..17bca640a29 --- /dev/null +++ b/tests/cases/conformance/expressions/contextualTyping/arrayLiteralExpressionContextualTyping.ts @@ -0,0 +1,14 @@ +// In a contextually typed array literal expression containing no spread elements, an element expression at index N is contextually typed by +// the type of the property with the numeric name N in the contextual type, if any, or otherwise +// the numeric index type of the contextual type, if any. +var array = [1, 2, 3]; +var array1 = [true, 2, 3]; // Contextual type by the numeric index type of the contextual type +var tup: [number, number, number] = [1, 2, 3, 4]; +var tup1: [number|string, number|string, number|string] = [1, 2, 3, "string"]; +var tup2: [number, number, number] = [1, 2, 3, "string"]; // Error + +// In a contextually typed array literal expression containing one or more spread elements, +// an element expression at index N is contextually typed by the numeric index type of the contextual type, if any. +var spr = [1, 2, 3, ...array]; +var spr1 = [1, 2, 3, ...tup]; +var spr2:[number, number, number] = [1, 2, 3, ...tup]; // Error diff --git a/tests/cases/conformance/expressions/contextualTyping/getSetAccessorContextualTyping.ts b/tests/cases/conformance/expressions/contextualTyping/getSetAccessorContextualTyping.ts new file mode 100644 index 00000000000..dcea1cfe2ba --- /dev/null +++ b/tests/cases/conformance/expressions/contextualTyping/getSetAccessorContextualTyping.ts @@ -0,0 +1,26 @@ +// @target: es5 +// In the body of a get accessor with no return type annotation, +// if a matching set accessor exists and that set accessor has a parameter type annotation, +// return expressions are contextually typed by the type given in the set accessor's parameter type annotation. + +class C { + set X(x: number) { } + get X() { + return "string"; // Error; get contextual type by set accessor parameter type annotation + } + + set Y(y) { } + get Y() { + return true; + } + + set W(w) { } + get W(): boolean { + return true; + } + + set Z(z: number) { } + get Z() { + return 1; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/expressions/contextualTyping/objectLiteralContextualTyping.ts b/tests/cases/conformance/expressions/contextualTyping/objectLiteralContextualTyping.ts index cb2fe8ee8d4..97c399211be 100644 --- a/tests/cases/conformance/expressions/contextualTyping/objectLiteralContextualTyping.ts +++ b/tests/cases/conformance/expressions/contextualTyping/objectLiteralContextualTyping.ts @@ -1,4 +1,7 @@ -// Tests related to #1774 +// In a contextually typed object literal, each property value expression is contextually typed by +// the type of the property with a matching name in the contextual type, if any, or otherwise +// for a numerically named property, the numeric index type of the contextual type, if any, or otherwise +// the string index type of the contextual type, if any. interface Item { name: string; From ac8ae27139462c90a75ba89624589e55bb372120 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 16 Apr 2015 20:09:03 -0700 Subject: [PATCH 043/194] Address code review --- .../reference/typeGuardsOnClassProperty.errors.txt | 8 ++++---- tests/baselines/reference/typeGuardsOnClassProperty.js | 6 +++--- .../expressions/typeGuards/typeGuardsOnClassProperty.ts | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/baselines/reference/typeGuardsOnClassProperty.errors.txt b/tests/baselines/reference/typeGuardsOnClassProperty.errors.txt index 7d56c9a2049..4e6a8b83ae3 100644 --- a/tests/baselines/reference/typeGuardsOnClassProperty.errors.txt +++ b/tests/baselines/reference/typeGuardsOnClassProperty.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/expressions/typeGuards/typeGuardsOnClassProperty.ts(14,71): error TS2339: Property 'join' does not exist on type 'string | string[]'. +tests/cases/conformance/expressions/typeGuards/typeGuardsOnClassProperty.ts(14,70): error TS2339: Property 'join' does not exist on type 'string | string[]'. tests/cases/conformance/expressions/typeGuards/typeGuardsOnClassProperty.ts(26,44): error TS2339: Property 'toLowerCase' does not exist on type 'string | number'. @@ -7,7 +7,7 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsOnClassProperty.ts(26,4 // have no effect on members of objects such as properties. // Note that the class's property must be copied to a local variable for - // the type guard to have an affect + // the type guard to have an effect class D { data: string | string[]; getData() { @@ -16,8 +16,8 @@ tests/cases/conformance/expressions/typeGuards/typeGuardsOnClassProperty.ts(26,4 } getData1() { - return typeof this.data === "string" ? this.data : this. data.join(" "); - ~~~~ + return typeof this.data === "string" ? this.data : this.data.join(" "); + ~~~~ !!! error TS2339: Property 'join' does not exist on type 'string | string[]'. } } diff --git a/tests/baselines/reference/typeGuardsOnClassProperty.js b/tests/baselines/reference/typeGuardsOnClassProperty.js index 5edecd36b86..de4fcb50638 100644 --- a/tests/baselines/reference/typeGuardsOnClassProperty.js +++ b/tests/baselines/reference/typeGuardsOnClassProperty.js @@ -3,7 +3,7 @@ // have no effect on members of objects such as properties. // Note that the class's property must be copied to a local variable for -// the type guard to have an affect +// the type guard to have an effect class D { data: string | string[]; getData() { @@ -12,7 +12,7 @@ class D { } getData1() { - return typeof this.data === "string" ? this.data : this. data.join(" "); + return typeof this.data === "string" ? this.data : this.data.join(" "); } } @@ -32,7 +32,7 @@ if (typeof prop1 === "string" && prop1.toLocaleLowerCase()) { } // Note that type guards affect types of variables and parameters only and // have no effect on members of objects such as properties. // Note that the class's property must be copied to a local variable for -// the type guard to have an affect +// the type guard to have an effect var D = (function () { function D() { } diff --git a/tests/cases/conformance/expressions/typeGuards/typeGuardsOnClassProperty.ts b/tests/cases/conformance/expressions/typeGuards/typeGuardsOnClassProperty.ts index 20a0bf8242a..2c26b10c6a1 100644 --- a/tests/cases/conformance/expressions/typeGuards/typeGuardsOnClassProperty.ts +++ b/tests/cases/conformance/expressions/typeGuards/typeGuardsOnClassProperty.ts @@ -2,7 +2,7 @@ // have no effect on members of objects such as properties. // Note that the class's property must be copied to a local variable for -// the type guard to have an affect +// the type guard to have an effect class D { data: string | string[]; getData() { @@ -11,7 +11,7 @@ class D { } getData1() { - return typeof this.data === "string" ? this.data : this. data.join(" "); + return typeof this.data === "string" ? this.data : this.data.join(" "); } } From d5ee6d25b0170fc1ba239235c8ff62133de7c16c Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 16 Apr 2015 23:25:52 -0700 Subject: [PATCH 044/194] update baselines from merging master --- .../reference/ambientEnumDeclaration2.types | 12 ++-- tests/baselines/reference/constEnum1.types | 32 ++++----- .../reference/constEnumPropertyAccess1.types | 66 +++++++++---------- 3 files changed, 55 insertions(+), 55 deletions(-) diff --git a/tests/baselines/reference/ambientEnumDeclaration2.types b/tests/baselines/reference/ambientEnumDeclaration2.types index 2c87066b7fa..af66e4ac0c5 100644 --- a/tests/baselines/reference/ambientEnumDeclaration2.types +++ b/tests/baselines/reference/ambientEnumDeclaration2.types @@ -3,21 +3,21 @@ // that omit a value are considered computed members (as opposed to having auto- incremented values assigned). declare enum E { ->E : E, Symbol(E, Decl(ambientEnumDeclaration2.ts, 0, 0)) +>E : E a, // E.a ->a : E, Symbol(E.a, Decl(ambientEnumDeclaration2.ts, 3, 16)) +>a : E b, // E.b ->b : E, Symbol(E.b, Decl(ambientEnumDeclaration2.ts, 4, 6)) +>b : E } declare const enum E1 { ->E1 : E1, Symbol(E1, Decl(ambientEnumDeclaration2.ts, 6, 1)) +>E1 : E1 a, // E.a = 0 ->a : E1, Symbol(E1.a, Decl(ambientEnumDeclaration2.ts, 8, 23)) +>a : E1 b, // E.b = 1 ->b : E1, Symbol(E1.b, Decl(ambientEnumDeclaration2.ts, 9, 6)) +>b : E1 } diff --git a/tests/baselines/reference/constEnum1.types b/tests/baselines/reference/constEnum1.types index ef0e64d4377..9ae95992847 100644 --- a/tests/baselines/reference/constEnum1.types +++ b/tests/baselines/reference/constEnum1.types @@ -5,50 +5,50 @@ // it is an error for a member declaration to specify an expression that isn't classified as a constant enum expression. const enum E { ->E : E, Symbol(E, Decl(constEnum1.ts, 0, 0)) +>E : E a = 10, ->a : E, Symbol(E.a, Decl(constEnum1.ts, 5, 14)) +>a : E >10 : number b = a, ->b : E, Symbol(E.b, Decl(constEnum1.ts, 6, 11)) ->a : E, Symbol(E.a, Decl(constEnum1.ts, 5, 14)) +>b : E +>a : E c = (a+1), ->c : E, Symbol(E.c, Decl(constEnum1.ts, 7, 10)) +>c : E >(a+1) : number >a+1 : number ->a : E, Symbol(E.a, Decl(constEnum1.ts, 5, 14)) +>a : E >1 : number e, ->e : E, Symbol(E.e, Decl(constEnum1.ts, 8, 14)) +>e : E d = ~e, ->d : E, Symbol(E.d, Decl(constEnum1.ts, 9, 6)) +>d : E >~e : number ->e : E, Symbol(E.e, Decl(constEnum1.ts, 8, 14)) +>e : E f = a << 2 >> 1, ->f : E, Symbol(E.f, Decl(constEnum1.ts, 10, 11)) +>f : E >a << 2 >> 1 : number >a << 2 : number ->a : E, Symbol(E.a, Decl(constEnum1.ts, 5, 14)) +>a : E >2 : number >1 : number g = a << 2 >>> 1, ->g : E, Symbol(E.g, Decl(constEnum1.ts, 11, 20)) +>g : E >a << 2 >>> 1 : number >a << 2 : number ->a : E, Symbol(E.a, Decl(constEnum1.ts, 5, 14)) +>a : E >2 : number >1 : number h = a | b ->h : E, Symbol(E.h, Decl(constEnum1.ts, 12, 21)) +>h : E >a | b : number ->a : E, Symbol(E.a, Decl(constEnum1.ts, 5, 14)) ->b : E, Symbol(E.b, Decl(constEnum1.ts, 6, 11)) +>a : E +>b : E } diff --git a/tests/baselines/reference/constEnumPropertyAccess1.types b/tests/baselines/reference/constEnumPropertyAccess1.types index bf0c727f1c0..5ed2b932bd0 100644 --- a/tests/baselines/reference/constEnumPropertyAccess1.types +++ b/tests/baselines/reference/constEnumPropertyAccess1.types @@ -5,34 +5,34 @@ // than a property access that selects one of the enum's members const enum G { ->G : G, Symbol(G, Decl(constEnumPropertyAccess1.ts, 0, 0)) +>G : G A = 1, ->A : G, Symbol(G.A, Decl(constEnumPropertyAccess1.ts, 5, 14)) +>A : G >1 : number B = 2, ->B : G, Symbol(G.B, Decl(constEnumPropertyAccess1.ts, 6, 10)) +>B : G >2 : number C = A + B, ->C : G, Symbol(G.C, Decl(constEnumPropertyAccess1.ts, 7, 10)) +>C : G >A + B : number ->A : G, Symbol(G.A, Decl(constEnumPropertyAccess1.ts, 5, 14)) ->B : G, Symbol(G.B, Decl(constEnumPropertyAccess1.ts, 6, 10)) +>A : G +>B : G D = A * 2 ->D : G, Symbol(G.D, Decl(constEnumPropertyAccess1.ts, 8, 14)) +>D : G >A * 2 : number ->A : G, Symbol(G.A, Decl(constEnumPropertyAccess1.ts, 5, 14)) +>A : G >2 : number } var o: { ->o : { [idx: number]: boolean; }, Symbol(o, Decl(constEnumPropertyAccess1.ts, 12, 3)) +>o : { [idx: number]: boolean; } [idx: number]: boolean ->idx : number, Symbol(idx, Decl(constEnumPropertyAccess1.ts, 13, 5)) +>idx : number } = { >{ 1: true } : { [x: number]: boolean; 1: boolean; } @@ -43,46 +43,46 @@ var o: { }; var a = G.A; ->a : G, Symbol(a, Decl(constEnumPropertyAccess1.ts, 18, 3)) ->G.A : G, Symbol(G.A, Decl(constEnumPropertyAccess1.ts, 5, 14)) ->G : typeof G, Symbol(G, Decl(constEnumPropertyAccess1.ts, 0, 0)) ->A : G, Symbol(G.A, Decl(constEnumPropertyAccess1.ts, 5, 14)) +>a : G +>G.A : G +>G : typeof G +>A : G var a1 = G["A"]; ->a1 : G, Symbol(a1, Decl(constEnumPropertyAccess1.ts, 19, 3)) +>a1 : G >G["A"] : G ->G : typeof G, Symbol(G, Decl(constEnumPropertyAccess1.ts, 0, 0)) ->"A" : string, Symbol(G.A, Decl(constEnumPropertyAccess1.ts, 5, 14)) +>G : typeof G +>"A" : string var g = o[G.A]; ->g : boolean, Symbol(g, Decl(constEnumPropertyAccess1.ts, 20, 3)) +>g : boolean >o[G.A] : boolean ->o : { [idx: number]: boolean; }, Symbol(o, Decl(constEnumPropertyAccess1.ts, 12, 3)) ->G.A : G, Symbol(G.A, Decl(constEnumPropertyAccess1.ts, 5, 14)) ->G : typeof G, Symbol(G, Decl(constEnumPropertyAccess1.ts, 0, 0)) ->A : G, Symbol(G.A, Decl(constEnumPropertyAccess1.ts, 5, 14)) +>o : { [idx: number]: boolean; } +>G.A : G +>G : typeof G +>A : G class C { ->C : C, Symbol(C, Decl(constEnumPropertyAccess1.ts, 20, 15)) +>C : C [G.A]() { } ->G.A : G, Symbol(G.A, Decl(constEnumPropertyAccess1.ts, 5, 14)) ->G : typeof G, Symbol(G, Decl(constEnumPropertyAccess1.ts, 0, 0)) ->A : G, Symbol(G.A, Decl(constEnumPropertyAccess1.ts, 5, 14)) +>G.A : G +>G : typeof G +>A : G get [G.B]() { ->G.B : G, Symbol(G.B, Decl(constEnumPropertyAccess1.ts, 6, 10)) ->G : typeof G, Symbol(G, Decl(constEnumPropertyAccess1.ts, 0, 0)) ->B : G, Symbol(G.B, Decl(constEnumPropertyAccess1.ts, 6, 10)) +>G.B : G +>G : typeof G +>B : G return true; >true : boolean } set [G.B](x: number) { } ->G.B : G, Symbol(G.B, Decl(constEnumPropertyAccess1.ts, 6, 10)) ->G : typeof G, Symbol(G, Decl(constEnumPropertyAccess1.ts, 0, 0)) ->B : G, Symbol(G.B, Decl(constEnumPropertyAccess1.ts, 6, 10)) ->x : number, Symbol(x, Decl(constEnumPropertyAccess1.ts, 27, 14)) +>G.B : G +>G : typeof G +>B : G +>x : number } From 21d4602963e50fdd60462c051360ecf1355d811b Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 16 Apr 2015 23:25:52 -0700 Subject: [PATCH 045/194] update baselines from merging master --- .../reference/ambientEnumDeclaration2.symbols | 23 ++++++ .../reference/ambientEnumDeclaration2.types | 12 +-- tests/baselines/reference/constEnum1.symbols | 40 ++++++++++ tests/baselines/reference/constEnum1.types | 32 ++++---- .../constEnumPropertyAccess1.symbols | 76 +++++++++++++++++++ .../reference/constEnumPropertyAccess1.types | 66 ++++++++-------- 6 files changed, 194 insertions(+), 55 deletions(-) create mode 100644 tests/baselines/reference/ambientEnumDeclaration2.symbols create mode 100644 tests/baselines/reference/constEnum1.symbols create mode 100644 tests/baselines/reference/constEnumPropertyAccess1.symbols diff --git a/tests/baselines/reference/ambientEnumDeclaration2.symbols b/tests/baselines/reference/ambientEnumDeclaration2.symbols new file mode 100644 index 00000000000..7c4975f5878 --- /dev/null +++ b/tests/baselines/reference/ambientEnumDeclaration2.symbols @@ -0,0 +1,23 @@ +=== tests/cases/conformance/ambient/ambientEnumDeclaration2.ts === +// In ambient enum declarations that specify no const modifier, enum member declarations +// that omit a value are considered computed members (as opposed to having auto- incremented values assigned). + +declare enum E { +>E : Symbol(E, Decl(ambientEnumDeclaration2.ts, 0, 0)) + + a, // E.a +>a : Symbol(E.a, Decl(ambientEnumDeclaration2.ts, 3, 16)) + + b, // E.b +>b : Symbol(E.b, Decl(ambientEnumDeclaration2.ts, 4, 6)) +} + +declare const enum E1 { +>E1 : Symbol(E1, Decl(ambientEnumDeclaration2.ts, 6, 1)) + + a, // E.a = 0 +>a : Symbol(E1.a, Decl(ambientEnumDeclaration2.ts, 8, 23)) + + b, // E.b = 1 +>b : Symbol(E1.b, Decl(ambientEnumDeclaration2.ts, 9, 6)) +} diff --git a/tests/baselines/reference/ambientEnumDeclaration2.types b/tests/baselines/reference/ambientEnumDeclaration2.types index 2c87066b7fa..af66e4ac0c5 100644 --- a/tests/baselines/reference/ambientEnumDeclaration2.types +++ b/tests/baselines/reference/ambientEnumDeclaration2.types @@ -3,21 +3,21 @@ // that omit a value are considered computed members (as opposed to having auto- incremented values assigned). declare enum E { ->E : E, Symbol(E, Decl(ambientEnumDeclaration2.ts, 0, 0)) +>E : E a, // E.a ->a : E, Symbol(E.a, Decl(ambientEnumDeclaration2.ts, 3, 16)) +>a : E b, // E.b ->b : E, Symbol(E.b, Decl(ambientEnumDeclaration2.ts, 4, 6)) +>b : E } declare const enum E1 { ->E1 : E1, Symbol(E1, Decl(ambientEnumDeclaration2.ts, 6, 1)) +>E1 : E1 a, // E.a = 0 ->a : E1, Symbol(E1.a, Decl(ambientEnumDeclaration2.ts, 8, 23)) +>a : E1 b, // E.b = 1 ->b : E1, Symbol(E1.b, Decl(ambientEnumDeclaration2.ts, 9, 6)) +>b : E1 } diff --git a/tests/baselines/reference/constEnum1.symbols b/tests/baselines/reference/constEnum1.symbols new file mode 100644 index 00000000000..e94ed0a4722 --- /dev/null +++ b/tests/baselines/reference/constEnum1.symbols @@ -0,0 +1,40 @@ +=== tests/cases/conformance/constEnums/constEnum1.ts === + +// An enum declaration that specifies a const modifier is a constant enum declaration. +// In a constant enum declaration, all members must have constant values and +// it is an error for a member declaration to specify an expression that isn't classified as a constant enum expression. + +const enum E { +>E : Symbol(E, Decl(constEnum1.ts, 0, 0)) + + a = 10, +>a : Symbol(E.a, Decl(constEnum1.ts, 5, 14)) + + b = a, +>b : Symbol(E.b, Decl(constEnum1.ts, 6, 11)) +>a : Symbol(E.a, Decl(constEnum1.ts, 5, 14)) + + c = (a+1), +>c : Symbol(E.c, Decl(constEnum1.ts, 7, 10)) +>a : Symbol(E.a, Decl(constEnum1.ts, 5, 14)) + + e, +>e : Symbol(E.e, Decl(constEnum1.ts, 8, 14)) + + d = ~e, +>d : Symbol(E.d, Decl(constEnum1.ts, 9, 6)) +>e : Symbol(E.e, Decl(constEnum1.ts, 8, 14)) + + f = a << 2 >> 1, +>f : Symbol(E.f, Decl(constEnum1.ts, 10, 11)) +>a : Symbol(E.a, Decl(constEnum1.ts, 5, 14)) + + g = a << 2 >>> 1, +>g : Symbol(E.g, Decl(constEnum1.ts, 11, 20)) +>a : Symbol(E.a, Decl(constEnum1.ts, 5, 14)) + + h = a | b +>h : Symbol(E.h, Decl(constEnum1.ts, 12, 21)) +>a : Symbol(E.a, Decl(constEnum1.ts, 5, 14)) +>b : Symbol(E.b, Decl(constEnum1.ts, 6, 11)) +} diff --git a/tests/baselines/reference/constEnum1.types b/tests/baselines/reference/constEnum1.types index ef0e64d4377..9ae95992847 100644 --- a/tests/baselines/reference/constEnum1.types +++ b/tests/baselines/reference/constEnum1.types @@ -5,50 +5,50 @@ // it is an error for a member declaration to specify an expression that isn't classified as a constant enum expression. const enum E { ->E : E, Symbol(E, Decl(constEnum1.ts, 0, 0)) +>E : E a = 10, ->a : E, Symbol(E.a, Decl(constEnum1.ts, 5, 14)) +>a : E >10 : number b = a, ->b : E, Symbol(E.b, Decl(constEnum1.ts, 6, 11)) ->a : E, Symbol(E.a, Decl(constEnum1.ts, 5, 14)) +>b : E +>a : E c = (a+1), ->c : E, Symbol(E.c, Decl(constEnum1.ts, 7, 10)) +>c : E >(a+1) : number >a+1 : number ->a : E, Symbol(E.a, Decl(constEnum1.ts, 5, 14)) +>a : E >1 : number e, ->e : E, Symbol(E.e, Decl(constEnum1.ts, 8, 14)) +>e : E d = ~e, ->d : E, Symbol(E.d, Decl(constEnum1.ts, 9, 6)) +>d : E >~e : number ->e : E, Symbol(E.e, Decl(constEnum1.ts, 8, 14)) +>e : E f = a << 2 >> 1, ->f : E, Symbol(E.f, Decl(constEnum1.ts, 10, 11)) +>f : E >a << 2 >> 1 : number >a << 2 : number ->a : E, Symbol(E.a, Decl(constEnum1.ts, 5, 14)) +>a : E >2 : number >1 : number g = a << 2 >>> 1, ->g : E, Symbol(E.g, Decl(constEnum1.ts, 11, 20)) +>g : E >a << 2 >>> 1 : number >a << 2 : number ->a : E, Symbol(E.a, Decl(constEnum1.ts, 5, 14)) +>a : E >2 : number >1 : number h = a | b ->h : E, Symbol(E.h, Decl(constEnum1.ts, 12, 21)) +>h : E >a | b : number ->a : E, Symbol(E.a, Decl(constEnum1.ts, 5, 14)) ->b : E, Symbol(E.b, Decl(constEnum1.ts, 6, 11)) +>a : E +>b : E } diff --git a/tests/baselines/reference/constEnumPropertyAccess1.symbols b/tests/baselines/reference/constEnumPropertyAccess1.symbols new file mode 100644 index 00000000000..e5f2853f157 --- /dev/null +++ b/tests/baselines/reference/constEnumPropertyAccess1.symbols @@ -0,0 +1,76 @@ +=== tests/cases/conformance/constEnums/constEnumPropertyAccess1.ts === + +// constant enum declarations are completely erased in the emitted JavaScript code. +// it is an error to reference a constant enum object in any other context +// than a property access that selects one of the enum's members + +const enum G { +>G : Symbol(G, Decl(constEnumPropertyAccess1.ts, 0, 0)) + + A = 1, +>A : Symbol(G.A, Decl(constEnumPropertyAccess1.ts, 5, 14)) + + B = 2, +>B : Symbol(G.B, Decl(constEnumPropertyAccess1.ts, 6, 10)) + + C = A + B, +>C : Symbol(G.C, Decl(constEnumPropertyAccess1.ts, 7, 10)) +>A : Symbol(G.A, Decl(constEnumPropertyAccess1.ts, 5, 14)) +>B : Symbol(G.B, Decl(constEnumPropertyAccess1.ts, 6, 10)) + + D = A * 2 +>D : Symbol(G.D, Decl(constEnumPropertyAccess1.ts, 8, 14)) +>A : Symbol(G.A, Decl(constEnumPropertyAccess1.ts, 5, 14)) +} + +var o: { +>o : Symbol(o, Decl(constEnumPropertyAccess1.ts, 12, 3)) + + [idx: number]: boolean +>idx : Symbol(idx, Decl(constEnumPropertyAccess1.ts, 13, 5)) + +} = { + 1: true + }; + +var a = G.A; +>a : Symbol(a, Decl(constEnumPropertyAccess1.ts, 18, 3)) +>G.A : Symbol(G.A, Decl(constEnumPropertyAccess1.ts, 5, 14)) +>G : Symbol(G, Decl(constEnumPropertyAccess1.ts, 0, 0)) +>A : Symbol(G.A, Decl(constEnumPropertyAccess1.ts, 5, 14)) + +var a1 = G["A"]; +>a1 : Symbol(a1, Decl(constEnumPropertyAccess1.ts, 19, 3)) +>G : Symbol(G, Decl(constEnumPropertyAccess1.ts, 0, 0)) +>"A" : Symbol(G.A, Decl(constEnumPropertyAccess1.ts, 5, 14)) + +var g = o[G.A]; +>g : Symbol(g, Decl(constEnumPropertyAccess1.ts, 20, 3)) +>o : Symbol(o, Decl(constEnumPropertyAccess1.ts, 12, 3)) +>G.A : Symbol(G.A, Decl(constEnumPropertyAccess1.ts, 5, 14)) +>G : Symbol(G, Decl(constEnumPropertyAccess1.ts, 0, 0)) +>A : Symbol(G.A, Decl(constEnumPropertyAccess1.ts, 5, 14)) + +class C { +>C : Symbol(C, Decl(constEnumPropertyAccess1.ts, 20, 15)) + + [G.A]() { } +>G.A : Symbol(G.A, Decl(constEnumPropertyAccess1.ts, 5, 14)) +>G : Symbol(G, Decl(constEnumPropertyAccess1.ts, 0, 0)) +>A : Symbol(G.A, Decl(constEnumPropertyAccess1.ts, 5, 14)) + + get [G.B]() { +>G.B : Symbol(G.B, Decl(constEnumPropertyAccess1.ts, 6, 10)) +>G : Symbol(G, Decl(constEnumPropertyAccess1.ts, 0, 0)) +>B : Symbol(G.B, Decl(constEnumPropertyAccess1.ts, 6, 10)) + + return true; + } + set [G.B](x: number) { } +>G.B : Symbol(G.B, Decl(constEnumPropertyAccess1.ts, 6, 10)) +>G : Symbol(G, Decl(constEnumPropertyAccess1.ts, 0, 0)) +>B : Symbol(G.B, Decl(constEnumPropertyAccess1.ts, 6, 10)) +>x : Symbol(x, Decl(constEnumPropertyAccess1.ts, 27, 14)) +} + + diff --git a/tests/baselines/reference/constEnumPropertyAccess1.types b/tests/baselines/reference/constEnumPropertyAccess1.types index bf0c727f1c0..5ed2b932bd0 100644 --- a/tests/baselines/reference/constEnumPropertyAccess1.types +++ b/tests/baselines/reference/constEnumPropertyAccess1.types @@ -5,34 +5,34 @@ // than a property access that selects one of the enum's members const enum G { ->G : G, Symbol(G, Decl(constEnumPropertyAccess1.ts, 0, 0)) +>G : G A = 1, ->A : G, Symbol(G.A, Decl(constEnumPropertyAccess1.ts, 5, 14)) +>A : G >1 : number B = 2, ->B : G, Symbol(G.B, Decl(constEnumPropertyAccess1.ts, 6, 10)) +>B : G >2 : number C = A + B, ->C : G, Symbol(G.C, Decl(constEnumPropertyAccess1.ts, 7, 10)) +>C : G >A + B : number ->A : G, Symbol(G.A, Decl(constEnumPropertyAccess1.ts, 5, 14)) ->B : G, Symbol(G.B, Decl(constEnumPropertyAccess1.ts, 6, 10)) +>A : G +>B : G D = A * 2 ->D : G, Symbol(G.D, Decl(constEnumPropertyAccess1.ts, 8, 14)) +>D : G >A * 2 : number ->A : G, Symbol(G.A, Decl(constEnumPropertyAccess1.ts, 5, 14)) +>A : G >2 : number } var o: { ->o : { [idx: number]: boolean; }, Symbol(o, Decl(constEnumPropertyAccess1.ts, 12, 3)) +>o : { [idx: number]: boolean; } [idx: number]: boolean ->idx : number, Symbol(idx, Decl(constEnumPropertyAccess1.ts, 13, 5)) +>idx : number } = { >{ 1: true } : { [x: number]: boolean; 1: boolean; } @@ -43,46 +43,46 @@ var o: { }; var a = G.A; ->a : G, Symbol(a, Decl(constEnumPropertyAccess1.ts, 18, 3)) ->G.A : G, Symbol(G.A, Decl(constEnumPropertyAccess1.ts, 5, 14)) ->G : typeof G, Symbol(G, Decl(constEnumPropertyAccess1.ts, 0, 0)) ->A : G, Symbol(G.A, Decl(constEnumPropertyAccess1.ts, 5, 14)) +>a : G +>G.A : G +>G : typeof G +>A : G var a1 = G["A"]; ->a1 : G, Symbol(a1, Decl(constEnumPropertyAccess1.ts, 19, 3)) +>a1 : G >G["A"] : G ->G : typeof G, Symbol(G, Decl(constEnumPropertyAccess1.ts, 0, 0)) ->"A" : string, Symbol(G.A, Decl(constEnumPropertyAccess1.ts, 5, 14)) +>G : typeof G +>"A" : string var g = o[G.A]; ->g : boolean, Symbol(g, Decl(constEnumPropertyAccess1.ts, 20, 3)) +>g : boolean >o[G.A] : boolean ->o : { [idx: number]: boolean; }, Symbol(o, Decl(constEnumPropertyAccess1.ts, 12, 3)) ->G.A : G, Symbol(G.A, Decl(constEnumPropertyAccess1.ts, 5, 14)) ->G : typeof G, Symbol(G, Decl(constEnumPropertyAccess1.ts, 0, 0)) ->A : G, Symbol(G.A, Decl(constEnumPropertyAccess1.ts, 5, 14)) +>o : { [idx: number]: boolean; } +>G.A : G +>G : typeof G +>A : G class C { ->C : C, Symbol(C, Decl(constEnumPropertyAccess1.ts, 20, 15)) +>C : C [G.A]() { } ->G.A : G, Symbol(G.A, Decl(constEnumPropertyAccess1.ts, 5, 14)) ->G : typeof G, Symbol(G, Decl(constEnumPropertyAccess1.ts, 0, 0)) ->A : G, Symbol(G.A, Decl(constEnumPropertyAccess1.ts, 5, 14)) +>G.A : G +>G : typeof G +>A : G get [G.B]() { ->G.B : G, Symbol(G.B, Decl(constEnumPropertyAccess1.ts, 6, 10)) ->G : typeof G, Symbol(G, Decl(constEnumPropertyAccess1.ts, 0, 0)) ->B : G, Symbol(G.B, Decl(constEnumPropertyAccess1.ts, 6, 10)) +>G.B : G +>G : typeof G +>B : G return true; >true : boolean } set [G.B](x: number) { } ->G.B : G, Symbol(G.B, Decl(constEnumPropertyAccess1.ts, 6, 10)) ->G : typeof G, Symbol(G, Decl(constEnumPropertyAccess1.ts, 0, 0)) ->B : G, Symbol(G.B, Decl(constEnumPropertyAccess1.ts, 6, 10)) ->x : number, Symbol(x, Decl(constEnumPropertyAccess1.ts, 27, 14)) +>G.B : G +>G : typeof G +>B : G +>x : number } From cc385530d1b466c92bf642416610af2934ffcd9c Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 20 Apr 2015 10:47:17 -0700 Subject: [PATCH 046/194] rename local variable --- src/compiler/emitter.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 941bc973837..e9d0242593f 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2009,12 +2009,12 @@ var __param = this.__param || function(index, decorator) { return function (targ emitDestructuring(node, node.parent.kind === SyntaxKind.ExpressionStatement); } else { - const emitPublishOfExportedValue = + const exportChanged = node.operatorToken.kind <= SyntaxKind.LastAssignment && node.operatorToken.kind <= SyntaxKind.LastAssignment && isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.left); - if (emitPublishOfExportedValue) { + if (exportChanged) { write(`${exportFunctionForFile}("`); emitNodeWithoutSourceMap(node.left); write(`", `); @@ -2025,7 +2025,7 @@ var __param = this.__param || function(index, decorator) { return function (targ let indentedAfterOperator = indentIfOnDifferentLines(node, node.operatorToken, node.right, " "); emit(node.right); decreaseIndentIf(indentedBeforeOperator, indentedAfterOperator); - if (emitPublishOfExportedValue) { + if (exportChanged) { write(")"); } } From 6e5082658dd258cb741e1485e6ff4eccff2ed9a5 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 20 Apr 2015 14:17:38 -0700 Subject: [PATCH 047/194] skip 'import ...' nodes when creating variable statement for imports --- src/compiler/emitter.ts | 6 +- tests/baselines/reference/systemModule10.js | 4 +- .../reference/systemModule11.errors.txt | 11 +++ tests/baselines/reference/systemModule11.js | 21 +++++ .../reference/systemModule2.errors.txt | 4 +- .../baselines/reference/systemModule4.symbols | 8 ++ tests/baselines/reference/systemModule4.types | 1 + .../baselines/reference/systemModule7.symbols | 17 ++++ tests/baselines/reference/systemModule7.types | 1 + tests/baselines/reference/systemModule8.js | 2 +- .../baselines/reference/systemModule8.symbols | 77 +++++++++++++++++++ tests/baselines/reference/systemModule8.types | 23 +++++- .../reference/systemModule9.errors.txt | 19 ++--- tests/baselines/reference/systemModule9.js | 18 +++-- tests/cases/compiler/systemModule11.ts | 7 ++ 15 files changed, 193 insertions(+), 26 deletions(-) create mode 100644 tests/baselines/reference/systemModule11.errors.txt create mode 100644 tests/baselines/reference/systemModule11.js create mode 100644 tests/baselines/reference/systemModule4.symbols create mode 100644 tests/baselines/reference/systemModule7.symbols create mode 100644 tests/baselines/reference/systemModule8.symbols create mode 100644 tests/cases/compiler/systemModule11.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index d0d6f7c8c74..f61813f704a 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4880,7 +4880,11 @@ var __param = this.__param || function(index, decorator) { return function (targ writeLine(); let started = false; for (let importNode of externalImports) { - if (importNode.kind === SyntaxKind.ExportDeclaration) { + let skipNode = + importNode.kind === SyntaxKind.ExportDeclaration || + (importNode.kind === SyntaxKind.ImportDeclaration && !(importNode).importClause) + + if (skipNode) { continue; } diff --git a/tests/baselines/reference/systemModule10.js b/tests/baselines/reference/systemModule10.js index c5c95e05f9b..ab374c2261f 100644 --- a/tests/baselines/reference/systemModule10.js +++ b/tests/baselines/reference/systemModule10.js @@ -16,8 +16,8 @@ System.register(['file1', 'file2'], function(exports_1) { setters:[ function (v_1) { file1_1 = v_1 - exports_1("n", file1_1.default); - exports_1("n1", file1_1.default); + exports_1("n", file1_1["default"]); + exports_1("n1", file1_1["default"]); exports_1("x", file1_1.x); exports_1("y", file1_1.x); }, diff --git a/tests/baselines/reference/systemModule11.errors.txt b/tests/baselines/reference/systemModule11.errors.txt new file mode 100644 index 00000000000..a2c30e5fa64 --- /dev/null +++ b/tests/baselines/reference/systemModule11.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/systemModule11.ts(3,17): error TS2307: Cannot find external module 'bar'. + + +==== tests/cases/compiler/systemModule11.ts (1 errors) ==== + + import 'foo' + import {f} from 'bar'; + ~~~~~ +!!! error TS2307: Cannot find external module 'bar'. + + f(); \ No newline at end of file diff --git a/tests/baselines/reference/systemModule11.js b/tests/baselines/reference/systemModule11.js new file mode 100644 index 00000000000..522ea7d925a --- /dev/null +++ b/tests/baselines/reference/systemModule11.js @@ -0,0 +1,21 @@ +//// [systemModule11.ts] + +import 'foo' +import {f} from 'bar'; + +f(); + +//// [systemModule11.js] +System.register(['foo', 'bar'], function(exports_1) { + var bar_1; + return { + setters:[ + function (v_1) {}, + function (v_1) { + bar_1 = v_1 + }], + execute: function() { + bar_1.f(); + } + } +}); diff --git a/tests/baselines/reference/systemModule2.errors.txt b/tests/baselines/reference/systemModule2.errors.txt index 0ce216b73d9..e323e2cde2e 100644 --- a/tests/baselines/reference/systemModule2.errors.txt +++ b/tests/baselines/reference/systemModule2.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/systemModule2.ts(3,1): error TS1212: Export assignment is not supported when '--module' flag is 'system'. +tests/cases/compiler/systemModule2.ts(3,1): error TS1218: Export assignment is not supported when '--module' flag is 'system'. ==== tests/cases/compiler/systemModule2.ts (1 errors) ==== @@ -6,4 +6,4 @@ tests/cases/compiler/systemModule2.ts(3,1): error TS1212: Export assignment is n var x = 1; export = x; ~~~~~~~~~~~ -!!! error TS1212: Export assignment is not supported when '--module' flag is 'system'. \ No newline at end of file +!!! error TS1218: Export assignment is not supported when '--module' flag is 'system'. \ No newline at end of file diff --git a/tests/baselines/reference/systemModule4.symbols b/tests/baselines/reference/systemModule4.symbols new file mode 100644 index 00000000000..b0bc1a1cfc1 --- /dev/null +++ b/tests/baselines/reference/systemModule4.symbols @@ -0,0 +1,8 @@ +=== tests/cases/compiler/systemModule4.ts === + +export var x = 1; +>x : Symbol(x, Decl(systemModule4.ts, 1, 10)) + +export var y; +>y : Symbol(y, Decl(systemModule4.ts, 2, 10)) + diff --git a/tests/baselines/reference/systemModule4.types b/tests/baselines/reference/systemModule4.types index 17216d20e32..2029cdb88d7 100644 --- a/tests/baselines/reference/systemModule4.types +++ b/tests/baselines/reference/systemModule4.types @@ -2,6 +2,7 @@ export var x = 1; >x : number +>1 : number export var y; >y : any diff --git a/tests/baselines/reference/systemModule7.symbols b/tests/baselines/reference/systemModule7.symbols new file mode 100644 index 00000000000..e47ab5510b5 --- /dev/null +++ b/tests/baselines/reference/systemModule7.symbols @@ -0,0 +1,17 @@ +=== tests/cases/compiler/systemModule7.ts === + +// filename: instantiatedModule.ts +export module M { +>M : Symbol(M, Decl(systemModule7.ts, 0, 0), Decl(systemModule7.ts, 4, 1)) + + var x = 1; +>x : Symbol(x, Decl(systemModule7.ts, 3, 7)) +} + +// filename: nonInstantiatedModule.ts +export module M { +>M : Symbol(M, Decl(systemModule7.ts, 0, 0), Decl(systemModule7.ts, 4, 1)) + + interface I {} +>I : Symbol(I, Decl(systemModule7.ts, 7, 17)) +} diff --git a/tests/baselines/reference/systemModule7.types b/tests/baselines/reference/systemModule7.types index e1b6bd04613..650e2d6cdb1 100644 --- a/tests/baselines/reference/systemModule7.types +++ b/tests/baselines/reference/systemModule7.types @@ -6,6 +6,7 @@ export module M { var x = 1; >x : number +>1 : number } // filename: nonInstantiatedModule.ts diff --git a/tests/baselines/reference/systemModule8.js b/tests/baselines/reference/systemModule8.js index e4c0e12aae3..e4ee68a1bb1 100644 --- a/tests/baselines/reference/systemModule8.js +++ b/tests/baselines/reference/systemModule8.js @@ -52,7 +52,7 @@ System.register([], function(exports_1) { for (exports_1("x", x = 15);; exports_1("x", ++x)) { } for (exports_1("x", x = 18);; exports_1("x", --x)) { } for (x_1 = 50;;) { } - exports_1("y", y = ([1])[0]); + exports_1("y", y = [1][0]); _a = { a: true, b: { c: "123" } }, exports_1("z0", z0 = _a.a), exports_1("z1", z1 = _a.b.c); for (var _i = 0, _b = [[1]]; _i < _b.length; _i++) { exports_1("x", x = _b[_i][0]); diff --git a/tests/baselines/reference/systemModule8.symbols b/tests/baselines/reference/systemModule8.symbols new file mode 100644 index 00000000000..14f5bc7e94c --- /dev/null +++ b/tests/baselines/reference/systemModule8.symbols @@ -0,0 +1,77 @@ +=== tests/cases/compiler/systemModule8.ts === + +export var x; +>x : Symbol(x, Decl(systemModule8.ts, 1, 10)) + +x = 1; +>x : Symbol(x, Decl(systemModule8.ts, 1, 10)) + +x++; +>x : Symbol(x, Decl(systemModule8.ts, 1, 10)) + +x--; +>x : Symbol(x, Decl(systemModule8.ts, 1, 10)) + +++x; +>x : Symbol(x, Decl(systemModule8.ts, 1, 10)) + +--x; +>x : Symbol(x, Decl(systemModule8.ts, 1, 10)) + +x += 1; +>x : Symbol(x, Decl(systemModule8.ts, 1, 10)) + +x -= 1; +>x : Symbol(x, Decl(systemModule8.ts, 1, 10)) + +x *= 1; +>x : Symbol(x, Decl(systemModule8.ts, 1, 10)) + +x /= 1; +>x : Symbol(x, Decl(systemModule8.ts, 1, 10)) + +x |= 1; +>x : Symbol(x, Decl(systemModule8.ts, 1, 10)) + +x &= 1; +>x : Symbol(x, Decl(systemModule8.ts, 1, 10)) + +for (x = 5;;x++) {} +>x : Symbol(x, Decl(systemModule8.ts, 1, 10)) +>x : Symbol(x, Decl(systemModule8.ts, 1, 10)) + +for (x = 8;;x--) {} +>x : Symbol(x, Decl(systemModule8.ts, 1, 10)) +>x : Symbol(x, Decl(systemModule8.ts, 1, 10)) + +for (x = 15;;++x) {} +>x : Symbol(x, Decl(systemModule8.ts, 1, 10)) +>x : Symbol(x, Decl(systemModule8.ts, 1, 10)) + +for (x = 18;;--x) {} +>x : Symbol(x, Decl(systemModule8.ts, 1, 10)) +>x : Symbol(x, Decl(systemModule8.ts, 1, 10)) + +for (let x = 50;;) {} +>x : Symbol(x, Decl(systemModule8.ts, 18, 8)) + +function foo() { +>foo : Symbol(foo, Decl(systemModule8.ts, 18, 21)) + + x = 100; +>x : Symbol(x, Decl(systemModule8.ts, 1, 10)) +} + +export let [y] = [1]; +>y : Symbol(y, Decl(systemModule8.ts, 23, 12)) + +export const {a: z0, b: {c: z1}} = {a: true, b: {c: "123"}}; +>z0 : Symbol(z0, Decl(systemModule8.ts, 24, 14)) +>z1 : Symbol(z1, Decl(systemModule8.ts, 24, 25)) +>a : Symbol(a, Decl(systemModule8.ts, 24, 36)) +>b : Symbol(b, Decl(systemModule8.ts, 24, 44)) +>c : Symbol(c, Decl(systemModule8.ts, 24, 49)) + +for ([x] of [[1]]) {} +>x : Symbol(x, Decl(systemModule8.ts, 1, 10)) + diff --git a/tests/baselines/reference/systemModule8.types b/tests/baselines/reference/systemModule8.types index cd192662078..39f2ac4104e 100644 --- a/tests/baselines/reference/systemModule8.types +++ b/tests/baselines/reference/systemModule8.types @@ -6,6 +6,7 @@ export var x; x = 1; >x = 1 : number >x : any +>1 : number x++; >x++ : number @@ -26,53 +27,64 @@ x--; x += 1; >x += 1 : any >x : any +>1 : number x -= 1; >x -= 1 : number >x : any +>1 : number x *= 1; >x *= 1 : number >x : any +>1 : number x /= 1; >x /= 1 : number >x : any +>1 : number x |= 1; >x |= 1 : number >x : any +>1 : number x &= 1; >x &= 1 : number >x : any +>1 : number for (x = 5;;x++) {} >x = 5 : number >x : any +>5 : number >x++ : number >x : any for (x = 8;;x--) {} >x = 8 : number >x : any +>8 : number >x-- : number >x : any for (x = 15;;++x) {} >x = 15 : number >x : any +>15 : number >++x : number >x : any for (x = 18;;--x) {} >x = 18 : number >x : any +>18 : number >--x : number >x : any for (let x = 50;;) {} >x : number +>50 : number function foo() { >foo : () => void @@ -80,27 +92,32 @@ function foo() { x = 100; >x = 100 : number >x : any +>100 : number } export let [y] = [1]; >y : number >[1] : [number] +>1 : number export const {a: z0, b: {c: z1}} = {a: true, b: {c: "123"}}; ->a : unknown +>a : any >z0 : boolean ->b : unknown ->c : unknown +>b : any +>c : any >z1 : string >{a: true, b: {c: "123"}} : { a: boolean; b: { c: string; }; } >a : boolean +>true : boolean >b : { c: string; } >{c: "123"} : { c: string; } >c : string +>"123" : string for ([x] of [[1]]) {} >[x] : any[] >x : any >[[1]] : number[][] >[1] : number[] +>1 : number diff --git a/tests/baselines/reference/systemModule9.errors.txt b/tests/baselines/reference/systemModule9.errors.txt index 4a536d2a55b..f997ed97703 100644 --- a/tests/baselines/reference/systemModule9.errors.txt +++ b/tests/baselines/reference/systemModule9.errors.txt @@ -1,9 +1,9 @@ tests/cases/compiler/systemModule9.ts(2,21): error TS2307: Cannot find external module 'file1'. tests/cases/compiler/systemModule9.ts(3,25): error TS2307: Cannot find external module 'file2'. tests/cases/compiler/systemModule9.ts(4,15): error TS2307: Cannot find external module 'file3'. -tests/cases/compiler/systemModule9.ts(5,25): error TS2307: Cannot find external module 'file4'. -tests/cases/compiler/systemModule9.ts(6,22): error TS2307: Cannot find external module 'file5'. -tests/cases/compiler/systemModule9.ts(16,15): error TS2307: Cannot find external module 'file6'. +tests/cases/compiler/systemModule9.ts(6,25): error TS2307: Cannot find external module 'file5'. +tests/cases/compiler/systemModule9.ts(7,22): error TS2307: Cannot find external module 'file6'. +tests/cases/compiler/systemModule9.ts(17,15): error TS2307: Cannot find external module 'file7'. ==== tests/cases/compiler/systemModule9.ts (6 errors) ==== @@ -17,12 +17,13 @@ tests/cases/compiler/systemModule9.ts(16,15): error TS2307: Cannot find external import d from 'file3' ~~~~~~~ !!! error TS2307: Cannot find external module 'file3'. - import e, * as ns2 from 'file4'; + import 'file4' + import e, * as ns2 from 'file5'; ~~~~~~~ -!!! error TS2307: Cannot find external module 'file4'. - import ns3 = require('file5'); - ~~~~~~~ !!! error TS2307: Cannot find external module 'file5'. + import ns3 = require('file6'); + ~~~~~~~ +!!! error TS2307: Cannot find external module 'file6'. ns.f(); a(); @@ -32,9 +33,9 @@ tests/cases/compiler/systemModule9.ts(16,15): error TS2307: Cannot find external ns2.f(); ns3.f(); - export * from 'file6'; + export * from 'file7'; ~~~~~~~ -!!! error TS2307: Cannot find external module 'file6'. +!!! error TS2307: Cannot find external module 'file7'. var x, y = true; export {x}; diff --git a/tests/baselines/reference/systemModule9.js b/tests/baselines/reference/systemModule9.js index 10654721726..eb149254d8b 100644 --- a/tests/baselines/reference/systemModule9.js +++ b/tests/baselines/reference/systemModule9.js @@ -3,8 +3,9 @@ import * as ns from 'file1'; import {a, b as c} from 'file2'; import d from 'file3' -import e, * as ns2 from 'file4'; -import ns3 = require('file5'); +import 'file4' +import e, * as ns2 from 'file5'; +import ns3 = require('file6'); ns.f(); a(); @@ -14,15 +15,15 @@ e(); ns2.f(); ns3.f(); -export * from 'file6'; +export * from 'file7'; var x, y = true; export {x}; export {y as z}; //// [systemModule9.js] -System.register(['file1', 'file2', 'file3', 'file4', 'file5', 'file6'], function(exports_1) { - var ns, file2_1, file3_1, file4_1, ns3; +System.register(['file1', 'file2', 'file3', 'file4', 'file5', 'file6', 'file7'], function(exports_1) { + var ns, file2_1, file3_1, file5_1, ns3; var x, y; return { setters:[ @@ -35,8 +36,9 @@ System.register(['file1', 'file2', 'file3', 'file4', 'file5', 'file6'], function function (v_1) { file3_1 = v_1 }, + function (v_1) {}, function (v_1) { - file4_1 = v_1 + file5_1 = v_1 }, function (v_1) { ns3 = v_1 @@ -48,8 +50,8 @@ System.register(['file1', 'file2', 'file3', 'file4', 'file5', 'file6'], function ns.f(); file2_1.a(); file2_1.b(); - file3_1.default(); - file4_1.default(); + file3_1["default"](); + file5_1["default"](); ns2.f(); ns3.f(); y = true; diff --git a/tests/cases/compiler/systemModule11.ts b/tests/cases/compiler/systemModule11.ts new file mode 100644 index 00000000000..023b4f5f56b --- /dev/null +++ b/tests/cases/compiler/systemModule11.ts @@ -0,0 +1,7 @@ +// @module: system +// @separateCompilation: true + +import 'foo' +import {f} from 'bar'; + +f(); \ No newline at end of file From bef6e089933fcc7dc7e3e9ff0490d28857e2bcb2 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 20 Apr 2015 16:56:36 -0700 Subject: [PATCH 048/194] added comments, updated test baselines --- src/compiler/emitter.ts | 131 ++++++++++++++++++-- tests/baselines/reference/systemModule10.js | 8 +- tests/baselines/reference/systemModule11.js | 6 +- tests/baselines/reference/systemModule9.js | 26 ++-- 4 files changed, 138 insertions(+), 33 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index f61813f704a..646f4fa6562 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1934,7 +1934,10 @@ var __param = this.__param || function(index, decorator) { return function (targ const isVariableDeclarationOrBindingElement = node.parent && (node.parent.kind === SyntaxKind.VariableDeclaration || node.parent.kind === SyntaxKind.BindingElement); - const targetDeclaration = isVariableDeclarationOrBindingElement ? node.parent : resolver.getReferencedValueDeclaration(node); + const targetDeclaration = + isVariableDeclarationOrBindingElement + ? node.parent + : resolver.getReferencedValueDeclaration(node); return isSourceFileLevelDeclarationInSystemExternalModule(targetDeclaration, /*isExported*/ true); } @@ -1943,6 +1946,10 @@ var __param = this.__param || function(index, decorator) { return function (targ const exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.operand); if (exportChanged) { + // emit + // ++x + // as + // exports('x', ++x) write(`${exportFunctionForFile}("`); emitNodeWithoutSourceMap(node.operand); write(`", `); @@ -1980,6 +1987,8 @@ var __param = this.__param || function(index, decorator) { return function (targ function emitPostfixUnaryExpression(node: PostfixUnaryExpression) { const exportChanged = isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.operand); if (exportChanged) { + // export function returns the value that was passes as the second argument + // however for postfix unary expressions result value should be the value before modification. // emit 'x++' as '(export('x', ++x) - 1)' and 'x--' as '(export('x', --x) + 1)' write(`(${exportFunctionForFile}("`); emitNodeWithoutSourceMap(node.operand); @@ -2001,6 +2010,16 @@ var __param = this.__param || function(index, decorator) { return function (targ } } + /* + * Checks if given node is a source file level declaration (not nested in module/function). + * If 'isExported' is true - then declaration must also be exported. + * This function is used in two cases: + * - check if node is a exported source file level value to determine + * if we should also export the value after its it changed + * - check if node is a source level declaration to emit it differently, + * i.e non-exported variable statement 'var x = 1' is hoisted so + * we we emit variable statement 'var' should be dropped. + */ function isSourceFileLevelDeclarationInSystemExternalModule(node: Node, isExported: boolean): boolean { if (!node || languageVersion >= ScriptTarget.ES6 || !isCurrentFileSystemExternalModule()) { return false; @@ -4880,6 +4899,7 @@ var __param = this.__param || function(index, decorator) { return function (targ writeLine(); let started = false; for (let importNode of externalImports) { + // do not create variable declaration for exports and imports that lack import clause let skipNode = importNode.kind === SyntaxKind.ExportDeclaration || (importNode.kind === SyntaxKind.ImportDeclaration && !(importNode).importClause) @@ -4905,6 +4925,15 @@ var __param = this.__param || function(index, decorator) { return function (targ } function hoistTopLevelVariableAndFunctionDeclarations(node: SourceFile): void { + // per ES6 spec: + // 15.2.1.16.4 ModuleDeclarationInstantiation() Concrete Method + // - var declarations are initialized to undefined - 14.a.ii + // - function/generator declarations are instantiated - 16.a.iv + // this means that after module is instantiated but before its evaluation + // exported functions are already accessible at import sites + // in theory we should hoist only exported functions and its dependencies + // in practice to simplify things we'll hoist all source level functions and variable declaration + // including variables declarations for module and class declarations let hoistedVars: (Identifier | ClassDeclaration | ModuleDeclaration)[]; let hoistedFunctionDeclarations: FunctionDeclaration[]; @@ -4980,6 +5009,42 @@ var __param = this.__param || function(index, decorator) { return function (targ } function emitSystemModuleBody(node: SourceFile, startIndex: number): void { + // shape of the body in system modules: + // function (exports) { + // + // + // + // return { + // setters: [ + // + // ], + // execute: function() { + // + // } + // } + // + // } + // I.e: + // import {x} from 'file1' + // var y = 1; + // export function foo() { return y + x(); } + // console.log(y); + // will be transformed to + // function(exports) { + // var file1; // local alias + // var y; + // function foo() { return y + file1.x(); } + // exports("foo", foo); + // return { + // setters: [ + // function(v) { file1 = v } + // ], + // execute(): function() { + // y = 1; + // console.log(y); + // } + // }; + // } emitVariableDeclarationsForImports(); writeLine(); hoistTopLevelVariableAndFunctionDeclarations(node); @@ -4990,6 +5055,7 @@ var __param = this.__param || function(index, decorator) { return function (targ emitSetters(); writeLine(); emitExecute(node, startIndex); + emitTempDeclarations(/*newLine*/ true) decreaseIndent(); writeLine(); write("}"); // return @@ -4997,7 +5063,6 @@ var __param = this.__param || function(index, decorator) { return function (targ function emitSetters() { write("setters:[") - let setterParameterName = makeUniqueName("v"); for (let i = 0; i < externalImports.length; ++i) { if (i !== 0) { write(","); @@ -5005,38 +5070,59 @@ var __param = this.__param || function(index, decorator) { return function (targ writeLine(); increaseIndent(); - write(`function (${setterParameterName}) {`); let importNode = externalImports[i]; + let importVariableName = getLocalNameForExternalImport(importNode) || ""; + let parameterName = "_" + importVariableName; + write(`function (${parameterName}) {`); switch (importNode.kind) { case SyntaxKind.ImportDeclaration: if (!(importNode).importClause) { + // 'import "..."' case + // module is imported only for side-effects, setter body will be empty break; } // fall-through case SyntaxKind.ImportEqualsDeclaration: + Debug.assert(importVariableName !== ""); + increaseIndent(); writeLine(); - write(getLocalNameForExternalImport(importNode)) - write(` = ${setterParameterName}`); + // save import into the local + write(`${importVariableName} = ${parameterName}`); writeLine(); let defaultName = importNode.kind === SyntaxKind.ImportDeclaration ? (importNode).importClause.name : (importNode).name; + if (defaultName) { + // emit re-export for imported default name + // import n1 from 'foo1' + // import n2 = require('foo2') + // export {n1} + // export {n2} emitExportMemberAssignments(defaultName); writeLine(); } - if (importNode.kind === SyntaxKind.ImportDeclaration && (importNode).importClause.namedBindings) { - if ((importNode).importClause.namedBindings.kind === SyntaxKind.NamespaceImport) { - emitExportMemberAssignments(((importNode).importClause.namedBindings).name); + if (importNode.kind === SyntaxKind.ImportDeclaration && + (importNode).importClause.namedBindings) { + + let namedBindings = (importNode).importClause.namedBindings; + if (namedBindings.kind === SyntaxKind.NamespaceImport) { + // emit re-export for namespace + // import * as n from 'foo' + // export {n} + emitExportMemberAssignments((namedBindings).name); writeLine(); } else { - for (let element of ((importNode).importClause.namedBindings).elements) { + // emit re-exports for named imports + // import {a, b} from 'foo' + // export {a, b as c} + for (let element of (namedBindings).elements) { emitExportMemberAssignments(element.name || element.propertyName); writeLine() } @@ -5046,22 +5132,31 @@ var __param = this.__param || function(index, decorator) { return function (targ decreaseIndent(); break; case SyntaxKind.ExportDeclaration: + Debug.assert(importVariableName !== ""); + increaseIndent(); if ((importNode).exportClause) { + // export {a, b as c} from 'foo' + // emit as: + // exports('a', _foo["a"]) + // exports('c', _foo["b"]) for (let e of (importNode).exportClause.elements) { writeLine(); write(`${exportFunctionForFile}("`); emitNodeWithoutSourceMap(e.name); - write(`", ${setterParameterName}["`); + write(`", ${parameterName}["`); emitNodeWithoutSourceMap(e.propertyName || e.name); write(`"]);`); } } else { writeLine(); - // export * from - write(`for (var n in ${setterParameterName}) ${exportFunctionForFile}(n, ${setterParameterName}[n]);`); + // export * from 'foo' + // emit as: + // for (var n in _foo) exports(n, _foo[n]); + // NOTE: it is safe to use name 'n' since parameter name always starts with '_' + write(`for (var n in ${parameterName}) ${exportFunctionForFile}(n, ${parameterName}[n]);`); } writeLine(); @@ -5081,6 +5176,8 @@ var __param = this.__param || function(index, decorator) { return function (targ writeLine(); for (let i = startIndex; i < node.statements.length; ++i) { let statement = node.statements[i]; + // - imports/exports are not emitted for system modules + // - function declarations are not emitted because they were already hoisted switch (statement.kind) { case SyntaxKind.ExportDeclaration: case SyntaxKind.ImportDeclaration: @@ -5094,12 +5191,20 @@ var __param = this.__param || function(index, decorator) { return function (targ decreaseIndent(); writeLine(); write("}") // execute - emitTempDeclarations(/*newLine*/ true); } function emitSystemModule(node: SourceFile, startIndex: number): void { collectExternalModuleInfo(node); + // System modules has the following shape + // System.register(['dep-1', ... 'dep-n'], function(exports) {/* module body function */}) + // 'exports' here is a function 'exports(name: string, value: T): T' that is used to publish exported values. + // 'exports' returns its 'value' argument so in most cases expressions + // that mutate exported values can be rewritten as: + // expr -> exports('name', expr). + // The only exception in this rule is postfix unary operators, + // see comment to 'emitPostfixUnaryExpression' for more details Debug.assert(!exportFunctionForFile); + // make sure that name of 'exports' function does not conflict with existing identifiers exportFunctionForFile = makeUniqueName("exports"); write("System.register(["); for (let i = 0; i < externalImports.length; ++i) { diff --git a/tests/baselines/reference/systemModule10.js b/tests/baselines/reference/systemModule10.js index ab374c2261f..66e7e9755d1 100644 --- a/tests/baselines/reference/systemModule10.js +++ b/tests/baselines/reference/systemModule10.js @@ -14,15 +14,15 @@ System.register(['file1', 'file2'], function(exports_1) { var file1_1, n2; return { setters:[ - function (v_1) { - file1_1 = v_1 + function (_file1_1) { + file1_1 = _file1_1 exports_1("n", file1_1["default"]); exports_1("n1", file1_1["default"]); exports_1("x", file1_1.x); exports_1("y", file1_1.x); }, - function (v_1) { - n2 = v_1 + function (_n2) { + n2 = _n2 exports_1("n2", n2); exports_1("n3", n2); }], diff --git a/tests/baselines/reference/systemModule11.js b/tests/baselines/reference/systemModule11.js index 522ea7d925a..f04cabcf935 100644 --- a/tests/baselines/reference/systemModule11.js +++ b/tests/baselines/reference/systemModule11.js @@ -10,9 +10,9 @@ System.register(['foo', 'bar'], function(exports_1) { var bar_1; return { setters:[ - function (v_1) {}, - function (v_1) { - bar_1 = v_1 + function (_) {}, + function (_bar_1) { + bar_1 = _bar_1 }], execute: function() { bar_1.f(); diff --git a/tests/baselines/reference/systemModule9.js b/tests/baselines/reference/systemModule9.js index eb149254d8b..831aa778f38 100644 --- a/tests/baselines/reference/systemModule9.js +++ b/tests/baselines/reference/systemModule9.js @@ -27,24 +27,24 @@ System.register(['file1', 'file2', 'file3', 'file4', 'file5', 'file6', 'file7'], var x, y; return { setters:[ - function (v_1) { - ns = v_1 + function (_ns) { + ns = _ns }, - function (v_1) { - file2_1 = v_1 + function (_file2_1) { + file2_1 = _file2_1 }, - function (v_1) { - file3_1 = v_1 + function (_file3_1) { + file3_1 = _file3_1 }, - function (v_1) {}, - function (v_1) { - file5_1 = v_1 + function (_) {}, + function (_file5_1) { + file5_1 = _file5_1 }, - function (v_1) { - ns3 = v_1 + function (_ns3) { + ns3 = _ns3 }, - function (v_1) { - for (var n in v_1) exports_1(n, v_1[n]); + function (_file7_1) { + for (var n in _file7_1) exports_1(n, _file7_1[n]); }], execute: function() { ns.f(); From b4bd216013c4eadf27badae6da96775580b28360 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Mon, 20 Apr 2015 17:01:47 -0700 Subject: [PATCH 049/194] fixed indentation in comments --- src/compiler/emitter.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 646f4fa6562..b6ebf566fa0 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -5240,12 +5240,12 @@ var __param = this.__param || function(index, decorator) { return function (targ // we need to add modules without alias names to the end of the dependencies list let aliasedModuleNames: string[] = []; // names of modules with corresponding parameter in the - // factory function. + // factory function. let unaliasedModuleNames: string[] = []; // names of modules with no corresponding parameters in - // factory function. + // factory function. let importAliasNames: string[] = []; // names of the parameters in the factory function; these - // paramters need to match the indexes of the corresponding - // module names in aliasedModuleNames. + // parameters need to match the indexes of the corresponding + // module names in aliasedModuleNames. // Fill in amd-dependency tags for (let amdDependency of node.amdDependencies) { From 658bba9eaf7475790ed06ca1b24e0a2138efbd7e Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 20 Apr 2015 20:33:31 -0700 Subject: [PATCH 050/194] Add --inlineSources option --- src/compiler/commandLineParser.ts | 4 + .../diagnosticInformationMap.generated.ts | 2 +- src/compiler/diagnosticMessages.json | 2 +- src/compiler/emitter.ts | 11 +- src/compiler/program.ts | 8 +- src/compiler/types.ts | 18 +-- src/harness/harness.ts | 7 +- src/harness/sourceMapRecorder.ts | 3 + tests/baselines/reference/inlineSourceMap.js | 2 +- .../reference/inlineSourceMap.sourcemap.txt | 4 +- .../reference/inlineSourceMap2.errors.txt | 2 - tests/baselines/reference/inlineSourceMap2.js | 2 +- .../reference/inlineSourceMap2.sourcemap.txt | 4 +- .../reference/inlineSources.errors.txt | 16 +++ tests/baselines/reference/inlineSources.js | 17 +++ .../baselines/reference/inlineSources.js.map | 2 + .../reference/inlineSources.sourcemap.txt | 114 ++++++++++++++++++ .../reference/inlineSources2.errors.txt | 16 +++ tests/baselines/reference/inlineSources2.js | 17 +++ .../reference/inlineSources2.sourcemap.txt | 114 ++++++++++++++++++ tests/cases/compiler/inlineSources.ts | 12 ++ tests/cases/compiler/inlineSources2.ts | 12 ++ 22 files changed, 366 insertions(+), 23 deletions(-) create mode 100644 tests/baselines/reference/inlineSources.errors.txt create mode 100644 tests/baselines/reference/inlineSources.js create mode 100644 tests/baselines/reference/inlineSources.js.map create mode 100644 tests/baselines/reference/inlineSources.sourcemap.txt create mode 100644 tests/baselines/reference/inlineSources2.errors.txt create mode 100644 tests/baselines/reference/inlineSources2.js create mode 100644 tests/baselines/reference/inlineSources2.sourcemap.txt create mode 100644 tests/cases/compiler/inlineSources.ts create mode 100644 tests/cases/compiler/inlineSources2.ts diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index d34d56b46ca..e1a0063e513 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -34,6 +34,10 @@ module ts { name: "inlineSourceMap", type: "boolean", }, + { + name: "inlineSources", + type: "boolean", + }, { name: "listFiles", type: "boolean", diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 9ff765d732a..d683333e1d4 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -455,7 +455,7 @@ module ts { Option_sourceMap_cannot_be_specified_with_option_inlineSourceMap: { code: 5048, category: DiagnosticCategory.Error, key: "Option 'sourceMap' cannot be specified with option 'inlineSourceMap'." }, Option_sourceRoot_cannot_be_specified_with_option_inlineSourceMap: { code: 5049, category: DiagnosticCategory.Error, key: "Option 'sourceRoot' cannot be specified with option 'inlineSourceMap'." }, Option_mapRoot_cannot_be_specified_with_option_inlineSourceMap: { code: 5050, category: DiagnosticCategory.Error, key: "Option 'mapRoot' cannot be specified with option 'inlineSourceMap'." }, - Option_out_cannot_be_specified_with_option_inlineSourceMap: { code: 5051, category: DiagnosticCategory.Error, key: "Option 'out' cannot be specified with option 'inlineSourceMap'." }, + Option_inlineSources_can_only_be_used_when_either_option_inlineSourceMap_or_option_sourceMap_is_provided: { code: 5051, category: DiagnosticCategory.Error, key: "Option 'inlineSources' can only be used when either option '--inlineSourceMap' or option '--sourceMap' is provided." }, Concatenate_and_emit_output_to_single_file: { code: 6001, category: DiagnosticCategory.Message, key: "Concatenate and emit output to single file." }, Generates_corresponding_d_ts_file: { code: 6002, category: DiagnosticCategory.Message, key: "Generates corresponding '.d.ts' file." }, Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations: { code: 6003, category: DiagnosticCategory.Message, key: "Specifies the location where debugger should locate map files instead of generated locations." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 51e1be81086..915134d8cde 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1808,7 +1808,7 @@ "category": "Error", "code": 5050 }, - "Option 'out' cannot be specified with option 'inlineSourceMap'.": { + "Option 'inlineSources' can only be used when either option '--inlineSourceMap' or option '--sourceMap' is provided.": { "category": "Error", "code": 5051 }, diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index be35991630e..90d5022f6cd 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -493,6 +493,13 @@ var __param = this.__param || function(index, decorator) { return function (targ // The one that can be used from program to get the actual source file sourceMapData.inputSourceFileNames.push(node.fileName); + + if (compilerOptions.inlineSources) { + if (!sourceMapData.sourceMapSourcesContent) { + sourceMapData.sourceMapSourcesContent = []; + } + sourceMapData.sourceMapSourcesContent.push(node.text); + } } function recordScopeNameOfNode(node: Node, scopeName?: string) { @@ -599,7 +606,6 @@ var __param = this.__param || function(index, decorator) { return function (targ function writeJavaScriptAndSourceMapFile(emitOutput: string, writeByteOrderMark: boolean) { encodeLastRecordedSourceMapSpan(); - let fileContents = compilerOptions.inlineSourceMap ? [currentSourceFile.text] : undefined; let sourceMapText = serializeSourceMapContents( 3, sourceMapData.sourceMapFile, @@ -607,7 +613,7 @@ var __param = this.__param || function(index, decorator) { return function (targ sourceMapData.sourceMapSources, sourceMapData.sourceMapNames, sourceMapData.sourceMapMappings, - fileContents); + sourceMapData.sourceMapSourcesContent); sourceMapDataList.push(sourceMapData); @@ -638,6 +644,7 @@ var __param = this.__param || function(index, decorator) { return function (targ inputSourceFileNames: [], sourceMapNames: [], sourceMapMappings: "", + sourceMapSourcesContent: undefined, sourceMapDecodedMappings: [] }; diff --git a/src/compiler/program.ts b/src/compiler/program.ts index eff1c204741..d9bb0914355 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -484,8 +484,12 @@ module ts { if (options.sourceRoot) { diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_sourceRoot_cannot_be_specified_with_option_inlineSourceMap)); } - if (options.out) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_out_cannot_be_specified_with_option_inlineSourceMap)); + } + + + if (options.inlineSources) { + if (!options.sourceMap && !options.inlineSourceMap) { + diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_inlineSources_can_only_be_used_when_either_option_inlineSourceMap_or_option_sourceMap_is_provided)); } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 3741a1b0930..5b75ffa974d 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1092,14 +1092,15 @@ module ts { } export interface SourceMapData { - sourceMapFilePath: string; // Where the sourcemap file is written - jsSourceMappingURL: string; // source map URL written in the .js file - sourceMapFile: string; // Source map's file field - .js file name - sourceMapSourceRoot: string; // Source map's sourceRoot field - location where the sources will be present if not "" - sourceMapSources: string[]; // Source map's sources field - list of sources that can be indexed in this source map - inputSourceFileNames: string[]; // Input source file (which one can use on program to get the file), 1:1 mapping with the sourceMapSources list - sourceMapNames?: string[]; // Source map's names field - list of names that can be indexed in this source map - sourceMapMappings: string; // Source map's mapping field - encoded source map spans + sourceMapFilePath: string; // Where the sourcemap file is written + jsSourceMappingURL: string; // source map URL written in the .js file + sourceMapFile: string; // Source map's file field - .js file name + sourceMapSourceRoot: string; // Source map's sourceRoot field - location where the sources will be present if not "" + sourceMapSources: string[]; // Source map's sources field - list of sources that can be indexed in this source map + sourceMapSourcesContent?: string[]; // Source map's sourcesContent field - list of the sources' text to be embedded in the source map + inputSourceFileNames: string[]; // Input source file (which one can use on program to get the file), 1:1 mapping with the sourceMapSources list + sourceMapNames?: string[]; // Source map's names field - list of names that can be indexed in this source map + sourceMapMappings: string; // Source map's mapping field - encoded source map spans sourceMapDecodedMappings: SourceMapSpan[]; // Raw source map spans that were encoded into the sourceMapMappings } @@ -1640,6 +1641,7 @@ module ts { emitBOM?: boolean; help?: boolean; inlineSourceMap?: boolean; + inlineSources?: boolean; listFiles?: boolean; locale?: string; mapRoot?: string; diff --git a/src/harness/harness.ts b/src/harness/harness.ts index bef3c38cc01..a73b91cc57a 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -1076,6 +1076,10 @@ module Harness { case 'inlinesourcemap': options.inlineSourceMap = setting.value === 'true'; break; + + case 'inlinesources': + options.inlineSources = setting.value === 'true'; + break; default: throw new Error('Unsupported compiler setting ' + setting.flag); @@ -1473,7 +1477,8 @@ module Harness { "noimplicitany", "noresolve", "newline", "newlines", "emitbom", "errortruncation", "usecasesensitivefilenames", "preserveconstenums", "includebuiltfile", "suppressimplicitanyindexerrors", "stripinternal", - "separatecompilation", "inlinesourcemap", "maproot", "sourceroot"]; + "separatecompilation", "inlinesourcemap", "maproot", "sourceroot", + "inlinesources"]; function extractCompilerSettings(content: string): CompilerSetting[] { diff --git a/src/harness/sourceMapRecorder.ts b/src/harness/sourceMapRecorder.ts index f7d6bcfeaa1..528e6ddd52b 100644 --- a/src/harness/sourceMapRecorder.ts +++ b/src/harness/sourceMapRecorder.ts @@ -237,6 +237,9 @@ module Harness.SourceMapRecoder { sourceMapRecoder.WriteLine("mapUrl: " + sourceMapData.jsSourceMappingURL); sourceMapRecoder.WriteLine("sourceRoot: " + sourceMapData.sourceMapSourceRoot); sourceMapRecoder.WriteLine("sources: " + sourceMapData.sourceMapSources); + if (sourceMapData.sourceMapSourcesContent) { + sourceMapRecoder.WriteLine("sourcesContent: " + JSON.stringify(sourceMapData.sourceMapSourcesContent)); + } sourceMapRecoder.WriteLine("==================================================================="); } diff --git a/tests/baselines/reference/inlineSourceMap.js b/tests/baselines/reference/inlineSourceMap.js index da0f6de96d3..94ad43d4487 100644 --- a/tests/baselines/reference/inlineSourceMap.js +++ b/tests/baselines/reference/inlineSourceMap.js @@ -6,4 +6,4 @@ console.log(x); //// [inlineSourceMap.js] var x = 0; console.log(x); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5saW5lU291cmNlTWFwLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiaW5saW5lU291cmNlTWFwLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLElBQUksQ0FBQyxHQUFHLENBQUMsQ0FBQztBQUNWLE9BQU8sQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFDLENBQUMiLCJzb3VyY2VzQ29udGVudCI6WyJcbnZhciB4ID0gMDtcbmNvbnNvbGUubG9nKHgpOyJdfQ== \ No newline at end of file +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5saW5lU291cmNlTWFwLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiaW5saW5lU291cmNlTWFwLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLElBQUksQ0FBQyxHQUFHLENBQUMsQ0FBQztBQUNWLE9BQU8sQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFDLENBQUMifQ== \ No newline at end of file diff --git a/tests/baselines/reference/inlineSourceMap.sourcemap.txt b/tests/baselines/reference/inlineSourceMap.sourcemap.txt index e344ecc43ab..6625cc46b21 100644 --- a/tests/baselines/reference/inlineSourceMap.sourcemap.txt +++ b/tests/baselines/reference/inlineSourceMap.sourcemap.txt @@ -39,7 +39,7 @@ sourceFile:inlineSourceMap.ts 6 > ^ 7 > ^ 8 > ^ -9 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +9 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1-> > 2 >console @@ -58,4 +58,4 @@ sourceFile:inlineSourceMap.ts 7 >Emitted(2, 15) Source(3, 15) + SourceIndex(0) 8 >Emitted(2, 16) Source(3, 16) + SourceIndex(0) --- ->>>//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5saW5lU291cmNlTWFwLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiaW5saW5lU291cmNlTWFwLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLElBQUksQ0FBQyxHQUFHLENBQUMsQ0FBQztBQUNWLE9BQU8sQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFDLENBQUMiLCJzb3VyY2VzQ29udGVudCI6WyJcbnZhciB4ID0gMDtcbmNvbnNvbGUubG9nKHgpOyJdfQ== \ No newline at end of file +>>>//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5saW5lU291cmNlTWFwLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiaW5saW5lU291cmNlTWFwLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLElBQUksQ0FBQyxHQUFHLENBQUMsQ0FBQztBQUNWLE9BQU8sQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFDLENBQUMifQ== \ No newline at end of file diff --git a/tests/baselines/reference/inlineSourceMap2.errors.txt b/tests/baselines/reference/inlineSourceMap2.errors.txt index f35aabd8fa6..75db5689c66 100644 --- a/tests/baselines/reference/inlineSourceMap2.errors.txt +++ b/tests/baselines/reference/inlineSourceMap2.errors.txt @@ -1,11 +1,9 @@ -error TS5051: Option 'out' cannot be specified with option 'inlineSourceMap'. error TS5050: Option 'mapRoot' cannot be specified with option 'inlineSourceMap'. error TS5049: Option 'sourceRoot' cannot be specified with option 'inlineSourceMap'. error TS5048: Option 'sourceMap' cannot be specified with option 'inlineSourceMap'. tests/cases/compiler/inlineSourceMap2.ts(5,1): error TS2304: Cannot find name 'console'. -!!! error TS5051: Option 'out' cannot be specified with option 'inlineSourceMap'. !!! error TS5050: Option 'mapRoot' cannot be specified with option 'inlineSourceMap'. !!! error TS5049: Option 'sourceRoot' cannot be specified with option 'inlineSourceMap'. !!! error TS5048: Option 'sourceMap' cannot be specified with option 'inlineSourceMap'. diff --git a/tests/baselines/reference/inlineSourceMap2.js b/tests/baselines/reference/inlineSourceMap2.js index 679b480af3e..9cf27863346 100644 --- a/tests/baselines/reference/inlineSourceMap2.js +++ b/tests/baselines/reference/inlineSourceMap2.js @@ -9,4 +9,4 @@ console.log(x); // configuration errors var x = 0; console.log(x); -//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib3V0ZmlsZS5qcyIsInNvdXJjZVJvb3QiOiJmaWxlOi8vL2ZvbGRlci8iLCJzb3VyY2VzIjpbImlubGluZVNvdXJjZU1hcDIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsdUJBQXVCO0FBRXZCLElBQUksQ0FBQyxHQUFHLENBQUMsQ0FBQztBQUNWLE9BQU8sQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFDLENBQUMiLCJzb3VyY2VzQ29udGVudCI6WyJcbi8vIGNvbmZpZ3VyYXRpb24gZXJyb3JzXG5cbnZhciB4ID0gMDtcbmNvbnNvbGUubG9nKHgpOyJdfQ== \ No newline at end of file +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib3V0ZmlsZS5qcyIsInNvdXJjZVJvb3QiOiJmaWxlOi8vL2ZvbGRlci8iLCJzb3VyY2VzIjpbImlubGluZVNvdXJjZU1hcDIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsdUJBQXVCO0FBRXZCLElBQUksQ0FBQyxHQUFHLENBQUMsQ0FBQztBQUNWLE9BQU8sQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFDLENBQUMifQ== \ No newline at end of file diff --git a/tests/baselines/reference/inlineSourceMap2.sourcemap.txt b/tests/baselines/reference/inlineSourceMap2.sourcemap.txt index 3994efe82bf..4d7f499b55a 100644 --- a/tests/baselines/reference/inlineSourceMap2.sourcemap.txt +++ b/tests/baselines/reference/inlineSourceMap2.sourcemap.txt @@ -49,7 +49,7 @@ sourceFile:inlineSourceMap2.ts 6 > ^ 7 > ^ 8 > ^ -9 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +9 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1-> > 2 >console @@ -68,4 +68,4 @@ sourceFile:inlineSourceMap2.ts 7 >Emitted(3, 15) Source(5, 15) + SourceIndex(0) 8 >Emitted(3, 16) Source(5, 16) + SourceIndex(0) --- ->>>//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib3V0ZmlsZS5qcyIsInNvdXJjZVJvb3QiOiJmaWxlOi8vL2ZvbGRlci8iLCJzb3VyY2VzIjpbImlubGluZVNvdXJjZU1hcDIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsdUJBQXVCO0FBRXZCLElBQUksQ0FBQyxHQUFHLENBQUMsQ0FBQztBQUNWLE9BQU8sQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFDLENBQUMiLCJzb3VyY2VzQ29udGVudCI6WyJcbi8vIGNvbmZpZ3VyYXRpb24gZXJyb3JzXG5cbnZhciB4ID0gMDtcbmNvbnNvbGUubG9nKHgpOyJdfQ== \ No newline at end of file +>>>//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib3V0ZmlsZS5qcyIsInNvdXJjZVJvb3QiOiJmaWxlOi8vL2ZvbGRlci8iLCJzb3VyY2VzIjpbImlubGluZVNvdXJjZU1hcDIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsdUJBQXVCO0FBRXZCLElBQUksQ0FBQyxHQUFHLENBQUMsQ0FBQztBQUNWLE9BQU8sQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFDLENBQUMifQ== \ No newline at end of file diff --git a/tests/baselines/reference/inlineSources.errors.txt b/tests/baselines/reference/inlineSources.errors.txt new file mode 100644 index 00000000000..1c86dcf4d99 --- /dev/null +++ b/tests/baselines/reference/inlineSources.errors.txt @@ -0,0 +1,16 @@ +tests/cases/compiler/a.ts(3,1): error TS2304: Cannot find name 'console'. +tests/cases/compiler/b.ts(2,1): error TS2304: Cannot find name 'console'. + + +==== tests/cases/compiler/a.ts (1 errors) ==== + + var a = 0; + console.log(a); + ~~~~~~~ +!!! error TS2304: Cannot find name 'console'. + +==== tests/cases/compiler/b.ts (1 errors) ==== + var b = 0; + console.log(b); + ~~~~~~~ +!!! error TS2304: Cannot find name 'console'. \ No newline at end of file diff --git a/tests/baselines/reference/inlineSources.js b/tests/baselines/reference/inlineSources.js new file mode 100644 index 00000000000..c700af7e4c6 --- /dev/null +++ b/tests/baselines/reference/inlineSources.js @@ -0,0 +1,17 @@ +//// [tests/cases/compiler/inlineSources.ts] //// + +//// [a.ts] + +var a = 0; +console.log(a); + +//// [b.ts] +var b = 0; +console.log(b); + +//// [out.js] +var a = 0; +console.log(a); +var b = 0; +console.log(b); +//# sourceMappingURL=out.js.map \ No newline at end of file diff --git a/tests/baselines/reference/inlineSources.js.map b/tests/baselines/reference/inlineSources.js.map new file mode 100644 index 00000000000..7e09d95a35c --- /dev/null +++ b/tests/baselines/reference/inlineSources.js.map @@ -0,0 +1,2 @@ +//// [out.js.map] +{"version":3,"file":"out.js","sourceRoot":"","sources":["tests/cases/compiler/a.ts","tests/cases/compiler/b.ts"],"names":[],"mappings":"AACA,IAAI,CAAC,GAAG,CAAC,CAAC;AACV,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;ACFf,IAAI,CAAC,GAAG,CAAC,CAAC;AACV,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC","sourcesContent":["\nvar a = 0;\nconsole.log(a);\n","var b = 0;\nconsole.log(b);"]} \ No newline at end of file diff --git a/tests/baselines/reference/inlineSources.sourcemap.txt b/tests/baselines/reference/inlineSources.sourcemap.txt new file mode 100644 index 00000000000..47d762f044e --- /dev/null +++ b/tests/baselines/reference/inlineSources.sourcemap.txt @@ -0,0 +1,114 @@ +=================================================================== +JsFile: out.js +mapUrl: out.js.map +sourceRoot: +sources: tests/cases/compiler/a.ts,tests/cases/compiler/b.ts +sourcesContent: ["\nvar a = 0;\nconsole.log(a);\n","var b = 0;\nconsole.log(b);"] +=================================================================== +------------------------------------------------------------------- +emittedFile:out.js +sourceFile:tests/cases/compiler/a.ts +------------------------------------------------------------------- +>>>var a = 0; +1 > +2 >^^^^ +3 > ^ +4 > ^^^ +5 > ^ +6 > ^ +7 > ^^^^^^-> +1 > + > +2 >var +3 > a +4 > = +5 > 0 +6 > ; +1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) +2 >Emitted(1, 5) Source(2, 5) + SourceIndex(0) +3 >Emitted(1, 6) Source(2, 6) + SourceIndex(0) +4 >Emitted(1, 9) Source(2, 9) + SourceIndex(0) +5 >Emitted(1, 10) Source(2, 10) + SourceIndex(0) +6 >Emitted(1, 11) Source(2, 11) + SourceIndex(0) +--- +>>>console.log(a); +1-> +2 >^^^^^^^ +3 > ^ +4 > ^^^ +5 > ^ +6 > ^ +7 > ^ +8 > ^ +1-> + > +2 >console +3 > . +4 > log +5 > ( +6 > a +7 > ) +8 > ; +1->Emitted(2, 1) Source(3, 1) + SourceIndex(0) +2 >Emitted(2, 8) Source(3, 8) + SourceIndex(0) +3 >Emitted(2, 9) Source(3, 9) + SourceIndex(0) +4 >Emitted(2, 12) Source(3, 12) + SourceIndex(0) +5 >Emitted(2, 13) Source(3, 13) + SourceIndex(0) +6 >Emitted(2, 14) Source(3, 14) + SourceIndex(0) +7 >Emitted(2, 15) Source(3, 15) + SourceIndex(0) +8 >Emitted(2, 16) Source(3, 16) + SourceIndex(0) +--- +------------------------------------------------------------------- +emittedFile:out.js +sourceFile:tests/cases/compiler/b.ts +------------------------------------------------------------------- +>>>var b = 0; +1 > +2 >^^^^ +3 > ^ +4 > ^^^ +5 > ^ +6 > ^ +7 > ^^^^^^-> +1 > +2 >var +3 > b +4 > = +5 > 0 +6 > ; +1 >Emitted(3, 1) Source(1, 1) + SourceIndex(1) +2 >Emitted(3, 5) Source(1, 5) + SourceIndex(1) +3 >Emitted(3, 6) Source(1, 6) + SourceIndex(1) +4 >Emitted(3, 9) Source(1, 9) + SourceIndex(1) +5 >Emitted(3, 10) Source(1, 10) + SourceIndex(1) +6 >Emitted(3, 11) Source(1, 11) + SourceIndex(1) +--- +>>>console.log(b); +1-> +2 >^^^^^^^ +3 > ^ +4 > ^^^ +5 > ^ +6 > ^ +7 > ^ +8 > ^ +9 > ^^^^^^^^^^^^^^^-> +1-> + > +2 >console +3 > . +4 > log +5 > ( +6 > b +7 > ) +8 > ; +1->Emitted(4, 1) Source(2, 1) + SourceIndex(1) +2 >Emitted(4, 8) Source(2, 8) + SourceIndex(1) +3 >Emitted(4, 9) Source(2, 9) + SourceIndex(1) +4 >Emitted(4, 12) Source(2, 12) + SourceIndex(1) +5 >Emitted(4, 13) Source(2, 13) + SourceIndex(1) +6 >Emitted(4, 14) Source(2, 14) + SourceIndex(1) +7 >Emitted(4, 15) Source(2, 15) + SourceIndex(1) +8 >Emitted(4, 16) Source(2, 16) + SourceIndex(1) +--- +>>>//# sourceMappingURL=out.js.map \ No newline at end of file diff --git a/tests/baselines/reference/inlineSources2.errors.txt b/tests/baselines/reference/inlineSources2.errors.txt new file mode 100644 index 00000000000..1c86dcf4d99 --- /dev/null +++ b/tests/baselines/reference/inlineSources2.errors.txt @@ -0,0 +1,16 @@ +tests/cases/compiler/a.ts(3,1): error TS2304: Cannot find name 'console'. +tests/cases/compiler/b.ts(2,1): error TS2304: Cannot find name 'console'. + + +==== tests/cases/compiler/a.ts (1 errors) ==== + + var a = 0; + console.log(a); + ~~~~~~~ +!!! error TS2304: Cannot find name 'console'. + +==== tests/cases/compiler/b.ts (1 errors) ==== + var b = 0; + console.log(b); + ~~~~~~~ +!!! error TS2304: Cannot find name 'console'. \ No newline at end of file diff --git a/tests/baselines/reference/inlineSources2.js b/tests/baselines/reference/inlineSources2.js new file mode 100644 index 00000000000..7f4c82f2ac2 --- /dev/null +++ b/tests/baselines/reference/inlineSources2.js @@ -0,0 +1,17 @@ +//// [tests/cases/compiler/inlineSources2.ts] //// + +//// [a.ts] + +var a = 0; +console.log(a); + +//// [b.ts] +var b = 0; +console.log(b); + +//// [out.js] +var a = 0; +console.log(a); +var b = 0; +console.log(b); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib3V0LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsidGVzdHMvY2FzZXMvY29tcGlsZXIvYS50cyIsInRlc3RzL2Nhc2VzL2NvbXBpbGVyL2IudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsSUFBSSxDQUFDLEdBQUcsQ0FBQyxDQUFDO0FBQ1YsT0FBTyxDQUFDLEdBQUcsQ0FBQyxDQUFDLENBQUMsQ0FBQztBQ0ZmLElBQUksQ0FBQyxHQUFHLENBQUMsQ0FBQztBQUNWLE9BQU8sQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFDLENBQUMiLCJzb3VyY2VzQ29udGVudCI6WyJcbnZhciBhID0gMDtcbmNvbnNvbGUubG9nKGEpO1xuIiwidmFyIGIgPSAwO1xuY29uc29sZS5sb2coYik7Il19 \ No newline at end of file diff --git a/tests/baselines/reference/inlineSources2.sourcemap.txt b/tests/baselines/reference/inlineSources2.sourcemap.txt new file mode 100644 index 00000000000..e3e14d01e9e --- /dev/null +++ b/tests/baselines/reference/inlineSources2.sourcemap.txt @@ -0,0 +1,114 @@ +=================================================================== +JsFile: out.js +mapUrl: out.js.map +sourceRoot: +sources: tests/cases/compiler/a.ts,tests/cases/compiler/b.ts +sourcesContent: ["\nvar a = 0;\nconsole.log(a);\n","var b = 0;\nconsole.log(b);"] +=================================================================== +------------------------------------------------------------------- +emittedFile:out.js +sourceFile:tests/cases/compiler/a.ts +------------------------------------------------------------------- +>>>var a = 0; +1 > +2 >^^^^ +3 > ^ +4 > ^^^ +5 > ^ +6 > ^ +7 > ^^^^^^-> +1 > + > +2 >var +3 > a +4 > = +5 > 0 +6 > ; +1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) +2 >Emitted(1, 5) Source(2, 5) + SourceIndex(0) +3 >Emitted(1, 6) Source(2, 6) + SourceIndex(0) +4 >Emitted(1, 9) Source(2, 9) + SourceIndex(0) +5 >Emitted(1, 10) Source(2, 10) + SourceIndex(0) +6 >Emitted(1, 11) Source(2, 11) + SourceIndex(0) +--- +>>>console.log(a); +1-> +2 >^^^^^^^ +3 > ^ +4 > ^^^ +5 > ^ +6 > ^ +7 > ^ +8 > ^ +1-> + > +2 >console +3 > . +4 > log +5 > ( +6 > a +7 > ) +8 > ; +1->Emitted(2, 1) Source(3, 1) + SourceIndex(0) +2 >Emitted(2, 8) Source(3, 8) + SourceIndex(0) +3 >Emitted(2, 9) Source(3, 9) + SourceIndex(0) +4 >Emitted(2, 12) Source(3, 12) + SourceIndex(0) +5 >Emitted(2, 13) Source(3, 13) + SourceIndex(0) +6 >Emitted(2, 14) Source(3, 14) + SourceIndex(0) +7 >Emitted(2, 15) Source(3, 15) + SourceIndex(0) +8 >Emitted(2, 16) Source(3, 16) + SourceIndex(0) +--- +------------------------------------------------------------------- +emittedFile:out.js +sourceFile:tests/cases/compiler/b.ts +------------------------------------------------------------------- +>>>var b = 0; +1 > +2 >^^^^ +3 > ^ +4 > ^^^ +5 > ^ +6 > ^ +7 > ^^^^^^-> +1 > +2 >var +3 > b +4 > = +5 > 0 +6 > ; +1 >Emitted(3, 1) Source(1, 1) + SourceIndex(1) +2 >Emitted(3, 5) Source(1, 5) + SourceIndex(1) +3 >Emitted(3, 6) Source(1, 6) + SourceIndex(1) +4 >Emitted(3, 9) Source(1, 9) + SourceIndex(1) +5 >Emitted(3, 10) Source(1, 10) + SourceIndex(1) +6 >Emitted(3, 11) Source(1, 11) + SourceIndex(1) +--- +>>>console.log(b); +1-> +2 >^^^^^^^ +3 > ^ +4 > ^^^ +5 > ^ +6 > ^ +7 > ^ +8 > ^ +9 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1-> + > +2 >console +3 > . +4 > log +5 > ( +6 > b +7 > ) +8 > ; +1->Emitted(4, 1) Source(2, 1) + SourceIndex(1) +2 >Emitted(4, 8) Source(2, 8) + SourceIndex(1) +3 >Emitted(4, 9) Source(2, 9) + SourceIndex(1) +4 >Emitted(4, 12) Source(2, 12) + SourceIndex(1) +5 >Emitted(4, 13) Source(2, 13) + SourceIndex(1) +6 >Emitted(4, 14) Source(2, 14) + SourceIndex(1) +7 >Emitted(4, 15) Source(2, 15) + SourceIndex(1) +8 >Emitted(4, 16) Source(2, 16) + SourceIndex(1) +--- +>>>//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib3V0LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsidGVzdHMvY2FzZXMvY29tcGlsZXIvYS50cyIsInRlc3RzL2Nhc2VzL2NvbXBpbGVyL2IudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQ0EsSUFBSSxDQUFDLEdBQUcsQ0FBQyxDQUFDO0FBQ1YsT0FBTyxDQUFDLEdBQUcsQ0FBQyxDQUFDLENBQUMsQ0FBQztBQ0ZmLElBQUksQ0FBQyxHQUFHLENBQUMsQ0FBQztBQUNWLE9BQU8sQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFDLENBQUMiLCJzb3VyY2VzQ29udGVudCI6WyJcbnZhciBhID0gMDtcbmNvbnNvbGUubG9nKGEpO1xuIiwidmFyIGIgPSAwO1xuY29uc29sZS5sb2coYik7Il19 \ No newline at end of file diff --git a/tests/cases/compiler/inlineSources.ts b/tests/cases/compiler/inlineSources.ts new file mode 100644 index 00000000000..f46eacdb57c --- /dev/null +++ b/tests/cases/compiler/inlineSources.ts @@ -0,0 +1,12 @@ +// @target: ES3 +// @sourcemap: true +// @inlinesources: true +// @out: out.js + +// @filename: a.ts +var a = 0; +console.log(a); + +// @filename: b.ts +var b = 0; +console.log(b); \ No newline at end of file diff --git a/tests/cases/compiler/inlineSources2.ts b/tests/cases/compiler/inlineSources2.ts new file mode 100644 index 00000000000..6fa567dc521 --- /dev/null +++ b/tests/cases/compiler/inlineSources2.ts @@ -0,0 +1,12 @@ +// @target: ES3 +// @inlinesourcemap: true +// @inlinesources: true +// @out: out.js + +// @filename: a.ts +var a = 0; +console.log(a); + +// @filename: b.ts +var b = 0; +console.log(b); \ No newline at end of file From 767d76241a75033be9d9285696879eb271562ec6 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Tue, 21 Apr 2015 06:49:31 -0700 Subject: [PATCH 051/194] added comments, fixed typo --- src/compiler/emitter.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index b6ebf566fa0..016f392580b 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2046,11 +2046,12 @@ var __param = this.__param || function(index, decorator) { return function (targ } else { const exportChanged = - node.operatorToken.kind <= SyntaxKind.LastAssignment && + node.operatorToken.kind >= SyntaxKind.FirstAssignment && node.operatorToken.kind <= SyntaxKind.LastAssignment && isNameOfExportedSourceLevelDeclarationInSystemExternalModule(node.left); if (exportChanged) { + // emit assignment 'x y' as 'exports("x", x y)' write(`${exportFunctionForFile}("`); emitNodeWithoutSourceMap(node.left); write(`", `); From 3f7e64661d742fc03d51acc9b4b69a538a5b9603 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Tue, 21 Apr 2015 08:31:14 -0700 Subject: [PATCH 052/194] do not hoist non-top level block scoped variables --- src/compiler/emitter.ts | 47 +++++++++++-------- tests/baselines/reference/systemModule8.js | 12 ++++- .../baselines/reference/systemModule8.symbols | 28 +++++++---- tests/baselines/reference/systemModule8.types | 20 ++++++++ tests/cases/compiler/systemModule8.ts | 4 ++ 5 files changed, 82 insertions(+), 29 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 016f392580b..d7b5aa61f93 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2190,8 +2190,9 @@ var __param = this.__param || function(index, decorator) { return function (targ emitEmbeddedStatement(node.statement); } - function emitStartOfVariableDeclarationList(decl: Node, startPos?: number): boolean { - if (isSourceFileLevelDeclarationInSystemExternalModule(decl, /*isExported*/ false)) { + function emitStartOfVariableDeclarationList(decl: VariableDeclarationList, startPos?: number): boolean { + if (shouldHoistVariable(decl, /*checkIfSourceFileLevelDecl*/ true)) { + // variables in variable declaration list were already hoisted return false; } @@ -2252,10 +2253,9 @@ var __param = this.__param || function(index, decorator) { return function (targ endPos = emitToken(SyntaxKind.OpenParenToken, endPos); if (node.initializer && node.initializer.kind === SyntaxKind.VariableDeclarationList) { let variableDeclarationList = node.initializer; - let declarations = variableDeclarationList.declarations; - let startIsEmitted = emitStartOfVariableDeclarationList(declarations[0], endPos); + let startIsEmitted = emitStartOfVariableDeclarationList(variableDeclarationList, endPos); if (startIsEmitted) { - emitCommaList(declarations); + emitCommaList(variableDeclarationList.declarations); } else { emitVariableDeclarationListSkippingUninitializedEntries(variableDeclarationList); @@ -2283,9 +2283,8 @@ var __param = this.__param || function(index, decorator) { return function (targ if (node.initializer.kind === SyntaxKind.VariableDeclarationList) { let variableDeclarationList = node.initializer; if (variableDeclarationList.declarations.length >= 1) { - let decl = variableDeclarationList.declarations[0]; - emitStartOfVariableDeclarationList(decl, endPos); - emit(decl); + emitStartOfVariableDeclarationList(variableDeclarationList, endPos); + emit(variableDeclarationList.declarations[0]); } } else { @@ -2998,10 +2997,6 @@ var __param = this.__param || function(index, decorator) { return function (targ if (resolver.resolvesToSomeValue(parent, (node).text)) { let variableId = resolver.getBlockScopedVariableId(node); - if (blockScopedVariableToGeneratedName && blockScopedVariableToGeneratedName[variableId]) { - // already renamed - return; - } if (!blockScopedVariableToGeneratedName) { blockScopedVariableToGeneratedName = []; } @@ -4983,13 +4978,14 @@ var __param = this.__param || function(index, decorator) { return function (targ } if (node.kind === SyntaxKind.VariableDeclaration || node.kind === SyntaxKind.BindingElement) { - let name = (node).name; - if (name.kind === SyntaxKind.Identifier) { - renameNonTopLevelLetAndConst(name); - (hoistedVars || (hoistedVars = [])).push(name); - } - else { - forEachChild(name, visit); + if (shouldHoistVariable(node, /*checkIfSourceFileLevelDecl*/ false)) { + let name = (node).name; + if (name.kind === SyntaxKind.Identifier) { + (hoistedVars || (hoistedVars = [])).push(name); + } + else { + forEachChild(name, visit); + } } return; } @@ -5005,6 +5001,19 @@ var __param = this.__param || function(index, decorator) { return function (targ } } + function shouldHoistVariable(node: VariableDeclaration | VariableDeclarationList | BindingElement, checkIfSourceFileLevelDecl: boolean): boolean { + if (checkIfSourceFileLevelDecl && !isSourceFileLevelDeclarationInSystemExternalModule(node, /*isExported*/ false)) { + return false; + } + // hoist variable if + // - it is not block scoped + // - it is top level block scoped + // if block scoped variables are nested in some another block then + // no other functions can use them except ones that are defined at least in the same block + return (getCombinedNodeFlags(node) & NodeFlags.BlockScoped) === 0 || + getEnclosingBlockScopeContainer(node).kind === SyntaxKind.SourceFile; + } + function isCurrentFileSystemExternalModule() { return compilerOptions.module === ModuleKind.System && isExternalModule(currentSourceFile); } diff --git a/tests/baselines/reference/systemModule8.js b/tests/baselines/reference/systemModule8.js index e4ee68a1bb1..578814d0ab2 100644 --- a/tests/baselines/reference/systemModule8.js +++ b/tests/baselines/reference/systemModule8.js @@ -12,6 +12,10 @@ x *= 1; x /= 1; x |= 1; x &= 1; +x + 1; +x - 1; +x & 1; +x | 1; for (x = 5;;x++) {} for (x = 8;;x--) {} for (x = 15;;++x) {} @@ -28,7 +32,7 @@ for ([x] of [[1]]) {} //// [systemModule8.js] System.register([], function(exports_1) { - var x, x_1, y, z0, z1; + var x, y, z0, z1; function foo() { exports_1("x", x = 100); } @@ -47,11 +51,15 @@ System.register([], function(exports_1) { exports_1("x", x /= 1); exports_1("x", x |= 1); exports_1("x", x &= 1); + x + 1; + x - 1; + x & 1; + x | 1; for (exports_1("x", x = 5);; (exports_1("x", ++x) - 1)) { } for (exports_1("x", x = 8);; (exports_1("x", --x) + 1)) { } for (exports_1("x", x = 15);; exports_1("x", ++x)) { } for (exports_1("x", x = 18);; exports_1("x", --x)) { } - for (x_1 = 50;;) { } + for (var x_1 = 50;;) { } exports_1("y", y = [1][0]); _a = { a: true, b: { c: "123" } }, exports_1("z0", z0 = _a.a), exports_1("z1", z1 = _a.b.c); for (var _i = 0, _b = [[1]]; _i < _b.length; _i++) { diff --git a/tests/baselines/reference/systemModule8.symbols b/tests/baselines/reference/systemModule8.symbols index 14f5bc7e94c..3365ce7e37d 100644 --- a/tests/baselines/reference/systemModule8.symbols +++ b/tests/baselines/reference/systemModule8.symbols @@ -36,6 +36,18 @@ x |= 1; x &= 1; >x : Symbol(x, Decl(systemModule8.ts, 1, 10)) +x + 1; +>x : Symbol(x, Decl(systemModule8.ts, 1, 10)) + +x - 1; +>x : Symbol(x, Decl(systemModule8.ts, 1, 10)) + +x & 1; +>x : Symbol(x, Decl(systemModule8.ts, 1, 10)) + +x | 1; +>x : Symbol(x, Decl(systemModule8.ts, 1, 10)) + for (x = 5;;x++) {} >x : Symbol(x, Decl(systemModule8.ts, 1, 10)) >x : Symbol(x, Decl(systemModule8.ts, 1, 10)) @@ -53,24 +65,24 @@ for (x = 18;;--x) {} >x : Symbol(x, Decl(systemModule8.ts, 1, 10)) for (let x = 50;;) {} ->x : Symbol(x, Decl(systemModule8.ts, 18, 8)) +>x : Symbol(x, Decl(systemModule8.ts, 22, 8)) function foo() { ->foo : Symbol(foo, Decl(systemModule8.ts, 18, 21)) +>foo : Symbol(foo, Decl(systemModule8.ts, 22, 21)) x = 100; >x : Symbol(x, Decl(systemModule8.ts, 1, 10)) } export let [y] = [1]; ->y : Symbol(y, Decl(systemModule8.ts, 23, 12)) +>y : Symbol(y, Decl(systemModule8.ts, 27, 12)) export const {a: z0, b: {c: z1}} = {a: true, b: {c: "123"}}; ->z0 : Symbol(z0, Decl(systemModule8.ts, 24, 14)) ->z1 : Symbol(z1, Decl(systemModule8.ts, 24, 25)) ->a : Symbol(a, Decl(systemModule8.ts, 24, 36)) ->b : Symbol(b, Decl(systemModule8.ts, 24, 44)) ->c : Symbol(c, Decl(systemModule8.ts, 24, 49)) +>z0 : Symbol(z0, Decl(systemModule8.ts, 28, 14)) +>z1 : Symbol(z1, Decl(systemModule8.ts, 28, 25)) +>a : Symbol(a, Decl(systemModule8.ts, 28, 36)) +>b : Symbol(b, Decl(systemModule8.ts, 28, 44)) +>c : Symbol(c, Decl(systemModule8.ts, 28, 49)) for ([x] of [[1]]) {} >x : Symbol(x, Decl(systemModule8.ts, 1, 10)) diff --git a/tests/baselines/reference/systemModule8.types b/tests/baselines/reference/systemModule8.types index 39f2ac4104e..2c3dd1e48bb 100644 --- a/tests/baselines/reference/systemModule8.types +++ b/tests/baselines/reference/systemModule8.types @@ -54,6 +54,26 @@ x &= 1; >x : any >1 : number +x + 1; +>x + 1 : any +>x : any +>1 : number + +x - 1; +>x - 1 : number +>x : any +>1 : number + +x & 1; +>x & 1 : number +>x : any +>1 : number + +x | 1; +>x | 1 : number +>x : any +>1 : number + for (x = 5;;x++) {} >x = 5 : number >x : any diff --git a/tests/cases/compiler/systemModule8.ts b/tests/cases/compiler/systemModule8.ts index fb75c43df56..c3e0c7c7437 100644 --- a/tests/cases/compiler/systemModule8.ts +++ b/tests/cases/compiler/systemModule8.ts @@ -12,6 +12,10 @@ x *= 1; x /= 1; x |= 1; x &= 1; +x + 1; +x - 1; +x & 1; +x | 1; for (x = 5;;x++) {} for (x = 8;;x--) {} for (x = 15;;++x) {} From ed9dceb50130f8ee562c76c1a665b5cc0179166d Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 21 Apr 2015 11:19:44 -0700 Subject: [PATCH 053/194] Defer resolution of declared members in classes and interfaces --- src/compiler/checker.ts | 65 +++++++++++++++++------------------------ src/compiler/types.ts | 10 +++---- 2 files changed, 31 insertions(+), 44 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d5e5b5c67e4..261924dd9a4 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2516,10 +2516,11 @@ module ts { } } - function getDeclaredTypeOfClass(symbol: Symbol): InterfaceType { + function getDeclaredTypeOfClassOrInterface(symbol: Symbol): InterfaceType { let links = getSymbolLinks(symbol); if (!links.declaredType) { - let type = links.declaredType = createObjectType(TypeFlags.Class, symbol); + let kind = symbol.flags & SymbolFlags.Class ? TypeFlags.Class : TypeFlags.Interface; + let type = links.declaredType = createObjectType(kind, symbol); let typeParameters = getTypeParametersOfClassOrInterface(symbol); if (typeParameters) { type.flags |= TypeFlags.Reference; @@ -2529,35 +2530,6 @@ module ts { (type).target = type; (type).typeArguments = type.typeParameters; } - - type.declaredProperties = getNamedMembers(symbol.members); - type.declaredCallSignatures = emptyArray; - type.declaredConstructSignatures = emptyArray; - type.declaredStringIndexType = getIndexTypeOfSymbol(symbol, IndexKind.String); - type.declaredNumberIndexType = getIndexTypeOfSymbol(symbol, IndexKind.Number); - } - return links.declaredType; - } - - function getDeclaredTypeOfInterface(symbol: Symbol): InterfaceType { - let links = getSymbolLinks(symbol); - if (!links.declaredType) { - let type = links.declaredType = createObjectType(TypeFlags.Interface, symbol); - let typeParameters = getTypeParametersOfClassOrInterface(symbol); - if (typeParameters) { - type.flags |= TypeFlags.Reference; - type.typeParameters = typeParameters; - (type).instantiations = {}; - (type).instantiations[getTypeListId(type.typeParameters)] = type; - (type).target = type; - (type).typeArguments = type.typeParameters; - } - - type.declaredProperties = getNamedMembers(symbol.members); - type.declaredCallSignatures = getSignaturesOfSymbol(symbol.members["__call"]); - type.declaredConstructSignatures = getSignaturesOfSymbol(symbol.members["__new"]); - type.declaredStringIndexType = getIndexTypeOfSymbol(symbol, IndexKind.String); - type.declaredNumberIndexType = getIndexTypeOfSymbol(symbol, IndexKind.Number); } return links.declaredType; } @@ -2613,11 +2585,8 @@ module ts { function getDeclaredTypeOfSymbol(symbol: Symbol): Type { Debug.assert((symbol.flags & SymbolFlags.Instantiated) === 0); - if (symbol.flags & SymbolFlags.Class) { - return getDeclaredTypeOfClass(symbol); - } - if (symbol.flags & SymbolFlags.Interface) { - return getDeclaredTypeOfInterface(symbol); + if (symbol.flags & (SymbolFlags.Class | SymbolFlags.Interface)) { + return getDeclaredTypeOfClassOrInterface(symbol); } if (symbol.flags & SymbolFlags.TypeAlias) { return getDeclaredTypeOfTypeAlias(symbol); @@ -2666,7 +2635,24 @@ module ts { } } + function getDeclaredPropertiesOfClassOrInterface(type: InterfaceType): Symbol[] { + resolveDeclaredMembers(type); + return type.declaredProperties; + } + + function resolveDeclaredMembers(type: InterfaceType) { + if (!type.declaredProperties) { + var symbol = type.symbol; + type.declaredProperties = getNamedMembers(symbol.members); + type.declaredCallSignatures = getSignaturesOfSymbol(symbol.members["__call"]); + type.declaredConstructSignatures = getSignaturesOfSymbol(symbol.members["__new"]); + type.declaredStringIndexType = getIndexTypeOfSymbol(symbol, IndexKind.String); + type.declaredNumberIndexType = getIndexTypeOfSymbol(symbol, IndexKind.Number); + } + } + function resolveClassOrInterfaceMembers(type: InterfaceType): void { + resolveDeclaredMembers(type); let members = type.symbol.members; let callSignatures = type.declaredCallSignatures; let constructSignatures = type.declaredConstructSignatures; @@ -2688,6 +2674,7 @@ module ts { function resolveTypeReferenceMembers(type: TypeReference): void { let target = type.target; + resolveDeclaredMembers(target); let mapper = createTypeMapper(target.typeParameters, type.typeArguments); let members = createInstantiatedSymbolTable(target.declaredProperties, mapper); let callSignatures = instantiateList(target.declaredCallSignatures, mapper, instantiateSignature); @@ -2843,7 +2830,7 @@ module ts { callSignatures = getSignaturesOfSymbol(symbol); } if (symbol.flags & SymbolFlags.Class) { - let classType = getDeclaredTypeOfClass(symbol); + let classType = getDeclaredTypeOfClassOrInterface(symbol); constructSignatures = getSignaturesOfSymbol(symbol.members["__constructor"]); if (!constructSignatures.length) { constructSignatures = getDefaultConstructSignatures(classType); @@ -3084,7 +3071,7 @@ module ts { function getSignatureFromDeclaration(declaration: SignatureDeclaration): Signature { let links = getNodeLinks(declaration); if (!links.resolvedSignature) { - let classType = declaration.kind === SyntaxKind.Constructor ? getDeclaredTypeOfClass((declaration.parent).symbol) : undefined; + let classType = declaration.kind === SyntaxKind.Constructor ? getDeclaredTypeOfClassOrInterface((declaration.parent).symbol) : undefined; let typeParameters = classType ? classType.typeParameters : declaration.typeParameters ? getTypeParametersFromDeclaration(declaration.typeParameters) : undefined; let parameters: Symbol[] = []; @@ -10152,7 +10139,7 @@ module ts { } let seen: Map<{ prop: Symbol; containingType: Type }> = {}; - forEach(type.declaredProperties, p => { seen[p.name] = { prop: p, containingType: type }; }); + forEach(getDeclaredPropertiesOfClassOrInterface(type), p => { seen[p.name] = { prop: p, containingType: type }; }); let ok = true; for (let base of baseTypes) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index bff15a1ab9d..54f2e5e2bd4 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1485,11 +1485,11 @@ module ts { // Class and interface types (TypeFlags.Class and TypeFlags.Interface) export interface InterfaceType extends ObjectType { typeParameters: TypeParameter[]; // Type parameters (undefined if non-generic) - declaredProperties: Symbol[]; // Declared members - declaredCallSignatures: Signature[]; // Declared call signatures - declaredConstructSignatures: Signature[]; // Declared construct signatures - declaredStringIndexType: Type; // Declared string index type - declaredNumberIndexType: Type; // Declared numeric index type + declaredProperties: Symbol[]; // Declared members (computed by resolveDeclaredMembers) + declaredCallSignatures: Signature[]; // Declared call signatures (computed by resolveDeclaredMembers) + declaredConstructSignatures: Signature[]; // Declared construct signatures (computed by resolveDeclaredMembers) + declaredStringIndexType: Type; // Declared string index type (computed by resolveDeclaredMembers) + declaredNumberIndexType: Type; // Declared numeric index type (computed by resolveDeclaredMembers) } export interface InterfaceTypeWithBaseTypes extends InterfaceType { From 8182b7132ef0df3a0856793578296a6a6a1d1fac Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 21 Apr 2015 11:20:43 -0700 Subject: [PATCH 054/194] Adding tests --- .../circularTypeAliasForUnionWithClass.js | 39 +++++++++ .../circularTypeAliasForUnionWithClass.types | 49 ++++++++++++ .../circularTypeAliasForUnionWithInterface.js | 38 +++++++++ ...rcularTypeAliasForUnionWithInterface.types | 79 +++++++++++++++++++ .../circularTypeAliasForUnionWithClass.ts | 17 ++++ .../circularTypeAliasForUnionWithInterface.ts | 29 +++++++ 6 files changed, 251 insertions(+) create mode 100644 tests/baselines/reference/circularTypeAliasForUnionWithClass.js create mode 100644 tests/baselines/reference/circularTypeAliasForUnionWithClass.types create mode 100644 tests/baselines/reference/circularTypeAliasForUnionWithInterface.js create mode 100644 tests/baselines/reference/circularTypeAliasForUnionWithInterface.types create mode 100644 tests/cases/conformance/types/typeAliases/circularTypeAliasForUnionWithClass.ts create mode 100644 tests/cases/conformance/types/typeAliases/circularTypeAliasForUnionWithInterface.ts diff --git a/tests/baselines/reference/circularTypeAliasForUnionWithClass.js b/tests/baselines/reference/circularTypeAliasForUnionWithClass.js new file mode 100644 index 00000000000..90a11364897 --- /dev/null +++ b/tests/baselines/reference/circularTypeAliasForUnionWithClass.js @@ -0,0 +1,39 @@ +//// [circularTypeAliasForUnionWithClass.ts] +var v0: T0; +type T0 = string | I0; +class I0 { + x: T0; +} + +var v3: T3; +type T3 = string | I3; +class I3 { + [x: number]: T3; +} + +var v4: T4; +type T4 = string | I4; +class I4 { + [x: string]: T4; +} + + +//// [circularTypeAliasForUnionWithClass.js] +var v0; +var I0 = (function () { + function I0() { + } + return I0; +})(); +var v3; +var I3 = (function () { + function I3() { + } + return I3; +})(); +var v4; +var I4 = (function () { + function I4() { + } + return I4; +})(); diff --git a/tests/baselines/reference/circularTypeAliasForUnionWithClass.types b/tests/baselines/reference/circularTypeAliasForUnionWithClass.types new file mode 100644 index 00000000000..99a05f3d66a --- /dev/null +++ b/tests/baselines/reference/circularTypeAliasForUnionWithClass.types @@ -0,0 +1,49 @@ +=== tests/cases/conformance/types/typeAliases/circularTypeAliasForUnionWithClass.ts === +var v0: T0; +>v0 : string | I0 +>T0 : string | I0 + +type T0 = string | I0; +>T0 : string | I0 +>I0 : I0 + +class I0 { +>I0 : I0 + + x: T0; +>x : string | I0 +>T0 : string | I0 +} + +var v3: T3; +>v3 : string | I3 +>T3 : string | I3 + +type T3 = string | I3; +>T3 : string | I3 +>I3 : I3 + +class I3 { +>I3 : I3 + + [x: number]: T3; +>x : number +>T3 : string | I3 +} + +var v4: T4; +>v4 : string | I4 +>T4 : string | I4 + +type T4 = string | I4; +>T4 : string | I4 +>I4 : I4 + +class I4 { +>I4 : I4 + + [x: string]: T4; +>x : string +>T4 : string | I4 +} + diff --git a/tests/baselines/reference/circularTypeAliasForUnionWithInterface.js b/tests/baselines/reference/circularTypeAliasForUnionWithInterface.js new file mode 100644 index 00000000000..60f4df9a8b6 --- /dev/null +++ b/tests/baselines/reference/circularTypeAliasForUnionWithInterface.js @@ -0,0 +1,38 @@ +//// [circularTypeAliasForUnionWithInterface.ts] +var v0: T0; +type T0 = string | I0; +interface I0 { + x: T0; +} + +var v1: T1; +type T1 = string | I1; +interface I1 { + (): T1; +} + +var v2: T2; +type T2 = string | I2; +interface I2 { + new (): T2; +} + +var v3: T3; +type T3 = string | I3; +interface I3 { + [x: number]: T3; +} + +var v4: T4; +type T4 = string | I4; +interface I4 { + [x: string]: T4; +} + + +//// [circularTypeAliasForUnionWithInterface.js] +var v0; +var v1; +var v2; +var v3; +var v4; diff --git a/tests/baselines/reference/circularTypeAliasForUnionWithInterface.types b/tests/baselines/reference/circularTypeAliasForUnionWithInterface.types new file mode 100644 index 00000000000..4325f9c774a --- /dev/null +++ b/tests/baselines/reference/circularTypeAliasForUnionWithInterface.types @@ -0,0 +1,79 @@ +=== tests/cases/conformance/types/typeAliases/circularTypeAliasForUnionWithInterface.ts === +var v0: T0; +>v0 : string | I0 +>T0 : string | I0 + +type T0 = string | I0; +>T0 : string | I0 +>I0 : I0 + +interface I0 { +>I0 : I0 + + x: T0; +>x : string | I0 +>T0 : string | I0 +} + +var v1: T1; +>v1 : string | I1 +>T1 : string | I1 + +type T1 = string | I1; +>T1 : string | I1 +>I1 : I1 + +interface I1 { +>I1 : I1 + + (): T1; +>T1 : string | I1 +} + +var v2: T2; +>v2 : string | I2 +>T2 : string | I2 + +type T2 = string | I2; +>T2 : string | I2 +>I2 : I2 + +interface I2 { +>I2 : I2 + + new (): T2; +>T2 : string | I2 +} + +var v3: T3; +>v3 : string | I3 +>T3 : string | I3 + +type T3 = string | I3; +>T3 : string | I3 +>I3 : I3 + +interface I3 { +>I3 : I3 + + [x: number]: T3; +>x : number +>T3 : string | I3 +} + +var v4: T4; +>v4 : string | I4 +>T4 : string | I4 + +type T4 = string | I4; +>T4 : string | I4 +>I4 : I4 + +interface I4 { +>I4 : I4 + + [x: string]: T4; +>x : string +>T4 : string | I4 +} + diff --git a/tests/cases/conformance/types/typeAliases/circularTypeAliasForUnionWithClass.ts b/tests/cases/conformance/types/typeAliases/circularTypeAliasForUnionWithClass.ts new file mode 100644 index 00000000000..e7cca719f4b --- /dev/null +++ b/tests/cases/conformance/types/typeAliases/circularTypeAliasForUnionWithClass.ts @@ -0,0 +1,17 @@ +var v0: T0; +type T0 = string | I0; +class I0 { + x: T0; +} + +var v3: T3; +type T3 = string | I3; +class I3 { + [x: number]: T3; +} + +var v4: T4; +type T4 = string | I4; +class I4 { + [x: string]: T4; +} diff --git a/tests/cases/conformance/types/typeAliases/circularTypeAliasForUnionWithInterface.ts b/tests/cases/conformance/types/typeAliases/circularTypeAliasForUnionWithInterface.ts new file mode 100644 index 00000000000..c3eab454384 --- /dev/null +++ b/tests/cases/conformance/types/typeAliases/circularTypeAliasForUnionWithInterface.ts @@ -0,0 +1,29 @@ +var v0: T0; +type T0 = string | I0; +interface I0 { + x: T0; +} + +var v1: T1; +type T1 = string | I1; +interface I1 { + (): T1; +} + +var v2: T2; +type T2 = string | I2; +interface I2 { + new (): T2; +} + +var v3: T3; +type T3 = string | I3; +interface I3 { + [x: number]: T3; +} + +var v4: T4; +type T4 = string | I4; +interface I4 { + [x: string]: T4; +} From cd48b965f88223f39f019131ff22b4db08e56cfc Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 21 Apr 2015 12:08:42 -0700 Subject: [PATCH 055/194] Accepting new baselines --- ...circularTypeAliasForUnionWithClass.symbols | 49 ++++++++++++ ...ularTypeAliasForUnionWithInterface.symbols | 79 +++++++++++++++++++ 2 files changed, 128 insertions(+) create mode 100644 tests/baselines/reference/circularTypeAliasForUnionWithClass.symbols create mode 100644 tests/baselines/reference/circularTypeAliasForUnionWithInterface.symbols diff --git a/tests/baselines/reference/circularTypeAliasForUnionWithClass.symbols b/tests/baselines/reference/circularTypeAliasForUnionWithClass.symbols new file mode 100644 index 00000000000..ecfba63332d --- /dev/null +++ b/tests/baselines/reference/circularTypeAliasForUnionWithClass.symbols @@ -0,0 +1,49 @@ +=== tests/cases/conformance/types/typeAliases/circularTypeAliasForUnionWithClass.ts === +var v0: T0; +>v0 : Symbol(v0, Decl(circularTypeAliasForUnionWithClass.ts, 0, 3)) +>T0 : Symbol(T0, Decl(circularTypeAliasForUnionWithClass.ts, 0, 11)) + +type T0 = string | I0; +>T0 : Symbol(T0, Decl(circularTypeAliasForUnionWithClass.ts, 0, 11)) +>I0 : Symbol(I0, Decl(circularTypeAliasForUnionWithClass.ts, 1, 22)) + +class I0 { +>I0 : Symbol(I0, Decl(circularTypeAliasForUnionWithClass.ts, 1, 22)) + + x: T0; +>x : Symbol(x, Decl(circularTypeAliasForUnionWithClass.ts, 2, 10)) +>T0 : Symbol(T0, Decl(circularTypeAliasForUnionWithClass.ts, 0, 11)) +} + +var v3: T3; +>v3 : Symbol(v3, Decl(circularTypeAliasForUnionWithClass.ts, 6, 3)) +>T3 : Symbol(T3, Decl(circularTypeAliasForUnionWithClass.ts, 6, 11)) + +type T3 = string | I3; +>T3 : Symbol(T3, Decl(circularTypeAliasForUnionWithClass.ts, 6, 11)) +>I3 : Symbol(I3, Decl(circularTypeAliasForUnionWithClass.ts, 7, 22)) + +class I3 { +>I3 : Symbol(I3, Decl(circularTypeAliasForUnionWithClass.ts, 7, 22)) + + [x: number]: T3; +>x : Symbol(x, Decl(circularTypeAliasForUnionWithClass.ts, 9, 5)) +>T3 : Symbol(T3, Decl(circularTypeAliasForUnionWithClass.ts, 6, 11)) +} + +var v4: T4; +>v4 : Symbol(v4, Decl(circularTypeAliasForUnionWithClass.ts, 12, 3)) +>T4 : Symbol(T4, Decl(circularTypeAliasForUnionWithClass.ts, 12, 11)) + +type T4 = string | I4; +>T4 : Symbol(T4, Decl(circularTypeAliasForUnionWithClass.ts, 12, 11)) +>I4 : Symbol(I4, Decl(circularTypeAliasForUnionWithClass.ts, 13, 22)) + +class I4 { +>I4 : Symbol(I4, Decl(circularTypeAliasForUnionWithClass.ts, 13, 22)) + + [x: string]: T4; +>x : Symbol(x, Decl(circularTypeAliasForUnionWithClass.ts, 15, 5)) +>T4 : Symbol(T4, Decl(circularTypeAliasForUnionWithClass.ts, 12, 11)) +} + diff --git a/tests/baselines/reference/circularTypeAliasForUnionWithInterface.symbols b/tests/baselines/reference/circularTypeAliasForUnionWithInterface.symbols new file mode 100644 index 00000000000..29bc3098d91 --- /dev/null +++ b/tests/baselines/reference/circularTypeAliasForUnionWithInterface.symbols @@ -0,0 +1,79 @@ +=== tests/cases/conformance/types/typeAliases/circularTypeAliasForUnionWithInterface.ts === +var v0: T0; +>v0 : Symbol(v0, Decl(circularTypeAliasForUnionWithInterface.ts, 0, 3)) +>T0 : Symbol(T0, Decl(circularTypeAliasForUnionWithInterface.ts, 0, 11)) + +type T0 = string | I0; +>T0 : Symbol(T0, Decl(circularTypeAliasForUnionWithInterface.ts, 0, 11)) +>I0 : Symbol(I0, Decl(circularTypeAliasForUnionWithInterface.ts, 1, 22)) + +interface I0 { +>I0 : Symbol(I0, Decl(circularTypeAliasForUnionWithInterface.ts, 1, 22)) + + x: T0; +>x : Symbol(x, Decl(circularTypeAliasForUnionWithInterface.ts, 2, 14)) +>T0 : Symbol(T0, Decl(circularTypeAliasForUnionWithInterface.ts, 0, 11)) +} + +var v1: T1; +>v1 : Symbol(v1, Decl(circularTypeAliasForUnionWithInterface.ts, 6, 3)) +>T1 : Symbol(T1, Decl(circularTypeAliasForUnionWithInterface.ts, 6, 11)) + +type T1 = string | I1; +>T1 : Symbol(T1, Decl(circularTypeAliasForUnionWithInterface.ts, 6, 11)) +>I1 : Symbol(I1, Decl(circularTypeAliasForUnionWithInterface.ts, 7, 22)) + +interface I1 { +>I1 : Symbol(I1, Decl(circularTypeAliasForUnionWithInterface.ts, 7, 22)) + + (): T1; +>T1 : Symbol(T1, Decl(circularTypeAliasForUnionWithInterface.ts, 6, 11)) +} + +var v2: T2; +>v2 : Symbol(v2, Decl(circularTypeAliasForUnionWithInterface.ts, 12, 3)) +>T2 : Symbol(T2, Decl(circularTypeAliasForUnionWithInterface.ts, 12, 11)) + +type T2 = string | I2; +>T2 : Symbol(T2, Decl(circularTypeAliasForUnionWithInterface.ts, 12, 11)) +>I2 : Symbol(I2, Decl(circularTypeAliasForUnionWithInterface.ts, 13, 22)) + +interface I2 { +>I2 : Symbol(I2, Decl(circularTypeAliasForUnionWithInterface.ts, 13, 22)) + + new (): T2; +>T2 : Symbol(T2, Decl(circularTypeAliasForUnionWithInterface.ts, 12, 11)) +} + +var v3: T3; +>v3 : Symbol(v3, Decl(circularTypeAliasForUnionWithInterface.ts, 18, 3)) +>T3 : Symbol(T3, Decl(circularTypeAliasForUnionWithInterface.ts, 18, 11)) + +type T3 = string | I3; +>T3 : Symbol(T3, Decl(circularTypeAliasForUnionWithInterface.ts, 18, 11)) +>I3 : Symbol(I3, Decl(circularTypeAliasForUnionWithInterface.ts, 19, 22)) + +interface I3 { +>I3 : Symbol(I3, Decl(circularTypeAliasForUnionWithInterface.ts, 19, 22)) + + [x: number]: T3; +>x : Symbol(x, Decl(circularTypeAliasForUnionWithInterface.ts, 21, 5)) +>T3 : Symbol(T3, Decl(circularTypeAliasForUnionWithInterface.ts, 18, 11)) +} + +var v4: T4; +>v4 : Symbol(v4, Decl(circularTypeAliasForUnionWithInterface.ts, 24, 3)) +>T4 : Symbol(T4, Decl(circularTypeAliasForUnionWithInterface.ts, 24, 11)) + +type T4 = string | I4; +>T4 : Symbol(T4, Decl(circularTypeAliasForUnionWithInterface.ts, 24, 11)) +>I4 : Symbol(I4, Decl(circularTypeAliasForUnionWithInterface.ts, 25, 22)) + +interface I4 { +>I4 : Symbol(I4, Decl(circularTypeAliasForUnionWithInterface.ts, 25, 22)) + + [x: string]: T4; +>x : Symbol(x, Decl(circularTypeAliasForUnionWithInterface.ts, 27, 5)) +>T4 : Symbol(T4, Decl(circularTypeAliasForUnionWithInterface.ts, 24, 11)) +} + From 80ae52b7e9f70a2595cc64f9888d77ced4b58459 Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Tue, 21 Apr 2015 13:24:02 -0700 Subject: [PATCH 056/194] expose the config file processing throught the LS and add a callback to enumerate files in a directory --- src/compiler/commandLineParser.ts | 4 +-- src/compiler/tsc.ts | 2 +- src/compiler/types.ts | 4 +++ src/harness/harnessLanguageService.ts | 8 ++++- src/server/editorServices.ts | 2 +- src/services/shims.ts | 49 ++++++++++++++++++++++++--- 6 files changed, 59 insertions(+), 10 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 8169421ca17..fc1293d6040 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -292,7 +292,7 @@ module ts { * @param basePath A root directory to resolve relative path entries in the config * file to. e.g. outDir */ - export function parseConfigFile(json: any, basePath?: string): ParsedCommandLine { + export function parseConfigFile(json: any, host: ParseConfigHost, basePath?: string): ParsedCommandLine { var errors: Diagnostic[] = []; return { @@ -351,7 +351,7 @@ module ts { } } else { - var sysFiles = sys.readDirectory(basePath, ".ts"); + var sysFiles = host.readDirectory(basePath, ".ts"); for (var i = 0; i < sysFiles.length; i++) { var name = sysFiles[i]; if (!fileExtensionIs(name, ".d.ts") || !contains(sysFiles, name.substr(0, name.length - 5) + ".ts")) { diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 0cbeff8204a..7eb86efbfae 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -213,7 +213,7 @@ module ts { reportDiagnostic(createCompilerDiagnostic(Diagnostics.Unable_to_open_file_0, configFileName)); return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); } - var configParseResult = parseConfigFile(configObject, getDirectoryPath(configFileName)); + var configParseResult = parseConfigFile(configObject, sys, getDirectoryPath(configFileName)); if (configParseResult.errors.length > 0) { reportDiagnostics(configParseResult.errors); return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 9191a6999bf..7decd8bd215 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1032,6 +1032,10 @@ module ts { getCurrentDirectory(): string; } + export interface ParseConfigHost { + readDirectory(rootDir: string, extension: string): string[]; + } + export interface WriteFileCallback { (fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void): void; } diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index bce4c9828fa..e7c60e4d862 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -186,6 +186,7 @@ module Harness.LanguageService { var script = this.getScriptInfo(fileName); return script ? script.version.toString() : undefined; } + log(s: string): void { } trace(s: string): void { } error(s: string): void { } @@ -203,7 +204,7 @@ module Harness.LanguageService { } /// Shim adapter - class ShimLanguageServiceHost extends LanguageServiceAdapterHost implements ts.LanguageServiceShimHost { + class ShimLanguageServiceHost extends LanguageServiceAdapterHost implements ts.LanguageServiceShimHost, ts.CoreServicesShimHost { private nativeHost: NativeLanguageServiceHost; constructor(cancellationToken?: ts.CancellationToken, options?: ts.CompilerOptions) { super(cancellationToken, options); @@ -227,6 +228,11 @@ module Harness.LanguageService { } getScriptVersion(fileName: string): string { return this.nativeHost.getScriptVersion(fileName); } getLocalizedDiagnosticMessages(): string { return JSON.stringify({}); } + + readDirectory(rootDir: string, extension: string): string { + throw new Error("NYI"); + } + log(s: string): void { this.nativeHost.log(s); } trace(s: string): void { this.nativeHost.trace(s); } error(s: string): void { this.nativeHost.error(s); } diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 8b4ab2cffa8..9ed31c91968 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -910,7 +910,7 @@ module ts.server { return { errorMsg: "tsconfig syntax error" }; } else { - var parsedCommandLine = ts.parseConfigFile(rawConfig, dirPath); + var parsedCommandLine = ts.parseConfigFile(rawConfig, ts.sys, dirPath); if (parsedCommandLine.errors && (parsedCommandLine.errors.length > 0)) { return { errorMsg: "tsconfig option errors" }; } diff --git a/src/services/shims.ts b/src/services/shims.ts index 110090daf5c..a8de3b817c4 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -57,6 +57,12 @@ module ts { getNewLine?(): string; } + /** Public interface of the the of a config service shim instance.*/ + export interface CoreServicesShimHost extends Logger { + /** Returns a JSON-encoded value of the type: string[] */ + readDirectory(rootDir: string, extension: string): string; + } + /// /// Pre-processing /// @@ -77,7 +83,7 @@ module ts { export interface Shim { dispose(dummy: any): void; } - + export interface LanguageServiceShim extends Shim { languageService: LanguageService; @@ -188,6 +194,7 @@ module ts { export interface CoreServicesShim extends Shim { getPreProcessedFileInfo(fileName: string, sourceText: IScriptSnapshot): string; + getTSConfigFileInfo(fileName: string, sourceText: IScriptSnapshot): string; getDefaultCompilationSettings(): string; } @@ -302,6 +309,17 @@ module ts { } } } + + export class CoreServicesShimHostAdapter implements ParseConfigHost { + + constructor(private shimHost: CoreServicesShimHost) { + } + + public readDirectory(rootDir: string, extension: string): string[] { + var encoded = this.shimHost.readDirectory(rootDir, extension); + return JSON.parse(encoded); + } + } function simpleForwardCall(logger: Logger, actionDescription: string, action: () => any): any { logger.log(actionDescription); @@ -741,7 +759,8 @@ module ts { } class CoreServicesShimObject extends ShimBase implements CoreServicesShim { - constructor(factory: ShimFactory, public logger: Logger) { + + constructor(factory: ShimFactory, public logger: Logger, private host: CoreServicesShimHostAdapter) { super(factory); } @@ -779,6 +798,25 @@ module ts { }); } + public getTSConfigFileInfo(fileName: string, sourceTextSnapshot: IScriptSnapshot): string { + return this.forwardJSONCall( + "getTSConfigFileInfo('" + fileName + "')", + () => { + var text = sourceTextSnapshot.getText(0, sourceTextSnapshot.getLength()); + var json = /\S/.test(text) ? JSON.parse(text) : {}; + + var configFile = parseConfigFile(json, this.host, getDirectoryPath(normalizeSlashes(fileName))); + + var realErrors = realizeDiagnostics(configFile.errors, '\r\n'); + + return { + options: configFile.options, + files: configFile.fileNames, + errors: realErrors + }; + }); + } + public getDefaultCompilationSettings(): string { return this.forwardJSONCall( "getDefaultCompilationSettings()", @@ -821,12 +859,13 @@ module ts { } } - public createCoreServicesShim(logger: Logger): CoreServicesShim { + public createCoreServicesShim(host: CoreServicesShimHost): CoreServicesShim { try { - return new CoreServicesShimObject(this, logger); + var adapter = new CoreServicesShimHostAdapter(host); + return new CoreServicesShimObject(this, host, adapter); } catch (err) { - logInternalError(logger, err); + logInternalError(host, err); throw err; } } From 1295519b8f397729e68b9cffec78094554a3a334 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 21 Apr 2015 14:10:37 -0700 Subject: [PATCH 057/194] Updated emit for __decorator and __metadata helpers --- src/compiler/emitter.ts | 7 +- .../classExpressionWithDecorator1.js | 3 +- .../decoratedClassFromExternalModule.js | 3 +- .../baselines/reference/decoratorOnClass1.js | 3 +- .../baselines/reference/decoratorOnClass2.js | 3 +- .../baselines/reference/decoratorOnClass3.js | 3 +- .../baselines/reference/decoratorOnClass4.js | 3 +- .../baselines/reference/decoratorOnClass5.js | 3 +- .../baselines/reference/decoratorOnClass8.js | 3 +- .../reference/decoratorOnClassAccessor1.js | 3 +- .../reference/decoratorOnClassAccessor2.js | 3 +- .../reference/decoratorOnClassAccessor3.js | 3 +- .../reference/decoratorOnClassAccessor4.js | 3 +- .../reference/decoratorOnClassAccessor5.js | 3 +- .../reference/decoratorOnClassAccessor6.js | 3 +- .../decoratorOnClassConstructorParameter1.js | 3 +- .../decoratorOnClassConstructorParameter4.js | 3 +- .../reference/decoratorOnClassMethod1.js | 3 +- .../reference/decoratorOnClassMethod10.js | 3 +- .../reference/decoratorOnClassMethod11.js | 3 +- .../reference/decoratorOnClassMethod12.js | 3 +- .../reference/decoratorOnClassMethod13.js | 3 +- .../reference/decoratorOnClassMethod2.js | 3 +- .../reference/decoratorOnClassMethod3.js | 3 +- .../reference/decoratorOnClassMethod4.js | 3 +- .../reference/decoratorOnClassMethod5.js | 3 +- .../reference/decoratorOnClassMethod6.js | 3 +- .../reference/decoratorOnClassMethod7.js | 3 +- .../reference/decoratorOnClassMethod8.js | 3 +- .../decoratorOnClassMethodParameter1.js | 3 +- .../reference/decoratorOnClassProperty1.js | 3 +- .../reference/decoratorOnClassProperty10.js | 3 +- .../reference/decoratorOnClassProperty11.js | 3 +- .../reference/decoratorOnClassProperty2.js | 3 +- .../reference/decoratorOnClassProperty3.js | 3 +- .../reference/decoratorOnClassProperty6.js | 3 +- .../reference/decoratorOnClassProperty7.js | 3 +- .../sourceMapValidationDecorators.js | 3 +- .../sourceMapValidationDecorators.js.map | 2 +- ...ourceMapValidationDecorators.sourcemap.txt | 405 +++++++++--------- 40 files changed, 283 insertions(+), 242 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 226c682d2d7..f4aa0fe1022 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -34,7 +34,8 @@ var __extends = this.__extends || function (d, b) { // emit output for the __decorate helper function const decorateHelper = ` -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { +var __decorate = this.__decorate || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); switch (arguments.length) { case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); @@ -44,7 +45,9 @@ var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.deco // emit output for the __metadata helper function const metadataHelper = ` -var __metadata = this.__metadata || (typeof Reflect === "object" && Reflect.metadata) || function () { };`; +var __metadata = this.__metadata || function (k, v) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); +};`; // emit output for the __param helper function const paramHelper = ` diff --git a/tests/baselines/reference/classExpressionWithDecorator1.js b/tests/baselines/reference/classExpressionWithDecorator1.js index 3e255398904..964a92bb277 100644 --- a/tests/baselines/reference/classExpressionWithDecorator1.js +++ b/tests/baselines/reference/classExpressionWithDecorator1.js @@ -2,7 +2,8 @@ var v = @decorate class C { static p = 1 }; //// [classExpressionWithDecorator1.js] -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { +var __decorate = this.__decorate || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); switch (arguments.length) { case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); diff --git a/tests/baselines/reference/decoratedClassFromExternalModule.js b/tests/baselines/reference/decoratedClassFromExternalModule.js index a58eb01a426..62c03937a50 100644 --- a/tests/baselines/reference/decoratedClassFromExternalModule.js +++ b/tests/baselines/reference/decoratedClassFromExternalModule.js @@ -10,7 +10,8 @@ export default class Decorated { } import Decorated from 'decorated'; //// [decorated.js] -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { +var __decorate = this.__decorate || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); switch (arguments.length) { case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); diff --git a/tests/baselines/reference/decoratorOnClass1.js b/tests/baselines/reference/decoratorOnClass1.js index cd5c51e7a93..679561e2b2f 100644 --- a/tests/baselines/reference/decoratorOnClass1.js +++ b/tests/baselines/reference/decoratorOnClass1.js @@ -6,7 +6,8 @@ class C { } //// [decoratorOnClass1.js] -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { +var __decorate = this.__decorate || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); switch (arguments.length) { case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); diff --git a/tests/baselines/reference/decoratorOnClass2.js b/tests/baselines/reference/decoratorOnClass2.js index fbd9a106ddf..43a67745ae8 100644 --- a/tests/baselines/reference/decoratorOnClass2.js +++ b/tests/baselines/reference/decoratorOnClass2.js @@ -6,7 +6,8 @@ export class C { } //// [decoratorOnClass2.js] -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { +var __decorate = this.__decorate || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); switch (arguments.length) { case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); diff --git a/tests/baselines/reference/decoratorOnClass3.js b/tests/baselines/reference/decoratorOnClass3.js index 21536028091..05e01f7c382 100644 --- a/tests/baselines/reference/decoratorOnClass3.js +++ b/tests/baselines/reference/decoratorOnClass3.js @@ -7,7 +7,8 @@ class C { } //// [decoratorOnClass3.js] -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { +var __decorate = this.__decorate || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); switch (arguments.length) { case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); diff --git a/tests/baselines/reference/decoratorOnClass4.js b/tests/baselines/reference/decoratorOnClass4.js index 5099d16b5b4..747a68a790e 100644 --- a/tests/baselines/reference/decoratorOnClass4.js +++ b/tests/baselines/reference/decoratorOnClass4.js @@ -6,7 +6,8 @@ class C { } //// [decoratorOnClass4.js] -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { +var __decorate = this.__decorate || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); switch (arguments.length) { case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); diff --git a/tests/baselines/reference/decoratorOnClass5.js b/tests/baselines/reference/decoratorOnClass5.js index 0555f618e7e..5c7799937d6 100644 --- a/tests/baselines/reference/decoratorOnClass5.js +++ b/tests/baselines/reference/decoratorOnClass5.js @@ -6,7 +6,8 @@ class C { } //// [decoratorOnClass5.js] -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { +var __decorate = this.__decorate || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); switch (arguments.length) { case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); diff --git a/tests/baselines/reference/decoratorOnClass8.js b/tests/baselines/reference/decoratorOnClass8.js index fad73c0c8fc..86c52b50b44 100644 --- a/tests/baselines/reference/decoratorOnClass8.js +++ b/tests/baselines/reference/decoratorOnClass8.js @@ -6,7 +6,8 @@ class C { } //// [decoratorOnClass8.js] -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { +var __decorate = this.__decorate || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); switch (arguments.length) { case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); diff --git a/tests/baselines/reference/decoratorOnClassAccessor1.js b/tests/baselines/reference/decoratorOnClassAccessor1.js index 68fa7ccec0a..5143f7daceb 100644 --- a/tests/baselines/reference/decoratorOnClassAccessor1.js +++ b/tests/baselines/reference/decoratorOnClassAccessor1.js @@ -6,7 +6,8 @@ class C { } //// [decoratorOnClassAccessor1.js] -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { +var __decorate = this.__decorate || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); switch (arguments.length) { case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); diff --git a/tests/baselines/reference/decoratorOnClassAccessor2.js b/tests/baselines/reference/decoratorOnClassAccessor2.js index 17d3e2e422d..fc5da177eaa 100644 --- a/tests/baselines/reference/decoratorOnClassAccessor2.js +++ b/tests/baselines/reference/decoratorOnClassAccessor2.js @@ -6,7 +6,8 @@ class C { } //// [decoratorOnClassAccessor2.js] -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { +var __decorate = this.__decorate || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); switch (arguments.length) { case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); diff --git a/tests/baselines/reference/decoratorOnClassAccessor3.js b/tests/baselines/reference/decoratorOnClassAccessor3.js index 23e689f3114..08032785683 100644 --- a/tests/baselines/reference/decoratorOnClassAccessor3.js +++ b/tests/baselines/reference/decoratorOnClassAccessor3.js @@ -6,7 +6,8 @@ class C { } //// [decoratorOnClassAccessor3.js] -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { +var __decorate = this.__decorate || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); switch (arguments.length) { case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); diff --git a/tests/baselines/reference/decoratorOnClassAccessor4.js b/tests/baselines/reference/decoratorOnClassAccessor4.js index 77bcb568fe1..f43ad96771b 100644 --- a/tests/baselines/reference/decoratorOnClassAccessor4.js +++ b/tests/baselines/reference/decoratorOnClassAccessor4.js @@ -6,7 +6,8 @@ class C { } //// [decoratorOnClassAccessor4.js] -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { +var __decorate = this.__decorate || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); switch (arguments.length) { case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); diff --git a/tests/baselines/reference/decoratorOnClassAccessor5.js b/tests/baselines/reference/decoratorOnClassAccessor5.js index 37fc33abefd..781585eb4d4 100644 --- a/tests/baselines/reference/decoratorOnClassAccessor5.js +++ b/tests/baselines/reference/decoratorOnClassAccessor5.js @@ -6,7 +6,8 @@ class C { } //// [decoratorOnClassAccessor5.js] -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { +var __decorate = this.__decorate || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); switch (arguments.length) { case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); diff --git a/tests/baselines/reference/decoratorOnClassAccessor6.js b/tests/baselines/reference/decoratorOnClassAccessor6.js index 465e13ebb1d..74feb09088b 100644 --- a/tests/baselines/reference/decoratorOnClassAccessor6.js +++ b/tests/baselines/reference/decoratorOnClassAccessor6.js @@ -6,7 +6,8 @@ class C { } //// [decoratorOnClassAccessor6.js] -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { +var __decorate = this.__decorate || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); switch (arguments.length) { case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); diff --git a/tests/baselines/reference/decoratorOnClassConstructorParameter1.js b/tests/baselines/reference/decoratorOnClassConstructorParameter1.js index a1748a725ba..efd290b0668 100644 --- a/tests/baselines/reference/decoratorOnClassConstructorParameter1.js +++ b/tests/baselines/reference/decoratorOnClassConstructorParameter1.js @@ -6,7 +6,8 @@ class C { } //// [decoratorOnClassConstructorParameter1.js] -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { +var __decorate = this.__decorate || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); switch (arguments.length) { case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); diff --git a/tests/baselines/reference/decoratorOnClassConstructorParameter4.js b/tests/baselines/reference/decoratorOnClassConstructorParameter4.js index 9d2b4a690ab..c1869d6050b 100644 --- a/tests/baselines/reference/decoratorOnClassConstructorParameter4.js +++ b/tests/baselines/reference/decoratorOnClassConstructorParameter4.js @@ -6,7 +6,8 @@ class C { } //// [decoratorOnClassConstructorParameter4.js] -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { +var __decorate = this.__decorate || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); switch (arguments.length) { case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); diff --git a/tests/baselines/reference/decoratorOnClassMethod1.js b/tests/baselines/reference/decoratorOnClassMethod1.js index 23be1094305..b13928ab75e 100644 --- a/tests/baselines/reference/decoratorOnClassMethod1.js +++ b/tests/baselines/reference/decoratorOnClassMethod1.js @@ -6,7 +6,8 @@ class C { } //// [decoratorOnClassMethod1.js] -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { +var __decorate = this.__decorate || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); switch (arguments.length) { case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); diff --git a/tests/baselines/reference/decoratorOnClassMethod10.js b/tests/baselines/reference/decoratorOnClassMethod10.js index f87e3137777..5faf5f5adfd 100644 --- a/tests/baselines/reference/decoratorOnClassMethod10.js +++ b/tests/baselines/reference/decoratorOnClassMethod10.js @@ -6,7 +6,8 @@ class C { } //// [decoratorOnClassMethod10.js] -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { +var __decorate = this.__decorate || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); switch (arguments.length) { case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); diff --git a/tests/baselines/reference/decoratorOnClassMethod11.js b/tests/baselines/reference/decoratorOnClassMethod11.js index f8276de2fe3..2250eef2d88 100644 --- a/tests/baselines/reference/decoratorOnClassMethod11.js +++ b/tests/baselines/reference/decoratorOnClassMethod11.js @@ -9,7 +9,8 @@ module M { } //// [decoratorOnClassMethod11.js] -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { +var __decorate = this.__decorate || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); switch (arguments.length) { case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); diff --git a/tests/baselines/reference/decoratorOnClassMethod12.js b/tests/baselines/reference/decoratorOnClassMethod12.js index 7f23947929c..36874663abd 100644 --- a/tests/baselines/reference/decoratorOnClassMethod12.js +++ b/tests/baselines/reference/decoratorOnClassMethod12.js @@ -16,7 +16,8 @@ var __extends = this.__extends || function (d, b) { __.prototype = b.prototype; d.prototype = new __(); }; -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { +var __decorate = this.__decorate || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); switch (arguments.length) { case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); diff --git a/tests/baselines/reference/decoratorOnClassMethod13.js b/tests/baselines/reference/decoratorOnClassMethod13.js index 4321bbb0156..36dfcf750c0 100644 --- a/tests/baselines/reference/decoratorOnClassMethod13.js +++ b/tests/baselines/reference/decoratorOnClassMethod13.js @@ -7,7 +7,8 @@ class C { } //// [decoratorOnClassMethod13.js] -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { +var __decorate = this.__decorate || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); switch (arguments.length) { case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); diff --git a/tests/baselines/reference/decoratorOnClassMethod2.js b/tests/baselines/reference/decoratorOnClassMethod2.js index 33a22f419d4..7089c4701e4 100644 --- a/tests/baselines/reference/decoratorOnClassMethod2.js +++ b/tests/baselines/reference/decoratorOnClassMethod2.js @@ -6,7 +6,8 @@ class C { } //// [decoratorOnClassMethod2.js] -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { +var __decorate = this.__decorate || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); switch (arguments.length) { case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); diff --git a/tests/baselines/reference/decoratorOnClassMethod3.js b/tests/baselines/reference/decoratorOnClassMethod3.js index f93b7d7a6b2..6c09a14c1a3 100644 --- a/tests/baselines/reference/decoratorOnClassMethod3.js +++ b/tests/baselines/reference/decoratorOnClassMethod3.js @@ -6,7 +6,8 @@ class C { } //// [decoratorOnClassMethod3.js] -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { +var __decorate = this.__decorate || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); switch (arguments.length) { case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); diff --git a/tests/baselines/reference/decoratorOnClassMethod4.js b/tests/baselines/reference/decoratorOnClassMethod4.js index 038432f2cf0..1e5f03a0ad4 100644 --- a/tests/baselines/reference/decoratorOnClassMethod4.js +++ b/tests/baselines/reference/decoratorOnClassMethod4.js @@ -6,7 +6,8 @@ class C { } //// [decoratorOnClassMethod4.js] -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { +var __decorate = this.__decorate || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); switch (arguments.length) { case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); diff --git a/tests/baselines/reference/decoratorOnClassMethod5.js b/tests/baselines/reference/decoratorOnClassMethod5.js index 460c11f145b..fd6520f99da 100644 --- a/tests/baselines/reference/decoratorOnClassMethod5.js +++ b/tests/baselines/reference/decoratorOnClassMethod5.js @@ -6,7 +6,8 @@ class C { } //// [decoratorOnClassMethod5.js] -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { +var __decorate = this.__decorate || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); switch (arguments.length) { case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); diff --git a/tests/baselines/reference/decoratorOnClassMethod6.js b/tests/baselines/reference/decoratorOnClassMethod6.js index 9f120599183..b99cacd6ca0 100644 --- a/tests/baselines/reference/decoratorOnClassMethod6.js +++ b/tests/baselines/reference/decoratorOnClassMethod6.js @@ -6,7 +6,8 @@ class C { } //// [decoratorOnClassMethod6.js] -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { +var __decorate = this.__decorate || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); switch (arguments.length) { case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); diff --git a/tests/baselines/reference/decoratorOnClassMethod7.js b/tests/baselines/reference/decoratorOnClassMethod7.js index 6ab01e68bba..e86480e9895 100644 --- a/tests/baselines/reference/decoratorOnClassMethod7.js +++ b/tests/baselines/reference/decoratorOnClassMethod7.js @@ -6,7 +6,8 @@ class C { } //// [decoratorOnClassMethod7.js] -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { +var __decorate = this.__decorate || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); switch (arguments.length) { case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); diff --git a/tests/baselines/reference/decoratorOnClassMethod8.js b/tests/baselines/reference/decoratorOnClassMethod8.js index 3e88f8c2793..c9048ce30f3 100644 --- a/tests/baselines/reference/decoratorOnClassMethod8.js +++ b/tests/baselines/reference/decoratorOnClassMethod8.js @@ -6,7 +6,8 @@ class C { } //// [decoratorOnClassMethod8.js] -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { +var __decorate = this.__decorate || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); switch (arguments.length) { case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); diff --git a/tests/baselines/reference/decoratorOnClassMethodParameter1.js b/tests/baselines/reference/decoratorOnClassMethodParameter1.js index d228ed9302b..3d62dfe3d96 100644 --- a/tests/baselines/reference/decoratorOnClassMethodParameter1.js +++ b/tests/baselines/reference/decoratorOnClassMethodParameter1.js @@ -6,7 +6,8 @@ class C { } //// [decoratorOnClassMethodParameter1.js] -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { +var __decorate = this.__decorate || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); switch (arguments.length) { case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); diff --git a/tests/baselines/reference/decoratorOnClassProperty1.js b/tests/baselines/reference/decoratorOnClassProperty1.js index aa38252b995..45307cfc57e 100644 --- a/tests/baselines/reference/decoratorOnClassProperty1.js +++ b/tests/baselines/reference/decoratorOnClassProperty1.js @@ -6,7 +6,8 @@ class C { } //// [decoratorOnClassProperty1.js] -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { +var __decorate = this.__decorate || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); switch (arguments.length) { case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); diff --git a/tests/baselines/reference/decoratorOnClassProperty10.js b/tests/baselines/reference/decoratorOnClassProperty10.js index bccbc0bb737..1479d2033c9 100644 --- a/tests/baselines/reference/decoratorOnClassProperty10.js +++ b/tests/baselines/reference/decoratorOnClassProperty10.js @@ -6,7 +6,8 @@ class C { } //// [decoratorOnClassProperty10.js] -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { +var __decorate = this.__decorate || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); switch (arguments.length) { case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); diff --git a/tests/baselines/reference/decoratorOnClassProperty11.js b/tests/baselines/reference/decoratorOnClassProperty11.js index f31e40d3c40..e86c112f436 100644 --- a/tests/baselines/reference/decoratorOnClassProperty11.js +++ b/tests/baselines/reference/decoratorOnClassProperty11.js @@ -6,7 +6,8 @@ class C { } //// [decoratorOnClassProperty11.js] -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { +var __decorate = this.__decorate || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); switch (arguments.length) { case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); diff --git a/tests/baselines/reference/decoratorOnClassProperty2.js b/tests/baselines/reference/decoratorOnClassProperty2.js index 477320b40fa..fed6e57116e 100644 --- a/tests/baselines/reference/decoratorOnClassProperty2.js +++ b/tests/baselines/reference/decoratorOnClassProperty2.js @@ -6,7 +6,8 @@ class C { } //// [decoratorOnClassProperty2.js] -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { +var __decorate = this.__decorate || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); switch (arguments.length) { case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); diff --git a/tests/baselines/reference/decoratorOnClassProperty3.js b/tests/baselines/reference/decoratorOnClassProperty3.js index 05476c66e7d..0b81416b3fd 100644 --- a/tests/baselines/reference/decoratorOnClassProperty3.js +++ b/tests/baselines/reference/decoratorOnClassProperty3.js @@ -6,7 +6,8 @@ class C { } //// [decoratorOnClassProperty3.js] -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { +var __decorate = this.__decorate || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); switch (arguments.length) { case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); diff --git a/tests/baselines/reference/decoratorOnClassProperty6.js b/tests/baselines/reference/decoratorOnClassProperty6.js index 46e2d5fc069..740ad346aa3 100644 --- a/tests/baselines/reference/decoratorOnClassProperty6.js +++ b/tests/baselines/reference/decoratorOnClassProperty6.js @@ -6,7 +6,8 @@ class C { } //// [decoratorOnClassProperty6.js] -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { +var __decorate = this.__decorate || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); switch (arguments.length) { case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); diff --git a/tests/baselines/reference/decoratorOnClassProperty7.js b/tests/baselines/reference/decoratorOnClassProperty7.js index 14ca0612cb1..1b34d5dac07 100644 --- a/tests/baselines/reference/decoratorOnClassProperty7.js +++ b/tests/baselines/reference/decoratorOnClassProperty7.js @@ -6,7 +6,8 @@ class C { } //// [decoratorOnClassProperty7.js] -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { +var __decorate = this.__decorate || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); switch (arguments.length) { case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); diff --git a/tests/baselines/reference/sourceMapValidationDecorators.js b/tests/baselines/reference/sourceMapValidationDecorators.js index 5577a6967cd..d5a63997ea7 100644 --- a/tests/baselines/reference/sourceMapValidationDecorators.js +++ b/tests/baselines/reference/sourceMapValidationDecorators.js @@ -55,7 +55,8 @@ class Greeter { } //// [sourceMapValidationDecorators.js] -var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { +var __decorate = this.__decorate || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); switch (arguments.length) { case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); diff --git a/tests/baselines/reference/sourceMapValidationDecorators.js.map b/tests/baselines/reference/sourceMapValidationDecorators.js.map index 84ebad316fa..d0e29441661 100644 --- a/tests/baselines/reference/sourceMapValidationDecorators.js.map +++ b/tests/baselines/reference/sourceMapValidationDecorators.js.map @@ -1,2 +1,2 @@ //// [sourceMapValidationDecorators.js.map] -{"version":3,"file":"sourceMapValidationDecorators.js","sourceRoot":"","sources":["sourceMapValidationDecorators.ts"],"names":["Greeter","Greeter.constructor","Greeter.greet","Greeter.fn","Greeter.greetings"],"mappings":";;;;;;;;AAOA;IAGIA,iBAGSA,QAAgBA;QAEvBC,WAEcA;aAFdA,WAEcA,CAFdA,sBAEcA,CAFdA,IAEcA;YAFdA,0BAEcA;;QAJPA,aAAQA,GAARA,QAAQA,CAAQA;IAKzBA,CAACA;IAIDD,uBAAKA,GAFLA;QAGIE,MAAMA,CAACA,MAAMA,GAAGA,IAAIA,CAACA,QAAQA,GAAGA,OAAOA,CAACA;IAC5CA,CAACA;IAUOF,oBAAEA,GAAVA,UAGEA,CAASA;QACPG,MAAMA,CAACA,IAAIA,CAACA,QAAQA,CAACA;IACzBA,CAACA;IAEDH,sBAEIA,8BAASA;aAFbA;YAGII,MAAMA,CAACA,IAAIA,CAACA,QAAQA,CAACA;QACzBA,CAACA;aAEDJ,UAGEA,SAAiBA;YACfI,IAAIA,CAACA,QAAQA,GAAGA,SAASA,CAACA;QAC9BA,CAACA;;;OAPAJ;IAbcA,UAAEA,GAAWA,EAAEA,CAACA;IAZ/BA,sBAEAA,0BAAKA;;YAFJA,kBAAkBA;YAClBA,kBAAkBA,CAACA,EAAEA,CAACA;WACvBA,0BAAKA,kCAALA,0BAAKA,IAEJA;IAEDA;QAACA,kBAAkBA;QAClBA,kBAAkBA,CAACA,EAAEA,CAACA;OACfA,sBAACA,EAASA;IAMlBA,sBAAQA,uBAAEA;;YACRA,WAACA,mBAAmBA,CAAAA;YACpBA,WAACA,mBAAmBA,CAACA,EAAEA,CAACA,CAAAA;WAFlBA,uBAAEA,kCAAFA,uBAAEA,IAKTA;IAEDA,sBAEIA,8BAASA;;YAFZA,kBAAkBA;YAClBA,kBAAkBA,CAACA,EAAEA,CAACA;YAMrBA,WAACA,mBAAmBA,CAAAA;YACpBA,WAACA,mBAAmBA,CAACA,EAAEA,CAACA,CAAAA;WANtBA,8BAASA,kCAATA,8BAASA,IAEZA;IAfDA;QAACA,kBAAkBA;QAClBA,kBAAkBA,CAACA,EAAEA,CAACA;OACRA,aAAEA,EAAcA;IAzBnCA;QAACA,eAAeA;QACfA,eAAeA,CAACA,EAAEA,CAACA;QAGdA,WAACA,mBAAmBA,CAAAA;QACpBA,WAACA,mBAAmBA,CAACA,EAAEA,CAACA,CAAAA;QAGxBA,WAACA,mBAAmBA,CAAAA;QACpBA,WAACA,mBAAmBA,CAACA,EAAEA,CAACA,CAAAA;gBAqC7BA;IAADA,cAACA;AAADA,CAACA,AA9CD,IA8CC"} \ No newline at end of file +{"version":3,"file":"sourceMapValidationDecorators.js","sourceRoot":"","sources":["sourceMapValidationDecorators.ts"],"names":["Greeter","Greeter.constructor","Greeter.greet","Greeter.fn","Greeter.greetings"],"mappings":";;;;;;;;;AAOA;IAGIA,iBAGSA,QAAgBA;QAEvBC,WAEcA;aAFdA,WAEcA,CAFdA,sBAEcA,CAFdA,IAEcA;YAFdA,0BAEcA;;QAJPA,aAAQA,GAARA,QAAQA,CAAQA;IAKzBA,CAACA;IAIDD,uBAAKA,GAFLA;QAGIE,MAAMA,CAACA,MAAMA,GAAGA,IAAIA,CAACA,QAAQA,GAAGA,OAAOA,CAACA;IAC5CA,CAACA;IAUOF,oBAAEA,GAAVA,UAGEA,CAASA;QACPG,MAAMA,CAACA,IAAIA,CAACA,QAAQA,CAACA;IACzBA,CAACA;IAEDH,sBAEIA,8BAASA;aAFbA;YAGII,MAAMA,CAACA,IAAIA,CAACA,QAAQA,CAACA;QACzBA,CAACA;aAEDJ,UAGEA,SAAiBA;YACfI,IAAIA,CAACA,QAAQA,GAAGA,SAASA,CAACA;QAC9BA,CAACA;;;OAPAJ;IAbcA,UAAEA,GAAWA,EAAEA,CAACA;IAZ/BA,sBAEAA,0BAAKA;;YAFJA,kBAAkBA;YAClBA,kBAAkBA,CAACA,EAAEA,CAACA;WACvBA,0BAAKA,kCAALA,0BAAKA,IAEJA;IAEDA;QAACA,kBAAkBA;QAClBA,kBAAkBA,CAACA,EAAEA,CAACA;OACfA,sBAACA,EAASA;IAMlBA,sBAAQA,uBAAEA;;YACRA,WAACA,mBAAmBA,CAAAA;YACpBA,WAACA,mBAAmBA,CAACA,EAAEA,CAACA,CAAAA;WAFlBA,uBAAEA,kCAAFA,uBAAEA,IAKTA;IAEDA,sBAEIA,8BAASA;;YAFZA,kBAAkBA;YAClBA,kBAAkBA,CAACA,EAAEA,CAACA;YAMrBA,WAACA,mBAAmBA,CAAAA;YACpBA,WAACA,mBAAmBA,CAACA,EAAEA,CAACA,CAAAA;WANtBA,8BAASA,kCAATA,8BAASA,IAEZA;IAfDA;QAACA,kBAAkBA;QAClBA,kBAAkBA,CAACA,EAAEA,CAACA;OACRA,aAAEA,EAAcA;IAzBnCA;QAACA,eAAeA;QACfA,eAAeA,CAACA,EAAEA,CAACA;QAGdA,WAACA,mBAAmBA,CAAAA;QACpBA,WAACA,mBAAmBA,CAACA,EAAEA,CAACA,CAAAA;QAGxBA,WAACA,mBAAmBA,CAAAA;QACpBA,WAACA,mBAAmBA,CAACA,EAAEA,CAACA,CAAAA;gBAqC7BA;IAADA,cAACA;AAADA,CAACA,AA9CD,IA8CC"} \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationDecorators.sourcemap.txt b/tests/baselines/reference/sourceMapValidationDecorators.sourcemap.txt index f4c64c49579..cde46038669 100644 --- a/tests/baselines/reference/sourceMapValidationDecorators.sourcemap.txt +++ b/tests/baselines/reference/sourceMapValidationDecorators.sourcemap.txt @@ -8,7 +8,8 @@ sources: sourceMapValidationDecorators.ts emittedFile:tests/cases/compiler/sourceMapValidationDecorators.js sourceFile:sourceMapValidationDecorators.ts ------------------------------------------------------------------- ->>>var __decorate = this.__decorate || (typeof Reflect === "object" && Reflect.decorate) || function (decorators, target, key, desc) { +>>>var __decorate = this.__decorate || function (decorators, target, key, desc) { +>>> if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); >>> switch (arguments.length) { >>> case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); >>> case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); @@ -27,7 +28,7 @@ sourceFile:sourceMapValidationDecorators.ts >declare function ParameterDecorator2(x: number): (target: Function, key: string | symbol, paramIndex: number) => void; > > -1 >Emitted(9, 1) Source(8, 1) + SourceIndex(0) +1 >Emitted(10, 1) Source(8, 1) + SourceIndex(0) --- >>> function Greeter(greeting) { 1->^^^^ @@ -42,9 +43,9 @@ sourceFile:sourceMapValidationDecorators.ts > @ParameterDecorator2(20) > public 3 > greeting: string -1->Emitted(10, 5) Source(11, 5) + SourceIndex(0) name (Greeter) -2 >Emitted(10, 22) Source(14, 14) + SourceIndex(0) name (Greeter) -3 >Emitted(10, 30) Source(14, 30) + SourceIndex(0) name (Greeter) +1->Emitted(11, 5) Source(11, 5) + SourceIndex(0) name (Greeter) +2 >Emitted(11, 22) Source(14, 14) + SourceIndex(0) name (Greeter) +3 >Emitted(11, 30) Source(14, 30) + SourceIndex(0) name (Greeter) --- >>> var b = []; 1 >^^^^^^^^ @@ -56,8 +57,8 @@ sourceFile:sourceMapValidationDecorators.ts 2 > @ParameterDecorator1 > @ParameterDecorator2(30) > ...b: string[] -1 >Emitted(11, 9) Source(16, 7) + SourceIndex(0) name (Greeter.constructor) -2 >Emitted(11, 20) Source(18, 21) + SourceIndex(0) name (Greeter.constructor) +1 >Emitted(12, 9) Source(16, 7) + SourceIndex(0) name (Greeter.constructor) +2 >Emitted(12, 20) Source(18, 21) + SourceIndex(0) name (Greeter.constructor) --- >>> for (var _i = 1; _i < arguments.length; _i++) { 1->^^^^^^^^^^^^^ @@ -78,12 +79,12 @@ sourceFile:sourceMapValidationDecorators.ts 6 > @ParameterDecorator1 > @ParameterDecorator2(30) > ...b: string[] -1->Emitted(12, 14) Source(16, 7) + SourceIndex(0) name (Greeter.constructor) -2 >Emitted(12, 25) Source(18, 21) + SourceIndex(0) name (Greeter.constructor) -3 >Emitted(12, 26) Source(16, 7) + SourceIndex(0) name (Greeter.constructor) -4 >Emitted(12, 48) Source(18, 21) + SourceIndex(0) name (Greeter.constructor) -5 >Emitted(12, 49) Source(16, 7) + SourceIndex(0) name (Greeter.constructor) -6 >Emitted(12, 53) Source(18, 21) + SourceIndex(0) name (Greeter.constructor) +1->Emitted(13, 14) Source(16, 7) + SourceIndex(0) name (Greeter.constructor) +2 >Emitted(13, 25) Source(18, 21) + SourceIndex(0) name (Greeter.constructor) +3 >Emitted(13, 26) Source(16, 7) + SourceIndex(0) name (Greeter.constructor) +4 >Emitted(13, 48) Source(18, 21) + SourceIndex(0) name (Greeter.constructor) +5 >Emitted(13, 49) Source(16, 7) + SourceIndex(0) name (Greeter.constructor) +6 >Emitted(13, 53) Source(18, 21) + SourceIndex(0) name (Greeter.constructor) --- >>> b[_i - 1] = arguments[_i]; 1 >^^^^^^^^^^^^ @@ -92,8 +93,8 @@ sourceFile:sourceMapValidationDecorators.ts 2 > @ParameterDecorator1 > @ParameterDecorator2(30) > ...b: string[] -1 >Emitted(13, 13) Source(16, 7) + SourceIndex(0) name (Greeter.constructor) -2 >Emitted(13, 39) Source(18, 21) + SourceIndex(0) name (Greeter.constructor) +1 >Emitted(14, 13) Source(16, 7) + SourceIndex(0) name (Greeter.constructor) +2 >Emitted(14, 39) Source(18, 21) + SourceIndex(0) name (Greeter.constructor) --- >>> } >>> this.greeting = greeting; @@ -107,11 +108,11 @@ sourceFile:sourceMapValidationDecorators.ts 3 > 4 > greeting 5 > : string -1 >Emitted(15, 9) Source(14, 14) + SourceIndex(0) name (Greeter.constructor) -2 >Emitted(15, 22) Source(14, 22) + SourceIndex(0) name (Greeter.constructor) -3 >Emitted(15, 25) Source(14, 14) + SourceIndex(0) name (Greeter.constructor) -4 >Emitted(15, 33) Source(14, 22) + SourceIndex(0) name (Greeter.constructor) -5 >Emitted(15, 34) Source(14, 30) + SourceIndex(0) name (Greeter.constructor) +1 >Emitted(16, 9) Source(14, 14) + SourceIndex(0) name (Greeter.constructor) +2 >Emitted(16, 22) Source(14, 22) + SourceIndex(0) name (Greeter.constructor) +3 >Emitted(16, 25) Source(14, 14) + SourceIndex(0) name (Greeter.constructor) +4 >Emitted(16, 33) Source(14, 22) + SourceIndex(0) name (Greeter.constructor) +5 >Emitted(16, 34) Source(14, 30) + SourceIndex(0) name (Greeter.constructor) --- >>> } 1 >^^^^ @@ -124,8 +125,8 @@ sourceFile:sourceMapValidationDecorators.ts > ...b: string[]) { > 2 > } -1 >Emitted(16, 5) Source(19, 5) + SourceIndex(0) name (Greeter.constructor) -2 >Emitted(16, 6) Source(19, 6) + SourceIndex(0) name (Greeter.constructor) +1 >Emitted(17, 5) Source(19, 5) + SourceIndex(0) name (Greeter.constructor) +2 >Emitted(17, 6) Source(19, 6) + SourceIndex(0) name (Greeter.constructor) --- >>> Greeter.prototype.greet = function () { 1->^^^^ @@ -139,9 +140,9 @@ sourceFile:sourceMapValidationDecorators.ts > 2 > greet 3 > -1->Emitted(17, 5) Source(23, 5) + SourceIndex(0) name (Greeter) -2 >Emitted(17, 28) Source(23, 10) + SourceIndex(0) name (Greeter) -3 >Emitted(17, 31) Source(21, 5) + SourceIndex(0) name (Greeter) +1->Emitted(18, 5) Source(23, 5) + SourceIndex(0) name (Greeter) +2 >Emitted(18, 28) Source(23, 10) + SourceIndex(0) name (Greeter) +3 >Emitted(18, 31) Source(21, 5) + SourceIndex(0) name (Greeter) --- >>> return "

" + this.greeting + "

"; 1->^^^^^^^^ @@ -169,17 +170,17 @@ sourceFile:sourceMapValidationDecorators.ts 9 > + 10> "" 11> ; -1->Emitted(18, 9) Source(24, 9) + SourceIndex(0) name (Greeter.greet) -2 >Emitted(18, 15) Source(24, 15) + SourceIndex(0) name (Greeter.greet) -3 >Emitted(18, 16) Source(24, 16) + SourceIndex(0) name (Greeter.greet) -4 >Emitted(18, 22) Source(24, 22) + SourceIndex(0) name (Greeter.greet) -5 >Emitted(18, 25) Source(24, 25) + SourceIndex(0) name (Greeter.greet) -6 >Emitted(18, 29) Source(24, 29) + SourceIndex(0) name (Greeter.greet) -7 >Emitted(18, 30) Source(24, 30) + SourceIndex(0) name (Greeter.greet) -8 >Emitted(18, 38) Source(24, 38) + SourceIndex(0) name (Greeter.greet) -9 >Emitted(18, 41) Source(24, 41) + SourceIndex(0) name (Greeter.greet) -10>Emitted(18, 48) Source(24, 48) + SourceIndex(0) name (Greeter.greet) -11>Emitted(18, 49) Source(24, 49) + SourceIndex(0) name (Greeter.greet) +1->Emitted(19, 9) Source(24, 9) + SourceIndex(0) name (Greeter.greet) +2 >Emitted(19, 15) Source(24, 15) + SourceIndex(0) name (Greeter.greet) +3 >Emitted(19, 16) Source(24, 16) + SourceIndex(0) name (Greeter.greet) +4 >Emitted(19, 22) Source(24, 22) + SourceIndex(0) name (Greeter.greet) +5 >Emitted(19, 25) Source(24, 25) + SourceIndex(0) name (Greeter.greet) +6 >Emitted(19, 29) Source(24, 29) + SourceIndex(0) name (Greeter.greet) +7 >Emitted(19, 30) Source(24, 30) + SourceIndex(0) name (Greeter.greet) +8 >Emitted(19, 38) Source(24, 38) + SourceIndex(0) name (Greeter.greet) +9 >Emitted(19, 41) Source(24, 41) + SourceIndex(0) name (Greeter.greet) +10>Emitted(19, 48) Source(24, 48) + SourceIndex(0) name (Greeter.greet) +11>Emitted(19, 49) Source(24, 49) + SourceIndex(0) name (Greeter.greet) --- >>> }; 1 >^^^^ @@ -188,8 +189,8 @@ sourceFile:sourceMapValidationDecorators.ts 1 > > 2 > } -1 >Emitted(19, 5) Source(25, 5) + SourceIndex(0) name (Greeter.greet) -2 >Emitted(19, 6) Source(25, 6) + SourceIndex(0) name (Greeter.greet) +1 >Emitted(20, 5) Source(25, 5) + SourceIndex(0) name (Greeter.greet) +2 >Emitted(20, 6) Source(25, 6) + SourceIndex(0) name (Greeter.greet) --- >>> Greeter.prototype.fn = function (x) { 1->^^^^ @@ -215,11 +216,11 @@ sourceFile:sourceMapValidationDecorators.ts > @ParameterDecorator2(70) > 5 > x: number -1->Emitted(20, 5) Source(35, 13) + SourceIndex(0) name (Greeter) -2 >Emitted(20, 25) Source(35, 15) + SourceIndex(0) name (Greeter) -3 >Emitted(20, 28) Source(35, 5) + SourceIndex(0) name (Greeter) -4 >Emitted(20, 38) Source(38, 7) + SourceIndex(0) name (Greeter) -5 >Emitted(20, 39) Source(38, 16) + SourceIndex(0) name (Greeter) +1->Emitted(21, 5) Source(35, 13) + SourceIndex(0) name (Greeter) +2 >Emitted(21, 25) Source(35, 15) + SourceIndex(0) name (Greeter) +3 >Emitted(21, 28) Source(35, 5) + SourceIndex(0) name (Greeter) +4 >Emitted(21, 38) Source(38, 7) + SourceIndex(0) name (Greeter) +5 >Emitted(21, 39) Source(38, 16) + SourceIndex(0) name (Greeter) --- >>> return this.greeting; 1 >^^^^^^^^ @@ -237,13 +238,13 @@ sourceFile:sourceMapValidationDecorators.ts 5 > . 6 > greeting 7 > ; -1 >Emitted(21, 9) Source(39, 9) + SourceIndex(0) name (Greeter.fn) -2 >Emitted(21, 15) Source(39, 15) + SourceIndex(0) name (Greeter.fn) -3 >Emitted(21, 16) Source(39, 16) + SourceIndex(0) name (Greeter.fn) -4 >Emitted(21, 20) Source(39, 20) + SourceIndex(0) name (Greeter.fn) -5 >Emitted(21, 21) Source(39, 21) + SourceIndex(0) name (Greeter.fn) -6 >Emitted(21, 29) Source(39, 29) + SourceIndex(0) name (Greeter.fn) -7 >Emitted(21, 30) Source(39, 30) + SourceIndex(0) name (Greeter.fn) +1 >Emitted(22, 9) Source(39, 9) + SourceIndex(0) name (Greeter.fn) +2 >Emitted(22, 15) Source(39, 15) + SourceIndex(0) name (Greeter.fn) +3 >Emitted(22, 16) Source(39, 16) + SourceIndex(0) name (Greeter.fn) +4 >Emitted(22, 20) Source(39, 20) + SourceIndex(0) name (Greeter.fn) +5 >Emitted(22, 21) Source(39, 21) + SourceIndex(0) name (Greeter.fn) +6 >Emitted(22, 29) Source(39, 29) + SourceIndex(0) name (Greeter.fn) +7 >Emitted(22, 30) Source(39, 30) + SourceIndex(0) name (Greeter.fn) --- >>> }; 1 >^^^^ @@ -252,8 +253,8 @@ sourceFile:sourceMapValidationDecorators.ts 1 > > 2 > } -1 >Emitted(22, 5) Source(40, 5) + SourceIndex(0) name (Greeter.fn) -2 >Emitted(22, 6) Source(40, 6) + SourceIndex(0) name (Greeter.fn) +1 >Emitted(23, 5) Source(40, 5) + SourceIndex(0) name (Greeter.fn) +2 >Emitted(23, 6) Source(40, 6) + SourceIndex(0) name (Greeter.fn) --- >>> Object.defineProperty(Greeter.prototype, "greetings", { 1->^^^^ @@ -266,15 +267,15 @@ sourceFile:sourceMapValidationDecorators.ts > @PropertyDecorator2(80) > get 3 > greetings -1->Emitted(23, 5) Source(42, 5) + SourceIndex(0) name (Greeter) -2 >Emitted(23, 27) Source(44, 9) + SourceIndex(0) name (Greeter) -3 >Emitted(23, 57) Source(44, 18) + SourceIndex(0) name (Greeter) +1->Emitted(24, 5) Source(42, 5) + SourceIndex(0) name (Greeter) +2 >Emitted(24, 27) Source(44, 9) + SourceIndex(0) name (Greeter) +3 >Emitted(24, 57) Source(44, 18) + SourceIndex(0) name (Greeter) --- >>> get: function () { 1 >^^^^^^^^^^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^-> 1 > -1 >Emitted(24, 14) Source(42, 5) + SourceIndex(0) name (Greeter) +1 >Emitted(25, 14) Source(42, 5) + SourceIndex(0) name (Greeter) --- >>> return this.greeting; 1->^^^^^^^^^^^^ @@ -294,13 +295,13 @@ sourceFile:sourceMapValidationDecorators.ts 5 > . 6 > greeting 7 > ; -1->Emitted(25, 13) Source(45, 9) + SourceIndex(0) name (Greeter.greetings) -2 >Emitted(25, 19) Source(45, 15) + SourceIndex(0) name (Greeter.greetings) -3 >Emitted(25, 20) Source(45, 16) + SourceIndex(0) name (Greeter.greetings) -4 >Emitted(25, 24) Source(45, 20) + SourceIndex(0) name (Greeter.greetings) -5 >Emitted(25, 25) Source(45, 21) + SourceIndex(0) name (Greeter.greetings) -6 >Emitted(25, 33) Source(45, 29) + SourceIndex(0) name (Greeter.greetings) -7 >Emitted(25, 34) Source(45, 30) + SourceIndex(0) name (Greeter.greetings) +1->Emitted(26, 13) Source(45, 9) + SourceIndex(0) name (Greeter.greetings) +2 >Emitted(26, 19) Source(45, 15) + SourceIndex(0) name (Greeter.greetings) +3 >Emitted(26, 20) Source(45, 16) + SourceIndex(0) name (Greeter.greetings) +4 >Emitted(26, 24) Source(45, 20) + SourceIndex(0) name (Greeter.greetings) +5 >Emitted(26, 25) Source(45, 21) + SourceIndex(0) name (Greeter.greetings) +6 >Emitted(26, 33) Source(45, 29) + SourceIndex(0) name (Greeter.greetings) +7 >Emitted(26, 34) Source(45, 30) + SourceIndex(0) name (Greeter.greetings) --- >>> }, 1 >^^^^^^^^ @@ -309,8 +310,8 @@ sourceFile:sourceMapValidationDecorators.ts 1 > > 2 > } -1 >Emitted(26, 9) Source(46, 5) + SourceIndex(0) name (Greeter.greetings) -2 >Emitted(26, 10) Source(46, 6) + SourceIndex(0) name (Greeter.greetings) +1 >Emitted(27, 9) Source(46, 5) + SourceIndex(0) name (Greeter.greetings) +2 >Emitted(27, 10) Source(46, 6) + SourceIndex(0) name (Greeter.greetings) --- >>> set: function (greetings) { 1->^^^^^^^^^^^^^ @@ -325,9 +326,9 @@ sourceFile:sourceMapValidationDecorators.ts > @ParameterDecorator2(90) > 3 > greetings: string -1->Emitted(27, 14) Source(48, 5) + SourceIndex(0) name (Greeter) -2 >Emitted(27, 24) Source(51, 7) + SourceIndex(0) name (Greeter) -3 >Emitted(27, 33) Source(51, 24) + SourceIndex(0) name (Greeter) +1->Emitted(28, 14) Source(48, 5) + SourceIndex(0) name (Greeter) +2 >Emitted(28, 24) Source(51, 7) + SourceIndex(0) name (Greeter) +3 >Emitted(28, 33) Source(51, 24) + SourceIndex(0) name (Greeter) --- >>> this.greeting = greetings; 1->^^^^^^^^^^^^ @@ -345,13 +346,13 @@ sourceFile:sourceMapValidationDecorators.ts 5 > = 6 > greetings 7 > ; -1->Emitted(28, 13) Source(52, 9) + SourceIndex(0) name (Greeter.greetings) -2 >Emitted(28, 17) Source(52, 13) + SourceIndex(0) name (Greeter.greetings) -3 >Emitted(28, 18) Source(52, 14) + SourceIndex(0) name (Greeter.greetings) -4 >Emitted(28, 26) Source(52, 22) + SourceIndex(0) name (Greeter.greetings) -5 >Emitted(28, 29) Source(52, 25) + SourceIndex(0) name (Greeter.greetings) -6 >Emitted(28, 38) Source(52, 34) + SourceIndex(0) name (Greeter.greetings) -7 >Emitted(28, 39) Source(52, 35) + SourceIndex(0) name (Greeter.greetings) +1->Emitted(29, 13) Source(52, 9) + SourceIndex(0) name (Greeter.greetings) +2 >Emitted(29, 17) Source(52, 13) + SourceIndex(0) name (Greeter.greetings) +3 >Emitted(29, 18) Source(52, 14) + SourceIndex(0) name (Greeter.greetings) +4 >Emitted(29, 26) Source(52, 22) + SourceIndex(0) name (Greeter.greetings) +5 >Emitted(29, 29) Source(52, 25) + SourceIndex(0) name (Greeter.greetings) +6 >Emitted(29, 38) Source(52, 34) + SourceIndex(0) name (Greeter.greetings) +7 >Emitted(29, 39) Source(52, 35) + SourceIndex(0) name (Greeter.greetings) --- >>> }, 1 >^^^^^^^^ @@ -360,8 +361,8 @@ sourceFile:sourceMapValidationDecorators.ts 1 > > 2 > } -1 >Emitted(29, 9) Source(53, 5) + SourceIndex(0) name (Greeter.greetings) -2 >Emitted(29, 10) Source(53, 6) + SourceIndex(0) name (Greeter.greetings) +1 >Emitted(30, 9) Source(53, 5) + SourceIndex(0) name (Greeter.greetings) +2 >Emitted(30, 10) Source(53, 6) + SourceIndex(0) name (Greeter.greetings) --- >>> enumerable: true, >>> configurable: true @@ -369,7 +370,7 @@ sourceFile:sourceMapValidationDecorators.ts 1->^^^^^^^ 2 > ^^^^^^^^^^^^^^-> 1-> -1->Emitted(32, 8) Source(46, 6) + SourceIndex(0) name (Greeter) +1->Emitted(33, 8) Source(46, 6) + SourceIndex(0) name (Greeter) --- >>> Greeter.x1 = 10; 1->^^^^ @@ -383,11 +384,11 @@ sourceFile:sourceMapValidationDecorators.ts 3 > : number = 4 > 10 5 > ; -1->Emitted(33, 5) Source(33, 20) + SourceIndex(0) name (Greeter) -2 >Emitted(33, 15) Source(33, 22) + SourceIndex(0) name (Greeter) -3 >Emitted(33, 18) Source(33, 33) + SourceIndex(0) name (Greeter) -4 >Emitted(33, 20) Source(33, 35) + SourceIndex(0) name (Greeter) -5 >Emitted(33, 21) Source(33, 36) + SourceIndex(0) name (Greeter) +1->Emitted(34, 5) Source(33, 20) + SourceIndex(0) name (Greeter) +2 >Emitted(34, 15) Source(33, 22) + SourceIndex(0) name (Greeter) +3 >Emitted(34, 18) Source(33, 33) + SourceIndex(0) name (Greeter) +4 >Emitted(34, 20) Source(33, 35) + SourceIndex(0) name (Greeter) +5 >Emitted(34, 21) Source(33, 36) + SourceIndex(0) name (Greeter) --- >>> Object.defineProperty(Greeter.prototype, "greet", 1->^^^^ @@ -398,9 +399,9 @@ sourceFile:sourceMapValidationDecorators.ts > @PropertyDecorator2(40) > 3 > greet -1->Emitted(34, 5) Source(21, 5) + SourceIndex(0) name (Greeter) -2 >Emitted(34, 27) Source(23, 5) + SourceIndex(0) name (Greeter) -3 >Emitted(34, 53) Source(23, 10) + SourceIndex(0) name (Greeter) +1->Emitted(35, 5) Source(21, 5) + SourceIndex(0) name (Greeter) +2 >Emitted(35, 27) Source(23, 5) + SourceIndex(0) name (Greeter) +3 >Emitted(35, 53) Source(23, 10) + SourceIndex(0) name (Greeter) --- >>> __decorate([ >>> PropertyDecorator1, @@ -409,8 +410,8 @@ sourceFile:sourceMapValidationDecorators.ts 3 > ^^^^^-> 1 > 2 > PropertyDecorator1 -1 >Emitted(36, 13) Source(21, 6) + SourceIndex(0) name (Greeter) -2 >Emitted(36, 31) Source(21, 24) + SourceIndex(0) name (Greeter) +1 >Emitted(37, 13) Source(21, 6) + SourceIndex(0) name (Greeter) +2 >Emitted(37, 31) Source(21, 24) + SourceIndex(0) name (Greeter) --- >>> PropertyDecorator2(40) 1->^^^^^^^^^^^^ @@ -425,11 +426,11 @@ sourceFile:sourceMapValidationDecorators.ts 3 > ( 4 > 40 5 > ) -1->Emitted(37, 13) Source(22, 6) + SourceIndex(0) name (Greeter) -2 >Emitted(37, 31) Source(22, 24) + SourceIndex(0) name (Greeter) -3 >Emitted(37, 32) Source(22, 25) + SourceIndex(0) name (Greeter) -4 >Emitted(37, 34) Source(22, 27) + SourceIndex(0) name (Greeter) -5 >Emitted(37, 35) Source(22, 28) + SourceIndex(0) name (Greeter) +1->Emitted(38, 13) Source(22, 6) + SourceIndex(0) name (Greeter) +2 >Emitted(38, 31) Source(22, 24) + SourceIndex(0) name (Greeter) +3 >Emitted(38, 32) Source(22, 25) + SourceIndex(0) name (Greeter) +4 >Emitted(38, 34) Source(22, 27) + SourceIndex(0) name (Greeter) +5 >Emitted(38, 35) Source(22, 28) + SourceIndex(0) name (Greeter) --- >>> ], Greeter.prototype, "greet", Object.getOwnPropertyDescriptor(Greeter.prototype, "greet"))); 1->^^^^^^^^^^^ @@ -445,11 +446,11 @@ sourceFile:sourceMapValidationDecorators.ts 5 > () { > return "

" + this.greeting + "

"; > } -1->Emitted(38, 12) Source(23, 5) + SourceIndex(0) name (Greeter) -2 >Emitted(38, 38) Source(23, 10) + SourceIndex(0) name (Greeter) -3 >Emitted(38, 72) Source(23, 5) + SourceIndex(0) name (Greeter) -4 >Emitted(38, 98) Source(23, 10) + SourceIndex(0) name (Greeter) -5 >Emitted(38, 102) Source(25, 6) + SourceIndex(0) name (Greeter) +1->Emitted(39, 12) Source(23, 5) + SourceIndex(0) name (Greeter) +2 >Emitted(39, 38) Source(23, 10) + SourceIndex(0) name (Greeter) +3 >Emitted(39, 72) Source(23, 5) + SourceIndex(0) name (Greeter) +4 >Emitted(39, 98) Source(23, 10) + SourceIndex(0) name (Greeter) +5 >Emitted(39, 102) Source(25, 6) + SourceIndex(0) name (Greeter) --- >>> __decorate([ 1 >^^^^ @@ -457,7 +458,7 @@ sourceFile:sourceMapValidationDecorators.ts 1 > > > -1 >Emitted(39, 5) Source(27, 5) + SourceIndex(0) name (Greeter) +1 >Emitted(40, 5) Source(27, 5) + SourceIndex(0) name (Greeter) --- >>> PropertyDecorator1, 1->^^^^^^^^ @@ -465,8 +466,8 @@ sourceFile:sourceMapValidationDecorators.ts 3 > ^^^^^-> 1->@ 2 > PropertyDecorator1 -1->Emitted(40, 9) Source(27, 6) + SourceIndex(0) name (Greeter) -2 >Emitted(40, 27) Source(27, 24) + SourceIndex(0) name (Greeter) +1->Emitted(41, 9) Source(27, 6) + SourceIndex(0) name (Greeter) +2 >Emitted(41, 27) Source(27, 24) + SourceIndex(0) name (Greeter) --- >>> PropertyDecorator2(50) 1->^^^^^^^^ @@ -481,11 +482,11 @@ sourceFile:sourceMapValidationDecorators.ts 3 > ( 4 > 50 5 > ) -1->Emitted(41, 9) Source(28, 6) + SourceIndex(0) name (Greeter) -2 >Emitted(41, 27) Source(28, 24) + SourceIndex(0) name (Greeter) -3 >Emitted(41, 28) Source(28, 25) + SourceIndex(0) name (Greeter) -4 >Emitted(41, 30) Source(28, 27) + SourceIndex(0) name (Greeter) -5 >Emitted(41, 31) Source(28, 28) + SourceIndex(0) name (Greeter) +1->Emitted(42, 9) Source(28, 6) + SourceIndex(0) name (Greeter) +2 >Emitted(42, 27) Source(28, 24) + SourceIndex(0) name (Greeter) +3 >Emitted(42, 28) Source(28, 25) + SourceIndex(0) name (Greeter) +4 >Emitted(42, 30) Source(28, 27) + SourceIndex(0) name (Greeter) +5 >Emitted(42, 31) Source(28, 28) + SourceIndex(0) name (Greeter) --- >>> ], Greeter.prototype, "x"); 1->^^^^^^^ @@ -496,9 +497,9 @@ sourceFile:sourceMapValidationDecorators.ts > private 2 > x 3 > : string; -1->Emitted(42, 8) Source(29, 13) + SourceIndex(0) name (Greeter) -2 >Emitted(42, 30) Source(29, 14) + SourceIndex(0) name (Greeter) -3 >Emitted(42, 32) Source(29, 23) + SourceIndex(0) name (Greeter) +1->Emitted(43, 8) Source(29, 13) + SourceIndex(0) name (Greeter) +2 >Emitted(43, 30) Source(29, 14) + SourceIndex(0) name (Greeter) +3 >Emitted(43, 32) Source(29, 23) + SourceIndex(0) name (Greeter) --- >>> Object.defineProperty(Greeter.prototype, "fn", 1->^^^^ @@ -513,9 +514,9 @@ sourceFile:sourceMapValidationDecorators.ts > 2 > private 3 > fn -1->Emitted(43, 5) Source(35, 5) + SourceIndex(0) name (Greeter) -2 >Emitted(43, 27) Source(35, 13) + SourceIndex(0) name (Greeter) -3 >Emitted(43, 50) Source(35, 15) + SourceIndex(0) name (Greeter) +1->Emitted(44, 5) Source(35, 5) + SourceIndex(0) name (Greeter) +2 >Emitted(44, 27) Source(35, 13) + SourceIndex(0) name (Greeter) +3 >Emitted(44, 50) Source(35, 15) + SourceIndex(0) name (Greeter) --- >>> __decorate([ >>> __param(0, ParameterDecorator1), @@ -529,10 +530,10 @@ sourceFile:sourceMapValidationDecorators.ts 2 > @ 3 > ParameterDecorator1 4 > -1 >Emitted(45, 13) Source(36, 7) + SourceIndex(0) name (Greeter) -2 >Emitted(45, 24) Source(36, 8) + SourceIndex(0) name (Greeter) -3 >Emitted(45, 43) Source(36, 27) + SourceIndex(0) name (Greeter) -4 >Emitted(45, 44) Source(36, 27) + SourceIndex(0) name (Greeter) +1 >Emitted(46, 13) Source(36, 7) + SourceIndex(0) name (Greeter) +2 >Emitted(46, 24) Source(36, 8) + SourceIndex(0) name (Greeter) +3 >Emitted(46, 43) Source(36, 27) + SourceIndex(0) name (Greeter) +4 >Emitted(46, 44) Source(36, 27) + SourceIndex(0) name (Greeter) --- >>> __param(0, ParameterDecorator2(70)) 1->^^^^^^^^^^^^ @@ -551,13 +552,13 @@ sourceFile:sourceMapValidationDecorators.ts 5 > 70 6 > ) 7 > -1->Emitted(46, 13) Source(37, 7) + SourceIndex(0) name (Greeter) -2 >Emitted(46, 24) Source(37, 8) + SourceIndex(0) name (Greeter) -3 >Emitted(46, 43) Source(37, 27) + SourceIndex(0) name (Greeter) -4 >Emitted(46, 44) Source(37, 28) + SourceIndex(0) name (Greeter) -5 >Emitted(46, 46) Source(37, 30) + SourceIndex(0) name (Greeter) -6 >Emitted(46, 47) Source(37, 31) + SourceIndex(0) name (Greeter) -7 >Emitted(46, 48) Source(37, 31) + SourceIndex(0) name (Greeter) +1->Emitted(47, 13) Source(37, 7) + SourceIndex(0) name (Greeter) +2 >Emitted(47, 24) Source(37, 8) + SourceIndex(0) name (Greeter) +3 >Emitted(47, 43) Source(37, 27) + SourceIndex(0) name (Greeter) +4 >Emitted(47, 44) Source(37, 28) + SourceIndex(0) name (Greeter) +5 >Emitted(47, 46) Source(37, 30) + SourceIndex(0) name (Greeter) +6 >Emitted(47, 47) Source(37, 31) + SourceIndex(0) name (Greeter) +7 >Emitted(47, 48) Source(37, 31) + SourceIndex(0) name (Greeter) --- >>> ], Greeter.prototype, "fn", Object.getOwnPropertyDescriptor(Greeter.prototype, "fn"))); 1->^^^^^^^^^^^ @@ -575,11 +576,11 @@ sourceFile:sourceMapValidationDecorators.ts > x: number) { > return this.greeting; > } -1->Emitted(47, 12) Source(35, 13) + SourceIndex(0) name (Greeter) -2 >Emitted(47, 35) Source(35, 15) + SourceIndex(0) name (Greeter) -3 >Emitted(47, 69) Source(35, 13) + SourceIndex(0) name (Greeter) -4 >Emitted(47, 92) Source(35, 15) + SourceIndex(0) name (Greeter) -5 >Emitted(47, 96) Source(40, 6) + SourceIndex(0) name (Greeter) +1->Emitted(48, 12) Source(35, 13) + SourceIndex(0) name (Greeter) +2 >Emitted(48, 35) Source(35, 15) + SourceIndex(0) name (Greeter) +3 >Emitted(48, 69) Source(35, 13) + SourceIndex(0) name (Greeter) +4 >Emitted(48, 92) Source(35, 15) + SourceIndex(0) name (Greeter) +5 >Emitted(48, 96) Source(40, 6) + SourceIndex(0) name (Greeter) --- >>> Object.defineProperty(Greeter.prototype, "greetings", 1 >^^^^ @@ -592,9 +593,9 @@ sourceFile:sourceMapValidationDecorators.ts > @PropertyDecorator2(80) > get 3 > greetings -1 >Emitted(48, 5) Source(42, 5) + SourceIndex(0) name (Greeter) -2 >Emitted(48, 27) Source(44, 9) + SourceIndex(0) name (Greeter) -3 >Emitted(48, 57) Source(44, 18) + SourceIndex(0) name (Greeter) +1 >Emitted(49, 5) Source(42, 5) + SourceIndex(0) name (Greeter) +2 >Emitted(49, 27) Source(44, 9) + SourceIndex(0) name (Greeter) +3 >Emitted(49, 57) Source(44, 18) + SourceIndex(0) name (Greeter) --- >>> __decorate([ >>> PropertyDecorator1, @@ -603,8 +604,8 @@ sourceFile:sourceMapValidationDecorators.ts 3 > ^^^^^^-> 1 > 2 > PropertyDecorator1 -1 >Emitted(50, 13) Source(42, 6) + SourceIndex(0) name (Greeter) -2 >Emitted(50, 31) Source(42, 24) + SourceIndex(0) name (Greeter) +1 >Emitted(51, 13) Source(42, 6) + SourceIndex(0) name (Greeter) +2 >Emitted(51, 31) Source(42, 24) + SourceIndex(0) name (Greeter) --- >>> PropertyDecorator2(80), 1->^^^^^^^^^^^^ @@ -619,11 +620,11 @@ sourceFile:sourceMapValidationDecorators.ts 3 > ( 4 > 80 5 > ) -1->Emitted(51, 13) Source(43, 6) + SourceIndex(0) name (Greeter) -2 >Emitted(51, 31) Source(43, 24) + SourceIndex(0) name (Greeter) -3 >Emitted(51, 32) Source(43, 25) + SourceIndex(0) name (Greeter) -4 >Emitted(51, 34) Source(43, 27) + SourceIndex(0) name (Greeter) -5 >Emitted(51, 35) Source(43, 28) + SourceIndex(0) name (Greeter) +1->Emitted(52, 13) Source(43, 6) + SourceIndex(0) name (Greeter) +2 >Emitted(52, 31) Source(43, 24) + SourceIndex(0) name (Greeter) +3 >Emitted(52, 32) Source(43, 25) + SourceIndex(0) name (Greeter) +4 >Emitted(52, 34) Source(43, 27) + SourceIndex(0) name (Greeter) +5 >Emitted(52, 35) Source(43, 28) + SourceIndex(0) name (Greeter) --- >>> __param(0, ParameterDecorator1), 1->^^^^^^^^^^^^ @@ -641,10 +642,10 @@ sourceFile:sourceMapValidationDecorators.ts 2 > @ 3 > ParameterDecorator1 4 > -1->Emitted(52, 13) Source(49, 7) + SourceIndex(0) name (Greeter) -2 >Emitted(52, 24) Source(49, 8) + SourceIndex(0) name (Greeter) -3 >Emitted(52, 43) Source(49, 27) + SourceIndex(0) name (Greeter) -4 >Emitted(52, 44) Source(49, 27) + SourceIndex(0) name (Greeter) +1->Emitted(53, 13) Source(49, 7) + SourceIndex(0) name (Greeter) +2 >Emitted(53, 24) Source(49, 8) + SourceIndex(0) name (Greeter) +3 >Emitted(53, 43) Source(49, 27) + SourceIndex(0) name (Greeter) +4 >Emitted(53, 44) Source(49, 27) + SourceIndex(0) name (Greeter) --- >>> __param(0, ParameterDecorator2(90)) 1->^^^^^^^^^^^^ @@ -663,13 +664,13 @@ sourceFile:sourceMapValidationDecorators.ts 5 > 90 6 > ) 7 > -1->Emitted(53, 13) Source(50, 7) + SourceIndex(0) name (Greeter) -2 >Emitted(53, 24) Source(50, 8) + SourceIndex(0) name (Greeter) -3 >Emitted(53, 43) Source(50, 27) + SourceIndex(0) name (Greeter) -4 >Emitted(53, 44) Source(50, 28) + SourceIndex(0) name (Greeter) -5 >Emitted(53, 46) Source(50, 30) + SourceIndex(0) name (Greeter) -6 >Emitted(53, 47) Source(50, 31) + SourceIndex(0) name (Greeter) -7 >Emitted(53, 48) Source(50, 31) + SourceIndex(0) name (Greeter) +1->Emitted(54, 13) Source(50, 7) + SourceIndex(0) name (Greeter) +2 >Emitted(54, 24) Source(50, 8) + SourceIndex(0) name (Greeter) +3 >Emitted(54, 43) Source(50, 27) + SourceIndex(0) name (Greeter) +4 >Emitted(54, 44) Source(50, 28) + SourceIndex(0) name (Greeter) +5 >Emitted(54, 46) Source(50, 30) + SourceIndex(0) name (Greeter) +6 >Emitted(54, 47) Source(50, 31) + SourceIndex(0) name (Greeter) +7 >Emitted(54, 48) Source(50, 31) + SourceIndex(0) name (Greeter) --- >>> ], Greeter.prototype, "greetings", Object.getOwnPropertyDescriptor(Greeter.prototype, "greetings"))); 1->^^^^^^^^^^^ @@ -684,17 +685,17 @@ sourceFile:sourceMapValidationDecorators.ts 5 > () { > return this.greeting; > } -1->Emitted(54, 12) Source(44, 9) + SourceIndex(0) name (Greeter) -2 >Emitted(54, 42) Source(44, 18) + SourceIndex(0) name (Greeter) -3 >Emitted(54, 76) Source(44, 9) + SourceIndex(0) name (Greeter) -4 >Emitted(54, 106) Source(44, 18) + SourceIndex(0) name (Greeter) -5 >Emitted(54, 110) Source(46, 6) + SourceIndex(0) name (Greeter) +1->Emitted(55, 12) Source(44, 9) + SourceIndex(0) name (Greeter) +2 >Emitted(55, 42) Source(44, 18) + SourceIndex(0) name (Greeter) +3 >Emitted(55, 76) Source(44, 9) + SourceIndex(0) name (Greeter) +4 >Emitted(55, 106) Source(44, 18) + SourceIndex(0) name (Greeter) +5 >Emitted(55, 110) Source(46, 6) + SourceIndex(0) name (Greeter) --- >>> __decorate([ 1 >^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > -1 >Emitted(55, 5) Source(31, 5) + SourceIndex(0) name (Greeter) +1 >Emitted(56, 5) Source(31, 5) + SourceIndex(0) name (Greeter) --- >>> PropertyDecorator1, 1->^^^^^^^^ @@ -702,8 +703,8 @@ sourceFile:sourceMapValidationDecorators.ts 3 > ^^^^^-> 1->@ 2 > PropertyDecorator1 -1->Emitted(56, 9) Source(31, 6) + SourceIndex(0) name (Greeter) -2 >Emitted(56, 27) Source(31, 24) + SourceIndex(0) name (Greeter) +1->Emitted(57, 9) Source(31, 6) + SourceIndex(0) name (Greeter) +2 >Emitted(57, 27) Source(31, 24) + SourceIndex(0) name (Greeter) --- >>> PropertyDecorator2(60) 1->^^^^^^^^ @@ -717,11 +718,11 @@ sourceFile:sourceMapValidationDecorators.ts 3 > ( 4 > 60 5 > ) -1->Emitted(57, 9) Source(32, 6) + SourceIndex(0) name (Greeter) -2 >Emitted(57, 27) Source(32, 24) + SourceIndex(0) name (Greeter) -3 >Emitted(57, 28) Source(32, 25) + SourceIndex(0) name (Greeter) -4 >Emitted(57, 30) Source(32, 27) + SourceIndex(0) name (Greeter) -5 >Emitted(57, 31) Source(32, 28) + SourceIndex(0) name (Greeter) +1->Emitted(58, 9) Source(32, 6) + SourceIndex(0) name (Greeter) +2 >Emitted(58, 27) Source(32, 24) + SourceIndex(0) name (Greeter) +3 >Emitted(58, 28) Source(32, 25) + SourceIndex(0) name (Greeter) +4 >Emitted(58, 30) Source(32, 27) + SourceIndex(0) name (Greeter) +5 >Emitted(58, 31) Source(32, 28) + SourceIndex(0) name (Greeter) --- >>> ], Greeter, "x1"); 1 >^^^^^^^ @@ -732,15 +733,15 @@ sourceFile:sourceMapValidationDecorators.ts > private static 2 > x1 3 > : number = 10; -1 >Emitted(58, 8) Source(33, 20) + SourceIndex(0) name (Greeter) -2 >Emitted(58, 21) Source(33, 22) + SourceIndex(0) name (Greeter) -3 >Emitted(58, 23) Source(33, 36) + SourceIndex(0) name (Greeter) +1 >Emitted(59, 8) Source(33, 20) + SourceIndex(0) name (Greeter) +2 >Emitted(59, 21) Source(33, 22) + SourceIndex(0) name (Greeter) +3 >Emitted(59, 23) Source(33, 36) + SourceIndex(0) name (Greeter) --- >>> Greeter = __decorate([ 1->^^^^ 2 > ^^^^^^^^^^^^^^^^^^^^^-> 1-> -1->Emitted(59, 5) Source(8, 1) + SourceIndex(0) name (Greeter) +1->Emitted(60, 5) Source(8, 1) + SourceIndex(0) name (Greeter) --- >>> ClassDecorator1, 1->^^^^^^^^ @@ -748,8 +749,8 @@ sourceFile:sourceMapValidationDecorators.ts 3 > ^^^^^^-> 1->@ 2 > ClassDecorator1 -1->Emitted(60, 9) Source(8, 2) + SourceIndex(0) name (Greeter) -2 >Emitted(60, 24) Source(8, 17) + SourceIndex(0) name (Greeter) +1->Emitted(61, 9) Source(8, 2) + SourceIndex(0) name (Greeter) +2 >Emitted(61, 24) Source(8, 17) + SourceIndex(0) name (Greeter) --- >>> ClassDecorator2(10), 1->^^^^^^^^ @@ -764,11 +765,11 @@ sourceFile:sourceMapValidationDecorators.ts 3 > ( 4 > 10 5 > ) -1->Emitted(61, 9) Source(9, 2) + SourceIndex(0) name (Greeter) -2 >Emitted(61, 24) Source(9, 17) + SourceIndex(0) name (Greeter) -3 >Emitted(61, 25) Source(9, 18) + SourceIndex(0) name (Greeter) -4 >Emitted(61, 27) Source(9, 20) + SourceIndex(0) name (Greeter) -5 >Emitted(61, 28) Source(9, 21) + SourceIndex(0) name (Greeter) +1->Emitted(62, 9) Source(9, 2) + SourceIndex(0) name (Greeter) +2 >Emitted(62, 24) Source(9, 17) + SourceIndex(0) name (Greeter) +3 >Emitted(62, 25) Source(9, 18) + SourceIndex(0) name (Greeter) +4 >Emitted(62, 27) Source(9, 20) + SourceIndex(0) name (Greeter) +5 >Emitted(62, 28) Source(9, 21) + SourceIndex(0) name (Greeter) --- >>> __param(0, ParameterDecorator1), 1->^^^^^^^^ @@ -783,10 +784,10 @@ sourceFile:sourceMapValidationDecorators.ts 2 > @ 3 > ParameterDecorator1 4 > -1->Emitted(62, 9) Source(12, 7) + SourceIndex(0) name (Greeter) -2 >Emitted(62, 20) Source(12, 8) + SourceIndex(0) name (Greeter) -3 >Emitted(62, 39) Source(12, 27) + SourceIndex(0) name (Greeter) -4 >Emitted(62, 40) Source(12, 27) + SourceIndex(0) name (Greeter) +1->Emitted(63, 9) Source(12, 7) + SourceIndex(0) name (Greeter) +2 >Emitted(63, 20) Source(12, 8) + SourceIndex(0) name (Greeter) +3 >Emitted(63, 39) Source(12, 27) + SourceIndex(0) name (Greeter) +4 >Emitted(63, 40) Source(12, 27) + SourceIndex(0) name (Greeter) --- >>> __param(0, ParameterDecorator2(20)), 1->^^^^^^^^ @@ -804,13 +805,13 @@ sourceFile:sourceMapValidationDecorators.ts 5 > 20 6 > ) 7 > -1->Emitted(63, 9) Source(13, 7) + SourceIndex(0) name (Greeter) -2 >Emitted(63, 20) Source(13, 8) + SourceIndex(0) name (Greeter) -3 >Emitted(63, 39) Source(13, 27) + SourceIndex(0) name (Greeter) -4 >Emitted(63, 40) Source(13, 28) + SourceIndex(0) name (Greeter) -5 >Emitted(63, 42) Source(13, 30) + SourceIndex(0) name (Greeter) -6 >Emitted(63, 43) Source(13, 31) + SourceIndex(0) name (Greeter) -7 >Emitted(63, 44) Source(13, 31) + SourceIndex(0) name (Greeter) +1->Emitted(64, 9) Source(13, 7) + SourceIndex(0) name (Greeter) +2 >Emitted(64, 20) Source(13, 8) + SourceIndex(0) name (Greeter) +3 >Emitted(64, 39) Source(13, 27) + SourceIndex(0) name (Greeter) +4 >Emitted(64, 40) Source(13, 28) + SourceIndex(0) name (Greeter) +5 >Emitted(64, 42) Source(13, 30) + SourceIndex(0) name (Greeter) +6 >Emitted(64, 43) Source(13, 31) + SourceIndex(0) name (Greeter) +7 >Emitted(64, 44) Source(13, 31) + SourceIndex(0) name (Greeter) --- >>> __param(1, ParameterDecorator1), 1 >^^^^^^^^ @@ -825,10 +826,10 @@ sourceFile:sourceMapValidationDecorators.ts 2 > @ 3 > ParameterDecorator1 4 > -1 >Emitted(64, 9) Source(16, 7) + SourceIndex(0) name (Greeter) -2 >Emitted(64, 20) Source(16, 8) + SourceIndex(0) name (Greeter) -3 >Emitted(64, 39) Source(16, 27) + SourceIndex(0) name (Greeter) -4 >Emitted(64, 40) Source(16, 27) + SourceIndex(0) name (Greeter) +1 >Emitted(65, 9) Source(16, 7) + SourceIndex(0) name (Greeter) +2 >Emitted(65, 20) Source(16, 8) + SourceIndex(0) name (Greeter) +3 >Emitted(65, 39) Source(16, 27) + SourceIndex(0) name (Greeter) +4 >Emitted(65, 40) Source(16, 27) + SourceIndex(0) name (Greeter) --- >>> __param(1, ParameterDecorator2(30)) 1->^^^^^^^^ @@ -846,13 +847,13 @@ sourceFile:sourceMapValidationDecorators.ts 5 > 30 6 > ) 7 > -1->Emitted(65, 9) Source(17, 7) + SourceIndex(0) name (Greeter) -2 >Emitted(65, 20) Source(17, 8) + SourceIndex(0) name (Greeter) -3 >Emitted(65, 39) Source(17, 27) + SourceIndex(0) name (Greeter) -4 >Emitted(65, 40) Source(17, 28) + SourceIndex(0) name (Greeter) -5 >Emitted(65, 42) Source(17, 30) + SourceIndex(0) name (Greeter) -6 >Emitted(65, 43) Source(17, 31) + SourceIndex(0) name (Greeter) -7 >Emitted(65, 44) Source(17, 31) + SourceIndex(0) name (Greeter) +1->Emitted(66, 9) Source(17, 7) + SourceIndex(0) name (Greeter) +2 >Emitted(66, 20) Source(17, 8) + SourceIndex(0) name (Greeter) +3 >Emitted(66, 39) Source(17, 27) + SourceIndex(0) name (Greeter) +4 >Emitted(66, 40) Source(17, 28) + SourceIndex(0) name (Greeter) +5 >Emitted(66, 42) Source(17, 30) + SourceIndex(0) name (Greeter) +6 >Emitted(66, 43) Source(17, 31) + SourceIndex(0) name (Greeter) +7 >Emitted(66, 44) Source(17, 31) + SourceIndex(0) name (Greeter) --- >>> ], Greeter); 1 >^^^^^^^^^^^^^^^^ @@ -895,15 +896,15 @@ sourceFile:sourceMapValidationDecorators.ts > this.greeting = greetings; > } >} -1 >Emitted(66, 17) Source(54, 2) + SourceIndex(0) name (Greeter) +1 >Emitted(67, 17) Source(54, 2) + SourceIndex(0) name (Greeter) --- >>> return Greeter; 1->^^^^ 2 > ^^^^^^^^^^^^^^ 1-> 2 > } -1->Emitted(67, 5) Source(54, 1) + SourceIndex(0) name (Greeter) -2 >Emitted(67, 19) Source(54, 2) + SourceIndex(0) name (Greeter) +1->Emitted(68, 5) Source(54, 1) + SourceIndex(0) name (Greeter) +2 >Emitted(68, 19) Source(54, 2) + SourceIndex(0) name (Greeter) --- >>>})(); 1 > @@ -961,9 +962,9 @@ sourceFile:sourceMapValidationDecorators.ts > this.greeting = greetings; > } > } -1 >Emitted(68, 1) Source(54, 1) + SourceIndex(0) name (Greeter) -2 >Emitted(68, 2) Source(54, 2) + SourceIndex(0) name (Greeter) -3 >Emitted(68, 2) Source(8, 1) + SourceIndex(0) -4 >Emitted(68, 6) Source(54, 2) + SourceIndex(0) +1 >Emitted(69, 1) Source(54, 1) + SourceIndex(0) name (Greeter) +2 >Emitted(69, 2) Source(54, 2) + SourceIndex(0) name (Greeter) +3 >Emitted(69, 2) Source(8, 1) + SourceIndex(0) +4 >Emitted(69, 6) Source(54, 2) + SourceIndex(0) --- >>>//# sourceMappingURL=sourceMapValidationDecorators.js.map \ No newline at end of file From 3657d99a5e68f4e0df18ccb6640164e5862723de Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Tue, 21 Apr 2015 16:46:37 -0700 Subject: [PATCH 058/194] Updated LKG --- bin/lib.d.ts | 46 +++++++------- bin/lib.dom.d.ts | 46 +++++++------- bin/lib.es6.d.ts | 46 +++++++------- bin/tsc.js | 107 ++++++++++++++++++++++----------- bin/tsserver.js | 110 ++++++++++++++++++++++----------- bin/typescript.d.ts | 1 + bin/typescript.js | 117 ++++++++++++++++++++++++------------ bin/typescriptServices.d.ts | 1 + bin/typescriptServices.js | 117 ++++++++++++++++++++++++------------ 9 files changed, 370 insertions(+), 221 deletions(-) diff --git a/bin/lib.d.ts b/bin/lib.d.ts index 82a6fa8345c..5eaa933d164 100644 --- a/bin/lib.d.ts +++ b/bin/lib.d.ts @@ -13878,7 +13878,7 @@ interface SourceBuffer extends EventTarget { videoTracks: VideoTrackList; abort(): void; appendBuffer(data: ArrayBuffer): void; - appendBuffer(data: any): void; + appendBuffer(data: ArrayBufferView): void; appendStream(stream: MSStream, maxSize?: number): void; remove(start: number, end: number): void; } @@ -13986,31 +13986,31 @@ declare var StyleSheetPageList: { } interface SubtleCrypto { - decrypt(algorithm: string, key: CryptoKey, data: any): any; - decrypt(algorithm: Algorithm, key: CryptoKey, data: any): any; + decrypt(algorithm: string, key: CryptoKey, data: ArrayBufferView): any; + decrypt(algorithm: Algorithm, key: CryptoKey, data: ArrayBufferView): any; deriveBits(algorithm: string, baseKey: CryptoKey, length: number): any; deriveBits(algorithm: Algorithm, baseKey: CryptoKey, length: number): any; deriveKey(algorithm: string, baseKey: CryptoKey, derivedKeyType: string, extractable: boolean, keyUsages: string[]): any; deriveKey(algorithm: string, baseKey: CryptoKey, derivedKeyType: Algorithm, extractable: boolean, keyUsages: string[]): any; deriveKey(algorithm: Algorithm, baseKey: CryptoKey, derivedKeyType: string, extractable: boolean, keyUsages: string[]): any; deriveKey(algorithm: Algorithm, baseKey: CryptoKey, derivedKeyType: Algorithm, extractable: boolean, keyUsages: string[]): any; - digest(algorithm: string, data: any): any; - digest(algorithm: Algorithm, data: any): any; - encrypt(algorithm: string, key: CryptoKey, data: any): any; - encrypt(algorithm: Algorithm, key: CryptoKey, data: any): any; + digest(algorithm: string, data: ArrayBufferView): any; + digest(algorithm: Algorithm, data: ArrayBufferView): any; + encrypt(algorithm: string, key: CryptoKey, data: ArrayBufferView): any; + encrypt(algorithm: Algorithm, key: CryptoKey, data: ArrayBufferView): any; exportKey(format: string, key: CryptoKey): any; generateKey(algorithm: string, extractable: boolean, keyUsages: string[]): any; generateKey(algorithm: Algorithm, extractable: boolean, keyUsages: string[]): any; - importKey(format: string, keyData: any, algorithm: string, extractable: boolean, keyUsages: string[]): any; - importKey(format: string, keyData: any, algorithm: Algorithm, extractable: boolean, keyUsages: string[]): any; - sign(algorithm: string, key: CryptoKey, data: any): any; - sign(algorithm: Algorithm, key: CryptoKey, data: any): any; - unwrapKey(format: string, wrappedKey: any, unwrappingKey: CryptoKey, unwrapAlgorithm: string, unwrappedKeyAlgorithm: string, extractable: boolean, keyUsages: string[]): any; - unwrapKey(format: string, wrappedKey: any, unwrappingKey: CryptoKey, unwrapAlgorithm: string, unwrappedKeyAlgorithm: Algorithm, extractable: boolean, keyUsages: string[]): any; - unwrapKey(format: string, wrappedKey: any, unwrappingKey: CryptoKey, unwrapAlgorithm: Algorithm, unwrappedKeyAlgorithm: string, extractable: boolean, keyUsages: string[]): any; - unwrapKey(format: string, wrappedKey: any, unwrappingKey: CryptoKey, unwrapAlgorithm: Algorithm, unwrappedKeyAlgorithm: Algorithm, extractable: boolean, keyUsages: string[]): any; - verify(algorithm: string, key: CryptoKey, signature: any, data: any): any; - verify(algorithm: Algorithm, key: CryptoKey, signature: any, data: any): any; + importKey(format: string, keyData: ArrayBufferView, algorithm: string, extractable: boolean, keyUsages: string[]): any; + importKey(format: string, keyData: ArrayBufferView, algorithm: Algorithm, extractable: boolean, keyUsages: string[]): any; + sign(algorithm: string, key: CryptoKey, data: ArrayBufferView): any; + sign(algorithm: Algorithm, key: CryptoKey, data: ArrayBufferView): any; + unwrapKey(format: string, wrappedKey: ArrayBufferView, unwrappingKey: CryptoKey, unwrapAlgorithm: string, unwrappedKeyAlgorithm: string, extractable: boolean, keyUsages: string[]): any; + unwrapKey(format: string, wrappedKey: ArrayBufferView, unwrappingKey: CryptoKey, unwrapAlgorithm: string, unwrappedKeyAlgorithm: Algorithm, extractable: boolean, keyUsages: string[]): any; + unwrapKey(format: string, wrappedKey: ArrayBufferView, unwrappingKey: CryptoKey, unwrapAlgorithm: Algorithm, unwrappedKeyAlgorithm: string, extractable: boolean, keyUsages: string[]): any; + unwrapKey(format: string, wrappedKey: ArrayBufferView, unwrappingKey: CryptoKey, unwrapAlgorithm: Algorithm, unwrappedKeyAlgorithm: Algorithm, extractable: boolean, keyUsages: string[]): any; + verify(algorithm: string, key: CryptoKey, signature: ArrayBufferView, data: ArrayBufferView): any; + verify(algorithm: Algorithm, key: CryptoKey, signature: ArrayBufferView, data: ArrayBufferView): any; wrapKey(format: string, key: CryptoKey, wrappingKey: CryptoKey, wrapAlgorithm: string): any; wrapKey(format: string, key: CryptoKey, wrappingKey: CryptoKey, wrapAlgorithm: Algorithm): any; } @@ -14522,9 +14522,9 @@ interface WebGLRenderingContext { blendFunc(sfactor: number, dfactor: number): void; blendFuncSeparate(srcRGB: number, dstRGB: number, srcAlpha: number, dstAlpha: number): void; bufferData(target: number, size: number, usage: number): void; + bufferData(target: number, size: ArrayBufferView, usage: number): void; bufferData(target: number, size: any, usage: number): void; - bufferData(target: number, size: any, usage: number): void; - bufferSubData(target: number, offset: number, data: any): void; + bufferSubData(target: number, offset: number, data: ArrayBufferView): void; bufferSubData(target: number, offset: number, data: any): void; checkFramebufferStatus(target: number): number; clear(mask: number): void; @@ -14533,8 +14533,8 @@ interface WebGLRenderingContext { clearStencil(s: number): void; colorMask(red: boolean, green: boolean, blue: boolean, alpha: boolean): void; compileShader(shader: WebGLShader): void; - compressedTexImage2D(target: number, level: number, internalformat: number, width: number, height: number, border: number, data: any): void; - compressedTexSubImage2D(target: number, level: number, xoffset: number, yoffset: number, width: number, height: number, format: number, data: any): void; + compressedTexImage2D(target: number, level: number, internalformat: number, width: number, height: number, border: number, data: ArrayBufferView): void; + compressedTexSubImage2D(target: number, level: number, xoffset: number, yoffset: number, width: number, height: number, format: number, data: ArrayBufferView): void; copyTexImage2D(target: number, level: number, internalformat: number, x: number, y: number, width: number, height: number, border: number): void; copyTexSubImage2D(target: number, level: number, xoffset: number, yoffset: number, x: number, y: number, width: number, height: number): void; createBuffer(): WebGLBuffer; @@ -14602,7 +14602,7 @@ interface WebGLRenderingContext { linkProgram(program: WebGLProgram): void; pixelStorei(pname: number, param: number): void; polygonOffset(factor: number, units: number): void; - readPixels(x: number, y: number, width: number, height: number, format: number, type: number, pixels: any): void; + readPixels(x: number, y: number, width: number, height: number, format: number, type: number, pixels: ArrayBufferView): void; renderbufferStorage(target: number, internalformat: number, width: number, height: number): void; sampleCoverage(value: number, invert: boolean): void; scissor(x: number, y: number, width: number, height: number): void; @@ -16026,7 +16026,7 @@ interface NodeSelector { } interface RandomSource { - getRandomValues(array: any): any; + getRandomValues(array: ArrayBufferView): ArrayBufferView; } interface SVGAnimatedPathData { diff --git a/bin/lib.dom.d.ts b/bin/lib.dom.d.ts index d66afb9b27f..2c970a1cf52 100644 --- a/bin/lib.dom.d.ts +++ b/bin/lib.dom.d.ts @@ -12708,7 +12708,7 @@ interface SourceBuffer extends EventTarget { videoTracks: VideoTrackList; abort(): void; appendBuffer(data: ArrayBuffer): void; - appendBuffer(data: any): void; + appendBuffer(data: ArrayBufferView): void; appendStream(stream: MSStream, maxSize?: number): void; remove(start: number, end: number): void; } @@ -12816,31 +12816,31 @@ declare var StyleSheetPageList: { } interface SubtleCrypto { - decrypt(algorithm: string, key: CryptoKey, data: any): any; - decrypt(algorithm: Algorithm, key: CryptoKey, data: any): any; + decrypt(algorithm: string, key: CryptoKey, data: ArrayBufferView): any; + decrypt(algorithm: Algorithm, key: CryptoKey, data: ArrayBufferView): any; deriveBits(algorithm: string, baseKey: CryptoKey, length: number): any; deriveBits(algorithm: Algorithm, baseKey: CryptoKey, length: number): any; deriveKey(algorithm: string, baseKey: CryptoKey, derivedKeyType: string, extractable: boolean, keyUsages: string[]): any; deriveKey(algorithm: string, baseKey: CryptoKey, derivedKeyType: Algorithm, extractable: boolean, keyUsages: string[]): any; deriveKey(algorithm: Algorithm, baseKey: CryptoKey, derivedKeyType: string, extractable: boolean, keyUsages: string[]): any; deriveKey(algorithm: Algorithm, baseKey: CryptoKey, derivedKeyType: Algorithm, extractable: boolean, keyUsages: string[]): any; - digest(algorithm: string, data: any): any; - digest(algorithm: Algorithm, data: any): any; - encrypt(algorithm: string, key: CryptoKey, data: any): any; - encrypt(algorithm: Algorithm, key: CryptoKey, data: any): any; + digest(algorithm: string, data: ArrayBufferView): any; + digest(algorithm: Algorithm, data: ArrayBufferView): any; + encrypt(algorithm: string, key: CryptoKey, data: ArrayBufferView): any; + encrypt(algorithm: Algorithm, key: CryptoKey, data: ArrayBufferView): any; exportKey(format: string, key: CryptoKey): any; generateKey(algorithm: string, extractable: boolean, keyUsages: string[]): any; generateKey(algorithm: Algorithm, extractable: boolean, keyUsages: string[]): any; - importKey(format: string, keyData: any, algorithm: string, extractable: boolean, keyUsages: string[]): any; - importKey(format: string, keyData: any, algorithm: Algorithm, extractable: boolean, keyUsages: string[]): any; - sign(algorithm: string, key: CryptoKey, data: any): any; - sign(algorithm: Algorithm, key: CryptoKey, data: any): any; - unwrapKey(format: string, wrappedKey: any, unwrappingKey: CryptoKey, unwrapAlgorithm: string, unwrappedKeyAlgorithm: string, extractable: boolean, keyUsages: string[]): any; - unwrapKey(format: string, wrappedKey: any, unwrappingKey: CryptoKey, unwrapAlgorithm: string, unwrappedKeyAlgorithm: Algorithm, extractable: boolean, keyUsages: string[]): any; - unwrapKey(format: string, wrappedKey: any, unwrappingKey: CryptoKey, unwrapAlgorithm: Algorithm, unwrappedKeyAlgorithm: string, extractable: boolean, keyUsages: string[]): any; - unwrapKey(format: string, wrappedKey: any, unwrappingKey: CryptoKey, unwrapAlgorithm: Algorithm, unwrappedKeyAlgorithm: Algorithm, extractable: boolean, keyUsages: string[]): any; - verify(algorithm: string, key: CryptoKey, signature: any, data: any): any; - verify(algorithm: Algorithm, key: CryptoKey, signature: any, data: any): any; + importKey(format: string, keyData: ArrayBufferView, algorithm: string, extractable: boolean, keyUsages: string[]): any; + importKey(format: string, keyData: ArrayBufferView, algorithm: Algorithm, extractable: boolean, keyUsages: string[]): any; + sign(algorithm: string, key: CryptoKey, data: ArrayBufferView): any; + sign(algorithm: Algorithm, key: CryptoKey, data: ArrayBufferView): any; + unwrapKey(format: string, wrappedKey: ArrayBufferView, unwrappingKey: CryptoKey, unwrapAlgorithm: string, unwrappedKeyAlgorithm: string, extractable: boolean, keyUsages: string[]): any; + unwrapKey(format: string, wrappedKey: ArrayBufferView, unwrappingKey: CryptoKey, unwrapAlgorithm: string, unwrappedKeyAlgorithm: Algorithm, extractable: boolean, keyUsages: string[]): any; + unwrapKey(format: string, wrappedKey: ArrayBufferView, unwrappingKey: CryptoKey, unwrapAlgorithm: Algorithm, unwrappedKeyAlgorithm: string, extractable: boolean, keyUsages: string[]): any; + unwrapKey(format: string, wrappedKey: ArrayBufferView, unwrappingKey: CryptoKey, unwrapAlgorithm: Algorithm, unwrappedKeyAlgorithm: Algorithm, extractable: boolean, keyUsages: string[]): any; + verify(algorithm: string, key: CryptoKey, signature: ArrayBufferView, data: ArrayBufferView): any; + verify(algorithm: Algorithm, key: CryptoKey, signature: ArrayBufferView, data: ArrayBufferView): any; wrapKey(format: string, key: CryptoKey, wrappingKey: CryptoKey, wrapAlgorithm: string): any; wrapKey(format: string, key: CryptoKey, wrappingKey: CryptoKey, wrapAlgorithm: Algorithm): any; } @@ -13352,9 +13352,9 @@ interface WebGLRenderingContext { blendFunc(sfactor: number, dfactor: number): void; blendFuncSeparate(srcRGB: number, dstRGB: number, srcAlpha: number, dstAlpha: number): void; bufferData(target: number, size: number, usage: number): void; + bufferData(target: number, size: ArrayBufferView, usage: number): void; bufferData(target: number, size: any, usage: number): void; - bufferData(target: number, size: any, usage: number): void; - bufferSubData(target: number, offset: number, data: any): void; + bufferSubData(target: number, offset: number, data: ArrayBufferView): void; bufferSubData(target: number, offset: number, data: any): void; checkFramebufferStatus(target: number): number; clear(mask: number): void; @@ -13363,8 +13363,8 @@ interface WebGLRenderingContext { clearStencil(s: number): void; colorMask(red: boolean, green: boolean, blue: boolean, alpha: boolean): void; compileShader(shader: WebGLShader): void; - compressedTexImage2D(target: number, level: number, internalformat: number, width: number, height: number, border: number, data: any): void; - compressedTexSubImage2D(target: number, level: number, xoffset: number, yoffset: number, width: number, height: number, format: number, data: any): void; + compressedTexImage2D(target: number, level: number, internalformat: number, width: number, height: number, border: number, data: ArrayBufferView): void; + compressedTexSubImage2D(target: number, level: number, xoffset: number, yoffset: number, width: number, height: number, format: number, data: ArrayBufferView): void; copyTexImage2D(target: number, level: number, internalformat: number, x: number, y: number, width: number, height: number, border: number): void; copyTexSubImage2D(target: number, level: number, xoffset: number, yoffset: number, x: number, y: number, width: number, height: number): void; createBuffer(): WebGLBuffer; @@ -13432,7 +13432,7 @@ interface WebGLRenderingContext { linkProgram(program: WebGLProgram): void; pixelStorei(pname: number, param: number): void; polygonOffset(factor: number, units: number): void; - readPixels(x: number, y: number, width: number, height: number, format: number, type: number, pixels: any): void; + readPixels(x: number, y: number, width: number, height: number, format: number, type: number, pixels: ArrayBufferView): void; renderbufferStorage(target: number, internalformat: number, width: number, height: number): void; sampleCoverage(value: number, invert: boolean): void; scissor(x: number, y: number, width: number, height: number): void; @@ -14856,7 +14856,7 @@ interface NodeSelector { } interface RandomSource { - getRandomValues(array: any): any; + getRandomValues(array: ArrayBufferView): ArrayBufferView; } interface SVGAnimatedPathData { diff --git a/bin/lib.es6.d.ts b/bin/lib.es6.d.ts index e2a76a04ae2..297cac973e3 100644 --- a/bin/lib.es6.d.ts +++ b/bin/lib.es6.d.ts @@ -15356,7 +15356,7 @@ interface SourceBuffer extends EventTarget { videoTracks: VideoTrackList; abort(): void; appendBuffer(data: ArrayBuffer): void; - appendBuffer(data: any): void; + appendBuffer(data: ArrayBufferView): void; appendStream(stream: MSStream, maxSize?: number): void; remove(start: number, end: number): void; } @@ -15464,31 +15464,31 @@ declare var StyleSheetPageList: { } interface SubtleCrypto { - decrypt(algorithm: string, key: CryptoKey, data: any): any; - decrypt(algorithm: Algorithm, key: CryptoKey, data: any): any; + decrypt(algorithm: string, key: CryptoKey, data: ArrayBufferView): any; + decrypt(algorithm: Algorithm, key: CryptoKey, data: ArrayBufferView): any; deriveBits(algorithm: string, baseKey: CryptoKey, length: number): any; deriveBits(algorithm: Algorithm, baseKey: CryptoKey, length: number): any; deriveKey(algorithm: string, baseKey: CryptoKey, derivedKeyType: string, extractable: boolean, keyUsages: string[]): any; deriveKey(algorithm: string, baseKey: CryptoKey, derivedKeyType: Algorithm, extractable: boolean, keyUsages: string[]): any; deriveKey(algorithm: Algorithm, baseKey: CryptoKey, derivedKeyType: string, extractable: boolean, keyUsages: string[]): any; deriveKey(algorithm: Algorithm, baseKey: CryptoKey, derivedKeyType: Algorithm, extractable: boolean, keyUsages: string[]): any; - digest(algorithm: string, data: any): any; - digest(algorithm: Algorithm, data: any): any; - encrypt(algorithm: string, key: CryptoKey, data: any): any; - encrypt(algorithm: Algorithm, key: CryptoKey, data: any): any; + digest(algorithm: string, data: ArrayBufferView): any; + digest(algorithm: Algorithm, data: ArrayBufferView): any; + encrypt(algorithm: string, key: CryptoKey, data: ArrayBufferView): any; + encrypt(algorithm: Algorithm, key: CryptoKey, data: ArrayBufferView): any; exportKey(format: string, key: CryptoKey): any; generateKey(algorithm: string, extractable: boolean, keyUsages: string[]): any; generateKey(algorithm: Algorithm, extractable: boolean, keyUsages: string[]): any; - importKey(format: string, keyData: any, algorithm: string, extractable: boolean, keyUsages: string[]): any; - importKey(format: string, keyData: any, algorithm: Algorithm, extractable: boolean, keyUsages: string[]): any; - sign(algorithm: string, key: CryptoKey, data: any): any; - sign(algorithm: Algorithm, key: CryptoKey, data: any): any; - unwrapKey(format: string, wrappedKey: any, unwrappingKey: CryptoKey, unwrapAlgorithm: string, unwrappedKeyAlgorithm: string, extractable: boolean, keyUsages: string[]): any; - unwrapKey(format: string, wrappedKey: any, unwrappingKey: CryptoKey, unwrapAlgorithm: string, unwrappedKeyAlgorithm: Algorithm, extractable: boolean, keyUsages: string[]): any; - unwrapKey(format: string, wrappedKey: any, unwrappingKey: CryptoKey, unwrapAlgorithm: Algorithm, unwrappedKeyAlgorithm: string, extractable: boolean, keyUsages: string[]): any; - unwrapKey(format: string, wrappedKey: any, unwrappingKey: CryptoKey, unwrapAlgorithm: Algorithm, unwrappedKeyAlgorithm: Algorithm, extractable: boolean, keyUsages: string[]): any; - verify(algorithm: string, key: CryptoKey, signature: any, data: any): any; - verify(algorithm: Algorithm, key: CryptoKey, signature: any, data: any): any; + importKey(format: string, keyData: ArrayBufferView, algorithm: string, extractable: boolean, keyUsages: string[]): any; + importKey(format: string, keyData: ArrayBufferView, algorithm: Algorithm, extractable: boolean, keyUsages: string[]): any; + sign(algorithm: string, key: CryptoKey, data: ArrayBufferView): any; + sign(algorithm: Algorithm, key: CryptoKey, data: ArrayBufferView): any; + unwrapKey(format: string, wrappedKey: ArrayBufferView, unwrappingKey: CryptoKey, unwrapAlgorithm: string, unwrappedKeyAlgorithm: string, extractable: boolean, keyUsages: string[]): any; + unwrapKey(format: string, wrappedKey: ArrayBufferView, unwrappingKey: CryptoKey, unwrapAlgorithm: string, unwrappedKeyAlgorithm: Algorithm, extractable: boolean, keyUsages: string[]): any; + unwrapKey(format: string, wrappedKey: ArrayBufferView, unwrappingKey: CryptoKey, unwrapAlgorithm: Algorithm, unwrappedKeyAlgorithm: string, extractable: boolean, keyUsages: string[]): any; + unwrapKey(format: string, wrappedKey: ArrayBufferView, unwrappingKey: CryptoKey, unwrapAlgorithm: Algorithm, unwrappedKeyAlgorithm: Algorithm, extractable: boolean, keyUsages: string[]): any; + verify(algorithm: string, key: CryptoKey, signature: ArrayBufferView, data: ArrayBufferView): any; + verify(algorithm: Algorithm, key: CryptoKey, signature: ArrayBufferView, data: ArrayBufferView): any; wrapKey(format: string, key: CryptoKey, wrappingKey: CryptoKey, wrapAlgorithm: string): any; wrapKey(format: string, key: CryptoKey, wrappingKey: CryptoKey, wrapAlgorithm: Algorithm): any; } @@ -16000,9 +16000,9 @@ interface WebGLRenderingContext { blendFunc(sfactor: number, dfactor: number): void; blendFuncSeparate(srcRGB: number, dstRGB: number, srcAlpha: number, dstAlpha: number): void; bufferData(target: number, size: number, usage: number): void; + bufferData(target: number, size: ArrayBufferView, usage: number): void; bufferData(target: number, size: any, usage: number): void; - bufferData(target: number, size: any, usage: number): void; - bufferSubData(target: number, offset: number, data: any): void; + bufferSubData(target: number, offset: number, data: ArrayBufferView): void; bufferSubData(target: number, offset: number, data: any): void; checkFramebufferStatus(target: number): number; clear(mask: number): void; @@ -16011,8 +16011,8 @@ interface WebGLRenderingContext { clearStencil(s: number): void; colorMask(red: boolean, green: boolean, blue: boolean, alpha: boolean): void; compileShader(shader: WebGLShader): void; - compressedTexImage2D(target: number, level: number, internalformat: number, width: number, height: number, border: number, data: any): void; - compressedTexSubImage2D(target: number, level: number, xoffset: number, yoffset: number, width: number, height: number, format: number, data: any): void; + compressedTexImage2D(target: number, level: number, internalformat: number, width: number, height: number, border: number, data: ArrayBufferView): void; + compressedTexSubImage2D(target: number, level: number, xoffset: number, yoffset: number, width: number, height: number, format: number, data: ArrayBufferView): void; copyTexImage2D(target: number, level: number, internalformat: number, x: number, y: number, width: number, height: number, border: number): void; copyTexSubImage2D(target: number, level: number, xoffset: number, yoffset: number, x: number, y: number, width: number, height: number): void; createBuffer(): WebGLBuffer; @@ -16080,7 +16080,7 @@ interface WebGLRenderingContext { linkProgram(program: WebGLProgram): void; pixelStorei(pname: number, param: number): void; polygonOffset(factor: number, units: number): void; - readPixels(x: number, y: number, width: number, height: number, format: number, type: number, pixels: any): void; + readPixels(x: number, y: number, width: number, height: number, format: number, type: number, pixels: ArrayBufferView): void; renderbufferStorage(target: number, internalformat: number, width: number, height: number): void; sampleCoverage(value: number, invert: boolean): void; scissor(x: number, y: number, width: number, height: number): void; @@ -17504,7 +17504,7 @@ interface NodeSelector { } interface RandomSource { - getRandomValues(array: any): any; + getRandomValues(array: ArrayBufferView): ArrayBufferView; } interface SVGAnimatedPathData { diff --git a/bin/tsc.js b/bin/tsc.js index 3323c446649..49960ff3e50 100644 --- a/bin/tsc.js +++ b/bin/tsc.js @@ -1399,6 +1399,8 @@ var ts; Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures: { code: 6055, category: ts.DiagnosticCategory.Message, key: "Suppress noImplicitAny errors for indexing objects lacking index signatures." }, Do_not_emit_declarations_for_code_that_has_an_internal_annotation: { code: 6056, category: ts.DiagnosticCategory.Message, key: "Do not emit declarations for code that has an '@internal' annotation." }, Preserve_new_lines_when_emitting_code: { code: 6057, category: ts.DiagnosticCategory.Message, key: "Preserve new-lines when emitting code." }, + Specifies_the_root_directory_of_input_files_Use_to_control_the_output_directory_structure_with_outDir: { code: 6058, category: ts.DiagnosticCategory.Message, key: "Specifies the root directory of input files. Use to control the output directory structure with --outDir." }, + File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files: { code: 6059, category: ts.DiagnosticCategory.Error, key: "File '{0}' is not under 'rootDir' '{1}'. 'rootDir' is expected to contain all source files." }, Variable_0_implicitly_has_an_1_type: { code: 7005, category: ts.DiagnosticCategory.Error, key: "Variable '{0}' implicitly has an '{1}' type." }, Parameter_0_implicitly_has_an_1_type: { code: 7006, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' implicitly has an '{1}' type." }, Member_0_implicitly_has_an_1_type: { code: 7008, category: ts.DiagnosticCategory.Error, key: "Member '{0}' implicitly has an '{1}' type." }, @@ -11553,7 +11555,7 @@ var ts; return type; } function combineTypeMappers(mapper1, mapper2) { - return function (t) { return mapper2(mapper1(t)); }; + return function (t) { return instantiateType(mapper1(t), mapper2); }; } function instantiateTypeParameter(typeParameter, mapper) { var result = createType(512); @@ -20156,8 +20158,8 @@ var ts; ts.isExternalModuleOrDeclarationFile = isExternalModuleOrDeclarationFile; function emitFiles(resolver, host, targetSourceFile) { var extendsHelper = "\nvar __extends = this.__extends || function (d, b) {\n for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];\n function __() { this.constructor = d; }\n __.prototype = b.prototype;\n d.prototype = new __();\n};"; - var decorateHelper = "\nvar __decorate = this.__decorate || (typeof Reflect === \"object\" && Reflect.decorate) || function (decorators, target, key, desc) {\n switch (arguments.length) {\n case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);\n case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);\n case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);\n }\n};"; - var metadataHelper = "\nvar __metadata = this.__metadata || (typeof Reflect === \"object\" && Reflect.metadata) || function () { };"; + var decorateHelper = "\nvar __decorate = this.__decorate || function (decorators, target, key, desc) {\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") return Reflect.decorate(decorators, target, key, desc);\n switch (arguments.length) {\n case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);\n case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);\n case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);\n }\n};"; + var metadataHelper = "\nvar __metadata = this.__metadata || function (k, v) {\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(k, v);\n};"; var paramHelper = "\nvar __param = this.__param || function(index, decorator) { return function (target, key) { decorator(target, key, index); } };"; var compilerOptions = host.getCompilerOptions(); var languageVersion = compilerOptions.target || 0; @@ -24441,7 +24443,7 @@ var ts; getDiagnosticsProducingTypeChecker: getDiagnosticsProducingTypeChecker, getCommonSourceDirectory: function () { return commonSourceDirectory; }, emit: emit, - getCurrentDirectory: host.getCurrentDirectory, + getCurrentDirectory: function () { return host.getCurrentDirectory(); }, getNodeCount: function () { return getDiagnosticsProducingTypeChecker().getNodeCount(); }, getIdentifierCount: function () { return getDiagnosticsProducingTypeChecker().getIdentifierCount(); }, getSymbolCount: function () { return getDiagnosticsProducingTypeChecker().getSymbolCount(); }, @@ -24450,14 +24452,14 @@ var ts; return program; function getEmitHost(writeFileCallback) { return { - getCanonicalFileName: host.getCanonicalFileName, + getCanonicalFileName: function (fileName) { return host.getCanonicalFileName(fileName); }, getCommonSourceDirectory: program.getCommonSourceDirectory, getCompilerOptions: program.getCompilerOptions, - getCurrentDirectory: host.getCurrentDirectory, - getNewLine: host.getNewLine, + getCurrentDirectory: function () { return host.getCurrentDirectory(); }, + getNewLine: function () { return host.getNewLine(); }, getSourceFile: program.getSourceFile, getSourceFiles: program.getSourceFiles, - writeFile: writeFileCallback || host.writeFile + writeFile: writeFileCallback || (function (fileName, data, writeByteOrderMark, onError) { return host.writeFile(fileName, data, writeByteOrderMark, onError); }) }; } function getDiagnosticsProducingTypeChecker() { @@ -24663,6 +24665,53 @@ var ts; return findSourceFile(fileName, false, file, nameLiteral.pos, nameLiteral.end - nameLiteral.pos); } } + function computeCommonSourceDirectory(sourceFiles) { + var commonPathComponents; + var currentDirectory = host.getCurrentDirectory(); + ts.forEach(files, function (sourceFile) { + if (ts.isDeclarationFile(sourceFile)) { + return; + } + var sourcePathComponents = ts.getNormalizedPathComponents(sourceFile.fileName, currentDirectory); + sourcePathComponents.pop(); + if (!commonPathComponents) { + commonPathComponents = sourcePathComponents; + return; + } + for (var i = 0, n = Math.min(commonPathComponents.length, sourcePathComponents.length); i < n; i++) { + if (commonPathComponents[i] !== sourcePathComponents[i]) { + if (i === 0) { + diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_find_the_common_subdirectory_path_for_the_input_files)); + return; + } + commonPathComponents.length = i; + break; + } + } + if (sourcePathComponents.length < commonPathComponents.length) { + commonPathComponents.length = sourcePathComponents.length; + } + }); + return ts.getNormalizedPathFromPathComponents(commonPathComponents); + } + function checkSourceFilesBelongToPath(sourceFiles, rootDirectory) { + var allFilesBelongToPath = true; + if (sourceFiles) { + var currentDirectory = host.getCurrentDirectory(); + var absoluteRootDirectoryPath = host.getCanonicalFileName(ts.getNormalizedAbsolutePath(rootDirectory, currentDirectory)); + for (var _i = 0; _i < sourceFiles.length; _i++) { + var sourceFile = sourceFiles[_i]; + if (!ts.isDeclarationFile(sourceFile)) { + var absoluteSourceFilePath = host.getCanonicalFileName(ts.getNormalizedAbsolutePath(sourceFile.fileName, currentDirectory)); + if (absoluteSourceFilePath.indexOf(absoluteRootDirectoryPath) !== 0) { + diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, sourceFile.fileName, options.rootDir)); + allFilesBelongToPath = false; + } + } + } + } + return allFilesBelongToPath; + } function verifyCompilerOptions() { if (options.separateCompilation) { if (options.sourceMap) { @@ -24710,34 +24759,13 @@ var ts; options.sourceRoot || (options.mapRoot && (!options.out || firstExternalModuleSourceFile !== undefined))) { - var commonPathComponents; - ts.forEach(files, function (sourceFile) { - if (!(sourceFile.flags & 2048) - && !ts.fileExtensionIs(sourceFile.fileName, ".js")) { - var sourcePathComponents = ts.getNormalizedPathComponents(sourceFile.fileName, host.getCurrentDirectory()); - sourcePathComponents.pop(); - if (commonPathComponents) { - for (var i = 0; i < Math.min(commonPathComponents.length, sourcePathComponents.length); i++) { - if (commonPathComponents[i] !== sourcePathComponents[i]) { - if (i === 0) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_find_the_common_subdirectory_path_for_the_input_files)); - return; - } - commonPathComponents.length = i; - break; - } - } - if (sourcePathComponents.length < commonPathComponents.length) { - commonPathComponents.length = sourcePathComponents.length; - } - } - else { - commonPathComponents = sourcePathComponents; - } - } - }); - commonSourceDirectory = ts.getNormalizedPathFromPathComponents(commonPathComponents); - if (commonSourceDirectory) { + if (options.rootDir && checkSourceFilesBelongToPath(files, options.rootDir)) { + commonSourceDirectory = ts.getNormalizedAbsolutePath(options.rootDir, host.getCurrentDirectory()); + } + else { + commonSourceDirectory = computeCommonSourceDirectory(files); + } + if (commonSourceDirectory && commonSourceDirectory[commonSourceDirectory.length - 1] !== ts.directorySeparator) { commonSourceDirectory += ts.directorySeparator; } } @@ -24864,6 +24892,13 @@ var ts; type: "boolean", description: ts.Diagnostics.Do_not_emit_comments_to_output }, + { + name: "rootDir", + type: "string", + isFilePath: true, + description: ts.Diagnostics.Specifies_the_root_directory_of_input_files_Use_to_control_the_output_directory_structure_with_outDir, + paramType: ts.Diagnostics.LOCATION + }, { name: "separateCompilation", type: "boolean" diff --git a/bin/tsserver.js b/bin/tsserver.js index b54ac96e5d0..782f4471799 100644 --- a/bin/tsserver.js +++ b/bin/tsserver.js @@ -1399,6 +1399,8 @@ var ts; Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures: { code: 6055, category: ts.DiagnosticCategory.Message, key: "Suppress noImplicitAny errors for indexing objects lacking index signatures." }, Do_not_emit_declarations_for_code_that_has_an_internal_annotation: { code: 6056, category: ts.DiagnosticCategory.Message, key: "Do not emit declarations for code that has an '@internal' annotation." }, Preserve_new_lines_when_emitting_code: { code: 6057, category: ts.DiagnosticCategory.Message, key: "Preserve new-lines when emitting code." }, + Specifies_the_root_directory_of_input_files_Use_to_control_the_output_directory_structure_with_outDir: { code: 6058, category: ts.DiagnosticCategory.Message, key: "Specifies the root directory of input files. Use to control the output directory structure with --outDir." }, + File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files: { code: 6059, category: ts.DiagnosticCategory.Error, key: "File '{0}' is not under 'rootDir' '{1}'. 'rootDir' is expected to contain all source files." }, Variable_0_implicitly_has_an_1_type: { code: 7005, category: ts.DiagnosticCategory.Error, key: "Variable '{0}' implicitly has an '{1}' type." }, Parameter_0_implicitly_has_an_1_type: { code: 7006, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' implicitly has an '{1}' type." }, Member_0_implicitly_has_an_1_type: { code: 7008, category: ts.DiagnosticCategory.Error, key: "Member '{0}' implicitly has an '{1}' type." }, @@ -2796,6 +2798,13 @@ var ts; type: "boolean", description: ts.Diagnostics.Do_not_emit_comments_to_output }, + { + name: "rootDir", + type: "string", + isFilePath: true, + description: ts.Diagnostics.Specifies_the_root_directory_of_input_files_Use_to_control_the_output_directory_structure_with_outDir, + paramType: ts.Diagnostics.LOCATION + }, { name: "separateCompilation", type: "boolean" @@ -11896,7 +11905,7 @@ var ts; return type; } function combineTypeMappers(mapper1, mapper2) { - return function (t) { return mapper2(mapper1(t)); }; + return function (t) { return instantiateType(mapper1(t), mapper2); }; } function instantiateTypeParameter(typeParameter, mapper) { var result = createType(512); @@ -20499,8 +20508,8 @@ var ts; ts.isExternalModuleOrDeclarationFile = isExternalModuleOrDeclarationFile; function emitFiles(resolver, host, targetSourceFile) { var extendsHelper = "\nvar __extends = this.__extends || function (d, b) {\n for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];\n function __() { this.constructor = d; }\n __.prototype = b.prototype;\n d.prototype = new __();\n};"; - var decorateHelper = "\nvar __decorate = this.__decorate || (typeof Reflect === \"object\" && Reflect.decorate) || function (decorators, target, key, desc) {\n switch (arguments.length) {\n case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);\n case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);\n case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);\n }\n};"; - var metadataHelper = "\nvar __metadata = this.__metadata || (typeof Reflect === \"object\" && Reflect.metadata) || function () { };"; + var decorateHelper = "\nvar __decorate = this.__decorate || function (decorators, target, key, desc) {\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") return Reflect.decorate(decorators, target, key, desc);\n switch (arguments.length) {\n case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);\n case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);\n case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);\n }\n};"; + var metadataHelper = "\nvar __metadata = this.__metadata || function (k, v) {\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(k, v);\n};"; var paramHelper = "\nvar __param = this.__param || function(index, decorator) { return function (target, key) { decorator(target, key, index); } };"; var compilerOptions = host.getCompilerOptions(); var languageVersion = compilerOptions.target || 0; @@ -24784,7 +24793,7 @@ var ts; getDiagnosticsProducingTypeChecker: getDiagnosticsProducingTypeChecker, getCommonSourceDirectory: function () { return commonSourceDirectory; }, emit: emit, - getCurrentDirectory: host.getCurrentDirectory, + getCurrentDirectory: function () { return host.getCurrentDirectory(); }, getNodeCount: function () { return getDiagnosticsProducingTypeChecker().getNodeCount(); }, getIdentifierCount: function () { return getDiagnosticsProducingTypeChecker().getIdentifierCount(); }, getSymbolCount: function () { return getDiagnosticsProducingTypeChecker().getSymbolCount(); }, @@ -24793,14 +24802,14 @@ var ts; return program; function getEmitHost(writeFileCallback) { return { - getCanonicalFileName: host.getCanonicalFileName, + getCanonicalFileName: function (fileName) { return host.getCanonicalFileName(fileName); }, getCommonSourceDirectory: program.getCommonSourceDirectory, getCompilerOptions: program.getCompilerOptions, - getCurrentDirectory: host.getCurrentDirectory, - getNewLine: host.getNewLine, + getCurrentDirectory: function () { return host.getCurrentDirectory(); }, + getNewLine: function () { return host.getNewLine(); }, getSourceFile: program.getSourceFile, getSourceFiles: program.getSourceFiles, - writeFile: writeFileCallback || host.writeFile + writeFile: writeFileCallback || (function (fileName, data, writeByteOrderMark, onError) { return host.writeFile(fileName, data, writeByteOrderMark, onError); }) }; } function getDiagnosticsProducingTypeChecker() { @@ -25006,6 +25015,53 @@ var ts; return findSourceFile(fileName, false, file, nameLiteral.pos, nameLiteral.end - nameLiteral.pos); } } + function computeCommonSourceDirectory(sourceFiles) { + var commonPathComponents; + var currentDirectory = host.getCurrentDirectory(); + ts.forEach(files, function (sourceFile) { + if (ts.isDeclarationFile(sourceFile)) { + return; + } + var sourcePathComponents = ts.getNormalizedPathComponents(sourceFile.fileName, currentDirectory); + sourcePathComponents.pop(); + if (!commonPathComponents) { + commonPathComponents = sourcePathComponents; + return; + } + for (var i = 0, n = Math.min(commonPathComponents.length, sourcePathComponents.length); i < n; i++) { + if (commonPathComponents[i] !== sourcePathComponents[i]) { + if (i === 0) { + diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_find_the_common_subdirectory_path_for_the_input_files)); + return; + } + commonPathComponents.length = i; + break; + } + } + if (sourcePathComponents.length < commonPathComponents.length) { + commonPathComponents.length = sourcePathComponents.length; + } + }); + return ts.getNormalizedPathFromPathComponents(commonPathComponents); + } + function checkSourceFilesBelongToPath(sourceFiles, rootDirectory) { + var allFilesBelongToPath = true; + if (sourceFiles) { + var currentDirectory = host.getCurrentDirectory(); + var absoluteRootDirectoryPath = host.getCanonicalFileName(ts.getNormalizedAbsolutePath(rootDirectory, currentDirectory)); + for (var _i = 0; _i < sourceFiles.length; _i++) { + var sourceFile = sourceFiles[_i]; + if (!ts.isDeclarationFile(sourceFile)) { + var absoluteSourceFilePath = host.getCanonicalFileName(ts.getNormalizedAbsolutePath(sourceFile.fileName, currentDirectory)); + if (absoluteSourceFilePath.indexOf(absoluteRootDirectoryPath) !== 0) { + diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, sourceFile.fileName, options.rootDir)); + allFilesBelongToPath = false; + } + } + } + } + return allFilesBelongToPath; + } function verifyCompilerOptions() { if (options.separateCompilation) { if (options.sourceMap) { @@ -25053,34 +25109,13 @@ var ts; options.sourceRoot || (options.mapRoot && (!options.out || firstExternalModuleSourceFile !== undefined))) { - var commonPathComponents; - ts.forEach(files, function (sourceFile) { - if (!(sourceFile.flags & 2048) - && !ts.fileExtensionIs(sourceFile.fileName, ".js")) { - var sourcePathComponents = ts.getNormalizedPathComponents(sourceFile.fileName, host.getCurrentDirectory()); - sourcePathComponents.pop(); - if (commonPathComponents) { - for (var i = 0; i < Math.min(commonPathComponents.length, sourcePathComponents.length); i++) { - if (commonPathComponents[i] !== sourcePathComponents[i]) { - if (i === 0) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_find_the_common_subdirectory_path_for_the_input_files)); - return; - } - commonPathComponents.length = i; - break; - } - } - if (sourcePathComponents.length < commonPathComponents.length) { - commonPathComponents.length = sourcePathComponents.length; - } - } - else { - commonPathComponents = sourcePathComponents; - } - } - }); - commonSourceDirectory = ts.getNormalizedPathFromPathComponents(commonPathComponents); - if (commonSourceDirectory) { + if (options.rootDir && checkSourceFilesBelongToPath(files, options.rootDir)) { + commonSourceDirectory = ts.getNormalizedAbsolutePath(options.rootDir, host.getCurrentDirectory()); + } + else { + commonSourceDirectory = computeCommonSourceDirectory(files); + } + if (commonSourceDirectory && commonSourceDirectory[commonSourceDirectory.length - 1] !== ts.directorySeparator) { commonSourceDirectory += ts.directorySeparator; } } @@ -34835,6 +34870,9 @@ var ts; if (lineText.charAt(i) == " ") { indentPosition--; } + else if (lineText.charAt(i) == "\t") { + indentPosition -= editorOptions.IndentSize; + } else { break; } diff --git a/bin/typescript.d.ts b/bin/typescript.d.ts index 2ce77b9fb70..f86da199763 100644 --- a/bin/typescript.d.ts +++ b/bin/typescript.d.ts @@ -1095,6 +1095,7 @@ declare module "typescript" { preserveConstEnums?: boolean; project?: string; removeComments?: boolean; + rootDir?: string; sourceMap?: boolean; sourceRoot?: string; suppressImplicitAnyIndexErrors?: boolean; diff --git a/bin/typescript.js b/bin/typescript.js index 8b29d8d0252..e012dbafb5b 100644 --- a/bin/typescript.js +++ b/bin/typescript.js @@ -2133,6 +2133,8 @@ var ts; Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures: { code: 6055, category: ts.DiagnosticCategory.Message, key: "Suppress noImplicitAny errors for indexing objects lacking index signatures." }, Do_not_emit_declarations_for_code_that_has_an_internal_annotation: { code: 6056, category: ts.DiagnosticCategory.Message, key: "Do not emit declarations for code that has an '@internal' annotation." }, Preserve_new_lines_when_emitting_code: { code: 6057, category: ts.DiagnosticCategory.Message, key: "Preserve new-lines when emitting code." }, + Specifies_the_root_directory_of_input_files_Use_to_control_the_output_directory_structure_with_outDir: { code: 6058, category: ts.DiagnosticCategory.Message, key: "Specifies the root directory of input files. Use to control the output directory structure with --outDir." }, + File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files: { code: 6059, category: ts.DiagnosticCategory.Error, key: "File '{0}' is not under 'rootDir' '{1}'. 'rootDir' is expected to contain all source files." }, Variable_0_implicitly_has_an_1_type: { code: 7005, category: ts.DiagnosticCategory.Error, key: "Variable '{0}' implicitly has an '{1}' type." }, Parameter_0_implicitly_has_an_1_type: { code: 7006, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' implicitly has an '{1}' type." }, Member_0_implicitly_has_an_1_type: { code: 7008, category: ts.DiagnosticCategory.Error, key: "Member '{0}' implicitly has an '{1}' type." }, @@ -14105,7 +14107,7 @@ var ts; return type; } function combineTypeMappers(mapper1, mapper2) { - return function (t) { return mapper2(mapper1(t)); }; + return function (t) { return instantiateType(mapper1(t), mapper2); }; } function instantiateTypeParameter(typeParameter, mapper) { var result = createType(512 /* TypeParameter */); @@ -24025,9 +24027,9 @@ var ts; // emit output for the __extends helper function var extendsHelper = "\nvar __extends = this.__extends || function (d, b) {\n for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];\n function __() { this.constructor = d; }\n __.prototype = b.prototype;\n d.prototype = new __();\n};"; // emit output for the __decorate helper function - var decorateHelper = "\nvar __decorate = this.__decorate || (typeof Reflect === \"object\" && Reflect.decorate) || function (decorators, target, key, desc) {\n switch (arguments.length) {\n case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);\n case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);\n case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);\n }\n};"; + var decorateHelper = "\nvar __decorate = this.__decorate || function (decorators, target, key, desc) {\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") return Reflect.decorate(decorators, target, key, desc);\n switch (arguments.length) {\n case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);\n case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);\n case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);\n }\n};"; // emit output for the __metadata helper function - var metadataHelper = "\nvar __metadata = this.__metadata || (typeof Reflect === \"object\" && Reflect.metadata) || function () { };"; + var metadataHelper = "\nvar __metadata = this.__metadata || function (k, v) {\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(k, v);\n};"; // emit output for the __param helper function var paramHelper = "\nvar __param = this.__param || function(index, decorator) { return function (target, key) { decorator(target, key, index); } };"; var compilerOptions = host.getCompilerOptions(); @@ -28855,7 +28857,7 @@ var ts; getDiagnosticsProducingTypeChecker: getDiagnosticsProducingTypeChecker, getCommonSourceDirectory: function () { return commonSourceDirectory; }, emit: emit, - getCurrentDirectory: host.getCurrentDirectory, + getCurrentDirectory: function () { return host.getCurrentDirectory(); }, getNodeCount: function () { return getDiagnosticsProducingTypeChecker().getNodeCount(); }, getIdentifierCount: function () { return getDiagnosticsProducingTypeChecker().getIdentifierCount(); }, getSymbolCount: function () { return getDiagnosticsProducingTypeChecker().getSymbolCount(); }, @@ -28864,14 +28866,14 @@ var ts; return program; function getEmitHost(writeFileCallback) { return { - getCanonicalFileName: host.getCanonicalFileName, + getCanonicalFileName: function (fileName) { return host.getCanonicalFileName(fileName); }, getCommonSourceDirectory: program.getCommonSourceDirectory, getCompilerOptions: program.getCompilerOptions, - getCurrentDirectory: host.getCurrentDirectory, - getNewLine: host.getNewLine, + getCurrentDirectory: function () { return host.getCurrentDirectory(); }, + getNewLine: function () { return host.getNewLine(); }, getSourceFile: program.getSourceFile, getSourceFiles: program.getSourceFiles, - writeFile: writeFileCallback || host.writeFile + writeFile: writeFileCallback || (function (fileName, data, writeByteOrderMark, onError) { return host.writeFile(fileName, data, writeByteOrderMark, onError); }) }; } function getDiagnosticsProducingTypeChecker() { @@ -29095,6 +29097,57 @@ var ts; return findSourceFile(fileName, false, file, nameLiteral.pos, nameLiteral.end - nameLiteral.pos); } } + function computeCommonSourceDirectory(sourceFiles) { + var commonPathComponents; + var currentDirectory = host.getCurrentDirectory(); + ts.forEach(files, function (sourceFile) { + // Each file contributes into common source file path + if (ts.isDeclarationFile(sourceFile)) { + return; + } + var sourcePathComponents = ts.getNormalizedPathComponents(sourceFile.fileName, currentDirectory); + sourcePathComponents.pop(); // The base file name is not part of the common directory path + if (!commonPathComponents) { + // first file + commonPathComponents = sourcePathComponents; + return; + } + for (var i = 0, n = Math.min(commonPathComponents.length, sourcePathComponents.length); i < n; i++) { + if (commonPathComponents[i] !== sourcePathComponents[i]) { + if (i === 0) { + diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_find_the_common_subdirectory_path_for_the_input_files)); + return; + } + // New common path found that is 0 -> i-1 + commonPathComponents.length = i; + break; + } + } + // If the sourcePathComponents was shorter than the commonPathComponents, truncate to the sourcePathComponents + if (sourcePathComponents.length < commonPathComponents.length) { + commonPathComponents.length = sourcePathComponents.length; + } + }); + return ts.getNormalizedPathFromPathComponents(commonPathComponents); + } + function checkSourceFilesBelongToPath(sourceFiles, rootDirectory) { + var allFilesBelongToPath = true; + if (sourceFiles) { + var currentDirectory = host.getCurrentDirectory(); + var absoluteRootDirectoryPath = host.getCanonicalFileName(ts.getNormalizedAbsolutePath(rootDirectory, currentDirectory)); + for (var _i = 0; _i < sourceFiles.length; _i++) { + var sourceFile = sourceFiles[_i]; + if (!ts.isDeclarationFile(sourceFile)) { + var absoluteSourceFilePath = host.getCanonicalFileName(ts.getNormalizedAbsolutePath(sourceFile.fileName, currentDirectory)); + if (absoluteSourceFilePath.indexOf(absoluteRootDirectoryPath) !== 0) { + diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, sourceFile.fileName, options.rootDir)); + allFilesBelongToPath = false; + } + } + } + } + return allFilesBelongToPath; + } function verifyCompilerOptions() { if (options.separateCompilation) { if (options.sourceMap) { @@ -29147,38 +29200,15 @@ var ts; options.sourceRoot || (options.mapRoot && (!options.out || firstExternalModuleSourceFile !== undefined))) { - var commonPathComponents; - ts.forEach(files, function (sourceFile) { - // Each file contributes into common source file path - if (!(sourceFile.flags & 2048 /* DeclarationFile */) - && !ts.fileExtensionIs(sourceFile.fileName, ".js")) { - var sourcePathComponents = ts.getNormalizedPathComponents(sourceFile.fileName, host.getCurrentDirectory()); - sourcePathComponents.pop(); // FileName is not part of directory - if (commonPathComponents) { - for (var i = 0; i < Math.min(commonPathComponents.length, sourcePathComponents.length); i++) { - if (commonPathComponents[i] !== sourcePathComponents[i]) { - if (i === 0) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_find_the_common_subdirectory_path_for_the_input_files)); - return; - } - // New common path found that is 0 -> i-1 - commonPathComponents.length = i; - break; - } - } - // If the fileComponent path completely matched and less than already found update the length - if (sourcePathComponents.length < commonPathComponents.length) { - commonPathComponents.length = sourcePathComponents.length; - } - } - else { - // first file - commonPathComponents = sourcePathComponents; - } - } - }); - commonSourceDirectory = ts.getNormalizedPathFromPathComponents(commonPathComponents); - if (commonSourceDirectory) { + if (options.rootDir && checkSourceFilesBelongToPath(files, options.rootDir)) { + // If a rootDir is specified and is valid use it as the commonSourceDirectory + commonSourceDirectory = ts.getNormalizedAbsolutePath(options.rootDir, host.getCurrentDirectory()); + } + else { + // Compute the commonSourceDirectory from the input files + commonSourceDirectory = computeCommonSourceDirectory(files); + } + if (commonSourceDirectory && commonSourceDirectory[commonSourceDirectory.length - 1] !== ts.directorySeparator) { // Make sure directory path ends with directory separator so this string can directly // used to replace with "" to get the relative path of the source file and the relative path doesn't // start with / making it rooted path @@ -29309,6 +29339,13 @@ var ts; type: "boolean", description: ts.Diagnostics.Do_not_emit_comments_to_output }, + { + name: "rootDir", + type: "string", + isFilePath: true, + description: ts.Diagnostics.Specifies_the_root_directory_of_input_files_Use_to_control_the_output_directory_structure_with_outDir, + paramType: ts.Diagnostics.LOCATION + }, { name: "separateCompilation", type: "boolean" diff --git a/bin/typescriptServices.d.ts b/bin/typescriptServices.d.ts index e6d06765c27..cd8ee05add4 100644 --- a/bin/typescriptServices.d.ts +++ b/bin/typescriptServices.d.ts @@ -1095,6 +1095,7 @@ declare module ts { preserveConstEnums?: boolean; project?: string; removeComments?: boolean; + rootDir?: string; sourceMap?: boolean; sourceRoot?: string; suppressImplicitAnyIndexErrors?: boolean; diff --git a/bin/typescriptServices.js b/bin/typescriptServices.js index 8b29d8d0252..e012dbafb5b 100644 --- a/bin/typescriptServices.js +++ b/bin/typescriptServices.js @@ -2133,6 +2133,8 @@ var ts; Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures: { code: 6055, category: ts.DiagnosticCategory.Message, key: "Suppress noImplicitAny errors for indexing objects lacking index signatures." }, Do_not_emit_declarations_for_code_that_has_an_internal_annotation: { code: 6056, category: ts.DiagnosticCategory.Message, key: "Do not emit declarations for code that has an '@internal' annotation." }, Preserve_new_lines_when_emitting_code: { code: 6057, category: ts.DiagnosticCategory.Message, key: "Preserve new-lines when emitting code." }, + Specifies_the_root_directory_of_input_files_Use_to_control_the_output_directory_structure_with_outDir: { code: 6058, category: ts.DiagnosticCategory.Message, key: "Specifies the root directory of input files. Use to control the output directory structure with --outDir." }, + File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files: { code: 6059, category: ts.DiagnosticCategory.Error, key: "File '{0}' is not under 'rootDir' '{1}'. 'rootDir' is expected to contain all source files." }, Variable_0_implicitly_has_an_1_type: { code: 7005, category: ts.DiagnosticCategory.Error, key: "Variable '{0}' implicitly has an '{1}' type." }, Parameter_0_implicitly_has_an_1_type: { code: 7006, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' implicitly has an '{1}' type." }, Member_0_implicitly_has_an_1_type: { code: 7008, category: ts.DiagnosticCategory.Error, key: "Member '{0}' implicitly has an '{1}' type." }, @@ -14105,7 +14107,7 @@ var ts; return type; } function combineTypeMappers(mapper1, mapper2) { - return function (t) { return mapper2(mapper1(t)); }; + return function (t) { return instantiateType(mapper1(t), mapper2); }; } function instantiateTypeParameter(typeParameter, mapper) { var result = createType(512 /* TypeParameter */); @@ -24025,9 +24027,9 @@ var ts; // emit output for the __extends helper function var extendsHelper = "\nvar __extends = this.__extends || function (d, b) {\n for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];\n function __() { this.constructor = d; }\n __.prototype = b.prototype;\n d.prototype = new __();\n};"; // emit output for the __decorate helper function - var decorateHelper = "\nvar __decorate = this.__decorate || (typeof Reflect === \"object\" && Reflect.decorate) || function (decorators, target, key, desc) {\n switch (arguments.length) {\n case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);\n case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);\n case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);\n }\n};"; + var decorateHelper = "\nvar __decorate = this.__decorate || function (decorators, target, key, desc) {\n if (typeof Reflect === \"object\" && typeof Reflect.decorate === \"function\") return Reflect.decorate(decorators, target, key, desc);\n switch (arguments.length) {\n case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);\n case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);\n case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);\n }\n};"; // emit output for the __metadata helper function - var metadataHelper = "\nvar __metadata = this.__metadata || (typeof Reflect === \"object\" && Reflect.metadata) || function () { };"; + var metadataHelper = "\nvar __metadata = this.__metadata || function (k, v) {\n if (typeof Reflect === \"object\" && typeof Reflect.metadata === \"function\") return Reflect.metadata(k, v);\n};"; // emit output for the __param helper function var paramHelper = "\nvar __param = this.__param || function(index, decorator) { return function (target, key) { decorator(target, key, index); } };"; var compilerOptions = host.getCompilerOptions(); @@ -28855,7 +28857,7 @@ var ts; getDiagnosticsProducingTypeChecker: getDiagnosticsProducingTypeChecker, getCommonSourceDirectory: function () { return commonSourceDirectory; }, emit: emit, - getCurrentDirectory: host.getCurrentDirectory, + getCurrentDirectory: function () { return host.getCurrentDirectory(); }, getNodeCount: function () { return getDiagnosticsProducingTypeChecker().getNodeCount(); }, getIdentifierCount: function () { return getDiagnosticsProducingTypeChecker().getIdentifierCount(); }, getSymbolCount: function () { return getDiagnosticsProducingTypeChecker().getSymbolCount(); }, @@ -28864,14 +28866,14 @@ var ts; return program; function getEmitHost(writeFileCallback) { return { - getCanonicalFileName: host.getCanonicalFileName, + getCanonicalFileName: function (fileName) { return host.getCanonicalFileName(fileName); }, getCommonSourceDirectory: program.getCommonSourceDirectory, getCompilerOptions: program.getCompilerOptions, - getCurrentDirectory: host.getCurrentDirectory, - getNewLine: host.getNewLine, + getCurrentDirectory: function () { return host.getCurrentDirectory(); }, + getNewLine: function () { return host.getNewLine(); }, getSourceFile: program.getSourceFile, getSourceFiles: program.getSourceFiles, - writeFile: writeFileCallback || host.writeFile + writeFile: writeFileCallback || (function (fileName, data, writeByteOrderMark, onError) { return host.writeFile(fileName, data, writeByteOrderMark, onError); }) }; } function getDiagnosticsProducingTypeChecker() { @@ -29095,6 +29097,57 @@ var ts; return findSourceFile(fileName, false, file, nameLiteral.pos, nameLiteral.end - nameLiteral.pos); } } + function computeCommonSourceDirectory(sourceFiles) { + var commonPathComponents; + var currentDirectory = host.getCurrentDirectory(); + ts.forEach(files, function (sourceFile) { + // Each file contributes into common source file path + if (ts.isDeclarationFile(sourceFile)) { + return; + } + var sourcePathComponents = ts.getNormalizedPathComponents(sourceFile.fileName, currentDirectory); + sourcePathComponents.pop(); // The base file name is not part of the common directory path + if (!commonPathComponents) { + // first file + commonPathComponents = sourcePathComponents; + return; + } + for (var i = 0, n = Math.min(commonPathComponents.length, sourcePathComponents.length); i < n; i++) { + if (commonPathComponents[i] !== sourcePathComponents[i]) { + if (i === 0) { + diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_find_the_common_subdirectory_path_for_the_input_files)); + return; + } + // New common path found that is 0 -> i-1 + commonPathComponents.length = i; + break; + } + } + // If the sourcePathComponents was shorter than the commonPathComponents, truncate to the sourcePathComponents + if (sourcePathComponents.length < commonPathComponents.length) { + commonPathComponents.length = sourcePathComponents.length; + } + }); + return ts.getNormalizedPathFromPathComponents(commonPathComponents); + } + function checkSourceFilesBelongToPath(sourceFiles, rootDirectory) { + var allFilesBelongToPath = true; + if (sourceFiles) { + var currentDirectory = host.getCurrentDirectory(); + var absoluteRootDirectoryPath = host.getCanonicalFileName(ts.getNormalizedAbsolutePath(rootDirectory, currentDirectory)); + for (var _i = 0; _i < sourceFiles.length; _i++) { + var sourceFile = sourceFiles[_i]; + if (!ts.isDeclarationFile(sourceFile)) { + var absoluteSourceFilePath = host.getCanonicalFileName(ts.getNormalizedAbsolutePath(sourceFile.fileName, currentDirectory)); + if (absoluteSourceFilePath.indexOf(absoluteRootDirectoryPath) !== 0) { + diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files, sourceFile.fileName, options.rootDir)); + allFilesBelongToPath = false; + } + } + } + } + return allFilesBelongToPath; + } function verifyCompilerOptions() { if (options.separateCompilation) { if (options.sourceMap) { @@ -29147,38 +29200,15 @@ var ts; options.sourceRoot || (options.mapRoot && (!options.out || firstExternalModuleSourceFile !== undefined))) { - var commonPathComponents; - ts.forEach(files, function (sourceFile) { - // Each file contributes into common source file path - if (!(sourceFile.flags & 2048 /* DeclarationFile */) - && !ts.fileExtensionIs(sourceFile.fileName, ".js")) { - var sourcePathComponents = ts.getNormalizedPathComponents(sourceFile.fileName, host.getCurrentDirectory()); - sourcePathComponents.pop(); // FileName is not part of directory - if (commonPathComponents) { - for (var i = 0; i < Math.min(commonPathComponents.length, sourcePathComponents.length); i++) { - if (commonPathComponents[i] !== sourcePathComponents[i]) { - if (i === 0) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_find_the_common_subdirectory_path_for_the_input_files)); - return; - } - // New common path found that is 0 -> i-1 - commonPathComponents.length = i; - break; - } - } - // If the fileComponent path completely matched and less than already found update the length - if (sourcePathComponents.length < commonPathComponents.length) { - commonPathComponents.length = sourcePathComponents.length; - } - } - else { - // first file - commonPathComponents = sourcePathComponents; - } - } - }); - commonSourceDirectory = ts.getNormalizedPathFromPathComponents(commonPathComponents); - if (commonSourceDirectory) { + if (options.rootDir && checkSourceFilesBelongToPath(files, options.rootDir)) { + // If a rootDir is specified and is valid use it as the commonSourceDirectory + commonSourceDirectory = ts.getNormalizedAbsolutePath(options.rootDir, host.getCurrentDirectory()); + } + else { + // Compute the commonSourceDirectory from the input files + commonSourceDirectory = computeCommonSourceDirectory(files); + } + if (commonSourceDirectory && commonSourceDirectory[commonSourceDirectory.length - 1] !== ts.directorySeparator) { // Make sure directory path ends with directory separator so this string can directly // used to replace with "" to get the relative path of the source file and the relative path doesn't // start with / making it rooted path @@ -29309,6 +29339,13 @@ var ts; type: "boolean", description: ts.Diagnostics.Do_not_emit_comments_to_output }, + { + name: "rootDir", + type: "string", + isFilePath: true, + description: ts.Diagnostics.Specifies_the_root_directory_of_input_files_Use_to_control_the_output_directory_structure_with_outDir, + paramType: ts.Diagnostics.LOCATION + }, { name: "separateCompilation", type: "boolean" From a17d1cd38c2f475431deac851e7095770b12c79b Mon Sep 17 00:00:00 2001 From: Pedro Maltez Date: Wed, 22 Apr 2015 00:57:59 +0100 Subject: [PATCH 059/194] Add SVG version of logo as per #1375 --- doc/logo.svg | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 doc/logo.svg diff --git a/doc/logo.svg b/doc/logo.svg new file mode 100644 index 00000000000..fc7e0fadd66 --- /dev/null +++ b/doc/logo.svg @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + From 92756e135b08a6d1481c238256d3859c968d0ce0 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 21 Apr 2015 17:01:34 -0700 Subject: [PATCH 060/194] Blocks with locals should be added to the container chain so we can detect name collisions in them. --- src/compiler/binder.ts | 15 +++++++---- src/compiler/scanner.ts | 2 +- .../nameCollisionWithBlockScopedVariable1.js | 25 +++++++++++++++++++ ...eCollisionWithBlockScopedVariable1.symbols | 17 +++++++++++++ ...ameCollisionWithBlockScopedVariable1.types | 19 ++++++++++++++ .../nameCollisionWithBlockScopedVariable1.ts | 10 ++++++++ 6 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 tests/baselines/reference/nameCollisionWithBlockScopedVariable1.js create mode 100644 tests/baselines/reference/nameCollisionWithBlockScopedVariable1.symbols create mode 100644 tests/baselines/reference/nameCollisionWithBlockScopedVariable1.types create mode 100644 tests/cases/compiler/nameCollisionWithBlockScopedVariable1.ts diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 9d6d9fab35b..170f3d3c830 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -239,11 +239,7 @@ module ts { if (symbolKind & SymbolFlags.IsContainer) { container = node; - if (lastContainer) { - lastContainer.nextContainer = container; - } - - lastContainer = container; + addToContainerChain(container); } if (isBlockScopeContainer) { @@ -262,6 +258,14 @@ module ts { blockScopeContainer = savedBlockScopeContainer; } + function addToContainerChain(node: Node) { + if (lastContainer) { + lastContainer.nextContainer = node; + } + + lastContainer = node; + } + function bindDeclaration(node: Declaration, symbolKind: SymbolFlags, symbolExcludes: SymbolFlags, isBlockScopeContainer: boolean) { switch (container.kind) { case SyntaxKind.ModuleDeclaration: @@ -403,6 +407,7 @@ module ts { default: if (!blockScopeContainer.locals) { blockScopeContainer.locals = {}; + addToContainerChain(blockScopeContainer); } declareSymbol(blockScopeContainer.locals, undefined, node, symbolKind, symbolExcludes); } diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index c2b693d6772..df6c20a8107 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -352,7 +352,7 @@ module ts { export function isLineBreak(ch: number): boolean { // ES5 7.3: // The ECMAScript line terminator characters are listed in Table 3. - // Table 3 Line Terminator Characters + // Table 3: Line Terminator Characters // Code Unit Value Name Formal Name // \u000A Line Feed // \u000D Carriage Return diff --git a/tests/baselines/reference/nameCollisionWithBlockScopedVariable1.js b/tests/baselines/reference/nameCollisionWithBlockScopedVariable1.js new file mode 100644 index 00000000000..6a7041a6733 --- /dev/null +++ b/tests/baselines/reference/nameCollisionWithBlockScopedVariable1.js @@ -0,0 +1,25 @@ +//// [nameCollisionWithBlockScopedVariable1.ts] +module M { + export class C { } +} +module M { + { + let M = 0; + new C(); + } +} + +//// [nameCollisionWithBlockScopedVariable1.js] +var M; +(function (M) { + class C { + } + M.C = C; +})(M || (M = {})); +var M; +(function (M_1) { + { + let M = 0; + new M_1.C(); + } +})(M || (M = {})); diff --git a/tests/baselines/reference/nameCollisionWithBlockScopedVariable1.symbols b/tests/baselines/reference/nameCollisionWithBlockScopedVariable1.symbols new file mode 100644 index 00000000000..9c0d01bd8e9 --- /dev/null +++ b/tests/baselines/reference/nameCollisionWithBlockScopedVariable1.symbols @@ -0,0 +1,17 @@ +=== tests/cases/compiler/nameCollisionWithBlockScopedVariable1.ts === +module M { +>M : Symbol(M, Decl(nameCollisionWithBlockScopedVariable1.ts, 0, 0), Decl(nameCollisionWithBlockScopedVariable1.ts, 2, 1)) + + export class C { } +>C : Symbol(C, Decl(nameCollisionWithBlockScopedVariable1.ts, 0, 10)) +} +module M { +>M : Symbol(M, Decl(nameCollisionWithBlockScopedVariable1.ts, 0, 0), Decl(nameCollisionWithBlockScopedVariable1.ts, 2, 1)) + { + let M = 0; +>M : Symbol(M, Decl(nameCollisionWithBlockScopedVariable1.ts, 5, 11)) + + new C(); +>C : Symbol(C, Decl(nameCollisionWithBlockScopedVariable1.ts, 0, 10)) + } +} diff --git a/tests/baselines/reference/nameCollisionWithBlockScopedVariable1.types b/tests/baselines/reference/nameCollisionWithBlockScopedVariable1.types new file mode 100644 index 00000000000..7a3c07af187 --- /dev/null +++ b/tests/baselines/reference/nameCollisionWithBlockScopedVariable1.types @@ -0,0 +1,19 @@ +=== tests/cases/compiler/nameCollisionWithBlockScopedVariable1.ts === +module M { +>M : typeof M + + export class C { } +>C : C +} +module M { +>M : typeof M + { + let M = 0; +>M : number +>0 : number + + new C(); +>new C() : C +>C : typeof C + } +} diff --git a/tests/cases/compiler/nameCollisionWithBlockScopedVariable1.ts b/tests/cases/compiler/nameCollisionWithBlockScopedVariable1.ts new file mode 100644 index 00000000000..231476ee339 --- /dev/null +++ b/tests/cases/compiler/nameCollisionWithBlockScopedVariable1.ts @@ -0,0 +1,10 @@ +// @target: es6 +module M { + export class C { } +} +module M { + { + let M = 0; + new C(); + } +} \ No newline at end of file From 81ebac5d77b90f616a687bd6a0b8466fd09f65ff Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Tue, 21 Apr 2015 17:05:03 -0700 Subject: [PATCH 061/194] Produce type and symbol baseslines when running tests. --- src/harness/compilerRunner.ts | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/harness/compilerRunner.ts b/src/harness/compilerRunner.ts index 42a0cabe48c..3dbd67190e9 100644 --- a/src/harness/compilerRunner.ts +++ b/src/harness/compilerRunner.ts @@ -97,7 +97,7 @@ class CompilerBaselineRunner extends RunnerBase { program = _program; }, function (settings) { harnessCompiler.setCompilerSettings(tcSettings); - }); + }); }); beforeEach(() => { @@ -252,7 +252,7 @@ class CompilerBaselineRunner extends RunnerBase { } }); - it('Correct type baselines for ' + fileName, () => { + it('Correct type/symbol baselines for ' + fileName, () => { if (fileName.indexOf("APISample") >= 0) { return; } @@ -289,8 +289,26 @@ class CompilerBaselineRunner extends RunnerBase { // Produce baselines. The first gives the types for all expressions. // The second gives symbols for all identifiers. - checkBaseLines(/*isSymbolBaseLine:*/ false); - checkBaseLines(/*isSymbolBaseLine:*/ true); + var e1: Error, e2: Error; + try { + checkBaseLines(/*isSymbolBaseLine:*/ false); + } + catch (e) { + e1 = e; + } + + try { + checkBaseLines(/*isSymbolBaseLine:*/ true); + } + catch (e) { + e2 = e; + } + + if (e1 || e2) { + throw e1 || e2; + } + + return; function checkBaseLines(isSymbolBaseLine: boolean) { let fullBaseLine = generateBaseLine(fullResults, isSymbolBaseLine); From 782c55f7711573106461161a12657f6df901c75e Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 21 Apr 2015 17:39:50 -0700 Subject: [PATCH 062/194] Addressing CR feedback --- src/compiler/checker.ts | 41 ++++++++++++++++++----------------------- src/compiler/types.ts | 13 ++++++++----- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 261924dd9a4..9b54f771f21 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2635,32 +2635,28 @@ module ts { } } - function getDeclaredPropertiesOfClassOrInterface(type: InterfaceType): Symbol[] { - resolveDeclaredMembers(type); - return type.declaredProperties; - } - - function resolveDeclaredMembers(type: InterfaceType) { - if (!type.declaredProperties) { + function resolveDeclaredMembers(type: InterfaceType): InterfaceTypeWithDeclaredMembers { + if (!(type).declaredProperties) { var symbol = type.symbol; - type.declaredProperties = getNamedMembers(symbol.members); - type.declaredCallSignatures = getSignaturesOfSymbol(symbol.members["__call"]); - type.declaredConstructSignatures = getSignaturesOfSymbol(symbol.members["__new"]); - type.declaredStringIndexType = getIndexTypeOfSymbol(symbol, IndexKind.String); - type.declaredNumberIndexType = getIndexTypeOfSymbol(symbol, IndexKind.Number); + (type).declaredProperties = getNamedMembers(symbol.members); + (type).declaredCallSignatures = getSignaturesOfSymbol(symbol.members["__call"]); + (type).declaredConstructSignatures = getSignaturesOfSymbol(symbol.members["__new"]); + (type).declaredStringIndexType = getIndexTypeOfSymbol(symbol, IndexKind.String); + (type).declaredNumberIndexType = getIndexTypeOfSymbol(symbol, IndexKind.Number); } + return type; } function resolveClassOrInterfaceMembers(type: InterfaceType): void { - resolveDeclaredMembers(type); - let members = type.symbol.members; - let callSignatures = type.declaredCallSignatures; - let constructSignatures = type.declaredConstructSignatures; - let stringIndexType = type.declaredStringIndexType; - let numberIndexType = type.declaredNumberIndexType; - let baseTypes = getBaseTypes(type); + let target = resolveDeclaredMembers(type); + let members = target.symbol.members; + let callSignatures = target.declaredCallSignatures; + let constructSignatures = target.declaredConstructSignatures; + let stringIndexType = target.declaredStringIndexType; + let numberIndexType = target.declaredNumberIndexType; + let baseTypes = getBaseTypes(target); if (baseTypes.length) { - members = createSymbolTable(type.declaredProperties); + members = createSymbolTable(target.declaredProperties); for (let baseType of baseTypes) { addInheritedMembers(members, getPropertiesOfObjectType(baseType)); callSignatures = concatenate(callSignatures, getSignaturesOfType(baseType, SignatureKind.Call)); @@ -2673,8 +2669,7 @@ module ts { } function resolveTypeReferenceMembers(type: TypeReference): void { - let target = type.target; - resolveDeclaredMembers(target); + let target = resolveDeclaredMembers(type.target); let mapper = createTypeMapper(target.typeParameters, type.typeArguments); let members = createInstantiatedSymbolTable(target.declaredProperties, mapper); let callSignatures = instantiateList(target.declaredCallSignatures, mapper, instantiateSignature); @@ -10139,7 +10134,7 @@ module ts { } let seen: Map<{ prop: Symbol; containingType: Type }> = {}; - forEach(getDeclaredPropertiesOfClassOrInterface(type), p => { seen[p.name] = { prop: p, containingType: type }; }); + forEach(resolveDeclaredMembers(type).declaredProperties, p => { seen[p.name] = { prop: p, containingType: type }; }); let ok = true; for (let base of baseTypes) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 54f2e5e2bd4..353f63e4287 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1485,17 +1485,20 @@ module ts { // Class and interface types (TypeFlags.Class and TypeFlags.Interface) export interface InterfaceType extends ObjectType { typeParameters: TypeParameter[]; // Type parameters (undefined if non-generic) - declaredProperties: Symbol[]; // Declared members (computed by resolveDeclaredMembers) - declaredCallSignatures: Signature[]; // Declared call signatures (computed by resolveDeclaredMembers) - declaredConstructSignatures: Signature[]; // Declared construct signatures (computed by resolveDeclaredMembers) - declaredStringIndexType: Type; // Declared string index type (computed by resolveDeclaredMembers) - declaredNumberIndexType: Type; // Declared numeric index type (computed by resolveDeclaredMembers) } export interface InterfaceTypeWithBaseTypes extends InterfaceType { baseTypes: ObjectType[]; } + export interface InterfaceTypeWithDeclaredMembers extends InterfaceType { + declaredProperties: Symbol[]; // Declared members + declaredCallSignatures: Signature[]; // Declared call signatures + declaredConstructSignatures: Signature[]; // Declared construct signatures + declaredStringIndexType: Type; // Declared string index type + declaredNumberIndexType: Type; // Declared numeric index type + } + // Type references (TypeFlags.Reference) export interface TypeReference extends ObjectType { target: GenericType; // Type reference target From afc3dd3c6206508235b42ec0157343510595554f Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Tue, 21 Apr 2015 22:27:33 -0700 Subject: [PATCH 063/194] addressed PR feedback --- src/compiler/emitter.ts | 55 ++++++++++++++----- .../reference/systemModule10_ES5.errors.txt | 18 ++++++ .../baselines/reference/systemModule10_ES5.js | 32 +++++++++++ tests/cases/compiler/systemModule10_ES5.ts | 12 ++++ 4 files changed, 103 insertions(+), 14 deletions(-) create mode 100644 tests/baselines/reference/systemModule10_ES5.errors.txt create mode 100644 tests/baselines/reference/systemModule10_ES5.js create mode 100644 tests/cases/compiler/systemModule10_ES5.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index d7b5aa61f93..dce57ca15f6 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -117,6 +117,12 @@ var __param = this.__param || function(index, decorator) { return function (targ let decreaseIndent = writer.decreaseIndent; let currentSourceFile: SourceFile; + // name of an exporter function if file is a System external module + // System.register([...], function () {...}) + // exporting in System modules looks like: + // export var x; ... x = 1 + // => + // var x;... exporter("x", x = 1) let exportFunctionForFile: string; let generatedNameSet: Map = {}; @@ -2190,7 +2196,11 @@ var __param = this.__param || function(index, decorator) { return function (targ emitEmbeddedStatement(node.statement); } - function emitStartOfVariableDeclarationList(decl: VariableDeclarationList, startPos?: number): boolean { + /* Returns true if start of variable declaration list was emitted. + * Return false if nothing was written - this can happen for source file level variable declarations + * in system modules - such variable declarations are hoisted. + */ + function tryEmitStartOfVariableDeclarationList(decl: VariableDeclarationList, startPos?: number): boolean { if (shouldHoistVariable(decl, /*checkIfSourceFileLevelDecl*/ true)) { // variables in variable declaration list were already hoisted return false; @@ -2253,7 +2263,7 @@ var __param = this.__param || function(index, decorator) { return function (targ endPos = emitToken(SyntaxKind.OpenParenToken, endPos); if (node.initializer && node.initializer.kind === SyntaxKind.VariableDeclarationList) { let variableDeclarationList = node.initializer; - let startIsEmitted = emitStartOfVariableDeclarationList(variableDeclarationList, endPos); + let startIsEmitted = tryEmitStartOfVariableDeclarationList(variableDeclarationList, endPos); if (startIsEmitted) { emitCommaList(variableDeclarationList.declarations); } @@ -2283,7 +2293,7 @@ var __param = this.__param || function(index, decorator) { return function (targ if (node.initializer.kind === SyntaxKind.VariableDeclarationList) { let variableDeclarationList = node.initializer; if (variableDeclarationList.declarations.length >= 1) { - emitStartOfVariableDeclarationList(variableDeclarationList, endPos); + tryEmitStartOfVariableDeclarationList(variableDeclarationList, endPos); emit(variableDeclarationList.declarations[0]); } } @@ -2664,14 +2674,14 @@ var __param = this.__param || function(index, decorator) { return function (targ // temporary variables in an exported declaration need to have real declarations elsewhere // Also temporary variables should be explicitly allocated for source level declarations when module target is system // because actual variable declarations are hoisted - let canDefineTempVariablesInplace = false; + let canDefineTempVariablesInPlace = false; if (root.kind === SyntaxKind.VariableDeclaration) { let isExported = getCombinedNodeFlags(root) & NodeFlags.Export; let isSourceLevelForSystemModuleKind = isSourceFileLevelDeclarationInSystemExternalModule(root, /*isExported*/ false); - canDefineTempVariablesInplace = !isExported && !isSourceLevelForSystemModuleKind; + canDefineTempVariablesInPlace = !isExported && !isSourceLevelForSystemModuleKind; } else if (root.kind === SyntaxKind.Parameter) { - canDefineTempVariablesInplace = true; + canDefineTempVariablesInPlace = true; } if (root.kind === SyntaxKind.BinaryExpression) { @@ -2718,7 +2728,7 @@ var __param = this.__param || function(index, decorator) { return function (targ function ensureIdentifier(expr: Expression): Expression { if (expr.kind !== SyntaxKind.Identifier) { let identifier = createTempVariable(TempFlags.Auto); - if (!canDefineTempVariablesInplace) { + if (!canDefineTempVariablesInPlace) { recordTempDeclaration(identifier); } emitAssignment(identifier, expr); @@ -3015,12 +3025,12 @@ var __param = this.__param || function(index, decorator) { return function (targ function emitVariableStatement(node: VariableStatement) { let startIsEmitted = true; if (!(node.flags & NodeFlags.Export)) { - startIsEmitted = emitStartOfVariableDeclarationList(node.declarationList); + startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList); } else if (isES6ExportedDeclaration(node)) { // Exported ES6 module member write("export "); - startIsEmitted = emitStartOfVariableDeclarationList(node.declarationList); + startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList); } if (startIsEmitted) { emitCommaList(node.declarationList.declarations); @@ -3922,6 +3932,7 @@ var __param = this.__param || function(index, decorator) { return function (targ function emitClassLikeDeclarationBelowES6(node: ClassLikeDeclaration) { if (node.kind === SyntaxKind.ClassDeclaration) { + // source file level classes in system modules are hoisted so 'var's for them are already defined if (!isSourceFileLevelDeclarationInSystemExternalModule(node, /*isExported*/ false)) { write("var "); } @@ -4962,18 +4973,30 @@ var __param = this.__param || function(index, decorator) { return function (targ function visit(node: Node): void { if (node.kind === SyntaxKind.FunctionDeclaration) { - (hoistedFunctionDeclarations || (hoistedFunctionDeclarations = [])).push(node); + if (!hoistedFunctionDeclarations) { + hoistedFunctionDeclarations = []; + } + + hoistedFunctionDeclarations.push(node); return; } if (node.kind === SyntaxKind.ClassDeclaration) { // TODO: rename block scoped classes - (hoistedVars || (hoistedVars = [])).push(node); + if (!hoistedVars) { + hoistedVars = []; + } + + hoistedVars.push(node); return; } if (node.kind === SyntaxKind.ModuleDeclaration && shouldEmitModuleDeclaration(node)) { - (hoistedVars || (hoistedVars = [])).push(node); + if (!hoistedVars) { + hoistedVars = []; + } + + hoistedVars.push(node); return; } @@ -4981,7 +5004,11 @@ var __param = this.__param || function(index, decorator) { return function (targ if (shouldHoistVariable(node, /*checkIfSourceFileLevelDecl*/ false)) { let name = (node).name; if (name.kind === SyntaxKind.Identifier) { - (hoistedVars || (hoistedVars = [])).push(name); + if (!hoistedVars) { + hoistedVars = []; + } + + hoistedVars.push(name); } else { forEachChild(name, visit); @@ -5072,7 +5099,7 @@ var __param = this.__param || function(index, decorator) { return function (targ } function emitSetters() { - write("setters:[") + write("setters:["); for (let i = 0; i < externalImports.length; ++i) { if (i !== 0) { write(","); diff --git a/tests/baselines/reference/systemModule10_ES5.errors.txt b/tests/baselines/reference/systemModule10_ES5.errors.txt new file mode 100644 index 00000000000..5c384837a84 --- /dev/null +++ b/tests/baselines/reference/systemModule10_ES5.errors.txt @@ -0,0 +1,18 @@ +tests/cases/compiler/systemModule10_ES5.ts(2,20): error TS2307: Cannot find external module 'file1'. +tests/cases/compiler/systemModule10_ES5.ts(3,21): error TS2307: Cannot find external module 'file2'. + + +==== tests/cases/compiler/systemModule10_ES5.ts (2 errors) ==== + + import n, {x} from 'file1' + ~~~~~~~ +!!! error TS2307: Cannot find external module 'file1'. + import n2 = require('file2'); + ~~~~~~~ +!!! error TS2307: Cannot find external module 'file2'. + export {x} + export {x as y} + export {n} + export {n as n1} + export {n2} + export {n2 as n3} \ No newline at end of file diff --git a/tests/baselines/reference/systemModule10_ES5.js b/tests/baselines/reference/systemModule10_ES5.js new file mode 100644 index 00000000000..04c946d9abe --- /dev/null +++ b/tests/baselines/reference/systemModule10_ES5.js @@ -0,0 +1,32 @@ +//// [systemModule10_ES5.ts] + +import n, {x} from 'file1' +import n2 = require('file2'); +export {x} +export {x as y} +export {n} +export {n as n1} +export {n2} +export {n2 as n3} + +//// [systemModule10_ES5.js] +System.register(['file1', 'file2'], function(exports_1) { + var file1_1, n2; + return { + setters:[ + function (_file1_1) { + file1_1 = _file1_1 + exports_1("n", file1_1.default); + exports_1("n1", file1_1.default); + exports_1("x", file1_1.x); + exports_1("y", file1_1.x); + }, + function (_n2) { + n2 = _n2 + exports_1("n2", n2); + exports_1("n3", n2); + }], + execute: function() { + } + } +}); diff --git a/tests/cases/compiler/systemModule10_ES5.ts b/tests/cases/compiler/systemModule10_ES5.ts new file mode 100644 index 00000000000..6468e4125d1 --- /dev/null +++ b/tests/cases/compiler/systemModule10_ES5.ts @@ -0,0 +1,12 @@ +// @target: es5 +// @module: system +// @separateCompilation: true + +import n, {x} from 'file1' +import n2 = require('file2'); +export {x} +export {x as y} +export {n} +export {n as n1} +export {n2} +export {n2 as n3} \ No newline at end of file From 378b5ffd1af2249658c8b7a3dc7465d911af93ff Mon Sep 17 00:00:00 2001 From: Colin Snover Date: Fri, 3 Apr 2015 06:05:58 +0000 Subject: [PATCH 064/194] Add support for UMD-like module export format The new module format enables global-less universal modules, compatible with both AMD and CJS module loaders. Fixes #2036. --- src/compiler/commandLineParser.ts | 7 +- .../diagnosticInformationMap.generated.ts | 4 +- src/compiler/diagnosticMessages.json | 4 +- src/compiler/emitter.ts | 68 ++++++++--- src/compiler/types.ts | 1 + src/harness/harness.ts | 2 + tests/baselines/reference/es5-umd.js | 32 +++++ tests/baselines/reference/es5-umd.js.map | 2 + .../baselines/reference/es5-umd.sourcemap.txt | 115 ++++++++++++++++++ tests/baselines/reference/es5-umd.symbols | 17 +++ tests/baselines/reference/es5-umd.types | 18 +++ .../umdDependencyComment2.errors.txt | 11 ++ .../reference/umdDependencyComment2.js | 20 +++ .../umdDependencyCommentName1.errors.txt | 11 ++ .../reference/umdDependencyCommentName1.js | 20 +++ .../umdDependencyCommentName2.errors.txt | 13 ++ .../reference/umdDependencyCommentName2.js | 24 ++++ tests/cases/compiler/es5-umd.ts | 17 +++ tests/cases/compiler/umdDependencyComment2.ts | 5 + .../compiler/umdDependencyCommentName1.ts | 5 + .../compiler/umdDependencyCommentName2.ts | 7 ++ 21 files changed, 378 insertions(+), 25 deletions(-) create mode 100644 tests/baselines/reference/es5-umd.js create mode 100644 tests/baselines/reference/es5-umd.js.map create mode 100644 tests/baselines/reference/es5-umd.sourcemap.txt create mode 100644 tests/baselines/reference/es5-umd.symbols create mode 100644 tests/baselines/reference/es5-umd.types create mode 100644 tests/baselines/reference/umdDependencyComment2.errors.txt create mode 100644 tests/baselines/reference/umdDependencyComment2.js create mode 100644 tests/baselines/reference/umdDependencyCommentName1.errors.txt create mode 100644 tests/baselines/reference/umdDependencyCommentName1.js create mode 100644 tests/baselines/reference/umdDependencyCommentName2.errors.txt create mode 100644 tests/baselines/reference/umdDependencyCommentName2.js create mode 100644 tests/cases/compiler/es5-umd.ts create mode 100644 tests/cases/compiler/umdDependencyComment2.ts create mode 100644 tests/cases/compiler/umdDependencyCommentName1.ts create mode 100644 tests/cases/compiler/umdDependencyCommentName2.ts diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 47f0594a76e..adb0e2d37c5 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -50,11 +50,12 @@ module ts { shortName: "m", type: { "commonjs": ModuleKind.CommonJS, - "amd": ModuleKind.AMD + "amd": ModuleKind.AMD, + "umd": ModuleKind.UMD }, - description: Diagnostics.Specify_module_code_generation_Colon_commonjs_or_amd, + description: Diagnostics.Specify_module_code_generation_Colon_commonjs_amd_or_umd, paramType: Diagnostics.KIND, - error: Diagnostics.Argument_for_module_option_must_be_commonjs_or_amd + error: Diagnostics.Argument_for_module_option_must_be_commonjs_amd_or_umd }, { name: "noEmit", diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 90f0ed0a0df..f03b2ea16b3 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -463,7 +463,7 @@ module ts { Do_not_emit_comments_to_output: { code: 6009, category: DiagnosticCategory.Message, key: "Do not emit comments to output." }, Do_not_emit_outputs: { code: 6010, category: DiagnosticCategory.Message, key: "Do not emit outputs." }, Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental: { code: 6015, category: DiagnosticCategory.Message, key: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES6' (experimental)" }, - Specify_module_code_generation_Colon_commonjs_or_amd: { code: 6016, category: DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs' or 'amd'" }, + Specify_module_code_generation_Colon_commonjs_amd_or_umd: { code: 6016, category: DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs', 'amd', or 'umd'" }, Print_this_message: { code: 6017, category: DiagnosticCategory.Message, key: "Print this message." }, Print_the_compiler_s_version: { code: 6019, category: DiagnosticCategory.Message, key: "Print the compiler's version." }, Compile_the_project_in_the_given_directory: { code: 6020, category: DiagnosticCategory.Message, key: "Compile the project in the given directory." }, @@ -484,7 +484,7 @@ module ts { Generates_corresponding_map_file: { code: 6043, category: DiagnosticCategory.Message, key: "Generates corresponding '.map' file." }, Compiler_option_0_expects_an_argument: { code: 6044, category: DiagnosticCategory.Error, key: "Compiler option '{0}' expects an argument." }, Unterminated_quoted_string_in_response_file_0: { code: 6045, category: DiagnosticCategory.Error, key: "Unterminated quoted string in response file '{0}'." }, - Argument_for_module_option_must_be_commonjs_or_amd: { code: 6046, category: DiagnosticCategory.Error, key: "Argument for '--module' option must be 'commonjs' or 'amd'." }, + Argument_for_module_option_must_be_commonjs_amd_or_umd: { code: 6046, category: DiagnosticCategory.Error, key: "Argument for '--module' option must be 'commonjs', 'amd', or 'umd'." }, Argument_for_target_option_must_be_es3_es5_or_es6: { code: 6047, category: DiagnosticCategory.Error, key: "Argument for '--target' option must be 'es3', 'es5', or 'es6'." }, Locale_must_be_of_the_form_language_or_language_territory_For_example_0_or_1: { code: 6048, category: DiagnosticCategory.Error, key: "Locale must be of the form or -. For example '{0}' or '{1}'." }, Unsupported_locale_0: { code: 6049, category: DiagnosticCategory.Error, key: "Unsupported locale '{0}'." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 48ef245c766..7192987f810 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1840,7 +1840,7 @@ "category": "Message", "code": 6015 }, - "Specify module code generation: 'commonjs' or 'amd'": { + "Specify module code generation: 'commonjs', 'amd', or 'umd'": { "category": "Message", "code": 6016 }, @@ -1924,7 +1924,7 @@ "category": "Error", "code": 6045 }, - "Argument for '--module' option must be 'commonjs' or 'amd'.": { + "Argument for '--module' option must be 'commonjs', 'amd', or 'umd'.": { "category": "Error", "code": 6046 }, diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index f4aa0fe1022..5a3c227931c 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4645,27 +4645,25 @@ var __param = this.__param || function(index, decorator) { return function (targ } } - function emitAMDModule(node: SourceFile, startIndex: number) { - collectExternalModuleInfo(node); - + function emitAMDDependencies(node: SourceFile, includeNonAmdDependencies: boolean) { // An AMD define function has the following shape: // define(id?, dependencies?, factory); // // This has the shape of // define(name, ["module1", "module2"], function (module1Alias) { - // The location of the alias in the parameter list in the factory function needs to + // The location of the alias in the parameter list in the factory function needs to // match the position of the module name in the dependency list. // - // To ensure this is true in cases of modules with no aliases, e.g.: - // `import "module"` or `` + // To ensure this is true in cases of modules with no aliases, e.g.: + // `import "module"` or `` // we need to add modules without alias names to the end of the dependencies list - - let aliasedModuleNames: string[] = []; // names of modules with corresponding parameter in the + + let aliasedModuleNames: string[] = []; // names of modules with corresponding parameter in the // factory function. let unaliasedModuleNames: string[] = []; // names of modules with no corresponding parameters in // factory function. - let importAliasNames: string[] = []; // names of the parameters in the factory function; these - // paramters need to match the indexes of the corresponding + let importAliasNames: string[] = []; // names of the parameters in the factory function; these + // parameters need to match the indexes of the corresponding // module names in aliasedModuleNames. // Fill in amd-dependency tags @@ -4687,7 +4685,7 @@ var __param = this.__param || function(index, decorator) { return function (targ externalModuleName = getLiteralText(moduleName); } - // Find the name of the module alais, if there is one + // Find the name of the module alias, if there is one let importAliasName: string; let namespaceDeclaration = getNamespaceDeclarationNode(importNode); if (namespaceDeclaration && !isDefaultImport(importNode)) { @@ -4697,7 +4695,7 @@ var __param = this.__param || function(index, decorator) { return function (targ importAliasName = getGeneratedNameForNode(importNode); } - if (importAliasName) { + if (includeNonAmdDependencies && importAliasName) { aliasedModuleNames.push(externalModuleName); importAliasNames.push(importAliasName); } @@ -4705,12 +4703,7 @@ var __param = this.__param || function(index, decorator) { return function (targ unaliasedModuleNames.push(externalModuleName); } } - - writeLine(); - write("define("); - if (node.amdModuleName) { - write("\"" + node.amdModuleName + "\", "); - } + write("[\"require\", \"exports\""); if (aliasedModuleNames.length) { write(", "); @@ -4725,6 +4718,17 @@ var __param = this.__param || function(index, decorator) { return function (targ write(", "); write(importAliasNames.join(", ")); } + } + + function emitAMDModule(node: SourceFile, startIndex: number) { + collectExternalModuleInfo(node); + + writeLine(); + write("define("); + if (node.amdModuleName) { + write("\"" + node.amdModuleName + "\", "); + } + emitAMDDependencies(node, /*includeNonAmdDependencies*/ true); write(") {"); increaseIndent(); emitExportStarHelper(); @@ -4746,6 +4750,31 @@ var __param = this.__param || function(index, decorator) { return function (targ emitExportEquals(/*emitAsReturn*/ false); } + function emitUMDModule(node: SourceFile, startIndex: number) { + collectExternalModuleInfo(node); + + // Module is detected first to support Browserify users that load into a browser with an AMD loader + writeLines(`(function (deps, factory) { + if (typeof module === 'object' && typeof module.exports === 'object') { + var v = factory(require, exports); if (v !== undefined) module.exports = v; + } + else if (typeof define === 'function' && define.amd) { + define(deps, factory); + } +})(`); + emitAMDDependencies(node, false); + write(") {"); + increaseIndent(); + emitExportStarHelper(); + emitCaptureThisForNodeIfNecessary(node); + emitLinesStartingAt(node.statements, startIndex); + emitTempDeclarations(/*newLine*/ true); + emitExportEquals(/*emitAsReturn*/ true); + decreaseIndent(); + writeLine(); + write("});"); + } + function emitES6Module(node: SourceFile, startIndex: number) { externalImports = undefined; exportSpecifiers = undefined; @@ -4830,6 +4859,9 @@ var __param = this.__param || function(index, decorator) { return function (targ else if (compilerOptions.module === ModuleKind.AMD) { emitAMDModule(node, startIndex); } + else if (compilerOptions.module === ModuleKind.UMD) { + emitUMDModule(node, startIndex); + } else { emitCommonJSModule(node, startIndex); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index bff15a1ab9d..deb8cafc095 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1671,6 +1671,7 @@ module ts { None = 0, CommonJS = 1, AMD = 2, + UMD = 3, } export interface LineAndCharacter { diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 784d8312d69..bec929b7dbf 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -957,6 +957,8 @@ module Harness { if (typeof setting.value === 'string') { if (setting.value.toLowerCase() === 'amd') { options.module = ts.ModuleKind.AMD; + } else if (setting.value.toLowerCase() === 'umd') { + options.module = ts.ModuleKind.UMD; } else if (setting.value.toLowerCase() === 'commonjs') { options.module = ts.ModuleKind.CommonJS; } else if (setting.value.toLowerCase() === 'unspecified') { diff --git a/tests/baselines/reference/es5-umd.js b/tests/baselines/reference/es5-umd.js new file mode 100644 index 00000000000..2fe8d686242 --- /dev/null +++ b/tests/baselines/reference/es5-umd.js @@ -0,0 +1,32 @@ +//// [es5-umd.ts] + +class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} + + +//// [es5-umd.js] +var A = (function () { + function A() { + } + A.prototype.B = function () { + return 42; + }; + return A; +})(); +//# sourceMappingURL=es5-umd.js.map + +//// [es5-umd.d.ts] +declare class A { + constructor(); + B(): number; +} diff --git a/tests/baselines/reference/es5-umd.js.map b/tests/baselines/reference/es5-umd.js.map new file mode 100644 index 00000000000..785990dc2cb --- /dev/null +++ b/tests/baselines/reference/es5-umd.js.map @@ -0,0 +1,2 @@ +//// [es5-umd.js.map] +{"version":3,"file":"es5-umd.js","sourceRoot":"","sources":["es5-umd.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 diff --git a/tests/baselines/reference/es5-umd.sourcemap.txt b/tests/baselines/reference/es5-umd.sourcemap.txt new file mode 100644 index 00000000000..55413ee1eb2 --- /dev/null +++ b/tests/baselines/reference/es5-umd.sourcemap.txt @@ -0,0 +1,115 @@ +=================================================================== +JsFile: es5-umd.js +mapUrl: es5-umd.js.map +sourceRoot: +sources: es5-umd.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/es5-umd.js +sourceFile:es5-umd.ts +------------------------------------------------------------------- +>>>var A = (function () { +1 > +2 >^^^^^^^^^^^^^^^^^^^-> +1 > + > +1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) +--- +>>> function A() { +1->^^^^ +2 > ^^-> +1->class A + >{ + > +1->Emitted(2, 5) Source(4, 5) + SourceIndex(0) name (A) +--- +>>> } +1->^^^^ +2 > ^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1->constructor () + > { + > + > +2 > } +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 () { +1->^^^^ +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) +--- +>>> return 42; +1 >^^^^^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^ +5 > ^ +1 >public B() + > { + > +2 > return +3 > +4 > 42 +5 > ; +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 > +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) +--- +>>>//# sourceMappingURL=es5-umd.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es5-umd.symbols b/tests/baselines/reference/es5-umd.symbols new file mode 100644 index 00000000000..1914a7877c1 --- /dev/null +++ b/tests/baselines/reference/es5-umd.symbols @@ -0,0 +1,17 @@ +=== tests/cases/compiler/es5-umd.ts === + +class A +>A : Symbol(A, Decl(es5-umd.ts, 0, 0)) +{ + constructor () + { + + } + + public B() +>B : Symbol(B, Decl(es5-umd.ts, 6, 5)) + { + return 42; + } +} + diff --git a/tests/baselines/reference/es5-umd.types b/tests/baselines/reference/es5-umd.types new file mode 100644 index 00000000000..f0e513e8b88 --- /dev/null +++ b/tests/baselines/reference/es5-umd.types @@ -0,0 +1,18 @@ +=== tests/cases/compiler/es5-umd.ts === + +class A +>A : A +{ + constructor () + { + + } + + public B() +>B : () => number + { + return 42; +>42 : number + } +} + diff --git a/tests/baselines/reference/umdDependencyComment2.errors.txt b/tests/baselines/reference/umdDependencyComment2.errors.txt new file mode 100644 index 00000000000..1e85844af64 --- /dev/null +++ b/tests/baselines/reference/umdDependencyComment2.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/umdDependencyComment2.ts(3,21): error TS2307: Cannot find external module 'm2'. + + +==== tests/cases/compiler/umdDependencyComment2.ts (1 errors) ==== + /// + + import m1 = require("m2") + ~~~~ +!!! error TS2307: Cannot find external module 'm2'. + m1.f(); + \ No newline at end of file diff --git a/tests/baselines/reference/umdDependencyComment2.js b/tests/baselines/reference/umdDependencyComment2.js new file mode 100644 index 00000000000..462dad2daca --- /dev/null +++ b/tests/baselines/reference/umdDependencyComment2.js @@ -0,0 +1,20 @@ +//// [umdDependencyComment2.ts] +/// + +import m1 = require("m2") +m1.f(); + + +//// [umdDependencyComment2.js] +/// +(function (deps, factory) { + if (typeof module === 'object' && typeof module.exports === 'object') { + var v = factory(require, exports); if (v !== undefined) module.exports = v; + } + else if (typeof define === 'function' && define.amd) { + define(deps, factory); + } +})(["require", "exports", "bar", "m2"], function (require, exports) { + var m1 = require("m2"); + m1.f(); +}); diff --git a/tests/baselines/reference/umdDependencyCommentName1.errors.txt b/tests/baselines/reference/umdDependencyCommentName1.errors.txt new file mode 100644 index 00000000000..080ae2d852a --- /dev/null +++ b/tests/baselines/reference/umdDependencyCommentName1.errors.txt @@ -0,0 +1,11 @@ +tests/cases/compiler/umdDependencyCommentName1.ts(3,21): error TS2307: Cannot find external module 'm2'. + + +==== tests/cases/compiler/umdDependencyCommentName1.ts (1 errors) ==== + /// + + import m1 = require("m2") + ~~~~ +!!! error TS2307: Cannot find external module 'm2'. + m1.f(); + \ No newline at end of file diff --git a/tests/baselines/reference/umdDependencyCommentName1.js b/tests/baselines/reference/umdDependencyCommentName1.js new file mode 100644 index 00000000000..20ef7c1326f --- /dev/null +++ b/tests/baselines/reference/umdDependencyCommentName1.js @@ -0,0 +1,20 @@ +//// [umdDependencyCommentName1.ts] +/// + +import m1 = require("m2") +m1.f(); + + +//// [umdDependencyCommentName1.js] +/// +(function (deps, factory) { + if (typeof module === 'object' && typeof module.exports === 'object') { + var v = factory(require, exports); if (v !== undefined) module.exports = v; + } + else if (typeof define === 'function' && define.amd) { + define(deps, factory); + } +})(["require", "exports", "bar", "m2"], function (require, exports, b) { + var m1 = require("m2"); + m1.f(); +}); diff --git a/tests/baselines/reference/umdDependencyCommentName2.errors.txt b/tests/baselines/reference/umdDependencyCommentName2.errors.txt new file mode 100644 index 00000000000..903ca4ecfaf --- /dev/null +++ b/tests/baselines/reference/umdDependencyCommentName2.errors.txt @@ -0,0 +1,13 @@ +tests/cases/compiler/umdDependencyCommentName2.ts(5,21): error TS2307: Cannot find external module 'm2'. + + +==== tests/cases/compiler/umdDependencyCommentName2.ts (1 errors) ==== + /// + /// + /// + + import m1 = require("m2") + ~~~~ +!!! error TS2307: Cannot find external module 'm2'. + m1.f(); + \ No newline at end of file diff --git a/tests/baselines/reference/umdDependencyCommentName2.js b/tests/baselines/reference/umdDependencyCommentName2.js new file mode 100644 index 00000000000..22a0cc709bc --- /dev/null +++ b/tests/baselines/reference/umdDependencyCommentName2.js @@ -0,0 +1,24 @@ +//// [umdDependencyCommentName2.ts] +/// +/// +/// + +import m1 = require("m2") +m1.f(); + + +//// [umdDependencyCommentName2.js] +/// +/// +/// +(function (deps, factory) { + if (typeof module === 'object' && typeof module.exports === 'object') { + var v = factory(require, exports); if (v !== undefined) module.exports = v; + } + else if (typeof define === 'function' && define.amd) { + define(deps, factory); + } +})(["require", "exports", "bar", "goo", "foo", "m2"], function (require, exports, b, c) { + var m1 = require("m2"); + m1.f(); +}); diff --git a/tests/cases/compiler/es5-umd.ts b/tests/cases/compiler/es5-umd.ts new file mode 100644 index 00000000000..d0f65f76982 --- /dev/null +++ b/tests/cases/compiler/es5-umd.ts @@ -0,0 +1,17 @@ +// @target: ES5 +// @sourcemap: false +// @declaration: false +// @module: umd + +class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} diff --git a/tests/cases/compiler/umdDependencyComment2.ts b/tests/cases/compiler/umdDependencyComment2.ts new file mode 100644 index 00000000000..87e4fd48526 --- /dev/null +++ b/tests/cases/compiler/umdDependencyComment2.ts @@ -0,0 +1,5 @@ +//@module: umd +/// + +import m1 = require("m2") +m1.f(); diff --git a/tests/cases/compiler/umdDependencyCommentName1.ts b/tests/cases/compiler/umdDependencyCommentName1.ts new file mode 100644 index 00000000000..90b852c9bfd --- /dev/null +++ b/tests/cases/compiler/umdDependencyCommentName1.ts @@ -0,0 +1,5 @@ +//@module: umd +/// + +import m1 = require("m2") +m1.f(); diff --git a/tests/cases/compiler/umdDependencyCommentName2.ts b/tests/cases/compiler/umdDependencyCommentName2.ts new file mode 100644 index 00000000000..bbdd847b84b --- /dev/null +++ b/tests/cases/compiler/umdDependencyCommentName2.ts @@ -0,0 +1,7 @@ +//@module: umd +/// +/// +/// + +import m1 = require("m2") +m1.f(); From 4dc9da255fa9f55c9e9de8ef29f69c9f9b48bc77 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Wed, 22 Apr 2015 13:23:52 -0700 Subject: [PATCH 065/194] Fix Iterator type in es6.d.ts --- src/lib/es6.d.ts | 4 ++-- tests/baselines/reference/for-of30.errors.txt | 4 ++-- tests/baselines/reference/for-of31.errors.txt | 4 ++-- tests/baselines/reference/iteratorSpreadInArray9.errors.txt | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/lib/es6.d.ts b/src/lib/es6.d.ts index b81a3341a6c..888ded962ef 100644 --- a/src/lib/es6.d.ts +++ b/src/lib/es6.d.ts @@ -442,8 +442,8 @@ interface IteratorResult { } interface Iterator { - next(): IteratorResult; - return?(value?: any): IteratorResult; + next(value?: any): IteratorResult; + return?(value?: T): IteratorResult; throw?(e?: any): IteratorResult; } diff --git a/tests/baselines/reference/for-of30.errors.txt b/tests/baselines/reference/for-of30.errors.txt index 6434b5294d5..bc93a031bf5 100644 --- a/tests/baselines/reference/for-of30.errors.txt +++ b/tests/baselines/reference/for-of30.errors.txt @@ -3,7 +3,7 @@ tests/cases/conformance/es6/for-ofStatements/for-of30.ts(1,15): error TS2322: Ty Type '() => StringIterator' is not assignable to type '() => Iterator'. Type 'StringIterator' is not assignable to type 'Iterator'. Types of property 'return' are incompatible. - Type 'number' is not assignable to type '(value?: any) => IteratorResult'. + Type 'number' is not assignable to type '(value?: string) => IteratorResult'. ==== tests/cases/conformance/es6/for-ofStatements/for-of30.ts (1 errors) ==== @@ -14,7 +14,7 @@ tests/cases/conformance/es6/for-ofStatements/for-of30.ts(1,15): error TS2322: Ty !!! error TS2322: Type '() => StringIterator' is not assignable to type '() => Iterator'. !!! error TS2322: Type 'StringIterator' is not assignable to type 'Iterator'. !!! error TS2322: Types of property 'return' are incompatible. -!!! error TS2322: Type 'number' is not assignable to type '(value?: any) => IteratorResult'. +!!! error TS2322: Type 'number' is not assignable to type '(value?: string) => IteratorResult'. class StringIterator { next() { diff --git a/tests/baselines/reference/for-of31.errors.txt b/tests/baselines/reference/for-of31.errors.txt index 74afff00e99..6d5f6e816be 100644 --- a/tests/baselines/reference/for-of31.errors.txt +++ b/tests/baselines/reference/for-of31.errors.txt @@ -3,7 +3,7 @@ tests/cases/conformance/es6/for-ofStatements/for-of31.ts(1,15): error TS2322: Ty Type '() => StringIterator' is not assignable to type '() => Iterator'. Type 'StringIterator' is not assignable to type 'Iterator'. Types of property 'next' are incompatible. - Type '() => { value: string; }' is not assignable to type '() => IteratorResult'. + Type '() => { value: string; }' is not assignable to type '(value?: any) => IteratorResult'. Type '{ value: string; }' is not assignable to type 'IteratorResult'. Property 'done' is missing in type '{ value: string; }'. @@ -16,7 +16,7 @@ tests/cases/conformance/es6/for-ofStatements/for-of31.ts(1,15): error TS2322: Ty !!! error TS2322: Type '() => StringIterator' is not assignable to type '() => Iterator'. !!! error TS2322: Type 'StringIterator' is not assignable to type 'Iterator'. !!! error TS2322: Types of property 'next' are incompatible. -!!! error TS2322: Type '() => { value: string; }' is not assignable to type '() => IteratorResult'. +!!! error TS2322: Type '() => { value: string; }' is not assignable to type '(value?: any) => IteratorResult'. !!! error TS2322: Type '{ value: string; }' is not assignable to type 'IteratorResult'. !!! error TS2322: Property 'done' is missing in type '{ value: string; }'. diff --git a/tests/baselines/reference/iteratorSpreadInArray9.errors.txt b/tests/baselines/reference/iteratorSpreadInArray9.errors.txt index e0e3d061f16..90b8bdbeb46 100644 --- a/tests/baselines/reference/iteratorSpreadInArray9.errors.txt +++ b/tests/baselines/reference/iteratorSpreadInArray9.errors.txt @@ -3,7 +3,7 @@ tests/cases/conformance/es6/spread/iteratorSpreadInArray9.ts(1,17): error TS2322 Type '() => SymbolIterator' is not assignable to type '() => Iterator'. Type 'SymbolIterator' is not assignable to type 'Iterator'. Types of property 'next' are incompatible. - Type '() => { value: symbol; }' is not assignable to type '() => IteratorResult'. + Type '() => { value: symbol; }' is not assignable to type '(value?: any) => IteratorResult'. Type '{ value: symbol; }' is not assignable to type 'IteratorResult'. Property 'done' is missing in type '{ value: symbol; }'. @@ -16,7 +16,7 @@ tests/cases/conformance/es6/spread/iteratorSpreadInArray9.ts(1,17): error TS2322 !!! error TS2322: Type '() => SymbolIterator' is not assignable to type '() => Iterator'. !!! error TS2322: Type 'SymbolIterator' is not assignable to type 'Iterator'. !!! error TS2322: Types of property 'next' are incompatible. -!!! error TS2322: Type '() => { value: symbol; }' is not assignable to type '() => IteratorResult'. +!!! error TS2322: Type '() => { value: symbol; }' is not assignable to type '(value?: any) => IteratorResult'. !!! error TS2322: Type '{ value: symbol; }' is not assignable to type 'IteratorResult'. !!! error TS2322: Property 'done' is missing in type '{ value: symbol; }'. From 4487fa426b4aca9ebd7bc4b293d4173d9b0491e6 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Wed, 22 Apr 2015 13:29:50 -0700 Subject: [PATCH 066/194] Rename iterator property of ForStatement to incrementor --- src/compiler/checker.ts | 2 +- src/compiler/emitter.ts | 2 +- src/compiler/parser.ts | 4 ++-- src/compiler/types.ts | 2 +- src/compiler/utilities.ts | 2 +- src/services/breakpoints.ts | 4 ++-- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d5e5b5c67e4..268db63ebb0 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9367,7 +9367,7 @@ module ts { } if (node.condition) checkExpression(node.condition); - if (node.iterator) checkExpression(node.iterator); + if (node.incrementor) checkExpression(node.incrementor); checkSourceElement(node.statement); } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index f4aa0fe1022..bb65078009f 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2138,7 +2138,7 @@ var __param = this.__param || function(index, decorator) { return function (targ write(";"); emitOptional(" ", node.condition); write(";"); - emitOptional(" ", node.iterator); + emitOptional(" ", node.incrementor); write(")"); emitEmbeddedStatement(node.statement); } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 6ad38ac73c1..1a06a2743ba 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -194,7 +194,7 @@ module ts { case SyntaxKind.ForStatement: return visitNode(cbNode, (node).initializer) || visitNode(cbNode, (node).condition) || - visitNode(cbNode, (node).iterator) || + visitNode(cbNode, (node).incrementor) || visitNode(cbNode, (node).statement); case SyntaxKind.ForInStatement: return visitNode(cbNode, (node).initializer) || @@ -3497,7 +3497,7 @@ module ts { } parseExpected(SyntaxKind.SemicolonToken); if (token !== SyntaxKind.CloseParenToken) { - forStatement.iterator = allowInAnd(parseExpression); + forStatement.incrementor = allowInAnd(parseExpression); } parseExpected(SyntaxKind.CloseParenToken); forOrForInOrForOfStatement = forStatement; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index bff15a1ab9d..66a5d7ed030 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -795,7 +795,7 @@ module ts { export interface ForStatement extends IterationStatement { initializer?: VariableDeclarationList | Expression; condition?: Expression; - iterator?: Expression; + incrementor?: Expression; } export interface ForInStatement extends IterationStatement { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index b1aa59be323..eabfb7e256a 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -775,7 +775,7 @@ module ts { let forStatement = parent; return (forStatement.initializer === node && forStatement.initializer.kind !== SyntaxKind.VariableDeclarationList) || forStatement.condition === node || - forStatement.iterator === node; + forStatement.incrementor === node; case SyntaxKind.ForInStatement: case SyntaxKind.ForOfStatement: let forInStatement = parent; diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index caed0582c33..19235269f22 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -401,8 +401,8 @@ module ts.BreakpointResolver { if (forStatement.condition) { return textSpan(forStatement.condition); } - if (forStatement.iterator) { - return textSpan(forStatement.iterator); + if (forStatement.incrementor) { + return textSpan(forStatement.incrementor); } } From 2a2ef28fc6aeca3f0957fd900eb426cd7050ca8f Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Wed, 22 Apr 2015 13:38:30 -0700 Subject: [PATCH 067/194] Undo the change to return --- src/lib/es6.d.ts | 2 +- tests/baselines/reference/for-of30.errors.txt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/es6.d.ts b/src/lib/es6.d.ts index 888ded962ef..71778ecf907 100644 --- a/src/lib/es6.d.ts +++ b/src/lib/es6.d.ts @@ -443,7 +443,7 @@ interface IteratorResult { interface Iterator { next(value?: any): IteratorResult; - return?(value?: T): IteratorResult; + return?(value?: any): IteratorResult; throw?(e?: any): IteratorResult; } diff --git a/tests/baselines/reference/for-of30.errors.txt b/tests/baselines/reference/for-of30.errors.txt index bc93a031bf5..6434b5294d5 100644 --- a/tests/baselines/reference/for-of30.errors.txt +++ b/tests/baselines/reference/for-of30.errors.txt @@ -3,7 +3,7 @@ tests/cases/conformance/es6/for-ofStatements/for-of30.ts(1,15): error TS2322: Ty Type '() => StringIterator' is not assignable to type '() => Iterator'. Type 'StringIterator' is not assignable to type 'Iterator'. Types of property 'return' are incompatible. - Type 'number' is not assignable to type '(value?: string) => IteratorResult'. + Type 'number' is not assignable to type '(value?: any) => IteratorResult'. ==== tests/cases/conformance/es6/for-ofStatements/for-of30.ts (1 errors) ==== @@ -14,7 +14,7 @@ tests/cases/conformance/es6/for-ofStatements/for-of30.ts(1,15): error TS2322: Ty !!! error TS2322: Type '() => StringIterator' is not assignable to type '() => Iterator'. !!! error TS2322: Type 'StringIterator' is not assignable to type 'Iterator'. !!! error TS2322: Types of property 'return' are incompatible. -!!! error TS2322: Type 'number' is not assignable to type '(value?: string) => IteratorResult'. +!!! error TS2322: Type 'number' is not assignable to type '(value?: any) => IteratorResult'. class StringIterator { next() { From b1472d99f2c898105fcfee6164097d27aae45972 Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Wed, 22 Apr 2015 14:27:05 -0700 Subject: [PATCH 068/194] Add error handling. --- src/services/shims.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/services/shims.ts b/src/services/shims.ts index a8de3b817c4..99df0e093a4 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -802,17 +802,27 @@ module ts { return this.forwardJSONCall( "getTSConfigFileInfo('" + fileName + "')", () => { - var text = sourceTextSnapshot.getText(0, sourceTextSnapshot.getLength()); - var json = /\S/.test(text) ? JSON.parse(text) : {}; + let text = sourceTextSnapshot.getText(0, sourceTextSnapshot.getLength()); - var configFile = parseConfigFile(json, this.host, getDirectoryPath(normalizeSlashes(fileName))); + try { + var json = /\S/.test(text) ? JSON.parse(text) : {}; + } + catch (e) { + return { + options: {}, + files: [], + errors: realizeDiagnostic(createCompilerDiagnostic(Diagnostics.Unable_to_open_file_0, fileName), '\r\n') + } + } - var realErrors = realizeDiagnostics(configFile.errors, '\r\n'); + if (json) { + var configFile = parseConfigFile(json, this.host, getDirectoryPath(normalizeSlashes(fileName))); + } return { options: configFile.options, files: configFile.fileNames, - errors: realErrors + errors: realizeDiagnostics(configFile.errors, '\r\n') }; }); } From 5c44a0ff3e93628a4cf59509c103dc827504d317 Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Wed, 22 Apr 2015 15:58:04 -0700 Subject: [PATCH 069/194] Improve error message when encountering an invalid tsconfig.json file. --- src/compiler/commandLineParser.ts | 2 +- src/compiler/diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 4 ++++ src/compiler/tsc.ts | 9 ++++++--- src/services/shims.ts | 2 +- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 3645695ca76..a83e742a122 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -299,7 +299,7 @@ module ts { * @param basePath A root directory to resolve relative path entries in the config * file to. e.g. outDir */ - export function parseConfigFile(json: any, host: ParseConfigHost, basePath?: string): ParsedCommandLine { + export function parseConfigFile(json: any, host: ParseConfigHost, basePath: string): ParsedCommandLine { var errors: Diagnostic[] = []; return { diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 90f0ed0a0df..df7928d5717 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -439,6 +439,7 @@ module ts { 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." }, Cannot_read_file_0_Colon_1: { code: 5012, category: DiagnosticCategory.Error, key: "Cannot read file '{0}': {1}" }, Unsupported_file_encoding: { code: 5013, category: DiagnosticCategory.Error, key: "Unsupported file encoding." }, + Failed_to_parse_file_0_Colon_1: { code: 5014, category: DiagnosticCategory.Error, key: "Failed to parse file '{0}': {1}." }, Unknown_compiler_option_0: { code: 5023, category: DiagnosticCategory.Error, key: "Unknown compiler option '{0}'." }, Compiler_option_0_requires_a_value_of_type_1: { code: 5024, category: DiagnosticCategory.Error, key: "Compiler option '{0}' requires a value of type {1}." }, Could_not_write_file_0_Colon_1: { code: 5033, category: DiagnosticCategory.Error, key: "Could not write file '{0}': {1}" }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 48ef245c766..afd21593f81 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1744,6 +1744,10 @@ "category": "Error", "code": 5013 }, + "Failed to parse file '{0}': {1}.": { + "category": "Error", + "code": 5014 + }, "Unknown compiler option '{0}'.": { "category": "Error", "code": 5023 diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 7eb86efbfae..89464e6b6e4 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -208,9 +208,12 @@ module ts { if (!cachedProgram) { if (configFileName) { - var configObject = readConfigFile(configFileName); - if (!configObject) { - reportDiagnostic(createCompilerDiagnostic(Diagnostics.Unable_to_open_file_0, configFileName)); + try { + var configObject = readConfigFile(configFileName); + } + catch (e) + { + reportDiagnostic(createCompilerDiagnostic(Diagnostics.Failed_to_parse_file_0_Colon_1, configFileName, e.message)); return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); } var configParseResult = parseConfigFile(configObject, sys, getDirectoryPath(configFileName)); diff --git a/src/services/shims.ts b/src/services/shims.ts index 99df0e093a4..6caec3cd23f 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -811,7 +811,7 @@ module ts { return { options: {}, files: [], - errors: realizeDiagnostic(createCompilerDiagnostic(Diagnostics.Unable_to_open_file_0, fileName), '\r\n') + errors: realizeDiagnostic(createCompilerDiagnostic(Diagnostics.Failed_to_parse_file_0_Colon_1, fileName, e.message), '\r\n') } } From f8424d0b0c91a487a2c8cc226c89ffb359816b7b Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Wed, 22 Apr 2015 18:00:09 -0700 Subject: [PATCH 070/194] Minor clean up to make it more readable. --- src/compiler/commandLineParser.ts | 5 +++-- src/compiler/tsc.ts | 16 ++++++++-------- src/services/shims.ts | 24 +++++++++++++++--------- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index a83e742a122..b477c97fec8 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -284,12 +284,13 @@ module ts { * Read tsconfig.json file * @param fileName The path to the config file */ - export function readConfigFile(fileName: string): any { + export function readConfigFile(fileName: string): { config?: any; error?: Diagnostic } { try { var text = sys.readFile(fileName); - return /\S/.test(text) ? JSON.parse(text) : {}; + return { config: /\S/.test(text) ? JSON.parse(text) : {} }; } catch (e) { + return { error: createCompilerDiagnostic(Diagnostics.Failed_to_parse_file_0_Colon_1, fileName, e.message) }; } } diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 89464e6b6e4..15cc665e351 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -208,15 +208,15 @@ module ts { if (!cachedProgram) { if (configFileName) { - try { - var configObject = readConfigFile(configFileName); - } - catch (e) - { - reportDiagnostic(createCompilerDiagnostic(Diagnostics.Failed_to_parse_file_0_Colon_1, configFileName, e.message)); + + let result = readConfigFile(configFileName); + if (result.error) { + reportDiagnostic(result.error); return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); } - var configParseResult = parseConfigFile(configObject, sys, getDirectoryPath(configFileName)); + + let configObject = result.config; + let configParseResult = parseConfigFile(configObject, sys, getDirectoryPath(configFileName)); if (configParseResult.errors.length > 0) { reportDiagnostics(configParseResult.errors); return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); @@ -233,7 +233,7 @@ module ts { compilerHost.getSourceFile = getSourceFile; } - var compileResult = compile(rootFileNames, compilerOptions, compilerHost); + let compileResult = compile(rootFileNames, compilerOptions, compilerHost); if (!compilerOptions.watch) { return sys.exit(compileResult.exitStatus); diff --git a/src/services/shims.ts b/src/services/shims.ts index 6caec3cd23f..ddcc32b8640 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -804,20 +804,17 @@ module ts { () => { let text = sourceTextSnapshot.getText(0, sourceTextSnapshot.getLength()); - try { - var json = /\S/.test(text) ? JSON.parse(text) : {}; - } - catch (e) { + let result = this.parseConfigFileText(fileName, text); + + if (result.error) { return { options: {}, files: [], - errors: realizeDiagnostic(createCompilerDiagnostic(Diagnostics.Failed_to_parse_file_0_Colon_1, fileName, e.message), '\r\n') - } + errors: [realizeDiagnostic(result.error, '/r/n')] + }; } - if (json) { - var configFile = parseConfigFile(json, this.host, getDirectoryPath(normalizeSlashes(fileName))); - } + var configFile = parseConfigFile(result.config, this.host, getDirectoryPath(normalizeSlashes(fileName))); return { options: configFile.options, @@ -827,6 +824,15 @@ module ts { }); } + private parseConfigFileText(fileName: string, jsonText: string): { config?: any; error?: Diagnostic } { + try { + return { config: /\S/.test(jsonText) ? JSON.parse(jsonText) : {} }; + } + catch (e) { + return { error: createCompilerDiagnostic(Diagnostics.Failed_to_parse_file_0_Colon_1, fileName, e.message) }; + } + } + public getDefaultCompilationSettings(): string { return this.forwardJSONCall( "getDefaultCompilationSettings()", From 8955d7ba572803cbb9f4353f1cc641bdf6f52bf1 Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Wed, 22 Apr 2015 18:09:55 -0700 Subject: [PATCH 071/194] More refactoring --- src/compiler/commandLineParser.ts | 18 ++++++++++++++++-- src/services/shims.ts | 11 +---------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index b477c97fec8..a4b25b08d23 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -284,10 +284,24 @@ module ts { * Read tsconfig.json file * @param fileName The path to the config file */ - export function readConfigFile(fileName: string): { config?: any; error?: Diagnostic } { + export function readConfigFile(fileName: string): { config?: any; error?: Diagnostic } { try { var text = sys.readFile(fileName); - return { config: /\S/.test(text) ? JSON.parse(text) : {} }; + return parseConfigFileText(fileName, text); + } + catch (e) { + return { error: createCompilerDiagnostic(Diagnostics.Cannot_read_file_0_Colon_1, fileName, e.message) }; + } + } + + /** + * Parse the text of the tsconfig.json file + * @param fileName The path to the config file + * @param jsonText The text of the config file + */ + export function parseConfigFileText(fileName: string, jsonText: string): { config?: any; error?: Diagnostic } { + try { + return { config: /\S/.test(jsonText) ? JSON.parse(jsonText) : {} }; } catch (e) { return { error: createCompilerDiagnostic(Diagnostics.Failed_to_parse_file_0_Colon_1, fileName, e.message) }; diff --git a/src/services/shims.ts b/src/services/shims.ts index ddcc32b8640..5c08e503b1c 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -804,7 +804,7 @@ module ts { () => { let text = sourceTextSnapshot.getText(0, sourceTextSnapshot.getLength()); - let result = this.parseConfigFileText(fileName, text); + let result = parseConfigFileText(fileName, text); if (result.error) { return { @@ -824,15 +824,6 @@ module ts { }); } - private parseConfigFileText(fileName: string, jsonText: string): { config?: any; error?: Diagnostic } { - try { - return { config: /\S/.test(jsonText) ? JSON.parse(jsonText) : {} }; - } - catch (e) { - return { error: createCompilerDiagnostic(Diagnostics.Failed_to_parse_file_0_Colon_1, fileName, e.message) }; - } - } - public getDefaultCompilationSettings(): string { return this.forwardJSONCall( "getDefaultCompilationSettings()", From 05b95c30ff4142ae0dec915ebb5938d7518c8cd5 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 22 Apr 2015 21:46:10 -0700 Subject: [PATCH 072/194] fixed formatting for equals token in type aliases --- src/services/formatting/rules.ts | 8 +++++--- .../fourslash/formattingEqualsBeforeBracketInTypeAlias.ts | 6 ++++++ 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 tests/cases/fourslash/formattingEqualsBeforeBracketInTypeAlias.ts diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index 73b586e3706..23c835eaec2 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -458,7 +458,11 @@ module ts.formatting { case SyntaxKind.BinaryExpression: case SyntaxKind.ConditionalExpression: return true; - + + // equals in binding elements: function foo([[x, y] = [1, 2]]) + case SyntaxKind.BindingElement: + // equals in type X = ... + case SyntaxKind.TypeAliasDeclaration: // equal in import a = module('a'); case SyntaxKind.ImportEqualsDeclaration: // equal in let a = 0; @@ -475,8 +479,6 @@ module ts.formatting { // Technically, "of" is not a binary operator, but format it the same way as "in" case SyntaxKind.ForOfStatement: return context.currentTokenSpan.kind === SyntaxKind.OfKeyword || context.nextTokenSpan.kind === SyntaxKind.OfKeyword; - case SyntaxKind.BindingElement: - return context.currentTokenSpan.kind === SyntaxKind.EqualsToken || context.nextTokenSpan.kind === SyntaxKind.EqualsToken; } return false; } diff --git a/tests/cases/fourslash/formattingEqualsBeforeBracketInTypeAlias.ts b/tests/cases/fourslash/formattingEqualsBeforeBracketInTypeAlias.ts new file mode 100644 index 00000000000..043ff2247a9 --- /dev/null +++ b/tests/cases/fourslash/formattingEqualsBeforeBracketInTypeAlias.ts @@ -0,0 +1,6 @@ +/// + +////type X = [number]/*1*/ +goTo.marker("1"); +edit.insert(";"); +verify.currentLineContentIs("type X = [number];"); \ No newline at end of file From f96dbd151c70fd8decdd0899724c9fe2638c1f84 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 23 Apr 2015 09:37:20 -0700 Subject: [PATCH 073/194] Fix #2837: remove (y, x) from the comment --- src/lib/core.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/core.d.ts b/src/lib/core.d.ts index 822b7ca5202..c03ab344ab2 100644 --- a/src/lib/core.d.ts +++ b/src/lib/core.d.ts @@ -546,7 +546,7 @@ interface Math { */ atan(x: number): number; /** - * Returns the angle (in radians) from the X axis to a point (y,x). + * Returns the angle (in radians) from the X axis to a point. * @param y A numeric expression representing the cartesian y-coordinate. * @param x A numeric expression representing the cartesian x-coordinate. */ From b6477607acd3e89383a468685ec6e5b2fca3987b Mon Sep 17 00:00:00 2001 From: Paul van Brenk Date: Thu, 23 Apr 2015 10:17:57 -0700 Subject: [PATCH 074/194] correct the slashes for a new line. --- 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 5c08e503b1c..993627619cb 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -810,7 +810,7 @@ module ts { return { options: {}, files: [], - errors: [realizeDiagnostic(result.error, '/r/n')] + errors: [realizeDiagnostic(result.error, '\r\n')] }; } From 5172c172b7553f55ca3c8c5c65849c8fd42b0d5a Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 23 Apr 2015 10:44:44 -0700 Subject: [PATCH 075/194] Add more tests --- tests/baselines/reference/es5-umd.js | 38 ++-- tests/baselines/reference/es5-umd.js.map | 2 +- .../baselines/reference/es5-umd.sourcemap.txt | 182 +++++++++--------- tests/baselines/reference/es5-umd.symbols | 34 ++-- tests/baselines/reference/es5-umd.types | 36 ++-- tests/baselines/reference/es5-umd2.js | 42 ++++ tests/baselines/reference/es5-umd2.js.map | 2 + .../reference/es5-umd2.sourcemap.txt | 149 ++++++++++++++ tests/baselines/reference/es5-umd2.symbols | 17 ++ tests/baselines/reference/es5-umd2.types | 18 ++ tests/baselines/reference/es5-umd3.js | 42 ++++ tests/baselines/reference/es5-umd3.js.map | 2 + .../reference/es5-umd3.sourcemap.txt | 146 ++++++++++++++ tests/baselines/reference/es5-umd3.symbols | 17 ++ tests/baselines/reference/es5-umd3.types | 18 ++ tests/baselines/reference/es5-umd4.js | 45 +++++ tests/baselines/reference/es5-umd4.js.map | 2 + .../reference/es5-umd4.sourcemap.txt | 143 ++++++++++++++ tests/baselines/reference/es5-umd4.symbols | 20 ++ tests/baselines/reference/es5-umd4.types | 21 ++ tests/baselines/reference/es6-umd.errors.txt | 18 ++ tests/baselines/reference/es6-umd.js | 30 +++ tests/baselines/reference/es6-umd.js.map | 2 + .../baselines/reference/es6-umd.sourcemap.txt | 91 +++++++++ tests/baselines/reference/es6-umd2.errors.txt | 18 ++ tests/baselines/reference/es6-umd2.js | 30 +++ tests/baselines/reference/es6-umd2.js.map | 2 + .../reference/es6-umd2.sourcemap.txt | 91 +++++++++ .../umdDependencyComment2.errors.txt | 20 +- .../reference/umdDependencyComment2.js | 32 +-- .../umdDependencyCommentName1.errors.txt | 20 +- .../reference/umdDependencyCommentName1.js | 32 +-- .../umdDependencyCommentName2.errors.txt | 24 +-- .../reference/umdDependencyCommentName2.js | 36 ++-- tests/cases/compiler/es5-umd2.ts | 17 ++ tests/cases/compiler/es5-umd3.ts | 17 ++ tests/cases/compiler/es5-umd4.ts | 19 ++ tests/cases/compiler/es6-umd.ts | 17 ++ tests/cases/compiler/es6-umd2.ts | 17 ++ 39 files changed, 1281 insertions(+), 228 deletions(-) create mode 100644 tests/baselines/reference/es5-umd2.js create mode 100644 tests/baselines/reference/es5-umd2.js.map create mode 100644 tests/baselines/reference/es5-umd2.sourcemap.txt create mode 100644 tests/baselines/reference/es5-umd2.symbols create mode 100644 tests/baselines/reference/es5-umd2.types create mode 100644 tests/baselines/reference/es5-umd3.js create mode 100644 tests/baselines/reference/es5-umd3.js.map create mode 100644 tests/baselines/reference/es5-umd3.sourcemap.txt create mode 100644 tests/baselines/reference/es5-umd3.symbols create mode 100644 tests/baselines/reference/es5-umd3.types create mode 100644 tests/baselines/reference/es5-umd4.js create mode 100644 tests/baselines/reference/es5-umd4.js.map create mode 100644 tests/baselines/reference/es5-umd4.sourcemap.txt create mode 100644 tests/baselines/reference/es5-umd4.symbols create mode 100644 tests/baselines/reference/es5-umd4.types create mode 100644 tests/baselines/reference/es6-umd.errors.txt create mode 100644 tests/baselines/reference/es6-umd.js create mode 100644 tests/baselines/reference/es6-umd.js.map create mode 100644 tests/baselines/reference/es6-umd.sourcemap.txt create mode 100644 tests/baselines/reference/es6-umd2.errors.txt create mode 100644 tests/baselines/reference/es6-umd2.js create mode 100644 tests/baselines/reference/es6-umd2.js.map create mode 100644 tests/baselines/reference/es6-umd2.sourcemap.txt create mode 100644 tests/cases/compiler/es5-umd2.ts create mode 100644 tests/cases/compiler/es5-umd3.ts create mode 100644 tests/cases/compiler/es5-umd4.ts create mode 100644 tests/cases/compiler/es6-umd.ts create mode 100644 tests/cases/compiler/es6-umd2.ts diff --git a/tests/baselines/reference/es5-umd.js b/tests/baselines/reference/es5-umd.js index 2fe8d686242..0175e8e9fe8 100644 --- a/tests/baselines/reference/es5-umd.js +++ b/tests/baselines/reference/es5-umd.js @@ -1,4 +1,4 @@ -//// [es5-umd.ts] +//// [es5-umd.ts] class A { @@ -12,21 +12,21 @@ class A return 42; } } - - -//// [es5-umd.js] -var A = (function () { - function A() { - } - A.prototype.B = function () { - return 42; - }; - return A; -})(); -//# sourceMappingURL=es5-umd.js.map - -//// [es5-umd.d.ts] -declare class A { - constructor(); - B(): number; -} + + +//// [es5-umd.js] +var A = (function () { + function A() { + } + A.prototype.B = function () { + return 42; + }; + return A; +})(); +//# sourceMappingURL=es5-umd.js.map + +//// [es5-umd.d.ts] +declare class A { + constructor(); + B(): number; +} diff --git a/tests/baselines/reference/es5-umd.js.map b/tests/baselines/reference/es5-umd.js.map index 785990dc2cb..5e29a48796e 100644 --- a/tests/baselines/reference/es5-umd.js.map +++ b/tests/baselines/reference/es5-umd.js.map @@ -1,2 +1,2 @@ -//// [es5-umd.js.map] +//// [es5-umd.js.map] {"version":3,"file":"es5-umd.js","sourceRoot":"","sources":["es5-umd.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 diff --git a/tests/baselines/reference/es5-umd.sourcemap.txt b/tests/baselines/reference/es5-umd.sourcemap.txt index 55413ee1eb2..bdbdec5fa9e 100644 --- a/tests/baselines/reference/es5-umd.sourcemap.txt +++ b/tests/baselines/reference/es5-umd.sourcemap.txt @@ -1,100 +1,100 @@ -=================================================================== -JsFile: es5-umd.js -mapUrl: es5-umd.js.map -sourceRoot: -sources: es5-umd.ts -=================================================================== -------------------------------------------------------------------- -emittedFile:tests/cases/compiler/es5-umd.js -sourceFile:es5-umd.ts -------------------------------------------------------------------- ->>>var A = (function () { +=================================================================== +JsFile: es5-umd.js +mapUrl: es5-umd.js.map +sourceRoot: +sources: es5-umd.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/es5-umd.js +sourceFile:es5-umd.ts +------------------------------------------------------------------- +>>>var A = (function () { +1 > +2 >^^^^^^^^^^^^^^^^^^^-> 1 > -2 >^^^^^^^^^^^^^^^^^^^-> -1 > - > -1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) ---- ->>> function A() { -1->^^^^ -2 > ^^-> + > +1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) +--- +>>> function A() { +1->^^^^ +2 > ^^-> 1->class A >{ - > -1->Emitted(2, 5) Source(4, 5) + SourceIndex(0) name (A) ---- ->>> } -1->^^^^ -2 > ^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> + > +1->Emitted(2, 5) Source(4, 5) + SourceIndex(0) name (A) +--- +>>> } +1->^^^^ +2 > ^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1->constructor () > { > - > -2 > } -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 () { -1->^^^^ -2 > ^^^^^^^^^^^^^ -3 > ^^^ + > +2 > } +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 () { +1->^^^^ +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) ---- ->>> return 42; -1 >^^^^^^^^ -2 > ^^^^^^ -3 > ^ -4 > ^^ -5 > ^ + > 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) +--- +>>> return 42; +1 >^^^^^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^ +5 > ^ 1 >public B() > { - > -2 > return -3 > -4 > 42 -5 > ; -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 > ^^^^^^^^^-> + > +2 > return +3 > +4 > 42 +5 > ; +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 > ^^^^^^^^ + > +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 > -2 >} -3 > + > +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 > +2 >} +3 > 4 > class A > { > constructor () @@ -106,10 +106,10 @@ sourceFile:es5-umd.ts > { > 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(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) +--- >>>//# sourceMappingURL=es5-umd.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es5-umd.symbols b/tests/baselines/reference/es5-umd.symbols index 1914a7877c1..f570afd9548 100644 --- a/tests/baselines/reference/es5-umd.symbols +++ b/tests/baselines/reference/es5-umd.symbols @@ -1,17 +1,17 @@ -=== tests/cases/compiler/es5-umd.ts === - -class A ->A : Symbol(A, Decl(es5-umd.ts, 0, 0)) -{ - constructor () - { - - } - - public B() ->B : Symbol(B, Decl(es5-umd.ts, 6, 5)) - { - return 42; - } -} - +=== tests/cases/compiler/es5-umd.ts === + +class A +>A : Symbol(A, Decl(es5-umd.ts, 0, 0)) +{ + constructor () + { + + } + + public B() +>B : Symbol(B, Decl(es5-umd.ts, 6, 5)) + { + return 42; + } +} + diff --git a/tests/baselines/reference/es5-umd.types b/tests/baselines/reference/es5-umd.types index f0e513e8b88..60987d429e0 100644 --- a/tests/baselines/reference/es5-umd.types +++ b/tests/baselines/reference/es5-umd.types @@ -1,18 +1,18 @@ -=== tests/cases/compiler/es5-umd.ts === - -class A ->A : A -{ - constructor () - { - - } - - public B() ->B : () => number - { - return 42; ->42 : number - } -} - +=== tests/cases/compiler/es5-umd.ts === + +class A +>A : A +{ + constructor () + { + + } + + public B() +>B : () => number + { + return 42; +>42 : number + } +} + diff --git a/tests/baselines/reference/es5-umd2.js b/tests/baselines/reference/es5-umd2.js new file mode 100644 index 00000000000..cb0265bf92f --- /dev/null +++ b/tests/baselines/reference/es5-umd2.js @@ -0,0 +1,42 @@ +//// [es5-umd2.ts] + +export class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} + + +//// [es5-umd2.js] +(function (deps, factory) { + if (typeof module === 'object' && typeof module.exports === 'object') { + var v = factory(require, exports); if (v !== undefined) module.exports = v; + } + else if (typeof define === 'function' && define.amd) { + define(deps, factory); + } +})(["require", "exports"], function (require, exports) { + var A = (function () { + function A() { + } + A.prototype.B = function () { + return 42; + }; + return A; + })(); + exports.A = A; +}); +//# sourceMappingURL=es5-umd2.js.map + +//// [es5-umd2.d.ts] +export declare class A { + constructor(); + B(): number; +} diff --git a/tests/baselines/reference/es5-umd2.js.map b/tests/baselines/reference/es5-umd2.js.map new file mode 100644 index 00000000000..13a785b2edc --- /dev/null +++ b/tests/baselines/reference/es5-umd2.js.map @@ -0,0 +1,2 @@ +//// [es5-umd2.js.map] +{"version":3,"file":"es5-umd2.js","sourceRoot":"","sources":["es5-umd2.ts"],"names":["A","A.constructor","A.B"],"mappings":";;;;;;;;IACA;QAEIA;QAGAC,CAACA;QAEMD,aAACA,GAARA;YAEIE,MAAMA,CAACA,EAAEA,CAACA;QACdA,CAACA;QACLF,QAACA;IAADA,CAACA,AAXD,IAWC;IAXY,SAAC,IAWb,CAAA"} \ No newline at end of file diff --git a/tests/baselines/reference/es5-umd2.sourcemap.txt b/tests/baselines/reference/es5-umd2.sourcemap.txt new file mode 100644 index 00000000000..bfadd9615f3 --- /dev/null +++ b/tests/baselines/reference/es5-umd2.sourcemap.txt @@ -0,0 +1,149 @@ +=================================================================== +JsFile: es5-umd2.js +mapUrl: es5-umd2.js.map +sourceRoot: +sources: es5-umd2.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/es5-umd2.js +sourceFile:es5-umd2.ts +------------------------------------------------------------------- +>>>(function (deps, factory) { +>>> if (typeof module === 'object' && typeof module.exports === 'object') { +>>> var v = factory(require, exports); if (v !== undefined) module.exports = v; +>>> } +>>> else if (typeof define === 'function' && define.amd) { +>>> define(deps, factory); +>>> } +>>>})(["require", "exports"], function (require, exports) { +>>> var A = (function () { +1 >^^^^ +2 > ^^^^^^^^^^^^^^^^^^^-> +1 > + > +1 >Emitted(9, 5) Source(2, 1) + SourceIndex(0) +--- +>>> function A() { +1->^^^^^^^^ +2 > ^^-> +1->export class A + >{ + > +1->Emitted(10, 9) Source(4, 5) + SourceIndex(0) name (A) +--- +>>> } +1->^^^^^^^^ +2 > ^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1->constructor () + > { + > + > +2 > } +1->Emitted(11, 9) Source(7, 5) + SourceIndex(0) name (A.constructor) +2 >Emitted(11, 10) Source(7, 6) + SourceIndex(0) name (A.constructor) +--- +>>> A.prototype.B = function () { +1->^^^^^^^^ +2 > ^^^^^^^^^^^^^ +3 > ^^^ +1-> + > + > public +2 > B +3 > +1->Emitted(12, 9) Source(9, 12) + SourceIndex(0) name (A) +2 >Emitted(12, 22) Source(9, 13) + SourceIndex(0) name (A) +3 >Emitted(12, 25) Source(9, 5) + SourceIndex(0) name (A) +--- +>>> return 42; +1 >^^^^^^^^^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^ +5 > ^ +1 >public B() + > { + > +2 > return +3 > +4 > 42 +5 > ; +1 >Emitted(13, 13) Source(11, 9) + SourceIndex(0) name (A.B) +2 >Emitted(13, 19) Source(11, 15) + SourceIndex(0) name (A.B) +3 >Emitted(13, 20) Source(11, 16) + SourceIndex(0) name (A.B) +4 >Emitted(13, 22) Source(11, 18) + SourceIndex(0) name (A.B) +5 >Emitted(13, 23) Source(11, 19) + SourceIndex(0) name (A.B) +--- +>>> }; +1 >^^^^^^^^ +2 > ^ +3 > ^^^^^^^^^-> +1 > + > +2 > } +1 >Emitted(14, 9) Source(12, 5) + SourceIndex(0) name (A.B) +2 >Emitted(14, 10) Source(12, 6) + SourceIndex(0) name (A.B) +--- +>>> return A; +1->^^^^^^^^ +2 > ^^^^^^^^ +1-> + > +2 > } +1->Emitted(15, 9) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(15, 17) Source(13, 2) + SourceIndex(0) name (A) +--- +>>> })(); +1 >^^^^ +2 > ^ +3 > +4 > ^^^^ +5 > ^^^^^^^^^^-> +1 > +2 > } +3 > +4 > export class A + > { + > constructor () + > { + > + > } + > + > public B() + > { + > return 42; + > } + > } +1 >Emitted(16, 5) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(16, 6) Source(13, 2) + SourceIndex(0) name (A) +3 >Emitted(16, 6) Source(2, 1) + SourceIndex(0) +4 >Emitted(16, 10) Source(13, 2) + SourceIndex(0) +--- +>>> exports.A = A; +1->^^^^ +2 > ^^^^^^^^^ +3 > ^^^^ +4 > ^ +1-> +2 > A +3 > + > { + > constructor () + > { + > + > } + > + > public B() + > { + > return 42; + > } + > } +4 > +1->Emitted(17, 5) Source(2, 14) + SourceIndex(0) +2 >Emitted(17, 14) Source(2, 15) + SourceIndex(0) +3 >Emitted(17, 18) Source(13, 2) + SourceIndex(0) +4 >Emitted(17, 19) Source(13, 2) + SourceIndex(0) +--- +>>>}); +>>>//# sourceMappingURL=es5-umd2.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es5-umd2.symbols b/tests/baselines/reference/es5-umd2.symbols new file mode 100644 index 00000000000..3b911d7e6f0 --- /dev/null +++ b/tests/baselines/reference/es5-umd2.symbols @@ -0,0 +1,17 @@ +=== tests/cases/compiler/es5-umd2.ts === + +export class A +>A : Symbol(A, Decl(es5-umd2.ts, 0, 0)) +{ + constructor () + { + + } + + public B() +>B : Symbol(B, Decl(es5-umd2.ts, 6, 5)) + { + return 42; + } +} + diff --git a/tests/baselines/reference/es5-umd2.types b/tests/baselines/reference/es5-umd2.types new file mode 100644 index 00000000000..fab4e9dfc01 --- /dev/null +++ b/tests/baselines/reference/es5-umd2.types @@ -0,0 +1,18 @@ +=== tests/cases/compiler/es5-umd2.ts === + +export class A +>A : A +{ + constructor () + { + + } + + public B() +>B : () => number + { + return 42; +>42 : number + } +} + diff --git a/tests/baselines/reference/es5-umd3.js b/tests/baselines/reference/es5-umd3.js new file mode 100644 index 00000000000..2d18e2eecc3 --- /dev/null +++ b/tests/baselines/reference/es5-umd3.js @@ -0,0 +1,42 @@ +//// [es5-umd3.ts] + +export default class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} + + +//// [es5-umd3.js] +(function (deps, factory) { + if (typeof module === 'object' && typeof module.exports === 'object') { + var v = factory(require, exports); if (v !== undefined) module.exports = v; + } + else if (typeof define === 'function' && define.amd) { + define(deps, factory); + } +})(["require", "exports"], function (require, exports) { + var A = (function () { + function A() { + } + A.prototype.B = function () { + return 42; + }; + return A; + })(); + exports.default = A; +}); +//# sourceMappingURL=es5-umd3.js.map + +//// [es5-umd3.d.ts] +export default class A { + constructor(); + B(): number; +} diff --git a/tests/baselines/reference/es5-umd3.js.map b/tests/baselines/reference/es5-umd3.js.map new file mode 100644 index 00000000000..8b955f11936 --- /dev/null +++ b/tests/baselines/reference/es5-umd3.js.map @@ -0,0 +1,2 @@ +//// [es5-umd3.js.map] +{"version":3,"file":"es5-umd3.js","sourceRoot":"","sources":["es5-umd3.ts"],"names":["A","A.constructor","A.B"],"mappings":";;;;;;;;IACA;QAEIA;QAGAC,CAACA;QAEMD,aAACA,GAARA;YAEIE,MAAMA,CAACA,EAAEA,CAACA;QACdA,CAACA;QACLF,QAACA;IAADA,CAACA,AAXD,IAWC;IAXD,mBAWC,CAAA"} \ No newline at end of file diff --git a/tests/baselines/reference/es5-umd3.sourcemap.txt b/tests/baselines/reference/es5-umd3.sourcemap.txt new file mode 100644 index 00000000000..afb879ac713 --- /dev/null +++ b/tests/baselines/reference/es5-umd3.sourcemap.txt @@ -0,0 +1,146 @@ +=================================================================== +JsFile: es5-umd3.js +mapUrl: es5-umd3.js.map +sourceRoot: +sources: es5-umd3.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/es5-umd3.js +sourceFile:es5-umd3.ts +------------------------------------------------------------------- +>>>(function (deps, factory) { +>>> if (typeof module === 'object' && typeof module.exports === 'object') { +>>> var v = factory(require, exports); if (v !== undefined) module.exports = v; +>>> } +>>> else if (typeof define === 'function' && define.amd) { +>>> define(deps, factory); +>>> } +>>>})(["require", "exports"], function (require, exports) { +>>> var A = (function () { +1 >^^^^ +2 > ^^^^^^^^^^^^^^^^^^^-> +1 > + > +1 >Emitted(9, 5) Source(2, 1) + SourceIndex(0) +--- +>>> function A() { +1->^^^^^^^^ +2 > ^^-> +1->export default class A + >{ + > +1->Emitted(10, 9) Source(4, 5) + SourceIndex(0) name (A) +--- +>>> } +1->^^^^^^^^ +2 > ^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1->constructor () + > { + > + > +2 > } +1->Emitted(11, 9) Source(7, 5) + SourceIndex(0) name (A.constructor) +2 >Emitted(11, 10) Source(7, 6) + SourceIndex(0) name (A.constructor) +--- +>>> A.prototype.B = function () { +1->^^^^^^^^ +2 > ^^^^^^^^^^^^^ +3 > ^^^ +1-> + > + > public +2 > B +3 > +1->Emitted(12, 9) Source(9, 12) + SourceIndex(0) name (A) +2 >Emitted(12, 22) Source(9, 13) + SourceIndex(0) name (A) +3 >Emitted(12, 25) Source(9, 5) + SourceIndex(0) name (A) +--- +>>> return 42; +1 >^^^^^^^^^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^ +5 > ^ +1 >public B() + > { + > +2 > return +3 > +4 > 42 +5 > ; +1 >Emitted(13, 13) Source(11, 9) + SourceIndex(0) name (A.B) +2 >Emitted(13, 19) Source(11, 15) + SourceIndex(0) name (A.B) +3 >Emitted(13, 20) Source(11, 16) + SourceIndex(0) name (A.B) +4 >Emitted(13, 22) Source(11, 18) + SourceIndex(0) name (A.B) +5 >Emitted(13, 23) Source(11, 19) + SourceIndex(0) name (A.B) +--- +>>> }; +1 >^^^^^^^^ +2 > ^ +3 > ^^^^^^^^^-> +1 > + > +2 > } +1 >Emitted(14, 9) Source(12, 5) + SourceIndex(0) name (A.B) +2 >Emitted(14, 10) Source(12, 6) + SourceIndex(0) name (A.B) +--- +>>> return A; +1->^^^^^^^^ +2 > ^^^^^^^^ +1-> + > +2 > } +1->Emitted(15, 9) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(15, 17) Source(13, 2) + SourceIndex(0) name (A) +--- +>>> })(); +1 >^^^^ +2 > ^ +3 > +4 > ^^^^ +5 > ^^^^^^^^^^^^^^^^-> +1 > +2 > } +3 > +4 > export default class A + > { + > constructor () + > { + > + > } + > + > public B() + > { + > return 42; + > } + > } +1 >Emitted(16, 5) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(16, 6) Source(13, 2) + SourceIndex(0) name (A) +3 >Emitted(16, 6) Source(2, 1) + SourceIndex(0) +4 >Emitted(16, 10) Source(13, 2) + SourceIndex(0) +--- +>>> exports.default = A; +1->^^^^ +2 > ^^^^^^^^^^^^^^^^^^^ +3 > ^ +1-> +2 > export default class A + > { + > constructor () + > { + > + > } + > + > public B() + > { + > return 42; + > } + > } +3 > +1->Emitted(17, 5) Source(2, 1) + SourceIndex(0) +2 >Emitted(17, 24) Source(13, 2) + SourceIndex(0) +3 >Emitted(17, 25) Source(13, 2) + SourceIndex(0) +--- +>>>}); +>>>//# sourceMappingURL=es5-umd3.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es5-umd3.symbols b/tests/baselines/reference/es5-umd3.symbols new file mode 100644 index 00000000000..3f830ae3637 --- /dev/null +++ b/tests/baselines/reference/es5-umd3.symbols @@ -0,0 +1,17 @@ +=== tests/cases/compiler/es5-umd3.ts === + +export default class A +>A : Symbol(A, Decl(es5-umd3.ts, 0, 0)) +{ + constructor () + { + + } + + public B() +>B : Symbol(B, Decl(es5-umd3.ts, 6, 5)) + { + return 42; + } +} + diff --git a/tests/baselines/reference/es5-umd3.types b/tests/baselines/reference/es5-umd3.types new file mode 100644 index 00000000000..b4b5f0dc366 --- /dev/null +++ b/tests/baselines/reference/es5-umd3.types @@ -0,0 +1,18 @@ +=== tests/cases/compiler/es5-umd3.ts === + +export default class A +>A : A +{ + constructor () + { + + } + + public B() +>B : () => number + { + return 42; +>42 : number + } +} + diff --git a/tests/baselines/reference/es5-umd4.js b/tests/baselines/reference/es5-umd4.js new file mode 100644 index 00000000000..85683f8f3c2 --- /dev/null +++ b/tests/baselines/reference/es5-umd4.js @@ -0,0 +1,45 @@ +//// [es5-umd4.ts] + +class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} + +export = A; + + +//// [es5-umd4.js] +(function (deps, factory) { + if (typeof module === 'object' && typeof module.exports === 'object') { + var v = factory(require, exports); if (v !== undefined) module.exports = v; + } + else if (typeof define === 'function' && define.amd) { + define(deps, factory); + } +})(["require", "exports"], function (require, exports) { + var A = (function () { + function A() { + } + A.prototype.B = function () { + return 42; + }; + return A; + })(); + return A; +}); +//# sourceMappingURL=es5-umd4.js.map + +//// [es5-umd4.d.ts] +declare class A { + constructor(); + B(): number; +} +export = A; diff --git a/tests/baselines/reference/es5-umd4.js.map b/tests/baselines/reference/es5-umd4.js.map new file mode 100644 index 00000000000..0a47d679ed9 --- /dev/null +++ b/tests/baselines/reference/es5-umd4.js.map @@ -0,0 +1,2 @@ +//// [es5-umd4.js.map] +{"version":3,"file":"es5-umd4.js","sourceRoot":"","sources":["es5-umd4.ts"],"names":["A","A.constructor","A.B"],"mappings":";;;;;;;;IACA;QAEIA;QAGAC,CAACA;QAEMD,aAACA,GAARA;YAEIE,MAAMA,CAACA,EAAEA,CAACA;QACdA,CAACA;QACLF,QAACA;IAADA,CAACA,AAXD,IAWC;IAEU,AAAX,OAAS,CAAC,CAAC"} \ No newline at end of file diff --git a/tests/baselines/reference/es5-umd4.sourcemap.txt b/tests/baselines/reference/es5-umd4.sourcemap.txt new file mode 100644 index 00000000000..9afd8effecf --- /dev/null +++ b/tests/baselines/reference/es5-umd4.sourcemap.txt @@ -0,0 +1,143 @@ +=================================================================== +JsFile: es5-umd4.js +mapUrl: es5-umd4.js.map +sourceRoot: +sources: es5-umd4.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/es5-umd4.js +sourceFile:es5-umd4.ts +------------------------------------------------------------------- +>>>(function (deps, factory) { +>>> if (typeof module === 'object' && typeof module.exports === 'object') { +>>> var v = factory(require, exports); if (v !== undefined) module.exports = v; +>>> } +>>> else if (typeof define === 'function' && define.amd) { +>>> define(deps, factory); +>>> } +>>>})(["require", "exports"], function (require, exports) { +>>> var A = (function () { +1 >^^^^ +2 > ^^^^^^^^^^^^^^^^^^^-> +1 > + > +1 >Emitted(9, 5) Source(2, 1) + SourceIndex(0) +--- +>>> function A() { +1->^^^^^^^^ +2 > ^^-> +1->class A + >{ + > +1->Emitted(10, 9) Source(4, 5) + SourceIndex(0) name (A) +--- +>>> } +1->^^^^^^^^ +2 > ^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1->constructor () + > { + > + > +2 > } +1->Emitted(11, 9) Source(7, 5) + SourceIndex(0) name (A.constructor) +2 >Emitted(11, 10) Source(7, 6) + SourceIndex(0) name (A.constructor) +--- +>>> A.prototype.B = function () { +1->^^^^^^^^ +2 > ^^^^^^^^^^^^^ +3 > ^^^ +1-> + > + > public +2 > B +3 > +1->Emitted(12, 9) Source(9, 12) + SourceIndex(0) name (A) +2 >Emitted(12, 22) Source(9, 13) + SourceIndex(0) name (A) +3 >Emitted(12, 25) Source(9, 5) + SourceIndex(0) name (A) +--- +>>> return 42; +1 >^^^^^^^^^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^ +5 > ^ +1 >public B() + > { + > +2 > return +3 > +4 > 42 +5 > ; +1 >Emitted(13, 13) Source(11, 9) + SourceIndex(0) name (A.B) +2 >Emitted(13, 19) Source(11, 15) + SourceIndex(0) name (A.B) +3 >Emitted(13, 20) Source(11, 16) + SourceIndex(0) name (A.B) +4 >Emitted(13, 22) Source(11, 18) + SourceIndex(0) name (A.B) +5 >Emitted(13, 23) Source(11, 19) + SourceIndex(0) name (A.B) +--- +>>> }; +1 >^^^^^^^^ +2 > ^ +3 > ^^^^^^^^^-> +1 > + > +2 > } +1 >Emitted(14, 9) Source(12, 5) + SourceIndex(0) name (A.B) +2 >Emitted(14, 10) Source(12, 6) + SourceIndex(0) name (A.B) +--- +>>> return A; +1->^^^^^^^^ +2 > ^^^^^^^^ +1-> + > +2 > } +1->Emitted(15, 9) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(15, 17) Source(13, 2) + SourceIndex(0) name (A) +--- +>>> })(); +1 >^^^^ +2 > ^ +3 > +4 > ^^^^ +5 > ^^^^^-> +1 > +2 > } +3 > +4 > class A + > { + > constructor () + > { + > + > } + > + > public B() + > { + > return 42; + > } + > } +1 >Emitted(16, 5) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(16, 6) Source(13, 2) + SourceIndex(0) name (A) +3 >Emitted(16, 6) Source(2, 1) + SourceIndex(0) +4 >Emitted(16, 10) Source(13, 2) + SourceIndex(0) +--- +>>> return A; +1->^^^^ +2 > +3 > ^^^^^^^ +4 > ^ +5 > ^ +1-> + > + >export = A; +2 > +3 > export = +4 > A +5 > ; +1->Emitted(17, 5) Source(15, 12) + SourceIndex(0) +2 >Emitted(17, 5) Source(15, 1) + SourceIndex(0) +3 >Emitted(17, 12) Source(15, 10) + SourceIndex(0) +4 >Emitted(17, 13) Source(15, 11) + SourceIndex(0) +5 >Emitted(17, 14) Source(15, 12) + SourceIndex(0) +--- +>>>}); +>>>//# sourceMappingURL=es5-umd4.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es5-umd4.symbols b/tests/baselines/reference/es5-umd4.symbols new file mode 100644 index 00000000000..cdf1e135cf7 --- /dev/null +++ b/tests/baselines/reference/es5-umd4.symbols @@ -0,0 +1,20 @@ +=== tests/cases/compiler/es5-umd4.ts === + +class A +>A : Symbol(A, Decl(es5-umd4.ts, 0, 0)) +{ + constructor () + { + + } + + public B() +>B : Symbol(B, Decl(es5-umd4.ts, 6, 5)) + { + return 42; + } +} + +export = A; +>A : Symbol(A, Decl(es5-umd4.ts, 0, 0)) + diff --git a/tests/baselines/reference/es5-umd4.types b/tests/baselines/reference/es5-umd4.types new file mode 100644 index 00000000000..59d23e6bd8d --- /dev/null +++ b/tests/baselines/reference/es5-umd4.types @@ -0,0 +1,21 @@ +=== tests/cases/compiler/es5-umd4.ts === + +class A +>A : A +{ + constructor () + { + + } + + public B() +>B : () => number + { + return 42; +>42 : number + } +} + +export = A; +>A : A + diff --git a/tests/baselines/reference/es6-umd.errors.txt b/tests/baselines/reference/es6-umd.errors.txt new file mode 100644 index 00000000000..c231fe0b12b --- /dev/null +++ b/tests/baselines/reference/es6-umd.errors.txt @@ -0,0 +1,18 @@ +error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. + + +!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +==== tests/cases/compiler/es6-umd.ts (0 errors) ==== + + class A + { + constructor () + { + + } + + public B() + { + return 42; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/es6-umd.js b/tests/baselines/reference/es6-umd.js new file mode 100644 index 00000000000..74cd671f5ef --- /dev/null +++ b/tests/baselines/reference/es6-umd.js @@ -0,0 +1,30 @@ +//// [es6-umd.ts] + +class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} + +//// [es6-umd.js] +class A { + constructor() { + } + B() { + return 42; + } +} +//# sourceMappingURL=es6-umd.js.map + +//// [es6-umd.d.ts] +declare class A { + constructor(); + B(): number; +} diff --git a/tests/baselines/reference/es6-umd.js.map b/tests/baselines/reference/es6-umd.js.map new file mode 100644 index 00000000000..a5e82f7ccfd --- /dev/null +++ b/tests/baselines/reference/es6-umd.js.map @@ -0,0 +1,2 @@ +//// [es6-umd.js.map] +{"version":3,"file":"es6-umd.js","sourceRoot":"","sources":["es6-umd.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-umd.sourcemap.txt b/tests/baselines/reference/es6-umd.sourcemap.txt new file mode 100644 index 00000000000..bb8281ce741 --- /dev/null +++ b/tests/baselines/reference/es6-umd.sourcemap.txt @@ -0,0 +1,91 @@ +=================================================================== +JsFile: es6-umd.js +mapUrl: es6-umd.js.map +sourceRoot: +sources: es6-umd.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/es6-umd.js +sourceFile:es6-umd.ts +------------------------------------------------------------------- +>>>class A { +1 > +2 >^^^^^^^^^^^^^^^^^^^^-> +1 > + > +1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) +--- +>>> constructor() { +1->^^^^ +2 > ^^-> +1->class A + >{ + > +1->Emitted(2, 5) Source(4, 5) + SourceIndex(0) name (A) +--- +>>> } +1->^^^^ +2 > ^ +3 > ^^^^^-> +1->constructor () + > { + > + > +2 > } +1->Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor) +2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor) +--- +>>> B() { +1->^^^^ +2 > ^ +3 > ^^^^^^^^^^^^^^-> +1-> + > + > public +2 > B +1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A) +2 >Emitted(4, 6) Source(9, 13) + SourceIndex(0) name (A) +--- +>>> return 42; +1->^^^^^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^ +5 > ^ +1->() + > { + > +2 > return +3 > +4 > 42 +5 > ; +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 > ^ +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) +--- +>>>} +1 > +2 >^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + > +2 >} +1 >Emitted(7, 1) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(7, 2) Source(13, 2) + SourceIndex(0) name (A) +--- +>>>//# sourceMappingURL=es6-umd.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-umd2.errors.txt b/tests/baselines/reference/es6-umd2.errors.txt new file mode 100644 index 00000000000..ac05e967356 --- /dev/null +++ b/tests/baselines/reference/es6-umd2.errors.txt @@ -0,0 +1,18 @@ +error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. + + +!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +==== tests/cases/compiler/es6-umd2.ts (0 errors) ==== + + export class A + { + constructor () + { + + } + + public B() + { + return 42; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/es6-umd2.js b/tests/baselines/reference/es6-umd2.js new file mode 100644 index 00000000000..b12d35aacf8 --- /dev/null +++ b/tests/baselines/reference/es6-umd2.js @@ -0,0 +1,30 @@ +//// [es6-umd2.ts] + +export class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} + +//// [es6-umd2.js] +export class A { + constructor() { + } + B() { + return 42; + } +} +//# sourceMappingURL=es6-umd2.js.map + +//// [es6-umd2.d.ts] +export declare class A { + constructor(); + B(): number; +} diff --git a/tests/baselines/reference/es6-umd2.js.map b/tests/baselines/reference/es6-umd2.js.map new file mode 100644 index 00000000000..81f3d85a6cd --- /dev/null +++ b/tests/baselines/reference/es6-umd2.js.map @@ -0,0 +1,2 @@ +//// [es6-umd2.js.map] +{"version":3,"file":"es6-umd2.js","sourceRoot":"","sources":["es6-umd2.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-umd2.sourcemap.txt b/tests/baselines/reference/es6-umd2.sourcemap.txt new file mode 100644 index 00000000000..d032aa3d6c7 --- /dev/null +++ b/tests/baselines/reference/es6-umd2.sourcemap.txt @@ -0,0 +1,91 @@ +=================================================================== +JsFile: es6-umd2.js +mapUrl: es6-umd2.js.map +sourceRoot: +sources: es6-umd2.ts +=================================================================== +------------------------------------------------------------------- +emittedFile:tests/cases/compiler/es6-umd2.js +sourceFile:es6-umd2.ts +------------------------------------------------------------------- +>>>export class A { +1 > +2 >^^^^^^^^^^^^^^^^^^^^-> +1 > + > +1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) +--- +>>> constructor() { +1->^^^^ +2 > ^^-> +1->export class A + >{ + > +1->Emitted(2, 5) Source(4, 5) + SourceIndex(0) name (A) +--- +>>> } +1->^^^^ +2 > ^ +3 > ^^^^^-> +1->constructor () + > { + > + > +2 > } +1->Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor) +2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor) +--- +>>> B() { +1->^^^^ +2 > ^ +3 > ^^^^^^^^^^^^^^-> +1-> + > + > public +2 > B +1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A) +2 >Emitted(4, 6) Source(9, 13) + SourceIndex(0) name (A) +--- +>>> return 42; +1->^^^^^^^^ +2 > ^^^^^^ +3 > ^ +4 > ^^ +5 > ^ +1->() + > { + > +2 > return +3 > +4 > 42 +5 > ; +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 > ^ +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) +--- +>>>} +1 > +2 >^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + > +2 >} +1 >Emitted(7, 1) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(7, 2) Source(13, 2) + SourceIndex(0) name (A) +--- +>>>//# sourceMappingURL=es6-umd2.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/umdDependencyComment2.errors.txt b/tests/baselines/reference/umdDependencyComment2.errors.txt index 1e85844af64..66c4adf4c1d 100644 --- a/tests/baselines/reference/umdDependencyComment2.errors.txt +++ b/tests/baselines/reference/umdDependencyComment2.errors.txt @@ -1,11 +1,11 @@ -tests/cases/compiler/umdDependencyComment2.ts(3,21): error TS2307: Cannot find external module 'm2'. - - -==== tests/cases/compiler/umdDependencyComment2.ts (1 errors) ==== - /// - - import m1 = require("m2") - ~~~~ -!!! error TS2307: Cannot find external module 'm2'. - m1.f(); +tests/cases/compiler/umdDependencyComment2.ts(3,21): error TS2307: Cannot find external module 'm2'. + + +==== tests/cases/compiler/umdDependencyComment2.ts (1 errors) ==== + /// + + import m1 = require("m2") + ~~~~ +!!! error TS2307: Cannot find external module 'm2'. + m1.f(); \ No newline at end of file diff --git a/tests/baselines/reference/umdDependencyComment2.js b/tests/baselines/reference/umdDependencyComment2.js index 462dad2daca..cae34631517 100644 --- a/tests/baselines/reference/umdDependencyComment2.js +++ b/tests/baselines/reference/umdDependencyComment2.js @@ -1,20 +1,20 @@ -//// [umdDependencyComment2.ts] +//// [umdDependencyComment2.ts] /// import m1 = require("m2") m1.f(); - - -//// [umdDependencyComment2.js] -/// -(function (deps, factory) { - if (typeof module === 'object' && typeof module.exports === 'object') { - var v = factory(require, exports); if (v !== undefined) module.exports = v; - } - else if (typeof define === 'function' && define.amd) { - define(deps, factory); - } -})(["require", "exports", "bar", "m2"], function (require, exports) { - var m1 = require("m2"); - m1.f(); -}); + + +//// [umdDependencyComment2.js] +/// +(function (deps, factory) { + if (typeof module === 'object' && typeof module.exports === 'object') { + var v = factory(require, exports); if (v !== undefined) module.exports = v; + } + else if (typeof define === 'function' && define.amd) { + define(deps, factory); + } +})(["require", "exports", "bar", "m2"], function (require, exports) { + var m1 = require("m2"); + m1.f(); +}); diff --git a/tests/baselines/reference/umdDependencyCommentName1.errors.txt b/tests/baselines/reference/umdDependencyCommentName1.errors.txt index 080ae2d852a..6acb71c4b00 100644 --- a/tests/baselines/reference/umdDependencyCommentName1.errors.txt +++ b/tests/baselines/reference/umdDependencyCommentName1.errors.txt @@ -1,11 +1,11 @@ -tests/cases/compiler/umdDependencyCommentName1.ts(3,21): error TS2307: Cannot find external module 'm2'. - - -==== tests/cases/compiler/umdDependencyCommentName1.ts (1 errors) ==== - /// - - import m1 = require("m2") - ~~~~ -!!! error TS2307: Cannot find external module 'm2'. - m1.f(); +tests/cases/compiler/umdDependencyCommentName1.ts(3,21): error TS2307: Cannot find external module 'm2'. + + +==== tests/cases/compiler/umdDependencyCommentName1.ts (1 errors) ==== + /// + + import m1 = require("m2") + ~~~~ +!!! error TS2307: Cannot find external module 'm2'. + m1.f(); \ No newline at end of file diff --git a/tests/baselines/reference/umdDependencyCommentName1.js b/tests/baselines/reference/umdDependencyCommentName1.js index 20ef7c1326f..6cb87eb45f5 100644 --- a/tests/baselines/reference/umdDependencyCommentName1.js +++ b/tests/baselines/reference/umdDependencyCommentName1.js @@ -1,20 +1,20 @@ -//// [umdDependencyCommentName1.ts] +//// [umdDependencyCommentName1.ts] /// import m1 = require("m2") m1.f(); - - -//// [umdDependencyCommentName1.js] -/// -(function (deps, factory) { - if (typeof module === 'object' && typeof module.exports === 'object') { - var v = factory(require, exports); if (v !== undefined) module.exports = v; - } - else if (typeof define === 'function' && define.amd) { - define(deps, factory); - } -})(["require", "exports", "bar", "m2"], function (require, exports, b) { - var m1 = require("m2"); - m1.f(); -}); + + +//// [umdDependencyCommentName1.js] +/// +(function (deps, factory) { + if (typeof module === 'object' && typeof module.exports === 'object') { + var v = factory(require, exports); if (v !== undefined) module.exports = v; + } + else if (typeof define === 'function' && define.amd) { + define(deps, factory); + } +})(["require", "exports", "bar", "m2"], function (require, exports, b) { + var m1 = require("m2"); + m1.f(); +}); diff --git a/tests/baselines/reference/umdDependencyCommentName2.errors.txt b/tests/baselines/reference/umdDependencyCommentName2.errors.txt index 903ca4ecfaf..3481ca61148 100644 --- a/tests/baselines/reference/umdDependencyCommentName2.errors.txt +++ b/tests/baselines/reference/umdDependencyCommentName2.errors.txt @@ -1,13 +1,13 @@ -tests/cases/compiler/umdDependencyCommentName2.ts(5,21): error TS2307: Cannot find external module 'm2'. - - -==== tests/cases/compiler/umdDependencyCommentName2.ts (1 errors) ==== - /// - /// - /// - - import m1 = require("m2") - ~~~~ -!!! error TS2307: Cannot find external module 'm2'. - m1.f(); +tests/cases/compiler/umdDependencyCommentName2.ts(5,21): error TS2307: Cannot find external module 'm2'. + + +==== tests/cases/compiler/umdDependencyCommentName2.ts (1 errors) ==== + /// + /// + /// + + import m1 = require("m2") + ~~~~ +!!! error TS2307: Cannot find external module 'm2'. + m1.f(); \ No newline at end of file diff --git a/tests/baselines/reference/umdDependencyCommentName2.js b/tests/baselines/reference/umdDependencyCommentName2.js index 22a0cc709bc..d474454936d 100644 --- a/tests/baselines/reference/umdDependencyCommentName2.js +++ b/tests/baselines/reference/umdDependencyCommentName2.js @@ -1,24 +1,24 @@ -//// [umdDependencyCommentName2.ts] +//// [umdDependencyCommentName2.ts] /// /// /// import m1 = require("m2") m1.f(); - - -//// [umdDependencyCommentName2.js] -/// -/// -/// -(function (deps, factory) { - if (typeof module === 'object' && typeof module.exports === 'object') { - var v = factory(require, exports); if (v !== undefined) module.exports = v; - } - else if (typeof define === 'function' && define.amd) { - define(deps, factory); - } -})(["require", "exports", "bar", "goo", "foo", "m2"], function (require, exports, b, c) { - var m1 = require("m2"); - m1.f(); -}); + + +//// [umdDependencyCommentName2.js] +/// +/// +/// +(function (deps, factory) { + if (typeof module === 'object' && typeof module.exports === 'object') { + var v = factory(require, exports); if (v !== undefined) module.exports = v; + } + else if (typeof define === 'function' && define.amd) { + define(deps, factory); + } +})(["require", "exports", "bar", "goo", "foo", "m2"], function (require, exports, b, c) { + var m1 = require("m2"); + m1.f(); +}); diff --git a/tests/cases/compiler/es5-umd2.ts b/tests/cases/compiler/es5-umd2.ts new file mode 100644 index 00000000000..a74ae21f4dd --- /dev/null +++ b/tests/cases/compiler/es5-umd2.ts @@ -0,0 +1,17 @@ +// @target: ES5 +// @sourcemap: false +// @declaration: false +// @module: umd + +export class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} diff --git a/tests/cases/compiler/es5-umd3.ts b/tests/cases/compiler/es5-umd3.ts new file mode 100644 index 00000000000..b4ab3cc1cf1 --- /dev/null +++ b/tests/cases/compiler/es5-umd3.ts @@ -0,0 +1,17 @@ +// @target: ES5 +// @sourcemap: false +// @declaration: false +// @module: umd + +export default class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} diff --git a/tests/cases/compiler/es5-umd4.ts b/tests/cases/compiler/es5-umd4.ts new file mode 100644 index 00000000000..5ab7e7de4e3 --- /dev/null +++ b/tests/cases/compiler/es5-umd4.ts @@ -0,0 +1,19 @@ +// @target: ES5 +// @sourcemap: false +// @declaration: false +// @module: umd + +class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} + +export = A; diff --git a/tests/cases/compiler/es6-umd.ts b/tests/cases/compiler/es6-umd.ts new file mode 100644 index 00000000000..239ff49ef6c --- /dev/null +++ b/tests/cases/compiler/es6-umd.ts @@ -0,0 +1,17 @@ +// @target: ES6 +// @sourcemap: false +// @declaration: false +// @module: umd + +class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/es6-umd2.ts b/tests/cases/compiler/es6-umd2.ts new file mode 100644 index 00000000000..54622fe81aa --- /dev/null +++ b/tests/cases/compiler/es6-umd2.ts @@ -0,0 +1,17 @@ +// @target: ES6 +// @sourcemap: false +// @declaration: false +// @module: umd + +export class A +{ + constructor () + { + + } + + public B() + { + return 42; + } +} \ No newline at end of file From ded0e398b4758218001a837c893e60e92596cc40 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 23 Apr 2015 10:53:19 -0700 Subject: [PATCH 076/194] update error messages --- src/compiler/commandLineParser.ts | 2 +- src/compiler/diagnosticInformationMap.generated.ts | 6 +++--- src/compiler/diagnosticMessages.json | 6 +++--- src/compiler/program.ts | 2 +- .../reference/constDeclarations-access5.errors.txt | 4 ++-- tests/baselines/reference/es6-amd.errors.txt | 4 ++-- tests/baselines/reference/es6-declaration-amd.errors.txt | 4 ++-- tests/baselines/reference/es6-sourcemap-amd.errors.txt | 4 ++-- tests/baselines/reference/es6-umd.errors.txt | 4 ++-- tests/baselines/reference/es6-umd2.errors.txt | 4 ++-- ...s6ImportDefaultBindingFollowedWithNamedImport.errors.txt | 4 ++-- .../baselines/reference/es6ImportNameSpaceImport.errors.txt | 4 ++-- tests/baselines/reference/es6ImportNamedImport.errors.txt | 4 ++-- .../es6ImportNamedImportInExportAssignment.errors.txt | 4 ++-- .../reference/es6ModuleWithModuleGenTargetAmd.errors.txt | 4 ++-- .../es6ModuleWithModuleGenTargetCommonjs.errors.txt | 4 ++-- 16 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index adb0e2d37c5..002e049bdd0 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -151,7 +151,7 @@ module ts { type: { "es3": ScriptTarget.ES3, "es5": ScriptTarget.ES5, "es6": ScriptTarget.ES6 }, description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental, paramType: Diagnostics.VERSION, - error: Diagnostics.Argument_for_target_option_must_be_es3_es5_or_es6 + error: Diagnostics.Argument_for_target_option_must_be_ES3_ES5_or_ES6 }, { name: "version", diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index f03b2ea16b3..0af10bdb89a 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -161,7 +161,7 @@ module ts { Line_terminator_not_permitted_before_arrow: { code: 1200, category: DiagnosticCategory.Error, key: "Line terminator not permitted before arrow." }, Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_or_import_d_from_mod_instead: { code: 1202, category: DiagnosticCategory.Error, key: "Import assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'import * as ns from \"mod\"', 'import {a} from \"mod\"' or 'import d from \"mod\"' instead." }, Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_or_higher_Consider_using_export_default_instead: { code: 1203, category: DiagnosticCategory.Error, key: "Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead." }, - Cannot_compile_external_modules_into_amd_or_commonjs_when_targeting_es6_or_higher: { code: 1204, category: DiagnosticCategory.Error, key: "Cannot compile external modules into amd or commonjs when targeting es6 or higher." }, + Cannot_compile_external_modules_into_amd_commonjs_or_umd_when_targeting_ES6_or_higher: { code: 1204, category: DiagnosticCategory.Error, key: "Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher." }, Decorators_are_only_available_when_targeting_ECMAScript_5_and_higher: { code: 1205, category: DiagnosticCategory.Error, key: "Decorators are only available when targeting ECMAScript 5 and higher." }, Decorators_are_not_valid_here: { code: 1206, category: DiagnosticCategory.Error, key: "Decorators are not valid here." }, Decorators_cannot_be_applied_to_multiple_get_Slashset_accessors_of_the_same_name: { code: 1207, category: DiagnosticCategory.Error, key: "Decorators cannot be applied to multiple get/set accessors of the same name." }, @@ -463,7 +463,7 @@ module ts { Do_not_emit_comments_to_output: { code: 6009, category: DiagnosticCategory.Message, key: "Do not emit comments to output." }, Do_not_emit_outputs: { code: 6010, category: DiagnosticCategory.Message, key: "Do not emit outputs." }, Specify_ECMAScript_target_version_Colon_ES3_default_ES5_or_ES6_experimental: { code: 6015, category: DiagnosticCategory.Message, key: "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES6' (experimental)" }, - Specify_module_code_generation_Colon_commonjs_amd_or_umd: { code: 6016, category: DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs', 'amd', or 'umd'" }, + Specify_module_code_generation_Colon_commonjs_amd_or_umd: { code: 6016, category: DiagnosticCategory.Message, key: "Specify module code generation: 'commonjs', 'amd', or 'umd'." }, Print_this_message: { code: 6017, category: DiagnosticCategory.Message, key: "Print this message." }, Print_the_compiler_s_version: { code: 6019, category: DiagnosticCategory.Message, key: "Print the compiler's version." }, Compile_the_project_in_the_given_directory: { code: 6020, category: DiagnosticCategory.Message, key: "Compile the project in the given directory." }, @@ -485,7 +485,7 @@ module ts { Compiler_option_0_expects_an_argument: { code: 6044, category: DiagnosticCategory.Error, key: "Compiler option '{0}' expects an argument." }, Unterminated_quoted_string_in_response_file_0: { code: 6045, category: DiagnosticCategory.Error, key: "Unterminated quoted string in response file '{0}'." }, Argument_for_module_option_must_be_commonjs_amd_or_umd: { code: 6046, category: DiagnosticCategory.Error, key: "Argument for '--module' option must be 'commonjs', 'amd', or 'umd'." }, - Argument_for_target_option_must_be_es3_es5_or_es6: { code: 6047, category: DiagnosticCategory.Error, key: "Argument for '--target' option must be 'es3', 'es5', or 'es6'." }, + Argument_for_target_option_must_be_ES3_ES5_or_ES6: { code: 6047, category: DiagnosticCategory.Error, key: "Argument for '--target' option must be 'ES3', 'ES5', or 'ES6'." }, Locale_must_be_of_the_form_language_or_language_territory_For_example_0_or_1: { code: 6048, category: DiagnosticCategory.Error, key: "Locale must be of the form or -. For example '{0}' or '{1}'." }, Unsupported_locale_0: { code: 6049, category: DiagnosticCategory.Error, key: "Unsupported locale '{0}'." }, Unable_to_open_file_0: { code: 6050, category: DiagnosticCategory.Error, key: "Unable to open file '{0}'." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 7192987f810..8aa4f73fe7c 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -631,7 +631,7 @@ "category": "Error", "code": 1203 }, - "Cannot compile external modules into amd or commonjs when targeting es6 or higher.": { + "Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher.": { "category": "Error", "code": 1204 }, @@ -1840,7 +1840,7 @@ "category": "Message", "code": 6015 }, - "Specify module code generation: 'commonjs', 'amd', or 'umd'": { + "Specify module code generation: 'commonjs', 'amd', or 'umd'.": { "category": "Message", "code": 6016 }, @@ -1928,7 +1928,7 @@ "category": "Error", "code": 6046 }, - "Argument for '--target' option must be 'es3', 'es5', or 'es6'.": { + "Argument for '--target' option must be 'ES3', 'ES5', or 'ES6'.": { "category": "Error", "code": 6047 }, diff --git a/src/compiler/program.ts b/src/compiler/program.ts index d49e01bd45d..97c681838f2 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -567,7 +567,7 @@ module ts { // Cannot specify module gen target when in es6 or above if (options.module && languageVersion >= ScriptTarget.ES6) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_compile_external_modules_into_amd_or_commonjs_when_targeting_es6_or_higher)); + diagnostics.add(createCompilerDiagnostic(Diagnostics.Cannot_compile_external_modules_into_amd_commonjs_or_umd_when_targeting_ES6_or_higher)); } // there has to be common source directory if user specified --outdir || --sourceRoot diff --git a/tests/baselines/reference/constDeclarations-access5.errors.txt b/tests/baselines/reference/constDeclarations-access5.errors.txt index a098b0e72c6..e689bbf8b4e 100644 --- a/tests/baselines/reference/constDeclarations-access5.errors.txt +++ b/tests/baselines/reference/constDeclarations-access5.errors.txt @@ -1,4 +1,4 @@ -error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher. tests/cases/compiler/constDeclarations_access_2.ts(2,1): error TS1202: 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. @@ -20,7 +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 TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +!!! error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' 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/es6-amd.errors.txt b/tests/baselines/reference/es6-amd.errors.txt index cb1ef4b1287..e1e44b4a493 100644 --- a/tests/baselines/reference/es6-amd.errors.txt +++ b/tests/baselines/reference/es6-amd.errors.txt @@ -1,7 +1,7 @@ -error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher. -!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +!!! error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher. ==== tests/cases/compiler/es6-amd.ts (0 errors) ==== class A diff --git a/tests/baselines/reference/es6-declaration-amd.errors.txt b/tests/baselines/reference/es6-declaration-amd.errors.txt index 18319504dc9..30cf14f0861 100644 --- a/tests/baselines/reference/es6-declaration-amd.errors.txt +++ b/tests/baselines/reference/es6-declaration-amd.errors.txt @@ -1,7 +1,7 @@ -error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher. -!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +!!! error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher. ==== tests/cases/compiler/es6-declaration-amd.ts (0 errors) ==== class A diff --git a/tests/baselines/reference/es6-sourcemap-amd.errors.txt b/tests/baselines/reference/es6-sourcemap-amd.errors.txt index 24a83f8ee12..da8968e9d5e 100644 --- a/tests/baselines/reference/es6-sourcemap-amd.errors.txt +++ b/tests/baselines/reference/es6-sourcemap-amd.errors.txt @@ -1,7 +1,7 @@ -error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher. -!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +!!! error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher. ==== tests/cases/compiler/es6-sourcemap-amd.ts (0 errors) ==== class A diff --git a/tests/baselines/reference/es6-umd.errors.txt b/tests/baselines/reference/es6-umd.errors.txt index c231fe0b12b..874b41552c5 100644 --- a/tests/baselines/reference/es6-umd.errors.txt +++ b/tests/baselines/reference/es6-umd.errors.txt @@ -1,7 +1,7 @@ -error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher. -!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +!!! error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher. ==== tests/cases/compiler/es6-umd.ts (0 errors) ==== class A diff --git a/tests/baselines/reference/es6-umd2.errors.txt b/tests/baselines/reference/es6-umd2.errors.txt index ac05e967356..88d732df122 100644 --- a/tests/baselines/reference/es6-umd2.errors.txt +++ b/tests/baselines/reference/es6-umd2.errors.txt @@ -1,7 +1,7 @@ -error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher. -!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +!!! error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher. ==== tests/cases/compiler/es6-umd2.ts (0 errors) ==== export class A diff --git a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt index 34bb303a571..5844f39ed3a 100644 --- a/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt +++ b/tests/baselines/reference/es6ImportDefaultBindingFollowedWithNamedImport.errors.txt @@ -1,7 +1,7 @@ -error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher. -!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +!!! error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher. ==== tests/cases/compiler/es6ImportDefaultBindingFollowedWithNamedImport_0.ts (0 errors) ==== export var a = 10; diff --git a/tests/baselines/reference/es6ImportNameSpaceImport.errors.txt b/tests/baselines/reference/es6ImportNameSpaceImport.errors.txt index 635bb955c00..20b74ee394e 100644 --- a/tests/baselines/reference/es6ImportNameSpaceImport.errors.txt +++ b/tests/baselines/reference/es6ImportNameSpaceImport.errors.txt @@ -1,7 +1,7 @@ -error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher. -!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +!!! error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher. ==== tests/cases/compiler/es6ImportNameSpaceImport_0.ts (0 errors) ==== export var a = 10; diff --git a/tests/baselines/reference/es6ImportNamedImport.errors.txt b/tests/baselines/reference/es6ImportNamedImport.errors.txt index 5723b5c20d4..b20f3808c95 100644 --- a/tests/baselines/reference/es6ImportNamedImport.errors.txt +++ b/tests/baselines/reference/es6ImportNamedImport.errors.txt @@ -1,7 +1,7 @@ -error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher. -!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +!!! error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher. ==== tests/cases/compiler/es6ImportNamedImport_0.ts (0 errors) ==== export var a = 10; diff --git a/tests/baselines/reference/es6ImportNamedImportInExportAssignment.errors.txt b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.errors.txt index 41d3f160938..ce4d4965921 100644 --- a/tests/baselines/reference/es6ImportNamedImportInExportAssignment.errors.txt +++ b/tests/baselines/reference/es6ImportNamedImportInExportAssignment.errors.txt @@ -1,8 +1,8 @@ -error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher. tests/cases/compiler/es6ImportNamedImportInExportAssignment_1.ts(2,1): error TS1203: Export assignment cannot be used when targeting ECMAScript 6 or higher. Consider using 'export default' instead. -!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +!!! error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher. ==== tests/cases/compiler/es6ImportNamedImportInExportAssignment_0.ts (0 errors) ==== export var a = 10; diff --git a/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.errors.txt b/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.errors.txt index bbe0d8b78b6..e851817ee8e 100644 --- a/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.errors.txt +++ b/tests/baselines/reference/es6ModuleWithModuleGenTargetAmd.errors.txt @@ -1,7 +1,7 @@ -error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher. -!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +!!! error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher. ==== tests/cases/compiler/es6ModuleWithModuleGenTargetAmd.ts (0 errors) ==== export class A { diff --git a/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.errors.txt b/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.errors.txt index 87f53cb7810..1de27c03c54 100644 --- a/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.errors.txt +++ b/tests/baselines/reference/es6ModuleWithModuleGenTargetCommonjs.errors.txt @@ -1,7 +1,7 @@ -error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher. -!!! error TS1204: Cannot compile external modules into amd or commonjs when targeting es6 or higher. +!!! error TS1204: Cannot compile external modules into 'amd', 'commonjs' or 'umd' when targeting 'ES6' or higher. ==== tests/cases/compiler/es6ModuleWithModuleGenTargetCommonjs.ts (0 errors) ==== export class A { From a9e79bf06b97cd32821bcea891b7feb03dfd492f Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Thu, 23 Apr 2015 11:04:44 -0700 Subject: [PATCH 077/194] Lazy resolution of global decorator types --- src/compiler/checker.ts | 26 +++++++++---------- src/compiler/core.ts | 11 ++++++++ .../reference/noDefaultLib.errors.txt | 10 ------- .../reference/parser509698.errors.txt | 26 ++++++------------- .../noDefaultLib/amd/noDefaultLib.errors.txt | 26 ++++++------------- .../noDefaultLib/node/noDefaultLib.errors.txt | 26 ++++++------------- .../typeCheckTypeArgument.errors.txt | 22 +++++----------- 7 files changed, 53 insertions(+), 94 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 50d17638371..489e44a9cd3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -114,11 +114,10 @@ module ts { let globalIterableType: ObjectType; let anyArrayType: Type; - let globalTypedPropertyDescriptorType: ObjectType; - let globalClassDecoratorType: ObjectType; - let globalParameterDecoratorType: ObjectType; - let globalPropertyDecoratorType: ObjectType; - let globalMethodDecoratorType: ObjectType; + let getGlobalClassDecoratorType: () => ObjectType; + let getGlobalParameterDecoratorType: () => ObjectType; + let getGlobalPropertyDecoratorType: () => ObjectType; + let getGlobalMethodDecoratorType: () => ObjectType; let tupleTypes: Map = {}; let unionTypes: Map = {}; @@ -8790,24 +8789,24 @@ module ts { case SyntaxKind.ClassDeclaration: let classSymbol = getSymbolOfNode(node.parent); let classConstructorType = getTypeOfSymbol(classSymbol); - let classDecoratorType = instantiateSingleCallFunctionType(globalClassDecoratorType, [classConstructorType]); + let classDecoratorType = instantiateSingleCallFunctionType(getGlobalClassDecoratorType(), [classConstructorType]); checkTypeAssignableTo(exprType, classDecoratorType, node); break; case SyntaxKind.PropertyDeclaration: - checkTypeAssignableTo(exprType, globalPropertyDecoratorType, node); + checkTypeAssignableTo(exprType, getGlobalPropertyDecoratorType(), node); break; case SyntaxKind.MethodDeclaration: case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: let methodType = getTypeOfNode(node.parent); - let methodDecoratorType = instantiateSingleCallFunctionType(globalMethodDecoratorType, [methodType]); + let methodDecoratorType = instantiateSingleCallFunctionType(getGlobalMethodDecoratorType(), [methodType]); checkTypeAssignableTo(exprType, methodDecoratorType, node); break; case SyntaxKind.Parameter: - checkTypeAssignableTo(exprType, globalParameterDecoratorType, node); + checkTypeAssignableTo(exprType, getGlobalParameterDecoratorType(), node); break; } } @@ -11969,11 +11968,10 @@ module ts { globalNumberType = getGlobalType("Number"); globalBooleanType = getGlobalType("Boolean"); globalRegExpType = getGlobalType("RegExp"); - globalTypedPropertyDescriptorType = getTypeOfGlobalSymbol(getGlobalTypeSymbol("TypedPropertyDescriptor"), 1); - globalClassDecoratorType = getGlobalType("ClassDecorator"); - globalPropertyDecoratorType = getGlobalType("PropertyDecorator"); - globalMethodDecoratorType = getGlobalType("MethodDecorator"); - globalParameterDecoratorType = getGlobalType("ParameterDecorator"); + getGlobalClassDecoratorType = memoize(() => getGlobalType("ClassDecorator")); + getGlobalPropertyDecoratorType = memoize(() => getGlobalType("PropertyDecorator")); + getGlobalMethodDecoratorType = memoize(() => getGlobalType("MethodDecorator")); + getGlobalParameterDecoratorType = memoize(() => getGlobalType("ParameterDecorator")); // If we're in ES6 mode, load the TemplateStringsArray. // Otherwise, default to 'unknown' for the purposes of type checking in LS scenarios. diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 80840068332..6383108b0d6 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -281,6 +281,17 @@ module ts { return result; } + export function memoize(callback: () => T): () => T { + let value: T; + return () => { + if (callback) { + value = callback(); + callback = undefined; + } + return value; + }; + } + function formatStringFromArgs(text: string, args: { [index: number]: any; }, baseIndex?: number): string { baseIndex = baseIndex || 0; diff --git a/tests/baselines/reference/noDefaultLib.errors.txt b/tests/baselines/reference/noDefaultLib.errors.txt index c73f3e0b948..b8f42ba7c33 100644 --- a/tests/baselines/reference/noDefaultLib.errors.txt +++ b/tests/baselines/reference/noDefaultLib.errors.txt @@ -1,19 +1,9 @@ -error TS2318: Cannot find global type 'TypedPropertyDescriptor'. -error TS2318: Cannot find global type 'PropertyDecorator'. -error TS2318: Cannot find global type 'ParameterDecorator'. -error TS2318: Cannot find global type 'MethodDecorator'. error TS2318: Cannot find global type 'IArguments'. -error TS2318: Cannot find global type 'ClassDecorator'. error TS2318: Cannot find global type 'Boolean'. tests/cases/compiler/noDefaultLib.ts(4,11): error TS2317: Global type 'Array' must have 1 type parameter(s). -!!! error TS2318: Cannot find global type 'TypedPropertyDescriptor'. -!!! error TS2318: Cannot find global type 'PropertyDecorator'. -!!! error TS2318: Cannot find global type 'ParameterDecorator'. -!!! error TS2318: Cannot find global type 'MethodDecorator'. !!! error TS2318: Cannot find global type 'IArguments'. -!!! error TS2318: Cannot find global type 'ClassDecorator'. !!! error TS2318: Cannot find global type 'Boolean'. ==== tests/cases/compiler/noDefaultLib.ts (1 errors) ==== /// diff --git a/tests/baselines/reference/parser509698.errors.txt b/tests/baselines/reference/parser509698.errors.txt index 3dd70275e5c..85485dd6501 100644 --- a/tests/baselines/reference/parser509698.errors.txt +++ b/tests/baselines/reference/parser509698.errors.txt @@ -1,31 +1,21 @@ -error TS2318: Cannot find global type 'Number'. -error TS2318: Cannot find global type 'TypedPropertyDescriptor'. -error TS2318: Cannot find global type 'Object'. -error TS2318: Cannot find global type 'Array'. -error TS2318: Cannot find global type 'ClassDecorator'. error TS2318: Cannot find global type 'String'. error TS2318: Cannot find global type 'RegExp'. -error TS2318: Cannot find global type 'PropertyDecorator'. -error TS2318: Cannot find global type 'ParameterDecorator'. +error TS2318: Cannot find global type 'Object'. +error TS2318: Cannot find global type 'Number'. +error TS2318: Cannot find global type 'IArguments'. error TS2318: Cannot find global type 'Function'. error TS2318: Cannot find global type 'Boolean'. -error TS2318: Cannot find global type 'MethodDecorator'. -error TS2318: Cannot find global type 'IArguments'. +error TS2318: Cannot find global type 'Array'. -!!! error TS2318: Cannot find global type 'Number'. -!!! error TS2318: Cannot find global type 'TypedPropertyDescriptor'. -!!! error TS2318: Cannot find global type 'Object'. -!!! error TS2318: Cannot find global type 'Array'. -!!! error TS2318: Cannot find global type 'ClassDecorator'. !!! error TS2318: Cannot find global type 'String'. !!! error TS2318: Cannot find global type 'RegExp'. -!!! error TS2318: Cannot find global type 'PropertyDecorator'. -!!! error TS2318: Cannot find global type 'ParameterDecorator'. +!!! error TS2318: Cannot find global type 'Object'. +!!! error TS2318: Cannot find global type 'Number'. +!!! error TS2318: Cannot find global type 'IArguments'. !!! error TS2318: Cannot find global type 'Function'. !!! error TS2318: Cannot find global type 'Boolean'. -!!! error TS2318: Cannot find global type 'MethodDecorator'. -!!! error TS2318: Cannot find global type 'IArguments'. +!!! error TS2318: Cannot find global type 'Array'. ==== tests/cases/conformance/parser/ecmascript5/RegressionTests/parser509698.ts (0 errors) ==== ///