Progress on printer. Added substitutions.
This commit is contained in:
parent
e4bcfd2a5d
commit
abd46f9f36
|
@ -47,6 +47,7 @@ var compilerSources = [
|
|||
"transforms/ts.ts",
|
||||
"transforms/es6.ts",
|
||||
"declarationEmitter.ts",
|
||||
"printer.ts",
|
||||
"emitter.ts",
|
||||
"program.ts",
|
||||
"commandLineParser.ts",
|
||||
|
@ -72,6 +73,7 @@ var servicesSources = [
|
|||
"transforms/ts.ts",
|
||||
"transforms/es6.ts",
|
||||
"declarationEmitter.ts",
|
||||
"printer.ts",
|
||||
"emitter.ts",
|
||||
"program.ts",
|
||||
"commandLineParser.ts",
|
||||
|
|
|
@ -15274,7 +15274,7 @@ namespace ts {
|
|||
// Grammar checking for computedPropertName and shorthandPropertyAssignment
|
||||
checkGrammarForInvalidQuestionMark(prop, (<PropertyAssignment>prop).questionToken, Diagnostics.An_object_member_cannot_be_declared_optional);
|
||||
if (name.kind === SyntaxKind.NumericLiteral) {
|
||||
checkGrammarNumericLiteral(<Identifier>name);
|
||||
checkGrammarNumericLiteral(<LiteralExpression>name);
|
||||
}
|
||||
currentKind = Property;
|
||||
}
|
||||
|
@ -15825,7 +15825,7 @@ namespace ts {
|
|||
}
|
||||
}
|
||||
|
||||
function checkGrammarNumericLiteral(node: Identifier): boolean {
|
||||
function checkGrammarNumericLiteral(node: LiteralExpression): boolean {
|
||||
// Grammar checking
|
||||
if (node.flags & NodeFlags.OctalLiteral && languageVersion >= ScriptTarget.ES5) {
|
||||
return grammarErrorOnNode(node, Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/// <reference path="checker.ts"/>
|
||||
/// <reference path="transform.ts" />
|
||||
/// <reference path="declarationEmitter.ts"/>
|
||||
/// <reference path="printer.ts" />
|
||||
|
||||
/* @internal */
|
||||
namespace ts {
|
||||
|
@ -78,9 +79,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
|||
let shouldEmitJsx = (s: SourceFile) => (s.languageVariant === LanguageVariant.JSX && !jsxDesugaring);
|
||||
let transformationChain = getTransformationChain(compilerOptions);
|
||||
let sourceFiles: SourceFile[];
|
||||
let transformationResolver: TransformationResolver;
|
||||
|
||||
if (targetSourceFile === undefined) {
|
||||
sourceFiles = transformFilesIfNeeded(resolver, host, host.getSourceFiles(), transformationChain);
|
||||
({ sourceFiles, transformationResolver } = transformFilesIfNeeded(resolver, host, host.getSourceFiles(), transformationChain));
|
||||
forEach(sourceFiles, sourceFile => {
|
||||
if (shouldEmitToOwnFile(sourceFile, compilerOptions)) {
|
||||
let jsFilePath = getOwnEmitOutputFilePath(sourceFile, host, shouldEmitJsx(sourceFile) ? ".jsx" : ".js");
|
||||
|
@ -96,11 +98,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
|||
// targetSourceFile is specified (e.g calling emitter from language service or calling getSemanticDiagnostic from language service)
|
||||
if (shouldEmitToOwnFile(targetSourceFile, compilerOptions)) {
|
||||
let jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, host, shouldEmitJsx(targetSourceFile) ? ".jsx" : ".js");
|
||||
[targetSourceFile] = transformFilesIfNeeded(resolver, host, [targetSourceFile], transformationChain);
|
||||
({ sourceFiles: [targetSourceFile], transformationResolver } = transformFilesIfNeeded(resolver, host, [targetSourceFile], transformationChain));
|
||||
emitFile(jsFilePath, targetSourceFile);
|
||||
}
|
||||
else if (!isDeclarationFile(targetSourceFile) && (compilerOptions.outFile || compilerOptions.out)) {
|
||||
sourceFiles = transformFilesIfNeeded(resolver, host, host.getSourceFiles(), transformationChain);
|
||||
({ sourceFiles, transformationResolver } = transformFilesIfNeeded(resolver, host, host.getSourceFiles(), transformationChain));
|
||||
emitFile(compilerOptions.outFile || compilerOptions.out);
|
||||
}
|
||||
}
|
||||
|
@ -8000,7 +8002,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
|||
}
|
||||
|
||||
function emitFile(jsFilePath: string, sourceFile?: SourceFile) {
|
||||
emitJavaScript(jsFilePath, sourceFile);
|
||||
if (compilerOptions.experimentalTransforms) {
|
||||
let result = sourceFile
|
||||
? printFile(resolver, transformationResolver, host, [sourceFile], jsFilePath)
|
||||
: printFile(resolver, transformationResolver, host, sourceFiles, jsFilePath);
|
||||
|
||||
writeFile(host, diagnostics, result.fileName, result.text, compilerOptions.emitBOM);
|
||||
}
|
||||
else {
|
||||
emitJavaScript(jsFilePath, sourceFile);
|
||||
}
|
||||
|
||||
if (compilerOptions.declaration) {
|
||||
writeDeclarationFile(jsFilePath, getOriginalNodeIf(sourceFile, isSourceFile), host, resolver, diagnostics);
|
||||
|
|
|
@ -666,7 +666,7 @@ namespace ts {
|
|||
if (name) node.name = name;
|
||||
return node;
|
||||
}
|
||||
export function createNamedImports(elements?: Array<ImportOrExportSpecifier>, location?: TextRange, flags?: NodeFlags): NamedImports {
|
||||
export function createNamedImports(elements?: Array<ImportSpecifier>, location?: TextRange, flags?: NodeFlags): NamedImports {
|
||||
let node = createNode<NamedImports>(SyntaxKind.NamedImports, location, flags);
|
||||
if (elements) node.elements = createNodeArray(elements);
|
||||
return node;
|
||||
|
@ -692,7 +692,7 @@ namespace ts {
|
|||
if (moduleSpecifier) node.moduleSpecifier = moduleSpecifier;
|
||||
return node;
|
||||
}
|
||||
export function createNamedExports(elements?: Array<ImportOrExportSpecifier>, location?: TextRange, flags?: NodeFlags): NamedExports {
|
||||
export function createNamedExports(elements?: Array<ExportSpecifier>, location?: TextRange, flags?: NodeFlags): NamedExports {
|
||||
let node = createNode<NamedExports>(SyntaxKind.NamedExports, location, flags);
|
||||
if (elements) node.elements = createNodeArray(elements);
|
||||
return node;
|
||||
|
@ -1557,7 +1557,7 @@ namespace ts {
|
|||
}
|
||||
return node;
|
||||
}
|
||||
export function updateNamedImports(node: NamedImports, elements: Array<ImportOrExportSpecifier>): NamedImports {
|
||||
export function updateNamedImports(node: NamedImports, elements: Array<ImportSpecifier>): NamedImports {
|
||||
if (elements !== node.elements) {
|
||||
let newNode = createNamedImports(elements);
|
||||
return updateFrom(node, newNode);
|
||||
|
@ -1585,7 +1585,7 @@ namespace ts {
|
|||
}
|
||||
return node;
|
||||
}
|
||||
export function updateNamedExports(node: NamedExports, elements: Array<ImportOrExportSpecifier>): NamedExports {
|
||||
export function updateNamedExports(node: NamedExports, elements: Array<ExportSpecifier>): NamedExports {
|
||||
if (elements !== node.elements) {
|
||||
let newNode = createNamedExports(elements);
|
||||
return updateFrom(node, newNode);
|
||||
|
@ -2338,11 +2338,108 @@ namespace ts {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
export function isExpressionNode(node: Node): node is Expression {
|
||||
if (node) {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.TrueKeyword:
|
||||
case SyntaxKind.FalseKeyword:
|
||||
case SyntaxKind.NullKeyword:
|
||||
case SyntaxKind.ThisKeyword:
|
||||
case SyntaxKind.SuperKeyword:
|
||||
case SyntaxKind.Identifier:
|
||||
case SyntaxKind.NumericLiteral:
|
||||
case SyntaxKind.RegularExpressionLiteral:
|
||||
case SyntaxKind.NoSubstitutionTemplateLiteral:
|
||||
case SyntaxKind.TemplateHead:
|
||||
case SyntaxKind.TemplateMiddle:
|
||||
case SyntaxKind.TemplateTail:
|
||||
case SyntaxKind.StringLiteral:
|
||||
case SyntaxKind.RawExpression:
|
||||
case SyntaxKind.ObjectLiteralExpression:
|
||||
case SyntaxKind.ArrayLiteralExpression:
|
||||
case SyntaxKind.FunctionExpression:
|
||||
case SyntaxKind.TemplateExpression:
|
||||
case SyntaxKind.ParenthesizedExpression:
|
||||
case SyntaxKind.NewExpression:
|
||||
case SyntaxKind.JsxElement:
|
||||
case SyntaxKind.JsxSelfClosingElement:
|
||||
case SyntaxKind.ClassExpression:
|
||||
case SyntaxKind.PropertyAccessExpression:
|
||||
case SyntaxKind.ElementAccessExpression:
|
||||
case SyntaxKind.TaggedTemplateExpression:
|
||||
case SyntaxKind.CallExpression:
|
||||
case SyntaxKind.PostfixUnaryExpression:
|
||||
case SyntaxKind.PrefixUnaryExpression:
|
||||
case SyntaxKind.DeleteExpression:
|
||||
case SyntaxKind.TypeOfExpression:
|
||||
case SyntaxKind.VoidExpression:
|
||||
case SyntaxKind.AwaitExpression:
|
||||
case SyntaxKind.TypeAssertionExpression:
|
||||
case SyntaxKind.OmittedExpression:
|
||||
case SyntaxKind.YieldExpression:
|
||||
case SyntaxKind.BinaryExpression:
|
||||
case SyntaxKind.ConditionalExpression:
|
||||
case SyntaxKind.ArrowFunction:
|
||||
case SyntaxKind.SpreadElementExpression:
|
||||
case SyntaxKind.AsExpression:
|
||||
case SyntaxKind.JsxOpeningElement:
|
||||
case SyntaxKind.JsxExpression:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
export function isEntityName(node: Node): node is EntityName {
|
||||
if (node) {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.Identifier:
|
||||
case SyntaxKind.QualifiedName:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
export function isDeclarationNameNode(node: Node): node is DeclarationName {
|
||||
if (node) {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.ObjectBindingPattern:
|
||||
case SyntaxKind.ArrayBindingPattern:
|
||||
case SyntaxKind.ComputedPropertyName:
|
||||
case SyntaxKind.Identifier:
|
||||
case SyntaxKind.NumericLiteral:
|
||||
case SyntaxKind.RegularExpressionLiteral:
|
||||
case SyntaxKind.NoSubstitutionTemplateLiteral:
|
||||
case SyntaxKind.TemplateHead:
|
||||
case SyntaxKind.TemplateMiddle:
|
||||
case SyntaxKind.TemplateTail:
|
||||
case SyntaxKind.StringLiteral:
|
||||
case SyntaxKind.RawExpression:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
export function isPropertyName(node: Node): node is PropertyName {
|
||||
if (node) {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.ComputedPropertyName:
|
||||
case SyntaxKind.Identifier:
|
||||
case SyntaxKind.NumericLiteral:
|
||||
case SyntaxKind.RegularExpressionLiteral:
|
||||
case SyntaxKind.NoSubstitutionTemplateLiteral:
|
||||
case SyntaxKind.TemplateHead:
|
||||
case SyntaxKind.TemplateMiddle:
|
||||
case SyntaxKind.TemplateTail:
|
||||
case SyntaxKind.StringLiteral:
|
||||
case SyntaxKind.RawExpression:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
export function isStatementNode(node: Node): node is Statement {
|
||||
if (node) {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.EmptyStatement:
|
||||
case SyntaxKind.DebuggerStatement:
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.MissingDeclaration:
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
|
@ -2355,6 +2452,8 @@ namespace ts {
|
|||
case SyntaxKind.ExportAssignment:
|
||||
case SyntaxKind.Block:
|
||||
case SyntaxKind.RawStatement:
|
||||
case SyntaxKind.EmptyStatement:
|
||||
case SyntaxKind.DebuggerStatement:
|
||||
case SyntaxKind.ModuleBlock:
|
||||
case SyntaxKind.VariableStatement:
|
||||
case SyntaxKind.ExpressionStatement:
|
||||
|
@ -2378,23 +2477,6 @@ namespace ts {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
export function isUnaryExpression(node: Node): node is UnaryExpression {
|
||||
if (node) {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.CallExpression:
|
||||
case SyntaxKind.NewExpression:
|
||||
case SyntaxKind.PostfixUnaryExpression:
|
||||
case SyntaxKind.PrefixUnaryExpression:
|
||||
case SyntaxKind.DeleteExpression:
|
||||
case SyntaxKind.TypeOfExpression:
|
||||
case SyntaxKind.VoidExpression:
|
||||
case SyntaxKind.AwaitExpression:
|
||||
case SyntaxKind.TypeAssertionExpression:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
export function isTypeNodeNode(node: Node): node is TypeNode {
|
||||
if (node) {
|
||||
switch (node.kind) {
|
||||
|
@ -2486,10 +2568,9 @@ namespace ts {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
export function isExpressionNode(node: Node): node is Expression {
|
||||
export function isUnaryExpression(node: Node): node is UnaryExpression {
|
||||
if (node) {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.OmittedExpression:
|
||||
case SyntaxKind.TrueKeyword:
|
||||
case SyntaxKind.FalseKeyword:
|
||||
case SyntaxKind.NullKeyword:
|
||||
|
@ -2524,14 +2605,6 @@ namespace ts {
|
|||
case SyntaxKind.VoidExpression:
|
||||
case SyntaxKind.AwaitExpression:
|
||||
case SyntaxKind.TypeAssertionExpression:
|
||||
case SyntaxKind.YieldExpression:
|
||||
case SyntaxKind.BinaryExpression:
|
||||
case SyntaxKind.ConditionalExpression:
|
||||
case SyntaxKind.ArrowFunction:
|
||||
case SyntaxKind.SpreadElementExpression:
|
||||
case SyntaxKind.AsExpression:
|
||||
case SyntaxKind.JsxOpeningElement:
|
||||
case SyntaxKind.JsxExpression:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -2553,6 +2626,58 @@ namespace ts {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
export function isConciseBody(node: Node): node is ConciseBody {
|
||||
if (node) {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.TrueKeyword:
|
||||
case SyntaxKind.FalseKeyword:
|
||||
case SyntaxKind.NullKeyword:
|
||||
case SyntaxKind.ThisKeyword:
|
||||
case SyntaxKind.SuperKeyword:
|
||||
case SyntaxKind.Identifier:
|
||||
case SyntaxKind.NumericLiteral:
|
||||
case SyntaxKind.RegularExpressionLiteral:
|
||||
case SyntaxKind.NoSubstitutionTemplateLiteral:
|
||||
case SyntaxKind.TemplateHead:
|
||||
case SyntaxKind.TemplateMiddle:
|
||||
case SyntaxKind.TemplateTail:
|
||||
case SyntaxKind.StringLiteral:
|
||||
case SyntaxKind.RawExpression:
|
||||
case SyntaxKind.ObjectLiteralExpression:
|
||||
case SyntaxKind.ArrayLiteralExpression:
|
||||
case SyntaxKind.FunctionExpression:
|
||||
case SyntaxKind.TemplateExpression:
|
||||
case SyntaxKind.ParenthesizedExpression:
|
||||
case SyntaxKind.NewExpression:
|
||||
case SyntaxKind.JsxElement:
|
||||
case SyntaxKind.JsxSelfClosingElement:
|
||||
case SyntaxKind.ClassExpression:
|
||||
case SyntaxKind.PropertyAccessExpression:
|
||||
case SyntaxKind.ElementAccessExpression:
|
||||
case SyntaxKind.TaggedTemplateExpression:
|
||||
case SyntaxKind.CallExpression:
|
||||
case SyntaxKind.PostfixUnaryExpression:
|
||||
case SyntaxKind.PrefixUnaryExpression:
|
||||
case SyntaxKind.DeleteExpression:
|
||||
case SyntaxKind.TypeOfExpression:
|
||||
case SyntaxKind.VoidExpression:
|
||||
case SyntaxKind.AwaitExpression:
|
||||
case SyntaxKind.TypeAssertionExpression:
|
||||
case SyntaxKind.OmittedExpression:
|
||||
case SyntaxKind.YieldExpression:
|
||||
case SyntaxKind.BinaryExpression:
|
||||
case SyntaxKind.ConditionalExpression:
|
||||
case SyntaxKind.ArrowFunction:
|
||||
case SyntaxKind.SpreadElementExpression:
|
||||
case SyntaxKind.AsExpression:
|
||||
case SyntaxKind.JsxOpeningElement:
|
||||
case SyntaxKind.JsxExpression:
|
||||
case SyntaxKind.Block:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
export function isLiteralExpressionOrTemplateExpression(node: Node): node is LiteralExpression | TemplateExpression {
|
||||
if (node) {
|
||||
switch (node.kind) {
|
||||
|
@ -2580,10 +2705,21 @@ namespace ts {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
export function isJsxChild(node: Node): node is JsxChild {
|
||||
if (node) {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.JsxElement:
|
||||
case SyntaxKind.JsxExpression:
|
||||
case SyntaxKind.JsxSelfClosingElement:
|
||||
case SyntaxKind.JsxText:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
export function isExpressionOrVariableDeclarationList(node: Node): node is Expression | VariableDeclarationList {
|
||||
if (node) {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.OmittedExpression:
|
||||
case SyntaxKind.TrueKeyword:
|
||||
case SyntaxKind.FalseKeyword:
|
||||
case SyntaxKind.NullKeyword:
|
||||
|
@ -2618,6 +2754,7 @@ namespace ts {
|
|||
case SyntaxKind.VoidExpression:
|
||||
case SyntaxKind.AwaitExpression:
|
||||
case SyntaxKind.TypeAssertionExpression:
|
||||
case SyntaxKind.OmittedExpression:
|
||||
case SyntaxKind.YieldExpression:
|
||||
case SyntaxKind.BinaryExpression:
|
||||
case SyntaxKind.ConditionalExpression:
|
||||
|
@ -2632,6 +2769,26 @@ namespace ts {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
export function isCaseOrDefaultClause(node: Node): node is CaseOrDefaultClause {
|
||||
if (node) {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.CaseClause:
|
||||
case SyntaxKind.DefaultClause:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
export function isModuleBody(node: Node): node is ModuleBody {
|
||||
if (node) {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.ModuleBlock:
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
export function isIdentifierOrLiteralExpression(node: Node): node is Identifier | LiteralExpression {
|
||||
if (node) {
|
||||
switch (node.kind) {
|
||||
|
@ -2652,6 +2809,8 @@ namespace ts {
|
|||
export function isEntityNameOrExternalModuleReference(node: Node): node is EntityName | ExternalModuleReference {
|
||||
if (node) {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.Identifier:
|
||||
case SyntaxKind.QualifiedName:
|
||||
case SyntaxKind.ExternalModuleReference:
|
||||
return true;
|
||||
}
|
||||
|
@ -2668,16 +2827,6 @@ namespace ts {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
export function isImportOrExportSpecifier(node: Node): node is ImportOrExportSpecifier {
|
||||
if (node) {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.ImportSpecifier:
|
||||
case SyntaxKind.ExportSpecifier:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
export function isJSDocType(node: Node): node is JSDocType {
|
||||
if (node) {
|
||||
switch (node.kind) {
|
||||
|
@ -3186,7 +3335,7 @@ namespace ts {
|
|||
case SyntaxKind.NamespaceImport:
|
||||
return updateNamespaceImport(<NamespaceImport>node, (<NamespaceImport>node).name);
|
||||
case SyntaxKind.NamedImports:
|
||||
return updateNamedImports(<NamedImports>node, transformer.visitNodes((<NamedImports>node).elements, visitor, isImportOrExportSpecifier));
|
||||
return updateNamedImports(<NamedImports>node, transformer.visitNodes((<NamedImports>node).elements, visitor, isImportSpecifier));
|
||||
case SyntaxKind.ImportSpecifier:
|
||||
return updateImportSpecifier(<ImportSpecifier>node, (<ImportSpecifier>node).propertyName, (<ImportSpecifier>node).name);
|
||||
case SyntaxKind.ExportAssignment:
|
||||
|
@ -3194,7 +3343,7 @@ namespace ts {
|
|||
case SyntaxKind.ExportDeclaration:
|
||||
return updateExportDeclaration(<ExportDeclaration>node, transformer.visitNodes((<ExportDeclaration>node).decorators, visitor, isDecorator), transformer.visitNodes((<ExportDeclaration>node).modifiers, visitor, isModifier), (<ExportDeclaration>node).exportClause, (<ExportDeclaration>node).moduleSpecifier);
|
||||
case SyntaxKind.NamedExports:
|
||||
return updateNamedExports(<NamedExports>node, transformer.visitNodes((<NamedExports>node).elements, visitor, isImportOrExportSpecifier));
|
||||
return updateNamedExports(<NamedExports>node, transformer.visitNodes((<NamedExports>node).elements, visitor, isExportSpecifier));
|
||||
case SyntaxKind.ExportSpecifier:
|
||||
return updateExportSpecifier(<ExportSpecifier>node, (<ExportSpecifier>node).propertyName, (<ExportSpecifier>node).name);
|
||||
case SyntaxKind.MissingDeclaration:
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -33,31 +33,31 @@ namespace ts {
|
|||
|
||||
// Add the TypeScript and Module transforms to the chain.
|
||||
transforms.push(transformTypeScript);
|
||||
// transforms.push(transformModule);
|
||||
// // transforms.push(transformModule);
|
||||
|
||||
// Add the JSX transform to the chain.
|
||||
if (jsx === JsxEmit.React) {
|
||||
transforms.push(transformJsx);
|
||||
}
|
||||
// // Add the JSX transform to the chain.
|
||||
// if (jsx === JsxEmit.React) {
|
||||
// transforms.push(transformJsx);
|
||||
// }
|
||||
|
||||
// Add the ES6 transform to the chain.
|
||||
if (languageVersion < ScriptTarget.ES6) {
|
||||
transforms.push(transformES6);
|
||||
}
|
||||
// // Add the ES6 transform to the chain.
|
||||
// if (languageVersion < ScriptTarget.ES6) {
|
||||
// transforms.push(transformES6);
|
||||
// }
|
||||
|
||||
return chainTransformations(transforms);
|
||||
}
|
||||
|
||||
export function transformFilesIfNeeded(resolver: EmitResolver, host: EmitHost, sourceFiles: SourceFile[], transformationChain: TransformationChain) {
|
||||
export function transformFilesIfNeeded(resolver: EmitResolver, host: EmitHost, sourceFiles: SourceFile[], transformationChain: TransformationChain): TransformationResult {
|
||||
let compilerOptions = host.getCompilerOptions();
|
||||
if (compilerOptions.experimentalTransforms) {
|
||||
return transformFiles(resolver, host, sourceFiles, transformationChain);
|
||||
}
|
||||
|
||||
return sourceFiles;
|
||||
return { sourceFiles };
|
||||
}
|
||||
|
||||
export function transformFiles(resolver: EmitResolver, host: EmitHost, sourceFiles: SourceFile[], transformationChain: TransformationChain) {
|
||||
export function transformFiles(resolver: EmitResolver, host: EmitHost, sourceFiles: SourceFile[], transformationChain: TransformationChain): TransformationResult {
|
||||
// emit output for the __extends helper function
|
||||
const extendsHelper = `
|
||||
var __extends = (this && this.__extends) || function (d, b) {
|
||||
|
@ -114,8 +114,8 @@ function __export(m) {
|
|||
let transformFlags: TransformFlags;
|
||||
let generatedNameSet: Map<string>;
|
||||
let tempVariableNameSet: Map<string>;
|
||||
let nodeToGeneratedName: string[];
|
||||
let nodeToGeneratedIdentifier: Identifier[];
|
||||
let nodeToGeneratedName: string[] = [];
|
||||
let nodeToGeneratedIdentifier: Identifier[] = [];
|
||||
let lexicalEnvironmentStackSize: number;
|
||||
let lexicalEnvironmentStack: LexicalEnvironment[] = [];
|
||||
let tempFlags: TempFlags;
|
||||
|
@ -131,6 +131,9 @@ function __export(m) {
|
|||
let updatedNode: Node;
|
||||
let updatedNodes: Node[];
|
||||
let helpersEmitted: NodeCheckFlags;
|
||||
let assignmentSubstitutions: ((node: BinaryExpression) => Expression)[] = [];
|
||||
let bindingIdentifierSubstitutions: ((node: Identifier) => Identifier)[] = [];
|
||||
let expressionIdentifierSubstitutions: ((node: Identifier) => LeftHandSideExpression)[] = [];
|
||||
let transformer: Transformer = {
|
||||
getEmitResolver: () => resolver,
|
||||
getCompilerOptions: () => compilerOptions,
|
||||
|
@ -154,6 +157,12 @@ function __export(m) {
|
|||
hoistFunctionDeclaration,
|
||||
emitEmitHelpers,
|
||||
emitExportStarHelper,
|
||||
getAssignmentSubstitution,
|
||||
setAssignmentSubstitution,
|
||||
getBindingIdentifierSubstitution,
|
||||
setBindingIdentifierSubstitution,
|
||||
getExpressionIdentifierSubstitution,
|
||||
setExpressionIdentifierSubstitution,
|
||||
startLexicalEnvironment,
|
||||
endLexicalEnvironment,
|
||||
pipeNode,
|
||||
|
@ -173,7 +182,14 @@ function __export(m) {
|
|||
}
|
||||
};
|
||||
|
||||
return map(sourceFiles, transformSourceFile);
|
||||
return {
|
||||
sourceFiles: map(sourceFiles, transformSourceFile),
|
||||
transformationResolver: {
|
||||
getAssignmentSubstitution,
|
||||
getBindingIdentifierSubstitution,
|
||||
getExpressionIdentifierSubstitution,
|
||||
}
|
||||
};
|
||||
|
||||
function transformSourceFile(sourceFile: SourceFile) {
|
||||
if (isDeclarationFile(sourceFile)) {
|
||||
|
@ -183,8 +199,6 @@ function __export(m) {
|
|||
currentSourceFile = sourceFile;
|
||||
generatedNameSet = {};
|
||||
tempVariableNameSet = {};
|
||||
nodeToGeneratedName = [];
|
||||
nodeToGeneratedIdentifier = [];
|
||||
lexicalEnvironmentStackSize = 0;
|
||||
nodeStack = createNodeStack();
|
||||
helpersEmitted = undefined;
|
||||
|
@ -198,8 +212,6 @@ function __export(m) {
|
|||
currentSourceFile = undefined;
|
||||
generatedNameSet = undefined;
|
||||
tempVariableNameSet = undefined;
|
||||
nodeToGeneratedName = undefined;
|
||||
nodeToGeneratedIdentifier = undefined;
|
||||
lexicalEnvironmentStackSize = undefined;
|
||||
nodeStack = undefined;
|
||||
helpersEmitted = undefined;
|
||||
|
@ -207,6 +219,34 @@ function __export(m) {
|
|||
return visited;
|
||||
}
|
||||
|
||||
function getAssignmentSubstitution(sourceFile: SourceFile): (node: BinaryExpression) => Expression {
|
||||
return assignmentSubstitutions[getNodeId(getOriginalNode(sourceFile))] || identitySubstitution;
|
||||
}
|
||||
|
||||
function setAssignmentSubstitution(sourceFile: SourceFile, substitution: (node: BinaryExpression) => Expression) {
|
||||
assignmentSubstitutions[getNodeId(getOriginalNode(sourceFile))] = substitution;
|
||||
}
|
||||
|
||||
function getBindingIdentifierSubstitution(sourceFile: SourceFile): (node: Identifier) => Identifier {
|
||||
return bindingIdentifierSubstitutions[getNodeId(getOriginalNode(sourceFile))] || identitySubstitution;
|
||||
}
|
||||
|
||||
function setBindingIdentifierSubstitution(sourceFile: SourceFile, substitution: (node: Identifier) => Identifier): void {
|
||||
bindingIdentifierSubstitutions[getNodeId(getOriginalNode(sourceFile))] = substitution;
|
||||
}
|
||||
|
||||
function getExpressionIdentifierSubstitution(sourceFile: SourceFile): (node: Identifier) => LeftHandSideExpression {
|
||||
return expressionIdentifierSubstitutions[getNodeId(getOriginalNode(sourceFile))] || identitySubstitution;
|
||||
}
|
||||
|
||||
function setExpressionIdentifierSubstitution(sourceFile: SourceFile, substitution: (node: Identifier) => LeftHandSideExpression) {
|
||||
expressionIdentifierSubstitutions[getNodeId(getOriginalNode(sourceFile))] = substitution;
|
||||
}
|
||||
|
||||
function identitySubstitution<T extends Node>(node: T): T {
|
||||
return node;
|
||||
}
|
||||
|
||||
// Return the next available name in the pattern _a ... _z, _0, _1, ...
|
||||
// TempFlags._i or TempFlags._n may be used to express a preference for that dedicated name.
|
||||
// Note that names generated by makeTempVariableName and makeUniqueName will never conflict.
|
||||
|
|
|
@ -46,6 +46,8 @@ namespace ts {
|
|||
let exportSpecifiers: Map<ExportSpecifier[]>;
|
||||
let exportEquals: ExportAssignment;
|
||||
let exportFunctionForFile: string;
|
||||
let savedSubstituteExpressionIdentifier = transformer.getExpressionIdentifierSubstitution(node);
|
||||
transformer.setExpressionIdentifierSubstitution(node, substituteExpressionIdentifier);
|
||||
|
||||
// Mark that we are about to visit a new lexical environment.
|
||||
return visitSourceFile(node, visitor);
|
||||
|
@ -869,21 +871,6 @@ namespace ts {
|
|||
}
|
||||
|
||||
transformBindingElementToExpressionWithParenthesisIfNeeded(node, write, /*parenthesizeObjectLiteralAssignment*/ true);
|
||||
|
||||
let name = node.name;
|
||||
if (isBindingPattern(name)) {
|
||||
let expr = mapNode(name, transformBindingPatternToExpression);
|
||||
let initializer = visitNode(node.initializer, visitor, isExpressionNode);
|
||||
let assignExpr = createAssignmentExpression(expr, initializer);
|
||||
let parenExpr = createParenthesizedExpression(assignExpr);
|
||||
write(parenExpr);
|
||||
}
|
||||
else {
|
||||
let qualifiedName = getModuleMemberName(name);
|
||||
let initializer = visitNode(node.initializer, visitor, isExpressionNode);
|
||||
let assignExpr = createAssignmentExpression(qualifiedName, initializer);
|
||||
write(assignExpr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1026,6 +1013,15 @@ namespace ts {
|
|||
return !!(resolver.getNodeCheckFlags(node) & NodeCheckFlags.LexicalModuleMergesWithClass);
|
||||
}
|
||||
|
||||
function substituteExpressionIdentifier(node: Identifier): LeftHandSideExpression {
|
||||
let container = resolver.getReferencedExportContainer(node);
|
||||
if (isModuleDeclaration(container)) {
|
||||
return createPropertyAccessExpression2(getGeneratedNameForNode(container), node, node);
|
||||
}
|
||||
|
||||
return savedSubstituteExpressionIdentifier(node);
|
||||
}
|
||||
|
||||
function visitImportEqualsDeclaration(node: ImportEqualsDeclaration, write: (node: Statement) => void): void {
|
||||
Debug.assert(!isExternalModuleImportEqualsDeclaration(node));
|
||||
|
||||
|
|
|
@ -507,7 +507,6 @@ namespace ts {
|
|||
// @factoryhidden("jsDocComment", true)
|
||||
// @factoryhidden("nextContainer", true)
|
||||
// @factoryorder("decorators", "modifiers")
|
||||
// @nofactoryanynodetest
|
||||
export interface Node extends TextRange {
|
||||
kind: SyntaxKind;
|
||||
flags: NodeFlags;
|
||||
|
@ -547,7 +546,8 @@ namespace ts {
|
|||
// @kind(SyntaxKind.PrivateKeyword, { create: false, update: false, test: false })
|
||||
// @kind(SyntaxKind.ProtectedKeyword, { create: false, update: false, test: false })
|
||||
// @kind(SyntaxKind.StaticKeyword, { create: false, update: false, test: false })
|
||||
export type Modifier = Node;
|
||||
export interface Modifier extends Node {
|
||||
}
|
||||
|
||||
// @kind(SyntaxKind.Identifier)
|
||||
export interface Identifier extends PrimaryExpression {
|
||||
|
@ -731,10 +731,12 @@ namespace ts {
|
|||
}
|
||||
|
||||
// @kind(SyntaxKind.ObjectBindingPattern)
|
||||
export type ObjectBindingPattern = BindingPattern;
|
||||
export interface ObjectBindingPattern extends BindingPattern {
|
||||
}
|
||||
|
||||
// @kind(SyntaxKind.ArrayBindingPattern)
|
||||
export type ArrayBindingPattern = BindingPattern;
|
||||
export interface ArrayBindingPattern extends BindingPattern {
|
||||
}
|
||||
|
||||
/**
|
||||
* Several node kinds share function-like features such as a signature,
|
||||
|
@ -823,14 +825,16 @@ namespace ts {
|
|||
// @factoryhidden("questionToken")
|
||||
// @factoryhidden("asteriskToken")
|
||||
// @factoryorder("decorators", "modifiers", "name", "parameters", "type", "body")
|
||||
export type GetAccessorDeclaration = AccessorDeclaration;
|
||||
export interface GetAccessorDeclaration extends AccessorDeclaration {
|
||||
}
|
||||
|
||||
// @kind(SyntaxKind.SetAccessor)
|
||||
// @factoryhidden("typeParameters")
|
||||
// @factoryhidden("questionToken")
|
||||
// @factoryhidden("asteriskToken")
|
||||
// @factoryorder("decorators", "modifiers", "name", "parameters", "type", "body")
|
||||
export type SetAccessorDeclaration = AccessorDeclaration;
|
||||
export interface SetAccessorDeclaration extends AccessorDeclaration {
|
||||
}
|
||||
|
||||
// @kind(SyntaxKind.IndexSignature)
|
||||
// @factoryhidden("typeParameters")
|
||||
|
@ -852,13 +856,15 @@ namespace ts {
|
|||
// @factoryhidden("name")
|
||||
// @factoryhidden("decorators")
|
||||
// @factoryhidden("modifiers")
|
||||
export type FunctionTypeNode = FunctionOrConstructorTypeNode;
|
||||
export interface FunctionTypeNode extends FunctionOrConstructorTypeNode {
|
||||
}
|
||||
|
||||
// @kind(SyntaxKind.ConstructorType)
|
||||
// @factoryhidden("name")
|
||||
// @factoryhidden("decorators")
|
||||
// @factoryhidden("modifiers")
|
||||
export type ConstructorTypeNode = FunctionOrConstructorTypeNode;
|
||||
export interface ConstructorTypeNode extends FunctionOrConstructorTypeNode {
|
||||
}
|
||||
|
||||
// @kind(SyntaxKind.TypeReference)
|
||||
export interface TypeReferenceNode extends TypeNode {
|
||||
|
@ -931,11 +937,10 @@ namespace ts {
|
|||
}
|
||||
|
||||
// @kind(SyntaxKind.OmittedExpression)
|
||||
export type OmittedExpression = Expression;
|
||||
export interface OmittedExpression extends Expression { }
|
||||
|
||||
// @kind(SyntaxKind.RawExpression)
|
||||
export interface RawExpression extends LiteralExpression {
|
||||
}
|
||||
export interface RawExpression extends LiteralExpression { }
|
||||
|
||||
export interface UnaryExpression extends Expression {
|
||||
_unaryExpressionBrand: any;
|
||||
|
@ -1216,10 +1221,10 @@ namespace ts {
|
|||
}
|
||||
|
||||
// @kind(SyntaxKind.EmptyStatement)
|
||||
export type EmptyStatement = Statement;
|
||||
export interface EmptyStatement extends Statement { }
|
||||
|
||||
// @kind(SyntaxKind.DebuggerStatement)
|
||||
export type DebuggerStatement = Statement;
|
||||
export interface DebuggerStatement extends Statement { }
|
||||
|
||||
// @kind(SyntaxKind.MissingDeclaration)
|
||||
// @factoryhidden("name", true)
|
||||
|
@ -1287,15 +1292,17 @@ namespace ts {
|
|||
expression: Expression;
|
||||
}
|
||||
|
||||
export interface BreakOrContinueStatement extends Statement {
|
||||
// @kind(SyntaxKind.BreakStatement)
|
||||
export interface BreakStatement extends Statement {
|
||||
label?: Identifier;
|
||||
}
|
||||
|
||||
// @kind(SyntaxKind.BreakStatement)
|
||||
export type BreakStatement = BreakOrContinueStatement;
|
||||
|
||||
// @kind(SyntaxKind.ContinueStatement)
|
||||
export type ContinueStatement = BreakOrContinueStatement;
|
||||
export interface ContinueStatement extends Statement {
|
||||
label?: Identifier;
|
||||
}
|
||||
|
||||
export type BreakOrContinueStatement = BreakStatement | ContinueStatement;
|
||||
|
||||
// @kind(SyntaxKind.ReturnStatement)
|
||||
export interface ReturnStatement extends Statement {
|
||||
|
@ -1492,28 +1499,35 @@ namespace ts {
|
|||
moduleSpecifier?: Expression;
|
||||
}
|
||||
|
||||
export interface NamedImportsOrExports extends Node {
|
||||
elements: NodeArray<ImportOrExportSpecifier>;
|
||||
// @kind(SyntaxKind.NamedImports)
|
||||
export interface NamedImports extends Node {
|
||||
elements: NodeArray<ImportSpecifier>;
|
||||
}
|
||||
|
||||
// @kind(SyntaxKind.NamedImports)
|
||||
export type NamedImports = NamedImportsOrExports;
|
||||
|
||||
// @kind(SyntaxKind.NamedExports)
|
||||
export type NamedExports = NamedImportsOrExports;
|
||||
export interface NamedExports extends Node {
|
||||
elements: NodeArray<ExportSpecifier>;
|
||||
}
|
||||
|
||||
export type NamedImportsOrExports = NamedImports | NamedExports;
|
||||
|
||||
// @kind(SyntaxKind.ImportSpecifier)
|
||||
// @factoryhidden("decorators", true)
|
||||
// @factoryhidden("modifiers", true)
|
||||
export interface ImportOrExportSpecifier extends Declaration {
|
||||
export interface ImportSpecifier extends Declaration {
|
||||
propertyName?: Identifier; // Name preceding "as" keyword (or undefined when "as" is absent)
|
||||
name: Identifier; // Declared name
|
||||
}
|
||||
|
||||
// @kind(SyntaxKind.ImportSpecifier)
|
||||
export type ImportSpecifier = ImportOrExportSpecifier;
|
||||
|
||||
// @kind(SyntaxKind.ExportSpecifier)
|
||||
export type ExportSpecifier = ImportOrExportSpecifier;
|
||||
// @factoryhidden("decorators", true)
|
||||
// @factoryhidden("modifiers", true)
|
||||
export interface ExportSpecifier extends Declaration {
|
||||
propertyName?: Identifier; // Name preceding "as" keyword (or undefined when "as" is absent)
|
||||
name: Identifier; // Declared name
|
||||
}
|
||||
|
||||
export type ImportOrExportSpecifier = ImportSpecifier | ExportSpecifier;
|
||||
|
||||
// @kind(SyntaxKind.ExportAssignment)
|
||||
// @factoryhidden("name", true)
|
||||
|
@ -2959,6 +2973,19 @@ namespace ts {
|
|||
write(node: T): void;
|
||||
}
|
||||
|
||||
// @internal
|
||||
export interface TransformationResolver {
|
||||
getAssignmentSubstitution(sourceFile: SourceFile): (node: BinaryExpression) => Expression;
|
||||
getExpressionIdentifierSubstitution(sourceFile: SourceFile): (node: Identifier) => LeftHandSideExpression;
|
||||
getBindingIdentifierSubstitution(sourceFile: SourceFile): (node: Identifier) => Identifier;
|
||||
}
|
||||
|
||||
// @internal
|
||||
export interface TransformationResult {
|
||||
sourceFiles: SourceFile[];
|
||||
transformationResolver?: TransformationResolver;
|
||||
}
|
||||
|
||||
// @internal
|
||||
export interface Transformer {
|
||||
getEmitResolver(): EmitResolver;
|
||||
|
@ -2988,6 +3015,15 @@ namespace ts {
|
|||
emitEmitHelpers(write: (node: Statement) => void): void;
|
||||
emitExportStarHelper(write: (node: Statement) => void): void;
|
||||
|
||||
getAssignmentSubstitution(sourceFile: SourceFile): (node: BinaryExpression) => Expression;
|
||||
setAssignmentSubstitution(sourceFile: SourceFile, substitution: (node: BinaryExpression) => Expression): void;
|
||||
|
||||
getExpressionIdentifierSubstitution(sourceFile: SourceFile): (node: Identifier) => LeftHandSideExpression;
|
||||
setExpressionIdentifierSubstitution(sourceFile: SourceFile, substitution: (node: Identifier) => LeftHandSideExpression): void;
|
||||
|
||||
getBindingIdentifierSubstitution(sourceFile: SourceFile): (node: Identifier) => Identifier;
|
||||
setBindingIdentifierSubstitution(sourceFile: SourceFile, substitution: (node: Identifier) => Identifier): void;
|
||||
|
||||
startLexicalEnvironment(): void;
|
||||
endLexicalEnvironment(out: ((node: Statement) => void) | Statement[]): void;
|
||||
|
||||
|
|
|
@ -1251,7 +1251,11 @@ namespace ts {
|
|||
// If we don't need to downlevel and we can reach the original source text using
|
||||
// the node's parent reference, then simply get the text as it was originally written.
|
||||
if (!nodeIsSynthesized(node) && node.parent) {
|
||||
return getSourceTextOfNodeFromSourceFile(sourceFile, node);
|
||||
let text = getSourceTextOfNodeFromSourceFile(sourceFile, node);
|
||||
if (languageVersion < ScriptTarget.ES6 && isBinaryOrOctalIntegerLiteral(node, text)) {
|
||||
return node.text;
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
// If we can't reach the original source text, use the canonical form if it's a number,
|
||||
|
@ -1274,6 +1278,19 @@ namespace ts {
|
|||
Debug.fail(`Literal kind '${node.kind}' not accounted for.`);
|
||||
}
|
||||
|
||||
function isBinaryOrOctalIntegerLiteral(node: LiteralExpression, text: string) {
|
||||
if (node.kind === SyntaxKind.NumericLiteral && text.length > 1) {
|
||||
switch (text.charCodeAt(1)) {
|
||||
case CharacterCodes.b:
|
||||
case CharacterCodes.B:
|
||||
case CharacterCodes.o:
|
||||
case CharacterCodes.O:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function getQuotedEscapedLiteralText(leftQuote: string, text: string, rightQuote: string) {
|
||||
return leftQuote + escapeNonAsciiCharacters(escapeString(text)) + rightQuote;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue