From 5e672b77918ecf0c76e47957f60ab570894e3984 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Fri, 12 Jun 2015 13:49:38 -0700 Subject: [PATCH 1/2] Don't log by default. On the managed side tracing is disabled by default anyways. By logging we still cause tons of allocations of strings on the managed side. These then cause expensive GCs which can pause editing. --- src/services/shims.ts | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/services/shims.ts b/src/services/shims.ts index 004393fb3b5..d6f9f7a968a 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -246,16 +246,22 @@ module ts { export class LanguageServiceShimHostAdapter implements LanguageServiceHost { private files: string[]; + private loggingEnabled = false; + private tracingEnabled = false; constructor(private shimHost: LanguageServiceShimHost) { } public log(s: string): void { - this.shimHost.log(s); + if (this.loggingEnabled) { + this.shimHost.log(s); + } } public trace(s: string): void { - this.shimHost.trace(s); + if (this.tracingEnabled) { + this.shimHost.trace(s); + } } public error(s: string): void { @@ -349,15 +355,15 @@ module ts { } } - function simpleForwardCall(logger: Logger, actionDescription: string, action: () => any, noPerfLogging: boolean): any { - if (!noPerfLogging) { + function simpleForwardCall(logger: Logger, actionDescription: string, action: () => any, logPerformance: boolean): any { + if (logPerformance) { logger.log(actionDescription); var start = Date.now(); } var result = action(); - if (!noPerfLogging) { + if (logPerformance) { var end = Date.now(); logger.log(actionDescription + " completed in " + (end - start) + " msec"); if (typeof (result) === "string") { @@ -372,9 +378,9 @@ module ts { return result; } - function forwardJSONCall(logger: Logger, actionDescription: string, action: () => any, noPerfLogging: boolean): string { + function forwardJSONCall(logger: Logger, actionDescription: string, action: () => any, logPerformance: boolean): string { try { - var result = simpleForwardCall(logger, actionDescription, action, noPerfLogging); + var result = simpleForwardCall(logger, actionDescription, action, logPerformance); return JSON.stringify({ result: result }); } catch (err) { @@ -413,6 +419,7 @@ module ts { class LanguageServiceShimObject extends ShimBase implements LanguageServiceShim { private logger: Logger; + private logPerformance = false; constructor(factory: ShimFactory, private host: LanguageServiceShimHost, @@ -422,7 +429,7 @@ module ts { } public forwardJSONCall(actionDescription: string, action: () => any): string { - return forwardJSONCall(this.logger, actionDescription, action, /*noPerfLogging:*/ false); + return forwardJSONCall(this.logger, actionDescription, action, this.logPerformance); } /// DISPOSE @@ -811,6 +818,7 @@ module ts { class ClassifierShimObject extends ShimBase implements ClassifierShim { public classifier: Classifier; + private logPerformance = false; constructor(factory: ShimFactory, private logger: Logger) { super(factory); @@ -820,7 +828,7 @@ module ts { public getEncodedLexicalClassifications(text: string, lexState: EndOfLineState, syntacticClassifierAbsent?: boolean): string { return forwardJSONCall(this.logger, "getEncodedLexicalClassifications", () => convertClassifications(this.classifier.getEncodedLexicalClassifications(text, lexState, syntacticClassifierAbsent)), - /*noPerfLogging:*/ true); + this.logPerformance); } /// COLORIZATION @@ -838,13 +846,14 @@ module ts { } class CoreServicesShimObject extends ShimBase implements CoreServicesShim { + private logPerformance = false; constructor(factory: ShimFactory, public logger: Logger, private host: CoreServicesShimHostAdapter) { super(factory); } private forwardJSONCall(actionDescription: string, action: () => any): any { - return forwardJSONCall(this.logger, actionDescription, action, /*noPerfLogging:*/ false); + return forwardJSONCall(this.logger, actionDescription, action, this.logPerformance); } public getPreProcessedFileInfo(fileName: string, sourceTextSnapshot: IScriptSnapshot): string { From 331b63df7d05c9476b6b9cae97a7a158eba303ca Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Fri, 19 Jun 2015 16:01:27 -0700 Subject: [PATCH 2/2] update LKG --- bin/tsc.js | 83 +++++++++++----- bin/tsserver.js | 134 ++++++++++++++++---------- bin/typescript.d.ts | 14 ++- bin/typescript.js | 182 ++++++++++++++++++++++++------------ bin/typescriptServices.d.ts | 14 ++- bin/typescriptServices.js | 182 ++++++++++++++++++++++++------------ 6 files changed, 415 insertions(+), 194 deletions(-) diff --git a/bin/tsc.js b/bin/tsc.js index e7a41e8aa7e..0aa82496955 100644 --- a/bin/tsc.js +++ b/bin/tsc.js @@ -31,6 +31,36 @@ var ts; /// var ts; (function (ts) { + function createFileMap(getCanonicalFileName) { + var files = {}; + return { + get: get, + set: set, + contains: contains, + remove: remove, + forEachValue: forEachValueInMap + }; + function set(fileName, value) { + files[normalizeKey(fileName)] = value; + } + function get(fileName) { + return files[normalizeKey(fileName)]; + } + function contains(fileName) { + return hasProperty(files, normalizeKey(fileName)); + } + function remove(fileName) { + var key = normalizeKey(fileName); + delete files[key]; + } + function forEachValueInMap(f) { + forEachValue(files, f); + } + function normalizeKey(key) { + return getCanonicalFileName(normalizeSlashes(key)); + } + } + ts.createFileMap = createFileMap; function forEach(array, callback) { if (array) { for (var i = 0, len = array.length; i < len; i++) { @@ -7758,7 +7788,7 @@ var ts; token === 18) { return parsePropertyOrMethodDeclaration(fullStart, decorators, modifiers); } - if (decorators) { + if (decorators || modifiers) { var name_3 = createMissingNode(65, true, ts.Diagnostics.Declaration_expected); return parsePropertyDeclaration(fullStart, decorators, modifiers, name_3, undefined); } @@ -8162,7 +8192,7 @@ var ts; case 85: return parseImportDeclarationOrImportEqualsDeclaration(fullStart, decorators, modifiers); default: - if (decorators) { + if (decorators || modifiers) { var node = createMissingNode(219, true, ts.Diagnostics.Declaration_expected); node.pos = fullStart; node.decorators = decorators; @@ -8238,7 +8268,7 @@ var ts; } sourceFile.referencedFiles = referencedFiles; sourceFile.amdDependencies = amdDependencies; - sourceFile.amdModuleName = amdModuleName; + sourceFile.moduleName = amdModuleName; } function setExternalModuleIndicator(sourceFile) { sourceFile.externalModuleIndicator = ts.forEach(sourceFile.statements, function (node) { @@ -8849,21 +8879,24 @@ var ts; if (!ts.isExternalModule(location)) break; case 206: - if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 8914931)) { - if (result.flags & meaning || !(result.flags & 8388608 && getDeclarationOfAliasSymbol(result).kind === 218)) { - break loop; - } - result = undefined; - } - else if (location.kind === 228 || + var moduleExports = getSymbolOfNode(location).exports; + if (location.kind === 228 || (location.kind === 206 && location.name.kind === 8)) { - result = getSymbolOfNode(location).exports["default"]; + if (ts.hasProperty(moduleExports, name) && + moduleExports[name].flags === 8388608 && + ts.getDeclarationOfKind(moduleExports[name], 218)) { + break; + } + result = moduleExports["default"]; var localSymbol = ts.getLocalSymbolForExportDefault(result); if (result && localSymbol && (result.flags & meaning) && localSymbol.name === name) { break loop; } result = undefined; } + if (result = getSymbol(moduleExports, name, meaning & 8914931)) { + break loop; + } break; case 205: if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 8)) { @@ -24450,10 +24483,10 @@ var ts; emitSetters(exportStarFunction); writeLine(); emitExecute(node, startIndex); - emitTempDeclarations(true); decreaseIndent(); writeLine(); write("}"); + emitTempDeclarations(true); } function emitSetters(exportStarFunction) { write("setters:["); @@ -24553,7 +24586,11 @@ var ts; collectExternalModuleInfo(node); ts.Debug.assert(!exportFunctionForFile); exportFunctionForFile = makeUniqueName("exports"); - write("System.register(["); + write("System.register("); + if (node.moduleName) { + write("\"" + node.moduleName + "\", "); + } + write("["); for (var i = 0; i < externalImports.length; ++i) { var text = getExternalModuleNameText(externalImports[i]); if (i !== 0) { @@ -24626,8 +24663,8 @@ var ts; collectExternalModuleInfo(node); writeLine(); write("define("); - if (node.amdModuleName) { - write("\"" + node.amdModuleName + "\", "); + if (node.moduleName) { + write("\"" + node.moduleName + "\", "); } emitAMDDependencies(node, true); write(") {"); @@ -25201,7 +25238,6 @@ var ts; function createProgram(rootNames, options, host) { var program; var files = []; - var filesByName = {}; var diagnostics = ts.createDiagnosticCollection(); var seenNoDefaultLib = options.noLib; var commonSourceDirectory; @@ -25209,6 +25245,7 @@ var ts; var noDiagnosticsTypeChecker; var start = new Date().getTime(); host = host || createCompilerHost(options); + var filesByName = ts.createFileMap(function (fileName) { return host.getCanonicalFileName(fileName); }); ts.forEach(rootNames, function (name) { return processRootFile(name, false); }); if (!seenNoDefaultLib) { processRootFile(host.getDefaultLibFileName(options), true); @@ -25264,8 +25301,7 @@ var ts; return emitResult; } function getSourceFile(fileName) { - fileName = host.getCanonicalFileName(ts.normalizeSlashes(fileName)); - return ts.hasProperty(filesByName, fileName) ? filesByName[fileName] : undefined; + return filesByName.get(fileName); } function getDiagnosticsHelper(sourceFile, getDiagnostics) { if (sourceFile) { @@ -25361,16 +25397,16 @@ var ts; } function findSourceFile(fileName, isDefaultLib, refFile, refStart, refLength) { var canonicalName = host.getCanonicalFileName(ts.normalizeSlashes(fileName)); - if (ts.hasProperty(filesByName, canonicalName)) { + if (filesByName.contains(canonicalName)) { return getSourceFileFromCache(fileName, canonicalName, false); } else { var normalizedAbsolutePath = ts.getNormalizedAbsolutePath(fileName, host.getCurrentDirectory()); var canonicalAbsolutePath = host.getCanonicalFileName(normalizedAbsolutePath); - if (ts.hasProperty(filesByName, canonicalAbsolutePath)) { + if (filesByName.contains(canonicalAbsolutePath)) { return getSourceFileFromCache(normalizedAbsolutePath, canonicalAbsolutePath, true); } - var file = filesByName[canonicalName] = host.getSourceFile(fileName, options.target, function (hostErrorMessage) { + var file = host.getSourceFile(fileName, options.target, function (hostErrorMessage) { if (refFile) { diagnostics.add(ts.createFileDiagnostic(refFile, refStart, refLength, ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); } @@ -25378,9 +25414,10 @@ var ts; diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); } }); + filesByName.set(canonicalName, file); if (file) { seenNoDefaultLib = seenNoDefaultLib || file.hasNoDefaultLib; - filesByName[canonicalAbsolutePath] = file; + filesByName.set(canonicalAbsolutePath, file); if (!options.noResolve) { var basePath = ts.getDirectoryPath(fileName); processReferencedFiles(file, basePath); @@ -25396,7 +25433,7 @@ var ts; return file; } function getSourceFileFromCache(fileName, canonicalName, useAbsolutePath) { - var file = filesByName[canonicalName]; + var file = filesByName.get(canonicalName); if (file && host.useCaseSensitiveFileNames()) { var sourceFileName = useAbsolutePath ? ts.getNormalizedAbsolutePath(file.fileName, host.getCurrentDirectory()) : file.fileName; if (canonicalName !== sourceFileName) { diff --git a/bin/tsserver.js b/bin/tsserver.js index 8536491127d..040eac2ef75 100644 --- a/bin/tsserver.js +++ b/bin/tsserver.js @@ -31,6 +31,36 @@ var ts; /// var ts; (function (ts) { + function createFileMap(getCanonicalFileName) { + var files = {}; + return { + get: get, + set: set, + contains: contains, + remove: remove, + forEachValue: forEachValueInMap + }; + function set(fileName, value) { + files[normalizeKey(fileName)] = value; + } + function get(fileName) { + return files[normalizeKey(fileName)]; + } + function contains(fileName) { + return hasProperty(files, normalizeKey(fileName)); + } + function remove(fileName) { + var key = normalizeKey(fileName); + delete files[key]; + } + function forEachValueInMap(f) { + forEachValue(files, f); + } + function normalizeKey(key) { + return getCanonicalFileName(normalizeSlashes(key)); + } + } + ts.createFileMap = createFileMap; function forEach(array, callback) { if (array) { for (var i = 0, len = array.length; i < len; i++) { @@ -7635,7 +7665,7 @@ var ts; token === 18) { return parsePropertyOrMethodDeclaration(fullStart, decorators, modifiers); } - if (decorators) { + if (decorators || modifiers) { var name_3 = createMissingNode(65, true, ts.Diagnostics.Declaration_expected); return parsePropertyDeclaration(fullStart, decorators, modifiers, name_3, undefined); } @@ -8039,7 +8069,7 @@ var ts; case 85: return parseImportDeclarationOrImportEqualsDeclaration(fullStart, decorators, modifiers); default: - if (decorators) { + if (decorators || modifiers) { var node = createMissingNode(219, true, ts.Diagnostics.Declaration_expected); node.pos = fullStart; node.decorators = decorators; @@ -8115,7 +8145,7 @@ var ts; } sourceFile.referencedFiles = referencedFiles; sourceFile.amdDependencies = amdDependencies; - sourceFile.amdModuleName = amdModuleName; + sourceFile.moduleName = amdModuleName; } function setExternalModuleIndicator(sourceFile) { sourceFile.externalModuleIndicator = ts.forEach(sourceFile.statements, function (node) { @@ -9239,21 +9269,24 @@ var ts; if (!ts.isExternalModule(location)) break; case 206: - if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 8914931)) { - if (result.flags & meaning || !(result.flags & 8388608 && getDeclarationOfAliasSymbol(result).kind === 218)) { - break loop; - } - result = undefined; - } - else if (location.kind === 228 || + var moduleExports = getSymbolOfNode(location).exports; + if (location.kind === 228 || (location.kind === 206 && location.name.kind === 8)) { - result = getSymbolOfNode(location).exports["default"]; + if (ts.hasProperty(moduleExports, name) && + moduleExports[name].flags === 8388608 && + ts.getDeclarationOfKind(moduleExports[name], 218)) { + break; + } + result = moduleExports["default"]; var localSymbol = ts.getLocalSymbolForExportDefault(result); if (result && localSymbol && (result.flags & meaning) && localSymbol.name === name) { break loop; } result = undefined; } + if (result = getSymbol(moduleExports, name, meaning & 8914931)) { + break loop; + } break; case 205: if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 8)) { @@ -24840,10 +24873,10 @@ var ts; emitSetters(exportStarFunction); writeLine(); emitExecute(node, startIndex); - emitTempDeclarations(true); decreaseIndent(); writeLine(); write("}"); + emitTempDeclarations(true); } function emitSetters(exportStarFunction) { write("setters:["); @@ -24943,7 +24976,11 @@ var ts; collectExternalModuleInfo(node); ts.Debug.assert(!exportFunctionForFile); exportFunctionForFile = makeUniqueName("exports"); - write("System.register(["); + write("System.register("); + if (node.moduleName) { + write("\"" + node.moduleName + "\", "); + } + write("["); for (var i = 0; i < externalImports.length; ++i) { var text = getExternalModuleNameText(externalImports[i]); if (i !== 0) { @@ -25016,8 +25053,8 @@ var ts; collectExternalModuleInfo(node); writeLine(); write("define("); - if (node.amdModuleName) { - write("\"" + node.amdModuleName + "\", "); + if (node.moduleName) { + write("\"" + node.moduleName + "\", "); } emitAMDDependencies(node, true); write(") {"); @@ -25591,7 +25628,6 @@ var ts; function createProgram(rootNames, options, host) { var program; var files = []; - var filesByName = {}; var diagnostics = ts.createDiagnosticCollection(); var seenNoDefaultLib = options.noLib; var commonSourceDirectory; @@ -25599,6 +25635,7 @@ var ts; var noDiagnosticsTypeChecker; var start = new Date().getTime(); host = host || createCompilerHost(options); + var filesByName = ts.createFileMap(function (fileName) { return host.getCanonicalFileName(fileName); }); ts.forEach(rootNames, function (name) { return processRootFile(name, false); }); if (!seenNoDefaultLib) { processRootFile(host.getDefaultLibFileName(options), true); @@ -25654,8 +25691,7 @@ var ts; return emitResult; } function getSourceFile(fileName) { - fileName = host.getCanonicalFileName(ts.normalizeSlashes(fileName)); - return ts.hasProperty(filesByName, fileName) ? filesByName[fileName] : undefined; + return filesByName.get(fileName); } function getDiagnosticsHelper(sourceFile, getDiagnostics) { if (sourceFile) { @@ -25751,16 +25787,16 @@ var ts; } function findSourceFile(fileName, isDefaultLib, refFile, refStart, refLength) { var canonicalName = host.getCanonicalFileName(ts.normalizeSlashes(fileName)); - if (ts.hasProperty(filesByName, canonicalName)) { + if (filesByName.contains(canonicalName)) { return getSourceFileFromCache(fileName, canonicalName, false); } else { var normalizedAbsolutePath = ts.getNormalizedAbsolutePath(fileName, host.getCurrentDirectory()); var canonicalAbsolutePath = host.getCanonicalFileName(normalizedAbsolutePath); - if (ts.hasProperty(filesByName, canonicalAbsolutePath)) { + if (filesByName.contains(canonicalAbsolutePath)) { return getSourceFileFromCache(normalizedAbsolutePath, canonicalAbsolutePath, true); } - var file = filesByName[canonicalName] = host.getSourceFile(fileName, options.target, function (hostErrorMessage) { + var file = host.getSourceFile(fileName, options.target, function (hostErrorMessage) { if (refFile) { diagnostics.add(ts.createFileDiagnostic(refFile, refStart, refLength, ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); } @@ -25768,9 +25804,10 @@ var ts; diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); } }); + filesByName.set(canonicalName, file); if (file) { seenNoDefaultLib = seenNoDefaultLib || file.hasNoDefaultLib; - filesByName[canonicalAbsolutePath] = file; + filesByName.set(canonicalAbsolutePath, file); if (!options.noResolve) { var basePath = ts.getDirectoryPath(fileName); processReferencedFiles(file, basePath); @@ -25786,7 +25823,7 @@ var ts; return file; } function getSourceFileFromCache(fileName, canonicalName, useAbsolutePath) { - var file = filesByName[canonicalName]; + var file = filesByName.get(canonicalName); if (file && host.useCaseSensitiveFileNames()) { var sourceFileName = useAbsolutePath ? ts.getNormalizedAbsolutePath(file.fileName, host.getCurrentDirectory()) : file.fileName; if (canonicalName !== sourceFileName) { @@ -31308,8 +31345,7 @@ var ts; var HostCache = (function () { function HostCache(host, getCanonicalFileName) { this.host = host; - this.getCanonicalFileName = getCanonicalFileName; - this.fileNameToEntry = {}; + this.fileNameToEntry = ts.createFileMap(getCanonicalFileName); var rootFileNames = host.getScriptFileNames(); for (var _i = 0; _i < rootFileNames.length; _i++) { var fileName = rootFileNames[_i]; @@ -31320,9 +31356,6 @@ var ts; HostCache.prototype.compilationSettings = function () { return this._compilationSettings; }; - HostCache.prototype.normalizeFileName = function (fileName) { - return this.getCanonicalFileName(ts.normalizeSlashes(fileName)); - }; HostCache.prototype.createEntry = function (fileName) { var entry; var scriptSnapshot = this.host.getScriptSnapshot(fileName); @@ -31333,13 +31366,14 @@ var ts; scriptSnapshot: scriptSnapshot }; } - return this.fileNameToEntry[this.normalizeFileName(fileName)] = entry; + this.fileNameToEntry.set(fileName, entry); + return entry; }; HostCache.prototype.getEntry = function (fileName) { - return ts.lookUp(this.fileNameToEntry, this.normalizeFileName(fileName)); + return this.fileNameToEntry.get(fileName); }; HostCache.prototype.contains = function (fileName) { - return ts.hasProperty(this.fileNameToEntry, this.normalizeFileName(fileName)); + return this.fileNameToEntry.contains(fileName); }; HostCache.prototype.getOrCreateEntry = function (fileName) { if (this.contains(fileName)) { @@ -31348,12 +31382,10 @@ var ts; return this.createEntry(fileName); }; HostCache.prototype.getRootFileNames = function () { - var _this = this; var fileNames = []; - ts.forEachKey(this.fileNameToEntry, function (key) { - var entry = _this.getEntry(key); - if (entry) { - fileNames.push(entry.hostFileName); + this.fileNameToEntry.forEachValue(function (value) { + if (value) { + fileNames.push(value.hostFileName); } }); return fileNames; @@ -31400,7 +31432,7 @@ var ts; sourceFile.version = version; sourceFile.scriptSnapshot = scriptSnapshot; } - function transpile(input, compilerOptions, fileName, diagnostics) { + function transpile(input, compilerOptions, fileName, diagnostics, moduleName) { var options = compilerOptions ? ts.clone(compilerOptions) : getDefaultCompilerOptions(); options.isolatedModules = true; options.allowNonTsExtensions = true; @@ -31408,6 +31440,9 @@ var ts; options.noResolve = true; var inputFileName = fileName || "module.ts"; var sourceFile = ts.createSourceFile(inputFileName, input, options.target); + if (moduleName) { + sourceFile.moduleName = moduleName; + } if (diagnostics && sourceFile.parseDiagnostics) { diagnostics.push.apply(diagnostics, sourceFile.parseDiagnostics); } @@ -31474,8 +31509,14 @@ var ts; return createLanguageServiceSourceFile(sourceFile.fileName, scriptSnapshot, sourceFile.languageVersion, version, true); } ts.updateLanguageServiceSourceFile = updateLanguageServiceSourceFile; - function createDocumentRegistry() { + function createGetCanonicalFileName(useCaseSensitivefileNames) { + return useCaseSensitivefileNames + ? (function (fileName) { return fileName; }) + : (function (fileName) { return fileName.toLowerCase(); }); + } + function createDocumentRegistry(useCaseSensitiveFileNames) { var buckets = {}; + var getCanonicalFileName = createGetCanonicalFileName(!!useCaseSensitiveFileNames); function getKeyFromCompilationSettings(settings) { return "_" + settings.target; } @@ -31483,7 +31524,7 @@ var ts; var key = getKeyFromCompilationSettings(settings); var bucket = ts.lookUp(buckets, key); if (!bucket && createIfMissing) { - buckets[key] = bucket = {}; + buckets[key] = bucket = ts.createFileMap(getCanonicalFileName); } return bucket; } @@ -31492,7 +31533,7 @@ var ts; var entries = ts.lookUp(buckets, name); var sourceFiles = []; for (var i in entries) { - var entry = entries[i]; + var entry = entries.get(i); sourceFiles.push({ name: i, refCount: entry.languageServiceRefCount, @@ -31515,15 +31556,16 @@ var ts; } function acquireOrUpdateDocument(fileName, compilationSettings, scriptSnapshot, version, acquiring) { var bucket = getBucketForCompilationSettings(compilationSettings, true); - var entry = ts.lookUp(bucket, fileName); + var entry = bucket.get(fileName); if (!entry) { ts.Debug.assert(acquiring, "How could we be trying to update a document that the registry doesn't have?"); var sourceFile = createLanguageServiceSourceFile(fileName, scriptSnapshot, compilationSettings.target, version, false); - bucket[fileName] = entry = { + entry = { sourceFile: sourceFile, languageServiceRefCount: 0, owners: [] }; + bucket.set(fileName, entry); } else { if (entry.sourceFile.version !== version) { @@ -31538,11 +31580,11 @@ var ts; function releaseDocument(fileName, compilationSettings) { var bucket = getBucketForCompilationSettings(compilationSettings, false); ts.Debug.assert(bucket !== undefined); - var entry = ts.lookUp(bucket, fileName); + var entry = bucket.get(fileName); entry.languageServiceRefCount--; ts.Debug.assert(entry.languageServiceRefCount >= 0); if (entry.languageServiceRefCount === 0) { - delete bucket[fileName]; + bucket.remove(fileName); } } return { @@ -31887,9 +31929,7 @@ var ts; host.log(message); } } - function getCanonicalFileName(fileName) { - return useCaseSensitivefileNames ? fileName : fileName.toLowerCase(); - } + var getCanonicalFileName = createGetCanonicalFileName(useCaseSensitivefileNames); function getValidSourceFile(fileName) { fileName = ts.normalizeSlashes(fileName); var sourceFile = program.getSourceFile(getCanonicalFileName(fileName)); diff --git a/bin/typescript.d.ts b/bin/typescript.d.ts index 50f5c1ade22..11169b6fa28 100644 --- a/bin/typescript.d.ts +++ b/bin/typescript.d.ts @@ -17,6 +17,13 @@ declare module "typescript" { interface Map { [index: string]: T; } + interface FileMap { + get(fileName: string): T; + set(fileName: string, value: T): void; + contains(fileName: string): boolean; + remove(fileName: string): void; + forEachValue(f: (v: T) => void): void; + } interface TextRange { pos: number; end: number; @@ -748,7 +755,7 @@ declare module "typescript" { path: string; name: string; }[]; - amdModuleName: string; + moduleName: string; referencedFiles: FileReference[]; hasNoDefaultLib: boolean; languageVersion: ScriptTarget; @@ -1391,6 +1398,7 @@ declare module "typescript" { log?(s: string): void; trace?(s: string): void; error?(s: string): void; + useCaseSensitiveFileNames?(): boolean; } interface LanguageService { cleanupSemanticCache(): void; @@ -1847,11 +1855,11 @@ declare module "typescript" { isCancellationRequested(): boolean; throwIfCancellationRequested(): void; } - function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[]): string; + function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[], moduleName?: string): string; function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile; let disableIncrementalParsing: boolean; function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile; - function createDocumentRegistry(): DocumentRegistry; + function createDocumentRegistry(useCaseSensitiveFileNames?: boolean): DocumentRegistry; function preProcessFile(sourceText: string, readImportFiles?: boolean): PreProcessedFileInfo; function createLanguageService(host: LanguageServiceHost, documentRegistry?: DocumentRegistry): LanguageService; function createClassifier(): Classifier; diff --git a/bin/typescript.js b/bin/typescript.js index b393f2ee881..c2f23126ea8 100644 --- a/bin/typescript.js +++ b/bin/typescript.js @@ -706,6 +706,36 @@ var ts; Ternary[Ternary["True"] = -1] = "True"; })(ts.Ternary || (ts.Ternary = {})); var Ternary = ts.Ternary; + function createFileMap(getCanonicalFileName) { + var files = {}; + return { + get: get, + set: set, + contains: contains, + remove: remove, + forEachValue: forEachValueInMap + }; + function set(fileName, value) { + files[normalizeKey(fileName)] = value; + } + function get(fileName) { + return files[normalizeKey(fileName)]; + } + function contains(fileName) { + return hasProperty(files, normalizeKey(fileName)); + } + function remove(fileName) { + var key = normalizeKey(fileName); + delete files[key]; + } + function forEachValueInMap(f) { + forEachValue(files, f); + } + function normalizeKey(key) { + return getCanonicalFileName(normalizeSlashes(key)); + } + } + ts.createFileMap = createFileMap; (function (Comparison) { Comparison[Comparison["LessThan"] = -1] = "LessThan"; Comparison[Comparison["EqualTo"] = 0] = "EqualTo"; @@ -9703,7 +9733,7 @@ var ts; token === 18 /* OpenBracketToken */) { return parsePropertyOrMethodDeclaration(fullStart, decorators, modifiers); } - if (decorators) { + if (decorators || modifiers) { // treat this as a property declaration with a missing name. var name_3 = createMissingNode(65 /* Identifier */, true, ts.Diagnostics.Declaration_expected); return parsePropertyDeclaration(fullStart, decorators, modifiers, name_3, undefined); @@ -10161,7 +10191,7 @@ var ts; case 85 /* ImportKeyword */: return parseImportDeclarationOrImportEqualsDeclaration(fullStart, decorators, modifiers); default: - if (decorators) { + if (decorators || modifiers) { // We reached this point because we encountered an AtToken and assumed a declaration would // follow. For recovery and error reporting purposes, return an incomplete declaration. var node = createMissingNode(219 /* MissingDeclaration */, true, ts.Diagnostics.Declaration_expected); @@ -10242,7 +10272,7 @@ var ts; } sourceFile.referencedFiles = referencedFiles; sourceFile.amdDependencies = amdDependencies; - sourceFile.amdModuleName = amdModuleName; + sourceFile.moduleName = amdModuleName; } function setExternalModuleIndicator(sourceFile) { sourceFile.externalModuleIndicator = ts.forEach(sourceFile.statements, function (node) { @@ -11085,21 +11115,35 @@ var ts; if (!ts.isExternalModule(location)) break; case 206 /* ModuleDeclaration */: - if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 8914931 /* ModuleMember */)) { - if (result.flags & meaning || !(result.flags & 8388608 /* Alias */ && getDeclarationOfAliasSymbol(result).kind === 218 /* ExportSpecifier */)) { - break loop; - } - result = undefined; - } - else if (location.kind === 228 /* SourceFile */ || + var moduleExports = getSymbolOfNode(location).exports; + if (location.kind === 228 /* SourceFile */ || (location.kind === 206 /* ModuleDeclaration */ && location.name.kind === 8 /* StringLiteral */)) { - result = getSymbolOfNode(location).exports["default"]; + // It's an external module. Because of module/namespace merging, a module's exports are in scope, + // yet we never want to treat an export specifier as putting a member in scope. Therefore, + // if the name we find is purely an export specifier, it is not actually considered in scope. + // Two things to note about this: + // 1. We have to check this without calling getSymbol. The problem with calling getSymbol + // on an export specifier is that it might find the export specifier itself, and try to + // resolve it as an alias. This will cause the checker to consider the export specifier + // a circular alias reference when it might not be. + // 2. We check === SymbolFlags.Alias in order to check that the symbol is *purely* + // an alias. If we used &, we'd be throwing out symbols that have non alias aspects, + // which is not the desired behavior. + if (ts.hasProperty(moduleExports, name) && + moduleExports[name].flags === 8388608 /* Alias */ && + ts.getDeclarationOfKind(moduleExports[name], 218 /* ExportSpecifier */)) { + break; + } + result = moduleExports["default"]; var localSymbol = ts.getLocalSymbolForExportDefault(result); if (result && localSymbol && (result.flags & meaning) && localSymbol.name === name) { break loop; } result = undefined; } + if (result = getSymbol(moduleExports, name, meaning & 8914931 /* ModuleMember */)) { + break loop; + } break; case 205 /* EnumDeclaration */: if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 8 /* EnumMember */)) { @@ -28972,10 +29016,10 @@ var ts; emitSetters(exportStarFunction); writeLine(); emitExecute(node, startIndex); - emitTempDeclarations(true); decreaseIndent(); writeLine(); write("}"); // return + emitTempDeclarations(true); } function emitSetters(exportStarFunction) { write("setters:["); @@ -29108,7 +29152,11 @@ var ts; ts.Debug.assert(!exportFunctionForFile); // make sure that name of 'exports' function does not conflict with existing identifiers exportFunctionForFile = makeUniqueName("exports"); - write("System.register(["); + write("System.register("); + if (node.moduleName) { + write("\"" + node.moduleName + "\", "); + } + write("["); for (var i = 0; i < externalImports.length; ++i) { var text = getExternalModuleNameText(externalImports[i]); if (i !== 0) { @@ -29188,8 +29236,8 @@ var ts; collectExternalModuleInfo(node); writeLine(); write("define("); - if (node.amdModuleName) { - write("\"" + node.amdModuleName + "\", "); + if (node.moduleName) { + write("\"" + node.moduleName + "\", "); } emitAMDDependencies(node, true); write(") {"); @@ -29810,7 +29858,6 @@ var ts; function createProgram(rootNames, options, host) { var program; var files = []; - var filesByName = {}; var diagnostics = ts.createDiagnosticCollection(); var seenNoDefaultLib = options.noLib; var commonSourceDirectory; @@ -29818,6 +29865,7 @@ var ts; var noDiagnosticsTypeChecker; var start = new Date().getTime(); host = host || createCompilerHost(options); + var filesByName = ts.createFileMap(function (fileName) { return host.getCanonicalFileName(fileName); }); ts.forEach(rootNames, function (name) { return processRootFile(name, false); }); if (!seenNoDefaultLib) { processRootFile(host.getDefaultLibFileName(options), true); @@ -29883,8 +29931,7 @@ var ts; return emitResult; } function getSourceFile(fileName) { - fileName = host.getCanonicalFileName(ts.normalizeSlashes(fileName)); - return ts.hasProperty(filesByName, fileName) ? filesByName[fileName] : undefined; + return filesByName.get(fileName); } function getDiagnosticsHelper(sourceFile, getDiagnostics) { if (sourceFile) { @@ -29982,18 +30029,18 @@ var ts; // Get source file from normalized fileName function findSourceFile(fileName, isDefaultLib, refFile, refStart, refLength) { var canonicalName = host.getCanonicalFileName(ts.normalizeSlashes(fileName)); - if (ts.hasProperty(filesByName, canonicalName)) { + if (filesByName.contains(canonicalName)) { // We've already looked for this file, use cached result return getSourceFileFromCache(fileName, canonicalName, false); } else { var normalizedAbsolutePath = ts.getNormalizedAbsolutePath(fileName, host.getCurrentDirectory()); var canonicalAbsolutePath = host.getCanonicalFileName(normalizedAbsolutePath); - if (ts.hasProperty(filesByName, canonicalAbsolutePath)) { + if (filesByName.contains(canonicalAbsolutePath)) { return getSourceFileFromCache(normalizedAbsolutePath, canonicalAbsolutePath, true); } // We haven't looked for this file, do so now and cache result - var file = filesByName[canonicalName] = host.getSourceFile(fileName, options.target, function (hostErrorMessage) { + var file = host.getSourceFile(fileName, options.target, function (hostErrorMessage) { if (refFile) { diagnostics.add(ts.createFileDiagnostic(refFile, refStart, refLength, ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); } @@ -30001,10 +30048,11 @@ var ts; diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); } }); + filesByName.set(canonicalName, file); if (file) { seenNoDefaultLib = seenNoDefaultLib || file.hasNoDefaultLib; // Set the source file for normalized absolute path - filesByName[canonicalAbsolutePath] = file; + filesByName.set(canonicalAbsolutePath, file); if (!options.noResolve) { var basePath = ts.getDirectoryPath(fileName); processReferencedFiles(file, basePath); @@ -30020,7 +30068,7 @@ var ts; return file; } function getSourceFileFromCache(fileName, canonicalName, useAbsolutePath) { - var file = filesByName[canonicalName]; + var file = filesByName.get(canonicalName); if (file && host.useCaseSensitiveFileNames()) { var sourceFileName = useAbsolutePath ? ts.getNormalizedAbsolutePath(file.fileName, host.getCurrentDirectory()) : file.fileName; if (canonicalName !== sourceFileName) { @@ -36625,9 +36673,8 @@ var ts; var HostCache = (function () { function HostCache(host, getCanonicalFileName) { this.host = host; - this.getCanonicalFileName = getCanonicalFileName; // script id => script index - this.fileNameToEntry = {}; + this.fileNameToEntry = ts.createFileMap(getCanonicalFileName); // Initialize the list with the root file names var rootFileNames = host.getScriptFileNames(); for (var _i = 0; _i < rootFileNames.length; _i++) { @@ -36640,9 +36687,6 @@ var ts; HostCache.prototype.compilationSettings = function () { return this._compilationSettings; }; - HostCache.prototype.normalizeFileName = function (fileName) { - return this.getCanonicalFileName(ts.normalizeSlashes(fileName)); - }; HostCache.prototype.createEntry = function (fileName) { var entry; var scriptSnapshot = this.host.getScriptSnapshot(fileName); @@ -36653,13 +36697,14 @@ var ts; scriptSnapshot: scriptSnapshot }; } - return this.fileNameToEntry[this.normalizeFileName(fileName)] = entry; + this.fileNameToEntry.set(fileName, entry); + return entry; }; HostCache.prototype.getEntry = function (fileName) { - return ts.lookUp(this.fileNameToEntry, this.normalizeFileName(fileName)); + return this.fileNameToEntry.get(fileName); }; HostCache.prototype.contains = function (fileName) { - return ts.hasProperty(this.fileNameToEntry, this.normalizeFileName(fileName)); + return this.fileNameToEntry.contains(fileName); }; HostCache.prototype.getOrCreateEntry = function (fileName) { if (this.contains(fileName)) { @@ -36668,12 +36713,10 @@ var ts; return this.createEntry(fileName); }; HostCache.prototype.getRootFileNames = function () { - var _this = this; var fileNames = []; - ts.forEachKey(this.fileNameToEntry, function (key) { - var entry = _this.getEntry(key); - if (entry) { - fileNames.push(entry.hostFileName); + this.fileNameToEntry.forEachValue(function (value) { + if (value) { + fileNames.push(value.hostFileName); } }); return fileNames; @@ -36733,7 +36776,7 @@ var ts; * - noLib = true * - noResolve = true */ - function transpile(input, compilerOptions, fileName, diagnostics) { + function transpile(input, compilerOptions, fileName, diagnostics, moduleName) { var options = compilerOptions ? ts.clone(compilerOptions) : getDefaultCompilerOptions(); options.isolatedModules = true; // Filename can be non-ts file. @@ -36747,6 +36790,9 @@ var ts; // Parse var inputFileName = fileName || "module.ts"; var sourceFile = ts.createSourceFile(inputFileName, input, options.target); + if (moduleName) { + sourceFile.moduleName = moduleName; + } // Store syntactic diagnostics if (diagnostics && sourceFile.parseDiagnostics) { diagnostics.push.apply(diagnostics, sourceFile.parseDiagnostics); @@ -36829,10 +36875,16 @@ var ts; return createLanguageServiceSourceFile(sourceFile.fileName, scriptSnapshot, sourceFile.languageVersion, version, true); } ts.updateLanguageServiceSourceFile = updateLanguageServiceSourceFile; - function createDocumentRegistry() { + function createGetCanonicalFileName(useCaseSensitivefileNames) { + return useCaseSensitivefileNames + ? (function (fileName) { return fileName; }) + : (function (fileName) { return fileName.toLowerCase(); }); + } + function createDocumentRegistry(useCaseSensitiveFileNames) { // Maps from compiler setting target (ES3, ES5, etc.) to all the cached documents we have // for those settings. var buckets = {}; + var getCanonicalFileName = createGetCanonicalFileName(!!useCaseSensitiveFileNames); function getKeyFromCompilationSettings(settings) { return "_" + settings.target; // + "|" + settings.propagateEnumConstantoString() } @@ -36840,7 +36892,7 @@ var ts; var key = getKeyFromCompilationSettings(settings); var bucket = ts.lookUp(buckets, key); if (!bucket && createIfMissing) { - buckets[key] = bucket = {}; + buckets[key] = bucket = ts.createFileMap(getCanonicalFileName); } return bucket; } @@ -36849,7 +36901,7 @@ var ts; var entries = ts.lookUp(buckets, name); var sourceFiles = []; for (var i in entries) { - var entry = entries[i]; + var entry = entries.get(i); sourceFiles.push({ name: i, refCount: entry.languageServiceRefCount, @@ -36872,16 +36924,17 @@ var ts; } function acquireOrUpdateDocument(fileName, compilationSettings, scriptSnapshot, version, acquiring) { var bucket = getBucketForCompilationSettings(compilationSettings, true); - var entry = ts.lookUp(bucket, fileName); + var entry = bucket.get(fileName); if (!entry) { ts.Debug.assert(acquiring, "How could we be trying to update a document that the registry doesn't have?"); // Have never seen this file with these settings. Create a new source file for it. var sourceFile = createLanguageServiceSourceFile(fileName, scriptSnapshot, compilationSettings.target, version, false); - bucket[fileName] = entry = { + entry = { sourceFile: sourceFile, languageServiceRefCount: 0, owners: [] }; + bucket.set(fileName, entry); } else { // We have an entry for this file. However, it may be for a different version of @@ -36904,11 +36957,11 @@ var ts; function releaseDocument(fileName, compilationSettings) { var bucket = getBucketForCompilationSettings(compilationSettings, false); ts.Debug.assert(bucket !== undefined); - var entry = ts.lookUp(bucket, fileName); + var entry = bucket.get(fileName); entry.languageServiceRefCount--; ts.Debug.assert(entry.languageServiceRefCount >= 0); if (entry.languageServiceRefCount === 0) { - delete bucket[fileName]; + bucket.remove(fileName); } } return { @@ -37305,9 +37358,7 @@ var ts; host.log(message); } } - function getCanonicalFileName(fileName) { - return useCaseSensitivefileNames ? fileName : fileName.toLowerCase(); - } + var getCanonicalFileName = createGetCanonicalFileName(useCaseSensitivefileNames); function getValidSourceFile(fileName) { fileName = ts.normalizeSlashes(fileName); var sourceFile = program.getSourceFile(getCanonicalFileName(fileName)); @@ -41901,12 +41952,18 @@ var ts; var LanguageServiceShimHostAdapter = (function () { function LanguageServiceShimHostAdapter(shimHost) { this.shimHost = shimHost; + this.loggingEnabled = false; + this.tracingEnabled = false; } LanguageServiceShimHostAdapter.prototype.log = function (s) { - this.shimHost.log(s); + if (this.loggingEnabled) { + this.shimHost.log(s); + } }; LanguageServiceShimHostAdapter.prototype.trace = function (s) { - this.shimHost.trace(s); + if (this.tracingEnabled) { + this.shimHost.trace(s); + } }; LanguageServiceShimHostAdapter.prototype.error = function (s) { this.shimHost.error(s); @@ -41918,6 +41975,9 @@ var ts; } return this.shimHost.getProjectVersion(); }; + LanguageServiceShimHostAdapter.prototype.useCaseSensitiveFileNames = function () { + return this.shimHost.useCaseSensitiveFileNames ? this.shimHost.useCaseSensitiveFileNames() : false; + }; LanguageServiceShimHostAdapter.prototype.getCompilationSettings = function () { var settingsJson = this.shimHost.getCompilationSettings(); if (settingsJson == null || settingsJson == "") { @@ -41985,13 +42045,13 @@ var ts; return CoreServicesShimHostAdapter; })(); ts.CoreServicesShimHostAdapter = CoreServicesShimHostAdapter; - function simpleForwardCall(logger, actionDescription, action, noPerfLogging) { - if (!noPerfLogging) { + function simpleForwardCall(logger, actionDescription, action, logPerformance) { + if (logPerformance) { logger.log(actionDescription); var start = Date.now(); } var result = action(); - if (!noPerfLogging) { + if (logPerformance) { var end = Date.now(); logger.log(actionDescription + " completed in " + (end - start) + " msec"); if (typeof (result) === "string") { @@ -42004,9 +42064,9 @@ var ts; } return result; } - function forwardJSONCall(logger, actionDescription, action, noPerfLogging) { + function forwardJSONCall(logger, actionDescription, action, logPerformance) { try { - var result = simpleForwardCall(logger, actionDescription, action, noPerfLogging); + var result = simpleForwardCall(logger, actionDescription, action, logPerformance); return JSON.stringify({ result: result }); } catch (err) { @@ -42048,10 +42108,11 @@ var ts; _super.call(this, factory); this.host = host; this.languageService = languageService; + this.logPerformance = false; this.logger = this.host; } LanguageServiceShimObject.prototype.forwardJSONCall = function (actionDescription, action) { - return forwardJSONCall(this.logger, actionDescription, action, false); + return forwardJSONCall(this.logger, actionDescription, action, this.logPerformance); }; /// DISPOSE /** @@ -42358,12 +42419,12 @@ var ts; function ClassifierShimObject(factory, logger) { _super.call(this, factory); this.logger = logger; + this.logPerformance = false; this.classifier = ts.createClassifier(); } ClassifierShimObject.prototype.getEncodedLexicalClassifications = function (text, lexState, syntacticClassifierAbsent) { var _this = this; - return forwardJSONCall(this.logger, "getEncodedLexicalClassifications", function () { return convertClassifications(_this.classifier.getEncodedLexicalClassifications(text, lexState, syntacticClassifierAbsent)); }, - /*noPerfLogging:*/ true); + return forwardJSONCall(this.logger, "getEncodedLexicalClassifications", function () { return convertClassifications(_this.classifier.getEncodedLexicalClassifications(text, lexState, syntacticClassifierAbsent)); }, this.logPerformance); }; /// COLORIZATION ClassifierShimObject.prototype.getClassificationsForLine = function (text, lexState, classifyKeywordsInGenerics) { @@ -42385,9 +42446,10 @@ var ts; _super.call(this, factory); this.logger = logger; this.host = host; + this.logPerformance = false; } CoreServicesShimObject.prototype.forwardJSONCall = function (actionDescription, action) { - return forwardJSONCall(this.logger, actionDescription, action, false); + return forwardJSONCall(this.logger, actionDescription, action, this.logPerformance); }; CoreServicesShimObject.prototype.getPreProcessedFileInfo = function (fileName, sourceTextSnapshot) { return this.forwardJSONCall("getPreProcessedFileInfo('" + fileName + "')", function () { @@ -42444,7 +42506,6 @@ var ts; var TypeScriptServicesFactory = (function () { function TypeScriptServicesFactory() { this._shims = []; - this.documentRegistry = ts.createDocumentRegistry(); } /* * Returns script API version. @@ -42454,6 +42515,9 @@ var ts; }; TypeScriptServicesFactory.prototype.createLanguageServiceShim = function (host) { try { + if (this.documentRegistry === undefined) { + this.documentRegistry = ts.createDocumentRegistry(host.useCaseSensitiveFileNames && host.useCaseSensitiveFileNames()); + } var hostAdapter = new LanguageServiceShimHostAdapter(host); var languageService = ts.createLanguageService(hostAdapter, this.documentRegistry); return new LanguageServiceShimObject(this, host, languageService); diff --git a/bin/typescriptServices.d.ts b/bin/typescriptServices.d.ts index 558504fcede..ae49ab102ad 100644 --- a/bin/typescriptServices.d.ts +++ b/bin/typescriptServices.d.ts @@ -17,6 +17,13 @@ declare module ts { interface Map { [index: string]: T; } + interface FileMap { + get(fileName: string): T; + set(fileName: string, value: T): void; + contains(fileName: string): boolean; + remove(fileName: string): void; + forEachValue(f: (v: T) => void): void; + } interface TextRange { pos: number; end: number; @@ -748,7 +755,7 @@ declare module ts { path: string; name: string; }[]; - amdModuleName: string; + moduleName: string; referencedFiles: FileReference[]; hasNoDefaultLib: boolean; languageVersion: ScriptTarget; @@ -1391,6 +1398,7 @@ declare module ts { log?(s: string): void; trace?(s: string): void; error?(s: string): void; + useCaseSensitiveFileNames?(): boolean; } interface LanguageService { cleanupSemanticCache(): void; @@ -1847,11 +1855,11 @@ declare module ts { isCancellationRequested(): boolean; throwIfCancellationRequested(): void; } - function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[]): string; + function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[], moduleName?: string): string; function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile; let disableIncrementalParsing: boolean; function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile; - function createDocumentRegistry(): DocumentRegistry; + function createDocumentRegistry(useCaseSensitiveFileNames?: boolean): DocumentRegistry; function preProcessFile(sourceText: string, readImportFiles?: boolean): PreProcessedFileInfo; function createLanguageService(host: LanguageServiceHost, documentRegistry?: DocumentRegistry): LanguageService; function createClassifier(): Classifier; diff --git a/bin/typescriptServices.js b/bin/typescriptServices.js index b393f2ee881..c2f23126ea8 100644 --- a/bin/typescriptServices.js +++ b/bin/typescriptServices.js @@ -706,6 +706,36 @@ var ts; Ternary[Ternary["True"] = -1] = "True"; })(ts.Ternary || (ts.Ternary = {})); var Ternary = ts.Ternary; + function createFileMap(getCanonicalFileName) { + var files = {}; + return { + get: get, + set: set, + contains: contains, + remove: remove, + forEachValue: forEachValueInMap + }; + function set(fileName, value) { + files[normalizeKey(fileName)] = value; + } + function get(fileName) { + return files[normalizeKey(fileName)]; + } + function contains(fileName) { + return hasProperty(files, normalizeKey(fileName)); + } + function remove(fileName) { + var key = normalizeKey(fileName); + delete files[key]; + } + function forEachValueInMap(f) { + forEachValue(files, f); + } + function normalizeKey(key) { + return getCanonicalFileName(normalizeSlashes(key)); + } + } + ts.createFileMap = createFileMap; (function (Comparison) { Comparison[Comparison["LessThan"] = -1] = "LessThan"; Comparison[Comparison["EqualTo"] = 0] = "EqualTo"; @@ -9703,7 +9733,7 @@ var ts; token === 18 /* OpenBracketToken */) { return parsePropertyOrMethodDeclaration(fullStart, decorators, modifiers); } - if (decorators) { + if (decorators || modifiers) { // treat this as a property declaration with a missing name. var name_3 = createMissingNode(65 /* Identifier */, true, ts.Diagnostics.Declaration_expected); return parsePropertyDeclaration(fullStart, decorators, modifiers, name_3, undefined); @@ -10161,7 +10191,7 @@ var ts; case 85 /* ImportKeyword */: return parseImportDeclarationOrImportEqualsDeclaration(fullStart, decorators, modifiers); default: - if (decorators) { + if (decorators || modifiers) { // We reached this point because we encountered an AtToken and assumed a declaration would // follow. For recovery and error reporting purposes, return an incomplete declaration. var node = createMissingNode(219 /* MissingDeclaration */, true, ts.Diagnostics.Declaration_expected); @@ -10242,7 +10272,7 @@ var ts; } sourceFile.referencedFiles = referencedFiles; sourceFile.amdDependencies = amdDependencies; - sourceFile.amdModuleName = amdModuleName; + sourceFile.moduleName = amdModuleName; } function setExternalModuleIndicator(sourceFile) { sourceFile.externalModuleIndicator = ts.forEach(sourceFile.statements, function (node) { @@ -11085,21 +11115,35 @@ var ts; if (!ts.isExternalModule(location)) break; case 206 /* ModuleDeclaration */: - if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 8914931 /* ModuleMember */)) { - if (result.flags & meaning || !(result.flags & 8388608 /* Alias */ && getDeclarationOfAliasSymbol(result).kind === 218 /* ExportSpecifier */)) { - break loop; - } - result = undefined; - } - else if (location.kind === 228 /* SourceFile */ || + var moduleExports = getSymbolOfNode(location).exports; + if (location.kind === 228 /* SourceFile */ || (location.kind === 206 /* ModuleDeclaration */ && location.name.kind === 8 /* StringLiteral */)) { - result = getSymbolOfNode(location).exports["default"]; + // It's an external module. Because of module/namespace merging, a module's exports are in scope, + // yet we never want to treat an export specifier as putting a member in scope. Therefore, + // if the name we find is purely an export specifier, it is not actually considered in scope. + // Two things to note about this: + // 1. We have to check this without calling getSymbol. The problem with calling getSymbol + // on an export specifier is that it might find the export specifier itself, and try to + // resolve it as an alias. This will cause the checker to consider the export specifier + // a circular alias reference when it might not be. + // 2. We check === SymbolFlags.Alias in order to check that the symbol is *purely* + // an alias. If we used &, we'd be throwing out symbols that have non alias aspects, + // which is not the desired behavior. + if (ts.hasProperty(moduleExports, name) && + moduleExports[name].flags === 8388608 /* Alias */ && + ts.getDeclarationOfKind(moduleExports[name], 218 /* ExportSpecifier */)) { + break; + } + result = moduleExports["default"]; var localSymbol = ts.getLocalSymbolForExportDefault(result); if (result && localSymbol && (result.flags & meaning) && localSymbol.name === name) { break loop; } result = undefined; } + if (result = getSymbol(moduleExports, name, meaning & 8914931 /* ModuleMember */)) { + break loop; + } break; case 205 /* EnumDeclaration */: if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 8 /* EnumMember */)) { @@ -28972,10 +29016,10 @@ var ts; emitSetters(exportStarFunction); writeLine(); emitExecute(node, startIndex); - emitTempDeclarations(true); decreaseIndent(); writeLine(); write("}"); // return + emitTempDeclarations(true); } function emitSetters(exportStarFunction) { write("setters:["); @@ -29108,7 +29152,11 @@ var ts; ts.Debug.assert(!exportFunctionForFile); // make sure that name of 'exports' function does not conflict with existing identifiers exportFunctionForFile = makeUniqueName("exports"); - write("System.register(["); + write("System.register("); + if (node.moduleName) { + write("\"" + node.moduleName + "\", "); + } + write("["); for (var i = 0; i < externalImports.length; ++i) { var text = getExternalModuleNameText(externalImports[i]); if (i !== 0) { @@ -29188,8 +29236,8 @@ var ts; collectExternalModuleInfo(node); writeLine(); write("define("); - if (node.amdModuleName) { - write("\"" + node.amdModuleName + "\", "); + if (node.moduleName) { + write("\"" + node.moduleName + "\", "); } emitAMDDependencies(node, true); write(") {"); @@ -29810,7 +29858,6 @@ var ts; function createProgram(rootNames, options, host) { var program; var files = []; - var filesByName = {}; var diagnostics = ts.createDiagnosticCollection(); var seenNoDefaultLib = options.noLib; var commonSourceDirectory; @@ -29818,6 +29865,7 @@ var ts; var noDiagnosticsTypeChecker; var start = new Date().getTime(); host = host || createCompilerHost(options); + var filesByName = ts.createFileMap(function (fileName) { return host.getCanonicalFileName(fileName); }); ts.forEach(rootNames, function (name) { return processRootFile(name, false); }); if (!seenNoDefaultLib) { processRootFile(host.getDefaultLibFileName(options), true); @@ -29883,8 +29931,7 @@ var ts; return emitResult; } function getSourceFile(fileName) { - fileName = host.getCanonicalFileName(ts.normalizeSlashes(fileName)); - return ts.hasProperty(filesByName, fileName) ? filesByName[fileName] : undefined; + return filesByName.get(fileName); } function getDiagnosticsHelper(sourceFile, getDiagnostics) { if (sourceFile) { @@ -29982,18 +30029,18 @@ var ts; // Get source file from normalized fileName function findSourceFile(fileName, isDefaultLib, refFile, refStart, refLength) { var canonicalName = host.getCanonicalFileName(ts.normalizeSlashes(fileName)); - if (ts.hasProperty(filesByName, canonicalName)) { + if (filesByName.contains(canonicalName)) { // We've already looked for this file, use cached result return getSourceFileFromCache(fileName, canonicalName, false); } else { var normalizedAbsolutePath = ts.getNormalizedAbsolutePath(fileName, host.getCurrentDirectory()); var canonicalAbsolutePath = host.getCanonicalFileName(normalizedAbsolutePath); - if (ts.hasProperty(filesByName, canonicalAbsolutePath)) { + if (filesByName.contains(canonicalAbsolutePath)) { return getSourceFileFromCache(normalizedAbsolutePath, canonicalAbsolutePath, true); } // We haven't looked for this file, do so now and cache result - var file = filesByName[canonicalName] = host.getSourceFile(fileName, options.target, function (hostErrorMessage) { + var file = host.getSourceFile(fileName, options.target, function (hostErrorMessage) { if (refFile) { diagnostics.add(ts.createFileDiagnostic(refFile, refStart, refLength, ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); } @@ -30001,10 +30048,11 @@ var ts; diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Cannot_read_file_0_Colon_1, fileName, hostErrorMessage)); } }); + filesByName.set(canonicalName, file); if (file) { seenNoDefaultLib = seenNoDefaultLib || file.hasNoDefaultLib; // Set the source file for normalized absolute path - filesByName[canonicalAbsolutePath] = file; + filesByName.set(canonicalAbsolutePath, file); if (!options.noResolve) { var basePath = ts.getDirectoryPath(fileName); processReferencedFiles(file, basePath); @@ -30020,7 +30068,7 @@ var ts; return file; } function getSourceFileFromCache(fileName, canonicalName, useAbsolutePath) { - var file = filesByName[canonicalName]; + var file = filesByName.get(canonicalName); if (file && host.useCaseSensitiveFileNames()) { var sourceFileName = useAbsolutePath ? ts.getNormalizedAbsolutePath(file.fileName, host.getCurrentDirectory()) : file.fileName; if (canonicalName !== sourceFileName) { @@ -36625,9 +36673,8 @@ var ts; var HostCache = (function () { function HostCache(host, getCanonicalFileName) { this.host = host; - this.getCanonicalFileName = getCanonicalFileName; // script id => script index - this.fileNameToEntry = {}; + this.fileNameToEntry = ts.createFileMap(getCanonicalFileName); // Initialize the list with the root file names var rootFileNames = host.getScriptFileNames(); for (var _i = 0; _i < rootFileNames.length; _i++) { @@ -36640,9 +36687,6 @@ var ts; HostCache.prototype.compilationSettings = function () { return this._compilationSettings; }; - HostCache.prototype.normalizeFileName = function (fileName) { - return this.getCanonicalFileName(ts.normalizeSlashes(fileName)); - }; HostCache.prototype.createEntry = function (fileName) { var entry; var scriptSnapshot = this.host.getScriptSnapshot(fileName); @@ -36653,13 +36697,14 @@ var ts; scriptSnapshot: scriptSnapshot }; } - return this.fileNameToEntry[this.normalizeFileName(fileName)] = entry; + this.fileNameToEntry.set(fileName, entry); + return entry; }; HostCache.prototype.getEntry = function (fileName) { - return ts.lookUp(this.fileNameToEntry, this.normalizeFileName(fileName)); + return this.fileNameToEntry.get(fileName); }; HostCache.prototype.contains = function (fileName) { - return ts.hasProperty(this.fileNameToEntry, this.normalizeFileName(fileName)); + return this.fileNameToEntry.contains(fileName); }; HostCache.prototype.getOrCreateEntry = function (fileName) { if (this.contains(fileName)) { @@ -36668,12 +36713,10 @@ var ts; return this.createEntry(fileName); }; HostCache.prototype.getRootFileNames = function () { - var _this = this; var fileNames = []; - ts.forEachKey(this.fileNameToEntry, function (key) { - var entry = _this.getEntry(key); - if (entry) { - fileNames.push(entry.hostFileName); + this.fileNameToEntry.forEachValue(function (value) { + if (value) { + fileNames.push(value.hostFileName); } }); return fileNames; @@ -36733,7 +36776,7 @@ var ts; * - noLib = true * - noResolve = true */ - function transpile(input, compilerOptions, fileName, diagnostics) { + function transpile(input, compilerOptions, fileName, diagnostics, moduleName) { var options = compilerOptions ? ts.clone(compilerOptions) : getDefaultCompilerOptions(); options.isolatedModules = true; // Filename can be non-ts file. @@ -36747,6 +36790,9 @@ var ts; // Parse var inputFileName = fileName || "module.ts"; var sourceFile = ts.createSourceFile(inputFileName, input, options.target); + if (moduleName) { + sourceFile.moduleName = moduleName; + } // Store syntactic diagnostics if (diagnostics && sourceFile.parseDiagnostics) { diagnostics.push.apply(diagnostics, sourceFile.parseDiagnostics); @@ -36829,10 +36875,16 @@ var ts; return createLanguageServiceSourceFile(sourceFile.fileName, scriptSnapshot, sourceFile.languageVersion, version, true); } ts.updateLanguageServiceSourceFile = updateLanguageServiceSourceFile; - function createDocumentRegistry() { + function createGetCanonicalFileName(useCaseSensitivefileNames) { + return useCaseSensitivefileNames + ? (function (fileName) { return fileName; }) + : (function (fileName) { return fileName.toLowerCase(); }); + } + function createDocumentRegistry(useCaseSensitiveFileNames) { // Maps from compiler setting target (ES3, ES5, etc.) to all the cached documents we have // for those settings. var buckets = {}; + var getCanonicalFileName = createGetCanonicalFileName(!!useCaseSensitiveFileNames); function getKeyFromCompilationSettings(settings) { return "_" + settings.target; // + "|" + settings.propagateEnumConstantoString() } @@ -36840,7 +36892,7 @@ var ts; var key = getKeyFromCompilationSettings(settings); var bucket = ts.lookUp(buckets, key); if (!bucket && createIfMissing) { - buckets[key] = bucket = {}; + buckets[key] = bucket = ts.createFileMap(getCanonicalFileName); } return bucket; } @@ -36849,7 +36901,7 @@ var ts; var entries = ts.lookUp(buckets, name); var sourceFiles = []; for (var i in entries) { - var entry = entries[i]; + var entry = entries.get(i); sourceFiles.push({ name: i, refCount: entry.languageServiceRefCount, @@ -36872,16 +36924,17 @@ var ts; } function acquireOrUpdateDocument(fileName, compilationSettings, scriptSnapshot, version, acquiring) { var bucket = getBucketForCompilationSettings(compilationSettings, true); - var entry = ts.lookUp(bucket, fileName); + var entry = bucket.get(fileName); if (!entry) { ts.Debug.assert(acquiring, "How could we be trying to update a document that the registry doesn't have?"); // Have never seen this file with these settings. Create a new source file for it. var sourceFile = createLanguageServiceSourceFile(fileName, scriptSnapshot, compilationSettings.target, version, false); - bucket[fileName] = entry = { + entry = { sourceFile: sourceFile, languageServiceRefCount: 0, owners: [] }; + bucket.set(fileName, entry); } else { // We have an entry for this file. However, it may be for a different version of @@ -36904,11 +36957,11 @@ var ts; function releaseDocument(fileName, compilationSettings) { var bucket = getBucketForCompilationSettings(compilationSettings, false); ts.Debug.assert(bucket !== undefined); - var entry = ts.lookUp(bucket, fileName); + var entry = bucket.get(fileName); entry.languageServiceRefCount--; ts.Debug.assert(entry.languageServiceRefCount >= 0); if (entry.languageServiceRefCount === 0) { - delete bucket[fileName]; + bucket.remove(fileName); } } return { @@ -37305,9 +37358,7 @@ var ts; host.log(message); } } - function getCanonicalFileName(fileName) { - return useCaseSensitivefileNames ? fileName : fileName.toLowerCase(); - } + var getCanonicalFileName = createGetCanonicalFileName(useCaseSensitivefileNames); function getValidSourceFile(fileName) { fileName = ts.normalizeSlashes(fileName); var sourceFile = program.getSourceFile(getCanonicalFileName(fileName)); @@ -41901,12 +41952,18 @@ var ts; var LanguageServiceShimHostAdapter = (function () { function LanguageServiceShimHostAdapter(shimHost) { this.shimHost = shimHost; + this.loggingEnabled = false; + this.tracingEnabled = false; } LanguageServiceShimHostAdapter.prototype.log = function (s) { - this.shimHost.log(s); + if (this.loggingEnabled) { + this.shimHost.log(s); + } }; LanguageServiceShimHostAdapter.prototype.trace = function (s) { - this.shimHost.trace(s); + if (this.tracingEnabled) { + this.shimHost.trace(s); + } }; LanguageServiceShimHostAdapter.prototype.error = function (s) { this.shimHost.error(s); @@ -41918,6 +41975,9 @@ var ts; } return this.shimHost.getProjectVersion(); }; + LanguageServiceShimHostAdapter.prototype.useCaseSensitiveFileNames = function () { + return this.shimHost.useCaseSensitiveFileNames ? this.shimHost.useCaseSensitiveFileNames() : false; + }; LanguageServiceShimHostAdapter.prototype.getCompilationSettings = function () { var settingsJson = this.shimHost.getCompilationSettings(); if (settingsJson == null || settingsJson == "") { @@ -41985,13 +42045,13 @@ var ts; return CoreServicesShimHostAdapter; })(); ts.CoreServicesShimHostAdapter = CoreServicesShimHostAdapter; - function simpleForwardCall(logger, actionDescription, action, noPerfLogging) { - if (!noPerfLogging) { + function simpleForwardCall(logger, actionDescription, action, logPerformance) { + if (logPerformance) { logger.log(actionDescription); var start = Date.now(); } var result = action(); - if (!noPerfLogging) { + if (logPerformance) { var end = Date.now(); logger.log(actionDescription + " completed in " + (end - start) + " msec"); if (typeof (result) === "string") { @@ -42004,9 +42064,9 @@ var ts; } return result; } - function forwardJSONCall(logger, actionDescription, action, noPerfLogging) { + function forwardJSONCall(logger, actionDescription, action, logPerformance) { try { - var result = simpleForwardCall(logger, actionDescription, action, noPerfLogging); + var result = simpleForwardCall(logger, actionDescription, action, logPerformance); return JSON.stringify({ result: result }); } catch (err) { @@ -42048,10 +42108,11 @@ var ts; _super.call(this, factory); this.host = host; this.languageService = languageService; + this.logPerformance = false; this.logger = this.host; } LanguageServiceShimObject.prototype.forwardJSONCall = function (actionDescription, action) { - return forwardJSONCall(this.logger, actionDescription, action, false); + return forwardJSONCall(this.logger, actionDescription, action, this.logPerformance); }; /// DISPOSE /** @@ -42358,12 +42419,12 @@ var ts; function ClassifierShimObject(factory, logger) { _super.call(this, factory); this.logger = logger; + this.logPerformance = false; this.classifier = ts.createClassifier(); } ClassifierShimObject.prototype.getEncodedLexicalClassifications = function (text, lexState, syntacticClassifierAbsent) { var _this = this; - return forwardJSONCall(this.logger, "getEncodedLexicalClassifications", function () { return convertClassifications(_this.classifier.getEncodedLexicalClassifications(text, lexState, syntacticClassifierAbsent)); }, - /*noPerfLogging:*/ true); + return forwardJSONCall(this.logger, "getEncodedLexicalClassifications", function () { return convertClassifications(_this.classifier.getEncodedLexicalClassifications(text, lexState, syntacticClassifierAbsent)); }, this.logPerformance); }; /// COLORIZATION ClassifierShimObject.prototype.getClassificationsForLine = function (text, lexState, classifyKeywordsInGenerics) { @@ -42385,9 +42446,10 @@ var ts; _super.call(this, factory); this.logger = logger; this.host = host; + this.logPerformance = false; } CoreServicesShimObject.prototype.forwardJSONCall = function (actionDescription, action) { - return forwardJSONCall(this.logger, actionDescription, action, false); + return forwardJSONCall(this.logger, actionDescription, action, this.logPerformance); }; CoreServicesShimObject.prototype.getPreProcessedFileInfo = function (fileName, sourceTextSnapshot) { return this.forwardJSONCall("getPreProcessedFileInfo('" + fileName + "')", function () { @@ -42444,7 +42506,6 @@ var ts; var TypeScriptServicesFactory = (function () { function TypeScriptServicesFactory() { this._shims = []; - this.documentRegistry = ts.createDocumentRegistry(); } /* * Returns script API version. @@ -42454,6 +42515,9 @@ var ts; }; TypeScriptServicesFactory.prototype.createLanguageServiceShim = function (host) { try { + if (this.documentRegistry === undefined) { + this.documentRegistry = ts.createDocumentRegistry(host.useCaseSensitiveFileNames && host.useCaseSensitiveFileNames()); + } var hostAdapter = new LanguageServiceShimHostAdapter(host); var languageService = ts.createLanguageService(hostAdapter, this.documentRegistry); return new LanguageServiceShimObject(this, host, languageService);