diff --git a/.gitignore b/.gitignore
index fb84462083c..740e43525b5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -39,4 +39,5 @@ scripts/debug.bat
scripts/run.bat
scripts/word2md.js
scripts/ior.js
+scripts/*.js.map
coverage/
diff --git a/Jakefile b/Jakefile
index 0a34de4182b..ba82e9c3f43 100644
--- a/Jakefile
+++ b/Jakefile
@@ -135,7 +135,6 @@ function concatenateFiles(destinationFile, sourceFiles) {
}
var useDebugMode = true;
-var generateDeclarations = false;
var host = (process.env.host || process.env.TYPESCRIPT_HOST || "node");
var compilerFilename = "tsc.js";
/* Compiles a file from a list of sources
@@ -146,7 +145,7 @@ var compilerFilename = "tsc.js";
* @param useBuiltCompiler: true to use the built compiler, false to use the LKG
* @param noOutFile: true to compile without using --out
*/
-function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOutFile) {
+function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOutFile, generateDeclarations) {
file(outFile, prereqs, function() {
var dir = useBuiltCompiler ? builtLocalDirectory : LKGDirectory;
var options = "-removeComments --module commonjs -noImplicitAny ";
@@ -157,7 +156,7 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOu
if (useDebugMode) {
options += "--preserveConstEnums ";
}
-
+
var cmd = host + " " + dir + compilerFilename + " " + options + " ";
cmd = cmd + sources.join(" ") + (!noOutFile ? " -out " + outFile : "");
if (useDebugMode) {
@@ -184,7 +183,7 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, noOu
fs.unlinkSync(outFile);
console.log("Compilation of " + outFile + " unsuccessful");
});
- ex.run();
+ ex.run();
}, {async: true});
}
@@ -239,7 +238,7 @@ file(diagnosticInfoMapTs, [processDiagnosticMessagesJs, diagnosticMessagesJson],
ex.addListener("cmdEnd", function() {
complete();
});
- ex.run();
+ ex.run();
}, {async: true})
@@ -252,7 +251,8 @@ var tscFile = path.join(builtLocalDirectory, compilerFilename);
compileFile(tscFile, compilerSources, [builtLocalDirectory, copyright].concat(compilerSources), [copyright], /*useBuiltCompiler:*/ false);
var servicesFile = path.join(builtLocalDirectory, "typescriptServices.js");
-compileFile(servicesFile, servicesSources, [builtLocalDirectory, copyright].concat(servicesSources), [copyright], /*useBuiltCompiler:*/ true);
+var servicesDefinitionsFile = path.join(builtLocalDirectory, "typescriptServices.d.ts");
+compileFile(servicesFile, servicesSources, [builtLocalDirectory, copyright].concat(servicesSources), [copyright], /*useBuiltCompiler:*/ true, /*noOutFile:*/ false, /*generateDeclarations:*/ true);
// Local target to build the compiler and services
desc("Builds the full compiler and services");
@@ -275,11 +275,6 @@ task("clean", function() {
jake.rmRf(builtDirectory);
});
-// generate declarations for compiler and services
-desc("Generate declarations for compiler and services");
-task("declaration", function() {
- generateDeclarations = true;
-});
// Generate Markdown spec
var word2mdJs = path.join(scriptsDirectory, "word2md.js");
@@ -314,7 +309,7 @@ task("generate-spec", [specMd])
// Makes a new LKG. This target does not build anything, but errors if not all the outputs are present in the built/local directory
desc("Makes a new LKG out of the built js files");
task("LKG", ["clean", "release", "local"].concat(libraryTargets), function() {
- var expectedFiles = [tscFile, servicesFile].concat(libraryTargets);
+ var expectedFiles = [tscFile, servicesFile, servicesDefinitionsFile].concat(libraryTargets);
var missingFiles = expectedFiles.filter(function (f) {
return !fs.existsSync(f);
});
@@ -547,7 +542,7 @@ file(loggedIOJsPath, [builtLocalDirectory, loggedIOpath], function() {
jake.rmRf(temp);
complete();
});
- ex.run();
+ ex.run();
}, {async: true});
var instrumenterPath = harnessDirectory + 'instrumenter.ts';
diff --git a/bin/lib.d.ts b/bin/lib.d.ts
index 8890fab4284..c18bd4ff8b4 100644
--- a/bin/lib.d.ts
+++ b/bin/lib.d.ts
@@ -1489,7 +1489,7 @@ interface Uint32Array extends ArrayBufferView {
set(array: number[], offset?: number): void;
/**
- * Gets a new Int8Array view of the ArrayBuffer Object store for this array, specifying the first and last members of the subarray.
+ * Gets a new Uint32Array view of the ArrayBuffer Object store for this array, specifying the first and last members of the subarray.
* @param begin The index of the beginning of the array.
* @param end The index of the end of the array.
*/
diff --git a/bin/tsc.js b/bin/tsc.js
index df74c76f504..c1ce8cee83d 100644
--- a/bin/tsc.js
+++ b/bin/tsc.js
@@ -418,6 +418,10 @@ var ts;
return normalizedPathComponents(path, rootLength);
}
ts.getNormalizedPathComponents = getNormalizedPathComponents;
+ function getNormalizedAbsolutePath(filename, currentDirectory) {
+ return getNormalizedPathFromPathComponents(getNormalizedPathComponents(filename, currentDirectory));
+ }
+ ts.getNormalizedAbsolutePath = getNormalizedAbsolutePath;
function getNormalizedPathFromPathComponents(pathComponents) {
if (pathComponents && pathComponents.length) {
return pathComponents[0] + pathComponents.slice(1).join(ts.directorySeparator);
@@ -907,7 +911,8 @@ var ts;
Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1159, category: 1 /* Error */, key: "Tagged templates are only available when targeting ECMAScript 6 and higher." },
Unterminated_template_literal: { code: 1160, category: 1 /* Error */, key: "Unterminated template literal." },
Unterminated_regular_expression_literal: { code: 1161, category: 1 /* Error */, key: "Unterminated regular expression literal." },
- A_object_member_cannot_be_declared_optional: { code: 1160, category: 1 /* Error */, key: "A object member cannot be declared optional." },
+ An_object_member_cannot_be_declared_optional: { code: 1162, category: 1 /* Error */, key: "An object member cannot be declared optional." },
+ yield_expression_must_be_contained_within_a_generator_declaration: { code: 1163, category: 1 /* Error */, key: "'yield' expression must be contained_within a generator declaration." },
Duplicate_identifier_0: { code: 2300, category: 1 /* Error */, key: "Duplicate identifier '{0}'." },
Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: 1 /* Error */, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." },
Static_members_cannot_reference_class_type_parameters: { code: 2302, category: 1 /* Error */, key: "Static members cannot reference class type parameters." },
@@ -1058,27 +1063,16 @@ var ts;
Type_alias_name_cannot_be_0: { code: 2457, category: 1 /* Error */, key: "Type alias name cannot be '{0}'" },
An_AMD_module_cannot_have_multiple_name_assignments: { code: 2458, category: 1 /* Error */, key: "An AMD module cannot have multiple name assignments." },
Import_declaration_0_is_using_private_name_1: { code: 4000, category: 1 /* Error */, key: "Import declaration '{0}' is using private name '{1}'." },
- Type_parameter_0_of_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4001, category: 1 /* Error */, key: "Type parameter '{0}' of exported class has or is using name '{1}' from private module '{2}'." },
Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: 1 /* Error */, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." },
- Type_parameter_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 4003, category: 1 /* Error */, key: "Type parameter '{0}' of exported interface has or is using name '{1}' from private module '{2}'." },
Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: 1 /* Error */, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." },
- Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 4005, category: 1 /* Error */, key: "Type parameter '{0}' of constructor signature from exported interface has or is using name '{1}' from private module '{2}'." },
Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1: { code: 4006, category: 1 /* Error */, key: "Type parameter '{0}' of constructor signature from exported interface has or is using private name '{1}'." },
- Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 4007, category: 1 /* Error */, key: "Type parameter '{0}' of call signature from exported interface has or is using name '{1}' from private module '{2}'." },
Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1: { code: 4008, category: 1 /* Error */, key: "Type parameter '{0}' of call signature from exported interface has or is using private name '{1}'." },
- Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4009, category: 1 /* Error */, key: "Type parameter '{0}' of public static method from exported class has or is using name '{1}' from private module '{2}'." },
Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1: { code: 4010, category: 1 /* Error */, key: "Type parameter '{0}' of public static method from exported class has or is using private name '{1}'." },
- Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4011, category: 1 /* Error */, key: "Type parameter '{0}' of public method from exported class has or is using name '{1}' from private module '{2}'." },
Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1: { code: 4012, category: 1 /* Error */, key: "Type parameter '{0}' of public method from exported class has or is using private name '{1}'." },
- Type_parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 4013, category: 1 /* Error */, key: "Type parameter '{0}' of method from exported interface has or is using name '{1}' from private module '{2}'." },
Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1: { code: 4014, category: 1 /* Error */, key: "Type parameter '{0}' of method from exported interface has or is using private name '{1}'." },
- Type_parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2: { code: 4015, category: 1 /* Error */, key: "Type parameter '{0}' of exported function has or is using name '{1}' from private module '{2}'." },
Type_parameter_0_of_exported_function_has_or_is_using_private_name_1: { code: 4016, category: 1 /* Error */, key: "Type parameter '{0}' of exported function has or is using private name '{1}'." },
- Implements_clause_of_exported_class_0_has_or_is_using_name_1_from_private_module_2: { code: 4017, category: 1 /* Error */, key: "Implements clause of exported class '{0}' has or is using name '{1}' from private module '{2}'." },
- Extends_clause_of_exported_class_0_has_or_is_using_name_1_from_private_module_2: { code: 4018, category: 1 /* Error */, key: "Extends clause of exported class '{0}' has or is using name '{1}' from private module '{2}'." },
Implements_clause_of_exported_class_0_has_or_is_using_private_name_1: { code: 4019, category: 1 /* Error */, key: "Implements clause of exported class '{0}' has or is using private name '{1}'." },
Extends_clause_of_exported_class_0_has_or_is_using_private_name_1: { code: 4020, category: 1 /* Error */, key: "Extends clause of exported class '{0}' has or is using private name '{1}'." },
- Extends_clause_of_exported_interface_0_has_or_is_using_name_1_from_private_module_2: { code: 4021, category: 1 /* Error */, key: "Extends clause of exported interface '{0}' has or is using name '{1}' from private module '{2}'." },
Extends_clause_of_exported_interface_0_has_or_is_using_private_name_1: { code: 4022, category: 1 /* Error */, key: "Extends clause of exported interface '{0}' has or is using private name '{1}'." },
Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: { code: 4023, category: 1 /* Error */, key: "Exported variable '{0}' has or is using name '{1}' from external module {2} but cannot be named." },
Exported_variable_0_has_or_is_using_name_1_from_private_module_2: { code: 4024, category: 1 /* Error */, key: "Exported variable '{0}' has or is using name '{1}' from private module '{2}'." },
@@ -1136,8 +1130,6 @@ var ts;
Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: { code: 4076, category: 1 /* Error */, key: "Parameter '{0}' of exported function has or is using name '{1}' from external module {2} but cannot be named." },
Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2: { code: 4077, category: 1 /* Error */, key: "Parameter '{0}' of exported function has or is using name '{1}' from private module '{2}'." },
Parameter_0_of_exported_function_has_or_is_using_private_name_1: { code: 4078, category: 1 /* Error */, key: "Parameter '{0}' of exported function has or is using private name '{1}'." },
- Exported_type_alias_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: { code: 4079, category: 1 /* Error */, key: "Exported type alias '{0}' has or is using name '{1}' from external module {2} but cannot be named." },
- Exported_type_alias_0_has_or_is_using_name_1_from_private_module_2: { code: 4080, category: 1 /* Error */, key: "Exported type alias '{0}' has or is using name '{1}' from private module '{2}'." },
Exported_type_alias_0_has_or_is_using_private_name_1: { code: 4081, category: 1 /* Error */, key: "Exported type alias '{0}' has or is using private name '{1}'." },
Enum_declarations_must_all_be_const_or_non_const: { code: 4082, category: 1 /* Error */, key: "Enum declarations must all be const or non-const." },
In_const_enum_declarations_member_initializer_must_be_constant_expression: { code: 4083, category: 1 /* Error */, key: "In 'const' enum declarations member initializer must be constant expression.", isEarly: true },
@@ -1208,7 +1200,9 @@ var ts;
_0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer: { code: 7022, category: 1 /* Error */, key: "'{0}' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer." },
_0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7023, category: 1 /* Error */, key: "'{0}' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." },
Function_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7024, category: 1 /* Error */, key: "Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." },
- You_cannot_rename_this_element: { code: 8000, category: 1 /* Error */, key: "You cannot rename this element." }
+ You_cannot_rename_this_element: { code: 8000, category: 1 /* Error */, key: "You cannot rename this element." },
+ yield_expressions_are_not_currently_supported: { code: 9000, category: 1 /* Error */, key: "'yield' expressions are not currently supported." },
+ generators_are_not_currently_supported: { code: 9001, category: 1 /* Error */, key: "'generators' are not currently supported." }
};
})(ts || (ts = {}));
var ts;
@@ -1981,11 +1975,11 @@ var ts;
value = 0;
}
tokenValue = "" + value;
- return 6 /* NumericLiteral */;
+ return token = 6 /* NumericLiteral */;
}
if (pos + 1 < len && isOctalDigit(text.charCodeAt(pos + 1))) {
tokenValue = "" + scanOctalDigits();
- return 6 /* NumericLiteral */;
+ return token = 6 /* NumericLiteral */;
}
case 49 /* _1 */:
case 50 /* _2 */:
@@ -2206,7 +2200,7 @@ var ts;
})(ts || (ts = {}));
var ts;
(function (ts) {
- var nodeConstructors = new Array(199 /* Count */);
+ var nodeConstructors = new Array(200 /* Count */);
function getNodeConstructor(kind) {
return nodeConstructors[kind] || (nodeConstructors[kind] = ts.objectAllocator.getNodeConstructor(kind));
}
@@ -2219,7 +2213,7 @@ var ts;
return node;
}
function getSourceFileOfNode(node) {
- while (node && node.kind !== 196 /* SourceFile */)
+ while (node && node.kind !== 197 /* SourceFile */)
node = node.parent;
return node;
}
@@ -2241,13 +2235,17 @@ var ts;
return ts.skipTrivia((sourceFile || getSourceFileOfNode(node)).text, node.pos);
}
ts.getTokenPosOfNode = getTokenPosOfNode;
+ function getSourceTextOfNodeFromSourceFile(sourceFile, node) {
+ var text = sourceFile.text;
+ return text.substring(ts.skipTrivia(text, node.pos), node.end);
+ }
+ ts.getSourceTextOfNodeFromSourceFile = getSourceTextOfNodeFromSourceFile;
function getTextOfNodeFromSourceText(sourceText, node) {
return sourceText.substring(ts.skipTrivia(sourceText, node.pos), node.end);
}
ts.getTextOfNodeFromSourceText = getTextOfNodeFromSourceText;
function getTextOfNode(node) {
- var text = getSourceFileOfNode(node).text;
- return text.substring(ts.skipTrivia(text, node.pos), node.end);
+ return getSourceTextOfNodeFromSourceFile(getSourceFileOfNode(node), node);
}
ts.getTextOfNode = getTextOfNode;
function escapeIdentifier(identifier) {
@@ -2281,12 +2279,12 @@ var ts;
function getErrorSpanForNode(node) {
var errorSpan;
switch (node.kind) {
- case 184 /* VariableDeclaration */:
- case 187 /* ClassDeclaration */:
- case 188 /* InterfaceDeclaration */:
- case 191 /* ModuleDeclaration */:
- case 190 /* EnumDeclaration */:
- case 195 /* EnumMember */:
+ case 185 /* VariableDeclaration */:
+ case 188 /* ClassDeclaration */:
+ case 189 /* InterfaceDeclaration */:
+ case 192 /* ModuleDeclaration */:
+ case 191 /* EnumDeclaration */:
+ case 196 /* EnumMember */:
errorSpan = node.name;
break;
}
@@ -2302,11 +2300,19 @@ var ts;
}
ts.isDeclarationFile = isDeclarationFile;
function isConstEnumDeclaration(node) {
- return (node.flags & 4096 /* Const */) !== 0;
+ return node.kind === 191 /* EnumDeclaration */ && isConst(node);
}
ts.isConstEnumDeclaration = isConstEnumDeclaration;
+ function isConst(node) {
+ return !!(node.flags & 4096 /* Const */);
+ }
+ ts.isConst = isConst;
+ function isLet(node) {
+ return !!(node.flags & 2048 /* Let */);
+ }
+ ts.isLet = isLet;
function isPrologueDirective(node) {
- return node.kind === 164 /* ExpressionStatement */ && node.expression.kind === 7 /* StringLiteral */;
+ return node.kind === 165 /* ExpressionStatement */ && node.expression.kind === 7 /* StringLiteral */;
}
ts.isPrologueDirective = isPrologueDirective;
function isEvalOrArgumentsIdentifier(node) {
@@ -2375,7 +2381,7 @@ var ts;
case 127 /* GetAccessor */:
case 128 /* SetAccessor */:
case 152 /* FunctionExpression */:
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
case 153 /* ArrowFunction */:
return child(node.name) || children(node.typeParameters) || children(node.parameters) || child(node.type) || child(node.body);
case 132 /* TypeReference */:
@@ -2416,64 +2422,64 @@ var ts;
return child(node.left) || child(node.right);
case 157 /* ConditionalExpression */:
return child(node.condition) || child(node.whenTrue) || child(node.whenFalse);
- case 161 /* Block */:
- case 180 /* TryBlock */:
- case 182 /* FinallyBlock */:
- case 186 /* FunctionBlock */:
- case 192 /* ModuleBlock */:
- case 196 /* SourceFile */:
+ case 162 /* Block */:
+ case 181 /* TryBlock */:
+ case 183 /* FinallyBlock */:
+ case 187 /* FunctionBlock */:
+ case 193 /* ModuleBlock */:
+ case 197 /* SourceFile */:
return children(node.statements);
- case 162 /* VariableStatement */:
+ case 163 /* VariableStatement */:
return children(node.declarations);
- case 164 /* ExpressionStatement */:
+ case 165 /* ExpressionStatement */:
return child(node.expression);
- case 165 /* IfStatement */:
+ case 166 /* IfStatement */:
return child(node.expression) || child(node.thenStatement) || child(node.elseStatement);
- case 166 /* DoStatement */:
+ case 167 /* DoStatement */:
return child(node.statement) || child(node.expression);
- case 167 /* WhileStatement */:
+ case 168 /* WhileStatement */:
return child(node.expression) || child(node.statement);
- case 168 /* ForStatement */:
+ case 169 /* ForStatement */:
return children(node.declarations) || child(node.initializer) || child(node.condition) || child(node.iterator) || child(node.statement);
- case 169 /* ForInStatement */:
- return child(node.declaration) || child(node.variable) || child(node.expression) || child(node.statement);
- case 170 /* ContinueStatement */:
- case 171 /* BreakStatement */:
+ case 170 /* ForInStatement */:
+ return children(node.declarations) || child(node.variable) || child(node.expression) || child(node.statement);
+ case 171 /* ContinueStatement */:
+ case 172 /* BreakStatement */:
return child(node.label);
- case 172 /* ReturnStatement */:
+ case 173 /* ReturnStatement */:
return child(node.expression);
- case 173 /* WithStatement */:
+ case 174 /* WithStatement */:
return child(node.expression) || child(node.statement);
- case 174 /* SwitchStatement */:
+ case 175 /* SwitchStatement */:
return child(node.expression) || children(node.clauses);
- case 175 /* CaseClause */:
- case 176 /* DefaultClause */:
+ case 176 /* CaseClause */:
+ case 177 /* DefaultClause */:
return child(node.expression) || children(node.statements);
- case 177 /* LabeledStatement */:
+ case 178 /* LabeledStatement */:
return child(node.label) || child(node.statement);
- case 178 /* ThrowStatement */:
+ case 179 /* ThrowStatement */:
return child(node.expression);
- case 179 /* TryStatement */:
+ case 180 /* TryStatement */:
return child(node.tryBlock) || child(node.catchBlock) || child(node.finallyBlock);
- case 181 /* CatchBlock */:
+ case 182 /* CatchBlock */:
return child(node.variable) || children(node.statements);
- case 184 /* VariableDeclaration */:
+ case 185 /* VariableDeclaration */:
return child(node.name) || child(node.type) || child(node.initializer);
- case 187 /* ClassDeclaration */:
+ case 188 /* ClassDeclaration */:
return child(node.name) || children(node.typeParameters) || child(node.baseType) || children(node.implementedTypes) || children(node.members);
- case 188 /* InterfaceDeclaration */:
+ case 189 /* InterfaceDeclaration */:
return child(node.name) || children(node.typeParameters) || children(node.baseTypes) || children(node.members);
- case 189 /* TypeAliasDeclaration */:
+ case 190 /* TypeAliasDeclaration */:
return child(node.name) || child(node.type);
- case 190 /* EnumDeclaration */:
+ case 191 /* EnumDeclaration */:
return child(node.name) || children(node.members);
- case 195 /* EnumMember */:
+ case 196 /* EnumMember */:
return child(node.name) || child(node.initializer);
- case 191 /* ModuleDeclaration */:
+ case 192 /* ModuleDeclaration */:
return child(node.name) || child(node.body);
- case 193 /* ImportDeclaration */:
+ case 194 /* ImportDeclaration */:
return child(node.name) || child(node.entityName) || child(node.externalModuleName);
- case 194 /* ExportAssignment */:
+ case 195 /* ExportAssignment */:
return child(node.exportName);
case 158 /* TemplateExpression */:
return child(node.head) || children(node.templateSpans);
@@ -2486,24 +2492,24 @@ var ts;
return traverse(body);
function traverse(node) {
switch (node.kind) {
- case 172 /* ReturnStatement */:
+ case 173 /* ReturnStatement */:
return visitor(node);
- case 161 /* Block */:
- case 186 /* FunctionBlock */:
- case 165 /* IfStatement */:
- case 166 /* DoStatement */:
- case 167 /* WhileStatement */:
- case 168 /* ForStatement */:
- case 169 /* ForInStatement */:
- case 173 /* WithStatement */:
- case 174 /* SwitchStatement */:
- case 175 /* CaseClause */:
- case 176 /* DefaultClause */:
- case 177 /* LabeledStatement */:
- case 179 /* TryStatement */:
- case 180 /* TryBlock */:
- case 181 /* CatchBlock */:
- case 182 /* FinallyBlock */:
+ case 162 /* Block */:
+ case 187 /* FunctionBlock */:
+ case 166 /* IfStatement */:
+ case 167 /* DoStatement */:
+ case 168 /* WhileStatement */:
+ case 169 /* ForStatement */:
+ case 170 /* ForInStatement */:
+ case 174 /* WithStatement */:
+ case 175 /* SwitchStatement */:
+ case 176 /* CaseClause */:
+ case 177 /* DefaultClause */:
+ case 178 /* LabeledStatement */:
+ case 180 /* TryStatement */:
+ case 181 /* TryBlock */:
+ case 182 /* CatchBlock */:
+ case 183 /* FinallyBlock */:
return forEachChild(node, traverse);
}
}
@@ -2513,7 +2519,7 @@ var ts;
if (node) {
switch (node.kind) {
case 152 /* FunctionExpression */:
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
case 153 /* ArrowFunction */:
case 125 /* Method */:
case 127 /* GetAccessor */:
@@ -2545,16 +2551,16 @@ var ts;
if (!includeArrowFunctions) {
continue;
}
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
case 152 /* FunctionExpression */:
- case 191 /* ModuleDeclaration */:
+ case 192 /* ModuleDeclaration */:
case 124 /* Property */:
case 125 /* Method */:
case 126 /* Constructor */:
case 127 /* GetAccessor */:
case 128 /* SetAccessor */:
- case 190 /* EnumDeclaration */:
- case 196 /* SourceFile */:
+ case 191 /* EnumDeclaration */:
+ case 197 /* SourceFile */:
return node;
}
}
@@ -2577,6 +2583,13 @@ var ts;
}
}
ts.getSuperContainer = getSuperContainer;
+ function getInvokedExpression(node) {
+ if (node.kind === 149 /* TaggedTemplateExpression */) {
+ return node.tag;
+ }
+ return node.func;
+ }
+ ts.getInvokedExpression = getInvokedExpression;
function isExpression(node) {
switch (node.kind) {
case 91 /* ThisKeyword */:
@@ -2602,7 +2615,7 @@ var ts;
case 157 /* ConditionalExpression */:
case 158 /* TemplateExpression */:
case 9 /* NoSubstitutionTemplateLiteral */:
- case 160 /* OmittedExpression */:
+ case 161 /* OmittedExpression */:
return true;
case 121 /* QualifiedName */:
while (node.parent.kind === 121 /* QualifiedName */)
@@ -2616,26 +2629,26 @@ var ts;
case 7 /* StringLiteral */:
var parent = node.parent;
switch (parent.kind) {
- case 184 /* VariableDeclaration */:
+ case 185 /* VariableDeclaration */:
case 123 /* Parameter */:
case 124 /* Property */:
- case 195 /* EnumMember */:
+ case 196 /* EnumMember */:
case 143 /* PropertyAssignment */:
return parent.initializer === node;
- case 164 /* ExpressionStatement */:
- case 165 /* IfStatement */:
- case 166 /* DoStatement */:
- case 167 /* WhileStatement */:
- case 172 /* ReturnStatement */:
- case 173 /* WithStatement */:
- case 174 /* SwitchStatement */:
- case 175 /* CaseClause */:
- case 178 /* ThrowStatement */:
- case 174 /* SwitchStatement */:
+ case 165 /* ExpressionStatement */:
+ case 166 /* IfStatement */:
+ case 167 /* DoStatement */:
+ case 168 /* WhileStatement */:
+ case 173 /* ReturnStatement */:
+ case 174 /* WithStatement */:
+ case 175 /* SwitchStatement */:
+ case 176 /* CaseClause */:
+ case 179 /* ThrowStatement */:
+ case 175 /* SwitchStatement */:
return parent.expression === node;
- case 168 /* ForStatement */:
+ case 169 /* ForStatement */:
return parent.initializer === node || parent.condition === node || parent.iterator === node;
- case 169 /* ForInStatement */:
+ case 170 /* ForInStatement */:
return parent.variable === node || parent.expression === node;
case 150 /* TypeAssertion */:
return node === parent.operand;
@@ -2679,21 +2692,22 @@ var ts;
switch (node.kind) {
case 122 /* TypeParameter */:
case 123 /* Parameter */:
- case 184 /* VariableDeclaration */:
+ case 185 /* VariableDeclaration */:
case 124 /* Property */:
case 143 /* PropertyAssignment */:
case 144 /* ShorthandPropertyAssignment */:
- case 195 /* EnumMember */:
+ case 196 /* EnumMember */:
case 125 /* Method */:
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
case 127 /* GetAccessor */:
case 128 /* SetAccessor */:
- case 187 /* ClassDeclaration */:
- case 188 /* InterfaceDeclaration */:
- case 189 /* TypeAliasDeclaration */:
- case 190 /* EnumDeclaration */:
- case 191 /* ModuleDeclaration */:
- case 193 /* ImportDeclaration */:
+ case 126 /* Constructor */:
+ case 188 /* ClassDeclaration */:
+ case 189 /* InterfaceDeclaration */:
+ case 190 /* TypeAliasDeclaration */:
+ case 191 /* EnumDeclaration */:
+ case 192 /* ModuleDeclaration */:
+ case 194 /* ImportDeclaration */:
return true;
}
return false;
@@ -2701,24 +2715,24 @@ var ts;
ts.isDeclaration = isDeclaration;
function isStatement(n) {
switch (n.kind) {
- case 171 /* BreakStatement */:
- case 170 /* ContinueStatement */:
- case 183 /* DebuggerStatement */:
- case 166 /* DoStatement */:
- case 164 /* ExpressionStatement */:
- case 163 /* EmptyStatement */:
- case 169 /* ForInStatement */:
- case 168 /* ForStatement */:
- case 165 /* IfStatement */:
- case 177 /* LabeledStatement */:
- case 172 /* ReturnStatement */:
- case 174 /* SwitchStatement */:
+ case 172 /* BreakStatement */:
+ case 171 /* ContinueStatement */:
+ case 184 /* DebuggerStatement */:
+ case 167 /* DoStatement */:
+ case 165 /* ExpressionStatement */:
+ case 164 /* EmptyStatement */:
+ case 170 /* ForInStatement */:
+ case 169 /* ForStatement */:
+ case 166 /* IfStatement */:
+ case 178 /* LabeledStatement */:
+ case 173 /* ReturnStatement */:
+ case 175 /* SwitchStatement */:
case 92 /* ThrowKeyword */:
- case 179 /* TryStatement */:
- case 162 /* VariableStatement */:
- case 167 /* WhileStatement */:
- case 173 /* WithStatement */:
- case 194 /* ExportAssignment */:
+ case 180 /* TryStatement */:
+ case 163 /* VariableStatement */:
+ case 168 /* WhileStatement */:
+ case 174 /* WithStatement */:
+ case 195 /* ExportAssignment */:
return true;
default:
return false;
@@ -2733,24 +2747,32 @@ var ts;
if (isDeclaration(parent) || parent.kind === 152 /* FunctionExpression */) {
return parent.name === name;
}
- if (parent.kind === 181 /* CatchBlock */) {
+ if (parent.kind === 182 /* CatchBlock */) {
return parent.variable === name;
}
return false;
}
ts.isDeclarationOrFunctionExpressionOrCatchVariableName = isDeclarationOrFunctionExpressionOrCatchVariableName;
+ function tryResolveScriptReference(program, sourceFile, reference) {
+ if (!program.getCompilerOptions().noResolve) {
+ var referenceFileName = ts.isRootedDiskPath(reference.filename) ? reference.filename : ts.combinePaths(ts.getDirectoryPath(sourceFile.filename), reference.filename);
+ referenceFileName = ts.getNormalizedAbsolutePath(referenceFileName, program.getCompilerHost().getCurrentDirectory());
+ return program.getSourceFile(referenceFileName);
+ }
+ }
+ ts.tryResolveScriptReference = tryResolveScriptReference;
function getAncestor(node, kind) {
switch (kind) {
- case 187 /* ClassDeclaration */:
+ case 188 /* ClassDeclaration */:
while (node) {
switch (node.kind) {
- case 187 /* ClassDeclaration */:
+ case 188 /* ClassDeclaration */:
return node;
- case 190 /* EnumDeclaration */:
- case 188 /* InterfaceDeclaration */:
- case 189 /* TypeAliasDeclaration */:
- case 191 /* ModuleDeclaration */:
- case 193 /* ImportDeclaration */:
+ case 191 /* EnumDeclaration */:
+ case 189 /* InterfaceDeclaration */:
+ case 190 /* TypeAliasDeclaration */:
+ case 192 /* ModuleDeclaration */:
+ case 194 /* ImportDeclaration */:
return undefined;
default:
node = node.parent;
@@ -2835,11 +2857,14 @@ var ts;
}
ts.isTrivia = isTrivia;
function isUnterminatedTemplateEnd(node) {
- ts.Debug.assert(node.kind === 9 /* NoSubstitutionTemplateLiteral */ || node.kind === 12 /* TemplateTail */);
+ ts.Debug.assert(isTemplateLiteralKind(node.kind));
var sourceText = getSourceFileOfNode(node).text;
if (node.end !== sourceText.length) {
return false;
}
+ if (node.kind !== 12 /* TemplateTail */ && node.kind !== 9 /* NoSubstitutionTemplateLiteral */) {
+ return false;
+ }
return sourceText.charCodeAt(node.end - 1) !== 96 /* backtick */ || node.text.length === 0;
}
ts.isUnterminatedTemplateEnd = isUnterminatedTemplateEnd;
@@ -2856,6 +2881,17 @@ var ts;
return false;
}
ts.isModifier = isModifier;
+ function modifierToFlag(token) {
+ switch (token) {
+ case 107 /* StaticKeyword */: return 128 /* Static */;
+ case 106 /* PublicKeyword */: return 16 /* Public */;
+ case 105 /* ProtectedKeyword */: return 64 /* Protected */;
+ case 104 /* PrivateKeyword */: return 32 /* Private */;
+ case 76 /* ExportKeyword */: return 1 /* Export */;
+ case 112 /* DeclareKeyword */: return 2 /* Ambient */;
+ }
+ return 0;
+ }
function createSourceFile(filename, sourceText, languageVersion, version, isOpen) {
if (isOpen === void 0) { isOpen = false; }
var file;
@@ -2867,86 +2903,76 @@ var ts;
var identifierCount = 0;
var nodeCount = 0;
var lineStarts;
- var isInStrictMode = false;
var lookAheadMode = 0 /* NotLookingAhead */;
- var inAmbientContext = false;
- var inFunctionBody = false;
- var inSwitchStatement = 0 /* NotNested */;
- var inIterationStatement = 0 /* NotNested */;
- var labelledStatementInfo = (function () {
- var functionBoundarySentinel;
- var currentLabelSet;
- var labelSetStack;
- var isIterationStack;
- function addLabel(label) {
- if (!currentLabelSet) {
- currentLabelSet = {};
- }
- currentLabelSet[label.text] = true;
+ var contextFlags = 0;
+ function setContextFlag(val, flag) {
+ if (val) {
+ contextFlags |= flag;
}
- function pushCurrentLabelSet(isIterationStatement) {
- if (!labelSetStack && !isIterationStack) {
- labelSetStack = [];
- isIterationStack = [];
- }
- ts.Debug.assert(currentLabelSet !== undefined);
- labelSetStack.push(currentLabelSet);
- isIterationStack.push(isIterationStatement);
- currentLabelSet = undefined;
+ else {
+ contextFlags &= ~flag;
}
- function pushFunctionBoundary() {
- if (!functionBoundarySentinel) {
- functionBoundarySentinel = {};
- if (!labelSetStack && !isIterationStack) {
- labelSetStack = [];
- isIterationStack = [];
- }
- }
- ts.Debug.assert(currentLabelSet === undefined);
- labelSetStack.push(functionBoundarySentinel);
- isIterationStack.push(false);
+ }
+ function setStrictModeContext(val) {
+ setContextFlag(val, 1 /* StrictMode */);
+ }
+ function setDisallowInContext(val) {
+ setContextFlag(val, 2 /* DisallowIn */);
+ }
+ function setYieldContext(val) {
+ setContextFlag(val, 4 /* Yield */);
+ }
+ function setGeneratorParameterContext(val) {
+ setContextFlag(val, 8 /* GeneratorParameter */);
+ }
+ function allowInAnd(func) {
+ if (contextFlags & 2 /* DisallowIn */) {
+ setDisallowInContext(false);
+ var result = func();
+ setDisallowInContext(true);
+ return result;
}
- function pop() {
- ts.Debug.assert(labelSetStack.length && isIterationStack.length && currentLabelSet === undefined);
- labelSetStack.pop();
- isIterationStack.pop();
+ return func();
+ }
+ function disallowInAnd(func) {
+ if (contextFlags & 2 /* DisallowIn */) {
+ return func();
}
- function nodeIsNestedInLabel(label, requireIterationStatement, stopAtFunctionBoundary) {
- if (!requireIterationStatement && currentLabelSet && ts.hasProperty(currentLabelSet, label.text)) {
- return 1 /* Nested */;
- }
- if (!labelSetStack) {
- return 0 /* NotNested */;
- }
- var crossedFunctionBoundary = false;
- for (var i = labelSetStack.length - 1; i >= 0; i--) {
- var labelSet = labelSetStack[i];
- if (labelSet === functionBoundarySentinel) {
- if (stopAtFunctionBoundary) {
- break;
- }
- else {
- crossedFunctionBoundary = true;
- continue;
- }
- }
- if (requireIterationStatement && isIterationStack[i] === false) {
- continue;
- }
- if (ts.hasProperty(labelSet, label.text)) {
- return crossedFunctionBoundary ? 2 /* CrossingFunctionBoundary */ : 1 /* Nested */;
- }
- }
- return 0 /* NotNested */;
+ setDisallowInContext(true);
+ var result = func();
+ setDisallowInContext(false);
+ return result;
+ }
+ function doInYieldContext(func) {
+ if (contextFlags & 4 /* Yield */) {
+ return func();
}
- return {
- addLabel: addLabel,
- pushCurrentLabelSet: pushCurrentLabelSet,
- pushFunctionBoundary: pushFunctionBoundary,
- pop: pop,
- nodeIsNestedInLabel: nodeIsNestedInLabel
- };
- })();
+ setYieldContext(true);
+ var result = func();
+ setYieldContext(false);
+ return result;
+ }
+ function doOutsideOfYieldContext(func) {
+ if (contextFlags & 4 /* Yield */) {
+ setYieldContext(false);
+ var result = func();
+ setYieldContext(true);
+ return result;
+ }
+ return func();
+ }
+ function inYieldContext() {
+ return (contextFlags & 4 /* Yield */) !== 0;
+ }
+ function inStrictModeContext() {
+ return (contextFlags & 1 /* StrictMode */) !== 0;
+ }
+ function inGeneratorParameterContext() {
+ return (contextFlags & 8 /* GeneratorParameter */) !== 0;
+ }
+ function inDisallowInContext() {
+ return (contextFlags & 2 /* DisallowIn */) !== 0;
+ }
function getLineStarts() {
return lineStarts || (lineStarts = ts.computeLineStarts(sourceText));
}
@@ -2961,25 +2987,12 @@ var ts;
var length = scanner.getTextPos() - start;
errorAtPos(start, length, message, arg0, arg1, arg2);
}
- function grammarErrorOnNode(node, message, arg0, arg1, arg2) {
- var span = getErrorSpanForNode(node);
- var start = span.end > span.pos ? ts.skipTrivia(file.text, span.pos) : span.pos;
- var length = span.end - start;
- file.syntacticErrors.push(ts.createFileDiagnostic(file, start, length, message, arg0, arg1, arg2));
- }
- function reportInvalidUseInStrictMode(node) {
- var name = sourceText.substring(ts.skipTrivia(sourceText, node.pos), node.end);
- grammarErrorOnNode(node, ts.Diagnostics.Invalid_use_of_0_in_strict_mode, name);
- }
- function grammarErrorAtPos(start, length, message, arg0, arg1, arg2) {
- file.syntacticErrors.push(ts.createFileDiagnostic(file, start, length, message, arg0, arg1, arg2));
- }
function errorAtPos(start, length, message, arg0, arg1, arg2) {
- var lastErrorPos = file.syntacticErrors.length ? file.syntacticErrors[file.syntacticErrors.length - 1].start : -1;
+ var lastErrorPos = file.parseDiagnostics.length ? file.parseDiagnostics[file.parseDiagnostics.length - 1].start : -1;
if (start !== lastErrorPos) {
var diagnostic = ts.createFileDiagnostic(file, start, length, message, arg0, arg1, arg2);
diagnostic.isParseError = true;
- file.syntacticErrors.push(diagnostic);
+ file.parseDiagnostics.push(diagnostic);
}
if (lookAheadMode === 1 /* NoErrorYet */) {
lookAheadMode = 2 /* Error */;
@@ -3016,7 +3029,7 @@ var ts;
}
function lookAheadHelper(callback, alwaysResetState) {
var saveToken = token;
- var saveSyntacticErrorsLength = file.syntacticErrors.length;
+ var saveSyntacticErrorsLength = file.parseDiagnostics.length;
var saveLookAheadMode = lookAheadMode;
lookAheadMode = 1 /* NoErrorYet */;
var result = callback();
@@ -3027,7 +3040,7 @@ var ts;
lookAheadMode = saveLookAheadMode;
if (!result || alwaysResetState) {
token = saveToken;
- file.syntacticErrors.length = saveSyntacticErrorsLength;
+ file.parseDiagnostics.length = saveSyntacticErrorsLength;
}
return result;
}
@@ -3043,7 +3056,13 @@ var ts;
return scanner.tryScan(function () { return lookAheadHelper(callback, false); });
}
function isIdentifier() {
- return token === 63 /* Identifier */ || (isInStrictMode ? token > 108 /* LastFutureReservedWord */ : token > 99 /* LastReservedWord */);
+ if (token === 63 /* Identifier */) {
+ return true;
+ }
+ if (token === 108 /* YieldKeyword */ && inYieldContext()) {
+ return false;
+ }
+ return inStrictModeContext() ? token > 108 /* LastFutureReservedWord */ : token > 99 /* LastReservedWord */;
}
function parseExpected(t) {
if (token === t) {
@@ -3060,6 +3079,14 @@ var ts;
}
return false;
}
+ function parseOptionalToken(t) {
+ if (token === t) {
+ var node = createNode(t);
+ nextToken();
+ return finishNode(node);
+ }
+ return undefined;
+ }
function canParseSemicolon() {
if (token === 21 /* SemicolonToken */) {
return true;
@@ -3079,18 +3106,22 @@ var ts;
function createNode(kind, pos) {
nodeCount++;
var node = new (nodeConstructors[kind] || (nodeConstructors[kind] = ts.objectAllocator.getNodeConstructor(kind)))();
- if (!(pos >= 0))
+ if (!(pos >= 0)) {
pos = scanner.getStartPos();
+ }
node.pos = pos;
node.end = pos;
return node;
}
function finishNode(node) {
node.end = scanner.getStartPos();
+ if (contextFlags) {
+ node.parserContextFlags = contextFlags;
+ }
return node;
}
- function createMissingNode() {
- return createNode(120 /* Missing */);
+ function createMissingNode(pos) {
+ return createNode(120 /* Missing */, pos);
}
function internIdentifier(text) {
text = escapeIdentifier(text);
@@ -3133,7 +3164,7 @@ var ts;
function parseAnyContextualModifier() {
return isModifier(token) && tryParse(function () {
nextToken();
- return token === 17 /* OpenBracketToken */ || isPropertyName();
+ return token === 17 /* OpenBracketToken */ || token === 34 /* AsteriskToken */ || isPropertyName();
});
}
function isListElement(kind, inErrorRecovery) {
@@ -3151,8 +3182,9 @@ var ts;
case 6 /* ClassMembers */:
return lookAhead(isClassMemberStart);
case 7 /* EnumMembers */:
- case 11 /* ObjectLiteralMembers */:
return isPropertyName();
+ case 11 /* ObjectLiteralMembers */:
+ return token === 34 /* AsteriskToken */ || isPropertyName();
case 8 /* BaseTypeReferences */:
return isIdentifier() && ((token !== 77 /* ExtendsKeyword */ && token !== 100 /* ImplementsKeyword */) || !lookAhead(function () { return (nextToken(), isIdentifier()); }));
case 9 /* VariableDeclarations */:
@@ -3229,15 +3261,15 @@ var ts;
parsingContext |= 1 << kind;
var result = [];
result.pos = getNodePos();
- var saveIsInStrictMode = isInStrictMode;
+ var savedStrictModeContext = inStrictModeContext();
while (!isListTerminator(kind)) {
if (isListElement(kind, false)) {
var element = parseElement();
result.push(element);
- if (!isInStrictMode && checkForStrictMode) {
+ if (!inStrictModeContext() && checkForStrictMode) {
if (isPrologueDirective(element)) {
if (isUseStrictPrologueDirective(element)) {
- isInStrictMode = true;
+ setStrictModeContext(true);
checkForStrictMode = false;
}
}
@@ -3254,17 +3286,16 @@ var ts;
nextToken();
}
}
- isInStrictMode = saveIsInStrictMode;
+ setStrictModeContext(savedStrictModeContext);
result.end = getNodeEnd();
parsingContext = saveParsingContext;
return result;
}
- function parseDelimitedList(kind, parseElement, allowTrailingComma) {
+ function parseDelimitedList(kind, parseElement) {
var saveParsingContext = parsingContext;
parsingContext |= 1 << kind;
var result = [];
result.pos = getNodePos();
- var errorCountBeforeParsingList = file.syntacticErrors.length;
var commaStart = -1;
while (true) {
if (isListElement(kind, false)) {
@@ -3291,11 +3322,6 @@ var ts;
}
}
if (commaStart >= 0) {
- if (!allowTrailingComma) {
- if (file.syntacticErrors.length === errorCountBeforeParsingList) {
- grammarErrorAtPos(commaStart, scanner.getStartPos() - commaStart, ts.Diagnostics.Trailing_comma_not_allowed);
- }
- }
result.hasTrailingComma = true;
}
result.end = getNodeEnd();
@@ -3309,16 +3335,10 @@ var ts;
result.end = pos;
return result;
}
- function createNodeArray(node) {
- var result = [node];
- result.pos = node.pos;
- result.end = node.end;
- return result;
- }
- function parseBracketedList(kind, parseElement, startToken, endToken) {
- if (parseExpected(startToken)) {
- var result = parseDelimitedList(kind, parseElement, false);
- parseExpected(endToken);
+ function parseBracketedList(kind, parseElement, open, close) {
+ if (parseExpected(open)) {
+ var result = parseDelimitedList(kind, parseElement);
+ parseExpected(close);
return result;
}
return createMissingList();
@@ -3353,7 +3373,7 @@ var ts;
}
function parseTemplateSpan() {
var span = createNode(159 /* TemplateSpan */);
- span.expression = parseExpression(false);
+ span.expression = allowInAnd(parseExpression);
var literal;
if (token === 14 /* CloseBraceToken */) {
reScanTemplateToken();
@@ -3375,12 +3395,7 @@ var ts;
nextToken();
finishNode(node);
if (node.kind === 6 /* NumericLiteral */ && sourceText.charCodeAt(tokenPos) === 48 /* _0 */ && ts.isOctalDigit(sourceText.charCodeAt(tokenPos + 1))) {
- if (isInStrictMode) {
- grammarErrorOnNode(node, ts.Diagnostics.Octal_literals_are_not_allowed_in_strict_mode);
- }
- else if (languageVersion >= 1 /* ES5 */) {
- grammarErrorOnNode(node, ts.Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher);
- }
+ node.flags |= 8192 /* OctalLiteral */;
}
return node;
}
@@ -3413,22 +3428,14 @@ var ts;
node.constraint = parseType();
}
else {
- var expr = parseUnaryExpression();
- grammarErrorOnNode(expr, ts.Diagnostics.Type_expected);
+ node.expression = parseUnaryExpression();
}
}
return finishNode(node);
}
function parseTypeParameters() {
if (token === 23 /* LessThanToken */) {
- var pos = getNodePos();
- var result = parseBracketedList(14 /* TypeParameters */, parseTypeParameter, 23 /* LessThanToken */, 24 /* GreaterThanToken */);
- if (!result.length) {
- var start = getTokenPos(pos);
- var length = getNodePos() - start;
- errorAtPos(start, length, ts.Diagnostics.Type_parameter_list_cannot_be_empty);
- }
- return result;
+ return parseBracketedList(14 /* TypeParameters */, parseTypeParameter, 23 /* LessThanToken */, 24 /* GreaterThanToken */);
}
}
function parseParameterType() {
@@ -3437,14 +3444,20 @@ var ts;
function isStartOfParameter() {
return token === 20 /* DotDotDotToken */ || isIdentifier() || isModifier(token);
}
- function parseParameter(flags) {
- if (flags === void 0) { flags = 0; }
+ function setModifiers(node, modifiers) {
+ if (modifiers) {
+ node.flags |= modifiers.flags;
+ node.modifiers = modifiers;
+ }
+ }
+ function parseParameter() {
var node = createNode(123 /* Parameter */);
- node.flags |= parseAndCheckModifiers(3 /* Parameters */);
+ var modifiers = parseModifiers();
+ setModifiers(node, modifiers);
if (parseOptional(20 /* DotDotDotToken */)) {
node.flags |= 8 /* Rest */;
}
- node.name = parseIdentifier();
+ node.name = inGeneratorParameterContext() ? doInYieldContext(parseIdentifier) : parseIdentifier();
if (node.name.kind === 120 /* Missing */ && node.flags === 0 && isModifier(token)) {
nextToken();
}
@@ -3452,153 +3465,82 @@ var ts;
node.flags |= 4 /* QuestionMark */;
}
node.type = parseParameterType();
- node.initializer = parseInitializer(true);
+ node.initializer = inGeneratorParameterContext() ? doOutsideOfYieldContext(parseParameterInitializer) : parseParameterInitializer();
return finishNode(node);
}
- function parseSignature(kind, returnToken, returnTokenRequired) {
+ function parseParameterInitializer() {
+ return parseInitializer(true);
+ }
+ function parseSignature(kind, returnToken, returnTokenRequired, yieldAndGeneratorParameterContext) {
+ var signature = {};
+ fillSignature(kind, returnToken, returnTokenRequired, yieldAndGeneratorParameterContext, signature);
+ return signature;
+ }
+ function fillSignature(kind, returnToken, returnTokenRequired, yieldAndGeneratorParameterContext, signature) {
if (kind === 130 /* ConstructSignature */) {
parseExpected(86 /* NewKeyword */);
}
- var typeParameters = parseTypeParameters();
- var parameters = parseParameterList(15 /* OpenParenToken */, 16 /* CloseParenToken */);
- checkParameterList(parameters);
- var type;
+ signature.typeParameters = parseTypeParameters();
+ signature.parameters = parseParameterList(yieldAndGeneratorParameterContext);
if (returnTokenRequired) {
parseExpected(returnToken);
- type = parseType();
+ signature.type = parseType();
}
else if (parseOptional(returnToken)) {
- type = parseType();
+ signature.type = parseType();
}
- return {
- typeParameters: typeParameters,
- parameters: parameters,
- type: type
- };
}
- function parseParameterList(startDelimiter, endDelimiter) {
- return parseBracketedList(13 /* Parameters */, parseParameter, startDelimiter, endDelimiter);
- }
- function checkParameterList(parameters) {
- var seenOptionalParameter = false;
- var parameterCount = parameters.length;
- for (var i = 0; i < parameterCount; i++) {
- var parameter = parameters[i];
- if (isInStrictMode && isEvalOrArgumentsIdentifier(parameter.name)) {
- reportInvalidUseInStrictMode(parameter.name);
- return;
- }
- else if (parameter.flags & 8 /* Rest */) {
- if (i !== (parameterCount - 1)) {
- grammarErrorOnNode(parameter.name, ts.Diagnostics.A_rest_parameter_must_be_last_in_a_parameter_list);
- return;
- }
- if (parameter.flags & 4 /* QuestionMark */) {
- grammarErrorOnNode(parameter.name, ts.Diagnostics.A_rest_parameter_cannot_be_optional);
- return;
- }
- if (parameter.initializer) {
- grammarErrorOnNode(parameter.name, ts.Diagnostics.A_rest_parameter_cannot_have_an_initializer);
- return;
- }
- }
- else if (parameter.flags & 4 /* QuestionMark */ || parameter.initializer) {
- seenOptionalParameter = true;
- if (parameter.flags & 4 /* QuestionMark */ && parameter.initializer) {
- grammarErrorOnNode(parameter.name, ts.Diagnostics.Parameter_cannot_have_question_mark_and_initializer);
- return;
- }
- }
- else {
- if (seenOptionalParameter) {
- grammarErrorOnNode(parameter.name, ts.Diagnostics.A_required_parameter_cannot_follow_an_optional_parameter);
- return;
- }
- }
+ function parseParameterList(yieldAndGeneratorParameterContext) {
+ if (parseExpected(15 /* OpenParenToken */)) {
+ var savedYieldContext = inYieldContext();
+ var savedGeneratorParameterContext = inGeneratorParameterContext();
+ setYieldContext(yieldAndGeneratorParameterContext);
+ setGeneratorParameterContext(yieldAndGeneratorParameterContext);
+ var result = parseDelimitedList(13 /* Parameters */, parseParameter);
+ parseExpected(16 /* CloseParenToken */);
+ setYieldContext(savedYieldContext);
+ setGeneratorParameterContext(savedGeneratorParameterContext);
+ return result;
}
+ return createMissingList();
}
function parseSignatureMember(kind, returnToken) {
var node = createNode(kind);
- var sig = parseSignature(kind, returnToken, false);
- node.typeParameters = sig.typeParameters;
- node.parameters = sig.parameters;
- node.type = sig.type;
+ fillSignature(kind, returnToken, false, false, node);
parseSemicolon();
return finishNode(node);
}
- function parseIndexSignatureMember() {
- var node = createNode(131 /* IndexSignature */);
- var errorCountBeforeIndexSignature = file.syntacticErrors.length;
- var indexerStart = scanner.getTokenPos();
- node.parameters = parseParameterList(17 /* OpenBracketToken */, 18 /* CloseBracketToken */);
- var indexerLength = scanner.getStartPos() - indexerStart;
+ function parseIndexSignatureMember(fullStart, modifiers) {
+ var node = createNode(131 /* IndexSignature */, fullStart);
+ setModifiers(node, modifiers);
+ node.parameters = parseBracketedList(13 /* Parameters */, parseParameter, 17 /* OpenBracketToken */, 18 /* CloseBracketToken */);
node.type = parseTypeAnnotation();
parseSemicolon();
- if (file.syntacticErrors.length === errorCountBeforeIndexSignature) {
- checkIndexSignature(node, indexerStart, indexerLength);
- }
return finishNode(node);
}
- function checkIndexSignature(node, indexerStart, indexerLength) {
- var parameter = node.parameters[0];
- if (node.parameters.length !== 1) {
- var arityDiagnostic = ts.Diagnostics.An_index_signature_must_have_exactly_one_parameter;
- if (parameter) {
- grammarErrorOnNode(parameter.name, arityDiagnostic);
- }
- else {
- grammarErrorAtPos(indexerStart, indexerLength, arityDiagnostic);
- }
- return;
- }
- else if (parameter.flags & 8 /* Rest */) {
- grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_cannot_have_a_rest_parameter);
- return;
- }
- else if (parameter.flags & 243 /* Modifier */) {
- grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_cannot_have_an_accessibility_modifier);
- return;
- }
- else if (parameter.flags & 4 /* QuestionMark */) {
- grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_cannot_have_a_question_mark);
- return;
- }
- else if (parameter.initializer) {
- grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_cannot_have_an_initializer);
- return;
- }
- else if (!parameter.type) {
- grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_must_have_a_type_annotation);
- return;
- }
- else if (parameter.type.kind !== 118 /* StringKeyword */ && parameter.type.kind !== 116 /* NumberKeyword */) {
- grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_type_must_be_string_or_number);
- return;
- }
- else if (!node.type) {
- grammarErrorAtPos(indexerStart, indexerLength, ts.Diagnostics.An_index_signature_must_have_a_type_annotation);
- return;
- }
- }
function parsePropertyOrMethod() {
- var node = createNode(0 /* Unknown */);
- node.name = parsePropertyName();
+ var fullStart = scanner.getStartPos();
+ var name = parsePropertyName();
+ var flags = 0;
if (parseOptional(49 /* QuestionToken */)) {
- node.flags |= 4 /* QuestionMark */;
+ flags = 4 /* QuestionMark */;
}
if (token === 15 /* OpenParenToken */ || token === 23 /* LessThanToken */) {
- node.kind = 125 /* Method */;
- var sig = parseSignature(129 /* CallSignature */, 50 /* ColonToken */, false);
- node.typeParameters = sig.typeParameters;
- node.parameters = sig.parameters;
- node.type = sig.type;
+ var method = createNode(125 /* Method */, fullStart);
+ method.name = name;
+ method.flags = flags;
+ fillSignature(129 /* CallSignature */, 50 /* ColonToken */, false, false, method);
+ parseSemicolon();
+ return finishNode(method);
}
else {
- node.kind = 124 /* Property */;
- node.type = parseTypeAnnotation();
+ var property = createNode(124 /* Property */, fullStart);
+ property.name = name;
+ property.flags = flags;
+ property.type = parseTypeAnnotation();
+ parseSemicolon();
+ return finishNode(property);
}
- parseSemicolon();
- return finishNode(node);
}
function isStartOfTypeMember() {
switch (token) {
@@ -3616,7 +3558,7 @@ var ts;
case 23 /* LessThanToken */:
return parseSignatureMember(129 /* CallSignature */, 50 /* ColonToken */);
case 17 /* OpenBracketToken */:
- return parseIndexSignatureMember();
+ return parseIndexSignatureMember(scanner.getStartPos(), undefined);
case 86 /* NewKeyword */:
if (lookAhead(function () { return nextToken() === 15 /* OpenParenToken */ || token === 23 /* LessThanToken */; })) {
return parseSignatureMember(130 /* ConstructSignature */, 50 /* ColonToken */);
@@ -3632,23 +3574,23 @@ var ts;
}
function parseTypeLiteral() {
var node = createNode(136 /* TypeLiteral */);
+ node.members = parseObjectType();
+ return finishNode(node);
+ }
+ function parseObjectType() {
+ var members;
if (parseExpected(13 /* OpenBraceToken */)) {
- node.members = parseList(5 /* TypeMembers */, false, parseTypeMember);
+ members = parseList(5 /* TypeMembers */, false, parseTypeMember);
parseExpected(14 /* CloseBraceToken */);
}
else {
- node.members = createMissingList();
+ members = createMissingList();
}
- return finishNode(node);
+ return members;
}
function parseTupleType() {
var node = createNode(138 /* TupleType */);
- var startTokenPos = scanner.getTokenPos();
- var startErrorCount = file.syntacticErrors.length;
node.elementTypes = parseBracketedList(16 /* TupleElementTypes */, parseType, 17 /* OpenBracketToken */, 18 /* CloseBracketToken */);
- if (!node.elementTypes.length && file.syntacticErrors.length === startErrorCount) {
- grammarErrorAtPos(startTokenPos, scanner.getStartPos() - startTokenPos, ts.Diagnostics.A_tuple_type_element_list_cannot_be_empty);
- }
return finishNode(node);
}
function parseParenType() {
@@ -3659,13 +3601,9 @@ var ts;
return finishNode(node);
}
function parseFunctionType(typeKind) {
- var member = createNode(typeKind);
- var sig = parseSignature(typeKind === 133 /* FunctionType */ ? 129 /* CallSignature */ : 130 /* ConstructSignature */, 31 /* EqualsGreaterThanToken */, true);
- member.typeParameters = sig.typeParameters;
- member.parameters = sig.parameters;
- member.type = sig.type;
- finishNode(member);
- return member;
+ var node = createNode(typeKind);
+ fillSignature(typeKind === 133 /* FunctionType */ ? 129 /* CallSignature */ : 130 /* ConstructSignature */, 31 /* EqualsGreaterThanToken */, true, false, node);
+ return finishNode(node);
}
function parseKeywordAndNoDot() {
var node = parseTokenNode();
@@ -3765,6 +3703,16 @@ var ts;
});
}
function parseType() {
+ var savedYieldContext = inYieldContext();
+ var savedGeneratorParameterContext = inGeneratorParameterContext();
+ setYieldContext(false);
+ setGeneratorParameterContext(false);
+ var result = parseTypeWorker();
+ setYieldContext(savedYieldContext);
+ setGeneratorParameterContext(savedGeneratorParameterContext);
+ return result;
+ }
+ function parseTypeWorker() {
if (isStartOfFunctionType()) {
return parseFunctionType(133 /* FunctionType */);
}
@@ -3805,6 +3753,7 @@ var ts;
case 38 /* MinusMinusToken */:
case 23 /* LessThanToken */:
case 63 /* Identifier */:
+ case 108 /* YieldKeyword */:
return true;
default:
return isIdentifier();
@@ -3813,70 +3762,68 @@ var ts;
function isStartOfExpressionStatement() {
return token !== 13 /* OpenBraceToken */ && token !== 81 /* FunctionKeyword */ && isStartOfExpression();
}
- function parseExpression(noIn) {
- var expr = parseAssignmentExpression(noIn);
+ function parseExpression() {
+ var expr = parseAssignmentExpression();
while (parseOptional(22 /* CommaToken */)) {
- expr = makeBinaryExpression(expr, 22 /* CommaToken */, parseAssignmentExpression(noIn));
+ expr = makeBinaryExpression(expr, 22 /* CommaToken */, parseAssignmentExpression());
}
return expr;
}
- function parseInitializer(inParameter, noIn) {
+ function parseInitializer(inParameter) {
if (token !== 51 /* EqualsToken */) {
if (scanner.hasPrecedingLineBreak() || (inParameter && token === 13 /* OpenBraceToken */) || !isStartOfExpression()) {
return undefined;
}
}
parseExpected(51 /* EqualsToken */);
- return parseAssignmentExpression(noIn);
+ return parseAssignmentExpression();
}
- function parseAssignmentExpression(noIn) {
+ function parseAssignmentExpression() {
+ if (isYieldExpression()) {
+ return parseYieldExpression();
+ }
var arrowExpression = tryParseParenthesizedArrowFunctionExpression();
if (arrowExpression) {
return arrowExpression;
}
- var expr = parseConditionalExpression(noIn);
+ var expr = parseConditionalExpression();
if (expr.kind === 63 /* Identifier */ && token === 31 /* EqualsGreaterThanToken */) {
return parseSimpleArrowFunctionExpression(expr);
}
- if (isLeftHandSideExpression(expr) && isAssignmentOperator()) {
- if (isInStrictMode && isEvalOrArgumentsIdentifier(expr)) {
- reportInvalidUseInStrictMode(expr);
- }
+ if (isLeftHandSideExpression(expr) && isAssignmentOperator(token)) {
var operator = token;
nextToken();
- return makeBinaryExpression(expr, operator, parseAssignmentExpression(noIn));
+ return makeBinaryExpression(expr, operator, parseAssignmentExpression());
}
return expr;
}
- function isLeftHandSideExpression(expr) {
- if (expr) {
- switch (expr.kind) {
- case 145 /* PropertyAccess */:
- case 146 /* IndexedAccess */:
- case 148 /* NewExpression */:
- case 147 /* CallExpression */:
- case 149 /* TaggedTemplateExpression */:
- case 141 /* ArrayLiteral */:
- case 151 /* ParenExpression */:
- case 142 /* ObjectLiteral */:
- case 152 /* FunctionExpression */:
- case 63 /* Identifier */:
- case 120 /* Missing */:
- case 8 /* RegularExpressionLiteral */:
- case 6 /* NumericLiteral */:
- case 7 /* StringLiteral */:
- case 9 /* NoSubstitutionTemplateLiteral */:
- case 158 /* TemplateExpression */:
- case 78 /* FalseKeyword */:
- case 87 /* NullKeyword */:
- case 91 /* ThisKeyword */:
- case 93 /* TrueKeyword */:
- case 89 /* SuperKeyword */:
- return true;
+ function isYieldExpression() {
+ if (token === 108 /* YieldKeyword */) {
+ if (inYieldContext()) {
+ return true;
}
+ if (inStrictModeContext()) {
+ return true;
+ }
+ return lookAhead(function () {
+ nextToken();
+ return !scanner.hasPrecedingLineBreak() && isIdentifier();
+ });
}
return false;
}
+ function parseYieldExpression() {
+ var node = createNode(160 /* YieldExpression */);
+ nextToken();
+ if (!scanner.hasPrecedingLineBreak() && (token === 34 /* AsteriskToken */ || isStartOfExpression())) {
+ node.asteriskToken = parseOptionalToken(34 /* AsteriskToken */);
+ node.expression = parseAssignmentExpression();
+ return finishNode(node);
+ }
+ else {
+ return finishNode(node);
+ }
+ }
function parseSimpleArrowFunctionExpression(identifier) {
ts.Debug.assert(token === 31 /* EqualsGreaterThanToken */, "parseSimpleArrowFunctionExpression should only have been called if we had a =>");
parseExpected(31 /* EqualsGreaterThanToken */);
@@ -3888,7 +3835,7 @@ var ts;
parameters.pos = parameter.pos;
parameters.end = parameter.end;
var signature = { parameters: parameters };
- return parseArrowExpressionTail(identifier.pos, signature, false);
+ return parseArrowExpressionTail(identifier.pos, signature);
}
function tryParseParenthesizedArrowFunctionExpression() {
var triState = isParenthesizedArrowFunctionExpression();
@@ -3897,18 +3844,18 @@ var ts;
}
var pos = getNodePos();
if (triState === 1 /* True */) {
- var sig = parseSignature(129 /* CallSignature */, 50 /* ColonToken */, false);
+ var sig = parseSignature(129 /* CallSignature */, 50 /* ColonToken */, false, false);
if (parseExpected(31 /* EqualsGreaterThanToken */) || token === 13 /* OpenBraceToken */) {
- return parseArrowExpressionTail(pos, sig, false);
+ return parseArrowExpressionTail(pos, sig);
}
else {
- return makeFunctionExpression(153 /* ArrowFunction */, pos, undefined, sig, createMissingNode());
+ return makeFunctionExpression(153 /* ArrowFunction */, pos, undefined, undefined, sig, createMissingNode());
}
}
var sig = tryParseSignatureIfArrowOrBraceFollows();
if (sig) {
parseExpected(31 /* EqualsGreaterThanToken */);
- return parseArrowExpressionTail(pos, sig, false);
+ return parseArrowExpressionTail(pos, sig);
}
else {
return undefined;
@@ -3958,52 +3905,46 @@ var ts;
}
function tryParseSignatureIfArrowOrBraceFollows() {
return tryParse(function () {
- var sig = parseSignature(129 /* CallSignature */, 50 /* ColonToken */, false);
+ var sig = parseSignature(129 /* CallSignature */, 50 /* ColonToken */, false, false);
if (token === 31 /* EqualsGreaterThanToken */ || token === 13 /* OpenBraceToken */) {
return sig;
}
return undefined;
});
}
- function parseArrowExpressionTail(pos, sig, noIn) {
+ function parseArrowExpressionTail(pos, sig) {
var body;
if (token === 13 /* OpenBraceToken */) {
- body = parseBody(false);
+ body = parseFunctionBlock(false, false);
}
else if (isStatement(true) && !isStartOfExpressionStatement() && token !== 81 /* FunctionKeyword */) {
- body = parseBody(true);
+ body = parseFunctionBlock(false, true);
}
else {
- body = parseAssignmentExpression(noIn);
+ body = parseAssignmentExpression();
}
- return makeFunctionExpression(153 /* ArrowFunction */, pos, undefined, sig, body);
+ return makeFunctionExpression(153 /* ArrowFunction */, pos, undefined, undefined, sig, body);
}
- function isAssignmentOperator() {
- return token >= 51 /* FirstAssignment */ && token <= 62 /* LastAssignment */;
- }
- function parseConditionalExpression(noIn) {
- var expr = parseBinaryExpression(noIn);
+ function parseConditionalExpression() {
+ var expr = parseBinaryOperators(parseUnaryExpression(), 0);
while (parseOptional(49 /* QuestionToken */)) {
var node = createNode(157 /* ConditionalExpression */, expr.pos);
node.condition = expr;
- node.whenTrue = parseAssignmentExpression(false);
+ node.whenTrue = allowInAnd(parseAssignmentExpression);
parseExpected(50 /* ColonToken */);
- node.whenFalse = parseAssignmentExpression(noIn);
+ node.whenFalse = parseAssignmentExpression();
expr = finishNode(node);
}
return expr;
}
- function parseBinaryExpression(noIn) {
- return parseBinaryOperators(parseUnaryExpression(), 0, noIn);
- }
- function parseBinaryOperators(expr, minPrecedence, noIn) {
+ function parseBinaryOperators(expr, minPrecedence) {
while (true) {
reScanGreaterToken();
var precedence = getOperatorPrecedence();
- if (precedence && precedence > minPrecedence && (!noIn || token !== 84 /* InKeyword */)) {
+ if (precedence && precedence > minPrecedence && (!inDisallowInContext() || token !== 84 /* InKeyword */)) {
var operator = token;
nextToken();
- expr = makeBinaryExpression(expr, operator, parseBinaryOperators(parseUnaryExpression(), precedence, noIn));
+ expr = makeBinaryExpression(expr, operator, parseBinaryOperators(parseUnaryExpression(), precedence));
continue;
}
return expr;
@@ -4068,16 +4009,7 @@ var ts;
case 38 /* MinusMinusToken */:
var operator = token;
nextToken();
- var operand = parseUnaryExpression();
- if (isInStrictMode) {
- if ((operator === 37 /* PlusPlusToken */ || operator === 38 /* MinusMinusToken */) && isEvalOrArgumentsIdentifier(operand)) {
- reportInvalidUseInStrictMode(operand);
- }
- else if (operator === 72 /* DeleteKeyword */ && operand.kind === 63 /* Identifier */) {
- grammarErrorOnNode(operand, ts.Diagnostics.delete_cannot_be_called_on_an_identifier_in_strict_mode);
- }
- }
- return makeUnaryExpression(154 /* PrefixOperator */, pos, operator, operand);
+ return makeUnaryExpression(154 /* PrefixOperator */, pos, operator, parseUnaryExpression());
case 23 /* LessThanToken */:
return parseTypeAssertion();
}
@@ -4089,9 +4021,6 @@ var ts;
var expr = parseCallAndAccess(primaryExpression, false);
ts.Debug.assert(isLeftHandSideExpression(expr));
if ((token === 37 /* PlusPlusToken */ || token === 38 /* MinusMinusToken */) && !scanner.hasPrecedingLineBreak()) {
- if (isInStrictMode && isEvalOrArgumentsIdentifier(expr)) {
- reportInvalidUseInStrictMode(expr);
- }
var operator = token;
nextToken();
expr = makeUnaryExpression(155 /* PostfixOperator */, expr.pos, operator, expr);
@@ -4117,15 +4046,19 @@ var ts;
var dotOrBracketStart = scanner.getTokenPos();
if (parseOptional(19 /* DotToken */)) {
var propertyAccess = createNode(145 /* PropertyAccess */, expr.pos);
- if (scanner.hasPrecedingLineBreak() && scanner.isReservedWord() && lookAhead(function () { return scanner.isReservedWord(); })) {
- grammarErrorAtPos(dotOrBracketStart, scanner.getStartPos() - dotOrBracketStart, ts.Diagnostics.Identifier_expected);
- var id = createMissingNode();
- }
- else {
- var id = parseIdentifierName();
+ var id;
+ if (scanner.hasPrecedingLineBreak() && scanner.isReservedWord()) {
+ var matchesPattern = lookAhead(function () {
+ nextToken();
+ return !scanner.hasPrecedingLineBreak() && (scanner.isIdentifier() || scanner.isReservedWord);
+ });
+ if (matchesPattern) {
+ errorAtPos(dotOrBracketStart + 1, 0, ts.Diagnostics.Identifier_expected);
+ id = createMissingNode();
+ }
}
propertyAccess.left = expr;
- propertyAccess.right = id;
+ propertyAccess.right = id || parseIdentifierName();
expr = finishNode(propertyAccess);
continue;
}
@@ -4134,10 +4067,9 @@ var ts;
indexedAccess.object = expr;
if (inNewExpression && parseOptional(18 /* CloseBracketToken */)) {
indexedAccess.index = createMissingNode();
- grammarErrorAtPos(dotOrBracketStart, scanner.getStartPos() - dotOrBracketStart, ts.Diagnostics.new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead);
}
else {
- indexedAccess.index = parseExpression();
+ indexedAccess.index = allowInAnd(parseExpression);
if (indexedAccess.index.kind === 7 /* StringLiteral */ || indexedAccess.index.kind === 6 /* NumericLiteral */) {
var literal = indexedAccess.index;
literal.text = internIdentifier(literal.text);
@@ -4157,7 +4089,7 @@ var ts;
else {
parseExpected(15 /* OpenParenToken */);
}
- callExpr.arguments = parseDelimitedList(10 /* ArgumentExpressions */, parseArgumentExpression, false);
+ callExpr.arguments = parseDelimitedList(10 /* ArgumentExpressions */, parseArgumentExpression);
parseExpected(16 /* CloseParenToken */);
expr = finishNode(callExpr);
continue;
@@ -4167,9 +4099,6 @@ var ts;
tagExpression.tag = expr;
tagExpression.template = token === 9 /* NoSubstitutionTemplateLiteral */ ? parseLiteralNode() : parseTemplateExpression();
expr = finishNode(tagExpression);
- if (languageVersion < 2 /* ES6 */) {
- grammarErrorOnNode(expr, ts.Diagnostics.Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher);
- }
continue;
}
return expr;
@@ -4181,19 +4110,10 @@ var ts;
return result;
}
function parseTypeArguments() {
- var typeArgumentListStart = scanner.getTokenPos();
- var errorCountBeforeTypeParameterList = file.syntacticErrors.length;
- var result = parseBracketedList(15 /* TypeArguments */, parseSingleTypeArgument, 23 /* LessThanToken */, 24 /* GreaterThanToken */);
- if (!result.length && file.syntacticErrors.length === errorCountBeforeTypeParameterList) {
- grammarErrorAtPos(typeArgumentListStart, scanner.getStartPos() - typeArgumentListStart, ts.Diagnostics.Type_argument_list_cannot_be_empty);
- }
- return result;
+ return parseBracketedList(15 /* TypeArguments */, parseSingleTypeArgument, 23 /* LessThanToken */, 24 /* GreaterThanToken */);
}
function parseSingleTypeArgument() {
if (token === 22 /* CommaToken */) {
- var errorStart = scanner.getTokenPos();
- var errorLength = scanner.getTextPos() - errorStart;
- grammarErrorAtPos(errorStart, errorLength, ts.Diagnostics.Type_expected);
return createNode(120 /* Missing */);
}
return parseType();
@@ -4239,55 +4159,49 @@ var ts;
function parseParenExpression() {
var node = createNode(151 /* ParenExpression */);
parseExpected(15 /* OpenParenToken */);
- node.expression = parseExpression();
+ node.expression = allowInAnd(parseExpression);
parseExpected(16 /* CloseParenToken */);
return finishNode(node);
}
- function parseAssignmentExpressionOrOmittedExpression(omittedExpressionDiagnostic) {
- if (token === 22 /* CommaToken */) {
- if (omittedExpressionDiagnostic) {
- var errorStart = scanner.getTokenPos();
- var errorLength = scanner.getTextPos() - errorStart;
- grammarErrorAtPos(errorStart, errorLength, omittedExpressionDiagnostic);
- }
- return createNode(160 /* OmittedExpression */);
- }
- return parseAssignmentExpression();
+ function parseAssignmentExpressionOrOmittedExpression() {
+ return token === 22 /* CommaToken */ ? createNode(161 /* OmittedExpression */) : parseAssignmentExpression();
}
function parseArrayLiteralElement() {
- return parseAssignmentExpressionOrOmittedExpression(undefined);
+ return parseAssignmentExpressionOrOmittedExpression();
}
function parseArgumentExpression() {
- return parseAssignmentExpressionOrOmittedExpression(ts.Diagnostics.Argument_expression_expected);
+ return allowInAnd(parseAssignmentExpressionOrOmittedExpression);
}
function parseArrayLiteral() {
var node = createNode(141 /* ArrayLiteral */);
parseExpected(17 /* OpenBracketToken */);
if (scanner.hasPrecedingLineBreak())
node.flags |= 256 /* MultiLine */;
- node.elements = parseDelimitedList(12 /* ArrayLiteralMembers */, parseArrayLiteralElement, true);
+ node.elements = parseDelimitedList(12 /* ArrayLiteralMembers */, parseArrayLiteralElement);
parseExpected(18 /* CloseBracketToken */);
return finishNode(node);
}
function parsePropertyAssignment() {
var nodePos = scanner.getStartPos();
+ var asteriskToken = parseOptionalToken(34 /* AsteriskToken */);
+ var tokenIsIdentifier = isIdentifier();
var nameToken = token;
var propertyName = parsePropertyName();
var node;
- if (token === 15 /* OpenParenToken */ || token === 23 /* LessThanToken */) {
+ if (asteriskToken || token === 15 /* OpenParenToken */ || token === 23 /* LessThanToken */) {
node = createNode(143 /* PropertyAssignment */, nodePos);
node.name = propertyName;
- var sig = parseSignature(129 /* CallSignature */, 50 /* ColonToken */, false);
- var body = parseBody(false);
- node.initializer = makeFunctionExpression(152 /* FunctionExpression */, node.pos, undefined, sig, body);
+ var sig = parseSignature(129 /* CallSignature */, 50 /* ColonToken */, false, !!asteriskToken);
+ var body = parseFunctionBlock(!!asteriskToken, false);
+ node.initializer = makeFunctionExpression(152 /* FunctionExpression */, node.pos, asteriskToken, undefined, sig, body);
return finishNode(node);
}
+ var flags = 0;
if (token === 49 /* QuestionToken */) {
- var questionStart = scanner.getTokenPos();
- grammarErrorAtPos(questionStart, scanner.getStartPos() - questionStart, ts.Diagnostics.A_object_member_cannot_be_declared_optional);
+ flags |= 4 /* QuestionMark */;
nextToken();
}
- if (token !== 50 /* ColonToken */ && nameToken === 63 /* Identifier */) {
+ if ((token === 22 /* CommaToken */ || token === 14 /* CloseBraceToken */) && tokenIsIdentifier) {
node = createNode(144 /* ShorthandPropertyAssignment */, nodePos);
node.name = propertyName;
}
@@ -4295,8 +4209,9 @@ var ts;
node = createNode(143 /* PropertyAssignment */, nodePos);
node.name = propertyName;
parseExpected(50 /* ColonToken */);
- node.initializer = parseAssignmentExpression(false);
+ node.initializer = allowInAnd(parseAssignmentExpression);
}
+ node.flags = flags;
return finishNode(node);
}
function parseObjectLiteralMember() {
@@ -4304,7 +4219,7 @@ var ts;
var initialToken = token;
if (parseContextualModifier(113 /* GetKeyword */) || parseContextualModifier(117 /* SetKeyword */)) {
var kind = initialToken === 113 /* GetKeyword */ ? 127 /* GetAccessor */ : 128 /* SetAccessor */;
- return parseAndCheckMemberAccessorDeclaration(kind, initialPos, 0);
+ return parseMemberAccessorDeclaration(kind, initialPos, undefined);
}
return parsePropertyAssignment();
}
@@ -4314,72 +4229,25 @@ var ts;
if (scanner.hasPrecedingLineBreak()) {
node.flags |= 256 /* MultiLine */;
}
- node.properties = parseDelimitedList(11 /* ObjectLiteralMembers */, parseObjectLiteralMember, true);
+ node.properties = parseDelimitedList(11 /* ObjectLiteralMembers */, parseObjectLiteralMember);
parseExpected(14 /* CloseBraceToken */);
- var seen = {};
- var Property = 1;
- var GetAccessor = 2;
- var SetAccesor = 4;
- var GetOrSetAccessor = GetAccessor | SetAccesor;
- ts.forEach(node.properties, function (p) {
- if (p.kind === 160 /* OmittedExpression */) {
- return;
- }
- var name = p.name;
- var currentKind;
- if (p.kind === 143 /* PropertyAssignment */) {
- currentKind = Property;
- }
- else if (p.kind === 144 /* ShorthandPropertyAssignment */) {
- currentKind = Property;
- }
- else if (p.kind === 127 /* GetAccessor */) {
- currentKind = GetAccessor;
- }
- else if (p.kind === 128 /* SetAccessor */) {
- currentKind = SetAccesor;
- }
- else {
- ts.Debug.fail("Unexpected syntax kind:" + p.kind);
- }
- if (!ts.hasProperty(seen, name.text)) {
- seen[name.text] = currentKind;
- }
- else {
- var existingKind = seen[name.text];
- if (currentKind === Property && existingKind === Property) {
- if (isInStrictMode) {
- grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode);
- }
- }
- else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) {
- if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) {
- seen[name.text] = currentKind | existingKind;
- }
- else {
- grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name);
- }
- }
- else {
- grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name);
- }
- }
- });
return finishNode(node);
}
function parseFunctionExpression() {
var pos = getNodePos();
parseExpected(81 /* FunctionKeyword */);
- var name = isIdentifier() ? parseIdentifier() : undefined;
- var sig = parseSignature(129 /* CallSignature */, 50 /* ColonToken */, false);
- var body = parseBody(false);
- if (name && isInStrictMode && isEvalOrArgumentsIdentifier(name)) {
- reportInvalidUseInStrictMode(name);
- }
- return makeFunctionExpression(152 /* FunctionExpression */, pos, name, sig, body);
+ var asteriskToken = parseOptionalToken(34 /* AsteriskToken */);
+ var name = asteriskToken ? doInYieldContext(parseOptionalIdentifier) : parseOptionalIdentifier();
+ var sig = parseSignature(129 /* CallSignature */, 50 /* ColonToken */, false, !!asteriskToken);
+ var body = parseFunctionBlock(!!asteriskToken, false);
+ return makeFunctionExpression(152 /* FunctionExpression */, pos, asteriskToken, name, sig, body);
}
- function makeFunctionExpression(kind, pos, name, sig, body) {
+ function parseOptionalIdentifier() {
+ return isIdentifier() ? parseIdentifier() : undefined;
+ }
+ function makeFunctionExpression(kind, pos, asteriskToken, name, sig, body) {
var node = createNode(kind, pos);
+ node.asteriskToken = asteriskToken;
node.name = name;
node.typeParameters = sig.typeParameters;
node.parameters = sig.parameters;
@@ -4392,18 +4260,15 @@ var ts;
parseExpected(86 /* NewKeyword */);
node.func = parseCallAndAccess(parsePrimaryExpression(), true);
if (parseOptional(15 /* OpenParenToken */) || token === 23 /* LessThanToken */ && (node.typeArguments = tryParse(parseTypeArgumentsAndOpenParen))) {
- node.arguments = parseDelimitedList(10 /* ArgumentExpressions */, parseArgumentExpression, false);
+ node.arguments = parseDelimitedList(10 /* ArgumentExpressions */, parseArgumentExpression);
parseExpected(16 /* CloseParenToken */);
}
return finishNode(node);
}
- function parseStatementAllowingLetDeclaration() {
- return parseStatement(true);
- }
function parseBlock(ignoreMissingOpenBrace, checkForStrictMode) {
- var node = createNode(161 /* Block */);
+ var node = createNode(162 /* Block */);
if (parseExpected(13 /* OpenBraceToken */) || ignoreMissingOpenBrace) {
- node.statements = parseList(2 /* BlockStatements */, checkForStrictMode, parseStatementAllowingLetDeclaration);
+ node.statements = parseList(2 /* BlockStatements */, checkForStrictMode, parseStatement);
parseExpected(14 /* CloseBraceToken */);
}
else {
@@ -4411,65 +4276,47 @@ var ts;
}
return finishNode(node);
}
- function parseBody(ignoreMissingOpenBrace) {
- var saveInFunctionBody = inFunctionBody;
- var saveInSwitchStatement = inSwitchStatement;
- var saveInIterationStatement = inIterationStatement;
- inFunctionBody = true;
- if (inSwitchStatement === 1 /* Nested */) {
- inSwitchStatement = 2 /* CrossingFunctionBoundary */;
- }
- if (inIterationStatement === 1 /* Nested */) {
- inIterationStatement = 2 /* CrossingFunctionBoundary */;
- }
- labelledStatementInfo.pushFunctionBoundary();
+ function parseFunctionBlock(allowYield, ignoreMissingOpenBrace) {
+ var savedYieldContext = inYieldContext();
+ setYieldContext(allowYield);
var block = parseBlock(ignoreMissingOpenBrace, true);
- block.kind = 186 /* FunctionBlock */;
- labelledStatementInfo.pop();
- inFunctionBody = saveInFunctionBody;
- inSwitchStatement = saveInSwitchStatement;
- inIterationStatement = saveInIterationStatement;
+ block.kind = 187 /* FunctionBlock */;
+ setYieldContext(savedYieldContext);
return block;
}
function parseEmptyStatement() {
- var node = createNode(163 /* EmptyStatement */);
+ var node = createNode(164 /* EmptyStatement */);
parseExpected(21 /* SemicolonToken */);
return finishNode(node);
}
function parseIfStatement() {
- var node = createNode(165 /* IfStatement */);
+ var node = createNode(166 /* IfStatement */);
parseExpected(82 /* IfKeyword */);
parseExpected(15 /* OpenParenToken */);
- node.expression = parseExpression();
+ node.expression = allowInAnd(parseExpression);
parseExpected(16 /* CloseParenToken */);
- node.thenStatement = parseStatement(false);
- node.elseStatement = parseOptional(74 /* ElseKeyword */) ? parseStatement(false) : undefined;
+ node.thenStatement = parseStatement();
+ node.elseStatement = parseOptional(74 /* ElseKeyword */) ? parseStatement() : undefined;
return finishNode(node);
}
function parseDoStatement() {
- var node = createNode(166 /* DoStatement */);
+ var node = createNode(167 /* DoStatement */);
parseExpected(73 /* DoKeyword */);
- var saveInIterationStatement = inIterationStatement;
- inIterationStatement = 1 /* Nested */;
- node.statement = parseStatement(false);
- inIterationStatement = saveInIterationStatement;
+ node.statement = parseStatement();
parseExpected(98 /* WhileKeyword */);
parseExpected(15 /* OpenParenToken */);
- node.expression = parseExpression();
+ node.expression = allowInAnd(parseExpression);
parseExpected(16 /* CloseParenToken */);
parseOptional(21 /* SemicolonToken */);
return finishNode(node);
}
function parseWhileStatement() {
- var node = createNode(167 /* WhileStatement */);
+ var node = createNode(168 /* WhileStatement */);
parseExpected(98 /* WhileKeyword */);
parseExpected(15 /* OpenParenToken */);
- node.expression = parseExpression();
+ node.expression = allowInAnd(parseExpression);
parseExpected(16 /* CloseParenToken */);
- var saveInIterationStatement = inIterationStatement;
- inIterationStatement = 1 /* Nested */;
- node.statement = parseStatement(false);
- inIterationStatement = saveInIterationStatement;
+ node.statement = parseStatement();
return finishNode(node);
}
function parseForOrForInStatement() {
@@ -4478,220 +4325,127 @@ var ts;
parseExpected(15 /* OpenParenToken */);
if (token !== 21 /* SemicolonToken */) {
if (parseOptional(96 /* VarKeyword */)) {
- var declarations = parseVariableDeclarationList(0, true);
- if (!declarations.length) {
- error(ts.Diagnostics.Variable_declaration_list_cannot_be_empty);
- }
+ var declarations = disallowInAnd(parseVariableDeclarationList);
}
else if (parseOptional(102 /* LetKeyword */)) {
- var declarations = parseVariableDeclarationList(2048 /* Let */, true);
- if (!declarations.length) {
- error(ts.Diagnostics.Variable_declaration_list_cannot_be_empty);
- }
- if (languageVersion < 2 /* ES6 */) {
- grammarErrorAtPos(declarations.pos, declarations.end - declarations.pos, ts.Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher);
- }
+ var declarations = setFlag(disallowInAnd(parseVariableDeclarationList), 2048 /* Let */);
}
else if (parseOptional(68 /* ConstKeyword */)) {
- var declarations = parseVariableDeclarationList(4096 /* Const */, true);
- if (!declarations.length) {
- error(ts.Diagnostics.Variable_declaration_list_cannot_be_empty);
- }
- if (languageVersion < 2 /* ES6 */) {
- grammarErrorAtPos(declarations.pos, declarations.end - declarations.pos, ts.Diagnostics.const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher);
- }
+ var declarations = setFlag(disallowInAnd(parseVariableDeclarationList), 4096 /* Const */);
}
else {
- var varOrInit = parseExpression(true);
+ var varOrInit = disallowInAnd(parseExpression);
}
}
var forOrForInStatement;
if (parseOptional(84 /* InKeyword */)) {
- var forInStatement = createNode(169 /* ForInStatement */, pos);
+ var forInStatement = createNode(170 /* ForInStatement */, pos);
if (declarations) {
- if (declarations.length > 1) {
- error(ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement);
- }
- forInStatement.declaration = declarations[0];
+ forInStatement.declarations = declarations;
}
else {
forInStatement.variable = varOrInit;
}
- forInStatement.expression = parseExpression();
+ forInStatement.expression = allowInAnd(parseExpression);
parseExpected(16 /* CloseParenToken */);
forOrForInStatement = forInStatement;
}
else {
- var forStatement = createNode(168 /* ForStatement */, pos);
- if (declarations)
+ var forStatement = createNode(169 /* ForStatement */, pos);
+ if (declarations) {
forStatement.declarations = declarations;
- if (varOrInit)
+ }
+ if (varOrInit) {
forStatement.initializer = varOrInit;
+ }
parseExpected(21 /* SemicolonToken */);
if (token !== 21 /* SemicolonToken */ && token !== 16 /* CloseParenToken */) {
- forStatement.condition = parseExpression();
+ forStatement.condition = allowInAnd(parseExpression);
}
parseExpected(21 /* SemicolonToken */);
if (token !== 16 /* CloseParenToken */) {
- forStatement.iterator = parseExpression();
+ forStatement.iterator = allowInAnd(parseExpression);
}
parseExpected(16 /* CloseParenToken */);
forOrForInStatement = forStatement;
}
- var saveInIterationStatement = inIterationStatement;
- inIterationStatement = 1 /* Nested */;
- forOrForInStatement.statement = parseStatement(false);
- inIterationStatement = saveInIterationStatement;
+ forOrForInStatement.statement = parseStatement();
return finishNode(forOrForInStatement);
}
function parseBreakOrContinueStatement(kind) {
var node = createNode(kind);
- var errorCountBeforeStatement = file.syntacticErrors.length;
- parseExpected(kind === 171 /* BreakStatement */ ? 64 /* BreakKeyword */ : 69 /* ContinueKeyword */);
- if (!canParseSemicolon())
+ parseExpected(kind === 172 /* BreakStatement */ ? 64 /* BreakKeyword */ : 69 /* ContinueKeyword */);
+ if (!canParseSemicolon()) {
node.label = parseIdentifier();
+ }
parseSemicolon();
- finishNode(node);
- if (!inAmbientContext && errorCountBeforeStatement === file.syntacticErrors.length) {
- if (node.label) {
- checkBreakOrContinueStatementWithLabel(node);
- }
- else {
- checkBareBreakOrContinueStatement(node);
- }
- }
- return node;
- }
- function checkBareBreakOrContinueStatement(node) {
- if (node.kind === 171 /* BreakStatement */) {
- if (inIterationStatement === 1 /* Nested */ || inSwitchStatement === 1 /* Nested */) {
- return;
- }
- else if (inIterationStatement === 0 /* NotNested */ && inSwitchStatement === 0 /* NotNested */) {
- grammarErrorOnNode(node, ts.Diagnostics.A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement);
- return;
- }
- }
- else if (node.kind === 170 /* ContinueStatement */) {
- if (inIterationStatement === 1 /* Nested */) {
- return;
- }
- else if (inIterationStatement === 0 /* NotNested */) {
- grammarErrorOnNode(node, ts.Diagnostics.A_continue_statement_can_only_be_used_within_an_enclosing_iteration_statement);
- return;
- }
- }
- else {
- ts.Debug.fail("checkAnonymousBreakOrContinueStatement");
- }
- ts.Debug.assert(inIterationStatement === 2 /* CrossingFunctionBoundary */ || inSwitchStatement === 2 /* CrossingFunctionBoundary */);
- grammarErrorOnNode(node, ts.Diagnostics.Jump_target_cannot_cross_function_boundary);
- }
- function checkBreakOrContinueStatementWithLabel(node) {
- var nodeIsNestedInLabel = labelledStatementInfo.nodeIsNestedInLabel(node.label, node.kind === 170 /* ContinueStatement */, false);
- if (nodeIsNestedInLabel === 1 /* Nested */) {
- return;
- }
- if (nodeIsNestedInLabel === 2 /* CrossingFunctionBoundary */) {
- grammarErrorOnNode(node, ts.Diagnostics.Jump_target_cannot_cross_function_boundary);
- return;
- }
- if (node.kind === 170 /* ContinueStatement */) {
- grammarErrorOnNode(node, ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement);
- }
- else if (node.kind === 171 /* BreakStatement */) {
- grammarErrorOnNode(node, ts.Diagnostics.A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement);
- }
- else {
- ts.Debug.fail("checkBreakOrContinueStatementWithLabel");
- }
+ return finishNode(node);
}
function parseReturnStatement() {
- var node = createNode(172 /* ReturnStatement */);
- var errorCountBeforeReturnStatement = file.syntacticErrors.length;
- var returnTokenStart = scanner.getTokenPos();
- var returnTokenLength = scanner.getTextPos() - returnTokenStart;
+ var node = createNode(173 /* ReturnStatement */);
parseExpected(88 /* ReturnKeyword */);
- if (!canParseSemicolon())
- node.expression = parseExpression();
- parseSemicolon();
- if (!inFunctionBody && !inAmbientContext && errorCountBeforeReturnStatement === file.syntacticErrors.length) {
- grammarErrorAtPos(returnTokenStart, returnTokenLength, ts.Diagnostics.A_return_statement_can_only_be_used_within_a_function_body);
+ if (!canParseSemicolon()) {
+ node.expression = allowInAnd(parseExpression);
}
+ parseSemicolon();
return finishNode(node);
}
function parseWithStatement() {
- var node = createNode(173 /* WithStatement */);
- var startPos = scanner.getTokenPos();
+ var node = createNode(174 /* WithStatement */);
parseExpected(99 /* WithKeyword */);
- var endPos = scanner.getStartPos();
parseExpected(15 /* OpenParenToken */);
- node.expression = parseExpression();
+ node.expression = allowInAnd(parseExpression);
parseExpected(16 /* CloseParenToken */);
- node.statement = parseStatement(false);
- node = finishNode(node);
- if (isInStrictMode) {
- grammarErrorAtPos(startPos, endPos - startPos, ts.Diagnostics.with_statements_are_not_allowed_in_strict_mode);
- }
- return node;
+ node.statement = parseStatement();
+ return finishNode(node);
}
function parseCaseClause() {
- var node = createNode(175 /* CaseClause */);
+ var node = createNode(176 /* CaseClause */);
parseExpected(65 /* CaseKeyword */);
- node.expression = parseExpression();
+ node.expression = allowInAnd(parseExpression);
parseExpected(50 /* ColonToken */);
- node.statements = parseList(4 /* SwitchClauseStatements */, false, parseStatementAllowingLetDeclaration);
+ node.statements = parseList(4 /* SwitchClauseStatements */, false, parseStatement);
return finishNode(node);
}
function parseDefaultClause() {
- var node = createNode(176 /* DefaultClause */);
+ var node = createNode(177 /* DefaultClause */);
parseExpected(71 /* DefaultKeyword */);
parseExpected(50 /* ColonToken */);
- node.statements = parseList(4 /* SwitchClauseStatements */, false, parseStatementAllowingLetDeclaration);
+ node.statements = parseList(4 /* SwitchClauseStatements */, false, parseStatement);
return finishNode(node);
}
function parseCaseOrDefaultClause() {
return token === 65 /* CaseKeyword */ ? parseCaseClause() : parseDefaultClause();
}
function parseSwitchStatement() {
- var node = createNode(174 /* SwitchStatement */);
+ var node = createNode(175 /* SwitchStatement */);
parseExpected(90 /* SwitchKeyword */);
parseExpected(15 /* OpenParenToken */);
- node.expression = parseExpression();
+ node.expression = allowInAnd(parseExpression);
parseExpected(16 /* CloseParenToken */);
parseExpected(13 /* OpenBraceToken */);
- var saveInSwitchStatement = inSwitchStatement;
- inSwitchStatement = 1 /* Nested */;
node.clauses = parseList(3 /* SwitchClauses */, false, parseCaseOrDefaultClause);
- inSwitchStatement = saveInSwitchStatement;
parseExpected(14 /* CloseBraceToken */);
- var defaultClauses = ts.filter(node.clauses, function (clause) { return clause.kind === 176 /* DefaultClause */; });
- for (var i = 1, n = defaultClauses.length; i < n; i++) {
- var clause = defaultClauses[i];
- var start = ts.skipTrivia(file.text, clause.pos);
- var end = clause.statements.length > 0 ? clause.statements[0].pos : clause.end;
- grammarErrorAtPos(start, end - start, ts.Diagnostics.A_default_clause_cannot_appear_more_than_once_in_a_switch_statement);
- }
return finishNode(node);
}
function parseThrowStatement() {
- var node = createNode(178 /* ThrowStatement */);
+ var node = createNode(179 /* ThrowStatement */);
parseExpected(92 /* ThrowKeyword */);
if (scanner.hasPrecedingLineBreak()) {
error(ts.Diagnostics.Line_break_not_permitted_here);
}
- node.expression = parseExpression();
+ node.expression = allowInAnd(parseExpression);
parseSemicolon();
return finishNode(node);
}
function parseTryStatement() {
- var node = createNode(179 /* TryStatement */);
- node.tryBlock = parseTokenAndBlock(94 /* TryKeyword */, 180 /* TryBlock */);
+ var node = createNode(180 /* TryStatement */);
+ node.tryBlock = parseTokenAndBlock(94 /* TryKeyword */, 181 /* TryBlock */);
if (token === 66 /* CatchKeyword */) {
node.catchBlock = parseCatchBlock();
}
if (token === 79 /* FinallyKeyword */) {
- node.finallyBlock = parseTokenAndBlock(79 /* FinallyKeyword */, 182 /* FinallyBlock */);
+ node.finallyBlock = parseTokenAndBlock(79 /* FinallyKeyword */, 183 /* FinallyBlock */);
}
if (!(node.catchBlock || node.finallyBlock)) {
error(ts.Diagnostics.catch_or_finally_expected);
@@ -4711,54 +4465,34 @@ var ts;
parseExpected(66 /* CatchKeyword */);
parseExpected(15 /* OpenParenToken */);
var variable = parseIdentifier();
- var typeAnnotationColonStart = scanner.getTokenPos();
- var typeAnnotationColonLength = scanner.getTextPos() - typeAnnotationColonStart;
var typeAnnotation = parseTypeAnnotation();
parseExpected(16 /* CloseParenToken */);
var result = parseBlock(false, false);
- result.kind = 181 /* CatchBlock */;
+ result.kind = 182 /* CatchBlock */;
result.pos = pos;
result.variable = variable;
- if (typeAnnotation) {
- errorAtPos(typeAnnotationColonStart, typeAnnotationColonLength, ts.Diagnostics.Catch_clause_parameter_cannot_have_a_type_annotation);
- }
- if (isInStrictMode && isEvalOrArgumentsIdentifier(variable)) {
- reportInvalidUseInStrictMode(variable);
- }
+ result.type = typeAnnotation;
return result;
}
function parseDebuggerStatement() {
- var node = createNode(183 /* DebuggerStatement */);
+ var node = createNode(184 /* DebuggerStatement */);
parseExpected(70 /* DebuggerKeyword */);
parseSemicolon();
return finishNode(node);
}
- function isIterationStatementStart() {
- return token === 98 /* WhileKeyword */ || token === 73 /* DoKeyword */ || token === 80 /* ForKeyword */;
- }
- function parseStatementWithLabelSet(allowLetAndConstDeclarations) {
- labelledStatementInfo.pushCurrentLabelSet(isIterationStatementStart());
- var statement = parseStatement(allowLetAndConstDeclarations);
- labelledStatementInfo.pop();
- return statement;
- }
function isLabel() {
return isIdentifier() && lookAhead(function () { return nextToken() === 50 /* ColonToken */; });
}
- function parseLabeledStatement(allowLetAndConstDeclarations) {
- var node = createNode(177 /* LabeledStatement */);
+ function parseLabeledStatement() {
+ var node = createNode(178 /* LabeledStatement */);
node.label = parseIdentifier();
parseExpected(50 /* ColonToken */);
- if (labelledStatementInfo.nodeIsNestedInLabel(node.label, false, true)) {
- grammarErrorOnNode(node.label, ts.Diagnostics.Duplicate_label_0, getTextOfNodeFromSourceText(sourceText, node.label));
- }
- labelledStatementInfo.addLabel(node.label);
- node.statement = isLabel() ? parseLabeledStatement(allowLetAndConstDeclarations) : parseStatementWithLabelSet(allowLetAndConstDeclarations);
+ node.statement = parseStatement();
return finishNode(node);
}
function parseExpressionStatement() {
- var node = createNode(164 /* ExpressionStatement */);
- node.expression = parseExpression();
+ var node = createNode(165 /* ExpressionStatement */);
+ node.expression = allowInAnd(parseExpression);
parseSemicolon();
return finishNode(node);
}
@@ -4807,16 +4541,16 @@ var ts;
return isStartOfExpression();
}
}
- function parseStatement(allowLetAndConstDeclarations) {
+ function parseStatement() {
switch (token) {
case 13 /* OpenBraceToken */:
return parseBlock(false, false);
case 96 /* VarKeyword */:
case 102 /* LetKeyword */:
case 68 /* ConstKeyword */:
- return parseVariableStatement(allowLetAndConstDeclarations);
+ return parseVariableStatement(scanner.getStartPos(), undefined);
case 81 /* FunctionKeyword */:
- return parseFunctionDeclaration();
+ return parseFunctionDeclaration(scanner.getStartPos(), undefined);
case 21 /* SemicolonToken */:
return parseEmptyStatement();
case 82 /* IfKeyword */:
@@ -4828,9 +4562,9 @@ var ts;
case 80 /* ForKeyword */:
return parseForOrForInStatement();
case 69 /* ContinueKeyword */:
- return parseBreakOrContinueStatement(170 /* ContinueStatement */);
+ return parseBreakOrContinueStatement(171 /* ContinueStatement */);
case 64 /* BreakKeyword */:
- return parseBreakOrContinueStatement(171 /* BreakStatement */);
+ return parseBreakOrContinueStatement(172 /* BreakStatement */);
case 88 /* ReturnKeyword */:
return parseReturnStatement();
case 99 /* WithKeyword */:
@@ -4846,22 +4580,12 @@ var ts;
case 70 /* DebuggerKeyword */:
return parseDebuggerStatement();
default:
- if (isLabel()) {
- return parseLabeledStatement(allowLetAndConstDeclarations);
- }
- return parseExpressionStatement();
+ return isLabel() ? parseLabeledStatement() : parseExpressionStatement();
}
}
- function parseAndCheckFunctionBody(isConstructor) {
- var initialPosition = scanner.getTokenPos();
- var errorCountBeforeBody = file.syntacticErrors.length;
+ function parseFunctionBlockOrSemicolon(isGenerator) {
if (token === 13 /* OpenBraceToken */) {
- var body = parseBody(false);
- if (body && inAmbientContext && file.syntacticErrors.length === errorCountBeforeBody) {
- var diagnostic = isConstructor ? ts.Diagnostics.A_constructor_implementation_cannot_be_declared_in_an_ambient_context : ts.Diagnostics.A_function_implementation_cannot_be_declared_in_an_ambient_context;
- grammarErrorAtPos(initialPosition, 1, diagnostic);
- }
- return body;
+ return parseFunctionBlock(isGenerator, false);
}
if (canParseSemicolon()) {
parseSemicolon();
@@ -4869,191 +4593,96 @@ var ts;
}
error(ts.Diagnostics.Block_or_expected);
}
- function parseVariableDeclaration(flags, noIn) {
- var node = createNode(184 /* VariableDeclaration */);
- node.flags = flags;
- var errorCountBeforeVariableDeclaration = file.syntacticErrors.length;
+ function parseVariableDeclaration() {
+ var node = createNode(185 /* VariableDeclaration */);
node.name = parseIdentifier();
node.type = parseTypeAnnotation();
- var initializerStart = scanner.getTokenPos();
- var initializerFirstTokenLength = scanner.getTextPos() - initializerStart;
- node.initializer = parseInitializer(false, noIn);
- if (inAmbientContext && node.initializer && errorCountBeforeVariableDeclaration === file.syntacticErrors.length) {
- grammarErrorAtPos(initializerStart, initializerFirstTokenLength, ts.Diagnostics.Initializers_are_not_allowed_in_ambient_contexts);
- }
- if (!inAmbientContext && !node.initializer && flags & 4096 /* Const */) {
- grammarErrorOnNode(node, ts.Diagnostics.const_declarations_must_be_initialized);
- }
- if (isInStrictMode && isEvalOrArgumentsIdentifier(node.name)) {
- reportInvalidUseInStrictMode(node.name);
- }
+ node.initializer = parseInitializer(false);
return finishNode(node);
}
- function parseVariableDeclarationList(flags, noIn) {
- return parseDelimitedList(9 /* VariableDeclarations */, function () { return parseVariableDeclaration(flags, noIn); }, false);
+ function setFlag(array, flag) {
+ for (var i = 0, n = array.length; i < n; i++) {
+ array[i].flags |= flag;
+ }
+ return array;
}
- function parseVariableStatement(allowLetAndConstDeclarations, pos, flags) {
- var node = createNode(162 /* VariableStatement */, pos);
- if (flags)
- node.flags = flags;
- var errorCountBeforeVarStatement = file.syntacticErrors.length;
+ function parseVariableDeclarationList() {
+ return parseDelimitedList(9 /* VariableDeclarations */, parseVariableDeclaration);
+ }
+ function parseVariableStatement(fullStart, modifiers) {
+ var node = createNode(163 /* VariableStatement */, fullStart);
+ setModifiers(node, modifiers);
if (token === 102 /* LetKeyword */) {
node.flags |= 2048 /* Let */;
}
else if (token === 68 /* ConstKeyword */) {
node.flags |= 4096 /* Const */;
}
- else if (token !== 96 /* VarKeyword */) {
- error(ts.Diagnostics.var_let_or_const_expected);
+ else {
+ ts.Debug.assert(token === 96 /* VarKeyword */);
}
nextToken();
- node.declarations = parseVariableDeclarationList(node.flags, false);
+ node.declarations = allowInAnd(parseVariableDeclarationList);
+ setFlag(node.declarations, node.flags);
parseSemicolon();
- finishNode(node);
- if (!node.declarations.length && file.syntacticErrors.length === errorCountBeforeVarStatement) {
- grammarErrorOnNode(node, ts.Diagnostics.Variable_declaration_list_cannot_be_empty);
- }
- if (languageVersion < 2 /* ES6 */) {
- if (node.flags & 2048 /* Let */) {
- grammarErrorOnNode(node, ts.Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher);
- }
- else if (node.flags & 4096 /* Const */) {
- grammarErrorOnNode(node, ts.Diagnostics.const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher);
- }
- }
- else if (!allowLetAndConstDeclarations) {
- if (node.flags & 2048 /* Let */) {
- grammarErrorOnNode(node, ts.Diagnostics.let_declarations_can_only_be_declared_inside_a_block);
- }
- else if (node.flags & 4096 /* Const */) {
- grammarErrorOnNode(node, ts.Diagnostics.const_declarations_can_only_be_declared_inside_a_block);
- }
- }
- return node;
+ return finishNode(node);
}
- function parseFunctionDeclaration(pos, flags) {
- var node = createNode(185 /* FunctionDeclaration */, pos);
- if (flags)
- node.flags = flags;
+ function parseFunctionDeclaration(fullStart, modifiers) {
+ var node = createNode(186 /* FunctionDeclaration */, fullStart);
+ setModifiers(node, modifiers);
parseExpected(81 /* FunctionKeyword */);
+ node.asteriskToken = parseOptionalToken(34 /* AsteriskToken */);
node.name = parseIdentifier();
- var sig = parseSignature(129 /* CallSignature */, 50 /* ColonToken */, false);
- node.typeParameters = sig.typeParameters;
- node.parameters = sig.parameters;
- node.type = sig.type;
- node.body = parseAndCheckFunctionBody(false);
- if (isInStrictMode && isEvalOrArgumentsIdentifier(node.name) && node.name.kind === 63 /* Identifier */) {
- reportInvalidUseInStrictMode(node.name);
- }
+ fillSignature(129 /* CallSignature */, 50 /* ColonToken */, false, !!node.asteriskToken, node);
+ node.body = parseFunctionBlockOrSemicolon(!!node.asteriskToken);
return finishNode(node);
}
- function parseConstructorDeclaration(pos, flags) {
+ function parseConstructorDeclaration(pos, modifiers) {
var node = createNode(126 /* Constructor */, pos);
- node.flags = flags;
+ setModifiers(node, modifiers);
parseExpected(111 /* ConstructorKeyword */);
- var sig = parseSignature(129 /* CallSignature */, 50 /* ColonToken */, false);
- node.typeParameters = sig.typeParameters;
- node.parameters = sig.parameters;
- node.type = sig.type;
- node.body = parseAndCheckFunctionBody(true);
- if (node.typeParameters) {
- grammarErrorAtPos(node.typeParameters.pos, node.typeParameters.end - node.typeParameters.pos, ts.Diagnostics.Type_parameters_cannot_appear_on_a_constructor_declaration);
- }
- if (node.type) {
- grammarErrorOnNode(node.type, ts.Diagnostics.Type_annotation_cannot_appear_on_a_constructor_declaration);
- }
+ fillSignature(129 /* CallSignature */, 50 /* ColonToken */, false, false, node);
+ node.body = parseFunctionBlockOrSemicolon(false);
return finishNode(node);
}
- function parsePropertyMemberDeclaration(pos, flags) {
- var errorCountBeforePropertyDeclaration = file.syntacticErrors.length;
+ function parsePropertyMemberDeclaration(fullStart, modifiers) {
+ var flags = modifiers ? modifiers.flags : 0;
+ var asteriskToken = parseOptionalToken(34 /* AsteriskToken */);
var name = parsePropertyName();
- var questionStart = scanner.getTokenPos();
if (parseOptional(49 /* QuestionToken */)) {
- errorAtPos(questionStart, scanner.getStartPos() - questionStart, ts.Diagnostics.A_class_member_cannot_be_declared_optional);
+ flags |= 4 /* QuestionMark */;
}
- if (token === 15 /* OpenParenToken */ || token === 23 /* LessThanToken */) {
- var method = createNode(125 /* Method */, pos);
- method.flags = flags;
+ if (asteriskToken || token === 15 /* OpenParenToken */ || token === 23 /* LessThanToken */) {
+ var method = createNode(125 /* Method */, fullStart);
+ setModifiers(method, modifiers);
+ if (flags) {
+ method.flags = flags;
+ }
+ method.asteriskToken = asteriskToken;
method.name = name;
- var sig = parseSignature(129 /* CallSignature */, 50 /* ColonToken */, false);
- method.typeParameters = sig.typeParameters;
- method.parameters = sig.parameters;
- method.type = sig.type;
- method.body = parseAndCheckFunctionBody(false);
+ fillSignature(129 /* CallSignature */, 50 /* ColonToken */, false, !!asteriskToken, method);
+ method.body = parseFunctionBlockOrSemicolon(!!asteriskToken);
return finishNode(method);
}
else {
- var property = createNode(124 /* Property */, pos);
- property.flags = flags;
+ var property = createNode(124 /* Property */, fullStart);
+ setModifiers(property, modifiers);
+ if (flags) {
+ property.flags = flags;
+ }
property.name = name;
property.type = parseTypeAnnotation();
- var initializerStart = scanner.getTokenPos();
- var initializerFirstTokenLength = scanner.getTextPos() - initializerStart;
- property.initializer = parseInitializer(false);
+ property.initializer = allowInAnd(function () { return parseInitializer(false); });
parseSemicolon();
- if (inAmbientContext && property.initializer && errorCountBeforePropertyDeclaration === file.syntacticErrors.length) {
- grammarErrorAtPos(initializerStart, initializerFirstTokenLength, ts.Diagnostics.Initializers_are_not_allowed_in_ambient_contexts);
- }
return finishNode(property);
}
}
- function parseAndCheckMemberAccessorDeclaration(kind, pos, flags) {
- var errorCountBeforeAccessor = file.syntacticErrors.length;
- var accessor = parseMemberAccessorDeclaration(kind, pos, flags);
- if (errorCountBeforeAccessor === file.syntacticErrors.length) {
- if (languageVersion < 1 /* ES5 */) {
- grammarErrorOnNode(accessor.name, ts.Diagnostics.Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher);
- }
- else if (inAmbientContext) {
- grammarErrorOnNode(accessor.name, ts.Diagnostics.An_accessor_cannot_be_declared_in_an_ambient_context);
- }
- else if (accessor.typeParameters) {
- grammarErrorOnNode(accessor.name, ts.Diagnostics.An_accessor_cannot_have_type_parameters);
- }
- else if (kind === 127 /* GetAccessor */ && accessor.parameters.length) {
- grammarErrorOnNode(accessor.name, ts.Diagnostics.A_get_accessor_cannot_have_parameters);
- }
- else if (kind === 128 /* SetAccessor */) {
- if (accessor.type) {
- grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_cannot_have_a_return_type_annotation);
- }
- else if (accessor.parameters.length !== 1) {
- grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_must_have_exactly_one_parameter);
- }
- else {
- var parameter = accessor.parameters[0];
- if (parameter.flags & 8 /* Rest */) {
- grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_cannot_have_rest_parameter);
- }
- else if (parameter.flags & 243 /* Modifier */) {
- grammarErrorOnNode(accessor.name, ts.Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation);
- }
- else if (parameter.flags & 4 /* QuestionMark */) {
- grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_cannot_have_an_optional_parameter);
- }
- else if (parameter.initializer) {
- grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_parameter_cannot_have_an_initializer);
- }
- }
- }
- }
- return accessor;
- }
- function parseMemberAccessorDeclaration(kind, pos, flags) {
- var node = createNode(kind, pos);
- node.flags = flags;
+ function parseMemberAccessorDeclaration(kind, fullStart, modifiers) {
+ var node = createNode(kind, fullStart);
+ setModifiers(node, modifiers);
node.name = parsePropertyName();
- var sig = parseSignature(129 /* CallSignature */, 50 /* ColonToken */, false);
- node.typeParameters = sig.typeParameters;
- node.parameters = sig.parameters;
- node.type = sig.type;
- if (inAmbientContext && canParseSemicolon()) {
- parseSemicolon();
- node.body = createMissingNode();
- }
- else {
- node.body = parseBody(false);
- }
+ fillSignature(129 /* CallSignature */, 50 /* ColonToken */, false, false, node);
+ node.body = parseFunctionBlockOrSemicolon(false);
return finishNode(node);
}
function isClassMemberStart() {
@@ -5062,6 +4691,9 @@ var ts;
idToken = token;
nextToken();
}
+ if (token === 34 /* AsteriskToken */) {
+ return true;
+ }
if (isPropertyName()) {
idToken = token;
nextToken();
@@ -5086,212 +4718,86 @@ var ts;
}
return false;
}
- function parseAndCheckModifiers(context) {
+ function parseModifiers() {
var flags = 0;
- var lastStaticModifierStart;
- var lastStaticModifierLength;
- var lastDeclareModifierStart;
- var lastDeclareModifierLength;
- var lastPrivateModifierStart;
- var lastPrivateModifierLength;
- var lastProtectedModifierStart;
- var lastProtectedModifierLength;
+ var modifiers;
while (true) {
var modifierStart = scanner.getTokenPos();
- var modifierToken = token;
- if (!parseAnyContextualModifier())
+ var modifierKind = token;
+ if (!parseAnyContextualModifier()) {
break;
- var modifierLength = scanner.getStartPos() - modifierStart;
- switch (modifierToken) {
- case 106 /* PublicKeyword */:
- if (flags & 112 /* AccessibilityModifier */) {
- grammarErrorAtPos(modifierStart, modifierLength, ts.Diagnostics.Accessibility_modifier_already_seen);
- }
- else if (flags & 128 /* Static */) {
- grammarErrorAtPos(modifierStart, modifierLength, ts.Diagnostics._0_modifier_must_precede_1_modifier, "public", "static");
- }
- else if (context === 1 /* ModuleElements */ || context === 0 /* SourceElements */) {
- grammarErrorAtPos(modifierStart, modifierLength, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_element, "public");
- }
- flags |= 16 /* Public */;
- break;
- case 104 /* PrivateKeyword */:
- if (flags & 112 /* AccessibilityModifier */) {
- grammarErrorAtPos(modifierStart, modifierLength, ts.Diagnostics.Accessibility_modifier_already_seen);
- }
- else if (flags & 128 /* Static */) {
- grammarErrorAtPos(modifierStart, modifierLength, ts.Diagnostics._0_modifier_must_precede_1_modifier, "private", "static");
- }
- else if (context === 1 /* ModuleElements */ || context === 0 /* SourceElements */) {
- grammarErrorAtPos(modifierStart, modifierLength, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_element, "private");
- }
- lastPrivateModifierStart = modifierStart;
- lastPrivateModifierLength = modifierLength;
- flags |= 32 /* Private */;
- break;
- case 105 /* ProtectedKeyword */:
- if (flags & 16 /* Public */ || flags & 32 /* Private */ || flags & 64 /* Protected */) {
- grammarErrorAtPos(modifierStart, modifierLength, ts.Diagnostics.Accessibility_modifier_already_seen);
- }
- else if (flags & 128 /* Static */) {
- grammarErrorAtPos(modifierStart, modifierLength, ts.Diagnostics._0_modifier_must_precede_1_modifier, "protected", "static");
- }
- else if (context === 1 /* ModuleElements */ || context === 0 /* SourceElements */) {
- grammarErrorAtPos(modifierStart, modifierLength, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_element, "protected");
- }
- lastProtectedModifierStart = modifierStart;
- lastProtectedModifierLength = modifierLength;
- flags |= 64 /* Protected */;
- break;
- case 107 /* StaticKeyword */:
- if (flags & 128 /* Static */) {
- grammarErrorAtPos(modifierStart, modifierLength, ts.Diagnostics._0_modifier_already_seen, "static");
- }
- else if (context === 1 /* ModuleElements */ || context === 0 /* SourceElements */) {
- grammarErrorAtPos(modifierStart, modifierLength, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_element, "static");
- }
- else if (context === 3 /* Parameters */) {
- grammarErrorAtPos(modifierStart, modifierLength, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "static");
- }
- lastStaticModifierStart = modifierStart;
- lastStaticModifierLength = modifierLength;
- flags |= 128 /* Static */;
- break;
- case 76 /* ExportKeyword */:
- if (flags & 1 /* Export */) {
- grammarErrorAtPos(modifierStart, modifierLength, ts.Diagnostics._0_modifier_already_seen, "export");
- }
- else if (flags & 2 /* Ambient */) {
- grammarErrorAtPos(modifierStart, modifierLength, ts.Diagnostics._0_modifier_must_precede_1_modifier, "export", "declare");
- }
- else if (context === 2 /* ClassMembers */) {
- grammarErrorAtPos(modifierStart, modifierLength, ts.Diagnostics._0_modifier_cannot_appear_on_a_class_element, "export");
- }
- else if (context === 3 /* Parameters */) {
- grammarErrorAtPos(modifierStart, modifierLength, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "export");
- }
- flags |= 1 /* Export */;
- break;
- case 112 /* DeclareKeyword */:
- if (flags & 2 /* Ambient */) {
- grammarErrorAtPos(modifierStart, modifierLength, ts.Diagnostics._0_modifier_already_seen, "declare");
- }
- else if (context === 2 /* ClassMembers */) {
- grammarErrorAtPos(modifierStart, modifierLength, ts.Diagnostics._0_modifier_cannot_appear_on_a_class_element, "declare");
- }
- else if (context === 3 /* Parameters */) {
- grammarErrorAtPos(modifierStart, modifierLength, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "declare");
- }
- else if (inAmbientContext && context === 1 /* ModuleElements */) {
- grammarErrorAtPos(modifierStart, modifierLength, ts.Diagnostics.A_declare_modifier_cannot_be_used_in_an_already_ambient_context);
- }
- lastDeclareModifierStart = modifierStart;
- lastDeclareModifierLength = modifierLength;
- flags |= 2 /* Ambient */;
- break;
}
- }
- if (token === 111 /* ConstructorKeyword */ && flags & 128 /* Static */) {
- grammarErrorAtPos(lastStaticModifierStart, lastStaticModifierLength, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "static");
- }
- else if (token === 111 /* ConstructorKeyword */ && flags & 32 /* Private */) {
- grammarErrorAtPos(lastPrivateModifierStart, lastPrivateModifierLength, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "private");
- }
- else if (token === 111 /* ConstructorKeyword */ && flags & 64 /* Protected */) {
- grammarErrorAtPos(lastProtectedModifierStart, lastProtectedModifierLength, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "protected");
- }
- else if (token === 83 /* ImportKeyword */) {
- if (flags & 2 /* Ambient */) {
- grammarErrorAtPos(lastDeclareModifierStart, lastDeclareModifierLength, ts.Diagnostics.A_declare_modifier_cannot_be_used_with_an_import_declaration, "declare");
+ if (!modifiers) {
+ modifiers = [];
}
+ flags |= modifierToFlag(modifierKind);
+ modifiers.push(finishNode(createNode(modifierKind, modifierStart)));
}
- else if (token === 101 /* InterfaceKeyword */) {
- if (flags & 2 /* Ambient */) {
- grammarErrorAtPos(lastDeclareModifierStart, lastDeclareModifierLength, ts.Diagnostics.A_declare_modifier_cannot_be_used_with_an_interface_declaration, "declare");
- }
+ if (modifiers) {
+ modifiers.flags = flags;
}
- else if (token !== 76 /* ExportKeyword */ && !(flags & 2 /* Ambient */) && inAmbientContext && context === 0 /* SourceElements */) {
- var declarationStart = scanner.getTokenPos();
- var declarationFirstTokenLength = scanner.getTextPos() - declarationStart;
- grammarErrorAtPos(declarationStart, declarationFirstTokenLength, ts.Diagnostics.A_declare_modifier_is_required_for_a_top_level_declaration_in_a_d_ts_file);
- }
- return flags;
+ return modifiers;
}
function parseClassMemberDeclaration() {
- var pos = getNodePos();
- var flags = parseAndCheckModifiers(2 /* ClassMembers */);
+ var fullStart = getNodePos();
+ var modifiers = parseModifiers();
if (parseContextualModifier(113 /* GetKeyword */)) {
- return parseAndCheckMemberAccessorDeclaration(127 /* GetAccessor */, pos, flags);
+ return parseMemberAccessorDeclaration(127 /* GetAccessor */, fullStart, modifiers);
}
if (parseContextualModifier(117 /* SetKeyword */)) {
- return parseAndCheckMemberAccessorDeclaration(128 /* SetAccessor */, pos, flags);
+ return parseMemberAccessorDeclaration(128 /* SetAccessor */, fullStart, modifiers);
}
if (token === 111 /* ConstructorKeyword */) {
- return parseConstructorDeclaration(pos, flags);
+ return parseConstructorDeclaration(fullStart, modifiers);
}
- if (token >= 63 /* Identifier */ || token === 7 /* StringLiteral */ || token === 6 /* NumericLiteral */) {
- return parsePropertyMemberDeclaration(pos, flags);
+ if (token >= 63 /* Identifier */ || token === 7 /* StringLiteral */ || token === 6 /* NumericLiteral */ || token === 34 /* AsteriskToken */) {
+ return parsePropertyMemberDeclaration(fullStart, modifiers);
}
if (token === 17 /* OpenBracketToken */) {
- if (flags) {
- var start = getTokenPos(pos);
- var length = getNodePos() - start;
- errorAtPos(start, length, ts.Diagnostics.Modifiers_not_permitted_on_index_signature_members);
- }
- return parseIndexSignatureMember();
+ return parseIndexSignatureMember(fullStart, modifiers);
}
ts.Debug.fail("Should not have attempted to parse class member declaration.");
}
- function parseClassDeclaration(pos, flags) {
- var node = createNode(187 /* ClassDeclaration */, pos);
- node.flags = flags;
- var errorCountBeforeClassDeclaration = file.syntacticErrors.length;
+ function parseClassDeclaration(fullStart, modifiers) {
+ var node = createNode(188 /* ClassDeclaration */, fullStart);
+ setModifiers(node, modifiers);
parseExpected(67 /* ClassKeyword */);
node.name = parseIdentifier();
node.typeParameters = parseTypeParameters();
- node.baseType = parseOptional(77 /* ExtendsKeyword */) ? parseTypeReference() : undefined;
- var implementsKeywordStart = scanner.getTokenPos();
- var implementsKeywordLength;
+ node.baseType = inGeneratorParameterContext() ? doOutsideOfYieldContext(parseClassBaseType) : parseClassBaseType();
if (parseOptional(100 /* ImplementsKeyword */)) {
- implementsKeywordLength = scanner.getStartPos() - implementsKeywordStart;
- node.implementedTypes = parseDelimitedList(8 /* BaseTypeReferences */, parseTypeReference, false);
+ node.implementedTypes = parseDelimitedList(8 /* BaseTypeReferences */, parseTypeReference);
}
- var errorCountBeforeClassBody = file.syntacticErrors.length;
if (parseExpected(13 /* OpenBraceToken */)) {
- node.members = parseList(6 /* ClassMembers */, false, parseClassMemberDeclaration);
+ node.members = inGeneratorParameterContext() ? doOutsideOfYieldContext(parseClassMembers) : parseClassMembers();
parseExpected(14 /* CloseBraceToken */);
}
else {
node.members = createMissingList();
}
- if (node.implementedTypes && !node.implementedTypes.length && errorCountBeforeClassBody === errorCountBeforeClassDeclaration) {
- grammarErrorAtPos(implementsKeywordStart, implementsKeywordLength, ts.Diagnostics._0_list_cannot_be_empty, "implements");
- }
return finishNode(node);
}
- function parseInterfaceDeclaration(pos, flags) {
- var node = createNode(188 /* InterfaceDeclaration */, pos);
- node.flags = flags;
- var errorCountBeforeInterfaceDeclaration = file.syntacticErrors.length;
+ function parseClassMembers() {
+ return parseList(6 /* ClassMembers */, false, parseClassMemberDeclaration);
+ }
+ function parseClassBaseType() {
+ return parseOptional(77 /* ExtendsKeyword */) ? parseTypeReference() : undefined;
+ }
+ function parseInterfaceDeclaration(fullStart, modifiers) {
+ var node = createNode(189 /* InterfaceDeclaration */, fullStart);
+ setModifiers(node, modifiers);
parseExpected(101 /* InterfaceKeyword */);
node.name = parseIdentifier();
node.typeParameters = parseTypeParameters();
- var extendsKeywordStart = scanner.getTokenPos();
- var extendsKeywordLength;
if (parseOptional(77 /* ExtendsKeyword */)) {
- extendsKeywordLength = scanner.getStartPos() - extendsKeywordStart;
- node.baseTypes = parseDelimitedList(8 /* BaseTypeReferences */, parseTypeReference, false);
- }
- var errorCountBeforeInterfaceBody = file.syntacticErrors.length;
- node.members = parseTypeLiteral().members;
- if (node.baseTypes && !node.baseTypes.length && errorCountBeforeInterfaceBody === errorCountBeforeInterfaceDeclaration) {
- grammarErrorAtPos(extendsKeywordStart, extendsKeywordLength, ts.Diagnostics._0_list_cannot_be_empty, "extends");
+ node.baseTypes = parseDelimitedList(8 /* BaseTypeReferences */, parseTypeReference);
}
+ node.members = parseObjectType();
return finishNode(node);
}
- function parseTypeAliasDeclaration(pos, flags) {
- var node = createNode(189 /* TypeAliasDeclaration */, pos);
- node.flags = flags;
+ function parseTypeAliasDeclaration(fullStart, modifiers) {
+ var node = createNode(190 /* TypeAliasDeclaration */, fullStart);
+ setModifiers(node, modifiers);
parseExpected(119 /* TypeKeyword */);
node.name = parseIdentifier();
parseExpected(51 /* EqualsToken */);
@@ -5299,53 +4805,22 @@ var ts;
parseSemicolon();
return finishNode(node);
}
- function parseAndCheckEnumDeclaration(pos, flags) {
- var enumIsConst = flags & 4096 /* Const */;
- function isIntegerLiteral(expression) {
- function isInteger(literalExpression) {
- return /^[0-9]+([eE]\+?[0-9]+)?$/.test(literalExpression.text);
- }
- if (expression.kind === 154 /* PrefixOperator */) {
- var unaryExpression = expression;
- if (unaryExpression.operator === 32 /* PlusToken */ || unaryExpression.operator === 33 /* MinusToken */) {
- expression = unaryExpression.operand;
- }
- }
- if (expression.kind === 6 /* NumericLiteral */) {
- return isInteger(expression);
- }
- return false;
- }
- var inConstantEnumMemberSection = true;
- function parseAndCheckEnumMember() {
- var node = createNode(195 /* EnumMember */);
- var errorCountBeforeEnumMember = file.syntacticErrors.length;
- node.name = parsePropertyName();
- node.initializer = parseInitializer(false);
- if (!enumIsConst) {
- if (inAmbientContext) {
- if (node.initializer && !isIntegerLiteral(node.initializer) && errorCountBeforeEnumMember === file.syntacticErrors.length) {
- grammarErrorOnNode(node.name, ts.Diagnostics.Ambient_enum_elements_can_only_have_integer_literal_initializers);
- }
- }
- else if (node.initializer) {
- inConstantEnumMemberSection = isIntegerLiteral(node.initializer);
- }
- else if (!inConstantEnumMemberSection && errorCountBeforeEnumMember === file.syntacticErrors.length) {
- grammarErrorOnNode(node.name, ts.Diagnostics.Enum_member_must_have_initializer);
- }
- }
- return finishNode(node);
- }
- var node = createNode(190 /* EnumDeclaration */, pos);
+ function parseEnumMember() {
+ var node = createNode(196 /* EnumMember */, scanner.getStartPos());
+ node.name = parsePropertyName();
+ node.initializer = allowInAnd(function () { return parseInitializer(false); });
+ return finishNode(node);
+ }
+ function parseAndCheckEnumDeclaration(fullStart, flags) {
+ var node = createNode(191 /* EnumDeclaration */, fullStart);
node.flags = flags;
- if (enumIsConst) {
+ if (flags & 4096 /* Const */) {
parseExpected(68 /* ConstKeyword */);
}
parseExpected(75 /* EnumKeyword */);
node.name = parseIdentifier();
if (parseExpected(13 /* OpenBraceToken */)) {
- node.members = parseDelimitedList(7 /* EnumMembers */, parseAndCheckEnumMember, true);
+ node.members = parseDelimitedList(7 /* EnumMembers */, parseEnumMember);
parseExpected(14 /* CloseBraceToken */);
}
else {
@@ -5354,7 +4829,7 @@ var ts;
return finishNode(node);
}
function parseModuleBody() {
- var node = createNode(192 /* ModuleBlock */);
+ var node = createNode(193 /* ModuleBlock */, scanner.getStartPos());
if (parseExpected(13 /* OpenBraceToken */)) {
node.statements = parseList(1 /* ModuleElements */, false, parseModuleElement);
parseExpected(14 /* CloseBraceToken */);
@@ -5364,49 +4839,27 @@ var ts;
}
return finishNode(node);
}
- function parseInternalModuleTail(pos, flags) {
- var node = createNode(191 /* ModuleDeclaration */, pos);
+ function parseInternalModuleTail(fullStart, flags) {
+ var node = createNode(192 /* ModuleDeclaration */, fullStart);
node.flags = flags;
node.name = parseIdentifier();
- if (parseOptional(19 /* DotToken */)) {
- node.body = parseInternalModuleTail(getNodePos(), 1 /* Export */);
- }
- else {
- node.body = parseModuleBody();
- ts.forEach(node.body.statements, function (s) {
- if (s.kind === 194 /* ExportAssignment */) {
- grammarErrorOnNode(s, ts.Diagnostics.An_export_assignment_cannot_be_used_in_an_internal_module);
- }
- else if (s.kind === 193 /* ImportDeclaration */ && s.externalModuleName) {
- grammarErrorOnNode(s, ts.Diagnostics.Import_declarations_in_an_internal_module_cannot_reference_an_external_module);
- }
- });
- }
+ node.body = parseOptional(19 /* DotToken */) ? parseInternalModuleTail(getNodePos(), 1 /* Export */) : parseModuleBody();
return finishNode(node);
}
- function parseAmbientExternalModuleDeclaration(pos, flags) {
- var node = createNode(191 /* ModuleDeclaration */, pos);
+ function parseAmbientExternalModuleDeclaration(fullStart, flags) {
+ var node = createNode(192 /* ModuleDeclaration */, fullStart);
node.flags = flags;
node.name = parseStringLiteral();
- if (!inAmbientContext) {
- var errorCount = file.syntacticErrors.length;
- if (!errorCount || file.syntacticErrors[errorCount - 1].start < getTokenPos(pos)) {
- grammarErrorOnNode(node.name, ts.Diagnostics.Only_ambient_modules_can_use_quoted_names);
- }
- }
- var saveInAmbientContext = inAmbientContext;
- inAmbientContext = true;
node.body = parseModuleBody();
- inAmbientContext = saveInAmbientContext;
return finishNode(node);
}
- function parseModuleDeclaration(pos, flags) {
+ function parseModuleDeclaration(fullStart, flags) {
parseExpected(114 /* ModuleKeyword */);
- return token === 7 /* StringLiteral */ ? parseAmbientExternalModuleDeclaration(pos, flags) : parseInternalModuleTail(pos, flags);
+ return token === 7 /* StringLiteral */ ? parseAmbientExternalModuleDeclaration(fullStart, flags) : parseInternalModuleTail(fullStart, flags);
}
- function parseImportDeclaration(pos, flags) {
- var node = createNode(193 /* ImportDeclaration */, pos);
- node.flags = flags;
+ function parseImportDeclaration(fullStart, modifiers) {
+ var node = createNode(194 /* ImportDeclaration */, fullStart);
+ setModifiers(node, modifiers);
parseExpected(83 /* ImportKeyword */);
node.name = parseIdentifier();
parseExpected(51 /* EqualsToken */);
@@ -5421,8 +4874,9 @@ var ts;
parseSemicolon();
return finishNode(node);
}
- function parseExportAssignmentTail(pos) {
- var node = createNode(194 /* ExportAssignment */, pos);
+ function parseExportAssignmentTail(fullStart, modifiers) {
+ var node = createNode(195 /* ExportAssignment */, fullStart);
+ setModifiers(node, modifiers);
node.exportName = parseIdentifier();
parseSemicolon();
return finishNode(node);
@@ -5455,89 +4909,71 @@ var ts;
});
}
}
- function parseDeclaration(modifierContext) {
- var pos = getNodePos();
- var errorCountBeforeModifiers = file.syntacticErrors.length;
- var flags = parseAndCheckModifiers(modifierContext);
+ function parseDeclaration() {
+ var fullStart = getNodePos();
+ var modifiers = parseModifiers();
if (token === 76 /* ExportKeyword */) {
- var modifiersEnd = scanner.getStartPos();
nextToken();
if (parseOptional(51 /* EqualsToken */)) {
- var exportAssignmentTail = parseExportAssignmentTail(pos);
- if (flags !== 0 && errorCountBeforeModifiers === file.syntacticErrors.length) {
- var modifiersStart = ts.skipTrivia(sourceText, pos);
- grammarErrorAtPos(modifiersStart, modifiersEnd - modifiersStart, ts.Diagnostics.An_export_assignment_cannot_have_modifiers);
- }
- return exportAssignmentTail;
+ return parseExportAssignmentTail(fullStart, modifiers);
}
}
- var saveInAmbientContext = inAmbientContext;
- if (flags & 2 /* Ambient */) {
- inAmbientContext = true;
- }
+ var flags = modifiers ? modifiers.flags : 0;
var result;
switch (token) {
case 96 /* VarKeyword */:
case 102 /* LetKeyword */:
- result = parseVariableStatement(true, pos, flags);
+ result = parseVariableStatement(fullStart, modifiers);
break;
case 68 /* ConstKeyword */:
var isConstEnum = lookAhead(function () { return nextToken() === 75 /* EnumKeyword */; });
if (isConstEnum) {
- result = parseAndCheckEnumDeclaration(pos, flags | 4096 /* Const */);
+ result = parseAndCheckEnumDeclaration(fullStart, flags | 4096 /* Const */);
}
else {
- result = parseVariableStatement(true, pos, flags);
+ result = parseVariableStatement(fullStart, modifiers);
}
break;
case 81 /* FunctionKeyword */:
- result = parseFunctionDeclaration(pos, flags);
+ result = parseFunctionDeclaration(fullStart, modifiers);
break;
case 67 /* ClassKeyword */:
- result = parseClassDeclaration(pos, flags);
+ result = parseClassDeclaration(fullStart, modifiers);
break;
case 101 /* InterfaceKeyword */:
- result = parseInterfaceDeclaration(pos, flags);
+ result = parseInterfaceDeclaration(fullStart, modifiers);
break;
case 119 /* TypeKeyword */:
- result = parseTypeAliasDeclaration(pos, flags);
+ result = parseTypeAliasDeclaration(fullStart, modifiers);
break;
case 75 /* EnumKeyword */:
- result = parseAndCheckEnumDeclaration(pos, flags);
+ result = parseAndCheckEnumDeclaration(fullStart, flags);
break;
case 114 /* ModuleKeyword */:
- result = parseModuleDeclaration(pos, flags);
+ result = parseModuleDeclaration(fullStart, flags);
break;
case 83 /* ImportKeyword */:
- result = parseImportDeclaration(pos, flags);
+ result = parseImportDeclaration(fullStart, modifiers);
break;
default:
error(ts.Diagnostics.Declaration_expected);
}
- inAmbientContext = saveInAmbientContext;
+ if (modifiers) {
+ result.modifiers = modifiers;
+ }
return result;
}
function isSourceElement(inErrorRecovery) {
return isDeclarationStart() || isStatement(inErrorRecovery);
}
function parseSourceElement() {
- return parseSourceElementOrModuleElement(0 /* SourceElements */);
+ return parseSourceElementOrModuleElement();
}
function parseModuleElement() {
- return parseSourceElementOrModuleElement(1 /* ModuleElements */);
+ return parseSourceElementOrModuleElement();
}
- function parseSourceElementOrModuleElement(modifierContext) {
- if (isDeclarationStart()) {
- return parseDeclaration(modifierContext);
- }
- var statementStart = scanner.getTokenPos();
- var statementFirstTokenLength = scanner.getTextPos() - statementStart;
- var errorCountBeforeStatement = file.syntacticErrors.length;
- var statement = parseStatement(true);
- if (inAmbientContext && file.syntacticErrors.length === errorCountBeforeStatement) {
- grammarErrorAtPos(statementStart, statementFirstTokenLength, ts.Diagnostics.Statements_are_not_allowed_in_ambient_contexts);
- }
- return statement;
+ function parseSourceElementOrModuleElement() {
+ return isDeclarationStart() ? parseDeclaration() : parseStatement();
}
function processReferenceComments() {
var referencedFiles = [];
@@ -5584,22 +5020,37 @@ var ts;
};
}
function getExternalModuleIndicator() {
- return ts.forEach(file.statements, function (node) { return node.flags & 1 /* Export */ || node.kind === 193 /* ImportDeclaration */ && node.externalModuleName || node.kind === 194 /* ExportAssignment */ ? node : undefined; });
+ return ts.forEach(file.statements, function (node) { return node.flags & 1 /* Export */ || node.kind === 194 /* ImportDeclaration */ && node.externalModuleName || node.kind === 195 /* ExportAssignment */ ? node : undefined; });
+ }
+ var syntacticDiagnostics;
+ function getSyntacticDiagnostics() {
+ if (syntacticDiagnostics === undefined) {
+ if (file.parseDiagnostics.length > 0) {
+ syntacticDiagnostics = file.parseDiagnostics;
+ }
+ else {
+ syntacticDiagnostics = file.grammarDiagnostics;
+ checkGrammar(sourceText, languageVersion, file);
+ }
+ }
+ ts.Debug.assert(syntacticDiagnostics !== undefined);
+ return syntacticDiagnostics;
}
scanner = ts.createScanner(languageVersion, true, sourceText, scanError, onComment);
var rootNodeFlags = 0;
if (ts.fileExtensionIs(filename, ".d.ts")) {
rootNodeFlags = 1024 /* DeclarationFile */;
- inAmbientContext = true;
}
- file = createRootNode(196 /* SourceFile */, 0, sourceText.length, rootNodeFlags);
+ file = createRootNode(197 /* SourceFile */, 0, sourceText.length, rootNodeFlags);
file.filename = ts.normalizePath(filename);
file.text = sourceText;
file.getLineAndCharacterFromPosition = getLineAndCharacterFromSourcePosition;
file.getPositionFromLineAndCharacter = getPositionFromSourceLineAndCharacter;
file.getLineStarts = getLineStarts;
- file.syntacticErrors = [];
- file.semanticErrors = [];
+ file.getSyntacticDiagnostics = getSyntacticDiagnostics;
+ file.parseDiagnostics = [];
+ file.grammarDiagnostics = [];
+ file.semanticDiagnostics = [];
var referenceComments = processReferenceComments();
file.referencedFiles = referenceComments.referencedFiles;
file.amdDependencies = referenceComments.amdDependencies;
@@ -5615,6 +5066,913 @@ var ts;
return file;
}
ts.createSourceFile = createSourceFile;
+ function isLeftHandSideExpression(expr) {
+ if (expr) {
+ switch (expr.kind) {
+ case 145 /* PropertyAccess */:
+ case 146 /* IndexedAccess */:
+ case 148 /* NewExpression */:
+ case 147 /* CallExpression */:
+ case 149 /* TaggedTemplateExpression */:
+ case 141 /* ArrayLiteral */:
+ case 151 /* ParenExpression */:
+ case 142 /* ObjectLiteral */:
+ case 152 /* FunctionExpression */:
+ case 63 /* Identifier */:
+ case 120 /* Missing */:
+ case 8 /* RegularExpressionLiteral */:
+ case 6 /* NumericLiteral */:
+ case 7 /* StringLiteral */:
+ case 9 /* NoSubstitutionTemplateLiteral */:
+ case 158 /* TemplateExpression */:
+ case 78 /* FalseKeyword */:
+ case 87 /* NullKeyword */:
+ case 91 /* ThisKeyword */:
+ case 93 /* TrueKeyword */:
+ case 89 /* SuperKeyword */:
+ return true;
+ }
+ }
+ return false;
+ }
+ function isAssignmentOperator(token) {
+ return token >= 51 /* FirstAssignment */ && token <= 62 /* LastAssignment */;
+ }
+ function checkGrammar(sourceText, languageVersion, file) {
+ var grammarDiagnostics = file.grammarDiagnostics;
+ var scanner = ts.createScanner(languageVersion, true, sourceText);
+ var inAmbientContext = ts.fileExtensionIs(file.filename, ".d.ts");
+ var inFunctionBlock = false;
+ var parent;
+ visitNode(file);
+ function visitNode(node) {
+ var savedParent = parent;
+ node.parent = parent;
+ parent = node;
+ if (!checkModifiers(node)) {
+ var savedInFunctionBlock = inFunctionBlock;
+ if (node.kind === 187 /* FunctionBlock */) {
+ inFunctionBlock = true;
+ }
+ var savedInAmbientContext = inAmbientContext;
+ if (node.flags & 2 /* Ambient */) {
+ inAmbientContext = true;
+ }
+ checkNodeAndChildren(node);
+ inAmbientContext = savedInAmbientContext;
+ inFunctionBlock = savedInFunctionBlock;
+ }
+ parent = savedParent;
+ }
+ function checkNodeAndChildren(node) {
+ var nodeKind = node.kind;
+ if (inAmbientContext && checkForStatementInAmbientContext(node, nodeKind)) {
+ return;
+ }
+ if (checkNode(node, nodeKind)) {
+ return;
+ }
+ forEachChild(node, visitNode);
+ }
+ function checkNode(node, nodeKind) {
+ switch (nodeKind) {
+ case 153 /* ArrowFunction */:
+ case 129 /* CallSignature */:
+ case 134 /* ConstructorType */:
+ case 130 /* ConstructSignature */:
+ case 133 /* FunctionType */:
+ return checkAnyParsedSignature(node);
+ case 172 /* BreakStatement */:
+ case 171 /* ContinueStatement */:
+ return checkBreakOrContinueStatement(node);
+ case 147 /* CallExpression */:
+ case 148 /* NewExpression */:
+ return checkCallOrNewExpression(node);
+ case 191 /* EnumDeclaration */: return checkEnumDeclaration(node);
+ case 156 /* BinaryExpression */: return checkBinaryExpression(node);
+ case 182 /* CatchBlock */: return checkCatchBlock(node);
+ case 188 /* ClassDeclaration */: return checkClassDeclaration(node);
+ case 126 /* Constructor */: return checkConstructor(node);
+ case 195 /* ExportAssignment */: return checkExportAssignment(node);
+ case 170 /* ForInStatement */: return checkForInStatement(node);
+ case 169 /* ForStatement */: return checkForStatement(node);
+ case 186 /* FunctionDeclaration */: return checkFunctionDeclaration(node);
+ case 152 /* FunctionExpression */: return checkFunctionExpression(node);
+ case 127 /* GetAccessor */: return checkGetAccessor(node);
+ case 146 /* IndexedAccess */: return checkIndexedAccess(node);
+ case 131 /* IndexSignature */: return checkIndexSignature(node);
+ case 189 /* InterfaceDeclaration */: return checkInterfaceDeclaration(node);
+ case 178 /* LabeledStatement */: return checkLabeledStatement(node);
+ case 125 /* Method */: return checkMethod(node);
+ case 192 /* ModuleDeclaration */: return checkModuleDeclaration(node);
+ case 142 /* ObjectLiteral */: return checkObjectLiteral(node);
+ case 6 /* NumericLiteral */: return checkNumericLiteral(node);
+ case 123 /* Parameter */: return checkParameter(node);
+ case 155 /* PostfixOperator */: return checkPostfixOperator(node);
+ case 154 /* PrefixOperator */: return checkPrefixOperator(node);
+ case 124 /* Property */: return checkProperty(node);
+ case 143 /* PropertyAssignment */: return checkPropertyAssignment(node);
+ case 173 /* ReturnStatement */: return checkReturnStatement(node);
+ case 128 /* SetAccessor */: return checkSetAccessor(node);
+ case 197 /* SourceFile */: return checkSourceFile(node);
+ case 144 /* ShorthandPropertyAssignment */: return checkShorthandPropertyAssignment(node);
+ case 175 /* SwitchStatement */: return checkSwitchStatement(node);
+ case 149 /* TaggedTemplateExpression */: return checkTaggedTemplateExpression(node);
+ case 138 /* TupleType */: return checkTupleType(node);
+ case 122 /* TypeParameter */: return checkTypeParameter(node);
+ case 132 /* TypeReference */: return checkTypeReference(node);
+ case 185 /* VariableDeclaration */: return checkVariableDeclaration(node);
+ case 163 /* VariableStatement */: return checkVariableStatement(node);
+ case 174 /* WithStatement */: return checkWithStatement(node);
+ case 160 /* YieldExpression */: return checkYieldExpression(node);
+ }
+ }
+ function grammarErrorOnFirstToken(node, message, arg0, arg1, arg2) {
+ var start = ts.skipTrivia(sourceText, node.pos);
+ scanner.setTextPos(start);
+ scanner.scan();
+ var end = scanner.getTextPos();
+ grammarDiagnostics.push(ts.createFileDiagnostic(file, start, end - start, message, arg0, arg1, arg2));
+ return true;
+ }
+ function grammarErrorOnNode(node, message, arg0, arg1, arg2) {
+ var span = getErrorSpanForNode(node);
+ var start = span.end > span.pos ? ts.skipTrivia(file.text, span.pos) : span.pos;
+ var length = span.end - start;
+ grammarDiagnostics.push(ts.createFileDiagnostic(file, start, length, message, arg0, arg1, arg2));
+ return true;
+ }
+ function grammarErrorAtPos(start, length, message, arg0, arg1, arg2) {
+ grammarDiagnostics.push(ts.createFileDiagnostic(file, start, length, message, arg0, arg1, arg2));
+ return true;
+ }
+ function reportInvalidUseInStrictMode(node) {
+ var name = sourceText.substring(ts.skipTrivia(sourceText, node.pos), node.end);
+ return grammarErrorOnNode(node, ts.Diagnostics.Invalid_use_of_0_in_strict_mode, name);
+ }
+ function checkForStatementInAmbientContext(node, kind) {
+ switch (kind) {
+ case 162 /* Block */:
+ case 164 /* EmptyStatement */:
+ case 166 /* IfStatement */:
+ case 167 /* DoStatement */:
+ case 168 /* WhileStatement */:
+ case 169 /* ForStatement */:
+ case 170 /* ForInStatement */:
+ case 171 /* ContinueStatement */:
+ case 172 /* BreakStatement */:
+ case 173 /* ReturnStatement */:
+ case 174 /* WithStatement */:
+ case 175 /* SwitchStatement */:
+ case 179 /* ThrowStatement */:
+ case 180 /* TryStatement */:
+ case 184 /* DebuggerStatement */:
+ case 178 /* LabeledStatement */:
+ case 165 /* ExpressionStatement */:
+ return grammarErrorOnFirstToken(node, ts.Diagnostics.Statements_are_not_allowed_in_ambient_contexts);
+ }
+ }
+ function checkAnyParsedSignature(node) {
+ return checkTypeParameterList(node.typeParameters) || checkParameterList(node.parameters);
+ }
+ function checkBinaryExpression(node) {
+ if (node.parserContextFlags & 1 /* StrictMode */) {
+ if (isLeftHandSideExpression(node.left) && isAssignmentOperator(node.operator)) {
+ if (isEvalOrArgumentsIdentifier(node.left)) {
+ return reportInvalidUseInStrictMode(node.left);
+ }
+ }
+ }
+ }
+ function isIterationStatement(node, lookInLabeledStatements) {
+ switch (node.kind) {
+ case 169 /* ForStatement */:
+ case 170 /* ForInStatement */:
+ case 167 /* DoStatement */:
+ case 168 /* WhileStatement */:
+ return true;
+ case 178 /* LabeledStatement */:
+ return lookInLabeledStatements && isIterationStatement(node.statement, lookInLabeledStatements);
+ }
+ return false;
+ }
+ function checkLabeledStatement(node) {
+ var current = node.parent;
+ while (current) {
+ if (isAnyFunction(current)) {
+ break;
+ }
+ if (current.kind === 178 /* LabeledStatement */ && current.label.text === node.label.text) {
+ return grammarErrorOnNode(node.label, ts.Diagnostics.Duplicate_label_0, getTextOfNodeFromSourceText(sourceText, node.label));
+ }
+ current = current.parent;
+ }
+ }
+ function checkBreakOrContinueStatement(node) {
+ var current = node;
+ while (current) {
+ if (isAnyFunction(current)) {
+ return grammarErrorOnNode(node, ts.Diagnostics.Jump_target_cannot_cross_function_boundary);
+ }
+ switch (current.kind) {
+ case 178 /* LabeledStatement */:
+ if (node.label && current.label.text === node.label.text) {
+ var isMisplacedContinueLabel = node.kind === 171 /* ContinueStatement */ && !isIterationStatement(current.statement, true);
+ if (isMisplacedContinueLabel) {
+ return grammarErrorOnNode(node, ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement);
+ }
+ return false;
+ }
+ break;
+ case 175 /* SwitchStatement */:
+ if (node.kind === 172 /* BreakStatement */ && !node.label) {
+ return false;
+ }
+ break;
+ default:
+ if (isIterationStatement(current, false) && !node.label) {
+ return false;
+ }
+ break;
+ }
+ current = current.parent;
+ }
+ if (node.label) {
+ var message = node.kind === 172 /* BreakStatement */ ? ts.Diagnostics.A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement : ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement;
+ return grammarErrorOnNode(node, message);
+ }
+ else {
+ var message = node.kind === 172 /* BreakStatement */ ? ts.Diagnostics.A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement : ts.Diagnostics.A_continue_statement_can_only_be_used_within_an_enclosing_iteration_statement;
+ return grammarErrorOnNode(node, message);
+ }
+ }
+ function checkCallOrNewExpression(node) {
+ return checkTypeArguments(node.typeArguments) || checkArguments(node.arguments);
+ }
+ function checkArguments(arguments) {
+ return checkForDisallowedTrailingComma(arguments) || checkForOmittedArgument(arguments);
+ }
+ function checkTypeArguments(typeArguments) {
+ return checkForDisallowedTrailingComma(typeArguments) || checkForAtLeastOneTypeArgument(typeArguments) || checkForMissingTypeArgument(typeArguments);
+ }
+ function checkForOmittedArgument(arguments) {
+ if (arguments) {
+ for (var i = 0, n = arguments.length; i < n; i++) {
+ var arg = arguments[i];
+ if (arg.kind === 161 /* OmittedExpression */) {
+ return grammarErrorAtPos(arg.pos, 0, ts.Diagnostics.Argument_expression_expected);
+ }
+ }
+ }
+ }
+ function checkForMissingTypeArgument(typeArguments) {
+ if (typeArguments) {
+ for (var i = 0, n = typeArguments.length; i < n; i++) {
+ var arg = typeArguments[i];
+ if (arg.kind === 120 /* Missing */) {
+ return grammarErrorAtPos(arg.pos, 0, ts.Diagnostics.Type_expected);
+ }
+ }
+ }
+ }
+ function checkForAtLeastOneTypeArgument(typeArguments) {
+ if (typeArguments && typeArguments.length === 0) {
+ var start = typeArguments.pos - "<".length;
+ var end = ts.skipTrivia(sourceText, typeArguments.end) + ">".length;
+ return grammarErrorAtPos(start, end - start, ts.Diagnostics.Type_argument_list_cannot_be_empty);
+ }
+ }
+ function checkForDisallowedTrailingComma(list) {
+ if (list && list.hasTrailingComma) {
+ var start = list.end - ",".length;
+ var end = list.end;
+ return grammarErrorAtPos(start, end - start, ts.Diagnostics.Trailing_comma_not_allowed);
+ }
+ }
+ function checkCatchBlock(node) {
+ if (node.type) {
+ var colonStart = ts.skipTrivia(sourceText, node.variable.end);
+ return grammarErrorAtPos(colonStart, ":".length, ts.Diagnostics.Catch_clause_parameter_cannot_have_a_type_annotation);
+ }
+ if (node.parserContextFlags & 1 /* StrictMode */ && isEvalOrArgumentsIdentifier(node.variable)) {
+ return reportInvalidUseInStrictMode(node.variable);
+ }
+ }
+ function checkClassDeclaration(node) {
+ return checkForDisallowedTrailingComma(node.implementedTypes) || checkForAtLeastOneHeritageClause(node.implementedTypes, "implements");
+ }
+ function checkForAtLeastOneHeritageClause(types, listType) {
+ if (types && types.length === 0) {
+ return grammarErrorAtPos(types.pos, 0, ts.Diagnostics._0_list_cannot_be_empty, listType);
+ }
+ }
+ function checkConstructor(node) {
+ return checkAnyParsedSignature(node) || checkConstructorTypeParameters(node) || checkConstructorTypeAnnotation(node) || checkForBodyInAmbientContext(node.body, true);
+ }
+ function checkConstructorTypeParameters(node) {
+ if (node.typeParameters) {
+ return grammarErrorAtPos(node.typeParameters.pos, node.typeParameters.end - node.typeParameters.pos, ts.Diagnostics.Type_parameters_cannot_appear_on_a_constructor_declaration);
+ }
+ }
+ function checkConstructorTypeAnnotation(node) {
+ if (node.type) {
+ return grammarErrorOnNode(node.type, ts.Diagnostics.Type_annotation_cannot_appear_on_a_constructor_declaration);
+ }
+ }
+ function checkEnumDeclaration(enumDecl) {
+ var enumIsConst = (enumDecl.flags & 4096 /* Const */) !== 0;
+ var hasError = false;
+ if (!enumIsConst) {
+ var inConstantEnumMemberSection = true;
+ for (var i = 0, n = enumDecl.members.length; i < n; i++) {
+ var node = enumDecl.members[i];
+ if (inAmbientContext) {
+ if (node.initializer && !isIntegerLiteral(node.initializer)) {
+ hasError = grammarErrorOnNode(node.name, ts.Diagnostics.Ambient_enum_elements_can_only_have_integer_literal_initializers) || hasError;
+ }
+ }
+ else if (node.initializer) {
+ inConstantEnumMemberSection = isIntegerLiteral(node.initializer);
+ }
+ else if (!inConstantEnumMemberSection) {
+ hasError = grammarErrorOnNode(node.name, ts.Diagnostics.Enum_member_must_have_initializer) || hasError;
+ }
+ }
+ }
+ return hasError;
+ }
+ function isIntegerLiteral(expression) {
+ function isInteger(literalExpression) {
+ return /^[0-9]+([eE]\+?[0-9]+)?$/.test(literalExpression.text);
+ }
+ if (expression.kind === 154 /* PrefixOperator */) {
+ var unaryExpression = expression;
+ if (unaryExpression.operator === 32 /* PlusToken */ || unaryExpression.operator === 33 /* MinusToken */) {
+ expression = unaryExpression.operand;
+ }
+ }
+ if (expression.kind === 6 /* NumericLiteral */) {
+ return isInteger(expression);
+ }
+ return false;
+ }
+ function checkExportAssignment(node) {
+ if (node.flags & 243 /* Modifier */) {
+ return grammarErrorOnFirstToken(node, ts.Diagnostics.An_export_assignment_cannot_have_modifiers);
+ }
+ }
+ function checkForInStatement(node) {
+ return checkVariableDeclarations(node.declarations) || checkForMoreThanOneDeclaration(node.declarations);
+ }
+ function checkForStatement(node) {
+ return checkVariableDeclarations(node.declarations);
+ }
+ function checkForMoreThanOneDeclaration(declarations) {
+ if (declarations && declarations.length > 1) {
+ return grammarErrorOnFirstToken(declarations[1], ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement);
+ }
+ }
+ function checkFunctionDeclaration(node) {
+ return checkAnyParsedSignature(node) || checkFunctionName(node.name) || checkForBodyInAmbientContext(node.body, false) || checkForGenerator(node);
+ }
+ function checkForGenerator(node) {
+ if (node.asteriskToken) {
+ return grammarErrorOnNode(node.asteriskToken, ts.Diagnostics.generators_are_not_currently_supported);
+ }
+ }
+ function checkFunctionExpression(node) {
+ return checkAnyParsedSignature(node) || checkFunctionName(node.name) || checkForGenerator(node);
+ }
+ function checkFunctionName(name) {
+ if (name && name.parserContextFlags & 1 /* StrictMode */ && isEvalOrArgumentsIdentifier(name)) {
+ return reportInvalidUseInStrictMode(name);
+ }
+ }
+ function checkGetAccessor(node) {
+ return checkAnyParsedSignature(node) || checkAccessor(node);
+ }
+ function checkIndexedAccess(node) {
+ if (node.index.kind === 120 /* Missing */ && node.parent.kind === 148 /* NewExpression */ && node.parent.func === node) {
+ var start = ts.skipTrivia(sourceText, node.parent.pos);
+ var end = node.end;
+ return grammarErrorAtPos(start, end - start, ts.Diagnostics.new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead);
+ }
+ }
+ function checkIndexSignature(node) {
+ return checkIndexSignatureParameters(node) || checkForIndexSignatureModifiers(node);
+ }
+ function checkForIndexSignatureModifiers(node) {
+ if (node.flags & 243 /* Modifier */) {
+ return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_not_permitted_on_index_signature_members);
+ }
+ }
+ function checkIndexSignatureParameters(node) {
+ var parameter = node.parameters[0];
+ if (node.parameters.length !== 1) {
+ if (parameter) {
+ return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_must_have_exactly_one_parameter);
+ }
+ else {
+ return grammarErrorOnNode(node, ts.Diagnostics.An_index_signature_must_have_exactly_one_parameter);
+ }
+ }
+ else if (parameter.flags & 8 /* Rest */) {
+ return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_cannot_have_a_rest_parameter);
+ }
+ else if (parameter.flags & 243 /* Modifier */) {
+ return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_cannot_have_an_accessibility_modifier);
+ }
+ else if (parameter.flags & 4 /* QuestionMark */) {
+ return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_cannot_have_a_question_mark);
+ }
+ else if (parameter.initializer) {
+ return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_cannot_have_an_initializer);
+ }
+ else if (!parameter.type) {
+ return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_must_have_a_type_annotation);
+ }
+ else if (parameter.type.kind !== 118 /* StringKeyword */ && parameter.type.kind !== 116 /* NumberKeyword */) {
+ return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_type_must_be_string_or_number);
+ }
+ else if (!node.type) {
+ return grammarErrorOnNode(node, ts.Diagnostics.An_index_signature_must_have_a_type_annotation);
+ }
+ }
+ function checkInterfaceDeclaration(node) {
+ return checkForDisallowedTrailingComma(node.baseTypes) || checkForAtLeastOneHeritageClause(node.baseTypes, "extends");
+ }
+ function checkMethod(node) {
+ return checkAnyParsedSignature(node) || checkForBodyInAmbientContext(node.body, false) || (node.parent.kind === 188 /* ClassDeclaration */ && checkForInvalidQuestionMark(node, ts.Diagnostics.A_class_member_cannot_be_declared_optional)) || checkForGenerator(node);
+ }
+ function checkForBodyInAmbientContext(body, isConstructor) {
+ if (inAmbientContext && body && body.kind === 187 /* FunctionBlock */) {
+ var diagnostic = isConstructor ? ts.Diagnostics.A_constructor_implementation_cannot_be_declared_in_an_ambient_context : ts.Diagnostics.A_function_implementation_cannot_be_declared_in_an_ambient_context;
+ return grammarErrorOnFirstToken(body, diagnostic);
+ }
+ }
+ function checkModuleDeclaration(node) {
+ return checkModuleDeclarationName(node) || checkModuleDeclarationStatements(node);
+ }
+ function checkModuleDeclarationName(node) {
+ if (!inAmbientContext && node.name.kind === 7 /* StringLiteral */) {
+ return grammarErrorOnNode(node.name, ts.Diagnostics.Only_ambient_modules_can_use_quoted_names);
+ }
+ }
+ function checkModuleDeclarationStatements(node) {
+ if (node.name.kind === 63 /* Identifier */ && node.body.kind === 193 /* ModuleBlock */) {
+ var statements = node.body.statements;
+ for (var i = 0, n = statements.length; i < n; i++) {
+ var statement = statements[i];
+ if (statement.kind === 195 /* ExportAssignment */) {
+ return grammarErrorOnNode(statement, ts.Diagnostics.An_export_assignment_cannot_be_used_in_an_internal_module);
+ }
+ else if (statement.kind === 194 /* ImportDeclaration */ && statement.externalModuleName) {
+ return grammarErrorOnNode(statement.externalModuleName, ts.Diagnostics.Import_declarations_in_an_internal_module_cannot_reference_an_external_module);
+ }
+ }
+ }
+ }
+ function checkObjectLiteral(node) {
+ var seen = {};
+ var Property = 1;
+ var GetAccessor = 2;
+ var SetAccesor = 4;
+ var GetOrSetAccessor = GetAccessor | SetAccesor;
+ var inStrictMode = (node.parserContextFlags & 1 /* StrictMode */) !== 0;
+ for (var i = 0, n = node.properties.length; i < n; i++) {
+ var prop = node.properties[i];
+ if (prop.kind === 161 /* OmittedExpression */) {
+ continue;
+ }
+ var p = prop;
+ var name = p.name;
+ var currentKind;
+ if (p.kind === 143 /* PropertyAssignment */) {
+ currentKind = Property;
+ }
+ else if (p.kind === 144 /* ShorthandPropertyAssignment */) {
+ currentKind = Property;
+ }
+ else if (p.kind === 127 /* GetAccessor */) {
+ currentKind = GetAccessor;
+ }
+ else if (p.kind === 128 /* SetAccessor */) {
+ currentKind = SetAccesor;
+ }
+ else {
+ ts.Debug.fail("Unexpected syntax kind:" + p.kind);
+ }
+ if (!ts.hasProperty(seen, name.text)) {
+ seen[name.text] = currentKind;
+ }
+ else {
+ var existingKind = seen[name.text];
+ if (currentKind === Property && existingKind === Property) {
+ if (inStrictMode) {
+ grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode);
+ }
+ }
+ else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) {
+ if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) {
+ seen[name.text] = currentKind | existingKind;
+ }
+ else {
+ return grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name);
+ }
+ }
+ else {
+ return grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name);
+ }
+ }
+ }
+ }
+ function checkNumericLiteral(node) {
+ if (node.flags & 8192 /* OctalLiteral */) {
+ if (node.parserContextFlags & 1 /* StrictMode */) {
+ return grammarErrorOnNode(node, ts.Diagnostics.Octal_literals_are_not_allowed_in_strict_mode);
+ }
+ else if (languageVersion >= 1 /* ES5 */) {
+ return grammarErrorOnNode(node, ts.Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher);
+ }
+ }
+ }
+ function checkModifiers(node) {
+ switch (node.kind) {
+ case 127 /* GetAccessor */:
+ case 128 /* SetAccessor */:
+ case 126 /* Constructor */:
+ case 124 /* Property */:
+ case 125 /* Method */:
+ case 131 /* IndexSignature */:
+ case 188 /* ClassDeclaration */:
+ case 189 /* InterfaceDeclaration */:
+ case 192 /* ModuleDeclaration */:
+ case 191 /* EnumDeclaration */:
+ case 195 /* ExportAssignment */:
+ case 163 /* VariableStatement */:
+ case 186 /* FunctionDeclaration */:
+ case 190 /* TypeAliasDeclaration */:
+ case 194 /* ImportDeclaration */:
+ case 123 /* Parameter */:
+ break;
+ default:
+ return false;
+ }
+ if (!node.modifiers) {
+ return;
+ }
+ var lastStatic, lastPrivate, lastProtected, lastDeclare;
+ var flags = 0;
+ for (var i = 0, n = node.modifiers.length; i < n; i++) {
+ var modifier = node.modifiers[i];
+ switch (modifier.kind) {
+ case 106 /* PublicKeyword */:
+ case 105 /* ProtectedKeyword */:
+ case 104 /* PrivateKeyword */:
+ var text;
+ if (modifier.kind === 106 /* PublicKeyword */) {
+ text = "public";
+ }
+ else if (modifier.kind === 105 /* ProtectedKeyword */) {
+ text = "protected";
+ lastProtected = modifier;
+ }
+ else {
+ text = "private";
+ lastPrivate = modifier;
+ }
+ if (flags & 112 /* AccessibilityModifier */) {
+ return grammarErrorOnNode(modifier, ts.Diagnostics.Accessibility_modifier_already_seen);
+ }
+ else if (flags & 128 /* Static */) {
+ return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, text, "static");
+ }
+ else if (node.parent.kind === 193 /* ModuleBlock */ || node.parent.kind === 197 /* SourceFile */) {
+ return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_element, text);
+ }
+ flags |= modifierToFlag(modifier.kind);
+ break;
+ case 107 /* StaticKeyword */:
+ if (flags & 128 /* Static */) {
+ return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "static");
+ }
+ else if (node.parent.kind === 193 /* ModuleBlock */ || node.parent.kind === 197 /* SourceFile */) {
+ return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_element, "static");
+ }
+ else if (node.kind === 123 /* Parameter */) {
+ return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "static");
+ }
+ flags |= 128 /* Static */;
+ lastStatic = modifier;
+ break;
+ case 76 /* ExportKeyword */:
+ if (flags & 1 /* Export */) {
+ return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "export");
+ }
+ else if (flags & 2 /* Ambient */) {
+ return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, "export", "declare");
+ }
+ else if (node.parent.kind === 188 /* ClassDeclaration */) {
+ return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_class_element, "export");
+ }
+ else if (node.kind === 123 /* Parameter */) {
+ return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "export");
+ }
+ flags |= 1 /* Export */;
+ break;
+ case 112 /* DeclareKeyword */:
+ if (flags & 2 /* Ambient */) {
+ return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "declare");
+ }
+ else if (node.parent.kind === 188 /* ClassDeclaration */) {
+ return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_class_element, "declare");
+ }
+ else if (node.kind === 123 /* Parameter */) {
+ return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "declare");
+ }
+ else if (inAmbientContext && node.parent.kind === 193 /* ModuleBlock */) {
+ return grammarErrorOnNode(modifier, ts.Diagnostics.A_declare_modifier_cannot_be_used_in_an_already_ambient_context);
+ }
+ flags |= 2 /* Ambient */;
+ lastDeclare = modifier;
+ break;
+ }
+ }
+ if (node.kind === 126 /* Constructor */) {
+ if (flags & 128 /* Static */) {
+ return grammarErrorOnNode(lastStatic, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "static");
+ }
+ else if (flags & 64 /* Protected */) {
+ return grammarErrorOnNode(lastProtected, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "protected");
+ }
+ else if (flags & 32 /* Private */) {
+ return grammarErrorOnNode(lastPrivate, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "private");
+ }
+ }
+ else if (node.kind === 194 /* ImportDeclaration */ && flags & 2 /* Ambient */) {
+ return grammarErrorOnNode(lastDeclare, ts.Diagnostics.A_declare_modifier_cannot_be_used_with_an_import_declaration, "declare");
+ }
+ else if (node.kind === 189 /* InterfaceDeclaration */ && flags & 2 /* Ambient */) {
+ return grammarErrorOnNode(lastDeclare, ts.Diagnostics.A_declare_modifier_cannot_be_used_with_an_interface_declaration, "declare");
+ }
+ }
+ function checkParameter(node) {
+ if (node.parserContextFlags & 1 /* StrictMode */ && isEvalOrArgumentsIdentifier(node.name)) {
+ return reportInvalidUseInStrictMode(node.name);
+ }
+ }
+ function checkTypeParameterList(typeParameters) {
+ if (checkForDisallowedTrailingComma(typeParameters)) {
+ return true;
+ }
+ if (typeParameters && typeParameters.length === 0) {
+ var start = typeParameters.pos - "<".length;
+ var end = ts.skipTrivia(sourceText, typeParameters.end) + ">".length;
+ return grammarErrorAtPos(start, end - start, ts.Diagnostics.Type_parameter_list_cannot_be_empty);
+ }
+ }
+ function checkParameterList(parameters) {
+ if (checkForDisallowedTrailingComma(parameters)) {
+ return true;
+ }
+ var seenOptionalParameter = false;
+ var parameterCount = parameters.length;
+ for (var i = 0; i < parameterCount; i++) {
+ var parameter = parameters[i];
+ if (parameter.flags & 8 /* Rest */) {
+ if (i !== (parameterCount - 1)) {
+ return grammarErrorOnNode(parameter.name, ts.Diagnostics.A_rest_parameter_must_be_last_in_a_parameter_list);
+ }
+ if (parameter.flags & 4 /* QuestionMark */) {
+ return grammarErrorOnNode(parameter.name, ts.Diagnostics.A_rest_parameter_cannot_be_optional);
+ }
+ if (parameter.initializer) {
+ return grammarErrorOnNode(parameter.name, ts.Diagnostics.A_rest_parameter_cannot_have_an_initializer);
+ }
+ }
+ else if (parameter.flags & 4 /* QuestionMark */ || parameter.initializer) {
+ seenOptionalParameter = true;
+ if (parameter.flags & 4 /* QuestionMark */ && parameter.initializer) {
+ return grammarErrorOnNode(parameter.name, ts.Diagnostics.Parameter_cannot_have_question_mark_and_initializer);
+ }
+ }
+ else {
+ if (seenOptionalParameter) {
+ return grammarErrorOnNode(parameter.name, ts.Diagnostics.A_required_parameter_cannot_follow_an_optional_parameter);
+ }
+ }
+ }
+ }
+ function checkPostfixOperator(node) {
+ if (node.parserContextFlags & 1 /* StrictMode */ && isEvalOrArgumentsIdentifier(node.operand)) {
+ return reportInvalidUseInStrictMode(node.operand);
+ }
+ }
+ function checkPrefixOperator(node) {
+ if (node.parserContextFlags & 1 /* StrictMode */) {
+ if ((node.operator === 37 /* PlusPlusToken */ || node.operator === 38 /* MinusMinusToken */) && isEvalOrArgumentsIdentifier(node.operand)) {
+ return reportInvalidUseInStrictMode(node.operand);
+ }
+ else if (node.operator === 72 /* DeleteKeyword */ && node.operand.kind === 63 /* Identifier */) {
+ return grammarErrorOnNode(node.operand, ts.Diagnostics.delete_cannot_be_called_on_an_identifier_in_strict_mode);
+ }
+ }
+ }
+ function checkProperty(node) {
+ return (node.parent.kind === 188 /* ClassDeclaration */ && checkForInvalidQuestionMark(node, ts.Diagnostics.A_class_member_cannot_be_declared_optional)) || checkForInitializerInAmbientContext(node);
+ }
+ function checkForInitializerInAmbientContext(node) {
+ if (inAmbientContext && node.initializer) {
+ return grammarErrorOnFirstToken(node.initializer, ts.Diagnostics.Initializers_are_not_allowed_in_ambient_contexts);
+ }
+ }
+ function checkPropertyAssignment(node) {
+ return checkForInvalidQuestionMark(node, ts.Diagnostics.An_object_member_cannot_be_declared_optional);
+ }
+ function checkForInvalidQuestionMark(node, message) {
+ if (node.flags & 4 /* QuestionMark */) {
+ var pos = ts.skipTrivia(sourceText, node.name.end);
+ return grammarErrorAtPos(pos, "?".length, message);
+ }
+ }
+ function checkReturnStatement(node) {
+ if (!inFunctionBlock) {
+ return grammarErrorOnFirstToken(node, ts.Diagnostics.A_return_statement_can_only_be_used_within_a_function_body);
+ }
+ }
+ function checkSetAccessor(node) {
+ return checkAnyParsedSignature(node) || checkAccessor(node);
+ }
+ function checkAccessor(accessor) {
+ var kind = accessor.kind;
+ if (languageVersion < 1 /* ES5 */) {
+ return grammarErrorOnNode(accessor.name, ts.Diagnostics.Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher);
+ }
+ else if (inAmbientContext) {
+ return grammarErrorOnNode(accessor.name, ts.Diagnostics.An_accessor_cannot_be_declared_in_an_ambient_context);
+ }
+ else if (accessor.body === undefined) {
+ return grammarErrorAtPos(accessor.end - 1, ";".length, ts.Diagnostics._0_expected, "{");
+ }
+ else if (accessor.typeParameters) {
+ return grammarErrorOnNode(accessor.name, ts.Diagnostics.An_accessor_cannot_have_type_parameters);
+ }
+ else if (kind === 127 /* GetAccessor */ && accessor.parameters.length) {
+ return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_get_accessor_cannot_have_parameters);
+ }
+ else if (kind === 128 /* SetAccessor */) {
+ if (accessor.type) {
+ return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_cannot_have_a_return_type_annotation);
+ }
+ else if (accessor.parameters.length !== 1) {
+ return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_must_have_exactly_one_parameter);
+ }
+ else {
+ var parameter = accessor.parameters[0];
+ if (parameter.flags & 8 /* Rest */) {
+ return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_cannot_have_rest_parameter);
+ }
+ else if (parameter.flags & 243 /* Modifier */) {
+ return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation);
+ }
+ else if (parameter.flags & 4 /* QuestionMark */) {
+ return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_cannot_have_an_optional_parameter);
+ }
+ else if (parameter.initializer) {
+ return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_parameter_cannot_have_an_initializer);
+ }
+ }
+ }
+ }
+ function checkSourceFile(node) {
+ return inAmbientContext && checkTopLevelElementsForRequiredDeclareModifier(file);
+ }
+ function checkTopLevelElementsForRequiredDeclareModifier(file) {
+ for (var i = 0, n = file.statements.length; i < n; i++) {
+ var decl = file.statements[i];
+ if (isDeclaration(decl) || decl.kind === 163 /* VariableStatement */) {
+ if (checkTopLevelElementForRequiredDeclareModifier(decl)) {
+ return true;
+ }
+ }
+ }
+ }
+ function checkTopLevelElementForRequiredDeclareModifier(node) {
+ if (node.kind === 189 /* InterfaceDeclaration */ || node.kind === 194 /* ImportDeclaration */ || node.kind === 195 /* ExportAssignment */ || (node.flags & 2 /* Ambient */)) {
+ return false;
+ }
+ return grammarErrorOnFirstToken(node, ts.Diagnostics.A_declare_modifier_is_required_for_a_top_level_declaration_in_a_d_ts_file);
+ }
+ function checkShorthandPropertyAssignment(node) {
+ return checkForInvalidQuestionMark(node, ts.Diagnostics.An_object_member_cannot_be_declared_optional);
+ }
+ function checkSwitchStatement(node) {
+ var firstDefaultClause;
+ for (var i = 0, n = node.clauses.length; i < n; i++) {
+ var clause = node.clauses[i];
+ if (clause.kind === 177 /* DefaultClause */) {
+ if (firstDefaultClause === undefined) {
+ firstDefaultClause = clause;
+ }
+ else {
+ var start = ts.skipTrivia(file.text, clause.pos);
+ var end = clause.statements.length > 0 ? clause.statements[0].pos : clause.end;
+ return grammarErrorAtPos(start, end - start, ts.Diagnostics.A_default_clause_cannot_appear_more_than_once_in_a_switch_statement);
+ }
+ }
+ }
+ }
+ function checkTaggedTemplateExpression(node) {
+ if (languageVersion < 2 /* ES6 */) {
+ return grammarErrorOnFirstToken(node.template, ts.Diagnostics.Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher);
+ }
+ }
+ function checkTupleType(node) {
+ return checkForDisallowedTrailingComma(node.elementTypes) || checkForAtLeastOneType(node);
+ }
+ function checkForAtLeastOneType(node) {
+ if (node.elementTypes.length === 0) {
+ return grammarErrorOnNode(node, ts.Diagnostics.A_tuple_type_element_list_cannot_be_empty);
+ }
+ }
+ function checkTypeParameter(node) {
+ if (node.expression) {
+ return grammarErrorOnFirstToken(node.expression, ts.Diagnostics.Type_expected);
+ }
+ }
+ function checkTypeReference(node) {
+ return checkTypeArguments(node.typeArguments);
+ }
+ function checkVariableDeclaration(node) {
+ if (inAmbientContext && node.initializer) {
+ var equalsPos = node.type ? ts.skipTrivia(sourceText, node.type.end) : ts.skipTrivia(sourceText, node.name.end);
+ return grammarErrorAtPos(equalsPos, "=".length, ts.Diagnostics.Initializers_are_not_allowed_in_ambient_contexts);
+ }
+ if (!inAmbientContext && !node.initializer && isConst(node)) {
+ return grammarErrorOnNode(node, ts.Diagnostics.const_declarations_must_be_initialized);
+ }
+ if (node.parserContextFlags & 1 /* StrictMode */ && isEvalOrArgumentsIdentifier(node.name)) {
+ return reportInvalidUseInStrictMode(node.name);
+ }
+ }
+ function checkVariableDeclarations(declarations) {
+ if (declarations) {
+ if (checkForDisallowedTrailingComma(declarations)) {
+ return true;
+ }
+ if (!declarations.length) {
+ return grammarErrorAtPos(declarations.pos, declarations.end - declarations.pos, ts.Diagnostics.Variable_declaration_list_cannot_be_empty);
+ }
+ var decl = declarations[0];
+ if (languageVersion < 2 /* ES6 */) {
+ if (isLet(decl)) {
+ return grammarErrorOnFirstToken(decl, ts.Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher);
+ }
+ else if (isConst(decl)) {
+ return grammarErrorOnFirstToken(decl, ts.Diagnostics.const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher);
+ }
+ }
+ }
+ }
+ function checkVariableStatement(node) {
+ return checkVariableDeclarations(node.declarations) || checkForDisallowedLetOrConstStatement(node);
+ }
+ function checkForDisallowedLetOrConstStatement(node) {
+ if (!allowLetAndConstDeclarations(node.parent)) {
+ if (isLet(node)) {
+ return grammarErrorOnNode(node, ts.Diagnostics.let_declarations_can_only_be_declared_inside_a_block);
+ }
+ else if (isConst(node)) {
+ return grammarErrorOnNode(node, ts.Diagnostics.const_declarations_can_only_be_declared_inside_a_block);
+ }
+ }
+ }
+ function allowLetAndConstDeclarations(parent) {
+ switch (parent.kind) {
+ case 166 /* IfStatement */:
+ case 167 /* DoStatement */:
+ case 168 /* WhileStatement */:
+ case 174 /* WithStatement */:
+ case 169 /* ForStatement */:
+ case 170 /* ForInStatement */:
+ return false;
+ case 178 /* LabeledStatement */:
+ return allowLetAndConstDeclarations(parent.parent);
+ }
+ return true;
+ }
+ function checkWithStatement(node) {
+ if (node.parserContextFlags & 1 /* StrictMode */) {
+ return grammarErrorOnFirstToken(node, ts.Diagnostics.with_statements_are_not_allowed_in_strict_mode);
+ }
+ }
+ function checkYieldExpression(node) {
+ if (!(node.parserContextFlags & 4 /* Yield */)) {
+ return grammarErrorOnFirstToken(node, ts.Diagnostics.yield_expression_must_be_contained_within_a_generator_declaration);
+ }
+ return grammarErrorOnFirstToken(node, ts.Diagnostics.yield_expressions_are_not_currently_supported);
+ }
+ }
function createProgram(rootNames, options, host) {
var program;
var files = [];
@@ -5690,17 +6048,20 @@ var ts;
function findSourceFile(filename, isDefaultLib, refFile, refStart, refLength) {
var canonicalName = host.getCanonicalFileName(filename);
if (ts.hasProperty(filesByName, canonicalName)) {
- var file = filesByName[canonicalName];
- if (file && host.useCaseSensitiveFileNames() && canonicalName !== file.filename) {
- errors.push(ts.createFileDiagnostic(refFile, refStart, refLength, ts.Diagnostics.Filename_0_differs_from_already_included_filename_1_only_in_casing, filename, file.filename));
- }
+ return getSourceFileFromCache(filename, canonicalName, false);
}
else {
+ var normalizedAbsolutePath = ts.getNormalizedAbsolutePath(filename, host.getCurrentDirectory());
+ var canonicalAbsolutePath = host.getCanonicalFileName(normalizedAbsolutePath);
+ if (ts.hasProperty(filesByName, canonicalAbsolutePath)) {
+ return getSourceFileFromCache(normalizedAbsolutePath, canonicalAbsolutePath, true);
+ }
var file = filesByName[canonicalName] = host.getSourceFile(filename, options.target, function (hostErrorMessage) {
errors.push(ts.createFileDiagnostic(refFile, refStart, refLength, ts.Diagnostics.Cannot_read_file_0_Colon_1, filename, hostErrorMessage));
});
if (file) {
seenNoDefaultLib = seenNoDefaultLib || file.hasNoDefaultLib;
+ filesByName[canonicalAbsolutePath] = file;
if (!options.noResolve) {
var basePath = ts.getDirectoryPath(filename);
processReferencedFiles(file, basePath);
@@ -5712,12 +6073,22 @@ var ts;
else {
files.push(file);
}
- ts.forEach(file.syntacticErrors, function (e) {
+ ts.forEach(file.getSyntacticDiagnostics(), function (e) {
errors.push(e);
});
}
}
return file;
+ function getSourceFileFromCache(filename, canonicalName, useAbsolutePath) {
+ var file = filesByName[canonicalName];
+ if (file && host.useCaseSensitiveFileNames()) {
+ var sourceFileName = useAbsolutePath ? ts.getNormalizedAbsolutePath(file.filename, host.getCurrentDirectory()) : file.filename;
+ if (canonicalName !== sourceFileName) {
+ errors.push(ts.createFileDiagnostic(refFile, refStart, refLength, ts.Diagnostics.Filename_0_differs_from_already_included_filename_1_only_in_casing, filename, sourceFileName));
+ }
+ }
+ return file;
+ }
}
function processReferencedFiles(file, basePath) {
ts.forEach(file.referencedFiles, function (ref) {
@@ -5727,7 +6098,7 @@ var ts;
}
function processImportedModules(file, basePath) {
ts.forEach(file.statements, function (node) {
- if (node.kind === 193 /* ImportDeclaration */ && node.externalModuleName) {
+ if (node.kind === 194 /* ImportDeclaration */ && node.externalModuleName) {
var nameLiteral = node.externalModuleName;
var moduleName = nameLiteral.text;
if (moduleName) {
@@ -5745,9 +6116,9 @@ var ts;
}
}
}
- else if (node.kind === 191 /* ModuleDeclaration */ && node.name.kind === 7 /* StringLiteral */ && (node.flags & 2 /* Ambient */ || isDeclarationFile(file))) {
+ else if (node.kind === 192 /* ModuleDeclaration */ && node.name.kind === 7 /* StringLiteral */ && (node.flags & 2 /* Ambient */ || isDeclarationFile(file))) {
forEachChild(node.body, function (node) {
- if (node.kind === 193 /* ImportDeclaration */ && node.externalModuleName) {
+ if (node.kind === 194 /* ImportDeclaration */ && node.externalModuleName) {
var nameLiteral = node.externalModuleName;
var moduleName = nameLiteral.text;
if (moduleName) {
@@ -5820,16 +6191,16 @@ var ts;
var ts;
(function (ts) {
function getModuleInstanceState(node) {
- if (node.kind === 188 /* InterfaceDeclaration */) {
+ if (node.kind === 189 /* InterfaceDeclaration */) {
return 0 /* NonInstantiated */;
}
- else if (node.kind === 190 /* EnumDeclaration */ && ts.isConstEnumDeclaration(node)) {
+ else if (ts.isConstEnumDeclaration(node)) {
return 2 /* ConstEnumOnly */;
}
- else if (node.kind === 193 /* ImportDeclaration */ && !(node.flags & 1 /* Export */)) {
+ else if (node.kind === 194 /* ImportDeclaration */ && !(node.flags & 1 /* Export */)) {
return 0 /* NonInstantiated */;
}
- else if (node.kind === 192 /* ModuleBlock */) {
+ else if (node.kind === 193 /* ModuleBlock */) {
var state = 0 /* NonInstantiated */;
ts.forEachChild(node, function (n) {
switch (getModuleInstanceState(n)) {
@@ -5845,7 +6216,7 @@ var ts;
});
return state;
}
- else if (node.kind === 191 /* ModuleDeclaration */) {
+ else if (node.kind === 192 /* ModuleDeclaration */) {
return getModuleInstanceState(node.body);
}
else {
@@ -5885,7 +6256,7 @@ var ts;
}
function getDeclarationName(node) {
if (node.name) {
- if (node.kind === 191 /* ModuleDeclaration */ && node.name.kind === 7 /* StringLiteral */) {
+ if (node.kind === 192 /* ModuleDeclaration */ && node.name.kind === 7 /* StringLiteral */) {
return '"' + node.name.text + '"';
}
return node.name.text;
@@ -5916,9 +6287,9 @@ var ts;
}
var message = symbol.flags & 2 /* BlockScopedVariable */ ? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0 : ts.Diagnostics.Duplicate_identifier_0;
ts.forEach(symbol.declarations, function (declaration) {
- file.semanticErrors.push(ts.createDiagnosticForNode(declaration.name, message, getDisplayName(declaration)));
+ file.semanticDiagnostics.push(ts.createDiagnosticForNode(declaration.name, message, getDisplayName(declaration)));
});
- file.semanticErrors.push(ts.createDiagnosticForNode(node.name, message, getDisplayName(node)));
+ file.semanticDiagnostics.push(ts.createDiagnosticForNode(node.name, message, getDisplayName(node)));
symbol = createSymbol(0, name);
}
}
@@ -5927,13 +6298,13 @@ var ts;
}
addDeclarationToSymbol(symbol, node, includes);
symbol.parent = parent;
- if (node.kind === 187 /* ClassDeclaration */ && symbol.exports) {
+ if (node.kind === 188 /* ClassDeclaration */ && symbol.exports) {
var prototypeSymbol = createSymbol(4 /* Property */ | 536870912 /* Prototype */, "prototype");
if (ts.hasProperty(symbol.exports, prototypeSymbol.name)) {
if (node.name) {
node.name.parent = node;
}
- file.semanticErrors.push(ts.createDiagnosticForNode(symbol.exports[prototypeSymbol.name].declarations[0], ts.Diagnostics.Duplicate_identifier_0, prototypeSymbol.name));
+ file.semanticDiagnostics.push(ts.createDiagnosticForNode(symbol.exports[prototypeSymbol.name].declarations[0], ts.Diagnostics.Duplicate_identifier_0, prototypeSymbol.name));
}
symbol.exports[prototypeSymbol.name] = prototypeSymbol;
prototypeSymbol.parent = symbol;
@@ -5959,7 +6330,7 @@ var ts;
if (symbolKind & 1536 /* Namespace */) {
exportKind |= 16777216 /* ExportNamespace */;
}
- if (node.flags & 1 /* Export */ || (node.kind !== 193 /* ImportDeclaration */ && isAmbientContext(container))) {
+ if (node.flags & 1 /* Export */ || (node.kind !== 194 /* ImportDeclaration */ && isAmbientContext(container))) {
if (exportKind) {
var local = declareSymbol(container.locals, undefined, node, exportKind, symbolExcludes);
local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes);
@@ -6000,10 +6371,10 @@ var ts;
}
function bindDeclaration(node, symbolKind, symbolExcludes, isBlockScopeContainer) {
switch (container.kind) {
- case 191 /* ModuleDeclaration */:
+ case 192 /* ModuleDeclaration */:
declareModuleMember(node, symbolKind, symbolExcludes);
break;
- case 196 /* SourceFile */:
+ case 197 /* SourceFile */:
if (ts.isExternalModule(container)) {
declareModuleMember(node, symbolKind, symbolExcludes);
break;
@@ -6017,22 +6388,22 @@ var ts;
case 126 /* Constructor */:
case 127 /* GetAccessor */:
case 128 /* SetAccessor */:
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
case 152 /* FunctionExpression */:
case 153 /* ArrowFunction */:
declareSymbol(container.locals, undefined, node, symbolKind, symbolExcludes);
break;
- case 187 /* ClassDeclaration */:
+ case 188 /* ClassDeclaration */:
if (node.flags & 128 /* Static */) {
declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes);
break;
}
case 136 /* TypeLiteral */:
case 142 /* ObjectLiteral */:
- case 188 /* InterfaceDeclaration */:
+ case 189 /* InterfaceDeclaration */:
declareSymbol(container.symbol.members, container.symbol, node, symbolKind, symbolExcludes);
break;
- case 190 /* EnumDeclaration */:
+ case 191 /* EnumDeclaration */:
declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes);
break;
}
@@ -6093,10 +6464,10 @@ var ts;
}
function bindBlockScopedVariableDeclaration(node) {
switch (blockScopeContainer.kind) {
- case 191 /* ModuleDeclaration */:
+ case 192 /* ModuleDeclaration */:
declareModuleMember(node, 2 /* BlockScopedVariable */, 107455 /* BlockScopedVariableExcludes */);
break;
- case 196 /* SourceFile */:
+ case 197 /* SourceFile */:
if (ts.isExternalModule(container)) {
declareModuleMember(node, 2 /* BlockScopedVariable */, 107455 /* BlockScopedVariableExcludes */);
break;
@@ -6118,7 +6489,7 @@ var ts;
case 123 /* Parameter */:
bindDeclaration(node, 1 /* FunctionScopedVariable */, 107455 /* ParameterExcludes */, false);
break;
- case 184 /* VariableDeclaration */:
+ case 185 /* VariableDeclaration */:
if (node.flags & 6144 /* BlockScoped */) {
bindBlockScopedVariableDeclaration(node);
}
@@ -6131,7 +6502,7 @@ var ts;
case 144 /* ShorthandPropertyAssignment */:
bindDeclaration(node, 4 /* Property */, 107455 /* PropertyExcludes */, false);
break;
- case 195 /* EnumMember */:
+ case 196 /* EnumMember */:
bindDeclaration(node, 8 /* EnumMember */, 107455 /* EnumMemberExcludes */, false);
break;
case 129 /* CallSignature */:
@@ -6146,7 +6517,7 @@ var ts;
case 131 /* IndexSignature */:
bindDeclaration(node, 524288 /* IndexSignature */, 0, false);
break;
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
bindDeclaration(node, 16 /* Function */, 106927 /* FunctionExcludes */, true);
break;
case 126 /* Constructor */:
@@ -6172,44 +6543,44 @@ var ts;
case 153 /* ArrowFunction */:
bindAnonymousDeclaration(node, 16 /* Function */, "__function", true);
break;
- case 181 /* CatchBlock */:
+ case 182 /* CatchBlock */:
bindCatchVariableDeclaration(node);
break;
- case 187 /* ClassDeclaration */:
+ case 188 /* ClassDeclaration */:
bindDeclaration(node, 32 /* Class */, 3258879 /* ClassExcludes */, false);
break;
- case 188 /* InterfaceDeclaration */:
+ case 189 /* InterfaceDeclaration */:
bindDeclaration(node, 64 /* Interface */, 3152288 /* InterfaceExcludes */, false);
break;
- case 189 /* TypeAliasDeclaration */:
+ case 190 /* TypeAliasDeclaration */:
bindDeclaration(node, 2097152 /* TypeAlias */, 3152352 /* TypeAliasExcludes */, false);
break;
- case 190 /* EnumDeclaration */:
- if (ts.isConstEnumDeclaration(node)) {
+ case 191 /* EnumDeclaration */:
+ if (ts.isConst(node)) {
bindDeclaration(node, 128 /* ConstEnum */, 3259263 /* ConstEnumExcludes */, false);
}
else {
bindDeclaration(node, 256 /* RegularEnum */, 3258623 /* RegularEnumExcludes */, false);
}
break;
- case 191 /* ModuleDeclaration */:
+ case 192 /* ModuleDeclaration */:
bindModuleDeclaration(node);
break;
- case 193 /* ImportDeclaration */:
+ case 194 /* ImportDeclaration */:
bindDeclaration(node, 33554432 /* Import */, 33554432 /* ImportExcludes */, false);
break;
- case 196 /* SourceFile */:
+ case 197 /* SourceFile */:
if (ts.isExternalModule(node)) {
bindAnonymousDeclaration(node, 512 /* ValueModule */, '"' + ts.removeFileExtension(node.filename) + '"', true);
break;
}
- case 161 /* Block */:
- case 180 /* TryBlock */:
- case 181 /* CatchBlock */:
- case 182 /* FinallyBlock */:
- case 168 /* ForStatement */:
- case 169 /* ForInStatement */:
- case 174 /* SwitchStatement */:
+ case 162 /* Block */:
+ case 181 /* TryBlock */:
+ case 182 /* CatchBlock */:
+ case 183 /* FinallyBlock */:
+ case 169 /* ForStatement */:
+ case 170 /* ForInStatement */:
+ case 175 /* SwitchStatement */:
bindChildren(node, 0, true);
break;
default:
@@ -6249,6 +6620,1057 @@ var ts;
return ts.isExternalModule(sourceFile) || ts.isDeclarationFile(sourceFile);
}
ts.isExternalModuleOrDeclarationFile = isExternalModuleOrDeclarationFile;
+ function createTextWriter(newLine) {
+ var output = "";
+ var indent = 0;
+ var lineStart = true;
+ var lineCount = 0;
+ var linePos = 0;
+ function write(s) {
+ if (s && s.length) {
+ if (lineStart) {
+ output += getIndentString(indent);
+ lineStart = false;
+ }
+ output += s;
+ }
+ }
+ function rawWrite(s) {
+ if (s !== undefined) {
+ if (lineStart) {
+ lineStart = false;
+ }
+ output += s;
+ }
+ }
+ function writeLiteral(s) {
+ if (s && s.length) {
+ write(s);
+ var lineStartsOfS = ts.computeLineStarts(s);
+ if (lineStartsOfS.length > 1) {
+ lineCount = lineCount + lineStartsOfS.length - 1;
+ linePos = output.length - s.length + lineStartsOfS[lineStartsOfS.length - 1];
+ }
+ }
+ }
+ function writeLine() {
+ if (!lineStart) {
+ output += newLine;
+ lineCount++;
+ linePos = output.length;
+ lineStart = true;
+ }
+ }
+ function writeTextOfNode(sourceFile, node) {
+ write(ts.getSourceTextOfNodeFromSourceFile(sourceFile, node));
+ }
+ return {
+ write: write,
+ rawWrite: rawWrite,
+ writeTextOfNode: writeTextOfNode,
+ writeLiteral: writeLiteral,
+ writeLine: writeLine,
+ increaseIndent: function () { return indent++; },
+ decreaseIndent: function () { return indent--; },
+ getIndent: function () { return indent; },
+ getTextPos: function () { return output.length; },
+ getLine: function () { return lineCount + 1; },
+ getColumn: function () { return lineStart ? indent * getIndentSize() + 1 : output.length - linePos + 1; },
+ getText: function () { return output; }
+ };
+ }
+ function getLineOfLocalPosition(currentSourceFile, pos) {
+ return currentSourceFile.getLineAndCharacterFromPosition(pos).line;
+ }
+ function emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments) {
+ if (leadingComments && leadingComments.length && node.pos !== leadingComments[0].pos && getLineOfLocalPosition(currentSourceFile, node.pos) !== getLineOfLocalPosition(currentSourceFile, leadingComments[0].pos)) {
+ writer.writeLine();
+ }
+ }
+ function emitComments(currentSourceFile, writer, comments, trailingSeparator, newLine, writeComment) {
+ var emitLeadingSpace = !trailingSeparator;
+ ts.forEach(comments, function (comment) {
+ if (emitLeadingSpace) {
+ writer.write(" ");
+ emitLeadingSpace = false;
+ }
+ writeComment(currentSourceFile, writer, comment, newLine);
+ if (comment.hasTrailingNewLine) {
+ writer.writeLine();
+ }
+ else if (trailingSeparator) {
+ writer.write(" ");
+ }
+ else {
+ emitLeadingSpace = true;
+ }
+ });
+ }
+ function writeCommentRange(currentSourceFile, writer, comment, newLine) {
+ if (currentSourceFile.text.charCodeAt(comment.pos + 1) === 42 /* asterisk */) {
+ var firstCommentLineAndCharacter = currentSourceFile.getLineAndCharacterFromPosition(comment.pos);
+ var firstCommentLineIndent;
+ for (var pos = comment.pos, currentLine = firstCommentLineAndCharacter.line; pos < comment.end; currentLine++) {
+ var nextLineStart = currentSourceFile.getPositionFromLineAndCharacter(currentLine + 1, 1);
+ if (pos !== comment.pos) {
+ if (firstCommentLineIndent === undefined) {
+ firstCommentLineIndent = calculateIndent(currentSourceFile.getPositionFromLineAndCharacter(firstCommentLineAndCharacter.line, 1), comment.pos);
+ }
+ var currentWriterIndentSpacing = writer.getIndent() * getIndentSize();
+ var spacesToEmit = currentWriterIndentSpacing - firstCommentLineIndent + calculateIndent(pos, nextLineStart);
+ if (spacesToEmit > 0) {
+ var numberOfSingleSpacesToEmit = spacesToEmit % getIndentSize();
+ var indentSizeSpaceString = getIndentString((spacesToEmit - numberOfSingleSpacesToEmit) / getIndentSize());
+ writer.rawWrite(indentSizeSpaceString);
+ while (numberOfSingleSpacesToEmit) {
+ writer.rawWrite(" ");
+ numberOfSingleSpacesToEmit--;
+ }
+ }
+ else {
+ writer.rawWrite("");
+ }
+ }
+ writeTrimmedCurrentLine(pos, nextLineStart);
+ pos = nextLineStart;
+ }
+ }
+ else {
+ writer.write(currentSourceFile.text.substring(comment.pos, comment.end));
+ }
+ function writeTrimmedCurrentLine(pos, nextLineStart) {
+ var end = Math.min(comment.end, nextLineStart - 1);
+ var currentLineText = currentSourceFile.text.substring(pos, end).replace(/^\s+|\s+$/g, '');
+ if (currentLineText) {
+ writer.write(currentLineText);
+ if (end !== comment.end) {
+ writer.writeLine();
+ }
+ }
+ else {
+ writer.writeLiteral(newLine);
+ }
+ }
+ function calculateIndent(pos, end) {
+ var currentLineIndent = 0;
+ for (; pos < end && ts.isWhiteSpace(currentSourceFile.text.charCodeAt(pos)); pos++) {
+ if (currentSourceFile.text.charCodeAt(pos) === 9 /* tab */) {
+ currentLineIndent += getIndentSize() - (currentLineIndent % getIndentSize());
+ }
+ else {
+ currentLineIndent++;
+ }
+ }
+ return currentLineIndent;
+ }
+ }
+ function getFirstConstructorWithBody(node) {
+ return ts.forEach(node.members, function (member) {
+ if (member.kind === 126 /* Constructor */ && member.body) {
+ return member;
+ }
+ });
+ }
+ function getAllAccessorDeclarations(node, accessor) {
+ var firstAccessor;
+ var getAccessor;
+ var setAccessor;
+ ts.forEach(node.members, function (member) {
+ if ((member.kind === 127 /* GetAccessor */ || member.kind === 128 /* SetAccessor */) && member.name.text === accessor.name.text && (member.flags & 128 /* Static */) === (accessor.flags & 128 /* Static */)) {
+ if (!firstAccessor) {
+ firstAccessor = member;
+ }
+ if (member.kind === 127 /* GetAccessor */ && !getAccessor) {
+ getAccessor = member;
+ }
+ if (member.kind === 128 /* SetAccessor */ && !setAccessor) {
+ setAccessor = member;
+ }
+ }
+ });
+ return {
+ firstAccessor: firstAccessor,
+ getAccessor: getAccessor,
+ setAccessor: setAccessor
+ };
+ }
+ function getSourceFilePathInNewDir(sourceFile, program, newDirPath) {
+ var compilerHost = program.getCompilerHost();
+ var sourceFilePath = ts.getNormalizedAbsolutePath(sourceFile.filename, compilerHost.getCurrentDirectory());
+ sourceFilePath = sourceFilePath.replace(program.getCommonSourceDirectory(), "");
+ return ts.combinePaths(newDirPath, sourceFilePath);
+ }
+ function getOwnEmitOutputFilePath(sourceFile, program, extension) {
+ var compilerOptions = program.getCompilerOptions();
+ if (compilerOptions.outDir) {
+ var emitOutputFilePathWithoutExtension = ts.removeFileExtension(getSourceFilePathInNewDir(sourceFile, program, compilerOptions.outDir));
+ }
+ else {
+ var emitOutputFilePathWithoutExtension = ts.removeFileExtension(sourceFile.filename);
+ }
+ return emitOutputFilePathWithoutExtension + extension;
+ }
+ function writeFile(compilerHost, diagnostics, filename, data, writeByteOrderMark) {
+ compilerHost.writeFile(filename, data, writeByteOrderMark, function (hostErrorMessage) {
+ diagnostics.push(ts.createCompilerDiagnostic(ts.Diagnostics.Could_not_write_file_0_Colon_1, filename, hostErrorMessage));
+ });
+ }
+ function emitDeclarations(program, resolver, diagnostics, jsFilePath, root) {
+ var newLine = program.getCompilerHost().getNewLine();
+ var compilerOptions = program.getCompilerOptions();
+ var compilerHost = program.getCompilerHost();
+ var write;
+ var writeLine;
+ var increaseIndent;
+ var decreaseIndent;
+ var writeTextOfNode;
+ var writer = createAndSetNewTextWriterWithSymbolWriter();
+ var enclosingDeclaration;
+ var currentSourceFile;
+ var reportedDeclarationError = false;
+ var emitJsDocComments = compilerOptions.removeComments ? function (declaration) {
+ } : writeJsDocComments;
+ var aliasDeclarationEmitInfo = [];
+ function createAndSetNewTextWriterWithSymbolWriter() {
+ var writer = createTextWriter(newLine);
+ writer.trackSymbol = trackSymbol;
+ writer.writeKeyword = writer.write;
+ writer.writeOperator = writer.write;
+ writer.writePunctuation = writer.write;
+ writer.writeSpace = writer.write;
+ writer.writeStringLiteral = writer.writeLiteral;
+ writer.writeParameter = writer.write;
+ writer.writeSymbol = writer.write;
+ setWriter(writer);
+ return writer;
+ }
+ function setWriter(newWriter) {
+ writer = newWriter;
+ write = newWriter.write;
+ writeTextOfNode = newWriter.writeTextOfNode;
+ writeLine = newWriter.writeLine;
+ increaseIndent = newWriter.increaseIndent;
+ decreaseIndent = newWriter.decreaseIndent;
+ }
+ function writeAsychronousImportDeclarations(importDeclarations) {
+ var oldWriter = writer;
+ ts.forEach(importDeclarations, function (aliasToWrite) {
+ var aliasEmitInfo = ts.forEach(aliasDeclarationEmitInfo, function (declEmitInfo) { return declEmitInfo.declaration === aliasToWrite ? declEmitInfo : undefined; });
+ if (aliasEmitInfo) {
+ createAndSetNewTextWriterWithSymbolWriter();
+ for (var declarationIndent = aliasEmitInfo.indent; declarationIndent; declarationIndent--) {
+ increaseIndent();
+ }
+ writeImportDeclaration(aliasToWrite);
+ aliasEmitInfo.asynchronousOutput = writer.getText();
+ }
+ });
+ setWriter(oldWriter);
+ }
+ function handleSymbolAccessibilityError(symbolAccesibilityResult) {
+ if (symbolAccesibilityResult.accessibility === 0 /* Accessible */) {
+ if (symbolAccesibilityResult && symbolAccesibilityResult.aliasesToMakeVisible) {
+ writeAsychronousImportDeclarations(symbolAccesibilityResult.aliasesToMakeVisible);
+ }
+ }
+ else {
+ reportedDeclarationError = true;
+ var errorInfo = writer.getSymbolAccessibilityDiagnostic(symbolAccesibilityResult);
+ if (errorInfo) {
+ if (errorInfo.typeName) {
+ diagnostics.push(ts.createDiagnosticForNode(symbolAccesibilityResult.errorNode || errorInfo.errorNode, errorInfo.diagnosticMessage, ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, errorInfo.typeName), symbolAccesibilityResult.errorSymbolName, symbolAccesibilityResult.errorModuleName));
+ }
+ else {
+ diagnostics.push(ts.createDiagnosticForNode(symbolAccesibilityResult.errorNode || errorInfo.errorNode, errorInfo.diagnosticMessage, symbolAccesibilityResult.errorSymbolName, symbolAccesibilityResult.errorModuleName));
+ }
+ }
+ }
+ }
+ function trackSymbol(symbol, enclosingDeclaration, meaning) {
+ handleSymbolAccessibilityError(resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning));
+ }
+ function writeTypeAtLocation(location, type, getSymbolAccessibilityDiagnostic) {
+ writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic;
+ write(": ");
+ if (type) {
+ emitType(type);
+ }
+ else {
+ resolver.writeTypeAtLocation(location, enclosingDeclaration, 2 /* UseTypeOfFunction */, writer);
+ }
+ }
+ function writeReturnTypeAtSignature(signature, getSymbolAccessibilityDiagnostic) {
+ writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic;
+ write(": ");
+ if (signature.type) {
+ emitType(signature.type);
+ }
+ else {
+ resolver.writeReturnTypeOfSignatureDeclaration(signature, enclosingDeclaration, 2 /* UseTypeOfFunction */, writer);
+ }
+ }
+ function emitLines(nodes) {
+ for (var i = 0, n = nodes.length; i < n; i++) {
+ emitNode(nodes[i]);
+ }
+ }
+ function emitSeparatedList(nodes, separator, eachNodeEmitFn) {
+ var currentWriterPos = writer.getTextPos();
+ for (var i = 0, n = nodes.length; i < n; i++) {
+ if (currentWriterPos !== writer.getTextPos()) {
+ write(separator);
+ }
+ currentWriterPos = writer.getTextPos();
+ eachNodeEmitFn(nodes[i]);
+ }
+ }
+ function emitCommaList(nodes, eachNodeEmitFn) {
+ emitSeparatedList(nodes, ", ", eachNodeEmitFn);
+ }
+ function writeJsDocComments(declaration) {
+ if (declaration) {
+ var jsDocComments = ts.getJsDocComments(declaration, currentSourceFile);
+ emitNewLineBeforeLeadingComments(currentSourceFile, writer, declaration, jsDocComments);
+ emitComments(currentSourceFile, writer, jsDocComments, true, newLine, writeCommentRange);
+ }
+ }
+ function emitTypeWithNewGetSymbolAccessibilityDiangostic(type, getSymbolAccessibilityDiagnostic) {
+ writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic;
+ emitType(type);
+ }
+ function emitType(type) {
+ switch (type.kind) {
+ case 109 /* AnyKeyword */:
+ case 118 /* StringKeyword */:
+ case 116 /* NumberKeyword */:
+ case 110 /* BooleanKeyword */:
+ case 97 /* VoidKeyword */:
+ case 7 /* StringLiteral */:
+ return writeTextOfNode(currentSourceFile, type);
+ case 132 /* TypeReference */:
+ return emitTypeReference(type);
+ case 135 /* TypeQuery */:
+ return emitTypeQuery(type);
+ case 137 /* ArrayType */:
+ return emitArrayType(type);
+ case 138 /* TupleType */:
+ return emitTupleType(type);
+ case 139 /* UnionType */:
+ return emitUnionType(type);
+ case 140 /* ParenType */:
+ return emitParenType(type);
+ case 133 /* FunctionType */:
+ case 134 /* ConstructorType */:
+ return emitSignatureDeclarationWithJsDocComments(type);
+ case 136 /* TypeLiteral */:
+ return emitTypeLiteral(type);
+ case 63 /* Identifier */:
+ return emitEntityName(type);
+ case 121 /* QualifiedName */:
+ return emitEntityName(type);
+ default:
+ ts.Debug.fail("Unknown type annotation: " + type.kind);
+ }
+ function emitEntityName(entityName) {
+ var visibilityResult = resolver.isEntityNameVisible(entityName, entityName.parent.kind === 194 /* ImportDeclaration */ ? entityName.parent : enclosingDeclaration);
+ handleSymbolAccessibilityError(visibilityResult);
+ writeEntityName(entityName);
+ function writeEntityName(entityName) {
+ if (entityName.kind === 63 /* Identifier */) {
+ writeTextOfNode(currentSourceFile, entityName);
+ }
+ else {
+ var qualifiedName = entityName;
+ writeEntityName(qualifiedName.left);
+ write(".");
+ writeTextOfNode(currentSourceFile, qualifiedName.right);
+ }
+ }
+ }
+ function emitTypeReference(type) {
+ emitEntityName(type.typeName);
+ if (type.typeArguments) {
+ write("<");
+ emitCommaList(type.typeArguments, emitType);
+ write(">");
+ }
+ }
+ function emitTypeQuery(type) {
+ write("typeof ");
+ emitEntityName(type.exprName);
+ }
+ function emitArrayType(type) {
+ emitType(type.elementType);
+ write("[]");
+ }
+ function emitTupleType(type) {
+ write("[");
+ emitCommaList(type.elementTypes, emitType);
+ write("]");
+ }
+ function emitUnionType(type) {
+ emitSeparatedList(type.types, " | ", emitType);
+ }
+ function emitParenType(type) {
+ write("(");
+ emitType(type.type);
+ write(")");
+ }
+ function emitTypeLiteral(type) {
+ write("{");
+ if (type.members.length) {
+ writeLine();
+ increaseIndent();
+ emitLines(type.members);
+ decreaseIndent();
+ }
+ write("}");
+ }
+ }
+ function emitSourceFile(node) {
+ currentSourceFile = node;
+ enclosingDeclaration = node;
+ emitLines(node.statements);
+ }
+ function emitExportAssignment(node) {
+ write("export = ");
+ writeTextOfNode(currentSourceFile, node.exportName);
+ write(";");
+ writeLine();
+ }
+ function emitModuleElementDeclarationFlags(node) {
+ if (node.parent === currentSourceFile) {
+ if (node.flags & 1 /* Export */) {
+ write("export ");
+ }
+ if (node.kind !== 189 /* InterfaceDeclaration */) {
+ write("declare ");
+ }
+ }
+ }
+ function emitClassMemberDeclarationFlags(node) {
+ if (node.flags & 32 /* Private */) {
+ write("private ");
+ }
+ else if (node.flags & 64 /* Protected */) {
+ write("protected ");
+ }
+ if (node.flags & 128 /* Static */) {
+ write("static ");
+ }
+ }
+ function emitImportDeclaration(node) {
+ var nodeEmitInfo = {
+ declaration: node,
+ outputPos: writer.getTextPos(),
+ indent: writer.getIndent(),
+ hasWritten: resolver.isDeclarationVisible(node)
+ };
+ aliasDeclarationEmitInfo.push(nodeEmitInfo);
+ if (nodeEmitInfo.hasWritten) {
+ writeImportDeclaration(node);
+ }
+ }
+ function writeImportDeclaration(node) {
+ emitJsDocComments(node);
+ if (node.flags & 1 /* Export */) {
+ write("export ");
+ }
+ write("import ");
+ writeTextOfNode(currentSourceFile, node.name);
+ write(" = ");
+ if (node.entityName) {
+ emitTypeWithNewGetSymbolAccessibilityDiangostic(node.entityName, getImportEntityNameVisibilityError);
+ write(";");
+ }
+ else {
+ write("require(");
+ writeTextOfNode(currentSourceFile, node.externalModuleName);
+ write(");");
+ }
+ writer.writeLine();
+ function getImportEntityNameVisibilityError(symbolAccesibilityResult) {
+ return {
+ diagnosticMessage: ts.Diagnostics.Import_declaration_0_is_using_private_name_1,
+ errorNode: node,
+ typeName: node.name
+ };
+ }
+ }
+ function emitModuleDeclaration(node) {
+ if (resolver.isDeclarationVisible(node)) {
+ emitJsDocComments(node);
+ emitModuleElementDeclarationFlags(node);
+ write("module ");
+ writeTextOfNode(currentSourceFile, node.name);
+ while (node.body.kind !== 193 /* ModuleBlock */) {
+ node = node.body;
+ write(".");
+ writeTextOfNode(currentSourceFile, node.name);
+ }
+ var prevEnclosingDeclaration = enclosingDeclaration;
+ enclosingDeclaration = node;
+ write(" {");
+ writeLine();
+ increaseIndent();
+ emitLines(node.body.statements);
+ decreaseIndent();
+ write("}");
+ writeLine();
+ enclosingDeclaration = prevEnclosingDeclaration;
+ }
+ }
+ function emitTypeAliasDeclaration(node) {
+ if (resolver.isDeclarationVisible(node)) {
+ emitJsDocComments(node);
+ emitModuleElementDeclarationFlags(node);
+ write("type ");
+ writeTextOfNode(currentSourceFile, node.name);
+ write(" = ");
+ emitTypeWithNewGetSymbolAccessibilityDiangostic(node.type, getTypeAliasDeclarationVisibilityError);
+ write(";");
+ writeLine();
+ }
+ function getTypeAliasDeclarationVisibilityError(symbolAccesibilityResult) {
+ return {
+ diagnosticMessage: ts.Diagnostics.Exported_type_alias_0_has_or_is_using_private_name_1,
+ errorNode: node.type,
+ typeName: node.name
+ };
+ }
+ }
+ function emitEnumDeclaration(node) {
+ if (resolver.isDeclarationVisible(node)) {
+ emitJsDocComments(node);
+ emitModuleElementDeclarationFlags(node);
+ if (ts.isConst(node)) {
+ write("const ");
+ }
+ write("enum ");
+ writeTextOfNode(currentSourceFile, node.name);
+ write(" {");
+ writeLine();
+ increaseIndent();
+ emitLines(node.members);
+ decreaseIndent();
+ write("}");
+ writeLine();
+ }
+ }
+ function emitEnumMemberDeclaration(node) {
+ emitJsDocComments(node);
+ writeTextOfNode(currentSourceFile, node.name);
+ var enumMemberValue = resolver.getEnumMemberValue(node);
+ if (enumMemberValue !== undefined) {
+ write(" = ");
+ write(enumMemberValue.toString());
+ }
+ write(",");
+ writeLine();
+ }
+ function emitTypeParameters(typeParameters) {
+ function emitTypeParameter(node) {
+ increaseIndent();
+ emitJsDocComments(node);
+ decreaseIndent();
+ writeTextOfNode(currentSourceFile, node.name);
+ if (node.constraint && (node.parent.kind !== 125 /* Method */ || !(node.parent.flags & 32 /* Private */))) {
+ write(" extends ");
+ if (node.parent.kind === 133 /* FunctionType */ || node.parent.kind === 134 /* ConstructorType */ || (node.parent.parent && node.parent.parent.kind === 136 /* TypeLiteral */)) {
+ ts.Debug.assert(node.parent.kind === 125 /* Method */ || node.parent.kind === 133 /* FunctionType */ || node.parent.kind === 134 /* ConstructorType */ || node.parent.kind === 129 /* CallSignature */ || node.parent.kind === 130 /* ConstructSignature */);
+ emitType(node.constraint);
+ }
+ else {
+ emitTypeWithNewGetSymbolAccessibilityDiangostic(node.constraint, getTypeParameterConstraintVisibilityError);
+ }
+ }
+ function getTypeParameterConstraintVisibilityError(symbolAccesibilityResult) {
+ var diagnosticMessage;
+ switch (node.parent.kind) {
+ case 188 /* ClassDeclaration */:
+ diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_class_has_or_is_using_private_name_1;
+ break;
+ case 189 /* InterfaceDeclaration */:
+ diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1;
+ break;
+ case 130 /* ConstructSignature */:
+ diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1;
+ break;
+ case 129 /* CallSignature */:
+ diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1;
+ break;
+ case 125 /* Method */:
+ if (node.parent.flags & 128 /* Static */) {
+ diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1;
+ }
+ else if (node.parent.parent.kind === 188 /* ClassDeclaration */) {
+ diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1;
+ }
+ else {
+ diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1;
+ }
+ break;
+ case 186 /* FunctionDeclaration */:
+ diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_private_name_1;
+ break;
+ default:
+ ts.Debug.fail("This is unknown parent for type parameter: " + node.parent.kind);
+ }
+ return {
+ diagnosticMessage: diagnosticMessage,
+ errorNode: node,
+ typeName: node.name
+ };
+ }
+ }
+ if (typeParameters) {
+ write("<");
+ emitCommaList(typeParameters, emitTypeParameter);
+ write(">");
+ }
+ }
+ function emitHeritageClause(typeReferences, isImplementsList) {
+ if (typeReferences) {
+ write(isImplementsList ? " implements " : " extends ");
+ emitCommaList(typeReferences, emitTypeOfTypeReference);
+ }
+ function emitTypeOfTypeReference(node) {
+ emitTypeWithNewGetSymbolAccessibilityDiangostic(node, getHeritageClauseVisibilityError);
+ function getHeritageClauseVisibilityError(symbolAccesibilityResult) {
+ var diagnosticMessage;
+ if (node.parent.kind === 188 /* ClassDeclaration */) {
+ diagnosticMessage = isImplementsList ? ts.Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_private_name_1 : ts.Diagnostics.Extends_clause_of_exported_class_0_has_or_is_using_private_name_1;
+ }
+ else {
+ diagnosticMessage = ts.Diagnostics.Extends_clause_of_exported_interface_0_has_or_is_using_private_name_1;
+ }
+ return {
+ diagnosticMessage: diagnosticMessage,
+ errorNode: node,
+ typeName: node.parent.name
+ };
+ }
+ }
+ }
+ function emitClassDeclaration(node) {
+ function emitParameterProperties(constructorDeclaration) {
+ if (constructorDeclaration) {
+ ts.forEach(constructorDeclaration.parameters, function (param) {
+ if (param.flags & 112 /* AccessibilityModifier */) {
+ emitPropertyDeclaration(param);
+ }
+ });
+ }
+ }
+ if (resolver.isDeclarationVisible(node)) {
+ emitJsDocComments(node);
+ emitModuleElementDeclarationFlags(node);
+ write("class ");
+ writeTextOfNode(currentSourceFile, node.name);
+ var prevEnclosingDeclaration = enclosingDeclaration;
+ enclosingDeclaration = node;
+ emitTypeParameters(node.typeParameters);
+ if (node.baseType) {
+ emitHeritageClause([node.baseType], false);
+ }
+ emitHeritageClause(node.implementedTypes, true);
+ write(" {");
+ writeLine();
+ increaseIndent();
+ emitParameterProperties(getFirstConstructorWithBody(node));
+ emitLines(node.members);
+ decreaseIndent();
+ write("}");
+ writeLine();
+ enclosingDeclaration = prevEnclosingDeclaration;
+ }
+ }
+ function emitInterfaceDeclaration(node) {
+ if (resolver.isDeclarationVisible(node)) {
+ emitJsDocComments(node);
+ emitModuleElementDeclarationFlags(node);
+ write("interface ");
+ writeTextOfNode(currentSourceFile, node.name);
+ var prevEnclosingDeclaration = enclosingDeclaration;
+ enclosingDeclaration = node;
+ emitTypeParameters(node.typeParameters);
+ emitHeritageClause(node.baseTypes, false);
+ write(" {");
+ writeLine();
+ increaseIndent();
+ emitLines(node.members);
+ decreaseIndent();
+ write("}");
+ writeLine();
+ enclosingDeclaration = prevEnclosingDeclaration;
+ }
+ }
+ function emitPropertyDeclaration(node) {
+ emitJsDocComments(node);
+ emitClassMemberDeclarationFlags(node);
+ emitVariableDeclaration(node);
+ write(";");
+ writeLine();
+ }
+ function emitVariableDeclaration(node) {
+ if (node.kind !== 185 /* VariableDeclaration */ || resolver.isDeclarationVisible(node)) {
+ writeTextOfNode(currentSourceFile, node.name);
+ if (node.kind === 124 /* Property */ && (node.flags & 4 /* QuestionMark */)) {
+ write("?");
+ }
+ if (node.kind === 124 /* Property */ && node.parent.kind === 136 /* TypeLiteral */) {
+ emitTypeOfVariableDeclarationFromTypeLiteral(node);
+ }
+ else if (!(node.flags & 32 /* Private */)) {
+ writeTypeAtLocation(node, node.type, getVariableDeclarationTypeVisibilityError);
+ }
+ }
+ function getVariableDeclarationTypeVisibilityError(symbolAccesibilityResult) {
+ var diagnosticMessage;
+ if (node.kind === 185 /* VariableDeclaration */) {
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Exported_variable_0_has_or_is_using_private_name_1;
+ }
+ else if (node.kind === 124 /* Property */) {
+ if (node.flags & 128 /* Static */) {
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_private_name_1;
+ }
+ else if (node.parent.kind === 188 /* ClassDeclaration */) {
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_private_name_1;
+ }
+ else {
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Property_0_of_exported_interface_has_or_is_using_private_name_1;
+ }
+ }
+ return diagnosticMessage !== undefined ? {
+ diagnosticMessage: diagnosticMessage,
+ errorNode: node,
+ typeName: node.name
+ } : undefined;
+ }
+ }
+ function emitTypeOfVariableDeclarationFromTypeLiteral(node) {
+ if (node.type) {
+ write(": ");
+ emitType(node.type);
+ }
+ }
+ function emitVariableStatement(node) {
+ var hasDeclarationWithEmit = ts.forEach(node.declarations, function (varDeclaration) { return resolver.isDeclarationVisible(varDeclaration); });
+ if (hasDeclarationWithEmit) {
+ emitJsDocComments(node);
+ emitModuleElementDeclarationFlags(node);
+ if (ts.isLet(node)) {
+ write("let ");
+ }
+ else if (ts.isConst(node)) {
+ write("const ");
+ }
+ else {
+ write("var ");
+ }
+ emitCommaList(node.declarations, emitVariableDeclaration);
+ write(";");
+ writeLine();
+ }
+ }
+ function emitAccessorDeclaration(node) {
+ var accessors = getAllAccessorDeclarations(node.parent, node);
+ if (node === accessors.firstAccessor) {
+ emitJsDocComments(accessors.getAccessor);
+ emitJsDocComments(accessors.setAccessor);
+ emitClassMemberDeclarationFlags(node);
+ writeTextOfNode(currentSourceFile, node.name);
+ if (!(node.flags & 32 /* Private */)) {
+ var accessorWithTypeAnnotation = node;
+ var type = getTypeAnnotationFromAccessor(node);
+ if (!type) {
+ var anotherAccessor = node.kind === 127 /* GetAccessor */ ? accessors.setAccessor : accessors.getAccessor;
+ type = getTypeAnnotationFromAccessor(anotherAccessor);
+ if (type) {
+ accessorWithTypeAnnotation = anotherAccessor;
+ }
+ }
+ writeTypeAtLocation(node, type, getAccessorDeclarationTypeVisibilityError);
+ }
+ write(";");
+ writeLine();
+ }
+ function getTypeAnnotationFromAccessor(accessor) {
+ if (accessor) {
+ return accessor.kind === 127 /* GetAccessor */ ? accessor.type : accessor.parameters[0].type;
+ }
+ }
+ function getAccessorDeclarationTypeVisibilityError(symbolAccesibilityResult) {
+ var diagnosticMessage;
+ if (accessorWithTypeAnnotation.kind === 128 /* SetAccessor */) {
+ if (accessorWithTypeAnnotation.parent.flags & 128 /* Static */) {
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_private_name_1;
+ }
+ else {
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_private_name_1;
+ }
+ return {
+ diagnosticMessage: diagnosticMessage,
+ errorNode: accessorWithTypeAnnotation.parameters[0],
+ typeName: accessorWithTypeAnnotation.name
+ };
+ }
+ else {
+ if (accessorWithTypeAnnotation.flags & 128 /* Static */) {
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_private_name_0;
+ }
+ else {
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_private_name_0;
+ }
+ return {
+ diagnosticMessage: diagnosticMessage,
+ errorNode: accessorWithTypeAnnotation.name,
+ typeName: undefined
+ };
+ }
+ }
+ }
+ function emitFunctionDeclaration(node) {
+ if ((node.kind !== 186 /* FunctionDeclaration */ || resolver.isDeclarationVisible(node)) && !resolver.isImplementationOfOverload(node)) {
+ emitJsDocComments(node);
+ if (node.kind === 186 /* FunctionDeclaration */) {
+ emitModuleElementDeclarationFlags(node);
+ }
+ else if (node.kind === 125 /* Method */) {
+ emitClassMemberDeclarationFlags(node);
+ }
+ if (node.kind === 186 /* FunctionDeclaration */) {
+ write("function ");
+ writeTextOfNode(currentSourceFile, node.name);
+ }
+ else if (node.kind === 126 /* Constructor */) {
+ write("constructor");
+ }
+ else {
+ writeTextOfNode(currentSourceFile, node.name);
+ if (node.flags & 4 /* QuestionMark */) {
+ write("?");
+ }
+ }
+ emitSignatureDeclaration(node);
+ }
+ }
+ function emitSignatureDeclarationWithJsDocComments(node) {
+ emitJsDocComments(node);
+ emitSignatureDeclaration(node);
+ }
+ function emitSignatureDeclaration(node) {
+ if (node.kind === 130 /* ConstructSignature */ || node.kind === 134 /* ConstructorType */) {
+ write("new ");
+ }
+ emitTypeParameters(node.typeParameters);
+ if (node.kind === 131 /* IndexSignature */) {
+ write("[");
+ }
+ else {
+ write("(");
+ }
+ var prevEnclosingDeclaration = enclosingDeclaration;
+ enclosingDeclaration = node;
+ emitCommaList(node.parameters, emitParameterDeclaration);
+ if (node.kind === 131 /* IndexSignature */) {
+ write("]");
+ }
+ else {
+ write(")");
+ }
+ var isFunctionTypeOrConstructorType = node.kind === 133 /* FunctionType */ || node.kind === 134 /* ConstructorType */;
+ if (isFunctionTypeOrConstructorType || node.parent.kind === 136 /* TypeLiteral */) {
+ if (node.type) {
+ write(isFunctionTypeOrConstructorType ? " => " : ": ");
+ emitType(node.type);
+ }
+ }
+ else if (node.kind !== 126 /* Constructor */ && !(node.flags & 32 /* Private */)) {
+ writeReturnTypeAtSignature(node, getReturnTypeVisibilityError);
+ }
+ enclosingDeclaration = prevEnclosingDeclaration;
+ if (!isFunctionTypeOrConstructorType) {
+ write(";");
+ writeLine();
+ }
+ function getReturnTypeVisibilityError(symbolAccesibilityResult) {
+ var diagnosticMessage;
+ switch (node.kind) {
+ case 130 /* ConstructSignature */:
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_0;
+ break;
+ case 129 /* CallSignature */:
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_private_name_0;
+ break;
+ case 131 /* IndexSignature */:
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_private_name_0;
+ break;
+ case 125 /* Method */:
+ if (node.flags & 128 /* Static */) {
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_private_name_0;
+ }
+ else if (node.parent.kind === 188 /* ClassDeclaration */) {
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_private_name_0;
+ }
+ else {
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_private_name_0;
+ }
+ break;
+ case 186 /* FunctionDeclaration */:
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_private_name_0;
+ break;
+ default:
+ ts.Debug.fail("This is unknown kind for signature: " + node.kind);
+ }
+ return {
+ diagnosticMessage: diagnosticMessage,
+ errorNode: node.name || node
+ };
+ }
+ }
+ function emitParameterDeclaration(node) {
+ increaseIndent();
+ emitJsDocComments(node);
+ if (node.flags & 8 /* Rest */) {
+ write("...");
+ }
+ writeTextOfNode(currentSourceFile, node.name);
+ if (node.initializer || (node.flags & 4 /* QuestionMark */)) {
+ write("?");
+ }
+ decreaseIndent();
+ if (node.parent.kind === 133 /* FunctionType */ || node.parent.kind === 134 /* ConstructorType */ || node.parent.parent.kind === 136 /* TypeLiteral */) {
+ emitTypeOfVariableDeclarationFromTypeLiteral(node);
+ }
+ else if (!(node.parent.flags & 32 /* Private */)) {
+ writeTypeAtLocation(node, node.type, getParameterDeclarationTypeVisibilityError);
+ }
+ function getParameterDeclarationTypeVisibilityError(symbolAccesibilityResult) {
+ var diagnosticMessage;
+ switch (node.parent.kind) {
+ case 126 /* Constructor */:
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_private_name_1;
+ break;
+ case 130 /* ConstructSignature */:
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1;
+ break;
+ case 129 /* CallSignature */:
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1;
+ break;
+ case 125 /* Method */:
+ if (node.parent.flags & 128 /* Static */) {
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1;
+ }
+ else if (node.parent.parent.kind === 188 /* ClassDeclaration */) {
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1;
+ }
+ else {
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1;
+ }
+ break;
+ case 186 /* FunctionDeclaration */:
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_private_name_1;
+ break;
+ default:
+ ts.Debug.fail("This is unknown parent for parameter: " + node.parent.kind);
+ }
+ return {
+ diagnosticMessage: diagnosticMessage,
+ errorNode: node,
+ typeName: node.name
+ };
+ }
+ }
+ function emitNode(node) {
+ switch (node.kind) {
+ case 126 /* Constructor */:
+ case 186 /* FunctionDeclaration */:
+ case 125 /* Method */:
+ return emitFunctionDeclaration(node);
+ case 130 /* ConstructSignature */:
+ case 129 /* CallSignature */:
+ case 131 /* IndexSignature */:
+ return emitSignatureDeclarationWithJsDocComments(node);
+ case 127 /* GetAccessor */:
+ case 128 /* SetAccessor */:
+ return emitAccessorDeclaration(node);
+ case 163 /* VariableStatement */:
+ return emitVariableStatement(node);
+ case 124 /* Property */:
+ return emitPropertyDeclaration(node);
+ case 189 /* InterfaceDeclaration */:
+ return emitInterfaceDeclaration(node);
+ case 188 /* ClassDeclaration */:
+ return emitClassDeclaration(node);
+ case 190 /* TypeAliasDeclaration */:
+ return emitTypeAliasDeclaration(node);
+ case 196 /* EnumMember */:
+ return emitEnumMemberDeclaration(node);
+ case 191 /* EnumDeclaration */:
+ return emitEnumDeclaration(node);
+ case 192 /* ModuleDeclaration */:
+ return emitModuleDeclaration(node);
+ case 194 /* ImportDeclaration */:
+ return emitImportDeclaration(node);
+ case 195 /* ExportAssignment */:
+ return emitExportAssignment(node);
+ case 197 /* SourceFile */:
+ return emitSourceFile(node);
+ }
+ }
+ var referencePathsOutput = "";
+ function writeReferencePath(referencedFile) {
+ var declFileName = referencedFile.flags & 1024 /* DeclarationFile */ ? referencedFile.filename : shouldEmitToOwnFile(referencedFile, compilerOptions) ? getOwnEmitOutputFilePath(referencedFile, program, ".d.ts") : ts.removeFileExtension(compilerOptions.out) + ".d.ts";
+ declFileName = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizeSlashes(jsFilePath)), declFileName, compilerHost.getCurrentDirectory(), compilerHost.getCanonicalFileName, false);
+ referencePathsOutput += "/// " + newLine;
+ }
+ if (root) {
+ if (!compilerOptions.noResolve) {
+ var addedGlobalFileReference = false;
+ ts.forEach(root.referencedFiles, function (fileReference) {
+ var referencedFile = ts.tryResolveScriptReference(program, root, fileReference);
+ if (referencedFile && ((referencedFile.flags & 1024 /* DeclarationFile */) || shouldEmitToOwnFile(referencedFile, compilerOptions) || !addedGlobalFileReference)) {
+ writeReferencePath(referencedFile);
+ if (!isExternalModuleOrDeclarationFile(referencedFile)) {
+ addedGlobalFileReference = true;
+ }
+ }
+ });
+ }
+ emitNode(root);
+ }
+ else {
+ var emittedReferencedFiles = [];
+ ts.forEach(program.getSourceFiles(), function (sourceFile) {
+ if (!isExternalModuleOrDeclarationFile(sourceFile)) {
+ if (!compilerOptions.noResolve) {
+ ts.forEach(sourceFile.referencedFiles, function (fileReference) {
+ var referencedFile = ts.tryResolveScriptReference(program, sourceFile, fileReference);
+ if (referencedFile && (isExternalModuleOrDeclarationFile(referencedFile) && !ts.contains(emittedReferencedFiles, referencedFile))) {
+ writeReferencePath(referencedFile);
+ emittedReferencedFiles.push(referencedFile);
+ }
+ });
+ }
+ emitNode(sourceFile);
+ }
+ });
+ }
+ return {
+ reportedDeclarationError: reportedDeclarationError,
+ aliasDeclarationEmitInfo: aliasDeclarationEmitInfo,
+ synchronousDeclarationOutput: writer.getText(),
+ referencePathsOutput: referencePathsOutput
+ };
+ }
+ function getDeclarationDiagnostics(program, resolver, targetSourceFile) {
+ var diagnostics = [];
+ var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, program, ".js");
+ emitDeclarations(program, resolver, diagnostics, jsFilePath, targetSourceFile);
+ return diagnostics;
+ }
+ ts.getDeclarationDiagnostics = getDeclarationDiagnostics;
function emitFiles(resolver, targetSourceFile) {
var program = resolver.getProgram();
var compilerHost = program.getCompilerHost();
@@ -6256,206 +7678,14 @@ var ts;
var sourceMapDataList = compilerOptions.sourceMap ? [] : undefined;
var diagnostics = [];
var newLine = program.getCompilerHost().getNewLine();
- function getSourceFilePathInNewDir(newDirPath, sourceFile) {
- var sourceFilePath = ts.getNormalizedPathFromPathComponents(ts.getNormalizedPathComponents(sourceFile.filename, compilerHost.getCurrentDirectory()));
- sourceFilePath = sourceFilePath.replace(program.getCommonSourceDirectory(), "");
- return ts.combinePaths(newDirPath, sourceFilePath);
- }
- function getOwnEmitOutputFilePath(sourceFile, extension) {
- if (compilerOptions.outDir) {
- var emitOutputFilePathWithoutExtension = ts.removeFileExtension(getSourceFilePathInNewDir(compilerOptions.outDir, sourceFile));
- }
- else {
- var emitOutputFilePathWithoutExtension = ts.removeFileExtension(sourceFile.filename);
- }
- return emitOutputFilePathWithoutExtension + extension;
- }
- function getFirstConstructorWithBody(node) {
- return ts.forEach(node.members, function (member) {
- if (member.kind === 126 /* Constructor */ && member.body) {
- return member;
- }
- });
- }
- function getAllAccessorDeclarations(node, accessor) {
- var firstAccessor;
- var getAccessor;
- var setAccessor;
- ts.forEach(node.members, function (member) {
- if ((member.kind === 127 /* GetAccessor */ || member.kind === 128 /* SetAccessor */) && member.name.text === accessor.name.text && (member.flags & 128 /* Static */) === (accessor.flags & 128 /* Static */)) {
- if (!firstAccessor) {
- firstAccessor = member;
- }
- if (member.kind === 127 /* GetAccessor */ && !getAccessor) {
- getAccessor = member;
- }
- if (member.kind === 128 /* SetAccessor */ && !setAccessor) {
- setAccessor = member;
- }
- }
- });
- return {
- firstAccessor: firstAccessor,
- getAccessor: getAccessor,
- setAccessor: setAccessor
- };
- }
- function createTextWriter() {
- var output = "";
- var indent = 0;
- var lineStart = true;
- var lineCount = 0;
- var linePos = 0;
- function write(s) {
- if (s && s.length) {
- if (lineStart) {
- output += getIndentString(indent);
- lineStart = false;
- }
- output += s;
- }
- }
- function rawWrite(s) {
- if (s !== undefined) {
- if (lineStart) {
- lineStart = false;
- }
- output += s;
- }
- }
- function writeLiteral(s) {
- if (s && s.length) {
- write(s);
- var lineStartsOfS = ts.computeLineStarts(s);
- if (lineStartsOfS.length > 1) {
- lineCount = lineCount + lineStartsOfS.length - 1;
- linePos = output.length - s.length + lineStartsOfS[lineStartsOfS.length - 1];
- }
- }
- }
- function writeLine() {
- if (!lineStart) {
- output += newLine;
- lineCount++;
- linePos = output.length;
- lineStart = true;
- }
- }
- return {
- write: write,
- rawWrite: rawWrite,
- writeLiteral: writeLiteral,
- writeLine: writeLine,
- increaseIndent: function () { return indent++; },
- decreaseIndent: function () { return indent--; },
- getIndent: function () { return indent; },
- getTextPos: function () { return output.length; },
- getLine: function () { return lineCount + 1; },
- getColumn: function () { return lineStart ? indent * getIndentSize() + 1 : output.length - linePos + 1; },
- getText: function () { return output; }
- };
- }
- var currentSourceFile;
- function getSourceTextOfLocalNode(node) {
- var text = currentSourceFile.text;
- return text.substring(ts.skipTrivia(text, node.pos), node.end);
- }
- function getLineOfLocalPosition(pos) {
- return currentSourceFile.getLineAndCharacterFromPosition(pos).line;
- }
- function writeFile(filename, data, writeByteOrderMark) {
- compilerHost.writeFile(filename, data, writeByteOrderMark, function (hostErrorMessage) {
- diagnostics.push(ts.createCompilerDiagnostic(ts.Diagnostics.Could_not_write_file_0_Colon_1, filename, hostErrorMessage));
- });
- }
- function emitComments(comments, trailingSeparator, writer, writeComment) {
- var emitLeadingSpace = !trailingSeparator;
- ts.forEach(comments, function (comment) {
- if (emitLeadingSpace) {
- writer.write(" ");
- emitLeadingSpace = false;
- }
- writeComment(comment, writer);
- if (comment.hasTrailingNewLine) {
- writer.writeLine();
- }
- else if (trailingSeparator) {
- writer.write(" ");
- }
- else {
- emitLeadingSpace = true;
- }
- });
- }
- function emitNewLineBeforeLeadingComments(node, leadingComments, writer) {
- if (leadingComments && leadingComments.length && node.pos !== leadingComments[0].pos && getLineOfLocalPosition(node.pos) !== getLineOfLocalPosition(leadingComments[0].pos)) {
- writer.writeLine();
- }
- }
- function writeCommentRange(comment, writer) {
- if (currentSourceFile.text.charCodeAt(comment.pos + 1) === 42 /* asterisk */) {
- var firstCommentLineAndCharacter = currentSourceFile.getLineAndCharacterFromPosition(comment.pos);
- var firstCommentLineIndent;
- for (var pos = comment.pos, currentLine = firstCommentLineAndCharacter.line; pos < comment.end; currentLine++) {
- var nextLineStart = currentSourceFile.getPositionFromLineAndCharacter(currentLine + 1, 1);
- if (pos !== comment.pos) {
- if (firstCommentLineIndent === undefined) {
- firstCommentLineIndent = calculateIndent(currentSourceFile.getPositionFromLineAndCharacter(firstCommentLineAndCharacter.line, 1), comment.pos);
- }
- var currentWriterIndentSpacing = writer.getIndent() * getIndentSize();
- var spacesToEmit = currentWriterIndentSpacing - firstCommentLineIndent + calculateIndent(pos, nextLineStart);
- if (spacesToEmit > 0) {
- var numberOfSingleSpacesToEmit = spacesToEmit % getIndentSize();
- var indentSizeSpaceString = getIndentString((spacesToEmit - numberOfSingleSpacesToEmit) / getIndentSize());
- writer.rawWrite(indentSizeSpaceString);
- while (numberOfSingleSpacesToEmit) {
- writer.rawWrite(" ");
- numberOfSingleSpacesToEmit--;
- }
- }
- else {
- writer.rawWrite("");
- }
- }
- writeTrimmedCurrentLine(pos, nextLineStart);
- pos = nextLineStart;
- }
- }
- else {
- writer.write(currentSourceFile.text.substring(comment.pos, comment.end));
- }
- function writeTrimmedCurrentLine(pos, nextLineStart) {
- var end = Math.min(comment.end, nextLineStart - 1);
- var currentLineText = currentSourceFile.text.substring(pos, end).replace(/^\s+|\s+$/g, '');
- if (currentLineText) {
- writer.write(currentLineText);
- if (end !== comment.end) {
- writer.writeLine();
- }
- }
- else {
- writer.writeLiteral(newLine);
- }
- }
- function calculateIndent(pos, end) {
- var currentLineIndent = 0;
- for (; pos < end && ts.isWhiteSpace(currentSourceFile.text.charCodeAt(pos)); pos++) {
- if (currentSourceFile.text.charCodeAt(pos) === 9 /* tab */) {
- currentLineIndent += getIndentSize() - (currentLineIndent % getIndentSize());
- }
- else {
- currentLineIndent++;
- }
- }
- return currentLineIndent;
- }
- }
function emitJavaScript(jsFilePath, root) {
- var writer = createTextWriter();
+ var writer = createTextWriter(newLine);
var write = writer.write;
+ var writeTextOfNode = writer.writeTextOfNode;
var writeLine = writer.writeLine;
var increaseIndent = writer.increaseIndent;
var decreaseIndent = writer.decreaseIndent;
+ var currentSourceFile;
var extendsEmitted = false;
var writeEmittedFiles = writeJavaScriptFile;
var emitLeadingComments = compilerOptions.removeComments ? function (node) {
@@ -6612,7 +7842,7 @@ var ts;
if (scopeName) {
recordScopeNameStart(scopeName);
}
- else if (node.kind === 185 /* FunctionDeclaration */ || node.kind === 152 /* FunctionExpression */ || node.kind === 125 /* Method */ || node.kind === 127 /* GetAccessor */ || node.kind === 128 /* SetAccessor */ || node.kind === 191 /* ModuleDeclaration */ || node.kind === 187 /* ClassDeclaration */ || node.kind === 190 /* EnumDeclaration */) {
+ else if (node.kind === 186 /* FunctionDeclaration */ || node.kind === 152 /* FunctionExpression */ || node.kind === 125 /* Method */ || node.kind === 127 /* GetAccessor */ || node.kind === 128 /* SetAccessor */ || node.kind === 192 /* ModuleDeclaration */ || node.kind === 188 /* ClassDeclaration */ || node.kind === 191 /* EnumDeclaration */) {
if (node.name) {
scopeName = node.name.text;
}
@@ -6626,9 +7856,9 @@ var ts;
sourceMapNameIndices.pop();
}
;
- function writeCommentRangeWithMap(comment, writer) {
+ function writeCommentRangeWithMap(curentSourceFile, writer, comment, newLine) {
recordSourceMapSpan(comment.pos);
- writeCommentRange(comment, writer);
+ writeCommentRange(currentSourceFile, writer, comment, newLine);
recordSourceMapSpan(comment.end);
}
function serializeSourceMapContents(version, file, sourceRoot, sources, names, mappings) {
@@ -6656,7 +7886,7 @@ var ts;
}
function writeJavaScriptAndSourceMapFile(emitOutput, writeByteOrderMark) {
encodeLastRecordedSourceMapSpan();
- writeFile(sourceMapData.sourceMapFilePath, serializeSourceMapContents(3, sourceMapData.sourceMapFile, sourceMapData.sourceMapSourceRoot, sourceMapData.sourceMapSources, sourceMapData.sourceMapNames, sourceMapData.sourceMapMappings), false);
+ writeFile(compilerHost, diagnostics, sourceMapData.sourceMapFilePath, serializeSourceMapContents(3, sourceMapData.sourceMapFile, sourceMapData.sourceMapSourceRoot, sourceMapData.sourceMapSources, sourceMapData.sourceMapNames, sourceMapData.sourceMapMappings), false);
sourceMapDataList.push(sourceMapData);
writeJavaScriptFile(emitOutput + "//# sourceMappingURL=" + sourceMapData.jsSourceMappingURL, writeByteOrderMark);
}
@@ -6679,7 +7909,7 @@ var ts;
if (compilerOptions.mapRoot) {
sourceMapDir = ts.normalizeSlashes(compilerOptions.mapRoot);
if (root) {
- sourceMapDir = ts.getDirectoryPath(getSourceFilePathInNewDir(sourceMapDir, root));
+ sourceMapDir = ts.getDirectoryPath(getSourceFilePathInNewDir(root, program, sourceMapDir));
}
if (!ts.isRootedDiskPath(sourceMapDir) && !ts.isUrl(sourceMapDir)) {
sourceMapDir = ts.combinePaths(program.getCommonSourceDirectory(), sourceMapDir);
@@ -6694,7 +7924,7 @@ var ts;
}
function emitNodeWithMap(node) {
if (node) {
- if (node.kind != 196 /* SourceFile */) {
+ if (node.kind != 197 /* SourceFile */) {
recordEmitNodeStartSpan(node);
emitNode(node);
recordEmitNodeEndSpan(node);
@@ -6715,7 +7945,7 @@ var ts;
writeComment = writeCommentRangeWithMap;
}
function writeJavaScriptFile(emitOutput, writeByteOrderMark) {
- writeFile(jsFilePath, emitOutput, writeByteOrderMark);
+ writeFile(compilerHost, diagnostics, jsFilePath, emitOutput, writeByteOrderMark);
}
function emitTokenText(tokenKind, startPos, emitFn) {
var tokenString = ts.tokenToString(tokenKind);
@@ -6792,7 +8022,7 @@ var ts;
if (compilerOptions.target < 2 /* ES6 */ && ts.isTemplateLiteralKind(node.kind)) {
return getTemplateLiteralAsStringLiteral(node);
}
- return getSourceTextOfLocalNode(node);
+ return ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node);
}
}
function getTemplateLiteralAsStringLiteral(node) {
@@ -6804,8 +8034,8 @@ var ts;
return;
}
ts.Debug.assert(node.parent.kind !== 149 /* TaggedTemplateExpression */);
- var templateNeedsParens = ts.isExpression(node.parent) && node.parent.kind !== 151 /* ParenExpression */ && comparePrecedenceToBinaryPlus(node.parent) !== -1 /* LessThan */;
- if (templateNeedsParens) {
+ var emitOuterParens = ts.isExpression(node.parent) && templateNeedsParens(node, node.parent);
+ if (emitOuterParens) {
write("(");
}
emitLiteral(node.head);
@@ -6824,9 +8054,22 @@ var ts;
emitLiteral(templateSpan.literal);
}
});
- if (templateNeedsParens) {
+ if (emitOuterParens) {
write(")");
}
+ function templateNeedsParens(template, parent) {
+ switch (parent.kind) {
+ case 147 /* CallExpression */:
+ case 148 /* NewExpression */:
+ return parent.func === template;
+ case 151 /* ParenExpression */:
+ return false;
+ case 149 /* TaggedTemplateExpression */:
+ ts.Debug.fail("Path should be unreachable; tagged templates not supported pre-ES6.");
+ default:
+ return comparePrecedenceToBinaryPlus(parent) !== -1 /* LessThan */;
+ }
+ }
function comparePrecedenceToBinaryPlus(expression) {
ts.Debug.assert(compilerOptions.target <= 1 /* ES5 */);
switch (expression.kind) {
@@ -6862,7 +8105,7 @@ var ts;
write(node.text);
}
else {
- write(getSourceTextOfLocalNode(node));
+ writeTextOfNode(currentSourceFile, node);
}
write("\"");
}
@@ -6871,29 +8114,29 @@ var ts;
var parent = node.parent;
switch (parent.kind) {
case 123 /* Parameter */:
- case 184 /* VariableDeclaration */:
+ case 185 /* VariableDeclaration */:
case 124 /* Property */:
case 143 /* PropertyAssignment */:
case 144 /* ShorthandPropertyAssignment */:
- case 195 /* EnumMember */:
+ case 196 /* EnumMember */:
case 125 /* Method */:
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
case 127 /* GetAccessor */:
case 128 /* SetAccessor */:
case 152 /* FunctionExpression */:
- case 187 /* ClassDeclaration */:
- case 188 /* InterfaceDeclaration */:
- case 190 /* EnumDeclaration */:
- case 191 /* ModuleDeclaration */:
- case 193 /* ImportDeclaration */:
+ case 188 /* ClassDeclaration */:
+ case 189 /* InterfaceDeclaration */:
+ case 191 /* EnumDeclaration */:
+ case 192 /* ModuleDeclaration */:
+ case 194 /* ImportDeclaration */:
return parent.name === node;
- case 171 /* BreakStatement */:
- case 170 /* ContinueStatement */:
- case 194 /* ExportAssignment */:
+ case 172 /* BreakStatement */:
+ case 171 /* ContinueStatement */:
+ case 195 /* ExportAssignment */:
return false;
- case 177 /* LabeledStatement */:
+ case 178 /* LabeledStatement */:
return node.parent.label === node;
- case 181 /* CatchBlock */:
+ case 182 /* CatchBlock */:
return node.parent.variable === node;
}
}
@@ -6903,14 +8146,14 @@ var ts;
write(prefix);
write(".");
}
- write(getSourceTextOfLocalNode(node));
+ writeTextOfNode(currentSourceFile, node);
}
function emitIdentifier(node) {
if (!isNotExpressionIdentifier(node)) {
emitExpressionIdentifier(node);
}
else {
- write(getSourceTextOfLocalNode(node));
+ writeTextOfNode(currentSourceFile, node);
}
}
function emitThis(node) {
@@ -7117,8 +8360,8 @@ var ts;
emitToken(13 /* OpenBraceToken */, node.pos);
increaseIndent();
scopeEmitStart(node.parent);
- if (node.kind === 192 /* ModuleBlock */) {
- ts.Debug.assert(node.parent.kind === 191 /* ModuleDeclaration */);
+ if (node.kind === 193 /* ModuleBlock */) {
+ ts.Debug.assert(node.parent.kind === 192 /* ModuleDeclaration */);
emitCaptureThisForNodeIfNecessary(node.parent);
}
emitLines(node.statements);
@@ -7128,7 +8371,7 @@ var ts;
scopeEmitEnd();
}
function emitEmbeddedStatement(node) {
- if (node.kind === 161 /* Block */) {
+ if (node.kind === 162 /* Block */) {
write(" ");
emit(node);
}
@@ -7161,7 +8404,7 @@ var ts;
if (node.elseStatement) {
writeLine();
emitToken(74 /* ElseKeyword */, node.thenStatement.end);
- if (node.elseStatement.kind === 165 /* IfStatement */) {
+ if (node.elseStatement.kind === 166 /* IfStatement */) {
write(" ");
emit(node.elseStatement);
}
@@ -7174,7 +8417,7 @@ var ts;
function emitDoStatement(node) {
write("do");
emitEmbeddedStatement(node.statement);
- if (node.statement.kind === 161 /* Block */) {
+ if (node.statement.kind === 162 /* Block */) {
write(" ");
}
else {
@@ -7195,10 +8438,10 @@ var ts;
write(" ");
endPos = emitToken(15 /* OpenParenToken */, endPos);
if (node.declarations) {
- if (node.declarations[0] && node.declarations[0].flags & 2048 /* Let */) {
+ if (node.declarations[0] && ts.isLet(node.declarations[0])) {
emitToken(102 /* LetKeyword */, endPos);
}
- else if (node.declarations[0] && node.declarations[0].flags & 4096 /* Const */) {
+ else if (node.declarations[0] && ts.isConst(node.declarations[0])) {
emitToken(68 /* ConstKeyword */, endPos);
}
else {
@@ -7221,15 +8464,18 @@ var ts;
var endPos = emitToken(80 /* ForKeyword */, node.pos);
write(" ");
endPos = emitToken(15 /* OpenParenToken */, endPos);
- if (node.declaration) {
- if (node.declaration.flags & 2048 /* Let */) {
- emitToken(102 /* LetKeyword */, endPos);
+ if (node.declarations) {
+ if (node.declarations.length >= 1) {
+ var decl = node.declarations[0];
+ if (ts.isLet(decl)) {
+ emitToken(102 /* LetKeyword */, endPos);
+ }
+ else {
+ emitToken(96 /* VarKeyword */, endPos);
+ }
+ write(" ");
+ emit(decl);
}
- else {
- emitToken(96 /* VarKeyword */, endPos);
- }
- write(" ");
- emit(node.declaration);
}
else {
emit(node.variable);
@@ -7240,7 +8486,7 @@ var ts;
emitEmbeddedStatement(node.statement);
}
function emitBreakOrContinueStatement(node) {
- emitToken(node.kind === 171 /* BreakStatement */ ? 64 /* BreakKeyword */ : 69 /* ContinueKeyword */, node.pos);
+ emitToken(node.kind === 172 /* BreakStatement */ ? 64 /* BreakKeyword */ : 69 /* ContinueKeyword */, node.pos);
emitOptional(" ", node.label);
write(";");
}
@@ -7272,10 +8518,10 @@ var ts;
emitToken(14 /* CloseBraceToken */, node.clauses.end);
}
function isOnSameLine(node1, node2) {
- return getLineOfLocalPosition(ts.skipTrivia(currentSourceFile.text, node1.pos)) === getLineOfLocalPosition(ts.skipTrivia(currentSourceFile.text, node2.pos));
+ return getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node1.pos)) === getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node2.pos));
}
function emitCaseOrDefaultClause(node) {
- if (node.kind === 175 /* CaseClause */) {
+ if (node.kind === 176 /* CaseClause */) {
write("case ");
emit(node.expression);
write(":");
@@ -7330,7 +8576,7 @@ var ts;
function getContainingModule(node) {
do {
node = node.parent;
- } while (node && node.kind !== 191 /* ModuleDeclaration */);
+ } while (node && node.kind !== 192 /* ModuleDeclaration */);
return node;
}
function emitModuleMemberName(node) {
@@ -7352,10 +8598,10 @@ var ts;
function emitVariableStatement(node) {
emitLeadingComments(node);
if (!(node.flags & 1 /* Export */)) {
- if (node.flags & 2048 /* Let */) {
+ if (ts.isLet(node)) {
write("let ");
}
- else if (node.flags & 4096 /* Const */) {
+ else if (ts.isConst(node)) {
write("const ");
}
else {
@@ -7442,7 +8688,7 @@ var ts;
emitLeadingComments(node);
}
write("function ");
- if (node.kind === 185 /* FunctionDeclaration */ || (node.kind === 152 /* FunctionExpression */ && node.name)) {
+ if (node.kind === 186 /* FunctionDeclaration */ || (node.kind === 152 /* FunctionExpression */ && node.name)) {
emit(node.name);
}
emitSignatureAndBody(node);
@@ -7472,16 +8718,16 @@ var ts;
write(" {");
scopeEmitStart(node);
increaseIndent();
- emitDetachedComments(node.body.kind === 186 /* FunctionBlock */ ? node.body.statements : node.body);
+ emitDetachedComments(node.body.kind === 187 /* FunctionBlock */ ? node.body.statements : node.body);
var startIndex = 0;
- if (node.body.kind === 186 /* FunctionBlock */) {
+ if (node.body.kind === 187 /* FunctionBlock */) {
startIndex = emitDirectivePrologues(node.body.statements, true);
}
var outPos = writer.getTextPos();
emitCaptureThisForNodeIfNecessary(node);
emitDefaultValueAssignments(node);
emitRestParameter(node);
- if (node.body.kind !== 186 /* FunctionBlock */ && outPos === writer.getTextPos()) {
+ if (node.body.kind !== 187 /* FunctionBlock */ && outPos === writer.getTextPos()) {
decreaseIndent();
write(" ");
emitStart(node.body);
@@ -7494,7 +8740,7 @@ var ts;
emitEnd(node.body);
}
else {
- if (node.body.kind === 186 /* FunctionBlock */) {
+ if (node.body.kind === 187 /* FunctionBlock */) {
emitLinesStartingAt(node.body.statements, startIndex);
}
else {
@@ -7506,7 +8752,7 @@ var ts;
emitTrailingComments(node.body);
}
writeLine();
- if (node.body.kind === 186 /* FunctionBlock */) {
+ if (node.body.kind === 187 /* FunctionBlock */) {
emitLeadingCommentsOfPosition(node.body.statements.end);
decreaseIndent();
emitToken(14 /* CloseBraceToken */, node.body.statements.end);
@@ -7532,7 +8778,7 @@ var ts;
function findInitialSuperCall(ctor) {
if (ctor.body) {
var statement = ctor.body.statements[0];
- if (statement && statement.kind === 164 /* ExpressionStatement */) {
+ if (statement && statement.kind === 165 /* ExpressionStatement */) {
var expr = statement.expression;
if (expr && expr.kind === 147 /* CallExpression */) {
var func = expr.func;
@@ -7783,7 +9029,7 @@ var ts;
emitPinnedOrTripleSlashComments(node);
}
function emitEnumDeclaration(node) {
- var isConstEnum = ts.isConstEnumDeclaration(node);
+ var isConstEnum = ts.isConst(node);
if (isConstEnum && !compilerOptions.preserveConstEnums) {
return;
}
@@ -7852,13 +9098,14 @@ var ts;
}
}
function getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration) {
- if (moduleDeclaration.body.kind === 191 /* ModuleDeclaration */) {
+ if (moduleDeclaration.body.kind === 192 /* ModuleDeclaration */) {
var recursiveInnerModule = getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration.body);
return recursiveInnerModule || moduleDeclaration.body;
}
}
function emitModuleDeclaration(node) {
- if (ts.getModuleInstanceState(node) !== 1 /* Instantiated */) {
+ var shouldEmit = ts.getModuleInstanceState(node) === 1 /* Instantiated */ || (ts.getModuleInstanceState(node) === 2 /* ConstEnumOnly */ && compilerOptions.preserveConstEnums);
+ if (!shouldEmit) {
return emitPinnedOrTripleSlashComments(node);
}
emitLeadingComments(node);
@@ -7874,7 +9121,7 @@ var ts;
write(resolver.getLocalNameOfContainer(node));
emitEnd(node.name);
write(") ");
- if (node.body.kind === 192 /* ModuleBlock */) {
+ if (node.body.kind === 193 /* ModuleBlock */) {
emit(node.body);
}
else {
@@ -7908,7 +9155,7 @@ var ts;
emitImportDeclaration = !ts.isExternalModule(currentSourceFile) && resolver.isTopLevelValueImportWithEntityName(node);
}
if (emitImportDeclaration) {
- if (node.externalModuleName && node.parent.kind === 196 /* SourceFile */ && compilerOptions.module === 2 /* AMD */) {
+ if (node.externalModuleName && node.parent.kind === 197 /* SourceFile */ && compilerOptions.module === 2 /* AMD */) {
if (node.flags & 1 /* Export */) {
writeLine();
emitLeadingComments(node);
@@ -7948,7 +9195,7 @@ var ts;
function getExternalImportDeclarations(node) {
var result = [];
ts.forEach(node.statements, function (stat) {
- if (stat.kind === 193 /* ImportDeclaration */ && stat.externalModuleName && resolver.isReferencedImportDeclaration(stat)) {
+ if (stat.kind === 194 /* ImportDeclaration */ && stat.externalModuleName && resolver.isReferencedImportDeclaration(stat)) {
result.push(stat);
}
});
@@ -7956,7 +9203,7 @@ var ts;
}
function getFirstExportAssignment(sourceFile) {
return ts.forEach(sourceFile.statements, function (node) {
- if (node.kind === 194 /* ExportAssignment */) {
+ if (node.kind === 195 /* ExportAssignment */) {
return node;
}
});
@@ -8129,7 +9376,7 @@ var ts;
return emit(node.operand);
case 151 /* ParenExpression */:
return emitParenExpression(node);
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
case 152 /* FunctionExpression */:
case 153 /* ArrowFunction */:
return emitFunctionDeclaration(node);
@@ -8140,65 +9387,65 @@ var ts;
return emitBinaryExpression(node);
case 157 /* ConditionalExpression */:
return emitConditionalExpression(node);
- case 160 /* OmittedExpression */:
+ case 161 /* OmittedExpression */:
return;
- case 161 /* Block */:
- case 180 /* TryBlock */:
- case 182 /* FinallyBlock */:
- case 186 /* FunctionBlock */:
- case 192 /* ModuleBlock */:
+ case 162 /* Block */:
+ case 181 /* TryBlock */:
+ case 183 /* FinallyBlock */:
+ case 187 /* FunctionBlock */:
+ case 193 /* ModuleBlock */:
return emitBlock(node);
- case 162 /* VariableStatement */:
+ case 163 /* VariableStatement */:
return emitVariableStatement(node);
- case 163 /* EmptyStatement */:
+ case 164 /* EmptyStatement */:
return write(";");
- case 164 /* ExpressionStatement */:
+ case 165 /* ExpressionStatement */:
return emitExpressionStatement(node);
- case 165 /* IfStatement */:
+ case 166 /* IfStatement */:
return emitIfStatement(node);
- case 166 /* DoStatement */:
+ case 167 /* DoStatement */:
return emitDoStatement(node);
- case 167 /* WhileStatement */:
+ case 168 /* WhileStatement */:
return emitWhileStatement(node);
- case 168 /* ForStatement */:
+ case 169 /* ForStatement */:
return emitForStatement(node);
- case 169 /* ForInStatement */:
+ case 170 /* ForInStatement */:
return emitForInStatement(node);
- case 170 /* ContinueStatement */:
- case 171 /* BreakStatement */:
+ case 171 /* ContinueStatement */:
+ case 172 /* BreakStatement */:
return emitBreakOrContinueStatement(node);
- case 172 /* ReturnStatement */:
+ case 173 /* ReturnStatement */:
return emitReturnStatement(node);
- case 173 /* WithStatement */:
+ case 174 /* WithStatement */:
return emitWithStatement(node);
- case 174 /* SwitchStatement */:
+ case 175 /* SwitchStatement */:
return emitSwitchStatement(node);
- case 175 /* CaseClause */:
- case 176 /* DefaultClause */:
+ case 176 /* CaseClause */:
+ case 177 /* DefaultClause */:
return emitCaseOrDefaultClause(node);
- case 177 /* LabeledStatement */:
+ case 178 /* LabeledStatement */:
return emitLabelledStatement(node);
- case 178 /* ThrowStatement */:
+ case 179 /* ThrowStatement */:
return emitThrowStatement(node);
- case 179 /* TryStatement */:
+ case 180 /* TryStatement */:
return emitTryStatement(node);
- case 181 /* CatchBlock */:
+ case 182 /* CatchBlock */:
return emitCatchBlock(node);
- case 183 /* DebuggerStatement */:
+ case 184 /* DebuggerStatement */:
return emitDebuggerStatement(node);
- case 184 /* VariableDeclaration */:
+ case 185 /* VariableDeclaration */:
return emitVariableDeclaration(node);
- case 187 /* ClassDeclaration */:
+ case 188 /* ClassDeclaration */:
return emitClassDeclaration(node);
- case 188 /* InterfaceDeclaration */:
+ case 189 /* InterfaceDeclaration */:
return emitInterfaceDeclaration(node);
- case 190 /* EnumDeclaration */:
+ case 191 /* EnumDeclaration */:
return emitEnumDeclaration(node);
- case 191 /* ModuleDeclaration */:
+ case 192 /* ModuleDeclaration */:
return emitModuleDeclaration(node);
- case 193 /* ImportDeclaration */:
+ case 194 /* ImportDeclaration */:
return emitImportDeclaration(node);
- case 196 /* SourceFile */:
+ case 197 /* SourceFile */:
return emitSourceFile(node);
}
}
@@ -8216,7 +9463,7 @@ var ts;
return leadingComments;
}
function getLeadingCommentsToEmit(node) {
- if (node.parent.kind === 196 /* SourceFile */ || node.pos !== node.parent.pos) {
+ if (node.parent.kind === 197 /* SourceFile */ || node.pos !== node.parent.pos) {
var leadingComments;
if (hasDetachedComments(node.pos)) {
leadingComments = getLeadingCommentsWithoutDetachedComments();
@@ -8229,13 +9476,13 @@ var ts;
}
function emitLeadingDeclarationComments(node) {
var leadingComments = getLeadingCommentsToEmit(node);
- emitNewLineBeforeLeadingComments(node, leadingComments, writer);
- emitComments(leadingComments, true, writer, writeComment);
+ emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments);
+ emitComments(currentSourceFile, writer, leadingComments, true, newLine, writeComment);
}
function emitTrailingDeclarationComments(node) {
- if (node.parent.kind === 196 /* SourceFile */ || node.end !== node.parent.end) {
+ if (node.parent.kind === 197 /* SourceFile */ || node.end !== node.parent.end) {
var trailingComments = ts.getTrailingCommentRanges(currentSourceFile.text, node.end);
- emitComments(trailingComments, false, writer, writeComment);
+ emitComments(currentSourceFile, writer, trailingComments, false, newLine, writeComment);
}
}
function emitLeadingCommentsOfLocalPosition(pos) {
@@ -8246,8 +9493,8 @@ var ts;
else {
leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, pos);
}
- emitNewLineBeforeLeadingComments({ pos: pos, end: pos }, leadingComments, writer);
- emitComments(leadingComments, true, writer, writeComment);
+ emitNewLineBeforeLeadingComments(currentSourceFile, writer, { pos: pos, end: pos }, leadingComments);
+ emitComments(currentSourceFile, writer, leadingComments, true, newLine, writeComment);
}
function emitDetachedCommentsAtPosition(node) {
var leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, node.pos);
@@ -8256,8 +9503,8 @@ var ts;
var lastComment;
ts.forEach(leadingComments, function (comment) {
if (lastComment) {
- var lastCommentLine = getLineOfLocalPosition(lastComment.end);
- var commentLine = getLineOfLocalPosition(comment.pos);
+ var lastCommentLine = getLineOfLocalPosition(currentSourceFile, lastComment.end);
+ var commentLine = getLineOfLocalPosition(currentSourceFile, comment.pos);
if (commentLine >= lastCommentLine + 2) {
return detachedComments;
}
@@ -8266,11 +9513,11 @@ var ts;
lastComment = comment;
});
if (detachedComments.length) {
- var lastCommentLine = getLineOfLocalPosition(detachedComments[detachedComments.length - 1].end);
- var astLine = getLineOfLocalPosition(ts.skipTrivia(currentSourceFile.text, node.pos));
+ var lastCommentLine = getLineOfLocalPosition(currentSourceFile, detachedComments[detachedComments.length - 1].end);
+ var astLine = getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node.pos));
if (astLine >= lastCommentLine + 2) {
- emitNewLineBeforeLeadingComments(node, leadingComments, writer);
- emitComments(detachedComments, true, writer, writeComment);
+ emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments);
+ emitComments(currentSourceFile, writer, detachedComments, true, newLine, writeComment);
var currentDetachedCommentInfo = { nodePos: node.pos, detachedCommentEndPos: detachedComments[detachedComments.length - 1].end };
if (detachedCommentsInfo) {
detachedCommentsInfo.push(currentDetachedCommentInfo);
@@ -8292,8 +9539,8 @@ var ts;
return true;
}
}
- emitNewLineBeforeLeadingComments(node, pinnedComments, writer);
- emitComments(pinnedComments, true, writer, writeComment);
+ emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, pinnedComments);
+ emitComments(currentSourceFile, writer, pinnedComments, true, newLine, writeComment);
}
if (compilerOptions.sourceMap) {
initializeEmitterWithSourceMaps();
@@ -8311,722 +9558,20 @@ var ts;
writeLine();
writeEmittedFiles(writer.getText(), compilerOptions.emitBOM);
}
- function emitDeclarations(jsFilePath, root) {
- var writer = createTextWriterWithSymbolWriter();
- var write = writer.write;
- var writeLine = writer.writeLine;
- var increaseIndent = writer.increaseIndent;
- var decreaseIndent = writer.decreaseIndent;
- var enclosingDeclaration;
- var reportedDeclarationError = false;
- var emitJsDocComments = compilerOptions.removeComments ? function (declaration) {
- } : writeJsDocComments;
- var aliasDeclarationEmitInfo = [];
- var getSymbolVisibilityDiagnosticMessage;
- function createTextWriterWithSymbolWriter() {
- var writer = createTextWriter();
- writer.trackSymbol = trackSymbol;
- writer.writeKeyword = writer.write;
- writer.writeOperator = writer.write;
- writer.writePunctuation = writer.write;
- writer.writeSpace = writer.write;
- writer.writeStringLiteral = writer.writeLiteral;
- writer.writeParameter = writer.write;
- writer.writeSymbol = writer.write;
- return writer;
- }
- function writeAsychronousImportDeclarations(importDeclarations) {
- var oldWriter = writer;
- ts.forEach(importDeclarations, function (aliasToWrite) {
- var aliasEmitInfo = ts.forEach(aliasDeclarationEmitInfo, function (declEmitInfo) { return declEmitInfo.declaration === aliasToWrite ? declEmitInfo : undefined; });
- writer = createTextWriterWithSymbolWriter();
- for (var declarationIndent = aliasEmitInfo.indent; declarationIndent; declarationIndent--) {
- writer.increaseIndent();
- }
- writeImportDeclaration(aliasToWrite);
- aliasEmitInfo.asynchronousOutput = writer.getText();
- });
- writer = oldWriter;
- }
- function trackSymbol(symbol, enclosingDeclaration, meaning) {
- var symbolAccesibilityResult = resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning);
- if (symbolAccesibilityResult.accessibility === 0 /* Accessible */) {
- if (symbolAccesibilityResult && symbolAccesibilityResult.aliasesToMakeVisible) {
- writeAsychronousImportDeclarations(symbolAccesibilityResult.aliasesToMakeVisible);
- }
- }
- else {
- reportedDeclarationError = true;
- var errorInfo = getSymbolVisibilityDiagnosticMessage(symbolAccesibilityResult);
- if (errorInfo) {
- if (errorInfo.typeName) {
- diagnostics.push(ts.createDiagnosticForNode(errorInfo.errorNode, errorInfo.diagnosticMessage, getSourceTextOfLocalNode(errorInfo.typeName), symbolAccesibilityResult.errorSymbolName, symbolAccesibilityResult.errorModuleName));
- }
- else {
- diagnostics.push(ts.createDiagnosticForNode(errorInfo.errorNode, errorInfo.diagnosticMessage, symbolAccesibilityResult.errorSymbolName, symbolAccesibilityResult.errorModuleName));
- }
- }
- }
- }
- function emitLines(nodes) {
- for (var i = 0, n = nodes.length; i < n; i++) {
- emitNode(nodes[i]);
- }
- }
- function emitCommaList(nodes, eachNodeEmitFn) {
- var currentWriterPos = writer.getTextPos();
- for (var i = 0, n = nodes.length; i < n; i++) {
- if (currentWriterPos !== writer.getTextPos()) {
- write(", ");
- }
- currentWriterPos = writer.getTextPos();
- eachNodeEmitFn(nodes[i]);
- }
- }
- function writeJsDocComments(declaration) {
- if (declaration) {
- var jsDocComments = ts.getJsDocComments(declaration, currentSourceFile);
- emitNewLineBeforeLeadingComments(declaration, jsDocComments, writer);
- emitComments(jsDocComments, true, writer, writeCommentRange);
- }
- }
- function emitSourceTextOfNode(node) {
- write(getSourceTextOfLocalNode(node));
- }
- function emitSourceFile(node) {
- currentSourceFile = node;
- enclosingDeclaration = node;
- emitLines(node.statements);
- }
- function emitExportAssignment(node) {
- write("export = ");
- emitSourceTextOfNode(node.exportName);
- write(";");
- writeLine();
- }
- function emitDeclarationFlags(node) {
- if (node.flags & 128 /* Static */) {
- if (node.flags & 32 /* Private */) {
- write("private ");
- }
- else if (node.flags & 64 /* Protected */) {
- write("protected ");
- }
- write("static ");
- }
- else {
- if (node.flags & 32 /* Private */) {
- write("private ");
- }
- else if (node.flags & 64 /* Protected */) {
- write("protected ");
- }
- else if (node.parent === currentSourceFile) {
- if (node.flags & 1 /* Export */) {
- write("export ");
- }
- if (node.kind !== 188 /* InterfaceDeclaration */) {
- write("declare ");
- }
- }
- }
- }
- function emitImportDeclaration(node) {
- var nodeEmitInfo = {
- declaration: node,
- outputPos: writer.getTextPos(),
- indent: writer.getIndent(),
- hasWritten: resolver.isDeclarationVisible(node)
- };
- aliasDeclarationEmitInfo.push(nodeEmitInfo);
- if (nodeEmitInfo.hasWritten) {
- writeImportDeclaration(node);
- }
- }
- function writeImportDeclaration(node) {
- emitJsDocComments(node);
- if (node.flags & 1 /* Export */) {
- writer.write("export ");
- }
- writer.write("import ");
- writer.write(getSourceTextOfLocalNode(node.name));
- writer.write(" = ");
- if (node.entityName) {
- checkEntityNameAccessible();
- writer.write(getSourceTextOfLocalNode(node.entityName));
- writer.write(";");
- }
- else {
- writer.write("require(");
- writer.write(getSourceTextOfLocalNode(node.externalModuleName));
- writer.write(");");
- }
- writer.writeLine();
- function checkEntityNameAccessible() {
- var symbolAccesibilityResult = resolver.isImportDeclarationEntityNameReferenceDeclarationVisibile(node.entityName);
- if (symbolAccesibilityResult.accessibility === 0 /* Accessible */) {
- if (symbolAccesibilityResult.aliasesToMakeVisible) {
- writeAsychronousImportDeclarations(symbolAccesibilityResult.aliasesToMakeVisible);
- }
- }
- else {
- reportedDeclarationError = true;
- diagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.Import_declaration_0_is_using_private_name_1, getSourceTextOfLocalNode(node.name), symbolAccesibilityResult.errorSymbolName));
- }
- }
- }
- function emitModuleDeclaration(node) {
- if (resolver.isDeclarationVisible(node)) {
- emitJsDocComments(node);
- emitDeclarationFlags(node);
- write("module ");
- emitSourceTextOfNode(node.name);
- while (node.body.kind !== 192 /* ModuleBlock */) {
- node = node.body;
- write(".");
- emitSourceTextOfNode(node.name);
- }
- var prevEnclosingDeclaration = enclosingDeclaration;
- enclosingDeclaration = node;
- write(" {");
- writeLine();
- increaseIndent();
- emitLines(node.body.statements);
- decreaseIndent();
- write("}");
- writeLine();
- enclosingDeclaration = prevEnclosingDeclaration;
- }
- }
- function emitTypeAliasDeclaration(node) {
- if (resolver.isDeclarationVisible(node)) {
- emitJsDocComments(node);
- emitDeclarationFlags(node);
- write("type ");
- emitSourceTextOfNode(node.name);
- write(" = ");
- getSymbolVisibilityDiagnosticMessage = getTypeAliasDeclarationVisibilityError;
- resolver.writeTypeAtLocation(node.type, enclosingDeclaration, 2 /* UseTypeOfFunction */, writer);
- write(";");
- writeLine();
- }
- function getTypeAliasDeclarationVisibilityError(symbolAccesibilityResult) {
- var diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Exported_type_alias_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Exported_type_alias_0_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Exported_type_alias_0_has_or_is_using_private_name_1;
- return {
- diagnosticMessage: diagnosticMessage,
- errorNode: node,
- typeName: node.name
- };
- }
- }
- function emitEnumDeclaration(node) {
- if (resolver.isDeclarationVisible(node)) {
- emitJsDocComments(node);
- emitDeclarationFlags(node);
- if (ts.isConstEnumDeclaration(node)) {
- write("const ");
- }
- write("enum ");
- emitSourceTextOfNode(node.name);
- write(" {");
- writeLine();
- increaseIndent();
- emitLines(node.members);
- decreaseIndent();
- write("}");
- writeLine();
- }
- }
- function emitEnumMemberDeclaration(node) {
- emitJsDocComments(node);
- emitSourceTextOfNode(node.name);
- var enumMemberValue = resolver.getEnumMemberValue(node);
- if (enumMemberValue !== undefined) {
- write(" = ");
- write(enumMemberValue.toString());
- }
- write(",");
- writeLine();
- }
- function emitTypeParameters(typeParameters) {
- function emitTypeParameter(node) {
- function getTypeParameterConstraintVisibilityError(symbolAccesibilityResult) {
- var diagnosticMessage;
- switch (node.parent.kind) {
- case 187 /* ClassDeclaration */:
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Type_parameter_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Type_parameter_0_of_exported_class_has_or_is_using_private_name_1;
- break;
- case 188 /* InterfaceDeclaration */:
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1;
- break;
- case 130 /* ConstructSignature */:
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1;
- break;
- case 129 /* CallSignature */:
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1;
- break;
- case 125 /* Method */:
- if (node.parent.flags & 128 /* Static */) {
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1;
- }
- else if (node.parent.parent.kind === 187 /* ClassDeclaration */) {
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1;
- }
- else {
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Type_parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1;
- }
- break;
- case 185 /* FunctionDeclaration */:
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_private_name_1;
- break;
- default:
- ts.Debug.fail("This is unknown parent for type parameter: " + node.parent.kind);
- }
- return {
- diagnosticMessage: diagnosticMessage,
- errorNode: node,
- typeName: node.name
- };
- }
- increaseIndent();
- emitJsDocComments(node);
- decreaseIndent();
- emitSourceTextOfNode(node.name);
- if (node.constraint && (node.parent.kind !== 125 /* Method */ || !(node.parent.flags & 32 /* Private */))) {
- write(" extends ");
- getSymbolVisibilityDiagnosticMessage = getTypeParameterConstraintVisibilityError;
- resolver.writeTypeAtLocation(node.constraint, enclosingDeclaration, 2 /* UseTypeOfFunction */, writer);
- }
- }
- if (typeParameters) {
- write("<");
- emitCommaList(typeParameters, emitTypeParameter);
- write(">");
- }
- }
- function emitHeritageClause(typeReferences, isImplementsList) {
- if (typeReferences) {
- write(isImplementsList ? " implements " : " extends ");
- emitCommaList(typeReferences, emitTypeOfTypeReference);
- }
- function emitTypeOfTypeReference(node) {
- getSymbolVisibilityDiagnosticMessage = getHeritageClauseVisibilityError;
- resolver.writeTypeAtLocation(node, enclosingDeclaration, 1 /* WriteArrayAsGenericType */ | 2 /* UseTypeOfFunction */, writer);
- function getHeritageClauseVisibilityError(symbolAccesibilityResult) {
- var diagnosticMessage;
- if (node.parent.kind === 187 /* ClassDeclaration */) {
- if (symbolAccesibilityResult.errorModuleName) {
- diagnosticMessage = isImplementsList ? ts.Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Extends_clause_of_exported_class_0_has_or_is_using_name_1_from_private_module_2;
- }
- else {
- diagnosticMessage = isImplementsList ? ts.Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_private_name_1 : ts.Diagnostics.Extends_clause_of_exported_class_0_has_or_is_using_private_name_1;
- }
- }
- else {
- if (symbolAccesibilityResult.errorModuleName) {
- diagnosticMessage = ts.Diagnostics.Extends_clause_of_exported_interface_0_has_or_is_using_name_1_from_private_module_2;
- }
- else {
- diagnosticMessage = ts.Diagnostics.Extends_clause_of_exported_interface_0_has_or_is_using_private_name_1;
- }
- }
- return {
- diagnosticMessage: diagnosticMessage,
- errorNode: node,
- typeName: node.parent.name
- };
- }
- }
- }
- function emitClassDeclaration(node) {
- function emitParameterProperties(constructorDeclaration) {
- if (constructorDeclaration) {
- ts.forEach(constructorDeclaration.parameters, function (param) {
- if (param.flags & 112 /* AccessibilityModifier */) {
- emitPropertyDeclaration(param);
- }
- });
- }
- }
- if (resolver.isDeclarationVisible(node)) {
- emitJsDocComments(node);
- emitDeclarationFlags(node);
- write("class ");
- emitSourceTextOfNode(node.name);
- var prevEnclosingDeclaration = enclosingDeclaration;
- enclosingDeclaration = node;
- emitTypeParameters(node.typeParameters);
- if (node.baseType) {
- emitHeritageClause([node.baseType], false);
- }
- emitHeritageClause(node.implementedTypes, true);
- write(" {");
- writeLine();
- increaseIndent();
- emitParameterProperties(getFirstConstructorWithBody(node));
- emitLines(node.members);
- decreaseIndent();
- write("}");
- writeLine();
- enclosingDeclaration = prevEnclosingDeclaration;
- }
- }
- function emitInterfaceDeclaration(node) {
- if (resolver.isDeclarationVisible(node)) {
- emitJsDocComments(node);
- emitDeclarationFlags(node);
- write("interface ");
- emitSourceTextOfNode(node.name);
- var prevEnclosingDeclaration = enclosingDeclaration;
- enclosingDeclaration = node;
- emitTypeParameters(node.typeParameters);
- emitHeritageClause(node.baseTypes, false);
- write(" {");
- writeLine();
- increaseIndent();
- emitLines(node.members);
- decreaseIndent();
- write("}");
- writeLine();
- enclosingDeclaration = prevEnclosingDeclaration;
- }
- }
- function emitPropertyDeclaration(node) {
- emitJsDocComments(node);
- emitDeclarationFlags(node);
- emitVariableDeclaration(node);
- write(";");
- writeLine();
- }
- function emitVariableDeclaration(node) {
- if (node.kind !== 184 /* VariableDeclaration */ || resolver.isDeclarationVisible(node)) {
- emitSourceTextOfNode(node.name);
- if (node.kind === 124 /* Property */ && (node.flags & 4 /* QuestionMark */)) {
- write("?");
- }
- if (!(node.flags & 32 /* Private */)) {
- write(": ");
- getSymbolVisibilityDiagnosticMessage = getVariableDeclarationTypeVisibilityError;
- resolver.writeTypeAtLocation(node, enclosingDeclaration, 2 /* UseTypeOfFunction */, writer);
- }
- }
- function getVariableDeclarationTypeVisibilityError(symbolAccesibilityResult) {
- var diagnosticMessage;
- if (node.kind === 184 /* VariableDeclaration */) {
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Exported_variable_0_has_or_is_using_private_name_1;
- }
- else if (node.kind === 124 /* Property */) {
- if (node.flags & 128 /* Static */) {
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_private_name_1;
- }
- else if (node.parent.kind === 187 /* ClassDeclaration */) {
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_private_name_1;
- }
- else {
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Property_0_of_exported_interface_has_or_is_using_private_name_1;
- }
- }
- return diagnosticMessage !== undefined ? {
- diagnosticMessage: diagnosticMessage,
- errorNode: node,
- typeName: node.name
- } : undefined;
- }
- }
- function emitVariableStatement(node) {
- var hasDeclarationWithEmit = ts.forEach(node.declarations, function (varDeclaration) { return resolver.isDeclarationVisible(varDeclaration); });
- if (hasDeclarationWithEmit) {
- emitJsDocComments(node);
- emitDeclarationFlags(node);
- if (node.flags & 2048 /* Let */) {
- write("let ");
- }
- else if (node.flags & 4096 /* Const */) {
- write("const ");
- }
- else {
- write("var ");
- }
- emitCommaList(node.declarations, emitVariableDeclaration);
- write(";");
- writeLine();
- }
- }
- function emitAccessorDeclaration(node) {
- var accessors = getAllAccessorDeclarations(node.parent, node);
- if (node === accessors.firstAccessor) {
- emitJsDocComments(accessors.getAccessor);
- emitJsDocComments(accessors.setAccessor);
- emitDeclarationFlags(node);
- emitSourceTextOfNode(node.name);
- if (!(node.flags & 32 /* Private */)) {
- write(": ");
- getSymbolVisibilityDiagnosticMessage = getAccessorDeclarationTypeVisibilityError;
- resolver.writeTypeAtLocation(node, enclosingDeclaration, 2 /* UseTypeOfFunction */, writer);
- }
- write(";");
- writeLine();
- }
- function getAccessorDeclarationTypeVisibilityError(symbolAccesibilityResult) {
- var diagnosticMessage;
- if (node.kind === 128 /* SetAccessor */) {
- if (node.parent.flags & 128 /* Static */) {
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_private_name_1;
- }
- else {
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_private_name_1;
- }
- return {
- diagnosticMessage: diagnosticMessage,
- errorNode: node.parameters[0],
- typeName: node.name
- };
- }
- else {
- if (node.flags & 128 /* Static */) {
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_private_name_0;
- }
- else {
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_private_name_0;
- }
- return {
- diagnosticMessage: diagnosticMessage,
- errorNode: node.name,
- typeName: undefined
- };
- }
- }
- }
- function emitFunctionDeclaration(node) {
- if ((node.kind !== 185 /* FunctionDeclaration */ || resolver.isDeclarationVisible(node)) && !resolver.isImplementationOfOverload(node)) {
- emitJsDocComments(node);
- emitDeclarationFlags(node);
- if (node.kind === 185 /* FunctionDeclaration */) {
- write("function ");
- emitSourceTextOfNode(node.name);
- }
- else if (node.kind === 126 /* Constructor */) {
- write("constructor");
- }
- else {
- emitSourceTextOfNode(node.name);
- if (node.flags & 4 /* QuestionMark */) {
- write("?");
- }
- }
- emitSignatureDeclaration(node);
- }
- }
- function emitConstructSignatureDeclaration(node) {
- emitJsDocComments(node);
- write("new ");
- emitSignatureDeclaration(node);
- }
- function emitSignatureDeclaration(node) {
- if (node.kind === 129 /* CallSignature */ || node.kind === 131 /* IndexSignature */) {
- emitJsDocComments(node);
- }
- emitTypeParameters(node.typeParameters);
- if (node.kind === 131 /* IndexSignature */) {
- write("[");
- }
- else {
- write("(");
- }
- emitCommaList(node.parameters, emitParameterDeclaration);
- if (node.kind === 131 /* IndexSignature */) {
- write("]");
- }
- else {
- write(")");
- }
- if (node.kind !== 126 /* Constructor */ && !(node.flags & 32 /* Private */)) {
- write(": ");
- getSymbolVisibilityDiagnosticMessage = getReturnTypeVisibilityError;
- resolver.writeReturnTypeOfSignatureDeclaration(node, enclosingDeclaration, 2 /* UseTypeOfFunction */, writer);
- }
- write(";");
- writeLine();
- function getReturnTypeVisibilityError(symbolAccesibilityResult) {
- var diagnosticMessage;
- switch (node.kind) {
- case 130 /* ConstructSignature */:
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_0;
- break;
- case 129 /* CallSignature */:
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_private_name_0;
- break;
- case 131 /* IndexSignature */:
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_private_name_0;
- break;
- case 125 /* Method */:
- if (node.flags & 128 /* Static */) {
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_private_name_0;
- }
- else if (node.parent.kind === 187 /* ClassDeclaration */) {
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_private_name_0;
- }
- else {
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_private_name_0;
- }
- break;
- case 185 /* FunctionDeclaration */:
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_private_name_0;
- break;
- default:
- ts.Debug.fail("This is unknown kind for signature: " + node.kind);
- }
- return {
- diagnosticMessage: diagnosticMessage,
- errorNode: node.name || node
- };
- }
- }
- function emitParameterDeclaration(node) {
- increaseIndent();
- emitJsDocComments(node);
- if (node.flags & 8 /* Rest */) {
- write("...");
- }
- emitSourceTextOfNode(node.name);
- if (node.initializer || (node.flags & 4 /* QuestionMark */)) {
- write("?");
- }
- decreaseIndent();
- if (!(node.parent.flags & 32 /* Private */)) {
- write(": ");
- getSymbolVisibilityDiagnosticMessage = getParameterDeclarationTypeVisibilityError;
- resolver.writeTypeAtLocation(node, enclosingDeclaration, 2 /* UseTypeOfFunction */, writer);
- }
- function getParameterDeclarationTypeVisibilityError(symbolAccesibilityResult) {
- var diagnosticMessage;
- switch (node.parent.kind) {
- case 126 /* Constructor */:
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_private_name_1;
- break;
- case 130 /* ConstructSignature */:
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1;
- break;
- case 129 /* CallSignature */:
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1;
- break;
- case 125 /* Method */:
- if (node.parent.flags & 128 /* Static */) {
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1;
- }
- else if (node.parent.parent.kind === 187 /* ClassDeclaration */) {
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1;
- }
- else {
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1;
- }
- break;
- case 185 /* FunctionDeclaration */:
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_private_name_1;
- break;
- default:
- ts.Debug.fail("This is unknown parent for parameter: " + node.parent.kind);
- }
- return {
- diagnosticMessage: diagnosticMessage,
- errorNode: node,
- typeName: node.name
- };
- }
- }
- function emitNode(node) {
- switch (node.kind) {
- case 126 /* Constructor */:
- case 185 /* FunctionDeclaration */:
- case 125 /* Method */:
- return emitFunctionDeclaration(node);
- case 130 /* ConstructSignature */:
- return emitConstructSignatureDeclaration(node);
- case 129 /* CallSignature */:
- case 131 /* IndexSignature */:
- return emitSignatureDeclaration(node);
- case 127 /* GetAccessor */:
- case 128 /* SetAccessor */:
- return emitAccessorDeclaration(node);
- case 162 /* VariableStatement */:
- return emitVariableStatement(node);
- case 124 /* Property */:
- return emitPropertyDeclaration(node);
- case 188 /* InterfaceDeclaration */:
- return emitInterfaceDeclaration(node);
- case 187 /* ClassDeclaration */:
- return emitClassDeclaration(node);
- case 189 /* TypeAliasDeclaration */:
- return emitTypeAliasDeclaration(node);
- case 195 /* EnumMember */:
- return emitEnumMemberDeclaration(node);
- case 190 /* EnumDeclaration */:
- return emitEnumDeclaration(node);
- case 191 /* ModuleDeclaration */:
- return emitModuleDeclaration(node);
- case 193 /* ImportDeclaration */:
- return emitImportDeclaration(node);
- case 194 /* ExportAssignment */:
- return emitExportAssignment(node);
- case 196 /* SourceFile */:
- return emitSourceFile(node);
- }
- }
- function tryResolveScriptReference(sourceFile, reference) {
- var referenceFileName = ts.normalizePath(ts.combinePaths(ts.getDirectoryPath(sourceFile.filename), reference.filename));
- return program.getSourceFile(referenceFileName);
- }
- var referencePathsOutput = "";
- function writeReferencePath(referencedFile) {
- var declFileName = referencedFile.flags & 1024 /* DeclarationFile */ ? referencedFile.filename : shouldEmitToOwnFile(referencedFile, compilerOptions) ? getOwnEmitOutputFilePath(referencedFile, ".d.ts") : ts.removeFileExtension(compilerOptions.out) + ".d.ts";
- declFileName = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizeSlashes(jsFilePath)), declFileName, compilerHost.getCurrentDirectory(), compilerHost.getCanonicalFileName, false);
- referencePathsOutput += "/// " + newLine;
- }
- if (root) {
- if (!compilerOptions.noResolve) {
- var addedGlobalFileReference = false;
- ts.forEach(root.referencedFiles, function (fileReference) {
- var referencedFile = tryResolveScriptReference(root, fileReference);
- if (referencedFile && ((referencedFile.flags & 1024 /* DeclarationFile */) || shouldEmitToOwnFile(referencedFile, compilerOptions) || !addedGlobalFileReference)) {
- writeReferencePath(referencedFile);
- if (!isExternalModuleOrDeclarationFile(referencedFile)) {
- addedGlobalFileReference = true;
- }
- }
- });
- }
- emitNode(root);
- }
- else {
- var emittedReferencedFiles = [];
- ts.forEach(program.getSourceFiles(), function (sourceFile) {
- if (!isExternalModuleOrDeclarationFile(sourceFile)) {
- if (!compilerOptions.noResolve) {
- ts.forEach(sourceFile.referencedFiles, function (fileReference) {
- var referencedFile = tryResolveScriptReference(sourceFile, fileReference);
- if (referencedFile && (isExternalModuleOrDeclarationFile(referencedFile) && !ts.contains(emittedReferencedFiles, referencedFile))) {
- writeReferencePath(referencedFile);
- emittedReferencedFiles.push(referencedFile);
- }
- });
- }
- emitNode(sourceFile);
- }
- });
- }
- if (!reportedDeclarationError) {
- var declarationOutput = referencePathsOutput;
- var synchronousDeclarationOutput = writer.getText();
+ function writeDeclarationFile(jsFilePath, sourceFile) {
+ var emitDeclarationResult = emitDeclarations(program, resolver, diagnostics, jsFilePath, sourceFile);
+ if (!emitDeclarationResult.reportedDeclarationError) {
+ var declarationOutput = emitDeclarationResult.referencePathsOutput;
var appliedSyncOutputPos = 0;
- ts.forEach(aliasDeclarationEmitInfo, function (aliasEmitInfo) {
+ ts.forEach(emitDeclarationResult.aliasDeclarationEmitInfo, function (aliasEmitInfo) {
if (aliasEmitInfo.asynchronousOutput) {
- declarationOutput += synchronousDeclarationOutput.substring(appliedSyncOutputPos, aliasEmitInfo.outputPos);
+ declarationOutput += emitDeclarationResult.synchronousDeclarationOutput.substring(appliedSyncOutputPos, aliasEmitInfo.outputPos);
declarationOutput += aliasEmitInfo.asynchronousOutput;
appliedSyncOutputPos = aliasEmitInfo.outputPos;
}
});
- declarationOutput += synchronousDeclarationOutput.substring(appliedSyncOutputPos);
- writeFile(ts.removeFileExtension(jsFilePath) + ".d.ts", declarationOutput, compilerOptions.emitBOM);
+ declarationOutput += emitDeclarationResult.synchronousDeclarationOutput.substring(appliedSyncOutputPos);
+ writeFile(compilerHost, diagnostics, ts.removeFileExtension(jsFilePath) + ".d.ts", declarationOutput, compilerOptions.emitBOM);
}
}
var hasSemanticErrors = resolver.hasSemanticErrors();
@@ -9035,14 +9580,14 @@ var ts;
if (!isEmitBlocked) {
emitJavaScript(jsFilePath, sourceFile);
if (!hasSemanticErrors && compilerOptions.declaration) {
- emitDeclarations(jsFilePath, sourceFile);
+ writeDeclarationFile(jsFilePath, sourceFile);
}
}
}
if (targetSourceFile === undefined) {
ts.forEach(program.getSourceFiles(), function (sourceFile) {
if (shouldEmitToOwnFile(sourceFile, compilerOptions)) {
- var jsFilePath = getOwnEmitOutputFilePath(sourceFile, ".js");
+ var jsFilePath = getOwnEmitOutputFilePath(sourceFile, program, ".js");
emitFile(jsFilePath, sourceFile);
}
});
@@ -9052,7 +9597,7 @@ var ts;
}
else {
if (shouldEmitToOwnFile(targetSourceFile, compilerOptions)) {
- var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, ".js");
+ var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, program, ".js");
emitFile(jsFilePath, targetSourceFile);
}
else if (!ts.isDeclarationFile(targetSourceFile) && compilerOptions.out) {
@@ -9145,10 +9690,11 @@ var ts;
getTypeCount: function () { return typeCount; },
isUndefinedSymbol: function (symbol) { return symbol === undefinedSymbol; },
isArgumentsSymbol: function (symbol) { return symbol === argumentsSymbol; },
+ emitFiles: invokeEmitter,
getDiagnostics: getDiagnostics,
+ getDeclarationDiagnostics: getDeclarationDiagnostics,
getGlobalDiagnostics: getGlobalDiagnostics,
checkProgram: checkProgram,
- invokeEmitter: invokeEmitter,
getParentOfSymbol: getParentOfSymbol,
getNarrowedTypeOfSymbol: getNarrowedTypeOfSymbol,
getDeclaredTypeOfSymbol: getDeclaredTypeOfSymbol,
@@ -9354,10 +9900,10 @@ var ts;
return nodeLinks[node.id] || (nodeLinks[node.id] = {});
}
function getSourceFile(node) {
- return ts.getAncestor(node, 196 /* SourceFile */);
+ return ts.getAncestor(node, 197 /* SourceFile */);
}
function isGlobalSourceFile(node) {
- return node.kind === 196 /* SourceFile */ && !ts.isExternalModule(node);
+ return node.kind === 197 /* SourceFile */ && !ts.isExternalModule(node);
}
function getSymbol(symbols, name, meaning) {
if (meaning && ts.hasProperty(symbols, name)) {
@@ -9398,21 +9944,21 @@ var ts;
}
}
switch (location.kind) {
- case 196 /* SourceFile */:
+ case 197 /* SourceFile */:
if (!ts.isExternalModule(location))
break;
- case 191 /* ModuleDeclaration */:
+ case 192 /* ModuleDeclaration */:
if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 35653619 /* ModuleMember */)) {
break loop;
}
break;
- case 190 /* EnumDeclaration */:
+ case 191 /* EnumDeclaration */:
if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 8 /* EnumMember */)) {
break loop;
}
break;
case 124 /* Property */:
- if (location.parent.kind === 187 /* ClassDeclaration */ && !(location.flags & 128 /* Static */)) {
+ if (location.parent.kind === 188 /* ClassDeclaration */ && !(location.flags & 128 /* Static */)) {
var ctor = findConstructorDeclaration(location.parent);
if (ctor && ctor.locals) {
if (getSymbol(ctor.locals, name, meaning & 107455 /* Value */)) {
@@ -9421,8 +9967,8 @@ var ts;
}
}
break;
- case 187 /* ClassDeclaration */:
- case 188 /* InterfaceDeclaration */:
+ case 188 /* ClassDeclaration */:
+ case 189 /* InterfaceDeclaration */:
if (result = getSymbol(getSymbolOfNode(location).members, name, meaning & 3152352 /* Type */)) {
if (lastLocation && lastLocation.flags & 128 /* Static */) {
error(errorLocation, ts.Diagnostics.Static_members_cannot_reference_class_type_parameters);
@@ -9435,7 +9981,7 @@ var ts;
case 126 /* Constructor */:
case 127 /* GetAccessor */:
case 128 /* SetAccessor */:
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
case 153 /* ArrowFunction */:
if (name === "arguments") {
result = argumentsSymbol;
@@ -9453,7 +9999,7 @@ var ts;
break loop;
}
break;
- case 181 /* CatchBlock */:
+ case 182 /* CatchBlock */:
var id = location.variable;
if (name === id.text) {
result = location.symbol;
@@ -9494,7 +10040,7 @@ var ts;
var links = getSymbolLinks(symbol);
if (!links.target) {
links.target = resolvingSymbol;
- var node = getDeclarationOfKind(symbol, 193 /* ImportDeclaration */);
+ var node = getDeclarationOfKind(symbol, 194 /* ImportDeclaration */);
var target = node.externalModuleName ? resolveExternalModuleName(node, node.externalModuleName) : getSymbolOfPartOfRightHandSideOfImport(node.entityName, node);
if (links.target === resolvingSymbol) {
links.target = target || unknownSymbol;
@@ -9510,7 +10056,7 @@ var ts;
}
function getSymbolOfPartOfRightHandSideOfImport(entityName, importDeclaration) {
if (!importDeclaration) {
- importDeclaration = ts.getAncestor(entityName, 193 /* ImportDeclaration */);
+ importDeclaration = ts.getAncestor(entityName, 194 /* ImportDeclaration */);
ts.Debug.assert(importDeclaration !== undefined);
}
if (entityName.kind === 63 /* Identifier */ && isRightSideOfQualifiedNameOrPropertyAccess(entityName)) {
@@ -9520,7 +10066,7 @@ var ts;
return resolveEntityName(importDeclaration, entityName, 1536 /* Namespace */);
}
else {
- ts.Debug.assert(entityName.parent.kind === 193 /* ImportDeclaration */);
+ ts.Debug.assert(entityName.parent.kind === 194 /* ImportDeclaration */);
return resolveEntityName(importDeclaration, entityName, 107455 /* Value */ | 3152352 /* Type */ | 1536 /* Namespace */);
}
}
@@ -9625,9 +10171,9 @@ var ts;
var seenExportedMember = false;
var result = [];
ts.forEach(symbol.declarations, function (declaration) {
- var block = (declaration.kind === 196 /* SourceFile */ ? declaration : declaration.body);
+ var block = (declaration.kind === 197 /* SourceFile */ ? declaration : declaration.body);
ts.forEach(block.statements, function (node) {
- if (node.kind === 194 /* ExportAssignment */) {
+ if (node.kind === 195 /* ExportAssignment */) {
result.push(node);
}
else {
@@ -9734,17 +10280,17 @@ var ts;
}
}
switch (location.kind) {
- case 196 /* SourceFile */:
+ case 197 /* SourceFile */:
if (!ts.isExternalModule(location)) {
break;
}
- case 191 /* ModuleDeclaration */:
+ case 192 /* ModuleDeclaration */:
if (result = callback(getSymbolOfNode(location).exports)) {
return result;
}
break;
- case 187 /* ClassDeclaration */:
- case 188 /* InterfaceDeclaration */:
+ case 188 /* ClassDeclaration */:
+ case 189 /* InterfaceDeclaration */:
if (result = callback(getSymbolOfNode(location).members)) {
return result;
}
@@ -9775,7 +10321,7 @@ var ts;
}
return ts.forEachValue(symbols, function (symbolFromSymbolTable) {
if (symbolFromSymbolTable.flags & 33554432 /* Import */) {
- if (!useOnlyExternalAliasing || ts.forEach(symbolFromSymbolTable.declarations, function (declaration) { return declaration.kind === 193 /* ImportDeclaration */ && declaration.externalModuleName; })) {
+ if (!useOnlyExternalAliasing || ts.forEach(symbolFromSymbolTable.declarations, function (declaration) { return declaration.kind === 194 /* ImportDeclaration */ && declaration.externalModuleName; })) {
var resolvedImportedSymbol = resolveImport(symbolFromSymbolTable);
if (isAccessible(symbolFromSymbolTable, resolveImport(symbolFromSymbolTable))) {
return [symbolFromSymbolTable];
@@ -9826,7 +10372,7 @@ var ts;
errorModuleName: symbol !== initialSymbol ? symbolToString(symbol, enclosingDeclaration, 1536 /* Namespace */) : undefined
};
}
- return { accessibility: 0 /* Accessible */, aliasesToMakeVisible: hasAccessibleDeclarations.aliasesToMakeVisible };
+ return hasAccessibleDeclarations;
}
meaningToLook = getQualifiedLeftMeaning(meaning);
symbol = getParentOfSymbol(symbol);
@@ -9857,17 +10403,17 @@ var ts;
}
}
function hasExternalModuleSymbol(declaration) {
- return (declaration.kind === 191 /* ModuleDeclaration */ && declaration.name.kind === 7 /* StringLiteral */) || (declaration.kind === 196 /* SourceFile */ && ts.isExternalModule(declaration));
+ return (declaration.kind === 192 /* ModuleDeclaration */ && declaration.name.kind === 7 /* StringLiteral */) || (declaration.kind === 197 /* SourceFile */ && ts.isExternalModule(declaration));
}
function hasVisibleDeclarations(symbol) {
var aliasesToMakeVisible;
if (ts.forEach(symbol.declarations, function (declaration) { return !getIsDeclarationVisible(declaration); })) {
return undefined;
}
- return { aliasesToMakeVisible: aliasesToMakeVisible };
+ return { accessibility: 0 /* Accessible */, aliasesToMakeVisible: aliasesToMakeVisible };
function getIsDeclarationVisible(declaration) {
if (!isDeclarationVisible(declaration)) {
- if (declaration.kind === 193 /* ImportDeclaration */ && !(declaration.flags & 1 /* Export */) && isDeclarationVisible(declaration.parent)) {
+ if (declaration.kind === 194 /* ImportDeclaration */ && !(declaration.flags & 1 /* Export */) && isDeclarationVisible(declaration.parent)) {
getNodeLinks(declaration).isVisible = true;
if (aliasesToMakeVisible) {
if (!ts.contains(aliasesToMakeVisible, declaration)) {
@@ -9884,11 +10430,24 @@ var ts;
return true;
}
}
- function isImportDeclarationEntityNameReferenceDeclarationVisibile(entityName) {
+ function isEntityNameVisible(entityName, enclosingDeclaration) {
+ var meaning;
+ if (entityName.parent.kind === 135 /* TypeQuery */) {
+ meaning = 107455 /* Value */ | 4194304 /* ExportValue */;
+ }
+ else if (entityName.kind === 121 /* QualifiedName */ || entityName.parent.kind === 194 /* ImportDeclaration */) {
+ meaning = 1536 /* Namespace */;
+ }
+ else {
+ meaning = 3152352 /* Type */;
+ }
var firstIdentifier = getFirstIdentifier(entityName);
- var symbolOfNameSpace = resolveName(entityName.parent, firstIdentifier.text, 1536 /* Namespace */, ts.Diagnostics.Cannot_find_name_0, firstIdentifier);
- var hasNamespaceDeclarationsVisibile = hasVisibleDeclarations(symbolOfNameSpace);
- return hasNamespaceDeclarationsVisibile ? { accessibility: 0 /* Accessible */, aliasesToMakeVisible: hasNamespaceDeclarationsVisibile.aliasesToMakeVisible } : { accessibility: 1 /* NotAccessible */, errorSymbolName: ts.declarationNameToString(firstIdentifier) };
+ var symbol = resolveName(enclosingDeclaration, firstIdentifier.text, meaning, undefined, undefined);
+ return hasVisibleDeclarations(symbol) || {
+ accessibility: 1 /* NotAccessible */,
+ errorSymbolName: ts.getTextOfNode(firstIdentifier),
+ errorNode: firstIdentifier
+ };
}
function releaseStringWriter(writer) {
writer.clear();
@@ -9930,7 +10489,7 @@ var ts;
while (node.kind === 140 /* ParenType */) {
node = node.parent;
}
- if (node.kind === 189 /* TypeAliasDeclaration */) {
+ if (node.kind === 190 /* TypeAliasDeclaration */) {
return getSymbolOfNode(node);
}
}
@@ -10093,7 +10652,7 @@ var ts;
function shouldWriteTypeOfFunctionSymbol() {
if (type.symbol) {
var isStaticMethodSymbol = !!(type.symbol.flags & 8192 /* Method */ && ts.forEach(type.symbol.declarations, function (declaration) { return declaration.flags & 128 /* Static */; }));
- var isNonLocalFunctionSymbol = !!(type.symbol.flags & 16 /* Function */) && (type.symbol.parent || ts.forEach(type.symbol.declarations, function (declaration) { return declaration.parent.kind === 196 /* SourceFile */ || declaration.parent.kind === 192 /* ModuleBlock */; }));
+ var isNonLocalFunctionSymbol = !!(type.symbol.flags & 16 /* Function */) && (type.symbol.parent || ts.forEach(type.symbol.declarations, function (declaration) { return declaration.parent.kind === 197 /* SourceFile */ || declaration.parent.kind === 193 /* ModuleBlock */; }));
if (isStaticMethodSymbol || isNonLocalFunctionSymbol) {
return !!(flags & 2 /* UseTypeOfFunction */) || (typeStack && ts.contains(typeStack, type));
}
@@ -10312,12 +10871,12 @@ var ts;
function isDeclarationVisible(node) {
function getContainingExternalModule(node) {
for (; node; node = node.parent) {
- if (node.kind === 191 /* ModuleDeclaration */) {
+ if (node.kind === 192 /* ModuleDeclaration */) {
if (node.name.kind === 7 /* StringLiteral */) {
return node;
}
}
- else if (node.kind === 196 /* SourceFile */) {
+ else if (node.kind === 197 /* SourceFile */) {
return ts.isExternalModule(node) ? node : undefined;
}
}
@@ -10359,16 +10918,16 @@ var ts;
}
function determineIfDeclarationIsVisible() {
switch (node.kind) {
- case 184 /* VariableDeclaration */:
- case 191 /* ModuleDeclaration */:
- case 187 /* ClassDeclaration */:
- case 188 /* InterfaceDeclaration */:
- case 189 /* TypeAliasDeclaration */:
- case 185 /* FunctionDeclaration */:
- case 190 /* EnumDeclaration */:
- case 193 /* ImportDeclaration */:
- var parent = node.kind === 184 /* VariableDeclaration */ ? node.parent.parent : node.parent;
- if (!(node.flags & 1 /* Export */) && !(node.kind !== 193 /* ImportDeclaration */ && parent.kind !== 196 /* SourceFile */ && ts.isInAmbientContext(parent))) {
+ case 185 /* VariableDeclaration */:
+ case 192 /* ModuleDeclaration */:
+ case 188 /* ClassDeclaration */:
+ case 189 /* InterfaceDeclaration */:
+ case 190 /* TypeAliasDeclaration */:
+ case 186 /* FunctionDeclaration */:
+ case 191 /* EnumDeclaration */:
+ case 194 /* ImportDeclaration */:
+ var parent = node.kind === 185 /* VariableDeclaration */ ? node.parent.parent : node.parent;
+ if (!(node.flags & 1 /* Export */) && !(node.kind !== 194 /* ImportDeclaration */ && parent.kind !== 197 /* SourceFile */ && ts.isInAmbientContext(parent))) {
return isGlobalSourceFile(parent) || isUsedInExportAssignment(node);
}
return isDeclarationVisible(parent);
@@ -10382,9 +10941,10 @@ var ts;
case 129 /* CallSignature */:
case 131 /* IndexSignature */:
case 123 /* Parameter */:
- case 192 /* ModuleBlock */:
+ case 193 /* ModuleBlock */:
+ case 122 /* TypeParameter */:
return isDeclarationVisible(node.parent);
- case 196 /* SourceFile */:
+ case 197 /* SourceFile */:
return true;
default:
ts.Debug.fail("isDeclarationVisible unknown: SyntaxKind: " + node.kind);
@@ -10403,7 +10963,7 @@ var ts;
return classType.typeParameters ? createTypeReference(classType, ts.map(classType.typeParameters, function (_) { return anyType; })) : classType;
}
function getTypeOfVariableOrPropertyDeclaration(declaration) {
- if (declaration.parent.kind === 169 /* ForInStatement */) {
+ if (declaration.parent.kind === 170 /* ForInStatement */) {
return anyType;
}
if (declaration.type) {
@@ -10470,7 +11030,7 @@ var ts;
return links.type = getTypeOfPrototypeProperty(symbol);
}
var declaration = symbol.valueDeclaration;
- if (declaration.kind === 181 /* CatchBlock */) {
+ if (declaration.kind === 182 /* CatchBlock */) {
return links.type = anyType;
}
links.type = resolvingType;
@@ -10525,7 +11085,7 @@ var ts;
type = setterParameterType;
}
else {
- if (getter) {
+ if (getter && getter.body) {
type = getReturnTypeFromBody(getter);
}
else {
@@ -10610,7 +11170,7 @@ var ts;
function getTypeParametersOfClassOrInterface(symbol) {
var result;
ts.forEach(symbol.declarations, function (node) {
- if (node.kind === 188 /* InterfaceDeclaration */ || node.kind === 187 /* ClassDeclaration */) {
+ if (node.kind === 189 /* InterfaceDeclaration */ || node.kind === 188 /* ClassDeclaration */) {
var declaration = node;
if (declaration.typeParameters && declaration.typeParameters.length) {
ts.forEach(declaration.typeParameters, function (node) {
@@ -10641,7 +11201,7 @@ var ts;
type.typeArguments = type.typeParameters;
}
type.baseTypes = [];
- var declaration = getDeclarationOfKind(symbol, 187 /* ClassDeclaration */);
+ var declaration = getDeclarationOfKind(symbol, 188 /* ClassDeclaration */);
if (declaration.baseType) {
var baseType = getTypeFromTypeReferenceNode(declaration.baseType);
if (baseType !== unknownType) {
@@ -10681,7 +11241,7 @@ var ts;
}
type.baseTypes = [];
ts.forEach(symbol.declarations, function (declaration) {
- if (declaration.kind === 188 /* InterfaceDeclaration */ && declaration.baseTypes) {
+ if (declaration.kind === 189 /* InterfaceDeclaration */ && declaration.baseTypes) {
ts.forEach(declaration.baseTypes, function (node) {
var baseType = getTypeFromTypeReferenceNode(node);
if (baseType !== unknownType) {
@@ -10712,7 +11272,7 @@ var ts;
var links = getSymbolLinks(symbol);
if (!links.declaredType) {
links.declaredType = resolvingType;
- var declaration = getDeclarationOfKind(symbol, 189 /* TypeAliasDeclaration */);
+ var declaration = getDeclarationOfKind(symbol, 190 /* TypeAliasDeclaration */);
var type = getTypeFromTypeNode(declaration.type);
if (links.declaredType === resolvingType) {
links.declaredType = type;
@@ -10720,7 +11280,7 @@ var ts;
}
else if (links.declaredType === resolvingType) {
links.declaredType = unknownType;
- var declaration = getDeclarationOfKind(symbol, 189 /* TypeAliasDeclaration */);
+ var declaration = getDeclarationOfKind(symbol, 190 /* TypeAliasDeclaration */);
error(declaration.name, ts.Diagnostics.Type_alias_0_circularly_references_itself, symbolToString(symbol));
}
return links.declaredType;
@@ -11191,7 +11751,7 @@ var ts;
switch (node.kind) {
case 133 /* FunctionType */:
case 134 /* ConstructorType */:
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
case 125 /* Method */:
case 126 /* Constructor */:
case 129 /* CallSignature */:
@@ -11421,9 +11981,9 @@ var ts;
for (var i = 0; i < declarations.length; i++) {
var declaration = declarations[i];
switch (declaration.kind) {
- case 187 /* ClassDeclaration */:
- case 188 /* InterfaceDeclaration */:
- case 190 /* EnumDeclaration */:
+ case 188 /* ClassDeclaration */:
+ case 189 /* InterfaceDeclaration */:
+ case 191 /* EnumDeclaration */:
return declaration;
}
}
@@ -12732,7 +13292,7 @@ var ts;
switch (node.kind) {
case 156 /* BinaryExpression */:
return isAssignedInBinaryExpression(node);
- case 184 /* VariableDeclaration */:
+ case 185 /* VariableDeclaration */:
return isAssignedInVariableDeclaration(node);
case 141 /* ArrayLiteral */:
case 142 /* ObjectLiteral */:
@@ -12745,25 +13305,25 @@ var ts;
case 154 /* PrefixOperator */:
case 155 /* PostfixOperator */:
case 157 /* ConditionalExpression */:
- case 161 /* Block */:
- case 162 /* VariableStatement */:
- case 164 /* ExpressionStatement */:
- case 165 /* IfStatement */:
- case 166 /* DoStatement */:
- case 167 /* WhileStatement */:
- case 168 /* ForStatement */:
- case 169 /* ForInStatement */:
- case 172 /* ReturnStatement */:
- case 173 /* WithStatement */:
- case 174 /* SwitchStatement */:
- case 175 /* CaseClause */:
- case 176 /* DefaultClause */:
- case 177 /* LabeledStatement */:
- case 178 /* ThrowStatement */:
- case 179 /* TryStatement */:
- case 180 /* TryBlock */:
- case 181 /* CatchBlock */:
- case 182 /* FinallyBlock */:
+ case 162 /* Block */:
+ case 163 /* VariableStatement */:
+ case 165 /* ExpressionStatement */:
+ case 166 /* IfStatement */:
+ case 167 /* DoStatement */:
+ case 168 /* WhileStatement */:
+ case 169 /* ForStatement */:
+ case 170 /* ForInStatement */:
+ case 173 /* ReturnStatement */:
+ case 174 /* WithStatement */:
+ case 175 /* SwitchStatement */:
+ case 176 /* CaseClause */:
+ case 177 /* DefaultClause */:
+ case 178 /* LabeledStatement */:
+ case 179 /* ThrowStatement */:
+ case 180 /* TryStatement */:
+ case 181 /* TryBlock */:
+ case 182 /* CatchBlock */:
+ case 183 /* FinallyBlock */:
return ts.forEachChild(node, isAssignedIn);
}
return false;
@@ -12777,7 +13337,7 @@ var ts;
node = node.parent;
var narrowedType = type;
switch (node.kind) {
- case 165 /* IfStatement */:
+ case 166 /* IfStatement */:
if (child !== node.expression) {
narrowedType = narrowType(type, node.expression, child === node.thenStatement);
}
@@ -12797,9 +13357,9 @@ var ts;
}
}
break;
- case 196 /* SourceFile */:
- case 191 /* ModuleDeclaration */:
- case 185 /* FunctionDeclaration */:
+ case 197 /* SourceFile */:
+ case 192 /* ModuleDeclaration */:
+ case 186 /* FunctionDeclaration */:
case 125 /* Method */:
case 127 /* GetAccessor */:
case 128 /* SetAccessor */:
@@ -12909,7 +13469,7 @@ var ts;
return getNarrowedTypeOfSymbol(getExportSymbolOfValueSymbolIfExported(symbol), node);
}
function captureLexicalThis(node, container) {
- var classNode = container.parent && container.parent.kind === 187 /* ClassDeclaration */ ? container.parent : undefined;
+ var classNode = container.parent && container.parent.kind === 188 /* ClassDeclaration */ ? container.parent : undefined;
getNodeLinks(node).flags |= 2 /* LexicalThis */;
if (container.kind === 124 /* Property */ || container.kind === 126 /* Constructor */) {
getNodeLinks(classNode).flags |= 4 /* CaptureThis */;
@@ -12926,10 +13486,10 @@ var ts;
needToCaptureLexicalThis = true;
}
switch (container.kind) {
- case 191 /* ModuleDeclaration */:
+ case 192 /* ModuleDeclaration */:
error(node, ts.Diagnostics.this_cannot_be_referenced_in_a_module_body);
break;
- case 190 /* EnumDeclaration */:
+ case 191 /* EnumDeclaration */:
error(node, ts.Diagnostics.this_cannot_be_referenced_in_current_location);
break;
case 126 /* Constructor */:
@@ -12946,7 +13506,7 @@ var ts;
if (needToCaptureLexicalThis) {
captureLexicalThis(node, container);
}
- var classNode = container.parent && container.parent.kind === 187 /* ClassDeclaration */ ? container.parent : undefined;
+ var classNode = container.parent && container.parent.kind === 188 /* ClassDeclaration */ ? container.parent : undefined;
if (classNode) {
var symbol = getSymbolOfNode(classNode);
return container.flags & 128 /* Static */ ? getTypeOfSymbol(symbol) : getDeclaredTypeOfSymbol(symbol);
@@ -12959,7 +13519,7 @@ var ts;
if (!node)
return node;
switch (node.kind) {
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
case 152 /* FunctionExpression */:
case 153 /* ArrowFunction */:
case 124 /* Property */:
@@ -12981,7 +13541,7 @@ var ts;
}
function checkSuperExpression(node) {
var isCallExpression = node.parent.kind === 147 /* CallExpression */ && node.parent.func === node;
- var enclosingClass = ts.getAncestor(node, 187 /* ClassDeclaration */);
+ var enclosingClass = ts.getAncestor(node, 188 /* ClassDeclaration */);
var baseClass;
if (enclosingClass && enclosingClass.baseType) {
var classType = getDeclaredTypeOfSymbol(getSymbolOfNode(enclosingClass));
@@ -13003,7 +13563,7 @@ var ts;
container = getSuperContainer(container);
needToCaptureLexicalThis = true;
}
- if (container && container.parent && container.parent.kind === 187 /* ClassDeclaration */) {
+ if (container && container.parent && container.parent.kind === 188 /* ClassDeclaration */) {
if (container.flags & 128 /* Static */) {
canUseSuperExpression = container.kind === 125 /* Method */ || container.kind === 127 /* GetAccessor */ || container.kind === 128 /* SetAccessor */;
}
@@ -13181,12 +13741,12 @@ var ts;
}
var parent = node.parent;
switch (parent.kind) {
- case 184 /* VariableDeclaration */:
+ case 185 /* VariableDeclaration */:
case 123 /* Parameter */:
case 124 /* Property */:
return getContextualTypeForInitializerExpression(node);
case 153 /* ArrowFunction */:
- case 172 /* ReturnStatement */:
+ case 173 /* ReturnStatement */:
return getContextualTypeForReturnExpression(node);
case 147 /* CallExpression */:
case 148 /* NewExpression */:
@@ -13337,7 +13897,7 @@ var ts;
if (!(flags & (32 /* Private */ | 64 /* Protected */))) {
return;
}
- var enclosingClassDeclaration = ts.getAncestor(node, 187 /* ClassDeclaration */);
+ var enclosingClassDeclaration = ts.getAncestor(node, 188 /* ClassDeclaration */);
var enclosingClass = enclosingClassDeclaration ? getDeclaredTypeOfSymbol(getSymbolOfNode(enclosingClassDeclaration)) : undefined;
var declaringClass = getDeclaredTypeOfSymbol(prop.parent);
if (flags & 32 /* Private */) {
@@ -13522,7 +14082,7 @@ var ts;
var context = createInferenceContext(typeParameters, false);
var mapper = createInferenceMapper(context);
for (var i = 0; i < args.length; i++) {
- if (args[i].kind === 160 /* OmittedExpression */) {
+ if (args[i].kind === 161 /* OmittedExpression */) {
continue;
}
if (!excludeArgument || excludeArgument[i] === undefined) {
@@ -13536,7 +14096,7 @@ var ts;
}
if (excludeArgument) {
for (var i = 0; i < args.length; i++) {
- if (args[i].kind === 160 /* OmittedExpression */) {
+ if (args[i].kind === 161 /* OmittedExpression */) {
continue;
}
if (excludeArgument[i] === false) {
@@ -13574,7 +14134,7 @@ var ts;
for (var i = 0; i < args.length; i++) {
var arg = args[i];
var argType;
- if (arg.kind === 160 /* OmittedExpression */) {
+ if (arg.kind === 161 /* OmittedExpression */) {
continue;
}
var paramType = getTypeAtPosition(signature, i);
@@ -13897,7 +14457,7 @@ var ts;
}
function getReturnTypeFromBody(func, contextualMapper) {
var contextualSignature = getContextualSignature(func);
- if (func.body.kind !== 186 /* FunctionBlock */) {
+ if (func.body.kind !== 187 /* FunctionBlock */) {
var unwidenedType = checkAndMarkExpression(func.body, contextualMapper);
var widenedType = getWidenedType(unwidenedType);
if (fullTypeCheck && compilerOptions.noImplicitAny && !contextualSignature && widenedType !== unwidenedType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) {
@@ -13945,7 +14505,7 @@ var ts;
});
}
function bodyContainsSingleThrowStatement(body) {
- return (body.statements.length === 1) && (body.statements[0].kind === 178 /* ThrowStatement */);
+ return (body.statements.length === 1) && (body.statements[0].kind === 179 /* ThrowStatement */);
}
function checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(func, returnType) {
if (!fullTypeCheck) {
@@ -13954,7 +14514,7 @@ var ts;
if (returnType === voidType || returnType === anyType) {
return;
}
- if (!func.body || func.body.kind !== 186 /* FunctionBlock */) {
+ if (!func.body || func.body.kind !== 187 /* FunctionBlock */) {
return;
}
var bodyBlock = func.body;
@@ -13998,7 +14558,7 @@ var ts;
if (node.type) {
checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type));
}
- if (node.body.kind === 186 /* FunctionBlock */) {
+ if (node.body.kind === 187 /* FunctionBlock */) {
checkSourceElement(node.body);
}
else {
@@ -14346,7 +14906,7 @@ var ts;
return checkBinaryExpression(node, contextualMapper);
case 157 /* ConditionalExpression */:
return checkConditionalExpression(node, contextualMapper);
- case 160 /* OmittedExpression */:
+ case 161 /* OmittedExpression */:
return undefinedType;
}
return unknownType;
@@ -14426,7 +14986,7 @@ var ts;
checkSpecializedSignatureDeclaration(node);
}
function checkTypeForDuplicateIndexSignatures(node) {
- if (node.kind === 188 /* InterfaceDeclaration */) {
+ if (node.kind === 189 /* InterfaceDeclaration */) {
var nodeSymbol = getSymbolOfNode(node);
if (nodeSymbol.declarations.length > 0 && nodeSymbol.declarations[0] !== node) {
return;
@@ -14490,7 +15050,7 @@ var ts;
}
switch (n.kind) {
case 152 /* FunctionExpression */:
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
case 153 /* ArrowFunction */:
case 142 /* ObjectLiteral */: return false;
default: return ts.forEachChild(n, containsSuperCall);
@@ -14500,7 +15060,7 @@ var ts;
if (n.kind === 91 /* ThisKeyword */) {
error(n, ts.Diagnostics.this_cannot_be_referenced_in_current_location);
}
- else if (n.kind !== 152 /* FunctionExpression */ && n.kind !== 185 /* FunctionDeclaration */) {
+ else if (n.kind !== 152 /* FunctionExpression */ && n.kind !== 186 /* FunctionDeclaration */) {
ts.forEachChild(n, markThisReferencesAsErrors);
}
}
@@ -14512,7 +15072,7 @@ var ts;
var superCallShouldBeFirst = ts.forEach(node.parent.members, isInstancePropertyWithInitializer) || ts.forEach(node.parameters, function (p) { return p.flags & (16 /* Public */ | 32 /* Private */ | 64 /* Protected */); });
if (superCallShouldBeFirst) {
var statements = node.body.statements;
- if (!statements.length || statements[0].kind !== 164 /* ExpressionStatement */ || !isSuperCallExpression(statements[0].expression)) {
+ if (!statements.length || statements[0].kind !== 165 /* ExpressionStatement */ || !isSuperCallExpression(statements[0].expression)) {
error(node, ts.Diagnostics.A_super_call_must_be_the_first_statement_in_the_constructor_when_a_class_contains_initialized_properties_or_has_parameter_properties);
}
else {
@@ -14600,7 +15160,7 @@ var ts;
return;
}
var signaturesToCheck;
- if (!signatureDeclarationNode.name && signatureDeclarationNode.parent && signatureDeclarationNode.parent.kind === 188 /* InterfaceDeclaration */) {
+ if (!signatureDeclarationNode.name && signatureDeclarationNode.parent && signatureDeclarationNode.parent.kind === 189 /* InterfaceDeclaration */) {
ts.Debug.assert(signatureDeclarationNode.kind === 129 /* CallSignature */ || signatureDeclarationNode.kind === 130 /* ConstructSignature */);
var signatureKind = signatureDeclarationNode.kind === 129 /* CallSignature */ ? 0 /* Call */ : 1 /* Construct */;
var containingSymbol = getSymbolOfNode(signatureDeclarationNode.parent);
@@ -14620,7 +15180,7 @@ var ts;
}
function getEffectiveDeclarationFlags(n, flagsToCheck) {
var flags = n.flags;
- if (n.parent.kind !== 188 /* InterfaceDeclaration */ && ts.isInAmbientContext(n)) {
+ if (n.parent.kind !== 189 /* InterfaceDeclaration */ && ts.isInAmbientContext(n)) {
if (!(flags & 2 /* Ambient */)) {
flags |= 1 /* Export */;
}
@@ -14706,11 +15266,11 @@ var ts;
for (var i = 0; i < declarations.length; i++) {
var node = declarations[i];
var inAmbientContext = ts.isInAmbientContext(node);
- var inAmbientContextOrInterface = node.parent.kind === 188 /* InterfaceDeclaration */ || node.parent.kind === 136 /* TypeLiteral */ || inAmbientContext;
+ var inAmbientContextOrInterface = node.parent.kind === 189 /* InterfaceDeclaration */ || node.parent.kind === 136 /* TypeLiteral */ || inAmbientContext;
if (inAmbientContextOrInterface) {
previousDeclaration = undefined;
}
- if (node.kind === 185 /* FunctionDeclaration */ || node.kind === 125 /* Method */ || node.kind === 126 /* Constructor */) {
+ if (node.kind === 186 /* FunctionDeclaration */ || node.kind === 125 /* Method */ || node.kind === 126 /* Constructor */) {
var currentNodeFlags = getEffectiveDeclarationFlags(node, flagsToCheck);
someNodeFlags |= currentNodeFlags;
allNodeFlags &= currentNodeFlags;
@@ -14804,14 +15364,14 @@ var ts;
}
function getDeclarationSpaces(d) {
switch (d.kind) {
- case 188 /* InterfaceDeclaration */:
+ case 189 /* InterfaceDeclaration */:
return 8388608 /* ExportType */;
- case 191 /* ModuleDeclaration */:
+ case 192 /* ModuleDeclaration */:
return d.name.kind === 7 /* StringLiteral */ || ts.getModuleInstanceState(d) !== 0 /* NonInstantiated */ ? 16777216 /* ExportNamespace */ | 4194304 /* ExportValue */ : 16777216 /* ExportNamespace */;
- case 187 /* ClassDeclaration */:
- case 190 /* EnumDeclaration */:
+ case 188 /* ClassDeclaration */:
+ case 191 /* EnumDeclaration */:
return 8388608 /* ExportType */ | 4194304 /* ExportValue */;
- case 193 /* ImportDeclaration */:
+ case 194 /* ImportDeclaration */:
var result = 0;
var target = resolveImport(getSymbolOfNode(d));
ts.forEach(target.declarations, function (d) {
@@ -14886,7 +15446,7 @@ var ts;
return;
}
switch (current.kind) {
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
case 152 /* FunctionExpression */:
case 125 /* Method */:
case 153 /* ArrowFunction */:
@@ -14941,7 +15501,7 @@ var ts;
if (!needCollisionCheckForIdentifier(node, name, "_super")) {
return;
}
- var enclosingClass = ts.getAncestor(node, 187 /* ClassDeclaration */);
+ var enclosingClass = ts.getAncestor(node, 188 /* ClassDeclaration */);
if (!enclosingClass || ts.isInAmbientContext(enclosingClass)) {
return;
}
@@ -14959,11 +15519,11 @@ var ts;
if (!needCollisionCheckForIdentifier(node, name, "require") && !needCollisionCheckForIdentifier(node, name, "exports")) {
return;
}
- if (node.kind === 191 /* ModuleDeclaration */ && ts.getModuleInstanceState(node) !== 1 /* Instantiated */) {
+ if (node.kind === 192 /* ModuleDeclaration */ && ts.getModuleInstanceState(node) !== 1 /* Instantiated */) {
return;
}
- var parent = node.kind === 184 /* VariableDeclaration */ ? node.parent.parent : node.parent;
- if (parent.kind === 196 /* SourceFile */ && ts.isExternalModule(parent)) {
+ var parent = node.kind === 185 /* VariableDeclaration */ ? node.parent.parent : node.parent;
+ if (parent.kind === 197 /* SourceFile */ && ts.isExternalModule(parent)) {
error(name, ts.Diagnostics.Duplicate_identifier_0_Compiler_reserves_name_1_in_top_level_scope_of_an_external_module, ts.declarationNameToString(name), ts.declarationNameToString(name));
}
}
@@ -15041,10 +15601,13 @@ var ts;
checkSourceElement(node.statement);
}
function checkForInStatement(node) {
- if (node.declaration) {
- checkVariableDeclaration(node.declaration);
- if (node.declaration.type) {
- error(node.declaration, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation);
+ if (node.declarations) {
+ if (node.declarations.length >= 1) {
+ var decl = node.declarations[0];
+ checkVariableDeclaration(decl);
+ if (decl.type) {
+ error(decl, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation);
+ }
}
}
if (node.variable) {
@@ -15351,7 +15914,7 @@ var ts;
checkTypeNameIsReserved(node.name, ts.Diagnostics.Interface_name_cannot_be_0);
checkExportsOnMergedDeclarations(node);
var symbol = getSymbolOfNode(node);
- var firstInterfaceDecl = getDeclarationOfKind(symbol, 188 /* InterfaceDeclaration */);
+ var firstInterfaceDecl = getDeclarationOfKind(symbol, 189 /* InterfaceDeclaration */);
if (symbol.declarations.length > 1) {
if (node !== firstInterfaceDecl && !areTypeParametersIdentical(firstInterfaceDecl.typeParameters, node.typeParameters)) {
error(node.name, ts.Diagnostics.All_declarations_of_an_interface_must_have_identical_type_parameters);
@@ -15384,7 +15947,7 @@ var ts;
var enumType = getDeclaredTypeOfSymbol(enumSymbol);
var autoValue = 0;
var ambient = ts.isInAmbientContext(node);
- var enumIsConst = ts.isConstEnumDeclaration(node);
+ var enumIsConst = ts.isConst(node);
ts.forEach(node.members, function (member) {
if (isNumericName(member.name.text)) {
error(member.name, ts.Diagnostics.An_enum_member_cannot_have_a_numeric_name);
@@ -15525,7 +16088,7 @@ var ts;
var firstDeclaration = getDeclarationOfKind(enumSymbol, node.kind);
if (node === firstDeclaration) {
if (enumSymbol.declarations.length > 1) {
- var enumIsConst = ts.isConstEnumDeclaration(node);
+ var enumIsConst = ts.isConst(node);
ts.forEach(enumSymbol.declarations, function (decl) {
if (ts.isConstEnumDeclaration(decl) !== enumIsConst) {
error(decl.name, ts.Diagnostics.Enum_declarations_must_all_be_const_or_non_const);
@@ -15534,7 +16097,7 @@ var ts;
}
var seenEnumMissingInitialInitializer = false;
ts.forEach(enumSymbol.declarations, function (declaration) {
- if (declaration.kind !== 190 /* EnumDeclaration */) {
+ if (declaration.kind !== 191 /* EnumDeclaration */) {
return false;
}
var enumDeclaration = declaration;
@@ -15557,7 +16120,7 @@ var ts;
var declarations = symbol.declarations;
for (var i = 0; i < declarations.length; i++) {
var declaration = declarations[i];
- if ((declaration.kind === 187 /* ClassDeclaration */ || (declaration.kind === 185 /* FunctionDeclaration */ && declaration.body)) && !ts.isInAmbientContext(declaration)) {
+ if ((declaration.kind === 188 /* ClassDeclaration */ || (declaration.kind === 186 /* FunctionDeclaration */ && declaration.body)) && !ts.isInAmbientContext(declaration)) {
return declaration;
}
}
@@ -15620,10 +16183,10 @@ var ts;
}
}
else {
- if (node.parent.kind === 196 /* SourceFile */) {
+ if (node.parent.kind === 197 /* SourceFile */) {
target = resolveImport(symbol);
}
- else if (node.parent.kind === 192 /* ModuleBlock */ && node.parent.parent.name.kind === 7 /* StringLiteral */) {
+ else if (node.parent.kind === 193 /* ModuleBlock */ && node.parent.parent.name.kind === 7 /* StringLiteral */) {
if (isExternalModuleNameRelative(node.externalModuleName.text)) {
error(node, ts.Diagnostics.Import_declaration_in_an_ambient_external_module_declaration_cannot_reference_external_module_through_relative_external_module_name);
target = unknownSymbol;
@@ -15645,7 +16208,7 @@ var ts;
}
function checkExportAssignment(node) {
var container = node.parent;
- if (container.kind !== 196 /* SourceFile */) {
+ if (container.kind !== 197 /* SourceFile */) {
container = container.parent;
}
checkTypeOfExportAssignmentSymbol(getSymbolOfNode(container));
@@ -15687,57 +16250,57 @@ var ts;
return checkUnionType(node);
case 140 /* ParenType */:
return checkSourceElement(node.type);
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
return checkFunctionDeclaration(node);
- case 161 /* Block */:
+ case 162 /* Block */:
return checkBlock(node);
- case 186 /* FunctionBlock */:
- case 192 /* ModuleBlock */:
+ case 187 /* FunctionBlock */:
+ case 193 /* ModuleBlock */:
return checkBody(node);
- case 162 /* VariableStatement */:
+ case 163 /* VariableStatement */:
return checkVariableStatement(node);
- case 164 /* ExpressionStatement */:
+ case 165 /* ExpressionStatement */:
return checkExpressionStatement(node);
- case 165 /* IfStatement */:
+ case 166 /* IfStatement */:
return checkIfStatement(node);
- case 166 /* DoStatement */:
+ case 167 /* DoStatement */:
return checkDoStatement(node);
- case 167 /* WhileStatement */:
+ case 168 /* WhileStatement */:
return checkWhileStatement(node);
- case 168 /* ForStatement */:
+ case 169 /* ForStatement */:
return checkForStatement(node);
- case 169 /* ForInStatement */:
+ case 170 /* ForInStatement */:
return checkForInStatement(node);
- case 170 /* ContinueStatement */:
- case 171 /* BreakStatement */:
+ case 171 /* ContinueStatement */:
+ case 172 /* BreakStatement */:
return checkBreakOrContinueStatement(node);
- case 172 /* ReturnStatement */:
+ case 173 /* ReturnStatement */:
return checkReturnStatement(node);
- case 173 /* WithStatement */:
+ case 174 /* WithStatement */:
return checkWithStatement(node);
- case 174 /* SwitchStatement */:
+ case 175 /* SwitchStatement */:
return checkSwitchStatement(node);
- case 177 /* LabeledStatement */:
+ case 178 /* LabeledStatement */:
return checkLabeledStatement(node);
- case 178 /* ThrowStatement */:
+ case 179 /* ThrowStatement */:
return checkThrowStatement(node);
- case 179 /* TryStatement */:
+ case 180 /* TryStatement */:
return checkTryStatement(node);
- case 184 /* VariableDeclaration */:
+ case 185 /* VariableDeclaration */:
return ts.Debug.fail("Checker encountered variable declaration");
- case 187 /* ClassDeclaration */:
+ case 188 /* ClassDeclaration */:
return checkClassDeclaration(node);
- case 188 /* InterfaceDeclaration */:
+ case 189 /* InterfaceDeclaration */:
return checkInterfaceDeclaration(node);
- case 189 /* TypeAliasDeclaration */:
+ case 190 /* TypeAliasDeclaration */:
return checkTypeAliasDeclaration(node);
- case 190 /* EnumDeclaration */:
+ case 191 /* EnumDeclaration */:
return checkEnumDeclaration(node);
- case 191 /* ModuleDeclaration */:
+ case 192 /* ModuleDeclaration */:
return checkModuleDeclaration(node);
- case 193 /* ImportDeclaration */:
+ case 194 /* ImportDeclaration */:
return checkImportDeclaration(node);
- case 194 /* ExportAssignment */:
+ case 195 /* ExportAssignment */:
return checkExportAssignment(node);
}
}
@@ -15752,10 +16315,10 @@ var ts;
case 126 /* Constructor */:
case 127 /* GetAccessor */:
case 128 /* SetAccessor */:
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
ts.forEach(node.parameters, checkFunctionExpressionBodies);
break;
- case 173 /* WithStatement */:
+ case 174 /* WithStatement */:
checkFunctionExpressionBodies(node.expression);
break;
case 123 /* Parameter */:
@@ -15774,33 +16337,33 @@ var ts;
case 155 /* PostfixOperator */:
case 156 /* BinaryExpression */:
case 157 /* ConditionalExpression */:
- case 161 /* Block */:
- case 186 /* FunctionBlock */:
- case 192 /* ModuleBlock */:
- case 162 /* VariableStatement */:
- case 164 /* ExpressionStatement */:
- case 165 /* IfStatement */:
- case 166 /* DoStatement */:
- case 167 /* WhileStatement */:
- case 168 /* ForStatement */:
- case 169 /* ForInStatement */:
- case 170 /* ContinueStatement */:
- case 171 /* BreakStatement */:
- case 172 /* ReturnStatement */:
- case 174 /* SwitchStatement */:
- case 175 /* CaseClause */:
- case 176 /* DefaultClause */:
- case 177 /* LabeledStatement */:
- case 178 /* ThrowStatement */:
- case 179 /* TryStatement */:
- case 180 /* TryBlock */:
- case 181 /* CatchBlock */:
- case 182 /* FinallyBlock */:
- case 184 /* VariableDeclaration */:
- case 187 /* ClassDeclaration */:
- case 190 /* EnumDeclaration */:
- case 195 /* EnumMember */:
- case 196 /* SourceFile */:
+ case 162 /* Block */:
+ case 187 /* FunctionBlock */:
+ case 193 /* ModuleBlock */:
+ case 163 /* VariableStatement */:
+ case 165 /* ExpressionStatement */:
+ case 166 /* IfStatement */:
+ case 167 /* DoStatement */:
+ case 168 /* WhileStatement */:
+ case 169 /* ForStatement */:
+ case 170 /* ForInStatement */:
+ case 171 /* ContinueStatement */:
+ case 172 /* BreakStatement */:
+ case 173 /* ReturnStatement */:
+ case 175 /* SwitchStatement */:
+ case 176 /* CaseClause */:
+ case 177 /* DefaultClause */:
+ case 178 /* LabeledStatement */:
+ case 179 /* ThrowStatement */:
+ case 180 /* TryStatement */:
+ case 181 /* TryBlock */:
+ case 182 /* CatchBlock */:
+ case 183 /* FinallyBlock */:
+ case 185 /* VariableDeclaration */:
+ case 188 /* ClassDeclaration */:
+ case 191 /* EnumDeclaration */:
+ case 196 /* EnumMember */:
+ case 197 /* SourceFile */:
ts.forEachChild(node, checkFunctionExpressionBodies);
break;
}
@@ -15850,6 +16413,11 @@ var ts;
checkProgram();
return getSortedDiagnostics();
}
+ function getDeclarationDiagnostics(targetSourceFile) {
+ var resolver = createResolver();
+ checkSourceFile(targetSourceFile);
+ return ts.getDeclarationDiagnostics(program, resolver, targetSourceFile);
+ }
function getGlobalDiagnostics() {
return ts.filter(getSortedDiagnostics(), function (d) { return !d.file; });
}
@@ -15871,7 +16439,7 @@ var ts;
function isInsideWithStatementBody(node) {
if (node) {
while (node.parent) {
- if (node.parent.kind === 173 /* WithStatement */ && node.parent.statement === node) {
+ if (node.parent.kind === 174 /* WithStatement */ && node.parent.statement === node) {
return true;
}
node = node.parent;
@@ -15907,17 +16475,17 @@ var ts;
copySymbols(location.locals, meaning);
}
switch (location.kind) {
- case 196 /* SourceFile */:
+ case 197 /* SourceFile */:
if (!ts.isExternalModule(location))
break;
- case 191 /* ModuleDeclaration */:
+ case 192 /* ModuleDeclaration */:
copySymbols(getSymbolOfNode(location).exports, meaning & 35653619 /* ModuleMember */);
break;
- case 190 /* EnumDeclaration */:
+ case 191 /* EnumDeclaration */:
copySymbols(getSymbolOfNode(location).exports, meaning & 8 /* EnumMember */);
break;
- case 187 /* ClassDeclaration */:
- case 188 /* InterfaceDeclaration */:
+ case 188 /* ClassDeclaration */:
+ case 189 /* InterfaceDeclaration */:
if (!(memberFlags & 128 /* Static */)) {
copySymbols(getSymbolOfNode(location).members, meaning & 3152352 /* Type */);
}
@@ -15927,7 +16495,7 @@ var ts;
copySymbol(location.symbol, meaning);
}
break;
- case 181 /* CatchBlock */:
+ case 182 /* CatchBlock */:
if (location.variable.text) {
copySymbol(location.symbol, meaning);
}
@@ -15945,10 +16513,10 @@ var ts;
function isTypeDeclaration(node) {
switch (node.kind) {
case 122 /* TypeParameter */:
- case 187 /* ClassDeclaration */:
- case 188 /* InterfaceDeclaration */:
- case 189 /* TypeAliasDeclaration */:
- case 190 /* EnumDeclaration */:
+ case 188 /* ClassDeclaration */:
+ case 189 /* InterfaceDeclaration */:
+ case 190 /* TypeAliasDeclaration */:
+ case 191 /* EnumDeclaration */:
return true;
}
}
@@ -15990,9 +16558,9 @@ var ts;
return node === parent.constraint;
case 124 /* Property */:
case 123 /* Parameter */:
- case 184 /* VariableDeclaration */:
+ case 185 /* VariableDeclaration */:
return node === parent.type;
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
case 152 /* FunctionExpression */:
case 153 /* ArrowFunction */:
case 126 /* Constructor */:
@@ -16019,10 +16587,10 @@ var ts;
while (node.parent.kind === 121 /* QualifiedName */) {
node = node.parent;
}
- if (node.parent.kind === 193 /* ImportDeclaration */) {
+ if (node.parent.kind === 194 /* ImportDeclaration */) {
return node.parent.entityName === node;
}
- if (node.parent.kind === 194 /* ExportAssignment */) {
+ if (node.parent.kind === 195 /* ExportAssignment */) {
return node.parent.exportName === node;
}
return false;
@@ -16034,7 +16602,7 @@ var ts;
if (ts.isDeclarationOrFunctionExpressionOrCatchVariableName(entityName)) {
return getSymbolOfNode(entityName.parent);
}
- if (entityName.parent.kind === 194 /* ExportAssignment */) {
+ if (entityName.parent.kind === 195 /* ExportAssignment */) {
return resolveEntityName(entityName.parent.parent, entityName, 107455 /* Value */ | 3152352 /* Type */ | 1536 /* Namespace */ | 33554432 /* Import */);
}
if (isInRightSideOfImportOrExportAssignment(entityName)) {
@@ -16074,7 +16642,7 @@ var ts;
return getSymbolOfNode(node.parent);
}
if (node.kind === 63 /* Identifier */ && isInRightSideOfImportOrExportAssignment(node)) {
- return node.parent.kind === 194 /* ExportAssignment */ ? getSymbolOfEntityName(node) : getSymbolOfPartOfRightHandSideOfImport(node);
+ return node.parent.kind === 195 /* ExportAssignment */ ? getSymbolOfEntityName(node) : getSymbolOfPartOfRightHandSideOfImport(node);
}
switch (node.kind) {
case 63 /* Identifier */:
@@ -16092,7 +16660,7 @@ var ts;
}
return undefined;
case 7 /* StringLiteral */:
- if (node.parent.kind === 193 /* ImportDeclaration */ && node.parent.externalModuleName === node) {
+ if (node.parent.kind === 194 /* ImportDeclaration */ && node.parent.externalModuleName === node) {
var importSymbol = getSymbolOfNode(node.parent);
var moduleType = getTypeOfSymbol(importSymbol);
return moduleType ? moduleType.symbol : undefined;
@@ -16186,7 +16754,7 @@ var ts;
return [symbol];
}
function isExternalModuleSymbol(symbol) {
- return symbol.flags & 512 /* ValueModule */ && symbol.declarations.length === 1 && symbol.declarations[0].kind === 196 /* SourceFile */;
+ return symbol.flags & 512 /* ValueModule */ && symbol.declarations.length === 1 && symbol.declarations[0].kind === 197 /* SourceFile */;
}
function isNodeDescendentOf(node, ancestor) {
while (node) {
@@ -16219,7 +16787,7 @@ var ts;
function getLocalNameForSymbol(symbol, location) {
var node = location;
while (node) {
- if ((node.kind === 191 /* ModuleDeclaration */ || node.kind === 190 /* EnumDeclaration */) && getSymbolOfNode(node) === symbol) {
+ if ((node.kind === 192 /* ModuleDeclaration */ || node.kind === 191 /* EnumDeclaration */) && getSymbolOfNode(node) === symbol) {
return getLocalNameOfContainer(node);
}
node = node.parent;
@@ -16243,7 +16811,7 @@ var ts;
return symbol && symbolIsValue(symbol) && !isConstEnumSymbol(symbol) ? symbolToString(symbol) : undefined;
}
function isTopLevelValueImportWithEntityName(node) {
- if (node.parent.kind !== 196 /* SourceFile */ || !node.entityName) {
+ if (node.parent.kind !== 197 /* SourceFile */ || !node.entityName) {
return false;
}
return isImportResolvedToValue(getSymbolOfNode(node));
@@ -16294,7 +16862,7 @@ var ts;
if (symbol && (symbol.flags & 8 /* EnumMember */)) {
var declaration = symbol.valueDeclaration;
var constantValue;
- if (declaration.kind === 195 /* EnumMember */ && (constantValue = getNodeLinks(declaration).enumMemberValue) !== undefined) {
+ if (declaration.kind === 196 /* EnumMember */ && (constantValue = getNodeLinks(declaration).enumMemberValue) !== undefined) {
return constantValue;
}
}
@@ -16309,8 +16877,8 @@ var ts;
var signature = getSignatureFromDeclaration(signatureDeclaration);
getSymbolDisplayBuilder().buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags);
}
- function invokeEmitter(targetSourceFile) {
- var resolver = {
+ function createResolver() {
+ return {
getProgram: function () { return program; },
getLocalNameOfContainer: getLocalNameOfContainer,
getExpressionNamePrefix: getExpressionNamePrefix,
@@ -16326,16 +16894,19 @@ var ts;
writeTypeAtLocation: writeTypeAtLocation,
writeReturnTypeOfSignatureDeclaration: writeReturnTypeOfSignatureDeclaration,
isSymbolAccessible: isSymbolAccessible,
- isImportDeclarationEntityNameReferenceDeclarationVisibile: isImportDeclarationEntityNameReferenceDeclarationVisibile,
+ isEntityNameVisible: isEntityNameVisible,
getConstantValue: getConstantValue
};
+ }
+ function invokeEmitter(targetSourceFile) {
+ var resolver = createResolver();
checkProgram();
return ts.emitFiles(resolver, targetSourceFile);
}
function initializeTypeChecker() {
ts.forEach(program.getSourceFiles(), function (file) {
ts.bindSourceFile(file);
- ts.forEach(file.semanticErrors, addDiagnostic);
+ ts.forEach(file.semanticDiagnostics, addDiagnostic);
});
ts.forEach(program.getSourceFiles(), function (file) {
if (!ts.isExternalModule(file)) {
@@ -16863,7 +17434,7 @@ var ts;
}
else {
var emitStart = new Date().getTime();
- var emitOutput = checker.invokeEmitter();
+ var emitOutput = checker.emitFiles();
var emitErrors = emitOutput.diagnostics;
exitStatus = emitOutput.emitResultStatus;
var reportStart = new Date().getTime();
diff --git a/bin/typescriptServices.js b/bin/typescriptServices.js
index ca2b7ec0318..8c36e0b88f6 100644
--- a/bin/typescriptServices.js
+++ b/bin/typescriptServices.js
@@ -418,6 +418,10 @@ var ts;
return normalizedPathComponents(path, rootLength);
}
ts.getNormalizedPathComponents = getNormalizedPathComponents;
+ function getNormalizedAbsolutePath(filename, currentDirectory) {
+ return getNormalizedPathFromPathComponents(getNormalizedPathComponents(filename, currentDirectory));
+ }
+ ts.getNormalizedAbsolutePath = getNormalizedAbsolutePath;
function getNormalizedPathFromPathComponents(pathComponents) {
if (pathComponents && pathComponents.length) {
return pathComponents[0] + pathComponents.slice(1).join(ts.directorySeparator);
@@ -712,7 +716,8 @@ var ts;
Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1159, category: 1 /* Error */, key: "Tagged templates are only available when targeting ECMAScript 6 and higher." },
Unterminated_template_literal: { code: 1160, category: 1 /* Error */, key: "Unterminated template literal." },
Unterminated_regular_expression_literal: { code: 1161, category: 1 /* Error */, key: "Unterminated regular expression literal." },
- A_object_member_cannot_be_declared_optional: { code: 1160, category: 1 /* Error */, key: "A object member cannot be declared optional." },
+ An_object_member_cannot_be_declared_optional: { code: 1162, category: 1 /* Error */, key: "An object member cannot be declared optional." },
+ yield_expression_must_be_contained_within_a_generator_declaration: { code: 1163, category: 1 /* Error */, key: "'yield' expression must be contained_within a generator declaration." },
Duplicate_identifier_0: { code: 2300, category: 1 /* Error */, key: "Duplicate identifier '{0}'." },
Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: 1 /* Error */, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." },
Static_members_cannot_reference_class_type_parameters: { code: 2302, category: 1 /* Error */, key: "Static members cannot reference class type parameters." },
@@ -863,27 +868,16 @@ var ts;
Type_alias_name_cannot_be_0: { code: 2457, category: 1 /* Error */, key: "Type alias name cannot be '{0}'" },
An_AMD_module_cannot_have_multiple_name_assignments: { code: 2458, category: 1 /* Error */, key: "An AMD module cannot have multiple name assignments." },
Import_declaration_0_is_using_private_name_1: { code: 4000, category: 1 /* Error */, key: "Import declaration '{0}' is using private name '{1}'." },
- Type_parameter_0_of_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4001, category: 1 /* Error */, key: "Type parameter '{0}' of exported class has or is using name '{1}' from private module '{2}'." },
Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: 1 /* Error */, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." },
- Type_parameter_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 4003, category: 1 /* Error */, key: "Type parameter '{0}' of exported interface has or is using name '{1}' from private module '{2}'." },
Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: 1 /* Error */, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." },
- Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 4005, category: 1 /* Error */, key: "Type parameter '{0}' of constructor signature from exported interface has or is using name '{1}' from private module '{2}'." },
Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1: { code: 4006, category: 1 /* Error */, key: "Type parameter '{0}' of constructor signature from exported interface has or is using private name '{1}'." },
- Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 4007, category: 1 /* Error */, key: "Type parameter '{0}' of call signature from exported interface has or is using name '{1}' from private module '{2}'." },
Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1: { code: 4008, category: 1 /* Error */, key: "Type parameter '{0}' of call signature from exported interface has or is using private name '{1}'." },
- Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4009, category: 1 /* Error */, key: "Type parameter '{0}' of public static method from exported class has or is using name '{1}' from private module '{2}'." },
Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1: { code: 4010, category: 1 /* Error */, key: "Type parameter '{0}' of public static method from exported class has or is using private name '{1}'." },
- Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4011, category: 1 /* Error */, key: "Type parameter '{0}' of public method from exported class has or is using name '{1}' from private module '{2}'." },
Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1: { code: 4012, category: 1 /* Error */, key: "Type parameter '{0}' of public method from exported class has or is using private name '{1}'." },
- Type_parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 4013, category: 1 /* Error */, key: "Type parameter '{0}' of method from exported interface has or is using name '{1}' from private module '{2}'." },
Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1: { code: 4014, category: 1 /* Error */, key: "Type parameter '{0}' of method from exported interface has or is using private name '{1}'." },
- Type_parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2: { code: 4015, category: 1 /* Error */, key: "Type parameter '{0}' of exported function has or is using name '{1}' from private module '{2}'." },
Type_parameter_0_of_exported_function_has_or_is_using_private_name_1: { code: 4016, category: 1 /* Error */, key: "Type parameter '{0}' of exported function has or is using private name '{1}'." },
- Implements_clause_of_exported_class_0_has_or_is_using_name_1_from_private_module_2: { code: 4017, category: 1 /* Error */, key: "Implements clause of exported class '{0}' has or is using name '{1}' from private module '{2}'." },
- Extends_clause_of_exported_class_0_has_or_is_using_name_1_from_private_module_2: { code: 4018, category: 1 /* Error */, key: "Extends clause of exported class '{0}' has or is using name '{1}' from private module '{2}'." },
Implements_clause_of_exported_class_0_has_or_is_using_private_name_1: { code: 4019, category: 1 /* Error */, key: "Implements clause of exported class '{0}' has or is using private name '{1}'." },
Extends_clause_of_exported_class_0_has_or_is_using_private_name_1: { code: 4020, category: 1 /* Error */, key: "Extends clause of exported class '{0}' has or is using private name '{1}'." },
- Extends_clause_of_exported_interface_0_has_or_is_using_name_1_from_private_module_2: { code: 4021, category: 1 /* Error */, key: "Extends clause of exported interface '{0}' has or is using name '{1}' from private module '{2}'." },
Extends_clause_of_exported_interface_0_has_or_is_using_private_name_1: { code: 4022, category: 1 /* Error */, key: "Extends clause of exported interface '{0}' has or is using private name '{1}'." },
Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: { code: 4023, category: 1 /* Error */, key: "Exported variable '{0}' has or is using name '{1}' from external module {2} but cannot be named." },
Exported_variable_0_has_or_is_using_name_1_from_private_module_2: { code: 4024, category: 1 /* Error */, key: "Exported variable '{0}' has or is using name '{1}' from private module '{2}'." },
@@ -941,8 +935,6 @@ var ts;
Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: { code: 4076, category: 1 /* Error */, key: "Parameter '{0}' of exported function has or is using name '{1}' from external module {2} but cannot be named." },
Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2: { code: 4077, category: 1 /* Error */, key: "Parameter '{0}' of exported function has or is using name '{1}' from private module '{2}'." },
Parameter_0_of_exported_function_has_or_is_using_private_name_1: { code: 4078, category: 1 /* Error */, key: "Parameter '{0}' of exported function has or is using private name '{1}'." },
- Exported_type_alias_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: { code: 4079, category: 1 /* Error */, key: "Exported type alias '{0}' has or is using name '{1}' from external module {2} but cannot be named." },
- Exported_type_alias_0_has_or_is_using_name_1_from_private_module_2: { code: 4080, category: 1 /* Error */, key: "Exported type alias '{0}' has or is using name '{1}' from private module '{2}'." },
Exported_type_alias_0_has_or_is_using_private_name_1: { code: 4081, category: 1 /* Error */, key: "Exported type alias '{0}' has or is using private name '{1}'." },
Enum_declarations_must_all_be_const_or_non_const: { code: 4082, category: 1 /* Error */, key: "Enum declarations must all be const or non-const." },
In_const_enum_declarations_member_initializer_must_be_constant_expression: { code: 4083, category: 1 /* Error */, key: "In 'const' enum declarations member initializer must be constant expression.", isEarly: true },
@@ -1013,7 +1005,9 @@ var ts;
_0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer: { code: 7022, category: 1 /* Error */, key: "'{0}' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer." },
_0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7023, category: 1 /* Error */, key: "'{0}' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." },
Function_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7024, category: 1 /* Error */, key: "Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." },
- You_cannot_rename_this_element: { code: 8000, category: 1 /* Error */, key: "You cannot rename this element." }
+ You_cannot_rename_this_element: { code: 8000, category: 1 /* Error */, key: "You cannot rename this element." },
+ yield_expressions_are_not_currently_supported: { code: 9000, category: 1 /* Error */, key: "'yield' expressions are not currently supported." },
+ generators_are_not_currently_supported: { code: 9001, category: 1 /* Error */, key: "'generators' are not currently supported." }
};
})(ts || (ts = {}));
var ts;
@@ -1786,11 +1780,11 @@ var ts;
value = 0;
}
tokenValue = "" + value;
- return 6 /* NumericLiteral */;
+ return token = 6 /* NumericLiteral */;
}
if (pos + 1 < len && isOctalDigit(text.charCodeAt(pos + 1))) {
tokenValue = "" + scanOctalDigits();
- return 6 /* NumericLiteral */;
+ return token = 6 /* NumericLiteral */;
}
case 49 /* _1 */:
case 50 /* _2 */:
@@ -2011,7 +2005,7 @@ var ts;
})(ts || (ts = {}));
var ts;
(function (ts) {
- var nodeConstructors = new Array(199 /* Count */);
+ var nodeConstructors = new Array(200 /* Count */);
function getNodeConstructor(kind) {
return nodeConstructors[kind] || (nodeConstructors[kind] = ts.objectAllocator.getNodeConstructor(kind));
}
@@ -2024,7 +2018,7 @@ var ts;
return node;
}
function getSourceFileOfNode(node) {
- while (node && node.kind !== 196 /* SourceFile */)
+ while (node && node.kind !== 197 /* SourceFile */)
node = node.parent;
return node;
}
@@ -2046,13 +2040,17 @@ var ts;
return ts.skipTrivia((sourceFile || getSourceFileOfNode(node)).text, node.pos);
}
ts.getTokenPosOfNode = getTokenPosOfNode;
+ function getSourceTextOfNodeFromSourceFile(sourceFile, node) {
+ var text = sourceFile.text;
+ return text.substring(ts.skipTrivia(text, node.pos), node.end);
+ }
+ ts.getSourceTextOfNodeFromSourceFile = getSourceTextOfNodeFromSourceFile;
function getTextOfNodeFromSourceText(sourceText, node) {
return sourceText.substring(ts.skipTrivia(sourceText, node.pos), node.end);
}
ts.getTextOfNodeFromSourceText = getTextOfNodeFromSourceText;
function getTextOfNode(node) {
- var text = getSourceFileOfNode(node).text;
- return text.substring(ts.skipTrivia(text, node.pos), node.end);
+ return getSourceTextOfNodeFromSourceFile(getSourceFileOfNode(node), node);
}
ts.getTextOfNode = getTextOfNode;
function escapeIdentifier(identifier) {
@@ -2086,12 +2084,12 @@ var ts;
function getErrorSpanForNode(node) {
var errorSpan;
switch (node.kind) {
- case 184 /* VariableDeclaration */:
- case 187 /* ClassDeclaration */:
- case 188 /* InterfaceDeclaration */:
- case 191 /* ModuleDeclaration */:
- case 190 /* EnumDeclaration */:
- case 195 /* EnumMember */:
+ case 185 /* VariableDeclaration */:
+ case 188 /* ClassDeclaration */:
+ case 189 /* InterfaceDeclaration */:
+ case 192 /* ModuleDeclaration */:
+ case 191 /* EnumDeclaration */:
+ case 196 /* EnumMember */:
errorSpan = node.name;
break;
}
@@ -2107,11 +2105,19 @@ var ts;
}
ts.isDeclarationFile = isDeclarationFile;
function isConstEnumDeclaration(node) {
- return (node.flags & 4096 /* Const */) !== 0;
+ return node.kind === 191 /* EnumDeclaration */ && isConst(node);
}
ts.isConstEnumDeclaration = isConstEnumDeclaration;
+ function isConst(node) {
+ return !!(node.flags & 4096 /* Const */);
+ }
+ ts.isConst = isConst;
+ function isLet(node) {
+ return !!(node.flags & 2048 /* Let */);
+ }
+ ts.isLet = isLet;
function isPrologueDirective(node) {
- return node.kind === 164 /* ExpressionStatement */ && node.expression.kind === 7 /* StringLiteral */;
+ return node.kind === 165 /* ExpressionStatement */ && node.expression.kind === 7 /* StringLiteral */;
}
ts.isPrologueDirective = isPrologueDirective;
function isEvalOrArgumentsIdentifier(node) {
@@ -2180,7 +2186,7 @@ var ts;
case 127 /* GetAccessor */:
case 128 /* SetAccessor */:
case 152 /* FunctionExpression */:
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
case 153 /* ArrowFunction */:
return child(node.name) || children(node.typeParameters) || children(node.parameters) || child(node.type) || child(node.body);
case 132 /* TypeReference */:
@@ -2221,64 +2227,64 @@ var ts;
return child(node.left) || child(node.right);
case 157 /* ConditionalExpression */:
return child(node.condition) || child(node.whenTrue) || child(node.whenFalse);
- case 161 /* Block */:
- case 180 /* TryBlock */:
- case 182 /* FinallyBlock */:
- case 186 /* FunctionBlock */:
- case 192 /* ModuleBlock */:
- case 196 /* SourceFile */:
+ case 162 /* Block */:
+ case 181 /* TryBlock */:
+ case 183 /* FinallyBlock */:
+ case 187 /* FunctionBlock */:
+ case 193 /* ModuleBlock */:
+ case 197 /* SourceFile */:
return children(node.statements);
- case 162 /* VariableStatement */:
+ case 163 /* VariableStatement */:
return children(node.declarations);
- case 164 /* ExpressionStatement */:
+ case 165 /* ExpressionStatement */:
return child(node.expression);
- case 165 /* IfStatement */:
+ case 166 /* IfStatement */:
return child(node.expression) || child(node.thenStatement) || child(node.elseStatement);
- case 166 /* DoStatement */:
+ case 167 /* DoStatement */:
return child(node.statement) || child(node.expression);
- case 167 /* WhileStatement */:
+ case 168 /* WhileStatement */:
return child(node.expression) || child(node.statement);
- case 168 /* ForStatement */:
+ case 169 /* ForStatement */:
return children(node.declarations) || child(node.initializer) || child(node.condition) || child(node.iterator) || child(node.statement);
- case 169 /* ForInStatement */:
- return child(node.declaration) || child(node.variable) || child(node.expression) || child(node.statement);
- case 170 /* ContinueStatement */:
- case 171 /* BreakStatement */:
+ case 170 /* ForInStatement */:
+ return children(node.declarations) || child(node.variable) || child(node.expression) || child(node.statement);
+ case 171 /* ContinueStatement */:
+ case 172 /* BreakStatement */:
return child(node.label);
- case 172 /* ReturnStatement */:
+ case 173 /* ReturnStatement */:
return child(node.expression);
- case 173 /* WithStatement */:
+ case 174 /* WithStatement */:
return child(node.expression) || child(node.statement);
- case 174 /* SwitchStatement */:
+ case 175 /* SwitchStatement */:
return child(node.expression) || children(node.clauses);
- case 175 /* CaseClause */:
- case 176 /* DefaultClause */:
+ case 176 /* CaseClause */:
+ case 177 /* DefaultClause */:
return child(node.expression) || children(node.statements);
- case 177 /* LabeledStatement */:
+ case 178 /* LabeledStatement */:
return child(node.label) || child(node.statement);
- case 178 /* ThrowStatement */:
+ case 179 /* ThrowStatement */:
return child(node.expression);
- case 179 /* TryStatement */:
+ case 180 /* TryStatement */:
return child(node.tryBlock) || child(node.catchBlock) || child(node.finallyBlock);
- case 181 /* CatchBlock */:
+ case 182 /* CatchBlock */:
return child(node.variable) || children(node.statements);
- case 184 /* VariableDeclaration */:
+ case 185 /* VariableDeclaration */:
return child(node.name) || child(node.type) || child(node.initializer);
- case 187 /* ClassDeclaration */:
+ case 188 /* ClassDeclaration */:
return child(node.name) || children(node.typeParameters) || child(node.baseType) || children(node.implementedTypes) || children(node.members);
- case 188 /* InterfaceDeclaration */:
+ case 189 /* InterfaceDeclaration */:
return child(node.name) || children(node.typeParameters) || children(node.baseTypes) || children(node.members);
- case 189 /* TypeAliasDeclaration */:
+ case 190 /* TypeAliasDeclaration */:
return child(node.name) || child(node.type);
- case 190 /* EnumDeclaration */:
+ case 191 /* EnumDeclaration */:
return child(node.name) || children(node.members);
- case 195 /* EnumMember */:
+ case 196 /* EnumMember */:
return child(node.name) || child(node.initializer);
- case 191 /* ModuleDeclaration */:
+ case 192 /* ModuleDeclaration */:
return child(node.name) || child(node.body);
- case 193 /* ImportDeclaration */:
+ case 194 /* ImportDeclaration */:
return child(node.name) || child(node.entityName) || child(node.externalModuleName);
- case 194 /* ExportAssignment */:
+ case 195 /* ExportAssignment */:
return child(node.exportName);
case 158 /* TemplateExpression */:
return child(node.head) || children(node.templateSpans);
@@ -2291,24 +2297,24 @@ var ts;
return traverse(body);
function traverse(node) {
switch (node.kind) {
- case 172 /* ReturnStatement */:
+ case 173 /* ReturnStatement */:
return visitor(node);
- case 161 /* Block */:
- case 186 /* FunctionBlock */:
- case 165 /* IfStatement */:
- case 166 /* DoStatement */:
- case 167 /* WhileStatement */:
- case 168 /* ForStatement */:
- case 169 /* ForInStatement */:
- case 173 /* WithStatement */:
- case 174 /* SwitchStatement */:
- case 175 /* CaseClause */:
- case 176 /* DefaultClause */:
- case 177 /* LabeledStatement */:
- case 179 /* TryStatement */:
- case 180 /* TryBlock */:
- case 181 /* CatchBlock */:
- case 182 /* FinallyBlock */:
+ case 162 /* Block */:
+ case 187 /* FunctionBlock */:
+ case 166 /* IfStatement */:
+ case 167 /* DoStatement */:
+ case 168 /* WhileStatement */:
+ case 169 /* ForStatement */:
+ case 170 /* ForInStatement */:
+ case 174 /* WithStatement */:
+ case 175 /* SwitchStatement */:
+ case 176 /* CaseClause */:
+ case 177 /* DefaultClause */:
+ case 178 /* LabeledStatement */:
+ case 180 /* TryStatement */:
+ case 181 /* TryBlock */:
+ case 182 /* CatchBlock */:
+ case 183 /* FinallyBlock */:
return forEachChild(node, traverse);
}
}
@@ -2318,7 +2324,7 @@ var ts;
if (node) {
switch (node.kind) {
case 152 /* FunctionExpression */:
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
case 153 /* ArrowFunction */:
case 125 /* Method */:
case 127 /* GetAccessor */:
@@ -2350,16 +2356,16 @@ var ts;
if (!includeArrowFunctions) {
continue;
}
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
case 152 /* FunctionExpression */:
- case 191 /* ModuleDeclaration */:
+ case 192 /* ModuleDeclaration */:
case 124 /* Property */:
case 125 /* Method */:
case 126 /* Constructor */:
case 127 /* GetAccessor */:
case 128 /* SetAccessor */:
- case 190 /* EnumDeclaration */:
- case 196 /* SourceFile */:
+ case 191 /* EnumDeclaration */:
+ case 197 /* SourceFile */:
return node;
}
}
@@ -2382,6 +2388,13 @@ var ts;
}
}
ts.getSuperContainer = getSuperContainer;
+ function getInvokedExpression(node) {
+ if (node.kind === 149 /* TaggedTemplateExpression */) {
+ return node.tag;
+ }
+ return node.func;
+ }
+ ts.getInvokedExpression = getInvokedExpression;
function isExpression(node) {
switch (node.kind) {
case 91 /* ThisKeyword */:
@@ -2407,7 +2420,7 @@ var ts;
case 157 /* ConditionalExpression */:
case 158 /* TemplateExpression */:
case 9 /* NoSubstitutionTemplateLiteral */:
- case 160 /* OmittedExpression */:
+ case 161 /* OmittedExpression */:
return true;
case 121 /* QualifiedName */:
while (node.parent.kind === 121 /* QualifiedName */)
@@ -2421,26 +2434,26 @@ var ts;
case 7 /* StringLiteral */:
var parent = node.parent;
switch (parent.kind) {
- case 184 /* VariableDeclaration */:
+ case 185 /* VariableDeclaration */:
case 123 /* Parameter */:
case 124 /* Property */:
- case 195 /* EnumMember */:
+ case 196 /* EnumMember */:
case 143 /* PropertyAssignment */:
return parent.initializer === node;
- case 164 /* ExpressionStatement */:
- case 165 /* IfStatement */:
- case 166 /* DoStatement */:
- case 167 /* WhileStatement */:
- case 172 /* ReturnStatement */:
- case 173 /* WithStatement */:
- case 174 /* SwitchStatement */:
- case 175 /* CaseClause */:
- case 178 /* ThrowStatement */:
- case 174 /* SwitchStatement */:
+ case 165 /* ExpressionStatement */:
+ case 166 /* IfStatement */:
+ case 167 /* DoStatement */:
+ case 168 /* WhileStatement */:
+ case 173 /* ReturnStatement */:
+ case 174 /* WithStatement */:
+ case 175 /* SwitchStatement */:
+ case 176 /* CaseClause */:
+ case 179 /* ThrowStatement */:
+ case 175 /* SwitchStatement */:
return parent.expression === node;
- case 168 /* ForStatement */:
+ case 169 /* ForStatement */:
return parent.initializer === node || parent.condition === node || parent.iterator === node;
- case 169 /* ForInStatement */:
+ case 170 /* ForInStatement */:
return parent.variable === node || parent.expression === node;
case 150 /* TypeAssertion */:
return node === parent.operand;
@@ -2484,21 +2497,22 @@ var ts;
switch (node.kind) {
case 122 /* TypeParameter */:
case 123 /* Parameter */:
- case 184 /* VariableDeclaration */:
+ case 185 /* VariableDeclaration */:
case 124 /* Property */:
case 143 /* PropertyAssignment */:
case 144 /* ShorthandPropertyAssignment */:
- case 195 /* EnumMember */:
+ case 196 /* EnumMember */:
case 125 /* Method */:
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
case 127 /* GetAccessor */:
case 128 /* SetAccessor */:
- case 187 /* ClassDeclaration */:
- case 188 /* InterfaceDeclaration */:
- case 189 /* TypeAliasDeclaration */:
- case 190 /* EnumDeclaration */:
- case 191 /* ModuleDeclaration */:
- case 193 /* ImportDeclaration */:
+ case 126 /* Constructor */:
+ case 188 /* ClassDeclaration */:
+ case 189 /* InterfaceDeclaration */:
+ case 190 /* TypeAliasDeclaration */:
+ case 191 /* EnumDeclaration */:
+ case 192 /* ModuleDeclaration */:
+ case 194 /* ImportDeclaration */:
return true;
}
return false;
@@ -2506,24 +2520,24 @@ var ts;
ts.isDeclaration = isDeclaration;
function isStatement(n) {
switch (n.kind) {
- case 171 /* BreakStatement */:
- case 170 /* ContinueStatement */:
- case 183 /* DebuggerStatement */:
- case 166 /* DoStatement */:
- case 164 /* ExpressionStatement */:
- case 163 /* EmptyStatement */:
- case 169 /* ForInStatement */:
- case 168 /* ForStatement */:
- case 165 /* IfStatement */:
- case 177 /* LabeledStatement */:
- case 172 /* ReturnStatement */:
- case 174 /* SwitchStatement */:
+ case 172 /* BreakStatement */:
+ case 171 /* ContinueStatement */:
+ case 184 /* DebuggerStatement */:
+ case 167 /* DoStatement */:
+ case 165 /* ExpressionStatement */:
+ case 164 /* EmptyStatement */:
+ case 170 /* ForInStatement */:
+ case 169 /* ForStatement */:
+ case 166 /* IfStatement */:
+ case 178 /* LabeledStatement */:
+ case 173 /* ReturnStatement */:
+ case 175 /* SwitchStatement */:
case 92 /* ThrowKeyword */:
- case 179 /* TryStatement */:
- case 162 /* VariableStatement */:
- case 167 /* WhileStatement */:
- case 173 /* WithStatement */:
- case 194 /* ExportAssignment */:
+ case 180 /* TryStatement */:
+ case 163 /* VariableStatement */:
+ case 168 /* WhileStatement */:
+ case 174 /* WithStatement */:
+ case 195 /* ExportAssignment */:
return true;
default:
return false;
@@ -2538,24 +2552,32 @@ var ts;
if (isDeclaration(parent) || parent.kind === 152 /* FunctionExpression */) {
return parent.name === name;
}
- if (parent.kind === 181 /* CatchBlock */) {
+ if (parent.kind === 182 /* CatchBlock */) {
return parent.variable === name;
}
return false;
}
ts.isDeclarationOrFunctionExpressionOrCatchVariableName = isDeclarationOrFunctionExpressionOrCatchVariableName;
+ function tryResolveScriptReference(program, sourceFile, reference) {
+ if (!program.getCompilerOptions().noResolve) {
+ var referenceFileName = ts.isRootedDiskPath(reference.filename) ? reference.filename : ts.combinePaths(ts.getDirectoryPath(sourceFile.filename), reference.filename);
+ referenceFileName = ts.getNormalizedAbsolutePath(referenceFileName, program.getCompilerHost().getCurrentDirectory());
+ return program.getSourceFile(referenceFileName);
+ }
+ }
+ ts.tryResolveScriptReference = tryResolveScriptReference;
function getAncestor(node, kind) {
switch (kind) {
- case 187 /* ClassDeclaration */:
+ case 188 /* ClassDeclaration */:
while (node) {
switch (node.kind) {
- case 187 /* ClassDeclaration */:
+ case 188 /* ClassDeclaration */:
return node;
- case 190 /* EnumDeclaration */:
- case 188 /* InterfaceDeclaration */:
- case 189 /* TypeAliasDeclaration */:
- case 191 /* ModuleDeclaration */:
- case 193 /* ImportDeclaration */:
+ case 191 /* EnumDeclaration */:
+ case 189 /* InterfaceDeclaration */:
+ case 190 /* TypeAliasDeclaration */:
+ case 192 /* ModuleDeclaration */:
+ case 194 /* ImportDeclaration */:
return undefined;
default:
node = node.parent;
@@ -2640,11 +2662,14 @@ var ts;
}
ts.isTrivia = isTrivia;
function isUnterminatedTemplateEnd(node) {
- ts.Debug.assert(node.kind === 9 /* NoSubstitutionTemplateLiteral */ || node.kind === 12 /* TemplateTail */);
+ ts.Debug.assert(isTemplateLiteralKind(node.kind));
var sourceText = getSourceFileOfNode(node).text;
if (node.end !== sourceText.length) {
return false;
}
+ if (node.kind !== 12 /* TemplateTail */ && node.kind !== 9 /* NoSubstitutionTemplateLiteral */) {
+ return false;
+ }
return sourceText.charCodeAt(node.end - 1) !== 96 /* backtick */ || node.text.length === 0;
}
ts.isUnterminatedTemplateEnd = isUnterminatedTemplateEnd;
@@ -2661,6 +2686,17 @@ var ts;
return false;
}
ts.isModifier = isModifier;
+ function modifierToFlag(token) {
+ switch (token) {
+ case 107 /* StaticKeyword */: return 128 /* Static */;
+ case 106 /* PublicKeyword */: return 16 /* Public */;
+ case 105 /* ProtectedKeyword */: return 64 /* Protected */;
+ case 104 /* PrivateKeyword */: return 32 /* Private */;
+ case 76 /* ExportKeyword */: return 1 /* Export */;
+ case 112 /* DeclareKeyword */: return 2 /* Ambient */;
+ }
+ return 0;
+ }
function createSourceFile(filename, sourceText, languageVersion, version, isOpen) {
if (isOpen === void 0) { isOpen = false; }
var file;
@@ -2672,86 +2708,76 @@ var ts;
var identifierCount = 0;
var nodeCount = 0;
var lineStarts;
- var isInStrictMode = false;
var lookAheadMode = 0 /* NotLookingAhead */;
- var inAmbientContext = false;
- var inFunctionBody = false;
- var inSwitchStatement = 0 /* NotNested */;
- var inIterationStatement = 0 /* NotNested */;
- var labelledStatementInfo = (function () {
- var functionBoundarySentinel;
- var currentLabelSet;
- var labelSetStack;
- var isIterationStack;
- function addLabel(label) {
- if (!currentLabelSet) {
- currentLabelSet = {};
- }
- currentLabelSet[label.text] = true;
+ var contextFlags = 0;
+ function setContextFlag(val, flag) {
+ if (val) {
+ contextFlags |= flag;
}
- function pushCurrentLabelSet(isIterationStatement) {
- if (!labelSetStack && !isIterationStack) {
- labelSetStack = [];
- isIterationStack = [];
- }
- ts.Debug.assert(currentLabelSet !== undefined);
- labelSetStack.push(currentLabelSet);
- isIterationStack.push(isIterationStatement);
- currentLabelSet = undefined;
+ else {
+ contextFlags &= ~flag;
}
- function pushFunctionBoundary() {
- if (!functionBoundarySentinel) {
- functionBoundarySentinel = {};
- if (!labelSetStack && !isIterationStack) {
- labelSetStack = [];
- isIterationStack = [];
- }
- }
- ts.Debug.assert(currentLabelSet === undefined);
- labelSetStack.push(functionBoundarySentinel);
- isIterationStack.push(false);
+ }
+ function setStrictModeContext(val) {
+ setContextFlag(val, 1 /* StrictMode */);
+ }
+ function setDisallowInContext(val) {
+ setContextFlag(val, 2 /* DisallowIn */);
+ }
+ function setYieldContext(val) {
+ setContextFlag(val, 4 /* Yield */);
+ }
+ function setGeneratorParameterContext(val) {
+ setContextFlag(val, 8 /* GeneratorParameter */);
+ }
+ function allowInAnd(func) {
+ if (contextFlags & 2 /* DisallowIn */) {
+ setDisallowInContext(false);
+ var result = func();
+ setDisallowInContext(true);
+ return result;
}
- function pop() {
- ts.Debug.assert(labelSetStack.length && isIterationStack.length && currentLabelSet === undefined);
- labelSetStack.pop();
- isIterationStack.pop();
+ return func();
+ }
+ function disallowInAnd(func) {
+ if (contextFlags & 2 /* DisallowIn */) {
+ return func();
}
- function nodeIsNestedInLabel(label, requireIterationStatement, stopAtFunctionBoundary) {
- if (!requireIterationStatement && currentLabelSet && ts.hasProperty(currentLabelSet, label.text)) {
- return 1 /* Nested */;
- }
- if (!labelSetStack) {
- return 0 /* NotNested */;
- }
- var crossedFunctionBoundary = false;
- for (var i = labelSetStack.length - 1; i >= 0; i--) {
- var labelSet = labelSetStack[i];
- if (labelSet === functionBoundarySentinel) {
- if (stopAtFunctionBoundary) {
- break;
- }
- else {
- crossedFunctionBoundary = true;
- continue;
- }
- }
- if (requireIterationStatement && isIterationStack[i] === false) {
- continue;
- }
- if (ts.hasProperty(labelSet, label.text)) {
- return crossedFunctionBoundary ? 2 /* CrossingFunctionBoundary */ : 1 /* Nested */;
- }
- }
- return 0 /* NotNested */;
+ setDisallowInContext(true);
+ var result = func();
+ setDisallowInContext(false);
+ return result;
+ }
+ function doInYieldContext(func) {
+ if (contextFlags & 4 /* Yield */) {
+ return func();
}
- return {
- addLabel: addLabel,
- pushCurrentLabelSet: pushCurrentLabelSet,
- pushFunctionBoundary: pushFunctionBoundary,
- pop: pop,
- nodeIsNestedInLabel: nodeIsNestedInLabel
- };
- })();
+ setYieldContext(true);
+ var result = func();
+ setYieldContext(false);
+ return result;
+ }
+ function doOutsideOfYieldContext(func) {
+ if (contextFlags & 4 /* Yield */) {
+ setYieldContext(false);
+ var result = func();
+ setYieldContext(true);
+ return result;
+ }
+ return func();
+ }
+ function inYieldContext() {
+ return (contextFlags & 4 /* Yield */) !== 0;
+ }
+ function inStrictModeContext() {
+ return (contextFlags & 1 /* StrictMode */) !== 0;
+ }
+ function inGeneratorParameterContext() {
+ return (contextFlags & 8 /* GeneratorParameter */) !== 0;
+ }
+ function inDisallowInContext() {
+ return (contextFlags & 2 /* DisallowIn */) !== 0;
+ }
function getLineStarts() {
return lineStarts || (lineStarts = ts.computeLineStarts(sourceText));
}
@@ -2766,25 +2792,12 @@ var ts;
var length = scanner.getTextPos() - start;
errorAtPos(start, length, message, arg0, arg1, arg2);
}
- function grammarErrorOnNode(node, message, arg0, arg1, arg2) {
- var span = getErrorSpanForNode(node);
- var start = span.end > span.pos ? ts.skipTrivia(file.text, span.pos) : span.pos;
- var length = span.end - start;
- file.syntacticErrors.push(ts.createFileDiagnostic(file, start, length, message, arg0, arg1, arg2));
- }
- function reportInvalidUseInStrictMode(node) {
- var name = sourceText.substring(ts.skipTrivia(sourceText, node.pos), node.end);
- grammarErrorOnNode(node, ts.Diagnostics.Invalid_use_of_0_in_strict_mode, name);
- }
- function grammarErrorAtPos(start, length, message, arg0, arg1, arg2) {
- file.syntacticErrors.push(ts.createFileDiagnostic(file, start, length, message, arg0, arg1, arg2));
- }
function errorAtPos(start, length, message, arg0, arg1, arg2) {
- var lastErrorPos = file.syntacticErrors.length ? file.syntacticErrors[file.syntacticErrors.length - 1].start : -1;
+ var lastErrorPos = file.parseDiagnostics.length ? file.parseDiagnostics[file.parseDiagnostics.length - 1].start : -1;
if (start !== lastErrorPos) {
var diagnostic = ts.createFileDiagnostic(file, start, length, message, arg0, arg1, arg2);
diagnostic.isParseError = true;
- file.syntacticErrors.push(diagnostic);
+ file.parseDiagnostics.push(diagnostic);
}
if (lookAheadMode === 1 /* NoErrorYet */) {
lookAheadMode = 2 /* Error */;
@@ -2821,7 +2834,7 @@ var ts;
}
function lookAheadHelper(callback, alwaysResetState) {
var saveToken = token;
- var saveSyntacticErrorsLength = file.syntacticErrors.length;
+ var saveSyntacticErrorsLength = file.parseDiagnostics.length;
var saveLookAheadMode = lookAheadMode;
lookAheadMode = 1 /* NoErrorYet */;
var result = callback();
@@ -2832,7 +2845,7 @@ var ts;
lookAheadMode = saveLookAheadMode;
if (!result || alwaysResetState) {
token = saveToken;
- file.syntacticErrors.length = saveSyntacticErrorsLength;
+ file.parseDiagnostics.length = saveSyntacticErrorsLength;
}
return result;
}
@@ -2848,7 +2861,13 @@ var ts;
return scanner.tryScan(function () { return lookAheadHelper(callback, false); });
}
function isIdentifier() {
- return token === 63 /* Identifier */ || (isInStrictMode ? token > 108 /* LastFutureReservedWord */ : token > 99 /* LastReservedWord */);
+ if (token === 63 /* Identifier */) {
+ return true;
+ }
+ if (token === 108 /* YieldKeyword */ && inYieldContext()) {
+ return false;
+ }
+ return inStrictModeContext() ? token > 108 /* LastFutureReservedWord */ : token > 99 /* LastReservedWord */;
}
function parseExpected(t) {
if (token === t) {
@@ -2865,6 +2884,14 @@ var ts;
}
return false;
}
+ function parseOptionalToken(t) {
+ if (token === t) {
+ var node = createNode(t);
+ nextToken();
+ return finishNode(node);
+ }
+ return undefined;
+ }
function canParseSemicolon() {
if (token === 21 /* SemicolonToken */) {
return true;
@@ -2884,18 +2911,22 @@ var ts;
function createNode(kind, pos) {
nodeCount++;
var node = new (nodeConstructors[kind] || (nodeConstructors[kind] = ts.objectAllocator.getNodeConstructor(kind)))();
- if (!(pos >= 0))
+ if (!(pos >= 0)) {
pos = scanner.getStartPos();
+ }
node.pos = pos;
node.end = pos;
return node;
}
function finishNode(node) {
node.end = scanner.getStartPos();
+ if (contextFlags) {
+ node.parserContextFlags = contextFlags;
+ }
return node;
}
- function createMissingNode() {
- return createNode(120 /* Missing */);
+ function createMissingNode(pos) {
+ return createNode(120 /* Missing */, pos);
}
function internIdentifier(text) {
text = escapeIdentifier(text);
@@ -2938,7 +2969,7 @@ var ts;
function parseAnyContextualModifier() {
return isModifier(token) && tryParse(function () {
nextToken();
- return token === 17 /* OpenBracketToken */ || isPropertyName();
+ return token === 17 /* OpenBracketToken */ || token === 34 /* AsteriskToken */ || isPropertyName();
});
}
function isListElement(kind, inErrorRecovery) {
@@ -2956,8 +2987,9 @@ var ts;
case 6 /* ClassMembers */:
return lookAhead(isClassMemberStart);
case 7 /* EnumMembers */:
- case 11 /* ObjectLiteralMembers */:
return isPropertyName();
+ case 11 /* ObjectLiteralMembers */:
+ return token === 34 /* AsteriskToken */ || isPropertyName();
case 8 /* BaseTypeReferences */:
return isIdentifier() && ((token !== 77 /* ExtendsKeyword */ && token !== 100 /* ImplementsKeyword */) || !lookAhead(function () { return (nextToken(), isIdentifier()); }));
case 9 /* VariableDeclarations */:
@@ -3034,15 +3066,15 @@ var ts;
parsingContext |= 1 << kind;
var result = [];
result.pos = getNodePos();
- var saveIsInStrictMode = isInStrictMode;
+ var savedStrictModeContext = inStrictModeContext();
while (!isListTerminator(kind)) {
if (isListElement(kind, false)) {
var element = parseElement();
result.push(element);
- if (!isInStrictMode && checkForStrictMode) {
+ if (!inStrictModeContext() && checkForStrictMode) {
if (isPrologueDirective(element)) {
if (isUseStrictPrologueDirective(element)) {
- isInStrictMode = true;
+ setStrictModeContext(true);
checkForStrictMode = false;
}
}
@@ -3059,17 +3091,16 @@ var ts;
nextToken();
}
}
- isInStrictMode = saveIsInStrictMode;
+ setStrictModeContext(savedStrictModeContext);
result.end = getNodeEnd();
parsingContext = saveParsingContext;
return result;
}
- function parseDelimitedList(kind, parseElement, allowTrailingComma) {
+ function parseDelimitedList(kind, parseElement) {
var saveParsingContext = parsingContext;
parsingContext |= 1 << kind;
var result = [];
result.pos = getNodePos();
- var errorCountBeforeParsingList = file.syntacticErrors.length;
var commaStart = -1;
while (true) {
if (isListElement(kind, false)) {
@@ -3096,11 +3127,6 @@ var ts;
}
}
if (commaStart >= 0) {
- if (!allowTrailingComma) {
- if (file.syntacticErrors.length === errorCountBeforeParsingList) {
- grammarErrorAtPos(commaStart, scanner.getStartPos() - commaStart, ts.Diagnostics.Trailing_comma_not_allowed);
- }
- }
result.hasTrailingComma = true;
}
result.end = getNodeEnd();
@@ -3114,16 +3140,10 @@ var ts;
result.end = pos;
return result;
}
- function createNodeArray(node) {
- var result = [node];
- result.pos = node.pos;
- result.end = node.end;
- return result;
- }
- function parseBracketedList(kind, parseElement, startToken, endToken) {
- if (parseExpected(startToken)) {
- var result = parseDelimitedList(kind, parseElement, false);
- parseExpected(endToken);
+ function parseBracketedList(kind, parseElement, open, close) {
+ if (parseExpected(open)) {
+ var result = parseDelimitedList(kind, parseElement);
+ parseExpected(close);
return result;
}
return createMissingList();
@@ -3158,7 +3178,7 @@ var ts;
}
function parseTemplateSpan() {
var span = createNode(159 /* TemplateSpan */);
- span.expression = parseExpression(false);
+ span.expression = allowInAnd(parseExpression);
var literal;
if (token === 14 /* CloseBraceToken */) {
reScanTemplateToken();
@@ -3180,12 +3200,7 @@ var ts;
nextToken();
finishNode(node);
if (node.kind === 6 /* NumericLiteral */ && sourceText.charCodeAt(tokenPos) === 48 /* _0 */ && ts.isOctalDigit(sourceText.charCodeAt(tokenPos + 1))) {
- if (isInStrictMode) {
- grammarErrorOnNode(node, ts.Diagnostics.Octal_literals_are_not_allowed_in_strict_mode);
- }
- else if (languageVersion >= 1 /* ES5 */) {
- grammarErrorOnNode(node, ts.Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher);
- }
+ node.flags |= 8192 /* OctalLiteral */;
}
return node;
}
@@ -3218,22 +3233,14 @@ var ts;
node.constraint = parseType();
}
else {
- var expr = parseUnaryExpression();
- grammarErrorOnNode(expr, ts.Diagnostics.Type_expected);
+ node.expression = parseUnaryExpression();
}
}
return finishNode(node);
}
function parseTypeParameters() {
if (token === 23 /* LessThanToken */) {
- var pos = getNodePos();
- var result = parseBracketedList(14 /* TypeParameters */, parseTypeParameter, 23 /* LessThanToken */, 24 /* GreaterThanToken */);
- if (!result.length) {
- var start = getTokenPos(pos);
- var length = getNodePos() - start;
- errorAtPos(start, length, ts.Diagnostics.Type_parameter_list_cannot_be_empty);
- }
- return result;
+ return parseBracketedList(14 /* TypeParameters */, parseTypeParameter, 23 /* LessThanToken */, 24 /* GreaterThanToken */);
}
}
function parseParameterType() {
@@ -3242,14 +3249,20 @@ var ts;
function isStartOfParameter() {
return token === 20 /* DotDotDotToken */ || isIdentifier() || isModifier(token);
}
- function parseParameter(flags) {
- if (flags === void 0) { flags = 0; }
+ function setModifiers(node, modifiers) {
+ if (modifiers) {
+ node.flags |= modifiers.flags;
+ node.modifiers = modifiers;
+ }
+ }
+ function parseParameter() {
var node = createNode(123 /* Parameter */);
- node.flags |= parseAndCheckModifiers(3 /* Parameters */);
+ var modifiers = parseModifiers();
+ setModifiers(node, modifiers);
if (parseOptional(20 /* DotDotDotToken */)) {
node.flags |= 8 /* Rest */;
}
- node.name = parseIdentifier();
+ node.name = inGeneratorParameterContext() ? doInYieldContext(parseIdentifier) : parseIdentifier();
if (node.name.kind === 120 /* Missing */ && node.flags === 0 && isModifier(token)) {
nextToken();
}
@@ -3257,153 +3270,82 @@ var ts;
node.flags |= 4 /* QuestionMark */;
}
node.type = parseParameterType();
- node.initializer = parseInitializer(true);
+ node.initializer = inGeneratorParameterContext() ? doOutsideOfYieldContext(parseParameterInitializer) : parseParameterInitializer();
return finishNode(node);
}
- function parseSignature(kind, returnToken, returnTokenRequired) {
+ function parseParameterInitializer() {
+ return parseInitializer(true);
+ }
+ function parseSignature(kind, returnToken, returnTokenRequired, yieldAndGeneratorParameterContext) {
+ var signature = {};
+ fillSignature(kind, returnToken, returnTokenRequired, yieldAndGeneratorParameterContext, signature);
+ return signature;
+ }
+ function fillSignature(kind, returnToken, returnTokenRequired, yieldAndGeneratorParameterContext, signature) {
if (kind === 130 /* ConstructSignature */) {
parseExpected(86 /* NewKeyword */);
}
- var typeParameters = parseTypeParameters();
- var parameters = parseParameterList(15 /* OpenParenToken */, 16 /* CloseParenToken */);
- checkParameterList(parameters);
- var type;
+ signature.typeParameters = parseTypeParameters();
+ signature.parameters = parseParameterList(yieldAndGeneratorParameterContext);
if (returnTokenRequired) {
parseExpected(returnToken);
- type = parseType();
+ signature.type = parseType();
}
else if (parseOptional(returnToken)) {
- type = parseType();
+ signature.type = parseType();
}
- return {
- typeParameters: typeParameters,
- parameters: parameters,
- type: type
- };
}
- function parseParameterList(startDelimiter, endDelimiter) {
- return parseBracketedList(13 /* Parameters */, parseParameter, startDelimiter, endDelimiter);
- }
- function checkParameterList(parameters) {
- var seenOptionalParameter = false;
- var parameterCount = parameters.length;
- for (var i = 0; i < parameterCount; i++) {
- var parameter = parameters[i];
- if (isInStrictMode && isEvalOrArgumentsIdentifier(parameter.name)) {
- reportInvalidUseInStrictMode(parameter.name);
- return;
- }
- else if (parameter.flags & 8 /* Rest */) {
- if (i !== (parameterCount - 1)) {
- grammarErrorOnNode(parameter.name, ts.Diagnostics.A_rest_parameter_must_be_last_in_a_parameter_list);
- return;
- }
- if (parameter.flags & 4 /* QuestionMark */) {
- grammarErrorOnNode(parameter.name, ts.Diagnostics.A_rest_parameter_cannot_be_optional);
- return;
- }
- if (parameter.initializer) {
- grammarErrorOnNode(parameter.name, ts.Diagnostics.A_rest_parameter_cannot_have_an_initializer);
- return;
- }
- }
- else if (parameter.flags & 4 /* QuestionMark */ || parameter.initializer) {
- seenOptionalParameter = true;
- if (parameter.flags & 4 /* QuestionMark */ && parameter.initializer) {
- grammarErrorOnNode(parameter.name, ts.Diagnostics.Parameter_cannot_have_question_mark_and_initializer);
- return;
- }
- }
- else {
- if (seenOptionalParameter) {
- grammarErrorOnNode(parameter.name, ts.Diagnostics.A_required_parameter_cannot_follow_an_optional_parameter);
- return;
- }
- }
+ function parseParameterList(yieldAndGeneratorParameterContext) {
+ if (parseExpected(15 /* OpenParenToken */)) {
+ var savedYieldContext = inYieldContext();
+ var savedGeneratorParameterContext = inGeneratorParameterContext();
+ setYieldContext(yieldAndGeneratorParameterContext);
+ setGeneratorParameterContext(yieldAndGeneratorParameterContext);
+ var result = parseDelimitedList(13 /* Parameters */, parseParameter);
+ parseExpected(16 /* CloseParenToken */);
+ setYieldContext(savedYieldContext);
+ setGeneratorParameterContext(savedGeneratorParameterContext);
+ return result;
}
+ return createMissingList();
}
function parseSignatureMember(kind, returnToken) {
var node = createNode(kind);
- var sig = parseSignature(kind, returnToken, false);
- node.typeParameters = sig.typeParameters;
- node.parameters = sig.parameters;
- node.type = sig.type;
+ fillSignature(kind, returnToken, false, false, node);
parseSemicolon();
return finishNode(node);
}
- function parseIndexSignatureMember() {
- var node = createNode(131 /* IndexSignature */);
- var errorCountBeforeIndexSignature = file.syntacticErrors.length;
- var indexerStart = scanner.getTokenPos();
- node.parameters = parseParameterList(17 /* OpenBracketToken */, 18 /* CloseBracketToken */);
- var indexerLength = scanner.getStartPos() - indexerStart;
+ function parseIndexSignatureMember(fullStart, modifiers) {
+ var node = createNode(131 /* IndexSignature */, fullStart);
+ setModifiers(node, modifiers);
+ node.parameters = parseBracketedList(13 /* Parameters */, parseParameter, 17 /* OpenBracketToken */, 18 /* CloseBracketToken */);
node.type = parseTypeAnnotation();
parseSemicolon();
- if (file.syntacticErrors.length === errorCountBeforeIndexSignature) {
- checkIndexSignature(node, indexerStart, indexerLength);
- }
return finishNode(node);
}
- function checkIndexSignature(node, indexerStart, indexerLength) {
- var parameter = node.parameters[0];
- if (node.parameters.length !== 1) {
- var arityDiagnostic = ts.Diagnostics.An_index_signature_must_have_exactly_one_parameter;
- if (parameter) {
- grammarErrorOnNode(parameter.name, arityDiagnostic);
- }
- else {
- grammarErrorAtPos(indexerStart, indexerLength, arityDiagnostic);
- }
- return;
- }
- else if (parameter.flags & 8 /* Rest */) {
- grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_cannot_have_a_rest_parameter);
- return;
- }
- else if (parameter.flags & 243 /* Modifier */) {
- grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_cannot_have_an_accessibility_modifier);
- return;
- }
- else if (parameter.flags & 4 /* QuestionMark */) {
- grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_cannot_have_a_question_mark);
- return;
- }
- else if (parameter.initializer) {
- grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_cannot_have_an_initializer);
- return;
- }
- else if (!parameter.type) {
- grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_must_have_a_type_annotation);
- return;
- }
- else if (parameter.type.kind !== 118 /* StringKeyword */ && parameter.type.kind !== 116 /* NumberKeyword */) {
- grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_type_must_be_string_or_number);
- return;
- }
- else if (!node.type) {
- grammarErrorAtPos(indexerStart, indexerLength, ts.Diagnostics.An_index_signature_must_have_a_type_annotation);
- return;
- }
- }
function parsePropertyOrMethod() {
- var node = createNode(0 /* Unknown */);
- node.name = parsePropertyName();
+ var fullStart = scanner.getStartPos();
+ var name = parsePropertyName();
+ var flags = 0;
if (parseOptional(49 /* QuestionToken */)) {
- node.flags |= 4 /* QuestionMark */;
+ flags = 4 /* QuestionMark */;
}
if (token === 15 /* OpenParenToken */ || token === 23 /* LessThanToken */) {
- node.kind = 125 /* Method */;
- var sig = parseSignature(129 /* CallSignature */, 50 /* ColonToken */, false);
- node.typeParameters = sig.typeParameters;
- node.parameters = sig.parameters;
- node.type = sig.type;
+ var method = createNode(125 /* Method */, fullStart);
+ method.name = name;
+ method.flags = flags;
+ fillSignature(129 /* CallSignature */, 50 /* ColonToken */, false, false, method);
+ parseSemicolon();
+ return finishNode(method);
}
else {
- node.kind = 124 /* Property */;
- node.type = parseTypeAnnotation();
+ var property = createNode(124 /* Property */, fullStart);
+ property.name = name;
+ property.flags = flags;
+ property.type = parseTypeAnnotation();
+ parseSemicolon();
+ return finishNode(property);
}
- parseSemicolon();
- return finishNode(node);
}
function isStartOfTypeMember() {
switch (token) {
@@ -3421,7 +3363,7 @@ var ts;
case 23 /* LessThanToken */:
return parseSignatureMember(129 /* CallSignature */, 50 /* ColonToken */);
case 17 /* OpenBracketToken */:
- return parseIndexSignatureMember();
+ return parseIndexSignatureMember(scanner.getStartPos(), undefined);
case 86 /* NewKeyword */:
if (lookAhead(function () { return nextToken() === 15 /* OpenParenToken */ || token === 23 /* LessThanToken */; })) {
return parseSignatureMember(130 /* ConstructSignature */, 50 /* ColonToken */);
@@ -3437,23 +3379,23 @@ var ts;
}
function parseTypeLiteral() {
var node = createNode(136 /* TypeLiteral */);
+ node.members = parseObjectType();
+ return finishNode(node);
+ }
+ function parseObjectType() {
+ var members;
if (parseExpected(13 /* OpenBraceToken */)) {
- node.members = parseList(5 /* TypeMembers */, false, parseTypeMember);
+ members = parseList(5 /* TypeMembers */, false, parseTypeMember);
parseExpected(14 /* CloseBraceToken */);
}
else {
- node.members = createMissingList();
+ members = createMissingList();
}
- return finishNode(node);
+ return members;
}
function parseTupleType() {
var node = createNode(138 /* TupleType */);
- var startTokenPos = scanner.getTokenPos();
- var startErrorCount = file.syntacticErrors.length;
node.elementTypes = parseBracketedList(16 /* TupleElementTypes */, parseType, 17 /* OpenBracketToken */, 18 /* CloseBracketToken */);
- if (!node.elementTypes.length && file.syntacticErrors.length === startErrorCount) {
- grammarErrorAtPos(startTokenPos, scanner.getStartPos() - startTokenPos, ts.Diagnostics.A_tuple_type_element_list_cannot_be_empty);
- }
return finishNode(node);
}
function parseParenType() {
@@ -3464,13 +3406,9 @@ var ts;
return finishNode(node);
}
function parseFunctionType(typeKind) {
- var member = createNode(typeKind);
- var sig = parseSignature(typeKind === 133 /* FunctionType */ ? 129 /* CallSignature */ : 130 /* ConstructSignature */, 31 /* EqualsGreaterThanToken */, true);
- member.typeParameters = sig.typeParameters;
- member.parameters = sig.parameters;
- member.type = sig.type;
- finishNode(member);
- return member;
+ var node = createNode(typeKind);
+ fillSignature(typeKind === 133 /* FunctionType */ ? 129 /* CallSignature */ : 130 /* ConstructSignature */, 31 /* EqualsGreaterThanToken */, true, false, node);
+ return finishNode(node);
}
function parseKeywordAndNoDot() {
var node = parseTokenNode();
@@ -3570,6 +3508,16 @@ var ts;
});
}
function parseType() {
+ var savedYieldContext = inYieldContext();
+ var savedGeneratorParameterContext = inGeneratorParameterContext();
+ setYieldContext(false);
+ setGeneratorParameterContext(false);
+ var result = parseTypeWorker();
+ setYieldContext(savedYieldContext);
+ setGeneratorParameterContext(savedGeneratorParameterContext);
+ return result;
+ }
+ function parseTypeWorker() {
if (isStartOfFunctionType()) {
return parseFunctionType(133 /* FunctionType */);
}
@@ -3610,6 +3558,7 @@ var ts;
case 38 /* MinusMinusToken */:
case 23 /* LessThanToken */:
case 63 /* Identifier */:
+ case 108 /* YieldKeyword */:
return true;
default:
return isIdentifier();
@@ -3618,70 +3567,68 @@ var ts;
function isStartOfExpressionStatement() {
return token !== 13 /* OpenBraceToken */ && token !== 81 /* FunctionKeyword */ && isStartOfExpression();
}
- function parseExpression(noIn) {
- var expr = parseAssignmentExpression(noIn);
+ function parseExpression() {
+ var expr = parseAssignmentExpression();
while (parseOptional(22 /* CommaToken */)) {
- expr = makeBinaryExpression(expr, 22 /* CommaToken */, parseAssignmentExpression(noIn));
+ expr = makeBinaryExpression(expr, 22 /* CommaToken */, parseAssignmentExpression());
}
return expr;
}
- function parseInitializer(inParameter, noIn) {
+ function parseInitializer(inParameter) {
if (token !== 51 /* EqualsToken */) {
if (scanner.hasPrecedingLineBreak() || (inParameter && token === 13 /* OpenBraceToken */) || !isStartOfExpression()) {
return undefined;
}
}
parseExpected(51 /* EqualsToken */);
- return parseAssignmentExpression(noIn);
+ return parseAssignmentExpression();
}
- function parseAssignmentExpression(noIn) {
+ function parseAssignmentExpression() {
+ if (isYieldExpression()) {
+ return parseYieldExpression();
+ }
var arrowExpression = tryParseParenthesizedArrowFunctionExpression();
if (arrowExpression) {
return arrowExpression;
}
- var expr = parseConditionalExpression(noIn);
+ var expr = parseConditionalExpression();
if (expr.kind === 63 /* Identifier */ && token === 31 /* EqualsGreaterThanToken */) {
return parseSimpleArrowFunctionExpression(expr);
}
- if (isLeftHandSideExpression(expr) && isAssignmentOperator()) {
- if (isInStrictMode && isEvalOrArgumentsIdentifier(expr)) {
- reportInvalidUseInStrictMode(expr);
- }
+ if (isLeftHandSideExpression(expr) && isAssignmentOperator(token)) {
var operator = token;
nextToken();
- return makeBinaryExpression(expr, operator, parseAssignmentExpression(noIn));
+ return makeBinaryExpression(expr, operator, parseAssignmentExpression());
}
return expr;
}
- function isLeftHandSideExpression(expr) {
- if (expr) {
- switch (expr.kind) {
- case 145 /* PropertyAccess */:
- case 146 /* IndexedAccess */:
- case 148 /* NewExpression */:
- case 147 /* CallExpression */:
- case 149 /* TaggedTemplateExpression */:
- case 141 /* ArrayLiteral */:
- case 151 /* ParenExpression */:
- case 142 /* ObjectLiteral */:
- case 152 /* FunctionExpression */:
- case 63 /* Identifier */:
- case 120 /* Missing */:
- case 8 /* RegularExpressionLiteral */:
- case 6 /* NumericLiteral */:
- case 7 /* StringLiteral */:
- case 9 /* NoSubstitutionTemplateLiteral */:
- case 158 /* TemplateExpression */:
- case 78 /* FalseKeyword */:
- case 87 /* NullKeyword */:
- case 91 /* ThisKeyword */:
- case 93 /* TrueKeyword */:
- case 89 /* SuperKeyword */:
- return true;
+ function isYieldExpression() {
+ if (token === 108 /* YieldKeyword */) {
+ if (inYieldContext()) {
+ return true;
}
+ if (inStrictModeContext()) {
+ return true;
+ }
+ return lookAhead(function () {
+ nextToken();
+ return !scanner.hasPrecedingLineBreak() && isIdentifier();
+ });
}
return false;
}
+ function parseYieldExpression() {
+ var node = createNode(160 /* YieldExpression */);
+ nextToken();
+ if (!scanner.hasPrecedingLineBreak() && (token === 34 /* AsteriskToken */ || isStartOfExpression())) {
+ node.asteriskToken = parseOptionalToken(34 /* AsteriskToken */);
+ node.expression = parseAssignmentExpression();
+ return finishNode(node);
+ }
+ else {
+ return finishNode(node);
+ }
+ }
function parseSimpleArrowFunctionExpression(identifier) {
ts.Debug.assert(token === 31 /* EqualsGreaterThanToken */, "parseSimpleArrowFunctionExpression should only have been called if we had a =>");
parseExpected(31 /* EqualsGreaterThanToken */);
@@ -3693,7 +3640,7 @@ var ts;
parameters.pos = parameter.pos;
parameters.end = parameter.end;
var signature = { parameters: parameters };
- return parseArrowExpressionTail(identifier.pos, signature, false);
+ return parseArrowExpressionTail(identifier.pos, signature);
}
function tryParseParenthesizedArrowFunctionExpression() {
var triState = isParenthesizedArrowFunctionExpression();
@@ -3702,18 +3649,18 @@ var ts;
}
var pos = getNodePos();
if (triState === 1 /* True */) {
- var sig = parseSignature(129 /* CallSignature */, 50 /* ColonToken */, false);
+ var sig = parseSignature(129 /* CallSignature */, 50 /* ColonToken */, false, false);
if (parseExpected(31 /* EqualsGreaterThanToken */) || token === 13 /* OpenBraceToken */) {
- return parseArrowExpressionTail(pos, sig, false);
+ return parseArrowExpressionTail(pos, sig);
}
else {
- return makeFunctionExpression(153 /* ArrowFunction */, pos, undefined, sig, createMissingNode());
+ return makeFunctionExpression(153 /* ArrowFunction */, pos, undefined, undefined, sig, createMissingNode());
}
}
var sig = tryParseSignatureIfArrowOrBraceFollows();
if (sig) {
parseExpected(31 /* EqualsGreaterThanToken */);
- return parseArrowExpressionTail(pos, sig, false);
+ return parseArrowExpressionTail(pos, sig);
}
else {
return undefined;
@@ -3763,52 +3710,46 @@ var ts;
}
function tryParseSignatureIfArrowOrBraceFollows() {
return tryParse(function () {
- var sig = parseSignature(129 /* CallSignature */, 50 /* ColonToken */, false);
+ var sig = parseSignature(129 /* CallSignature */, 50 /* ColonToken */, false, false);
if (token === 31 /* EqualsGreaterThanToken */ || token === 13 /* OpenBraceToken */) {
return sig;
}
return undefined;
});
}
- function parseArrowExpressionTail(pos, sig, noIn) {
+ function parseArrowExpressionTail(pos, sig) {
var body;
if (token === 13 /* OpenBraceToken */) {
- body = parseBody(false);
+ body = parseFunctionBlock(false, false);
}
else if (isStatement(true) && !isStartOfExpressionStatement() && token !== 81 /* FunctionKeyword */) {
- body = parseBody(true);
+ body = parseFunctionBlock(false, true);
}
else {
- body = parseAssignmentExpression(noIn);
+ body = parseAssignmentExpression();
}
- return makeFunctionExpression(153 /* ArrowFunction */, pos, undefined, sig, body);
+ return makeFunctionExpression(153 /* ArrowFunction */, pos, undefined, undefined, sig, body);
}
- function isAssignmentOperator() {
- return token >= 51 /* FirstAssignment */ && token <= 62 /* LastAssignment */;
- }
- function parseConditionalExpression(noIn) {
- var expr = parseBinaryExpression(noIn);
+ function parseConditionalExpression() {
+ var expr = parseBinaryOperators(parseUnaryExpression(), 0);
while (parseOptional(49 /* QuestionToken */)) {
var node = createNode(157 /* ConditionalExpression */, expr.pos);
node.condition = expr;
- node.whenTrue = parseAssignmentExpression(false);
+ node.whenTrue = allowInAnd(parseAssignmentExpression);
parseExpected(50 /* ColonToken */);
- node.whenFalse = parseAssignmentExpression(noIn);
+ node.whenFalse = parseAssignmentExpression();
expr = finishNode(node);
}
return expr;
}
- function parseBinaryExpression(noIn) {
- return parseBinaryOperators(parseUnaryExpression(), 0, noIn);
- }
- function parseBinaryOperators(expr, minPrecedence, noIn) {
+ function parseBinaryOperators(expr, minPrecedence) {
while (true) {
reScanGreaterToken();
var precedence = getOperatorPrecedence();
- if (precedence && precedence > minPrecedence && (!noIn || token !== 84 /* InKeyword */)) {
+ if (precedence && precedence > minPrecedence && (!inDisallowInContext() || token !== 84 /* InKeyword */)) {
var operator = token;
nextToken();
- expr = makeBinaryExpression(expr, operator, parseBinaryOperators(parseUnaryExpression(), precedence, noIn));
+ expr = makeBinaryExpression(expr, operator, parseBinaryOperators(parseUnaryExpression(), precedence));
continue;
}
return expr;
@@ -3873,16 +3814,7 @@ var ts;
case 38 /* MinusMinusToken */:
var operator = token;
nextToken();
- var operand = parseUnaryExpression();
- if (isInStrictMode) {
- if ((operator === 37 /* PlusPlusToken */ || operator === 38 /* MinusMinusToken */) && isEvalOrArgumentsIdentifier(operand)) {
- reportInvalidUseInStrictMode(operand);
- }
- else if (operator === 72 /* DeleteKeyword */ && operand.kind === 63 /* Identifier */) {
- grammarErrorOnNode(operand, ts.Diagnostics.delete_cannot_be_called_on_an_identifier_in_strict_mode);
- }
- }
- return makeUnaryExpression(154 /* PrefixOperator */, pos, operator, operand);
+ return makeUnaryExpression(154 /* PrefixOperator */, pos, operator, parseUnaryExpression());
case 23 /* LessThanToken */:
return parseTypeAssertion();
}
@@ -3894,9 +3826,6 @@ var ts;
var expr = parseCallAndAccess(primaryExpression, false);
ts.Debug.assert(isLeftHandSideExpression(expr));
if ((token === 37 /* PlusPlusToken */ || token === 38 /* MinusMinusToken */) && !scanner.hasPrecedingLineBreak()) {
- if (isInStrictMode && isEvalOrArgumentsIdentifier(expr)) {
- reportInvalidUseInStrictMode(expr);
- }
var operator = token;
nextToken();
expr = makeUnaryExpression(155 /* PostfixOperator */, expr.pos, operator, expr);
@@ -3922,15 +3851,19 @@ var ts;
var dotOrBracketStart = scanner.getTokenPos();
if (parseOptional(19 /* DotToken */)) {
var propertyAccess = createNode(145 /* PropertyAccess */, expr.pos);
- if (scanner.hasPrecedingLineBreak() && scanner.isReservedWord() && lookAhead(function () { return scanner.isReservedWord(); })) {
- grammarErrorAtPos(dotOrBracketStart, scanner.getStartPos() - dotOrBracketStart, ts.Diagnostics.Identifier_expected);
- var id = createMissingNode();
- }
- else {
- var id = parseIdentifierName();
+ var id;
+ if (scanner.hasPrecedingLineBreak() && scanner.isReservedWord()) {
+ var matchesPattern = lookAhead(function () {
+ nextToken();
+ return !scanner.hasPrecedingLineBreak() && (scanner.isIdentifier() || scanner.isReservedWord);
+ });
+ if (matchesPattern) {
+ errorAtPos(dotOrBracketStart + 1, 0, ts.Diagnostics.Identifier_expected);
+ id = createMissingNode();
+ }
}
propertyAccess.left = expr;
- propertyAccess.right = id;
+ propertyAccess.right = id || parseIdentifierName();
expr = finishNode(propertyAccess);
continue;
}
@@ -3939,10 +3872,9 @@ var ts;
indexedAccess.object = expr;
if (inNewExpression && parseOptional(18 /* CloseBracketToken */)) {
indexedAccess.index = createMissingNode();
- grammarErrorAtPos(dotOrBracketStart, scanner.getStartPos() - dotOrBracketStart, ts.Diagnostics.new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead);
}
else {
- indexedAccess.index = parseExpression();
+ indexedAccess.index = allowInAnd(parseExpression);
if (indexedAccess.index.kind === 7 /* StringLiteral */ || indexedAccess.index.kind === 6 /* NumericLiteral */) {
var literal = indexedAccess.index;
literal.text = internIdentifier(literal.text);
@@ -3962,7 +3894,7 @@ var ts;
else {
parseExpected(15 /* OpenParenToken */);
}
- callExpr.arguments = parseDelimitedList(10 /* ArgumentExpressions */, parseArgumentExpression, false);
+ callExpr.arguments = parseDelimitedList(10 /* ArgumentExpressions */, parseArgumentExpression);
parseExpected(16 /* CloseParenToken */);
expr = finishNode(callExpr);
continue;
@@ -3972,9 +3904,6 @@ var ts;
tagExpression.tag = expr;
tagExpression.template = token === 9 /* NoSubstitutionTemplateLiteral */ ? parseLiteralNode() : parseTemplateExpression();
expr = finishNode(tagExpression);
- if (languageVersion < 2 /* ES6 */) {
- grammarErrorOnNode(expr, ts.Diagnostics.Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher);
- }
continue;
}
return expr;
@@ -3986,19 +3915,10 @@ var ts;
return result;
}
function parseTypeArguments() {
- var typeArgumentListStart = scanner.getTokenPos();
- var errorCountBeforeTypeParameterList = file.syntacticErrors.length;
- var result = parseBracketedList(15 /* TypeArguments */, parseSingleTypeArgument, 23 /* LessThanToken */, 24 /* GreaterThanToken */);
- if (!result.length && file.syntacticErrors.length === errorCountBeforeTypeParameterList) {
- grammarErrorAtPos(typeArgumentListStart, scanner.getStartPos() - typeArgumentListStart, ts.Diagnostics.Type_argument_list_cannot_be_empty);
- }
- return result;
+ return parseBracketedList(15 /* TypeArguments */, parseSingleTypeArgument, 23 /* LessThanToken */, 24 /* GreaterThanToken */);
}
function parseSingleTypeArgument() {
if (token === 22 /* CommaToken */) {
- var errorStart = scanner.getTokenPos();
- var errorLength = scanner.getTextPos() - errorStart;
- grammarErrorAtPos(errorStart, errorLength, ts.Diagnostics.Type_expected);
return createNode(120 /* Missing */);
}
return parseType();
@@ -4044,55 +3964,49 @@ var ts;
function parseParenExpression() {
var node = createNode(151 /* ParenExpression */);
parseExpected(15 /* OpenParenToken */);
- node.expression = parseExpression();
+ node.expression = allowInAnd(parseExpression);
parseExpected(16 /* CloseParenToken */);
return finishNode(node);
}
- function parseAssignmentExpressionOrOmittedExpression(omittedExpressionDiagnostic) {
- if (token === 22 /* CommaToken */) {
- if (omittedExpressionDiagnostic) {
- var errorStart = scanner.getTokenPos();
- var errorLength = scanner.getTextPos() - errorStart;
- grammarErrorAtPos(errorStart, errorLength, omittedExpressionDiagnostic);
- }
- return createNode(160 /* OmittedExpression */);
- }
- return parseAssignmentExpression();
+ function parseAssignmentExpressionOrOmittedExpression() {
+ return token === 22 /* CommaToken */ ? createNode(161 /* OmittedExpression */) : parseAssignmentExpression();
}
function parseArrayLiteralElement() {
- return parseAssignmentExpressionOrOmittedExpression(undefined);
+ return parseAssignmentExpressionOrOmittedExpression();
}
function parseArgumentExpression() {
- return parseAssignmentExpressionOrOmittedExpression(ts.Diagnostics.Argument_expression_expected);
+ return allowInAnd(parseAssignmentExpressionOrOmittedExpression);
}
function parseArrayLiteral() {
var node = createNode(141 /* ArrayLiteral */);
parseExpected(17 /* OpenBracketToken */);
if (scanner.hasPrecedingLineBreak())
node.flags |= 256 /* MultiLine */;
- node.elements = parseDelimitedList(12 /* ArrayLiteralMembers */, parseArrayLiteralElement, true);
+ node.elements = parseDelimitedList(12 /* ArrayLiteralMembers */, parseArrayLiteralElement);
parseExpected(18 /* CloseBracketToken */);
return finishNode(node);
}
function parsePropertyAssignment() {
var nodePos = scanner.getStartPos();
+ var asteriskToken = parseOptionalToken(34 /* AsteriskToken */);
+ var tokenIsIdentifier = isIdentifier();
var nameToken = token;
var propertyName = parsePropertyName();
var node;
- if (token === 15 /* OpenParenToken */ || token === 23 /* LessThanToken */) {
+ if (asteriskToken || token === 15 /* OpenParenToken */ || token === 23 /* LessThanToken */) {
node = createNode(143 /* PropertyAssignment */, nodePos);
node.name = propertyName;
- var sig = parseSignature(129 /* CallSignature */, 50 /* ColonToken */, false);
- var body = parseBody(false);
- node.initializer = makeFunctionExpression(152 /* FunctionExpression */, node.pos, undefined, sig, body);
+ var sig = parseSignature(129 /* CallSignature */, 50 /* ColonToken */, false, !!asteriskToken);
+ var body = parseFunctionBlock(!!asteriskToken, false);
+ node.initializer = makeFunctionExpression(152 /* FunctionExpression */, node.pos, asteriskToken, undefined, sig, body);
return finishNode(node);
}
+ var flags = 0;
if (token === 49 /* QuestionToken */) {
- var questionStart = scanner.getTokenPos();
- grammarErrorAtPos(questionStart, scanner.getStartPos() - questionStart, ts.Diagnostics.A_object_member_cannot_be_declared_optional);
+ flags |= 4 /* QuestionMark */;
nextToken();
}
- if (token !== 50 /* ColonToken */ && nameToken === 63 /* Identifier */) {
+ if ((token === 22 /* CommaToken */ || token === 14 /* CloseBraceToken */) && tokenIsIdentifier) {
node = createNode(144 /* ShorthandPropertyAssignment */, nodePos);
node.name = propertyName;
}
@@ -4100,8 +4014,9 @@ var ts;
node = createNode(143 /* PropertyAssignment */, nodePos);
node.name = propertyName;
parseExpected(50 /* ColonToken */);
- node.initializer = parseAssignmentExpression(false);
+ node.initializer = allowInAnd(parseAssignmentExpression);
}
+ node.flags = flags;
return finishNode(node);
}
function parseObjectLiteralMember() {
@@ -4109,7 +4024,7 @@ var ts;
var initialToken = token;
if (parseContextualModifier(113 /* GetKeyword */) || parseContextualModifier(117 /* SetKeyword */)) {
var kind = initialToken === 113 /* GetKeyword */ ? 127 /* GetAccessor */ : 128 /* SetAccessor */;
- return parseAndCheckMemberAccessorDeclaration(kind, initialPos, 0);
+ return parseMemberAccessorDeclaration(kind, initialPos, undefined);
}
return parsePropertyAssignment();
}
@@ -4119,72 +4034,25 @@ var ts;
if (scanner.hasPrecedingLineBreak()) {
node.flags |= 256 /* MultiLine */;
}
- node.properties = parseDelimitedList(11 /* ObjectLiteralMembers */, parseObjectLiteralMember, true);
+ node.properties = parseDelimitedList(11 /* ObjectLiteralMembers */, parseObjectLiteralMember);
parseExpected(14 /* CloseBraceToken */);
- var seen = {};
- var Property = 1;
- var GetAccessor = 2;
- var SetAccesor = 4;
- var GetOrSetAccessor = GetAccessor | SetAccesor;
- ts.forEach(node.properties, function (p) {
- if (p.kind === 160 /* OmittedExpression */) {
- return;
- }
- var name = p.name;
- var currentKind;
- if (p.kind === 143 /* PropertyAssignment */) {
- currentKind = Property;
- }
- else if (p.kind === 144 /* ShorthandPropertyAssignment */) {
- currentKind = Property;
- }
- else if (p.kind === 127 /* GetAccessor */) {
- currentKind = GetAccessor;
- }
- else if (p.kind === 128 /* SetAccessor */) {
- currentKind = SetAccesor;
- }
- else {
- ts.Debug.fail("Unexpected syntax kind:" + p.kind);
- }
- if (!ts.hasProperty(seen, name.text)) {
- seen[name.text] = currentKind;
- }
- else {
- var existingKind = seen[name.text];
- if (currentKind === Property && existingKind === Property) {
- if (isInStrictMode) {
- grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode);
- }
- }
- else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) {
- if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) {
- seen[name.text] = currentKind | existingKind;
- }
- else {
- grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name);
- }
- }
- else {
- grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name);
- }
- }
- });
return finishNode(node);
}
function parseFunctionExpression() {
var pos = getNodePos();
parseExpected(81 /* FunctionKeyword */);
- var name = isIdentifier() ? parseIdentifier() : undefined;
- var sig = parseSignature(129 /* CallSignature */, 50 /* ColonToken */, false);
- var body = parseBody(false);
- if (name && isInStrictMode && isEvalOrArgumentsIdentifier(name)) {
- reportInvalidUseInStrictMode(name);
- }
- return makeFunctionExpression(152 /* FunctionExpression */, pos, name, sig, body);
+ var asteriskToken = parseOptionalToken(34 /* AsteriskToken */);
+ var name = asteriskToken ? doInYieldContext(parseOptionalIdentifier) : parseOptionalIdentifier();
+ var sig = parseSignature(129 /* CallSignature */, 50 /* ColonToken */, false, !!asteriskToken);
+ var body = parseFunctionBlock(!!asteriskToken, false);
+ return makeFunctionExpression(152 /* FunctionExpression */, pos, asteriskToken, name, sig, body);
}
- function makeFunctionExpression(kind, pos, name, sig, body) {
+ function parseOptionalIdentifier() {
+ return isIdentifier() ? parseIdentifier() : undefined;
+ }
+ function makeFunctionExpression(kind, pos, asteriskToken, name, sig, body) {
var node = createNode(kind, pos);
+ node.asteriskToken = asteriskToken;
node.name = name;
node.typeParameters = sig.typeParameters;
node.parameters = sig.parameters;
@@ -4197,18 +4065,15 @@ var ts;
parseExpected(86 /* NewKeyword */);
node.func = parseCallAndAccess(parsePrimaryExpression(), true);
if (parseOptional(15 /* OpenParenToken */) || token === 23 /* LessThanToken */ && (node.typeArguments = tryParse(parseTypeArgumentsAndOpenParen))) {
- node.arguments = parseDelimitedList(10 /* ArgumentExpressions */, parseArgumentExpression, false);
+ node.arguments = parseDelimitedList(10 /* ArgumentExpressions */, parseArgumentExpression);
parseExpected(16 /* CloseParenToken */);
}
return finishNode(node);
}
- function parseStatementAllowingLetDeclaration() {
- return parseStatement(true);
- }
function parseBlock(ignoreMissingOpenBrace, checkForStrictMode) {
- var node = createNode(161 /* Block */);
+ var node = createNode(162 /* Block */);
if (parseExpected(13 /* OpenBraceToken */) || ignoreMissingOpenBrace) {
- node.statements = parseList(2 /* BlockStatements */, checkForStrictMode, parseStatementAllowingLetDeclaration);
+ node.statements = parseList(2 /* BlockStatements */, checkForStrictMode, parseStatement);
parseExpected(14 /* CloseBraceToken */);
}
else {
@@ -4216,65 +4081,47 @@ var ts;
}
return finishNode(node);
}
- function parseBody(ignoreMissingOpenBrace) {
- var saveInFunctionBody = inFunctionBody;
- var saveInSwitchStatement = inSwitchStatement;
- var saveInIterationStatement = inIterationStatement;
- inFunctionBody = true;
- if (inSwitchStatement === 1 /* Nested */) {
- inSwitchStatement = 2 /* CrossingFunctionBoundary */;
- }
- if (inIterationStatement === 1 /* Nested */) {
- inIterationStatement = 2 /* CrossingFunctionBoundary */;
- }
- labelledStatementInfo.pushFunctionBoundary();
+ function parseFunctionBlock(allowYield, ignoreMissingOpenBrace) {
+ var savedYieldContext = inYieldContext();
+ setYieldContext(allowYield);
var block = parseBlock(ignoreMissingOpenBrace, true);
- block.kind = 186 /* FunctionBlock */;
- labelledStatementInfo.pop();
- inFunctionBody = saveInFunctionBody;
- inSwitchStatement = saveInSwitchStatement;
- inIterationStatement = saveInIterationStatement;
+ block.kind = 187 /* FunctionBlock */;
+ setYieldContext(savedYieldContext);
return block;
}
function parseEmptyStatement() {
- var node = createNode(163 /* EmptyStatement */);
+ var node = createNode(164 /* EmptyStatement */);
parseExpected(21 /* SemicolonToken */);
return finishNode(node);
}
function parseIfStatement() {
- var node = createNode(165 /* IfStatement */);
+ var node = createNode(166 /* IfStatement */);
parseExpected(82 /* IfKeyword */);
parseExpected(15 /* OpenParenToken */);
- node.expression = parseExpression();
+ node.expression = allowInAnd(parseExpression);
parseExpected(16 /* CloseParenToken */);
- node.thenStatement = parseStatement(false);
- node.elseStatement = parseOptional(74 /* ElseKeyword */) ? parseStatement(false) : undefined;
+ node.thenStatement = parseStatement();
+ node.elseStatement = parseOptional(74 /* ElseKeyword */) ? parseStatement() : undefined;
return finishNode(node);
}
function parseDoStatement() {
- var node = createNode(166 /* DoStatement */);
+ var node = createNode(167 /* DoStatement */);
parseExpected(73 /* DoKeyword */);
- var saveInIterationStatement = inIterationStatement;
- inIterationStatement = 1 /* Nested */;
- node.statement = parseStatement(false);
- inIterationStatement = saveInIterationStatement;
+ node.statement = parseStatement();
parseExpected(98 /* WhileKeyword */);
parseExpected(15 /* OpenParenToken */);
- node.expression = parseExpression();
+ node.expression = allowInAnd(parseExpression);
parseExpected(16 /* CloseParenToken */);
parseOptional(21 /* SemicolonToken */);
return finishNode(node);
}
function parseWhileStatement() {
- var node = createNode(167 /* WhileStatement */);
+ var node = createNode(168 /* WhileStatement */);
parseExpected(98 /* WhileKeyword */);
parseExpected(15 /* OpenParenToken */);
- node.expression = parseExpression();
+ node.expression = allowInAnd(parseExpression);
parseExpected(16 /* CloseParenToken */);
- var saveInIterationStatement = inIterationStatement;
- inIterationStatement = 1 /* Nested */;
- node.statement = parseStatement(false);
- inIterationStatement = saveInIterationStatement;
+ node.statement = parseStatement();
return finishNode(node);
}
function parseForOrForInStatement() {
@@ -4283,220 +4130,127 @@ var ts;
parseExpected(15 /* OpenParenToken */);
if (token !== 21 /* SemicolonToken */) {
if (parseOptional(96 /* VarKeyword */)) {
- var declarations = parseVariableDeclarationList(0, true);
- if (!declarations.length) {
- error(ts.Diagnostics.Variable_declaration_list_cannot_be_empty);
- }
+ var declarations = disallowInAnd(parseVariableDeclarationList);
}
else if (parseOptional(102 /* LetKeyword */)) {
- var declarations = parseVariableDeclarationList(2048 /* Let */, true);
- if (!declarations.length) {
- error(ts.Diagnostics.Variable_declaration_list_cannot_be_empty);
- }
- if (languageVersion < 2 /* ES6 */) {
- grammarErrorAtPos(declarations.pos, declarations.end - declarations.pos, ts.Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher);
- }
+ var declarations = setFlag(disallowInAnd(parseVariableDeclarationList), 2048 /* Let */);
}
else if (parseOptional(68 /* ConstKeyword */)) {
- var declarations = parseVariableDeclarationList(4096 /* Const */, true);
- if (!declarations.length) {
- error(ts.Diagnostics.Variable_declaration_list_cannot_be_empty);
- }
- if (languageVersion < 2 /* ES6 */) {
- grammarErrorAtPos(declarations.pos, declarations.end - declarations.pos, ts.Diagnostics.const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher);
- }
+ var declarations = setFlag(disallowInAnd(parseVariableDeclarationList), 4096 /* Const */);
}
else {
- var varOrInit = parseExpression(true);
+ var varOrInit = disallowInAnd(parseExpression);
}
}
var forOrForInStatement;
if (parseOptional(84 /* InKeyword */)) {
- var forInStatement = createNode(169 /* ForInStatement */, pos);
+ var forInStatement = createNode(170 /* ForInStatement */, pos);
if (declarations) {
- if (declarations.length > 1) {
- error(ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement);
- }
- forInStatement.declaration = declarations[0];
+ forInStatement.declarations = declarations;
}
else {
forInStatement.variable = varOrInit;
}
- forInStatement.expression = parseExpression();
+ forInStatement.expression = allowInAnd(parseExpression);
parseExpected(16 /* CloseParenToken */);
forOrForInStatement = forInStatement;
}
else {
- var forStatement = createNode(168 /* ForStatement */, pos);
- if (declarations)
+ var forStatement = createNode(169 /* ForStatement */, pos);
+ if (declarations) {
forStatement.declarations = declarations;
- if (varOrInit)
+ }
+ if (varOrInit) {
forStatement.initializer = varOrInit;
+ }
parseExpected(21 /* SemicolonToken */);
if (token !== 21 /* SemicolonToken */ && token !== 16 /* CloseParenToken */) {
- forStatement.condition = parseExpression();
+ forStatement.condition = allowInAnd(parseExpression);
}
parseExpected(21 /* SemicolonToken */);
if (token !== 16 /* CloseParenToken */) {
- forStatement.iterator = parseExpression();
+ forStatement.iterator = allowInAnd(parseExpression);
}
parseExpected(16 /* CloseParenToken */);
forOrForInStatement = forStatement;
}
- var saveInIterationStatement = inIterationStatement;
- inIterationStatement = 1 /* Nested */;
- forOrForInStatement.statement = parseStatement(false);
- inIterationStatement = saveInIterationStatement;
+ forOrForInStatement.statement = parseStatement();
return finishNode(forOrForInStatement);
}
function parseBreakOrContinueStatement(kind) {
var node = createNode(kind);
- var errorCountBeforeStatement = file.syntacticErrors.length;
- parseExpected(kind === 171 /* BreakStatement */ ? 64 /* BreakKeyword */ : 69 /* ContinueKeyword */);
- if (!canParseSemicolon())
+ parseExpected(kind === 172 /* BreakStatement */ ? 64 /* BreakKeyword */ : 69 /* ContinueKeyword */);
+ if (!canParseSemicolon()) {
node.label = parseIdentifier();
+ }
parseSemicolon();
- finishNode(node);
- if (!inAmbientContext && errorCountBeforeStatement === file.syntacticErrors.length) {
- if (node.label) {
- checkBreakOrContinueStatementWithLabel(node);
- }
- else {
- checkBareBreakOrContinueStatement(node);
- }
- }
- return node;
- }
- function checkBareBreakOrContinueStatement(node) {
- if (node.kind === 171 /* BreakStatement */) {
- if (inIterationStatement === 1 /* Nested */ || inSwitchStatement === 1 /* Nested */) {
- return;
- }
- else if (inIterationStatement === 0 /* NotNested */ && inSwitchStatement === 0 /* NotNested */) {
- grammarErrorOnNode(node, ts.Diagnostics.A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement);
- return;
- }
- }
- else if (node.kind === 170 /* ContinueStatement */) {
- if (inIterationStatement === 1 /* Nested */) {
- return;
- }
- else if (inIterationStatement === 0 /* NotNested */) {
- grammarErrorOnNode(node, ts.Diagnostics.A_continue_statement_can_only_be_used_within_an_enclosing_iteration_statement);
- return;
- }
- }
- else {
- ts.Debug.fail("checkAnonymousBreakOrContinueStatement");
- }
- ts.Debug.assert(inIterationStatement === 2 /* CrossingFunctionBoundary */ || inSwitchStatement === 2 /* CrossingFunctionBoundary */);
- grammarErrorOnNode(node, ts.Diagnostics.Jump_target_cannot_cross_function_boundary);
- }
- function checkBreakOrContinueStatementWithLabel(node) {
- var nodeIsNestedInLabel = labelledStatementInfo.nodeIsNestedInLabel(node.label, node.kind === 170 /* ContinueStatement */, false);
- if (nodeIsNestedInLabel === 1 /* Nested */) {
- return;
- }
- if (nodeIsNestedInLabel === 2 /* CrossingFunctionBoundary */) {
- grammarErrorOnNode(node, ts.Diagnostics.Jump_target_cannot_cross_function_boundary);
- return;
- }
- if (node.kind === 170 /* ContinueStatement */) {
- grammarErrorOnNode(node, ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement);
- }
- else if (node.kind === 171 /* BreakStatement */) {
- grammarErrorOnNode(node, ts.Diagnostics.A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement);
- }
- else {
- ts.Debug.fail("checkBreakOrContinueStatementWithLabel");
- }
+ return finishNode(node);
}
function parseReturnStatement() {
- var node = createNode(172 /* ReturnStatement */);
- var errorCountBeforeReturnStatement = file.syntacticErrors.length;
- var returnTokenStart = scanner.getTokenPos();
- var returnTokenLength = scanner.getTextPos() - returnTokenStart;
+ var node = createNode(173 /* ReturnStatement */);
parseExpected(88 /* ReturnKeyword */);
- if (!canParseSemicolon())
- node.expression = parseExpression();
- parseSemicolon();
- if (!inFunctionBody && !inAmbientContext && errorCountBeforeReturnStatement === file.syntacticErrors.length) {
- grammarErrorAtPos(returnTokenStart, returnTokenLength, ts.Diagnostics.A_return_statement_can_only_be_used_within_a_function_body);
+ if (!canParseSemicolon()) {
+ node.expression = allowInAnd(parseExpression);
}
+ parseSemicolon();
return finishNode(node);
}
function parseWithStatement() {
- var node = createNode(173 /* WithStatement */);
- var startPos = scanner.getTokenPos();
+ var node = createNode(174 /* WithStatement */);
parseExpected(99 /* WithKeyword */);
- var endPos = scanner.getStartPos();
parseExpected(15 /* OpenParenToken */);
- node.expression = parseExpression();
+ node.expression = allowInAnd(parseExpression);
parseExpected(16 /* CloseParenToken */);
- node.statement = parseStatement(false);
- node = finishNode(node);
- if (isInStrictMode) {
- grammarErrorAtPos(startPos, endPos - startPos, ts.Diagnostics.with_statements_are_not_allowed_in_strict_mode);
- }
- return node;
+ node.statement = parseStatement();
+ return finishNode(node);
}
function parseCaseClause() {
- var node = createNode(175 /* CaseClause */);
+ var node = createNode(176 /* CaseClause */);
parseExpected(65 /* CaseKeyword */);
- node.expression = parseExpression();
+ node.expression = allowInAnd(parseExpression);
parseExpected(50 /* ColonToken */);
- node.statements = parseList(4 /* SwitchClauseStatements */, false, parseStatementAllowingLetDeclaration);
+ node.statements = parseList(4 /* SwitchClauseStatements */, false, parseStatement);
return finishNode(node);
}
function parseDefaultClause() {
- var node = createNode(176 /* DefaultClause */);
+ var node = createNode(177 /* DefaultClause */);
parseExpected(71 /* DefaultKeyword */);
parseExpected(50 /* ColonToken */);
- node.statements = parseList(4 /* SwitchClauseStatements */, false, parseStatementAllowingLetDeclaration);
+ node.statements = parseList(4 /* SwitchClauseStatements */, false, parseStatement);
return finishNode(node);
}
function parseCaseOrDefaultClause() {
return token === 65 /* CaseKeyword */ ? parseCaseClause() : parseDefaultClause();
}
function parseSwitchStatement() {
- var node = createNode(174 /* SwitchStatement */);
+ var node = createNode(175 /* SwitchStatement */);
parseExpected(90 /* SwitchKeyword */);
parseExpected(15 /* OpenParenToken */);
- node.expression = parseExpression();
+ node.expression = allowInAnd(parseExpression);
parseExpected(16 /* CloseParenToken */);
parseExpected(13 /* OpenBraceToken */);
- var saveInSwitchStatement = inSwitchStatement;
- inSwitchStatement = 1 /* Nested */;
node.clauses = parseList(3 /* SwitchClauses */, false, parseCaseOrDefaultClause);
- inSwitchStatement = saveInSwitchStatement;
parseExpected(14 /* CloseBraceToken */);
- var defaultClauses = ts.filter(node.clauses, function (clause) { return clause.kind === 176 /* DefaultClause */; });
- for (var i = 1, n = defaultClauses.length; i < n; i++) {
- var clause = defaultClauses[i];
- var start = ts.skipTrivia(file.text, clause.pos);
- var end = clause.statements.length > 0 ? clause.statements[0].pos : clause.end;
- grammarErrorAtPos(start, end - start, ts.Diagnostics.A_default_clause_cannot_appear_more_than_once_in_a_switch_statement);
- }
return finishNode(node);
}
function parseThrowStatement() {
- var node = createNode(178 /* ThrowStatement */);
+ var node = createNode(179 /* ThrowStatement */);
parseExpected(92 /* ThrowKeyword */);
if (scanner.hasPrecedingLineBreak()) {
error(ts.Diagnostics.Line_break_not_permitted_here);
}
- node.expression = parseExpression();
+ node.expression = allowInAnd(parseExpression);
parseSemicolon();
return finishNode(node);
}
function parseTryStatement() {
- var node = createNode(179 /* TryStatement */);
- node.tryBlock = parseTokenAndBlock(94 /* TryKeyword */, 180 /* TryBlock */);
+ var node = createNode(180 /* TryStatement */);
+ node.tryBlock = parseTokenAndBlock(94 /* TryKeyword */, 181 /* TryBlock */);
if (token === 66 /* CatchKeyword */) {
node.catchBlock = parseCatchBlock();
}
if (token === 79 /* FinallyKeyword */) {
- node.finallyBlock = parseTokenAndBlock(79 /* FinallyKeyword */, 182 /* FinallyBlock */);
+ node.finallyBlock = parseTokenAndBlock(79 /* FinallyKeyword */, 183 /* FinallyBlock */);
}
if (!(node.catchBlock || node.finallyBlock)) {
error(ts.Diagnostics.catch_or_finally_expected);
@@ -4516,54 +4270,34 @@ var ts;
parseExpected(66 /* CatchKeyword */);
parseExpected(15 /* OpenParenToken */);
var variable = parseIdentifier();
- var typeAnnotationColonStart = scanner.getTokenPos();
- var typeAnnotationColonLength = scanner.getTextPos() - typeAnnotationColonStart;
var typeAnnotation = parseTypeAnnotation();
parseExpected(16 /* CloseParenToken */);
var result = parseBlock(false, false);
- result.kind = 181 /* CatchBlock */;
+ result.kind = 182 /* CatchBlock */;
result.pos = pos;
result.variable = variable;
- if (typeAnnotation) {
- errorAtPos(typeAnnotationColonStart, typeAnnotationColonLength, ts.Diagnostics.Catch_clause_parameter_cannot_have_a_type_annotation);
- }
- if (isInStrictMode && isEvalOrArgumentsIdentifier(variable)) {
- reportInvalidUseInStrictMode(variable);
- }
+ result.type = typeAnnotation;
return result;
}
function parseDebuggerStatement() {
- var node = createNode(183 /* DebuggerStatement */);
+ var node = createNode(184 /* DebuggerStatement */);
parseExpected(70 /* DebuggerKeyword */);
parseSemicolon();
return finishNode(node);
}
- function isIterationStatementStart() {
- return token === 98 /* WhileKeyword */ || token === 73 /* DoKeyword */ || token === 80 /* ForKeyword */;
- }
- function parseStatementWithLabelSet(allowLetAndConstDeclarations) {
- labelledStatementInfo.pushCurrentLabelSet(isIterationStatementStart());
- var statement = parseStatement(allowLetAndConstDeclarations);
- labelledStatementInfo.pop();
- return statement;
- }
function isLabel() {
return isIdentifier() && lookAhead(function () { return nextToken() === 50 /* ColonToken */; });
}
- function parseLabeledStatement(allowLetAndConstDeclarations) {
- var node = createNode(177 /* LabeledStatement */);
+ function parseLabeledStatement() {
+ var node = createNode(178 /* LabeledStatement */);
node.label = parseIdentifier();
parseExpected(50 /* ColonToken */);
- if (labelledStatementInfo.nodeIsNestedInLabel(node.label, false, true)) {
- grammarErrorOnNode(node.label, ts.Diagnostics.Duplicate_label_0, getTextOfNodeFromSourceText(sourceText, node.label));
- }
- labelledStatementInfo.addLabel(node.label);
- node.statement = isLabel() ? parseLabeledStatement(allowLetAndConstDeclarations) : parseStatementWithLabelSet(allowLetAndConstDeclarations);
+ node.statement = parseStatement();
return finishNode(node);
}
function parseExpressionStatement() {
- var node = createNode(164 /* ExpressionStatement */);
- node.expression = parseExpression();
+ var node = createNode(165 /* ExpressionStatement */);
+ node.expression = allowInAnd(parseExpression);
parseSemicolon();
return finishNode(node);
}
@@ -4612,16 +4346,16 @@ var ts;
return isStartOfExpression();
}
}
- function parseStatement(allowLetAndConstDeclarations) {
+ function parseStatement() {
switch (token) {
case 13 /* OpenBraceToken */:
return parseBlock(false, false);
case 96 /* VarKeyword */:
case 102 /* LetKeyword */:
case 68 /* ConstKeyword */:
- return parseVariableStatement(allowLetAndConstDeclarations);
+ return parseVariableStatement(scanner.getStartPos(), undefined);
case 81 /* FunctionKeyword */:
- return parseFunctionDeclaration();
+ return parseFunctionDeclaration(scanner.getStartPos(), undefined);
case 21 /* SemicolonToken */:
return parseEmptyStatement();
case 82 /* IfKeyword */:
@@ -4633,9 +4367,9 @@ var ts;
case 80 /* ForKeyword */:
return parseForOrForInStatement();
case 69 /* ContinueKeyword */:
- return parseBreakOrContinueStatement(170 /* ContinueStatement */);
+ return parseBreakOrContinueStatement(171 /* ContinueStatement */);
case 64 /* BreakKeyword */:
- return parseBreakOrContinueStatement(171 /* BreakStatement */);
+ return parseBreakOrContinueStatement(172 /* BreakStatement */);
case 88 /* ReturnKeyword */:
return parseReturnStatement();
case 99 /* WithKeyword */:
@@ -4651,22 +4385,12 @@ var ts;
case 70 /* DebuggerKeyword */:
return parseDebuggerStatement();
default:
- if (isLabel()) {
- return parseLabeledStatement(allowLetAndConstDeclarations);
- }
- return parseExpressionStatement();
+ return isLabel() ? parseLabeledStatement() : parseExpressionStatement();
}
}
- function parseAndCheckFunctionBody(isConstructor) {
- var initialPosition = scanner.getTokenPos();
- var errorCountBeforeBody = file.syntacticErrors.length;
+ function parseFunctionBlockOrSemicolon(isGenerator) {
if (token === 13 /* OpenBraceToken */) {
- var body = parseBody(false);
- if (body && inAmbientContext && file.syntacticErrors.length === errorCountBeforeBody) {
- var diagnostic = isConstructor ? ts.Diagnostics.A_constructor_implementation_cannot_be_declared_in_an_ambient_context : ts.Diagnostics.A_function_implementation_cannot_be_declared_in_an_ambient_context;
- grammarErrorAtPos(initialPosition, 1, diagnostic);
- }
- return body;
+ return parseFunctionBlock(isGenerator, false);
}
if (canParseSemicolon()) {
parseSemicolon();
@@ -4674,191 +4398,96 @@ var ts;
}
error(ts.Diagnostics.Block_or_expected);
}
- function parseVariableDeclaration(flags, noIn) {
- var node = createNode(184 /* VariableDeclaration */);
- node.flags = flags;
- var errorCountBeforeVariableDeclaration = file.syntacticErrors.length;
+ function parseVariableDeclaration() {
+ var node = createNode(185 /* VariableDeclaration */);
node.name = parseIdentifier();
node.type = parseTypeAnnotation();
- var initializerStart = scanner.getTokenPos();
- var initializerFirstTokenLength = scanner.getTextPos() - initializerStart;
- node.initializer = parseInitializer(false, noIn);
- if (inAmbientContext && node.initializer && errorCountBeforeVariableDeclaration === file.syntacticErrors.length) {
- grammarErrorAtPos(initializerStart, initializerFirstTokenLength, ts.Diagnostics.Initializers_are_not_allowed_in_ambient_contexts);
- }
- if (!inAmbientContext && !node.initializer && flags & 4096 /* Const */) {
- grammarErrorOnNode(node, ts.Diagnostics.const_declarations_must_be_initialized);
- }
- if (isInStrictMode && isEvalOrArgumentsIdentifier(node.name)) {
- reportInvalidUseInStrictMode(node.name);
- }
+ node.initializer = parseInitializer(false);
return finishNode(node);
}
- function parseVariableDeclarationList(flags, noIn) {
- return parseDelimitedList(9 /* VariableDeclarations */, function () { return parseVariableDeclaration(flags, noIn); }, false);
+ function setFlag(array, flag) {
+ for (var i = 0, n = array.length; i < n; i++) {
+ array[i].flags |= flag;
+ }
+ return array;
}
- function parseVariableStatement(allowLetAndConstDeclarations, pos, flags) {
- var node = createNode(162 /* VariableStatement */, pos);
- if (flags)
- node.flags = flags;
- var errorCountBeforeVarStatement = file.syntacticErrors.length;
+ function parseVariableDeclarationList() {
+ return parseDelimitedList(9 /* VariableDeclarations */, parseVariableDeclaration);
+ }
+ function parseVariableStatement(fullStart, modifiers) {
+ var node = createNode(163 /* VariableStatement */, fullStart);
+ setModifiers(node, modifiers);
if (token === 102 /* LetKeyword */) {
node.flags |= 2048 /* Let */;
}
else if (token === 68 /* ConstKeyword */) {
node.flags |= 4096 /* Const */;
}
- else if (token !== 96 /* VarKeyword */) {
- error(ts.Diagnostics.var_let_or_const_expected);
+ else {
+ ts.Debug.assert(token === 96 /* VarKeyword */);
}
nextToken();
- node.declarations = parseVariableDeclarationList(node.flags, false);
+ node.declarations = allowInAnd(parseVariableDeclarationList);
+ setFlag(node.declarations, node.flags);
parseSemicolon();
- finishNode(node);
- if (!node.declarations.length && file.syntacticErrors.length === errorCountBeforeVarStatement) {
- grammarErrorOnNode(node, ts.Diagnostics.Variable_declaration_list_cannot_be_empty);
- }
- if (languageVersion < 2 /* ES6 */) {
- if (node.flags & 2048 /* Let */) {
- grammarErrorOnNode(node, ts.Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher);
- }
- else if (node.flags & 4096 /* Const */) {
- grammarErrorOnNode(node, ts.Diagnostics.const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher);
- }
- }
- else if (!allowLetAndConstDeclarations) {
- if (node.flags & 2048 /* Let */) {
- grammarErrorOnNode(node, ts.Diagnostics.let_declarations_can_only_be_declared_inside_a_block);
- }
- else if (node.flags & 4096 /* Const */) {
- grammarErrorOnNode(node, ts.Diagnostics.const_declarations_can_only_be_declared_inside_a_block);
- }
- }
- return node;
+ return finishNode(node);
}
- function parseFunctionDeclaration(pos, flags) {
- var node = createNode(185 /* FunctionDeclaration */, pos);
- if (flags)
- node.flags = flags;
+ function parseFunctionDeclaration(fullStart, modifiers) {
+ var node = createNode(186 /* FunctionDeclaration */, fullStart);
+ setModifiers(node, modifiers);
parseExpected(81 /* FunctionKeyword */);
+ node.asteriskToken = parseOptionalToken(34 /* AsteriskToken */);
node.name = parseIdentifier();
- var sig = parseSignature(129 /* CallSignature */, 50 /* ColonToken */, false);
- node.typeParameters = sig.typeParameters;
- node.parameters = sig.parameters;
- node.type = sig.type;
- node.body = parseAndCheckFunctionBody(false);
- if (isInStrictMode && isEvalOrArgumentsIdentifier(node.name) && node.name.kind === 63 /* Identifier */) {
- reportInvalidUseInStrictMode(node.name);
- }
+ fillSignature(129 /* CallSignature */, 50 /* ColonToken */, false, !!node.asteriskToken, node);
+ node.body = parseFunctionBlockOrSemicolon(!!node.asteriskToken);
return finishNode(node);
}
- function parseConstructorDeclaration(pos, flags) {
+ function parseConstructorDeclaration(pos, modifiers) {
var node = createNode(126 /* Constructor */, pos);
- node.flags = flags;
+ setModifiers(node, modifiers);
parseExpected(111 /* ConstructorKeyword */);
- var sig = parseSignature(129 /* CallSignature */, 50 /* ColonToken */, false);
- node.typeParameters = sig.typeParameters;
- node.parameters = sig.parameters;
- node.type = sig.type;
- node.body = parseAndCheckFunctionBody(true);
- if (node.typeParameters) {
- grammarErrorAtPos(node.typeParameters.pos, node.typeParameters.end - node.typeParameters.pos, ts.Diagnostics.Type_parameters_cannot_appear_on_a_constructor_declaration);
- }
- if (node.type) {
- grammarErrorOnNode(node.type, ts.Diagnostics.Type_annotation_cannot_appear_on_a_constructor_declaration);
- }
+ fillSignature(129 /* CallSignature */, 50 /* ColonToken */, false, false, node);
+ node.body = parseFunctionBlockOrSemicolon(false);
return finishNode(node);
}
- function parsePropertyMemberDeclaration(pos, flags) {
- var errorCountBeforePropertyDeclaration = file.syntacticErrors.length;
+ function parsePropertyMemberDeclaration(fullStart, modifiers) {
+ var flags = modifiers ? modifiers.flags : 0;
+ var asteriskToken = parseOptionalToken(34 /* AsteriskToken */);
var name = parsePropertyName();
- var questionStart = scanner.getTokenPos();
if (parseOptional(49 /* QuestionToken */)) {
- errorAtPos(questionStart, scanner.getStartPos() - questionStart, ts.Diagnostics.A_class_member_cannot_be_declared_optional);
+ flags |= 4 /* QuestionMark */;
}
- if (token === 15 /* OpenParenToken */ || token === 23 /* LessThanToken */) {
- var method = createNode(125 /* Method */, pos);
- method.flags = flags;
+ if (asteriskToken || token === 15 /* OpenParenToken */ || token === 23 /* LessThanToken */) {
+ var method = createNode(125 /* Method */, fullStart);
+ setModifiers(method, modifiers);
+ if (flags) {
+ method.flags = flags;
+ }
+ method.asteriskToken = asteriskToken;
method.name = name;
- var sig = parseSignature(129 /* CallSignature */, 50 /* ColonToken */, false);
- method.typeParameters = sig.typeParameters;
- method.parameters = sig.parameters;
- method.type = sig.type;
- method.body = parseAndCheckFunctionBody(false);
+ fillSignature(129 /* CallSignature */, 50 /* ColonToken */, false, !!asteriskToken, method);
+ method.body = parseFunctionBlockOrSemicolon(!!asteriskToken);
return finishNode(method);
}
else {
- var property = createNode(124 /* Property */, pos);
- property.flags = flags;
+ var property = createNode(124 /* Property */, fullStart);
+ setModifiers(property, modifiers);
+ if (flags) {
+ property.flags = flags;
+ }
property.name = name;
property.type = parseTypeAnnotation();
- var initializerStart = scanner.getTokenPos();
- var initializerFirstTokenLength = scanner.getTextPos() - initializerStart;
- property.initializer = parseInitializer(false);
+ property.initializer = allowInAnd(function () { return parseInitializer(false); });
parseSemicolon();
- if (inAmbientContext && property.initializer && errorCountBeforePropertyDeclaration === file.syntacticErrors.length) {
- grammarErrorAtPos(initializerStart, initializerFirstTokenLength, ts.Diagnostics.Initializers_are_not_allowed_in_ambient_contexts);
- }
return finishNode(property);
}
}
- function parseAndCheckMemberAccessorDeclaration(kind, pos, flags) {
- var errorCountBeforeAccessor = file.syntacticErrors.length;
- var accessor = parseMemberAccessorDeclaration(kind, pos, flags);
- if (errorCountBeforeAccessor === file.syntacticErrors.length) {
- if (languageVersion < 1 /* ES5 */) {
- grammarErrorOnNode(accessor.name, ts.Diagnostics.Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher);
- }
- else if (inAmbientContext) {
- grammarErrorOnNode(accessor.name, ts.Diagnostics.An_accessor_cannot_be_declared_in_an_ambient_context);
- }
- else if (accessor.typeParameters) {
- grammarErrorOnNode(accessor.name, ts.Diagnostics.An_accessor_cannot_have_type_parameters);
- }
- else if (kind === 127 /* GetAccessor */ && accessor.parameters.length) {
- grammarErrorOnNode(accessor.name, ts.Diagnostics.A_get_accessor_cannot_have_parameters);
- }
- else if (kind === 128 /* SetAccessor */) {
- if (accessor.type) {
- grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_cannot_have_a_return_type_annotation);
- }
- else if (accessor.parameters.length !== 1) {
- grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_must_have_exactly_one_parameter);
- }
- else {
- var parameter = accessor.parameters[0];
- if (parameter.flags & 8 /* Rest */) {
- grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_cannot_have_rest_parameter);
- }
- else if (parameter.flags & 243 /* Modifier */) {
- grammarErrorOnNode(accessor.name, ts.Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation);
- }
- else if (parameter.flags & 4 /* QuestionMark */) {
- grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_cannot_have_an_optional_parameter);
- }
- else if (parameter.initializer) {
- grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_parameter_cannot_have_an_initializer);
- }
- }
- }
- }
- return accessor;
- }
- function parseMemberAccessorDeclaration(kind, pos, flags) {
- var node = createNode(kind, pos);
- node.flags = flags;
+ function parseMemberAccessorDeclaration(kind, fullStart, modifiers) {
+ var node = createNode(kind, fullStart);
+ setModifiers(node, modifiers);
node.name = parsePropertyName();
- var sig = parseSignature(129 /* CallSignature */, 50 /* ColonToken */, false);
- node.typeParameters = sig.typeParameters;
- node.parameters = sig.parameters;
- node.type = sig.type;
- if (inAmbientContext && canParseSemicolon()) {
- parseSemicolon();
- node.body = createMissingNode();
- }
- else {
- node.body = parseBody(false);
- }
+ fillSignature(129 /* CallSignature */, 50 /* ColonToken */, false, false, node);
+ node.body = parseFunctionBlockOrSemicolon(false);
return finishNode(node);
}
function isClassMemberStart() {
@@ -4867,6 +4496,9 @@ var ts;
idToken = token;
nextToken();
}
+ if (token === 34 /* AsteriskToken */) {
+ return true;
+ }
if (isPropertyName()) {
idToken = token;
nextToken();
@@ -4891,212 +4523,86 @@ var ts;
}
return false;
}
- function parseAndCheckModifiers(context) {
+ function parseModifiers() {
var flags = 0;
- var lastStaticModifierStart;
- var lastStaticModifierLength;
- var lastDeclareModifierStart;
- var lastDeclareModifierLength;
- var lastPrivateModifierStart;
- var lastPrivateModifierLength;
- var lastProtectedModifierStart;
- var lastProtectedModifierLength;
+ var modifiers;
while (true) {
var modifierStart = scanner.getTokenPos();
- var modifierToken = token;
- if (!parseAnyContextualModifier())
+ var modifierKind = token;
+ if (!parseAnyContextualModifier()) {
break;
- var modifierLength = scanner.getStartPos() - modifierStart;
- switch (modifierToken) {
- case 106 /* PublicKeyword */:
- if (flags & 112 /* AccessibilityModifier */) {
- grammarErrorAtPos(modifierStart, modifierLength, ts.Diagnostics.Accessibility_modifier_already_seen);
- }
- else if (flags & 128 /* Static */) {
- grammarErrorAtPos(modifierStart, modifierLength, ts.Diagnostics._0_modifier_must_precede_1_modifier, "public", "static");
- }
- else if (context === 1 /* ModuleElements */ || context === 0 /* SourceElements */) {
- grammarErrorAtPos(modifierStart, modifierLength, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_element, "public");
- }
- flags |= 16 /* Public */;
- break;
- case 104 /* PrivateKeyword */:
- if (flags & 112 /* AccessibilityModifier */) {
- grammarErrorAtPos(modifierStart, modifierLength, ts.Diagnostics.Accessibility_modifier_already_seen);
- }
- else if (flags & 128 /* Static */) {
- grammarErrorAtPos(modifierStart, modifierLength, ts.Diagnostics._0_modifier_must_precede_1_modifier, "private", "static");
- }
- else if (context === 1 /* ModuleElements */ || context === 0 /* SourceElements */) {
- grammarErrorAtPos(modifierStart, modifierLength, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_element, "private");
- }
- lastPrivateModifierStart = modifierStart;
- lastPrivateModifierLength = modifierLength;
- flags |= 32 /* Private */;
- break;
- case 105 /* ProtectedKeyword */:
- if (flags & 16 /* Public */ || flags & 32 /* Private */ || flags & 64 /* Protected */) {
- grammarErrorAtPos(modifierStart, modifierLength, ts.Diagnostics.Accessibility_modifier_already_seen);
- }
- else if (flags & 128 /* Static */) {
- grammarErrorAtPos(modifierStart, modifierLength, ts.Diagnostics._0_modifier_must_precede_1_modifier, "protected", "static");
- }
- else if (context === 1 /* ModuleElements */ || context === 0 /* SourceElements */) {
- grammarErrorAtPos(modifierStart, modifierLength, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_element, "protected");
- }
- lastProtectedModifierStart = modifierStart;
- lastProtectedModifierLength = modifierLength;
- flags |= 64 /* Protected */;
- break;
- case 107 /* StaticKeyword */:
- if (flags & 128 /* Static */) {
- grammarErrorAtPos(modifierStart, modifierLength, ts.Diagnostics._0_modifier_already_seen, "static");
- }
- else if (context === 1 /* ModuleElements */ || context === 0 /* SourceElements */) {
- grammarErrorAtPos(modifierStart, modifierLength, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_element, "static");
- }
- else if (context === 3 /* Parameters */) {
- grammarErrorAtPos(modifierStart, modifierLength, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "static");
- }
- lastStaticModifierStart = modifierStart;
- lastStaticModifierLength = modifierLength;
- flags |= 128 /* Static */;
- break;
- case 76 /* ExportKeyword */:
- if (flags & 1 /* Export */) {
- grammarErrorAtPos(modifierStart, modifierLength, ts.Diagnostics._0_modifier_already_seen, "export");
- }
- else if (flags & 2 /* Ambient */) {
- grammarErrorAtPos(modifierStart, modifierLength, ts.Diagnostics._0_modifier_must_precede_1_modifier, "export", "declare");
- }
- else if (context === 2 /* ClassMembers */) {
- grammarErrorAtPos(modifierStart, modifierLength, ts.Diagnostics._0_modifier_cannot_appear_on_a_class_element, "export");
- }
- else if (context === 3 /* Parameters */) {
- grammarErrorAtPos(modifierStart, modifierLength, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "export");
- }
- flags |= 1 /* Export */;
- break;
- case 112 /* DeclareKeyword */:
- if (flags & 2 /* Ambient */) {
- grammarErrorAtPos(modifierStart, modifierLength, ts.Diagnostics._0_modifier_already_seen, "declare");
- }
- else if (context === 2 /* ClassMembers */) {
- grammarErrorAtPos(modifierStart, modifierLength, ts.Diagnostics._0_modifier_cannot_appear_on_a_class_element, "declare");
- }
- else if (context === 3 /* Parameters */) {
- grammarErrorAtPos(modifierStart, modifierLength, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "declare");
- }
- else if (inAmbientContext && context === 1 /* ModuleElements */) {
- grammarErrorAtPos(modifierStart, modifierLength, ts.Diagnostics.A_declare_modifier_cannot_be_used_in_an_already_ambient_context);
- }
- lastDeclareModifierStart = modifierStart;
- lastDeclareModifierLength = modifierLength;
- flags |= 2 /* Ambient */;
- break;
}
- }
- if (token === 111 /* ConstructorKeyword */ && flags & 128 /* Static */) {
- grammarErrorAtPos(lastStaticModifierStart, lastStaticModifierLength, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "static");
- }
- else if (token === 111 /* ConstructorKeyword */ && flags & 32 /* Private */) {
- grammarErrorAtPos(lastPrivateModifierStart, lastPrivateModifierLength, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "private");
- }
- else if (token === 111 /* ConstructorKeyword */ && flags & 64 /* Protected */) {
- grammarErrorAtPos(lastProtectedModifierStart, lastProtectedModifierLength, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "protected");
- }
- else if (token === 83 /* ImportKeyword */) {
- if (flags & 2 /* Ambient */) {
- grammarErrorAtPos(lastDeclareModifierStart, lastDeclareModifierLength, ts.Diagnostics.A_declare_modifier_cannot_be_used_with_an_import_declaration, "declare");
+ if (!modifiers) {
+ modifiers = [];
}
+ flags |= modifierToFlag(modifierKind);
+ modifiers.push(finishNode(createNode(modifierKind, modifierStart)));
}
- else if (token === 101 /* InterfaceKeyword */) {
- if (flags & 2 /* Ambient */) {
- grammarErrorAtPos(lastDeclareModifierStart, lastDeclareModifierLength, ts.Diagnostics.A_declare_modifier_cannot_be_used_with_an_interface_declaration, "declare");
- }
+ if (modifiers) {
+ modifiers.flags = flags;
}
- else if (token !== 76 /* ExportKeyword */ && !(flags & 2 /* Ambient */) && inAmbientContext && context === 0 /* SourceElements */) {
- var declarationStart = scanner.getTokenPos();
- var declarationFirstTokenLength = scanner.getTextPos() - declarationStart;
- grammarErrorAtPos(declarationStart, declarationFirstTokenLength, ts.Diagnostics.A_declare_modifier_is_required_for_a_top_level_declaration_in_a_d_ts_file);
- }
- return flags;
+ return modifiers;
}
function parseClassMemberDeclaration() {
- var pos = getNodePos();
- var flags = parseAndCheckModifiers(2 /* ClassMembers */);
+ var fullStart = getNodePos();
+ var modifiers = parseModifiers();
if (parseContextualModifier(113 /* GetKeyword */)) {
- return parseAndCheckMemberAccessorDeclaration(127 /* GetAccessor */, pos, flags);
+ return parseMemberAccessorDeclaration(127 /* GetAccessor */, fullStart, modifiers);
}
if (parseContextualModifier(117 /* SetKeyword */)) {
- return parseAndCheckMemberAccessorDeclaration(128 /* SetAccessor */, pos, flags);
+ return parseMemberAccessorDeclaration(128 /* SetAccessor */, fullStart, modifiers);
}
if (token === 111 /* ConstructorKeyword */) {
- return parseConstructorDeclaration(pos, flags);
+ return parseConstructorDeclaration(fullStart, modifiers);
}
- if (token >= 63 /* Identifier */ || token === 7 /* StringLiteral */ || token === 6 /* NumericLiteral */) {
- return parsePropertyMemberDeclaration(pos, flags);
+ if (token >= 63 /* Identifier */ || token === 7 /* StringLiteral */ || token === 6 /* NumericLiteral */ || token === 34 /* AsteriskToken */) {
+ return parsePropertyMemberDeclaration(fullStart, modifiers);
}
if (token === 17 /* OpenBracketToken */) {
- if (flags) {
- var start = getTokenPos(pos);
- var length = getNodePos() - start;
- errorAtPos(start, length, ts.Diagnostics.Modifiers_not_permitted_on_index_signature_members);
- }
- return parseIndexSignatureMember();
+ return parseIndexSignatureMember(fullStart, modifiers);
}
ts.Debug.fail("Should not have attempted to parse class member declaration.");
}
- function parseClassDeclaration(pos, flags) {
- var node = createNode(187 /* ClassDeclaration */, pos);
- node.flags = flags;
- var errorCountBeforeClassDeclaration = file.syntacticErrors.length;
+ function parseClassDeclaration(fullStart, modifiers) {
+ var node = createNode(188 /* ClassDeclaration */, fullStart);
+ setModifiers(node, modifiers);
parseExpected(67 /* ClassKeyword */);
node.name = parseIdentifier();
node.typeParameters = parseTypeParameters();
- node.baseType = parseOptional(77 /* ExtendsKeyword */) ? parseTypeReference() : undefined;
- var implementsKeywordStart = scanner.getTokenPos();
- var implementsKeywordLength;
+ node.baseType = inGeneratorParameterContext() ? doOutsideOfYieldContext(parseClassBaseType) : parseClassBaseType();
if (parseOptional(100 /* ImplementsKeyword */)) {
- implementsKeywordLength = scanner.getStartPos() - implementsKeywordStart;
- node.implementedTypes = parseDelimitedList(8 /* BaseTypeReferences */, parseTypeReference, false);
+ node.implementedTypes = parseDelimitedList(8 /* BaseTypeReferences */, parseTypeReference);
}
- var errorCountBeforeClassBody = file.syntacticErrors.length;
if (parseExpected(13 /* OpenBraceToken */)) {
- node.members = parseList(6 /* ClassMembers */, false, parseClassMemberDeclaration);
+ node.members = inGeneratorParameterContext() ? doOutsideOfYieldContext(parseClassMembers) : parseClassMembers();
parseExpected(14 /* CloseBraceToken */);
}
else {
node.members = createMissingList();
}
- if (node.implementedTypes && !node.implementedTypes.length && errorCountBeforeClassBody === errorCountBeforeClassDeclaration) {
- grammarErrorAtPos(implementsKeywordStart, implementsKeywordLength, ts.Diagnostics._0_list_cannot_be_empty, "implements");
- }
return finishNode(node);
}
- function parseInterfaceDeclaration(pos, flags) {
- var node = createNode(188 /* InterfaceDeclaration */, pos);
- node.flags = flags;
- var errorCountBeforeInterfaceDeclaration = file.syntacticErrors.length;
+ function parseClassMembers() {
+ return parseList(6 /* ClassMembers */, false, parseClassMemberDeclaration);
+ }
+ function parseClassBaseType() {
+ return parseOptional(77 /* ExtendsKeyword */) ? parseTypeReference() : undefined;
+ }
+ function parseInterfaceDeclaration(fullStart, modifiers) {
+ var node = createNode(189 /* InterfaceDeclaration */, fullStart);
+ setModifiers(node, modifiers);
parseExpected(101 /* InterfaceKeyword */);
node.name = parseIdentifier();
node.typeParameters = parseTypeParameters();
- var extendsKeywordStart = scanner.getTokenPos();
- var extendsKeywordLength;
if (parseOptional(77 /* ExtendsKeyword */)) {
- extendsKeywordLength = scanner.getStartPos() - extendsKeywordStart;
- node.baseTypes = parseDelimitedList(8 /* BaseTypeReferences */, parseTypeReference, false);
- }
- var errorCountBeforeInterfaceBody = file.syntacticErrors.length;
- node.members = parseTypeLiteral().members;
- if (node.baseTypes && !node.baseTypes.length && errorCountBeforeInterfaceBody === errorCountBeforeInterfaceDeclaration) {
- grammarErrorAtPos(extendsKeywordStart, extendsKeywordLength, ts.Diagnostics._0_list_cannot_be_empty, "extends");
+ node.baseTypes = parseDelimitedList(8 /* BaseTypeReferences */, parseTypeReference);
}
+ node.members = parseObjectType();
return finishNode(node);
}
- function parseTypeAliasDeclaration(pos, flags) {
- var node = createNode(189 /* TypeAliasDeclaration */, pos);
- node.flags = flags;
+ function parseTypeAliasDeclaration(fullStart, modifiers) {
+ var node = createNode(190 /* TypeAliasDeclaration */, fullStart);
+ setModifiers(node, modifiers);
parseExpected(119 /* TypeKeyword */);
node.name = parseIdentifier();
parseExpected(51 /* EqualsToken */);
@@ -5104,53 +4610,22 @@ var ts;
parseSemicolon();
return finishNode(node);
}
- function parseAndCheckEnumDeclaration(pos, flags) {
- var enumIsConst = flags & 4096 /* Const */;
- function isIntegerLiteral(expression) {
- function isInteger(literalExpression) {
- return /^[0-9]+([eE]\+?[0-9]+)?$/.test(literalExpression.text);
- }
- if (expression.kind === 154 /* PrefixOperator */) {
- var unaryExpression = expression;
- if (unaryExpression.operator === 32 /* PlusToken */ || unaryExpression.operator === 33 /* MinusToken */) {
- expression = unaryExpression.operand;
- }
- }
- if (expression.kind === 6 /* NumericLiteral */) {
- return isInteger(expression);
- }
- return false;
- }
- var inConstantEnumMemberSection = true;
- function parseAndCheckEnumMember() {
- var node = createNode(195 /* EnumMember */);
- var errorCountBeforeEnumMember = file.syntacticErrors.length;
- node.name = parsePropertyName();
- node.initializer = parseInitializer(false);
- if (!enumIsConst) {
- if (inAmbientContext) {
- if (node.initializer && !isIntegerLiteral(node.initializer) && errorCountBeforeEnumMember === file.syntacticErrors.length) {
- grammarErrorOnNode(node.name, ts.Diagnostics.Ambient_enum_elements_can_only_have_integer_literal_initializers);
- }
- }
- else if (node.initializer) {
- inConstantEnumMemberSection = isIntegerLiteral(node.initializer);
- }
- else if (!inConstantEnumMemberSection && errorCountBeforeEnumMember === file.syntacticErrors.length) {
- grammarErrorOnNode(node.name, ts.Diagnostics.Enum_member_must_have_initializer);
- }
- }
- return finishNode(node);
- }
- var node = createNode(190 /* EnumDeclaration */, pos);
+ function parseEnumMember() {
+ var node = createNode(196 /* EnumMember */, scanner.getStartPos());
+ node.name = parsePropertyName();
+ node.initializer = allowInAnd(function () { return parseInitializer(false); });
+ return finishNode(node);
+ }
+ function parseAndCheckEnumDeclaration(fullStart, flags) {
+ var node = createNode(191 /* EnumDeclaration */, fullStart);
node.flags = flags;
- if (enumIsConst) {
+ if (flags & 4096 /* Const */) {
parseExpected(68 /* ConstKeyword */);
}
parseExpected(75 /* EnumKeyword */);
node.name = parseIdentifier();
if (parseExpected(13 /* OpenBraceToken */)) {
- node.members = parseDelimitedList(7 /* EnumMembers */, parseAndCheckEnumMember, true);
+ node.members = parseDelimitedList(7 /* EnumMembers */, parseEnumMember);
parseExpected(14 /* CloseBraceToken */);
}
else {
@@ -5159,7 +4634,7 @@ var ts;
return finishNode(node);
}
function parseModuleBody() {
- var node = createNode(192 /* ModuleBlock */);
+ var node = createNode(193 /* ModuleBlock */, scanner.getStartPos());
if (parseExpected(13 /* OpenBraceToken */)) {
node.statements = parseList(1 /* ModuleElements */, false, parseModuleElement);
parseExpected(14 /* CloseBraceToken */);
@@ -5169,49 +4644,27 @@ var ts;
}
return finishNode(node);
}
- function parseInternalModuleTail(pos, flags) {
- var node = createNode(191 /* ModuleDeclaration */, pos);
+ function parseInternalModuleTail(fullStart, flags) {
+ var node = createNode(192 /* ModuleDeclaration */, fullStart);
node.flags = flags;
node.name = parseIdentifier();
- if (parseOptional(19 /* DotToken */)) {
- node.body = parseInternalModuleTail(getNodePos(), 1 /* Export */);
- }
- else {
- node.body = parseModuleBody();
- ts.forEach(node.body.statements, function (s) {
- if (s.kind === 194 /* ExportAssignment */) {
- grammarErrorOnNode(s, ts.Diagnostics.An_export_assignment_cannot_be_used_in_an_internal_module);
- }
- else if (s.kind === 193 /* ImportDeclaration */ && s.externalModuleName) {
- grammarErrorOnNode(s, ts.Diagnostics.Import_declarations_in_an_internal_module_cannot_reference_an_external_module);
- }
- });
- }
+ node.body = parseOptional(19 /* DotToken */) ? parseInternalModuleTail(getNodePos(), 1 /* Export */) : parseModuleBody();
return finishNode(node);
}
- function parseAmbientExternalModuleDeclaration(pos, flags) {
- var node = createNode(191 /* ModuleDeclaration */, pos);
+ function parseAmbientExternalModuleDeclaration(fullStart, flags) {
+ var node = createNode(192 /* ModuleDeclaration */, fullStart);
node.flags = flags;
node.name = parseStringLiteral();
- if (!inAmbientContext) {
- var errorCount = file.syntacticErrors.length;
- if (!errorCount || file.syntacticErrors[errorCount - 1].start < getTokenPos(pos)) {
- grammarErrorOnNode(node.name, ts.Diagnostics.Only_ambient_modules_can_use_quoted_names);
- }
- }
- var saveInAmbientContext = inAmbientContext;
- inAmbientContext = true;
node.body = parseModuleBody();
- inAmbientContext = saveInAmbientContext;
return finishNode(node);
}
- function parseModuleDeclaration(pos, flags) {
+ function parseModuleDeclaration(fullStart, flags) {
parseExpected(114 /* ModuleKeyword */);
- return token === 7 /* StringLiteral */ ? parseAmbientExternalModuleDeclaration(pos, flags) : parseInternalModuleTail(pos, flags);
+ return token === 7 /* StringLiteral */ ? parseAmbientExternalModuleDeclaration(fullStart, flags) : parseInternalModuleTail(fullStart, flags);
}
- function parseImportDeclaration(pos, flags) {
- var node = createNode(193 /* ImportDeclaration */, pos);
- node.flags = flags;
+ function parseImportDeclaration(fullStart, modifiers) {
+ var node = createNode(194 /* ImportDeclaration */, fullStart);
+ setModifiers(node, modifiers);
parseExpected(83 /* ImportKeyword */);
node.name = parseIdentifier();
parseExpected(51 /* EqualsToken */);
@@ -5226,8 +4679,9 @@ var ts;
parseSemicolon();
return finishNode(node);
}
- function parseExportAssignmentTail(pos) {
- var node = createNode(194 /* ExportAssignment */, pos);
+ function parseExportAssignmentTail(fullStart, modifiers) {
+ var node = createNode(195 /* ExportAssignment */, fullStart);
+ setModifiers(node, modifiers);
node.exportName = parseIdentifier();
parseSemicolon();
return finishNode(node);
@@ -5260,89 +4714,71 @@ var ts;
});
}
}
- function parseDeclaration(modifierContext) {
- var pos = getNodePos();
- var errorCountBeforeModifiers = file.syntacticErrors.length;
- var flags = parseAndCheckModifiers(modifierContext);
+ function parseDeclaration() {
+ var fullStart = getNodePos();
+ var modifiers = parseModifiers();
if (token === 76 /* ExportKeyword */) {
- var modifiersEnd = scanner.getStartPos();
nextToken();
if (parseOptional(51 /* EqualsToken */)) {
- var exportAssignmentTail = parseExportAssignmentTail(pos);
- if (flags !== 0 && errorCountBeforeModifiers === file.syntacticErrors.length) {
- var modifiersStart = ts.skipTrivia(sourceText, pos);
- grammarErrorAtPos(modifiersStart, modifiersEnd - modifiersStart, ts.Diagnostics.An_export_assignment_cannot_have_modifiers);
- }
- return exportAssignmentTail;
+ return parseExportAssignmentTail(fullStart, modifiers);
}
}
- var saveInAmbientContext = inAmbientContext;
- if (flags & 2 /* Ambient */) {
- inAmbientContext = true;
- }
+ var flags = modifiers ? modifiers.flags : 0;
var result;
switch (token) {
case 96 /* VarKeyword */:
case 102 /* LetKeyword */:
- result = parseVariableStatement(true, pos, flags);
+ result = parseVariableStatement(fullStart, modifiers);
break;
case 68 /* ConstKeyword */:
var isConstEnum = lookAhead(function () { return nextToken() === 75 /* EnumKeyword */; });
if (isConstEnum) {
- result = parseAndCheckEnumDeclaration(pos, flags | 4096 /* Const */);
+ result = parseAndCheckEnumDeclaration(fullStart, flags | 4096 /* Const */);
}
else {
- result = parseVariableStatement(true, pos, flags);
+ result = parseVariableStatement(fullStart, modifiers);
}
break;
case 81 /* FunctionKeyword */:
- result = parseFunctionDeclaration(pos, flags);
+ result = parseFunctionDeclaration(fullStart, modifiers);
break;
case 67 /* ClassKeyword */:
- result = parseClassDeclaration(pos, flags);
+ result = parseClassDeclaration(fullStart, modifiers);
break;
case 101 /* InterfaceKeyword */:
- result = parseInterfaceDeclaration(pos, flags);
+ result = parseInterfaceDeclaration(fullStart, modifiers);
break;
case 119 /* TypeKeyword */:
- result = parseTypeAliasDeclaration(pos, flags);
+ result = parseTypeAliasDeclaration(fullStart, modifiers);
break;
case 75 /* EnumKeyword */:
- result = parseAndCheckEnumDeclaration(pos, flags);
+ result = parseAndCheckEnumDeclaration(fullStart, flags);
break;
case 114 /* ModuleKeyword */:
- result = parseModuleDeclaration(pos, flags);
+ result = parseModuleDeclaration(fullStart, flags);
break;
case 83 /* ImportKeyword */:
- result = parseImportDeclaration(pos, flags);
+ result = parseImportDeclaration(fullStart, modifiers);
break;
default:
error(ts.Diagnostics.Declaration_expected);
}
- inAmbientContext = saveInAmbientContext;
+ if (modifiers) {
+ result.modifiers = modifiers;
+ }
return result;
}
function isSourceElement(inErrorRecovery) {
return isDeclarationStart() || isStatement(inErrorRecovery);
}
function parseSourceElement() {
- return parseSourceElementOrModuleElement(0 /* SourceElements */);
+ return parseSourceElementOrModuleElement();
}
function parseModuleElement() {
- return parseSourceElementOrModuleElement(1 /* ModuleElements */);
+ return parseSourceElementOrModuleElement();
}
- function parseSourceElementOrModuleElement(modifierContext) {
- if (isDeclarationStart()) {
- return parseDeclaration(modifierContext);
- }
- var statementStart = scanner.getTokenPos();
- var statementFirstTokenLength = scanner.getTextPos() - statementStart;
- var errorCountBeforeStatement = file.syntacticErrors.length;
- var statement = parseStatement(true);
- if (inAmbientContext && file.syntacticErrors.length === errorCountBeforeStatement) {
- grammarErrorAtPos(statementStart, statementFirstTokenLength, ts.Diagnostics.Statements_are_not_allowed_in_ambient_contexts);
- }
- return statement;
+ function parseSourceElementOrModuleElement() {
+ return isDeclarationStart() ? parseDeclaration() : parseStatement();
}
function processReferenceComments() {
var referencedFiles = [];
@@ -5389,22 +4825,37 @@ var ts;
};
}
function getExternalModuleIndicator() {
- return ts.forEach(file.statements, function (node) { return node.flags & 1 /* Export */ || node.kind === 193 /* ImportDeclaration */ && node.externalModuleName || node.kind === 194 /* ExportAssignment */ ? node : undefined; });
+ return ts.forEach(file.statements, function (node) { return node.flags & 1 /* Export */ || node.kind === 194 /* ImportDeclaration */ && node.externalModuleName || node.kind === 195 /* ExportAssignment */ ? node : undefined; });
+ }
+ var syntacticDiagnostics;
+ function getSyntacticDiagnostics() {
+ if (syntacticDiagnostics === undefined) {
+ if (file.parseDiagnostics.length > 0) {
+ syntacticDiagnostics = file.parseDiagnostics;
+ }
+ else {
+ syntacticDiagnostics = file.grammarDiagnostics;
+ checkGrammar(sourceText, languageVersion, file);
+ }
+ }
+ ts.Debug.assert(syntacticDiagnostics !== undefined);
+ return syntacticDiagnostics;
}
scanner = ts.createScanner(languageVersion, true, sourceText, scanError, onComment);
var rootNodeFlags = 0;
if (ts.fileExtensionIs(filename, ".d.ts")) {
rootNodeFlags = 1024 /* DeclarationFile */;
- inAmbientContext = true;
}
- file = createRootNode(196 /* SourceFile */, 0, sourceText.length, rootNodeFlags);
+ file = createRootNode(197 /* SourceFile */, 0, sourceText.length, rootNodeFlags);
file.filename = ts.normalizePath(filename);
file.text = sourceText;
file.getLineAndCharacterFromPosition = getLineAndCharacterFromSourcePosition;
file.getPositionFromLineAndCharacter = getPositionFromSourceLineAndCharacter;
file.getLineStarts = getLineStarts;
- file.syntacticErrors = [];
- file.semanticErrors = [];
+ file.getSyntacticDiagnostics = getSyntacticDiagnostics;
+ file.parseDiagnostics = [];
+ file.grammarDiagnostics = [];
+ file.semanticDiagnostics = [];
var referenceComments = processReferenceComments();
file.referencedFiles = referenceComments.referencedFiles;
file.amdDependencies = referenceComments.amdDependencies;
@@ -5420,6 +4871,913 @@ var ts;
return file;
}
ts.createSourceFile = createSourceFile;
+ function isLeftHandSideExpression(expr) {
+ if (expr) {
+ switch (expr.kind) {
+ case 145 /* PropertyAccess */:
+ case 146 /* IndexedAccess */:
+ case 148 /* NewExpression */:
+ case 147 /* CallExpression */:
+ case 149 /* TaggedTemplateExpression */:
+ case 141 /* ArrayLiteral */:
+ case 151 /* ParenExpression */:
+ case 142 /* ObjectLiteral */:
+ case 152 /* FunctionExpression */:
+ case 63 /* Identifier */:
+ case 120 /* Missing */:
+ case 8 /* RegularExpressionLiteral */:
+ case 6 /* NumericLiteral */:
+ case 7 /* StringLiteral */:
+ case 9 /* NoSubstitutionTemplateLiteral */:
+ case 158 /* TemplateExpression */:
+ case 78 /* FalseKeyword */:
+ case 87 /* NullKeyword */:
+ case 91 /* ThisKeyword */:
+ case 93 /* TrueKeyword */:
+ case 89 /* SuperKeyword */:
+ return true;
+ }
+ }
+ return false;
+ }
+ function isAssignmentOperator(token) {
+ return token >= 51 /* FirstAssignment */ && token <= 62 /* LastAssignment */;
+ }
+ function checkGrammar(sourceText, languageVersion, file) {
+ var grammarDiagnostics = file.grammarDiagnostics;
+ var scanner = ts.createScanner(languageVersion, true, sourceText);
+ var inAmbientContext = ts.fileExtensionIs(file.filename, ".d.ts");
+ var inFunctionBlock = false;
+ var parent;
+ visitNode(file);
+ function visitNode(node) {
+ var savedParent = parent;
+ node.parent = parent;
+ parent = node;
+ if (!checkModifiers(node)) {
+ var savedInFunctionBlock = inFunctionBlock;
+ if (node.kind === 187 /* FunctionBlock */) {
+ inFunctionBlock = true;
+ }
+ var savedInAmbientContext = inAmbientContext;
+ if (node.flags & 2 /* Ambient */) {
+ inAmbientContext = true;
+ }
+ checkNodeAndChildren(node);
+ inAmbientContext = savedInAmbientContext;
+ inFunctionBlock = savedInFunctionBlock;
+ }
+ parent = savedParent;
+ }
+ function checkNodeAndChildren(node) {
+ var nodeKind = node.kind;
+ if (inAmbientContext && checkForStatementInAmbientContext(node, nodeKind)) {
+ return;
+ }
+ if (checkNode(node, nodeKind)) {
+ return;
+ }
+ forEachChild(node, visitNode);
+ }
+ function checkNode(node, nodeKind) {
+ switch (nodeKind) {
+ case 153 /* ArrowFunction */:
+ case 129 /* CallSignature */:
+ case 134 /* ConstructorType */:
+ case 130 /* ConstructSignature */:
+ case 133 /* FunctionType */:
+ return checkAnyParsedSignature(node);
+ case 172 /* BreakStatement */:
+ case 171 /* ContinueStatement */:
+ return checkBreakOrContinueStatement(node);
+ case 147 /* CallExpression */:
+ case 148 /* NewExpression */:
+ return checkCallOrNewExpression(node);
+ case 191 /* EnumDeclaration */: return checkEnumDeclaration(node);
+ case 156 /* BinaryExpression */: return checkBinaryExpression(node);
+ case 182 /* CatchBlock */: return checkCatchBlock(node);
+ case 188 /* ClassDeclaration */: return checkClassDeclaration(node);
+ case 126 /* Constructor */: return checkConstructor(node);
+ case 195 /* ExportAssignment */: return checkExportAssignment(node);
+ case 170 /* ForInStatement */: return checkForInStatement(node);
+ case 169 /* ForStatement */: return checkForStatement(node);
+ case 186 /* FunctionDeclaration */: return checkFunctionDeclaration(node);
+ case 152 /* FunctionExpression */: return checkFunctionExpression(node);
+ case 127 /* GetAccessor */: return checkGetAccessor(node);
+ case 146 /* IndexedAccess */: return checkIndexedAccess(node);
+ case 131 /* IndexSignature */: return checkIndexSignature(node);
+ case 189 /* InterfaceDeclaration */: return checkInterfaceDeclaration(node);
+ case 178 /* LabeledStatement */: return checkLabeledStatement(node);
+ case 125 /* Method */: return checkMethod(node);
+ case 192 /* ModuleDeclaration */: return checkModuleDeclaration(node);
+ case 142 /* ObjectLiteral */: return checkObjectLiteral(node);
+ case 6 /* NumericLiteral */: return checkNumericLiteral(node);
+ case 123 /* Parameter */: return checkParameter(node);
+ case 155 /* PostfixOperator */: return checkPostfixOperator(node);
+ case 154 /* PrefixOperator */: return checkPrefixOperator(node);
+ case 124 /* Property */: return checkProperty(node);
+ case 143 /* PropertyAssignment */: return checkPropertyAssignment(node);
+ case 173 /* ReturnStatement */: return checkReturnStatement(node);
+ case 128 /* SetAccessor */: return checkSetAccessor(node);
+ case 197 /* SourceFile */: return checkSourceFile(node);
+ case 144 /* ShorthandPropertyAssignment */: return checkShorthandPropertyAssignment(node);
+ case 175 /* SwitchStatement */: return checkSwitchStatement(node);
+ case 149 /* TaggedTemplateExpression */: return checkTaggedTemplateExpression(node);
+ case 138 /* TupleType */: return checkTupleType(node);
+ case 122 /* TypeParameter */: return checkTypeParameter(node);
+ case 132 /* TypeReference */: return checkTypeReference(node);
+ case 185 /* VariableDeclaration */: return checkVariableDeclaration(node);
+ case 163 /* VariableStatement */: return checkVariableStatement(node);
+ case 174 /* WithStatement */: return checkWithStatement(node);
+ case 160 /* YieldExpression */: return checkYieldExpression(node);
+ }
+ }
+ function grammarErrorOnFirstToken(node, message, arg0, arg1, arg2) {
+ var start = ts.skipTrivia(sourceText, node.pos);
+ scanner.setTextPos(start);
+ scanner.scan();
+ var end = scanner.getTextPos();
+ grammarDiagnostics.push(ts.createFileDiagnostic(file, start, end - start, message, arg0, arg1, arg2));
+ return true;
+ }
+ function grammarErrorOnNode(node, message, arg0, arg1, arg2) {
+ var span = getErrorSpanForNode(node);
+ var start = span.end > span.pos ? ts.skipTrivia(file.text, span.pos) : span.pos;
+ var length = span.end - start;
+ grammarDiagnostics.push(ts.createFileDiagnostic(file, start, length, message, arg0, arg1, arg2));
+ return true;
+ }
+ function grammarErrorAtPos(start, length, message, arg0, arg1, arg2) {
+ grammarDiagnostics.push(ts.createFileDiagnostic(file, start, length, message, arg0, arg1, arg2));
+ return true;
+ }
+ function reportInvalidUseInStrictMode(node) {
+ var name = sourceText.substring(ts.skipTrivia(sourceText, node.pos), node.end);
+ return grammarErrorOnNode(node, ts.Diagnostics.Invalid_use_of_0_in_strict_mode, name);
+ }
+ function checkForStatementInAmbientContext(node, kind) {
+ switch (kind) {
+ case 162 /* Block */:
+ case 164 /* EmptyStatement */:
+ case 166 /* IfStatement */:
+ case 167 /* DoStatement */:
+ case 168 /* WhileStatement */:
+ case 169 /* ForStatement */:
+ case 170 /* ForInStatement */:
+ case 171 /* ContinueStatement */:
+ case 172 /* BreakStatement */:
+ case 173 /* ReturnStatement */:
+ case 174 /* WithStatement */:
+ case 175 /* SwitchStatement */:
+ case 179 /* ThrowStatement */:
+ case 180 /* TryStatement */:
+ case 184 /* DebuggerStatement */:
+ case 178 /* LabeledStatement */:
+ case 165 /* ExpressionStatement */:
+ return grammarErrorOnFirstToken(node, ts.Diagnostics.Statements_are_not_allowed_in_ambient_contexts);
+ }
+ }
+ function checkAnyParsedSignature(node) {
+ return checkTypeParameterList(node.typeParameters) || checkParameterList(node.parameters);
+ }
+ function checkBinaryExpression(node) {
+ if (node.parserContextFlags & 1 /* StrictMode */) {
+ if (isLeftHandSideExpression(node.left) && isAssignmentOperator(node.operator)) {
+ if (isEvalOrArgumentsIdentifier(node.left)) {
+ return reportInvalidUseInStrictMode(node.left);
+ }
+ }
+ }
+ }
+ function isIterationStatement(node, lookInLabeledStatements) {
+ switch (node.kind) {
+ case 169 /* ForStatement */:
+ case 170 /* ForInStatement */:
+ case 167 /* DoStatement */:
+ case 168 /* WhileStatement */:
+ return true;
+ case 178 /* LabeledStatement */:
+ return lookInLabeledStatements && isIterationStatement(node.statement, lookInLabeledStatements);
+ }
+ return false;
+ }
+ function checkLabeledStatement(node) {
+ var current = node.parent;
+ while (current) {
+ if (isAnyFunction(current)) {
+ break;
+ }
+ if (current.kind === 178 /* LabeledStatement */ && current.label.text === node.label.text) {
+ return grammarErrorOnNode(node.label, ts.Diagnostics.Duplicate_label_0, getTextOfNodeFromSourceText(sourceText, node.label));
+ }
+ current = current.parent;
+ }
+ }
+ function checkBreakOrContinueStatement(node) {
+ var current = node;
+ while (current) {
+ if (isAnyFunction(current)) {
+ return grammarErrorOnNode(node, ts.Diagnostics.Jump_target_cannot_cross_function_boundary);
+ }
+ switch (current.kind) {
+ case 178 /* LabeledStatement */:
+ if (node.label && current.label.text === node.label.text) {
+ var isMisplacedContinueLabel = node.kind === 171 /* ContinueStatement */ && !isIterationStatement(current.statement, true);
+ if (isMisplacedContinueLabel) {
+ return grammarErrorOnNode(node, ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement);
+ }
+ return false;
+ }
+ break;
+ case 175 /* SwitchStatement */:
+ if (node.kind === 172 /* BreakStatement */ && !node.label) {
+ return false;
+ }
+ break;
+ default:
+ if (isIterationStatement(current, false) && !node.label) {
+ return false;
+ }
+ break;
+ }
+ current = current.parent;
+ }
+ if (node.label) {
+ var message = node.kind === 172 /* BreakStatement */ ? ts.Diagnostics.A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement : ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement;
+ return grammarErrorOnNode(node, message);
+ }
+ else {
+ var message = node.kind === 172 /* BreakStatement */ ? ts.Diagnostics.A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement : ts.Diagnostics.A_continue_statement_can_only_be_used_within_an_enclosing_iteration_statement;
+ return grammarErrorOnNode(node, message);
+ }
+ }
+ function checkCallOrNewExpression(node) {
+ return checkTypeArguments(node.typeArguments) || checkArguments(node.arguments);
+ }
+ function checkArguments(arguments) {
+ return checkForDisallowedTrailingComma(arguments) || checkForOmittedArgument(arguments);
+ }
+ function checkTypeArguments(typeArguments) {
+ return checkForDisallowedTrailingComma(typeArguments) || checkForAtLeastOneTypeArgument(typeArguments) || checkForMissingTypeArgument(typeArguments);
+ }
+ function checkForOmittedArgument(arguments) {
+ if (arguments) {
+ for (var i = 0, n = arguments.length; i < n; i++) {
+ var arg = arguments[i];
+ if (arg.kind === 161 /* OmittedExpression */) {
+ return grammarErrorAtPos(arg.pos, 0, ts.Diagnostics.Argument_expression_expected);
+ }
+ }
+ }
+ }
+ function checkForMissingTypeArgument(typeArguments) {
+ if (typeArguments) {
+ for (var i = 0, n = typeArguments.length; i < n; i++) {
+ var arg = typeArguments[i];
+ if (arg.kind === 120 /* Missing */) {
+ return grammarErrorAtPos(arg.pos, 0, ts.Diagnostics.Type_expected);
+ }
+ }
+ }
+ }
+ function checkForAtLeastOneTypeArgument(typeArguments) {
+ if (typeArguments && typeArguments.length === 0) {
+ var start = typeArguments.pos - "<".length;
+ var end = ts.skipTrivia(sourceText, typeArguments.end) + ">".length;
+ return grammarErrorAtPos(start, end - start, ts.Diagnostics.Type_argument_list_cannot_be_empty);
+ }
+ }
+ function checkForDisallowedTrailingComma(list) {
+ if (list && list.hasTrailingComma) {
+ var start = list.end - ",".length;
+ var end = list.end;
+ return grammarErrorAtPos(start, end - start, ts.Diagnostics.Trailing_comma_not_allowed);
+ }
+ }
+ function checkCatchBlock(node) {
+ if (node.type) {
+ var colonStart = ts.skipTrivia(sourceText, node.variable.end);
+ return grammarErrorAtPos(colonStart, ":".length, ts.Diagnostics.Catch_clause_parameter_cannot_have_a_type_annotation);
+ }
+ if (node.parserContextFlags & 1 /* StrictMode */ && isEvalOrArgumentsIdentifier(node.variable)) {
+ return reportInvalidUseInStrictMode(node.variable);
+ }
+ }
+ function checkClassDeclaration(node) {
+ return checkForDisallowedTrailingComma(node.implementedTypes) || checkForAtLeastOneHeritageClause(node.implementedTypes, "implements");
+ }
+ function checkForAtLeastOneHeritageClause(types, listType) {
+ if (types && types.length === 0) {
+ return grammarErrorAtPos(types.pos, 0, ts.Diagnostics._0_list_cannot_be_empty, listType);
+ }
+ }
+ function checkConstructor(node) {
+ return checkAnyParsedSignature(node) || checkConstructorTypeParameters(node) || checkConstructorTypeAnnotation(node) || checkForBodyInAmbientContext(node.body, true);
+ }
+ function checkConstructorTypeParameters(node) {
+ if (node.typeParameters) {
+ return grammarErrorAtPos(node.typeParameters.pos, node.typeParameters.end - node.typeParameters.pos, ts.Diagnostics.Type_parameters_cannot_appear_on_a_constructor_declaration);
+ }
+ }
+ function checkConstructorTypeAnnotation(node) {
+ if (node.type) {
+ return grammarErrorOnNode(node.type, ts.Diagnostics.Type_annotation_cannot_appear_on_a_constructor_declaration);
+ }
+ }
+ function checkEnumDeclaration(enumDecl) {
+ var enumIsConst = (enumDecl.flags & 4096 /* Const */) !== 0;
+ var hasError = false;
+ if (!enumIsConst) {
+ var inConstantEnumMemberSection = true;
+ for (var i = 0, n = enumDecl.members.length; i < n; i++) {
+ var node = enumDecl.members[i];
+ if (inAmbientContext) {
+ if (node.initializer && !isIntegerLiteral(node.initializer)) {
+ hasError = grammarErrorOnNode(node.name, ts.Diagnostics.Ambient_enum_elements_can_only_have_integer_literal_initializers) || hasError;
+ }
+ }
+ else if (node.initializer) {
+ inConstantEnumMemberSection = isIntegerLiteral(node.initializer);
+ }
+ else if (!inConstantEnumMemberSection) {
+ hasError = grammarErrorOnNode(node.name, ts.Diagnostics.Enum_member_must_have_initializer) || hasError;
+ }
+ }
+ }
+ return hasError;
+ }
+ function isIntegerLiteral(expression) {
+ function isInteger(literalExpression) {
+ return /^[0-9]+([eE]\+?[0-9]+)?$/.test(literalExpression.text);
+ }
+ if (expression.kind === 154 /* PrefixOperator */) {
+ var unaryExpression = expression;
+ if (unaryExpression.operator === 32 /* PlusToken */ || unaryExpression.operator === 33 /* MinusToken */) {
+ expression = unaryExpression.operand;
+ }
+ }
+ if (expression.kind === 6 /* NumericLiteral */) {
+ return isInteger(expression);
+ }
+ return false;
+ }
+ function checkExportAssignment(node) {
+ if (node.flags & 243 /* Modifier */) {
+ return grammarErrorOnFirstToken(node, ts.Diagnostics.An_export_assignment_cannot_have_modifiers);
+ }
+ }
+ function checkForInStatement(node) {
+ return checkVariableDeclarations(node.declarations) || checkForMoreThanOneDeclaration(node.declarations);
+ }
+ function checkForStatement(node) {
+ return checkVariableDeclarations(node.declarations);
+ }
+ function checkForMoreThanOneDeclaration(declarations) {
+ if (declarations && declarations.length > 1) {
+ return grammarErrorOnFirstToken(declarations[1], ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement);
+ }
+ }
+ function checkFunctionDeclaration(node) {
+ return checkAnyParsedSignature(node) || checkFunctionName(node.name) || checkForBodyInAmbientContext(node.body, false) || checkForGenerator(node);
+ }
+ function checkForGenerator(node) {
+ if (node.asteriskToken) {
+ return grammarErrorOnNode(node.asteriskToken, ts.Diagnostics.generators_are_not_currently_supported);
+ }
+ }
+ function checkFunctionExpression(node) {
+ return checkAnyParsedSignature(node) || checkFunctionName(node.name) || checkForGenerator(node);
+ }
+ function checkFunctionName(name) {
+ if (name && name.parserContextFlags & 1 /* StrictMode */ && isEvalOrArgumentsIdentifier(name)) {
+ return reportInvalidUseInStrictMode(name);
+ }
+ }
+ function checkGetAccessor(node) {
+ return checkAnyParsedSignature(node) || checkAccessor(node);
+ }
+ function checkIndexedAccess(node) {
+ if (node.index.kind === 120 /* Missing */ && node.parent.kind === 148 /* NewExpression */ && node.parent.func === node) {
+ var start = ts.skipTrivia(sourceText, node.parent.pos);
+ var end = node.end;
+ return grammarErrorAtPos(start, end - start, ts.Diagnostics.new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead);
+ }
+ }
+ function checkIndexSignature(node) {
+ return checkIndexSignatureParameters(node) || checkForIndexSignatureModifiers(node);
+ }
+ function checkForIndexSignatureModifiers(node) {
+ if (node.flags & 243 /* Modifier */) {
+ return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_not_permitted_on_index_signature_members);
+ }
+ }
+ function checkIndexSignatureParameters(node) {
+ var parameter = node.parameters[0];
+ if (node.parameters.length !== 1) {
+ if (parameter) {
+ return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_must_have_exactly_one_parameter);
+ }
+ else {
+ return grammarErrorOnNode(node, ts.Diagnostics.An_index_signature_must_have_exactly_one_parameter);
+ }
+ }
+ else if (parameter.flags & 8 /* Rest */) {
+ return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_cannot_have_a_rest_parameter);
+ }
+ else if (parameter.flags & 243 /* Modifier */) {
+ return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_cannot_have_an_accessibility_modifier);
+ }
+ else if (parameter.flags & 4 /* QuestionMark */) {
+ return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_cannot_have_a_question_mark);
+ }
+ else if (parameter.initializer) {
+ return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_cannot_have_an_initializer);
+ }
+ else if (!parameter.type) {
+ return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_must_have_a_type_annotation);
+ }
+ else if (parameter.type.kind !== 118 /* StringKeyword */ && parameter.type.kind !== 116 /* NumberKeyword */) {
+ return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_type_must_be_string_or_number);
+ }
+ else if (!node.type) {
+ return grammarErrorOnNode(node, ts.Diagnostics.An_index_signature_must_have_a_type_annotation);
+ }
+ }
+ function checkInterfaceDeclaration(node) {
+ return checkForDisallowedTrailingComma(node.baseTypes) || checkForAtLeastOneHeritageClause(node.baseTypes, "extends");
+ }
+ function checkMethod(node) {
+ return checkAnyParsedSignature(node) || checkForBodyInAmbientContext(node.body, false) || (node.parent.kind === 188 /* ClassDeclaration */ && checkForInvalidQuestionMark(node, ts.Diagnostics.A_class_member_cannot_be_declared_optional)) || checkForGenerator(node);
+ }
+ function checkForBodyInAmbientContext(body, isConstructor) {
+ if (inAmbientContext && body && body.kind === 187 /* FunctionBlock */) {
+ var diagnostic = isConstructor ? ts.Diagnostics.A_constructor_implementation_cannot_be_declared_in_an_ambient_context : ts.Diagnostics.A_function_implementation_cannot_be_declared_in_an_ambient_context;
+ return grammarErrorOnFirstToken(body, diagnostic);
+ }
+ }
+ function checkModuleDeclaration(node) {
+ return checkModuleDeclarationName(node) || checkModuleDeclarationStatements(node);
+ }
+ function checkModuleDeclarationName(node) {
+ if (!inAmbientContext && node.name.kind === 7 /* StringLiteral */) {
+ return grammarErrorOnNode(node.name, ts.Diagnostics.Only_ambient_modules_can_use_quoted_names);
+ }
+ }
+ function checkModuleDeclarationStatements(node) {
+ if (node.name.kind === 63 /* Identifier */ && node.body.kind === 193 /* ModuleBlock */) {
+ var statements = node.body.statements;
+ for (var i = 0, n = statements.length; i < n; i++) {
+ var statement = statements[i];
+ if (statement.kind === 195 /* ExportAssignment */) {
+ return grammarErrorOnNode(statement, ts.Diagnostics.An_export_assignment_cannot_be_used_in_an_internal_module);
+ }
+ else if (statement.kind === 194 /* ImportDeclaration */ && statement.externalModuleName) {
+ return grammarErrorOnNode(statement.externalModuleName, ts.Diagnostics.Import_declarations_in_an_internal_module_cannot_reference_an_external_module);
+ }
+ }
+ }
+ }
+ function checkObjectLiteral(node) {
+ var seen = {};
+ var Property = 1;
+ var GetAccessor = 2;
+ var SetAccesor = 4;
+ var GetOrSetAccessor = GetAccessor | SetAccesor;
+ var inStrictMode = (node.parserContextFlags & 1 /* StrictMode */) !== 0;
+ for (var i = 0, n = node.properties.length; i < n; i++) {
+ var prop = node.properties[i];
+ if (prop.kind === 161 /* OmittedExpression */) {
+ continue;
+ }
+ var p = prop;
+ var name = p.name;
+ var currentKind;
+ if (p.kind === 143 /* PropertyAssignment */) {
+ currentKind = Property;
+ }
+ else if (p.kind === 144 /* ShorthandPropertyAssignment */) {
+ currentKind = Property;
+ }
+ else if (p.kind === 127 /* GetAccessor */) {
+ currentKind = GetAccessor;
+ }
+ else if (p.kind === 128 /* SetAccessor */) {
+ currentKind = SetAccesor;
+ }
+ else {
+ ts.Debug.fail("Unexpected syntax kind:" + p.kind);
+ }
+ if (!ts.hasProperty(seen, name.text)) {
+ seen[name.text] = currentKind;
+ }
+ else {
+ var existingKind = seen[name.text];
+ if (currentKind === Property && existingKind === Property) {
+ if (inStrictMode) {
+ grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode);
+ }
+ }
+ else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) {
+ if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) {
+ seen[name.text] = currentKind | existingKind;
+ }
+ else {
+ return grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name);
+ }
+ }
+ else {
+ return grammarErrorOnNode(name, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name);
+ }
+ }
+ }
+ }
+ function checkNumericLiteral(node) {
+ if (node.flags & 8192 /* OctalLiteral */) {
+ if (node.parserContextFlags & 1 /* StrictMode */) {
+ return grammarErrorOnNode(node, ts.Diagnostics.Octal_literals_are_not_allowed_in_strict_mode);
+ }
+ else if (languageVersion >= 1 /* ES5 */) {
+ return grammarErrorOnNode(node, ts.Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher);
+ }
+ }
+ }
+ function checkModifiers(node) {
+ switch (node.kind) {
+ case 127 /* GetAccessor */:
+ case 128 /* SetAccessor */:
+ case 126 /* Constructor */:
+ case 124 /* Property */:
+ case 125 /* Method */:
+ case 131 /* IndexSignature */:
+ case 188 /* ClassDeclaration */:
+ case 189 /* InterfaceDeclaration */:
+ case 192 /* ModuleDeclaration */:
+ case 191 /* EnumDeclaration */:
+ case 195 /* ExportAssignment */:
+ case 163 /* VariableStatement */:
+ case 186 /* FunctionDeclaration */:
+ case 190 /* TypeAliasDeclaration */:
+ case 194 /* ImportDeclaration */:
+ case 123 /* Parameter */:
+ break;
+ default:
+ return false;
+ }
+ if (!node.modifiers) {
+ return;
+ }
+ var lastStatic, lastPrivate, lastProtected, lastDeclare;
+ var flags = 0;
+ for (var i = 0, n = node.modifiers.length; i < n; i++) {
+ var modifier = node.modifiers[i];
+ switch (modifier.kind) {
+ case 106 /* PublicKeyword */:
+ case 105 /* ProtectedKeyword */:
+ case 104 /* PrivateKeyword */:
+ var text;
+ if (modifier.kind === 106 /* PublicKeyword */) {
+ text = "public";
+ }
+ else if (modifier.kind === 105 /* ProtectedKeyword */) {
+ text = "protected";
+ lastProtected = modifier;
+ }
+ else {
+ text = "private";
+ lastPrivate = modifier;
+ }
+ if (flags & 112 /* AccessibilityModifier */) {
+ return grammarErrorOnNode(modifier, ts.Diagnostics.Accessibility_modifier_already_seen);
+ }
+ else if (flags & 128 /* Static */) {
+ return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, text, "static");
+ }
+ else if (node.parent.kind === 193 /* ModuleBlock */ || node.parent.kind === 197 /* SourceFile */) {
+ return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_element, text);
+ }
+ flags |= modifierToFlag(modifier.kind);
+ break;
+ case 107 /* StaticKeyword */:
+ if (flags & 128 /* Static */) {
+ return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "static");
+ }
+ else if (node.parent.kind === 193 /* ModuleBlock */ || node.parent.kind === 197 /* SourceFile */) {
+ return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_element, "static");
+ }
+ else if (node.kind === 123 /* Parameter */) {
+ return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "static");
+ }
+ flags |= 128 /* Static */;
+ lastStatic = modifier;
+ break;
+ case 76 /* ExportKeyword */:
+ if (flags & 1 /* Export */) {
+ return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "export");
+ }
+ else if (flags & 2 /* Ambient */) {
+ return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, "export", "declare");
+ }
+ else if (node.parent.kind === 188 /* ClassDeclaration */) {
+ return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_class_element, "export");
+ }
+ else if (node.kind === 123 /* Parameter */) {
+ return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "export");
+ }
+ flags |= 1 /* Export */;
+ break;
+ case 112 /* DeclareKeyword */:
+ if (flags & 2 /* Ambient */) {
+ return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "declare");
+ }
+ else if (node.parent.kind === 188 /* ClassDeclaration */) {
+ return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_class_element, "declare");
+ }
+ else if (node.kind === 123 /* Parameter */) {
+ return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "declare");
+ }
+ else if (inAmbientContext && node.parent.kind === 193 /* ModuleBlock */) {
+ return grammarErrorOnNode(modifier, ts.Diagnostics.A_declare_modifier_cannot_be_used_in_an_already_ambient_context);
+ }
+ flags |= 2 /* Ambient */;
+ lastDeclare = modifier;
+ break;
+ }
+ }
+ if (node.kind === 126 /* Constructor */) {
+ if (flags & 128 /* Static */) {
+ return grammarErrorOnNode(lastStatic, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "static");
+ }
+ else if (flags & 64 /* Protected */) {
+ return grammarErrorOnNode(lastProtected, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "protected");
+ }
+ else if (flags & 32 /* Private */) {
+ return grammarErrorOnNode(lastPrivate, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "private");
+ }
+ }
+ else if (node.kind === 194 /* ImportDeclaration */ && flags & 2 /* Ambient */) {
+ return grammarErrorOnNode(lastDeclare, ts.Diagnostics.A_declare_modifier_cannot_be_used_with_an_import_declaration, "declare");
+ }
+ else if (node.kind === 189 /* InterfaceDeclaration */ && flags & 2 /* Ambient */) {
+ return grammarErrorOnNode(lastDeclare, ts.Diagnostics.A_declare_modifier_cannot_be_used_with_an_interface_declaration, "declare");
+ }
+ }
+ function checkParameter(node) {
+ if (node.parserContextFlags & 1 /* StrictMode */ && isEvalOrArgumentsIdentifier(node.name)) {
+ return reportInvalidUseInStrictMode(node.name);
+ }
+ }
+ function checkTypeParameterList(typeParameters) {
+ if (checkForDisallowedTrailingComma(typeParameters)) {
+ return true;
+ }
+ if (typeParameters && typeParameters.length === 0) {
+ var start = typeParameters.pos - "<".length;
+ var end = ts.skipTrivia(sourceText, typeParameters.end) + ">".length;
+ return grammarErrorAtPos(start, end - start, ts.Diagnostics.Type_parameter_list_cannot_be_empty);
+ }
+ }
+ function checkParameterList(parameters) {
+ if (checkForDisallowedTrailingComma(parameters)) {
+ return true;
+ }
+ var seenOptionalParameter = false;
+ var parameterCount = parameters.length;
+ for (var i = 0; i < parameterCount; i++) {
+ var parameter = parameters[i];
+ if (parameter.flags & 8 /* Rest */) {
+ if (i !== (parameterCount - 1)) {
+ return grammarErrorOnNode(parameter.name, ts.Diagnostics.A_rest_parameter_must_be_last_in_a_parameter_list);
+ }
+ if (parameter.flags & 4 /* QuestionMark */) {
+ return grammarErrorOnNode(parameter.name, ts.Diagnostics.A_rest_parameter_cannot_be_optional);
+ }
+ if (parameter.initializer) {
+ return grammarErrorOnNode(parameter.name, ts.Diagnostics.A_rest_parameter_cannot_have_an_initializer);
+ }
+ }
+ else if (parameter.flags & 4 /* QuestionMark */ || parameter.initializer) {
+ seenOptionalParameter = true;
+ if (parameter.flags & 4 /* QuestionMark */ && parameter.initializer) {
+ return grammarErrorOnNode(parameter.name, ts.Diagnostics.Parameter_cannot_have_question_mark_and_initializer);
+ }
+ }
+ else {
+ if (seenOptionalParameter) {
+ return grammarErrorOnNode(parameter.name, ts.Diagnostics.A_required_parameter_cannot_follow_an_optional_parameter);
+ }
+ }
+ }
+ }
+ function checkPostfixOperator(node) {
+ if (node.parserContextFlags & 1 /* StrictMode */ && isEvalOrArgumentsIdentifier(node.operand)) {
+ return reportInvalidUseInStrictMode(node.operand);
+ }
+ }
+ function checkPrefixOperator(node) {
+ if (node.parserContextFlags & 1 /* StrictMode */) {
+ if ((node.operator === 37 /* PlusPlusToken */ || node.operator === 38 /* MinusMinusToken */) && isEvalOrArgumentsIdentifier(node.operand)) {
+ return reportInvalidUseInStrictMode(node.operand);
+ }
+ else if (node.operator === 72 /* DeleteKeyword */ && node.operand.kind === 63 /* Identifier */) {
+ return grammarErrorOnNode(node.operand, ts.Diagnostics.delete_cannot_be_called_on_an_identifier_in_strict_mode);
+ }
+ }
+ }
+ function checkProperty(node) {
+ return (node.parent.kind === 188 /* ClassDeclaration */ && checkForInvalidQuestionMark(node, ts.Diagnostics.A_class_member_cannot_be_declared_optional)) || checkForInitializerInAmbientContext(node);
+ }
+ function checkForInitializerInAmbientContext(node) {
+ if (inAmbientContext && node.initializer) {
+ return grammarErrorOnFirstToken(node.initializer, ts.Diagnostics.Initializers_are_not_allowed_in_ambient_contexts);
+ }
+ }
+ function checkPropertyAssignment(node) {
+ return checkForInvalidQuestionMark(node, ts.Diagnostics.An_object_member_cannot_be_declared_optional);
+ }
+ function checkForInvalidQuestionMark(node, message) {
+ if (node.flags & 4 /* QuestionMark */) {
+ var pos = ts.skipTrivia(sourceText, node.name.end);
+ return grammarErrorAtPos(pos, "?".length, message);
+ }
+ }
+ function checkReturnStatement(node) {
+ if (!inFunctionBlock) {
+ return grammarErrorOnFirstToken(node, ts.Diagnostics.A_return_statement_can_only_be_used_within_a_function_body);
+ }
+ }
+ function checkSetAccessor(node) {
+ return checkAnyParsedSignature(node) || checkAccessor(node);
+ }
+ function checkAccessor(accessor) {
+ var kind = accessor.kind;
+ if (languageVersion < 1 /* ES5 */) {
+ return grammarErrorOnNode(accessor.name, ts.Diagnostics.Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher);
+ }
+ else if (inAmbientContext) {
+ return grammarErrorOnNode(accessor.name, ts.Diagnostics.An_accessor_cannot_be_declared_in_an_ambient_context);
+ }
+ else if (accessor.body === undefined) {
+ return grammarErrorAtPos(accessor.end - 1, ";".length, ts.Diagnostics._0_expected, "{");
+ }
+ else if (accessor.typeParameters) {
+ return grammarErrorOnNode(accessor.name, ts.Diagnostics.An_accessor_cannot_have_type_parameters);
+ }
+ else if (kind === 127 /* GetAccessor */ && accessor.parameters.length) {
+ return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_get_accessor_cannot_have_parameters);
+ }
+ else if (kind === 128 /* SetAccessor */) {
+ if (accessor.type) {
+ return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_cannot_have_a_return_type_annotation);
+ }
+ else if (accessor.parameters.length !== 1) {
+ return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_must_have_exactly_one_parameter);
+ }
+ else {
+ var parameter = accessor.parameters[0];
+ if (parameter.flags & 8 /* Rest */) {
+ return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_cannot_have_rest_parameter);
+ }
+ else if (parameter.flags & 243 /* Modifier */) {
+ return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation);
+ }
+ else if (parameter.flags & 4 /* QuestionMark */) {
+ return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_cannot_have_an_optional_parameter);
+ }
+ else if (parameter.initializer) {
+ return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_parameter_cannot_have_an_initializer);
+ }
+ }
+ }
+ }
+ function checkSourceFile(node) {
+ return inAmbientContext && checkTopLevelElementsForRequiredDeclareModifier(file);
+ }
+ function checkTopLevelElementsForRequiredDeclareModifier(file) {
+ for (var i = 0, n = file.statements.length; i < n; i++) {
+ var decl = file.statements[i];
+ if (isDeclaration(decl) || decl.kind === 163 /* VariableStatement */) {
+ if (checkTopLevelElementForRequiredDeclareModifier(decl)) {
+ return true;
+ }
+ }
+ }
+ }
+ function checkTopLevelElementForRequiredDeclareModifier(node) {
+ if (node.kind === 189 /* InterfaceDeclaration */ || node.kind === 194 /* ImportDeclaration */ || node.kind === 195 /* ExportAssignment */ || (node.flags & 2 /* Ambient */)) {
+ return false;
+ }
+ return grammarErrorOnFirstToken(node, ts.Diagnostics.A_declare_modifier_is_required_for_a_top_level_declaration_in_a_d_ts_file);
+ }
+ function checkShorthandPropertyAssignment(node) {
+ return checkForInvalidQuestionMark(node, ts.Diagnostics.An_object_member_cannot_be_declared_optional);
+ }
+ function checkSwitchStatement(node) {
+ var firstDefaultClause;
+ for (var i = 0, n = node.clauses.length; i < n; i++) {
+ var clause = node.clauses[i];
+ if (clause.kind === 177 /* DefaultClause */) {
+ if (firstDefaultClause === undefined) {
+ firstDefaultClause = clause;
+ }
+ else {
+ var start = ts.skipTrivia(file.text, clause.pos);
+ var end = clause.statements.length > 0 ? clause.statements[0].pos : clause.end;
+ return grammarErrorAtPos(start, end - start, ts.Diagnostics.A_default_clause_cannot_appear_more_than_once_in_a_switch_statement);
+ }
+ }
+ }
+ }
+ function checkTaggedTemplateExpression(node) {
+ if (languageVersion < 2 /* ES6 */) {
+ return grammarErrorOnFirstToken(node.template, ts.Diagnostics.Tagged_templates_are_only_available_when_targeting_ECMAScript_6_and_higher);
+ }
+ }
+ function checkTupleType(node) {
+ return checkForDisallowedTrailingComma(node.elementTypes) || checkForAtLeastOneType(node);
+ }
+ function checkForAtLeastOneType(node) {
+ if (node.elementTypes.length === 0) {
+ return grammarErrorOnNode(node, ts.Diagnostics.A_tuple_type_element_list_cannot_be_empty);
+ }
+ }
+ function checkTypeParameter(node) {
+ if (node.expression) {
+ return grammarErrorOnFirstToken(node.expression, ts.Diagnostics.Type_expected);
+ }
+ }
+ function checkTypeReference(node) {
+ return checkTypeArguments(node.typeArguments);
+ }
+ function checkVariableDeclaration(node) {
+ if (inAmbientContext && node.initializer) {
+ var equalsPos = node.type ? ts.skipTrivia(sourceText, node.type.end) : ts.skipTrivia(sourceText, node.name.end);
+ return grammarErrorAtPos(equalsPos, "=".length, ts.Diagnostics.Initializers_are_not_allowed_in_ambient_contexts);
+ }
+ if (!inAmbientContext && !node.initializer && isConst(node)) {
+ return grammarErrorOnNode(node, ts.Diagnostics.const_declarations_must_be_initialized);
+ }
+ if (node.parserContextFlags & 1 /* StrictMode */ && isEvalOrArgumentsIdentifier(node.name)) {
+ return reportInvalidUseInStrictMode(node.name);
+ }
+ }
+ function checkVariableDeclarations(declarations) {
+ if (declarations) {
+ if (checkForDisallowedTrailingComma(declarations)) {
+ return true;
+ }
+ if (!declarations.length) {
+ return grammarErrorAtPos(declarations.pos, declarations.end - declarations.pos, ts.Diagnostics.Variable_declaration_list_cannot_be_empty);
+ }
+ var decl = declarations[0];
+ if (languageVersion < 2 /* ES6 */) {
+ if (isLet(decl)) {
+ return grammarErrorOnFirstToken(decl, ts.Diagnostics.let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher);
+ }
+ else if (isConst(decl)) {
+ return grammarErrorOnFirstToken(decl, ts.Diagnostics.const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher);
+ }
+ }
+ }
+ }
+ function checkVariableStatement(node) {
+ return checkVariableDeclarations(node.declarations) || checkForDisallowedLetOrConstStatement(node);
+ }
+ function checkForDisallowedLetOrConstStatement(node) {
+ if (!allowLetAndConstDeclarations(node.parent)) {
+ if (isLet(node)) {
+ return grammarErrorOnNode(node, ts.Diagnostics.let_declarations_can_only_be_declared_inside_a_block);
+ }
+ else if (isConst(node)) {
+ return grammarErrorOnNode(node, ts.Diagnostics.const_declarations_can_only_be_declared_inside_a_block);
+ }
+ }
+ }
+ function allowLetAndConstDeclarations(parent) {
+ switch (parent.kind) {
+ case 166 /* IfStatement */:
+ case 167 /* DoStatement */:
+ case 168 /* WhileStatement */:
+ case 174 /* WithStatement */:
+ case 169 /* ForStatement */:
+ case 170 /* ForInStatement */:
+ return false;
+ case 178 /* LabeledStatement */:
+ return allowLetAndConstDeclarations(parent.parent);
+ }
+ return true;
+ }
+ function checkWithStatement(node) {
+ if (node.parserContextFlags & 1 /* StrictMode */) {
+ return grammarErrorOnFirstToken(node, ts.Diagnostics.with_statements_are_not_allowed_in_strict_mode);
+ }
+ }
+ function checkYieldExpression(node) {
+ if (!(node.parserContextFlags & 4 /* Yield */)) {
+ return grammarErrorOnFirstToken(node, ts.Diagnostics.yield_expression_must_be_contained_within_a_generator_declaration);
+ }
+ return grammarErrorOnFirstToken(node, ts.Diagnostics.yield_expressions_are_not_currently_supported);
+ }
+ }
function createProgram(rootNames, options, host) {
var program;
var files = [];
@@ -5495,17 +5853,20 @@ var ts;
function findSourceFile(filename, isDefaultLib, refFile, refStart, refLength) {
var canonicalName = host.getCanonicalFileName(filename);
if (ts.hasProperty(filesByName, canonicalName)) {
- var file = filesByName[canonicalName];
- if (file && host.useCaseSensitiveFileNames() && canonicalName !== file.filename) {
- errors.push(ts.createFileDiagnostic(refFile, refStart, refLength, ts.Diagnostics.Filename_0_differs_from_already_included_filename_1_only_in_casing, filename, file.filename));
- }
+ return getSourceFileFromCache(filename, canonicalName, false);
}
else {
+ var normalizedAbsolutePath = ts.getNormalizedAbsolutePath(filename, host.getCurrentDirectory());
+ var canonicalAbsolutePath = host.getCanonicalFileName(normalizedAbsolutePath);
+ if (ts.hasProperty(filesByName, canonicalAbsolutePath)) {
+ return getSourceFileFromCache(normalizedAbsolutePath, canonicalAbsolutePath, true);
+ }
var file = filesByName[canonicalName] = host.getSourceFile(filename, options.target, function (hostErrorMessage) {
errors.push(ts.createFileDiagnostic(refFile, refStart, refLength, ts.Diagnostics.Cannot_read_file_0_Colon_1, filename, hostErrorMessage));
});
if (file) {
seenNoDefaultLib = seenNoDefaultLib || file.hasNoDefaultLib;
+ filesByName[canonicalAbsolutePath] = file;
if (!options.noResolve) {
var basePath = ts.getDirectoryPath(filename);
processReferencedFiles(file, basePath);
@@ -5517,12 +5878,22 @@ var ts;
else {
files.push(file);
}
- ts.forEach(file.syntacticErrors, function (e) {
+ ts.forEach(file.getSyntacticDiagnostics(), function (e) {
errors.push(e);
});
}
}
return file;
+ function getSourceFileFromCache(filename, canonicalName, useAbsolutePath) {
+ var file = filesByName[canonicalName];
+ if (file && host.useCaseSensitiveFileNames()) {
+ var sourceFileName = useAbsolutePath ? ts.getNormalizedAbsolutePath(file.filename, host.getCurrentDirectory()) : file.filename;
+ if (canonicalName !== sourceFileName) {
+ errors.push(ts.createFileDiagnostic(refFile, refStart, refLength, ts.Diagnostics.Filename_0_differs_from_already_included_filename_1_only_in_casing, filename, sourceFileName));
+ }
+ }
+ return file;
+ }
}
function processReferencedFiles(file, basePath) {
ts.forEach(file.referencedFiles, function (ref) {
@@ -5532,7 +5903,7 @@ var ts;
}
function processImportedModules(file, basePath) {
ts.forEach(file.statements, function (node) {
- if (node.kind === 193 /* ImportDeclaration */ && node.externalModuleName) {
+ if (node.kind === 194 /* ImportDeclaration */ && node.externalModuleName) {
var nameLiteral = node.externalModuleName;
var moduleName = nameLiteral.text;
if (moduleName) {
@@ -5550,9 +5921,9 @@ var ts;
}
}
}
- else if (node.kind === 191 /* ModuleDeclaration */ && node.name.kind === 7 /* StringLiteral */ && (node.flags & 2 /* Ambient */ || isDeclarationFile(file))) {
+ else if (node.kind === 192 /* ModuleDeclaration */ && node.name.kind === 7 /* StringLiteral */ && (node.flags & 2 /* Ambient */ || isDeclarationFile(file))) {
forEachChild(node.body, function (node) {
- if (node.kind === 193 /* ImportDeclaration */ && node.externalModuleName) {
+ if (node.kind === 194 /* ImportDeclaration */ && node.externalModuleName) {
var nameLiteral = node.externalModuleName;
var moduleName = nameLiteral.text;
if (moduleName) {
@@ -5625,16 +5996,16 @@ var ts;
var ts;
(function (ts) {
function getModuleInstanceState(node) {
- if (node.kind === 188 /* InterfaceDeclaration */) {
+ if (node.kind === 189 /* InterfaceDeclaration */) {
return 0 /* NonInstantiated */;
}
- else if (node.kind === 190 /* EnumDeclaration */ && ts.isConstEnumDeclaration(node)) {
+ else if (ts.isConstEnumDeclaration(node)) {
return 2 /* ConstEnumOnly */;
}
- else if (node.kind === 193 /* ImportDeclaration */ && !(node.flags & 1 /* Export */)) {
+ else if (node.kind === 194 /* ImportDeclaration */ && !(node.flags & 1 /* Export */)) {
return 0 /* NonInstantiated */;
}
- else if (node.kind === 192 /* ModuleBlock */) {
+ else if (node.kind === 193 /* ModuleBlock */) {
var state = 0 /* NonInstantiated */;
ts.forEachChild(node, function (n) {
switch (getModuleInstanceState(n)) {
@@ -5650,7 +6021,7 @@ var ts;
});
return state;
}
- else if (node.kind === 191 /* ModuleDeclaration */) {
+ else if (node.kind === 192 /* ModuleDeclaration */) {
return getModuleInstanceState(node.body);
}
else {
@@ -5690,7 +6061,7 @@ var ts;
}
function getDeclarationName(node) {
if (node.name) {
- if (node.kind === 191 /* ModuleDeclaration */ && node.name.kind === 7 /* StringLiteral */) {
+ if (node.kind === 192 /* ModuleDeclaration */ && node.name.kind === 7 /* StringLiteral */) {
return '"' + node.name.text + '"';
}
return node.name.text;
@@ -5721,9 +6092,9 @@ var ts;
}
var message = symbol.flags & 2 /* BlockScopedVariable */ ? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0 : ts.Diagnostics.Duplicate_identifier_0;
ts.forEach(symbol.declarations, function (declaration) {
- file.semanticErrors.push(ts.createDiagnosticForNode(declaration.name, message, getDisplayName(declaration)));
+ file.semanticDiagnostics.push(ts.createDiagnosticForNode(declaration.name, message, getDisplayName(declaration)));
});
- file.semanticErrors.push(ts.createDiagnosticForNode(node.name, message, getDisplayName(node)));
+ file.semanticDiagnostics.push(ts.createDiagnosticForNode(node.name, message, getDisplayName(node)));
symbol = createSymbol(0, name);
}
}
@@ -5732,13 +6103,13 @@ var ts;
}
addDeclarationToSymbol(symbol, node, includes);
symbol.parent = parent;
- if (node.kind === 187 /* ClassDeclaration */ && symbol.exports) {
+ if (node.kind === 188 /* ClassDeclaration */ && symbol.exports) {
var prototypeSymbol = createSymbol(4 /* Property */ | 536870912 /* Prototype */, "prototype");
if (ts.hasProperty(symbol.exports, prototypeSymbol.name)) {
if (node.name) {
node.name.parent = node;
}
- file.semanticErrors.push(ts.createDiagnosticForNode(symbol.exports[prototypeSymbol.name].declarations[0], ts.Diagnostics.Duplicate_identifier_0, prototypeSymbol.name));
+ file.semanticDiagnostics.push(ts.createDiagnosticForNode(symbol.exports[prototypeSymbol.name].declarations[0], ts.Diagnostics.Duplicate_identifier_0, prototypeSymbol.name));
}
symbol.exports[prototypeSymbol.name] = prototypeSymbol;
prototypeSymbol.parent = symbol;
@@ -5764,7 +6135,7 @@ var ts;
if (symbolKind & 1536 /* Namespace */) {
exportKind |= 16777216 /* ExportNamespace */;
}
- if (node.flags & 1 /* Export */ || (node.kind !== 193 /* ImportDeclaration */ && isAmbientContext(container))) {
+ if (node.flags & 1 /* Export */ || (node.kind !== 194 /* ImportDeclaration */ && isAmbientContext(container))) {
if (exportKind) {
var local = declareSymbol(container.locals, undefined, node, exportKind, symbolExcludes);
local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes);
@@ -5805,10 +6176,10 @@ var ts;
}
function bindDeclaration(node, symbolKind, symbolExcludes, isBlockScopeContainer) {
switch (container.kind) {
- case 191 /* ModuleDeclaration */:
+ case 192 /* ModuleDeclaration */:
declareModuleMember(node, symbolKind, symbolExcludes);
break;
- case 196 /* SourceFile */:
+ case 197 /* SourceFile */:
if (ts.isExternalModule(container)) {
declareModuleMember(node, symbolKind, symbolExcludes);
break;
@@ -5822,22 +6193,22 @@ var ts;
case 126 /* Constructor */:
case 127 /* GetAccessor */:
case 128 /* SetAccessor */:
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
case 152 /* FunctionExpression */:
case 153 /* ArrowFunction */:
declareSymbol(container.locals, undefined, node, symbolKind, symbolExcludes);
break;
- case 187 /* ClassDeclaration */:
+ case 188 /* ClassDeclaration */:
if (node.flags & 128 /* Static */) {
declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes);
break;
}
case 136 /* TypeLiteral */:
case 142 /* ObjectLiteral */:
- case 188 /* InterfaceDeclaration */:
+ case 189 /* InterfaceDeclaration */:
declareSymbol(container.symbol.members, container.symbol, node, symbolKind, symbolExcludes);
break;
- case 190 /* EnumDeclaration */:
+ case 191 /* EnumDeclaration */:
declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes);
break;
}
@@ -5898,10 +6269,10 @@ var ts;
}
function bindBlockScopedVariableDeclaration(node) {
switch (blockScopeContainer.kind) {
- case 191 /* ModuleDeclaration */:
+ case 192 /* ModuleDeclaration */:
declareModuleMember(node, 2 /* BlockScopedVariable */, 107455 /* BlockScopedVariableExcludes */);
break;
- case 196 /* SourceFile */:
+ case 197 /* SourceFile */:
if (ts.isExternalModule(container)) {
declareModuleMember(node, 2 /* BlockScopedVariable */, 107455 /* BlockScopedVariableExcludes */);
break;
@@ -5923,7 +6294,7 @@ var ts;
case 123 /* Parameter */:
bindDeclaration(node, 1 /* FunctionScopedVariable */, 107455 /* ParameterExcludes */, false);
break;
- case 184 /* VariableDeclaration */:
+ case 185 /* VariableDeclaration */:
if (node.flags & 6144 /* BlockScoped */) {
bindBlockScopedVariableDeclaration(node);
}
@@ -5936,7 +6307,7 @@ var ts;
case 144 /* ShorthandPropertyAssignment */:
bindDeclaration(node, 4 /* Property */, 107455 /* PropertyExcludes */, false);
break;
- case 195 /* EnumMember */:
+ case 196 /* EnumMember */:
bindDeclaration(node, 8 /* EnumMember */, 107455 /* EnumMemberExcludes */, false);
break;
case 129 /* CallSignature */:
@@ -5951,7 +6322,7 @@ var ts;
case 131 /* IndexSignature */:
bindDeclaration(node, 524288 /* IndexSignature */, 0, false);
break;
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
bindDeclaration(node, 16 /* Function */, 106927 /* FunctionExcludes */, true);
break;
case 126 /* Constructor */:
@@ -5977,44 +6348,44 @@ var ts;
case 153 /* ArrowFunction */:
bindAnonymousDeclaration(node, 16 /* Function */, "__function", true);
break;
- case 181 /* CatchBlock */:
+ case 182 /* CatchBlock */:
bindCatchVariableDeclaration(node);
break;
- case 187 /* ClassDeclaration */:
+ case 188 /* ClassDeclaration */:
bindDeclaration(node, 32 /* Class */, 3258879 /* ClassExcludes */, false);
break;
- case 188 /* InterfaceDeclaration */:
+ case 189 /* InterfaceDeclaration */:
bindDeclaration(node, 64 /* Interface */, 3152288 /* InterfaceExcludes */, false);
break;
- case 189 /* TypeAliasDeclaration */:
+ case 190 /* TypeAliasDeclaration */:
bindDeclaration(node, 2097152 /* TypeAlias */, 3152352 /* TypeAliasExcludes */, false);
break;
- case 190 /* EnumDeclaration */:
- if (ts.isConstEnumDeclaration(node)) {
+ case 191 /* EnumDeclaration */:
+ if (ts.isConst(node)) {
bindDeclaration(node, 128 /* ConstEnum */, 3259263 /* ConstEnumExcludes */, false);
}
else {
bindDeclaration(node, 256 /* RegularEnum */, 3258623 /* RegularEnumExcludes */, false);
}
break;
- case 191 /* ModuleDeclaration */:
+ case 192 /* ModuleDeclaration */:
bindModuleDeclaration(node);
break;
- case 193 /* ImportDeclaration */:
+ case 194 /* ImportDeclaration */:
bindDeclaration(node, 33554432 /* Import */, 33554432 /* ImportExcludes */, false);
break;
- case 196 /* SourceFile */:
+ case 197 /* SourceFile */:
if (ts.isExternalModule(node)) {
bindAnonymousDeclaration(node, 512 /* ValueModule */, '"' + ts.removeFileExtension(node.filename) + '"', true);
break;
}
- case 161 /* Block */:
- case 180 /* TryBlock */:
- case 181 /* CatchBlock */:
- case 182 /* FinallyBlock */:
- case 168 /* ForStatement */:
- case 169 /* ForInStatement */:
- case 174 /* SwitchStatement */:
+ case 162 /* Block */:
+ case 181 /* TryBlock */:
+ case 182 /* CatchBlock */:
+ case 183 /* FinallyBlock */:
+ case 169 /* ForStatement */:
+ case 170 /* ForInStatement */:
+ case 175 /* SwitchStatement */:
bindChildren(node, 0, true);
break;
default:
@@ -6054,6 +6425,1057 @@ var ts;
return ts.isExternalModule(sourceFile) || ts.isDeclarationFile(sourceFile);
}
ts.isExternalModuleOrDeclarationFile = isExternalModuleOrDeclarationFile;
+ function createTextWriter(newLine) {
+ var output = "";
+ var indent = 0;
+ var lineStart = true;
+ var lineCount = 0;
+ var linePos = 0;
+ function write(s) {
+ if (s && s.length) {
+ if (lineStart) {
+ output += getIndentString(indent);
+ lineStart = false;
+ }
+ output += s;
+ }
+ }
+ function rawWrite(s) {
+ if (s !== undefined) {
+ if (lineStart) {
+ lineStart = false;
+ }
+ output += s;
+ }
+ }
+ function writeLiteral(s) {
+ if (s && s.length) {
+ write(s);
+ var lineStartsOfS = ts.computeLineStarts(s);
+ if (lineStartsOfS.length > 1) {
+ lineCount = lineCount + lineStartsOfS.length - 1;
+ linePos = output.length - s.length + lineStartsOfS[lineStartsOfS.length - 1];
+ }
+ }
+ }
+ function writeLine() {
+ if (!lineStart) {
+ output += newLine;
+ lineCount++;
+ linePos = output.length;
+ lineStart = true;
+ }
+ }
+ function writeTextOfNode(sourceFile, node) {
+ write(ts.getSourceTextOfNodeFromSourceFile(sourceFile, node));
+ }
+ return {
+ write: write,
+ rawWrite: rawWrite,
+ writeTextOfNode: writeTextOfNode,
+ writeLiteral: writeLiteral,
+ writeLine: writeLine,
+ increaseIndent: function () { return indent++; },
+ decreaseIndent: function () { return indent--; },
+ getIndent: function () { return indent; },
+ getTextPos: function () { return output.length; },
+ getLine: function () { return lineCount + 1; },
+ getColumn: function () { return lineStart ? indent * getIndentSize() + 1 : output.length - linePos + 1; },
+ getText: function () { return output; }
+ };
+ }
+ function getLineOfLocalPosition(currentSourceFile, pos) {
+ return currentSourceFile.getLineAndCharacterFromPosition(pos).line;
+ }
+ function emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments) {
+ if (leadingComments && leadingComments.length && node.pos !== leadingComments[0].pos && getLineOfLocalPosition(currentSourceFile, node.pos) !== getLineOfLocalPosition(currentSourceFile, leadingComments[0].pos)) {
+ writer.writeLine();
+ }
+ }
+ function emitComments(currentSourceFile, writer, comments, trailingSeparator, newLine, writeComment) {
+ var emitLeadingSpace = !trailingSeparator;
+ ts.forEach(comments, function (comment) {
+ if (emitLeadingSpace) {
+ writer.write(" ");
+ emitLeadingSpace = false;
+ }
+ writeComment(currentSourceFile, writer, comment, newLine);
+ if (comment.hasTrailingNewLine) {
+ writer.writeLine();
+ }
+ else if (trailingSeparator) {
+ writer.write(" ");
+ }
+ else {
+ emitLeadingSpace = true;
+ }
+ });
+ }
+ function writeCommentRange(currentSourceFile, writer, comment, newLine) {
+ if (currentSourceFile.text.charCodeAt(comment.pos + 1) === 42 /* asterisk */) {
+ var firstCommentLineAndCharacter = currentSourceFile.getLineAndCharacterFromPosition(comment.pos);
+ var firstCommentLineIndent;
+ for (var pos = comment.pos, currentLine = firstCommentLineAndCharacter.line; pos < comment.end; currentLine++) {
+ var nextLineStart = currentSourceFile.getPositionFromLineAndCharacter(currentLine + 1, 1);
+ if (pos !== comment.pos) {
+ if (firstCommentLineIndent === undefined) {
+ firstCommentLineIndent = calculateIndent(currentSourceFile.getPositionFromLineAndCharacter(firstCommentLineAndCharacter.line, 1), comment.pos);
+ }
+ var currentWriterIndentSpacing = writer.getIndent() * getIndentSize();
+ var spacesToEmit = currentWriterIndentSpacing - firstCommentLineIndent + calculateIndent(pos, nextLineStart);
+ if (spacesToEmit > 0) {
+ var numberOfSingleSpacesToEmit = spacesToEmit % getIndentSize();
+ var indentSizeSpaceString = getIndentString((spacesToEmit - numberOfSingleSpacesToEmit) / getIndentSize());
+ writer.rawWrite(indentSizeSpaceString);
+ while (numberOfSingleSpacesToEmit) {
+ writer.rawWrite(" ");
+ numberOfSingleSpacesToEmit--;
+ }
+ }
+ else {
+ writer.rawWrite("");
+ }
+ }
+ writeTrimmedCurrentLine(pos, nextLineStart);
+ pos = nextLineStart;
+ }
+ }
+ else {
+ writer.write(currentSourceFile.text.substring(comment.pos, comment.end));
+ }
+ function writeTrimmedCurrentLine(pos, nextLineStart) {
+ var end = Math.min(comment.end, nextLineStart - 1);
+ var currentLineText = currentSourceFile.text.substring(pos, end).replace(/^\s+|\s+$/g, '');
+ if (currentLineText) {
+ writer.write(currentLineText);
+ if (end !== comment.end) {
+ writer.writeLine();
+ }
+ }
+ else {
+ writer.writeLiteral(newLine);
+ }
+ }
+ function calculateIndent(pos, end) {
+ var currentLineIndent = 0;
+ for (; pos < end && ts.isWhiteSpace(currentSourceFile.text.charCodeAt(pos)); pos++) {
+ if (currentSourceFile.text.charCodeAt(pos) === 9 /* tab */) {
+ currentLineIndent += getIndentSize() - (currentLineIndent % getIndentSize());
+ }
+ else {
+ currentLineIndent++;
+ }
+ }
+ return currentLineIndent;
+ }
+ }
+ function getFirstConstructorWithBody(node) {
+ return ts.forEach(node.members, function (member) {
+ if (member.kind === 126 /* Constructor */ && member.body) {
+ return member;
+ }
+ });
+ }
+ function getAllAccessorDeclarations(node, accessor) {
+ var firstAccessor;
+ var getAccessor;
+ var setAccessor;
+ ts.forEach(node.members, function (member) {
+ if ((member.kind === 127 /* GetAccessor */ || member.kind === 128 /* SetAccessor */) && member.name.text === accessor.name.text && (member.flags & 128 /* Static */) === (accessor.flags & 128 /* Static */)) {
+ if (!firstAccessor) {
+ firstAccessor = member;
+ }
+ if (member.kind === 127 /* GetAccessor */ && !getAccessor) {
+ getAccessor = member;
+ }
+ if (member.kind === 128 /* SetAccessor */ && !setAccessor) {
+ setAccessor = member;
+ }
+ }
+ });
+ return {
+ firstAccessor: firstAccessor,
+ getAccessor: getAccessor,
+ setAccessor: setAccessor
+ };
+ }
+ function getSourceFilePathInNewDir(sourceFile, program, newDirPath) {
+ var compilerHost = program.getCompilerHost();
+ var sourceFilePath = ts.getNormalizedAbsolutePath(sourceFile.filename, compilerHost.getCurrentDirectory());
+ sourceFilePath = sourceFilePath.replace(program.getCommonSourceDirectory(), "");
+ return ts.combinePaths(newDirPath, sourceFilePath);
+ }
+ function getOwnEmitOutputFilePath(sourceFile, program, extension) {
+ var compilerOptions = program.getCompilerOptions();
+ if (compilerOptions.outDir) {
+ var emitOutputFilePathWithoutExtension = ts.removeFileExtension(getSourceFilePathInNewDir(sourceFile, program, compilerOptions.outDir));
+ }
+ else {
+ var emitOutputFilePathWithoutExtension = ts.removeFileExtension(sourceFile.filename);
+ }
+ return emitOutputFilePathWithoutExtension + extension;
+ }
+ function writeFile(compilerHost, diagnostics, filename, data, writeByteOrderMark) {
+ compilerHost.writeFile(filename, data, writeByteOrderMark, function (hostErrorMessage) {
+ diagnostics.push(ts.createCompilerDiagnostic(ts.Diagnostics.Could_not_write_file_0_Colon_1, filename, hostErrorMessage));
+ });
+ }
+ function emitDeclarations(program, resolver, diagnostics, jsFilePath, root) {
+ var newLine = program.getCompilerHost().getNewLine();
+ var compilerOptions = program.getCompilerOptions();
+ var compilerHost = program.getCompilerHost();
+ var write;
+ var writeLine;
+ var increaseIndent;
+ var decreaseIndent;
+ var writeTextOfNode;
+ var writer = createAndSetNewTextWriterWithSymbolWriter();
+ var enclosingDeclaration;
+ var currentSourceFile;
+ var reportedDeclarationError = false;
+ var emitJsDocComments = compilerOptions.removeComments ? function (declaration) {
+ } : writeJsDocComments;
+ var aliasDeclarationEmitInfo = [];
+ function createAndSetNewTextWriterWithSymbolWriter() {
+ var writer = createTextWriter(newLine);
+ writer.trackSymbol = trackSymbol;
+ writer.writeKeyword = writer.write;
+ writer.writeOperator = writer.write;
+ writer.writePunctuation = writer.write;
+ writer.writeSpace = writer.write;
+ writer.writeStringLiteral = writer.writeLiteral;
+ writer.writeParameter = writer.write;
+ writer.writeSymbol = writer.write;
+ setWriter(writer);
+ return writer;
+ }
+ function setWriter(newWriter) {
+ writer = newWriter;
+ write = newWriter.write;
+ writeTextOfNode = newWriter.writeTextOfNode;
+ writeLine = newWriter.writeLine;
+ increaseIndent = newWriter.increaseIndent;
+ decreaseIndent = newWriter.decreaseIndent;
+ }
+ function writeAsychronousImportDeclarations(importDeclarations) {
+ var oldWriter = writer;
+ ts.forEach(importDeclarations, function (aliasToWrite) {
+ var aliasEmitInfo = ts.forEach(aliasDeclarationEmitInfo, function (declEmitInfo) { return declEmitInfo.declaration === aliasToWrite ? declEmitInfo : undefined; });
+ if (aliasEmitInfo) {
+ createAndSetNewTextWriterWithSymbolWriter();
+ for (var declarationIndent = aliasEmitInfo.indent; declarationIndent; declarationIndent--) {
+ increaseIndent();
+ }
+ writeImportDeclaration(aliasToWrite);
+ aliasEmitInfo.asynchronousOutput = writer.getText();
+ }
+ });
+ setWriter(oldWriter);
+ }
+ function handleSymbolAccessibilityError(symbolAccesibilityResult) {
+ if (symbolAccesibilityResult.accessibility === 0 /* Accessible */) {
+ if (symbolAccesibilityResult && symbolAccesibilityResult.aliasesToMakeVisible) {
+ writeAsychronousImportDeclarations(symbolAccesibilityResult.aliasesToMakeVisible);
+ }
+ }
+ else {
+ reportedDeclarationError = true;
+ var errorInfo = writer.getSymbolAccessibilityDiagnostic(symbolAccesibilityResult);
+ if (errorInfo) {
+ if (errorInfo.typeName) {
+ diagnostics.push(ts.createDiagnosticForNode(symbolAccesibilityResult.errorNode || errorInfo.errorNode, errorInfo.diagnosticMessage, ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, errorInfo.typeName), symbolAccesibilityResult.errorSymbolName, symbolAccesibilityResult.errorModuleName));
+ }
+ else {
+ diagnostics.push(ts.createDiagnosticForNode(symbolAccesibilityResult.errorNode || errorInfo.errorNode, errorInfo.diagnosticMessage, symbolAccesibilityResult.errorSymbolName, symbolAccesibilityResult.errorModuleName));
+ }
+ }
+ }
+ }
+ function trackSymbol(symbol, enclosingDeclaration, meaning) {
+ handleSymbolAccessibilityError(resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning));
+ }
+ function writeTypeAtLocation(location, type, getSymbolAccessibilityDiagnostic) {
+ writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic;
+ write(": ");
+ if (type) {
+ emitType(type);
+ }
+ else {
+ resolver.writeTypeAtLocation(location, enclosingDeclaration, 2 /* UseTypeOfFunction */, writer);
+ }
+ }
+ function writeReturnTypeAtSignature(signature, getSymbolAccessibilityDiagnostic) {
+ writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic;
+ write(": ");
+ if (signature.type) {
+ emitType(signature.type);
+ }
+ else {
+ resolver.writeReturnTypeOfSignatureDeclaration(signature, enclosingDeclaration, 2 /* UseTypeOfFunction */, writer);
+ }
+ }
+ function emitLines(nodes) {
+ for (var i = 0, n = nodes.length; i < n; i++) {
+ emitNode(nodes[i]);
+ }
+ }
+ function emitSeparatedList(nodes, separator, eachNodeEmitFn) {
+ var currentWriterPos = writer.getTextPos();
+ for (var i = 0, n = nodes.length; i < n; i++) {
+ if (currentWriterPos !== writer.getTextPos()) {
+ write(separator);
+ }
+ currentWriterPos = writer.getTextPos();
+ eachNodeEmitFn(nodes[i]);
+ }
+ }
+ function emitCommaList(nodes, eachNodeEmitFn) {
+ emitSeparatedList(nodes, ", ", eachNodeEmitFn);
+ }
+ function writeJsDocComments(declaration) {
+ if (declaration) {
+ var jsDocComments = ts.getJsDocComments(declaration, currentSourceFile);
+ emitNewLineBeforeLeadingComments(currentSourceFile, writer, declaration, jsDocComments);
+ emitComments(currentSourceFile, writer, jsDocComments, true, newLine, writeCommentRange);
+ }
+ }
+ function emitTypeWithNewGetSymbolAccessibilityDiangostic(type, getSymbolAccessibilityDiagnostic) {
+ writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic;
+ emitType(type);
+ }
+ function emitType(type) {
+ switch (type.kind) {
+ case 109 /* AnyKeyword */:
+ case 118 /* StringKeyword */:
+ case 116 /* NumberKeyword */:
+ case 110 /* BooleanKeyword */:
+ case 97 /* VoidKeyword */:
+ case 7 /* StringLiteral */:
+ return writeTextOfNode(currentSourceFile, type);
+ case 132 /* TypeReference */:
+ return emitTypeReference(type);
+ case 135 /* TypeQuery */:
+ return emitTypeQuery(type);
+ case 137 /* ArrayType */:
+ return emitArrayType(type);
+ case 138 /* TupleType */:
+ return emitTupleType(type);
+ case 139 /* UnionType */:
+ return emitUnionType(type);
+ case 140 /* ParenType */:
+ return emitParenType(type);
+ case 133 /* FunctionType */:
+ case 134 /* ConstructorType */:
+ return emitSignatureDeclarationWithJsDocComments(type);
+ case 136 /* TypeLiteral */:
+ return emitTypeLiteral(type);
+ case 63 /* Identifier */:
+ return emitEntityName(type);
+ case 121 /* QualifiedName */:
+ return emitEntityName(type);
+ default:
+ ts.Debug.fail("Unknown type annotation: " + type.kind);
+ }
+ function emitEntityName(entityName) {
+ var visibilityResult = resolver.isEntityNameVisible(entityName, entityName.parent.kind === 194 /* ImportDeclaration */ ? entityName.parent : enclosingDeclaration);
+ handleSymbolAccessibilityError(visibilityResult);
+ writeEntityName(entityName);
+ function writeEntityName(entityName) {
+ if (entityName.kind === 63 /* Identifier */) {
+ writeTextOfNode(currentSourceFile, entityName);
+ }
+ else {
+ var qualifiedName = entityName;
+ writeEntityName(qualifiedName.left);
+ write(".");
+ writeTextOfNode(currentSourceFile, qualifiedName.right);
+ }
+ }
+ }
+ function emitTypeReference(type) {
+ emitEntityName(type.typeName);
+ if (type.typeArguments) {
+ write("<");
+ emitCommaList(type.typeArguments, emitType);
+ write(">");
+ }
+ }
+ function emitTypeQuery(type) {
+ write("typeof ");
+ emitEntityName(type.exprName);
+ }
+ function emitArrayType(type) {
+ emitType(type.elementType);
+ write("[]");
+ }
+ function emitTupleType(type) {
+ write("[");
+ emitCommaList(type.elementTypes, emitType);
+ write("]");
+ }
+ function emitUnionType(type) {
+ emitSeparatedList(type.types, " | ", emitType);
+ }
+ function emitParenType(type) {
+ write("(");
+ emitType(type.type);
+ write(")");
+ }
+ function emitTypeLiteral(type) {
+ write("{");
+ if (type.members.length) {
+ writeLine();
+ increaseIndent();
+ emitLines(type.members);
+ decreaseIndent();
+ }
+ write("}");
+ }
+ }
+ function emitSourceFile(node) {
+ currentSourceFile = node;
+ enclosingDeclaration = node;
+ emitLines(node.statements);
+ }
+ function emitExportAssignment(node) {
+ write("export = ");
+ writeTextOfNode(currentSourceFile, node.exportName);
+ write(";");
+ writeLine();
+ }
+ function emitModuleElementDeclarationFlags(node) {
+ if (node.parent === currentSourceFile) {
+ if (node.flags & 1 /* Export */) {
+ write("export ");
+ }
+ if (node.kind !== 189 /* InterfaceDeclaration */) {
+ write("declare ");
+ }
+ }
+ }
+ function emitClassMemberDeclarationFlags(node) {
+ if (node.flags & 32 /* Private */) {
+ write("private ");
+ }
+ else if (node.flags & 64 /* Protected */) {
+ write("protected ");
+ }
+ if (node.flags & 128 /* Static */) {
+ write("static ");
+ }
+ }
+ function emitImportDeclaration(node) {
+ var nodeEmitInfo = {
+ declaration: node,
+ outputPos: writer.getTextPos(),
+ indent: writer.getIndent(),
+ hasWritten: resolver.isDeclarationVisible(node)
+ };
+ aliasDeclarationEmitInfo.push(nodeEmitInfo);
+ if (nodeEmitInfo.hasWritten) {
+ writeImportDeclaration(node);
+ }
+ }
+ function writeImportDeclaration(node) {
+ emitJsDocComments(node);
+ if (node.flags & 1 /* Export */) {
+ write("export ");
+ }
+ write("import ");
+ writeTextOfNode(currentSourceFile, node.name);
+ write(" = ");
+ if (node.entityName) {
+ emitTypeWithNewGetSymbolAccessibilityDiangostic(node.entityName, getImportEntityNameVisibilityError);
+ write(";");
+ }
+ else {
+ write("require(");
+ writeTextOfNode(currentSourceFile, node.externalModuleName);
+ write(");");
+ }
+ writer.writeLine();
+ function getImportEntityNameVisibilityError(symbolAccesibilityResult) {
+ return {
+ diagnosticMessage: ts.Diagnostics.Import_declaration_0_is_using_private_name_1,
+ errorNode: node,
+ typeName: node.name
+ };
+ }
+ }
+ function emitModuleDeclaration(node) {
+ if (resolver.isDeclarationVisible(node)) {
+ emitJsDocComments(node);
+ emitModuleElementDeclarationFlags(node);
+ write("module ");
+ writeTextOfNode(currentSourceFile, node.name);
+ while (node.body.kind !== 193 /* ModuleBlock */) {
+ node = node.body;
+ write(".");
+ writeTextOfNode(currentSourceFile, node.name);
+ }
+ var prevEnclosingDeclaration = enclosingDeclaration;
+ enclosingDeclaration = node;
+ write(" {");
+ writeLine();
+ increaseIndent();
+ emitLines(node.body.statements);
+ decreaseIndent();
+ write("}");
+ writeLine();
+ enclosingDeclaration = prevEnclosingDeclaration;
+ }
+ }
+ function emitTypeAliasDeclaration(node) {
+ if (resolver.isDeclarationVisible(node)) {
+ emitJsDocComments(node);
+ emitModuleElementDeclarationFlags(node);
+ write("type ");
+ writeTextOfNode(currentSourceFile, node.name);
+ write(" = ");
+ emitTypeWithNewGetSymbolAccessibilityDiangostic(node.type, getTypeAliasDeclarationVisibilityError);
+ write(";");
+ writeLine();
+ }
+ function getTypeAliasDeclarationVisibilityError(symbolAccesibilityResult) {
+ return {
+ diagnosticMessage: ts.Diagnostics.Exported_type_alias_0_has_or_is_using_private_name_1,
+ errorNode: node.type,
+ typeName: node.name
+ };
+ }
+ }
+ function emitEnumDeclaration(node) {
+ if (resolver.isDeclarationVisible(node)) {
+ emitJsDocComments(node);
+ emitModuleElementDeclarationFlags(node);
+ if (ts.isConst(node)) {
+ write("const ");
+ }
+ write("enum ");
+ writeTextOfNode(currentSourceFile, node.name);
+ write(" {");
+ writeLine();
+ increaseIndent();
+ emitLines(node.members);
+ decreaseIndent();
+ write("}");
+ writeLine();
+ }
+ }
+ function emitEnumMemberDeclaration(node) {
+ emitJsDocComments(node);
+ writeTextOfNode(currentSourceFile, node.name);
+ var enumMemberValue = resolver.getEnumMemberValue(node);
+ if (enumMemberValue !== undefined) {
+ write(" = ");
+ write(enumMemberValue.toString());
+ }
+ write(",");
+ writeLine();
+ }
+ function emitTypeParameters(typeParameters) {
+ function emitTypeParameter(node) {
+ increaseIndent();
+ emitJsDocComments(node);
+ decreaseIndent();
+ writeTextOfNode(currentSourceFile, node.name);
+ if (node.constraint && (node.parent.kind !== 125 /* Method */ || !(node.parent.flags & 32 /* Private */))) {
+ write(" extends ");
+ if (node.parent.kind === 133 /* FunctionType */ || node.parent.kind === 134 /* ConstructorType */ || (node.parent.parent && node.parent.parent.kind === 136 /* TypeLiteral */)) {
+ ts.Debug.assert(node.parent.kind === 125 /* Method */ || node.parent.kind === 133 /* FunctionType */ || node.parent.kind === 134 /* ConstructorType */ || node.parent.kind === 129 /* CallSignature */ || node.parent.kind === 130 /* ConstructSignature */);
+ emitType(node.constraint);
+ }
+ else {
+ emitTypeWithNewGetSymbolAccessibilityDiangostic(node.constraint, getTypeParameterConstraintVisibilityError);
+ }
+ }
+ function getTypeParameterConstraintVisibilityError(symbolAccesibilityResult) {
+ var diagnosticMessage;
+ switch (node.parent.kind) {
+ case 188 /* ClassDeclaration */:
+ diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_class_has_or_is_using_private_name_1;
+ break;
+ case 189 /* InterfaceDeclaration */:
+ diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1;
+ break;
+ case 130 /* ConstructSignature */:
+ diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1;
+ break;
+ case 129 /* CallSignature */:
+ diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1;
+ break;
+ case 125 /* Method */:
+ if (node.parent.flags & 128 /* Static */) {
+ diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1;
+ }
+ else if (node.parent.parent.kind === 188 /* ClassDeclaration */) {
+ diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1;
+ }
+ else {
+ diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1;
+ }
+ break;
+ case 186 /* FunctionDeclaration */:
+ diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_private_name_1;
+ break;
+ default:
+ ts.Debug.fail("This is unknown parent for type parameter: " + node.parent.kind);
+ }
+ return {
+ diagnosticMessage: diagnosticMessage,
+ errorNode: node,
+ typeName: node.name
+ };
+ }
+ }
+ if (typeParameters) {
+ write("<");
+ emitCommaList(typeParameters, emitTypeParameter);
+ write(">");
+ }
+ }
+ function emitHeritageClause(typeReferences, isImplementsList) {
+ if (typeReferences) {
+ write(isImplementsList ? " implements " : " extends ");
+ emitCommaList(typeReferences, emitTypeOfTypeReference);
+ }
+ function emitTypeOfTypeReference(node) {
+ emitTypeWithNewGetSymbolAccessibilityDiangostic(node, getHeritageClauseVisibilityError);
+ function getHeritageClauseVisibilityError(symbolAccesibilityResult) {
+ var diagnosticMessage;
+ if (node.parent.kind === 188 /* ClassDeclaration */) {
+ diagnosticMessage = isImplementsList ? ts.Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_private_name_1 : ts.Diagnostics.Extends_clause_of_exported_class_0_has_or_is_using_private_name_1;
+ }
+ else {
+ diagnosticMessage = ts.Diagnostics.Extends_clause_of_exported_interface_0_has_or_is_using_private_name_1;
+ }
+ return {
+ diagnosticMessage: diagnosticMessage,
+ errorNode: node,
+ typeName: node.parent.name
+ };
+ }
+ }
+ }
+ function emitClassDeclaration(node) {
+ function emitParameterProperties(constructorDeclaration) {
+ if (constructorDeclaration) {
+ ts.forEach(constructorDeclaration.parameters, function (param) {
+ if (param.flags & 112 /* AccessibilityModifier */) {
+ emitPropertyDeclaration(param);
+ }
+ });
+ }
+ }
+ if (resolver.isDeclarationVisible(node)) {
+ emitJsDocComments(node);
+ emitModuleElementDeclarationFlags(node);
+ write("class ");
+ writeTextOfNode(currentSourceFile, node.name);
+ var prevEnclosingDeclaration = enclosingDeclaration;
+ enclosingDeclaration = node;
+ emitTypeParameters(node.typeParameters);
+ if (node.baseType) {
+ emitHeritageClause([node.baseType], false);
+ }
+ emitHeritageClause(node.implementedTypes, true);
+ write(" {");
+ writeLine();
+ increaseIndent();
+ emitParameterProperties(getFirstConstructorWithBody(node));
+ emitLines(node.members);
+ decreaseIndent();
+ write("}");
+ writeLine();
+ enclosingDeclaration = prevEnclosingDeclaration;
+ }
+ }
+ function emitInterfaceDeclaration(node) {
+ if (resolver.isDeclarationVisible(node)) {
+ emitJsDocComments(node);
+ emitModuleElementDeclarationFlags(node);
+ write("interface ");
+ writeTextOfNode(currentSourceFile, node.name);
+ var prevEnclosingDeclaration = enclosingDeclaration;
+ enclosingDeclaration = node;
+ emitTypeParameters(node.typeParameters);
+ emitHeritageClause(node.baseTypes, false);
+ write(" {");
+ writeLine();
+ increaseIndent();
+ emitLines(node.members);
+ decreaseIndent();
+ write("}");
+ writeLine();
+ enclosingDeclaration = prevEnclosingDeclaration;
+ }
+ }
+ function emitPropertyDeclaration(node) {
+ emitJsDocComments(node);
+ emitClassMemberDeclarationFlags(node);
+ emitVariableDeclaration(node);
+ write(";");
+ writeLine();
+ }
+ function emitVariableDeclaration(node) {
+ if (node.kind !== 185 /* VariableDeclaration */ || resolver.isDeclarationVisible(node)) {
+ writeTextOfNode(currentSourceFile, node.name);
+ if (node.kind === 124 /* Property */ && (node.flags & 4 /* QuestionMark */)) {
+ write("?");
+ }
+ if (node.kind === 124 /* Property */ && node.parent.kind === 136 /* TypeLiteral */) {
+ emitTypeOfVariableDeclarationFromTypeLiteral(node);
+ }
+ else if (!(node.flags & 32 /* Private */)) {
+ writeTypeAtLocation(node, node.type, getVariableDeclarationTypeVisibilityError);
+ }
+ }
+ function getVariableDeclarationTypeVisibilityError(symbolAccesibilityResult) {
+ var diagnosticMessage;
+ if (node.kind === 185 /* VariableDeclaration */) {
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Exported_variable_0_has_or_is_using_private_name_1;
+ }
+ else if (node.kind === 124 /* Property */) {
+ if (node.flags & 128 /* Static */) {
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_private_name_1;
+ }
+ else if (node.parent.kind === 188 /* ClassDeclaration */) {
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_private_name_1;
+ }
+ else {
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Property_0_of_exported_interface_has_or_is_using_private_name_1;
+ }
+ }
+ return diagnosticMessage !== undefined ? {
+ diagnosticMessage: diagnosticMessage,
+ errorNode: node,
+ typeName: node.name
+ } : undefined;
+ }
+ }
+ function emitTypeOfVariableDeclarationFromTypeLiteral(node) {
+ if (node.type) {
+ write(": ");
+ emitType(node.type);
+ }
+ }
+ function emitVariableStatement(node) {
+ var hasDeclarationWithEmit = ts.forEach(node.declarations, function (varDeclaration) { return resolver.isDeclarationVisible(varDeclaration); });
+ if (hasDeclarationWithEmit) {
+ emitJsDocComments(node);
+ emitModuleElementDeclarationFlags(node);
+ if (ts.isLet(node)) {
+ write("let ");
+ }
+ else if (ts.isConst(node)) {
+ write("const ");
+ }
+ else {
+ write("var ");
+ }
+ emitCommaList(node.declarations, emitVariableDeclaration);
+ write(";");
+ writeLine();
+ }
+ }
+ function emitAccessorDeclaration(node) {
+ var accessors = getAllAccessorDeclarations(node.parent, node);
+ if (node === accessors.firstAccessor) {
+ emitJsDocComments(accessors.getAccessor);
+ emitJsDocComments(accessors.setAccessor);
+ emitClassMemberDeclarationFlags(node);
+ writeTextOfNode(currentSourceFile, node.name);
+ if (!(node.flags & 32 /* Private */)) {
+ var accessorWithTypeAnnotation = node;
+ var type = getTypeAnnotationFromAccessor(node);
+ if (!type) {
+ var anotherAccessor = node.kind === 127 /* GetAccessor */ ? accessors.setAccessor : accessors.getAccessor;
+ type = getTypeAnnotationFromAccessor(anotherAccessor);
+ if (type) {
+ accessorWithTypeAnnotation = anotherAccessor;
+ }
+ }
+ writeTypeAtLocation(node, type, getAccessorDeclarationTypeVisibilityError);
+ }
+ write(";");
+ writeLine();
+ }
+ function getTypeAnnotationFromAccessor(accessor) {
+ if (accessor) {
+ return accessor.kind === 127 /* GetAccessor */ ? accessor.type : accessor.parameters[0].type;
+ }
+ }
+ function getAccessorDeclarationTypeVisibilityError(symbolAccesibilityResult) {
+ var diagnosticMessage;
+ if (accessorWithTypeAnnotation.kind === 128 /* SetAccessor */) {
+ if (accessorWithTypeAnnotation.parent.flags & 128 /* Static */) {
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_private_name_1;
+ }
+ else {
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_private_name_1;
+ }
+ return {
+ diagnosticMessage: diagnosticMessage,
+ errorNode: accessorWithTypeAnnotation.parameters[0],
+ typeName: accessorWithTypeAnnotation.name
+ };
+ }
+ else {
+ if (accessorWithTypeAnnotation.flags & 128 /* Static */) {
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_private_name_0;
+ }
+ else {
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_private_name_0;
+ }
+ return {
+ diagnosticMessage: diagnosticMessage,
+ errorNode: accessorWithTypeAnnotation.name,
+ typeName: undefined
+ };
+ }
+ }
+ }
+ function emitFunctionDeclaration(node) {
+ if ((node.kind !== 186 /* FunctionDeclaration */ || resolver.isDeclarationVisible(node)) && !resolver.isImplementationOfOverload(node)) {
+ emitJsDocComments(node);
+ if (node.kind === 186 /* FunctionDeclaration */) {
+ emitModuleElementDeclarationFlags(node);
+ }
+ else if (node.kind === 125 /* Method */) {
+ emitClassMemberDeclarationFlags(node);
+ }
+ if (node.kind === 186 /* FunctionDeclaration */) {
+ write("function ");
+ writeTextOfNode(currentSourceFile, node.name);
+ }
+ else if (node.kind === 126 /* Constructor */) {
+ write("constructor");
+ }
+ else {
+ writeTextOfNode(currentSourceFile, node.name);
+ if (node.flags & 4 /* QuestionMark */) {
+ write("?");
+ }
+ }
+ emitSignatureDeclaration(node);
+ }
+ }
+ function emitSignatureDeclarationWithJsDocComments(node) {
+ emitJsDocComments(node);
+ emitSignatureDeclaration(node);
+ }
+ function emitSignatureDeclaration(node) {
+ if (node.kind === 130 /* ConstructSignature */ || node.kind === 134 /* ConstructorType */) {
+ write("new ");
+ }
+ emitTypeParameters(node.typeParameters);
+ if (node.kind === 131 /* IndexSignature */) {
+ write("[");
+ }
+ else {
+ write("(");
+ }
+ var prevEnclosingDeclaration = enclosingDeclaration;
+ enclosingDeclaration = node;
+ emitCommaList(node.parameters, emitParameterDeclaration);
+ if (node.kind === 131 /* IndexSignature */) {
+ write("]");
+ }
+ else {
+ write(")");
+ }
+ var isFunctionTypeOrConstructorType = node.kind === 133 /* FunctionType */ || node.kind === 134 /* ConstructorType */;
+ if (isFunctionTypeOrConstructorType || node.parent.kind === 136 /* TypeLiteral */) {
+ if (node.type) {
+ write(isFunctionTypeOrConstructorType ? " => " : ": ");
+ emitType(node.type);
+ }
+ }
+ else if (node.kind !== 126 /* Constructor */ && !(node.flags & 32 /* Private */)) {
+ writeReturnTypeAtSignature(node, getReturnTypeVisibilityError);
+ }
+ enclosingDeclaration = prevEnclosingDeclaration;
+ if (!isFunctionTypeOrConstructorType) {
+ write(";");
+ writeLine();
+ }
+ function getReturnTypeVisibilityError(symbolAccesibilityResult) {
+ var diagnosticMessage;
+ switch (node.kind) {
+ case 130 /* ConstructSignature */:
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_0;
+ break;
+ case 129 /* CallSignature */:
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_private_name_0;
+ break;
+ case 131 /* IndexSignature */:
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_private_name_0;
+ break;
+ case 125 /* Method */:
+ if (node.flags & 128 /* Static */) {
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_private_name_0;
+ }
+ else if (node.parent.kind === 188 /* ClassDeclaration */) {
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_private_name_0;
+ }
+ else {
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_private_name_0;
+ }
+ break;
+ case 186 /* FunctionDeclaration */:
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_private_name_0;
+ break;
+ default:
+ ts.Debug.fail("This is unknown kind for signature: " + node.kind);
+ }
+ return {
+ diagnosticMessage: diagnosticMessage,
+ errorNode: node.name || node
+ };
+ }
+ }
+ function emitParameterDeclaration(node) {
+ increaseIndent();
+ emitJsDocComments(node);
+ if (node.flags & 8 /* Rest */) {
+ write("...");
+ }
+ writeTextOfNode(currentSourceFile, node.name);
+ if (node.initializer || (node.flags & 4 /* QuestionMark */)) {
+ write("?");
+ }
+ decreaseIndent();
+ if (node.parent.kind === 133 /* FunctionType */ || node.parent.kind === 134 /* ConstructorType */ || node.parent.parent.kind === 136 /* TypeLiteral */) {
+ emitTypeOfVariableDeclarationFromTypeLiteral(node);
+ }
+ else if (!(node.parent.flags & 32 /* Private */)) {
+ writeTypeAtLocation(node, node.type, getParameterDeclarationTypeVisibilityError);
+ }
+ function getParameterDeclarationTypeVisibilityError(symbolAccesibilityResult) {
+ var diagnosticMessage;
+ switch (node.parent.kind) {
+ case 126 /* Constructor */:
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_private_name_1;
+ break;
+ case 130 /* ConstructSignature */:
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1;
+ break;
+ case 129 /* CallSignature */:
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1;
+ break;
+ case 125 /* Method */:
+ if (node.parent.flags & 128 /* Static */) {
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1;
+ }
+ else if (node.parent.parent.kind === 188 /* ClassDeclaration */) {
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1;
+ }
+ else {
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1;
+ }
+ break;
+ case 186 /* FunctionDeclaration */:
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_private_name_1;
+ break;
+ default:
+ ts.Debug.fail("This is unknown parent for parameter: " + node.parent.kind);
+ }
+ return {
+ diagnosticMessage: diagnosticMessage,
+ errorNode: node,
+ typeName: node.name
+ };
+ }
+ }
+ function emitNode(node) {
+ switch (node.kind) {
+ case 126 /* Constructor */:
+ case 186 /* FunctionDeclaration */:
+ case 125 /* Method */:
+ return emitFunctionDeclaration(node);
+ case 130 /* ConstructSignature */:
+ case 129 /* CallSignature */:
+ case 131 /* IndexSignature */:
+ return emitSignatureDeclarationWithJsDocComments(node);
+ case 127 /* GetAccessor */:
+ case 128 /* SetAccessor */:
+ return emitAccessorDeclaration(node);
+ case 163 /* VariableStatement */:
+ return emitVariableStatement(node);
+ case 124 /* Property */:
+ return emitPropertyDeclaration(node);
+ case 189 /* InterfaceDeclaration */:
+ return emitInterfaceDeclaration(node);
+ case 188 /* ClassDeclaration */:
+ return emitClassDeclaration(node);
+ case 190 /* TypeAliasDeclaration */:
+ return emitTypeAliasDeclaration(node);
+ case 196 /* EnumMember */:
+ return emitEnumMemberDeclaration(node);
+ case 191 /* EnumDeclaration */:
+ return emitEnumDeclaration(node);
+ case 192 /* ModuleDeclaration */:
+ return emitModuleDeclaration(node);
+ case 194 /* ImportDeclaration */:
+ return emitImportDeclaration(node);
+ case 195 /* ExportAssignment */:
+ return emitExportAssignment(node);
+ case 197 /* SourceFile */:
+ return emitSourceFile(node);
+ }
+ }
+ var referencePathsOutput = "";
+ function writeReferencePath(referencedFile) {
+ var declFileName = referencedFile.flags & 1024 /* DeclarationFile */ ? referencedFile.filename : shouldEmitToOwnFile(referencedFile, compilerOptions) ? getOwnEmitOutputFilePath(referencedFile, program, ".d.ts") : ts.removeFileExtension(compilerOptions.out) + ".d.ts";
+ declFileName = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizeSlashes(jsFilePath)), declFileName, compilerHost.getCurrentDirectory(), compilerHost.getCanonicalFileName, false);
+ referencePathsOutput += "/// " + newLine;
+ }
+ if (root) {
+ if (!compilerOptions.noResolve) {
+ var addedGlobalFileReference = false;
+ ts.forEach(root.referencedFiles, function (fileReference) {
+ var referencedFile = ts.tryResolveScriptReference(program, root, fileReference);
+ if (referencedFile && ((referencedFile.flags & 1024 /* DeclarationFile */) || shouldEmitToOwnFile(referencedFile, compilerOptions) || !addedGlobalFileReference)) {
+ writeReferencePath(referencedFile);
+ if (!isExternalModuleOrDeclarationFile(referencedFile)) {
+ addedGlobalFileReference = true;
+ }
+ }
+ });
+ }
+ emitNode(root);
+ }
+ else {
+ var emittedReferencedFiles = [];
+ ts.forEach(program.getSourceFiles(), function (sourceFile) {
+ if (!isExternalModuleOrDeclarationFile(sourceFile)) {
+ if (!compilerOptions.noResolve) {
+ ts.forEach(sourceFile.referencedFiles, function (fileReference) {
+ var referencedFile = ts.tryResolveScriptReference(program, sourceFile, fileReference);
+ if (referencedFile && (isExternalModuleOrDeclarationFile(referencedFile) && !ts.contains(emittedReferencedFiles, referencedFile))) {
+ writeReferencePath(referencedFile);
+ emittedReferencedFiles.push(referencedFile);
+ }
+ });
+ }
+ emitNode(sourceFile);
+ }
+ });
+ }
+ return {
+ reportedDeclarationError: reportedDeclarationError,
+ aliasDeclarationEmitInfo: aliasDeclarationEmitInfo,
+ synchronousDeclarationOutput: writer.getText(),
+ referencePathsOutput: referencePathsOutput
+ };
+ }
+ function getDeclarationDiagnostics(program, resolver, targetSourceFile) {
+ var diagnostics = [];
+ var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, program, ".js");
+ emitDeclarations(program, resolver, diagnostics, jsFilePath, targetSourceFile);
+ return diagnostics;
+ }
+ ts.getDeclarationDiagnostics = getDeclarationDiagnostics;
function emitFiles(resolver, targetSourceFile) {
var program = resolver.getProgram();
var compilerHost = program.getCompilerHost();
@@ -6061,206 +7483,14 @@ var ts;
var sourceMapDataList = compilerOptions.sourceMap ? [] : undefined;
var diagnostics = [];
var newLine = program.getCompilerHost().getNewLine();
- function getSourceFilePathInNewDir(newDirPath, sourceFile) {
- var sourceFilePath = ts.getNormalizedPathFromPathComponents(ts.getNormalizedPathComponents(sourceFile.filename, compilerHost.getCurrentDirectory()));
- sourceFilePath = sourceFilePath.replace(program.getCommonSourceDirectory(), "");
- return ts.combinePaths(newDirPath, sourceFilePath);
- }
- function getOwnEmitOutputFilePath(sourceFile, extension) {
- if (compilerOptions.outDir) {
- var emitOutputFilePathWithoutExtension = ts.removeFileExtension(getSourceFilePathInNewDir(compilerOptions.outDir, sourceFile));
- }
- else {
- var emitOutputFilePathWithoutExtension = ts.removeFileExtension(sourceFile.filename);
- }
- return emitOutputFilePathWithoutExtension + extension;
- }
- function getFirstConstructorWithBody(node) {
- return ts.forEach(node.members, function (member) {
- if (member.kind === 126 /* Constructor */ && member.body) {
- return member;
- }
- });
- }
- function getAllAccessorDeclarations(node, accessor) {
- var firstAccessor;
- var getAccessor;
- var setAccessor;
- ts.forEach(node.members, function (member) {
- if ((member.kind === 127 /* GetAccessor */ || member.kind === 128 /* SetAccessor */) && member.name.text === accessor.name.text && (member.flags & 128 /* Static */) === (accessor.flags & 128 /* Static */)) {
- if (!firstAccessor) {
- firstAccessor = member;
- }
- if (member.kind === 127 /* GetAccessor */ && !getAccessor) {
- getAccessor = member;
- }
- if (member.kind === 128 /* SetAccessor */ && !setAccessor) {
- setAccessor = member;
- }
- }
- });
- return {
- firstAccessor: firstAccessor,
- getAccessor: getAccessor,
- setAccessor: setAccessor
- };
- }
- function createTextWriter() {
- var output = "";
- var indent = 0;
- var lineStart = true;
- var lineCount = 0;
- var linePos = 0;
- function write(s) {
- if (s && s.length) {
- if (lineStart) {
- output += getIndentString(indent);
- lineStart = false;
- }
- output += s;
- }
- }
- function rawWrite(s) {
- if (s !== undefined) {
- if (lineStart) {
- lineStart = false;
- }
- output += s;
- }
- }
- function writeLiteral(s) {
- if (s && s.length) {
- write(s);
- var lineStartsOfS = ts.computeLineStarts(s);
- if (lineStartsOfS.length > 1) {
- lineCount = lineCount + lineStartsOfS.length - 1;
- linePos = output.length - s.length + lineStartsOfS[lineStartsOfS.length - 1];
- }
- }
- }
- function writeLine() {
- if (!lineStart) {
- output += newLine;
- lineCount++;
- linePos = output.length;
- lineStart = true;
- }
- }
- return {
- write: write,
- rawWrite: rawWrite,
- writeLiteral: writeLiteral,
- writeLine: writeLine,
- increaseIndent: function () { return indent++; },
- decreaseIndent: function () { return indent--; },
- getIndent: function () { return indent; },
- getTextPos: function () { return output.length; },
- getLine: function () { return lineCount + 1; },
- getColumn: function () { return lineStart ? indent * getIndentSize() + 1 : output.length - linePos + 1; },
- getText: function () { return output; }
- };
- }
- var currentSourceFile;
- function getSourceTextOfLocalNode(node) {
- var text = currentSourceFile.text;
- return text.substring(ts.skipTrivia(text, node.pos), node.end);
- }
- function getLineOfLocalPosition(pos) {
- return currentSourceFile.getLineAndCharacterFromPosition(pos).line;
- }
- function writeFile(filename, data, writeByteOrderMark) {
- compilerHost.writeFile(filename, data, writeByteOrderMark, function (hostErrorMessage) {
- diagnostics.push(ts.createCompilerDiagnostic(ts.Diagnostics.Could_not_write_file_0_Colon_1, filename, hostErrorMessage));
- });
- }
- function emitComments(comments, trailingSeparator, writer, writeComment) {
- var emitLeadingSpace = !trailingSeparator;
- ts.forEach(comments, function (comment) {
- if (emitLeadingSpace) {
- writer.write(" ");
- emitLeadingSpace = false;
- }
- writeComment(comment, writer);
- if (comment.hasTrailingNewLine) {
- writer.writeLine();
- }
- else if (trailingSeparator) {
- writer.write(" ");
- }
- else {
- emitLeadingSpace = true;
- }
- });
- }
- function emitNewLineBeforeLeadingComments(node, leadingComments, writer) {
- if (leadingComments && leadingComments.length && node.pos !== leadingComments[0].pos && getLineOfLocalPosition(node.pos) !== getLineOfLocalPosition(leadingComments[0].pos)) {
- writer.writeLine();
- }
- }
- function writeCommentRange(comment, writer) {
- if (currentSourceFile.text.charCodeAt(comment.pos + 1) === 42 /* asterisk */) {
- var firstCommentLineAndCharacter = currentSourceFile.getLineAndCharacterFromPosition(comment.pos);
- var firstCommentLineIndent;
- for (var pos = comment.pos, currentLine = firstCommentLineAndCharacter.line; pos < comment.end; currentLine++) {
- var nextLineStart = currentSourceFile.getPositionFromLineAndCharacter(currentLine + 1, 1);
- if (pos !== comment.pos) {
- if (firstCommentLineIndent === undefined) {
- firstCommentLineIndent = calculateIndent(currentSourceFile.getPositionFromLineAndCharacter(firstCommentLineAndCharacter.line, 1), comment.pos);
- }
- var currentWriterIndentSpacing = writer.getIndent() * getIndentSize();
- var spacesToEmit = currentWriterIndentSpacing - firstCommentLineIndent + calculateIndent(pos, nextLineStart);
- if (spacesToEmit > 0) {
- var numberOfSingleSpacesToEmit = spacesToEmit % getIndentSize();
- var indentSizeSpaceString = getIndentString((spacesToEmit - numberOfSingleSpacesToEmit) / getIndentSize());
- writer.rawWrite(indentSizeSpaceString);
- while (numberOfSingleSpacesToEmit) {
- writer.rawWrite(" ");
- numberOfSingleSpacesToEmit--;
- }
- }
- else {
- writer.rawWrite("");
- }
- }
- writeTrimmedCurrentLine(pos, nextLineStart);
- pos = nextLineStart;
- }
- }
- else {
- writer.write(currentSourceFile.text.substring(comment.pos, comment.end));
- }
- function writeTrimmedCurrentLine(pos, nextLineStart) {
- var end = Math.min(comment.end, nextLineStart - 1);
- var currentLineText = currentSourceFile.text.substring(pos, end).replace(/^\s+|\s+$/g, '');
- if (currentLineText) {
- writer.write(currentLineText);
- if (end !== comment.end) {
- writer.writeLine();
- }
- }
- else {
- writer.writeLiteral(newLine);
- }
- }
- function calculateIndent(pos, end) {
- var currentLineIndent = 0;
- for (; pos < end && ts.isWhiteSpace(currentSourceFile.text.charCodeAt(pos)); pos++) {
- if (currentSourceFile.text.charCodeAt(pos) === 9 /* tab */) {
- currentLineIndent += getIndentSize() - (currentLineIndent % getIndentSize());
- }
- else {
- currentLineIndent++;
- }
- }
- return currentLineIndent;
- }
- }
function emitJavaScript(jsFilePath, root) {
- var writer = createTextWriter();
+ var writer = createTextWriter(newLine);
var write = writer.write;
+ var writeTextOfNode = writer.writeTextOfNode;
var writeLine = writer.writeLine;
var increaseIndent = writer.increaseIndent;
var decreaseIndent = writer.decreaseIndent;
+ var currentSourceFile;
var extendsEmitted = false;
var writeEmittedFiles = writeJavaScriptFile;
var emitLeadingComments = compilerOptions.removeComments ? function (node) {
@@ -6417,7 +7647,7 @@ var ts;
if (scopeName) {
recordScopeNameStart(scopeName);
}
- else if (node.kind === 185 /* FunctionDeclaration */ || node.kind === 152 /* FunctionExpression */ || node.kind === 125 /* Method */ || node.kind === 127 /* GetAccessor */ || node.kind === 128 /* SetAccessor */ || node.kind === 191 /* ModuleDeclaration */ || node.kind === 187 /* ClassDeclaration */ || node.kind === 190 /* EnumDeclaration */) {
+ else if (node.kind === 186 /* FunctionDeclaration */ || node.kind === 152 /* FunctionExpression */ || node.kind === 125 /* Method */ || node.kind === 127 /* GetAccessor */ || node.kind === 128 /* SetAccessor */ || node.kind === 192 /* ModuleDeclaration */ || node.kind === 188 /* ClassDeclaration */ || node.kind === 191 /* EnumDeclaration */) {
if (node.name) {
scopeName = node.name.text;
}
@@ -6431,9 +7661,9 @@ var ts;
sourceMapNameIndices.pop();
}
;
- function writeCommentRangeWithMap(comment, writer) {
+ function writeCommentRangeWithMap(curentSourceFile, writer, comment, newLine) {
recordSourceMapSpan(comment.pos);
- writeCommentRange(comment, writer);
+ writeCommentRange(currentSourceFile, writer, comment, newLine);
recordSourceMapSpan(comment.end);
}
function serializeSourceMapContents(version, file, sourceRoot, sources, names, mappings) {
@@ -6461,7 +7691,7 @@ var ts;
}
function writeJavaScriptAndSourceMapFile(emitOutput, writeByteOrderMark) {
encodeLastRecordedSourceMapSpan();
- writeFile(sourceMapData.sourceMapFilePath, serializeSourceMapContents(3, sourceMapData.sourceMapFile, sourceMapData.sourceMapSourceRoot, sourceMapData.sourceMapSources, sourceMapData.sourceMapNames, sourceMapData.sourceMapMappings), false);
+ writeFile(compilerHost, diagnostics, sourceMapData.sourceMapFilePath, serializeSourceMapContents(3, sourceMapData.sourceMapFile, sourceMapData.sourceMapSourceRoot, sourceMapData.sourceMapSources, sourceMapData.sourceMapNames, sourceMapData.sourceMapMappings), false);
sourceMapDataList.push(sourceMapData);
writeJavaScriptFile(emitOutput + "//# sourceMappingURL=" + sourceMapData.jsSourceMappingURL, writeByteOrderMark);
}
@@ -6484,7 +7714,7 @@ var ts;
if (compilerOptions.mapRoot) {
sourceMapDir = ts.normalizeSlashes(compilerOptions.mapRoot);
if (root) {
- sourceMapDir = ts.getDirectoryPath(getSourceFilePathInNewDir(sourceMapDir, root));
+ sourceMapDir = ts.getDirectoryPath(getSourceFilePathInNewDir(root, program, sourceMapDir));
}
if (!ts.isRootedDiskPath(sourceMapDir) && !ts.isUrl(sourceMapDir)) {
sourceMapDir = ts.combinePaths(program.getCommonSourceDirectory(), sourceMapDir);
@@ -6499,7 +7729,7 @@ var ts;
}
function emitNodeWithMap(node) {
if (node) {
- if (node.kind != 196 /* SourceFile */) {
+ if (node.kind != 197 /* SourceFile */) {
recordEmitNodeStartSpan(node);
emitNode(node);
recordEmitNodeEndSpan(node);
@@ -6520,7 +7750,7 @@ var ts;
writeComment = writeCommentRangeWithMap;
}
function writeJavaScriptFile(emitOutput, writeByteOrderMark) {
- writeFile(jsFilePath, emitOutput, writeByteOrderMark);
+ writeFile(compilerHost, diagnostics, jsFilePath, emitOutput, writeByteOrderMark);
}
function emitTokenText(tokenKind, startPos, emitFn) {
var tokenString = ts.tokenToString(tokenKind);
@@ -6597,7 +7827,7 @@ var ts;
if (compilerOptions.target < 2 /* ES6 */ && ts.isTemplateLiteralKind(node.kind)) {
return getTemplateLiteralAsStringLiteral(node);
}
- return getSourceTextOfLocalNode(node);
+ return ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node);
}
}
function getTemplateLiteralAsStringLiteral(node) {
@@ -6609,8 +7839,8 @@ var ts;
return;
}
ts.Debug.assert(node.parent.kind !== 149 /* TaggedTemplateExpression */);
- var templateNeedsParens = ts.isExpression(node.parent) && node.parent.kind !== 151 /* ParenExpression */ && comparePrecedenceToBinaryPlus(node.parent) !== -1 /* LessThan */;
- if (templateNeedsParens) {
+ var emitOuterParens = ts.isExpression(node.parent) && templateNeedsParens(node, node.parent);
+ if (emitOuterParens) {
write("(");
}
emitLiteral(node.head);
@@ -6629,9 +7859,22 @@ var ts;
emitLiteral(templateSpan.literal);
}
});
- if (templateNeedsParens) {
+ if (emitOuterParens) {
write(")");
}
+ function templateNeedsParens(template, parent) {
+ switch (parent.kind) {
+ case 147 /* CallExpression */:
+ case 148 /* NewExpression */:
+ return parent.func === template;
+ case 151 /* ParenExpression */:
+ return false;
+ case 149 /* TaggedTemplateExpression */:
+ ts.Debug.fail("Path should be unreachable; tagged templates not supported pre-ES6.");
+ default:
+ return comparePrecedenceToBinaryPlus(parent) !== -1 /* LessThan */;
+ }
+ }
function comparePrecedenceToBinaryPlus(expression) {
ts.Debug.assert(compilerOptions.target <= 1 /* ES5 */);
switch (expression.kind) {
@@ -6667,7 +7910,7 @@ var ts;
write(node.text);
}
else {
- write(getSourceTextOfLocalNode(node));
+ writeTextOfNode(currentSourceFile, node);
}
write("\"");
}
@@ -6676,29 +7919,29 @@ var ts;
var parent = node.parent;
switch (parent.kind) {
case 123 /* Parameter */:
- case 184 /* VariableDeclaration */:
+ case 185 /* VariableDeclaration */:
case 124 /* Property */:
case 143 /* PropertyAssignment */:
case 144 /* ShorthandPropertyAssignment */:
- case 195 /* EnumMember */:
+ case 196 /* EnumMember */:
case 125 /* Method */:
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
case 127 /* GetAccessor */:
case 128 /* SetAccessor */:
case 152 /* FunctionExpression */:
- case 187 /* ClassDeclaration */:
- case 188 /* InterfaceDeclaration */:
- case 190 /* EnumDeclaration */:
- case 191 /* ModuleDeclaration */:
- case 193 /* ImportDeclaration */:
+ case 188 /* ClassDeclaration */:
+ case 189 /* InterfaceDeclaration */:
+ case 191 /* EnumDeclaration */:
+ case 192 /* ModuleDeclaration */:
+ case 194 /* ImportDeclaration */:
return parent.name === node;
- case 171 /* BreakStatement */:
- case 170 /* ContinueStatement */:
- case 194 /* ExportAssignment */:
+ case 172 /* BreakStatement */:
+ case 171 /* ContinueStatement */:
+ case 195 /* ExportAssignment */:
return false;
- case 177 /* LabeledStatement */:
+ case 178 /* LabeledStatement */:
return node.parent.label === node;
- case 181 /* CatchBlock */:
+ case 182 /* CatchBlock */:
return node.parent.variable === node;
}
}
@@ -6708,14 +7951,14 @@ var ts;
write(prefix);
write(".");
}
- write(getSourceTextOfLocalNode(node));
+ writeTextOfNode(currentSourceFile, node);
}
function emitIdentifier(node) {
if (!isNotExpressionIdentifier(node)) {
emitExpressionIdentifier(node);
}
else {
- write(getSourceTextOfLocalNode(node));
+ writeTextOfNode(currentSourceFile, node);
}
}
function emitThis(node) {
@@ -6922,8 +8165,8 @@ var ts;
emitToken(13 /* OpenBraceToken */, node.pos);
increaseIndent();
scopeEmitStart(node.parent);
- if (node.kind === 192 /* ModuleBlock */) {
- ts.Debug.assert(node.parent.kind === 191 /* ModuleDeclaration */);
+ if (node.kind === 193 /* ModuleBlock */) {
+ ts.Debug.assert(node.parent.kind === 192 /* ModuleDeclaration */);
emitCaptureThisForNodeIfNecessary(node.parent);
}
emitLines(node.statements);
@@ -6933,7 +8176,7 @@ var ts;
scopeEmitEnd();
}
function emitEmbeddedStatement(node) {
- if (node.kind === 161 /* Block */) {
+ if (node.kind === 162 /* Block */) {
write(" ");
emit(node);
}
@@ -6966,7 +8209,7 @@ var ts;
if (node.elseStatement) {
writeLine();
emitToken(74 /* ElseKeyword */, node.thenStatement.end);
- if (node.elseStatement.kind === 165 /* IfStatement */) {
+ if (node.elseStatement.kind === 166 /* IfStatement */) {
write(" ");
emit(node.elseStatement);
}
@@ -6979,7 +8222,7 @@ var ts;
function emitDoStatement(node) {
write("do");
emitEmbeddedStatement(node.statement);
- if (node.statement.kind === 161 /* Block */) {
+ if (node.statement.kind === 162 /* Block */) {
write(" ");
}
else {
@@ -7000,10 +8243,10 @@ var ts;
write(" ");
endPos = emitToken(15 /* OpenParenToken */, endPos);
if (node.declarations) {
- if (node.declarations[0] && node.declarations[0].flags & 2048 /* Let */) {
+ if (node.declarations[0] && ts.isLet(node.declarations[0])) {
emitToken(102 /* LetKeyword */, endPos);
}
- else if (node.declarations[0] && node.declarations[0].flags & 4096 /* Const */) {
+ else if (node.declarations[0] && ts.isConst(node.declarations[0])) {
emitToken(68 /* ConstKeyword */, endPos);
}
else {
@@ -7026,15 +8269,18 @@ var ts;
var endPos = emitToken(80 /* ForKeyword */, node.pos);
write(" ");
endPos = emitToken(15 /* OpenParenToken */, endPos);
- if (node.declaration) {
- if (node.declaration.flags & 2048 /* Let */) {
- emitToken(102 /* LetKeyword */, endPos);
+ if (node.declarations) {
+ if (node.declarations.length >= 1) {
+ var decl = node.declarations[0];
+ if (ts.isLet(decl)) {
+ emitToken(102 /* LetKeyword */, endPos);
+ }
+ else {
+ emitToken(96 /* VarKeyword */, endPos);
+ }
+ write(" ");
+ emit(decl);
}
- else {
- emitToken(96 /* VarKeyword */, endPos);
- }
- write(" ");
- emit(node.declaration);
}
else {
emit(node.variable);
@@ -7045,7 +8291,7 @@ var ts;
emitEmbeddedStatement(node.statement);
}
function emitBreakOrContinueStatement(node) {
- emitToken(node.kind === 171 /* BreakStatement */ ? 64 /* BreakKeyword */ : 69 /* ContinueKeyword */, node.pos);
+ emitToken(node.kind === 172 /* BreakStatement */ ? 64 /* BreakKeyword */ : 69 /* ContinueKeyword */, node.pos);
emitOptional(" ", node.label);
write(";");
}
@@ -7077,10 +8323,10 @@ var ts;
emitToken(14 /* CloseBraceToken */, node.clauses.end);
}
function isOnSameLine(node1, node2) {
- return getLineOfLocalPosition(ts.skipTrivia(currentSourceFile.text, node1.pos)) === getLineOfLocalPosition(ts.skipTrivia(currentSourceFile.text, node2.pos));
+ return getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node1.pos)) === getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node2.pos));
}
function emitCaseOrDefaultClause(node) {
- if (node.kind === 175 /* CaseClause */) {
+ if (node.kind === 176 /* CaseClause */) {
write("case ");
emit(node.expression);
write(":");
@@ -7135,7 +8381,7 @@ var ts;
function getContainingModule(node) {
do {
node = node.parent;
- } while (node && node.kind !== 191 /* ModuleDeclaration */);
+ } while (node && node.kind !== 192 /* ModuleDeclaration */);
return node;
}
function emitModuleMemberName(node) {
@@ -7157,10 +8403,10 @@ var ts;
function emitVariableStatement(node) {
emitLeadingComments(node);
if (!(node.flags & 1 /* Export */)) {
- if (node.flags & 2048 /* Let */) {
+ if (ts.isLet(node)) {
write("let ");
}
- else if (node.flags & 4096 /* Const */) {
+ else if (ts.isConst(node)) {
write("const ");
}
else {
@@ -7247,7 +8493,7 @@ var ts;
emitLeadingComments(node);
}
write("function ");
- if (node.kind === 185 /* FunctionDeclaration */ || (node.kind === 152 /* FunctionExpression */ && node.name)) {
+ if (node.kind === 186 /* FunctionDeclaration */ || (node.kind === 152 /* FunctionExpression */ && node.name)) {
emit(node.name);
}
emitSignatureAndBody(node);
@@ -7277,16 +8523,16 @@ var ts;
write(" {");
scopeEmitStart(node);
increaseIndent();
- emitDetachedComments(node.body.kind === 186 /* FunctionBlock */ ? node.body.statements : node.body);
+ emitDetachedComments(node.body.kind === 187 /* FunctionBlock */ ? node.body.statements : node.body);
var startIndex = 0;
- if (node.body.kind === 186 /* FunctionBlock */) {
+ if (node.body.kind === 187 /* FunctionBlock */) {
startIndex = emitDirectivePrologues(node.body.statements, true);
}
var outPos = writer.getTextPos();
emitCaptureThisForNodeIfNecessary(node);
emitDefaultValueAssignments(node);
emitRestParameter(node);
- if (node.body.kind !== 186 /* FunctionBlock */ && outPos === writer.getTextPos()) {
+ if (node.body.kind !== 187 /* FunctionBlock */ && outPos === writer.getTextPos()) {
decreaseIndent();
write(" ");
emitStart(node.body);
@@ -7299,7 +8545,7 @@ var ts;
emitEnd(node.body);
}
else {
- if (node.body.kind === 186 /* FunctionBlock */) {
+ if (node.body.kind === 187 /* FunctionBlock */) {
emitLinesStartingAt(node.body.statements, startIndex);
}
else {
@@ -7311,7 +8557,7 @@ var ts;
emitTrailingComments(node.body);
}
writeLine();
- if (node.body.kind === 186 /* FunctionBlock */) {
+ if (node.body.kind === 187 /* FunctionBlock */) {
emitLeadingCommentsOfPosition(node.body.statements.end);
decreaseIndent();
emitToken(14 /* CloseBraceToken */, node.body.statements.end);
@@ -7337,7 +8583,7 @@ var ts;
function findInitialSuperCall(ctor) {
if (ctor.body) {
var statement = ctor.body.statements[0];
- if (statement && statement.kind === 164 /* ExpressionStatement */) {
+ if (statement && statement.kind === 165 /* ExpressionStatement */) {
var expr = statement.expression;
if (expr && expr.kind === 147 /* CallExpression */) {
var func = expr.func;
@@ -7588,7 +8834,7 @@ var ts;
emitPinnedOrTripleSlashComments(node);
}
function emitEnumDeclaration(node) {
- var isConstEnum = ts.isConstEnumDeclaration(node);
+ var isConstEnum = ts.isConst(node);
if (isConstEnum && !compilerOptions.preserveConstEnums) {
return;
}
@@ -7657,13 +8903,14 @@ var ts;
}
}
function getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration) {
- if (moduleDeclaration.body.kind === 191 /* ModuleDeclaration */) {
+ if (moduleDeclaration.body.kind === 192 /* ModuleDeclaration */) {
var recursiveInnerModule = getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration.body);
return recursiveInnerModule || moduleDeclaration.body;
}
}
function emitModuleDeclaration(node) {
- if (ts.getModuleInstanceState(node) !== 1 /* Instantiated */) {
+ var shouldEmit = ts.getModuleInstanceState(node) === 1 /* Instantiated */ || (ts.getModuleInstanceState(node) === 2 /* ConstEnumOnly */ && compilerOptions.preserveConstEnums);
+ if (!shouldEmit) {
return emitPinnedOrTripleSlashComments(node);
}
emitLeadingComments(node);
@@ -7679,7 +8926,7 @@ var ts;
write(resolver.getLocalNameOfContainer(node));
emitEnd(node.name);
write(") ");
- if (node.body.kind === 192 /* ModuleBlock */) {
+ if (node.body.kind === 193 /* ModuleBlock */) {
emit(node.body);
}
else {
@@ -7713,7 +8960,7 @@ var ts;
emitImportDeclaration = !ts.isExternalModule(currentSourceFile) && resolver.isTopLevelValueImportWithEntityName(node);
}
if (emitImportDeclaration) {
- if (node.externalModuleName && node.parent.kind === 196 /* SourceFile */ && compilerOptions.module === 2 /* AMD */) {
+ if (node.externalModuleName && node.parent.kind === 197 /* SourceFile */ && compilerOptions.module === 2 /* AMD */) {
if (node.flags & 1 /* Export */) {
writeLine();
emitLeadingComments(node);
@@ -7753,7 +9000,7 @@ var ts;
function getExternalImportDeclarations(node) {
var result = [];
ts.forEach(node.statements, function (stat) {
- if (stat.kind === 193 /* ImportDeclaration */ && stat.externalModuleName && resolver.isReferencedImportDeclaration(stat)) {
+ if (stat.kind === 194 /* ImportDeclaration */ && stat.externalModuleName && resolver.isReferencedImportDeclaration(stat)) {
result.push(stat);
}
});
@@ -7761,7 +9008,7 @@ var ts;
}
function getFirstExportAssignment(sourceFile) {
return ts.forEach(sourceFile.statements, function (node) {
- if (node.kind === 194 /* ExportAssignment */) {
+ if (node.kind === 195 /* ExportAssignment */) {
return node;
}
});
@@ -7934,7 +9181,7 @@ var ts;
return emit(node.operand);
case 151 /* ParenExpression */:
return emitParenExpression(node);
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
case 152 /* FunctionExpression */:
case 153 /* ArrowFunction */:
return emitFunctionDeclaration(node);
@@ -7945,65 +9192,65 @@ var ts;
return emitBinaryExpression(node);
case 157 /* ConditionalExpression */:
return emitConditionalExpression(node);
- case 160 /* OmittedExpression */:
+ case 161 /* OmittedExpression */:
return;
- case 161 /* Block */:
- case 180 /* TryBlock */:
- case 182 /* FinallyBlock */:
- case 186 /* FunctionBlock */:
- case 192 /* ModuleBlock */:
+ case 162 /* Block */:
+ case 181 /* TryBlock */:
+ case 183 /* FinallyBlock */:
+ case 187 /* FunctionBlock */:
+ case 193 /* ModuleBlock */:
return emitBlock(node);
- case 162 /* VariableStatement */:
+ case 163 /* VariableStatement */:
return emitVariableStatement(node);
- case 163 /* EmptyStatement */:
+ case 164 /* EmptyStatement */:
return write(";");
- case 164 /* ExpressionStatement */:
+ case 165 /* ExpressionStatement */:
return emitExpressionStatement(node);
- case 165 /* IfStatement */:
+ case 166 /* IfStatement */:
return emitIfStatement(node);
- case 166 /* DoStatement */:
+ case 167 /* DoStatement */:
return emitDoStatement(node);
- case 167 /* WhileStatement */:
+ case 168 /* WhileStatement */:
return emitWhileStatement(node);
- case 168 /* ForStatement */:
+ case 169 /* ForStatement */:
return emitForStatement(node);
- case 169 /* ForInStatement */:
+ case 170 /* ForInStatement */:
return emitForInStatement(node);
- case 170 /* ContinueStatement */:
- case 171 /* BreakStatement */:
+ case 171 /* ContinueStatement */:
+ case 172 /* BreakStatement */:
return emitBreakOrContinueStatement(node);
- case 172 /* ReturnStatement */:
+ case 173 /* ReturnStatement */:
return emitReturnStatement(node);
- case 173 /* WithStatement */:
+ case 174 /* WithStatement */:
return emitWithStatement(node);
- case 174 /* SwitchStatement */:
+ case 175 /* SwitchStatement */:
return emitSwitchStatement(node);
- case 175 /* CaseClause */:
- case 176 /* DefaultClause */:
+ case 176 /* CaseClause */:
+ case 177 /* DefaultClause */:
return emitCaseOrDefaultClause(node);
- case 177 /* LabeledStatement */:
+ case 178 /* LabeledStatement */:
return emitLabelledStatement(node);
- case 178 /* ThrowStatement */:
+ case 179 /* ThrowStatement */:
return emitThrowStatement(node);
- case 179 /* TryStatement */:
+ case 180 /* TryStatement */:
return emitTryStatement(node);
- case 181 /* CatchBlock */:
+ case 182 /* CatchBlock */:
return emitCatchBlock(node);
- case 183 /* DebuggerStatement */:
+ case 184 /* DebuggerStatement */:
return emitDebuggerStatement(node);
- case 184 /* VariableDeclaration */:
+ case 185 /* VariableDeclaration */:
return emitVariableDeclaration(node);
- case 187 /* ClassDeclaration */:
+ case 188 /* ClassDeclaration */:
return emitClassDeclaration(node);
- case 188 /* InterfaceDeclaration */:
+ case 189 /* InterfaceDeclaration */:
return emitInterfaceDeclaration(node);
- case 190 /* EnumDeclaration */:
+ case 191 /* EnumDeclaration */:
return emitEnumDeclaration(node);
- case 191 /* ModuleDeclaration */:
+ case 192 /* ModuleDeclaration */:
return emitModuleDeclaration(node);
- case 193 /* ImportDeclaration */:
+ case 194 /* ImportDeclaration */:
return emitImportDeclaration(node);
- case 196 /* SourceFile */:
+ case 197 /* SourceFile */:
return emitSourceFile(node);
}
}
@@ -8021,7 +9268,7 @@ var ts;
return leadingComments;
}
function getLeadingCommentsToEmit(node) {
- if (node.parent.kind === 196 /* SourceFile */ || node.pos !== node.parent.pos) {
+ if (node.parent.kind === 197 /* SourceFile */ || node.pos !== node.parent.pos) {
var leadingComments;
if (hasDetachedComments(node.pos)) {
leadingComments = getLeadingCommentsWithoutDetachedComments();
@@ -8034,13 +9281,13 @@ var ts;
}
function emitLeadingDeclarationComments(node) {
var leadingComments = getLeadingCommentsToEmit(node);
- emitNewLineBeforeLeadingComments(node, leadingComments, writer);
- emitComments(leadingComments, true, writer, writeComment);
+ emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments);
+ emitComments(currentSourceFile, writer, leadingComments, true, newLine, writeComment);
}
function emitTrailingDeclarationComments(node) {
- if (node.parent.kind === 196 /* SourceFile */ || node.end !== node.parent.end) {
+ if (node.parent.kind === 197 /* SourceFile */ || node.end !== node.parent.end) {
var trailingComments = ts.getTrailingCommentRanges(currentSourceFile.text, node.end);
- emitComments(trailingComments, false, writer, writeComment);
+ emitComments(currentSourceFile, writer, trailingComments, false, newLine, writeComment);
}
}
function emitLeadingCommentsOfLocalPosition(pos) {
@@ -8051,8 +9298,8 @@ var ts;
else {
leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, pos);
}
- emitNewLineBeforeLeadingComments({ pos: pos, end: pos }, leadingComments, writer);
- emitComments(leadingComments, true, writer, writeComment);
+ emitNewLineBeforeLeadingComments(currentSourceFile, writer, { pos: pos, end: pos }, leadingComments);
+ emitComments(currentSourceFile, writer, leadingComments, true, newLine, writeComment);
}
function emitDetachedCommentsAtPosition(node) {
var leadingComments = ts.getLeadingCommentRanges(currentSourceFile.text, node.pos);
@@ -8061,8 +9308,8 @@ var ts;
var lastComment;
ts.forEach(leadingComments, function (comment) {
if (lastComment) {
- var lastCommentLine = getLineOfLocalPosition(lastComment.end);
- var commentLine = getLineOfLocalPosition(comment.pos);
+ var lastCommentLine = getLineOfLocalPosition(currentSourceFile, lastComment.end);
+ var commentLine = getLineOfLocalPosition(currentSourceFile, comment.pos);
if (commentLine >= lastCommentLine + 2) {
return detachedComments;
}
@@ -8071,11 +9318,11 @@ var ts;
lastComment = comment;
});
if (detachedComments.length) {
- var lastCommentLine = getLineOfLocalPosition(detachedComments[detachedComments.length - 1].end);
- var astLine = getLineOfLocalPosition(ts.skipTrivia(currentSourceFile.text, node.pos));
+ var lastCommentLine = getLineOfLocalPosition(currentSourceFile, detachedComments[detachedComments.length - 1].end);
+ var astLine = getLineOfLocalPosition(currentSourceFile, ts.skipTrivia(currentSourceFile.text, node.pos));
if (astLine >= lastCommentLine + 2) {
- emitNewLineBeforeLeadingComments(node, leadingComments, writer);
- emitComments(detachedComments, true, writer, writeComment);
+ emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, leadingComments);
+ emitComments(currentSourceFile, writer, detachedComments, true, newLine, writeComment);
var currentDetachedCommentInfo = { nodePos: node.pos, detachedCommentEndPos: detachedComments[detachedComments.length - 1].end };
if (detachedCommentsInfo) {
detachedCommentsInfo.push(currentDetachedCommentInfo);
@@ -8097,8 +9344,8 @@ var ts;
return true;
}
}
- emitNewLineBeforeLeadingComments(node, pinnedComments, writer);
- emitComments(pinnedComments, true, writer, writeComment);
+ emitNewLineBeforeLeadingComments(currentSourceFile, writer, node, pinnedComments);
+ emitComments(currentSourceFile, writer, pinnedComments, true, newLine, writeComment);
}
if (compilerOptions.sourceMap) {
initializeEmitterWithSourceMaps();
@@ -8116,722 +9363,20 @@ var ts;
writeLine();
writeEmittedFiles(writer.getText(), compilerOptions.emitBOM);
}
- function emitDeclarations(jsFilePath, root) {
- var writer = createTextWriterWithSymbolWriter();
- var write = writer.write;
- var writeLine = writer.writeLine;
- var increaseIndent = writer.increaseIndent;
- var decreaseIndent = writer.decreaseIndent;
- var enclosingDeclaration;
- var reportedDeclarationError = false;
- var emitJsDocComments = compilerOptions.removeComments ? function (declaration) {
- } : writeJsDocComments;
- var aliasDeclarationEmitInfo = [];
- var getSymbolVisibilityDiagnosticMessage;
- function createTextWriterWithSymbolWriter() {
- var writer = createTextWriter();
- writer.trackSymbol = trackSymbol;
- writer.writeKeyword = writer.write;
- writer.writeOperator = writer.write;
- writer.writePunctuation = writer.write;
- writer.writeSpace = writer.write;
- writer.writeStringLiteral = writer.writeLiteral;
- writer.writeParameter = writer.write;
- writer.writeSymbol = writer.write;
- return writer;
- }
- function writeAsychronousImportDeclarations(importDeclarations) {
- var oldWriter = writer;
- ts.forEach(importDeclarations, function (aliasToWrite) {
- var aliasEmitInfo = ts.forEach(aliasDeclarationEmitInfo, function (declEmitInfo) { return declEmitInfo.declaration === aliasToWrite ? declEmitInfo : undefined; });
- writer = createTextWriterWithSymbolWriter();
- for (var declarationIndent = aliasEmitInfo.indent; declarationIndent; declarationIndent--) {
- writer.increaseIndent();
- }
- writeImportDeclaration(aliasToWrite);
- aliasEmitInfo.asynchronousOutput = writer.getText();
- });
- writer = oldWriter;
- }
- function trackSymbol(symbol, enclosingDeclaration, meaning) {
- var symbolAccesibilityResult = resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning);
- if (symbolAccesibilityResult.accessibility === 0 /* Accessible */) {
- if (symbolAccesibilityResult && symbolAccesibilityResult.aliasesToMakeVisible) {
- writeAsychronousImportDeclarations(symbolAccesibilityResult.aliasesToMakeVisible);
- }
- }
- else {
- reportedDeclarationError = true;
- var errorInfo = getSymbolVisibilityDiagnosticMessage(symbolAccesibilityResult);
- if (errorInfo) {
- if (errorInfo.typeName) {
- diagnostics.push(ts.createDiagnosticForNode(errorInfo.errorNode, errorInfo.diagnosticMessage, getSourceTextOfLocalNode(errorInfo.typeName), symbolAccesibilityResult.errorSymbolName, symbolAccesibilityResult.errorModuleName));
- }
- else {
- diagnostics.push(ts.createDiagnosticForNode(errorInfo.errorNode, errorInfo.diagnosticMessage, symbolAccesibilityResult.errorSymbolName, symbolAccesibilityResult.errorModuleName));
- }
- }
- }
- }
- function emitLines(nodes) {
- for (var i = 0, n = nodes.length; i < n; i++) {
- emitNode(nodes[i]);
- }
- }
- function emitCommaList(nodes, eachNodeEmitFn) {
- var currentWriterPos = writer.getTextPos();
- for (var i = 0, n = nodes.length; i < n; i++) {
- if (currentWriterPos !== writer.getTextPos()) {
- write(", ");
- }
- currentWriterPos = writer.getTextPos();
- eachNodeEmitFn(nodes[i]);
- }
- }
- function writeJsDocComments(declaration) {
- if (declaration) {
- var jsDocComments = ts.getJsDocComments(declaration, currentSourceFile);
- emitNewLineBeforeLeadingComments(declaration, jsDocComments, writer);
- emitComments(jsDocComments, true, writer, writeCommentRange);
- }
- }
- function emitSourceTextOfNode(node) {
- write(getSourceTextOfLocalNode(node));
- }
- function emitSourceFile(node) {
- currentSourceFile = node;
- enclosingDeclaration = node;
- emitLines(node.statements);
- }
- function emitExportAssignment(node) {
- write("export = ");
- emitSourceTextOfNode(node.exportName);
- write(";");
- writeLine();
- }
- function emitDeclarationFlags(node) {
- if (node.flags & 128 /* Static */) {
- if (node.flags & 32 /* Private */) {
- write("private ");
- }
- else if (node.flags & 64 /* Protected */) {
- write("protected ");
- }
- write("static ");
- }
- else {
- if (node.flags & 32 /* Private */) {
- write("private ");
- }
- else if (node.flags & 64 /* Protected */) {
- write("protected ");
- }
- else if (node.parent === currentSourceFile) {
- if (node.flags & 1 /* Export */) {
- write("export ");
- }
- if (node.kind !== 188 /* InterfaceDeclaration */) {
- write("declare ");
- }
- }
- }
- }
- function emitImportDeclaration(node) {
- var nodeEmitInfo = {
- declaration: node,
- outputPos: writer.getTextPos(),
- indent: writer.getIndent(),
- hasWritten: resolver.isDeclarationVisible(node)
- };
- aliasDeclarationEmitInfo.push(nodeEmitInfo);
- if (nodeEmitInfo.hasWritten) {
- writeImportDeclaration(node);
- }
- }
- function writeImportDeclaration(node) {
- emitJsDocComments(node);
- if (node.flags & 1 /* Export */) {
- writer.write("export ");
- }
- writer.write("import ");
- writer.write(getSourceTextOfLocalNode(node.name));
- writer.write(" = ");
- if (node.entityName) {
- checkEntityNameAccessible();
- writer.write(getSourceTextOfLocalNode(node.entityName));
- writer.write(";");
- }
- else {
- writer.write("require(");
- writer.write(getSourceTextOfLocalNode(node.externalModuleName));
- writer.write(");");
- }
- writer.writeLine();
- function checkEntityNameAccessible() {
- var symbolAccesibilityResult = resolver.isImportDeclarationEntityNameReferenceDeclarationVisibile(node.entityName);
- if (symbolAccesibilityResult.accessibility === 0 /* Accessible */) {
- if (symbolAccesibilityResult.aliasesToMakeVisible) {
- writeAsychronousImportDeclarations(symbolAccesibilityResult.aliasesToMakeVisible);
- }
- }
- else {
- reportedDeclarationError = true;
- diagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.Import_declaration_0_is_using_private_name_1, getSourceTextOfLocalNode(node.name), symbolAccesibilityResult.errorSymbolName));
- }
- }
- }
- function emitModuleDeclaration(node) {
- if (resolver.isDeclarationVisible(node)) {
- emitJsDocComments(node);
- emitDeclarationFlags(node);
- write("module ");
- emitSourceTextOfNode(node.name);
- while (node.body.kind !== 192 /* ModuleBlock */) {
- node = node.body;
- write(".");
- emitSourceTextOfNode(node.name);
- }
- var prevEnclosingDeclaration = enclosingDeclaration;
- enclosingDeclaration = node;
- write(" {");
- writeLine();
- increaseIndent();
- emitLines(node.body.statements);
- decreaseIndent();
- write("}");
- writeLine();
- enclosingDeclaration = prevEnclosingDeclaration;
- }
- }
- function emitTypeAliasDeclaration(node) {
- if (resolver.isDeclarationVisible(node)) {
- emitJsDocComments(node);
- emitDeclarationFlags(node);
- write("type ");
- emitSourceTextOfNode(node.name);
- write(" = ");
- getSymbolVisibilityDiagnosticMessage = getTypeAliasDeclarationVisibilityError;
- resolver.writeTypeAtLocation(node.type, enclosingDeclaration, 2 /* UseTypeOfFunction */, writer);
- write(";");
- writeLine();
- }
- function getTypeAliasDeclarationVisibilityError(symbolAccesibilityResult) {
- var diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Exported_type_alias_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Exported_type_alias_0_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Exported_type_alias_0_has_or_is_using_private_name_1;
- return {
- diagnosticMessage: diagnosticMessage,
- errorNode: node,
- typeName: node.name
- };
- }
- }
- function emitEnumDeclaration(node) {
- if (resolver.isDeclarationVisible(node)) {
- emitJsDocComments(node);
- emitDeclarationFlags(node);
- if (ts.isConstEnumDeclaration(node)) {
- write("const ");
- }
- write("enum ");
- emitSourceTextOfNode(node.name);
- write(" {");
- writeLine();
- increaseIndent();
- emitLines(node.members);
- decreaseIndent();
- write("}");
- writeLine();
- }
- }
- function emitEnumMemberDeclaration(node) {
- emitJsDocComments(node);
- emitSourceTextOfNode(node.name);
- var enumMemberValue = resolver.getEnumMemberValue(node);
- if (enumMemberValue !== undefined) {
- write(" = ");
- write(enumMemberValue.toString());
- }
- write(",");
- writeLine();
- }
- function emitTypeParameters(typeParameters) {
- function emitTypeParameter(node) {
- function getTypeParameterConstraintVisibilityError(symbolAccesibilityResult) {
- var diagnosticMessage;
- switch (node.parent.kind) {
- case 187 /* ClassDeclaration */:
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Type_parameter_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Type_parameter_0_of_exported_class_has_or_is_using_private_name_1;
- break;
- case 188 /* InterfaceDeclaration */:
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1;
- break;
- case 130 /* ConstructSignature */:
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1;
- break;
- case 129 /* CallSignature */:
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1;
- break;
- case 125 /* Method */:
- if (node.parent.flags & 128 /* Static */) {
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1;
- }
- else if (node.parent.parent.kind === 187 /* ClassDeclaration */) {
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1;
- }
- else {
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Type_parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1;
- }
- break;
- case 185 /* FunctionDeclaration */:
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_private_name_1;
- break;
- default:
- ts.Debug.fail("This is unknown parent for type parameter: " + node.parent.kind);
- }
- return {
- diagnosticMessage: diagnosticMessage,
- errorNode: node,
- typeName: node.name
- };
- }
- increaseIndent();
- emitJsDocComments(node);
- decreaseIndent();
- emitSourceTextOfNode(node.name);
- if (node.constraint && (node.parent.kind !== 125 /* Method */ || !(node.parent.flags & 32 /* Private */))) {
- write(" extends ");
- getSymbolVisibilityDiagnosticMessage = getTypeParameterConstraintVisibilityError;
- resolver.writeTypeAtLocation(node.constraint, enclosingDeclaration, 2 /* UseTypeOfFunction */, writer);
- }
- }
- if (typeParameters) {
- write("<");
- emitCommaList(typeParameters, emitTypeParameter);
- write(">");
- }
- }
- function emitHeritageClause(typeReferences, isImplementsList) {
- if (typeReferences) {
- write(isImplementsList ? " implements " : " extends ");
- emitCommaList(typeReferences, emitTypeOfTypeReference);
- }
- function emitTypeOfTypeReference(node) {
- getSymbolVisibilityDiagnosticMessage = getHeritageClauseVisibilityError;
- resolver.writeTypeAtLocation(node, enclosingDeclaration, 1 /* WriteArrayAsGenericType */ | 2 /* UseTypeOfFunction */, writer);
- function getHeritageClauseVisibilityError(symbolAccesibilityResult) {
- var diagnosticMessage;
- if (node.parent.kind === 187 /* ClassDeclaration */) {
- if (symbolAccesibilityResult.errorModuleName) {
- diagnosticMessage = isImplementsList ? ts.Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Extends_clause_of_exported_class_0_has_or_is_using_name_1_from_private_module_2;
- }
- else {
- diagnosticMessage = isImplementsList ? ts.Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_private_name_1 : ts.Diagnostics.Extends_clause_of_exported_class_0_has_or_is_using_private_name_1;
- }
- }
- else {
- if (symbolAccesibilityResult.errorModuleName) {
- diagnosticMessage = ts.Diagnostics.Extends_clause_of_exported_interface_0_has_or_is_using_name_1_from_private_module_2;
- }
- else {
- diagnosticMessage = ts.Diagnostics.Extends_clause_of_exported_interface_0_has_or_is_using_private_name_1;
- }
- }
- return {
- diagnosticMessage: diagnosticMessage,
- errorNode: node,
- typeName: node.parent.name
- };
- }
- }
- }
- function emitClassDeclaration(node) {
- function emitParameterProperties(constructorDeclaration) {
- if (constructorDeclaration) {
- ts.forEach(constructorDeclaration.parameters, function (param) {
- if (param.flags & 112 /* AccessibilityModifier */) {
- emitPropertyDeclaration(param);
- }
- });
- }
- }
- if (resolver.isDeclarationVisible(node)) {
- emitJsDocComments(node);
- emitDeclarationFlags(node);
- write("class ");
- emitSourceTextOfNode(node.name);
- var prevEnclosingDeclaration = enclosingDeclaration;
- enclosingDeclaration = node;
- emitTypeParameters(node.typeParameters);
- if (node.baseType) {
- emitHeritageClause([node.baseType], false);
- }
- emitHeritageClause(node.implementedTypes, true);
- write(" {");
- writeLine();
- increaseIndent();
- emitParameterProperties(getFirstConstructorWithBody(node));
- emitLines(node.members);
- decreaseIndent();
- write("}");
- writeLine();
- enclosingDeclaration = prevEnclosingDeclaration;
- }
- }
- function emitInterfaceDeclaration(node) {
- if (resolver.isDeclarationVisible(node)) {
- emitJsDocComments(node);
- emitDeclarationFlags(node);
- write("interface ");
- emitSourceTextOfNode(node.name);
- var prevEnclosingDeclaration = enclosingDeclaration;
- enclosingDeclaration = node;
- emitTypeParameters(node.typeParameters);
- emitHeritageClause(node.baseTypes, false);
- write(" {");
- writeLine();
- increaseIndent();
- emitLines(node.members);
- decreaseIndent();
- write("}");
- writeLine();
- enclosingDeclaration = prevEnclosingDeclaration;
- }
- }
- function emitPropertyDeclaration(node) {
- emitJsDocComments(node);
- emitDeclarationFlags(node);
- emitVariableDeclaration(node);
- write(";");
- writeLine();
- }
- function emitVariableDeclaration(node) {
- if (node.kind !== 184 /* VariableDeclaration */ || resolver.isDeclarationVisible(node)) {
- emitSourceTextOfNode(node.name);
- if (node.kind === 124 /* Property */ && (node.flags & 4 /* QuestionMark */)) {
- write("?");
- }
- if (!(node.flags & 32 /* Private */)) {
- write(": ");
- getSymbolVisibilityDiagnosticMessage = getVariableDeclarationTypeVisibilityError;
- resolver.writeTypeAtLocation(node, enclosingDeclaration, 2 /* UseTypeOfFunction */, writer);
- }
- }
- function getVariableDeclarationTypeVisibilityError(symbolAccesibilityResult) {
- var diagnosticMessage;
- if (node.kind === 184 /* VariableDeclaration */) {
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Exported_variable_0_has_or_is_using_private_name_1;
- }
- else if (node.kind === 124 /* Property */) {
- if (node.flags & 128 /* Static */) {
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_private_name_1;
- }
- else if (node.parent.kind === 187 /* ClassDeclaration */) {
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_private_name_1;
- }
- else {
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Property_0_of_exported_interface_has_or_is_using_private_name_1;
- }
- }
- return diagnosticMessage !== undefined ? {
- diagnosticMessage: diagnosticMessage,
- errorNode: node,
- typeName: node.name
- } : undefined;
- }
- }
- function emitVariableStatement(node) {
- var hasDeclarationWithEmit = ts.forEach(node.declarations, function (varDeclaration) { return resolver.isDeclarationVisible(varDeclaration); });
- if (hasDeclarationWithEmit) {
- emitJsDocComments(node);
- emitDeclarationFlags(node);
- if (node.flags & 2048 /* Let */) {
- write("let ");
- }
- else if (node.flags & 4096 /* Const */) {
- write("const ");
- }
- else {
- write("var ");
- }
- emitCommaList(node.declarations, emitVariableDeclaration);
- write(";");
- writeLine();
- }
- }
- function emitAccessorDeclaration(node) {
- var accessors = getAllAccessorDeclarations(node.parent, node);
- if (node === accessors.firstAccessor) {
- emitJsDocComments(accessors.getAccessor);
- emitJsDocComments(accessors.setAccessor);
- emitDeclarationFlags(node);
- emitSourceTextOfNode(node.name);
- if (!(node.flags & 32 /* Private */)) {
- write(": ");
- getSymbolVisibilityDiagnosticMessage = getAccessorDeclarationTypeVisibilityError;
- resolver.writeTypeAtLocation(node, enclosingDeclaration, 2 /* UseTypeOfFunction */, writer);
- }
- write(";");
- writeLine();
- }
- function getAccessorDeclarationTypeVisibilityError(symbolAccesibilityResult) {
- var diagnosticMessage;
- if (node.kind === 128 /* SetAccessor */) {
- if (node.parent.flags & 128 /* Static */) {
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_private_name_1;
- }
- else {
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_private_name_1;
- }
- return {
- diagnosticMessage: diagnosticMessage,
- errorNode: node.parameters[0],
- typeName: node.name
- };
- }
- else {
- if (node.flags & 128 /* Static */) {
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_private_name_0;
- }
- else {
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_private_name_0;
- }
- return {
- diagnosticMessage: diagnosticMessage,
- errorNode: node.name,
- typeName: undefined
- };
- }
- }
- }
- function emitFunctionDeclaration(node) {
- if ((node.kind !== 185 /* FunctionDeclaration */ || resolver.isDeclarationVisible(node)) && !resolver.isImplementationOfOverload(node)) {
- emitJsDocComments(node);
- emitDeclarationFlags(node);
- if (node.kind === 185 /* FunctionDeclaration */) {
- write("function ");
- emitSourceTextOfNode(node.name);
- }
- else if (node.kind === 126 /* Constructor */) {
- write("constructor");
- }
- else {
- emitSourceTextOfNode(node.name);
- if (node.flags & 4 /* QuestionMark */) {
- write("?");
- }
- }
- emitSignatureDeclaration(node);
- }
- }
- function emitConstructSignatureDeclaration(node) {
- emitJsDocComments(node);
- write("new ");
- emitSignatureDeclaration(node);
- }
- function emitSignatureDeclaration(node) {
- if (node.kind === 129 /* CallSignature */ || node.kind === 131 /* IndexSignature */) {
- emitJsDocComments(node);
- }
- emitTypeParameters(node.typeParameters);
- if (node.kind === 131 /* IndexSignature */) {
- write("[");
- }
- else {
- write("(");
- }
- emitCommaList(node.parameters, emitParameterDeclaration);
- if (node.kind === 131 /* IndexSignature */) {
- write("]");
- }
- else {
- write(")");
- }
- if (node.kind !== 126 /* Constructor */ && !(node.flags & 32 /* Private */)) {
- write(": ");
- getSymbolVisibilityDiagnosticMessage = getReturnTypeVisibilityError;
- resolver.writeReturnTypeOfSignatureDeclaration(node, enclosingDeclaration, 2 /* UseTypeOfFunction */, writer);
- }
- write(";");
- writeLine();
- function getReturnTypeVisibilityError(symbolAccesibilityResult) {
- var diagnosticMessage;
- switch (node.kind) {
- case 130 /* ConstructSignature */:
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_0;
- break;
- case 129 /* CallSignature */:
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_private_name_0;
- break;
- case 131 /* IndexSignature */:
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_private_name_0;
- break;
- case 125 /* Method */:
- if (node.flags & 128 /* Static */) {
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_private_name_0;
- }
- else if (node.parent.kind === 187 /* ClassDeclaration */) {
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_private_name_0;
- }
- else {
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_private_name_0;
- }
- break;
- case 185 /* FunctionDeclaration */:
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named : ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_private_module_1 : ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_private_name_0;
- break;
- default:
- ts.Debug.fail("This is unknown kind for signature: " + node.kind);
- }
- return {
- diagnosticMessage: diagnosticMessage,
- errorNode: node.name || node
- };
- }
- }
- function emitParameterDeclaration(node) {
- increaseIndent();
- emitJsDocComments(node);
- if (node.flags & 8 /* Rest */) {
- write("...");
- }
- emitSourceTextOfNode(node.name);
- if (node.initializer || (node.flags & 4 /* QuestionMark */)) {
- write("?");
- }
- decreaseIndent();
- if (!(node.parent.flags & 32 /* Private */)) {
- write(": ");
- getSymbolVisibilityDiagnosticMessage = getParameterDeclarationTypeVisibilityError;
- resolver.writeTypeAtLocation(node, enclosingDeclaration, 2 /* UseTypeOfFunction */, writer);
- }
- function getParameterDeclarationTypeVisibilityError(symbolAccesibilityResult) {
- var diagnosticMessage;
- switch (node.parent.kind) {
- case 126 /* Constructor */:
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_private_name_1;
- break;
- case 130 /* ConstructSignature */:
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1;
- break;
- case 129 /* CallSignature */:
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1;
- break;
- case 125 /* Method */:
- if (node.parent.flags & 128 /* Static */) {
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1;
- }
- else if (node.parent.parent.kind === 187 /* ClassDeclaration */) {
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1;
- }
- else {
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? ts.Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1;
- }
- break;
- case 185 /* FunctionDeclaration */:
- diagnosticMessage = symbolAccesibilityResult.errorModuleName ? symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ? ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named : ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 : ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_private_name_1;
- break;
- default:
- ts.Debug.fail("This is unknown parent for parameter: " + node.parent.kind);
- }
- return {
- diagnosticMessage: diagnosticMessage,
- errorNode: node,
- typeName: node.name
- };
- }
- }
- function emitNode(node) {
- switch (node.kind) {
- case 126 /* Constructor */:
- case 185 /* FunctionDeclaration */:
- case 125 /* Method */:
- return emitFunctionDeclaration(node);
- case 130 /* ConstructSignature */:
- return emitConstructSignatureDeclaration(node);
- case 129 /* CallSignature */:
- case 131 /* IndexSignature */:
- return emitSignatureDeclaration(node);
- case 127 /* GetAccessor */:
- case 128 /* SetAccessor */:
- return emitAccessorDeclaration(node);
- case 162 /* VariableStatement */:
- return emitVariableStatement(node);
- case 124 /* Property */:
- return emitPropertyDeclaration(node);
- case 188 /* InterfaceDeclaration */:
- return emitInterfaceDeclaration(node);
- case 187 /* ClassDeclaration */:
- return emitClassDeclaration(node);
- case 189 /* TypeAliasDeclaration */:
- return emitTypeAliasDeclaration(node);
- case 195 /* EnumMember */:
- return emitEnumMemberDeclaration(node);
- case 190 /* EnumDeclaration */:
- return emitEnumDeclaration(node);
- case 191 /* ModuleDeclaration */:
- return emitModuleDeclaration(node);
- case 193 /* ImportDeclaration */:
- return emitImportDeclaration(node);
- case 194 /* ExportAssignment */:
- return emitExportAssignment(node);
- case 196 /* SourceFile */:
- return emitSourceFile(node);
- }
- }
- function tryResolveScriptReference(sourceFile, reference) {
- var referenceFileName = ts.normalizePath(ts.combinePaths(ts.getDirectoryPath(sourceFile.filename), reference.filename));
- return program.getSourceFile(referenceFileName);
- }
- var referencePathsOutput = "";
- function writeReferencePath(referencedFile) {
- var declFileName = referencedFile.flags & 1024 /* DeclarationFile */ ? referencedFile.filename : shouldEmitToOwnFile(referencedFile, compilerOptions) ? getOwnEmitOutputFilePath(referencedFile, ".d.ts") : ts.removeFileExtension(compilerOptions.out) + ".d.ts";
- declFileName = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizeSlashes(jsFilePath)), declFileName, compilerHost.getCurrentDirectory(), compilerHost.getCanonicalFileName, false);
- referencePathsOutput += "/// " + newLine;
- }
- if (root) {
- if (!compilerOptions.noResolve) {
- var addedGlobalFileReference = false;
- ts.forEach(root.referencedFiles, function (fileReference) {
- var referencedFile = tryResolveScriptReference(root, fileReference);
- if (referencedFile && ((referencedFile.flags & 1024 /* DeclarationFile */) || shouldEmitToOwnFile(referencedFile, compilerOptions) || !addedGlobalFileReference)) {
- writeReferencePath(referencedFile);
- if (!isExternalModuleOrDeclarationFile(referencedFile)) {
- addedGlobalFileReference = true;
- }
- }
- });
- }
- emitNode(root);
- }
- else {
- var emittedReferencedFiles = [];
- ts.forEach(program.getSourceFiles(), function (sourceFile) {
- if (!isExternalModuleOrDeclarationFile(sourceFile)) {
- if (!compilerOptions.noResolve) {
- ts.forEach(sourceFile.referencedFiles, function (fileReference) {
- var referencedFile = tryResolveScriptReference(sourceFile, fileReference);
- if (referencedFile && (isExternalModuleOrDeclarationFile(referencedFile) && !ts.contains(emittedReferencedFiles, referencedFile))) {
- writeReferencePath(referencedFile);
- emittedReferencedFiles.push(referencedFile);
- }
- });
- }
- emitNode(sourceFile);
- }
- });
- }
- if (!reportedDeclarationError) {
- var declarationOutput = referencePathsOutput;
- var synchronousDeclarationOutput = writer.getText();
+ function writeDeclarationFile(jsFilePath, sourceFile) {
+ var emitDeclarationResult = emitDeclarations(program, resolver, diagnostics, jsFilePath, sourceFile);
+ if (!emitDeclarationResult.reportedDeclarationError) {
+ var declarationOutput = emitDeclarationResult.referencePathsOutput;
var appliedSyncOutputPos = 0;
- ts.forEach(aliasDeclarationEmitInfo, function (aliasEmitInfo) {
+ ts.forEach(emitDeclarationResult.aliasDeclarationEmitInfo, function (aliasEmitInfo) {
if (aliasEmitInfo.asynchronousOutput) {
- declarationOutput += synchronousDeclarationOutput.substring(appliedSyncOutputPos, aliasEmitInfo.outputPos);
+ declarationOutput += emitDeclarationResult.synchronousDeclarationOutput.substring(appliedSyncOutputPos, aliasEmitInfo.outputPos);
declarationOutput += aliasEmitInfo.asynchronousOutput;
appliedSyncOutputPos = aliasEmitInfo.outputPos;
}
});
- declarationOutput += synchronousDeclarationOutput.substring(appliedSyncOutputPos);
- writeFile(ts.removeFileExtension(jsFilePath) + ".d.ts", declarationOutput, compilerOptions.emitBOM);
+ declarationOutput += emitDeclarationResult.synchronousDeclarationOutput.substring(appliedSyncOutputPos);
+ writeFile(compilerHost, diagnostics, ts.removeFileExtension(jsFilePath) + ".d.ts", declarationOutput, compilerOptions.emitBOM);
}
}
var hasSemanticErrors = resolver.hasSemanticErrors();
@@ -8840,14 +9385,14 @@ var ts;
if (!isEmitBlocked) {
emitJavaScript(jsFilePath, sourceFile);
if (!hasSemanticErrors && compilerOptions.declaration) {
- emitDeclarations(jsFilePath, sourceFile);
+ writeDeclarationFile(jsFilePath, sourceFile);
}
}
}
if (targetSourceFile === undefined) {
ts.forEach(program.getSourceFiles(), function (sourceFile) {
if (shouldEmitToOwnFile(sourceFile, compilerOptions)) {
- var jsFilePath = getOwnEmitOutputFilePath(sourceFile, ".js");
+ var jsFilePath = getOwnEmitOutputFilePath(sourceFile, program, ".js");
emitFile(jsFilePath, sourceFile);
}
});
@@ -8857,7 +9402,7 @@ var ts;
}
else {
if (shouldEmitToOwnFile(targetSourceFile, compilerOptions)) {
- var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, ".js");
+ var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, program, ".js");
emitFile(jsFilePath, targetSourceFile);
}
else if (!ts.isDeclarationFile(targetSourceFile) && compilerOptions.out) {
@@ -8950,10 +9495,11 @@ var ts;
getTypeCount: function () { return typeCount; },
isUndefinedSymbol: function (symbol) { return symbol === undefinedSymbol; },
isArgumentsSymbol: function (symbol) { return symbol === argumentsSymbol; },
+ emitFiles: invokeEmitter,
getDiagnostics: getDiagnostics,
+ getDeclarationDiagnostics: getDeclarationDiagnostics,
getGlobalDiagnostics: getGlobalDiagnostics,
checkProgram: checkProgram,
- invokeEmitter: invokeEmitter,
getParentOfSymbol: getParentOfSymbol,
getNarrowedTypeOfSymbol: getNarrowedTypeOfSymbol,
getDeclaredTypeOfSymbol: getDeclaredTypeOfSymbol,
@@ -9159,10 +9705,10 @@ var ts;
return nodeLinks[node.id] || (nodeLinks[node.id] = {});
}
function getSourceFile(node) {
- return ts.getAncestor(node, 196 /* SourceFile */);
+ return ts.getAncestor(node, 197 /* SourceFile */);
}
function isGlobalSourceFile(node) {
- return node.kind === 196 /* SourceFile */ && !ts.isExternalModule(node);
+ return node.kind === 197 /* SourceFile */ && !ts.isExternalModule(node);
}
function getSymbol(symbols, name, meaning) {
if (meaning && ts.hasProperty(symbols, name)) {
@@ -9203,21 +9749,21 @@ var ts;
}
}
switch (location.kind) {
- case 196 /* SourceFile */:
+ case 197 /* SourceFile */:
if (!ts.isExternalModule(location))
break;
- case 191 /* ModuleDeclaration */:
+ case 192 /* ModuleDeclaration */:
if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 35653619 /* ModuleMember */)) {
break loop;
}
break;
- case 190 /* EnumDeclaration */:
+ case 191 /* EnumDeclaration */:
if (result = getSymbol(getSymbolOfNode(location).exports, name, meaning & 8 /* EnumMember */)) {
break loop;
}
break;
case 124 /* Property */:
- if (location.parent.kind === 187 /* ClassDeclaration */ && !(location.flags & 128 /* Static */)) {
+ if (location.parent.kind === 188 /* ClassDeclaration */ && !(location.flags & 128 /* Static */)) {
var ctor = findConstructorDeclaration(location.parent);
if (ctor && ctor.locals) {
if (getSymbol(ctor.locals, name, meaning & 107455 /* Value */)) {
@@ -9226,8 +9772,8 @@ var ts;
}
}
break;
- case 187 /* ClassDeclaration */:
- case 188 /* InterfaceDeclaration */:
+ case 188 /* ClassDeclaration */:
+ case 189 /* InterfaceDeclaration */:
if (result = getSymbol(getSymbolOfNode(location).members, name, meaning & 3152352 /* Type */)) {
if (lastLocation && lastLocation.flags & 128 /* Static */) {
error(errorLocation, ts.Diagnostics.Static_members_cannot_reference_class_type_parameters);
@@ -9240,7 +9786,7 @@ var ts;
case 126 /* Constructor */:
case 127 /* GetAccessor */:
case 128 /* SetAccessor */:
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
case 153 /* ArrowFunction */:
if (name === "arguments") {
result = argumentsSymbol;
@@ -9258,7 +9804,7 @@ var ts;
break loop;
}
break;
- case 181 /* CatchBlock */:
+ case 182 /* CatchBlock */:
var id = location.variable;
if (name === id.text) {
result = location.symbol;
@@ -9299,7 +9845,7 @@ var ts;
var links = getSymbolLinks(symbol);
if (!links.target) {
links.target = resolvingSymbol;
- var node = getDeclarationOfKind(symbol, 193 /* ImportDeclaration */);
+ var node = getDeclarationOfKind(symbol, 194 /* ImportDeclaration */);
var target = node.externalModuleName ? resolveExternalModuleName(node, node.externalModuleName) : getSymbolOfPartOfRightHandSideOfImport(node.entityName, node);
if (links.target === resolvingSymbol) {
links.target = target || unknownSymbol;
@@ -9315,7 +9861,7 @@ var ts;
}
function getSymbolOfPartOfRightHandSideOfImport(entityName, importDeclaration) {
if (!importDeclaration) {
- importDeclaration = ts.getAncestor(entityName, 193 /* ImportDeclaration */);
+ importDeclaration = ts.getAncestor(entityName, 194 /* ImportDeclaration */);
ts.Debug.assert(importDeclaration !== undefined);
}
if (entityName.kind === 63 /* Identifier */ && isRightSideOfQualifiedNameOrPropertyAccess(entityName)) {
@@ -9325,7 +9871,7 @@ var ts;
return resolveEntityName(importDeclaration, entityName, 1536 /* Namespace */);
}
else {
- ts.Debug.assert(entityName.parent.kind === 193 /* ImportDeclaration */);
+ ts.Debug.assert(entityName.parent.kind === 194 /* ImportDeclaration */);
return resolveEntityName(importDeclaration, entityName, 107455 /* Value */ | 3152352 /* Type */ | 1536 /* Namespace */);
}
}
@@ -9430,9 +9976,9 @@ var ts;
var seenExportedMember = false;
var result = [];
ts.forEach(symbol.declarations, function (declaration) {
- var block = (declaration.kind === 196 /* SourceFile */ ? declaration : declaration.body);
+ var block = (declaration.kind === 197 /* SourceFile */ ? declaration : declaration.body);
ts.forEach(block.statements, function (node) {
- if (node.kind === 194 /* ExportAssignment */) {
+ if (node.kind === 195 /* ExportAssignment */) {
result.push(node);
}
else {
@@ -9539,17 +10085,17 @@ var ts;
}
}
switch (location.kind) {
- case 196 /* SourceFile */:
+ case 197 /* SourceFile */:
if (!ts.isExternalModule(location)) {
break;
}
- case 191 /* ModuleDeclaration */:
+ case 192 /* ModuleDeclaration */:
if (result = callback(getSymbolOfNode(location).exports)) {
return result;
}
break;
- case 187 /* ClassDeclaration */:
- case 188 /* InterfaceDeclaration */:
+ case 188 /* ClassDeclaration */:
+ case 189 /* InterfaceDeclaration */:
if (result = callback(getSymbolOfNode(location).members)) {
return result;
}
@@ -9580,7 +10126,7 @@ var ts;
}
return ts.forEachValue(symbols, function (symbolFromSymbolTable) {
if (symbolFromSymbolTable.flags & 33554432 /* Import */) {
- if (!useOnlyExternalAliasing || ts.forEach(symbolFromSymbolTable.declarations, function (declaration) { return declaration.kind === 193 /* ImportDeclaration */ && declaration.externalModuleName; })) {
+ if (!useOnlyExternalAliasing || ts.forEach(symbolFromSymbolTable.declarations, function (declaration) { return declaration.kind === 194 /* ImportDeclaration */ && declaration.externalModuleName; })) {
var resolvedImportedSymbol = resolveImport(symbolFromSymbolTable);
if (isAccessible(symbolFromSymbolTable, resolveImport(symbolFromSymbolTable))) {
return [symbolFromSymbolTable];
@@ -9631,7 +10177,7 @@ var ts;
errorModuleName: symbol !== initialSymbol ? symbolToString(symbol, enclosingDeclaration, 1536 /* Namespace */) : undefined
};
}
- return { accessibility: 0 /* Accessible */, aliasesToMakeVisible: hasAccessibleDeclarations.aliasesToMakeVisible };
+ return hasAccessibleDeclarations;
}
meaningToLook = getQualifiedLeftMeaning(meaning);
symbol = getParentOfSymbol(symbol);
@@ -9662,17 +10208,17 @@ var ts;
}
}
function hasExternalModuleSymbol(declaration) {
- return (declaration.kind === 191 /* ModuleDeclaration */ && declaration.name.kind === 7 /* StringLiteral */) || (declaration.kind === 196 /* SourceFile */ && ts.isExternalModule(declaration));
+ return (declaration.kind === 192 /* ModuleDeclaration */ && declaration.name.kind === 7 /* StringLiteral */) || (declaration.kind === 197 /* SourceFile */ && ts.isExternalModule(declaration));
}
function hasVisibleDeclarations(symbol) {
var aliasesToMakeVisible;
if (ts.forEach(symbol.declarations, function (declaration) { return !getIsDeclarationVisible(declaration); })) {
return undefined;
}
- return { aliasesToMakeVisible: aliasesToMakeVisible };
+ return { accessibility: 0 /* Accessible */, aliasesToMakeVisible: aliasesToMakeVisible };
function getIsDeclarationVisible(declaration) {
if (!isDeclarationVisible(declaration)) {
- if (declaration.kind === 193 /* ImportDeclaration */ && !(declaration.flags & 1 /* Export */) && isDeclarationVisible(declaration.parent)) {
+ if (declaration.kind === 194 /* ImportDeclaration */ && !(declaration.flags & 1 /* Export */) && isDeclarationVisible(declaration.parent)) {
getNodeLinks(declaration).isVisible = true;
if (aliasesToMakeVisible) {
if (!ts.contains(aliasesToMakeVisible, declaration)) {
@@ -9689,11 +10235,24 @@ var ts;
return true;
}
}
- function isImportDeclarationEntityNameReferenceDeclarationVisibile(entityName) {
+ function isEntityNameVisible(entityName, enclosingDeclaration) {
+ var meaning;
+ if (entityName.parent.kind === 135 /* TypeQuery */) {
+ meaning = 107455 /* Value */ | 4194304 /* ExportValue */;
+ }
+ else if (entityName.kind === 121 /* QualifiedName */ || entityName.parent.kind === 194 /* ImportDeclaration */) {
+ meaning = 1536 /* Namespace */;
+ }
+ else {
+ meaning = 3152352 /* Type */;
+ }
var firstIdentifier = getFirstIdentifier(entityName);
- var symbolOfNameSpace = resolveName(entityName.parent, firstIdentifier.text, 1536 /* Namespace */, ts.Diagnostics.Cannot_find_name_0, firstIdentifier);
- var hasNamespaceDeclarationsVisibile = hasVisibleDeclarations(symbolOfNameSpace);
- return hasNamespaceDeclarationsVisibile ? { accessibility: 0 /* Accessible */, aliasesToMakeVisible: hasNamespaceDeclarationsVisibile.aliasesToMakeVisible } : { accessibility: 1 /* NotAccessible */, errorSymbolName: ts.declarationNameToString(firstIdentifier) };
+ var symbol = resolveName(enclosingDeclaration, firstIdentifier.text, meaning, undefined, undefined);
+ return hasVisibleDeclarations(symbol) || {
+ accessibility: 1 /* NotAccessible */,
+ errorSymbolName: ts.getTextOfNode(firstIdentifier),
+ errorNode: firstIdentifier
+ };
}
function releaseStringWriter(writer) {
writer.clear();
@@ -9735,7 +10294,7 @@ var ts;
while (node.kind === 140 /* ParenType */) {
node = node.parent;
}
- if (node.kind === 189 /* TypeAliasDeclaration */) {
+ if (node.kind === 190 /* TypeAliasDeclaration */) {
return getSymbolOfNode(node);
}
}
@@ -9898,7 +10457,7 @@ var ts;
function shouldWriteTypeOfFunctionSymbol() {
if (type.symbol) {
var isStaticMethodSymbol = !!(type.symbol.flags & 8192 /* Method */ && ts.forEach(type.symbol.declarations, function (declaration) { return declaration.flags & 128 /* Static */; }));
- var isNonLocalFunctionSymbol = !!(type.symbol.flags & 16 /* Function */) && (type.symbol.parent || ts.forEach(type.symbol.declarations, function (declaration) { return declaration.parent.kind === 196 /* SourceFile */ || declaration.parent.kind === 192 /* ModuleBlock */; }));
+ var isNonLocalFunctionSymbol = !!(type.symbol.flags & 16 /* Function */) && (type.symbol.parent || ts.forEach(type.symbol.declarations, function (declaration) { return declaration.parent.kind === 197 /* SourceFile */ || declaration.parent.kind === 193 /* ModuleBlock */; }));
if (isStaticMethodSymbol || isNonLocalFunctionSymbol) {
return !!(flags & 2 /* UseTypeOfFunction */) || (typeStack && ts.contains(typeStack, type));
}
@@ -10117,12 +10676,12 @@ var ts;
function isDeclarationVisible(node) {
function getContainingExternalModule(node) {
for (; node; node = node.parent) {
- if (node.kind === 191 /* ModuleDeclaration */) {
+ if (node.kind === 192 /* ModuleDeclaration */) {
if (node.name.kind === 7 /* StringLiteral */) {
return node;
}
}
- else if (node.kind === 196 /* SourceFile */) {
+ else if (node.kind === 197 /* SourceFile */) {
return ts.isExternalModule(node) ? node : undefined;
}
}
@@ -10164,16 +10723,16 @@ var ts;
}
function determineIfDeclarationIsVisible() {
switch (node.kind) {
- case 184 /* VariableDeclaration */:
- case 191 /* ModuleDeclaration */:
- case 187 /* ClassDeclaration */:
- case 188 /* InterfaceDeclaration */:
- case 189 /* TypeAliasDeclaration */:
- case 185 /* FunctionDeclaration */:
- case 190 /* EnumDeclaration */:
- case 193 /* ImportDeclaration */:
- var parent = node.kind === 184 /* VariableDeclaration */ ? node.parent.parent : node.parent;
- if (!(node.flags & 1 /* Export */) && !(node.kind !== 193 /* ImportDeclaration */ && parent.kind !== 196 /* SourceFile */ && ts.isInAmbientContext(parent))) {
+ case 185 /* VariableDeclaration */:
+ case 192 /* ModuleDeclaration */:
+ case 188 /* ClassDeclaration */:
+ case 189 /* InterfaceDeclaration */:
+ case 190 /* TypeAliasDeclaration */:
+ case 186 /* FunctionDeclaration */:
+ case 191 /* EnumDeclaration */:
+ case 194 /* ImportDeclaration */:
+ var parent = node.kind === 185 /* VariableDeclaration */ ? node.parent.parent : node.parent;
+ if (!(node.flags & 1 /* Export */) && !(node.kind !== 194 /* ImportDeclaration */ && parent.kind !== 197 /* SourceFile */ && ts.isInAmbientContext(parent))) {
return isGlobalSourceFile(parent) || isUsedInExportAssignment(node);
}
return isDeclarationVisible(parent);
@@ -10187,9 +10746,10 @@ var ts;
case 129 /* CallSignature */:
case 131 /* IndexSignature */:
case 123 /* Parameter */:
- case 192 /* ModuleBlock */:
+ case 193 /* ModuleBlock */:
+ case 122 /* TypeParameter */:
return isDeclarationVisible(node.parent);
- case 196 /* SourceFile */:
+ case 197 /* SourceFile */:
return true;
default:
ts.Debug.fail("isDeclarationVisible unknown: SyntaxKind: " + node.kind);
@@ -10208,7 +10768,7 @@ var ts;
return classType.typeParameters ? createTypeReference(classType, ts.map(classType.typeParameters, function (_) { return anyType; })) : classType;
}
function getTypeOfVariableOrPropertyDeclaration(declaration) {
- if (declaration.parent.kind === 169 /* ForInStatement */) {
+ if (declaration.parent.kind === 170 /* ForInStatement */) {
return anyType;
}
if (declaration.type) {
@@ -10275,7 +10835,7 @@ var ts;
return links.type = getTypeOfPrototypeProperty(symbol);
}
var declaration = symbol.valueDeclaration;
- if (declaration.kind === 181 /* CatchBlock */) {
+ if (declaration.kind === 182 /* CatchBlock */) {
return links.type = anyType;
}
links.type = resolvingType;
@@ -10330,7 +10890,7 @@ var ts;
type = setterParameterType;
}
else {
- if (getter) {
+ if (getter && getter.body) {
type = getReturnTypeFromBody(getter);
}
else {
@@ -10415,7 +10975,7 @@ var ts;
function getTypeParametersOfClassOrInterface(symbol) {
var result;
ts.forEach(symbol.declarations, function (node) {
- if (node.kind === 188 /* InterfaceDeclaration */ || node.kind === 187 /* ClassDeclaration */) {
+ if (node.kind === 189 /* InterfaceDeclaration */ || node.kind === 188 /* ClassDeclaration */) {
var declaration = node;
if (declaration.typeParameters && declaration.typeParameters.length) {
ts.forEach(declaration.typeParameters, function (node) {
@@ -10446,7 +11006,7 @@ var ts;
type.typeArguments = type.typeParameters;
}
type.baseTypes = [];
- var declaration = getDeclarationOfKind(symbol, 187 /* ClassDeclaration */);
+ var declaration = getDeclarationOfKind(symbol, 188 /* ClassDeclaration */);
if (declaration.baseType) {
var baseType = getTypeFromTypeReferenceNode(declaration.baseType);
if (baseType !== unknownType) {
@@ -10486,7 +11046,7 @@ var ts;
}
type.baseTypes = [];
ts.forEach(symbol.declarations, function (declaration) {
- if (declaration.kind === 188 /* InterfaceDeclaration */ && declaration.baseTypes) {
+ if (declaration.kind === 189 /* InterfaceDeclaration */ && declaration.baseTypes) {
ts.forEach(declaration.baseTypes, function (node) {
var baseType = getTypeFromTypeReferenceNode(node);
if (baseType !== unknownType) {
@@ -10517,7 +11077,7 @@ var ts;
var links = getSymbolLinks(symbol);
if (!links.declaredType) {
links.declaredType = resolvingType;
- var declaration = getDeclarationOfKind(symbol, 189 /* TypeAliasDeclaration */);
+ var declaration = getDeclarationOfKind(symbol, 190 /* TypeAliasDeclaration */);
var type = getTypeFromTypeNode(declaration.type);
if (links.declaredType === resolvingType) {
links.declaredType = type;
@@ -10525,7 +11085,7 @@ var ts;
}
else if (links.declaredType === resolvingType) {
links.declaredType = unknownType;
- var declaration = getDeclarationOfKind(symbol, 189 /* TypeAliasDeclaration */);
+ var declaration = getDeclarationOfKind(symbol, 190 /* TypeAliasDeclaration */);
error(declaration.name, ts.Diagnostics.Type_alias_0_circularly_references_itself, symbolToString(symbol));
}
return links.declaredType;
@@ -10996,7 +11556,7 @@ var ts;
switch (node.kind) {
case 133 /* FunctionType */:
case 134 /* ConstructorType */:
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
case 125 /* Method */:
case 126 /* Constructor */:
case 129 /* CallSignature */:
@@ -11226,9 +11786,9 @@ var ts;
for (var i = 0; i < declarations.length; i++) {
var declaration = declarations[i];
switch (declaration.kind) {
- case 187 /* ClassDeclaration */:
- case 188 /* InterfaceDeclaration */:
- case 190 /* EnumDeclaration */:
+ case 188 /* ClassDeclaration */:
+ case 189 /* InterfaceDeclaration */:
+ case 191 /* EnumDeclaration */:
return declaration;
}
}
@@ -12537,7 +13097,7 @@ var ts;
switch (node.kind) {
case 156 /* BinaryExpression */:
return isAssignedInBinaryExpression(node);
- case 184 /* VariableDeclaration */:
+ case 185 /* VariableDeclaration */:
return isAssignedInVariableDeclaration(node);
case 141 /* ArrayLiteral */:
case 142 /* ObjectLiteral */:
@@ -12550,25 +13110,25 @@ var ts;
case 154 /* PrefixOperator */:
case 155 /* PostfixOperator */:
case 157 /* ConditionalExpression */:
- case 161 /* Block */:
- case 162 /* VariableStatement */:
- case 164 /* ExpressionStatement */:
- case 165 /* IfStatement */:
- case 166 /* DoStatement */:
- case 167 /* WhileStatement */:
- case 168 /* ForStatement */:
- case 169 /* ForInStatement */:
- case 172 /* ReturnStatement */:
- case 173 /* WithStatement */:
- case 174 /* SwitchStatement */:
- case 175 /* CaseClause */:
- case 176 /* DefaultClause */:
- case 177 /* LabeledStatement */:
- case 178 /* ThrowStatement */:
- case 179 /* TryStatement */:
- case 180 /* TryBlock */:
- case 181 /* CatchBlock */:
- case 182 /* FinallyBlock */:
+ case 162 /* Block */:
+ case 163 /* VariableStatement */:
+ case 165 /* ExpressionStatement */:
+ case 166 /* IfStatement */:
+ case 167 /* DoStatement */:
+ case 168 /* WhileStatement */:
+ case 169 /* ForStatement */:
+ case 170 /* ForInStatement */:
+ case 173 /* ReturnStatement */:
+ case 174 /* WithStatement */:
+ case 175 /* SwitchStatement */:
+ case 176 /* CaseClause */:
+ case 177 /* DefaultClause */:
+ case 178 /* LabeledStatement */:
+ case 179 /* ThrowStatement */:
+ case 180 /* TryStatement */:
+ case 181 /* TryBlock */:
+ case 182 /* CatchBlock */:
+ case 183 /* FinallyBlock */:
return ts.forEachChild(node, isAssignedIn);
}
return false;
@@ -12582,7 +13142,7 @@ var ts;
node = node.parent;
var narrowedType = type;
switch (node.kind) {
- case 165 /* IfStatement */:
+ case 166 /* IfStatement */:
if (child !== node.expression) {
narrowedType = narrowType(type, node.expression, child === node.thenStatement);
}
@@ -12602,9 +13162,9 @@ var ts;
}
}
break;
- case 196 /* SourceFile */:
- case 191 /* ModuleDeclaration */:
- case 185 /* FunctionDeclaration */:
+ case 197 /* SourceFile */:
+ case 192 /* ModuleDeclaration */:
+ case 186 /* FunctionDeclaration */:
case 125 /* Method */:
case 127 /* GetAccessor */:
case 128 /* SetAccessor */:
@@ -12714,7 +13274,7 @@ var ts;
return getNarrowedTypeOfSymbol(getExportSymbolOfValueSymbolIfExported(symbol), node);
}
function captureLexicalThis(node, container) {
- var classNode = container.parent && container.parent.kind === 187 /* ClassDeclaration */ ? container.parent : undefined;
+ var classNode = container.parent && container.parent.kind === 188 /* ClassDeclaration */ ? container.parent : undefined;
getNodeLinks(node).flags |= 2 /* LexicalThis */;
if (container.kind === 124 /* Property */ || container.kind === 126 /* Constructor */) {
getNodeLinks(classNode).flags |= 4 /* CaptureThis */;
@@ -12731,10 +13291,10 @@ var ts;
needToCaptureLexicalThis = true;
}
switch (container.kind) {
- case 191 /* ModuleDeclaration */:
+ case 192 /* ModuleDeclaration */:
error(node, ts.Diagnostics.this_cannot_be_referenced_in_a_module_body);
break;
- case 190 /* EnumDeclaration */:
+ case 191 /* EnumDeclaration */:
error(node, ts.Diagnostics.this_cannot_be_referenced_in_current_location);
break;
case 126 /* Constructor */:
@@ -12751,7 +13311,7 @@ var ts;
if (needToCaptureLexicalThis) {
captureLexicalThis(node, container);
}
- var classNode = container.parent && container.parent.kind === 187 /* ClassDeclaration */ ? container.parent : undefined;
+ var classNode = container.parent && container.parent.kind === 188 /* ClassDeclaration */ ? container.parent : undefined;
if (classNode) {
var symbol = getSymbolOfNode(classNode);
return container.flags & 128 /* Static */ ? getTypeOfSymbol(symbol) : getDeclaredTypeOfSymbol(symbol);
@@ -12764,7 +13324,7 @@ var ts;
if (!node)
return node;
switch (node.kind) {
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
case 152 /* FunctionExpression */:
case 153 /* ArrowFunction */:
case 124 /* Property */:
@@ -12786,7 +13346,7 @@ var ts;
}
function checkSuperExpression(node) {
var isCallExpression = node.parent.kind === 147 /* CallExpression */ && node.parent.func === node;
- var enclosingClass = ts.getAncestor(node, 187 /* ClassDeclaration */);
+ var enclosingClass = ts.getAncestor(node, 188 /* ClassDeclaration */);
var baseClass;
if (enclosingClass && enclosingClass.baseType) {
var classType = getDeclaredTypeOfSymbol(getSymbolOfNode(enclosingClass));
@@ -12808,7 +13368,7 @@ var ts;
container = getSuperContainer(container);
needToCaptureLexicalThis = true;
}
- if (container && container.parent && container.parent.kind === 187 /* ClassDeclaration */) {
+ if (container && container.parent && container.parent.kind === 188 /* ClassDeclaration */) {
if (container.flags & 128 /* Static */) {
canUseSuperExpression = container.kind === 125 /* Method */ || container.kind === 127 /* GetAccessor */ || container.kind === 128 /* SetAccessor */;
}
@@ -12986,12 +13546,12 @@ var ts;
}
var parent = node.parent;
switch (parent.kind) {
- case 184 /* VariableDeclaration */:
+ case 185 /* VariableDeclaration */:
case 123 /* Parameter */:
case 124 /* Property */:
return getContextualTypeForInitializerExpression(node);
case 153 /* ArrowFunction */:
- case 172 /* ReturnStatement */:
+ case 173 /* ReturnStatement */:
return getContextualTypeForReturnExpression(node);
case 147 /* CallExpression */:
case 148 /* NewExpression */:
@@ -13142,7 +13702,7 @@ var ts;
if (!(flags & (32 /* Private */ | 64 /* Protected */))) {
return;
}
- var enclosingClassDeclaration = ts.getAncestor(node, 187 /* ClassDeclaration */);
+ var enclosingClassDeclaration = ts.getAncestor(node, 188 /* ClassDeclaration */);
var enclosingClass = enclosingClassDeclaration ? getDeclaredTypeOfSymbol(getSymbolOfNode(enclosingClassDeclaration)) : undefined;
var declaringClass = getDeclaredTypeOfSymbol(prop.parent);
if (flags & 32 /* Private */) {
@@ -13327,7 +13887,7 @@ var ts;
var context = createInferenceContext(typeParameters, false);
var mapper = createInferenceMapper(context);
for (var i = 0; i < args.length; i++) {
- if (args[i].kind === 160 /* OmittedExpression */) {
+ if (args[i].kind === 161 /* OmittedExpression */) {
continue;
}
if (!excludeArgument || excludeArgument[i] === undefined) {
@@ -13341,7 +13901,7 @@ var ts;
}
if (excludeArgument) {
for (var i = 0; i < args.length; i++) {
- if (args[i].kind === 160 /* OmittedExpression */) {
+ if (args[i].kind === 161 /* OmittedExpression */) {
continue;
}
if (excludeArgument[i] === false) {
@@ -13379,7 +13939,7 @@ var ts;
for (var i = 0; i < args.length; i++) {
var arg = args[i];
var argType;
- if (arg.kind === 160 /* OmittedExpression */) {
+ if (arg.kind === 161 /* OmittedExpression */) {
continue;
}
var paramType = getTypeAtPosition(signature, i);
@@ -13702,7 +14262,7 @@ var ts;
}
function getReturnTypeFromBody(func, contextualMapper) {
var contextualSignature = getContextualSignature(func);
- if (func.body.kind !== 186 /* FunctionBlock */) {
+ if (func.body.kind !== 187 /* FunctionBlock */) {
var unwidenedType = checkAndMarkExpression(func.body, contextualMapper);
var widenedType = getWidenedType(unwidenedType);
if (fullTypeCheck && compilerOptions.noImplicitAny && !contextualSignature && widenedType !== unwidenedType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) {
@@ -13750,7 +14310,7 @@ var ts;
});
}
function bodyContainsSingleThrowStatement(body) {
- return (body.statements.length === 1) && (body.statements[0].kind === 178 /* ThrowStatement */);
+ return (body.statements.length === 1) && (body.statements[0].kind === 179 /* ThrowStatement */);
}
function checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(func, returnType) {
if (!fullTypeCheck) {
@@ -13759,7 +14319,7 @@ var ts;
if (returnType === voidType || returnType === anyType) {
return;
}
- if (!func.body || func.body.kind !== 186 /* FunctionBlock */) {
+ if (!func.body || func.body.kind !== 187 /* FunctionBlock */) {
return;
}
var bodyBlock = func.body;
@@ -13803,7 +14363,7 @@ var ts;
if (node.type) {
checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type));
}
- if (node.body.kind === 186 /* FunctionBlock */) {
+ if (node.body.kind === 187 /* FunctionBlock */) {
checkSourceElement(node.body);
}
else {
@@ -14151,7 +14711,7 @@ var ts;
return checkBinaryExpression(node, contextualMapper);
case 157 /* ConditionalExpression */:
return checkConditionalExpression(node, contextualMapper);
- case 160 /* OmittedExpression */:
+ case 161 /* OmittedExpression */:
return undefinedType;
}
return unknownType;
@@ -14231,7 +14791,7 @@ var ts;
checkSpecializedSignatureDeclaration(node);
}
function checkTypeForDuplicateIndexSignatures(node) {
- if (node.kind === 188 /* InterfaceDeclaration */) {
+ if (node.kind === 189 /* InterfaceDeclaration */) {
var nodeSymbol = getSymbolOfNode(node);
if (nodeSymbol.declarations.length > 0 && nodeSymbol.declarations[0] !== node) {
return;
@@ -14295,7 +14855,7 @@ var ts;
}
switch (n.kind) {
case 152 /* FunctionExpression */:
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
case 153 /* ArrowFunction */:
case 142 /* ObjectLiteral */: return false;
default: return ts.forEachChild(n, containsSuperCall);
@@ -14305,7 +14865,7 @@ var ts;
if (n.kind === 91 /* ThisKeyword */) {
error(n, ts.Diagnostics.this_cannot_be_referenced_in_current_location);
}
- else if (n.kind !== 152 /* FunctionExpression */ && n.kind !== 185 /* FunctionDeclaration */) {
+ else if (n.kind !== 152 /* FunctionExpression */ && n.kind !== 186 /* FunctionDeclaration */) {
ts.forEachChild(n, markThisReferencesAsErrors);
}
}
@@ -14317,7 +14877,7 @@ var ts;
var superCallShouldBeFirst = ts.forEach(node.parent.members, isInstancePropertyWithInitializer) || ts.forEach(node.parameters, function (p) { return p.flags & (16 /* Public */ | 32 /* Private */ | 64 /* Protected */); });
if (superCallShouldBeFirst) {
var statements = node.body.statements;
- if (!statements.length || statements[0].kind !== 164 /* ExpressionStatement */ || !isSuperCallExpression(statements[0].expression)) {
+ if (!statements.length || statements[0].kind !== 165 /* ExpressionStatement */ || !isSuperCallExpression(statements[0].expression)) {
error(node, ts.Diagnostics.A_super_call_must_be_the_first_statement_in_the_constructor_when_a_class_contains_initialized_properties_or_has_parameter_properties);
}
else {
@@ -14405,7 +14965,7 @@ var ts;
return;
}
var signaturesToCheck;
- if (!signatureDeclarationNode.name && signatureDeclarationNode.parent && signatureDeclarationNode.parent.kind === 188 /* InterfaceDeclaration */) {
+ if (!signatureDeclarationNode.name && signatureDeclarationNode.parent && signatureDeclarationNode.parent.kind === 189 /* InterfaceDeclaration */) {
ts.Debug.assert(signatureDeclarationNode.kind === 129 /* CallSignature */ || signatureDeclarationNode.kind === 130 /* ConstructSignature */);
var signatureKind = signatureDeclarationNode.kind === 129 /* CallSignature */ ? 0 /* Call */ : 1 /* Construct */;
var containingSymbol = getSymbolOfNode(signatureDeclarationNode.parent);
@@ -14425,7 +14985,7 @@ var ts;
}
function getEffectiveDeclarationFlags(n, flagsToCheck) {
var flags = n.flags;
- if (n.parent.kind !== 188 /* InterfaceDeclaration */ && ts.isInAmbientContext(n)) {
+ if (n.parent.kind !== 189 /* InterfaceDeclaration */ && ts.isInAmbientContext(n)) {
if (!(flags & 2 /* Ambient */)) {
flags |= 1 /* Export */;
}
@@ -14511,11 +15071,11 @@ var ts;
for (var i = 0; i < declarations.length; i++) {
var node = declarations[i];
var inAmbientContext = ts.isInAmbientContext(node);
- var inAmbientContextOrInterface = node.parent.kind === 188 /* InterfaceDeclaration */ || node.parent.kind === 136 /* TypeLiteral */ || inAmbientContext;
+ var inAmbientContextOrInterface = node.parent.kind === 189 /* InterfaceDeclaration */ || node.parent.kind === 136 /* TypeLiteral */ || inAmbientContext;
if (inAmbientContextOrInterface) {
previousDeclaration = undefined;
}
- if (node.kind === 185 /* FunctionDeclaration */ || node.kind === 125 /* Method */ || node.kind === 126 /* Constructor */) {
+ if (node.kind === 186 /* FunctionDeclaration */ || node.kind === 125 /* Method */ || node.kind === 126 /* Constructor */) {
var currentNodeFlags = getEffectiveDeclarationFlags(node, flagsToCheck);
someNodeFlags |= currentNodeFlags;
allNodeFlags &= currentNodeFlags;
@@ -14609,14 +15169,14 @@ var ts;
}
function getDeclarationSpaces(d) {
switch (d.kind) {
- case 188 /* InterfaceDeclaration */:
+ case 189 /* InterfaceDeclaration */:
return 8388608 /* ExportType */;
- case 191 /* ModuleDeclaration */:
+ case 192 /* ModuleDeclaration */:
return d.name.kind === 7 /* StringLiteral */ || ts.getModuleInstanceState(d) !== 0 /* NonInstantiated */ ? 16777216 /* ExportNamespace */ | 4194304 /* ExportValue */ : 16777216 /* ExportNamespace */;
- case 187 /* ClassDeclaration */:
- case 190 /* EnumDeclaration */:
+ case 188 /* ClassDeclaration */:
+ case 191 /* EnumDeclaration */:
return 8388608 /* ExportType */ | 4194304 /* ExportValue */;
- case 193 /* ImportDeclaration */:
+ case 194 /* ImportDeclaration */:
var result = 0;
var target = resolveImport(getSymbolOfNode(d));
ts.forEach(target.declarations, function (d) {
@@ -14691,7 +15251,7 @@ var ts;
return;
}
switch (current.kind) {
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
case 152 /* FunctionExpression */:
case 125 /* Method */:
case 153 /* ArrowFunction */:
@@ -14746,7 +15306,7 @@ var ts;
if (!needCollisionCheckForIdentifier(node, name, "_super")) {
return;
}
- var enclosingClass = ts.getAncestor(node, 187 /* ClassDeclaration */);
+ var enclosingClass = ts.getAncestor(node, 188 /* ClassDeclaration */);
if (!enclosingClass || ts.isInAmbientContext(enclosingClass)) {
return;
}
@@ -14764,11 +15324,11 @@ var ts;
if (!needCollisionCheckForIdentifier(node, name, "require") && !needCollisionCheckForIdentifier(node, name, "exports")) {
return;
}
- if (node.kind === 191 /* ModuleDeclaration */ && ts.getModuleInstanceState(node) !== 1 /* Instantiated */) {
+ if (node.kind === 192 /* ModuleDeclaration */ && ts.getModuleInstanceState(node) !== 1 /* Instantiated */) {
return;
}
- var parent = node.kind === 184 /* VariableDeclaration */ ? node.parent.parent : node.parent;
- if (parent.kind === 196 /* SourceFile */ && ts.isExternalModule(parent)) {
+ var parent = node.kind === 185 /* VariableDeclaration */ ? node.parent.parent : node.parent;
+ if (parent.kind === 197 /* SourceFile */ && ts.isExternalModule(parent)) {
error(name, ts.Diagnostics.Duplicate_identifier_0_Compiler_reserves_name_1_in_top_level_scope_of_an_external_module, ts.declarationNameToString(name), ts.declarationNameToString(name));
}
}
@@ -14846,10 +15406,13 @@ var ts;
checkSourceElement(node.statement);
}
function checkForInStatement(node) {
- if (node.declaration) {
- checkVariableDeclaration(node.declaration);
- if (node.declaration.type) {
- error(node.declaration, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation);
+ if (node.declarations) {
+ if (node.declarations.length >= 1) {
+ var decl = node.declarations[0];
+ checkVariableDeclaration(decl);
+ if (decl.type) {
+ error(decl, ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation);
+ }
}
}
if (node.variable) {
@@ -15156,7 +15719,7 @@ var ts;
checkTypeNameIsReserved(node.name, ts.Diagnostics.Interface_name_cannot_be_0);
checkExportsOnMergedDeclarations(node);
var symbol = getSymbolOfNode(node);
- var firstInterfaceDecl = getDeclarationOfKind(symbol, 188 /* InterfaceDeclaration */);
+ var firstInterfaceDecl = getDeclarationOfKind(symbol, 189 /* InterfaceDeclaration */);
if (symbol.declarations.length > 1) {
if (node !== firstInterfaceDecl && !areTypeParametersIdentical(firstInterfaceDecl.typeParameters, node.typeParameters)) {
error(node.name, ts.Diagnostics.All_declarations_of_an_interface_must_have_identical_type_parameters);
@@ -15189,7 +15752,7 @@ var ts;
var enumType = getDeclaredTypeOfSymbol(enumSymbol);
var autoValue = 0;
var ambient = ts.isInAmbientContext(node);
- var enumIsConst = ts.isConstEnumDeclaration(node);
+ var enumIsConst = ts.isConst(node);
ts.forEach(node.members, function (member) {
if (isNumericName(member.name.text)) {
error(member.name, ts.Diagnostics.An_enum_member_cannot_have_a_numeric_name);
@@ -15330,7 +15893,7 @@ var ts;
var firstDeclaration = getDeclarationOfKind(enumSymbol, node.kind);
if (node === firstDeclaration) {
if (enumSymbol.declarations.length > 1) {
- var enumIsConst = ts.isConstEnumDeclaration(node);
+ var enumIsConst = ts.isConst(node);
ts.forEach(enumSymbol.declarations, function (decl) {
if (ts.isConstEnumDeclaration(decl) !== enumIsConst) {
error(decl.name, ts.Diagnostics.Enum_declarations_must_all_be_const_or_non_const);
@@ -15339,7 +15902,7 @@ var ts;
}
var seenEnumMissingInitialInitializer = false;
ts.forEach(enumSymbol.declarations, function (declaration) {
- if (declaration.kind !== 190 /* EnumDeclaration */) {
+ if (declaration.kind !== 191 /* EnumDeclaration */) {
return false;
}
var enumDeclaration = declaration;
@@ -15362,7 +15925,7 @@ var ts;
var declarations = symbol.declarations;
for (var i = 0; i < declarations.length; i++) {
var declaration = declarations[i];
- if ((declaration.kind === 187 /* ClassDeclaration */ || (declaration.kind === 185 /* FunctionDeclaration */ && declaration.body)) && !ts.isInAmbientContext(declaration)) {
+ if ((declaration.kind === 188 /* ClassDeclaration */ || (declaration.kind === 186 /* FunctionDeclaration */ && declaration.body)) && !ts.isInAmbientContext(declaration)) {
return declaration;
}
}
@@ -15425,10 +15988,10 @@ var ts;
}
}
else {
- if (node.parent.kind === 196 /* SourceFile */) {
+ if (node.parent.kind === 197 /* SourceFile */) {
target = resolveImport(symbol);
}
- else if (node.parent.kind === 192 /* ModuleBlock */ && node.parent.parent.name.kind === 7 /* StringLiteral */) {
+ else if (node.parent.kind === 193 /* ModuleBlock */ && node.parent.parent.name.kind === 7 /* StringLiteral */) {
if (isExternalModuleNameRelative(node.externalModuleName.text)) {
error(node, ts.Diagnostics.Import_declaration_in_an_ambient_external_module_declaration_cannot_reference_external_module_through_relative_external_module_name);
target = unknownSymbol;
@@ -15450,7 +16013,7 @@ var ts;
}
function checkExportAssignment(node) {
var container = node.parent;
- if (container.kind !== 196 /* SourceFile */) {
+ if (container.kind !== 197 /* SourceFile */) {
container = container.parent;
}
checkTypeOfExportAssignmentSymbol(getSymbolOfNode(container));
@@ -15492,57 +16055,57 @@ var ts;
return checkUnionType(node);
case 140 /* ParenType */:
return checkSourceElement(node.type);
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
return checkFunctionDeclaration(node);
- case 161 /* Block */:
+ case 162 /* Block */:
return checkBlock(node);
- case 186 /* FunctionBlock */:
- case 192 /* ModuleBlock */:
+ case 187 /* FunctionBlock */:
+ case 193 /* ModuleBlock */:
return checkBody(node);
- case 162 /* VariableStatement */:
+ case 163 /* VariableStatement */:
return checkVariableStatement(node);
- case 164 /* ExpressionStatement */:
+ case 165 /* ExpressionStatement */:
return checkExpressionStatement(node);
- case 165 /* IfStatement */:
+ case 166 /* IfStatement */:
return checkIfStatement(node);
- case 166 /* DoStatement */:
+ case 167 /* DoStatement */:
return checkDoStatement(node);
- case 167 /* WhileStatement */:
+ case 168 /* WhileStatement */:
return checkWhileStatement(node);
- case 168 /* ForStatement */:
+ case 169 /* ForStatement */:
return checkForStatement(node);
- case 169 /* ForInStatement */:
+ case 170 /* ForInStatement */:
return checkForInStatement(node);
- case 170 /* ContinueStatement */:
- case 171 /* BreakStatement */:
+ case 171 /* ContinueStatement */:
+ case 172 /* BreakStatement */:
return checkBreakOrContinueStatement(node);
- case 172 /* ReturnStatement */:
+ case 173 /* ReturnStatement */:
return checkReturnStatement(node);
- case 173 /* WithStatement */:
+ case 174 /* WithStatement */:
return checkWithStatement(node);
- case 174 /* SwitchStatement */:
+ case 175 /* SwitchStatement */:
return checkSwitchStatement(node);
- case 177 /* LabeledStatement */:
+ case 178 /* LabeledStatement */:
return checkLabeledStatement(node);
- case 178 /* ThrowStatement */:
+ case 179 /* ThrowStatement */:
return checkThrowStatement(node);
- case 179 /* TryStatement */:
+ case 180 /* TryStatement */:
return checkTryStatement(node);
- case 184 /* VariableDeclaration */:
+ case 185 /* VariableDeclaration */:
return ts.Debug.fail("Checker encountered variable declaration");
- case 187 /* ClassDeclaration */:
+ case 188 /* ClassDeclaration */:
return checkClassDeclaration(node);
- case 188 /* InterfaceDeclaration */:
+ case 189 /* InterfaceDeclaration */:
return checkInterfaceDeclaration(node);
- case 189 /* TypeAliasDeclaration */:
+ case 190 /* TypeAliasDeclaration */:
return checkTypeAliasDeclaration(node);
- case 190 /* EnumDeclaration */:
+ case 191 /* EnumDeclaration */:
return checkEnumDeclaration(node);
- case 191 /* ModuleDeclaration */:
+ case 192 /* ModuleDeclaration */:
return checkModuleDeclaration(node);
- case 193 /* ImportDeclaration */:
+ case 194 /* ImportDeclaration */:
return checkImportDeclaration(node);
- case 194 /* ExportAssignment */:
+ case 195 /* ExportAssignment */:
return checkExportAssignment(node);
}
}
@@ -15557,10 +16120,10 @@ var ts;
case 126 /* Constructor */:
case 127 /* GetAccessor */:
case 128 /* SetAccessor */:
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
ts.forEach(node.parameters, checkFunctionExpressionBodies);
break;
- case 173 /* WithStatement */:
+ case 174 /* WithStatement */:
checkFunctionExpressionBodies(node.expression);
break;
case 123 /* Parameter */:
@@ -15579,33 +16142,33 @@ var ts;
case 155 /* PostfixOperator */:
case 156 /* BinaryExpression */:
case 157 /* ConditionalExpression */:
- case 161 /* Block */:
- case 186 /* FunctionBlock */:
- case 192 /* ModuleBlock */:
- case 162 /* VariableStatement */:
- case 164 /* ExpressionStatement */:
- case 165 /* IfStatement */:
- case 166 /* DoStatement */:
- case 167 /* WhileStatement */:
- case 168 /* ForStatement */:
- case 169 /* ForInStatement */:
- case 170 /* ContinueStatement */:
- case 171 /* BreakStatement */:
- case 172 /* ReturnStatement */:
- case 174 /* SwitchStatement */:
- case 175 /* CaseClause */:
- case 176 /* DefaultClause */:
- case 177 /* LabeledStatement */:
- case 178 /* ThrowStatement */:
- case 179 /* TryStatement */:
- case 180 /* TryBlock */:
- case 181 /* CatchBlock */:
- case 182 /* FinallyBlock */:
- case 184 /* VariableDeclaration */:
- case 187 /* ClassDeclaration */:
- case 190 /* EnumDeclaration */:
- case 195 /* EnumMember */:
- case 196 /* SourceFile */:
+ case 162 /* Block */:
+ case 187 /* FunctionBlock */:
+ case 193 /* ModuleBlock */:
+ case 163 /* VariableStatement */:
+ case 165 /* ExpressionStatement */:
+ case 166 /* IfStatement */:
+ case 167 /* DoStatement */:
+ case 168 /* WhileStatement */:
+ case 169 /* ForStatement */:
+ case 170 /* ForInStatement */:
+ case 171 /* ContinueStatement */:
+ case 172 /* BreakStatement */:
+ case 173 /* ReturnStatement */:
+ case 175 /* SwitchStatement */:
+ case 176 /* CaseClause */:
+ case 177 /* DefaultClause */:
+ case 178 /* LabeledStatement */:
+ case 179 /* ThrowStatement */:
+ case 180 /* TryStatement */:
+ case 181 /* TryBlock */:
+ case 182 /* CatchBlock */:
+ case 183 /* FinallyBlock */:
+ case 185 /* VariableDeclaration */:
+ case 188 /* ClassDeclaration */:
+ case 191 /* EnumDeclaration */:
+ case 196 /* EnumMember */:
+ case 197 /* SourceFile */:
ts.forEachChild(node, checkFunctionExpressionBodies);
break;
}
@@ -15655,6 +16218,11 @@ var ts;
checkProgram();
return getSortedDiagnostics();
}
+ function getDeclarationDiagnostics(targetSourceFile) {
+ var resolver = createResolver();
+ checkSourceFile(targetSourceFile);
+ return ts.getDeclarationDiagnostics(program, resolver, targetSourceFile);
+ }
function getGlobalDiagnostics() {
return ts.filter(getSortedDiagnostics(), function (d) { return !d.file; });
}
@@ -15676,7 +16244,7 @@ var ts;
function isInsideWithStatementBody(node) {
if (node) {
while (node.parent) {
- if (node.parent.kind === 173 /* WithStatement */ && node.parent.statement === node) {
+ if (node.parent.kind === 174 /* WithStatement */ && node.parent.statement === node) {
return true;
}
node = node.parent;
@@ -15712,17 +16280,17 @@ var ts;
copySymbols(location.locals, meaning);
}
switch (location.kind) {
- case 196 /* SourceFile */:
+ case 197 /* SourceFile */:
if (!ts.isExternalModule(location))
break;
- case 191 /* ModuleDeclaration */:
+ case 192 /* ModuleDeclaration */:
copySymbols(getSymbolOfNode(location).exports, meaning & 35653619 /* ModuleMember */);
break;
- case 190 /* EnumDeclaration */:
+ case 191 /* EnumDeclaration */:
copySymbols(getSymbolOfNode(location).exports, meaning & 8 /* EnumMember */);
break;
- case 187 /* ClassDeclaration */:
- case 188 /* InterfaceDeclaration */:
+ case 188 /* ClassDeclaration */:
+ case 189 /* InterfaceDeclaration */:
if (!(memberFlags & 128 /* Static */)) {
copySymbols(getSymbolOfNode(location).members, meaning & 3152352 /* Type */);
}
@@ -15732,7 +16300,7 @@ var ts;
copySymbol(location.symbol, meaning);
}
break;
- case 181 /* CatchBlock */:
+ case 182 /* CatchBlock */:
if (location.variable.text) {
copySymbol(location.symbol, meaning);
}
@@ -15750,10 +16318,10 @@ var ts;
function isTypeDeclaration(node) {
switch (node.kind) {
case 122 /* TypeParameter */:
- case 187 /* ClassDeclaration */:
- case 188 /* InterfaceDeclaration */:
- case 189 /* TypeAliasDeclaration */:
- case 190 /* EnumDeclaration */:
+ case 188 /* ClassDeclaration */:
+ case 189 /* InterfaceDeclaration */:
+ case 190 /* TypeAliasDeclaration */:
+ case 191 /* EnumDeclaration */:
return true;
}
}
@@ -15795,9 +16363,9 @@ var ts;
return node === parent.constraint;
case 124 /* Property */:
case 123 /* Parameter */:
- case 184 /* VariableDeclaration */:
+ case 185 /* VariableDeclaration */:
return node === parent.type;
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
case 152 /* FunctionExpression */:
case 153 /* ArrowFunction */:
case 126 /* Constructor */:
@@ -15824,10 +16392,10 @@ var ts;
while (node.parent.kind === 121 /* QualifiedName */) {
node = node.parent;
}
- if (node.parent.kind === 193 /* ImportDeclaration */) {
+ if (node.parent.kind === 194 /* ImportDeclaration */) {
return node.parent.entityName === node;
}
- if (node.parent.kind === 194 /* ExportAssignment */) {
+ if (node.parent.kind === 195 /* ExportAssignment */) {
return node.parent.exportName === node;
}
return false;
@@ -15839,7 +16407,7 @@ var ts;
if (ts.isDeclarationOrFunctionExpressionOrCatchVariableName(entityName)) {
return getSymbolOfNode(entityName.parent);
}
- if (entityName.parent.kind === 194 /* ExportAssignment */) {
+ if (entityName.parent.kind === 195 /* ExportAssignment */) {
return resolveEntityName(entityName.parent.parent, entityName, 107455 /* Value */ | 3152352 /* Type */ | 1536 /* Namespace */ | 33554432 /* Import */);
}
if (isInRightSideOfImportOrExportAssignment(entityName)) {
@@ -15879,7 +16447,7 @@ var ts;
return getSymbolOfNode(node.parent);
}
if (node.kind === 63 /* Identifier */ && isInRightSideOfImportOrExportAssignment(node)) {
- return node.parent.kind === 194 /* ExportAssignment */ ? getSymbolOfEntityName(node) : getSymbolOfPartOfRightHandSideOfImport(node);
+ return node.parent.kind === 195 /* ExportAssignment */ ? getSymbolOfEntityName(node) : getSymbolOfPartOfRightHandSideOfImport(node);
}
switch (node.kind) {
case 63 /* Identifier */:
@@ -15897,7 +16465,7 @@ var ts;
}
return undefined;
case 7 /* StringLiteral */:
- if (node.parent.kind === 193 /* ImportDeclaration */ && node.parent.externalModuleName === node) {
+ if (node.parent.kind === 194 /* ImportDeclaration */ && node.parent.externalModuleName === node) {
var importSymbol = getSymbolOfNode(node.parent);
var moduleType = getTypeOfSymbol(importSymbol);
return moduleType ? moduleType.symbol : undefined;
@@ -15991,7 +16559,7 @@ var ts;
return [symbol];
}
function isExternalModuleSymbol(symbol) {
- return symbol.flags & 512 /* ValueModule */ && symbol.declarations.length === 1 && symbol.declarations[0].kind === 196 /* SourceFile */;
+ return symbol.flags & 512 /* ValueModule */ && symbol.declarations.length === 1 && symbol.declarations[0].kind === 197 /* SourceFile */;
}
function isNodeDescendentOf(node, ancestor) {
while (node) {
@@ -16024,7 +16592,7 @@ var ts;
function getLocalNameForSymbol(symbol, location) {
var node = location;
while (node) {
- if ((node.kind === 191 /* ModuleDeclaration */ || node.kind === 190 /* EnumDeclaration */) && getSymbolOfNode(node) === symbol) {
+ if ((node.kind === 192 /* ModuleDeclaration */ || node.kind === 191 /* EnumDeclaration */) && getSymbolOfNode(node) === symbol) {
return getLocalNameOfContainer(node);
}
node = node.parent;
@@ -16048,7 +16616,7 @@ var ts;
return symbol && symbolIsValue(symbol) && !isConstEnumSymbol(symbol) ? symbolToString(symbol) : undefined;
}
function isTopLevelValueImportWithEntityName(node) {
- if (node.parent.kind !== 196 /* SourceFile */ || !node.entityName) {
+ if (node.parent.kind !== 197 /* SourceFile */ || !node.entityName) {
return false;
}
return isImportResolvedToValue(getSymbolOfNode(node));
@@ -16099,7 +16667,7 @@ var ts;
if (symbol && (symbol.flags & 8 /* EnumMember */)) {
var declaration = symbol.valueDeclaration;
var constantValue;
- if (declaration.kind === 195 /* EnumMember */ && (constantValue = getNodeLinks(declaration).enumMemberValue) !== undefined) {
+ if (declaration.kind === 196 /* EnumMember */ && (constantValue = getNodeLinks(declaration).enumMemberValue) !== undefined) {
return constantValue;
}
}
@@ -16114,8 +16682,8 @@ var ts;
var signature = getSignatureFromDeclaration(signatureDeclaration);
getSymbolDisplayBuilder().buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags);
}
- function invokeEmitter(targetSourceFile) {
- var resolver = {
+ function createResolver() {
+ return {
getProgram: function () { return program; },
getLocalNameOfContainer: getLocalNameOfContainer,
getExpressionNamePrefix: getExpressionNamePrefix,
@@ -16131,16 +16699,19 @@ var ts;
writeTypeAtLocation: writeTypeAtLocation,
writeReturnTypeOfSignatureDeclaration: writeReturnTypeOfSignatureDeclaration,
isSymbolAccessible: isSymbolAccessible,
- isImportDeclarationEntityNameReferenceDeclarationVisibile: isImportDeclarationEntityNameReferenceDeclarationVisibile,
+ isEntityNameVisible: isEntityNameVisible,
getConstantValue: getConstantValue
};
+ }
+ function invokeEmitter(targetSourceFile) {
+ var resolver = createResolver();
checkProgram();
return ts.emitFiles(resolver, targetSourceFile);
}
function initializeTypeChecker() {
ts.forEach(program.getSourceFiles(), function (file) {
ts.bindSourceFile(file);
- ts.forEach(file.semanticErrors, addDiagnostic);
+ ts.forEach(file.semanticDiagnostics, addDiagnostic);
});
ts.forEach(program.getSourceFiles(), function (file) {
if (!ts.isExternalModule(file)) {
@@ -16303,10 +16874,10 @@ var ts;
}
function autoCollapse(node) {
switch (node.kind) {
- case 192 /* ModuleBlock */:
- case 187 /* ClassDeclaration */:
- case 188 /* InterfaceDeclaration */:
- case 190 /* EnumDeclaration */:
+ case 193 /* ModuleBlock */:
+ case 188 /* ClassDeclaration */:
+ case 189 /* InterfaceDeclaration */:
+ case 191 /* EnumDeclaration */:
return false;
}
return true;
@@ -16318,11 +16889,11 @@ var ts;
return;
}
switch (n.kind) {
- case 161 /* Block */:
+ case 162 /* Block */:
var parent = n.parent;
var openBrace = ts.findChildOfKind(n, 13 /* OpenBraceToken */, sourceFile);
var closeBrace = ts.findChildOfKind(n, 14 /* CloseBraceToken */, sourceFile);
- if (parent.kind === 166 /* DoStatement */ || parent.kind === 169 /* ForInStatement */ || parent.kind === 168 /* ForStatement */ || parent.kind === 165 /* IfStatement */ || parent.kind === 167 /* WhileStatement */ || parent.kind === 173 /* WithStatement */) {
+ if (parent.kind === 167 /* DoStatement */ || parent.kind === 170 /* ForInStatement */ || parent.kind === 169 /* ForStatement */ || parent.kind === 166 /* IfStatement */ || parent.kind === 168 /* WhileStatement */ || parent.kind === 174 /* WithStatement */) {
addOutliningSpan(parent, openBrace, closeBrace, autoCollapse(n));
}
else {
@@ -16335,20 +16906,20 @@ var ts;
});
}
break;
- case 186 /* FunctionBlock */:
- case 192 /* ModuleBlock */:
- case 180 /* TryBlock */:
- case 181 /* CatchBlock */:
- case 182 /* FinallyBlock */:
+ case 187 /* FunctionBlock */:
+ case 193 /* ModuleBlock */:
+ case 181 /* TryBlock */:
+ case 182 /* CatchBlock */:
+ case 183 /* FinallyBlock */:
var openBrace = ts.findChildOfKind(n, 13 /* OpenBraceToken */, sourceFile);
var closeBrace = ts.findChildOfKind(n, 14 /* CloseBraceToken */, sourceFile);
addOutliningSpan(n.parent, openBrace, closeBrace, autoCollapse(n));
break;
- case 187 /* ClassDeclaration */:
- case 188 /* InterfaceDeclaration */:
- case 190 /* EnumDeclaration */:
+ case 188 /* ClassDeclaration */:
+ case 189 /* InterfaceDeclaration */:
+ case 191 /* EnumDeclaration */:
case 142 /* ObjectLiteral */:
- case 174 /* SwitchStatement */:
+ case 175 /* SwitchStatement */:
var openBrace = ts.findChildOfKind(n, 13 /* OpenBraceToken */, sourceFile);
var closeBrace = ts.findChildOfKind(n, 14 /* CloseBraceToken */, sourceFile);
addOutliningSpan(n, openBrace, closeBrace, autoCollapse(n));
@@ -16381,14 +16952,14 @@ var ts;
var current = node.parent;
while (current) {
switch (current.kind) {
- case 191 /* ModuleDeclaration */:
+ case 192 /* ModuleDeclaration */:
do {
current = current.parent;
- } while (current.kind === 191 /* ModuleDeclaration */);
- case 187 /* ClassDeclaration */:
- case 190 /* EnumDeclaration */:
- case 188 /* InterfaceDeclaration */:
- case 185 /* FunctionDeclaration */:
+ } while (current.kind === 192 /* ModuleDeclaration */);
+ case 188 /* ClassDeclaration */:
+ case 191 /* EnumDeclaration */:
+ case 189 /* InterfaceDeclaration */:
+ case 186 /* FunctionDeclaration */:
indent++;
}
current = current.parent;
@@ -16399,10 +16970,10 @@ var ts;
var childNodes = [];
for (var i = 0, n = nodes.length; i < n; i++) {
var node = nodes[i];
- if (node.kind === 187 /* ClassDeclaration */ || node.kind === 190 /* EnumDeclaration */ || node.kind === 188 /* InterfaceDeclaration */ || node.kind === 191 /* ModuleDeclaration */ || node.kind === 185 /* FunctionDeclaration */) {
+ if (node.kind === 188 /* ClassDeclaration */ || node.kind === 191 /* EnumDeclaration */ || node.kind === 189 /* InterfaceDeclaration */ || node.kind === 192 /* ModuleDeclaration */ || node.kind === 186 /* FunctionDeclaration */) {
childNodes.push(node);
}
- else if (node.kind === 162 /* VariableStatement */) {
+ else if (node.kind === 163 /* VariableStatement */) {
childNodes.push.apply(childNodes, node.declarations);
}
}
@@ -16435,17 +17006,17 @@ var ts;
for (var i = 0, n = nodes.length; i < n; i++) {
var node = nodes[i];
switch (node.kind) {
- case 187 /* ClassDeclaration */:
- case 190 /* EnumDeclaration */:
- case 188 /* InterfaceDeclaration */:
+ case 188 /* ClassDeclaration */:
+ case 191 /* EnumDeclaration */:
+ case 189 /* InterfaceDeclaration */:
topLevelNodes.push(node);
break;
- case 191 /* ModuleDeclaration */:
+ case 192 /* ModuleDeclaration */:
var moduleDeclaration = node;
topLevelNodes.push(node);
addTopLevelNodes(getInnermostModule(moduleDeclaration).body.statements, topLevelNodes);
break;
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
var functionDeclaration = node;
if (isTopLevelFunctionDeclaration(functionDeclaration)) {
topLevelNodes.push(node);
@@ -16456,12 +17027,12 @@ var ts;
}
}
function isTopLevelFunctionDeclaration(functionDeclaration) {
- if (functionDeclaration.kind === 185 /* FunctionDeclaration */) {
- if (functionDeclaration.body && functionDeclaration.body.kind === 186 /* FunctionBlock */) {
- if (ts.forEach(functionDeclaration.body.statements, function (s) { return s.kind === 185 /* FunctionDeclaration */ && !isEmpty(s.name.text); })) {
+ if (functionDeclaration.kind === 186 /* FunctionDeclaration */) {
+ if (functionDeclaration.body && functionDeclaration.body.kind === 187 /* FunctionBlock */) {
+ if (ts.forEach(functionDeclaration.body.statements, function (s) { return s.kind === 186 /* FunctionDeclaration */ && !isEmpty(s.name.text); })) {
return true;
}
- if (functionDeclaration.parent.kind !== 186 /* FunctionBlock */) {
+ if (functionDeclaration.parent.kind !== 187 /* FunctionBlock */) {
return true;
}
}
@@ -16524,7 +17095,7 @@ var ts;
return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberSetAccessorElement);
case 131 /* IndexSignature */:
return createItem(node, "[]", ts.ScriptElementKind.indexSignatureElement);
- case 195 /* EnumMember */:
+ case 196 /* EnumMember */:
return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberVariableElement);
case 129 /* CallSignature */:
return createItem(node, "()", ts.ScriptElementKind.callSignatureElement);
@@ -16532,11 +17103,14 @@ var ts;
return createItem(node, "new()", ts.ScriptElementKind.constructSignatureElement);
case 124 /* Property */:
return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.memberVariableElement);
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.functionElement);
- case 184 /* VariableDeclaration */:
- if (node.flags & 4096 /* Const */) {
- return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.constantElement);
+ case 185 /* VariableDeclaration */:
+ if (ts.isConst(node)) {
+ return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.constElement);
+ }
+ else if (ts.isLet(node)) {
+ return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.letElement);
}
else {
return createItem(node, getTextOfNode(node.name), ts.ScriptElementKind.variableElement);
@@ -16571,17 +17145,17 @@ var ts;
}
function createTopLevelItem(node) {
switch (node.kind) {
- case 196 /* SourceFile */:
+ case 197 /* SourceFile */:
return createSourceFileItem(node);
- case 187 /* ClassDeclaration */:
+ case 188 /* ClassDeclaration */:
return createClassItem(node);
- case 190 /* EnumDeclaration */:
+ case 191 /* EnumDeclaration */:
return createEnumItem(node);
- case 188 /* InterfaceDeclaration */:
+ case 189 /* InterfaceDeclaration */:
return createIterfaceItem(node);
- case 191 /* ModuleDeclaration */:
+ case 192 /* ModuleDeclaration */:
return createModuleItem(node);
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
return createFunctionItem(node);
}
return undefined;
@@ -16591,7 +17165,7 @@ var ts;
}
var result = [];
result.push(moduleDeclaration.name.text);
- while (moduleDeclaration.body && moduleDeclaration.body.kind === 191 /* ModuleDeclaration */) {
+ while (moduleDeclaration.body && moduleDeclaration.body.kind === 192 /* ModuleDeclaration */) {
moduleDeclaration = moduleDeclaration.body;
result.push(moduleDeclaration.name.text);
}
@@ -16603,7 +17177,7 @@ var ts;
return getNavigationBarItem(moduleName, ts.ScriptElementKind.moduleElement, ts.getNodeModifiers(node), [getNodeSpan(node)], childItems, getIndent(node));
}
function createFunctionItem(node) {
- if (node.name && node.body && node.body.kind === 186 /* FunctionBlock */) {
+ if (node.name && node.body && node.body.kind === 187 /* FunctionBlock */) {
var childItems = getItemsWorker(sortNodes(node.body.statements), createChildItem);
return getNavigationBarItem(node.name.text, ts.ScriptElementKind.functionElement, ts.getNodeModifiers(node), [getNodeSpan(node)], childItems, getIndent(node));
}
@@ -16639,13 +17213,13 @@ var ts;
}
}
function getInnermostModule(node) {
- while (node.body.kind === 191 /* ModuleDeclaration */) {
+ while (node.body.kind === 192 /* ModuleDeclaration */) {
node = node.body;
}
return node;
}
function getNodeSpan(node) {
- return node.kind === 196 /* SourceFile */ ? ts.TextSpan.fromBounds(node.getFullStart(), node.getEnd()) : ts.TextSpan.fromBounds(node.getStart(), node.getEnd());
+ return node.kind === 197 /* SourceFile */ ? ts.TextSpan.fromBounds(node.getFullStart(), node.getEnd()) : ts.TextSpan.fromBounds(node.getStart(), node.getEnd());
}
function getTextOfNode(node) {
return ts.getTextOfNodeFromSourceText(sourceFile.text, node);
@@ -16669,7 +17243,7 @@ var ts;
if (!argumentInfo) {
return undefined;
}
- var call = argumentInfo.list.parent;
+ var call = argumentInfo.invocation;
var candidates = [];
var resolvedSignature = typeInfoResolver.getResolvedSignature(call, candidates);
cancellationToken.throwIfCancellationRequested();
@@ -16678,23 +17252,103 @@ var ts;
}
return createSignatureHelpItems(candidates, resolvedSignature, argumentInfo);
function getImmediatelyContainingArgumentInfo(node) {
- if (node.parent.kind !== 147 /* CallExpression */ && node.parent.kind !== 148 /* NewExpression */) {
- return undefined;
+ if (node.parent.kind === 147 /* CallExpression */ || node.parent.kind === 148 /* NewExpression */) {
+ var callExpression = node.parent;
+ if (node.kind === 23 /* LessThanToken */ || node.kind === 15 /* OpenParenToken */) {
+ var list = getChildListThatStartsWithOpenerToken(callExpression, node, sourceFile);
+ var isTypeArgList = callExpression.typeArguments && callExpression.typeArguments.pos === list.pos;
+ ts.Debug.assert(list !== undefined);
+ return {
+ kind: isTypeArgList ? 0 /* TypeArguments */ : 1 /* CallArguments */,
+ invocation: callExpression,
+ argumentsSpan: getApplicableSpanForArguments(list),
+ argumentIndex: 0,
+ argumentCount: getCommaBasedArgCount(list)
+ };
+ }
+ var listItemInfo = ts.findListItemInfo(node);
+ if (listItemInfo) {
+ var list = listItemInfo.list;
+ var isTypeArgList = callExpression.typeArguments && callExpression.typeArguments.pos === list.pos;
+ var argumentIndex = (listItemInfo.listItemIndex + 1) >> 1;
+ return {
+ kind: isTypeArgList ? 0 /* TypeArguments */ : 1 /* CallArguments */,
+ invocation: callExpression,
+ argumentsSpan: getApplicableSpanForArguments(list),
+ argumentIndex: argumentIndex,
+ argumentCount: getCommaBasedArgCount(list)
+ };
+ }
}
- var parent = node.parent;
- if (node.kind === 23 /* LessThanToken */ || node.kind === 15 /* OpenParenToken */) {
- var list = getChildListThatStartsWithOpenerToken(parent, node, sourceFile);
- ts.Debug.assert(list !== undefined);
- return {
- list: list,
- listItemIndex: 0
- };
+ else if (node.kind === 9 /* NoSubstitutionTemplateLiteral */ && node.parent.kind === 149 /* TaggedTemplateExpression */) {
+ if (ts.isInsideTemplateLiteral(node, position)) {
+ return getArgumentListInfoForTemplate(node.parent, 0);
+ }
}
- return ts.findListItemInfo(node);
+ else if (node.kind === 10 /* TemplateHead */ && node.parent.parent.kind === 149 /* TaggedTemplateExpression */) {
+ var templateExpression = node.parent;
+ var tagExpression = templateExpression.parent;
+ ts.Debug.assert(templateExpression.kind === 158 /* TemplateExpression */);
+ var argumentIndex = ts.isInsideTemplateLiteral(node, position) ? 0 : 1;
+ return getArgumentListInfoForTemplate(tagExpression, argumentIndex);
+ }
+ else if (node.parent.kind === 159 /* TemplateSpan */ && node.parent.parent.parent.kind === 149 /* TaggedTemplateExpression */) {
+ var templateSpan = node.parent;
+ var templateExpression = templateSpan.parent;
+ var tagExpression = templateExpression.parent;
+ ts.Debug.assert(templateExpression.kind === 158 /* TemplateExpression */);
+ if (node.kind === 12 /* TemplateTail */ && position >= node.getEnd() && !ts.isUnterminatedTemplateEnd(node)) {
+ return undefined;
+ }
+ var spanIndex = templateExpression.templateSpans.indexOf(templateSpan);
+ var argumentIndex = getArgumentIndexForTemplatePiece(spanIndex, node);
+ return getArgumentListInfoForTemplate(tagExpression, argumentIndex);
+ }
+ return undefined;
+ }
+ function getCommaBasedArgCount(argumentsList) {
+ return argumentsList.getChildCount() === 0 ? 0 : 1 + ts.countWhere(argumentsList.getChildren(), function (arg) { return arg.kind === 22 /* CommaToken */; });
+ }
+ function getArgumentIndexForTemplatePiece(spanIndex, node) {
+ ts.Debug.assert(position >= node.getStart(), "Assumed 'position' could not occur before node.");
+ if (ts.isTemplateLiteralKind(node.kind)) {
+ if (ts.isInsideTemplateLiteral(node, position)) {
+ return 0;
+ }
+ return spanIndex + 2;
+ }
+ return spanIndex + 1;
+ }
+ function getArgumentListInfoForTemplate(tagExpression, argumentIndex) {
+ var argumentCount = tagExpression.template.kind === 9 /* NoSubstitutionTemplateLiteral */ ? 1 : tagExpression.template.templateSpans.length + 1;
+ return {
+ kind: 2 /* TaggedTemplateArguments */,
+ invocation: tagExpression,
+ argumentsSpan: getApplicableSpanForTaggedTemplate(tagExpression),
+ argumentIndex: argumentIndex,
+ argumentCount: argumentCount
+ };
+ }
+ function getApplicableSpanForArguments(argumentsList) {
+ var applicableSpanStart = argumentsList.getFullStart();
+ var applicableSpanEnd = ts.skipTrivia(sourceFile.text, argumentsList.getEnd(), false);
+ return new ts.TextSpan(applicableSpanStart, applicableSpanEnd - applicableSpanStart);
+ }
+ function getApplicableSpanForTaggedTemplate(taggedTemplate) {
+ var template = taggedTemplate.template;
+ var applicableSpanStart = template.getStart();
+ var applicableSpanEnd = template.getEnd();
+ if (template.kind === 158 /* TemplateExpression */) {
+ var lastSpan = ts.lastOrUndefined(template.templateSpans);
+ if (lastSpan.literal.kind === 120 /* Missing */) {
+ applicableSpanEnd = ts.skipTrivia(sourceFile.text, applicableSpanEnd, false);
+ }
+ }
+ return new ts.TextSpan(applicableSpanStart, applicableSpanEnd - applicableSpanStart);
}
function getContainingArgumentInfo(node) {
- for (var n = node; n.kind !== 196 /* SourceFile */; n = n.parent) {
- if (n.kind === 186 /* FunctionBlock */) {
+ for (var n = node; n.kind !== 197 /* SourceFile */; n = n.parent) {
+ if (n.kind === 187 /* FunctionBlock */) {
return undefined;
}
if (n.pos < n.parent.pos || n.end > n.parent.end) {
@@ -16728,13 +17382,12 @@ var ts;
}
return maxParamsSignatureIndex;
}
- function createSignatureHelpItems(candidates, bestSignature, argumentInfoOrTypeArgumentInfo) {
- var argumentListOrTypeArgumentList = argumentInfoOrTypeArgumentInfo.list;
- var parent = argumentListOrTypeArgumentList.parent;
- var isTypeParameterHelp = parent.typeArguments && parent.typeArguments.pos === argumentListOrTypeArgumentList.pos;
- ts.Debug.assert(isTypeParameterHelp || parent.arguments.pos === argumentListOrTypeArgumentList.pos);
- var callTargetNode = argumentListOrTypeArgumentList.parent.func;
- var callTargetSymbol = typeInfoResolver.getSymbolInfo(callTargetNode);
+ function createSignatureHelpItems(candidates, bestSignature, argumentListInfo) {
+ var applicableSpan = argumentListInfo.argumentsSpan;
+ var isTypeParameterList = argumentListInfo.kind === 0 /* TypeArguments */;
+ var invocation = argumentListInfo.invocation;
+ var callTarget = ts.getInvokedExpression(invocation);
+ var callTargetSymbol = typeInfoResolver.getSymbolInfo(callTarget);
var callTargetDisplayParts = callTargetSymbol && ts.symbolToDisplayParts(typeInfoResolver, callTargetSymbol, undefined, undefined);
var items = ts.map(candidates, function (candidateSignature) {
var signatureHelpParameters;
@@ -16743,23 +17396,23 @@ var ts;
if (callTargetDisplayParts) {
prefixDisplayParts.push.apply(prefixDisplayParts, callTargetDisplayParts);
}
- if (isTypeParameterHelp) {
+ if (isTypeParameterList) {
prefixDisplayParts.push(ts.punctuationPart(23 /* LessThanToken */));
var typeParameters = candidateSignature.typeParameters;
signatureHelpParameters = typeParameters && typeParameters.length > 0 ? ts.map(typeParameters, createSignatureHelpParameterForTypeParameter) : emptyArray;
suffixDisplayParts.push(ts.punctuationPart(24 /* GreaterThanToken */));
- var parameterParts = ts.mapToDisplayParts(function (writer) { return typeInfoResolver.getSymbolDisplayBuilder().buildDisplayForParametersAndDelimiters(candidateSignature.parameters, writer, argumentListOrTypeArgumentList); });
+ var parameterParts = ts.mapToDisplayParts(function (writer) { return typeInfoResolver.getSymbolDisplayBuilder().buildDisplayForParametersAndDelimiters(candidateSignature.parameters, writer, invocation); });
suffixDisplayParts.push.apply(suffixDisplayParts, parameterParts);
}
else {
- var typeParameterParts = ts.mapToDisplayParts(function (writer) { return typeInfoResolver.getSymbolDisplayBuilder().buildDisplayForTypeParametersAndDelimiters(candidateSignature.typeParameters, writer, argumentListOrTypeArgumentList); });
+ var typeParameterParts = ts.mapToDisplayParts(function (writer) { return typeInfoResolver.getSymbolDisplayBuilder().buildDisplayForTypeParametersAndDelimiters(candidateSignature.typeParameters, writer, invocation); });
prefixDisplayParts.push.apply(prefixDisplayParts, typeParameterParts);
prefixDisplayParts.push(ts.punctuationPart(15 /* OpenParenToken */));
var parameters = candidateSignature.parameters;
signatureHelpParameters = parameters.length > 0 ? ts.map(parameters, createSignatureHelpParameterForParameter) : emptyArray;
suffixDisplayParts.push(ts.punctuationPart(16 /* CloseParenToken */));
}
- var returnTypeParts = ts.mapToDisplayParts(function (writer) { return typeInfoResolver.getSymbolDisplayBuilder().buildReturnTypeDisplay(candidateSignature, writer, argumentListOrTypeArgumentList); });
+ var returnTypeParts = ts.mapToDisplayParts(function (writer) { return typeInfoResolver.getSymbolDisplayBuilder().buildReturnTypeDisplay(candidateSignature, writer, invocation); });
suffixDisplayParts.push.apply(suffixDisplayParts, returnTypeParts);
return {
isVariadic: candidateSignature.hasRestParameter,
@@ -16770,11 +17423,8 @@ var ts;
documentation: candidateSignature.getDocumentationComment()
};
});
- var applicableSpanStart = argumentListOrTypeArgumentList.getFullStart();
- var applicableSpanEnd = ts.skipTrivia(sourceFile.text, argumentListOrTypeArgumentList.end, false);
- var applicableSpan = new ts.TextSpan(applicableSpanStart, applicableSpanEnd - applicableSpanStart);
- var argumentIndex = (argumentInfoOrTypeArgumentInfo.listItemIndex + 1) >> 1;
- var argumentCount = argumentListOrTypeArgumentList.getChildCount() === 0 ? 0 : 1 + ts.countWhere(argumentListOrTypeArgumentList.getChildren(), function (arg) { return arg.kind === 22 /* CommaToken */; });
+ var argumentIndex = argumentListInfo.argumentIndex;
+ var argumentCount = argumentListInfo.argumentCount;
var selectedItemIndex = candidates.indexOf(bestSignature);
if (selectedItemIndex < 0) {
selectedItemIndex = selectBestInvalidOverloadIndex(candidates, argumentCount);
@@ -16787,7 +17437,7 @@ var ts;
argumentCount: argumentCount
};
function createSignatureHelpParameterForParameter(parameter) {
- var displayParts = ts.mapToDisplayParts(function (writer) { return typeInfoResolver.getSymbolDisplayBuilder().buildParameterDisplay(parameter, writer, argumentListOrTypeArgumentList); });
+ var displayParts = ts.mapToDisplayParts(function (writer) { return typeInfoResolver.getSymbolDisplayBuilder().buildParameterDisplay(parameter, writer, invocation); });
var isOptional = !!(parameter.valueDeclaration.flags & 4 /* QuestionMark */);
return {
name: parameter.name,
@@ -16797,7 +17447,7 @@ var ts;
};
}
function createSignatureHelpParameterForTypeParameter(typeParameter) {
- var displayParts = ts.mapToDisplayParts(function (writer) { return typeInfoResolver.getSymbolDisplayBuilder().buildTypeParameterDisplay(typeParameter, writer, argumentListOrTypeArgumentList); });
+ var displayParts = ts.mapToDisplayParts(function (writer) { return typeInfoResolver.getSymbolDisplayBuilder().buildTypeParameterDisplay(typeParameter, writer, invocation); });
return {
name: typeParameter.symbol.name,
documentation: emptyArray,
@@ -16882,7 +17532,7 @@ var ts;
ts.findChildOfKind = findChildOfKind;
function findContainingList(node) {
var syntaxList = ts.forEach(node.parent.getChildren(), function (c) {
- if (c.kind === 198 /* SyntaxList */ && c.pos <= node.pos && c.end >= node.end) {
+ if (c.kind === 199 /* SyntaxList */ && c.pos <= node.pos && c.end >= node.end) {
return c;
}
});
@@ -16890,7 +17540,7 @@ var ts;
}
ts.findContainingList = findContainingList;
function findListItemIndexContainingPosition(list, position) {
- ts.Debug.assert(list.kind === 198 /* SyntaxList */);
+ ts.Debug.assert(list.kind === 199 /* SyntaxList */);
var children = list.getChildren();
for (var i = 0; i < children.length; i++) {
if (children[i].pos <= position && children[i].end > position) {
@@ -16997,7 +17647,7 @@ var ts;
}
}
}
- ts.Debug.assert(startNode !== undefined || n.kind === 196 /* SourceFile */);
+ ts.Debug.assert(startNode !== undefined || n.kind === 197 /* SourceFile */);
if (children.length) {
var candidate = findRightmostChildNodeWithTokens(children, children.length);
return candidate && findRightmostToken(candidate);
@@ -17022,7 +17672,7 @@ var ts;
if (node.kind === 132 /* TypeReference */ || node.kind === 147 /* CallExpression */) {
return node.typeArguments;
}
- if (ts.isAnyFunction(node) || node.kind === 187 /* ClassDeclaration */ || node.kind === 188 /* InterfaceDeclaration */) {
+ if (ts.isAnyFunction(node) || node.kind === 188 /* ClassDeclaration */ || node.kind === 189 /* InterfaceDeclaration */) {
return node.typeParameters;
}
return undefined;
@@ -17046,6 +17696,10 @@ var ts;
return 13 /* FirstPunctuation */ <= kind && kind <= 62 /* LastPunctuation */;
}
ts.isPunctuation = isPunctuation;
+ function isInsideTemplateLiteral(node, position) {
+ return (node.getStart() < position && position < node.getEnd()) || (ts.isUnterminatedTemplateEnd(node) && position === node.getEnd());
+ }
+ ts.isInsideTemplateLiteral = isInsideTemplateLiteral;
})(ts || (ts = {}));
var ts;
(function (ts) {
@@ -17149,7 +17803,7 @@ var ts;
return deriveActualIndentationFromList(commaItemInfo.list.getChildren(), commaItemInfo.listItemIndex - 1, sourceFile, options);
}
function getActualIndentationForNode(current, parent, currentLineAndChar, parentAndChildShareLine, sourceFile, options) {
- var useActualIndentation = (ts.isDeclaration(current) || ts.isStatement(current)) && (parent.kind === 196 /* SourceFile */ || !parentAndChildShareLine);
+ var useActualIndentation = (ts.isDeclaration(current) || ts.isStatement(current)) && (parent.kind === 197 /* SourceFile */ || !parentAndChildShareLine);
if (!useActualIndentation) {
return -1;
}
@@ -17176,7 +17830,7 @@ var ts;
return candidate.end > position || !isCompletedNode(candidate, sourceFile);
}
function childStartsOnTheSameLineWithElseInIfStatement(parent, child, childStartLine, sourceFile) {
- if (parent.kind === 165 /* IfStatement */ && parent.elseStatement === child) {
+ if (parent.kind === 166 /* IfStatement */ && parent.elseStatement === child) {
var elseKeyword = ts.findChildOfKind(parent, 74 /* ElseKeyword */, sourceFile);
ts.Debug.assert(elseKeyword !== undefined);
var elseKeywordStartLine = getStartLineAndCharacterForNode(elseKeyword, sourceFile).line;
@@ -17189,7 +17843,7 @@ var ts;
if (node.parent) {
switch (node.parent.kind) {
case 132 /* TypeReference */:
- if (node.parent.typeArguments) {
+ if (node.parent.typeArguments && ts.rangeContainsStartEnd(node.parent.typeArguments, node.getStart(sourceFile), node.getEnd())) {
return node.parent.typeArguments;
}
break;
@@ -17197,22 +17851,30 @@ var ts;
return node.parent.properties;
case 141 /* ArrayLiteral */:
return node.parent.elements;
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
case 152 /* FunctionExpression */:
case 153 /* ArrowFunction */:
case 125 /* Method */:
case 129 /* CallSignature */:
case 130 /* ConstructSignature */:
- if (node.parent.typeParameters && node.end < node.parent.typeParameters.end) {
+ var start = node.getStart(sourceFile);
+ if (node.parent.typeParameters && ts.rangeContainsStartEnd(node.parent.typeParameters, start, node.getEnd())) {
return node.parent.typeParameters;
}
- return node.parent.parameters;
+ if (ts.rangeContainsStartEnd(node.parent.parameters, start, node.getEnd())) {
+ return node.parent.parameters;
+ }
+ break;
case 148 /* NewExpression */:
case 147 /* CallExpression */:
- if (node.parent.typeArguments && node.end < node.parent.typeArguments.end) {
+ var start = node.getStart(sourceFile);
+ if (node.parent.typeArguments && ts.rangeContainsStartEnd(node.parent.typeArguments, start, node.getEnd())) {
return node.parent.typeArguments;
}
- return node.parent.arguments;
+ if (ts.rangeContainsStartEnd(node.parent.arguments, start, node.getEnd())) {
+ return node.parent.arguments;
+ }
+ break;
}
}
return undefined;
@@ -17264,28 +17926,28 @@ var ts;
SmartIndenter.findFirstNonWhitespaceColumn = findFirstNonWhitespaceColumn;
function nodeContentIsAlwaysIndented(kind) {
switch (kind) {
- case 187 /* ClassDeclaration */:
- case 188 /* InterfaceDeclaration */:
- case 190 /* EnumDeclaration */:
+ case 188 /* ClassDeclaration */:
+ case 189 /* InterfaceDeclaration */:
+ case 191 /* EnumDeclaration */:
case 141 /* ArrayLiteral */:
- case 161 /* Block */:
- case 186 /* FunctionBlock */:
- case 180 /* TryBlock */:
- case 181 /* CatchBlock */:
- case 182 /* FinallyBlock */:
- case 192 /* ModuleBlock */:
+ case 162 /* Block */:
+ case 187 /* FunctionBlock */:
+ case 181 /* TryBlock */:
+ case 182 /* CatchBlock */:
+ case 183 /* FinallyBlock */:
+ case 193 /* ModuleBlock */:
case 142 /* ObjectLiteral */:
case 136 /* TypeLiteral */:
- case 174 /* SwitchStatement */:
- case 176 /* DefaultClause */:
- case 175 /* CaseClause */:
+ case 175 /* SwitchStatement */:
+ case 177 /* DefaultClause */:
+ case 176 /* CaseClause */:
case 151 /* ParenExpression */:
case 147 /* CallExpression */:
case 148 /* NewExpression */:
- case 162 /* VariableStatement */:
- case 184 /* VariableDeclaration */:
- case 194 /* ExportAssignment */:
- case 172 /* ReturnStatement */:
+ case 163 /* VariableStatement */:
+ case 185 /* VariableDeclaration */:
+ case 195 /* ExportAssignment */:
+ case 173 /* ReturnStatement */:
return true;
}
return false;
@@ -17295,20 +17957,20 @@ var ts;
return true;
}
switch (parent) {
- case 166 /* DoStatement */:
- case 167 /* WhileStatement */:
- case 169 /* ForInStatement */:
- case 168 /* ForStatement */:
- case 165 /* IfStatement */:
- return child !== 161 /* Block */;
- case 185 /* FunctionDeclaration */:
+ case 167 /* DoStatement */:
+ case 168 /* WhileStatement */:
+ case 170 /* ForInStatement */:
+ case 169 /* ForStatement */:
+ case 166 /* IfStatement */:
+ return child !== 162 /* Block */;
+ case 186 /* FunctionDeclaration */:
case 152 /* FunctionExpression */:
case 125 /* Method */:
case 153 /* ArrowFunction */:
case 126 /* Constructor */:
case 127 /* GetAccessor */:
case 128 /* SetAccessor */:
- return child !== 186 /* FunctionBlock */;
+ return child !== 187 /* FunctionBlock */;
default:
return false;
}
@@ -17329,46 +17991,46 @@ var ts;
}
function isCompletedNode(n, sourceFile) {
switch (n.kind) {
- case 187 /* ClassDeclaration */:
- case 188 /* InterfaceDeclaration */:
- case 190 /* EnumDeclaration */:
+ case 188 /* ClassDeclaration */:
+ case 189 /* InterfaceDeclaration */:
+ case 191 /* EnumDeclaration */:
case 142 /* ObjectLiteral */:
- case 161 /* Block */:
- case 181 /* CatchBlock */:
- case 182 /* FinallyBlock */:
- case 186 /* FunctionBlock */:
- case 192 /* ModuleBlock */:
- case 174 /* SwitchStatement */:
+ case 162 /* Block */:
+ case 182 /* CatchBlock */:
+ case 183 /* FinallyBlock */:
+ case 187 /* FunctionBlock */:
+ case 193 /* ModuleBlock */:
+ case 175 /* SwitchStatement */:
return nodeEndsWith(n, 14 /* CloseBraceToken */, sourceFile);
case 151 /* ParenExpression */:
case 129 /* CallSignature */:
case 147 /* CallExpression */:
case 130 /* ConstructSignature */:
return nodeEndsWith(n, 16 /* CloseParenToken */, sourceFile);
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
case 152 /* FunctionExpression */:
case 125 /* Method */:
case 153 /* ArrowFunction */:
return !n.body || isCompletedNode(n.body, sourceFile);
- case 191 /* ModuleDeclaration */:
+ case 192 /* ModuleDeclaration */:
return n.body && isCompletedNode(n.body, sourceFile);
- case 165 /* IfStatement */:
+ case 166 /* IfStatement */:
if (n.elseStatement) {
return isCompletedNode(n.elseStatement, sourceFile);
}
return isCompletedNode(n.thenStatement, sourceFile);
- case 164 /* ExpressionStatement */:
+ case 165 /* ExpressionStatement */:
return isCompletedNode(n.expression, sourceFile);
case 141 /* ArrayLiteral */:
return nodeEndsWith(n, 18 /* CloseBracketToken */, sourceFile);
case 120 /* Missing */:
return false;
- case 175 /* CaseClause */:
- case 176 /* DefaultClause */:
+ case 176 /* CaseClause */:
+ case 177 /* DefaultClause */:
return false;
- case 167 /* WhileStatement */:
+ case 168 /* WhileStatement */:
return isCompletedNode(n.statement, sourceFile);
- case 166 /* DoStatement */:
+ case 167 /* DoStatement */:
var hasWhileKeyword = ts.findChildOfKind(n, 98 /* WhileKeyword */, sourceFile);
if (hasWhileKeyword) {
return nodeEndsWith(n, 16 /* CloseParenToken */, sourceFile);
@@ -17943,7 +18605,7 @@ var ts;
throw new Error("Unknown rule");
};
Rules.IsForContext = function (context) {
- return context.contextNode.kind === 168 /* ForStatement */;
+ return context.contextNode.kind === 169 /* ForStatement */;
};
Rules.IsNotForContext = function (context) {
return !Rules.IsForContext(context);
@@ -17953,13 +18615,13 @@ var ts;
case 156 /* BinaryExpression */:
case 157 /* ConditionalExpression */:
return true;
- case 193 /* ImportDeclaration */:
- case 184 /* VariableDeclaration */:
+ case 194 /* ImportDeclaration */:
+ case 185 /* VariableDeclaration */:
case 123 /* Parameter */:
- case 195 /* EnumMember */:
+ case 196 /* EnumMember */:
case 124 /* Property */:
return context.currentTokenSpan.kind === 51 /* EqualsToken */ || context.nextTokenSpan.kind === 51 /* EqualsToken */;
- case 169 /* ForInStatement */:
+ case 170 /* ForInStatement */:
return context.currentTokenSpan.kind === 84 /* InKeyword */ || context.nextTokenSpan.kind === 84 /* InKeyword */;
}
return false;
@@ -17990,21 +18652,21 @@ var ts;
return true;
}
switch (node.kind) {
- case 161 /* Block */:
- case 174 /* SwitchStatement */:
+ case 162 /* Block */:
+ case 175 /* SwitchStatement */:
case 142 /* ObjectLiteral */:
- case 180 /* TryBlock */:
- case 181 /* CatchBlock */:
- case 182 /* FinallyBlock */:
- case 186 /* FunctionBlock */:
- case 192 /* ModuleBlock */:
+ case 181 /* TryBlock */:
+ case 182 /* CatchBlock */:
+ case 183 /* FinallyBlock */:
+ case 187 /* FunctionBlock */:
+ case 193 /* ModuleBlock */:
return true;
}
return false;
};
Rules.IsFunctionDeclContext = function (context) {
switch (context.contextNode.kind) {
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
case 125 /* Method */:
case 127 /* GetAccessor */:
case 128 /* SetAccessor */:
@@ -18012,7 +18674,7 @@ var ts;
case 152 /* FunctionExpression */:
case 126 /* Constructor */:
case 153 /* ArrowFunction */:
- case 188 /* InterfaceDeclaration */:
+ case 189 /* InterfaceDeclaration */:
return true;
}
return false;
@@ -18022,43 +18684,43 @@ var ts;
};
Rules.NodeIsTypeScriptDeclWithBlockContext = function (node) {
switch (node.kind) {
- case 187 /* ClassDeclaration */:
- case 188 /* InterfaceDeclaration */:
- case 190 /* EnumDeclaration */:
+ case 188 /* ClassDeclaration */:
+ case 189 /* InterfaceDeclaration */:
+ case 191 /* EnumDeclaration */:
case 136 /* TypeLiteral */:
- case 191 /* ModuleDeclaration */:
+ case 192 /* ModuleDeclaration */:
return true;
}
return false;
};
Rules.IsAfterCodeBlockContext = function (context) {
switch (context.currentTokenParent.kind) {
- case 187 /* ClassDeclaration */:
- case 191 /* ModuleDeclaration */:
- case 190 /* EnumDeclaration */:
- case 161 /* Block */:
- case 180 /* TryBlock */:
- case 181 /* CatchBlock */:
- case 182 /* FinallyBlock */:
- case 186 /* FunctionBlock */:
- case 192 /* ModuleBlock */:
- case 174 /* SwitchStatement */:
+ case 188 /* ClassDeclaration */:
+ case 192 /* ModuleDeclaration */:
+ case 191 /* EnumDeclaration */:
+ case 162 /* Block */:
+ case 181 /* TryBlock */:
+ case 182 /* CatchBlock */:
+ case 183 /* FinallyBlock */:
+ case 187 /* FunctionBlock */:
+ case 193 /* ModuleBlock */:
+ case 175 /* SwitchStatement */:
return true;
}
return false;
};
Rules.IsControlDeclContext = function (context) {
switch (context.contextNode.kind) {
- case 165 /* IfStatement */:
- case 174 /* SwitchStatement */:
- case 168 /* ForStatement */:
- case 169 /* ForInStatement */:
- case 167 /* WhileStatement */:
- case 179 /* TryStatement */:
- case 166 /* DoStatement */:
- case 173 /* WithStatement */:
- case 181 /* CatchBlock */:
- case 182 /* FinallyBlock */:
+ case 166 /* IfStatement */:
+ case 175 /* SwitchStatement */:
+ case 169 /* ForStatement */:
+ case 170 /* ForInStatement */:
+ case 168 /* WhileStatement */:
+ case 180 /* TryStatement */:
+ case 167 /* DoStatement */:
+ case 174 /* WithStatement */:
+ case 182 /* CatchBlock */:
+ case 183 /* FinallyBlock */:
return true;
default:
return false;
@@ -18083,7 +18745,7 @@ var ts;
return context.formattingRequestKind != 2 /* FormatOnEnter */;
};
Rules.IsModuleDeclContext = function (context) {
- return context.contextNode.kind === 191 /* ModuleDeclaration */;
+ return context.contextNode.kind === 192 /* ModuleDeclaration */;
};
Rules.IsObjectTypeContext = function (context) {
return context.contextNode.kind === 136 /* TypeLiteral */;
@@ -18094,9 +18756,9 @@ var ts;
}
switch (parent.kind) {
case 132 /* TypeReference */:
- case 187 /* ClassDeclaration */:
- case 188 /* InterfaceDeclaration */:
- case 185 /* FunctionDeclaration */:
+ case 188 /* ClassDeclaration */:
+ case 189 /* InterfaceDeclaration */:
+ case 186 /* FunctionDeclaration */:
case 152 /* FunctionExpression */:
case 153 /* ArrowFunction */:
case 125 /* Method */:
@@ -18533,18 +19195,18 @@ var ts;
}
function isListElement(parent, node) {
switch (parent.kind) {
- case 187 /* ClassDeclaration */:
- case 188 /* InterfaceDeclaration */:
+ case 188 /* ClassDeclaration */:
+ case 189 /* InterfaceDeclaration */:
return ts.rangeContainsRange(parent.members, node);
- case 191 /* ModuleDeclaration */:
+ case 192 /* ModuleDeclaration */:
var body = parent.body;
- return body && body.kind === 161 /* Block */ && ts.rangeContainsRange(body.statements, node);
- case 196 /* SourceFile */:
- case 161 /* Block */:
- case 180 /* TryBlock */:
- case 181 /* CatchBlock */:
- case 182 /* FinallyBlock */:
- case 192 /* ModuleBlock */:
+ return body && body.kind === 162 /* Block */ && ts.rangeContainsRange(body.statements, node);
+ case 197 /* SourceFile */:
+ case 162 /* Block */:
+ case 181 /* TryBlock */:
+ case 182 /* CatchBlock */:
+ case 183 /* FinallyBlock */:
+ case 193 /* ModuleBlock */:
return ts.rangeContainsRange(parent.statements, node);
}
return false;
@@ -18599,7 +19261,7 @@ var ts;
return precedingToken ? precedingToken.end : enclosingNode.pos;
}
function formatSpan(originalRange, sourceFile, options, rulesProvider, requestKind) {
- var rangeContainsError = prepareRangeContainsErrorFunction(sourceFile.syntacticErrors, originalRange);
+ var rangeContainsError = prepareRangeContainsErrorFunction(sourceFile.getSyntacticDiagnostics(), originalRange);
var formattingContext = new formatting.FormattingContext(sourceFile, requestKind);
var enclosingNode = findEnclosingNode(originalRange, sourceFile);
var formattingScanner = formatting.getFormattingScanner(sourceFile, getScanStartPosition(enclosingNode, originalRange, sourceFile), originalRange.end);
@@ -18637,7 +19299,7 @@ var ts;
var indentation = inheritedIndentation;
if (indentation === -1 /* Unknown */) {
if (isSomeBlock(node.kind)) {
- if (isSomeBlock(parent.kind) || parent.kind === 196 /* SourceFile */ || parent.kind === 175 /* CaseClause */ || parent.kind === 176 /* DefaultClause */) {
+ if (isSomeBlock(parent.kind) || parent.kind === 197 /* SourceFile */ || parent.kind === 176 /* CaseClause */ || parent.kind === 177 /* DefaultClause */) {
indentation = parentDynamicIndentation.getIndentation() + parentDynamicIndentation.getDelta();
}
else {
@@ -19032,12 +19694,12 @@ var ts;
}
function isSomeBlock(kind) {
switch (kind) {
- case 161 /* Block */:
- case 186 /* FunctionBlock */:
- case 180 /* TryBlock */:
- case 181 /* CatchBlock */:
- case 182 /* FinallyBlock */:
- case 192 /* ModuleBlock */:
+ case 162 /* Block */:
+ case 187 /* FunctionBlock */:
+ case 181 /* TryBlock */:
+ case 182 /* CatchBlock */:
+ case 183 /* FinallyBlock */:
+ case 193 /* ModuleBlock */:
return true;
}
return false;
@@ -19045,7 +19707,7 @@ var ts;
function getOpenTokenForList(node, list) {
switch (node.kind) {
case 126 /* Constructor */:
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
case 152 /* FunctionExpression */:
case 125 /* Method */:
case 153 /* ArrowFunction */:
@@ -19165,7 +19827,7 @@ var ts;
return pos;
};
NodeObject.prototype.createSyntaxList = function (nodes) {
- var list = createNode(198 /* SyntaxList */, nodes.pos, nodes.end, 512 /* Synthetic */, this);
+ var list = createNode(199 /* SyntaxList */, nodes.pos, nodes.end, 512 /* Synthetic */, this);
list._children = [];
var pos = nodes.pos;
for (var i = 0, len = nodes.length; i < len; i++) {
@@ -19291,13 +19953,13 @@ var ts;
}
});
}
- if (declaration.kind === 191 /* ModuleDeclaration */ && declaration.body.kind === 191 /* ModuleDeclaration */) {
+ if (declaration.kind === 192 /* ModuleDeclaration */ && declaration.body.kind === 192 /* ModuleDeclaration */) {
return;
}
- while (declaration.kind === 191 /* ModuleDeclaration */ && declaration.parent.kind === 191 /* ModuleDeclaration */) {
+ while (declaration.kind === 192 /* ModuleDeclaration */ && declaration.parent.kind === 192 /* ModuleDeclaration */) {
declaration = declaration.parent;
}
- ts.forEach(getJsDocCommentTextRange(declaration.kind === 184 /* VariableDeclaration */ ? declaration.parent : declaration, sourceFileOfDeclaration), function (jsDocCommentTextRange) {
+ ts.forEach(getJsDocCommentTextRange(declaration.kind === 185 /* VariableDeclaration */ ? declaration.parent : declaration, sourceFileOfDeclaration), function (jsDocCommentTextRange) {
var cleanedJsDocComment = getCleanedJsDocComment(jsDocCommentTextRange.pos, jsDocCommentTextRange.end, sourceFileOfDeclaration);
if (cleanedJsDocComment) {
jsDocCommentParts.push.apply(jsDocCommentParts, cleanedJsDocComment);
@@ -19559,15 +20221,6 @@ var ts;
function SourceFileObject() {
_super.apply(this, arguments);
}
- SourceFileObject.prototype.getLineAndCharacterFromPosition = function (position) {
- return null;
- };
- SourceFileObject.prototype.getPositionFromLineAndCharacter = function (line, character) {
- return -1;
- };
- SourceFileObject.prototype.getLineStarts = function () {
- return undefined;
- };
SourceFileObject.prototype.getScriptSnapshot = function () {
return this.scriptSnapshot;
};
@@ -19577,7 +20230,7 @@ var ts;
var namedDeclarations = [];
ts.forEachChild(sourceFile, function visit(node) {
switch (node.kind) {
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
case 125 /* Method */:
var functionDeclaration = node;
if (functionDeclaration.name && functionDeclaration.name.kind !== 120 /* Missing */) {
@@ -19593,12 +20246,12 @@ var ts;
ts.forEachChild(node, visit);
}
break;
- case 187 /* ClassDeclaration */:
- case 188 /* InterfaceDeclaration */:
- case 189 /* TypeAliasDeclaration */:
- case 190 /* EnumDeclaration */:
- case 191 /* ModuleDeclaration */:
- case 193 /* ImportDeclaration */:
+ case 188 /* ClassDeclaration */:
+ case 189 /* InterfaceDeclaration */:
+ case 190 /* TypeAliasDeclaration */:
+ case 191 /* EnumDeclaration */:
+ case 192 /* ModuleDeclaration */:
+ case 194 /* ImportDeclaration */:
case 127 /* GetAccessor */:
case 128 /* SetAccessor */:
case 136 /* TypeLiteral */:
@@ -19606,17 +20259,17 @@ var ts;
namedDeclarations.push(node);
}
case 126 /* Constructor */:
- case 162 /* VariableStatement */:
- case 192 /* ModuleBlock */:
- case 186 /* FunctionBlock */:
+ case 163 /* VariableStatement */:
+ case 193 /* ModuleBlock */:
+ case 187 /* FunctionBlock */:
ts.forEachChild(node, visit);
break;
case 123 /* Parameter */:
if (!(node.flags & 112 /* AccessibilityModifier */)) {
break;
}
- case 184 /* VariableDeclaration */:
- case 195 /* EnumMember */:
+ case 185 /* VariableDeclaration */:
+ case 196 /* EnumMember */:
case 124 /* Property */:
namedDeclarations.push(node);
break;
@@ -19720,7 +20373,8 @@ var ts;
ScriptElementKind.primitiveType = "primitive type";
ScriptElementKind.label = "label";
ScriptElementKind.alias = "alias";
- ScriptElementKind.constantElement = "constant";
+ ScriptElementKind.constElement = "const";
+ ScriptElementKind.letElement = "let";
return ScriptElementKind;
})();
ts.ScriptElementKind = ScriptElementKind;
@@ -19862,11 +20516,11 @@ var ts;
if (declaration.kind === 152 /* FunctionExpression */) {
return true;
}
- if (declaration.kind !== 184 /* VariableDeclaration */ && declaration.kind !== 185 /* FunctionDeclaration */) {
+ if (declaration.kind !== 185 /* VariableDeclaration */ && declaration.kind !== 186 /* FunctionDeclaration */) {
return false;
}
- for (var parent = declaration.parent; parent.kind !== 186 /* FunctionBlock */; parent = parent.parent) {
- if (parent.kind === 196 /* SourceFile */ || parent.kind === 192 /* ModuleBlock */) {
+ for (var parent = declaration.parent; parent.kind !== 187 /* FunctionBlock */; parent = parent.parent) {
+ if (parent.kind === 197 /* SourceFile */ || parent.kind === 193 /* ModuleBlock */) {
return false;
}
}
@@ -20258,7 +20912,7 @@ var ts;
ts.getNodeModifiers = getNodeModifiers;
function getTargetLabel(referenceNode, labelName) {
while (referenceNode) {
- if (referenceNode.kind === 177 /* LabeledStatement */ && referenceNode.label.text === labelName) {
+ if (referenceNode.kind === 178 /* LabeledStatement */ && referenceNode.label.text === labelName) {
return referenceNode.label;
}
referenceNode = referenceNode.parent;
@@ -20266,13 +20920,13 @@ var ts;
return undefined;
}
function isJumpStatementTarget(node) {
- return node.kind === 63 /* Identifier */ && (node.parent.kind === 171 /* BreakStatement */ || node.parent.kind === 170 /* ContinueStatement */) && node.parent.label === node;
+ return node.kind === 63 /* Identifier */ && (node.parent.kind === 172 /* BreakStatement */ || node.parent.kind === 171 /* ContinueStatement */) && node.parent.label === node;
}
function isLabelOfLabeledStatement(node) {
- return node.kind === 63 /* Identifier */ && node.parent.kind === 177 /* LabeledStatement */ && node.parent.label === node;
+ return node.kind === 63 /* Identifier */ && node.parent.kind === 178 /* LabeledStatement */ && node.parent.label === node;
}
function isLabeledBy(node, labelName) {
- for (var owner = node.parent; owner.kind === 177 /* LabeledStatement */; owner = owner.parent) {
+ for (var owner = node.parent; owner.kind === 178 /* LabeledStatement */; owner = owner.parent) {
if (owner.label.text === labelName) {
return true;
}
@@ -20301,7 +20955,7 @@ var ts;
return node && node.parent && node.parent.kind === 148 /* NewExpression */ && node.parent.func === node;
}
function isNameOfModuleDeclaration(node) {
- return node.parent.kind === 191 /* ModuleDeclaration */ && node.parent.name === node;
+ return node.parent.kind === 192 /* ModuleDeclaration */ && node.parent.name === node;
}
function isNameOfFunctionDeclaration(node) {
return node.kind === 63 /* Identifier */ && ts.isAnyFunction(node.parent) && node.parent.name === node;
@@ -20314,11 +20968,11 @@ var ts;
switch (node.parent.kind) {
case 124 /* Property */:
case 143 /* PropertyAssignment */:
- case 195 /* EnumMember */:
+ case 196 /* EnumMember */:
case 125 /* Method */:
case 127 /* GetAccessor */:
case 128 /* SetAccessor */:
- case 191 /* ModuleDeclaration */:
+ case 192 /* ModuleDeclaration */:
return node.parent.name === node;
case 146 /* IndexedAccess */:
return node.parent.index === node;
@@ -20327,7 +20981,7 @@ var ts;
return false;
}
function isNameOfExternalModuleImportOrDeclaration(node) {
- return node.kind === 7 /* StringLiteral */ && (isNameOfModuleDeclaration(node) || (node.parent.kind === 193 /* ImportDeclaration */ && node.parent.externalModuleName === node));
+ return node.kind === 7 /* StringLiteral */ && (isNameOfModuleDeclaration(node) || (node.parent.kind === 194 /* ImportDeclaration */ && node.parent.externalModuleName === node));
}
function isInsideComment(sourceFile, token, position) {
return position <= token.getStart(sourceFile) && (isInsideCommentRange(ts.getTrailingCommentRanges(sourceFile.text, token.getFullStart())) || isInsideCommentRange(ts.getLeadingCommentRanges(sourceFile.text, token.getFullStart())));
@@ -20374,8 +21028,11 @@ var ts;
if (!ts.localizedDiagnosticMessages) {
ts.localizedDiagnosticMessages = host.getLocalizedDiagnosticMessages();
}
+ function getCanonicalFileName(filename) {
+ return useCaseSensitivefilenames ? filename : filename.toLowerCase();
+ }
function getSourceFile(filename) {
- return ts.lookUp(sourceFilesByName, filename);
+ return ts.lookUp(sourceFilesByName, getCanonicalFileName(filename));
}
function getFullTypeCheckChecker() {
return fullTypeCheckChecker_doNotAccessDirectly || (fullTypeCheckChecker_doNotAccessDirectly = program.getTypeChecker(true));
@@ -20443,7 +21100,7 @@ var ts;
var filename = oldSourceFiles[i].filename;
if (!hostCache.contains(filename) || changesInCompilationSettingsAffectSyntax) {
documentRegistry.releaseDocument(filename, oldSettings);
- delete sourceFilesByName[filename];
+ delete sourceFilesByName[getCanonicalFileName(filename)];
}
}
}
@@ -20467,7 +21124,7 @@ var ts;
else {
sourceFile = documentRegistry.acquireDocument(filename, compilationSettings, scriptSnapshot, version, isOpen);
}
- sourceFilesByName[filename] = sourceFile;
+ sourceFilesByName[getCanonicalFileName(filename)] = sourceFile;
}
program = ts.createProgram(hostfilenames, compilationSettings, createCompilerHost());
typeInfoResolver = program.getTypeChecker(false);
@@ -20499,11 +21156,7 @@ var ts;
var targetSourceFile = getSourceFile(filename);
var allDiagnostics = checker.getDiagnostics(targetSourceFile);
if (compilerOptions.declaration) {
- var savedWriter = writer;
- writer = function (filename, data, writeByteOrderMark) {
- };
- allDiagnostics = allDiagnostics.concat(checker.invokeEmitter(targetSourceFile).diagnostics);
- writer = savedWriter;
+ allDiagnostics = allDiagnostics.concat(checker.getDeclarationDiagnostics(targetSourceFile));
}
return allDiagnostics;
}
@@ -20713,7 +21366,7 @@ var ts;
switch (kind) {
case 152 /* FunctionExpression */:
case 153 /* ArrowFunction */:
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
case 125 /* Method */:
case 126 /* Constructor */:
case 127 /* GetAccessor */:
@@ -20730,13 +21383,13 @@ var ts;
var containingNodeKind = previousToken.parent.kind;
switch (previousToken.kind) {
case 22 /* CommaToken */:
- return containingNodeKind === 184 /* VariableDeclaration */ || containingNodeKind === 162 /* VariableStatement */ || containingNodeKind === 190 /* EnumDeclaration */ || isFunction(containingNodeKind);
+ return containingNodeKind === 185 /* VariableDeclaration */ || containingNodeKind === 163 /* VariableStatement */ || containingNodeKind === 191 /* EnumDeclaration */ || isFunction(containingNodeKind);
case 15 /* OpenParenToken */:
- return containingNodeKind === 181 /* CatchBlock */ || isFunction(containingNodeKind);
+ return containingNodeKind === 182 /* CatchBlock */ || isFunction(containingNodeKind);
case 13 /* OpenBraceToken */:
- return containingNodeKind === 190 /* EnumDeclaration */ || containingNodeKind === 188 /* InterfaceDeclaration */;
+ return containingNodeKind === 191 /* EnumDeclaration */ || containingNodeKind === 189 /* InterfaceDeclaration */;
case 21 /* SemicolonToken */:
- return containingNodeKind === 124 /* Property */ && previousToken.parent.parent.kind === 188 /* InterfaceDeclaration */;
+ return containingNodeKind === 124 /* Property */ && previousToken.parent.parent.kind === 189 /* InterfaceDeclaration */;
case 106 /* PublicKeyword */:
case 104 /* PrivateKeyword */:
case 107 /* StaticKeyword */:
@@ -20830,19 +21483,19 @@ var ts;
while (true) {
node = node.parent;
if (!node) {
- return node;
+ return undefined;
}
switch (node.kind) {
- case 196 /* SourceFile */:
+ case 197 /* SourceFile */:
case 125 /* Method */:
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
case 152 /* FunctionExpression */:
case 127 /* GetAccessor */:
case 128 /* SetAccessor */:
- case 187 /* ClassDeclaration */:
- case 188 /* InterfaceDeclaration */:
- case 190 /* EnumDeclaration */:
- case 191 /* ModuleDeclaration */:
+ case 188 /* ClassDeclaration */:
+ case 189 /* InterfaceDeclaration */:
+ case 191 /* EnumDeclaration */:
+ case 192 /* ModuleDeclaration */:
return node;
}
}
@@ -20881,8 +21534,11 @@ var ts;
if (isFirstDeclarationOfSymbolParameter(symbol)) {
return ScriptElementKind.parameterElement;
}
- else if (symbol.valueDeclaration && symbol.valueDeclaration.flags & 4096 /* Const */) {
- return ScriptElementKind.constantElement;
+ else if (symbol.valueDeclaration && ts.isConst(symbol.valueDeclaration)) {
+ return ScriptElementKind.constElement;
+ }
+ else if (ts.forEach(symbol.declarations, function (declaration) { return ts.isLet(declaration); })) {
+ return ScriptElementKind.letElement;
}
return isLocalVariableOrFunction(symbol) ? ScriptElementKind.localVariableElement : ScriptElementKind.variableElement;
}
@@ -20936,13 +21592,13 @@ var ts;
}
function getNodeKind(node) {
switch (node.kind) {
- case 191 /* ModuleDeclaration */: return ScriptElementKind.moduleElement;
- case 187 /* ClassDeclaration */: return ScriptElementKind.classElement;
- case 188 /* InterfaceDeclaration */: return ScriptElementKind.interfaceElement;
- case 189 /* TypeAliasDeclaration */: return ScriptElementKind.typeElement;
- case 190 /* EnumDeclaration */: return ScriptElementKind.enumElement;
- case 184 /* VariableDeclaration */: return node.flags & 4096 /* Const */ ? ScriptElementKind.constantElement : ScriptElementKind.variableElement;
- case 185 /* FunctionDeclaration */: return ScriptElementKind.functionElement;
+ case 192 /* ModuleDeclaration */: return ScriptElementKind.moduleElement;
+ case 188 /* ClassDeclaration */: return ScriptElementKind.classElement;
+ case 189 /* InterfaceDeclaration */: return ScriptElementKind.interfaceElement;
+ case 190 /* TypeAliasDeclaration */: return ScriptElementKind.typeElement;
+ case 191 /* EnumDeclaration */: return ScriptElementKind.enumElement;
+ case 185 /* VariableDeclaration */: return ts.isConst(node) ? ScriptElementKind.constElement : node.flags & 2048 /* Let */ ? ScriptElementKind.letElement : ScriptElementKind.variableElement;
+ case 186 /* FunctionDeclaration */: return ScriptElementKind.functionElement;
case 127 /* GetAccessor */: return ScriptElementKind.memberGetAccessorElement;
case 128 /* SetAccessor */: return ScriptElementKind.memberSetAccessorElement;
case 125 /* Method */: return ScriptElementKind.memberFunctionElement;
@@ -20952,7 +21608,7 @@ var ts;
case 129 /* CallSignature */: return ScriptElementKind.callSignatureElement;
case 126 /* Constructor */: return ScriptElementKind.constructorImplementationElement;
case 122 /* TypeParameter */: return ScriptElementKind.typeParameterElement;
- case 195 /* EnumMember */: return ScriptElementKind.variableElement;
+ case 196 /* EnumMember */: return ScriptElementKind.variableElement;
case 123 /* Parameter */: return (node.flags & 112 /* AccessibilityModifier */) ? ScriptElementKind.memberVariableElement : ScriptElementKind.parameterElement;
}
return ScriptElementKind.unknown;
@@ -21020,7 +21676,7 @@ var ts;
switch (symbolKind) {
case ScriptElementKind.memberVariableElement:
case ScriptElementKind.variableElement:
- case ScriptElementKind.constantElement:
+ case ScriptElementKind.constElement:
case ScriptElementKind.parameterElement:
case ScriptElementKind.localVariableElement:
displayParts.push(punctuationPart(50 /* ColonToken */));
@@ -21086,6 +21742,10 @@ var ts;
}
if (symbolFlags & 384 /* Enum */) {
addNewLineIfDisplayPartsExist();
+ if (ts.forEach(symbol.declarations, function (declaration) { return ts.isConstEnumDeclaration(declaration); })) {
+ displayParts.push(keywordPart(68 /* ConstKeyword */));
+ displayParts.push(spacePart());
+ }
displayParts.push(keywordPart(75 /* EnumKeyword */));
displayParts.push(spacePart());
addFullSymbolName(symbol);
@@ -21126,7 +21786,7 @@ var ts;
if (symbolFlags & 8 /* EnumMember */) {
addPrefixForAnyFunctionOrVar(symbol, "enum member");
var declaration = symbol.declarations[0];
- if (declaration.kind === 195 /* EnumMember */) {
+ if (declaration.kind === 196 /* EnumMember */) {
var constantValue = typeResolver.getEnumMemberValue(declaration);
if (constantValue !== undefined) {
displayParts.push(spacePart());
@@ -21142,7 +21802,7 @@ var ts;
displayParts.push(spacePart());
addFullSymbolName(symbol);
ts.forEach(symbol.declarations, function (declaration) {
- if (declaration.kind === 193 /* ImportDeclaration */) {
+ if (declaration.kind === 194 /* ImportDeclaration */) {
var importDeclaration = declaration;
if (importDeclaration.externalModuleName) {
displayParts.push(spacePart());
@@ -21289,7 +21949,7 @@ var ts;
var declarations = [];
var definition;
ts.forEach(signatureDeclarations, function (d) {
- if ((selectConstructors && d.kind === 126 /* Constructor */) || (!selectConstructors && (d.kind === 185 /* FunctionDeclaration */ || d.kind === 125 /* Method */))) {
+ if ((selectConstructors && d.kind === 126 /* Constructor */) || (!selectConstructors && (d.kind === 186 /* FunctionDeclaration */ || d.kind === 125 /* Method */))) {
declarations.push(d);
if (d.body)
definition = d;
@@ -21309,7 +21969,7 @@ var ts;
if (isNewExpressionTarget(location) || location.kind === 111 /* ConstructorKeyword */) {
if (symbol.flags & 32 /* Class */) {
var classDeclaration = symbol.getDeclarations()[0];
- ts.Debug.assert(classDeclaration && classDeclaration.kind === 187 /* ClassDeclaration */);
+ ts.Debug.assert(classDeclaration && classDeclaration.kind === 188 /* ClassDeclaration */);
return tryAddSignature(classDeclaration.members, true, symbolKind, symbolName, containerName, result);
}
}
@@ -21335,11 +21995,10 @@ var ts;
}
var comment = ts.forEach(sourceFile.referencedFiles, function (r) { return (r.pos <= position && position < r.end) ? r : undefined; });
if (comment) {
- var targetFilename = ts.isRootedDiskPath(comment.filename) ? comment.filename : ts.combinePaths(ts.getDirectoryPath(filename), comment.filename);
- targetFilename = ts.normalizePath(targetFilename);
- if (program.getSourceFile(targetFilename)) {
+ var referenceFile = ts.tryResolveScriptReference(program, sourceFile, comment);
+ if (referenceFile) {
return [{
- fileName: targetFilename,
+ fileName: referenceFile.filename,
textSpan: ts.TextSpan.fromBounds(0, 0),
kind: ScriptElementKind.scriptElement,
name: comment.filename,
@@ -21391,52 +22050,52 @@ var ts;
switch (node.kind) {
case 82 /* IfKeyword */:
case 74 /* ElseKeyword */:
- if (hasKind(node.parent, 165 /* IfStatement */)) {
+ if (hasKind(node.parent, 166 /* IfStatement */)) {
return getIfElseOccurrences(node.parent);
}
break;
case 88 /* ReturnKeyword */:
- if (hasKind(node.parent, 172 /* ReturnStatement */)) {
+ if (hasKind(node.parent, 173 /* ReturnStatement */)) {
return getReturnOccurrences(node.parent);
}
break;
case 92 /* ThrowKeyword */:
- if (hasKind(node.parent, 178 /* ThrowStatement */)) {
+ if (hasKind(node.parent, 179 /* ThrowStatement */)) {
return getThrowOccurrences(node.parent);
}
break;
case 94 /* TryKeyword */:
case 66 /* CatchKeyword */:
case 79 /* FinallyKeyword */:
- if (hasKind(parent(parent(node)), 179 /* TryStatement */)) {
+ if (hasKind(parent(parent(node)), 180 /* TryStatement */)) {
return getTryCatchFinallyOccurrences(node.parent.parent);
}
break;
case 90 /* SwitchKeyword */:
- if (hasKind(node.parent, 174 /* SwitchStatement */)) {
+ if (hasKind(node.parent, 175 /* SwitchStatement */)) {
return getSwitchCaseDefaultOccurrences(node.parent);
}
break;
case 65 /* CaseKeyword */:
case 71 /* DefaultKeyword */:
- if (hasKind(parent(parent(node)), 174 /* SwitchStatement */)) {
+ if (hasKind(parent(parent(node)), 175 /* SwitchStatement */)) {
return getSwitchCaseDefaultOccurrences(node.parent.parent);
}
break;
case 64 /* BreakKeyword */:
case 69 /* ContinueKeyword */:
- if (hasKind(node.parent, 171 /* BreakStatement */) || hasKind(node.parent, 170 /* ContinueStatement */)) {
+ if (hasKind(node.parent, 172 /* BreakStatement */) || hasKind(node.parent, 171 /* ContinueStatement */)) {
return getBreakOrContinueStatementOccurences(node.parent);
}
break;
case 80 /* ForKeyword */:
- if (hasKind(node.parent, 168 /* ForStatement */) || hasKind(node.parent, 169 /* ForInStatement */)) {
+ if (hasKind(node.parent, 169 /* ForStatement */) || hasKind(node.parent, 170 /* ForInStatement */)) {
return getLoopBreakContinueOccurrences(node.parent);
}
break;
case 98 /* WhileKeyword */:
case 73 /* DoKeyword */:
- if (hasKind(node.parent, 167 /* WhileStatement */) || hasKind(node.parent, 166 /* DoStatement */)) {
+ if (hasKind(node.parent, 168 /* WhileStatement */) || hasKind(node.parent, 167 /* DoStatement */)) {
return getLoopBreakContinueOccurrences(node.parent);
}
break;
@@ -21450,11 +22109,15 @@ var ts;
if (hasKind(node.parent, 127 /* GetAccessor */) || hasKind(node.parent, 128 /* SetAccessor */)) {
return getGetAndSetOccurrences(node.parent);
}
+ default:
+ if (ts.isModifier(node.kind) && node.parent && (ts.isDeclaration(node.parent) || node.parent.kind === 163 /* VariableStatement */)) {
+ return getModifierOccurrences(node.kind, node.parent);
+ }
}
return undefined;
function getIfElseOccurrences(ifStatement) {
var keywords = [];
- while (hasKind(ifStatement.parent, 165 /* IfStatement */) && ifStatement.parent.elseStatement === ifStatement) {
+ while (hasKind(ifStatement.parent, 166 /* IfStatement */) && ifStatement.parent.elseStatement === ifStatement) {
ifStatement = ifStatement.parent;
}
while (ifStatement) {
@@ -21465,7 +22128,7 @@ var ts;
break;
}
}
- if (!hasKind(ifStatement.elseStatement, 165 /* IfStatement */)) {
+ if (!hasKind(ifStatement.elseStatement, 166 /* IfStatement */)) {
break;
}
ifStatement = ifStatement.elseStatement;
@@ -21498,7 +22161,7 @@ var ts;
}
function getReturnOccurrences(returnStatement) {
var func = ts.getContainingFunction(returnStatement);
- if (!(func && hasKind(func.body, 186 /* FunctionBlock */))) {
+ if (!(func && hasKind(func.body, 187 /* FunctionBlock */))) {
return undefined;
}
var keywords = [];
@@ -21519,7 +22182,7 @@ var ts;
ts.forEach(aggregateOwnedThrowStatements(owner), function (throwStatement) {
pushKeywordIf(keywords, throwStatement.getFirstToken(), 92 /* ThrowKeyword */);
});
- if (owner.kind === 186 /* FunctionBlock */) {
+ if (owner.kind === 187 /* FunctionBlock */) {
ts.forEachReturnStatement(owner, function (returnStatement) {
pushKeywordIf(keywords, returnStatement.getFirstToken(), 88 /* ReturnKeyword */);
});
@@ -21531,10 +22194,10 @@ var ts;
aggregate(node);
return statementAccumulator;
function aggregate(node) {
- if (node.kind === 178 /* ThrowStatement */) {
+ if (node.kind === 179 /* ThrowStatement */) {
statementAccumulator.push(node);
}
- else if (node.kind === 179 /* TryStatement */) {
+ else if (node.kind === 180 /* TryStatement */) {
var tryStatement = node;
if (tryStatement.catchBlock) {
aggregate(tryStatement.catchBlock);
@@ -21556,10 +22219,10 @@ var ts;
var child = throwStatement;
while (child.parent) {
var parent = child.parent;
- if (parent.kind === 186 /* FunctionBlock */ || parent.kind === 196 /* SourceFile */) {
+ if (parent.kind === 187 /* FunctionBlock */ || parent.kind === 197 /* SourceFile */) {
return parent;
}
- if (parent.kind === 179 /* TryStatement */) {
+ if (parent.kind === 180 /* TryStatement */) {
var tryStatement = parent;
if (tryStatement.tryBlock === child && tryStatement.catchBlock) {
return child;
@@ -21583,7 +22246,7 @@ var ts;
function getLoopBreakContinueOccurrences(loopNode) {
var keywords = [];
if (pushKeywordIf(keywords, loopNode.getFirstToken(), 80 /* ForKeyword */, 98 /* WhileKeyword */, 73 /* DoKeyword */)) {
- if (loopNode.kind === 166 /* DoStatement */) {
+ if (loopNode.kind === 167 /* DoStatement */) {
var loopTokens = loopNode.getChildren();
for (var i = loopTokens.length - 1; i >= 0; i--) {
if (pushKeywordIf(keywords, loopTokens[i], 98 /* WhileKeyword */)) {
@@ -21618,12 +22281,12 @@ var ts;
var owner = getBreakOrContinueOwner(breakOrContinueStatement);
if (owner) {
switch (owner.kind) {
- case 168 /* ForStatement */:
- case 169 /* ForInStatement */:
- case 166 /* DoStatement */:
- case 167 /* WhileStatement */:
+ case 169 /* ForStatement */:
+ case 170 /* ForInStatement */:
+ case 167 /* DoStatement */:
+ case 168 /* WhileStatement */:
return getLoopBreakContinueOccurrences(owner);
- case 174 /* SwitchStatement */:
+ case 175 /* SwitchStatement */:
return getSwitchCaseDefaultOccurrences(owner);
}
}
@@ -21634,7 +22297,7 @@ var ts;
aggregate(node);
return statementAccumulator;
function aggregate(node) {
- if (node.kind === 171 /* BreakStatement */ || node.kind === 170 /* ContinueStatement */) {
+ if (node.kind === 172 /* BreakStatement */ || node.kind === 171 /* ContinueStatement */) {
statementAccumulator.push(node);
}
else if (!ts.isAnyFunction(node)) {
@@ -21650,14 +22313,14 @@ var ts;
function getBreakOrContinueOwner(statement) {
for (var node = statement.parent; node; node = node.parent) {
switch (node.kind) {
- case 174 /* SwitchStatement */:
- if (statement.kind === 170 /* ContinueStatement */) {
+ case 175 /* SwitchStatement */:
+ if (statement.kind === 171 /* ContinueStatement */) {
continue;
}
- case 168 /* ForStatement */:
- case 169 /* ForInStatement */:
- case 167 /* WhileStatement */:
- case 166 /* DoStatement */:
+ case 169 /* ForStatement */:
+ case 170 /* ForInStatement */:
+ case 168 /* WhileStatement */:
+ case 167 /* DoStatement */:
if (!statement.label || isLabeledBy(node, statement.label.text)) {
return node;
}
@@ -21693,6 +22356,73 @@ var ts;
}
}
}
+ function getModifierOccurrences(modifier, declaration) {
+ var container = declaration.parent;
+ if (declaration.flags & 112 /* AccessibilityModifier */) {
+ if (!(container.kind === 188 /* ClassDeclaration */ || (declaration.kind === 123 /* Parameter */ && hasKind(container, 126 /* Constructor */)))) {
+ return undefined;
+ }
+ }
+ else if (declaration.flags & 128 /* Static */) {
+ if (container.kind !== 188 /* ClassDeclaration */) {
+ return undefined;
+ }
+ }
+ else if (declaration.flags & (1 /* Export */ | 2 /* Ambient */)) {
+ if (!(container.kind === 193 /* ModuleBlock */ || container.kind === 197 /* SourceFile */)) {
+ return undefined;
+ }
+ }
+ var keywords = [];
+ var modifierFlag = getFlagFromModifier(modifier);
+ var nodes;
+ switch (container.kind) {
+ case 193 /* ModuleBlock */:
+ case 197 /* SourceFile */:
+ nodes = container.statements;
+ break;
+ case 126 /* Constructor */:
+ nodes = container.parameters.concat(container.parent.members);
+ break;
+ case 188 /* ClassDeclaration */:
+ nodes = container.members;
+ if (modifierFlag & 112 /* AccessibilityModifier */) {
+ var constructor = ts.forEach(container.members, function (member) {
+ return member.kind === 126 /* Constructor */ && member;
+ });
+ if (constructor) {
+ nodes = nodes.concat(constructor.parameters);
+ }
+ }
+ break;
+ default:
+ ts.Debug.fail("Invalid container kind.");
+ }
+ ts.forEach(nodes, function (node) {
+ if (node.flags & modifierFlag) {
+ ts.forEach(node.getChildren(), function (child) { return pushKeywordIf(keywords, child, modifier); });
+ }
+ });
+ return ts.map(keywords, getReferenceEntryFromNode);
+ function getFlagFromModifier(modifier) {
+ switch (modifier) {
+ case 106 /* PublicKeyword */:
+ return 16 /* Public */;
+ case 104 /* PrivateKeyword */:
+ return 32 /* Private */;
+ case 105 /* ProtectedKeyword */:
+ return 64 /* Protected */;
+ case 107 /* StaticKeyword */:
+ return 128 /* Static */;
+ case 76 /* ExportKeyword */:
+ return 1 /* Export */;
+ case 112 /* DeclareKeyword */:
+ return 2 /* Ambient */;
+ default:
+ ts.Debug.fail();
+ }
+ }
+ }
function hasKind(node, kind) {
return node !== undefined && node.kind === kind;
}
@@ -21757,30 +22487,38 @@ var ts;
}
var result;
var searchMeaning = getIntersectingMeaningFromDeclarations(getMeaningFromLocation(node), declarations);
- var symbolName = getNormalizedSymbolName(symbol.name, declarations);
+ var declaredName = getDeclaredName(symbol);
var scope = getSymbolScope(symbol);
if (scope) {
result = [];
- getReferencesInNode(scope, symbol, symbolName, node, searchMeaning, findInStrings, findInComments, result);
+ getReferencesInNode(scope, symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result);
}
else {
+ var internedName = getInternedName(symbol, declarations);
ts.forEach(sourceFiles, function (sourceFile) {
cancellationToken.throwIfCancellationRequested();
- if (ts.lookUp(sourceFile.identifiers, symbolName)) {
+ if (ts.lookUp(sourceFile.identifiers, internedName)) {
result = result || [];
- getReferencesInNode(sourceFile, symbol, symbolName, node, searchMeaning, findInStrings, findInComments, result);
+ getReferencesInNode(sourceFile, symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result);
}
});
}
return result;
- function getNormalizedSymbolName(symbolName, declarations) {
+ function getDeclaredName(symbol) {
+ var name = typeInfoResolver.symbolToString(symbol);
+ return stripQuotes(name);
+ }
+ function getInternedName(symbol, declarations) {
var functionExpression = ts.forEach(declarations, function (d) { return d.kind === 152 /* FunctionExpression */ ? d : undefined; });
if (functionExpression && functionExpression.name) {
var name = functionExpression.name.text;
}
else {
- var name = symbolName;
+ var name = symbol.name;
}
+ return stripQuotes(name);
+ }
+ function stripQuotes(name) {
var length = name.length;
if (length >= 2 && name.charCodeAt(0) === 34 /* doubleQuote */ && name.charCodeAt(length - 1) === 34 /* doubleQuote */) {
return name.substring(1, length - 1);
@@ -21792,7 +22530,7 @@ var ts;
if (symbol.getFlags() && (4 /* Property */ | 8192 /* Method */)) {
var privateDeclaration = ts.forEach(symbol.getDeclarations(), function (d) { return (d.flags & 32 /* Private */) ? d : undefined; });
if (privateDeclaration) {
- return ts.getAncestor(privateDeclaration, 187 /* ClassDeclaration */);
+ return ts.getAncestor(privateDeclaration, 188 /* ClassDeclaration */);
}
}
if (symbol.parent) {
@@ -21803,10 +22541,13 @@ var ts;
if (declarations) {
for (var i = 0, n = declarations.length; i < n; i++) {
var container = getContainerNode(declarations[i]);
+ if (!container) {
+ return undefined;
+ }
if (scope && scope !== container) {
return undefined;
}
- if (container.kind === 196 /* SourceFile */ && !ts.isExternalModule(container)) {
+ if (container.kind === 197 /* SourceFile */ && !ts.isExternalModule(container)) {
return undefined;
}
scope = container;
@@ -21972,18 +22713,18 @@ var ts;
staticFlag &= searchSpaceNode.flags;
searchSpaceNode = searchSpaceNode.parent;
break;
- case 196 /* SourceFile */:
+ case 197 /* SourceFile */:
if (ts.isExternalModule(searchSpaceNode)) {
return undefined;
}
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
case 152 /* FunctionExpression */:
break;
default:
return undefined;
}
var result = [];
- if (searchSpaceNode.kind === 196 /* SourceFile */) {
+ if (searchSpaceNode.kind === 197 /* SourceFile */) {
ts.forEach(sourceFiles, function (sourceFile) {
var possiblePositions = getPossibleSymbolReferencePositions(sourceFile, "this", sourceFile.getStart(), sourceFile.getEnd());
getThisReferencesInFile(sourceFile, sourceFile, possiblePositions, result);
@@ -22005,18 +22746,18 @@ var ts;
var container = ts.getThisContainer(node, false);
switch (searchSpaceNode.kind) {
case 152 /* FunctionExpression */:
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
if (searchSpaceNode.symbol === container.symbol) {
result.push(getReferenceEntryFromNode(node));
}
break;
- case 187 /* ClassDeclaration */:
+ case 188 /* ClassDeclaration */:
if (container.parent && searchSpaceNode.symbol === container.parent.symbol && (container.flags & 128 /* Static */) === staticFlag) {
result.push(getReferenceEntryFromNode(node));
}
break;
- case 196 /* SourceFile */:
- if (container.kind === 196 /* SourceFile */ && !ts.isExternalModule(container)) {
+ case 197 /* SourceFile */:
+ if (container.kind === 197 /* SourceFile */ && !ts.isExternalModule(container)) {
result.push(getReferenceEntryFromNode(node));
}
break;
@@ -22048,11 +22789,11 @@ var ts;
function getPropertySymbolsFromBaseTypes(symbol, propertyName, result) {
if (symbol && symbol.flags & (32 /* Class */ | 64 /* Interface */)) {
ts.forEach(symbol.getDeclarations(), function (declaration) {
- if (declaration.kind === 187 /* ClassDeclaration */) {
+ if (declaration.kind === 188 /* ClassDeclaration */) {
getPropertySymbolFromTypeReference(declaration.baseType);
ts.forEach(declaration.implementedTypes, getPropertySymbolFromTypeReference);
}
- else if (declaration.kind === 188 /* InterfaceDeclaration */) {
+ else if (declaration.kind === 189 /* InterfaceDeclaration */) {
ts.forEach(declaration.baseTypes, getPropertySymbolFromTypeReference);
}
});
@@ -22190,8 +22931,8 @@ var ts;
matchKind: MatchKind[matchKind],
fileName: filename,
textSpan: ts.TextSpan.fromBounds(declaration.getStart(), declaration.getEnd()),
- containerName: container.name ? container.name.text : "",
- containerKind: container.name ? getNodeKind(container) : ""
+ containerName: container && container.name ? container.name.text : "",
+ containerKind: container && container.name ? getNodeKind(container) : ""
});
}
}
@@ -22266,7 +23007,7 @@ var ts;
writer = undefined;
return emitOutput;
}
- var emitFilesResult = getFullTypeCheckChecker().invokeEmitter(targetSourceFile);
+ var emitFilesResult = getFullTypeCheckChecker().emitFiles(targetSourceFile);
emitOutput.emitOutputStatus = emitFilesResult.emitResultStatus;
writer = undefined;
return emitOutput;
@@ -22274,29 +23015,29 @@ var ts;
function getMeaningFromDeclaration(node) {
switch (node.kind) {
case 123 /* Parameter */:
- case 184 /* VariableDeclaration */:
+ case 185 /* VariableDeclaration */:
case 124 /* Property */:
case 143 /* PropertyAssignment */:
case 144 /* ShorthandPropertyAssignment */:
- case 195 /* EnumMember */:
+ case 196 /* EnumMember */:
case 125 /* Method */:
case 126 /* Constructor */:
case 127 /* GetAccessor */:
case 128 /* SetAccessor */:
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
case 152 /* FunctionExpression */:
case 153 /* ArrowFunction */:
- case 181 /* CatchBlock */:
+ case 182 /* CatchBlock */:
return 1 /* Value */;
case 122 /* TypeParameter */:
- case 188 /* InterfaceDeclaration */:
- case 189 /* TypeAliasDeclaration */:
+ case 189 /* InterfaceDeclaration */:
+ case 190 /* TypeAliasDeclaration */:
case 136 /* TypeLiteral */:
return 2 /* Type */;
- case 187 /* ClassDeclaration */:
- case 190 /* EnumDeclaration */:
+ case 188 /* ClassDeclaration */:
+ case 191 /* EnumDeclaration */:
return 1 /* Value */ | 2 /* Type */;
- case 191 /* ModuleDeclaration */:
+ case 192 /* ModuleDeclaration */:
if (node.name.kind === 7 /* StringLiteral */) {
return 4 /* Namespace */ | 1 /* Value */;
}
@@ -22306,9 +23047,10 @@ var ts;
else {
return 4 /* Namespace */;
}
- break;
- case 193 /* ImportDeclaration */:
+ case 194 /* ImportDeclaration */:
return 1 /* Value */ | 2 /* Type */ | 4 /* Namespace */;
+ case 197 /* SourceFile */:
+ return 4 /* Namespace */ | 1 /* Value */;
}
ts.Debug.fail("Unknown declaration type");
}
@@ -22332,17 +23074,17 @@ var ts;
while (node.parent.kind === 121 /* QualifiedName */) {
node = node.parent;
}
- return node.parent.kind === 193 /* ImportDeclaration */ && node.parent.entityName === node;
+ return node.parent.kind === 194 /* ImportDeclaration */ && node.parent.entityName === node;
}
function getMeaningFromRightHandSideOfImport(node) {
ts.Debug.assert(node.kind === 63 /* Identifier */);
- if (node.parent.kind === 121 /* QualifiedName */ && node.parent.right === node && node.parent.parent.kind === 193 /* ImportDeclaration */) {
+ if (node.parent.kind === 121 /* QualifiedName */ && node.parent.right === node && node.parent.parent.kind === 194 /* ImportDeclaration */) {
return 1 /* Value */ | 2 /* Type */ | 4 /* Namespace */;
}
return 4 /* Namespace */;
}
function getMeaningFromLocation(node) {
- if (node.parent.kind === 194 /* ExportAssignment */) {
+ if (node.parent.kind === 195 /* ExportAssignment */) {
return 1 /* Value */ | 2 /* Type */ | 4 /* Namespace */;
}
else if (isInRightSideOfImport(node)) {
@@ -22367,54 +23109,6 @@ var ts;
var sourceFile = getSourceFile(fileName);
return ts.SignatureHelp.getSignatureHelpItems(sourceFile, position, typeInfoResolver, cancellationToken);
}
- function getSignatureAtPosition(filename, position) {
- var signatureHelpItems = getSignatureHelpItems(filename, position);
- if (!signatureHelpItems) {
- return undefined;
- }
- var currentArgumentState = { argumentIndex: signatureHelpItems.argumentIndex, argumentCount: signatureHelpItems.argumentCount };
- var formalSignatures = [];
- ts.forEach(signatureHelpItems.items, function (signature) {
- var signatureInfoString = displayPartsToString(signature.prefixDisplayParts);
- var parameters = [];
- if (signature.parameters) {
- for (var i = 0, n = signature.parameters.length; i < n; i++) {
- var parameter = signature.parameters[i];
- if (i) {
- signatureInfoString += displayPartsToString(signature.separatorDisplayParts);
- }
- var start = signatureInfoString.length;
- signatureInfoString += displayPartsToString(parameter.displayParts);
- var end = signatureInfoString.length;
- parameters.push({
- name: parameter.name,
- isVariable: i === n - 1 && signature.isVariadic,
- docComment: displayPartsToString(parameter.documentation),
- minChar: start,
- limChar: end
- });
- }
- }
- signatureInfoString += displayPartsToString(signature.suffixDisplayParts);
- formalSignatures.push({
- signatureInfo: signatureInfoString,
- docComment: displayPartsToString(signature.documentation),
- parameters: parameters,
- typeParameters: []
- });
- });
- var actualSignature = {
- parameterMinChar: signatureHelpItems.applicableSpan.start(),
- parameterLimChar: signatureHelpItems.applicableSpan.end(),
- currentParameterIsTypeParameter: false,
- currentParameter: currentArgumentState.argumentIndex
- };
- return {
- actual: actualSignature,
- formal: formalSignatures,
- activeFormal: 0
- };
- }
function getCurrentSourceFile(filename) {
filename = ts.normalizeSlashes(filename);
var currentSourceFile = syntaxTreeCache.getCurrentSourceFile(filename);
@@ -22446,7 +23140,7 @@ var ts;
nodeForStartPos = nodeForStartPos.parent;
}
else if (isNameOfModuleDeclaration(nodeForStartPos)) {
- if (nodeForStartPos.parent.parent.kind === 191 /* ModuleDeclaration */ && nodeForStartPos.parent.parent.body === nodeForStartPos.parent) {
+ if (nodeForStartPos.parent.parent.kind === 192 /* ModuleDeclaration */ && nodeForStartPos.parent.parent.body === nodeForStartPos.parent) {
nodeForStartPos = nodeForStartPos.parent.parent.name;
}
else {
@@ -22498,7 +23192,7 @@ var ts;
return undefined;
function hasValueSideModule(symbol) {
return ts.forEach(symbol.declarations, function (declaration) {
- return declaration.kind === 191 /* ModuleDeclaration */ && ts.getModuleInstanceState(declaration) == 1 /* Instantiated */;
+ return declaration.kind === 192 /* ModuleDeclaration */ && ts.getModuleInstanceState(declaration) == 1 /* Instantiated */;
});
}
}
@@ -22559,7 +23253,7 @@ var ts;
}
}
if (ts.isPunctuation(token.kind)) {
- if (token.parent.kind === 156 /* BinaryExpression */ || token.parent.kind === 184 /* VariableDeclaration */ || token.parent.kind === 154 /* PrefixOperator */ || token.parent.kind === 155 /* PostfixOperator */ || token.parent.kind === 157 /* ConditionalExpression */) {
+ if (token.parent.kind === 156 /* BinaryExpression */ || token.parent.kind === 185 /* VariableDeclaration */ || token.parent.kind === 154 /* PrefixOperator */ || token.parent.kind === 155 /* PostfixOperator */ || token.parent.kind === 157 /* ConditionalExpression */) {
return ClassificationTypeNames.operator;
}
else {
@@ -22580,7 +23274,7 @@ var ts;
}
else if (tokenKind === 63 /* Identifier */) {
switch (token.parent.kind) {
- case 187 /* ClassDeclaration */:
+ case 188 /* ClassDeclaration */:
if (token.parent.name === token) {
return ClassificationTypeNames.className;
}
@@ -22590,17 +23284,17 @@ var ts;
return ClassificationTypeNames.typeParameterName;
}
return;
- case 188 /* InterfaceDeclaration */:
+ case 189 /* InterfaceDeclaration */:
if (token.parent.name === token) {
return ClassificationTypeNames.interfaceName;
}
return;
- case 190 /* EnumDeclaration */:
+ case 191 /* EnumDeclaration */:
if (token.parent.name === token) {
return ClassificationTypeNames.enumName;
}
return;
- case 191 /* ModuleDeclaration */:
+ case 192 /* ModuleDeclaration */:
if (token.parent.name === token) {
return ClassificationTypeNames.moduleName;
}
@@ -22842,7 +23536,7 @@ var ts;
getFormattingEditsForDocument: getFormattingEditsForDocument,
getFormattingEditsAfterKeystroke: getFormattingEditsAfterKeystroke,
getEmitOutput: getEmitOutput,
- getSignatureAtPosition: getSignatureAtPosition
+ getSourceFile: getCurrentSourceFile
};
}
ts.createLanguageService = createLanguageService;
@@ -22879,7 +23573,7 @@ var ts;
}
return true;
}
- function getClassificationsForLine(text, lexState) {
+ function getClassificationsForLine(text, lexState, classifyKeywordsInGenerics) {
var offset = 0;
var token = 0 /* Unknown */;
var lastNonTriviaToken = 0 /* Unknown */;
@@ -22924,7 +23618,7 @@ var ts;
angleBracketStack--;
}
else if (token === 109 /* AnyKeyword */ || token === 118 /* StringKeyword */ || token === 116 /* NumberKeyword */ || token === 110 /* BooleanKeyword */) {
- if (angleBracketStack > 0) {
+ if (angleBracketStack > 0 && !classifyKeywordsInGenerics) {
token = 63 /* Identifier */;
}
}
@@ -23055,7 +23749,7 @@ var ts;
getNodeConstructor: function (kind) {
function Node() {
}
- var proto = kind === 196 /* SourceFile */ ? new SourceFileObject() : new NodeObject();
+ var proto = kind === 197 /* SourceFile */ ? new SourceFileObject() : new NodeObject();
proto.kind = kind;
proto.pos = 0;
proto.end = 0;
@@ -23109,10 +23803,10 @@ var ts;
function spanInNode(node) {
if (node) {
if (ts.isExpression(node)) {
- if (node.parent.kind === 166 /* DoStatement */) {
+ if (node.parent.kind === 167 /* DoStatement */) {
return spanInPreviousNode(node);
}
- if (node.parent.kind === 168 /* ForStatement */) {
+ if (node.parent.kind === 169 /* ForStatement */) {
return textSpan(node);
}
if (node.parent.kind === 156 /* BinaryExpression */ && node.parent.operator === 22 /* CommaToken */) {
@@ -23123,14 +23817,14 @@ var ts;
}
}
switch (node.kind) {
- case 162 /* VariableStatement */:
+ case 163 /* VariableStatement */:
return spanInVariableDeclaration(node.declarations[0]);
- case 184 /* VariableDeclaration */:
+ case 185 /* VariableDeclaration */:
case 124 /* Property */:
return spanInVariableDeclaration(node);
case 123 /* Parameter */:
return spanInParameterDeclaration(node);
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
case 125 /* Method */:
case 127 /* GetAccessor */:
case 128 /* SetAccessor */:
@@ -23138,62 +23832,62 @@ var ts;
case 152 /* FunctionExpression */:
case 153 /* ArrowFunction */:
return spanInFunctionDeclaration(node);
- case 186 /* FunctionBlock */:
+ case 187 /* FunctionBlock */:
return spanInFunctionBlock(node);
- case 161 /* Block */:
- case 180 /* TryBlock */:
- case 181 /* CatchBlock */:
- case 182 /* FinallyBlock */:
- case 192 /* ModuleBlock */:
+ case 162 /* Block */:
+ case 181 /* TryBlock */:
+ case 182 /* CatchBlock */:
+ case 183 /* FinallyBlock */:
+ case 193 /* ModuleBlock */:
return spanInBlock(node);
- case 164 /* ExpressionStatement */:
+ case 165 /* ExpressionStatement */:
return textSpan(node.expression);
- case 172 /* ReturnStatement */:
+ case 173 /* ReturnStatement */:
return textSpan(node.getChildAt(0), node.expression);
- case 167 /* WhileStatement */:
+ case 168 /* WhileStatement */:
return textSpan(node, ts.findNextToken(node.expression, node));
- case 166 /* DoStatement */:
+ case 167 /* DoStatement */:
return spanInNode(node.statement);
- case 183 /* DebuggerStatement */:
+ case 184 /* DebuggerStatement */:
return textSpan(node.getChildAt(0));
- case 165 /* IfStatement */:
+ case 166 /* IfStatement */:
return textSpan(node, ts.findNextToken(node.expression, node));
- case 177 /* LabeledStatement */:
+ case 178 /* LabeledStatement */:
return spanInNode(node.statement);
- case 171 /* BreakStatement */:
- case 170 /* ContinueStatement */:
+ case 172 /* BreakStatement */:
+ case 171 /* ContinueStatement */:
return textSpan(node.getChildAt(0), node.label);
- case 168 /* ForStatement */:
+ case 169 /* ForStatement */:
return spanInForStatement(node);
- case 169 /* ForInStatement */:
+ case 170 /* ForInStatement */:
return textSpan(node, ts.findNextToken(node.expression, node));
- case 174 /* SwitchStatement */:
+ case 175 /* SwitchStatement */:
return textSpan(node, ts.findNextToken(node.expression, node));
- case 175 /* CaseClause */:
- case 176 /* DefaultClause */:
+ case 176 /* CaseClause */:
+ case 177 /* DefaultClause */:
return spanInNode(node.statements[0]);
- case 179 /* TryStatement */:
+ case 180 /* TryStatement */:
return spanInBlock(node.tryBlock);
- case 178 /* ThrowStatement */:
+ case 179 /* ThrowStatement */:
return textSpan(node, node.expression);
- case 194 /* ExportAssignment */:
+ case 195 /* ExportAssignment */:
return textSpan(node, node.exportName);
- case 193 /* ImportDeclaration */:
+ case 194 /* ImportDeclaration */:
return textSpan(node, node.entityName || node.externalModuleName);
- case 191 /* ModuleDeclaration */:
+ case 192 /* ModuleDeclaration */:
if (ts.getModuleInstanceState(node) !== 1 /* Instantiated */) {
return undefined;
}
- case 187 /* ClassDeclaration */:
- case 190 /* EnumDeclaration */:
- case 195 /* EnumMember */:
+ case 188 /* ClassDeclaration */:
+ case 191 /* EnumDeclaration */:
+ case 196 /* EnumMember */:
case 147 /* CallExpression */:
case 148 /* NewExpression */:
return textSpan(node);
- case 173 /* WithStatement */:
+ case 174 /* WithStatement */:
return spanInNode(node.statement);
- case 188 /* InterfaceDeclaration */:
- case 189 /* TypeAliasDeclaration */:
+ case 189 /* InterfaceDeclaration */:
+ case 190 /* TypeAliasDeclaration */:
return undefined;
case 21 /* SemicolonToken */:
case 1 /* EndOfFileToken */:
@@ -23233,11 +23927,11 @@ var ts;
}
}
function spanInVariableDeclaration(variableDeclaration) {
- if (variableDeclaration.parent.kind === 169 /* ForInStatement */) {
+ if (variableDeclaration.parent.kind === 170 /* ForInStatement */) {
return spanInNode(variableDeclaration.parent);
}
- var isParentVariableStatement = variableDeclaration.parent.kind === 162 /* VariableStatement */;
- var isDeclarationOfForStatement = variableDeclaration.parent.kind === 168 /* ForStatement */ && ts.contains(variableDeclaration.parent.declarations, variableDeclaration);
+ var isParentVariableStatement = variableDeclaration.parent.kind === 163 /* VariableStatement */;
+ var isDeclarationOfForStatement = variableDeclaration.parent.kind === 169 /* ForStatement */ && ts.contains(variableDeclaration.parent.declarations, variableDeclaration);
var declarations = isParentVariableStatement ? variableDeclaration.parent.declarations : isDeclarationOfForStatement ? variableDeclaration.parent.declarations : undefined;
if (variableDeclaration.initializer || (variableDeclaration.flags & 1 /* Export */)) {
if (declarations && declarations[0] === variableDeclaration) {
@@ -23277,7 +23971,7 @@ var ts;
}
}
function canFunctionHaveSpanInWholeDeclaration(functionDeclaration) {
- return !!(functionDeclaration.flags & 1 /* Export */) || (functionDeclaration.parent.kind === 187 /* ClassDeclaration */ && functionDeclaration.kind !== 126 /* Constructor */);
+ return !!(functionDeclaration.flags & 1 /* Export */) || (functionDeclaration.parent.kind === 188 /* ClassDeclaration */ && functionDeclaration.kind !== 126 /* Constructor */);
}
function spanInFunctionDeclaration(functionDeclaration) {
if (!functionDeclaration.body) {
@@ -23297,15 +23991,15 @@ var ts;
}
function spanInBlock(block) {
switch (block.parent.kind) {
- case 191 /* ModuleDeclaration */:
+ case 192 /* ModuleDeclaration */:
if (ts.getModuleInstanceState(block.parent) !== 1 /* Instantiated */) {
return undefined;
}
- case 167 /* WhileStatement */:
- case 165 /* IfStatement */:
- case 169 /* ForInStatement */:
+ case 168 /* WhileStatement */:
+ case 166 /* IfStatement */:
+ case 170 /* ForInStatement */:
return spanInNodeIfStartsOnSameLine(block.parent, block.statements[0]);
- case 168 /* ForStatement */:
+ case 169 /* ForStatement */:
return spanInNodeIfStartsOnSameLine(ts.findPrecedingToken(block.pos, sourceFile, block.parent), block.statements[0]);
}
return spanInNode(block.statements[0]);
@@ -23326,34 +24020,34 @@ var ts;
}
function spanInOpenBraceToken(node) {
switch (node.parent.kind) {
- case 190 /* EnumDeclaration */:
+ case 191 /* EnumDeclaration */:
var enumDeclaration = node.parent;
return spanInNodeIfStartsOnSameLine(ts.findPrecedingToken(node.pos, sourceFile, node.parent), enumDeclaration.members.length ? enumDeclaration.members[0] : enumDeclaration.getLastToken(sourceFile));
- case 187 /* ClassDeclaration */:
+ case 188 /* ClassDeclaration */:
var classDeclaration = node.parent;
return spanInNodeIfStartsOnSameLine(ts.findPrecedingToken(node.pos, sourceFile, node.parent), classDeclaration.members.length ? classDeclaration.members[0] : classDeclaration.getLastToken(sourceFile));
- case 174 /* SwitchStatement */:
+ case 175 /* SwitchStatement */:
return spanInNodeIfStartsOnSameLine(node.parent, node.parent.clauses[0]);
}
return spanInNode(node.parent);
}
function spanInCloseBraceToken(node) {
switch (node.parent.kind) {
- case 192 /* ModuleBlock */:
+ case 193 /* ModuleBlock */:
if (ts.getModuleInstanceState(node.parent.parent) !== 1 /* Instantiated */) {
return undefined;
}
- case 186 /* FunctionBlock */:
- case 190 /* EnumDeclaration */:
- case 187 /* ClassDeclaration */:
+ case 187 /* FunctionBlock */:
+ case 191 /* EnumDeclaration */:
+ case 188 /* ClassDeclaration */:
return textSpan(node);
- case 161 /* Block */:
- case 180 /* TryBlock */:
- case 181 /* CatchBlock */:
- case 182 /* FinallyBlock */:
+ case 162 /* Block */:
+ case 181 /* TryBlock */:
+ case 182 /* CatchBlock */:
+ case 183 /* FinallyBlock */:
return spanInNode(node.parent.statements[node.parent.statements.length - 1]);
;
- case 174 /* SwitchStatement */:
+ case 175 /* SwitchStatement */:
var switchStatement = node.parent;
var lastClause = switchStatement.clauses[switchStatement.clauses.length - 1];
if (lastClause) {
@@ -23365,7 +24059,7 @@ var ts;
}
}
function spanInOpenParenToken(node) {
- if (node.parent.kind === 166 /* DoStatement */) {
+ if (node.parent.kind === 167 /* DoStatement */) {
return spanInPreviousNode(node);
}
return spanInNode(node.parent);
@@ -23373,15 +24067,15 @@ var ts;
function spanInCloseParenToken(node) {
switch (node.parent.kind) {
case 152 /* FunctionExpression */:
- case 185 /* FunctionDeclaration */:
+ case 186 /* FunctionDeclaration */:
case 153 /* ArrowFunction */:
case 125 /* Method */:
case 127 /* GetAccessor */:
case 128 /* SetAccessor */:
case 126 /* Constructor */:
- case 167 /* WhileStatement */:
- case 166 /* DoStatement */:
- case 168 /* ForStatement */:
+ case 168 /* WhileStatement */:
+ case 167 /* DoStatement */:
+ case 169 /* ForStatement */:
return spanInPreviousNode(node);
default:
return spanInNode(node.parent);
@@ -23401,7 +24095,7 @@ var ts;
return spanInNode(node.parent);
}
function spanInWhileKeyword(node) {
- if (node.parent.kind === 166 /* DoStatement */) {
+ if (node.parent.kind === 167 /* DoStatement */) {
return textSpan(node, ts.findNextToken(node.parent.expression, node.parent));
}
return spanInNode(node.parent);
@@ -23720,12 +24414,6 @@ var ts;
return signatureInfo;
});
};
- LanguageServiceShimObject.prototype.getSignatureAtPosition = function (fileName, position) {
- var _this = this;
- return this.forwardJSONCall("getSignatureAtPosition('" + fileName + "', " + position + ")", function () {
- return _this.languageService.getSignatureAtPosition(fileName, position);
- });
- };
LanguageServiceShimObject.prototype.getDefinitionAtPosition = function (fileName, position) {
var _this = this;
return this.forwardJSONCall("getDefinitionAtPosition('" + fileName + "', " + position + ")", function () {
@@ -23852,8 +24540,8 @@ var ts;
this.logger = logger;
this.classifier = ts.createClassifier(this.logger);
}
- ClassifierShimObject.prototype.getClassificationsForLine = function (text, lexState) {
- var classification = this.classifier.getClassificationsForLine(text, lexState);
+ ClassifierShimObject.prototype.getClassificationsForLine = function (text, lexState, classifyKeywordsInGenerics) {
+ var classification = this.classifier.getClassificationsForLine(text, lexState, classifyKeywordsInGenerics);
var items = classification.entries;
var result = "";
for (var i = 0; i < items.length; i++) {
diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts
index 3622f4cda2f..a0fd0b243d6 100644
--- a/src/compiler/binder.ts
+++ b/src/compiler/binder.ts
@@ -18,7 +18,7 @@ module ts {
return ModuleInstanceState.NonInstantiated;
}
// 2. const enum declarations don't make module instantiated
- else if (node.kind === SyntaxKind.EnumDeclaration && isConstEnumDeclaration(node)) {
+ else if (isConstEnumDeclaration(node)) {
return ModuleInstanceState.ConstEnumOnly;
}
// 3. non - exported import declarations
@@ -53,12 +53,22 @@ module ts {
}
}
+ /**
+ * Returns false if any of the following are true:
+ * 1. declaration has no name
+ * 2. declaration has a literal name (not computed)
+ * 3. declaration has a computed property name that is a known symbol
+ */
+ export function hasComputedNameButNotSymbol(declaration: Declaration): boolean {
+ return declaration.name && declaration.name.kind === SyntaxKind.ComputedPropertyName;
+ }
+
export function bindSourceFile(file: SourceFile) {
var parent: Node;
- var container: Declaration;
+ var container: Node;
var blockScopeContainer: Node;
- var lastContainer: Declaration;
+ var lastContainer: Node;
var symbolCount = 0;
var Symbol = objectAllocator.getSymbolConstructor();
@@ -84,13 +94,14 @@ module ts {
if (symbolKind & SymbolFlags.Value && !symbol.valueDeclaration) symbol.valueDeclaration = node;
}
- // TODO(jfreeman): Implement getDeclarationName for property name
+ // Should not be called on a declaration with a computed property name.
function getDeclarationName(node: Declaration): string {
if (node.name) {
if (node.kind === SyntaxKind.ModuleDeclaration && node.name.kind === SyntaxKind.StringLiteral) {
return '"' + (node.name).text + '"';
}
- return (node.name).text;
+ Debug.assert(!hasComputedNameButNotSymbol(node));
+ return (node.name).text;
}
switch (node.kind) {
case SyntaxKind.ConstructorType:
@@ -111,6 +122,12 @@ module ts {
}
function declareSymbol(symbols: SymbolTable, parent: Symbol, node: Declaration, includes: SymbolFlags, excludes: SymbolFlags): Symbol {
+ // Nodes with computed property names will not get symbols, because the type checker
+ // does not make properties for them.
+ if (hasComputedNameButNotSymbol(node)) {
+ return undefined;
+ }
+
var name = getDeclarationName(node);
if (name !== undefined) {
var symbol = hasProperty(symbols, name) ? symbols[name] : (symbols[name] = createSymbol(0, name));
@@ -125,9 +142,9 @@ module ts {
: Diagnostics.Duplicate_identifier_0;
forEach(symbol.declarations, declaration => {
- file.semanticErrors.push(createDiagnosticForNode(declaration.name, message, getDisplayName(declaration)));
+ file.semanticDiagnostics.push(createDiagnosticForNode(declaration.name, message, getDisplayName(declaration)));
});
- file.semanticErrors.push(createDiagnosticForNode(node.name, message, getDisplayName(node)));
+ file.semanticDiagnostics.push(createDiagnosticForNode(node.name, message, getDisplayName(node)));
symbol = createSymbol(0, name);
}
@@ -148,7 +165,7 @@ module ts {
if (node.name) {
node.name.parent = node;
}
- file.semanticErrors.push(createDiagnosticForNode(symbol.exports[prototypeSymbol.name].declarations[0],
+ file.semanticDiagnostics.push(createDiagnosticForNode(symbol.exports[prototypeSymbol.name].declarations[0],
Diagnostics.Duplicate_identifier_0, prototypeSymbol.name));
}
symbol.exports[prototypeSymbol.name] = prototypeSymbol;
@@ -205,7 +222,7 @@ module ts {
// All container nodes are kept on a linked list in declaration order. This list is used by the getLocalNameOfContainer function
// in the type checker to validate that the local name used for a container is unique.
- function bindChildren(node: Declaration, symbolKind: SymbolFlags, isBlockScopeContainer: boolean) {
+ function bindChildren(node: Node, symbolKind: SymbolFlags, isBlockScopeContainer: boolean) {
if (symbolKind & SymbolFlags.HasLocals) {
node.locals = {};
}
@@ -262,7 +279,7 @@ module ts {
break;
}
case SyntaxKind.TypeLiteral:
- case SyntaxKind.ObjectLiteral:
+ case SyntaxKind.ObjectLiteralExpression:
case SyntaxKind.InterfaceDeclaration:
declareSymbol(container.symbol.members, container.symbol, node, symbolKind, symbolExcludes);
break;
@@ -324,7 +341,7 @@ module ts {
typeLiteralSymbol.members[node.kind === SyntaxKind.FunctionType ? "__call" : "__new"] = symbol
}
- function bindAnonymousDeclaration(node: Node, symbolKind: SymbolFlags, name: string, isBlockScopeContainer: boolean) {
+ function bindAnonymousDeclaration(node: Declaration, symbolKind: SymbolFlags, name: string, isBlockScopeContainer: boolean) {
var symbol = createSymbol(symbolKind, name);
addDeclarationToSymbol(symbol, node, symbolKind);
bindChildren(node, symbolKind, isBlockScopeContainer);
@@ -417,14 +434,14 @@ module ts {
break;
case SyntaxKind.TypeLiteral:
- bindAnonymousDeclaration(node, SymbolFlags.TypeLiteral, "__type", /*isBlockScopeContainer*/ false);
+ bindAnonymousDeclaration(node, SymbolFlags.TypeLiteral, "__type", /*isBlockScopeContainer*/ false);
break;
- case SyntaxKind.ObjectLiteral:
- bindAnonymousDeclaration(node, SymbolFlags.ObjectLiteral, "__object", /*isBlockScopeContainer*/ false);
+ case SyntaxKind.ObjectLiteralExpression:
+ bindAnonymousDeclaration(node, SymbolFlags.ObjectLiteral, "__object", /*isBlockScopeContainer*/ false);
break;
case SyntaxKind.FunctionExpression:
case SyntaxKind.ArrowFunction:
- bindAnonymousDeclaration(node, SymbolFlags.Function, "__function", /*isBlockScopeContainer*/ true);
+ bindAnonymousDeclaration(node, SymbolFlags.Function, "__function", /*isBlockScopeContainer*/ true);
break;
case SyntaxKind.CatchBlock:
bindCatchVariableDeclaration(node);
@@ -439,7 +456,7 @@ module ts {
bindDeclaration(node, SymbolFlags.TypeAlias, SymbolFlags.TypeAliasExcludes, /*isBlockScopeContainer*/ false);
break;
case SyntaxKind.EnumDeclaration:
- if (isConstEnumDeclaration(node)) {
+ if (isConst(node)) {
bindDeclaration(node, SymbolFlags.ConstEnum, SymbolFlags.ConstEnumExcludes, /*isBlockScopeContainer*/ false);
}
else {
@@ -454,7 +471,7 @@ module ts {
break;
case SyntaxKind.SourceFile:
if (isExternalModule(node)) {
- bindAnonymousDeclaration(node, SymbolFlags.ValueModule, '"' + removeFileExtension((node).filename) + '"', /*isBlockScopeContainer*/ true);
+ bindAnonymousDeclaration(node, SymbolFlags.ValueModule, '"' + removeFileExtension((node).filename) + '"', /*isBlockScopeContainer*/ true);
break;
}
diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts
index 8cf39b31295..c43d1074dfa 100644
--- a/src/compiler/checker.ts
+++ b/src/compiler/checker.ts
@@ -81,10 +81,11 @@ module ts {
getTypeCount: () => typeCount,
isUndefinedSymbol: symbol => symbol === undefinedSymbol,
isArgumentsSymbol: symbol => symbol === argumentsSymbol,
+ emitFiles: invokeEmitter,
getDiagnostics,
+ getDeclarationDiagnostics,
getGlobalDiagnostics,
checkProgram,
- invokeEmitter,
getParentOfSymbol,
getNarrowedTypeOfSymbol,
getDeclaredTypeOfSymbol,
@@ -885,13 +886,13 @@ module ts {
if (accessibleSymbolChain) {
var hasAccessibleDeclarations = hasVisibleDeclarations(accessibleSymbolChain[0]);
if (!hasAccessibleDeclarations) {
- return {
+ return {
accessibility: SymbolAccessibility.NotAccessible,
errorSymbolName: symbolToString(initialSymbol, enclosingDeclaration, meaning),
errorModuleName: symbol !== initialSymbol ? symbolToString(symbol, enclosingDeclaration, SymbolFlags.Namespace) : undefined,
};
}
- return { accessibility: SymbolAccessibility.Accessible, aliasesToMakeVisible: hasAccessibleDeclarations.aliasesToMakeVisible };
+ return hasAccessibleDeclarations;
}
// If we haven't got the accessible symbol, it doesn't mean the symbol is actually inaccessible.
@@ -934,7 +935,7 @@ module ts {
return { accessibility: SymbolAccessibility.Accessible };
- function getExternalModuleContainer(declaration: Declaration) {
+ function getExternalModuleContainer(declaration: Node) {
for (; declaration; declaration = declaration.parent) {
if (hasExternalModuleSymbol(declaration)) {
return getSymbolOfNode(declaration);
@@ -943,17 +944,17 @@ module ts {
}
}
- function hasExternalModuleSymbol(declaration: Declaration) {
- return (declaration.kind === SyntaxKind.ModuleDeclaration && declaration.name.kind === SyntaxKind.StringLiteral) ||
+ function hasExternalModuleSymbol(declaration: Node) {
+ return (declaration.kind === SyntaxKind.ModuleDeclaration && (declaration).name.kind === SyntaxKind.StringLiteral) ||
(declaration.kind === SyntaxKind.SourceFile && isExternalModule(declaration));
}
- function hasVisibleDeclarations(symbol: Symbol): { aliasesToMakeVisible?: ImportDeclaration[]; } {
+ function hasVisibleDeclarations(symbol: Symbol): SymbolVisibilityResult {
var aliasesToMakeVisible: ImportDeclaration[];
if (forEach(symbol.declarations, declaration => !getIsDeclarationVisible(declaration))) {
return undefined;
}
- return { aliasesToMakeVisible };
+ return { accessibility: SymbolAccessibility.Accessible, aliasesToMakeVisible };
function getIsDeclarationVisible(declaration: Declaration) {
if (!isDeclarationVisible(declaration)) {
@@ -961,7 +962,7 @@ module ts {
// because these kind of aliases can be used to name types in declaration file
if (declaration.kind === SyntaxKind.ImportDeclaration &&
!(declaration.flags & NodeFlags.Export) &&
- isDeclarationVisible(declaration.parent)) {
+ isDeclarationVisible(declaration.parent)) {
getNodeLinks(declaration).isVisible = true;
if (aliasesToMakeVisible) {
if (!contains(aliasesToMakeVisible, declaration)) {
@@ -982,14 +983,33 @@ module ts {
}
}
- function isImportDeclarationEntityNameReferenceDeclarationVisibile(entityName: EntityName): SymbolAccessiblityResult {
+ function isEntityNameVisible(entityName: EntityName, enclosingDeclaration: Node): SymbolVisibilityResult {
+ // get symbol of the first identifier of the entityName
+ var meaning: SymbolFlags;
+ if (entityName.parent.kind === SyntaxKind.TypeQuery) {
+ // Typeof value
+ meaning = SymbolFlags.Value | SymbolFlags.ExportValue;
+ }
+ else if (entityName.kind === SyntaxKind.QualifiedName ||
+ entityName.parent.kind === SyntaxKind.ImportDeclaration) {
+ // Left identifier from type reference or TypeAlias
+ // Entity name of the import declaration
+ meaning = SymbolFlags.Namespace;
+ }
+ else {
+ // Type Reference or TypeAlias entity = Identifier
+ meaning = SymbolFlags.Type;
+ }
+
var firstIdentifier = getFirstIdentifier(entityName);
- var symbolOfNameSpace = resolveName(entityName.parent, (firstIdentifier).text, SymbolFlags.Namespace, Diagnostics.Cannot_find_name_0, firstIdentifier);
+ var symbol = resolveName(enclosingDeclaration, (firstIdentifier).text, meaning, /*nodeNotFoundErrorMessage*/ undefined, /*nameArg*/ undefined);
+
// Verify if the symbol is accessible
- var hasNamespaceDeclarationsVisibile = hasVisibleDeclarations(symbolOfNameSpace);
- return hasNamespaceDeclarationsVisibile ?
- { accessibility: SymbolAccessibility.Accessible, aliasesToMakeVisible: hasNamespaceDeclarationsVisibile.aliasesToMakeVisible } :
- { accessibility: SymbolAccessibility.NotAccessible, errorSymbolName: declarationNameToString(firstIdentifier) };
+ return hasVisibleDeclarations(symbol) || {
+ accessibility: SymbolAccessibility.NotAccessible,
+ errorSymbolName: getTextOfNode(firstIdentifier),
+ errorNode: firstIdentifier
+ };
}
function releaseStringWriter(writer: StringSymbolWriter) {
@@ -1041,7 +1061,7 @@ module ts {
function getTypeAliasForTypeLiteral(type: Type): Symbol {
if (type.symbol && type.symbol.flags & SymbolFlags.TypeLiteral) {
var node = type.symbol.declarations[0].parent;
- while (node.kind === SyntaxKind.ParenType) {
+ while (node.kind === SyntaxKind.ParenthesizedType) {
node = node.parent;
}
if (node.kind === SyntaxKind.TypeAliasDeclaration) {
@@ -1555,12 +1575,12 @@ module ts {
}
// Container of resolvedExportSymbol is visible
- return forEach(resolvedExportSymbol.declarations, declaration => {
- while (declaration) {
- if (declaration === node) {
+ return forEach(resolvedExportSymbol.declarations, (current: Node) => {
+ while (current) {
+ if (current === node) {
return true;
}
- declaration = declaration.parent;
+ current = current.parent;
}
});
}
@@ -1585,7 +1605,7 @@ module ts {
return isGlobalSourceFile(parent) || isUsedInExportAssignment(node);
}
// Exported members/ambient module elements (exception import declaration) are visible if parent is visible
- return isDeclarationVisible(parent);
+ return isDeclarationVisible(parent);
case SyntaxKind.Property:
case SyntaxKind.Method:
@@ -1601,7 +1621,8 @@ module ts {
case SyntaxKind.IndexSignature:
case SyntaxKind.Parameter:
case SyntaxKind.ModuleBlock:
- return isDeclarationVisible(node.parent);
+ case SyntaxKind.TypeParameter:
+ return isDeclarationVisible(node.parent);
// Source file is always visible
case SyntaxKind.SourceFile:
@@ -1642,7 +1663,7 @@ module ts {
if (declaration.kind === SyntaxKind.Parameter) {
var func = declaration.parent;
// For a parameter of a set accessor, use the type of the get accessor if one is present
- if (func.kind === SyntaxKind.SetAccessor) {
+ if (func.kind === SyntaxKind.SetAccessor && !hasComputedNameButNotSymbol(func)) {
var getter = getDeclarationOfKind(declaration.parent.symbol, SyntaxKind.GetAccessor);
if (getter) {
return getReturnTypeOfSignature(getSignatureFromDeclaration(getter));
@@ -1784,7 +1805,7 @@ module ts {
}
else {
// If there are no specified types, try to infer it from the body of the get accessor if it exists.
- if (getter) {
+ if (getter && getter.body) {
type = getReturnTypeFromBody(getter);
}
// Otherwise, fall back to 'any'.
@@ -1916,8 +1937,9 @@ module ts {
}
type.baseTypes = [];
var declaration = getDeclarationOfKind(symbol, SyntaxKind.ClassDeclaration);
- if (declaration.baseType) {
- var baseType = getTypeFromTypeReferenceNode(declaration.baseType);
+ var baseTypeNode = getClassBaseTypeNode(declaration);
+ if (baseTypeNode) {
+ var baseType = getTypeFromTypeReferenceNode(baseTypeNode);
if (baseType !== unknownType) {
if (getTargetType(baseType).flags & TypeFlags.Class) {
if (type !== baseType && !hasBaseType(baseType, type)) {
@@ -1928,7 +1950,7 @@ module ts {
}
}
else {
- error(declaration.baseType, Diagnostics.A_class_may_only_extend_another_class);
+ error(baseTypeNode, Diagnostics.A_class_may_only_extend_another_class);
}
}
}
@@ -1956,8 +1978,8 @@ module ts {
}
type.baseTypes = [];
forEach(symbol.declarations, declaration => {
- if (declaration.kind === SyntaxKind.InterfaceDeclaration && (declaration).baseTypes) {
- forEach((declaration).baseTypes, node => {
+ if (declaration.kind === SyntaxKind.InterfaceDeclaration && getInterfaceBaseTypeNodes(declaration)) {
+ forEach(getInterfaceBaseTypeNodes(declaration), node => {
var baseType = getTypeFromTypeReferenceNode(node);
if (baseType !== unknownType) {
if (getTargetType(baseType).flags & (TypeFlags.Class | TypeFlags.Interface)) {
@@ -2510,7 +2532,7 @@ module ts {
else {
// TypeScript 1.0 spec (April 2014):
// If only one accessor includes a type annotation, the other behaves as if it had the same type annotation.
- if (declaration.kind === SyntaxKind.GetAccessor) {
+ if (declaration.kind === SyntaxKind.GetAccessor && !hasComputedNameButNotSymbol(declaration)) {
var setter = getDeclarationOfKind(declaration.symbol, SyntaxKind.SetAccessor);
returnType = getAnnotatedAccessorType(setter);
}
@@ -3020,8 +3042,8 @@ module ts {
return getTypeFromTupleTypeNode(node);
case SyntaxKind.UnionType:
return getTypeFromUnionTypeNode(node);
- case SyntaxKind.ParenType:
- return getTypeFromTypeNode((node).type);
+ case SyntaxKind.ParenthesizedType:
+ return getTypeFromTypeNode((node).type);
case SyntaxKind.FunctionType:
case SyntaxKind.ConstructorType:
case SyntaxKind.TypeLiteral:
@@ -3202,11 +3224,11 @@ module ts {
case SyntaxKind.FunctionExpression:
case SyntaxKind.ArrowFunction:
return !(node).typeParameters && !forEach((node).parameters, p => p.type);
- case SyntaxKind.ObjectLiteral:
- return forEach((node).properties, p =>
+ case SyntaxKind.ObjectLiteralExpression:
+ return forEach((node).properties, p =>
p.kind === SyntaxKind.PropertyAssignment && isContextSensitiveExpression((p).initializer));
- case SyntaxKind.ArrayLiteral:
- return forEach((node).elements, e => isContextSensitiveExpression(e));
+ case SyntaxKind.ArrayLiteralExpression:
+ return forEach((node).elements, e => isContextSensitiveExpression(e));
case SyntaxKind.ConditionalExpression:
return isContextSensitiveExpression((node).whenTrue) ||
isContextSensitiveExpression((node).whenFalse);
@@ -4281,8 +4303,8 @@ module ts {
function isAssignedInBinaryExpression(node: BinaryExpression) {
if (node.operator >= SyntaxKind.FirstAssignment && node.operator <= SyntaxKind.LastAssignment) {
var n = node.left;
- while (n.kind === SyntaxKind.ParenExpression) {
- n = (n).expression;
+ while (n.kind === SyntaxKind.ParenthesizedExpression) {
+ n = (n).expression;
}
if (n.kind === SyntaxKind.Identifier && getResolvedSymbol(n) === symbol) {
return true;
@@ -4304,16 +4326,19 @@ module ts {
return isAssignedInBinaryExpression(node);
case SyntaxKind.VariableDeclaration:
return isAssignedInVariableDeclaration(node);
- case SyntaxKind.ArrayLiteral:
- case SyntaxKind.ObjectLiteral:
- case SyntaxKind.PropertyAccess:
- case SyntaxKind.IndexedAccess:
+ case SyntaxKind.ArrayLiteralExpression:
+ case SyntaxKind.ObjectLiteralExpression:
+ case SyntaxKind.PropertyAccessExpression:
+ case SyntaxKind.ElementAccessExpression:
case SyntaxKind.CallExpression:
case SyntaxKind.NewExpression:
- case SyntaxKind.TypeAssertion:
- case SyntaxKind.ParenExpression:
- case SyntaxKind.PrefixOperator:
- case SyntaxKind.PostfixOperator:
+ case SyntaxKind.TypeAssertionExpression:
+ case SyntaxKind.ParenthesizedExpression:
+ case SyntaxKind.PrefixUnaryExpression:
+ case SyntaxKind.DeleteExpression:
+ case SyntaxKind.TypeOfExpression:
+ case SyntaxKind.VoidExpression:
+ case SyntaxKind.PostfixUnaryExpression:
case SyntaxKind.ConditionalExpression:
case SyntaxKind.Block:
case SyntaxKind.VariableStatement:
@@ -4395,19 +4420,25 @@ module ts {
return type;
function narrowTypeByEquality(type: Type, expr: BinaryExpression, assumeTrue: boolean): Type {
- var left = expr.left;
- var right = expr.right;
// Check that we have 'typeof ' on the left and string literal on the right
- if (left.kind !== SyntaxKind.PrefixOperator || left.operator !== SyntaxKind.TypeOfKeyword ||
- left.operand.kind !== SyntaxKind.Identifier || right.kind !== SyntaxKind.StringLiteral ||
- getResolvedSymbol(left.operand) !== symbol) {
+ if (expr.left.kind !== SyntaxKind.TypeOfExpression || expr.right.kind !== SyntaxKind.StringLiteral) {
return type;
}
+
+ var left = expr.left;
+ var right = expr.right;
+ if (left.expression.kind !== SyntaxKind.Identifier ||
+ getResolvedSymbol(left.expression) !== symbol) {
+
+ return type;
+ }
+
var t = right.text;
var checkType: Type = t === "string" ? stringType : t === "number" ? numberType : t === "boolean" ? booleanType : emptyObjectType;
if (expr.operator === SyntaxKind.ExclamationEqualsEqualsToken) {
assumeTrue = !assumeTrue;
}
+
if (assumeTrue) {
// The assumed result is true. If check was for a primitive type, that type is the narrowed type. Otherwise we can
// remove the primitive types from the narrowed type.
@@ -4472,8 +4503,8 @@ module ts {
// Narrow the given type based on the given expression having the assumed boolean value
function narrowType(type: Type, expr: Expression, assumeTrue: boolean): Type {
switch (expr.kind) {
- case SyntaxKind.ParenExpression:
- return narrowType(type, (expr).expression, assumeTrue);
+ case SyntaxKind.ParenthesizedExpression:
+ return narrowType(type, (expr).expression, assumeTrue);
case SyntaxKind.BinaryExpression:
var operator = (expr).operator;
if (operator === SyntaxKind.EqualsEqualsEqualsToken || operator === SyntaxKind.ExclamationEqualsEqualsToken) {
@@ -4489,9 +4520,9 @@ module ts {
return narrowTypeByInstanceof(type, expr, assumeTrue);
}
break;
- case SyntaxKind.PrefixOperator:
- if ((expr).operator === SyntaxKind.ExclamationToken) {
- return narrowType(type, (expr).operand, !assumeTrue);
+ case SyntaxKind.PrefixUnaryExpression:
+ if ((expr).operator === SyntaxKind.ExclamationToken) {
+ return narrowType(type,(expr).operand, !assumeTrue);
}
break;
}
@@ -4601,10 +4632,10 @@ module ts {
}
function checkSuperExpression(node: Node): Type {
- var isCallExpression = node.parent.kind === SyntaxKind.CallExpression && (node.parent).func === node;
+ var isCallExpression = node.parent.kind === SyntaxKind.CallExpression && (node.parent).expression === node;
var enclosingClass = getAncestor(node, SyntaxKind.ClassDeclaration);
var baseClass: Type;
- if (enclosingClass && enclosingClass.baseType) {
+ if (enclosingClass && getClassBaseTypeNode(enclosingClass)) {
var classType = getDeclaredTypeOfSymbol(getSymbolOfNode(enclosingClass));
baseClass = classType.baseTypes.length && classType.baseTypes[0];
}
@@ -4696,8 +4727,8 @@ module ts {
// Return contextual type of parameter or undefined if no contextual type is available
function getContextuallyTypedParameterType(parameter: ParameterDeclaration): Type {
- var func = parameter.parent;
- if (func.kind === SyntaxKind.FunctionExpression || func.kind === SyntaxKind.ArrowFunction) {
+ if (isFunctionExpressionOrArrowFunction(parameter.parent)) {
+ var func = parameter.parent;
if (isContextSensitiveExpression(func)) {
var contextualSignature = getContextualSignature(func);
if (contextualSignature) {
@@ -4747,7 +4778,7 @@ module ts {
}
// Otherwise, if the containing function is contextually typed by a function type with exactly one call signature
// and that call signature is non-generic, return statements are contextually typed by the return type of the signature
- var signature = getContextualSignature(func);
+ var signature = getContextualSignatureForFunctionLikeDeclaration(func);
if (signature) {
return getReturnTypeOfSignature(signature);
}
@@ -4840,7 +4871,7 @@ module ts {
// exists. Otherwise, it is the type of the string index signature in T, if one exists.
function getContextualTypeForPropertyExpression(node: Expression): Type {
var declaration = node.parent;
- var objectLiteral = declaration.parent;
+ var objectLiteral = declaration.parent;
var type = getContextualType(objectLiteral);
// TODO(jfreeman): Handle this case for computed names and symbols
var name = (declaration.name).text;
@@ -4856,7 +4887,7 @@ module ts {
// the type of the property with the numeric name N in T, if one exists. Otherwise, it is the type of the numeric
// index signature in T, if one exists.
function getContextualTypeForElementExpression(node: Expression): Type {
- var arrayLiteral = node.parent;
+ var arrayLiteral = node.parent;
var type = getContextualType(arrayLiteral);
if (type) {
var index = indexOf(arrayLiteral.elements, node);
@@ -4893,13 +4924,13 @@ module ts {
case SyntaxKind.CallExpression:
case SyntaxKind.NewExpression:
return getContextualTypeForArgument(node);
- case SyntaxKind.TypeAssertion:
+ case SyntaxKind.TypeAssertionExpression:
return getTypeFromTypeNode((parent).type);
case SyntaxKind.BinaryExpression:
return getContextualTypeForBinaryOperand(node);
case SyntaxKind.PropertyAssignment:
return getContextualTypeForPropertyExpression(node);
- case SyntaxKind.ArrayLiteral:
+ case SyntaxKind.ArrayLiteralExpression:
return getContextualTypeForElementExpression(node);
case SyntaxKind.ConditionalExpression:
return getContextualTypeForConditionalOperand(node);
@@ -4919,12 +4950,21 @@ module ts {
}
}
+ function isFunctionExpressionOrArrowFunction(node: Node): boolean {
+ return node.kind === SyntaxKind.FunctionExpression || node.kind === SyntaxKind.ArrowFunction;
+ }
+
+ function getContextualSignatureForFunctionLikeDeclaration(node: FunctionLikeDeclaration): Signature {
+ // Only function expressions and arrow functions are contextually typed.
+ return isFunctionExpressionOrArrowFunction(node) ? getContextualSignature(node) : undefined;
+ }
+
// Return the contextual signature for a given expression node. A contextual type provides a
// contextual signature if it has a single call signature and if that call signature is non-generic.
// If the contextual type is a union type, get the signature from each type possible and if they are
// all identical ignoring their return type, the result is same signature but with return type as
// union type of return types from these signatures
- function getContextualSignature(node: Expression): Signature {
+ function getContextualSignature(node: FunctionExpression): Signature {
var type = getContextualType(node);
if (!type) {
return undefined;
@@ -4976,7 +5016,7 @@ module ts {
return mapper && mapper !== identityMapper;
}
- function checkArrayLiteral(node: ArrayLiteral, contextualMapper?: TypeMapper): Type {
+ function checkArrayLiteral(node: ArrayLiteralExpression, contextualMapper?: TypeMapper): Type {
var elements = node.elements;
if (!elements.length) {
return createArrayType(undefinedType);
@@ -5014,7 +5054,7 @@ module ts {
return (+name).toString() === name;
}
- function checkObjectLiteral(node: ObjectLiteral, contextualMapper?: TypeMapper): Type {
+ function checkObjectLiteral(node: ObjectLiteralExpression, contextualMapper?: TypeMapper): Type {
var members = node.symbol.members;
var properties: SymbolTable = {};
var contextualType = getContextualType(node);
@@ -5029,7 +5069,9 @@ module ts {
}
else {
Debug.assert(memberDecl.kind === SyntaxKind.ShorthandPropertyAssignment);
- type = checkExpression(memberDecl.name, contextualMapper);
+ type = memberDecl.name.kind === SyntaxKind.ComputedPropertyName
+ ? unknownType
+ : checkExpression(memberDecl.name, contextualMapper);
}
var prop = createSymbol(SymbolFlags.Property | SymbolFlags.Transient | member.flags, member.name);
prop.declarations = member.declarations;
@@ -5091,7 +5133,7 @@ module ts {
return s.valueDeclaration ? s.valueDeclaration.flags : s.flags & SymbolFlags.Prototype ? NodeFlags.Public | NodeFlags.Static : 0;
}
- function checkClassPropertyAccess(node: PropertyAccess, type: Type, prop: Symbol) {
+ function checkClassPropertyAccess(node: PropertyAccessExpression | QualifiedName, left: Expression | QualifiedName, type: Type, prop: Symbol) {
var flags = getDeclarationFlagsFromSymbol(prop);
// Public properties are always accessible
if (!(flags & (NodeFlags.Private | NodeFlags.Protected))) {
@@ -5111,7 +5153,7 @@ module ts {
}
// Property is known to be protected at this point
// All protected properties of a supertype are accessible in a super access
- if (node.left.kind === SyntaxKind.SuperKeyword) {
+ if (left.kind === SyntaxKind.SuperKeyword) {
return;
}
// A protected property is accessible in the declaring class and classes derived from it
@@ -5129,8 +5171,16 @@ module ts {
}
}
- function checkPropertyAccess(node: PropertyAccess) {
- var type = checkExpression(node.left);
+ function checkPropertyAccessExpression(node: PropertyAccessExpression) {
+ return checkPropertyAccessExpressionOrQualifiedName(node, node.expression, node.name);
+ }
+
+ function checkQualifiedName(node: QualifiedName) {
+ return checkPropertyAccessExpressionOrQualifiedName(node, node.left, node.right);
+ }
+
+ function checkPropertyAccessExpressionOrQualifiedName(node: PropertyAccessExpression | QualifiedName, left: Expression | QualifiedName, right: Identifier) {
+ var type = checkExpression(left);
if (type === unknownType) return type;
if (type !== anyType) {
var apparentType = getApparentType(getWidenedType(type));
@@ -5138,10 +5188,10 @@ module ts {
// handle cases when type is Type parameter with invalid constraint
return unknownType;
}
- var prop = getPropertyOfType(apparentType, node.right.text);
+ var prop = getPropertyOfType(apparentType, right.text);
if (!prop) {
- if (node.right.text) {
- error(node.right, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(node.right), typeToString(type));
+ if (right.text) {
+ error(right, Diagnostics.Property_0_does_not_exist_on_type_1, declarationNameToString(right), typeToString(type));
}
return unknownType;
}
@@ -5154,11 +5204,11 @@ module ts {
// - In a static member function or static member accessor
// where this references the constructor function object of a derived class,
// a super property access is permitted and must specify a public static member function of the base class.
- if (node.left.kind === SyntaxKind.SuperKeyword && getDeclarationKindFromSymbol(prop) !== SyntaxKind.Method) {
- error(node.right, Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword);
+ if (left.kind === SyntaxKind.SuperKeyword && getDeclarationKindFromSymbol(prop) !== SyntaxKind.Method) {
+ error(right, Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword);
}
else {
- checkClassPropertyAccess(node, type, prop);
+ checkClassPropertyAccess(node, left, type, prop);
}
}
return getTypeOfSymbol(prop);
@@ -5166,17 +5216,21 @@ module ts {
return anyType;
}
- function isValidPropertyAccess(node: PropertyAccess, propertyName: string): boolean {
- var type = checkExpression(node.left);
+ function isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean {
+ var left = node.kind === SyntaxKind.PropertyAccessExpression
+ ? (node).expression
+ : (node).left;
+
+ var type = checkExpression(left);
if (type !== unknownType && type !== anyType) {
var prop = getPropertyOfType(getWidenedType(type), propertyName);
if (prop && prop.parent && prop.parent.flags & SymbolFlags.Class) {
- if (node.left.kind === SyntaxKind.SuperKeyword && getDeclarationKindFromSymbol(prop) !== SyntaxKind.Method) {
+ if (left.kind === SyntaxKind.SuperKeyword && getDeclarationKindFromSymbol(prop) !== SyntaxKind.Method) {
return false;
}
else {
var diagnosticsCount = diagnostics.length;
- checkClassPropertyAccess(node, type, prop);
+ checkClassPropertyAccess(node, left, type, prop);
return diagnostics.length === diagnosticsCount
}
}
@@ -5184,15 +5238,15 @@ module ts {
return true;
}
- function checkIndexedAccess(node: IndexedAccess): Type {
+ function checkIndexedAccess(node: ElementAccessExpression): Type {
// Obtain base constraint such that we can bail out if the constraint is an unknown type
- var objectType = getApparentType(checkExpression(node.object));
- var indexType = checkExpression(node.index);
+ var objectType = getApparentType(checkExpression(node.expression));
+ var indexType = checkExpression(node.argumentExpression);
if (objectType === unknownType) return unknownType;
- if (isConstEnumObjectType(objectType) && node.index.kind !== SyntaxKind.StringLiteral) {
- error(node.index, Diagnostics.Index_expression_arguments_in_const_enums_must_be_of_type_string);
+ if (isConstEnumObjectType(objectType) && node.argumentExpression.kind !== SyntaxKind.StringLiteral) {
+ error(node.argumentExpression, Diagnostics.Index_expression_arguments_in_const_enums_must_be_of_type_string);
}
// TypeScript 1.0 spec (April 2014): 4.10 Property Access
@@ -5205,8 +5259,8 @@ module ts {
// - Otherwise, if IndexExpr is of type Any, the String or Number primitive type, or an enum type, the property access is of type Any.
// See if we can index as a property.
- if (node.index.kind === SyntaxKind.StringLiteral || node.index.kind === SyntaxKind.NumericLiteral) {
- var name = (node.index).text;
+ if (node.argumentExpression.kind === SyntaxKind.StringLiteral || node.argumentExpression.kind === SyntaxKind.NumericLiteral) {
+ var name = (node.argumentExpression).text;
var prop = getPropertyOfType(objectType, name);
if (prop) {
getNodeLinks(node).resolvedSymbol = prop;
@@ -5453,7 +5507,7 @@ module ts {
// String literals get string literal types unless we're reporting errors
argType = arg.kind === SyntaxKind.StringLiteral && !reportErrors
? getStringLiteralType(arg)
- : checkExpressionWithContextualType(arg, paramType, excludeArgument && excludeArgument[i] ? identityMapper : undefined);
+ : checkExpressionWithContextualType(arg, paramType, excludeArgument && excludeArgument[i] ? identityMapper : undefined);
}
// Use argument expression as error location when reporting errors
@@ -5605,7 +5659,7 @@ module ts {
Diagnostics.The_type_argument_for_type_parameter_0_cannot_be_inferred_from_the_usage_Consider_specifying_the_type_arguments_explicitly,
typeToString(failedTypeParameter));
- reportNoCommonSupertypeError(inferenceCandidates, (node).func || (node).tag, diagnosticChainHead);
+ reportNoCommonSupertypeError(inferenceCandidates, (node).expression || (node).tag, diagnosticChainHead);
}
}
else {
@@ -5735,15 +5789,15 @@ module ts {
}
function resolveCallExpression(node: CallExpression, candidatesOutArray: Signature[]): Signature {
- if (node.func.kind === SyntaxKind.SuperKeyword) {
- var superType = checkSuperExpression(node.func);
+ if (node.expression.kind === SyntaxKind.SuperKeyword) {
+ var superType = checkSuperExpression(node.expression);
if (superType !== unknownType) {
return resolveCall(node, getSignaturesOfType(superType, SignatureKind.Construct), candidatesOutArray);
}
return resolveUntypedCall(node);
}
- var funcType = checkExpression(node.func);
+ var funcType = checkExpression(node.expression);
var apparentType = getApparentType(funcType);
if (apparentType === unknownType) {
@@ -5787,7 +5841,7 @@ module ts {
}
function resolveNewExpression(node: NewExpression, candidatesOutArray: Signature[]): Signature {
- var expressionType = checkExpression(node.func);
+ var expressionType = checkExpression(node.expression);
// TS 1.0 spec: 4.11
// If ConstructExpr is of type Any, Args can be any argument
// list and the result of the operation is of type Any.
@@ -5887,7 +5941,7 @@ module ts {
function checkCallExpression(node: CallExpression): Type {
var signature = getResolvedSignature(node);
- if (node.func.kind === SyntaxKind.SuperKeyword) {
+ if (node.expression.kind === SyntaxKind.SuperKeyword) {
return voidType;
}
if (node.kind === SyntaxKind.NewExpression) {
@@ -5912,7 +5966,7 @@ module ts {
}
function checkTypeAssertion(node: TypeAssertion): Type {
- var exprType = checkExpression(node.operand);
+ var exprType = checkExpression(node.expression);
var targetType = getTypeFromTypeNode(node.type);
if (fullTypeCheck && targetType !== unknownType) {
var widenedType = getWidenedType(exprType, /*supressNoImplicitAnyErrors*/ true);
@@ -5944,9 +5998,9 @@ module ts {
}
function getReturnTypeFromBody(func: FunctionLikeDeclaration, contextualMapper?: TypeMapper): Type {
- var contextualSignature = getContextualSignature(func);
+ var contextualSignature = getContextualSignatureForFunctionLikeDeclaration(func);
if (func.body.kind !== SyntaxKind.FunctionBlock) {
- var unwidenedType = checkAndMarkExpression(func.body, contextualMapper);
+ var unwidenedType = checkAndMarkExpression(func.body, contextualMapper);
var widenedType = getWidenedType(unwidenedType);
if (fullTypeCheck && compilerOptions.noImplicitAny && !contextualSignature && widenedType !== unwidenedType && getInnermostTypeOfNestedArrayTypes(widenedType) === anyType) {
@@ -6085,6 +6139,12 @@ module ts {
checkSignatureDeclaration(node);
}
}
+
+ if (fullTypeCheck) {
+ checkCollisionWithCapturedSuperVariable(node, node.name);
+ checkCollisionWithCapturedThisVariable(node, node.name);
+ }
+
return type;
}
@@ -6096,7 +6156,7 @@ module ts {
checkSourceElement(node.body);
}
else {
- var exprType = checkExpression(node.body);
+ var exprType = checkExpression(node.body);
if (node.type) {
checkTypeAssignableTo(exprType, getTypeFromTypeNode(node.type), node.body, /*headMessage*/ undefined);
}
@@ -6135,17 +6195,17 @@ module ts {
// An identifier expression that references a variable or parameter is classified as a reference.
// An identifier expression that references any other kind of entity is classified as a value(and therefore cannot be the target of an assignment).
return !symbol || symbol === unknownSymbol || symbol === argumentsSymbol || (symbol.flags & SymbolFlags.Variable) !== 0;
- case SyntaxKind.PropertyAccess:
+ case SyntaxKind.PropertyAccessExpression:
var symbol = findSymbol(n);
// TypeScript 1.0 spec (April 2014): 4.10
// A property access expression is always classified as a reference.
// NOTE (not in spec): assignment to enum members should not be allowed
return !symbol || symbol === unknownSymbol || (symbol.flags & ~SymbolFlags.EnumMember) !== 0;
- case SyntaxKind.IndexedAccess:
+ case SyntaxKind.ElementAccessExpression:
// old compiler doesn't check indexed assess
return true;
- case SyntaxKind.ParenExpression:
- return isReferenceOrErrorExpression((n).expression);
+ case SyntaxKind.ParenthesizedExpression:
+ return isReferenceOrErrorExpression((n).expression);
default:
return false;
}
@@ -6154,20 +6214,20 @@ module ts {
function isConstVariableReference(n: Node): boolean {
switch (n.kind) {
case SyntaxKind.Identifier:
- case SyntaxKind.PropertyAccess:
+ case SyntaxKind.PropertyAccessExpression:
var symbol = findSymbol(n);
return symbol && (symbol.flags & SymbolFlags.Variable) !== 0 && (getDeclarationFlagsFromSymbol(symbol) & NodeFlags.Const) !== 0;
- case SyntaxKind.IndexedAccess:
- var index = (n).index;
- var symbol = findSymbol((n).object);
+ case SyntaxKind.ElementAccessExpression:
+ var index = (n).argumentExpression;
+ var symbol = findSymbol((n).expression);
if (symbol && index.kind === SyntaxKind.StringLiteral) {
var name = (index).text;
var prop = getPropertyOfType(getTypeOfSymbol(symbol), name);
return prop && (prop.flags & SymbolFlags.Variable) !== 0 && (getDeclarationFlagsFromSymbol(prop) & NodeFlags.Const) !== 0;
}
return false;
- case SyntaxKind.ParenExpression:
- return isConstVariableReference((n).expression);
+ case SyntaxKind.ParenthesizedExpression:
+ return isConstVariableReference((n).expression);
default:
return false;
}
@@ -6184,7 +6244,22 @@ module ts {
return true;
}
- function checkPrefixExpression(node: UnaryExpression): Type {
+ function checkDeleteExpression(node: DeleteExpression): Type {
+ var operandType = checkExpression(node.expression);
+ return booleanType;
+ }
+
+ function checkTypeOfExpression(node: TypeOfExpression): Type {
+ var operandType = checkExpression(node.expression);
+ return stringType;
+ }
+
+ function checkVoidExpression(node: VoidExpression): Type {
+ var operandType = checkExpression(node.expression);
+ return undefinedType;
+ }
+
+ function checkPrefixUnaryExpression(node: PrefixUnaryExpression): Type {
var operandType = checkExpression(node.operand);
switch (node.operator) {
case SyntaxKind.PlusToken:
@@ -6192,12 +6267,7 @@ module ts {
case SyntaxKind.TildeToken:
return numberType;
case SyntaxKind.ExclamationToken:
- case SyntaxKind.DeleteKeyword:
return booleanType;
- case SyntaxKind.TypeOfKeyword:
- return stringType;
- case SyntaxKind.VoidKeyword:
- return undefinedType;
case SyntaxKind.PlusPlusToken:
case SyntaxKind.MinusMinusToken:
var ok = checkArithmeticOperandType(node.operand, operandType, Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type);
@@ -6212,7 +6282,7 @@ module ts {
return unknownType;
}
- function checkPostfixExpression(node: UnaryExpression): Type {
+ function checkPostfixUnaryExpression(node: PostfixUnaryExpression): Type {
var operandType = checkExpression(node.operand);
var ok = checkArithmeticOperandType(node.operand, operandType, Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type);
if (ok) {
@@ -6463,12 +6533,12 @@ module ts {
// object, it serves as an indicator that all contained function and arrow expressions should be considered to
// have the wildcard function type; this form of type check is used during overload resolution to exclude
// contextually typed function and arrow expressions in the initial phase.
- function checkExpression(node: Expression, contextualMapper?: TypeMapper): Type {
+ function checkExpression(node: Expression | QualifiedName, contextualMapper?: TypeMapper): Type {
var type = checkExpressionNode(node, contextualMapper);
- if (contextualMapper && contextualMapper !== identityMapper) {
+ if (contextualMapper && contextualMapper !== identityMapper && node.kind !== SyntaxKind.QualifiedName) {
var signature = getSingleCallSignature(type);
if (signature && signature.typeParameters) {
- var contextualType = getContextualType(node);
+ var contextualType = getContextualType(node);
if (contextualType) {
var contextualSignature = getSingleCallSignature(contextualType);
if (contextualSignature && !contextualSignature.typeParameters) {
@@ -6484,9 +6554,9 @@ module ts {
// - 'object' in indexed access
// - target in rhs of import statement
var ok =
- (node.parent.kind === SyntaxKind.PropertyAccess && (node.parent).left === node) ||
- (node.parent.kind === SyntaxKind.IndexedAccess && (node.parent).object === node) ||
- ((node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.QualifiedName) && isInRightSideOfImportOrExportAssignment(node));
+ (node.parent.kind === SyntaxKind.PropertyAccessExpression && (node.parent).expression === node) ||
+ (node.parent.kind === SyntaxKind.ElementAccessExpression && (node.parent).expression === node) ||
+ ((node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.QualifiedName) && isInRightSideOfImportOrExportAssignment(node));
if (!ok) {
error(node, Diagnostics.const_enums_can_only_be_used_in_property_or_index_access_expressions_or_the_right_hand_side_of_an_import_declaration_or_export_assignment);
@@ -6495,7 +6565,7 @@ module ts {
return type;
}
- function checkExpressionNode(node: Expression, contextualMapper: TypeMapper): Type {
+ function checkExpressionNode(node: Expression | QualifiedName, contextualMapper: TypeMapper): Type {
switch (node.kind) {
case SyntaxKind.Identifier:
return checkIdentifier(node);
@@ -6518,31 +6588,37 @@ module ts {
case SyntaxKind.RegularExpressionLiteral:
return globalRegExpType;
case SyntaxKind.QualifiedName:
- return checkPropertyAccess(node);
- case SyntaxKind.ArrayLiteral:
- return checkArrayLiteral(node, contextualMapper);
- case SyntaxKind.ObjectLiteral:
- return checkObjectLiteral(node, contextualMapper);
- case SyntaxKind.PropertyAccess:
- return checkPropertyAccess(node);
- case SyntaxKind.IndexedAccess:
- return checkIndexedAccess(node);
+ return checkQualifiedName(node);
+ case SyntaxKind.ArrayLiteralExpression:
+ return checkArrayLiteral(node, contextualMapper);
+ case SyntaxKind.ObjectLiteralExpression:
+ return checkObjectLiteral(node, contextualMapper);
+ case SyntaxKind.PropertyAccessExpression:
+ return checkPropertyAccessExpression(node);
+ case SyntaxKind.ElementAccessExpression:
+ return checkIndexedAccess(node);
case SyntaxKind.CallExpression:
case SyntaxKind.NewExpression:
return checkCallExpression(node);
case SyntaxKind.TaggedTemplateExpression:
return checkTaggedTemplateExpression(node);
- case SyntaxKind.TypeAssertion:
+ case SyntaxKind.TypeAssertionExpression:
return checkTypeAssertion(node);
- case SyntaxKind.ParenExpression:
- return checkExpression((node).expression);
+ case SyntaxKind.ParenthesizedExpression:
+ return checkExpression((node).expression);
case SyntaxKind.FunctionExpression:
case SyntaxKind.ArrowFunction:
return checkFunctionExpression(node, contextualMapper);
- case SyntaxKind.PrefixOperator:
- return checkPrefixExpression(node);
- case SyntaxKind.PostfixOperator:
- return checkPostfixExpression(node);
+ case SyntaxKind.TypeOfExpression:
+ return checkTypeOfExpression(node);
+ case SyntaxKind.DeleteExpression:
+ return checkDeleteExpression(node);
+ case SyntaxKind.VoidExpression:
+ return checkVoidExpression(node);
+ case SyntaxKind.PrefixUnaryExpression:
+ return checkPrefixUnaryExpression(node);
+ case SyntaxKind.PostfixUnaryExpression:
+ return checkPostfixUnaryExpression(node);
case SyntaxKind.BinaryExpression:
return checkBinaryExpression(node, contextualMapper);
case SyntaxKind.ConditionalExpression:
@@ -6627,9 +6703,6 @@ module ts {
checkSourceElement(node.type);
}
if (fullTypeCheck) {
- checkCollisionWithCapturedSuperVariable(node, node.name);
- checkCollisionWithCapturedThisVariable(node, node.name);
- checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
checkCollisionWithArgumentsInGeneratedCode(node);
if (compilerOptions.noImplicitAny && !node.type) {
switch (node.kind) {
@@ -6690,17 +6763,16 @@ module ts {
}
function checkPropertyDeclaration(node: PropertyDeclaration) {
- // TODO
- checkVariableDeclaration(node);
+ if (fullTypeCheck) {
+ checkVariableOrPropertyInFullTypeCheck(node);
+ }
}
function checkMethodDeclaration(node: MethodDeclaration) {
- // TODO
- checkFunctionDeclaration(node);
+ checkFunctionLikeDeclaration(node);
}
function checkConstructorDeclaration(node: ConstructorDeclaration) {
- // TODO
checkSignatureDeclaration(node);
checkSourceElement(node.body);
@@ -6721,7 +6793,7 @@ module ts {
}
function isSuperCallExpression(n: Node): boolean {
- return n.kind === SyntaxKind.CallExpression && (n).func.kind === SyntaxKind.SuperKeyword;
+ return n.kind === SyntaxKind.CallExpression && (n).expression.kind === SyntaxKind.SuperKeyword;
}
function containsSuperCall(n: Node): boolean {
@@ -6732,7 +6804,7 @@ module ts {
case SyntaxKind.FunctionExpression:
case SyntaxKind.FunctionDeclaration:
case SyntaxKind.ArrowFunction:
- case SyntaxKind.ObjectLiteral: return false;
+ case SyntaxKind.ObjectLiteralExpression: return false;
default: return forEachChild(n, containsSuperCall);
}
}
@@ -6755,7 +6827,7 @@ module ts {
// TS 1.0 spec (April 2014): 8.3.2
// Constructors of classes with no extends clause may not contain super calls, whereas
// constructors of derived classes must contain at least one super call somewhere in their function body.
- if ((node.parent).baseType) {
+ if (getClassBaseTypeNode(node.parent)) {
if (containsSuperCall(node.body)) {
// The first statement in the body of a constructor must be a super call if both of the following are true:
@@ -6791,29 +6863,32 @@ module ts {
}
}
- // TypeScript 1.0 spec (April 2014): 8.4.3
- // Accessors for the same member name must specify the same accessibility.
- var otherKind = node.kind === SyntaxKind.GetAccessor ? SyntaxKind.SetAccessor : SyntaxKind.GetAccessor;
- var otherAccessor = getDeclarationOfKind(node.symbol, otherKind);
- if (otherAccessor) {
- if (((node.flags & NodeFlags.AccessibilityModifier) !== (otherAccessor.flags & NodeFlags.AccessibilityModifier))) {
- error(node.name, Diagnostics.Getter_and_setter_accessors_do_not_agree_in_visibility);
- }
+ if (!hasComputedNameButNotSymbol(node)) {
+ // TypeScript 1.0 spec (April 2014): 8.4.3
+ // Accessors for the same member name must specify the same accessibility.
+ var otherKind = node.kind === SyntaxKind.GetAccessor ? SyntaxKind.SetAccessor : SyntaxKind.GetAccessor;
+ var otherAccessor = getDeclarationOfKind(node.symbol, otherKind);
+ if (otherAccessor) {
+ if (((node.flags & NodeFlags.AccessibilityModifier) !== (otherAccessor.flags & NodeFlags.AccessibilityModifier))) {
+ error(node.name, Diagnostics.Getter_and_setter_accessors_do_not_agree_in_visibility);
+ }
- var thisType = getAnnotatedAccessorType(node);
- var otherType = getAnnotatedAccessorType(otherAccessor);
- // TypeScript 1.0 spec (April 2014): 4.5
- // If both accessors include type annotations, the specified types must be identical.
- if (thisType && otherType) {
- if (!isTypeIdenticalTo(thisType, otherType)) {
- error(node, Diagnostics.get_and_set_accessor_must_have_the_same_type);
+ var currentAccessorType = getAnnotatedAccessorType(node);
+ var otherAccessorType = getAnnotatedAccessorType(otherAccessor);
+ // TypeScript 1.0 spec (April 2014): 4.5
+ // If both accessors include type annotations, the specified types must be identical.
+ if (currentAccessorType && otherAccessorType) {
+ if (!isTypeIdenticalTo(currentAccessorType, otherAccessorType)) {
+ error(node, Diagnostics.get_and_set_accessor_must_have_the_same_type);
+ }
}
}
+
+ checkAndStoreTypeOfAccessors(getSymbolOfNode(node));
}
}
- checkFunctionDeclaration(node);
- checkAndStoreTypeOfAccessors(getSymbolOfNode(node));
+ checkFunctionLikeDeclaration(node);
}
function checkTypeReference(node: TypeReferenceNode) {
@@ -7067,7 +7142,7 @@ module ts {
}
if (duplicateFunctionDeclaration) {
- forEach( declarations, declaration => {
+ forEach(declarations, declaration => {
error(declaration.name, Diagnostics.Duplicate_function_implementation);
});
}
@@ -7183,26 +7258,37 @@ module ts {
}
}
- function checkFunctionDeclaration(node: FunctionLikeDeclaration): void {
+ function checkFunctionDeclaration(node: FunctionDeclaration): void {
+ checkFunctionLikeDeclaration(node);
+ if (fullTypeCheck) {
+ checkCollisionWithCapturedSuperVariable(node, node.name);
+ checkCollisionWithCapturedThisVariable(node, node.name);
+ checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
+ }
+ }
+
+ function checkFunctionLikeDeclaration(node: FunctionLikeDeclaration): void {
checkSignatureDeclaration(node);
- var symbol = getSymbolOfNode(node);
- // first we want to check the local symbol that contain this declaration
- // - if node.localSymbol !== undefined - this is current declaration is exported and localSymbol points to the local symbol
- // - if node.localSymbol === undefined - this node is non-exported so we can just pick the result of getSymbolOfNode
- var localSymbol = node.localSymbol || symbol;
+ if (!hasComputedNameButNotSymbol(node)) {
+ // first we want to check the local symbol that contain this declaration
+ // - if node.localSymbol !== undefined - this is current declaration is exported and localSymbol points to the local symbol
+ // - if node.localSymbol === undefined - this node is non-exported so we can just pick the result of getSymbolOfNode
+ var symbol = getSymbolOfNode(node);
+ var localSymbol = node.localSymbol || symbol;
- var firstDeclaration = getDeclarationOfKind(localSymbol, node.kind);
- // Only type check the symbol once
- if (node === firstDeclaration) {
- checkFunctionOrConstructorSymbol(localSymbol);
- }
+ var firstDeclaration = getDeclarationOfKind(localSymbol, node.kind);
+ // Only type check the symbol once
+ if (node === firstDeclaration) {
+ checkFunctionOrConstructorSymbol(localSymbol);
+ }
- if (symbol.parent) {
- // run check once for the first declaration
- if (getDeclarationOfKind(symbol, node.kind) === node) {
- // run check on export symbol to check that modifiers agree across all exported declarations
- checkFunctionOrConstructorSymbol(symbol);
+ if (symbol.parent) {
+ // run check once for the first declaration
+ if (getDeclarationOfKind(symbol, node.kind) === node) {
+ // run check on export symbol to check that modifiers agree across all exported declarations
+ checkFunctionOrConstructorSymbol(symbol);
+ }
}
}
@@ -7323,9 +7409,8 @@ module ts {
}
}
- // TODO(jfreeman): Decide what to do for computed properties
- function needCollisionCheckForIdentifier(node: Node, identifier: DeclarationName, name: string): boolean {
- if (!(identifier && (identifier).text === name)) {
+ function needCollisionCheckForIdentifier(node: Node, identifier: Identifier, name: string): boolean {
+ if (!identifier || identifier.text !== name) {
return false;
}
@@ -7350,12 +7435,10 @@ module ts {
return true;
}
- // TODO(jfreeman): Decide what to do for computed properties
- function checkCollisionWithCapturedThisVariable(node: Node, name: DeclarationName): void {
- if (!needCollisionCheckForIdentifier(node, name, "_this")) {
- return;
+ function checkCollisionWithCapturedThisVariable(node: Node, name: Identifier): void {
+ if (needCollisionCheckForIdentifier(node, name, "_this")) {
+ potentialThisCollisions.push(node);
}
- potentialThisCollisions.push(node);
}
// this function will run after checking the source file so 'CaptureThis' is correct for all nodes
@@ -7376,7 +7459,7 @@ module ts {
}
}
- function checkCollisionWithCapturedSuperVariable(node: Node, name: DeclarationName) {
+ function checkCollisionWithCapturedSuperVariable(node: Node, name: Identifier) {
if (!needCollisionCheckForIdentifier(node, name, "_super")) {
return;
}
@@ -7388,7 +7471,7 @@ module ts {
return;
}
- if (enclosingClass.baseType) {
+ if (getClassBaseTypeNode(enclosingClass)) {
var isDeclaration = node.kind !== SyntaxKind.Identifier;
if (isDeclaration) {
error(node, Diagnostics.Duplicate_identifier_super_Compiler_uses_super_to_capture_base_class_reference);
@@ -7399,8 +7482,7 @@ module ts {
}
}
- // TODO(jfreeman): Decide what to do for computed properties
- function checkCollisionWithRequireExportsInGeneratedCode(node: Node, name: DeclarationName) {
+ function checkCollisionWithRequireExportsInGeneratedCode(node: Node, name: Identifier) {
if (!needCollisionCheckForIdentifier(node, name, "require") && !needCollisionCheckForIdentifier(node, name, "exports")) {
return;
}
@@ -7451,40 +7533,49 @@ module ts {
}
}
- function checkVariableDeclaration(node: VariableDeclaration | PropertyDeclaration) {
+ function checkVariableOrPropertyInFullTypeCheck(node: VariableDeclaration | PropertyDeclaration) {
+ Debug.assert(fullTypeCheck);
checkSourceElement(node.type);
- checkExportsOnMergedDeclarations(node);
+ if (hasComputedNameButNotSymbol(node)) {
+ // Just check the initializer, since this property won't contribute to the enclosing type
+ return node.initializer ? checkAndMarkExpression(node.initializer) : anyType;
+ }
+
+ var symbol = getSymbolOfNode(node);
+ var type: Type;
+ if (symbol.valueDeclaration !== node) {
+ type = getTypeOfVariableOrPropertyDeclaration(node);
+ }
+ else {
+ type = getTypeOfVariableOrParameterOrProperty(symbol);
+ }
+
+ if (node.initializer && !(getNodeLinks(node.initializer).flags & NodeCheckFlags.TypeChecked)) {
+ // Use default messages
+ checkTypeAssignableTo(checkAndMarkExpression(node.initializer), type, node, /*headMessage*/ undefined);
+ }
+
+ return type;
+ }
+
+ function checkVariableDeclaration(node: VariableDeclaration) {
if (fullTypeCheck) {
- var symbol = getSymbolOfNode(node);
-
- var typeOfValueDeclaration = getTypeOfVariableOrParameterOrProperty(symbol);
- var type: Type;
- var useTypeFromValueDeclaration = node === symbol.valueDeclaration;
- if (useTypeFromValueDeclaration) {
- type = typeOfValueDeclaration;
- }
- else {
- type = getTypeOfVariableOrPropertyDeclaration(node);
- }
-
-
+ var type = checkVariableOrPropertyInFullTypeCheck(node);
+ checkExportsOnMergedDeclarations(node);
if (node.initializer) {
- if (!(getNodeLinks(node.initializer).flags & NodeCheckFlags.TypeChecked)) {
- // Use default messages
- checkTypeAssignableTo(checkAndMarkExpression(node.initializer), type, node, /*headMessage*/ undefined);
- }
- //TODO(jfreeman): Check that it is not a computed property
- checkCollisionWithConstDeclarations(node);
+ checkCollisionWithConstDeclarations(node);
}
checkCollisionWithCapturedSuperVariable(node, node.name);
checkCollisionWithCapturedThisVariable(node, node.name);
checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
- if (!useTypeFromValueDeclaration) {
+ var symbol = getSymbolOfNode(node);
+ if (node !== symbol.valueDeclaration) {
// TypeScript 1.0 spec (April 2014): 5.1
// Multiple declarations for the same variable name in the same declaration space are permitted,
// provided that each declaration associates the same type with the variable.
+ var typeOfValueDeclaration = getTypeOfVariableOrParameterOrProperty(symbol);
if (typeOfValueDeclaration !== unknownType && type !== unknownType && !isTypeIdenticalTo(typeOfValueDeclaration, type)) {
error(node.name, Diagnostics.Subsequent_variable_declarations_must_have_the_same_type_Variable_0_must_be_of_type_1_but_here_has_type_2, declarationNameToString(node.name), typeToString(typeOfValueDeclaration), typeToString(type));
}
@@ -7531,10 +7622,13 @@ module ts {
// for (var VarDecl in Expr) Statement
// VarDecl must be a variable declaration without a type annotation that declares a variable of type Any,
// and Expr must be an expression of type Any, an object type, or a type parameter type.
- if (node.declaration) {
- checkVariableDeclaration(node.declaration);
- if (node.declaration.type) {
- error(node.declaration, Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation);
+ if (node.declarations) {
+ if (node.declarations.length >= 1) {
+ var decl = node.declarations[0];
+ checkVariableDeclaration(decl);
+ if (decl.type) {
+ error(decl, Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation);
+ }
}
}
@@ -7617,7 +7711,7 @@ module ts {
checkTypeAssignableTo(caseType, expressionType, clause.expression, /*headMessage*/ undefined);
}
}
- checkBlock(clause);
+ forEach(clause.statements, checkSourceElement);
});
}
@@ -7745,9 +7839,10 @@ module ts {
var symbol = getSymbolOfNode(node);
var type = getDeclaredTypeOfSymbol(symbol);
var staticType = getTypeOfSymbol(symbol);
- if (node.baseType) {
+ var baseTypeNode = getClassBaseTypeNode(node);
+ if (baseTypeNode) {
emitExtends = emitExtends || !isInAmbientContext(node);
- checkTypeReference(node.baseType);
+ checkTypeReference(baseTypeNode);
}
if (type.baseTypes.length) {
if (fullTypeCheck) {
@@ -7756,18 +7851,20 @@ module ts {
var staticBaseType = getTypeOfSymbol(baseType.symbol);
checkTypeAssignableTo(staticType, getTypeWithoutConstructors(staticBaseType), node.name,
Diagnostics.Class_static_side_0_incorrectly_extends_base_class_static_side_1);
- if (baseType.symbol !== resolveEntityName(node, node.baseType.typeName, SymbolFlags.Value)) {
- error(node.baseType, Diagnostics.Type_name_0_in_extends_clause_does_not_reference_constructor_function_for_0, typeToString(baseType));
+ if (baseType.symbol !== resolveEntityName(node, baseTypeNode.typeName, SymbolFlags.Value)) {
+ error(baseTypeNode, Diagnostics.Type_name_0_in_extends_clause_does_not_reference_constructor_function_for_0, typeToString(baseType));
}
checkKindsOfPropertyMemberOverrides(type, baseType);
}
// Check that base type can be evaluated as expression
- checkExpression(node.baseType.typeName);
+ checkExpression(baseTypeNode.typeName);
}
- if (node.implementedTypes) {
- forEach(node.implementedTypes, typeRefNode => {
+
+ var implementedTypeNodes = getClassImplementedTypeNodes(node);
+ if (implementedTypeNodes) {
+ forEach(implementedTypeNodes, typeRefNode => {
checkTypeReference(typeRefNode);
if (fullTypeCheck) {
var t = getTypeFromTypeReferenceNode(typeRefNode);
@@ -7962,7 +8059,7 @@ module ts {
}
}
}
- forEach(node.baseTypes, checkTypeReference);
+ forEach(getInterfaceBaseTypeNodes(node), checkTypeReference);
forEach(node.members, checkSourceElement);
if (fullTypeCheck) {
@@ -7983,7 +8080,7 @@ module ts {
var enumType = getDeclaredTypeOfSymbol(enumSymbol);
var autoValue = 0;
var ambient = isInAmbientContext(node);
- var enumIsConst = isConstEnumDeclaration(node);
+ var enumIsConst = isConst(node);
forEach(node.members, member => {
// TODO(jfreeman): Check that it is not a computed name
@@ -8032,12 +8129,12 @@ module ts {
function evalConstant(e: Node): number {
switch (e.kind) {
- case SyntaxKind.PrefixOperator:
- var value = evalConstant((e).operand);
+ case SyntaxKind.PrefixUnaryExpression:
+ var value = evalConstant((e).operand);
if (value === undefined) {
return undefined;
}
- switch ((e).operator) {
+ switch ((e).operator) {
case SyntaxKind.PlusToken: return value;
case SyntaxKind.MinusToken: return -value;
case SyntaxKind.TildeToken: return enumIsConst ? ~value : undefined;
@@ -8072,11 +8169,11 @@ module ts {
return undefined;
case SyntaxKind.NumericLiteral:
return +(e).text;
- case SyntaxKind.ParenExpression:
- return enumIsConst ? evalConstant((e).expression) : undefined;
+ case SyntaxKind.ParenthesizedExpression:
+ return enumIsConst ? evalConstant((e).expression) : undefined;
case SyntaxKind.Identifier:
- case SyntaxKind.IndexedAccess:
- case SyntaxKind.PropertyAccess:
+ case SyntaxKind.ElementAccessExpression:
+ case SyntaxKind.PropertyAccessExpression:
if (!enumIsConst) {
return undefined;
}
@@ -8093,16 +8190,16 @@ module ts {
propertyName = (e).text;
}
else {
- if (e.kind === SyntaxKind.IndexedAccess) {
- if ((e).index.kind !== SyntaxKind.StringLiteral) {
+ if (e.kind === SyntaxKind.ElementAccessExpression) {
+ if ((e).argumentExpression.kind !== SyntaxKind.StringLiteral) {
return undefined;
}
- var enumType = getTypeOfNode((e).object);
- propertyName = ((e).index).text;
+ var enumType = getTypeOfNode((e).expression);
+ propertyName = ((e).argumentExpression).text;
}
else {
- var enumType = getTypeOfNode((e).left);
- propertyName = (e).right.text;
+ var enumType = getTypeOfNode((e).expression);
+ propertyName = (e).name.text;
}
if (enumType !== currentType) {
return undefined;
@@ -8154,10 +8251,10 @@ module ts {
var firstDeclaration = getDeclarationOfKind(enumSymbol, node.kind);
if (node === firstDeclaration) {
if (enumSymbol.declarations.length > 1) {
- var enumIsConst = isConstEnumDeclaration(node);
+ var enumIsConst = isConst(node);
// check that const is placed\omitted on all enum declarations
forEach(enumSymbol.declarations, decl => {
- if (isConstEnumDeclaration(decl) !== enumIsConst) {
+ if (isConstEnumDeclaration(decl) !== enumIsConst) {
error(decl.name, Diagnostics.Enum_declarations_must_all_be_const_or_non_const);
}
});
@@ -8338,10 +8435,10 @@ module ts {
return checkTupleType(node);
case SyntaxKind.UnionType:
return checkUnionType(node);
- case SyntaxKind.ParenType:
- return checkSourceElement((node).type);
+ case SyntaxKind.ParenthesizedType:
+ return checkSourceElement((node).type);
case SyntaxKind.FunctionDeclaration:
- return checkFunctionDeclaration(node);
+ return checkFunctionDeclaration(node);
case SyntaxKind.Block:
return checkBlock(node);
case SyntaxKind.FunctionBlock:
@@ -8423,18 +8520,21 @@ module ts {
break;
case SyntaxKind.Parameter:
case SyntaxKind.Property:
- case SyntaxKind.ArrayLiteral:
- case SyntaxKind.ObjectLiteral:
+ case SyntaxKind.ArrayLiteralExpression:
+ case SyntaxKind.ObjectLiteralExpression:
case SyntaxKind.PropertyAssignment:
- case SyntaxKind.PropertyAccess:
- case SyntaxKind.IndexedAccess:
+ case SyntaxKind.PropertyAccessExpression:
+ case SyntaxKind.ElementAccessExpression:
case SyntaxKind.CallExpression:
case SyntaxKind.NewExpression:
case SyntaxKind.TaggedTemplateExpression:
- case SyntaxKind.TypeAssertion:
- case SyntaxKind.ParenExpression:
- case SyntaxKind.PrefixOperator:
- case SyntaxKind.PostfixOperator:
+ case SyntaxKind.TypeAssertionExpression:
+ case SyntaxKind.ParenthesizedExpression:
+ case SyntaxKind.TypeOfExpression:
+ case SyntaxKind.VoidExpression:
+ case SyntaxKind.DeleteExpression:
+ case SyntaxKind.PrefixUnaryExpression:
+ case SyntaxKind.PostfixUnaryExpression:
case SyntaxKind.BinaryExpression:
case SyntaxKind.ConditionalExpression:
case SyntaxKind.Block:
@@ -8480,7 +8580,10 @@ module ts {
if (!(links.flags & NodeCheckFlags.TypeChecked)) {
emitExtends = false;
potentialThisCollisions.length = 0;
- checkBody(node);
+
+ forEach(node.statements, checkSourceElement);
+ checkFunctionExpressionBodies(node);
+
if (isExternalModule(node)) {
var symbol = getExportAssignmentSymbol(node.symbol);
if (symbol && symbol.flags & SymbolFlags.Import) {
@@ -8488,11 +8591,16 @@ module ts {
getSymbolLinks(symbol).referenced = true;
}
}
+
if (potentialThisCollisions.length) {
forEach(potentialThisCollisions, checkIfThisIsCapturedInEnclosingScope);
potentialThisCollisions.length = 0;
}
- if (emitExtends) links.flags |= NodeCheckFlags.EmitExtends;
+
+ if (emitExtends) {
+ links.flags |= NodeCheckFlags.EmitExtends;
+ }
+
links.flags |= NodeCheckFlags.TypeChecked;
}
}
@@ -8522,6 +8630,12 @@ module ts {
return getSortedDiagnostics();
}
+ function getDeclarationDiagnostics(targetSourceFile: SourceFile): Diagnostic[] {
+ var resolver = createResolver();
+ checkSourceFile(targetSourceFile);
+ return ts.getDeclarationDiagnostics(program, resolver, targetSourceFile);
+ }
+
function getGlobalDiagnostics(): Diagnostic[] {
return filter(getSortedDiagnostics(), d => !d.file);
}
@@ -8654,7 +8768,7 @@ module ts {
case SyntaxKind.BooleanKeyword:
return true;
case SyntaxKind.VoidKeyword:
- return node.parent.kind !== SyntaxKind.PrefixOperator;
+ return node.parent.kind !== SyntaxKind.VoidExpression;
case SyntaxKind.StringLiteral:
// Specialized signatures can have string literals as their parameters' type names
return node.parent.kind === SyntaxKind.Parameter;
@@ -8703,7 +8817,7 @@ module ts {
case SyntaxKind.ConstructSignature:
case SyntaxKind.IndexSignature:
return node === (parent).type;
- case SyntaxKind.TypeAssertion:
+ case SyntaxKind.TypeAssertionExpression:
return node === (parent).type;
case SyntaxKind.CallExpression:
case SyntaxKind.NewExpression:
@@ -8733,27 +8847,29 @@ module ts {
}
function isRightSideOfQualifiedNameOrPropertyAccess(node: Node) {
- return (node.parent.kind === SyntaxKind.QualifiedName || node.parent.kind === SyntaxKind.PropertyAccess) &&
- (node.parent).right === node;
+ return (node.parent.kind === SyntaxKind.QualifiedName && (node.parent).right === node) ||
+ (node.parent.kind === SyntaxKind.PropertyAccessExpression && (node.parent).name === node);
}
- function getSymbolOfEntityName(entityName: EntityName): Symbol {
+ function getSymbolOfEntityNameOrPropertyAccessExpression(entityName: EntityName | PropertyAccessExpression): Symbol {
if (isDeclarationOrFunctionExpressionOrCatchVariableName(entityName)) {
return getSymbolOfNode(entityName.parent);
}
if (entityName.parent.kind === SyntaxKind.ExportAssignment) {
- return resolveEntityName(/*location*/ entityName.parent.parent, entityName,
+ return resolveEntityName(/*location*/ entityName.parent.parent, entityName,
/*all meanings*/ SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Import);
}
- if (isInRightSideOfImportOrExportAssignment(entityName)) {
- // Since we already checked for ExportAssignment, this really could only be an Import
- return getSymbolOfPartOfRightHandSideOfImport(entityName);
+ if (entityName.kind !== SyntaxKind.PropertyAccessExpression) {
+ if (isInRightSideOfImportOrExportAssignment(entityName)) {
+ // Since we already checked for ExportAssignment, this really could only be an Import
+ return getSymbolOfPartOfRightHandSideOfImport(entityName);
+ }
}
if (isRightSideOfQualifiedNameOrPropertyAccess(entityName)) {
- entityName = entityName.parent;
+ entityName = entityName.parent;
}
if (isExpression(entityName)) {
@@ -8761,12 +8877,19 @@ module ts {
// Include Import in the meaning, this ensures that we do not follow aliases to where they point and instead
// return the alias symbol.
var meaning: SymbolFlags = SymbolFlags.Value | SymbolFlags.Import;
- return resolveEntityName(entityName, entityName, meaning);
+ return resolveEntityName(entityName, entityName, meaning);
}
- else if (entityName.kind === SyntaxKind.QualifiedName || entityName.kind === SyntaxKind.PropertyAccess) {
+ else if (entityName.kind === SyntaxKind.PropertyAccessExpression) {
var symbol = getNodeLinks(entityName).resolvedSymbol;
if (!symbol) {
- checkPropertyAccess(entityName);
+ checkPropertyAccessExpression(entityName);
+ }
+ return getNodeLinks(entityName).resolvedSymbol;
+ }
+ else if (entityName.kind === SyntaxKind.QualifiedName) {
+ var symbol = getNodeLinks(entityName).resolvedSymbol;
+ if (!symbol) {
+ checkQualifiedName(entityName);
}
return getNodeLinks(entityName).resolvedSymbol;
}
@@ -8775,12 +8898,12 @@ module ts {
return;
}
}
- else if (isTypeReferenceIdentifier(entityName)) {
+ else if (isTypeReferenceIdentifier(entityName)) {
var meaning = entityName.parent.kind === SyntaxKind.TypeReference ? SymbolFlags.Type : SymbolFlags.Namespace;
// Include Import in the meaning, this ensures that we do not follow aliases to where they point and instead
// return the alias symbol.
meaning |= SymbolFlags.Import;
- return resolveEntityName(entityName, entityName, meaning);
+ return resolveEntityName(entityName, entityName, meaning);
}
// Do we want to return undefined here?
@@ -8800,19 +8923,19 @@ module ts {
if (node.kind === SyntaxKind.Identifier && isInRightSideOfImportOrExportAssignment(node)) {
return node.parent.kind === SyntaxKind.ExportAssignment
- ? getSymbolOfEntityName(node)
+ ? getSymbolOfEntityNameOrPropertyAccessExpression(node)
: getSymbolOfPartOfRightHandSideOfImport(node);
}
switch (node.kind) {
case SyntaxKind.Identifier:
- case SyntaxKind.PropertyAccess:
+ case SyntaxKind.PropertyAccessExpression:
case SyntaxKind.QualifiedName:
- return getSymbolOfEntityName(node);
+ return getSymbolOfEntityNameOrPropertyAccessExpression(node);
case SyntaxKind.ThisKeyword:
case SyntaxKind.SuperKeyword:
- var type = checkExpression(node);
+ var type = checkExpression(node);
return type.symbol;
case SyntaxKind.ConstructorKeyword:
@@ -8834,8 +8957,8 @@ module ts {
// Intentional fall-through
case SyntaxKind.NumericLiteral:
// index access
- if (node.parent.kind == SyntaxKind.IndexedAccess && (node.parent).index === node) {
- var objectType = checkExpression((node.parent).object);
+ if (node.parent.kind == SyntaxKind.ElementAccessExpression && (node.parent).argumentExpression === node) {
+ var objectType = checkExpression((node.parent).expression);
if (objectType === unknownType) return undefined;
var apparentType = getApparentType(objectType);
if (apparentType === unknownType) return undefined;
@@ -8903,7 +9026,7 @@ module ts {
function getTypeOfExpression(expr: Expression): Type {
if (isRightSideOfQualifiedNameOrPropertyAccess(expr)) {
- expr = expr.parent;
+ expr = expr.parent;
}
return checkExpression(expr);
}
@@ -9087,7 +9210,7 @@ module ts {
return getNodeLinks(node).enumMemberValue;
}
- function getConstantValue(node: PropertyAccess | IndexedAccess): number {
+ function getConstantValue(node: PropertyAccessExpression | ElementAccessExpression): number {
var symbol = getNodeLinks(node).resolvedSymbol;
if (symbol && (symbol.flags & SymbolFlags.EnumMember)) {
var declaration = symbol.valueDeclaration;
@@ -9115,8 +9238,8 @@ module ts {
getSymbolDisplayBuilder().buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags);
}
- function invokeEmitter(targetSourceFile?: SourceFile) {
- var resolver: EmitResolver = {
+ function createResolver(): EmitResolver {
+ return {
getProgram: () => program,
getLocalNameOfContainer,
getExpressionNamePrefix,
@@ -9132,9 +9255,13 @@ module ts {
writeTypeAtLocation,
writeReturnTypeOfSignatureDeclaration,
isSymbolAccessible,
- isImportDeclarationEntityNameReferenceDeclarationVisibile,
+ isEntityNameVisible,
getConstantValue,
};
+ }
+
+ function invokeEmitter(targetSourceFile?: SourceFile) {
+ var resolver = createResolver();
checkProgram();
return emitFiles(resolver, targetSourceFile);
}
@@ -9143,7 +9270,7 @@ module ts {
// Bind all source files and propagate errors
forEach(program.getSourceFiles(), file => {
bindSourceFile(file);
- forEach(file.semanticErrors, addDiagnostic);
+ forEach(file.semanticDiagnostics, addDiagnostic);
});
// Initialize global symbol table
forEach(program.getSourceFiles(), file => {
diff --git a/src/compiler/core.ts b/src/compiler/core.ts
index 2c613996689..6bbf9a13d03 100644
--- a/src/compiler/core.ts
+++ b/src/compiler/core.ts
@@ -459,6 +459,10 @@ module ts {
return normalizedPathComponents(path, rootLength);
}
+ export function getNormalizedAbsolutePath(filename: string, currentDirectory: string) {
+ return getNormalizedPathFromPathComponents(getNormalizedPathComponents(filename, currentDirectory));
+ }
+
export function getNormalizedPathFromPathComponents(pathComponents: string[]) {
if (pathComponents && pathComponents.length) {
return pathComponents[0] + pathComponents.slice(1).join(directorySeparator);
diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts
index e4094b25812..c72054af9c7 100644
--- a/src/compiler/diagnosticInformationMap.generated.ts
+++ b/src/compiler/diagnosticInformationMap.generated.ts
@@ -125,8 +125,22 @@ module ts {
Unterminated_template_literal: { code: 1160, category: DiagnosticCategory.Error, key: "Unterminated template literal." },
Unterminated_regular_expression_literal: { code: 1161, category: DiagnosticCategory.Error, key: "Unterminated regular expression literal." },
An_object_member_cannot_be_declared_optional: { code: 1162, category: DiagnosticCategory.Error, key: "An object member cannot be declared optional." },
- Binary_digit_expected: { code: 1163, category: DiagnosticCategory.Error, key: "Binary digit expected." },
- Octal_digit_expected: { code: 1164, category: DiagnosticCategory.Error, key: "Octal digit expected." },
+ yield_expression_must_be_contained_within_a_generator_declaration: { code: 1163, category: DiagnosticCategory.Error, key: "'yield' expression must be contained_within a generator declaration." },
+ Computed_property_names_are_not_allowed_in_enums: { code: 1164, category: DiagnosticCategory.Error, key: "Computed property names are not allowed in enums." },
+ Computed_property_names_are_not_allowed_in_an_ambient_context: { code: 1165, category: DiagnosticCategory.Error, key: "Computed property names are not allowed in an ambient context." },
+ Computed_property_names_are_not_allowed_in_class_property_declarations: { code: 1166, category: DiagnosticCategory.Error, key: "Computed property names are not allowed in class property declarations." },
+ Computed_property_names_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1167, category: DiagnosticCategory.Error, key: "Computed property names are only available when targeting ECMAScript 6 and higher." },
+ Computed_property_names_are_not_allowed_in_method_overloads: { code: 1168, category: DiagnosticCategory.Error, key: "Computed property names are not allowed in method overloads." },
+ Computed_property_names_are_not_allowed_in_interfaces: { code: 1169, category: DiagnosticCategory.Error, key: "Computed property names are not allowed in interfaces." },
+ Computed_property_names_are_not_allowed_in_type_literals: { code: 1170, category: DiagnosticCategory.Error, key: "Computed property names are not allowed in type literals." },
+ A_comma_expression_is_not_allowed_in_a_computed_property_name: { code: 1171, category: DiagnosticCategory.Error, key: "A comma expression is not allowed in a computed property name." },
+ extends_clause_already_seen: { code: 1172, category: DiagnosticCategory.Error, key: "'extends' clause already seen." },
+ extends_clause_must_precede_implements_clause: { code: 1173, category: DiagnosticCategory.Error, key: "'extends' clause must precede 'implements' clause." },
+ Classes_can_only_extend_a_single_class: { code: 1174, category: DiagnosticCategory.Error, key: "Classes can only extend a single class." },
+ implements_clause_already_seen: { code: 1175, category: DiagnosticCategory.Error, key: "'implements' clause already seen." },
+ Interface_declaration_cannot_have_implements_clause: { code: 1176, category: DiagnosticCategory.Error, key: "Interface declaration cannot have 'implements' clause." },
+ Binary_digit_expected: { code: 1177, category: DiagnosticCategory.Error, key: "Binary digit expected." },
+ Octal_digit_expected: { code: 1178, category: DiagnosticCategory.Error, key: "Octal digit expected." },
Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." },
Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." },
@@ -277,27 +291,16 @@ module ts {
Type_alias_name_cannot_be_0: { code: 2457, category: DiagnosticCategory.Error, key: "Type alias name cannot be '{0}'" },
An_AMD_module_cannot_have_multiple_name_assignments: { code: 2458, category: DiagnosticCategory.Error, key: "An AMD module cannot have multiple name assignments." },
Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." },
- Type_parameter_0_of_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4001, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using name '{1}' from private module '{2}'." },
Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." },
- Type_parameter_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 4003, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using name '{1}' from private module '{2}'." },
Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." },
- Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 4005, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of constructor signature from exported interface has or is using name '{1}' from private module '{2}'." },
Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1: { code: 4006, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of constructor signature from exported interface has or is using private name '{1}'." },
- Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 4007, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of call signature from exported interface has or is using name '{1}' from private module '{2}'." },
Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1: { code: 4008, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of call signature from exported interface has or is using private name '{1}'." },
- Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4009, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of public static method from exported class has or is using name '{1}' from private module '{2}'." },
Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1: { code: 4010, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of public static method from exported class has or is using private name '{1}'." },
- Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 4011, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of public method from exported class has or is using name '{1}' from private module '{2}'." },
Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1: { code: 4012, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of public method from exported class has or is using private name '{1}'." },
- Type_parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 4013, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of method from exported interface has or is using name '{1}' from private module '{2}'." },
Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1: { code: 4014, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of method from exported interface has or is using private name '{1}'." },
- Type_parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2: { code: 4015, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported function has or is using name '{1}' from private module '{2}'." },
Type_parameter_0_of_exported_function_has_or_is_using_private_name_1: { code: 4016, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported function has or is using private name '{1}'." },
- Implements_clause_of_exported_class_0_has_or_is_using_name_1_from_private_module_2: { code: 4017, category: DiagnosticCategory.Error, key: "Implements clause of exported class '{0}' has or is using name '{1}' from private module '{2}'." },
- Extends_clause_of_exported_class_0_has_or_is_using_name_1_from_private_module_2: { code: 4018, category: DiagnosticCategory.Error, key: "Extends clause of exported class '{0}' has or is using name '{1}' from private module '{2}'." },
Implements_clause_of_exported_class_0_has_or_is_using_private_name_1: { code: 4019, category: DiagnosticCategory.Error, key: "Implements clause of exported class '{0}' has or is using private name '{1}'." },
Extends_clause_of_exported_class_0_has_or_is_using_private_name_1: { code: 4020, category: DiagnosticCategory.Error, key: "Extends clause of exported class '{0}' has or is using private name '{1}'." },
- Extends_clause_of_exported_interface_0_has_or_is_using_name_1_from_private_module_2: { code: 4021, category: DiagnosticCategory.Error, key: "Extends clause of exported interface '{0}' has or is using name '{1}' from private module '{2}'." },
Extends_clause_of_exported_interface_0_has_or_is_using_private_name_1: { code: 4022, category: DiagnosticCategory.Error, key: "Extends clause of exported interface '{0}' has or is using private name '{1}'." },
Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: { code: 4023, category: DiagnosticCategory.Error, key: "Exported variable '{0}' has or is using name '{1}' from external module {2} but cannot be named." },
Exported_variable_0_has_or_is_using_name_1_from_private_module_2: { code: 4024, category: DiagnosticCategory.Error, key: "Exported variable '{0}' has or is using name '{1}' from private module '{2}'." },
@@ -355,8 +358,6 @@ module ts {
Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: { code: 4076, category: DiagnosticCategory.Error, key: "Parameter '{0}' of exported function has or is using name '{1}' from external module {2} but cannot be named." },
Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2: { code: 4077, category: DiagnosticCategory.Error, key: "Parameter '{0}' of exported function has or is using name '{1}' from private module '{2}'." },
Parameter_0_of_exported_function_has_or_is_using_private_name_1: { code: 4078, category: DiagnosticCategory.Error, key: "Parameter '{0}' of exported function has or is using private name '{1}'." },
- Exported_type_alias_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named: { code: 4079, category: DiagnosticCategory.Error, key: "Exported type alias '{0}' has or is using name '{1}' from external module {2} but cannot be named." },
- Exported_type_alias_0_has_or_is_using_name_1_from_private_module_2: { code: 4080, category: DiagnosticCategory.Error, key: "Exported type alias '{0}' has or is using name '{1}' from private module '{2}'." },
Exported_type_alias_0_has_or_is_using_private_name_1: { code: 4081, category: DiagnosticCategory.Error, key: "Exported type alias '{0}' has or is using private name '{1}'." },
Enum_declarations_must_all_be_const_or_non_const: { code: 4082, category: DiagnosticCategory.Error, key: "Enum declarations must all be const or non-const." },
In_const_enum_declarations_member_initializer_must_be_constant_expression: { code: 4083, category: DiagnosticCategory.Error, key: "In 'const' enum declarations member initializer must be constant expression.", isEarly: true },
@@ -428,5 +429,7 @@ module ts {
_0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7023, category: DiagnosticCategory.Error, key: "'{0}' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." },
Function_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7024, category: DiagnosticCategory.Error, key: "Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." },
You_cannot_rename_this_element: { code: 8000, category: DiagnosticCategory.Error, key: "You cannot rename this element." },
+ yield_expressions_are_not_currently_supported: { code: 9000, category: DiagnosticCategory.Error, key: "'yield' expressions are not currently supported." },
+ generators_are_not_currently_supported: { code: 9001, category: DiagnosticCategory.Error, key: "'generators' are not currently supported." },
};
}
\ No newline at end of file
diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json
index 1cca0aa130d..21fe84be2c1 100644
--- a/src/compiler/diagnosticMessages.json
+++ b/src/compiler/diagnosticMessages.json
@@ -491,15 +491,71 @@
"category": "Error",
"code": 1162
},
- "Binary digit expected.": {
+ "'yield' expression must be contained_within a generator declaration."
+ : {
"category": "Error",
"code": 1163
},
- "Octal digit expected.": {
+ "Computed property names are not allowed in enums.": {
"category": "Error",
"code": 1164
},
-
+ "Computed property names are not allowed in an ambient context.": {
+ "category": "Error",
+ "code": 1165
+ },
+ "Computed property names are not allowed in class property declarations.": {
+ "category": "Error",
+ "code": 1166
+ },
+ "Computed property names are only available when targeting ECMAScript 6 and higher.": {
+ "category": "Error",
+ "code": 1167
+ },
+ "Computed property names are not allowed in method overloads.": {
+ "category": "Error",
+ "code": 1168
+ },
+ "Computed property names are not allowed in interfaces.": {
+ "category": "Error",
+ "code": 1169
+ },
+ "Computed property names are not allowed in type literals.": {
+ "category": "Error",
+ "code": 1170
+ },
+ "A comma expression is not allowed in a computed property name.": {
+ "category": "Error",
+ "code": 1171
+ },
+ "'extends' clause already seen.": {
+ "category": "Error",
+ "code": 1172
+ },
+ "'extends' clause must precede 'implements' clause.": {
+ "category": "Error",
+ "code": 1173
+ },
+ "Classes can only extend a single class.": {
+ "category": "Error",
+ "code": 1174
+ },
+ "'implements' clause already seen.": {
+ "category": "Error",
+ "code": 1175
+ },
+ "Interface declaration cannot have 'implements' clause.": {
+ "category": "Error",
+ "code": 1176
+ },
+ "Binary digit expected.": {
+ "category": "Error",
+ "code": 1177
+ },
+ "Octal digit expected.": {
+ "category": "Error",
+ "code": 1178
+ },
"Duplicate identifier '{0}'.": {
"category": "Error",
"code": 2300
@@ -1105,78 +1161,38 @@
"category": "Error",
"code": 4000
},
- "Type parameter '{0}' of exported class has or is using name '{1}' from private module '{2}'.": {
- "category": "Error",
- "code": 4001
- },
"Type parameter '{0}' of exported class has or is using private name '{1}'.": {
"category": "Error",
"code": 4002
},
- "Type parameter '{0}' of exported interface has or is using name '{1}' from private module '{2}'.": {
- "category": "Error",
- "code": 4003
- },
"Type parameter '{0}' of exported interface has or is using private name '{1}'.": {
"category": "Error",
"code": 4004
},
- "Type parameter '{0}' of constructor signature from exported interface has or is using name '{1}' from private module '{2}'.": {
- "category": "Error",
- "code": 4005
- },
"Type parameter '{0}' of constructor signature from exported interface has or is using private name '{1}'.": {
"category": "Error",
"code": 4006
},
- "Type parameter '{0}' of call signature from exported interface has or is using name '{1}' from private module '{2}'.": {
- "category": "Error",
- "code": 4007
- },
"Type parameter '{0}' of call signature from exported interface has or is using private name '{1}'.": {
"category": "Error",
"code": 4008
},
- "Type parameter '{0}' of public static method from exported class has or is using name '{1}' from private module '{2}'.": {
- "category": "Error",
- "code": 4009
- },
"Type parameter '{0}' of public static method from exported class has or is using private name '{1}'.": {
"category": "Error",
"code": 4010
},
- "Type parameter '{0}' of public method from exported class has or is using name '{1}' from private module '{2}'.": {
- "category": "Error",
- "code": 4011
- },
"Type parameter '{0}' of public method from exported class has or is using private name '{1}'.": {
"category": "Error",
"code": 4012
},
- "Type parameter '{0}' of method from exported interface has or is using name '{1}' from private module '{2}'.": {
- "category": "Error",
- "code": 4013
- },
"Type parameter '{0}' of method from exported interface has or is using private name '{1}'.": {
"category": "Error",
"code": 4014
},
- "Type parameter '{0}' of exported function has or is using name '{1}' from private module '{2}'.": {
- "category": "Error",
- "code": 4015
- },
"Type parameter '{0}' of exported function has or is using private name '{1}'.": {
"category": "Error",
"code": 4016
},
- "Implements clause of exported class '{0}' has or is using name '{1}' from private module '{2}'.": {
- "category": "Error",
- "code": 4017
- },
- "Extends clause of exported class '{0}' has or is using name '{1}' from private module '{2}'.": {
- "category": "Error",
- "code": 4018
- },
"Implements clause of exported class '{0}' has or is using private name '{1}'.": {
"category": "Error",
"code": 4019
@@ -1185,10 +1201,6 @@
"category": "Error",
"code": 4020
},
- "Extends clause of exported interface '{0}' has or is using name '{1}' from private module '{2}'.": {
- "category": "Error",
- "code": 4021
- },
"Extends clause of exported interface '{0}' has or is using private name '{1}'.": {
"category": "Error",
"code": 4022
@@ -1417,14 +1429,6 @@
"category": "Error",
"code": 4078
},
- "Exported type alias '{0}' has or is using name '{1}' from external module {2} but cannot be named.": {
- "category": "Error",
- "code": 4079
- },
- "Exported type alias '{0}' has or is using name '{1}' from private module '{2}'.": {
- "category": "Error",
- "code": 4080
- },
"Exported type alias '{0}' has or is using private name '{1}'.": {
"category": "Error",
"code": 4081
@@ -1710,5 +1714,13 @@
"You cannot rename this element.": {
"category": "Error",
"code": 8000
+ },
+ "'yield' expressions are not currently supported.": {
+ "category": "Error",
+ "code": 9000
+ },
+ "'generators' are not currently supported.": {
+ "category": "Error",
+ "code": 9001
}
}
diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts
index 78653337844..ed2d1a7d6f6 100644
--- a/src/compiler/emitter.ts
+++ b/src/compiler/emitter.ts
@@ -6,6 +6,7 @@
module ts {
interface EmitTextWriter {
write(s: string): void;
+ writeTextOfNode(sourceFile: SourceFile, node: Node): void;
writeLine(): void;
increaseIndent(): void;
decreaseIndent(): void;
@@ -18,7 +19,29 @@ module ts {
getIndent(): number;
}
- interface EmitTextWriterWithSymbolWriter extends EmitTextWriter, SymbolWriter{
+ interface SymbolAccessibilityDiagnostic {
+ errorNode: Node;
+ diagnosticMessage: DiagnosticMessage;
+ typeName?: DeclarationName;
+ }
+ type GetSymbolAccessibilityDiagnostic = (symbolAccesibilityResult: SymbolAccessiblityResult) => SymbolAccessibilityDiagnostic;
+
+ interface EmitTextWriterWithSymbolWriter extends EmitTextWriter, SymbolWriter {
+ getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic;
+ }
+
+ interface AliasDeclarationEmitInfo {
+ declaration: ImportDeclaration;
+ outputPos: number;
+ indent: number;
+ asynchronousOutput?: string; // If the output for alias was written asynchronously, the corresponding output
+ }
+
+ interface DeclarationEmit {
+ reportedDeclarationError: boolean;
+ aliasDeclarationEmitInfo: AliasDeclarationEmitInfo[];
+ synchronousDeclarationOutput: string;
+ referencePathsOutput: string;
}
var indentStrings: string[] = ["", " "];
@@ -47,46 +70,227 @@ module ts {
return isExternalModule(sourceFile) || isDeclarationFile(sourceFile);
}
- // targetSourceFile is when users only want one file in entire project to be emitted. This is used in compilerOnSave feature
- export function emitFiles(resolver: EmitResolver, targetSourceFile?: SourceFile): EmitResult {
- var program = resolver.getProgram();
- var compilerHost = program.getCompilerHost();
- var compilerOptions = program.getCompilerOptions();
- var sourceMapDataList: SourceMapData[] = compilerOptions.sourceMap ? [] : undefined;
- var diagnostics: Diagnostic[] = [];
- var newLine = program.getCompilerHost().getNewLine();
+ function createTextWriter(newLine: String): EmitTextWriter {
+ var output = "";
+ var indent = 0;
+ var lineStart = true;
+ var lineCount = 0;
+ var linePos = 0;
- function getSourceFilePathInNewDir(newDirPath: string, sourceFile: SourceFile) {
- var sourceFilePath = getNormalizedPathFromPathComponents(getNormalizedPathComponents(sourceFile.filename, compilerHost.getCurrentDirectory()));
- sourceFilePath = sourceFilePath.replace(program.getCommonSourceDirectory(), "");
- return combinePaths(newDirPath, sourceFilePath);
+ function write(s: string) {
+ if (s && s.length) {
+ if (lineStart) {
+ output += getIndentString(indent);
+ lineStart = false;
+ }
+ output += s;
+ }
}
- function getOwnEmitOutputFilePath(sourceFile: SourceFile, extension: string) {
- if (compilerOptions.outDir) {
- var emitOutputFilePathWithoutExtension = removeFileExtension(getSourceFilePathInNewDir(compilerOptions.outDir, sourceFile));
+ function rawWrite(s: string) {
+ if (s !== undefined) {
+ if (lineStart) {
+ lineStart = false;
+ }
+ output += s;
+ }
+ }
+
+ function writeLiteral(s: string) {
+ if (s && s.length) {
+ write(s);
+ var lineStartsOfS = computeLineStarts(s);
+ if (lineStartsOfS.length > 1) {
+ lineCount = lineCount + lineStartsOfS.length - 1;
+ linePos = output.length - s.length + lineStartsOfS[lineStartsOfS.length - 1];
+ }
+ }
+ }
+
+ function writeLine() {
+ if (!lineStart) {
+ output += newLine;
+ lineCount++;
+ linePos = output.length;
+ lineStart = true;
+ }
+ }
+
+ function writeTextOfNode(sourceFile: SourceFile, node: Node) {
+ write(getSourceTextOfNodeFromSourceFile(sourceFile, node));
+ }
+
+ return {
+ write,
+ rawWrite,
+ writeTextOfNode,
+ writeLiteral,
+ writeLine,
+ increaseIndent: () => indent++,
+ decreaseIndent: () => indent--,
+ getIndent: () => indent,
+ getTextPos: () => output.length,
+ getLine: () => lineCount + 1,
+ getColumn: () => lineStart ? indent * getIndentSize() + 1 : output.length - linePos + 1,
+ getText: () => output,
+ };
+ }
+
+ function getLineOfLocalPosition(currentSourceFile: SourceFile, pos: number) {
+ return currentSourceFile.getLineAndCharacterFromPosition(pos).line;
+ }
+
+ function emitNewLineBeforeLeadingComments(currentSourceFile: SourceFile, writer: EmitTextWriter, node: TextRange, leadingComments: CommentRange[]) {
+ // If the leading comments start on different line than the start of node, write new line
+ if (leadingComments && leadingComments.length && node.pos !== leadingComments[0].pos &&
+ getLineOfLocalPosition(currentSourceFile, node.pos) !== getLineOfLocalPosition(currentSourceFile, leadingComments[0].pos)) {
+ writer.writeLine();
+ }
+ }
+
+ function emitComments(currentSourceFile: SourceFile, writer: EmitTextWriter, comments: CommentRange[], trailingSeparator: boolean, newLine: string,
+ writeComment: (currentSourceFile: SourceFile, writer: EmitTextWriter, comment: CommentRange, newLine: string) => void) {
+ var emitLeadingSpace = !trailingSeparator;
+ forEach(comments, comment => {
+ if (emitLeadingSpace) {
+ writer.write(" ");
+ emitLeadingSpace = false;
+ }
+ writeComment(currentSourceFile, writer, comment, newLine);
+ if (comment.hasTrailingNewLine) {
+ writer.writeLine();
+ }
+ else if (trailingSeparator) {
+ writer.write(" ");
}
else {
- var emitOutputFilePathWithoutExtension = removeFileExtension(sourceFile.filename);
+ // Emit leading space to separate comment during next comment emit
+ emitLeadingSpace = true;
+ }
+ });
+ }
+
+ function writeCommentRange(currentSourceFile: SourceFile, writer: EmitTextWriter, comment: CommentRange, newLine: string){
+ if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk) {
+ var firstCommentLineAndCharacter = currentSourceFile.getLineAndCharacterFromPosition(comment.pos);
+ var firstCommentLineIndent: number;
+ for (var pos = comment.pos, currentLine = firstCommentLineAndCharacter.line; pos < comment.end; currentLine++) {
+ var nextLineStart = currentSourceFile.getPositionFromLineAndCharacter(currentLine + 1, /*character*/1);
+
+ if (pos !== comment.pos) {
+ // If we are not emitting first line, we need to write the spaces to adjust the alignment
+ if (firstCommentLineIndent === undefined) {
+ firstCommentLineIndent = calculateIndent(currentSourceFile.getPositionFromLineAndCharacter(firstCommentLineAndCharacter.line, /*character*/1),
+ comment.pos);
+ }
+
+ // These are number of spaces writer is going to write at current indent
+ var currentWriterIndentSpacing = writer.getIndent() * getIndentSize();
+
+ // Number of spaces we want to be writing
+ // eg: Assume writer indent
+ // module m {
+ // /* starts at character 9 this is line 1
+ // * starts at character pos 4 line --1 = 8 - 8 + 3
+ // More left indented comment */ --2 = 8 - 8 + 2
+ // class c { }
+ // }
+ // module m {
+ // /* this is line 1 -- Assume current writer indent 8
+ // * line --3 = 8 - 4 + 5
+ // More right indented comment */ --4 = 8 - 4 + 11
+ // class c { }
+ // }
+ var spacesToEmit = currentWriterIndentSpacing - firstCommentLineIndent + calculateIndent(pos, nextLineStart);
+ if (spacesToEmit > 0) {
+ var numberOfSingleSpacesToEmit = spacesToEmit % getIndentSize();
+ var indentSizeSpaceString = getIndentString((spacesToEmit - numberOfSingleSpacesToEmit) / getIndentSize());
+
+ // Write indent size string ( in eg 1: = "", 2: "" , 3: string with 8 spaces 4: string with 12 spaces
+ writer.rawWrite(indentSizeSpaceString);
+
+ // Emit the single spaces (in eg: 1: 3 spaces, 2: 2 spaces, 3: 1 space, 4: 3 spaces)
+ while (numberOfSingleSpacesToEmit) {
+ writer.rawWrite(" ");
+ numberOfSingleSpacesToEmit--;
+ }
+ }
+ else {
+ // No spaces to emit write empty string
+ writer.rawWrite("");
+ }
+ }
+
+ // Write the comment line text
+ writeTrimmedCurrentLine(pos, nextLineStart);
+
+ pos = nextLineStart;
+ }
+ }
+ else {
+ // Single line comment of style //....
+ writer.write(currentSourceFile.text.substring(comment.pos, comment.end));
+ }
+
+ function writeTrimmedCurrentLine(pos: number, nextLineStart: number) {
+ var end = Math.min(comment.end, nextLineStart - 1);
+ var currentLineText = currentSourceFile.text.substring(pos, end).replace(/^\s+|\s+$/g, '');
+ if (currentLineText) {
+ // trimmed forward and ending spaces text
+ writer.write(currentLineText);
+ if (end !== comment.end) {
+ writer.writeLine();
+ }
+ }
+ else {
+ // Empty string - make sure we write empty line
+ writer.writeLiteral(newLine);
+ }
+ }
+
+ function calculateIndent(pos: number, end: number) {
+ var currentLineIndent = 0;
+ for (; pos < end && isWhiteSpace(currentSourceFile.text.charCodeAt(pos)); pos++) {
+ if (currentSourceFile.text.charCodeAt(pos) === CharacterCodes.tab) {
+ // Tabs = TabSize = indent size and go to next tabStop
+ currentLineIndent += getIndentSize() - (currentLineIndent % getIndentSize());
+ }
+ else {
+ // Single space
+ currentLineIndent++;
+ }
}
- return emitOutputFilePathWithoutExtension + extension;
+ return currentLineIndent;
}
+ }
- function getFirstConstructorWithBody(node: ClassDeclaration): ConstructorDeclaration {
- return forEach(node.members, member => {
- if (member.kind === SyntaxKind.Constructor && (member).body) {
- return member;
- }
- });
+ function getFirstConstructorWithBody(node: ClassDeclaration): ConstructorDeclaration {
+ return forEach(node.members, member => {
+ if (member.kind === SyntaxKind.Constructor && (member).body) {
+ return member;
+ }
+ });
+ }
+
+ function getAllAccessorDeclarations(node: ClassDeclaration, accessor: AccessorDeclaration) {
+ var firstAccessor: AccessorDeclaration;
+ var getAccessor: AccessorDeclaration;
+ var setAccessor: AccessorDeclaration;
+ if (accessor.name.kind === SyntaxKind.ComputedPropertyName) {
+ firstAccessor = accessor;
+ if (accessor.kind === SyntaxKind.GetAccessor) {
+ getAccessor = accessor;
+ }
+ else if (accessor.kind === SyntaxKind.SetAccessor) {
+ setAccessor = accessor;
+ }
+ else {
+ Debug.fail("Accessor has wrong kind");
+ }
}
-
- function getAllAccessorDeclarations(node: ClassDeclaration, accessor: AccessorDeclaration) {
- var firstAccessor: AccessorDeclaration;
- var getAccessor: AccessorDeclaration;
- var setAccessor: AccessorDeclaration;
- forEach(node.members, (member: Declaration) => {
- // TODO(jfreeman): Handle computed names for accessor matching
+ else {
+ forEach(node.members,(member: Declaration) => {
if ((member.kind === SyntaxKind.GetAccessor || member.kind === SyntaxKind.SetAccessor) &&
(member.name).text === (accessor.name).text &&
(member.flags & NodeFlags.Static) === (accessor.flags & NodeFlags.Static)) {
@@ -103,224 +307,1177 @@ module ts {
}
}
});
- return {
- firstAccessor,
- getAccessor,
- setAccessor
- };
+ }
+ return {
+ firstAccessor,
+ getAccessor,
+ setAccessor
+ };
+ }
+
+ function getSourceFilePathInNewDir(sourceFile: SourceFile, program: Program, newDirPath: string) {
+ var compilerHost = program.getCompilerHost();
+ var sourceFilePath = getNormalizedAbsolutePath(sourceFile.filename, compilerHost.getCurrentDirectory());
+ sourceFilePath = sourceFilePath.replace(program.getCommonSourceDirectory(), "");
+ return combinePaths(newDirPath, sourceFilePath);
+ }
+
+ function getOwnEmitOutputFilePath(sourceFile: SourceFile, program: Program, extension: string){
+ var compilerOptions = program.getCompilerOptions();
+ if (compilerOptions.outDir) {
+ var emitOutputFilePathWithoutExtension = removeFileExtension(getSourceFilePathInNewDir(sourceFile, program, compilerOptions.outDir));
+ }
+ else {
+ var emitOutputFilePathWithoutExtension = removeFileExtension(sourceFile.filename);
}
- function createTextWriter(): EmitTextWriter {
- var output = "";
- var indent = 0;
- var lineStart = true;
- var lineCount = 0;
- var linePos = 0;
+ return emitOutputFilePathWithoutExtension + extension;
+ }
- function write(s: string) {
- if (s && s.length) {
- if (lineStart) {
- output += getIndentString(indent);
- lineStart = false;
- }
- output += s;
- }
- }
+ function writeFile(compilerHost: CompilerHost, diagnostics: Diagnostic[], filename: string, data: string, writeByteOrderMark: boolean) {
+ compilerHost.writeFile(filename, data, writeByteOrderMark, hostErrorMessage => {
+ diagnostics.push(createCompilerDiagnostic(Diagnostics.Could_not_write_file_0_Colon_1, filename, hostErrorMessage));
+ });
+ }
- function rawWrite(s: string) {
- if (s !== undefined) {
- if (lineStart) {
- lineStart = false;
- }
- output += s;
- }
- }
+ function emitDeclarations(program: Program, resolver: EmitResolver, diagnostics: Diagnostic[], jsFilePath: string, root?: SourceFile): DeclarationEmit {
+ var newLine = program.getCompilerHost().getNewLine();
+ var compilerOptions = program.getCompilerOptions();
+ var compilerHost = program.getCompilerHost();
- function writeLiteral(s: string) {
- if (s && s.length) {
- write(s);
- var lineStartsOfS = computeLineStarts(s);
- if (lineStartsOfS.length > 1) {
- lineCount = lineCount + lineStartsOfS.length - 1;
- linePos = output.length - s.length + lineStartsOfS[lineStartsOfS.length - 1];
- }
- }
- }
+ var write: (s: string) => void;
+ var writeLine: () => void;
+ var increaseIndent: () => void;
+ var decreaseIndent: () => void;
+ var writeTextOfNode: (sourceFile: SourceFile, node: Node) => void;
- function writeLine() {
- if (!lineStart) {
- output += newLine;
- lineCount++;
- linePos = output.length;
- lineStart = true;
- }
- }
+ var writer = createAndSetNewTextWriterWithSymbolWriter();
- return {
- write: write,
- rawWrite: rawWrite,
- writeLiteral: writeLiteral,
- writeLine: writeLine,
- increaseIndent: () => indent++,
- decreaseIndent: () => indent--,
- getIndent: () => indent,
- getTextPos: () => output.length,
- getLine: () => lineCount + 1,
- getColumn: () => lineStart ? indent * getIndentSize() + 1 : output.length - linePos + 1,
- getText: () => output,
- };
- }
-
- // Get source text of node in the current source file. Unlike getSourceTextOfNode this function
- // doesn't walk the parent chain to find the containing source file, rather it assumes the node is
- // in the source file currently being processed.
+ var enclosingDeclaration: Node;
var currentSourceFile: SourceFile;
- function getSourceTextOfLocalNode(node: Node): string {
- var text = currentSourceFile.text;
- return text.substring(skipTrivia(text, node.pos), node.end);
+ var reportedDeclarationError = false;
+
+ var emitJsDocComments = compilerOptions.removeComments ? function (declaration: Node) { } : writeJsDocComments;
+
+ var aliasDeclarationEmitInfo: AliasDeclarationEmitInfo[] = [];
+
+ function createAndSetNewTextWriterWithSymbolWriter(): EmitTextWriterWithSymbolWriter {
+ var writer = createTextWriter(newLine);
+ writer.trackSymbol = trackSymbol;
+ writer.writeKeyword = writer.write;
+ writer.writeOperator = writer.write;
+ writer.writePunctuation = writer.write;
+ writer.writeSpace = writer.write;
+ writer.writeStringLiteral = writer.writeLiteral;
+ writer.writeParameter = writer.write;
+ writer.writeSymbol = writer.write;
+ setWriter(writer);
+ return writer;
}
- function getLineOfLocalPosition(pos: number) {
- return currentSourceFile.getLineAndCharacterFromPosition(pos).line;
+ function setWriter(newWriter: EmitTextWriterWithSymbolWriter) {
+ writer = newWriter;
+ write = newWriter.write;
+ writeTextOfNode = newWriter.writeTextOfNode;
+ writeLine = newWriter.writeLine;
+ increaseIndent = newWriter.increaseIndent;
+ decreaseIndent = newWriter.decreaseIndent;
}
- function writeFile(filename: string, data: string, writeByteOrderMark: boolean) {
- compilerHost.writeFile(filename, data, writeByteOrderMark, hostErrorMessage => {
- diagnostics.push(createCompilerDiagnostic(Diagnostics.Could_not_write_file_0_Colon_1, filename, hostErrorMessage));
- });
- }
-
- function emitComments(comments: CommentRange[], trailingSeparator: boolean, writer: EmitTextWriter, writeComment: (comment: CommentRange, writer: EmitTextWriter) => void) {
- var emitLeadingSpace = !trailingSeparator;
- forEach(comments, comment => {
- if (emitLeadingSpace) {
- writer.write(" ");
- emitLeadingSpace = false;
- }
- writeComment(comment, writer);
- if (comment.hasTrailingNewLine) {
- writer.writeLine();
- }
- else if (trailingSeparator) {
- writer.write(" ");
- }
- else {
- // Emit leading space to separate comment during next comment emit
- emitLeadingSpace = true;
- }
- });
- }
-
- function emitNewLineBeforeLeadingComments(node: TextRange, leadingComments: CommentRange[], writer: EmitTextWriter) {
- // If the leading comments start on different line than the start of node, write new line
- if (leadingComments && leadingComments.length && node.pos !== leadingComments[0].pos &&
- getLineOfLocalPosition(node.pos) !== getLineOfLocalPosition(leadingComments[0].pos)) {
- writer.writeLine();
- }
- }
-
- function writeCommentRange(comment: CommentRange, writer: EmitTextWriter) {
- if (currentSourceFile.text.charCodeAt(comment.pos + 1) === CharacterCodes.asterisk) {
- var firstCommentLineAndCharacter = currentSourceFile.getLineAndCharacterFromPosition(comment.pos);
- var firstCommentLineIndent: number;
- for (var pos = comment.pos, currentLine = firstCommentLineAndCharacter.line; pos < comment.end; currentLine++) {
- var nextLineStart = currentSourceFile.getPositionFromLineAndCharacter(currentLine + 1, /*character*/1);
-
- if (pos !== comment.pos) {
- // If we are not emitting first line, we need to write the spaces to adjust the alignment
- if (firstCommentLineIndent === undefined) {
- firstCommentLineIndent = calculateIndent(currentSourceFile.getPositionFromLineAndCharacter(firstCommentLineAndCharacter.line, /*character*/1),
- comment.pos);
- }
-
- // These are number of spaces writer is going to write at current indent
- var currentWriterIndentSpacing = writer.getIndent() * getIndentSize();
-
- // Number of spaces we want to be writing
- // eg: Assume writer indent
- // module m {
- // /* starts at character 9 this is line 1
- // * starts at character pos 4 line --1 = 8 - 8 + 3
- // More left indented comment */ --2 = 8 - 8 + 2
- // class c { }
- // }
- // module m {
- // /* this is line 1 -- Assume current writer indent 8
- // * line --3 = 8 - 4 + 5
- // More right indented comment */ --4 = 8 - 4 + 11
- // class c { }
- // }
- var spacesToEmit = currentWriterIndentSpacing - firstCommentLineIndent + calculateIndent(pos, nextLineStart);
- if (spacesToEmit > 0) {
- var numberOfSingleSpacesToEmit = spacesToEmit % getIndentSize();
- var indentSizeSpaceString = getIndentString((spacesToEmit - numberOfSingleSpacesToEmit) / getIndentSize());
-
- // Write indent size string ( in eg 1: = "", 2: "" , 3: string with 8 spaces 4: string with 12 spaces
- writer.rawWrite(indentSizeSpaceString);
-
- // Emit the single spaces (in eg: 1: 3 spaces, 2: 2 spaces, 3: 1 space, 4: 3 spaces)
- while (numberOfSingleSpacesToEmit) {
- writer.rawWrite(" ");
- numberOfSingleSpacesToEmit--;
- }
- }
- else {
- // No spaces to emit write empty string
- writer.rawWrite("");
- }
+ function writeAsychronousImportDeclarations(importDeclarations: ImportDeclaration[]) {
+ var oldWriter = writer;
+ forEach(importDeclarations, aliasToWrite => {
+ var aliasEmitInfo = forEach(aliasDeclarationEmitInfo, declEmitInfo => declEmitInfo.declaration === aliasToWrite ? declEmitInfo : undefined);
+ // If the alias was marked as not visible when we saw its declaration, we would have saved the aliasEmitInfo, but if we haven't yet visited the alias declaration
+ // then we don't need to write it at this point. We will write it when we actually see its declaration
+ // Eg.
+ // export function bar(a: foo.Foo) { }
+ // import foo = require("foo");
+ // Writing of function bar would mark alias declaration foo as visible but we haven't yet visited that declaration so do nothing,
+ // we would write alias foo declaration when we visit it since it would now be marked as visible
+ if (aliasEmitInfo) {
+ createAndSetNewTextWriterWithSymbolWriter();
+ for (var declarationIndent = aliasEmitInfo.indent; declarationIndent; declarationIndent--) {
+ increaseIndent();
}
+ writeImportDeclaration(aliasToWrite);
+ aliasEmitInfo.asynchronousOutput = writer.getText();
+ }
+ });
+ setWriter(oldWriter);
+ }
- // Write the comment line text
- writeTrimmedCurrentLine(pos, nextLineStart);
-
- pos = nextLineStart;
+ function handleSymbolAccessibilityError(symbolAccesibilityResult: SymbolAccessiblityResult) {
+ if (symbolAccesibilityResult.accessibility === SymbolAccessibility.Accessible) {
+ // write the aliases
+ if (symbolAccesibilityResult && symbolAccesibilityResult.aliasesToMakeVisible) {
+ writeAsychronousImportDeclarations(symbolAccesibilityResult.aliasesToMakeVisible);
}
}
else {
- // Single line comment of style //....
- writer.write(currentSourceFile.text.substring(comment.pos, comment.end));
- }
-
- function writeTrimmedCurrentLine(pos: number, nextLineStart: number) {
- var end = Math.min(comment.end, nextLineStart - 1);
- var currentLineText = currentSourceFile.text.substring(pos, end).replace(/^\s+|\s+$/g, '');
- if (currentLineText) {
- // trimmed forward and ending spaces text
- writer.write(currentLineText);
- if (end !== comment.end) {
- writer.writeLine();
- }
- }
- else {
- // Empty string - make sure we write empty line
- writer.writeLiteral(newLine);
- }
- }
-
- function calculateIndent(pos: number, end: number) {
- var currentLineIndent = 0;
- for (; pos < end && isWhiteSpace(currentSourceFile.text.charCodeAt(pos)); pos++) {
- if (currentSourceFile.text.charCodeAt(pos) === CharacterCodes.tab) {
- // Tabs = TabSize = indent size and go to next tabStop
- currentLineIndent += getIndentSize() - (currentLineIndent % getIndentSize());
+ // Report error
+ reportedDeclarationError = true;
+ var errorInfo = writer.getSymbolAccessibilityDiagnostic(symbolAccesibilityResult);
+ if (errorInfo) {
+ if (errorInfo.typeName) {
+ diagnostics.push(createDiagnosticForNode(symbolAccesibilityResult.errorNode || errorInfo.errorNode,
+ errorInfo.diagnosticMessage,
+ getSourceTextOfNodeFromSourceFile(currentSourceFile, errorInfo.typeName),
+ symbolAccesibilityResult.errorSymbolName,
+ symbolAccesibilityResult.errorModuleName));
}
else {
- // Single space
- currentLineIndent++;
+ diagnostics.push(createDiagnosticForNode(symbolAccesibilityResult.errorNode || errorInfo.errorNode,
+ errorInfo.diagnosticMessage,
+ symbolAccesibilityResult.errorSymbolName,
+ symbolAccesibilityResult.errorModuleName));
}
}
-
- return currentLineIndent;
}
}
+ function trackSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags) {
+ handleSymbolAccessibilityError(resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning));
+ }
+
+ function writeTypeAtLocation(location: Node, type: TypeNode, getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic) {
+ writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic;
+ write(": ");
+ if (type) {
+ // Write the type
+ emitType(type);
+ }
+ else {
+ resolver.writeTypeAtLocation(location, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer);
+ }
+ }
+
+ function writeReturnTypeAtSignature(signature: SignatureDeclaration, getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic) {
+ writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic;
+ write(": ");
+ if (signature.type) {
+ // Write the type
+ emitType(signature.type);
+ }
+ else {
+ resolver.writeReturnTypeOfSignatureDeclaration(signature, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer);
+ }
+ }
+
+ function emitLines(nodes: Node[]) {
+ for (var i = 0, n = nodes.length; i < n; i++) {
+ emitNode(nodes[i]);
+ }
+ }
+
+ function emitSeparatedList(nodes: Node[], separator: string, eachNodeEmitFn: (node: Node) => void) {
+ var currentWriterPos = writer.getTextPos();
+ for (var i = 0, n = nodes.length; i < n; i++) {
+ if (currentWriterPos !== writer.getTextPos()) {
+ write(separator);
+ }
+ currentWriterPos = writer.getTextPos();
+ eachNodeEmitFn(nodes[i]);
+ }
+ }
+
+ function emitCommaList(nodes: Node[], eachNodeEmitFn: (node: Node) => void) {
+ emitSeparatedList(nodes, ", ", eachNodeEmitFn);
+ }
+
+ function writeJsDocComments(declaration: Node) {
+ if (declaration) {
+ var jsDocComments = getJsDocComments(declaration, currentSourceFile);
+ emitNewLineBeforeLeadingComments(currentSourceFile, writer, declaration, jsDocComments);
+ // jsDoc comments are emitted at /*leading comment1 */space/*leading comment*/space
+ emitComments(currentSourceFile, writer, jsDocComments, /*trailingSeparator*/ true, newLine, writeCommentRange);
+ }
+ }
+
+ function emitTypeWithNewGetSymbolAccessibilityDiangostic(type: TypeNode, getSymbolAccessibilityDiagnostic: GetSymbolAccessibilityDiagnostic) {
+ writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic;
+ emitType(type);
+ }
+
+ function emitType(type: TypeNode) {
+ switch (type.kind) {
+ case SyntaxKind.AnyKeyword:
+ case SyntaxKind.StringKeyword:
+ case SyntaxKind.NumberKeyword:
+ case SyntaxKind.BooleanKeyword:
+ case SyntaxKind.VoidKeyword:
+ case SyntaxKind.StringLiteral:
+ return writeTextOfNode(currentSourceFile, type);
+ case SyntaxKind.TypeReference:
+ return emitTypeReference(type);
+ case SyntaxKind.TypeQuery:
+ return emitTypeQuery(type);
+ case SyntaxKind.ArrayType:
+ return emitArrayType(type);
+ case SyntaxKind.TupleType:
+ return emitTupleType(type);
+ case SyntaxKind.UnionType:
+ return emitUnionType(type);
+ case SyntaxKind.ParenthesizedType:
+ return emitParenType(type);
+ case SyntaxKind.FunctionType:
+ case SyntaxKind.ConstructorType:
+ return emitSignatureDeclarationWithJsDocComments(type);
+ case SyntaxKind.TypeLiteral:
+ return emitTypeLiteral(type);
+ case SyntaxKind.Identifier:
+ return emitEntityName(type);
+ case SyntaxKind.QualifiedName:
+ return emitEntityName(type);
+ default:
+ Debug.fail("Unknown type annotation: " + type.kind);
+ }
+
+ function emitEntityName(entityName: EntityName) {
+ var visibilityResult = resolver.isEntityNameVisible(entityName,
+ // Aliases can be written asynchronously so use correct enclosing declaration
+ entityName.parent.kind === SyntaxKind.ImportDeclaration ? entityName.parent : enclosingDeclaration);
+
+ handleSymbolAccessibilityError(visibilityResult);
+ writeEntityName(entityName);
+
+ function writeEntityName(entityName: EntityName) {
+ if (entityName.kind === SyntaxKind.Identifier) {
+ writeTextOfNode(currentSourceFile, entityName);
+ }
+ else {
+ var qualifiedName = entityName;
+ writeEntityName(qualifiedName.left);
+ write(".");
+ writeTextOfNode(currentSourceFile, qualifiedName.right);
+ }
+ }
+ }
+
+ function emitTypeReference(type: TypeReferenceNode) {
+ emitEntityName(type.typeName);
+ if (type.typeArguments) {
+ write("<");
+ emitCommaList(type.typeArguments, emitType);
+ write(">");
+ }
+ }
+
+ function emitTypeQuery(type: TypeQueryNode) {
+ write("typeof ");
+ emitEntityName(type.exprName);
+ }
+
+ function emitArrayType(type: ArrayTypeNode) {
+ emitType(type.elementType);
+ write("[]");
+ }
+
+ function emitTupleType(type: TupleTypeNode) {
+ write("[");
+ emitCommaList(type.elementTypes, emitType);
+ write("]");
+ }
+
+ function emitUnionType(type: UnionTypeNode) {
+ emitSeparatedList(type.types, " | ", emitType);
+ }
+
+ function emitParenType(type: ParenthesizedTypeNode) {
+ write("(");
+ emitType(type.type);
+ write(")");
+ }
+
+ function emitTypeLiteral(type: TypeLiteralNode) {
+ write("{");
+ if (type.members.length) {
+ writeLine();
+ increaseIndent();
+ // write members
+ emitLines(type.members);
+ decreaseIndent();
+ }
+ write("}");
+ }
+ }
+
+ function emitSourceFile(node: SourceFile) {
+ currentSourceFile = node;
+ enclosingDeclaration = node;
+ emitLines(node.statements);
+ }
+
+ function emitExportAssignment(node: ExportAssignment) {
+ write("export = ");
+ writeTextOfNode(currentSourceFile, node.exportName);
+ write(";");
+ writeLine();
+ }
+
+ function emitModuleElementDeclarationFlags(node: Node) {
+ // If the node is parented in the current source file we need to emit export declare or just export
+ if (node.parent === currentSourceFile) {
+ // If the node is exported
+ if (node.flags & NodeFlags.Export) {
+ write("export ");
+ }
+
+ if (node.kind !== SyntaxKind.InterfaceDeclaration) {
+ write("declare ");
+ }
+ }
+ }
+
+ function emitClassMemberDeclarationFlags(node: Declaration) {
+ if (node.flags & NodeFlags.Private) {
+ write("private ");
+ }
+ else if (node.flags & NodeFlags.Protected) {
+ write("protected ");
+ }
+
+ if (node.flags & NodeFlags.Static) {
+ write("static ");
+ }
+ }
+
+ function emitImportDeclaration(node: ImportDeclaration) {
+ var nodeEmitInfo = {
+ declaration: node,
+ outputPos: writer.getTextPos(),
+ indent: writer.getIndent(),
+ hasWritten: resolver.isDeclarationVisible(node)
+ };
+ aliasDeclarationEmitInfo.push(nodeEmitInfo);
+ if (nodeEmitInfo.hasWritten) {
+ writeImportDeclaration(node);
+ }
+ }
+
+ function writeImportDeclaration(node: ImportDeclaration) {
+ // note usage of writer. methods instead of aliases created, just to make sure we are using
+ // correct writer especially to handle asynchronous alias writing
+ emitJsDocComments(node);
+ if (node.flags & NodeFlags.Export) {
+ write("export ");
+ }
+ write("import ");
+ writeTextOfNode(currentSourceFile, node.name);
+ write(" = ");
+ if (node.entityName) {
+ emitTypeWithNewGetSymbolAccessibilityDiangostic(node.entityName, getImportEntityNameVisibilityError);
+ write(";");
+ }
+ else {
+ write("require(");
+ writeTextOfNode(currentSourceFile, node.externalModuleName);
+ write(");");
+ }
+ writer.writeLine();
+
+ function getImportEntityNameVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic {
+ return {
+ diagnosticMessage: Diagnostics.Import_declaration_0_is_using_private_name_1,
+ errorNode: node,
+ typeName: node.name
+ };
+ }
+ }
+
+ function emitModuleDeclaration(node: ModuleDeclaration) {
+ if (resolver.isDeclarationVisible(node)) {
+ emitJsDocComments(node);
+ emitModuleElementDeclarationFlags(node);
+ write("module ");
+ writeTextOfNode(currentSourceFile, node.name);
+ while (node.body.kind !== SyntaxKind.ModuleBlock) {
+ node = node.body;
+ write(".");
+ writeTextOfNode(currentSourceFile, node.name);
+ }
+ var prevEnclosingDeclaration = enclosingDeclaration;
+ enclosingDeclaration = node;
+ write(" {");
+ writeLine();
+ increaseIndent();
+ emitLines((node.body).statements);
+ decreaseIndent();
+ write("}");
+ writeLine();
+ enclosingDeclaration = prevEnclosingDeclaration;
+ }
+ }
+
+ function emitTypeAliasDeclaration(node: TypeAliasDeclaration) {
+ if (resolver.isDeclarationVisible(node)) {
+ emitJsDocComments(node);
+ emitModuleElementDeclarationFlags(node);
+ write("type ");
+ writeTextOfNode(currentSourceFile, node.name);
+ write(" = ");
+ emitTypeWithNewGetSymbolAccessibilityDiangostic(node.type, getTypeAliasDeclarationVisibilityError);
+ write(";");
+ writeLine();
+ }
+ function getTypeAliasDeclarationVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic {
+ return {
+ diagnosticMessage: Diagnostics.Exported_type_alias_0_has_or_is_using_private_name_1,
+ errorNode: node.type,
+ typeName: node.name
+ };
+ }
+ }
+
+ function emitEnumDeclaration(node: EnumDeclaration) {
+ if (resolver.isDeclarationVisible(node)) {
+ emitJsDocComments(node);
+ emitModuleElementDeclarationFlags(node);
+ if (isConst(node)) {
+ write("const ")
+ }
+ write("enum ");
+ writeTextOfNode(currentSourceFile, node.name);
+ write(" {");
+ writeLine();
+ increaseIndent();
+ emitLines(node.members);
+ decreaseIndent();
+ write("}");
+ writeLine();
+ }
+ }
+
+ function emitEnumMemberDeclaration(node: EnumMember) {
+ emitJsDocComments(node);
+ writeTextOfNode(currentSourceFile, node.name);
+ var enumMemberValue = resolver.getEnumMemberValue(node);
+ if (enumMemberValue !== undefined) {
+ write(" = ");
+ write(enumMemberValue.toString());
+ }
+ write(",");
+ writeLine();
+ }
+
+ function emitTypeParameters(typeParameters: TypeParameterDeclaration[]) {
+ function emitTypeParameter(node: TypeParameterDeclaration) {
+ increaseIndent();
+ emitJsDocComments(node);
+ decreaseIndent();
+ writeTextOfNode(currentSourceFile, node.name);
+ // If there is constraint present and this is not a type parameter of the private method emit the constraint
+ if (node.constraint && (node.parent.kind !== SyntaxKind.Method || !(node.parent.flags & NodeFlags.Private))) {
+ write(" extends ");
+ if (node.parent.kind === SyntaxKind.FunctionType ||
+ node.parent.kind === SyntaxKind.ConstructorType ||
+ (node.parent.parent && node.parent.parent.kind === SyntaxKind.TypeLiteral)) {
+ Debug.assert(node.parent.kind === SyntaxKind.Method ||
+ node.parent.kind === SyntaxKind.FunctionType ||
+ node.parent.kind === SyntaxKind.ConstructorType ||
+ node.parent.kind === SyntaxKind.CallSignature ||
+ node.parent.kind === SyntaxKind.ConstructSignature);
+ emitType(node.constraint);
+ }
+ else {
+ emitTypeWithNewGetSymbolAccessibilityDiangostic(node.constraint, getTypeParameterConstraintVisibilityError);
+ }
+ }
+
+ function getTypeParameterConstraintVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic {
+ // Type parameter constraints are named by user so we should always be able to name it
+ var diagnosticMessage: DiagnosticMessage;
+ switch (node.parent.kind) {
+ case SyntaxKind.ClassDeclaration:
+ diagnosticMessage = Diagnostics.Type_parameter_0_of_exported_class_has_or_is_using_private_name_1;
+ break;
+
+ case SyntaxKind.InterfaceDeclaration:
+ diagnosticMessage = Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1;
+ break;
+
+ case SyntaxKind.ConstructSignature:
+ diagnosticMessage = Diagnostics.Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1;
+ break;
+
+ case SyntaxKind.CallSignature:
+ diagnosticMessage = Diagnostics.Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1;
+ break;
+
+ case SyntaxKind.Method:
+ if (node.parent.flags & NodeFlags.Static) {
+ diagnosticMessage = Diagnostics.Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1;
+ }
+ else if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) {
+ diagnosticMessage = Diagnostics.Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1;
+ }
+ else {
+ diagnosticMessage = Diagnostics.Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1;
+ }
+ break;
+
+ case SyntaxKind.FunctionDeclaration:
+ diagnosticMessage = Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_private_name_1;
+ break;
+
+ default:
+ Debug.fail("This is unknown parent for type parameter: " + node.parent.kind);
+ }
+
+ return {
+ diagnosticMessage,
+ errorNode: node,
+ typeName: node.name
+ };
+ }
+ }
+
+ if (typeParameters) {
+ write("<");
+ emitCommaList(typeParameters, emitTypeParameter);
+ write(">");
+ }
+ }
+
+ function emitHeritageClause(typeReferences: TypeReferenceNode[], isImplementsList: boolean) {
+ if (typeReferences) {
+ write(isImplementsList ? " implements " : " extends ");
+ emitCommaList(typeReferences, emitTypeOfTypeReference);
+ }
+
+ function emitTypeOfTypeReference(node: Node) {
+ emitTypeWithNewGetSymbolAccessibilityDiangostic(node, getHeritageClauseVisibilityError);
+
+ function getHeritageClauseVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic {
+ var diagnosticMessage: DiagnosticMessage;
+ // Heritage clause is written by user so it can always be named
+ if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) {
+ // Class or Interface implemented/extended is inaccessible
+ diagnosticMessage = isImplementsList ?
+ Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_private_name_1 :
+ Diagnostics.Extends_clause_of_exported_class_0_has_or_is_using_private_name_1;
+ }
+ else {
+ // interface is inaccessible
+ diagnosticMessage = Diagnostics.Extends_clause_of_exported_interface_0_has_or_is_using_private_name_1;
+ }
+
+ return {
+ diagnosticMessage,
+ errorNode: node,
+ typeName: (node.parent.parent).name
+ };
+ }
+ }
+ }
+
+ function emitClassDeclaration(node: ClassDeclaration) {
+ function emitParameterProperties(constructorDeclaration: ConstructorDeclaration) {
+ if (constructorDeclaration) {
+ forEach(constructorDeclaration.parameters, param => {
+ if (param.flags & NodeFlags.AccessibilityModifier) {
+ emitPropertyDeclaration(param);
+ }
+ });
+ }
+ }
+
+ if (resolver.isDeclarationVisible(node)) {
+ emitJsDocComments(node);
+ emitModuleElementDeclarationFlags(node);
+ write("class ");
+ writeTextOfNode(currentSourceFile, node.name);
+ var prevEnclosingDeclaration = enclosingDeclaration;
+ enclosingDeclaration = node;
+ emitTypeParameters(node.typeParameters);
+ var baseTypeNode = getClassBaseTypeNode(node);
+ if (baseTypeNode) {
+ emitHeritageClause([baseTypeNode], /*isImplementsList*/ false);
+ }
+ emitHeritageClause(getClassImplementedTypeNodes(node), /*isImplementsList*/ true);
+ write(" {");
+ writeLine();
+ increaseIndent();
+ emitParameterProperties(getFirstConstructorWithBody(node));
+ emitLines(node.members);
+ decreaseIndent();
+ write("}");
+ writeLine();
+ enclosingDeclaration = prevEnclosingDeclaration;
+ }
+ }
+
+ function emitInterfaceDeclaration(node: InterfaceDeclaration) {
+ if (resolver.isDeclarationVisible(node)) {
+ emitJsDocComments(node);
+ emitModuleElementDeclarationFlags(node);
+ write("interface ");
+ writeTextOfNode(currentSourceFile, node.name);
+ var prevEnclosingDeclaration = enclosingDeclaration;
+ enclosingDeclaration = node;
+ emitTypeParameters(node.typeParameters);
+ emitHeritageClause(getInterfaceBaseTypeNodes(node), /*isImplementsList*/ false);
+ write(" {");
+ writeLine();
+ increaseIndent();
+ emitLines(node.members);
+ decreaseIndent();
+ write("}");
+ writeLine();
+ enclosingDeclaration = prevEnclosingDeclaration;
+ }
+ }
+
+ function emitPropertyDeclaration(node: Declaration) {
+ emitJsDocComments(node);
+ emitClassMemberDeclarationFlags(node);
+ emitVariableDeclaration(node);
+ write(";");
+ writeLine();
+ }
+
+ // TODO(jfreeman): Factor out common part of property definition, but treat name differently
+ function emitVariableDeclaration(node: VariableDeclaration) {
+ // If we are emitting property it isn't moduleElement and hence we already know it needs to be emitted
+ // so there is no check needed to see if declaration is visible
+ if (node.kind !== SyntaxKind.VariableDeclaration || resolver.isDeclarationVisible(node)) {
+ writeTextOfNode(currentSourceFile, node.name);
+ // If optional property emit ?
+ if (node.kind === SyntaxKind.Property && (node.flags & NodeFlags.QuestionMark)) {
+ write("?");
+ }
+ if (node.kind === SyntaxKind.Property && node.parent.kind === SyntaxKind.TypeLiteral) {
+ emitTypeOfVariableDeclarationFromTypeLiteral(node);
+ }
+ else if (!(node.flags & NodeFlags.Private)) {
+ writeTypeAtLocation(node, node.type, getVariableDeclarationTypeVisibilityError);
+ }
+ }
+
+ function getVariableDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic {
+ var diagnosticMessage: DiagnosticMessage;
+ if (node.kind === SyntaxKind.VariableDeclaration) {
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
+ symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
+ Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
+ Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_private_module_2 :
+ Diagnostics.Exported_variable_0_has_or_is_using_private_name_1;
+ }
+ // This check is to ensure we don't report error on constructor parameter property as that error would be reported during parameter emit
+ else if (node.kind === SyntaxKind.Property) {
+ // TODO(jfreeman): Deal with computed properties in error reporting.
+ if (node.flags & NodeFlags.Static) {
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
+ symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
+ Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
+ Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 :
+ Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_private_name_1;
+ }
+ else if (node.parent.kind === SyntaxKind.ClassDeclaration) {
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
+ symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
+ Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
+ Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 :
+ Diagnostics.Public_property_0_of_exported_class_has_or_is_using_private_name_1;
+ }
+ else {
+ // Interfaces cannot have types that cannot be named
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
+ Diagnostics.Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 :
+ Diagnostics.Property_0_of_exported_interface_has_or_is_using_private_name_1;
+ }
+ }
+
+ return diagnosticMessage !== undefined ? {
+ diagnosticMessage,
+ errorNode: node,
+ typeName: node.name
+ } : undefined;
+ }
+ }
+
+ function emitTypeOfVariableDeclarationFromTypeLiteral(node: VariableDeclaration) {
+ // if this is property of type literal,
+ // or is parameter of method/call/construct/index signature of type literal
+ // emit only if type is specified
+ if (node.type) {
+ write(": ");
+ emitType(node.type);
+ }
+ }
+
+ function emitVariableStatement(node: VariableStatement) {
+ var hasDeclarationWithEmit = forEach(node.declarations, varDeclaration => resolver.isDeclarationVisible(varDeclaration));
+ if (hasDeclarationWithEmit) {
+ emitJsDocComments(node);
+ emitModuleElementDeclarationFlags(node);
+ if (isLet(node)) {
+ write("let ");
+ }
+ else if (isConst(node)) {
+ write("const ");
+ }
+ else {
+ write("var ");
+ }
+ emitCommaList(node.declarations, emitVariableDeclaration);
+ write(";");
+ writeLine();
+ }
+ }
+
+ function emitAccessorDeclaration(node: AccessorDeclaration) {
+ var accessors = getAllAccessorDeclarations(node.parent, node);
+ if (node === accessors.firstAccessor) {
+ emitJsDocComments(accessors.getAccessor);
+ emitJsDocComments(accessors.setAccessor);
+ emitClassMemberDeclarationFlags(node);
+ writeTextOfNode(currentSourceFile, node.name);
+ if (!(node.flags & NodeFlags.Private)) {
+ var accessorWithTypeAnnotation: AccessorDeclaration = node;
+ var type = getTypeAnnotationFromAccessor(node);
+ if (!type) {
+ // couldn't get type for the first accessor, try the another one
+ var anotherAccessor = node.kind === SyntaxKind.GetAccessor ? accessors.setAccessor : accessors.getAccessor;
+ type = getTypeAnnotationFromAccessor(anotherAccessor);
+ if (type) {
+ accessorWithTypeAnnotation = anotherAccessor;
+ }
+ }
+ writeTypeAtLocation(node, type, getAccessorDeclarationTypeVisibilityError);
+ }
+ write(";");
+ writeLine();
+ }
+
+ function getTypeAnnotationFromAccessor(accessor: AccessorDeclaration): TypeNode {
+ if (accessor) {
+ return accessor.kind === SyntaxKind.GetAccessor ?
+ accessor.type : // Getter - return type
+ accessor.parameters[0].type; // Setter parameter type
+ }
+ }
+
+ function getAccessorDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic {
+ var diagnosticMessage: DiagnosticMessage;
+ if (accessorWithTypeAnnotation.kind === SyntaxKind.SetAccessor) {
+ // Setters have to have type named and cannot infer it so, the type should always be named
+ if (accessorWithTypeAnnotation.parent.flags & NodeFlags.Static) {
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
+ Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
+ Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_private_name_1;
+ }
+ else {
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
+ Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
+ Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_private_name_1;
+ }
+ return {
+ diagnosticMessage,
+ errorNode: accessorWithTypeAnnotation.parameters[0],
+ // TODO(jfreeman): Investigate why we are passing node.name instead of node.parameters[0].name
+ typeName: accessorWithTypeAnnotation.name
+ };
+ }
+ else {
+ if (accessorWithTypeAnnotation.flags & NodeFlags.Static) {
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
+ symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
+ Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named :
+ Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 :
+ Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_private_name_0;
+ }
+ else {
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
+ symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
+ Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named :
+ Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 :
+ Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_private_name_0;
+ }
+ return {
+ diagnosticMessage,
+ errorNode: accessorWithTypeAnnotation.name,
+ typeName: undefined
+ };
+ }
+ }
+ }
+
+ function emitFunctionDeclaration(node: FunctionLikeDeclaration) {
+ // If we are emitting Method/Constructor it isn't moduleElement and hence already determined to be emitting
+ // so no need to verify if the declaration is visible
+ if ((node.kind !== SyntaxKind.FunctionDeclaration || resolver.isDeclarationVisible(node)) &&
+ !resolver.isImplementationOfOverload(node)) {
+ emitJsDocComments(node);
+ if (node.kind === SyntaxKind.FunctionDeclaration) {
+ emitModuleElementDeclarationFlags(node);
+ }
+ else if (node.kind === SyntaxKind.Method) {
+ emitClassMemberDeclarationFlags(node);
+ }
+ if (node.kind === SyntaxKind.FunctionDeclaration) {
+ write("function ");
+ writeTextOfNode(currentSourceFile, node.name);
+ }
+ else if (node.kind === SyntaxKind.Constructor) {
+ write("constructor");
+ }
+ else {
+ writeTextOfNode(currentSourceFile, node.name);
+ if (node.flags & NodeFlags.QuestionMark) {
+ write("?");
+ }
+ }
+ emitSignatureDeclaration(node);
+ }
+ }
+
+ function emitSignatureDeclarationWithJsDocComments(node: SignatureDeclaration) {
+ emitJsDocComments(node);
+ emitSignatureDeclaration(node);
+ }
+
+ function emitSignatureDeclaration(node: SignatureDeclaration) {
+ // Construct signature or constructor type write new Signature
+ if (node.kind === SyntaxKind.ConstructSignature || node.kind === SyntaxKind.ConstructorType) {
+ write("new ");
+ }
+ emitTypeParameters(node.typeParameters);
+ if (node.kind === SyntaxKind.IndexSignature) {
+ write("[");
+ }
+ else {
+ write("(");
+ }
+
+ var prevEnclosingDeclaration = enclosingDeclaration;
+ enclosingDeclaration = node;
+
+ // Parameters
+ emitCommaList(node.parameters, emitParameterDeclaration);
+
+ if (node.kind === SyntaxKind.IndexSignature) {
+ write("]");
+ }
+ else {
+ write(")");
+ }
+
+ // If this is not a constructor and is not private, emit the return type
+ var isFunctionTypeOrConstructorType = node.kind === SyntaxKind.FunctionType || node.kind === SyntaxKind.ConstructorType;
+ if (isFunctionTypeOrConstructorType || node.parent.kind === SyntaxKind.TypeLiteral) {
+ // Emit type literal signature return type only if specified
+ if (node.type) {
+ write(isFunctionTypeOrConstructorType ? " => " : ": ");
+ emitType(node.type);
+ }
+ }
+ else if (node.kind !== SyntaxKind.Constructor && !(node.flags & NodeFlags.Private)) {
+ writeReturnTypeAtSignature(node, getReturnTypeVisibilityError);
+ }
+
+ enclosingDeclaration = prevEnclosingDeclaration;
+
+ if (!isFunctionTypeOrConstructorType) {
+ write(";");
+ writeLine();
+ }
+
+ function getReturnTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic {
+ var diagnosticMessage: DiagnosticMessage;
+ switch (node.kind) {
+ case SyntaxKind.ConstructSignature:
+ // Interfaces cannot have return types that cannot be named
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
+ Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 :
+ Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_0;
+ break;
+
+ case SyntaxKind.CallSignature:
+ // Interfaces cannot have return types that cannot be named
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
+ Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 :
+ Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_private_name_0;
+ break;
+
+ case SyntaxKind.IndexSignature:
+ // Interfaces cannot have return types that cannot be named
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
+ Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 :
+ Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_private_name_0;
+ break;
+
+ case SyntaxKind.Method:
+ if (node.flags & NodeFlags.Static) {
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
+ symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
+ Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named :
+ Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 :
+ Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_private_name_0;
+ }
+ else if (node.parent.kind === SyntaxKind.ClassDeclaration) {
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
+ symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
+ Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named :
+ Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 :
+ Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_private_name_0;
+ }
+ else {
+ // Interfaces cannot have return types that cannot be named
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
+ Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_name_0_from_private_module_1 :
+ Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_private_name_0;
+ }
+ break;
+
+ case SyntaxKind.FunctionDeclaration:
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
+ symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
+ Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named :
+ Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_private_module_1 :
+ Diagnostics.Return_type_of_exported_function_has_or_is_using_private_name_0;
+ break;
+
+ default:
+ Debug.fail("This is unknown kind for signature: " + node.kind);
+ }
+
+ return {
+ diagnosticMessage,
+ errorNode: node.name || node,
+ };
+ }
+ }
+
+ function emitParameterDeclaration(node: ParameterDeclaration) {
+ increaseIndent();
+ emitJsDocComments(node);
+ if (node.flags & NodeFlags.Rest) {
+ write("...");
+ }
+ writeTextOfNode(currentSourceFile, node.name);
+ if (node.initializer || (node.flags & NodeFlags.QuestionMark)) {
+ write("?");
+ }
+ decreaseIndent();
+
+ if (node.parent.kind === SyntaxKind.FunctionType ||
+ node.parent.kind === SyntaxKind.ConstructorType ||
+ node.parent.parent.kind === SyntaxKind.TypeLiteral) {
+ emitTypeOfVariableDeclarationFromTypeLiteral(node);
+ }
+ else if (!(node.parent.flags & NodeFlags.Private)) {
+ writeTypeAtLocation(node, node.type, getParameterDeclarationTypeVisibilityError);
+ }
+
+ function getParameterDeclarationTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic {
+ var diagnosticMessage: DiagnosticMessage;
+ switch (node.parent.kind) {
+ case SyntaxKind.Constructor:
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
+ symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
+ Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
+ Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
+ Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_private_name_1;
+ break;
+
+ case SyntaxKind.ConstructSignature:
+ // Interfaces cannot have parameter types that cannot be named
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
+ Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 :
+ Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1;
+ break;
+
+ case SyntaxKind.CallSignature:
+ // Interfaces cannot have parameter types that cannot be named
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
+ Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 :
+ Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1;
+ break;
+
+ case SyntaxKind.Method:
+ if (node.parent.flags & NodeFlags.Static) {
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
+ symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
+ Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
+ Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
+ Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1;
+ }
+ else if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) {
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
+ symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
+ Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
+ Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
+ Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1;
+ }
+ else {
+ // Interfaces cannot have parameter types that cannot be named
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
+ Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 :
+ Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1;
+ }
+ break;
+
+ case SyntaxKind.FunctionDeclaration:
+ diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
+ symbolAccesibilityResult.accessibility === SymbolAccessibility.CannotBeNamed ?
+ Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
+ Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 :
+ Diagnostics.Parameter_0_of_exported_function_has_or_is_using_private_name_1;
+ break;
+
+ default:
+ Debug.fail("This is unknown parent for parameter: " + node.parent.kind);
+ }
+
+ return {
+ diagnosticMessage,
+ errorNode: node,
+ typeName: node.name
+ };
+ }
+ }
+
+ function emitNode(node: Node) {
+ switch (node.kind) {
+ case SyntaxKind.Constructor:
+ case SyntaxKind.FunctionDeclaration:
+ case SyntaxKind.Method:
+ return emitFunctionDeclaration(node);
+ case SyntaxKind.ConstructSignature:
+ case SyntaxKind.CallSignature:
+ case SyntaxKind.IndexSignature:
+ return emitSignatureDeclarationWithJsDocComments(node);
+ case SyntaxKind.GetAccessor:
+ case SyntaxKind.SetAccessor:
+ return emitAccessorDeclaration(node);
+ case SyntaxKind.VariableStatement:
+ return emitVariableStatement(node);
+ case SyntaxKind.Property:
+ return emitPropertyDeclaration(node);
+ case SyntaxKind.InterfaceDeclaration:
+ return emitInterfaceDeclaration(node);
+ case SyntaxKind.ClassDeclaration:
+ return emitClassDeclaration(node);
+ case SyntaxKind.TypeAliasDeclaration:
+ return emitTypeAliasDeclaration(node);
+ case SyntaxKind.EnumMember:
+ return emitEnumMemberDeclaration(node);
+ case SyntaxKind.EnumDeclaration:
+ return emitEnumDeclaration(node);
+ case SyntaxKind.ModuleDeclaration:
+ return emitModuleDeclaration(node);
+ case SyntaxKind.ImportDeclaration:
+ return emitImportDeclaration(node);
+ case SyntaxKind.ExportAssignment:
+ return emitExportAssignment(node);
+ case SyntaxKind.SourceFile:
+ return emitSourceFile(node);
+ }
+ }
+
+ // Contains the reference paths that needs to go in the declaration file.
+ // Collecting this separately because reference paths need to be first thing in the declaration file
+ // and we could be collecting these paths from multiple files into single one with --out option
+ var referencePathsOutput = "";
+ function writeReferencePath(referencedFile: SourceFile) {
+ var declFileName = referencedFile.flags & NodeFlags.DeclarationFile
+ ? referencedFile.filename // Declaration file, use declaration file name
+ : shouldEmitToOwnFile(referencedFile, compilerOptions)
+ ? getOwnEmitOutputFilePath(referencedFile, program, ".d.ts") // Own output file so get the .d.ts file
+ : removeFileExtension(compilerOptions.out) + ".d.ts";// Global out file
+
+ declFileName = getRelativePathToDirectoryOrUrl(
+ getDirectoryPath(normalizeSlashes(jsFilePath)),
+ declFileName,
+ compilerHost.getCurrentDirectory(),
+ compilerHost.getCanonicalFileName,
+ /*isAbsolutePathAnUrl*/ false);
+
+ referencePathsOutput += "/// " + newLine;
+ }
+
+ if (root) {
+ // Emitting just a single file, so emit references in this file only
+ if (!compilerOptions.noResolve) {
+ var addedGlobalFileReference = false;
+ forEach(root.referencedFiles, fileReference => {
+ var referencedFile = tryResolveScriptReference(program, root, fileReference);
+
+ // All the references that are not going to be part of same file
+ if (referencedFile && ((referencedFile.flags & NodeFlags.DeclarationFile) || // This is a declare file reference
+ shouldEmitToOwnFile(referencedFile, compilerOptions) || // This is referenced file is emitting its own js file
+ !addedGlobalFileReference)) { // Or the global out file corresponding to this reference was not added
+
+ writeReferencePath(referencedFile);
+ if (!isExternalModuleOrDeclarationFile(referencedFile)) {
+ addedGlobalFileReference = true;
+ }
+ }
+ });
+ }
+
+ emitNode(root);
+ }
+ else {
+ // Emit references corresponding to this file
+ var emittedReferencedFiles: SourceFile[] = [];
+ forEach(program.getSourceFiles(), sourceFile => {
+ if (!isExternalModuleOrDeclarationFile(sourceFile)) {
+ // Check what references need to be added
+ if (!compilerOptions.noResolve) {
+ forEach(sourceFile.referencedFiles, fileReference => {
+ var referencedFile = tryResolveScriptReference(program, sourceFile, fileReference);
+
+ // If the reference file is a declaration file or an external module, emit that reference
+ if (referencedFile && (isExternalModuleOrDeclarationFile(referencedFile) &&
+ !contains(emittedReferencedFiles, referencedFile))) { // If the file reference was not already emitted
+
+ writeReferencePath(referencedFile);
+ emittedReferencedFiles.push(referencedFile);
+ }
+ });
+ }
+
+ emitNode(sourceFile);
+ }
+ });
+ }
+
+ return {
+ reportedDeclarationError,
+ aliasDeclarationEmitInfo,
+ synchronousDeclarationOutput: writer.getText(),
+ referencePathsOutput,
+ }
+ }
+
+ export function getDeclarationDiagnostics(program: Program, resolver: EmitResolver, targetSourceFile: SourceFile): Diagnostic[] {
+ var diagnostics: Diagnostic[] = [];
+ var jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, program, ".js");
+ emitDeclarations(program, resolver, diagnostics, jsFilePath, targetSourceFile);
+ return diagnostics;
+ }
+
+ // targetSourceFile is when users only want one file in entire project to be emitted. This is used in compilerOnSave feature
+ export function emitFiles(resolver: EmitResolver, targetSourceFile?: SourceFile): EmitResult {
+ var program = resolver.getProgram();
+ var compilerHost = program.getCompilerHost();
+ var compilerOptions = program.getCompilerOptions();
+ var sourceMapDataList: SourceMapData[] = compilerOptions.sourceMap ? [] : undefined;
+ var diagnostics: Diagnostic[] = [];
+ var newLine = program.getCompilerHost().getNewLine();
+
function emitJavaScript(jsFilePath: string, root?: SourceFile) {
- var writer = createTextWriter();
+ var writer = createTextWriter(newLine);
var write = writer.write;
+ var writeTextOfNode = writer.writeTextOfNode;
var writeLine = writer.writeLine;
var increaseIndent = writer.increaseIndent;
var decreaseIndent = writer.decreaseIndent;
+ var currentSourceFile: SourceFile;
+
var extendsEmitted = false;
/** write emitted output to disk*/
@@ -593,9 +1750,9 @@ module ts {
sourceMapNameIndices.pop();
};
- function writeCommentRangeWithMap(comment: CommentRange, writer: EmitTextWriter) {
+ function writeCommentRangeWithMap(curentSourceFile: SourceFile, writer: EmitTextWriter, comment: CommentRange, newLine: string) {
recordSourceMapSpan(comment.pos);
- writeCommentRange(comment, writer);
+ writeCommentRange(currentSourceFile, writer, comment, newLine);
recordSourceMapSpan(comment.end);
}
@@ -628,7 +1785,7 @@ module ts {
function writeJavaScriptAndSourceMapFile(emitOutput: string, writeByteOrderMark: boolean) {
// Write source map file
encodeLastRecordedSourceMapSpan();
- writeFile(sourceMapData.sourceMapFilePath, serializeSourceMapContents(
+ writeFile(compilerHost, diagnostics, sourceMapData.sourceMapFilePath, serializeSourceMapContents(
3,
sourceMapData.sourceMapFile,
sourceMapData.sourceMapSourceRoot,
@@ -667,7 +1824,7 @@ module ts {
if (root) { // emitting single module file
// For modules or multiple emit files the mapRoot will have directory structure like the sources
// So if src\a.ts and src\lib\b.ts are compiled together user would be moving the maps into mapRoot\a.js.map and mapRoot\lib\b.js.map
- sourceMapDir = getDirectoryPath(getSourceFilePathInNewDir(sourceMapDir, root));
+ sourceMapDir = getDirectoryPath(getSourceFilePathInNewDir(root, program, sourceMapDir));
}
if (!isRootedDiskPath(sourceMapDir) && !isUrl(sourceMapDir)) {
@@ -713,7 +1870,7 @@ module ts {
}
function writeJavaScriptFile(emitOutput: string, writeByteOrderMark: boolean) {
- writeFile(jsFilePath, emitOutput, writeByteOrderMark);
+ writeFile(compilerHost, diagnostics, jsFilePath, emitOutput, writeByteOrderMark);
}
function emitTokenText(tokenKind: SyntaxKind, startPos: number, emitFn?: () => void) {
@@ -800,7 +1957,7 @@ module ts {
return false;
}
- function emitLiteral(node: LiteralExpression): void {
+ function emitLiteral(node: LiteralExpression) {
var text = getLiteralText();
if (compilerOptions.sourceMap && (node.kind === SyntaxKind.StringLiteral || isTemplateLiteralKind(node.kind))) {
@@ -808,7 +1965,7 @@ module ts {
}
// For version below ES6, emit binary integer literal and octal integer literal in canonical form
else if (compilerOptions.target < ScriptTarget.ES6 && node.kind === SyntaxKind.NumericLiteral && isBinaryOrOctalIntegerLiteral(text)) {
- write(node.text);
+ write(node.text);
}
else {
write(text);
@@ -818,14 +1975,15 @@ module ts {
if (compilerOptions.target < ScriptTarget.ES6 && isTemplateLiteralKind(node.kind)) {
return getTemplateLiteralAsStringLiteral(node)
}
- return getSourceTextOfLocalNode(node);
+
+ return getSourceTextOfNodeFromSourceFile(currentSourceFile, node);
}
}
function getTemplateLiteralAsStringLiteral(node: LiteralExpression): string {
return '"' + escapeString(node.text) + '"';
}
-
+
function emitTemplateExpression(node: TemplateExpression): void {
// In ES6 mode and above, we can simply emit each portion of a template in order, but in
// ES3 & ES5 we must convert the template expression into a series of string concatenations.
@@ -836,11 +1994,10 @@ module ts {
Debug.assert(node.parent.kind !== SyntaxKind.TaggedTemplateExpression);
- var templateNeedsParens = isExpression(node.parent)
- && node.parent.kind !== SyntaxKind.ParenExpression
- && comparePrecedenceToBinaryPlus(node.parent) !== Comparison.LessThan;
+ var emitOuterParens = isExpression(node.parent)
+ && templateNeedsParens(node, node.parent);
- if (templateNeedsParens) {
+ if (emitOuterParens) {
write("(");
}
@@ -849,14 +2006,14 @@ module ts {
forEach(node.templateSpans, templateSpan => {
// Check if the expression has operands and binds its operands less closely than binary '+'.
// If it does, we need to wrap the expression in parentheses. Otherwise, something like
- // `abc${ 1 << 2}`
+ // `abc${ 1 << 2 }`
// becomes
// "abc" + 1 << 2 + ""
// which is really
// ("abc" + 1) << (2 + "")
// rather than
// "abc" + (1 << 2) + ""
- var needsParens = templateSpan.expression.kind !== SyntaxKind.ParenExpression
+ var needsParens = templateSpan.expression.kind !== SyntaxKind.ParenthesizedExpression
&& comparePrecedenceToBinaryPlus(templateSpan.expression) !== Comparison.GreaterThan;
write(" + ");
@@ -870,18 +2027,33 @@ module ts {
}
// Only emit if the literal is non-empty.
- // The binary '+' operator is left-associative, so the first string concatenation will force
- // the result up to this point to be a string. Emitting a '+ ""' has no semantic effect.
+ // The binary '+' operator is left-associative, so the first string concatenation
+ // with the head will force the result up to this point to be a string.
+ // Emitting a '+ ""' has no semantic effect for middles and tails.
if (templateSpan.literal.text.length !== 0) {
write(" + ")
emitLiteral(templateSpan.literal);
}
});
-
- if (templateNeedsParens) {
+
+ if (emitOuterParens) {
write(")");
}
+ function templateNeedsParens(template: TemplateExpression, parent: Expression) {
+ switch (parent.kind) {
+ case SyntaxKind.CallExpression:
+ case SyntaxKind.NewExpression:
+ return (parent).expression === template;
+ case SyntaxKind.ParenthesizedExpression:
+ return false;
+ case SyntaxKind.TaggedTemplateExpression:
+ Debug.fail("Path should be unreachable; tagged templates not supported pre-ES6.");
+ default:
+ return comparePrecedenceToBinaryPlus(parent) !== Comparison.LessThan;
+ }
+ }
+
/**
* Returns whether the expression has lesser, greater,
* or equal precedence to the binary '+' operator
@@ -914,7 +2086,6 @@ module ts {
return Comparison.GreaterThan;
}
}
-
}
function emitTemplateSpan(span: TemplateSpan) {
@@ -928,6 +2099,9 @@ module ts {
if (node.kind === SyntaxKind.StringLiteral) {
emitLiteral(node);
}
+ else if (node.kind === SyntaxKind.ComputedPropertyName) {
+ emit((node).expression);
+ }
else {
write("\"");
@@ -935,7 +2109,7 @@ module ts {
write((node).text);
}
else {
- write(getSourceTextOfLocalNode(node));
+ writeTextOfNode(currentSourceFile, node);
}
write("\"");
@@ -979,7 +2153,7 @@ module ts {
write(prefix);
write(".");
}
- write(getSourceTextOfLocalNode(node));
+ writeTextOfNode(currentSourceFile, node);
}
function emitIdentifier(node: Identifier) {
@@ -987,7 +2161,7 @@ module ts {
emitExpressionIdentifier(node);
}
else {
- write(getSourceTextOfLocalNode(node));
+ writeTextOfNode(currentSourceFile, node);
}
}
@@ -1013,7 +2187,7 @@ module ts {
}
}
- function emitArrayLiteral(node: ArrayLiteral) {
+ function emitArrayLiteral(node: ArrayLiteralExpression) {
if (node.flags & NodeFlags.MultiLine) {
write("[");
increaseIndent();
@@ -1029,7 +2203,7 @@ module ts {
}
}
- function emitObjectLiteral(node: ObjectLiteral) {
+ function emitObjectLiteral(node: ObjectLiteralExpression) {
if (!node.properties.length) {
write("{}");
}
@@ -1048,6 +2222,12 @@ module ts {
}
}
+ function emitComputedPropertyName(node: ComputedPropertyName) {
+ write("[");
+ emit(node.expression);
+ write("]");
+ }
+
function emitPropertyAssignment(node: PropertyDeclaration) {
emitLeadingComments(node);
emit(node.name);
@@ -1086,48 +2266,54 @@ module ts {
}
}
- function tryEmitConstantValue(node: PropertyAccess | IndexedAccess): boolean {
+ function tryEmitConstantValue(node: PropertyAccessExpression | ElementAccessExpression): boolean {
var constantValue = resolver.getConstantValue(node);
if (constantValue !== undefined) {
- var propertyName = node.kind === SyntaxKind.PropertyAccess ? declarationNameToString((node).right) : getTextOfNode((node).index);
+ var propertyName = node.kind === SyntaxKind.PropertyAccessExpression ? declarationNameToString((node).name) : getTextOfNode((node).argumentExpression);
write(constantValue.toString() + " /* " + propertyName + " */");
return true;
}
return false;
}
- function emitPropertyAccess(node: PropertyAccess) {
+ function emitPropertyAccess(node: PropertyAccessExpression) {
if (tryEmitConstantValue(node)) {
return;
}
+ emit(node.expression);
+ write(".");
+ emit(node.name);
+ }
+
+ function emitQualifiedName(node: QualifiedName) {
emit(node.left);
write(".");
emit(node.right);
}
- function emitIndexedAccess(node: IndexedAccess) {
+ function emitIndexedAccess(node: ElementAccessExpression) {
if (tryEmitConstantValue(node)) {
return;
}
- emit(node.object);
+ emit(node.expression);
write("[");
- emit(node.index);
+ emit(node.argumentExpression);
write("]");
}
function emitCallExpression(node: CallExpression) {
var superCall = false;
- if (node.func.kind === SyntaxKind.SuperKeyword) {
+ if (node.expression.kind === SyntaxKind.SuperKeyword) {
write("_super");
superCall = true;
}
else {
- emit(node.func);
- superCall = node.func.kind === SyntaxKind.PropertyAccess && (node.func).left.kind === SyntaxKind.SuperKeyword;
+ emit(node.expression);
+ superCall = node.expression.kind === SyntaxKind.PropertyAccessExpression && (