From a69fc67986dc87406ea4ed2f69ea2118a15e75b9 Mon Sep 17 00:00:00 2001 From: Jason Ramsay Date: Fri, 14 Oct 2016 16:04:51 -0700 Subject: [PATCH 1/9] Restrict IsGlobalCompletion to: - SourceFile - Template Expression - Statements --- src/services/completions.ts | 11 ++-- .../completionListIsGlobalCompletion.ts | 51 +++++++++++++------ 2 files changed, 43 insertions(+), 19 deletions(-) diff --git a/src/services/completions.ts b/src/services/completions.ts index c8d7c019e54..cd4d64b3b09 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -1,3 +1,5 @@ +/// + /* @internal */ namespace ts.Completions { export function getCompletionsAtPosition(host: LanguageServiceHost, typeChecker: TypeChecker, log: (message: string) => void, compilerOptions: CompilerOptions, sourceFile: SourceFile, position: number): CompletionInfo { @@ -951,7 +953,6 @@ namespace ts.Completions { if (!tryGetGlobalSymbols()) { return undefined; } - isGlobalCompletion = true; } log("getCompletionData: Semantic work: " + (timestamp() - semanticStart)); @@ -1030,7 +1031,6 @@ namespace ts.Completions { if ((jsxContainer.kind === SyntaxKind.JsxSelfClosingElement) || (jsxContainer.kind === SyntaxKind.JsxOpeningElement)) { // Cursor is inside a JSX self-closing element or opening element attrsType = typeChecker.getJsxElementAttributesType(jsxContainer); - isGlobalCompletion = false; if (attrsType) { symbols = filterJsxAttributes(typeChecker.getPropertiesOfType(attrsType), (jsxContainer).attributes); @@ -1038,7 +1038,6 @@ namespace ts.Completions { isNewIdentifierLocation = false; return true; } - } } @@ -1079,6 +1078,12 @@ namespace ts.Completions { position; const scopeNode = getScopeNode(contextToken, adjustedPosition, sourceFile) || sourceFile; + if (scopeNode) { + isGlobalCompletion = + scopeNode.kind === SyntaxKind.SourceFile || + scopeNode.kind === SyntaxKind.TemplateExpression || + isStatement(scopeNode); + } /// TODO filter meaning based on the current context const symbolMeanings = SymbolFlags.Type | SymbolFlags.Value | SymbolFlags.Namespace | SymbolFlags.Alias; diff --git a/tests/cases/fourslash/completionListIsGlobalCompletion.ts b/tests/cases/fourslash/completionListIsGlobalCompletion.ts index 73cb6bb2176..3961f4fadae 100644 --- a/tests/cases/fourslash/completionListIsGlobalCompletion.ts +++ b/tests/cases/fourslash/completionListIsGlobalCompletion.ts @@ -1,27 +1,38 @@ /// +// @Filename: file.ts +////export var x = 10; +////export var y = 10; +////export default class C { +////} + +// @Filename: a.ts +////import { /*1*/ } from "./file.ts"; // no globals in imports - export found + //@Filename: file.tsx -/////// // no globals in reference paths -////import { /*2*/ } from "./file.ts"; // no globals in imports -////var test = "/*3*/"; // no globals in strings -/////*4*/class A { // insert globals +/////// // no globals in reference paths +////import { /*3*/ } from "./file1.ts"; // no globals in imports - export not found +////var test = "/*4*/"; // no globals in strings +/////*5*/class A { // insert globals //// foo(): string { return ''; } ////} //// -////class /*5*/B extends A { // no globals after class keyword +////class /*6*/B extends A { // no globals after class keyword //// bar(): string { -//// /*6*/ // insert globals +//// /*7*/ // insert globals //// return ''; //// } ////} //// -////class C { // no globals at beginning of generics +////class C { // no globals at beginning of generics //// x: U; -//// y = this./*8*/x; // no globals inserted for member completions -//// /*9*/ // insert globals +//// y = this./*9*/x; // no globals inserted for member completions +//// /*10*/ // insert globals ////} -/////*10*/ // insert globals -////const y =
; +/////*11*/ // insert globals +////const y =
; // no globals in jsx attribute found +////const z =
; // no globals in jsx attribute with syntax error +////const x = `/*14*/ ${/*15*/}`; // globals only in template expression goTo.marker("1"); verify.completionListIsGlobal(false); goTo.marker("2"); @@ -29,18 +40,26 @@ verify.completionListIsGlobal(false); goTo.marker("3"); verify.completionListIsGlobal(false); goTo.marker("4"); -verify.completionListIsGlobal(true); +verify.completionListIsGlobal(false); goTo.marker("5"); -verify.completionListIsGlobal(false); -goTo.marker("6"); verify.completionListIsGlobal(true); -goTo.marker("7"); +goTo.marker("6"); verify.completionListIsGlobal(false); +goTo.marker("7"); +verify.completionListIsGlobal(true); goTo.marker("8"); verify.completionListIsGlobal(false); goTo.marker("9"); -verify.completionListIsGlobal(true); +verify.completionListIsGlobal(false); goTo.marker("10"); verify.completionListIsGlobal(true); goTo.marker("11"); +verify.completionListIsGlobal(true); +goTo.marker("12"); verify.completionListIsGlobal(false); +goTo.marker("13"); +verify.completionListIsGlobal(false); +goTo.marker("14"); +verify.completionListIsGlobal(false); +goTo.marker("15"); +verify.completionListIsGlobal(true); \ No newline at end of file From de876bdfc96d942115ab22aef8b6130c210eaee3 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Tue, 18 Oct 2016 07:34:48 -0700 Subject: [PATCH 2/9] Use an ES5 target --- Jakefile.js | 2 ++ src/compiler/tsconfig.json | 3 ++- src/harness/tsconfig.json | 3 ++- src/server/cancellationToken/tsconfig.json | 3 ++- src/server/tsconfig.json | 3 ++- src/server/tsconfig.library.json | 3 ++- src/server/typingsInstaller/tsconfig.json | 3 ++- src/services/tsconfig.json | 3 ++- 8 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Jakefile.js b/Jakefile.js index 6592347b59e..301dc574eb6 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -448,6 +448,8 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, opts options += " --stripInternal"; } + options += " --target es5"; + var cmd = host + " " + compilerPath + " " + options + " "; cmd = cmd + sources.join(" "); console.log(cmd + "\n"); diff --git a/src/compiler/tsconfig.json b/src/compiler/tsconfig.json index 92a3ea38551..65ba20f18d2 100644 --- a/src/compiler/tsconfig.json +++ b/src/compiler/tsconfig.json @@ -8,7 +8,8 @@ "outFile": "../../built/local/tsc.js", "sourceMap": true, "declaration": true, - "stripInternal": true + "stripInternal": true, + "target": "es5" }, "files": [ "core.ts", diff --git a/src/harness/tsconfig.json b/src/harness/tsconfig.json index bbc1a49a0f7..d0f500e27aa 100644 --- a/src/harness/tsconfig.json +++ b/src/harness/tsconfig.json @@ -10,7 +10,8 @@ "stripInternal": true, "types": [ "node", "mocha", "chai" - ] + ], + "target": "es5" }, "files": [ "../compiler/core.ts", diff --git a/src/server/cancellationToken/tsconfig.json b/src/server/cancellationToken/tsconfig.json index 1245fc34fd5..bcfe5ddb465 100644 --- a/src/server/cancellationToken/tsconfig.json +++ b/src/server/cancellationToken/tsconfig.json @@ -10,7 +10,8 @@ "stripInternal": true, "types": [ "node" - ] + ], + "target": "es5" }, "files": [ "cancellationToken.ts" diff --git a/src/server/tsconfig.json b/src/server/tsconfig.json index 9f907446c03..5308abb0c84 100644 --- a/src/server/tsconfig.json +++ b/src/server/tsconfig.json @@ -10,7 +10,8 @@ "stripInternal": true, "types": [ "node" - ] + ], + "target": "es5" }, "files": [ "../services/shims.ts", diff --git a/src/server/tsconfig.library.json b/src/server/tsconfig.library.json index a450b591a7e..a287a77fed5 100644 --- a/src/server/tsconfig.library.json +++ b/src/server/tsconfig.library.json @@ -7,7 +7,8 @@ "sourceMap": true, "stripInternal": true, "declaration": true, - "types": [] + "types": [], + "target": "es5" }, "files": [ "../services/shims.ts", diff --git a/src/server/typingsInstaller/tsconfig.json b/src/server/typingsInstaller/tsconfig.json index fc4b896f267..58805081de6 100644 --- a/src/server/typingsInstaller/tsconfig.json +++ b/src/server/typingsInstaller/tsconfig.json @@ -10,7 +10,8 @@ "stripInternal": true, "types": [ "node" - ] + ], + "target": "es5" }, "files": [ "../types.d.ts", diff --git a/src/services/tsconfig.json b/src/services/tsconfig.json index a3482a63c31..4e130c7dfb2 100644 --- a/src/services/tsconfig.json +++ b/src/services/tsconfig.json @@ -9,7 +9,8 @@ "sourceMap": true, "stripInternal": true, "noResolve": false, - "declaration": true + "declaration": true, + "target": "es5" }, "files": [ "../compiler/core.ts", From 64e8221a4498179cd90ea91a9e5ceacd14bafa6d Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Tue, 18 Oct 2016 08:18:01 -0700 Subject: [PATCH 3/9] Use single `concat` call instead of repeated calls --- src/compiler/program.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 50e53ab9484..06e9f6f30f1 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -766,7 +766,7 @@ namespace ts { const fileProcessingDiagnosticsInFile = fileProcessingDiagnostics.getDiagnostics(sourceFile.fileName); const programDiagnosticsInFile = programDiagnostics.getDiagnostics(sourceFile.fileName); - return bindDiagnostics.concat(checkDiagnostics).concat(fileProcessingDiagnosticsInFile).concat(programDiagnosticsInFile); + return bindDiagnostics.concat(checkDiagnostics, fileProcessingDiagnosticsInFile, programDiagnosticsInFile); }); } From 1f7f67de17879bb70825d8c5955e3b7c036ace10 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Tue, 18 Oct 2016 08:09:56 -0700 Subject: [PATCH 4/9] Type arguments to formatStringFromArgs as strings instead of implicitly stringifying --- src/compiler/checker.ts | 16 +++++++++------- src/compiler/commandLineParser.ts | 5 +---- src/compiler/core.ts | 6 +++--- src/compiler/utilities.ts | 2 +- src/harness/unittests/commandLineParsing.ts | 16 ++++++++-------- .../convertCompilerOptionsFromJson.ts | 18 +++++++++--------- ...ions module-kind is out-of-range.errors.txt | 4 ++-- ...ns target-script is out-of-range.errors.txt | 4 ++-- 8 files changed, 35 insertions(+), 36 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d3f15f2367b..0fee5611c60 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -368,7 +368,7 @@ namespace ts { return emitResolver; } - function error(location: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): void { + function error(location: Node, message: DiagnosticMessage, arg0?: string, arg1?: string, arg2?: string): void { const diagnostic = location ? createDiagnosticForNode(location, message, arg0, arg1, arg2) : createCompilerDiagnostic(message, arg0, arg1, arg2); @@ -3004,7 +3004,8 @@ namespace ts { : elementType; if (!type) { if (isTupleType(parentType)) { - error(declaration, Diagnostics.Tuple_type_0_with_length_1_cannot_be_assigned_to_tuple_with_length_2, typeToString(parentType), getTypeReferenceArity(parentType), pattern.elements.length); + error(declaration, Diagnostics.Tuple_type_0_with_length_1_cannot_be_assigned_to_tuple_with_length_2, + typeToString(parentType), getTypeReferenceArity(parentType).toString(), pattern.elements.length.toString()); } else { error(declaration, Diagnostics.Type_0_has_no_property_1, typeToString(parentType), propName); @@ -5103,7 +5104,7 @@ namespace ts { const typeParameters = type.localTypeParameters; if (typeParameters) { if (!node.typeArguments || node.typeArguments.length !== typeParameters.length) { - error(node, Diagnostics.Generic_type_0_requires_1_type_argument_s, typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.WriteArrayAsGenericType), typeParameters.length); + error(node, Diagnostics.Generic_type_0_requires_1_type_argument_s, typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.WriteArrayAsGenericType), typeParameters.length.toString()); return unknownType; } // In a type reference, the outer type parameters of the referenced class or interface are automatically @@ -5127,7 +5128,7 @@ namespace ts { const typeParameters = links.typeParameters; if (typeParameters) { if (!node.typeArguments || node.typeArguments.length !== typeParameters.length) { - error(node, Diagnostics.Generic_type_0_requires_1_type_argument_s, symbolToString(symbol), typeParameters.length); + error(node, Diagnostics.Generic_type_0_requires_1_type_argument_s, symbolToString(symbol), typeParameters.length.toString()); return unknownType; } const typeArguments = map(node.typeArguments, getTypeFromTypeNodeNoAlias); @@ -5270,7 +5271,7 @@ namespace ts { return arity ? emptyGenericType : emptyObjectType; } if (((type).typeParameters ? (type).typeParameters.length : 0) !== arity) { - error(getTypeDeclaration(symbol), Diagnostics.Global_type_0_must_have_1_type_parameter_s, symbol.name, arity); + error(getTypeDeclaration(symbol), Diagnostics.Global_type_0_must_have_1_type_parameter_s, symbol.name, arity.toString()); return arity ? emptyGenericType : emptyObjectType; } return type; @@ -8537,7 +8538,7 @@ namespace ts { // An evolving array type tracks the element types that have so far been seen in an // 'x.push(value)' or 'x[n] = value' operation along the control flow graph. Evolving // array types are ultimately converted into manifest array types (using getFinalArrayType) - // and never escape the getFlowTypeOfReference function. + // and never escape the getFlowTypeOfReference function. function createEvolvingArrayType(elementType: Type): AnonymousType { const result = createObjectType(TypeFlags.Anonymous); result.elementType = elementType; @@ -13630,7 +13631,8 @@ namespace ts { // such as NodeCheckFlags.LexicalThis on "this"expression. checkExpression(element); if (isTupleType(sourceType)) { - error(element, Diagnostics.Tuple_type_0_with_length_1_cannot_be_assigned_to_tuple_with_length_2, typeToString(sourceType), getTypeReferenceArity(sourceType), elements.length); + error(element, Diagnostics.Tuple_type_0_with_length_1_cannot_be_assigned_to_tuple_with_length_2, + typeToString(sourceType), getTypeReferenceArity(sourceType).toString(), elements.length.toString()); } else { error(element, Diagnostics.Type_0_has_no_property_1, typeToString(sourceType), propName); diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index d5207e4ce9a..d6c7dad0e8e 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -515,10 +515,7 @@ namespace ts { /* @internal */ export function createCompilerDiagnosticForInvalidCustomType(opt: CommandLineOptionOfCustomType): Diagnostic { - const namesOfType: string[] = []; - for (const key in opt.type) { - namesOfType.push(` '${key}'`); - } + const namesOfType = Object.keys(opt.type).map(key => `'${key}'`).join(", "); return createCompilerDiagnostic(Diagnostics.Argument_for_0_option_must_be_Colon_1, `--${opt.name}`, namesOfType); } diff --git a/src/compiler/core.ts b/src/compiler/core.ts index befa30b6006..fd0724db311 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -940,7 +940,7 @@ namespace ts { } } - function formatStringFromArgs(text: string, args: { [index: number]: any; }, baseIndex?: number): string { + function formatStringFromArgs(text: string, args: { [index: number]: string; }, baseIndex?: number): string { baseIndex = baseIndex || 0; return text.replace(/{(\d+)}/g, (match, index?) => args[+index + baseIndex]); @@ -952,7 +952,7 @@ namespace ts { return localizedDiagnosticMessages && localizedDiagnosticMessages[message.key] || message.message; } - export function createFileDiagnostic(file: SourceFile, start: number, length: number, message: DiagnosticMessage, ...args: any[]): Diagnostic; + export function createFileDiagnostic(file: SourceFile, start: number, length: number, message: DiagnosticMessage, ...args: string[]): Diagnostic; export function createFileDiagnostic(file: SourceFile, start: number, length: number, message: DiagnosticMessage): Diagnostic { const end = start + length; @@ -992,7 +992,7 @@ namespace ts { return text; } - export function createCompilerDiagnostic(message: DiagnosticMessage, ...args: any[]): Diagnostic; + export function createCompilerDiagnostic(message: DiagnosticMessage, ...args: string[]): Diagnostic; export function createCompilerDiagnostic(message: DiagnosticMessage): Diagnostic { let text = getLocaleSpecificMessage(message); diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 952a3205250..dfdfae9c259 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -503,7 +503,7 @@ namespace ts { return getFullWidth(name) === 0 ? "(Missing)" : getTextOfNode(name); } - export function createDiagnosticForNode(node: Node, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): Diagnostic { + export function createDiagnosticForNode(node: Node, message: DiagnosticMessage, arg0?: string, arg1?: string, arg2?: string): Diagnostic { const sourceFile = getSourceFileOfNode(node); const span = getErrorSpanForNode(sourceFile, node); return createFileDiagnostic(sourceFile, span.start, span.length, message, arg0, arg1, arg2); diff --git a/src/harness/unittests/commandLineParsing.ts b/src/harness/unittests/commandLineParsing.ts index cd9bf88df60..67bc1e9b795 100644 --- a/src/harness/unittests/commandLineParsing.ts +++ b/src/harness/unittests/commandLineParsing.ts @@ -60,7 +60,7 @@ namespace ts { assertParseResult(["--lib", "es5,invalidOption", "0.ts"], { errors: [{ - messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'", + messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'", category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category, code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code, @@ -87,7 +87,7 @@ namespace ts { start: undefined, length: undefined, }, { - messageText: "Argument for '--jsx' option must be: 'preserve', 'react'", + messageText: "Argument for '--jsx' option must be: 'preserve', 'react'", category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category, code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code, @@ -113,7 +113,7 @@ namespace ts { start: undefined, length: undefined, }, { - messageText: "Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015'", + messageText: "Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015'", category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category, code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code, @@ -139,7 +139,7 @@ namespace ts { start: undefined, length: undefined, }, { - messageText: "Argument for '--newLine' option must be: 'crlf', 'lf'", + messageText: "Argument for '--newLine' option must be: 'crlf', 'lf'", category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category, code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code, @@ -165,7 +165,7 @@ namespace ts { start: undefined, length: undefined, }, { - messageText: "Argument for '--target' option must be: 'es3', 'es5', 'es6', 'es2015', 'es2016', 'es2017'", + messageText: "Argument for '--target' option must be: 'es3', 'es5', 'es6', 'es2015', 'es2016', 'es2017'", category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category, code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code, @@ -191,7 +191,7 @@ namespace ts { start: undefined, length: undefined, }, { - messageText: "Argument for '--moduleResolution' option must be: 'node', 'classic'", + messageText: "Argument for '--moduleResolution' option must be: 'node', 'classic'", category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category, code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code, @@ -263,7 +263,7 @@ namespace ts { assertParseResult(["--lib", "es5,", "es7", "0.ts"], { errors: [{ - messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'", + messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'", category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category, code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code, @@ -283,7 +283,7 @@ namespace ts { assertParseResult(["--lib", "es5, ", "es7", "0.ts"], { errors: [{ - messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'", + messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'", category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category, code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code, diff --git a/src/harness/unittests/convertCompilerOptionsFromJson.ts b/src/harness/unittests/convertCompilerOptionsFromJson.ts index a2174c17e41..2942675f0ac 100644 --- a/src/harness/unittests/convertCompilerOptionsFromJson.ts +++ b/src/harness/unittests/convertCompilerOptionsFromJson.ts @@ -94,7 +94,7 @@ namespace ts { file: undefined, start: 0, length: 0, - messageText: "Argument for '--jsx' option must be: 'preserve', 'react'", + messageText: "Argument for '--jsx' option must be: 'preserve', 'react'", code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code, category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category }] @@ -122,7 +122,7 @@ namespace ts { file: undefined, start: 0, length: 0, - messageText: "Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015'", + messageText: "Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015'", code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code, category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category }] @@ -150,7 +150,7 @@ namespace ts { file: undefined, start: 0, length: 0, - messageText: "Argument for '--newLine' option must be: 'crlf', 'lf'", + messageText: "Argument for '--newLine' option must be: 'crlf', 'lf'", code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code, category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category }] @@ -176,7 +176,7 @@ namespace ts { file: undefined, start: 0, length: 0, - messageText: "Argument for '--target' option must be: 'es3', 'es5', 'es6', 'es2015', 'es2016', 'es2017'", + messageText: "Argument for '--target' option must be: 'es3', 'es5', 'es6', 'es2015', 'es2016', 'es2017'", code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code, category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category }] @@ -202,7 +202,7 @@ namespace ts { file: undefined, start: 0, length: 0, - messageText: "Argument for '--moduleResolution' option must be: 'node', 'classic'", + messageText: "Argument for '--moduleResolution' option must be: 'node', 'classic'", code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code, category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category }] @@ -233,7 +233,7 @@ namespace ts { file: undefined, start: 0, length: 0, - messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'", + messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'", code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code, category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category }] @@ -264,7 +264,7 @@ namespace ts { file: undefined, start: 0, length: 0, - messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'", + messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'", code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code, category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category }] @@ -295,7 +295,7 @@ namespace ts { file: undefined, start: 0, length: 0, - messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'", + messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'", code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code, category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category }] @@ -326,7 +326,7 @@ namespace ts { file: undefined, start: 0, length: 0, - messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'", + messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'dom.iterable', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'", code: Diagnostics.Argument_for_0_option_must_be_Colon_1.code, category: Diagnostics.Argument_for_0_option_must_be_Colon_1.category }] diff --git a/tests/baselines/reference/transpile/Report an error when compiler-options module-kind is out-of-range.errors.txt b/tests/baselines/reference/transpile/Report an error when compiler-options module-kind is out-of-range.errors.txt index d7d6eb69300..7778f6c23c5 100644 --- a/tests/baselines/reference/transpile/Report an error when compiler-options module-kind is out-of-range.errors.txt +++ b/tests/baselines/reference/transpile/Report an error when compiler-options module-kind is out-of-range.errors.txt @@ -1,6 +1,6 @@ -error TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015' +error TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015' -!!! error TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015' +!!! error TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015' ==== file.ts (0 errors) ==== \ No newline at end of file diff --git a/tests/baselines/reference/transpile/Report an error when compiler-options target-script is out-of-range.errors.txt b/tests/baselines/reference/transpile/Report an error when compiler-options target-script is out-of-range.errors.txt index d7d6eb69300..7778f6c23c5 100644 --- a/tests/baselines/reference/transpile/Report an error when compiler-options target-script is out-of-range.errors.txt +++ b/tests/baselines/reference/transpile/Report an error when compiler-options target-script is out-of-range.errors.txt @@ -1,6 +1,6 @@ -error TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015' +error TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015' -!!! error TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015' +!!! error TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015' ==== file.ts (0 errors) ==== \ No newline at end of file From ff17eeda8f3487fb1a1659beb4bb233efcbc08d3 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Tue, 18 Oct 2016 11:35:22 -0700 Subject: [PATCH 5/9] check heritage clause for the presence of entry with Extends keyword (#11711) --- src/compiler/transformers/ts.ts | 2 +- tests/baselines/reference/classExpressions.js | 20 ++++++++++++++++++ .../reference/classExpressions.symbols | 19 +++++++++++++++++ .../reference/classExpressions.types | 21 +++++++++++++++++++ tests/cases/compiler/classExpressions.ts | 8 +++++++ 5 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/classExpressions.js create mode 100644 tests/baselines/reference/classExpressions.symbols create mode 100644 tests/baselines/reference/classExpressions.types create mode 100644 tests/cases/compiler/classExpressions.ts diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index 1d930c3c21e..a1190efee10 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -795,7 +795,7 @@ namespace ts { function visitClassExpression(node: ClassExpression): Expression { const staticProperties = getInitializedProperties(node, /*isStatic*/ true); const heritageClauses = visitNodes(node.heritageClauses, visitor, isHeritageClause); - const members = transformClassMembers(node, heritageClauses !== undefined); + const members = transformClassMembers(node, some(heritageClauses, c => c.token === SyntaxKind.ExtendsKeyword)); const classExpression = setOriginalNode( createClassExpression( diff --git a/tests/baselines/reference/classExpressions.js b/tests/baselines/reference/classExpressions.js new file mode 100644 index 00000000000..3932fa5045b --- /dev/null +++ b/tests/baselines/reference/classExpressions.js @@ -0,0 +1,20 @@ +//// [classExpressions.ts] +interface A {} +let x = class B implements A { + prop: number; + onStart(): void { + } + func = () => { + } +}; + +//// [classExpressions.js] +var x = (function () { + function B() { + this.func = function () { + }; + } + B.prototype.onStart = function () { + }; + return B; +}()); diff --git a/tests/baselines/reference/classExpressions.symbols b/tests/baselines/reference/classExpressions.symbols new file mode 100644 index 00000000000..038b1b81116 --- /dev/null +++ b/tests/baselines/reference/classExpressions.symbols @@ -0,0 +1,19 @@ +=== tests/cases/compiler/classExpressions.ts === +interface A {} +>A : Symbol(A, Decl(classExpressions.ts, 0, 0)) + +let x = class B implements A { +>x : Symbol(x, Decl(classExpressions.ts, 1, 3)) +>B : Symbol(B, Decl(classExpressions.ts, 1, 7)) +>A : Symbol(A, Decl(classExpressions.ts, 0, 0)) + + prop: number; +>prop : Symbol(B.prop, Decl(classExpressions.ts, 1, 30)) + + onStart(): void { +>onStart : Symbol(B.onStart, Decl(classExpressions.ts, 2, 17)) + } + func = () => { +>func : Symbol(B.func, Decl(classExpressions.ts, 4, 5)) + } +}; diff --git a/tests/baselines/reference/classExpressions.types b/tests/baselines/reference/classExpressions.types new file mode 100644 index 00000000000..3fcff32c4a4 --- /dev/null +++ b/tests/baselines/reference/classExpressions.types @@ -0,0 +1,21 @@ +=== tests/cases/compiler/classExpressions.ts === +interface A {} +>A : A + +let x = class B implements A { +>x : typeof B +>class B implements A { prop: number; onStart(): void { } func = () => { }} : typeof B +>B : typeof B +>A : A + + prop: number; +>prop : number + + onStart(): void { +>onStart : () => void + } + func = () => { +>func : () => void +>() => { } : () => void + } +}; diff --git a/tests/cases/compiler/classExpressions.ts b/tests/cases/compiler/classExpressions.ts new file mode 100644 index 00000000000..fc7ce376469 --- /dev/null +++ b/tests/cases/compiler/classExpressions.ts @@ -0,0 +1,8 @@ +interface A {} +let x = class B implements A { + prop: number; + onStart(): void { + } + func = () => { + } +}; \ No newline at end of file From 8dc9523fb0530bc5d35743e3250d3a4f0a67ce8d Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Tue, 18 Oct 2016 11:53:27 -0700 Subject: [PATCH 6/9] Allow number too --- src/compiler/checker.ts | 14 ++++++-------- src/compiler/core.ts | 4 ++-- src/compiler/utilities.ts | 2 +- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0fee5611c60..3708ea3582c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -368,7 +368,7 @@ namespace ts { return emitResolver; } - function error(location: Node, message: DiagnosticMessage, arg0?: string, arg1?: string, arg2?: string): void { + function error(location: Node, message: DiagnosticMessage, arg0?: string | number, arg1?: string | number, arg2?: string | number): void { const diagnostic = location ? createDiagnosticForNode(location, message, arg0, arg1, arg2) : createCompilerDiagnostic(message, arg0, arg1, arg2); @@ -3004,8 +3004,7 @@ namespace ts { : elementType; if (!type) { if (isTupleType(parentType)) { - error(declaration, Diagnostics.Tuple_type_0_with_length_1_cannot_be_assigned_to_tuple_with_length_2, - typeToString(parentType), getTypeReferenceArity(parentType).toString(), pattern.elements.length.toString()); + error(declaration, Diagnostics.Tuple_type_0_with_length_1_cannot_be_assigned_to_tuple_with_length_2, typeToString(parentType), getTypeReferenceArity(parentType), pattern.elements.length); } else { error(declaration, Diagnostics.Type_0_has_no_property_1, typeToString(parentType), propName); @@ -5104,7 +5103,7 @@ namespace ts { const typeParameters = type.localTypeParameters; if (typeParameters) { if (!node.typeArguments || node.typeArguments.length !== typeParameters.length) { - error(node, Diagnostics.Generic_type_0_requires_1_type_argument_s, typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.WriteArrayAsGenericType), typeParameters.length.toString()); + error(node, Diagnostics.Generic_type_0_requires_1_type_argument_s, typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.WriteArrayAsGenericType), typeParameters.length); return unknownType; } // In a type reference, the outer type parameters of the referenced class or interface are automatically @@ -5128,7 +5127,7 @@ namespace ts { const typeParameters = links.typeParameters; if (typeParameters) { if (!node.typeArguments || node.typeArguments.length !== typeParameters.length) { - error(node, Diagnostics.Generic_type_0_requires_1_type_argument_s, symbolToString(symbol), typeParameters.length.toString()); + error(node, Diagnostics.Generic_type_0_requires_1_type_argument_s, symbolToString(symbol), typeParameters.length); return unknownType; } const typeArguments = map(node.typeArguments, getTypeFromTypeNodeNoAlias); @@ -5271,7 +5270,7 @@ namespace ts { return arity ? emptyGenericType : emptyObjectType; } if (((type).typeParameters ? (type).typeParameters.length : 0) !== arity) { - error(getTypeDeclaration(symbol), Diagnostics.Global_type_0_must_have_1_type_parameter_s, symbol.name, arity.toString()); + error(getTypeDeclaration(symbol), Diagnostics.Global_type_0_must_have_1_type_parameter_s, symbol.name, arity); return arity ? emptyGenericType : emptyObjectType; } return type; @@ -13631,8 +13630,7 @@ namespace ts { // such as NodeCheckFlags.LexicalThis on "this"expression. checkExpression(element); if (isTupleType(sourceType)) { - error(element, Diagnostics.Tuple_type_0_with_length_1_cannot_be_assigned_to_tuple_with_length_2, - typeToString(sourceType), getTypeReferenceArity(sourceType).toString(), elements.length.toString()); + error(element, Diagnostics.Tuple_type_0_with_length_1_cannot_be_assigned_to_tuple_with_length_2, typeToString(sourceType), getTypeReferenceArity(sourceType), elements.length); } else { error(element, Diagnostics.Type_0_has_no_property_1, typeToString(sourceType), propName); diff --git a/src/compiler/core.ts b/src/compiler/core.ts index fd0724db311..b41f382badf 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -952,7 +952,7 @@ namespace ts { return localizedDiagnosticMessages && localizedDiagnosticMessages[message.key] || message.message; } - export function createFileDiagnostic(file: SourceFile, start: number, length: number, message: DiagnosticMessage, ...args: string[]): Diagnostic; + export function createFileDiagnostic(file: SourceFile, start: number, length: number, message: DiagnosticMessage, ...args: (string | number)[]): Diagnostic; export function createFileDiagnostic(file: SourceFile, start: number, length: number, message: DiagnosticMessage): Diagnostic { const end = start + length; @@ -992,7 +992,7 @@ namespace ts { return text; } - export function createCompilerDiagnostic(message: DiagnosticMessage, ...args: string[]): Diagnostic; + export function createCompilerDiagnostic(message: DiagnosticMessage, ...args: (string | number)[]): Diagnostic; export function createCompilerDiagnostic(message: DiagnosticMessage): Diagnostic { let text = getLocaleSpecificMessage(message); diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index dfdfae9c259..efdac40c287 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -503,7 +503,7 @@ namespace ts { return getFullWidth(name) === 0 ? "(Missing)" : getTextOfNode(name); } - export function createDiagnosticForNode(node: Node, message: DiagnosticMessage, arg0?: string, arg1?: string, arg2?: string): Diagnostic { + export function createDiagnosticForNode(node: Node, message: DiagnosticMessage, arg0?: string | number, arg1?: string | number, arg2?: string | number): Diagnostic { const sourceFile = getSourceFileOfNode(node); const span = getErrorSpanForNode(sourceFile, node); return createFileDiagnostic(sourceFile, span.start, span.length, message, arg0, arg1, arg2); From 7685e6af157d28dd6647def5de33c653efd37a17 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Mon, 10 Oct 2016 13:06:58 -0700 Subject: [PATCH 7/9] Forbid unused locals/parameters in compiler --- src/compiler/checker.ts | 49 ++++++++++------------ src/compiler/comments.ts | 10 ++--- src/compiler/core.ts | 17 ++++---- src/compiler/declarationEmitter.ts | 14 +++---- src/compiler/emitter.ts | 26 ++++++------ src/compiler/moduleNameResolver.ts | 2 +- src/compiler/parser.ts | 14 +++---- src/compiler/performance.ts | 2 +- src/compiler/program.ts | 49 +++++++++++----------- src/compiler/scanner.ts | 2 +- src/compiler/sys.ts | 12 ++---- src/compiler/transformer.ts | 2 +- src/compiler/transformers/destructuring.ts | 12 ++---- src/compiler/transformers/es2015.ts | 27 ++++++------ src/compiler/transformers/generators.ts | 6 +-- src/compiler/transformers/module/es2015.ts | 8 +--- src/compiler/transformers/module/module.ts | 1 - src/compiler/transformers/module/system.ts | 4 +- src/compiler/transformers/ts.ts | 25 +++++------ src/compiler/tsc.ts | 8 ++-- src/compiler/tsconfig.json | 4 +- src/compiler/utilities.ts | 4 +- src/compiler/visitor.ts | 6 +-- src/services/shims.ts | 4 +- 24 files changed, 142 insertions(+), 166 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3708ea3582c..f24f72491b0 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1054,7 +1054,7 @@ namespace ts { if (node.moduleReference.kind === SyntaxKind.ExternalModuleReference) { return resolveExternalModuleSymbol(resolveExternalModuleName(node, getExternalModuleImportEqualsDeclarationExpression(node))); } - return getSymbolOfPartOfRightHandSideOfImportEquals(node.moduleReference, node); + return getSymbolOfPartOfRightHandSideOfImportEquals(node.moduleReference); } function getTargetOfImportClause(node: ImportClause): Symbol { @@ -1267,7 +1267,7 @@ namespace ts { } // This function is only for imports with entity names - function getSymbolOfPartOfRightHandSideOfImportEquals(entityName: EntityName, importDeclaration: ImportEqualsDeclaration, dontResolveAlias?: boolean): Symbol { + function getSymbolOfPartOfRightHandSideOfImportEquals(entityName: EntityName, dontResolveAlias?: boolean): Symbol { // There are three things we might try to look for. In the following examples, // the search term is enclosed in |...|: // @@ -2583,7 +2583,7 @@ namespace ts { } } - function buildDisplayForTypeArgumentsAndDelimiters(typeParameters: TypeParameter[], mapper: TypeMapper, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) { + function buildDisplayForTypeArgumentsAndDelimiters(typeParameters: TypeParameter[], mapper: TypeMapper, writer: SymbolWriter, enclosingDeclaration?: Node) { if (typeParameters && typeParameters.length) { writePunctuation(writer, SyntaxKind.LessThanToken); let flags = TypeFormatFlags.InFirstTypeArgument; @@ -4795,7 +4795,7 @@ namespace ts { const typeParameters = classType ? classType.localTypeParameters : declaration.typeParameters ? getTypeParametersFromDeclaration(declaration.typeParameters) : getTypeParametersFromJSDocTemplate(declaration); - const returnType = getSignatureReturnTypeFromDeclaration(declaration, minArgumentCount, isJSConstructSignature, classType); + const returnType = getSignatureReturnTypeFromDeclaration(declaration, isJSConstructSignature, classType); const typePredicate = declaration.type && declaration.type.kind === SyntaxKind.TypePredicate ? createTypePredicateFromTypePredicateNode(declaration.type as TypePredicateNode) : undefined; @@ -4805,7 +4805,7 @@ namespace ts { return links.resolvedSignature; } - function getSignatureReturnTypeFromDeclaration(declaration: SignatureDeclaration, minArgumentCount: number, isJSConstructSignature: boolean, classType: Type) { + function getSignatureReturnTypeFromDeclaration(declaration: SignatureDeclaration, isJSConstructSignature: boolean, classType: Type) { if (isJSConstructSignature) { return getTypeFromTypeNode(declaration.parameters[0].type); } @@ -5170,10 +5170,7 @@ namespace ts { return undefined; } - function resolveTypeReferenceName( - node: TypeReferenceNode | ExpressionWithTypeArguments | JSDocTypeReference, - typeReferenceName: EntityNameExpression | EntityName) { - + function resolveTypeReferenceName(typeReferenceName: EntityNameExpression | EntityName) { if (!typeReferenceName) { return unknownSymbol; } @@ -5211,7 +5208,7 @@ namespace ts { let type: Type; if (node.kind === SyntaxKind.JSDocTypeReference) { const typeReferenceName = getTypeReferenceName(node); - symbol = resolveTypeReferenceName(node, typeReferenceName); + symbol = resolveTypeReferenceName(typeReferenceName); type = getTypeReferenceType(node, symbol); } else { @@ -6673,8 +6670,8 @@ namespace ts { } if (source.flags & TypeFlags.Union && target.flags & TypeFlags.Union || source.flags & TypeFlags.Intersection && target.flags & TypeFlags.Intersection) { - if (result = eachTypeRelatedToSomeType(source, target, /*reportErrors*/ false)) { - if (result &= eachTypeRelatedToSomeType(target, source, /*reportErrors*/ false)) { + if (result = eachTypeRelatedToSomeType(source, target)) { + if (result &= eachTypeRelatedToSomeType(target, source)) { return result; } } @@ -6735,7 +6732,7 @@ namespace ts { return false; } - function eachTypeRelatedToSomeType(source: UnionOrIntersectionType, target: UnionOrIntersectionType, reportErrors: boolean): Ternary { + function eachTypeRelatedToSomeType(source: UnionOrIntersectionType, target: UnionOrIntersectionType): Ternary { let result = Ternary.True; const sourceTypes = source.types; for (const sourceType of sourceTypes) { @@ -11772,7 +11769,7 @@ namespace ts { // If the effective argument is 'undefined', then it is an argument that is present but is synthetic. if (arg === undefined || arg.kind !== SyntaxKind.OmittedExpression) { const paramType = getTypeAtPosition(signature, i); - let argType = getEffectiveArgumentType(node, i, arg); + let argType = getEffectiveArgumentType(node, i); // If the effective argument type is 'undefined', there is no synthetic type // for the argument. In that case, we should check the argument. @@ -11858,7 +11855,7 @@ namespace ts { if (arg === undefined || arg.kind !== SyntaxKind.OmittedExpression) { // Check spread elements against rest type (from arity check we know spread argument corresponds to a rest parameter) const paramType = getTypeAtPosition(signature, i); - let argType = getEffectiveArgumentType(node, i, arg); + let argType = getEffectiveArgumentType(node, i); // If the effective argument type is 'undefined', there is no synthetic type // for the argument. In that case, we should check the argument. @@ -12151,7 +12148,7 @@ namespace ts { /** * Gets the effective argument type for an argument in a call expression. */ - function getEffectiveArgumentType(node: CallLikeExpression, argIndex: number, arg: Expression): Type { + function getEffectiveArgumentType(node: CallLikeExpression, argIndex: number): Type { // Decorators provide special arguments, a tagged template expression provides // a special first argument, and string literals get string literal types // unless we're reporting errors @@ -13556,15 +13553,15 @@ namespace ts { return booleanType; } - function checkObjectLiteralAssignment(node: ObjectLiteralExpression, sourceType: Type, contextualMapper?: TypeMapper): Type { + function checkObjectLiteralAssignment(node: ObjectLiteralExpression, sourceType: Type): Type { const properties = node.properties; for (const p of properties) { - checkObjectLiteralDestructuringPropertyAssignment(sourceType, p, contextualMapper); + checkObjectLiteralDestructuringPropertyAssignment(sourceType, p); } return sourceType; } - function checkObjectLiteralDestructuringPropertyAssignment(objectLiteralType: Type, property: ObjectLiteralElementLike, contextualMapper?: TypeMapper) { + function checkObjectLiteralDestructuringPropertyAssignment(objectLiteralType: Type, property: ObjectLiteralElementLike) { if (property.kind === SyntaxKind.PropertyAssignment || property.kind === SyntaxKind.ShorthandPropertyAssignment) { const name = (property).name; if (name.kind === SyntaxKind.ComputedPropertyName) { @@ -13679,7 +13676,7 @@ namespace ts { target = (target).left; } if (target.kind === SyntaxKind.ObjectLiteralExpression) { - return checkObjectLiteralAssignment(target, sourceType, contextualMapper); + return checkObjectLiteralAssignment(target, sourceType); } if (target.kind === SyntaxKind.ArrayLiteralExpression) { return checkArrayLiteralAssignment(target, sourceType, contextualMapper); @@ -18588,7 +18585,7 @@ namespace ts { // Since we already checked for ExportAssignment, this really could only be an Import const importEqualsDeclaration = getAncestor(entityName, SyntaxKind.ImportEqualsDeclaration); Debug.assert(importEqualsDeclaration !== undefined); - return getSymbolOfPartOfRightHandSideOfImportEquals(entityName, importEqualsDeclaration, /*dontResolveAlias*/ true); + return getSymbolOfPartOfRightHandSideOfImportEquals(entityName, /*dontResolveAlias*/ true); } if (isRightSideOfQualifiedNameOrPropertyAccess(entityName)) { @@ -19971,7 +19968,7 @@ namespace ts { } } - function checkGrammarTypeParameterList(node: FunctionLikeDeclaration, typeParameters: NodeArray, file: SourceFile): boolean { + function checkGrammarTypeParameterList(typeParameters: NodeArray, file: SourceFile): boolean { if (checkGrammarForDisallowedTrailingComma(typeParameters)) { return true; } @@ -20022,7 +20019,7 @@ namespace ts { function checkGrammarFunctionLikeDeclaration(node: FunctionLikeDeclaration): boolean { // Prevent cascading error by short-circuit const file = getSourceFileOfNode(node); - return checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarTypeParameterList(node, node.typeParameters, file) || + return checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarTypeParameterList(node.typeParameters, file) || checkGrammarParameterList(node.parameters) || checkGrammarArrowFunction(node, file); } @@ -20208,7 +20205,7 @@ namespace ts { } } - function checkGrammarForInvalidQuestionMark(node: Declaration, questionToken: Node, message: DiagnosticMessage): boolean { + function checkGrammarForInvalidQuestionMark(questionToken: Node, message: DiagnosticMessage): boolean { if (questionToken) { return grammarErrorOnNode(questionToken, message); } @@ -20254,7 +20251,7 @@ namespace ts { let currentKind: number; if (prop.kind === SyntaxKind.PropertyAssignment || prop.kind === SyntaxKind.ShorthandPropertyAssignment) { // Grammar checking for computedPropertyName and shorthandPropertyAssignment - checkGrammarForInvalidQuestionMark(prop, (prop).questionToken, Diagnostics.An_object_member_cannot_be_declared_optional); + checkGrammarForInvalidQuestionMark((prop).questionToken, Diagnostics.An_object_member_cannot_be_declared_optional); if (name.kind === SyntaxKind.NumericLiteral) { checkGrammarNumericLiteral(name); } @@ -20438,7 +20435,7 @@ namespace ts { } if (node.parent.kind === SyntaxKind.ObjectLiteralExpression) { - if (checkGrammarForInvalidQuestionMark(node, node.questionToken, Diagnostics.An_object_member_cannot_be_declared_optional)) { + if (checkGrammarForInvalidQuestionMark(node.questionToken, Diagnostics.An_object_member_cannot_be_declared_optional)) { return true; } else if (node.body === undefined) { diff --git a/src/compiler/comments.ts b/src/compiler/comments.ts index 116a8e849a3..c2cf49eeb6a 100644 --- a/src/compiler/comments.ts +++ b/src/compiler/comments.ts @@ -182,13 +182,13 @@ namespace ts { } } - function emitTripleSlashLeadingComment(commentPos: number, commentEnd: number, kind: SyntaxKind, hasTrailingNewLine: boolean, rangePos: number) { + function emitTripleSlashLeadingComment(commentPos: number, commentEnd: number, _kind: SyntaxKind, hasTrailingNewLine: boolean, rangePos: number) { if (isTripleSlashComment(commentPos, commentEnd)) { - emitLeadingComment(commentPos, commentEnd, kind, hasTrailingNewLine, rangePos); + emitLeadingComment(commentPos, commentEnd, _kind, hasTrailingNewLine, rangePos); } } - function emitLeadingComment(commentPos: number, commentEnd: number, kind: SyntaxKind, hasTrailingNewLine: boolean, rangePos: number) { + function emitLeadingComment(commentPos: number, commentEnd: number, _kind: SyntaxKind, hasTrailingNewLine: boolean, rangePos: number) { if (!hasWrittenComment) { emitNewLineBeforeLeadingCommentOfPosition(currentLineMap, writer, rangePos, commentPos); hasWrittenComment = true; @@ -211,7 +211,7 @@ namespace ts { forEachTrailingCommentToEmit(pos, emitTrailingComment); } - function emitTrailingComment(commentPos: number, commentEnd: number, kind: SyntaxKind, hasTrailingNewLine: boolean) { + function emitTrailingComment(commentPos: number, commentEnd: number, _kind: SyntaxKind, hasTrailingNewLine: boolean) { // trailing comments are emitted at space/*trailing comment1 */space/*trailing comment2*/ if (!writer.isAtStartOfLine()) { writer.write(" "); @@ -242,7 +242,7 @@ namespace ts { } } - function emitTrailingCommentOfPosition(commentPos: number, commentEnd: number, kind: SyntaxKind, hasTrailingNewLine: boolean) { + function emitTrailingCommentOfPosition(commentPos: number, commentEnd: number, _kind: SyntaxKind, hasTrailingNewLine: boolean) { // trailing comments of a position are emitted at /*trailing comment1 */space/*trailing comment*/space emitPos(commentPos); diff --git a/src/compiler/core.ts b/src/compiler/core.ts index b41f382badf..05efc6db909 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -903,7 +903,7 @@ namespace ts { return t => compose(a(t)); } else { - return t => u => u; + return _t => u => u; } } @@ -943,7 +943,7 @@ namespace ts { function formatStringFromArgs(text: string, args: { [index: number]: string; }, baseIndex?: number): string { baseIndex = baseIndex || 0; - return text.replace(/{(\d+)}/g, (match, index?) => args[+index + baseIndex]); + return text.replace(/{(\d+)}/g, (_match, index?) => args[+index + baseIndex]); } export let localizedDiagnosticMessages: Map = undefined; @@ -982,7 +982,7 @@ namespace ts { } /* internal */ - export function formatMessage(dummy: any, message: DiagnosticMessage): string { + export function formatMessage(_dummy: any, message: DiagnosticMessage): string { let text = getLocaleSpecificMessage(message); if (arguments.length > 2) { @@ -1623,7 +1623,7 @@ namespace ts { basePaths: string[]; } - export function getFileMatcherPatterns(path: string, extensions: string[], excludes: string[], includes: string[], useCaseSensitiveFileNames: boolean, currentDirectory: string): FileMatcherPatterns { + export function getFileMatcherPatterns(path: string, excludes: string[], includes: string[], useCaseSensitiveFileNames: boolean, currentDirectory: string): FileMatcherPatterns { path = normalizePath(path); currentDirectory = normalizePath(currentDirectory); const absolutePath = combinePaths(currentDirectory, path); @@ -1640,7 +1640,7 @@ namespace ts { path = normalizePath(path); currentDirectory = normalizePath(currentDirectory); - const patterns = getFileMatcherPatterns(path, extensions, excludes, includes, useCaseSensitiveFileNames, currentDirectory); + const patterns = getFileMatcherPatterns(path, excludes, includes, useCaseSensitiveFileNames, currentDirectory); const regexFlag = useCaseSensitiveFileNames ? "" : "i"; const includeFileRegex = patterns.includeFilePattern && new RegExp(patterns.includeFilePattern, regexFlag); @@ -1874,11 +1874,11 @@ namespace ts { this.declarations = undefined; } - function Type(this: Type, checker: TypeChecker, flags: TypeFlags) { + function Type(this: Type, _checker: TypeChecker, flags: TypeFlags) { this.flags = flags; } - function Signature(checker: TypeChecker) { + function Signature() { } function Node(this: Node, kind: SyntaxKind, pos: number, end: number) { @@ -1911,9 +1911,6 @@ namespace ts { } export namespace Debug { - declare var process: any; - declare var require: any; - export let currentAssertionLevel = AssertionLevel.None; export function shouldAssert(level: AssertionLevel): boolean { diff --git a/src/compiler/declarationEmitter.ts b/src/compiler/declarationEmitter.ts index 8bcce86c31f..27751a1dfc2 100644 --- a/src/compiler/declarationEmitter.ts +++ b/src/compiler/declarationEmitter.ts @@ -63,7 +63,7 @@ namespace ts { let isCurrentFileExternalModule: boolean; let reportedDeclarationError = false; let errorNameNode: DeclarationName; - const emitJsDocComments = compilerOptions.removeComments ? function (declaration: Node) { } : writeJsDocComments; + const emitJsDocComments = compilerOptions.removeComments ? () => {} : writeJsDocComments; const emit = compilerOptions.stripInternal ? stripInternal : emitNode; let noDeclare: boolean; @@ -580,7 +580,7 @@ namespace ts { writeAsynchronousModuleElements(nodes); } - function getDefaultExportAccessibilityDiagnostic(diagnostic: SymbolAccessibilityResult): SymbolAccessibilityDiagnostic { + function getDefaultExportAccessibilityDiagnostic(): SymbolAccessibilityDiagnostic { return { diagnosticMessage: Diagnostics.Default_export_of_the_module_has_or_is_using_private_name_0, errorNode: node @@ -710,7 +710,7 @@ namespace ts { } writer.writeLine(); - function getImportEntityNameVisibilityError(symbolAccessibilityResult: SymbolAccessibilityResult): SymbolAccessibilityDiagnostic { + function getImportEntityNameVisibilityError(): SymbolAccessibilityDiagnostic { return { diagnosticMessage: Diagnostics.Import_declaration_0_is_using_private_name_1, errorNode: node, @@ -888,7 +888,7 @@ namespace ts { writeLine(); enclosingDeclaration = prevEnclosingDeclaration; - function getTypeAliasDeclarationVisibilityError(symbolAccessibilityResult: SymbolAccessibilityResult): SymbolAccessibilityDiagnostic { + function getTypeAliasDeclarationVisibilityError(): SymbolAccessibilityDiagnostic { return { diagnosticMessage: Diagnostics.Exported_type_alias_0_has_or_is_using_private_name_1, errorNode: node.type, @@ -955,7 +955,7 @@ namespace ts { } } - function getTypeParameterConstraintVisibilityError(symbolAccessibilityResult: SymbolAccessibilityResult): SymbolAccessibilityDiagnostic { + function getTypeParameterConstraintVisibilityError(): SymbolAccessibilityDiagnostic { // Type parameter constraints are named by user so we should always be able to name it let diagnosticMessage: DiagnosticMessage; switch (node.parent.kind) { @@ -1029,7 +1029,7 @@ namespace ts { resolver.writeBaseConstructorTypeOfClass(enclosingDeclaration, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction | TypeFormatFlags.UseTypeAliasValue, writer); } - function getHeritageClauseVisibilityError(symbolAccessibilityResult: SymbolAccessibilityResult): SymbolAccessibilityDiagnostic { + function getHeritageClauseVisibilityError(): SymbolAccessibilityDiagnostic { let diagnosticMessage: DiagnosticMessage; // Heritage clause is written by user so it can always be named if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) { @@ -1743,7 +1743,7 @@ namespace ts { } return addedBundledEmitReference; - function getDeclFileName(emitFileNames: EmitFileNames, sourceFiles: SourceFile[], isBundledEmit: boolean) { + function getDeclFileName(emitFileNames: EmitFileNames, _sourceFiles: SourceFile[], isBundledEmit: boolean) { // Dont add reference path to this file if it is a bundled emit and caller asked not emit bundled file path if (isBundledEmit && !addBundledFileReference) { return; diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 16f7e5a1c8a..bf540f6a0cd 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -14,7 +14,7 @@ namespace ts { } const id = (s: SourceFile) => s; - const nullTransformers: Transformer[] = [ctx => id]; + const nullTransformers: Transformer[] = [_ctx => id]; // targetSourceFile is when users only want one file in entire project to be emitted. This is used in compileOnSave feature export function emitFiles(resolver: EmitResolver, host: EmitHost, targetSourceFile: SourceFile, emitOnlyDtsFiles?: boolean): EmitResult { @@ -593,7 +593,7 @@ const _super = (function (geti, seti) { case SyntaxKind.ExpressionWithTypeArguments: return emitExpressionWithTypeArguments(node); case SyntaxKind.ThisType: - return emitThisType(node); + return emitThisType(); case SyntaxKind.LiteralType: return emitLiteralType(node); @@ -609,7 +609,7 @@ const _super = (function (geti, seti) { case SyntaxKind.TemplateSpan: return emitTemplateSpan(node); case SyntaxKind.SemicolonClassElement: - return emitSemicolonClassElement(node); + return emitSemicolonClassElement(); // Statements case SyntaxKind.Block: @@ -617,7 +617,7 @@ const _super = (function (geti, seti) { case SyntaxKind.VariableStatement: return emitVariableStatement(node); case SyntaxKind.EmptyStatement: - return emitEmptyStatement(node); + return emitEmptyStatement(); case SyntaxKind.ExpressionStatement: return emitExpressionStatement(node); case SyntaxKind.IfStatement: @@ -1014,7 +1014,7 @@ const _super = (function (geti, seti) { write(";"); } - function emitSemicolonClassElement(node: SemicolonClassElement) { + function emitSemicolonClassElement() { write(";"); } @@ -1084,7 +1084,7 @@ const _super = (function (geti, seti) { write(")"); } - function emitThisType(node: ThisTypeNode) { + function emitThisType() { write("this"); } @@ -1397,7 +1397,7 @@ const _super = (function (geti, seti) { // Statements // - function emitBlock(node: Block, format?: ListFormat) { + function emitBlock(node: Block) { if (isSingleLineEmptyBlock(node)) { writeToken(SyntaxKind.OpenBraceToken, node.pos, /*contextNode*/ node); write(" "); @@ -1425,7 +1425,7 @@ const _super = (function (geti, seti) { write(";"); } - function emitEmptyStatement(node: EmptyStatement) { + function emitEmptyStatement() { write(";"); } @@ -1623,13 +1623,13 @@ const _super = (function (geti, seti) { if (getEmitFlags(node) & EmitFlags.ReuseTempVariableScope) { emitSignatureHead(node); - emitBlockFunctionBody(node, body); + emitBlockFunctionBody(body); } else { const savedTempFlags = tempFlags; tempFlags = 0; emitSignatureHead(node); - emitBlockFunctionBody(node, body); + emitBlockFunctionBody(body); tempFlags = savedTempFlags; } @@ -1656,7 +1656,7 @@ const _super = (function (geti, seti) { emitWithPrefix(": ", node.type); } - function shouldEmitBlockFunctionBodyOnSingleLine(parentNode: Node, body: Block) { + function shouldEmitBlockFunctionBodyOnSingleLine(body: Block) { // We must emit a function body as a single-line body in the following case: // * The body has NodeEmitFlags.SingleLine specified. @@ -1694,12 +1694,12 @@ const _super = (function (geti, seti) { return true; } - function emitBlockFunctionBody(parentNode: Node, body: Block) { + function emitBlockFunctionBody(body: Block) { write(" {"); increaseIndent(); emitBodyWithDetachedComments(body, body.statements, - shouldEmitBlockFunctionBodyOnSingleLine(parentNode, body) + shouldEmitBlockFunctionBodyOnSingleLine(body) ? emitBlockFunctionBodyOnSingleLine : emitBlockFunctionBodyWorker); diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index 4ebdc59e6dd..ba1f8497559 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -5,7 +5,7 @@ namespace ts { /* @internal */ export function trace(host: ModuleResolutionHost, message: DiagnosticMessage, ...args: any[]): void; - export function trace(host: ModuleResolutionHost, message: DiagnosticMessage): void { + export function trace(host: ModuleResolutionHost, _message: DiagnosticMessage): void { host.trace(formatMessage.apply(undefined, arguments)); } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 62ae61e4cb4..5481dc657b8 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -575,7 +575,7 @@ namespace ts { export function parseSourceFile(fileName: string, _sourceText: string, languageVersion: ScriptTarget, _syntaxCursor: IncrementalParser.SyntaxCursor, setParentNodes?: boolean, scriptKind?: ScriptKind): SourceFile { scriptKind = ensureScriptKind(fileName, scriptKind); - initializeState(fileName, _sourceText, languageVersion, _syntaxCursor, scriptKind); + initializeState(_sourceText, languageVersion, _syntaxCursor, scriptKind); const result = parseSourceFileWorker(fileName, languageVersion, setParentNodes, scriptKind); @@ -589,7 +589,7 @@ namespace ts { return scriptKind === ScriptKind.TSX || scriptKind === ScriptKind.JSX || scriptKind === ScriptKind.JS ? LanguageVariant.JSX : LanguageVariant.Standard; } - function initializeState(fileName: string, _sourceText: string, languageVersion: ScriptTarget, _syntaxCursor: IncrementalParser.SyntaxCursor, scriptKind: ScriptKind) { + function initializeState(_sourceText: string, languageVersion: ScriptTarget, _syntaxCursor: IncrementalParser.SyntaxCursor, scriptKind: ScriptKind) { NodeConstructor = objectAllocator.getNodeConstructor(); TokenConstructor = objectAllocator.getTokenConstructor(); IdentifierConstructor = objectAllocator.getIdentifierConstructor(); @@ -5259,7 +5259,7 @@ namespace ts { parseExpected(SyntaxKind.ClassKeyword); node.name = parseNameOfClassDeclarationOrExpression(); node.typeParameters = parseTypeParameters(); - node.heritageClauses = parseHeritageClauses(/*isClassHeritageClause*/ true); + node.heritageClauses = parseHeritageClauses(); if (parseExpected(SyntaxKind.OpenBraceToken)) { // ClassTail[Yield,Await] : (Modified) See 14.5 @@ -5289,7 +5289,7 @@ namespace ts { return token() === SyntaxKind.ImplementsKeyword && lookAhead(nextTokenIsIdentifierOrKeyword); } - function parseHeritageClauses(isClassHeritageClause: boolean): NodeArray { + function parseHeritageClauses(): NodeArray { // ClassTail[Yield,Await] : (Modified) See 14.5 // ClassHeritage[?Yield,?Await]opt { ClassBody[?Yield,?Await]opt } @@ -5337,7 +5337,7 @@ namespace ts { parseExpected(SyntaxKind.InterfaceKeyword); node.name = parseIdentifier(); node.typeParameters = parseTypeParameters(); - node.heritageClauses = parseHeritageClauses(/*isClassHeritageClause*/ false); + node.heritageClauses = parseHeritageClauses(); node.members = parseObjectTypeMembers(); return addJSDocComment(finishNode(node)); } @@ -5817,7 +5817,7 @@ namespace ts { } export function parseJSDocTypeExpressionForTests(content: string, start: number, length: number) { - initializeState("file.js", content, ScriptTarget.Latest, /*_syntaxCursor:*/ undefined, ScriptKind.JS); + initializeState(content, ScriptTarget.Latest, /*_syntaxCursor:*/ undefined, ScriptKind.JS); sourceFile = createSourceFile("file.js", ScriptTarget.Latest, ScriptKind.JS); scanner.setText(content, start, length); currentToken = scanner.scan(); @@ -6134,7 +6134,7 @@ namespace ts { } export function parseIsolatedJSDocComment(content: string, start: number, length: number) { - initializeState("file.js", content, ScriptTarget.Latest, /*_syntaxCursor:*/ undefined, ScriptKind.JS); + initializeState(content, ScriptTarget.Latest, /*_syntaxCursor:*/ undefined, ScriptKind.JS); sourceFile = { languageVariant: LanguageVariant.Standard, text: content }; const jsDoc = parseJSDocCommentWorker(start, length); const diagnostics = parseDiagnostics; diff --git a/src/compiler/performance.ts b/src/compiler/performance.ts index e8f064e81cd..a48eb117e28 100644 --- a/src/compiler/performance.ts +++ b/src/compiler/performance.ts @@ -12,7 +12,7 @@ namespace ts.performance { const profilerEvent = typeof onProfilerEvent === "function" && onProfilerEvent.profiler === true ? onProfilerEvent - : (markName: string) => { }; + : (_markName: string) => { }; let enabled = false; let profilerStart = 0; diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 06e9f6f30f1..b34791b7198 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -724,7 +724,7 @@ namespace ts { } } - function getSyntacticDiagnosticsForFile(sourceFile: SourceFile, cancellationToken: CancellationToken): Diagnostic[] { + function getSyntacticDiagnosticsForFile(sourceFile: SourceFile): Diagnostic[] { return sourceFile.parseDiagnostics; } @@ -761,7 +761,7 @@ namespace ts { // Instead, we just report errors for using TypeScript-only constructs from within a // JavaScript file. const checkDiagnostics = isSourceFileJavaScript(sourceFile) ? - getJavaScriptSemanticDiagnosticsForFile(sourceFile, cancellationToken) : + getJavaScriptSemanticDiagnosticsForFile(sourceFile) : typeChecker.getDiagnostics(sourceFile, cancellationToken); const fileProcessingDiagnosticsInFile = fileProcessingDiagnostics.getDiagnostics(sourceFile.fileName); const programDiagnosticsInFile = programDiagnostics.getDiagnostics(sourceFile.fileName); @@ -770,7 +770,7 @@ namespace ts { }); } - function getJavaScriptSemanticDiagnosticsForFile(sourceFile: SourceFile, cancellationToken: CancellationToken): Diagnostic[] { + function getJavaScriptSemanticDiagnosticsForFile(sourceFile: SourceFile): Diagnostic[] { return runWithCancellationToken(() => { const diagnostics: Diagnostic[] = []; walk(sourceFile); @@ -977,7 +977,7 @@ namespace ts { } function processRootFile(fileName: string, isDefaultLib: boolean) { - processSourceFile(normalizePath(fileName), isDefaultLib, /*isReference*/ true); + processSourceFile(normalizePath(fileName), isDefaultLib); } function fileReferenceIsEqualTo(a: FileReference, b: FileReference): boolean { @@ -1088,7 +1088,7 @@ namespace ts { /** * 'isReference' indicates whether the file was brought in via a reference directive (rather than an import declaration) */ - function processSourceFile(fileName: string, isDefaultLib: boolean, isReference: boolean, refFile?: SourceFile, refPos?: number, refEnd?: number) { + function processSourceFile(fileName: string, isDefaultLib: boolean, refFile?: SourceFile, refPos?: number, refEnd?: number) { let diagnosticArgument: string[]; let diagnostic: DiagnosticMessage; if (hasExtension(fileName)) { @@ -1096,7 +1096,7 @@ namespace ts { diagnostic = Diagnostics.File_0_has_unsupported_extension_The_only_supported_extensions_are_1; diagnosticArgument = [fileName, "'" + supportedExtensions.join("', '") + "'"]; } - else if (!findSourceFile(fileName, toPath(fileName, currentDirectory, getCanonicalFileName), isDefaultLib, isReference, refFile, refPos, refEnd)) { + else if (!findSourceFile(fileName, toPath(fileName, currentDirectory, getCanonicalFileName), isDefaultLib, refFile, refPos, refEnd)) { diagnostic = Diagnostics.File_0_not_found; diagnosticArgument = [fileName]; } @@ -1106,13 +1106,13 @@ namespace ts { } } else { - const nonTsFile: SourceFile = options.allowNonTsExtensions && findSourceFile(fileName, toPath(fileName, currentDirectory, getCanonicalFileName), isDefaultLib, isReference, refFile, refPos, refEnd); + const nonTsFile: SourceFile = options.allowNonTsExtensions && findSourceFile(fileName, toPath(fileName, currentDirectory, getCanonicalFileName), isDefaultLib, refFile, refPos, refEnd); if (!nonTsFile) { if (options.allowNonTsExtensions) { diagnostic = Diagnostics.File_0_not_found; diagnosticArgument = [fileName]; } - else if (!forEach(supportedExtensions, extension => findSourceFile(fileName + extension, toPath(fileName + extension, currentDirectory, getCanonicalFileName), isDefaultLib, isReference, refFile, refPos, refEnd))) { + else if (!forEach(supportedExtensions, extension => findSourceFile(fileName + extension, toPath(fileName + extension, currentDirectory, getCanonicalFileName), isDefaultLib, refFile, refPos, refEnd))) { diagnostic = Diagnostics.File_0_not_found; fileName += ".ts"; diagnosticArgument = [fileName]; @@ -1141,7 +1141,7 @@ namespace ts { } // Get source file from normalized fileName - function findSourceFile(fileName: string, path: Path, isDefaultLib: boolean, isReference: boolean, refFile?: SourceFile, refPos?: number, refEnd?: number): SourceFile { + function findSourceFile(fileName: string, path: Path, isDefaultLib: boolean, refFile?: SourceFile, refPos?: number, refEnd?: number): SourceFile { if (filesByName.contains(path)) { const file = filesByName.get(path); // try to check if we've already seen this file but with a different casing in path @@ -1155,18 +1155,18 @@ namespace ts { if (file && sourceFilesFoundSearchingNodeModules[file.path] && currentNodeModulesDepth == 0) { sourceFilesFoundSearchingNodeModules[file.path] = false; if (!options.noResolve) { - processReferencedFiles(file, getDirectoryPath(fileName), isDefaultLib); + processReferencedFiles(file, isDefaultLib); processTypeReferenceDirectives(file); } modulesWithElidedImports[file.path] = false; - processImportedModules(file, getDirectoryPath(fileName)); + processImportedModules(file); } // See if we need to reprocess the imports due to prior skipped imports else if (file && modulesWithElidedImports[file.path]) { if (currentNodeModulesDepth < maxNodeModulesJsDepth) { modulesWithElidedImports[file.path] = false; - processImportedModules(file, getDirectoryPath(fileName)); + processImportedModules(file); } } @@ -1202,14 +1202,13 @@ namespace ts { skipDefaultLib = skipDefaultLib || file.hasNoDefaultLib; - const basePath = getDirectoryPath(fileName); if (!options.noResolve) { - processReferencedFiles(file, basePath, isDefaultLib); + processReferencedFiles(file, isDefaultLib); processTypeReferenceDirectives(file); } // always process imported modules to record module name resolutions - processImportedModules(file, basePath); + processImportedModules(file); if (isDefaultLib) { files.unshift(file); @@ -1222,10 +1221,10 @@ namespace ts { return file; } - function processReferencedFiles(file: SourceFile, basePath: string, isDefaultLib: boolean) { + function processReferencedFiles(file: SourceFile, isDefaultLib: boolean) { forEach(file.referencedFiles, ref => { const referencedFileName = resolveTripleslashReference(ref.fileName, file.fileName); - processSourceFile(referencedFileName, isDefaultLib, /*isReference*/ true, file, ref.pos, ref.end); + processSourceFile(referencedFileName, isDefaultLib, file, ref.pos, ref.end); }); } @@ -1256,7 +1255,7 @@ namespace ts { if (resolvedTypeReferenceDirective) { if (resolvedTypeReferenceDirective.primary) { // resolved from the primary path - processSourceFile(resolvedTypeReferenceDirective.resolvedFileName, /*isDefaultLib*/ false, /*isReference*/ true, refFile, refPos, refEnd); + processSourceFile(resolvedTypeReferenceDirective.resolvedFileName, /*isDefaultLib*/ false, refFile, refPos, refEnd); } else { // If we already resolved to this file, it must have been a secondary reference. Check file contents @@ -1276,7 +1275,7 @@ namespace ts { } else { // First resolution of this library - processSourceFile(resolvedTypeReferenceDirective.resolvedFileName, /*isDefaultLib*/ false, /*isReference*/ true, refFile, refPos, refEnd); + processSourceFile(resolvedTypeReferenceDirective.resolvedFileName, /*isDefaultLib*/ false, refFile, refPos, refEnd); } } } @@ -1302,7 +1301,7 @@ namespace ts { return host.getCanonicalFileName(fileName); } - function processImportedModules(file: SourceFile, basePath: string) { + function processImportedModules(file: SourceFile) { collectExternalModuleReferences(file); if (file.imports.length || file.moduleAugmentations.length) { file.resolvedModules = createMap(); @@ -1333,7 +1332,7 @@ namespace ts { else if (shouldAddFile) { findSourceFile(resolution.resolvedFileName, toPath(resolution.resolvedFileName, currentDirectory, getCanonicalFileName), - /*isDefaultLib*/ false, /*isReference*/ false, + /*isDefaultLib*/ false, file, skipTrivia(file.text, file.imports[i].pos), file.imports[i].end); @@ -1541,7 +1540,7 @@ namespace ts { if (!options.noEmit && !options.suppressOutputPathCheck) { const emitHost = getEmitHost(); const emitFilesSeen = createFileMap(!host.useCaseSensitiveFileNames() ? key => key.toLocaleLowerCase() : undefined); - forEachExpectedEmitFile(emitHost, (emitFileNames, sourceFiles, isBundledEmit) => { + forEachExpectedEmitFile(emitHost, (emitFileNames) => { verifyEmitFilePath(emitFileNames.jsFilePath, emitFilesSeen); verifyEmitFilePath(emitFileNames.declarationFilePath, emitFilesSeen); }); @@ -1553,13 +1552,13 @@ namespace ts { const emitFilePath = toPath(emitFileName, currentDirectory, getCanonicalFileName); // Report error if the output overwrites input file if (filesByName.contains(emitFilePath)) { - createEmitBlockingDiagnostics(emitFileName, emitFilePath, Diagnostics.Cannot_write_file_0_because_it_would_overwrite_input_file); + createEmitBlockingDiagnostics(emitFileName, Diagnostics.Cannot_write_file_0_because_it_would_overwrite_input_file); } // Report error if multiple files write into same file if (emitFilesSeen.contains(emitFilePath)) { // Already seen the same emit file - report error - createEmitBlockingDiagnostics(emitFileName, emitFilePath, Diagnostics.Cannot_write_file_0_because_it_would_be_overwritten_by_multiple_input_files); + createEmitBlockingDiagnostics(emitFileName, Diagnostics.Cannot_write_file_0_because_it_would_be_overwritten_by_multiple_input_files); } else { emitFilesSeen.set(emitFilePath, true); @@ -1568,7 +1567,7 @@ namespace ts { } } - function createEmitBlockingDiagnostics(emitFileName: string, emitFilePath: Path, message: DiagnosticMessage) { + function createEmitBlockingDiagnostics(emitFileName: string, message: DiagnosticMessage) { hasEmitBlockingDiagnostics.set(toPath(emitFileName, currentDirectory, getCanonicalFileName), true); programDiagnostics.add(createCompilerDiagnostic(message, emitFileName)); } diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index b79106766da..ab76c7ffa19 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -723,7 +723,7 @@ namespace ts { return iterateCommentRanges(/*reduce*/ true, text, pos, /*trailing*/ true, cb, state, initial); } - function appendCommentRange(pos: number, end: number, kind: SyntaxKind, hasTrailingNewLine: boolean, state: any, comments: CommentRange[]) { + function appendCommentRange(pos: number, end: number, kind: SyntaxKind, hasTrailingNewLine: boolean, _state: any, comments: CommentRange[]) { if (!comments) { comments = []; } diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index 1efa1e2b010..bb945824b4d 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -46,13 +46,9 @@ namespace ts { } declare var require: any; - declare var module: any; declare var process: any; declare var global: any; declare var __filename: string; - declare var Buffer: { - new (str: string, encoding?: string): any; - }; declare class Enumerator { public atEnd(): boolean; @@ -324,7 +320,7 @@ namespace ts { const platform: string = _os.platform(); const useCaseSensitiveFileNames = isFileSystemCaseSensitive(); - function readFile(fileName: string, encoding?: string): string { + function readFile(fileName: string, _encoding?: string): string { if (!fileExists(fileName)) { return undefined; } @@ -576,7 +572,7 @@ namespace ts { args: ChakraHost.args, useCaseSensitiveFileNames: !!ChakraHost.useCaseSensitiveFileNames, write: ChakraHost.echo, - readFile(path: string, encoding?: string) { + readFile(path: string, _encoding?: string) { // encoding is automatically handled by the implementation in ChakraHost return ChakraHost.readFile(path); }, @@ -595,9 +591,9 @@ namespace ts { getExecutingFilePath: () => ChakraHost.executingFile, getCurrentDirectory: () => ChakraHost.currentDirectory, getDirectories: ChakraHost.getDirectories, - getEnvironmentVariable: ChakraHost.getEnvironmentVariable || ((name: string) => ""), + getEnvironmentVariable: ChakraHost.getEnvironmentVariable || ((_name: string) => ""), readDirectory: (path: string, extensions?: string[], excludes?: string[], includes?: string[]) => { - const pattern = getFileMatcherPatterns(path, extensions, excludes, includes, !!ChakraHost.useCaseSensitiveFileNames, ChakraHost.currentDirectory); + const pattern = getFileMatcherPatterns(path, excludes, includes, !!ChakraHost.useCaseSensitiveFileNames, ChakraHost.currentDirectory); return ChakraHost.readDirectory(path, extensions, pattern.basePaths, pattern.excludePattern, pattern.includeFilePattern, pattern.includeDirectoryPattern); }, exit: ChakraHost.quit, diff --git a/src/compiler/transformer.ts b/src/compiler/transformer.ts index e1e83a6b850..b27c8f6e79f 100644 --- a/src/compiler/transformer.ts +++ b/src/compiler/transformer.ts @@ -165,7 +165,7 @@ namespace ts { hoistFunctionDeclaration, startLexicalEnvironment, endLexicalEnvironment, - onSubstituteNode: (emitContext, node) => node, + onSubstituteNode: (_emitContext, node) => node, enableSubstitution, isSubstitutionEnabled, onEmitNode: (node, emitContext, emitCallback) => emitCallback(node, emitContext), diff --git a/src/compiler/transformers/destructuring.ts b/src/compiler/transformers/destructuring.ts index c7219866df7..3eaa1b764a9 100644 --- a/src/compiler/transformers/destructuring.ts +++ b/src/compiler/transformers/destructuring.ts @@ -51,7 +51,7 @@ namespace ts { location = value; } - flattenDestructuring(context, node, value, location, emitAssignment, emitTempVariableAssignment, visitor); + flattenDestructuring(node, value, location, emitAssignment, emitTempVariableAssignment, visitor); if (needsValue) { expressions.push(value); @@ -87,13 +87,12 @@ namespace ts { * @param visitor An optional visitor to use to visit expressions. */ export function flattenParameterDestructuring( - context: TransformationContext, node: ParameterDeclaration, value: Expression, visitor?: (node: Node) => VisitResult) { const declarations: VariableDeclaration[] = []; - flattenDestructuring(context, node, value, node, emitAssignment, emitTempVariableAssignment, visitor); + flattenDestructuring(node, value, node, emitAssignment, emitTempVariableAssignment, visitor); return declarations; @@ -123,7 +122,6 @@ namespace ts { * @param visitor An optional visitor to use to visit expressions. */ export function flattenVariableDestructuring( - context: TransformationContext, node: VariableDeclaration, value?: Expression, visitor?: (node: Node) => VisitResult, @@ -131,7 +129,7 @@ namespace ts { const declarations: VariableDeclaration[] = []; let pendingAssignments: Expression[]; - flattenDestructuring(context, node, value, node, emitAssignment, emitTempVariableAssignment, visitor); + flattenDestructuring(node, value, node, emitAssignment, emitTempVariableAssignment, visitor); return declarations; @@ -180,7 +178,6 @@ namespace ts { * @param visitor An optional visitor to use to visit expressions. */ export function flattenVariableDestructuringToExpression( - context: TransformationContext, node: VariableDeclaration, recordTempVariable: (name: Identifier) => void, nameSubstitution?: (name: Identifier) => Expression, @@ -188,7 +185,7 @@ namespace ts { const pendingAssignments: Expression[] = []; - flattenDestructuring(context, node, /*value*/ undefined, node, emitAssignment, emitTempVariableAssignment, visitor); + flattenDestructuring(node, /*value*/ undefined, node, emitAssignment, emitTempVariableAssignment, visitor); const expression = inlineExpressions(pendingAssignments); aggregateTransformFlags(expression); @@ -219,7 +216,6 @@ namespace ts { } function flattenDestructuring( - context: TransformationContext, root: VariableDeclaration | ParameterDeclaration | BindingElement | BinaryExpression, value: Expression, location: TextRange, diff --git a/src/compiler/transformers/es2015.ts b/src/compiler/transformers/es2015.ts index bb2e8ac2aa5..9972f339c16 100644 --- a/src/compiler/transformers/es2015.ts +++ b/src/compiler/transformers/es2015.ts @@ -396,7 +396,7 @@ namespace ts { return visitYieldExpression(node); case SyntaxKind.SuperKeyword: - return visitSuperKeyword(node); + return visitSuperKeyword(); case SyntaxKind.YieldExpression: // `yield` will be handled by a generators transform. @@ -1118,7 +1118,7 @@ namespace ts { createVariableStatement( /*modifiers*/ undefined, createVariableDeclarationList( - flattenParameterDestructuring(context, parameter, temp, visitor) + flattenParameterDestructuring(parameter, temp, visitor) ) ), EmitFlags.CustomPrologue @@ -1690,7 +1690,7 @@ namespace ts { if (decl.initializer) { let assignment: Expression; if (isBindingPattern(decl.name)) { - assignment = flattenVariableDestructuringToExpression(context, decl, hoistVariableDeclaration, /*nameSubstitution*/ undefined, visitor); + assignment = flattenVariableDestructuringToExpression(decl, hoistVariableDeclaration, /*nameSubstitution*/ undefined, visitor); } else { assignment = createBinary(decl.name, SyntaxKind.EqualsToken, visitNode(decl.initializer, visitor, isExpression)); @@ -1843,7 +1843,7 @@ namespace ts { if (isBindingPattern(node.name)) { const recordTempVariablesInLine = !enclosingVariableStatement || !hasModifier(enclosingVariableStatement, ModifierFlags.Export); - return flattenVariableDestructuring(context, node, /*value*/ undefined, visitor, + return flattenVariableDestructuring(node, /*value*/ undefined, visitor, recordTempVariablesInLine ? undefined : hoistVariableDeclaration); } @@ -1946,7 +1946,6 @@ namespace ts { // This works whether the declaration is a var, let, or const. // It will use rhsIterationValue _a[_i] as the initializer. const declarations = flattenVariableDestructuring( - context, firstOriginalDeclaration, createElementAccess(rhsReference, counter), visitor @@ -2539,15 +2538,15 @@ namespace ts { break; case SyntaxKind.PropertyAssignment: - expressions.push(transformPropertyAssignmentToExpression(node, property, receiver, node.multiLine)); + expressions.push(transformPropertyAssignmentToExpression(property, receiver, node.multiLine)); break; case SyntaxKind.ShorthandPropertyAssignment: - expressions.push(transformShorthandPropertyAssignmentToExpression(node, property, receiver, node.multiLine)); + expressions.push(transformShorthandPropertyAssignmentToExpression(property, receiver, node.multiLine)); break; case SyntaxKind.MethodDeclaration: - expressions.push(transformObjectLiteralMethodDeclarationToExpression(node, property, receiver, node.multiLine)); + expressions.push(transformObjectLiteralMethodDeclarationToExpression(property, receiver, node.multiLine)); break; default: @@ -2564,7 +2563,7 @@ namespace ts { * @param property The PropertyAssignment node. * @param receiver The receiver for the assignment. */ - function transformPropertyAssignmentToExpression(node: ObjectLiteralExpression, property: PropertyAssignment, receiver: Expression, startsOnNewLine: boolean) { + function transformPropertyAssignmentToExpression(property: PropertyAssignment, receiver: Expression, startsOnNewLine: boolean) { const expression = createAssignment( createMemberAccessForPropertyName( receiver, @@ -2586,7 +2585,7 @@ namespace ts { * @param property The ShorthandPropertyAssignment node. * @param receiver The receiver for the assignment. */ - function transformShorthandPropertyAssignmentToExpression(node: ObjectLiteralExpression, property: ShorthandPropertyAssignment, receiver: Expression, startsOnNewLine: boolean) { + function transformShorthandPropertyAssignmentToExpression(property: ShorthandPropertyAssignment, receiver: Expression, startsOnNewLine: boolean) { const expression = createAssignment( createMemberAccessForPropertyName( receiver, @@ -2608,7 +2607,7 @@ namespace ts { * @param method The MethodDeclaration node. * @param receiver The receiver for the assignment. */ - function transformObjectLiteralMethodDeclarationToExpression(node: ObjectLiteralExpression, method: MethodDeclaration, receiver: Expression, startsOnNewLine: boolean) { + function transformObjectLiteralMethodDeclarationToExpression(method: MethodDeclaration, receiver: Expression, startsOnNewLine: boolean) { const expression = createAssignment( createMemberAccessForPropertyName( receiver, @@ -2798,7 +2797,7 @@ namespace ts { // expressions into an array literal. const numElements = elements.length; const segments = flatten( - spanMap(elements, partitionSpreadElement, (partition, visitPartition, start, end) => + spanMap(elements, partitionSpreadElement, (partition, visitPartition, _start, end) => visitPartition(partition, multiLine, hasTrailingComma && end === numElements) ) ); @@ -2820,7 +2819,7 @@ namespace ts { : visitSpanOfNonSpreadElements; } - function visitSpanOfSpreadElements(chunk: Expression[], multiLine: boolean, hasTrailingComma: boolean): VisitResult { + function visitSpanOfSpreadElements(chunk: Expression[]): VisitResult { return map(chunk, visitExpressionOfSpreadElement); } @@ -3009,7 +3008,7 @@ namespace ts { /** * Visits the `super` keyword */ - function visitSuperKeyword(node: PrimaryExpression): LeftHandSideExpression { + function visitSuperKeyword(): LeftHandSideExpression { return enclosingNonAsyncFunctionBody && isClassElement(enclosingNonAsyncFunctionBody) && !hasModifier(enclosingNonAsyncFunctionBody, ModifierFlags.Static) diff --git a/src/compiler/transformers/generators.ts b/src/compiler/transformers/generators.ts index aaf9014c5cc..200e5ec7296 100644 --- a/src/compiler/transformers/generators.ts +++ b/src/compiler/transformers/generators.ts @@ -956,7 +956,7 @@ namespace ts { * @param elements The elements to visit. * @param multiLine Whether array literals created should be emitted on multiple lines. */ - function visitElements(elements: NodeArray, multiLine: boolean) { + function visitElements(elements: NodeArray, _multiLine?: boolean) { // [source] // ar = [1, yield, 2]; // @@ -1102,7 +1102,7 @@ namespace ts { createFunctionApply( cacheExpression(visitNode(target, visitor, isLeftHandSideExpression)), thisArg, - visitElements(node.arguments, /*multiLine*/ false), + visitElements(node.arguments), /*location*/ node ), node @@ -1131,7 +1131,7 @@ namespace ts { createFunctionApply( cacheExpression(visitNode(target, visitor, isExpression)), thisArg, - visitElements(node.arguments, /*multiLine*/ false) + visitElements(node.arguments) ), /*typeArguments*/ undefined, [], diff --git a/src/compiler/transformers/module/es2015.ts b/src/compiler/transformers/module/es2015.ts index 23fb444b6ff..93aa108617a 100644 --- a/src/compiler/transformers/module/es2015.ts +++ b/src/compiler/transformers/module/es2015.ts @@ -22,7 +22,8 @@ namespace ts { function visitor(node: Node): VisitResult { switch (node.kind) { case SyntaxKind.ImportEqualsDeclaration: - return visitImportEqualsDeclaration(node); + // Elide `import=` as it is not legal with --module ES6 + return undefined; case SyntaxKind.ExportAssignment: return visitExportAssignment(node); } @@ -30,11 +31,6 @@ namespace ts { return node; } - function visitImportEqualsDeclaration(node: ImportEqualsDeclaration): VisitResult { - // Elide `import=` as it is not legal with --module ES6 - return undefined; - } - function visitExportAssignment(node: ExportAssignment): VisitResult { // Elide `export=` as it is not legal with --module ES6 return node.isExportEquals ? undefined : node; diff --git a/src/compiler/transformers/module/module.ts b/src/compiler/transformers/module/module.ts index 1cca7a21777..1f56670c932 100644 --- a/src/compiler/transformers/module/module.ts +++ b/src/compiler/transformers/module/module.ts @@ -680,7 +680,6 @@ namespace ts { const name = node.name; if (isBindingPattern(name)) { return flattenVariableDestructuringToExpression( - context, node, hoistVariableDeclaration, getModuleMemberName, diff --git a/src/compiler/transformers/module/system.ts b/src/compiler/transformers/module/system.ts index 775d8fc34f9..61f2d5c0509 100644 --- a/src/compiler/transformers/module/system.ts +++ b/src/compiler/transformers/module/system.ts @@ -646,7 +646,7 @@ namespace ts { } else { // If the variable has a BindingPattern, flatten the variable into multiple assignment expressions. - return flattenVariableDestructuringToExpression(context, node, hoistVariableDeclaration); + return flattenVariableDestructuringToExpression(node, hoistVariableDeclaration); } } @@ -795,7 +795,7 @@ namespace ts { const name = firstDeclaration.name; return isIdentifier(name) ? name - : flattenVariableDestructuringToExpression(context, firstDeclaration, hoistVariableDeclaration); + : flattenVariableDestructuringToExpression(firstDeclaration, hoistVariableDeclaration); } /** diff --git a/src/compiler/transformers/ts.ts b/src/compiler/transformers/ts.ts index a1190efee10..925869da385 100644 --- a/src/compiler/transformers/ts.ts +++ b/src/compiler/transformers/ts.ts @@ -580,7 +580,7 @@ namespace ts { // HasLexicalDeclaration (N) : Determines if the argument identifier has a binding in this environment record that was created using // a lexical declaration such as a LexicalDeclaration or a ClassDeclaration. if (staticProperties.length) { - addInitializedPropertyStatements(statements, node, staticProperties, getLocalName(node, /*noSourceMaps*/ true)); + addInitializedPropertyStatements(statements, staticProperties, getLocalName(node, /*noSourceMaps*/ true)); } // Write any decorators of the node. @@ -822,7 +822,7 @@ namespace ts { // the body of a class with static initializers. setEmitFlags(classExpression, EmitFlags.Indented | getEmitFlags(classExpression)); expressions.push(startOnNewLine(createAssignment(temp, classExpression))); - addRange(expressions, generateInitializedPropertyExpressions(node, staticProperties, temp)); + addRange(expressions, generateInitializedPropertyExpressions(staticProperties, temp)); expressions.push(startOnNewLine(temp)); return inlineExpressions(expressions); } @@ -868,7 +868,7 @@ namespace ts { } const parameters = transformConstructorParameters(constructor); - const body = transformConstructorBody(node, constructor, hasExtendsClause, parameters); + const body = transformConstructorBody(node, constructor, hasExtendsClause); // constructor(${parameters}) { // ${body} @@ -922,9 +922,8 @@ namespace ts { * @param node The current class. * @param constructor The current class constructor. * @param hasExtendsClause A value indicating whether the class has an extends clause. - * @param parameters The transformed parameters for the constructor. */ - function transformConstructorBody(node: ClassExpression | ClassDeclaration, constructor: ConstructorDeclaration, hasExtendsClause: boolean, parameters: ParameterDeclaration[]) { + function transformConstructorBody(node: ClassExpression | ClassDeclaration, constructor: ConstructorDeclaration, hasExtendsClause: boolean) { const statements: Statement[] = []; let indexOfFirstStatement = 0; @@ -976,7 +975,7 @@ namespace ts { // } // const properties = getInitializedProperties(node, /*isStatic*/ false); - addInitializedPropertyStatements(statements, node, properties, createThis()); + addInitializedPropertyStatements(statements, properties, createThis()); if (constructor) { // The class already had a constructor, so we should add the existing statements, skipping the initial super call. @@ -1116,13 +1115,12 @@ namespace ts { /** * Generates assignment statements for property initializers. * - * @param node The class node. * @param properties An array of property declarations to transform. * @param receiver The receiver on which each property should be assigned. */ - function addInitializedPropertyStatements(statements: Statement[], node: ClassExpression | ClassDeclaration, properties: PropertyDeclaration[], receiver: LeftHandSideExpression) { + function addInitializedPropertyStatements(statements: Statement[], properties: PropertyDeclaration[], receiver: LeftHandSideExpression) { for (const property of properties) { - const statement = createStatement(transformInitializedProperty(node, property, receiver)); + const statement = createStatement(transformInitializedProperty(property, receiver)); setSourceMapRange(statement, moveRangePastModifiers(property)); setCommentRange(statement, property); statements.push(statement); @@ -1132,14 +1130,13 @@ namespace ts { /** * Generates assignment expressions for property initializers. * - * @param node The class node. * @param properties An array of property declarations to transform. * @param receiver The receiver on which each property should be assigned. */ - function generateInitializedPropertyExpressions(node: ClassExpression | ClassDeclaration, properties: PropertyDeclaration[], receiver: LeftHandSideExpression) { + function generateInitializedPropertyExpressions(properties: PropertyDeclaration[], receiver: LeftHandSideExpression) { const expressions: Expression[] = []; for (const property of properties) { - const expression = transformInitializedProperty(node, property, receiver); + const expression = transformInitializedProperty(property, receiver); expression.startsOnNewLine = true; setSourceMapRange(expression, moveRangePastModifiers(property)); setCommentRange(expression, property); @@ -1152,11 +1149,10 @@ namespace ts { /** * Transforms a property initializer into an assignment statement. * - * @param node The class containing the property. * @param property The property declaration. * @param receiver The object receiving the property assignment. */ - function transformInitializedProperty(node: ClassExpression | ClassDeclaration, property: PropertyDeclaration, receiver: LeftHandSideExpression) { + function transformInitializedProperty(property: PropertyDeclaration, receiver: LeftHandSideExpression) { const propertyName = visitPropertyNameOfClassElement(property); const initializer = visitNode(property.initializer, visitor, isExpression); const memberAccess = createMemberAccessForPropertyName(receiver, propertyName, /*location*/ propertyName); @@ -2423,7 +2419,6 @@ namespace ts { const name = node.name; if (isBindingPattern(name)) { return flattenVariableDestructuringToExpression( - context, node, hoistVariableDeclaration, getNamespaceMemberNameWithSourceMapsAndWithoutComments, diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index b39c017384e..aa277c9b507 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -29,7 +29,7 @@ namespace ts { } } - function reportEmittedFiles(files: string[], host: CompilerHost): void { + function reportEmittedFiles(files: string[]): void { if (!files || files.length == 0) { return; } @@ -111,7 +111,7 @@ namespace ts { return count; } - function getDiagnosticText(message: DiagnosticMessage, ...args: any[]): string { + function getDiagnosticText(_message: DiagnosticMessage, ..._args: any[]): string { const diagnostic = createCompilerDiagnostic.apply(undefined, arguments); return diagnostic.messageText; } @@ -456,7 +456,7 @@ namespace ts { const sourceFile = hostGetSourceFile(fileName, languageVersion, onError); if (sourceFile && isWatchSet(compilerOptions) && sys.watchFile) { // Attach a file watcher - sourceFile.fileWatcher = sys.watchFile(sourceFile.fileName, (fileName: string, removed?: boolean) => sourceFileChanged(sourceFile, removed)); + sourceFile.fileWatcher = sys.watchFile(sourceFile.fileName, (_fileName: string, removed?: boolean) => sourceFileChanged(sourceFile, removed)); } return sourceFile; } @@ -617,7 +617,7 @@ namespace ts { reportDiagnostics(sortAndDeduplicateDiagnostics(diagnostics), compilerHost); - reportEmittedFiles(emitOutput.emittedFiles, compilerHost); + reportEmittedFiles(emitOutput.emittedFiles); if (emitOutput.emitSkipped && diagnostics.length > 0) { // If the emitter didn't emit anything, then pass that value along. diff --git a/src/compiler/tsconfig.json b/src/compiler/tsconfig.json index 65ba20f18d2..a6c03d1b680 100644 --- a/src/compiler/tsconfig.json +++ b/src/compiler/tsconfig.json @@ -9,7 +9,9 @@ "sourceMap": true, "declaration": true, "stripInternal": true, - "target": "es5" + "target": "es5", + "noUnusedLocals": true, + "noUnusedParameters": true }, "files": [ "core.ts", diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index efdac40c287..55374a1cd74 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2566,7 +2566,7 @@ namespace ts { const options = host.getCompilerOptions(); // Emit on each source file if (options.outFile || options.out) { - onBundledEmit(host, sourceFiles); + onBundledEmit(sourceFiles); } else { for (const sourceFile of sourceFiles) { @@ -2599,7 +2599,7 @@ namespace ts { action(jsFilePath, sourceMapFilePath, declarationFilePath, [sourceFile], /*isBundledEmit*/ false); } - function onBundledEmit(host: EmitHost, sourceFiles: SourceFile[]) { + function onBundledEmit(sourceFiles: SourceFile[]) { if (sourceFiles.length) { const jsFilePath = options.outFile || options.out; const sourceMapFilePath = getSourceMapFilePath(jsFilePath, options); diff --git a/src/compiler/visitor.ts b/src/compiler/visitor.ts index 8dca78fec97..5c152c88e47 100644 --- a/src/compiler/visitor.ts +++ b/src/compiler/visitor.ts @@ -1331,18 +1331,18 @@ namespace ts { export namespace Debug { export const failNotOptional = shouldAssert(AssertionLevel.Normal) ? (message?: string) => assert(false, message || "Node not optional.") - : (message?: string) => {}; + : () => {}; export const failBadSyntaxKind = shouldAssert(AssertionLevel.Normal) ? (node: Node, message?: string) => assert(false, message || "Unexpected node.", () => `Node ${formatSyntaxKind(node.kind)} was unexpected.`) - : (node: Node, message?: string) => {}; + : () => {}; export const assertNode = shouldAssert(AssertionLevel.Normal) ? (node: Node, test: (node: Node) => boolean, message?: string) => assert( test === undefined || test(node), message || "Unexpected node.", () => `Node ${formatSyntaxKind(node.kind)} did not pass test '${getFunctionName(test)}'.`) - : (node: Node, test: (node: Node) => boolean, message?: string) => {}; + : () => {}; function getFunctionName(func: Function) { if (typeof func !== "function") { diff --git a/src/services/shims.ts b/src/services/shims.ts index 7ed1786640d..571f009d866 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -444,7 +444,7 @@ namespace ts { } public readDirectory(path: string, extensions?: string[], exclude?: string[], include?: string[], depth?: number): string[] { - const pattern = getFileMatcherPatterns(path, extensions, exclude, include, + const pattern = getFileMatcherPatterns(path, exclude, include, this.shimHost.useCaseSensitiveFileNames(), this.shimHost.getCurrentDirectory()); return JSON.parse(this.shimHost.readDirectory( path, @@ -509,7 +509,7 @@ namespace ts { // Wrap the API changes for 2.0 release. This try/catch // should be removed once TypeScript 2.0 has shipped. try { - const pattern = getFileMatcherPatterns(rootDir, extensions, exclude, include, + const pattern = getFileMatcherPatterns(rootDir, exclude, include, this.shimHost.useCaseSensitiveFileNames(), this.shimHost.getCurrentDirectory()); return JSON.parse(this.shimHost.readDirectory( rootDir, From dba03377b816123149046030b869baa70ae35291 Mon Sep 17 00:00:00 2001 From: Jason Ramsay Date: Tue, 18 Oct 2016 14:04:21 -0700 Subject: [PATCH 8/9] Adding JSXExpression check for isGlobalCompletion and associated tests --- src/services/completions.ts | 1 + .../fourslash/completionListIsGlobalCompletion.ts | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/services/completions.ts b/src/services/completions.ts index cd4d64b3b09..3b76fdc8c3b 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -1082,6 +1082,7 @@ namespace ts.Completions { isGlobalCompletion = scopeNode.kind === SyntaxKind.SourceFile || scopeNode.kind === SyntaxKind.TemplateExpression || + scopeNode.kind === SyntaxKind.JsxExpression || isStatement(scopeNode); } diff --git a/tests/cases/fourslash/completionListIsGlobalCompletion.ts b/tests/cases/fourslash/completionListIsGlobalCompletion.ts index 3961f4fadae..a1fadc6bb12 100644 --- a/tests/cases/fourslash/completionListIsGlobalCompletion.ts +++ b/tests/cases/fourslash/completionListIsGlobalCompletion.ts @@ -33,6 +33,7 @@ ////const y =
; // no globals in jsx attribute found ////const z =
; // no globals in jsx attribute with syntax error ////const x = `/*14*/ ${/*15*/}`; // globals only in template expression +////var user = ; // globals only in JSX expression (but not in JSX expression strings) goTo.marker("1"); verify.completionListIsGlobal(false); goTo.marker("2"); @@ -62,4 +63,12 @@ verify.completionListIsGlobal(false); goTo.marker("14"); verify.completionListIsGlobal(false); goTo.marker("15"); -verify.completionListIsGlobal(true); \ No newline at end of file +verify.completionListIsGlobal(true); +goTo.marker("16"); +verify.completionListIsGlobal(false); +goTo.marker("17"); +verify.completionListIsGlobal(false); +goTo.marker("18"); +verify.completionListIsGlobal(true); +goTo.marker("19"); +verify.completionListIsGlobal(false); \ No newline at end of file From f11dbc1ad160dde5209d06dd552f5d73cd832bac Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Wed, 19 Oct 2016 06:26:50 -0700 Subject: [PATCH 9/9] Respond to PR feedback --- src/compiler/comments.ts | 4 ++-- src/compiler/core.ts | 2 +- src/compiler/emitter.ts | 2 +- src/compiler/moduleNameResolver.ts | 2 +- src/compiler/parser.ts | 4 ++-- src/compiler/sys.ts | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/compiler/comments.ts b/src/compiler/comments.ts index c2cf49eeb6a..cd96981c093 100644 --- a/src/compiler/comments.ts +++ b/src/compiler/comments.ts @@ -182,9 +182,9 @@ namespace ts { } } - function emitTripleSlashLeadingComment(commentPos: number, commentEnd: number, _kind: SyntaxKind, hasTrailingNewLine: boolean, rangePos: number) { + function emitTripleSlashLeadingComment(commentPos: number, commentEnd: number, kind: SyntaxKind, hasTrailingNewLine: boolean, rangePos: number) { if (isTripleSlashComment(commentPos, commentEnd)) { - emitLeadingComment(commentPos, commentEnd, _kind, hasTrailingNewLine, rangePos); + emitLeadingComment(commentPos, commentEnd, kind, hasTrailingNewLine, rangePos); } } diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 05efc6db909..2f77b3040b3 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -903,7 +903,7 @@ namespace ts { return t => compose(a(t)); } else { - return _t => u => u; + return _ => u => u; } } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index bf540f6a0cd..1051c9adca9 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -14,7 +14,7 @@ namespace ts { } const id = (s: SourceFile) => s; - const nullTransformers: Transformer[] = [_ctx => id]; + const nullTransformers: Transformer[] = [_ => id]; // targetSourceFile is when users only want one file in entire project to be emitted. This is used in compileOnSave feature export function emitFiles(resolver: EmitResolver, host: EmitHost, targetSourceFile: SourceFile, emitOnlyDtsFiles?: boolean): EmitResult { diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index ba1f8497559..3fa54f127e1 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -5,7 +5,7 @@ namespace ts { /* @internal */ export function trace(host: ModuleResolutionHost, message: DiagnosticMessage, ...args: any[]): void; - export function trace(host: ModuleResolutionHost, _message: DiagnosticMessage): void { + export function trace(host: ModuleResolutionHost): void { host.trace(formatMessage.apply(undefined, arguments)); } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 5481dc657b8..8cdbf956d42 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -572,10 +572,10 @@ namespace ts { // attached to the EOF token. let parseErrorBeforeNextFinishedNode = false; - export function parseSourceFile(fileName: string, _sourceText: string, languageVersion: ScriptTarget, _syntaxCursor: IncrementalParser.SyntaxCursor, setParentNodes?: boolean, scriptKind?: ScriptKind): SourceFile { + export function parseSourceFile(fileName: string, sourceText: string, languageVersion: ScriptTarget, syntaxCursor: IncrementalParser.SyntaxCursor, setParentNodes?: boolean, scriptKind?: ScriptKind): SourceFile { scriptKind = ensureScriptKind(fileName, scriptKind); - initializeState(_sourceText, languageVersion, _syntaxCursor, scriptKind); + initializeState(sourceText, languageVersion, syntaxCursor, scriptKind); const result = parseSourceFileWorker(fileName, languageVersion, setParentNodes, scriptKind); diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index bb945824b4d..585fb60df32 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -591,7 +591,7 @@ namespace ts { getExecutingFilePath: () => ChakraHost.executingFile, getCurrentDirectory: () => ChakraHost.currentDirectory, getDirectories: ChakraHost.getDirectories, - getEnvironmentVariable: ChakraHost.getEnvironmentVariable || ((_name: string) => ""), + getEnvironmentVariable: ChakraHost.getEnvironmentVariable || (() => ""), readDirectory: (path: string, extensions?: string[], excludes?: string[], includes?: string[]) => { const pattern = getFileMatcherPatterns(path, excludes, includes, !!ChakraHost.useCaseSensitiveFileNames, ChakraHost.currentDirectory); return ChakraHost.readDirectory(path, extensions, pattern.basePaths, pattern.excludePattern, pattern.includeFilePattern, pattern.includeDirectoryPattern);