From bf642176153985f940ccfecb0d343d4df1d87c56 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Fri, 15 Aug 2014 13:54:19 -0700 Subject: [PATCH 1/4] create instance of the checker prior to making any types --- src/compiler/checker.ts | 56 ++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index de0e46995dd..a8a50bbd0fd 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -21,6 +21,34 @@ module ts { var emptyArray: any[] = []; var emptySymbols: SymbolTable = {}; + + var checker: TypeChecker = { + getProgram: () => program, + getDiagnostics: getDiagnostics, + getGlobalDiagnostics: getGlobalDiagnostics, + getNodeCount: () => sum(program.getSourceFiles(), "nodeCount"), + getIdentifierCount: () => sum(program.getSourceFiles(), "identifierCount"), + getSymbolCount: () => sum(program.getSourceFiles(), "symbolCount"), + getTypeCount: () => typeCount, + checkProgram: checkProgram, + emitFiles: invokeEmitter, + getSymbolOfNode: getSymbolOfNode, + getParentOfSymbol: getParentOfSymbol, + getTypeOfSymbol: getTypeOfSymbol, + getDeclaredTypeOfSymbol: getDeclaredTypeOfSymbol, + getPropertiesOfType: getPropertiesOfType, + getPropertyOfType: getPropertyOfType, + getSignaturesOfType: getSignaturesOfType, + getIndexTypeOfType: getIndexTypeOfType, + getReturnTypeOfSignature: getReturnTypeOfSignature, + resolveEntityName: resolveEntityName, + getSymbolsInScope: getSymbolsInScope, + getSymbolInfo: getSymbolInfo, + getTypeOfExpression: getTypeOfExpression, + typeToString: typeToString, + symbolToString: symbolToString, + getAugmentedPropertiesOfApparentType: getAugmentedPropertiesOfApparentType + }; var undefinedSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "undefined"); var argumentsSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "arguments"); @@ -68,34 +96,6 @@ module ts { var diagnostics: Diagnostic[] = []; var diagnosticsModified: boolean = false; - var checker: TypeChecker = { - getProgram: () => program, - getDiagnostics: getDiagnostics, - getGlobalDiagnostics: getGlobalDiagnostics, - getNodeCount: () => sum(program.getSourceFiles(), "nodeCount"), - getIdentifierCount: () => sum(program.getSourceFiles(), "identifierCount"), - getSymbolCount: () => sum(program.getSourceFiles(), "symbolCount"), - getTypeCount: () => typeCount, - checkProgram: checkProgram, - emitFiles: invokeEmitter, - getSymbolOfNode: getSymbolOfNode, - getParentOfSymbol: getParentOfSymbol, - getTypeOfSymbol: getTypeOfSymbol, - getDeclaredTypeOfSymbol: getDeclaredTypeOfSymbol, - getPropertiesOfType: getPropertiesOfType, - getPropertyOfType: getPropertyOfType, - getSignaturesOfType: getSignaturesOfType, - getIndexTypeOfType: getIndexTypeOfType, - getReturnTypeOfSignature: getReturnTypeOfSignature, - resolveEntityName: resolveEntityName, - getSymbolsInScope: getSymbolsInScope, - getSymbolInfo: getSymbolInfo, - getTypeOfExpression: getTypeOfExpression, - typeToString: typeToString, - symbolToString: symbolToString, - getAugmentedPropertiesOfApparentType: getAugmentedPropertiesOfApparentType - }; - function addDiagnostic(diagnostic: Diagnostic) { diagnostics.push(diagnostic); diagnosticsModified = true; From 00b438bad619d9335c677254d1ea6e7d3b13c547 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 15 Aug 2014 17:13:11 -0700 Subject: [PATCH 2/4] Normalized path for localized diagnostics message map. --- src/compiler/tsc.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 85f9ce6fe32..d3a627538c5 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -38,7 +38,7 @@ module ts { } function trySetLanguageAndTerritory(language: string, territory: string, errors: Diagnostic[]): boolean { - var compilerFilePath = sys.getExecutingFilePath(); + var compilerFilePath = normalizePath(sys.getExecutingFilePath()); var containingDirectoryPath = getDirectoryPath(compilerFilePath); var filePath = combinePaths(containingDirectoryPath, language); @@ -62,7 +62,7 @@ module ts { return false; } try { - localizedDiagnosticMessages = JSON.parse(fileContents); + ts.localizedDiagnosticMessages = JSON.parse(fileContents); } catch (e) { errors.push(createCompilerDiagnostic(Diagnostics.Corrupted_locale_file_0, filePath)); From 06e858ff40cf7ff366c574b930a50ce386600d36 Mon Sep 17 00:00:00 2001 From: Adam Freidin Date: Fri, 15 Aug 2014 20:12:04 -0700 Subject: [PATCH 3/4] fix --declaration typechecking (complex case) This fixes generation of typescriptServices.d.ts, although this is not a current requirement ( https://github.com/Microsoft/TypeScript/issues/465 ). --- src/compiler/checker.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 99c21d9ff15..cba51e8fd86 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -780,7 +780,7 @@ module ts { // But it cant, hence the accessible is going to be undefined, but that doesnt mean m.c is accessible // It is accessible if the parent m is accessible because then m.c can be accessed through qualification meaningToLook = getQualifiedLeftMeaning(meaning); - symbol = symbol.parent; + symbol = getParentOfSymbol(symbol); } // This could be a symbol that is not exported in the external module @@ -903,7 +903,7 @@ module ts { if (accessibleSymbolChain && !needsQualification(accessibleSymbolChain[0], enclosingDeclaration, accessibleSymbolChain.length === 1 ? meaning : getQualifiedLeftMeaning(meaning))) { break; } - symbol = accessibleSymbolChain ? accessibleSymbolChain[0].parent : symbol.parent; + symbol = getParentOfSymbol(accessibleSymbolChain ? accessibleSymbolChain[0] : symbol); meaning = getQualifiedLeftMeaning(meaning); } From d43f28d3a0b7bdb331e14a2acac84cf085220a3d Mon Sep 17 00:00:00 2001 From: Adam Freidin Date: Fri, 15 Aug 2014 21:14:33 -0700 Subject: [PATCH 4/4] baseline for typechecking --declaration --- .../reference/moduleSymbolMerging.js | 42 +++++++++++++++++++ tests/cases/compiler/moduleSymbolMerging.ts | 12 ++++++ 2 files changed, 54 insertions(+) create mode 100644 tests/baselines/reference/moduleSymbolMerging.js create mode 100644 tests/cases/compiler/moduleSymbolMerging.ts diff --git a/tests/baselines/reference/moduleSymbolMerging.js b/tests/baselines/reference/moduleSymbolMerging.js new file mode 100644 index 00000000000..4b35f939873 --- /dev/null +++ b/tests/baselines/reference/moduleSymbolMerging.js @@ -0,0 +1,42 @@ +//// [tests/cases/compiler/moduleSymbolMerging.ts] //// + +//// [A.ts] + +module A { export interface I {} } + +//// [B.ts] +/// +module A { ; } +module B { + export function f(): A.I { return null; } +} + + + +//// [A.js] +//// [B.js] +var A; +(function (A) { + ; +})(A || (A = {})); +var B; +(function (B) { + function f() { + return null; + } + B.f = f; +})(B || (B = {})); + + +//// [A.d.ts] +declare module A { + interface I { + } +} +//// [B.d.ts] +/// +declare module A { +} +declare module B { + function f(): A.I; +} diff --git a/tests/cases/compiler/moduleSymbolMerging.ts b/tests/cases/compiler/moduleSymbolMerging.ts new file mode 100644 index 00000000000..03df2c5e596 --- /dev/null +++ b/tests/cases/compiler/moduleSymbolMerging.ts @@ -0,0 +1,12 @@ +// @declaration: true + +// @Filename: A.ts +module A { export interface I {} } + +// @Filename: B.ts +/// +module A { ; } +module B { + export function f(): A.I { return null; } +} +