Comparing version 0.2.3 to 0.2.4
@@ -8,2 +8,3 @@ /** | ||
*/ | ||
import { SourceMapGenerator } from 'source-map'; | ||
import * as ts from 'typescript'; | ||
@@ -14,2 +15,3 @@ export declare const ANNOTATION_SUPPORT_CODE: string; | ||
diagnostics: ts.Diagnostic[]; | ||
sourceMap: SourceMapGenerator; | ||
}; |
@@ -12,2 +12,4 @@ /** | ||
export { processES5 } from './es5processor'; | ||
export { FileMap, ModulesManifest } from './modules_manifest'; | ||
export { Pass, TsickleCompilerHost, TsickleCompilerHostOptions, TsickleEnvironment } from './tsickle_compiler_host'; | ||
export interface Options { | ||
@@ -14,0 +16,0 @@ /** |
@@ -0,1 +1,2 @@ | ||
import * as ts from 'typescript'; | ||
/** | ||
@@ -9,1 +10,15 @@ * @license | ||
export declare function toArray<T>(iterator: Iterator<T>): T[]; | ||
/** | ||
* Constructs a new ts.CompilerHost that overlays sources in substituteSource | ||
* over another ts.CompilerHost. | ||
* | ||
* @param substituteSource A map of source file name -> overlay source text. | ||
*/ | ||
export declare function createSourceReplacingCompilerHost(substituteSource: Map<string, string>, delegate: ts.CompilerHost): ts.CompilerHost; | ||
/** | ||
* Constructs a new ts.CompilerHost that overlays sources in substituteSource | ||
* over another ts.CompilerHost. | ||
* | ||
* @param outputFiles map to fill with source file name -> output text. | ||
*/ | ||
export declare function createOutputRetainingCompilerHost(outputFiles: Map<string, string>, delegate: ts.CompilerHost): ts.CompilerHost; |
@@ -131,16 +131,2 @@ /** | ||
} | ||
else if (!arrayIncludes(JSDOC_TAGS_WHITELIST, tagName)) { | ||
// Silently drop tags we don't understand. This is a subtle | ||
// compromise between multiple issues. | ||
// 1) If we pass through these non-Closure tags, the user will | ||
// get a warning from Closure, and the point of tsickle is | ||
// to insulate the user from Closure. | ||
// 2) The output of tsickle is for Closure only, so we don't | ||
// care if we drop tags that Closure doesn't undersand. | ||
// 3) Finally, we don't want to warn because users should be | ||
// free to add whichever JSDoc they feel like. If the user | ||
// wants help ensuring they didn't typo a tag, that is the | ||
// responsibility of a linter. | ||
continue; | ||
} | ||
// Grab the parameter name from @param tags. | ||
@@ -167,3 +153,4 @@ var parameterName = void 0; | ||
else { | ||
tags[tags.length - 1].text += '\n' + line; | ||
var lastTag = tags[tags.length - 1]; | ||
lastTag.text = (lastTag.text || '') + '\n' + line; | ||
} | ||
@@ -185,3 +172,19 @@ } | ||
if (tag.tagName) { | ||
out += " @" + tag.tagName; | ||
if (!arrayIncludes(JSDOC_TAGS_WHITELIST, tag.tagName)) { | ||
// Escape tags we don't understand. This is a subtle | ||
// compromise between multiple issues. | ||
// 1) If we pass through these non-Closure tags, the user will | ||
// get a warning from Closure, and the point of tsickle is | ||
// to insulate the user from Closure. | ||
// 2) The output of tsickle is for Closure but also may be read | ||
// by humans, for example non-TypeScript users of Angular. | ||
// 3) Finally, we don't want to warn because users should be | ||
// free to add whichever JSDoc they feel like. If the user | ||
// wants help ensuring they didn't typo a tag, that is the | ||
// responsibility of a linter. | ||
out += " \\@" + tag.tagName; | ||
} | ||
else { | ||
out += " @" + tag.tagName; | ||
} | ||
} | ||
@@ -188,0 +191,0 @@ if (tag.type) { |
@@ -90,32 +90,2 @@ #!/usr/bin/env node | ||
/** | ||
* Constructs a new ts.CompilerHost that overlays sources in substituteSource | ||
* over another ts.CompilerHost. | ||
* | ||
* @param substituteSource A map of source file name -> overlay source text. | ||
*/ | ||
function createSourceReplacingCompilerHost(substituteSource, delegate) { | ||
return { | ||
getSourceFile: getSourceFile, | ||
getCancellationToken: delegate.getCancellationToken, | ||
getDefaultLibFileName: delegate.getDefaultLibFileName, | ||
writeFile: delegate.writeFile, | ||
getCurrentDirectory: delegate.getCurrentDirectory, | ||
getCanonicalFileName: delegate.getCanonicalFileName, | ||
useCaseSensitiveFileNames: delegate.useCaseSensitiveFileNames, | ||
getNewLine: delegate.getNewLine, | ||
fileExists: delegate.fileExists, | ||
readFile: delegate.readFile, | ||
directoryExists: delegate.directoryExists, | ||
getDirectories: delegate.getDirectories, | ||
}; | ||
function getSourceFile(fileName, languageVersion, onError) { | ||
var path = ts.sys.resolvePath(fileName); | ||
var sourceText = substituteSource.get(path); | ||
if (sourceText) { | ||
return ts.createSourceFile(path, sourceText, languageVersion); | ||
} | ||
return delegate.getSourceFile(path, languageVersion, onError); | ||
} | ||
} | ||
/** | ||
* Compiles TypeScript code into Closure-compiler-ready JS. | ||
@@ -137,35 +107,21 @@ * Doesn't write any files to disk; all JS content is returned in a map. | ||
} | ||
var tsickleOptions = { | ||
untyped: settings.isUntyped, | ||
logWarning: settings.verbose ? | ||
function (warning) { | ||
console.error(tsickle.formatDiagnostics([warning])); | ||
} : | ||
undefined, | ||
var tsickleCompilerHostOptions = { | ||
googmodule: true, | ||
es5Mode: false, | ||
tsickleTyped: !settings.isUntyped, | ||
prelude: '', | ||
}; | ||
// Process each input file with tsickle and save the output. | ||
var tsickleOutput = new Map(); | ||
var tsickleExterns = ''; | ||
for (var _i = 0, fileNames_1 = fileNames; _i < fileNames_1.length; _i++) { | ||
var fileName = fileNames_1[_i]; | ||
var _a = tsickle.annotate(program, program.getSourceFile(fileName), tsickleOptions), output = _a.output, externs = _a.externs, diagnostics_2 = _a.diagnostics; | ||
if (diagnostics_2.length > 0) { | ||
allDiagnostics.push.apply(allDiagnostics, diagnostics_2); | ||
return null; | ||
} | ||
tsickleOutput.set(ts.sys.resolvePath(fileName), output); | ||
if (externs) { | ||
tsickleExterns += externs; | ||
} | ||
} | ||
var tsickleEnvironment = { | ||
shouldSkipTsickleProcessing: function (fileName) { return fileNames.indexOf(fileName) === -1; }, | ||
pathToModuleName: cliSupport.pathToModuleName, | ||
shouldIgnoreWarningsForPath: function (filePath) { return false; }, | ||
fileNameToModuleId: function (fileName) { return fileName; }, | ||
}; | ||
var jsFiles = new Map(); | ||
var hostDelegate = util_1.createOutputRetainingCompilerHost(jsFiles, ts.createCompilerHost(options)); | ||
// Reparse and reload the program, inserting the tsickle output in | ||
// place of the original source. | ||
var host = createSourceReplacingCompilerHost(tsickleOutput, ts.createCompilerHost(options)); | ||
var host = new tsickle.TsickleCompilerHost(hostDelegate, tsickleCompilerHostOptions, tsickleEnvironment, program, tsickle.Pass.Tsickle); | ||
program = ts.createProgram(fileNames, options, host); | ||
// Emit, creating a map of fileName => generated JS source. | ||
var jsFiles = new Map(); | ||
function writeFile(fileName, data) { | ||
jsFiles.set(fileName, data); | ||
} | ||
var diagnostics = program.emit(undefined, writeFile).diagnostics; | ||
var diagnostics = program.emit(undefined).diagnostics; | ||
if (diagnostics.length > 0) { | ||
@@ -175,12 +131,5 @@ allDiagnostics.push.apply(allDiagnostics, diagnostics); | ||
} | ||
for (var _b = 0, _c = util_1.toArray(jsFiles.keys()); _b < _c.length; _b++) { | ||
var fileName = _c[_b]; | ||
if (path.extname(fileName) !== '.map') { | ||
var moduleId = fileName; // TODO: does anyone use this? | ||
var output = tsickle.processES5(fileName, moduleId, jsFiles.get(fileName), cliSupport.pathToModuleName).output; | ||
jsFiles.set(fileName, output); | ||
} | ||
} | ||
return { jsFiles: jsFiles, externs: tsickleExterns }; | ||
return { jsFiles: jsFiles, externs: host.getGeneratedExterns() }; | ||
} | ||
exports.toClosureJS = toClosureJS; | ||
function main(args) { | ||
@@ -187,0 +136,0 @@ var _a = loadSettingsFromArgs(args), settings = _a.settings, tscArgs = _a.tscArgs; |
@@ -23,2 +23,7 @@ /** | ||
exports.processES5 = es5processor_1.processES5; | ||
var modules_manifest_1 = require('./modules_manifest'); | ||
exports.ModulesManifest = modules_manifest_1.ModulesManifest; | ||
var tsickle_compiler_host_1 = require('./tsickle_compiler_host'); | ||
exports.Pass = tsickle_compiler_host_1.Pass; | ||
exports.TsickleCompilerHost = tsickle_compiler_host_1.TsickleCompilerHost; | ||
/** | ||
@@ -32,4 +37,12 @@ * Symbols that are already declared as externs in Closure, that should | ||
'module', | ||
// ErrorConstructor is the interface of the Error object itself. | ||
// tsickle detects that this is part of the TypeScript standard library | ||
// and assumes it's part of the Closure standard library, but this | ||
// assumption is wrong for ErrorConstructor. To properly handle this | ||
// we'd somehow need to map methods defined on the ErrorConstructor | ||
// interface into properties on Closure's Error object, but for now it's | ||
// simpler to just blacklist it. | ||
'ErrorConstructor', | ||
'Symbol', | ||
'WorkerGlobalScope', | ||
'Symbol', | ||
]; | ||
@@ -36,0 +49,0 @@ function formatDiagnostics(diags) { |
@@ -0,1 +1,3 @@ | ||
"use strict"; | ||
var ts = require('typescript'); | ||
/** | ||
@@ -8,3 +10,2 @@ * @license | ||
*/ | ||
"use strict"; | ||
// toArray is a temporary function to help in the use of | ||
@@ -25,3 +26,60 @@ // ES6 maps and sets when running on node 4, which doesn't | ||
exports.toArray = toArray; | ||
/** | ||
* Constructs a new ts.CompilerHost that overlays sources in substituteSource | ||
* over another ts.CompilerHost. | ||
* | ||
* @param substituteSource A map of source file name -> overlay source text. | ||
*/ | ||
function createSourceReplacingCompilerHost(substituteSource, delegate) { | ||
return { | ||
getSourceFile: getSourceFile, | ||
getCancellationToken: delegate.getCancellationToken, | ||
getDefaultLibFileName: delegate.getDefaultLibFileName, | ||
writeFile: delegate.writeFile, | ||
getCurrentDirectory: delegate.getCurrentDirectory, | ||
getCanonicalFileName: delegate.getCanonicalFileName, | ||
useCaseSensitiveFileNames: delegate.useCaseSensitiveFileNames, | ||
getNewLine: delegate.getNewLine, | ||
fileExists: delegate.fileExists, | ||
readFile: delegate.readFile, | ||
directoryExists: delegate.directoryExists, | ||
getDirectories: delegate.getDirectories, | ||
}; | ||
function getSourceFile(fileName, languageVersion, onError) { | ||
var path = ts.sys.resolvePath(fileName); | ||
var sourceText = substituteSource.get(path); | ||
if (sourceText) { | ||
return ts.createSourceFile(fileName, sourceText, languageVersion); | ||
} | ||
return delegate.getSourceFile(path, languageVersion, onError); | ||
} | ||
} | ||
exports.createSourceReplacingCompilerHost = createSourceReplacingCompilerHost; | ||
/** | ||
* Constructs a new ts.CompilerHost that overlays sources in substituteSource | ||
* over another ts.CompilerHost. | ||
* | ||
* @param outputFiles map to fill with source file name -> output text. | ||
*/ | ||
function createOutputRetainingCompilerHost(outputFiles, delegate) { | ||
return { | ||
getSourceFile: delegate.getSourceFile, | ||
getCancellationToken: delegate.getCancellationToken, | ||
getDefaultLibFileName: delegate.getDefaultLibFileName, | ||
writeFile: writeFile, | ||
getCurrentDirectory: delegate.getCurrentDirectory, | ||
getCanonicalFileName: delegate.getCanonicalFileName, | ||
useCaseSensitiveFileNames: delegate.useCaseSensitiveFileNames, | ||
getNewLine: delegate.getNewLine, | ||
fileExists: delegate.fileExists, | ||
readFile: delegate.readFile, | ||
directoryExists: delegate.directoryExists, | ||
getDirectories: delegate.getDirectories, | ||
}; | ||
function writeFile(fileName, content, writeByteOrderMark, onError, sourceFiles) { | ||
outputFiles.set(fileName, content); | ||
} | ||
} | ||
exports.createOutputRetainingCompilerHost = createOutputRetainingCompilerHost; | ||
//# sourceMappingURL=util.js.map |
{ | ||
"name": "tsickle", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "Transpile TypeScript code to JavaScript with Closure annotations.", | ||
@@ -45,3 +45,3 @@ "main": "build/src/tsickle.js", | ||
"tslint": "^3.15.1", | ||
"typescript": "^2.0.0" | ||
"typescript": "~2.0.0" | ||
}, | ||
@@ -48,0 +48,0 @@ "scripts": { |
@@ -9,2 +9,3 @@ /** | ||
import {SourceMapGenerator} from 'source-map'; | ||
import * as ts from 'typescript'; | ||
@@ -283,3 +284,3 @@ | ||
process(): {output: string, diagnostics: ts.Diagnostic[]} { | ||
process(): {output: string, diagnostics: ts.Diagnostic[], sourceMap: SourceMapGenerator} { | ||
this.visit(this.file); | ||
@@ -304,5 +305,5 @@ return this.getOutput(); | ||
export function convertDecorators(typeChecker: ts.TypeChecker, sourceFile: ts.SourceFile): | ||
{output: string, diagnostics: ts.Diagnostic[]} { | ||
{output: string, diagnostics: ts.Diagnostic[], sourceMap: SourceMapGenerator} { | ||
assertTypeChecked(sourceFile); | ||
return new DecoratorRewriter(typeChecker, sourceFile).process(); | ||
} |
@@ -155,15 +155,2 @@ /** | ||
continue; | ||
} else if (!arrayIncludes(JSDOC_TAGS_WHITELIST, tagName)) { | ||
// Silently drop tags we don't understand. This is a subtle | ||
// compromise between multiple issues. | ||
// 1) If we pass through these non-Closure tags, the user will | ||
// get a warning from Closure, and the point of tsickle is | ||
// to insulate the user from Closure. | ||
// 2) The output of tsickle is for Closure only, so we don't | ||
// care if we drop tags that Closure doesn't undersand. | ||
// 3) Finally, we don't want to warn because users should be | ||
// free to add whichever JSDoc they feel like. If the user | ||
// wants help ensuring they didn't typo a tag, that is the | ||
// responsibility of a linter. | ||
continue; | ||
} | ||
@@ -188,3 +175,4 @@ | ||
} else { | ||
tags[tags.length - 1].text += '\n' + line; | ||
const lastTag = tags[tags.length - 1]; | ||
lastTag.text = (lastTag.text || '') + '\n' + line; | ||
} | ||
@@ -206,3 +194,18 @@ } | ||
if (tag.tagName) { | ||
out += ` @${tag.tagName}`; | ||
if (!arrayIncludes(JSDOC_TAGS_WHITELIST, tag.tagName)) { | ||
// Escape tags we don't understand. This is a subtle | ||
// compromise between multiple issues. | ||
// 1) If we pass through these non-Closure tags, the user will | ||
// get a warning from Closure, and the point of tsickle is | ||
// to insulate the user from Closure. | ||
// 2) The output of tsickle is for Closure but also may be read | ||
// by humans, for example non-TypeScript users of Angular. | ||
// 3) Finally, we don't want to warn because users should be | ||
// free to add whichever JSDoc they feel like. If the user | ||
// wants help ensuring they didn't typo a tag, that is the | ||
// responsibility of a linter. | ||
out += ` \\@${tag.tagName}`; | ||
} else { | ||
out += ` @${tag.tagName}`; | ||
} | ||
} | ||
@@ -209,0 +212,0 @@ if (tag.type) { |
@@ -19,6 +19,6 @@ #!/usr/bin/env node | ||
import * as tsickle from './tsickle'; | ||
import {toArray} from './util'; | ||
import {toArray, createOutputRetainingCompilerHost} from './util'; | ||
/** Tsickle settings passed on the command line. */ | ||
interface Settings { | ||
export interface Settings { | ||
/** If provided, path to save externs to. */ | ||
@@ -129,41 +129,6 @@ externsPath?: string; | ||
/** | ||
* Constructs a new ts.CompilerHost that overlays sources in substituteSource | ||
* over another ts.CompilerHost. | ||
* | ||
* @param substituteSource A map of source file name -> overlay source text. | ||
*/ | ||
function createSourceReplacingCompilerHost( | ||
substituteSource: Map<string, string>, delegate: ts.CompilerHost): ts.CompilerHost { | ||
return { | ||
getSourceFile, | ||
getCancellationToken: delegate.getCancellationToken, | ||
getDefaultLibFileName: delegate.getDefaultLibFileName, | ||
writeFile: delegate.writeFile, | ||
getCurrentDirectory: delegate.getCurrentDirectory, | ||
getCanonicalFileName: delegate.getCanonicalFileName, | ||
useCaseSensitiveFileNames: delegate.useCaseSensitiveFileNames, | ||
getNewLine: delegate.getNewLine, | ||
fileExists: delegate.fileExists, | ||
readFile: delegate.readFile, | ||
directoryExists: delegate.directoryExists, | ||
getDirectories: delegate.getDirectories, | ||
}; | ||
function getSourceFile( | ||
fileName: string, languageVersion: ts.ScriptTarget, | ||
onError?: (message: string) => void): ts.SourceFile { | ||
let path: string = ts.sys.resolvePath(fileName); | ||
let sourceText = substituteSource.get(path); | ||
if (sourceText) { | ||
return ts.createSourceFile(path, sourceText, languageVersion); | ||
} | ||
return delegate.getSourceFile(path, languageVersion, onError); | ||
} | ||
} | ||
/** | ||
* Compiles TypeScript code into Closure-compiler-ready JS. | ||
* Doesn't write any files to disk; all JS content is returned in a map. | ||
*/ | ||
function toClosureJS( | ||
export function toClosureJS( | ||
options: ts.CompilerOptions, fileNames: string[], settings: Settings, | ||
@@ -184,39 +149,26 @@ allDiagnostics: ts.Diagnostic[]): {jsFiles: Map<string, string>, externs: string}|null { | ||
const tsickleOptions: tsickle.Options = { | ||
untyped: settings.isUntyped, | ||
logWarning: settings.verbose ? | ||
(warning: ts.Diagnostic) => { | ||
console.error(tsickle.formatDiagnostics([warning])); | ||
} : | ||
undefined, | ||
const tsickleCompilerHostOptions: tsickle.TsickleCompilerHostOptions = { | ||
googmodule: true, | ||
es5Mode: false, | ||
tsickleTyped: !settings.isUntyped, | ||
prelude: '', | ||
}; | ||
// Process each input file with tsickle and save the output. | ||
const tsickleOutput = new Map<string, string>(); | ||
let tsickleExterns = ''; | ||
for (let fileName of fileNames) { | ||
let {output, externs, diagnostics} = | ||
tsickle.annotate(program, program.getSourceFile(fileName), tsickleOptions); | ||
if (diagnostics.length > 0) { | ||
allDiagnostics.push(...diagnostics); | ||
return null; | ||
} | ||
tsickleOutput.set(ts.sys.resolvePath(fileName), output); | ||
if (externs) { | ||
tsickleExterns += externs; | ||
} | ||
} | ||
const tsickleEnvironment: tsickle.TsickleEnvironment = { | ||
shouldSkipTsickleProcessing: (fileName) => fileNames.indexOf(fileName) === -1, | ||
pathToModuleName: cliSupport.pathToModuleName, | ||
shouldIgnoreWarningsForPath: (filePath) => false, | ||
fileNameToModuleId: (fileName) => fileName, | ||
}; | ||
const jsFiles = new Map<string, string>(); | ||
const hostDelegate = createOutputRetainingCompilerHost(jsFiles, ts.createCompilerHost(options)); | ||
// Reparse and reload the program, inserting the tsickle output in | ||
// place of the original source. | ||
let host = createSourceReplacingCompilerHost(tsickleOutput, ts.createCompilerHost(options)); | ||
let host = new tsickle.TsickleCompilerHost( | ||
hostDelegate, tsickleCompilerHostOptions, tsickleEnvironment, program, tsickle.Pass.Tsickle); | ||
program = ts.createProgram(fileNames, options, host); | ||
// Emit, creating a map of fileName => generated JS source. | ||
const jsFiles = new Map<string, string>(); | ||
function writeFile(fileName: string, data: string): void { | ||
jsFiles.set(fileName, data); | ||
} | ||
let {diagnostics} = program.emit(undefined, writeFile); | ||
let {diagnostics} = program.emit(undefined); | ||
if (diagnostics.length > 0) { | ||
@@ -227,12 +179,3 @@ allDiagnostics.push(...diagnostics); | ||
for (let fileName of toArray(jsFiles.keys())) { | ||
if (path.extname(fileName) !== '.map') { | ||
const moduleId = fileName; // TODO: does anyone use this? | ||
let {output} = tsickle.processES5( | ||
fileName, moduleId, jsFiles.get(fileName)!, cliSupport.pathToModuleName); | ||
jsFiles.set(fileName, output); | ||
} | ||
} | ||
return {jsFiles, externs: tsickleExterns}; | ||
return {jsFiles, externs: host.getGeneratedExterns()}; | ||
} | ||
@@ -239,0 +182,0 @@ |
@@ -19,2 +19,4 @@ /** | ||
export {processES5} from './es5processor'; | ||
export {FileMap, ModulesManifest} from './modules_manifest'; | ||
export {Pass, TsickleCompilerHost, TsickleCompilerHostOptions, TsickleEnvironment} from './tsickle_compiler_host'; | ||
@@ -61,4 +63,12 @@ export interface Options { | ||
'module', | ||
// ErrorConstructor is the interface of the Error object itself. | ||
// tsickle detects that this is part of the TypeScript standard library | ||
// and assumes it's part of the Closure standard library, but this | ||
// assumption is wrong for ErrorConstructor. To properly handle this | ||
// we'd somehow need to map methods defined on the ErrorConstructor | ||
// interface into properties on Closure's Error object, but for now it's | ||
// simpler to just blacklist it. | ||
'ErrorConstructor', | ||
'Symbol', | ||
'WorkerGlobalScope', | ||
'Symbol', | ||
]; | ||
@@ -65,0 +75,0 @@ |
@@ -0,1 +1,3 @@ | ||
import * as ts from 'typescript'; | ||
/** | ||
@@ -24,1 +26,66 @@ * @license | ||
} | ||
/** | ||
* Constructs a new ts.CompilerHost that overlays sources in substituteSource | ||
* over another ts.CompilerHost. | ||
* | ||
* @param substituteSource A map of source file name -> overlay source text. | ||
*/ | ||
export function createSourceReplacingCompilerHost( | ||
substituteSource: Map<string, string>, delegate: ts.CompilerHost): ts.CompilerHost { | ||
return { | ||
getSourceFile, | ||
getCancellationToken: delegate.getCancellationToken, | ||
getDefaultLibFileName: delegate.getDefaultLibFileName, | ||
writeFile: delegate.writeFile, | ||
getCurrentDirectory: delegate.getCurrentDirectory, | ||
getCanonicalFileName: delegate.getCanonicalFileName, | ||
useCaseSensitiveFileNames: delegate.useCaseSensitiveFileNames, | ||
getNewLine: delegate.getNewLine, | ||
fileExists: delegate.fileExists, | ||
readFile: delegate.readFile, | ||
directoryExists: delegate.directoryExists, | ||
getDirectories: delegate.getDirectories, | ||
}; | ||
function getSourceFile( | ||
fileName: string, languageVersion: ts.ScriptTarget, | ||
onError?: (message: string) => void): ts.SourceFile { | ||
let path: string = ts.sys.resolvePath(fileName); | ||
let sourceText = substituteSource.get(path); | ||
if (sourceText) { | ||
return ts.createSourceFile(fileName, sourceText, languageVersion); | ||
} | ||
return delegate.getSourceFile(path, languageVersion, onError); | ||
} | ||
} | ||
/** | ||
* Constructs a new ts.CompilerHost that overlays sources in substituteSource | ||
* over another ts.CompilerHost. | ||
* | ||
* @param outputFiles map to fill with source file name -> output text. | ||
*/ | ||
export function createOutputRetainingCompilerHost( | ||
outputFiles: Map<string, string>, delegate: ts.CompilerHost): ts.CompilerHost { | ||
return { | ||
getSourceFile: delegate.getSourceFile, | ||
getCancellationToken: delegate.getCancellationToken, | ||
getDefaultLibFileName: delegate.getDefaultLibFileName, | ||
writeFile: writeFile, | ||
getCurrentDirectory: delegate.getCurrentDirectory, | ||
getCanonicalFileName: delegate.getCanonicalFileName, | ||
useCaseSensitiveFileNames: delegate.useCaseSensitiveFileNames, | ||
getNewLine: delegate.getNewLine, | ||
fileExists: delegate.fileExists, | ||
readFile: delegate.readFile, | ||
directoryExists: delegate.directoryExists, | ||
getDirectories: delegate.getDirectories, | ||
}; | ||
function writeFile( | ||
fileName: string, content: string, writeByteOrderMark: boolean, | ||
onError?: (message: string) => void, sourceFiles?: ts.SourceFile[]): void { | ||
outputFiles.set(fileName, content); | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
593148
70
9762