Comparing version 0.2.5 to 0.2.6
@@ -103,5 +103,12 @@ import { SourceMapConsumer, SourceMapGenerator } from 'source-map'; | ||
sourceMapConsumerToGenerator(sourceMapConsumer: SourceMapConsumer): SourceMapGenerator; | ||
sourceMapGeneratorToConsumer(sourceMapGenerator: SourceMapGenerator): SourceMapConsumer; | ||
/** | ||
* Tsc identifies source files by their relative path to the output file. Since | ||
* there's no easy way to identify these relative paths when tsickle generates its | ||
* own source maps, we patch them with the file name from the tsc source maps | ||
* before composing them. | ||
*/ | ||
sourceMapGeneratorToConsumerWithFileName(sourceMapGenerator: SourceMapGenerator, fileName: string): SourceMapConsumer; | ||
sourceMapTextToConsumer(sourceMapText: string): SourceMapConsumer; | ||
combineSourceMaps(tscSourceMapText: string): string; | ||
getSourceMapKey(outputFilePath: string, sourceFileName: string): string; | ||
combineSourceMaps(filePath: string, tscSourceMapText: string): string; | ||
convertCommonJsToGoogModule(fileName: string, content: string): string; | ||
@@ -108,0 +115,0 @@ private downlevelDecorators(sourceFile, program, fileName, languageVersion); |
@@ -78,3 +78,3 @@ "use strict"; | ||
else { | ||
content = this.combineSourceMaps(content); | ||
content = this.combineSourceMaps(fileName, content); | ||
} | ||
@@ -86,4 +86,12 @@ this.delegate.writeFile(fileName, content, writeByteOrderMark, onError, sourceFiles); | ||
}; | ||
TsickleCompilerHost.prototype.sourceMapGeneratorToConsumer = function (sourceMapGenerator) { | ||
/** | ||
* Tsc identifies source files by their relative path to the output file. Since | ||
* there's no easy way to identify these relative paths when tsickle generates its | ||
* own source maps, we patch them with the file name from the tsc source maps | ||
* before composing them. | ||
*/ | ||
TsickleCompilerHost.prototype.sourceMapGeneratorToConsumerWithFileName = function (sourceMapGenerator, fileName) { | ||
var rawSourceMap = sourceMapGenerator.toJSON(); | ||
rawSourceMap.sources = [fileName]; | ||
rawSourceMap.file = fileName; | ||
return new source_map_1.SourceMapConsumer(rawSourceMap); | ||
@@ -95,3 +103,7 @@ }; | ||
}; | ||
TsickleCompilerHost.prototype.combineSourceMaps = function (tscSourceMapText) { | ||
TsickleCompilerHost.prototype.getSourceMapKey = function (outputFilePath, sourceFileName) { | ||
var fileDir = path.dirname(outputFilePath); | ||
return this.getCanonicalFileName(path.resolve(fileDir, sourceFileName)); | ||
}; | ||
TsickleCompilerHost.prototype.combineSourceMaps = function (filePath, tscSourceMapText) { | ||
var tscSourceMapConsumer = this.sourceMapTextToConsumer(tscSourceMapText); | ||
@@ -103,4 +115,5 @@ var tscSourceMapGenerator = this.sourceMapConsumerToGenerator(tscSourceMapConsumer); | ||
var sourceFileName = _a[_i]; | ||
var tsickleSourceMapGenerator = this.tsickleSourceMaps.get(sourceFileName); | ||
var tsickleSourceMapConsumer = this.sourceMapGeneratorToConsumer(tsickleSourceMapGenerator); | ||
var sourceMapKey = this.getSourceMapKey(filePath, sourceFileName); | ||
var tsickleSourceMapGenerator = this.tsickleSourceMaps.get(sourceMapKey); | ||
var tsickleSourceMapConsumer = this.sourceMapGeneratorToConsumerWithFileName(tsickleSourceMapGenerator, sourceFileName); | ||
tscSourceMapGenerator.applySourceMap(tsickleSourceMapConsumer); | ||
@@ -113,4 +126,5 @@ } | ||
var sourceFileName = _c[_b]; | ||
var decoratorDownlevelSourceMapGenerator = this.decoratorDownlevelSourceMaps.get(sourceFileName); | ||
var decoratorDownlevelSourceMapConsumer = this.sourceMapGeneratorToConsumer(decoratorDownlevelSourceMapGenerator); | ||
var sourceMapKey = this.getSourceMapKey(filePath, sourceFileName); | ||
var decoratorDownlevelSourceMapGenerator = this.decoratorDownlevelSourceMaps.get(sourceMapKey); | ||
var decoratorDownlevelSourceMapConsumer = this.sourceMapGeneratorToConsumerWithFileName(decoratorDownlevelSourceMapGenerator, sourceFileName); | ||
tscSourceMapGenerator.applySourceMap(decoratorDownlevelSourceMapConsumer); | ||
@@ -133,2 +147,3 @@ } | ||
TsickleCompilerHost.prototype.downlevelDecorators = function (sourceFile, program, fileName, languageVersion) { | ||
this.decoratorDownlevelSourceMaps.set(this.getCanonicalFileName(sourceFile.path), new source_map_1.SourceMapGenerator()); | ||
if (this.environment.shouldSkipTsickleProcessing(fileName)) | ||
@@ -146,3 +161,3 @@ return sourceFile; | ||
fileContent = converted.output + ANNOTATION_SUPPORT; | ||
this.decoratorDownlevelSourceMaps.set(fileName, converted.sourceMap); | ||
this.decoratorDownlevelSourceMaps.set(this.getCanonicalFileName(sourceFile.path), converted.sourceMap); | ||
return ts.createSourceFile(fileName, fileContent, languageVersion, true); | ||
@@ -152,2 +167,3 @@ var _a; | ||
TsickleCompilerHost.prototype.closurize = function (sourceFile, program, fileName, languageVersion) { | ||
this.tsickleSourceMaps.set(this.getCanonicalFileName(sourceFile.path), new source_map_1.SourceMapGenerator()); | ||
var isDefinitions = /\.d\.ts$/.test(fileName); | ||
@@ -170,3 +186,3 @@ // Don't tsickle-process any d.ts that isn't a compilation target; | ||
this.diagnostics = diagnostics; | ||
this.tsickleSourceMaps.set(path.parse(fileName).base, sourceMap); | ||
this.tsickleSourceMaps.set(this.getCanonicalFileName(sourceFile.path), sourceMap); | ||
return ts.createSourceFile(fileName, output, languageVersion, true); | ||
@@ -173,0 +189,0 @@ }; |
{ | ||
"name": "tsickle", | ||
"version": "0.2.5", | ||
"version": "0.2.6", | ||
"description": "Transpile TypeScript code to JavaScript with Closure annotations.", | ||
@@ -5,0 +5,0 @@ "main": "build/src/tsickle.js", |
@@ -148,3 +148,3 @@ import * as path from 'path'; | ||
} else { | ||
content = this.combineSourceMaps(content); | ||
content = this.combineSourceMaps(fileName, content); | ||
} | ||
@@ -159,4 +159,13 @@ | ||
sourceMapGeneratorToConsumer(sourceMapGenerator: SourceMapGenerator): SourceMapConsumer { | ||
/** | ||
* Tsc identifies source files by their relative path to the output file. Since | ||
* there's no easy way to identify these relative paths when tsickle generates its | ||
* own source maps, we patch them with the file name from the tsc source maps | ||
* before composing them. | ||
*/ | ||
sourceMapGeneratorToConsumerWithFileName( | ||
sourceMapGenerator: SourceMapGenerator, fileName: string): SourceMapConsumer { | ||
const rawSourceMap = sourceMapGenerator.toJSON(); | ||
rawSourceMap.sources = [fileName]; | ||
rawSourceMap.file = fileName; | ||
return new SourceMapConsumer(rawSourceMap); | ||
@@ -170,11 +179,19 @@ } | ||
combineSourceMaps(tscSourceMapText: string): string { | ||
getSourceMapKey(outputFilePath: string, sourceFileName: string): string { | ||
const fileDir = path.dirname(outputFilePath); | ||
return this.getCanonicalFileName(path.resolve(fileDir, sourceFileName)); | ||
} | ||
combineSourceMaps(filePath: string, tscSourceMapText: string): string { | ||
const tscSourceMapConsumer = this.sourceMapTextToConsumer(tscSourceMapText); | ||
const tscSourceMapGenerator = this.sourceMapConsumerToGenerator(tscSourceMapConsumer); | ||
if (this.tsickleSourceMaps.size > 0) { | ||
// TODO(lucassloan): remove when the .d.ts has the correct types | ||
for (const sourceFileName of (tscSourceMapConsumer as any).sources) { | ||
const tsickleSourceMapGenerator = this.tsickleSourceMaps.get(sourceFileName)!; | ||
const tsickleSourceMapConsumer = | ||
this.sourceMapGeneratorToConsumer(tsickleSourceMapGenerator); | ||
const sourceMapKey = this.getSourceMapKey(filePath, sourceFileName); | ||
const tsickleSourceMapGenerator = this.tsickleSourceMaps.get(sourceMapKey)!; | ||
const tsickleSourceMapConsumer = this.sourceMapGeneratorToConsumerWithFileName( | ||
tsickleSourceMapGenerator, sourceFileName); | ||
tscSourceMapGenerator.applySourceMap(tsickleSourceMapConsumer); | ||
@@ -186,6 +203,7 @@ } | ||
for (const sourceFileName of (tscSourceMapConsumer as any).sources) { | ||
const sourceMapKey = this.getSourceMapKey(filePath, sourceFileName); | ||
const decoratorDownlevelSourceMapGenerator = | ||
this.decoratorDownlevelSourceMaps.get(sourceFileName)!; | ||
const decoratorDownlevelSourceMapConsumer = | ||
this.sourceMapGeneratorToConsumer(decoratorDownlevelSourceMapGenerator); | ||
this.decoratorDownlevelSourceMaps.get(sourceMapKey)!; | ||
const decoratorDownlevelSourceMapConsumer = this.sourceMapGeneratorToConsumerWithFileName( | ||
decoratorDownlevelSourceMapGenerator, sourceFileName); | ||
tscSourceMapGenerator.applySourceMap(decoratorDownlevelSourceMapConsumer); | ||
@@ -217,2 +235,4 @@ } | ||
languageVersion: ts.ScriptTarget): ts.SourceFile { | ||
this.decoratorDownlevelSourceMaps.set( | ||
this.getCanonicalFileName(sourceFile.path), new SourceMapGenerator()); | ||
if (this.environment.shouldSkipTsickleProcessing(fileName)) return sourceFile; | ||
@@ -229,3 +249,4 @@ let fileContent = sourceFile.text; | ||
fileContent = converted.output + ANNOTATION_SUPPORT; | ||
this.decoratorDownlevelSourceMaps.set(fileName, converted.sourceMap); | ||
this.decoratorDownlevelSourceMaps.set( | ||
this.getCanonicalFileName(sourceFile.path), converted.sourceMap); | ||
return ts.createSourceFile(fileName, fileContent, languageVersion, true); | ||
@@ -237,2 +258,4 @@ } | ||
languageVersion: ts.ScriptTarget): ts.SourceFile { | ||
this.tsickleSourceMaps.set( | ||
this.getCanonicalFileName(sourceFile.path), new SourceMapGenerator()); | ||
let isDefinitions = /\.d\.ts$/.test(fileName); | ||
@@ -256,3 +279,3 @@ // Don't tsickle-process any d.ts that isn't a compilation target; | ||
this.diagnostics = diagnostics; | ||
this.tsickleSourceMaps.set(path.parse(fileName).base, sourceMap); | ||
this.tsickleSourceMaps.set(this.getCanonicalFileName(sourceFile.path), sourceMap); | ||
return ts.createSourceFile(fileName, output, languageVersion, true); | ||
@@ -259,0 +282,0 @@ } |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
472401
6910