mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Add snapshot of release-1.0.3 sources
This commit is contained in:
+1898
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,647 @@
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export interface IParameters {
|
||||
length: number;
|
||||
lastParameterIsRest(): boolean;
|
||||
ast: AST;
|
||||
astAt(index: number): AST;
|
||||
identifierAt(index: number): Identifier;
|
||||
typeAt(index: number): AST;
|
||||
initializerAt(index: number): EqualsValueClause;
|
||||
isOptionalAt(index: number): boolean;
|
||||
}
|
||||
}
|
||||
|
||||
module TypeScript.ASTHelpers {
|
||||
export function scriptIsElided(sourceUnit: SourceUnit): boolean {
|
||||
return isDTSFile(sourceUnit.fileName()) || moduleMembersAreElided(sourceUnit.moduleElements);
|
||||
}
|
||||
|
||||
export function moduleIsElided(declaration: ModuleDeclaration): boolean {
|
||||
return hasModifier(declaration.modifiers, PullElementFlags.Ambient) || moduleMembersAreElided(declaration.moduleElements);
|
||||
}
|
||||
|
||||
function moduleMembersAreElided(members: ISyntaxList2): boolean {
|
||||
for (var i = 0, n = members.childCount(); i < n; i++) {
|
||||
var member = members.childAt(i);
|
||||
|
||||
// We should emit *this* module if it contains any non-interface types.
|
||||
// Caveat: if we have contain a module, then we should be emitted *if we want to
|
||||
// emit that inner module as well.
|
||||
if (member.kind() === SyntaxKind.ModuleDeclaration) {
|
||||
if (!moduleIsElided(<ModuleDeclaration>member)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (member.kind() !== SyntaxKind.InterfaceDeclaration) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
export function enumIsElided(declaration: EnumDeclaration): boolean {
|
||||
if (hasModifier(declaration.modifiers, PullElementFlags.Ambient)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export function isValidAstNode(ast: IASTSpan): boolean {
|
||||
if (!ast)
|
||||
return false;
|
||||
|
||||
if (ast.start() === -1 || ast.end() === -1)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
///
|
||||
/// Return the AST containing "position"
|
||||
///
|
||||
export function getAstAtPosition(script: AST, pos: number, useTrailingTriviaAsLimChar: boolean = true, forceInclusive: boolean = false): AST {
|
||||
var top: AST = null;
|
||||
|
||||
var pre = function (cur: AST, walker: IAstWalker) {
|
||||
if (isValidAstNode(cur)) {
|
||||
var isInvalid1 = cur.kind() === SyntaxKind.ExpressionStatement && cur.width() === 0;
|
||||
|
||||
if (isInvalid1) {
|
||||
walker.options.goChildren = false;
|
||||
}
|
||||
else {
|
||||
// Add "cur" to the stack if it contains our position
|
||||
// For "identifier" nodes, we need a special case: A position equal to "limChar" is
|
||||
// valid, since the position corresponds to a caret position (in between characters)
|
||||
// For example:
|
||||
// bar
|
||||
// 0123
|
||||
// If "position === 3", the caret is at the "right" of the "r" character, which should be considered valid
|
||||
var inclusive =
|
||||
forceInclusive ||
|
||||
cur.kind() === SyntaxKind.IdentifierName ||
|
||||
cur.kind() === SyntaxKind.MemberAccessExpression ||
|
||||
cur.kind() === SyntaxKind.QualifiedName ||
|
||||
//cur.kind() === SyntaxKind.TypeRef ||
|
||||
cur.kind() === SyntaxKind.VariableDeclaration ||
|
||||
cur.kind() === SyntaxKind.VariableDeclarator ||
|
||||
cur.kind() === SyntaxKind.InvocationExpression ||
|
||||
pos === script.end() + script.trailingTriviaWidth(); // Special "EOF" case
|
||||
|
||||
var minChar = cur.start();
|
||||
var limChar = cur.end() + (useTrailingTriviaAsLimChar ? cur.trailingTriviaWidth() : 0) + (inclusive ? 1 : 0);
|
||||
if (pos >= minChar && pos < limChar) {
|
||||
|
||||
// Ignore empty lists
|
||||
if ((cur.kind() !== SyntaxKind.List && cur.kind() !== SyntaxKind.SeparatedList) || cur.end() > cur.start()) {
|
||||
// TODO: Since AST is sometimes not correct wrt to position, only add "cur" if it's better
|
||||
// than top of the stack.
|
||||
if (top === null) {
|
||||
top = cur;
|
||||
}
|
||||
else if (cur.start() >= top.start() &&
|
||||
(cur.end() + (useTrailingTriviaAsLimChar ? cur.trailingTriviaWidth() : 0)) <= (top.end() + (useTrailingTriviaAsLimChar ? top.trailingTriviaWidth() : 0))) {
|
||||
// this new node appears to be better than the one we're
|
||||
// storing. Make this the new node.
|
||||
|
||||
// However, If the current top is a missing identifier, we
|
||||
// don't want to replace it with another missing identifier.
|
||||
// We want to return the first missing identifier found in a
|
||||
// depth first walk of the tree.
|
||||
if (top.width() !== 0 || cur.width() !== 0) {
|
||||
top = cur;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Don't go further down the tree if pos is outside of [minChar, limChar]
|
||||
walker.options.goChildren = (minChar <= pos && pos <= limChar);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
getAstWalkerFactory().walk(script, pre);
|
||||
return top;
|
||||
}
|
||||
|
||||
export function getExtendsHeritageClause(clauses: ISyntaxList2): HeritageClause {
|
||||
if (!clauses) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return <HeritageClause>clauses.firstOrDefault((c: HeritageClause) =>
|
||||
c.typeNames.nonSeparatorCount() > 0 && c.kind() === SyntaxKind.ExtendsHeritageClause);
|
||||
}
|
||||
|
||||
export function getImplementsHeritageClause(clauses: ISyntaxList2): HeritageClause {
|
||||
if (!clauses) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return <HeritageClause>clauses.firstOrDefault((c: HeritageClause) =>
|
||||
c.typeNames.nonSeparatorCount() > 0 && c.kind() === SyntaxKind.ImplementsHeritageClause);
|
||||
}
|
||||
|
||||
export function isCallExpression(ast: AST): boolean {
|
||||
return (ast && ast.kind() === SyntaxKind.InvocationExpression) ||
|
||||
(ast && ast.kind() === SyntaxKind.ObjectCreationExpression);
|
||||
}
|
||||
|
||||
export function isCallExpressionTarget(ast: AST): boolean {
|
||||
if (!ast) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var current = ast;
|
||||
|
||||
while (current && current.parent) {
|
||||
if (current.parent.kind() === SyntaxKind.MemberAccessExpression &&
|
||||
(<MemberAccessExpression>current.parent).name === current) {
|
||||
current = current.parent;
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (current && current.parent) {
|
||||
if (current.parent.kind() === SyntaxKind.InvocationExpression || current.parent.kind() === SyntaxKind.ObjectCreationExpression) {
|
||||
return current === (<InvocationExpression>current.parent).expression;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function isNameOfSomeDeclaration(ast: AST) {
|
||||
if (ast === null || ast.parent === null) {
|
||||
return false;
|
||||
}
|
||||
if (ast.kind() !== SyntaxKind.IdentifierName) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (ast.parent.kind()) {
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
return (<ClassDeclaration>ast.parent).identifier === ast;
|
||||
case SyntaxKind.InterfaceDeclaration:
|
||||
return (<InterfaceDeclaration>ast.parent).identifier === ast;
|
||||
case SyntaxKind.EnumDeclaration:
|
||||
return (<EnumDeclaration>ast.parent).identifier === ast;
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
return (<ModuleDeclaration>ast.parent).name === ast || (<ModuleDeclaration>ast.parent).stringLiteral === ast;
|
||||
case SyntaxKind.VariableDeclarator:
|
||||
return (<VariableDeclarator>ast.parent).propertyName === ast;
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
return (<FunctionDeclaration>ast.parent).identifier === ast;
|
||||
case SyntaxKind.MemberFunctionDeclaration:
|
||||
return (<MemberFunctionDeclaration>ast.parent).propertyName === ast;
|
||||
case SyntaxKind.Parameter:
|
||||
return (<Parameter>ast.parent).identifier === ast;
|
||||
case SyntaxKind.TypeParameter:
|
||||
return (<TypeParameter>ast.parent).identifier === ast;
|
||||
case SyntaxKind.SimplePropertyAssignment:
|
||||
return (<SimplePropertyAssignment>ast.parent).propertyName === ast;
|
||||
case SyntaxKind.FunctionPropertyAssignment:
|
||||
return (<FunctionPropertyAssignment>ast.parent).propertyName === ast;
|
||||
case SyntaxKind.EnumElement:
|
||||
return (<EnumElement>ast.parent).propertyName === ast;
|
||||
case SyntaxKind.ImportDeclaration:
|
||||
return (<ImportDeclaration>ast.parent).identifier === ast;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export function isDeclarationASTOrDeclarationNameAST(ast: AST) {
|
||||
return isNameOfSomeDeclaration(ast) || isDeclarationAST(ast);
|
||||
}
|
||||
|
||||
export function getEnclosingParameterForInitializer(ast: AST): Parameter {
|
||||
var current = ast;
|
||||
while (current) {
|
||||
switch (current.kind()) {
|
||||
case SyntaxKind.EqualsValueClause:
|
||||
if (current.parent && current.parent.kind() === SyntaxKind.Parameter) {
|
||||
return <Parameter>current.parent;
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
case SyntaxKind.InterfaceDeclaration:
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
// exit early
|
||||
return null;
|
||||
}
|
||||
|
||||
current = current.parent;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function getEnclosingMemberVariableDeclaration(ast: AST): MemberVariableDeclaration {
|
||||
var current = ast;
|
||||
|
||||
while (current) {
|
||||
switch (current.kind()) {
|
||||
case SyntaxKind.MemberVariableDeclaration:
|
||||
return <MemberVariableDeclaration>current;
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
case SyntaxKind.InterfaceDeclaration:
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
// exit early
|
||||
return null;
|
||||
}
|
||||
current = current.parent;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function isNameOfFunction(ast: AST) {
|
||||
return ast
|
||||
&& ast.parent
|
||||
&& ast.kind() === SyntaxKind.IdentifierName
|
||||
&& ast.parent.kind() === SyntaxKind.FunctionDeclaration
|
||||
&& (<FunctionDeclaration>ast.parent).identifier === ast;
|
||||
}
|
||||
|
||||
export function isNameOfMemberFunction(ast: AST) {
|
||||
return ast
|
||||
&& ast.parent
|
||||
&& ast.kind() === SyntaxKind.IdentifierName
|
||||
&& ast.parent.kind() === SyntaxKind.MemberFunctionDeclaration
|
||||
&& (<MemberFunctionDeclaration>ast.parent).propertyName === ast;
|
||||
}
|
||||
|
||||
export function isNameOfMemberAccessExpression(ast: AST) {
|
||||
if (ast &&
|
||||
ast.parent &&
|
||||
ast.parent.kind() === SyntaxKind.MemberAccessExpression &&
|
||||
(<MemberAccessExpression>ast.parent).name === ast) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export function isRightSideOfQualifiedName(ast: AST) {
|
||||
if (ast &&
|
||||
ast.parent &&
|
||||
ast.parent.kind() === SyntaxKind.QualifiedName &&
|
||||
(<QualifiedName>ast.parent).right === ast) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export function parentIsModuleDeclaration(ast: AST) {
|
||||
return ast.parent && ast.parent.kind() === SyntaxKind.ModuleDeclaration;
|
||||
}
|
||||
|
||||
export function parametersFromIdentifier(id: Identifier): IParameters {
|
||||
return {
|
||||
length: 1,
|
||||
lastParameterIsRest: () => false,
|
||||
ast: id,
|
||||
astAt: (index: number) => id,
|
||||
identifierAt: (index: number) => id,
|
||||
typeAt: (index: number): AST => null,
|
||||
initializerAt: (index: number): EqualsValueClause => null,
|
||||
isOptionalAt: (index: number) => false,
|
||||
};
|
||||
}
|
||||
|
||||
export function parametersFromParameter(parameter: Parameter): IParameters {
|
||||
return {
|
||||
length: 1,
|
||||
lastParameterIsRest: () => parameter.dotDotDotToken !== null,
|
||||
ast: parameter,
|
||||
astAt: (index: number) => parameter,
|
||||
identifierAt: (index: number) => parameter.identifier,
|
||||
typeAt: (index: number) => getType(parameter),
|
||||
initializerAt: (index: number) => parameter.equalsValueClause,
|
||||
isOptionalAt: (index: number) => parameterIsOptional(parameter),
|
||||
};
|
||||
}
|
||||
|
||||
function parameterIsOptional(parameter: Parameter): boolean {
|
||||
return parameter.questionToken !== null || parameter.equalsValueClause !== null;
|
||||
}
|
||||
|
||||
export function parametersFromParameterList(list: ParameterList): IParameters {
|
||||
return {
|
||||
length: list.parameters.nonSeparatorCount(),
|
||||
lastParameterIsRest: () => lastParameterIsRest(list),
|
||||
ast: list.parameters,
|
||||
astAt: (index: number) => list.parameters.nonSeparatorAt(index),
|
||||
identifierAt: (index: number) => (<Parameter>list.parameters.nonSeparatorAt(index)).identifier,
|
||||
typeAt: (index: number) => getType(list.parameters.nonSeparatorAt(index)),
|
||||
initializerAt: (index: number) => (<Parameter>list.parameters.nonSeparatorAt(index)).equalsValueClause,
|
||||
isOptionalAt: (index: number) => parameterIsOptional(<Parameter>list.parameters.nonSeparatorAt(index)),
|
||||
};
|
||||
}
|
||||
|
||||
export function isDeclarationAST(ast: AST): boolean {
|
||||
switch (ast.kind()) {
|
||||
case SyntaxKind.VariableDeclarator:
|
||||
return getVariableStatement(<VariableDeclarator>ast) !== null;
|
||||
|
||||
case SyntaxKind.ImportDeclaration:
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
case SyntaxKind.InterfaceDeclaration:
|
||||
case SyntaxKind.Parameter:
|
||||
case SyntaxKind.SimpleArrowFunctionExpression:
|
||||
case SyntaxKind.ParenthesizedArrowFunctionExpression:
|
||||
case SyntaxKind.IndexSignature:
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
case SyntaxKind.ArrayType:
|
||||
case SyntaxKind.ObjectType:
|
||||
case SyntaxKind.TypeParameter:
|
||||
case SyntaxKind.ConstructorDeclaration:
|
||||
case SyntaxKind.MemberFunctionDeclaration:
|
||||
case SyntaxKind.GetAccessor:
|
||||
case SyntaxKind.SetAccessor:
|
||||
case SyntaxKind.MemberVariableDeclaration:
|
||||
case SyntaxKind.IndexMemberDeclaration:
|
||||
case SyntaxKind.EnumDeclaration:
|
||||
case SyntaxKind.EnumElement:
|
||||
case SyntaxKind.SimplePropertyAssignment:
|
||||
case SyntaxKind.FunctionPropertyAssignment:
|
||||
case SyntaxKind.FunctionExpression:
|
||||
case SyntaxKind.CallSignature:
|
||||
case SyntaxKind.ConstructSignature:
|
||||
case SyntaxKind.MethodSignature:
|
||||
case SyntaxKind.PropertySignature:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function docComments(ast: AST): Comment[] {
|
||||
if (isDeclarationAST(ast)) {
|
||||
var preComments = ast.kind() === SyntaxKind.VariableDeclarator
|
||||
? getVariableStatement(<VariableDeclarator>ast).preComments()
|
||||
: ast.preComments();
|
||||
|
||||
if (preComments && preComments.length > 0) {
|
||||
var preCommentsLength = preComments.length;
|
||||
var docComments = new Array<Comment>();
|
||||
for (var i = preCommentsLength - 1; i >= 0; i--) {
|
||||
if (isDocComment(preComments[i])) {
|
||||
docComments.push(preComments[i]);
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return docComments.reverse();
|
||||
}
|
||||
}
|
||||
|
||||
return sentinelEmptyArray;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function isDocComment(comment: Comment) {
|
||||
if (comment.kind() === SyntaxKind.MultiLineCommentTrivia) {
|
||||
var fullText = comment.fullText();
|
||||
return fullText.charAt(2) === "*" && fullText.charAt(3) !== "/";
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export function getParameterList(ast: AST): ParameterList {
|
||||
if (ast) {
|
||||
switch (ast.kind()) {
|
||||
case SyntaxKind.ConstructorDeclaration:
|
||||
return getParameterList((<ConstructorDeclaration>ast).callSignature);
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
return getParameterList((<FunctionDeclaration>ast).callSignature);
|
||||
case SyntaxKind.ParenthesizedArrowFunctionExpression:
|
||||
return getParameterList((<ParenthesizedArrowFunctionExpression>ast).callSignature);
|
||||
case SyntaxKind.ConstructSignature:
|
||||
return getParameterList((<ConstructSignature>ast).callSignature);
|
||||
case SyntaxKind.MemberFunctionDeclaration:
|
||||
return getParameterList((<MemberFunctionDeclaration>ast).callSignature);
|
||||
case SyntaxKind.FunctionPropertyAssignment:
|
||||
return getParameterList((<FunctionPropertyAssignment>ast).callSignature);
|
||||
case SyntaxKind.FunctionExpression:
|
||||
return getParameterList((<FunctionExpression>ast).callSignature);
|
||||
case SyntaxKind.MethodSignature:
|
||||
return getParameterList((<MethodSignature>ast).callSignature);
|
||||
case SyntaxKind.ConstructorType:
|
||||
return (<ConstructorType>ast).parameterList;
|
||||
case SyntaxKind.FunctionType:
|
||||
return (<FunctionType>ast).parameterList;
|
||||
case SyntaxKind.CallSignature:
|
||||
return (<CallSignature>ast).parameterList;
|
||||
case SyntaxKind.GetAccessor:
|
||||
return (<GetAccessor>ast).parameterList;
|
||||
case SyntaxKind.SetAccessor:
|
||||
return (<SetAccessor>ast).parameterList;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function getType(ast: AST): AST {
|
||||
if (ast) {
|
||||
switch (ast.kind()) {
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
return getType((<FunctionDeclaration>ast).callSignature);
|
||||
case SyntaxKind.ParenthesizedArrowFunctionExpression:
|
||||
return getType((<ParenthesizedArrowFunctionExpression>ast).callSignature);
|
||||
case SyntaxKind.ConstructSignature:
|
||||
return getType((<ConstructSignature>ast).callSignature);
|
||||
case SyntaxKind.MemberFunctionDeclaration:
|
||||
return getType((<MemberFunctionDeclaration>ast).callSignature);
|
||||
case SyntaxKind.FunctionPropertyAssignment:
|
||||
return getType((<FunctionPropertyAssignment>ast).callSignature);
|
||||
case SyntaxKind.FunctionExpression:
|
||||
return getType((<FunctionExpression>ast).callSignature);
|
||||
case SyntaxKind.MethodSignature:
|
||||
return getType((<MethodSignature>ast).callSignature);
|
||||
case SyntaxKind.CallSignature:
|
||||
return getType((<CallSignature>ast).typeAnnotation);
|
||||
case SyntaxKind.IndexSignature:
|
||||
return getType((<IndexSignature>ast).typeAnnotation);
|
||||
case SyntaxKind.PropertySignature:
|
||||
return getType((<PropertySignature>ast).typeAnnotation);
|
||||
case SyntaxKind.GetAccessor:
|
||||
return getType((<GetAccessor>ast).typeAnnotation);
|
||||
case SyntaxKind.Parameter:
|
||||
return getType((<Parameter>ast).typeAnnotation);
|
||||
case SyntaxKind.MemberVariableDeclaration:
|
||||
return getType((<MemberVariableDeclaration>ast).variableDeclarator);
|
||||
case SyntaxKind.VariableDeclarator:
|
||||
return getType((<VariableDeclarator>ast).typeAnnotation);
|
||||
case SyntaxKind.CatchClause:
|
||||
return getType((<CatchClause>ast).typeAnnotation);
|
||||
case SyntaxKind.ConstructorType:
|
||||
return (<ConstructorType>ast).type;
|
||||
case SyntaxKind.FunctionType:
|
||||
return (<FunctionType>ast).type;
|
||||
case SyntaxKind.TypeAnnotation:
|
||||
return (<TypeAnnotation>ast).type;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function getVariableStatement(variableDeclarator: VariableDeclarator): VariableStatement {
|
||||
if (variableDeclarator && variableDeclarator.parent && variableDeclarator.parent.parent && variableDeclarator.parent.parent.parent &&
|
||||
variableDeclarator.parent.kind() === SyntaxKind.SeparatedList &&
|
||||
variableDeclarator.parent.parent.kind() === SyntaxKind.VariableDeclaration &&
|
||||
variableDeclarator.parent.parent.parent.kind() === SyntaxKind.VariableStatement) {
|
||||
|
||||
return <VariableStatement>variableDeclarator.parent.parent.parent;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function getVariableDeclaratorModifiers(variableDeclarator: VariableDeclarator): PullElementFlags[] {
|
||||
var variableStatement = getVariableStatement(variableDeclarator);
|
||||
return variableStatement ? variableStatement.modifiers : sentinelEmptyArray;
|
||||
}
|
||||
|
||||
export function isIntegerLiteralAST(expression: AST): boolean {
|
||||
if (expression) {
|
||||
switch (expression.kind()) {
|
||||
case SyntaxKind.PlusExpression:
|
||||
case SyntaxKind.NegateExpression:
|
||||
// Note: if there is a + or - sign, we can only allow a normal integer following
|
||||
// (and not a hex integer). i.e. -0xA is a legal expression, but it is not a
|
||||
// *literal*.
|
||||
expression = (<PrefixUnaryExpression>expression).operand;
|
||||
return expression.kind() === SyntaxKind.NumericLiteral && IntegerUtilities.isInteger((<NumericLiteral>expression).text());
|
||||
|
||||
case SyntaxKind.NumericLiteral:
|
||||
// If it doesn't have a + or -, then either an integer literal or a hex literal
|
||||
// is acceptable.
|
||||
var text = (<NumericLiteral>expression).text();
|
||||
return IntegerUtilities.isInteger(text) || IntegerUtilities.isHexInteger(text);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export function getEnclosingModuleDeclaration(ast: AST): ModuleDeclaration {
|
||||
while (ast) {
|
||||
if (ast.kind() === SyntaxKind.ModuleDeclaration) {
|
||||
return <ModuleDeclaration>ast;
|
||||
}
|
||||
|
||||
ast = ast.parent;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function isEntireNameOfModuleDeclaration(nameAST: AST) {
|
||||
return parentIsModuleDeclaration(nameAST) && (<ModuleDeclaration>nameAST.parent).name === nameAST;
|
||||
}
|
||||
|
||||
export function getModuleDeclarationFromNameAST(ast: AST): ModuleDeclaration {
|
||||
if (ast) {
|
||||
switch (ast.kind()) {
|
||||
case SyntaxKind.StringLiteral:
|
||||
if (parentIsModuleDeclaration(ast) && (<ModuleDeclaration>ast.parent).stringLiteral === ast) {
|
||||
return <ModuleDeclaration>ast.parent;
|
||||
}
|
||||
return null;
|
||||
|
||||
case SyntaxKind.IdentifierName:
|
||||
case SyntaxKind.QualifiedName:
|
||||
if (isEntireNameOfModuleDeclaration(ast)) {
|
||||
return <ModuleDeclaration>ast.parent;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
// Only qualified names can be name of module declaration if they didnt satisfy above conditions
|
||||
for (ast = ast.parent; ast && ast.kind() === SyntaxKind.QualifiedName; ast = ast.parent) {
|
||||
if (isEntireNameOfModuleDeclaration(ast)) {
|
||||
return <ModuleDeclaration>ast.parent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function isLastNameOfModule(ast: ModuleDeclaration, astName: AST): boolean {
|
||||
if (ast) {
|
||||
if (ast.stringLiteral) {
|
||||
return astName === ast.stringLiteral;
|
||||
}
|
||||
else if (ast.name.kind() === SyntaxKind.QualifiedName) {
|
||||
return astName === (<QualifiedName>ast.name).right;
|
||||
}
|
||||
else {
|
||||
return astName === ast.name;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export function getNameOfIdenfierOrQualifiedName(name: AST): string {
|
||||
if (name.kind() === SyntaxKind.IdentifierName) {
|
||||
return (<Identifier>name).text();
|
||||
}
|
||||
else {
|
||||
Debug.assert(name.kind() == SyntaxKind.QualifiedName);
|
||||
var dotExpr = <QualifiedName>name;
|
||||
return getNameOfIdenfierOrQualifiedName(dotExpr.left) + "." + getNameOfIdenfierOrQualifiedName(dotExpr.right);
|
||||
}
|
||||
}
|
||||
|
||||
export function getModuleNames(name: AST, result?: Identifier[]): Identifier[] {
|
||||
result = result || [];
|
||||
|
||||
if (name.kind() === SyntaxKind.QualifiedName) {
|
||||
getModuleNames((<QualifiedName>name).left, result);
|
||||
result.push((<QualifiedName>name).right);
|
||||
}
|
||||
else {
|
||||
result.push(<Identifier>name);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,717 @@
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
function walkListChildren(preAst: ISyntaxList2, walker: AstWalker): void {
|
||||
for (var i = 0, n = preAst.childCount(); i < n; i++) {
|
||||
walker.walk(preAst.childAt(i));
|
||||
}
|
||||
}
|
||||
|
||||
function walkThrowStatementChildren(preAst: ThrowStatement, walker: AstWalker): void {
|
||||
walker.walk(preAst.expression);
|
||||
}
|
||||
|
||||
function walkPrefixUnaryExpressionChildren(preAst: PrefixUnaryExpression, walker: AstWalker): void {
|
||||
walker.walk(preAst.operand);
|
||||
}
|
||||
|
||||
function walkPostfixUnaryExpressionChildren(preAst: PostfixUnaryExpression, walker: AstWalker): void {
|
||||
walker.walk(preAst.operand);
|
||||
}
|
||||
|
||||
function walkDeleteExpressionChildren(preAst: DeleteExpression, walker: AstWalker): void {
|
||||
walker.walk(preAst.expression);
|
||||
}
|
||||
|
||||
function walkTypeArgumentListChildren(preAst: TypeArgumentList, walker: AstWalker): void {
|
||||
walker.walk(preAst.typeArguments);
|
||||
}
|
||||
|
||||
function walkTypeOfExpressionChildren(preAst: TypeOfExpression, walker: AstWalker): void {
|
||||
walker.walk(preAst.expression);
|
||||
}
|
||||
|
||||
function walkVoidExpressionChildren(preAst: VoidExpression, walker: AstWalker): void {
|
||||
walker.walk(preAst.expression);
|
||||
}
|
||||
|
||||
function walkArgumentListChildren(preAst: ArgumentList, walker: AstWalker): void {
|
||||
walker.walk(preAst.typeArgumentList);
|
||||
walker.walk(preAst.arguments);
|
||||
}
|
||||
|
||||
function walkArrayLiteralExpressionChildren(preAst: ArrayLiteralExpression, walker: AstWalker): void {
|
||||
walker.walk(preAst.expressions);
|
||||
}
|
||||
|
||||
function walkSimplePropertyAssignmentChildren(preAst: SimplePropertyAssignment, walker: AstWalker): void {
|
||||
walker.walk(preAst.propertyName);
|
||||
walker.walk(preAst.expression);
|
||||
}
|
||||
|
||||
function walkFunctionPropertyAssignmentChildren(preAst: FunctionPropertyAssignment, walker: AstWalker): void {
|
||||
walker.walk(preAst.propertyName);
|
||||
walker.walk(preAst.callSignature);
|
||||
walker.walk(preAst.block);
|
||||
}
|
||||
|
||||
function walkGetAccessorChildren(preAst: GetAccessor, walker: AstWalker): void {
|
||||
walker.walk(preAst.propertyName);
|
||||
walker.walk(preAst.parameterList);
|
||||
walker.walk(preAst.typeAnnotation);
|
||||
walker.walk(preAst.block);
|
||||
}
|
||||
|
||||
function walkSeparatedListChildren(preAst: ISeparatedSyntaxList2, walker: AstWalker): void {
|
||||
for (var i = 0, n = preAst.nonSeparatorCount(); i < n; i++) {
|
||||
walker.walk(preAst.nonSeparatorAt(i));
|
||||
}
|
||||
}
|
||||
|
||||
function walkSetAccessorChildren(preAst: SetAccessor, walker: AstWalker): void {
|
||||
walker.walk(preAst.propertyName);
|
||||
walker.walk(preAst.parameterList);
|
||||
walker.walk(preAst.block);
|
||||
}
|
||||
|
||||
function walkObjectLiteralExpressionChildren(preAst: ObjectLiteralExpression, walker: AstWalker): void {
|
||||
walker.walk(preAst.propertyAssignments);
|
||||
}
|
||||
|
||||
function walkCastExpressionChildren(preAst: CastExpression, walker: AstWalker): void {
|
||||
walker.walk(preAst.type);
|
||||
walker.walk(preAst.expression);
|
||||
}
|
||||
|
||||
function walkParenthesizedExpressionChildren(preAst: ParenthesizedExpression, walker: AstWalker): void {
|
||||
walker.walk(preAst.expression);
|
||||
}
|
||||
|
||||
function walkElementAccessExpressionChildren(preAst: ElementAccessExpression, walker: AstWalker): void {
|
||||
walker.walk(preAst.expression);
|
||||
walker.walk(preAst.argumentExpression);
|
||||
}
|
||||
|
||||
function walkMemberAccessExpressionChildren(preAst: MemberAccessExpression, walker: AstWalker): void {
|
||||
walker.walk(preAst.expression);
|
||||
walker.walk(preAst.name);
|
||||
}
|
||||
|
||||
function walkQualifiedNameChildren(preAst: QualifiedName, walker: AstWalker): void {
|
||||
walker.walk(preAst.left);
|
||||
walker.walk(preAst.right);
|
||||
}
|
||||
|
||||
function walkBinaryExpressionChildren(preAst: BinaryExpression, walker: AstWalker): void {
|
||||
walker.walk(preAst.left);
|
||||
walker.walk(preAst.right);
|
||||
}
|
||||
|
||||
function walkEqualsValueClauseChildren(preAst: EqualsValueClause, walker: AstWalker): void {
|
||||
walker.walk(preAst.value);
|
||||
}
|
||||
|
||||
function walkTypeParameterChildren(preAst: TypeParameter, walker: AstWalker): void {
|
||||
walker.walk(preAst.identifier);
|
||||
walker.walk(preAst.constraint);
|
||||
}
|
||||
|
||||
function walkTypeParameterListChildren(preAst: TypeParameterList, walker: AstWalker): void {
|
||||
walker.walk(preAst.typeParameters);
|
||||
}
|
||||
|
||||
function walkGenericTypeChildren(preAst: GenericType, walker: AstWalker): void {
|
||||
walker.walk(preAst.name);
|
||||
walker.walk(preAst.typeArgumentList);
|
||||
}
|
||||
|
||||
function walkTypeAnnotationChildren(preAst: TypeAnnotation, walker: AstWalker): void {
|
||||
walker.walk(preAst.type);
|
||||
}
|
||||
|
||||
function walkTypeQueryChildren(preAst: TypeQuery, walker: AstWalker): void {
|
||||
walker.walk(preAst.name);
|
||||
}
|
||||
|
||||
function walkInvocationExpressionChildren(preAst: InvocationExpression, walker: AstWalker): void {
|
||||
walker.walk(preAst.expression);
|
||||
walker.walk(preAst.argumentList);
|
||||
}
|
||||
|
||||
function walkObjectCreationExpressionChildren(preAst: ObjectCreationExpression, walker: AstWalker): void {
|
||||
walker.walk(preAst.expression);
|
||||
walker.walk(preAst.argumentList);
|
||||
}
|
||||
|
||||
function walkTrinaryExpressionChildren(preAst: ConditionalExpression, walker: AstWalker): void {
|
||||
walker.walk(preAst.condition);
|
||||
walker.walk(preAst.whenTrue);
|
||||
walker.walk(preAst.whenFalse);
|
||||
}
|
||||
|
||||
function walkFunctionExpressionChildren(preAst: FunctionExpression, walker: AstWalker): void {
|
||||
walker.walk(preAst.identifier);
|
||||
walker.walk(preAst.callSignature);
|
||||
walker.walk(preAst.block);
|
||||
}
|
||||
|
||||
function walkFunctionTypeChildren(preAst: FunctionType, walker: AstWalker): void {
|
||||
walker.walk(preAst.typeParameterList);
|
||||
walker.walk(preAst.parameterList);
|
||||
walker.walk(preAst.type);
|
||||
}
|
||||
|
||||
function walkParenthesizedArrowFunctionExpressionChildren(preAst: ParenthesizedArrowFunctionExpression, walker: AstWalker): void {
|
||||
walker.walk(preAst.callSignature);
|
||||
walker.walk(preAst.block);
|
||||
walker.walk(preAst.expression);
|
||||
}
|
||||
|
||||
function walkSimpleArrowFunctionExpressionChildren(preAst: SimpleArrowFunctionExpression, walker: AstWalker): void {
|
||||
walker.walk(preAst.identifier);
|
||||
walker.walk(preAst.block);
|
||||
walker.walk(preAst.expression);
|
||||
}
|
||||
|
||||
function walkMemberFunctionDeclarationChildren(preAst: MemberFunctionDeclaration, walker: AstWalker): void {
|
||||
walker.walk(preAst.propertyName);
|
||||
walker.walk(preAst.callSignature);
|
||||
walker.walk(preAst.block);
|
||||
}
|
||||
|
||||
function walkFuncDeclChildren(preAst: FunctionDeclaration, walker: AstWalker): void {
|
||||
walker.walk(preAst.identifier);
|
||||
walker.walk(preAst.callSignature);
|
||||
walker.walk(preAst.block);
|
||||
}
|
||||
|
||||
function walkIndexMemberDeclarationChildren(preAst: IndexMemberDeclaration, walker: AstWalker): void {
|
||||
walker.walk(preAst.indexSignature);
|
||||
}
|
||||
|
||||
function walkIndexSignatureChildren(preAst: IndexSignature, walker: AstWalker): void {
|
||||
walker.walk(preAst.parameter);
|
||||
walker.walk(preAst.typeAnnotation);
|
||||
}
|
||||
|
||||
function walkCallSignatureChildren(preAst: CallSignature, walker: AstWalker): void {
|
||||
walker.walk(preAst.typeParameterList);
|
||||
walker.walk(preAst.parameterList);
|
||||
walker.walk(preAst.typeAnnotation);
|
||||
}
|
||||
|
||||
function walkConstraintChildren(preAst: Constraint, walker: AstWalker): void {
|
||||
walker.walk(preAst.type);
|
||||
}
|
||||
|
||||
function walkConstructorDeclarationChildren(preAst: ConstructorDeclaration, walker: AstWalker): void {
|
||||
walker.walk(preAst.callSignature);
|
||||
walker.walk(preAst.block);
|
||||
}
|
||||
|
||||
function walkConstructorTypeChildren(preAst: FunctionType, walker: AstWalker): void {
|
||||
walker.walk(preAst.typeParameterList);
|
||||
walker.walk(preAst.parameterList);
|
||||
walker.walk(preAst.type);
|
||||
}
|
||||
|
||||
function walkConstructSignatureChildren(preAst: ConstructSignature, walker: AstWalker): void {
|
||||
walker.walk(preAst.callSignature);
|
||||
}
|
||||
|
||||
function walkParameterChildren(preAst: Parameter, walker: AstWalker): void {
|
||||
walker.walk(preAst.identifier);
|
||||
walker.walk(preAst.typeAnnotation);
|
||||
walker.walk(preAst.equalsValueClause);
|
||||
}
|
||||
|
||||
function walkParameterListChildren(preAst: ParameterList, walker: AstWalker): void {
|
||||
walker.walk(preAst.parameters);
|
||||
}
|
||||
|
||||
function walkPropertySignatureChildren(preAst: PropertySignature, walker: AstWalker): void {
|
||||
walker.walk(preAst.propertyName);
|
||||
walker.walk(preAst.typeAnnotation);
|
||||
}
|
||||
|
||||
function walkVariableDeclaratorChildren(preAst: VariableDeclarator, walker: AstWalker): void {
|
||||
walker.walk(preAst.propertyName);
|
||||
walker.walk(preAst.typeAnnotation);
|
||||
walker.walk(preAst.equalsValueClause);
|
||||
}
|
||||
|
||||
function walkMemberVariableDeclarationChildren(preAst: MemberVariableDeclaration, walker: AstWalker): void {
|
||||
walker.walk(preAst.variableDeclarator);
|
||||
}
|
||||
|
||||
function walkMethodSignatureChildren(preAst: MethodSignature, walker: AstWalker): void {
|
||||
walker.walk(preAst.propertyName);
|
||||
walker.walk(preAst.callSignature);
|
||||
}
|
||||
|
||||
function walkReturnStatementChildren(preAst: ReturnStatement, walker: AstWalker): void {
|
||||
walker.walk(preAst.expression);
|
||||
}
|
||||
|
||||
function walkForStatementChildren(preAst: ForStatement, walker: AstWalker): void {
|
||||
walker.walk(preAst.variableDeclaration);
|
||||
walker.walk(preAst.initializer);
|
||||
walker.walk(preAst.condition);
|
||||
walker.walk(preAst.incrementor);
|
||||
walker.walk(preAst.statement);
|
||||
}
|
||||
|
||||
function walkForInStatementChildren(preAst: ForInStatement, walker: AstWalker): void {
|
||||
walker.walk(preAst.variableDeclaration);
|
||||
walker.walk(preAst.left);
|
||||
walker.walk(preAst.expression);
|
||||
walker.walk(preAst.statement);
|
||||
}
|
||||
|
||||
function walkIfStatementChildren(preAst: IfStatement, walker: AstWalker): void {
|
||||
walker.walk(preAst.condition);
|
||||
walker.walk(preAst.statement);
|
||||
walker.walk(preAst.elseClause);
|
||||
}
|
||||
|
||||
function walkElseClauseChildren(preAst: ElseClause, walker: AstWalker): void {
|
||||
walker.walk(preAst.statement);
|
||||
}
|
||||
|
||||
function walkWhileStatementChildren(preAst: WhileStatement, walker: AstWalker): void {
|
||||
walker.walk(preAst.condition);
|
||||
walker.walk(preAst.statement);
|
||||
}
|
||||
|
||||
function walkDoStatementChildren(preAst: DoStatement, walker: AstWalker): void {
|
||||
walker.walk(preAst.condition);
|
||||
walker.walk(preAst.statement);
|
||||
}
|
||||
|
||||
function walkBlockChildren(preAst: Block, walker: AstWalker): void {
|
||||
walker.walk(preAst.statements);
|
||||
}
|
||||
|
||||
function walkVariableDeclarationChildren(preAst: VariableDeclaration, walker: AstWalker): void {
|
||||
walker.walk(preAst.declarators);
|
||||
}
|
||||
|
||||
function walkCaseSwitchClauseChildren(preAst: CaseSwitchClause, walker: AstWalker): void {
|
||||
walker.walk(preAst.expression);
|
||||
walker.walk(preAst.statements);
|
||||
}
|
||||
|
||||
function walkDefaultSwitchClauseChildren(preAst: DefaultSwitchClause, walker: AstWalker): void {
|
||||
walker.walk(preAst.statements);
|
||||
}
|
||||
|
||||
function walkSwitchStatementChildren(preAst: SwitchStatement, walker: AstWalker): void {
|
||||
walker.walk(preAst.expression);
|
||||
walker.walk(preAst.switchClauses);
|
||||
}
|
||||
|
||||
function walkTryStatementChildren(preAst: TryStatement, walker: AstWalker): void {
|
||||
walker.walk(preAst.block);
|
||||
walker.walk(preAst.catchClause);
|
||||
walker.walk(preAst.finallyClause);
|
||||
}
|
||||
|
||||
function walkCatchClauseChildren(preAst: CatchClause, walker: AstWalker): void {
|
||||
walker.walk(preAst.identifier);
|
||||
walker.walk(preAst.typeAnnotation);
|
||||
walker.walk(preAst.block);
|
||||
}
|
||||
|
||||
function walkExternalModuleReferenceChildren(preAst: ExternalModuleReference, walker: AstWalker): void {
|
||||
walker.walk(preAst.stringLiteral);
|
||||
}
|
||||
|
||||
function walkFinallyClauseChildren(preAst: FinallyClause, walker: AstWalker): void {
|
||||
walker.walk(preAst.block);
|
||||
}
|
||||
|
||||
function walkClassDeclChildren(preAst: ClassDeclaration, walker: AstWalker): void {
|
||||
walker.walk(preAst.identifier);
|
||||
walker.walk(preAst.typeParameterList);
|
||||
walker.walk(preAst.heritageClauses);
|
||||
walker.walk(preAst.classElements);
|
||||
}
|
||||
|
||||
function walkScriptChildren(preAst: SourceUnit, walker: AstWalker): void {
|
||||
walker.walk(preAst.moduleElements);
|
||||
}
|
||||
|
||||
function walkHeritageClauseChildren(preAst: HeritageClause, walker: AstWalker): void {
|
||||
walker.walk(preAst.typeNames);
|
||||
}
|
||||
|
||||
function walkInterfaceDeclerationChildren(preAst: InterfaceDeclaration, walker: AstWalker): void {
|
||||
walker.walk(preAst.identifier);
|
||||
walker.walk(preAst.typeParameterList);
|
||||
walker.walk(preAst.heritageClauses);
|
||||
walker.walk(preAst.body);
|
||||
}
|
||||
|
||||
function walkObjectTypeChildren(preAst: ObjectType, walker: AstWalker): void {
|
||||
walker.walk(preAst.typeMembers);
|
||||
}
|
||||
|
||||
function walkArrayTypeChildren(preAst: ArrayType, walker: AstWalker): void {
|
||||
walker.walk(preAst.type);
|
||||
}
|
||||
|
||||
function walkModuleDeclarationChildren(preAst: ModuleDeclaration, walker: AstWalker): void {
|
||||
walker.walk(preAst.name);
|
||||
walker.walk(preAst.stringLiteral);
|
||||
walker.walk(preAst.moduleElements);
|
||||
}
|
||||
|
||||
function walkModuleNameModuleReferenceChildren(preAst: ModuleNameModuleReference, walker: AstWalker): void {
|
||||
walker.walk(preAst.moduleName);
|
||||
}
|
||||
|
||||
function walkEnumDeclarationChildren(preAst: EnumDeclaration, walker: AstWalker): void {
|
||||
walker.walk(preAst.identifier);
|
||||
walker.walk(preAst.enumElements);
|
||||
}
|
||||
|
||||
function walkEnumElementChildren(preAst: EnumElement, walker: AstWalker): void {
|
||||
walker.walk(preAst.propertyName);
|
||||
walker.walk(preAst.equalsValueClause);
|
||||
}
|
||||
|
||||
function walkImportDeclarationChildren(preAst: ImportDeclaration, walker: AstWalker): void {
|
||||
walker.walk(preAst.identifier);
|
||||
walker.walk(preAst.moduleReference);
|
||||
}
|
||||
|
||||
function walkExportAssignmentChildren(preAst: ExportAssignment, walker: AstWalker): void {
|
||||
walker.walk(preAst.identifier);
|
||||
}
|
||||
|
||||
function walkWithStatementChildren(preAst: WithStatement, walker: AstWalker): void {
|
||||
walker.walk(preAst.condition);
|
||||
walker.walk(preAst.statement);
|
||||
}
|
||||
|
||||
function walkExpressionStatementChildren(preAst: ExpressionStatement, walker: AstWalker): void {
|
||||
walker.walk(preAst.expression);
|
||||
}
|
||||
|
||||
function walkLabeledStatementChildren(preAst: LabeledStatement, walker: AstWalker): void {
|
||||
walker.walk(preAst.identifier);
|
||||
walker.walk(preAst.statement);
|
||||
}
|
||||
|
||||
function walkVariableStatementChildren(preAst: VariableStatement, walker: AstWalker): void {
|
||||
walker.walk(preAst.declaration);
|
||||
}
|
||||
|
||||
var childrenWalkers: IAstWalkChildren[] = new Array<IAstWalkChildren>(SyntaxKind.Last + 1);
|
||||
|
||||
// Tokens/trivia can't ever be walked into.
|
||||
for (var i = SyntaxKind.FirstToken, n = SyntaxKind.LastToken; i <= n; i++) {
|
||||
childrenWalkers[i] = null;
|
||||
}
|
||||
for (var i = SyntaxKind.FirstTrivia, n = SyntaxKind.LastTrivia; i <= n; i++) {
|
||||
childrenWalkers[i] = null;
|
||||
}
|
||||
|
||||
childrenWalkers[SyntaxKind.AddAssignmentExpression] = walkBinaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.AddExpression] = walkBinaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.AndAssignmentExpression] = walkBinaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.AnyKeyword] = null;
|
||||
childrenWalkers[SyntaxKind.ArgumentList] = walkArgumentListChildren;
|
||||
childrenWalkers[SyntaxKind.ArrayLiteralExpression] = walkArrayLiteralExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.ArrayType] = walkArrayTypeChildren;
|
||||
childrenWalkers[SyntaxKind.SimpleArrowFunctionExpression] = walkSimpleArrowFunctionExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.ParenthesizedArrowFunctionExpression] = walkParenthesizedArrowFunctionExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.AssignmentExpression] = walkBinaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.BitwiseAndExpression] = walkBinaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.BitwiseExclusiveOrExpression] = walkBinaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.BitwiseNotExpression] = walkPrefixUnaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.BitwiseOrExpression] = walkBinaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.Block] = walkBlockChildren;
|
||||
childrenWalkers[SyntaxKind.BooleanKeyword] = null;
|
||||
childrenWalkers[SyntaxKind.BreakStatement] = null;
|
||||
childrenWalkers[SyntaxKind.CallSignature] = walkCallSignatureChildren;
|
||||
childrenWalkers[SyntaxKind.CaseSwitchClause] = walkCaseSwitchClauseChildren;
|
||||
childrenWalkers[SyntaxKind.CastExpression] = walkCastExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.CatchClause] = walkCatchClauseChildren;
|
||||
childrenWalkers[SyntaxKind.ClassDeclaration] = walkClassDeclChildren;
|
||||
childrenWalkers[SyntaxKind.CommaExpression] = walkBinaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.ConditionalExpression] = walkTrinaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.Constraint] = walkConstraintChildren;
|
||||
childrenWalkers[SyntaxKind.ConstructorDeclaration] = walkConstructorDeclarationChildren;
|
||||
childrenWalkers[SyntaxKind.ConstructSignature] = walkConstructSignatureChildren;
|
||||
childrenWalkers[SyntaxKind.ContinueStatement] = null;
|
||||
childrenWalkers[SyntaxKind.ConstructorType] = walkConstructorTypeChildren;
|
||||
childrenWalkers[SyntaxKind.DebuggerStatement] = null;
|
||||
childrenWalkers[SyntaxKind.DefaultSwitchClause] = walkDefaultSwitchClauseChildren;
|
||||
childrenWalkers[SyntaxKind.DeleteExpression] = walkDeleteExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.DivideAssignmentExpression] = walkBinaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.DivideExpression] = walkBinaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.DoStatement] = walkDoStatementChildren;
|
||||
childrenWalkers[SyntaxKind.ElementAccessExpression] = walkElementAccessExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.ElseClause] = walkElseClauseChildren;
|
||||
childrenWalkers[SyntaxKind.EmptyStatement] = null;
|
||||
childrenWalkers[SyntaxKind.EnumDeclaration] = walkEnumDeclarationChildren;
|
||||
childrenWalkers[SyntaxKind.EnumElement] = walkEnumElementChildren;
|
||||
childrenWalkers[SyntaxKind.EqualsExpression] = walkBinaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.EqualsValueClause] = walkEqualsValueClauseChildren;
|
||||
childrenWalkers[SyntaxKind.EqualsWithTypeConversionExpression] = walkBinaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.ExclusiveOrAssignmentExpression] = walkBinaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.ExportAssignment] = walkExportAssignmentChildren;
|
||||
childrenWalkers[SyntaxKind.ExpressionStatement] = walkExpressionStatementChildren;
|
||||
childrenWalkers[SyntaxKind.ExtendsHeritageClause] = walkHeritageClauseChildren;
|
||||
childrenWalkers[SyntaxKind.ExternalModuleReference] = walkExternalModuleReferenceChildren;
|
||||
childrenWalkers[SyntaxKind.FalseKeyword] = null;
|
||||
childrenWalkers[SyntaxKind.FinallyClause] = walkFinallyClauseChildren;
|
||||
childrenWalkers[SyntaxKind.ForInStatement] = walkForInStatementChildren;
|
||||
childrenWalkers[SyntaxKind.ForStatement] = walkForStatementChildren;
|
||||
childrenWalkers[SyntaxKind.FunctionDeclaration] = walkFuncDeclChildren;
|
||||
childrenWalkers[SyntaxKind.FunctionExpression] = walkFunctionExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.FunctionPropertyAssignment] = walkFunctionPropertyAssignmentChildren;
|
||||
childrenWalkers[SyntaxKind.FunctionType] = walkFunctionTypeChildren;
|
||||
childrenWalkers[SyntaxKind.GenericType] = walkGenericTypeChildren;
|
||||
childrenWalkers[SyntaxKind.GetAccessor] = walkGetAccessorChildren;
|
||||
childrenWalkers[SyntaxKind.GreaterThanExpression] = walkBinaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.GreaterThanOrEqualExpression] = walkBinaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.IfStatement] = walkIfStatementChildren;
|
||||
childrenWalkers[SyntaxKind.ImplementsHeritageClause] = walkHeritageClauseChildren;
|
||||
childrenWalkers[SyntaxKind.ImportDeclaration] = walkImportDeclarationChildren;
|
||||
childrenWalkers[SyntaxKind.IndexMemberDeclaration] = walkIndexMemberDeclarationChildren;
|
||||
childrenWalkers[SyntaxKind.IndexSignature] = walkIndexSignatureChildren;
|
||||
childrenWalkers[SyntaxKind.InExpression] = walkBinaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.InstanceOfExpression] = walkBinaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.InterfaceDeclaration] = walkInterfaceDeclerationChildren;
|
||||
childrenWalkers[SyntaxKind.InvocationExpression] = walkInvocationExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.LabeledStatement] = walkLabeledStatementChildren;
|
||||
childrenWalkers[SyntaxKind.LeftShiftAssignmentExpression] = walkBinaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.LeftShiftExpression] = walkBinaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.LessThanExpression] = walkBinaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.LessThanOrEqualExpression] = walkBinaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.List] = walkListChildren;
|
||||
childrenWalkers[SyntaxKind.LogicalAndExpression] = walkBinaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.LogicalNotExpression] = walkPrefixUnaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.LogicalOrExpression] = walkBinaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.MemberAccessExpression] = walkMemberAccessExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.MemberFunctionDeclaration] = walkMemberFunctionDeclarationChildren;
|
||||
childrenWalkers[SyntaxKind.MemberVariableDeclaration] = walkMemberVariableDeclarationChildren;
|
||||
childrenWalkers[SyntaxKind.MethodSignature] = walkMethodSignatureChildren;
|
||||
childrenWalkers[SyntaxKind.ModuleDeclaration] = walkModuleDeclarationChildren;
|
||||
childrenWalkers[SyntaxKind.ModuleNameModuleReference] = walkModuleNameModuleReferenceChildren;
|
||||
childrenWalkers[SyntaxKind.ModuloAssignmentExpression] = walkBinaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.ModuloExpression] = walkBinaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.MultiplyAssignmentExpression] = walkBinaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.MultiplyExpression] = walkBinaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.IdentifierName] = null;
|
||||
childrenWalkers[SyntaxKind.NegateExpression] = walkPrefixUnaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.None] = null;
|
||||
childrenWalkers[SyntaxKind.NotEqualsExpression] = walkBinaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.NotEqualsWithTypeConversionExpression] = walkBinaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.NullKeyword] = null;
|
||||
childrenWalkers[SyntaxKind.NumberKeyword] = null;
|
||||
childrenWalkers[SyntaxKind.NumericLiteral] = null;
|
||||
childrenWalkers[SyntaxKind.ObjectCreationExpression] = walkObjectCreationExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.ObjectLiteralExpression] = walkObjectLiteralExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.ObjectType] = walkObjectTypeChildren;
|
||||
childrenWalkers[SyntaxKind.OmittedExpression] = null;
|
||||
childrenWalkers[SyntaxKind.OrAssignmentExpression] = walkBinaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.Parameter] = walkParameterChildren;
|
||||
childrenWalkers[SyntaxKind.ParameterList] = walkParameterListChildren;
|
||||
childrenWalkers[SyntaxKind.ParenthesizedExpression] = walkParenthesizedExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.PlusExpression] = walkPrefixUnaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.PostDecrementExpression] = walkPostfixUnaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.PostIncrementExpression] = walkPostfixUnaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.PreDecrementExpression] = walkPrefixUnaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.PreIncrementExpression] = walkPrefixUnaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.PropertySignature] = walkPropertySignatureChildren;
|
||||
childrenWalkers[SyntaxKind.QualifiedName] = walkQualifiedNameChildren;
|
||||
childrenWalkers[SyntaxKind.RegularExpressionLiteral] = null;
|
||||
childrenWalkers[SyntaxKind.ReturnStatement] = walkReturnStatementChildren;
|
||||
childrenWalkers[SyntaxKind.SourceUnit] = walkScriptChildren;
|
||||
childrenWalkers[SyntaxKind.SeparatedList] = walkSeparatedListChildren;
|
||||
childrenWalkers[SyntaxKind.SetAccessor] = walkSetAccessorChildren;
|
||||
childrenWalkers[SyntaxKind.SignedRightShiftAssignmentExpression] = walkBinaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.SignedRightShiftExpression] = walkBinaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.SimplePropertyAssignment] = walkSimplePropertyAssignmentChildren;
|
||||
childrenWalkers[SyntaxKind.StringLiteral] = null;
|
||||
childrenWalkers[SyntaxKind.StringKeyword] = null;
|
||||
childrenWalkers[SyntaxKind.SubtractAssignmentExpression] = walkBinaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.SubtractExpression] = walkBinaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.SuperKeyword] = null;
|
||||
childrenWalkers[SyntaxKind.SwitchStatement] = walkSwitchStatementChildren;
|
||||
childrenWalkers[SyntaxKind.ThisKeyword] = null;
|
||||
childrenWalkers[SyntaxKind.ThrowStatement] = walkThrowStatementChildren;
|
||||
childrenWalkers[SyntaxKind.TriviaList] = null;
|
||||
childrenWalkers[SyntaxKind.TrueKeyword] = null;
|
||||
childrenWalkers[SyntaxKind.TryStatement] = walkTryStatementChildren;
|
||||
childrenWalkers[SyntaxKind.TypeAnnotation] = walkTypeAnnotationChildren;
|
||||
childrenWalkers[SyntaxKind.TypeArgumentList] = walkTypeArgumentListChildren;
|
||||
childrenWalkers[SyntaxKind.TypeOfExpression] = walkTypeOfExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.TypeParameter] = walkTypeParameterChildren;
|
||||
childrenWalkers[SyntaxKind.TypeParameterList] = walkTypeParameterListChildren;
|
||||
childrenWalkers[SyntaxKind.TypeQuery] = walkTypeQueryChildren;
|
||||
childrenWalkers[SyntaxKind.UnsignedRightShiftAssignmentExpression] = walkBinaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.UnsignedRightShiftExpression] = walkBinaryExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.VariableDeclaration] = walkVariableDeclarationChildren;
|
||||
childrenWalkers[SyntaxKind.VariableDeclarator] = walkVariableDeclaratorChildren;
|
||||
childrenWalkers[SyntaxKind.VariableStatement] = walkVariableStatementChildren;
|
||||
childrenWalkers[SyntaxKind.VoidExpression] = walkVoidExpressionChildren;
|
||||
childrenWalkers[SyntaxKind.VoidKeyword] = null;
|
||||
childrenWalkers[SyntaxKind.WhileStatement] = walkWhileStatementChildren;
|
||||
childrenWalkers[SyntaxKind.WithStatement] = walkWithStatementChildren;
|
||||
|
||||
// Verify the code is up to date with the enum
|
||||
for (var e in SyntaxKind) {
|
||||
if (SyntaxKind.hasOwnProperty(e) && StringUtilities.isString(SyntaxKind[e])) {
|
||||
TypeScript.Debug.assert(childrenWalkers[e] !== undefined, "Fix initWalkers: " + SyntaxKind[e]);
|
||||
}
|
||||
}
|
||||
|
||||
export class AstWalkOptions {
|
||||
public goChildren = true;
|
||||
public stopWalking = false;
|
||||
}
|
||||
|
||||
interface IAstWalkChildren {
|
||||
(preAst: AST, walker: AstWalker): void;
|
||||
}
|
||||
|
||||
export interface IAstWalker {
|
||||
options: AstWalkOptions;
|
||||
state: any
|
||||
}
|
||||
|
||||
interface AstWalker {
|
||||
walk(ast: AST): void;
|
||||
}
|
||||
|
||||
class SimplePreAstWalker implements AstWalker {
|
||||
public options: AstWalkOptions = new AstWalkOptions();
|
||||
|
||||
constructor(
|
||||
private pre: (ast: AST, state: any) => void,
|
||||
public state: any) {
|
||||
}
|
||||
|
||||
public walk(ast: AST): void {
|
||||
if (!ast) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.pre(ast, this.state);
|
||||
|
||||
var walker = childrenWalkers[ast.kind()];
|
||||
if (walker) {
|
||||
walker(ast, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SimplePrePostAstWalker implements AstWalker {
|
||||
public options: AstWalkOptions = new AstWalkOptions();
|
||||
|
||||
constructor(
|
||||
private pre: (ast: AST, state: any) => void,
|
||||
private post: (ast: AST, state: any) => void,
|
||||
public state: any) {
|
||||
}
|
||||
|
||||
public walk(ast: AST): void {
|
||||
if (!ast) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.pre(ast, this.state);
|
||||
|
||||
var walker = childrenWalkers[ast.kind()];
|
||||
if (walker) {
|
||||
walker(ast, this);
|
||||
}
|
||||
|
||||
this.post(ast, this.state);
|
||||
}
|
||||
}
|
||||
|
||||
class NormalAstWalker implements AstWalker {
|
||||
public options: AstWalkOptions = new AstWalkOptions();
|
||||
|
||||
constructor(
|
||||
private pre: (ast: AST, walker: IAstWalker) => void,
|
||||
private post: (ast: AST, walker: IAstWalker) => void,
|
||||
public state: any) {
|
||||
}
|
||||
|
||||
public walk(ast: AST): void {
|
||||
if (!ast) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If we're stopping, then bail out immediately.
|
||||
if (this.options.stopWalking) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.pre(ast, this);
|
||||
|
||||
// If we were asked to stop, then stop.
|
||||
if (this.options.stopWalking) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.options.goChildren) {
|
||||
// Call the "walkChildren" function corresponding to "nodeType".
|
||||
var walker = childrenWalkers[ast.kind()];
|
||||
if (walker) {
|
||||
walker(ast, this);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// no go only applies to children of node issuing it
|
||||
this.options.goChildren = true;
|
||||
}
|
||||
|
||||
if (this.post) {
|
||||
this.post(ast, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class AstWalkerFactory {
|
||||
public walk(ast: AST, pre: (ast: AST, walker: IAstWalker) => void, post?: (ast: AST, walker: IAstWalker) => void, state?: any): void {
|
||||
new NormalAstWalker(pre, post, state).walk(ast);
|
||||
}
|
||||
|
||||
public simpleWalk(ast: AST, pre: (ast: AST, state: any) => void, post?: (ast: AST, state: any) => void, state?: any): void {
|
||||
if (post) {
|
||||
new SimplePrePostAstWalker(pre, post, state).walk(ast);
|
||||
}
|
||||
else {
|
||||
new SimplePreAstWalker(pre, state).walk(ast);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var globalAstWalkerFactory = new AstWalkerFactory();
|
||||
|
||||
export function getAstWalkerFactory(): AstWalkerFactory {
|
||||
return globalAstWalkerFactory;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
module TypeScript {
|
||||
class Base64Format {
|
||||
static encodedValues = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
||||
static encode(inValue: number) {
|
||||
if (inValue < 64) {
|
||||
return Base64Format.encodedValues.charAt(inValue);
|
||||
}
|
||||
throw TypeError(inValue + ": not a 64 based value");
|
||||
}
|
||||
|
||||
static decodeChar(inChar: string) {
|
||||
if (inChar.length === 1) {
|
||||
return Base64Format.encodedValues.indexOf(inChar);
|
||||
}
|
||||
else {
|
||||
throw TypeError('"' + inChar + '" must have length 1');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class Base64VLQFormat {
|
||||
static encode(inValue: number) {
|
||||
// Add a new least significant bit that has the sign of the value.
|
||||
// if negative number the least significant bit that gets added to the number has value 1
|
||||
// else least significant bit value that gets added is 0
|
||||
// eg. -1 changes to binary : 01 [1] => 3
|
||||
// +1 changes to binary : 01 [0] => 2
|
||||
if (inValue < 0) {
|
||||
inValue = ((-inValue) << 1) + 1;
|
||||
}
|
||||
else {
|
||||
inValue = inValue << 1;
|
||||
}
|
||||
|
||||
// Encode 5 bits at a time starting from least significant bits
|
||||
var encodedStr = "";
|
||||
do {
|
||||
var currentDigit = inValue & 31; // 11111
|
||||
inValue = inValue >> 5;
|
||||
if (inValue > 0) {
|
||||
// There are still more digits to decode, set the msb (6th bit)
|
||||
currentDigit = currentDigit | 32;
|
||||
}
|
||||
encodedStr = encodedStr + Base64Format.encode(currentDigit);
|
||||
} while (inValue > 0);
|
||||
|
||||
return encodedStr;
|
||||
}
|
||||
|
||||
static decode(inString: string) {
|
||||
var result = 0;
|
||||
var negative = false;
|
||||
|
||||
var shift = 0;
|
||||
for (var i = 0; i < inString.length; i++) {
|
||||
var byte = Base64Format.decodeChar(inString[i]);
|
||||
if (i === 0) {
|
||||
// Sign bit appears in the LSBit of the first value
|
||||
if ((byte & 1) === 1) {
|
||||
negative = true;
|
||||
}
|
||||
result = (byte >> 1) & 15; // 1111x
|
||||
}
|
||||
else {
|
||||
result = result | ((byte & 31) << shift); // 11111
|
||||
}
|
||||
|
||||
shift += (i === 0) ? 4 : 5;
|
||||
|
||||
if ((byte & 32) === 32) {
|
||||
// Continue
|
||||
}
|
||||
else {
|
||||
return { value: negative ? -(result) : result, rest: inString.substr(i + 1) };
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error(getDiagnosticMessage(DiagnosticCode.Base64_value_0_finished_with_a_continuation_bit, [inString]));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
///<reference path='core\integerUtilities.ts' />
|
||||
|
||||
module TypeScript {
|
||||
|
||||
export class BloomFilter {
|
||||
private bitArray: boolean[];
|
||||
private hashFunctionCount: number;
|
||||
|
||||
public static falsePositiveProbability: number = 0.0001;
|
||||
|
||||
/*
|
||||
* From the bloom filter calculator here: http://hur.st/bloomfilter?n=4&p=1.0E-20
|
||||
*
|
||||
* 1) n = Number of items in the filter
|
||||
*
|
||||
* 2) p = Probability of false positives, (a double between 0 and 1).
|
||||
*
|
||||
* 3) m = Number of bits in the filter
|
||||
*
|
||||
* 4) k = Number of hash functions
|
||||
*
|
||||
* m = ceil((n * log(p)) / log(1.0 / (pow(2.0, log(2.0)))))
|
||||
*
|
||||
* k = round(log(2.0) * m / n)
|
||||
*
|
||||
*/
|
||||
constructor(expectedCount: number) {
|
||||
var m: number = Math.max(1, BloomFilter.computeM(expectedCount));
|
||||
var k: number = Math.max(1, BloomFilter.computeK(expectedCount));;
|
||||
|
||||
// We must have size in even bytes, so that when we deserialize from bytes we get a bit array with the same count.
|
||||
// The count is used by the hash functions.
|
||||
var sizeInEvenBytes = (m + 7) & ~7;
|
||||
|
||||
this.bitArray = [];
|
||||
for (var i = 0, len = sizeInEvenBytes; i < len; i++) {
|
||||
this.bitArray[i] = false;
|
||||
}
|
||||
this.hashFunctionCount = k;
|
||||
}
|
||||
|
||||
// m = ceil((n * log(p)) / log(1.0 / (pow(2.0, log(2.0)))))
|
||||
static computeM(expectedCount: number): number {
|
||||
var p: number = BloomFilter.falsePositiveProbability;
|
||||
var n: number = expectedCount;
|
||||
|
||||
var numerator = n * Math.log(p);
|
||||
var denominator = Math.log(1.0 / Math.pow(2.0, Math.log(2.0)));
|
||||
return Math.ceil(numerator / denominator);
|
||||
}
|
||||
|
||||
// k = round(log(2.0) * m / n)
|
||||
static computeK(expectedCount: number): number {
|
||||
var n: number = expectedCount;
|
||||
var m: number = BloomFilter.computeM(expectedCount);
|
||||
|
||||
var temp = Math.log(2.0) * m / n;
|
||||
return Math.round(temp);
|
||||
}
|
||||
|
||||
/** Modification of the murmurhash2 algorithm. Code is simpler because it operates over
|
||||
* strings instead of byte arrays. Because each string character is two bytes, it is known
|
||||
* that the input will be an even number of bytes (though not necessarily a multiple of 4).
|
||||
*
|
||||
* This is needed over the normal 'string.GetHashCode()' because we need to be able to generate
|
||||
* 'k' different well distributed hashes for any given string s. Also, we want to be able to
|
||||
* generate these hashes without allocating any memory. My ideal solution would be to use an
|
||||
* MD5 hash. However, there appears to be no way to do MD5 in .Net where you can:
|
||||
*
|
||||
* a) feed it individual values instead of a byte[]
|
||||
*
|
||||
* b) have the hash computed into a byte[] you provide instead of a newly allocated one
|
||||
*
|
||||
* Generating 'k' pieces of garbage on each insert and lookup seems very wasteful. So,
|
||||
* instead, we use murmur hash since it provides well distributed values, allows for a
|
||||
* seed, and allocates no memory.
|
||||
*
|
||||
* Murmur hash is public domain. Actual code is included below as reference.
|
||||
*/
|
||||
private computeHash(key: string, seed: number): number {
|
||||
return Hash.computeMurmur2StringHashCode(key, seed);
|
||||
}
|
||||
|
||||
public addKeys(keys: IIndexable<any>) {
|
||||
for (var name in keys) {
|
||||
if (keys[name]) {
|
||||
this.add(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public add(value: string) {
|
||||
for (var i = 0; i < this.hashFunctionCount; i++) {
|
||||
var hash = this.computeHash(value, i);
|
||||
hash = hash % this.bitArray.length;
|
||||
this.bitArray[Math.abs(hash)] = true;
|
||||
}
|
||||
}
|
||||
|
||||
public probablyContains(value: string): boolean {
|
||||
for (var i = 0; i < this.hashFunctionCount; i++) {
|
||||
var hash = this.computeHash(value, i);
|
||||
hash = hash % this.bitArray.length;
|
||||
if (!this.bitArray[Math.abs(hash)]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public isEquivalent(filter: BloomFilter): boolean {
|
||||
return BloomFilter.isEquivalent(this.bitArray, filter.bitArray)
|
||||
&& this.hashFunctionCount === filter.hashFunctionCount;
|
||||
}
|
||||
|
||||
static isEquivalent(array1: boolean[], array2: boolean[]): boolean {
|
||||
if (array1.length !== array2.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (var i = 0; i < array1.length; i++) {
|
||||
if (array1[i] !== array2[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,253 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export class ArrayUtilities {
|
||||
public static isArray(value: any): boolean {
|
||||
return Object.prototype.toString.apply(value, []) === '[object Array]';
|
||||
}
|
||||
|
||||
public static sequenceEquals<T>(array1: T[], array2: T[], equals: (v1: T, v2: T) => boolean) {
|
||||
if (array1 === array2) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (array1 === null || array2 === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (array1.length !== array2.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (var i = 0, n = array1.length; i < n; i++) {
|
||||
if (!equals(array1[i], array2[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static contains<T>(array: T[], value: T): boolean {
|
||||
for (var i = 0; i < array.length; i++) {
|
||||
if (array[i] === value) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static groupBy<T>(array: T[], func: (v: T) => string): any {
|
||||
var result: IIndexable<T[]> = {};
|
||||
|
||||
for (var i = 0, n = array.length; i < n; i++) {
|
||||
var v: any = array[i];
|
||||
var k = func(v);
|
||||
|
||||
var list: T[] = result[k] || [];
|
||||
list.push(v);
|
||||
result[k] = list;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// Gets unique element array
|
||||
public static distinct<T>(array: T[], equalsFn?: (a: T, b: T) => boolean): T[] {
|
||||
var result: T[] = [];
|
||||
|
||||
// TODO: use map when available
|
||||
for (var i = 0, n = array.length; i < n; i++) {
|
||||
var current = array[i];
|
||||
for (var j = 0; j < result.length; j++) {
|
||||
if (equalsFn(result[j], current)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (j === result.length) {
|
||||
result.push(current);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static min<T>(array: T[], func: (v: T) => number): number {
|
||||
// Debug.assert(array.length > 0);
|
||||
var min = func(array[0]);
|
||||
|
||||
for (var i = 1; i < array.length; i++) {
|
||||
var next = func(array[i]);
|
||||
if (next < min) {
|
||||
min = next;
|
||||
}
|
||||
}
|
||||
|
||||
return min;
|
||||
}
|
||||
|
||||
public static max<T>(array: T[], func: (v: T) => number): number {
|
||||
// Debug.assert(array.length > 0);
|
||||
var max = func(array[0]);
|
||||
|
||||
for (var i = 1; i < array.length; i++) {
|
||||
var next = func(array[i]);
|
||||
if (next > max) {
|
||||
max = next;
|
||||
}
|
||||
}
|
||||
|
||||
return max;
|
||||
}
|
||||
|
||||
public static last<T>(array: T[]): T {
|
||||
if (array.length === 0) {
|
||||
throw Errors.argumentOutOfRange('array');
|
||||
}
|
||||
|
||||
return array[array.length - 1];
|
||||
}
|
||||
|
||||
public static lastOrDefault<T>(array: T[], predicate: (v: T, index: number) => boolean): T {
|
||||
for (var i = array.length - 1; i >= 0; i--) {
|
||||
var v = array[i];
|
||||
if (predicate(v, i)) {
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static firstOrDefault<T>(array: T[], func: (v: T, index: number) => boolean): T {
|
||||
for (var i = 0, n = array.length; i < n; i++) {
|
||||
var value = array[i];
|
||||
if (func(value, i)) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static first<T>(array: T[], func?: (v: T, index: number) => boolean): T {
|
||||
for (var i = 0, n = array.length; i < n; i++) {
|
||||
var value = array[i];
|
||||
if (!func || func(value, i)) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
throw Errors.invalidOperation();
|
||||
}
|
||||
|
||||
public static sum<T>(array: T[], func: (v: T) => number): number {
|
||||
var result = 0;
|
||||
|
||||
for (var i = 0, n = array.length; i < n; i++) {
|
||||
result += func(array[i]);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static select<T,S>(values: T[], func: (v: T) => S): S[] {
|
||||
var result: S[] = new Array<S>(values.length);
|
||||
|
||||
for (var i = 0; i < values.length; i++) {
|
||||
result[i] = func(values[i]);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static where<T>(values: T[], func: (v: T) => boolean): T[] {
|
||||
var result = new Array<T>();
|
||||
|
||||
for (var i = 0; i < values.length; i++) {
|
||||
if (func(values[i])) {
|
||||
result.push(values[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static any<T>(array: T[], func: (v: T) => boolean): boolean {
|
||||
for (var i = 0, n = array.length; i < n; i++) {
|
||||
if (func(array[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static all<T>(array: T[], func: (v: T) => boolean): boolean {
|
||||
for (var i = 0, n = array.length; i < n; i++) {
|
||||
if (!func(array[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static binarySearch(array: number[], value: number): number {
|
||||
var low = 0;
|
||||
var high = array.length - 1;
|
||||
|
||||
while (low <= high) {
|
||||
var middle = low + ((high - low) >> 1);
|
||||
var midValue = array[middle];
|
||||
|
||||
if (midValue === value) {
|
||||
return middle;
|
||||
}
|
||||
else if (midValue > value) {
|
||||
high = middle - 1;
|
||||
}
|
||||
else {
|
||||
low = middle + 1;
|
||||
}
|
||||
}
|
||||
|
||||
return ~low;
|
||||
}
|
||||
|
||||
public static createArray<T>(length: number, defaultValue: any): T[] {
|
||||
var result = new Array<T>(length);
|
||||
for (var i = 0; i < length; i++) {
|
||||
result[i] = defaultValue;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static grow<T>(array: T[], length: number, defaultValue: T): void {
|
||||
var count = length - array.length;
|
||||
for (var i = 0; i < count; i++) {
|
||||
array.push(defaultValue);
|
||||
}
|
||||
}
|
||||
|
||||
public static copy<T>(sourceArray: T[], sourceIndex: number, destinationArray: T[], destinationIndex: number, length: number): void {
|
||||
for (var i = 0; i < length; i++) {
|
||||
destinationArray[destinationIndex + i] = sourceArray[sourceIndex + i];
|
||||
}
|
||||
}
|
||||
|
||||
public static indexOf<T>(array: T[], predicate: (v: T) => boolean): number {
|
||||
for (var i = 0, n = array.length; i < n; i++) {
|
||||
if (predicate(array[i])) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export interface IBitMatrix {
|
||||
// Returns true if the bit at the specified indices is set. False otherwise.
|
||||
valueAt(x: number, y: number): boolean;
|
||||
|
||||
// Sets the value at this specified indices.
|
||||
setValueAt(x: number, y: number, value: boolean): void;
|
||||
|
||||
// Releases the bit matrix, allowing its resources to be used by another matrix.
|
||||
// This instance cannot be used after it is released.
|
||||
release(): void;
|
||||
}
|
||||
|
||||
export module BitMatrix {
|
||||
var pool: BitMatrixImpl[] = [];
|
||||
|
||||
class BitMatrixImpl implements IBitMatrix {
|
||||
public isReleased = false;
|
||||
private vectors: IBitVector[] = [];
|
||||
|
||||
constructor(public allowUndefinedValues: boolean) {
|
||||
}
|
||||
|
||||
public valueAt(x: number, y: number): boolean {
|
||||
Debug.assert(!this.isReleased, "Should not use a released bitvector");
|
||||
var vector = this.vectors[x];
|
||||
if (!vector) {
|
||||
return this.allowUndefinedValues ? undefined : false;
|
||||
}
|
||||
|
||||
return vector.valueAt(y);
|
||||
}
|
||||
|
||||
public setValueAt(x: number, y: number, value: boolean): void {
|
||||
Debug.assert(!this.isReleased, "Should not use a released bitvector");
|
||||
var vector = this.vectors[x];
|
||||
if (!vector) {
|
||||
if (value === undefined) {
|
||||
// If they're storing an undefined value, and we don't even have a vector,
|
||||
// then we can short circuit early here.
|
||||
return;
|
||||
}
|
||||
|
||||
vector = BitVector.getBitVector(this.allowUndefinedValues);
|
||||
this.vectors[x] = vector;
|
||||
}
|
||||
|
||||
vector.setValueAt(y, value);
|
||||
}
|
||||
|
||||
public release() {
|
||||
Debug.assert(!this.isReleased, "Should not use a released bitvector");
|
||||
this.isReleased = true;
|
||||
|
||||
// Release all the vectors back.
|
||||
for (var name in this.vectors) {
|
||||
if (this.vectors.hasOwnProperty(name)) {
|
||||
var vector = this.vectors[name];
|
||||
vector.release();
|
||||
}
|
||||
}
|
||||
|
||||
this.vectors.length = 0;
|
||||
pool.push(this);
|
||||
}
|
||||
}
|
||||
|
||||
export function getBitMatrix(allowUndefinedValues: boolean): IBitMatrix {
|
||||
if (pool.length === 0) {
|
||||
return new BitMatrixImpl(allowUndefinedValues);
|
||||
}
|
||||
|
||||
var matrix = pool.pop();
|
||||
matrix.isReleased = false;
|
||||
matrix.allowUndefinedValues = allowUndefinedValues;
|
||||
|
||||
return matrix;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
///<reference path='references.ts'/>
|
||||
|
||||
module TypeScript {
|
||||
export interface IBitVector {
|
||||
// Returns the value at the specified index. If this is a bi-state vector, then the result
|
||||
// will only be 'true' or 'false'. If this is a tri-state vector, then the result can be
|
||||
// 'true', 'false', or 'undefined'.
|
||||
valueAt(index: number): boolean;
|
||||
|
||||
// Sets the value at this specified bit. For a bi-state vector the value must be 'true' or
|
||||
// 'false'. For a tri-state vector, it can be 'true', 'false', or 'undefined'.
|
||||
setValueAt(index: number, value: boolean): void;
|
||||
|
||||
// Releases the bit vector, allowing its resources to be used by another BitVector.
|
||||
// This instance cannot be used after it is released.
|
||||
release(): void;
|
||||
}
|
||||
|
||||
export module BitVector {
|
||||
var pool: BitVectorImpl[] = [];
|
||||
enum Constants {
|
||||
// We only use up to 30 bits in a number. That way the encoded value can always fit
|
||||
// within an int so that the underlying engine doesn't use a 64bit float here.
|
||||
MaxBitsPerEncodedNumber = 30,
|
||||
BitsPerEncodedBiStateValue = 1,
|
||||
|
||||
// For a tri state vector we need 2 bits per encoded value. 00 for 'undefined',
|
||||
// '01' for 'false' and '10' for true.
|
||||
BitsPerEncodedTriStateValue = 2,
|
||||
|
||||
BiStateEncodedTrue = 1, // 1
|
||||
BiStateClearBitsMask = 1, // 1
|
||||
|
||||
TriStateEncodedFalse = 1, // 01
|
||||
TriStateEncodedTrue = 2, // 10
|
||||
TriStateClearBitsMask = 3, // 11
|
||||
}
|
||||
|
||||
class BitVectorImpl implements IBitVector {
|
||||
public isReleased = false;
|
||||
private bits: number[] = [];
|
||||
|
||||
constructor(public allowUndefinedValues: boolean) {
|
||||
}
|
||||
|
||||
private computeTriStateArrayIndex(index: number): number {
|
||||
// The number of values that can be encoded in a single number.
|
||||
var encodedValuesPerNumber = Constants.MaxBitsPerEncodedNumber / Constants.BitsPerEncodedTriStateValue;
|
||||
|
||||
return (index / encodedValuesPerNumber) >>> 0;
|
||||
}
|
||||
|
||||
private computeBiStateArrayIndex(index: number): number {
|
||||
// The number of values that can be encoded in a single number.
|
||||
var encodedValuesPerNumber = Constants.MaxBitsPerEncodedNumber / Constants.BitsPerEncodedBiStateValue;
|
||||
|
||||
return (index / encodedValuesPerNumber) >>> 0;
|
||||
}
|
||||
|
||||
private computeTriStateEncodedValueIndex(index: number): number {
|
||||
// The number of values that can be encoded in a single number.
|
||||
var encodedValuesPerNumber = Constants.MaxBitsPerEncodedNumber / Constants.BitsPerEncodedTriStateValue;
|
||||
|
||||
return (index % encodedValuesPerNumber) * Constants.BitsPerEncodedTriStateValue;
|
||||
}
|
||||
|
||||
private computeBiStateEncodedValueIndex(index: number): number {
|
||||
// The number of values that can be encoded in a single number.
|
||||
var encodedValuesPerNumber = Constants.MaxBitsPerEncodedNumber / Constants.BitsPerEncodedBiStateValue;
|
||||
|
||||
return (index % encodedValuesPerNumber) * Constants.BitsPerEncodedBiStateValue;
|
||||
}
|
||||
|
||||
public valueAt(index: number): boolean {
|
||||
Debug.assert(!this.isReleased, "Should not use a released bitvector");
|
||||
if (this.allowUndefinedValues) {
|
||||
// tri-state bit vector. 2 bits per value.
|
||||
|
||||
var arrayIndex = this.computeTriStateArrayIndex(index);
|
||||
var encoded = this.bits[arrayIndex];
|
||||
if (encoded === undefined) {
|
||||
// We don't even have an encoded value at this array position. That's
|
||||
// equivalent to 'undefined' for a tri-state vector.
|
||||
return undefined;
|
||||
}
|
||||
|
||||
var bitIndex = this.computeTriStateEncodedValueIndex(index);
|
||||
if (encoded & (Constants.TriStateEncodedTrue << bitIndex)) {
|
||||
return true;
|
||||
}
|
||||
else if (encoded & (Constants.TriStateEncodedFalse << bitIndex)) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Normal bitvector. One bit per value stored.
|
||||
|
||||
var arrayIndex = this.computeBiStateArrayIndex(index);
|
||||
var encoded = this.bits[arrayIndex];
|
||||
if (encoded === undefined) {
|
||||
// We don't even have an encoded value at this array position. That's
|
||||
// equivalent to 'false' for a bi-state vector.
|
||||
return false;
|
||||
}
|
||||
|
||||
// If we don't support undefined values, then we use one bit per value. Just
|
||||
// index to that bit and see if it's set or not.
|
||||
var bitIndex = this.computeBiStateEncodedValueIndex(index);
|
||||
if (encoded & (Constants.BiStateEncodedTrue << bitIndex)) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public setValueAt(index: number, value: boolean): void {
|
||||
Debug.assert(!this.isReleased, "Should not use a released bitvector");
|
||||
if (this.allowUndefinedValues) {
|
||||
Debug.assert(value === true || value === false || value === undefined, "value must only be true, false or undefined.");
|
||||
|
||||
var arrayIndex = this.computeTriStateArrayIndex(index);
|
||||
var encoded = this.bits[arrayIndex];
|
||||
if (encoded === undefined) {
|
||||
if (value === undefined) {
|
||||
// They're trying to set a bit to undefined that we don't even have an entry
|
||||
// for. We can bail out quickly here.
|
||||
return;
|
||||
}
|
||||
|
||||
encoded = 0;
|
||||
}
|
||||
|
||||
// First, we clear out any bits set at the appropriate index.
|
||||
var bitIndex = this.computeTriStateEncodedValueIndex(index);
|
||||
|
||||
// Create a mask similar to: 11111111100111111
|
||||
// i.e. all 1's except for 2 zeroes in the appropriate place.
|
||||
var clearMask = ~(Constants.TriStateClearBitsMask << bitIndex)
|
||||
encoded = encoded & clearMask;
|
||||
|
||||
if (value === true) {
|
||||
encoded = encoded | (Constants.TriStateEncodedTrue << bitIndex);
|
||||
}
|
||||
else if (value === false) {
|
||||
encoded = encoded | (Constants.TriStateEncodedFalse << bitIndex);
|
||||
}
|
||||
// else {
|
||||
// They're setting the value to 'undefined'. We already cleared the value
|
||||
// so there's nothing we need to do here.
|
||||
// }
|
||||
|
||||
this.bits[arrayIndex] = encoded;
|
||||
}
|
||||
else {
|
||||
Debug.assert(value === true || value === false, "value must only be true or false.");
|
||||
|
||||
var arrayIndex = this.computeBiStateArrayIndex(index);
|
||||
var encoded = this.bits[arrayIndex];
|
||||
if (encoded === undefined) {
|
||||
if (value === false) {
|
||||
// They're trying to set a bit to false that we don't even have an entry
|
||||
// for. We can bail out quickly here.
|
||||
return;
|
||||
}
|
||||
|
||||
encoded = 0;
|
||||
}
|
||||
|
||||
var bitIndex = this.computeBiStateEncodedValueIndex(index);
|
||||
// First, clear out the bit at this location.
|
||||
encoded = encoded & ~(Constants.BiStateClearBitsMask << bitIndex);
|
||||
|
||||
if (value) {
|
||||
encoded = encoded | (Constants.BiStateEncodedTrue << bitIndex);
|
||||
}
|
||||
// else {
|
||||
// They're setting the value to 'false'. We already cleared the value
|
||||
// so there's nothing we need to do here.
|
||||
// }
|
||||
|
||||
this.bits[arrayIndex] = encoded;
|
||||
}
|
||||
}
|
||||
|
||||
public release() {
|
||||
Debug.assert(!this.isReleased, "Should not use a released bitvector");
|
||||
this.isReleased = true;
|
||||
this.bits.length = 0;
|
||||
pool.push(this);
|
||||
}
|
||||
}
|
||||
|
||||
export function getBitVector(allowUndefinedValues: boolean): IBitVector {
|
||||
if (pool.length === 0) {
|
||||
return new BitVectorImpl(allowUndefinedValues);
|
||||
}
|
||||
|
||||
var vector = pool.pop();
|
||||
vector.isReleased = false;
|
||||
vector.allowUndefinedValues = allowUndefinedValues;
|
||||
|
||||
return vector;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
interface ICancellationToken {
|
||||
isCancellationRequested(): boolean;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
///<reference path='ICancellationToken.ts' />
|
||||
|
||||
interface ICancellationTokenSource {
|
||||
token(): ICancellationToken;
|
||||
|
||||
cancel(): void;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export enum Constants {
|
||||
// 2^30-1
|
||||
Max31BitInteger = 1073741823,
|
||||
Min31BitInteger = -1073741824,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export enum AssertionLevel {
|
||||
None = 0,
|
||||
Normal = 1,
|
||||
Aggressive = 2,
|
||||
VeryAggressive = 3,
|
||||
}
|
||||
|
||||
export class Debug {
|
||||
private static currentAssertionLevel = AssertionLevel.None;
|
||||
public static shouldAssert(level: AssertionLevel): boolean {
|
||||
return this.currentAssertionLevel >= level;
|
||||
}
|
||||
|
||||
public static assert(expression: any, message: string = "", verboseDebugInfo: () => string = null): void {
|
||||
if (!expression) {
|
||||
var verboseDebugString = "";
|
||||
if (verboseDebugInfo) {
|
||||
verboseDebugString = "\r\nVerbose Debug Information:" + verboseDebugInfo();
|
||||
}
|
||||
|
||||
throw new Error("Debug Failure. False expression: " + message + verboseDebugString);
|
||||
}
|
||||
}
|
||||
|
||||
public static fail(message?: string): void {
|
||||
Debug.assert(false, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export enum DiagnosticCategory {
|
||||
Warning,
|
||||
Error,
|
||||
Message,
|
||||
NoPrefix,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export var LocalizedDiagnosticMessages: IIndexable<any> = null;
|
||||
|
||||
export class Location {
|
||||
private _fileName: string;
|
||||
private _lineMap: LineMap;
|
||||
private _start: number;
|
||||
private _length: number;
|
||||
|
||||
constructor(fileName: string, lineMap: LineMap, start: number, length: number) {
|
||||
this._fileName = fileName;
|
||||
this._lineMap = lineMap;
|
||||
this._start = start;
|
||||
this._length = length;
|
||||
}
|
||||
|
||||
public fileName(): string {
|
||||
return this._fileName;
|
||||
}
|
||||
|
||||
public lineMap(): LineMap {
|
||||
return this._lineMap;
|
||||
}
|
||||
|
||||
public line(): number {
|
||||
return this._lineMap ? this._lineMap.getLineNumberFromPosition(this.start()) : 0;
|
||||
}
|
||||
|
||||
public character(): number {
|
||||
return this._lineMap ? this._lineMap.getLineAndCharacterFromPosition(this.start()).character() : 0;
|
||||
}
|
||||
|
||||
public start(): number {
|
||||
return this._start;
|
||||
}
|
||||
|
||||
public length(): number {
|
||||
return this._length;
|
||||
}
|
||||
|
||||
public static equals(location1: Location, location2: Location): boolean {
|
||||
return location1._fileName === location2._fileName &&
|
||||
location1._start === location2._start &&
|
||||
location1._length === location2._length;
|
||||
}
|
||||
}
|
||||
|
||||
export class Diagnostic extends Location {
|
||||
private _diagnosticKey: string;
|
||||
private _arguments: any[];
|
||||
private _additionalLocations: Location[];
|
||||
|
||||
constructor(fileName: string, lineMap: LineMap, start: number, length: number, diagnosticKey: string, _arguments: any[]= null, additionalLocations: Location[] = null) {
|
||||
super(fileName, lineMap, start, length);
|
||||
this._diagnosticKey = diagnosticKey;
|
||||
this._arguments = (_arguments && _arguments.length > 0) ? _arguments : null;
|
||||
this._additionalLocations = (additionalLocations && additionalLocations.length > 0) ? additionalLocations : null;
|
||||
}
|
||||
|
||||
public toJSON(key: any): any {
|
||||
var result: any = {};
|
||||
result.start = this.start();
|
||||
result.length = this.length();
|
||||
|
||||
result.diagnosticCode = this._diagnosticKey;
|
||||
|
||||
var _arguments: any[] = (<any>this).arguments();
|
||||
if (_arguments && _arguments.length > 0) {
|
||||
result.arguments = _arguments;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public diagnosticKey(): string {
|
||||
return this._diagnosticKey;
|
||||
}
|
||||
|
||||
public arguments(): any[] {
|
||||
return this._arguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the text of the message in the given language.
|
||||
*/
|
||||
public text(): string {
|
||||
return TypeScript.getLocalizedText(this._diagnosticKey, this._arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the text of the message including the error code in the given language.
|
||||
*/
|
||||
public message(): string {
|
||||
return TypeScript.getDiagnosticMessage(this._diagnosticKey, this._arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* If a derived class has additional information about other referenced symbols, it can
|
||||
* expose the locations of those symbols in a general way, so they can be reported along
|
||||
* with the error.
|
||||
*/
|
||||
public additionalLocations(): Location[] {
|
||||
return this._additionalLocations || [];
|
||||
}
|
||||
|
||||
public static equals(diagnostic1: Diagnostic, diagnostic2: Diagnostic): boolean {
|
||||
return Location.equals(diagnostic1, diagnostic2) &&
|
||||
diagnostic1._diagnosticKey === diagnostic2._diagnosticKey &&
|
||||
ArrayUtilities.sequenceEquals(diagnostic1._arguments, diagnostic2._arguments, (v1, v2) => v1 === v2);
|
||||
}
|
||||
|
||||
public info(): DiagnosticInfo {
|
||||
return getDiagnosticInfoFromKey(this.diagnosticKey());
|
||||
}
|
||||
}
|
||||
|
||||
export function newLine(): string {
|
||||
// TODO: We need to expose an extensibility point on our hosts to have them tell us what
|
||||
// they want the newline string to be. That way we can get the correct result regardless
|
||||
// of which host we use
|
||||
return Environment ? Environment.newLine : "\r\n";
|
||||
}
|
||||
|
||||
function getLargestIndex(diagnostic: string): number {
|
||||
var largest = -1;
|
||||
var regex = /\{(\d+)\}/g;
|
||||
|
||||
var match: RegExpExecArray;
|
||||
while (match = regex.exec(diagnostic)) {
|
||||
var val = parseInt(match[1]);
|
||||
if (!isNaN(val) && val > largest) {
|
||||
largest = val;
|
||||
}
|
||||
}
|
||||
|
||||
return largest;
|
||||
}
|
||||
|
||||
function getDiagnosticInfoFromKey(diagnosticKey: string): DiagnosticInfo {
|
||||
var result: DiagnosticInfo = diagnosticInformationMap[diagnosticKey];
|
||||
Debug.assert(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
export function getLocalizedText(diagnosticKey: string, args: any[]): string {
|
||||
if (LocalizedDiagnosticMessages) {
|
||||
//Debug.assert(LocalizedDiagnosticMessages.hasOwnProperty(diagnosticKey));
|
||||
}
|
||||
|
||||
var diagnosticMessageText: string = LocalizedDiagnosticMessages ? LocalizedDiagnosticMessages[diagnosticKey] : diagnosticKey;
|
||||
Debug.assert(diagnosticMessageText !== undefined && diagnosticMessageText !== null);
|
||||
|
||||
var actualCount = args ? args.length : 0;
|
||||
// We have a string like "foo_0_bar_1". We want to find the largest integer there.
|
||||
// (i.e.'1'). We then need one more arg than that to be correct.
|
||||
var expectedCount = 1 + getLargestIndex(diagnosticKey);
|
||||
|
||||
if (expectedCount !== actualCount) {
|
||||
throw new Error(getLocalizedText(DiagnosticCode.Expected_0_arguments_to_message_got_1_instead, [expectedCount, actualCount]));
|
||||
}
|
||||
|
||||
// This should also be the same number of arguments as the message text
|
||||
var valueCount = 1 + getLargestIndex(diagnosticMessageText);
|
||||
if (valueCount !== expectedCount) {
|
||||
throw new Error(getLocalizedText(DiagnosticCode.Expected_the_message_0_to_have_1_arguments_but_it_had_2, [diagnosticMessageText, expectedCount, valueCount]));
|
||||
}
|
||||
|
||||
diagnosticMessageText = diagnosticMessageText.replace(/{(\d+)}/g, function (match, num?) {
|
||||
return typeof args[num] !== 'undefined'
|
||||
? args[num]
|
||||
: match;
|
||||
});
|
||||
|
||||
diagnosticMessageText = diagnosticMessageText.replace(/{(NL)}/g, function (match) {
|
||||
return TypeScript.newLine();
|
||||
});
|
||||
|
||||
return diagnosticMessageText;
|
||||
}
|
||||
|
||||
export function getDiagnosticMessage(diagnosticKey: string, args: any[]): string {
|
||||
var diagnostic = getDiagnosticInfoFromKey(diagnosticKey);
|
||||
var diagnosticMessageText = getLocalizedText(diagnosticKey, args);
|
||||
|
||||
var message: string;
|
||||
if (diagnostic.category === DiagnosticCategory.Error) {
|
||||
message = getLocalizedText(DiagnosticCode.error_TS_0_1, [diagnostic.code, diagnosticMessageText]);
|
||||
}
|
||||
else if (diagnostic.category === DiagnosticCategory.Warning) {
|
||||
message = getLocalizedText(DiagnosticCode.warning_TS_0_1, [diagnostic.code, diagnosticMessageText]);
|
||||
}
|
||||
else {
|
||||
message = diagnosticMessageText;
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export interface DiagnosticInfo {
|
||||
category: DiagnosticCategory;
|
||||
message: string;
|
||||
code: number;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,390 @@
|
||||
///<reference path='references.ts' />
|
||||
///<reference path='..\enumerator.ts' />
|
||||
///<reference path='..\process.ts' />
|
||||
|
||||
declare var Buffer: {
|
||||
new (str: string, encoding?: string): any;
|
||||
}
|
||||
|
||||
module TypeScript {
|
||||
export var nodeMakeDirectoryTime = 0;
|
||||
export var nodeCreateBufferTime = 0;
|
||||
export var nodeWriteFileSyncTime = 0;
|
||||
|
||||
export enum ByteOrderMark {
|
||||
None = 0,
|
||||
Utf8 = 1,
|
||||
Utf16BigEndian = 2,
|
||||
Utf16LittleEndian = 3,
|
||||
}
|
||||
|
||||
export class FileInformation {
|
||||
constructor(public contents: string, public byteOrderMark: ByteOrderMark) {
|
||||
}
|
||||
}
|
||||
|
||||
export interface IEnvironment {
|
||||
supportsCodePage(): boolean;
|
||||
readFile(path: string, codepage: number): FileInformation;
|
||||
writeFile(path: string, contents: string, writeByteOrderMark: boolean): void;
|
||||
deleteFile(path: string): void;
|
||||
fileExists(path: string): boolean;
|
||||
directoryExists(path: string): boolean;
|
||||
listFiles(path: string, re?: RegExp, options?: { recursive?: boolean; }): string[];
|
||||
|
||||
arguments: string[];
|
||||
standardOut: ITextWriter;
|
||||
|
||||
currentDirectory(): string;
|
||||
newLine: string;
|
||||
}
|
||||
|
||||
export var Environment = (function () {
|
||||
// Create an IO object for use inside WindowsScriptHost hosts
|
||||
// Depends on WSCript and FileSystemObject
|
||||
function getWindowsScriptHostEnvironment(): IEnvironment {
|
||||
try {
|
||||
var fso = new ActiveXObject("Scripting.FileSystemObject");
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var streamObjectPool: any[] = [];
|
||||
|
||||
function getStreamObject(): any {
|
||||
if (streamObjectPool.length > 0) {
|
||||
return streamObjectPool.pop();
|
||||
}
|
||||
else {
|
||||
return new ActiveXObject("ADODB.Stream");
|
||||
}
|
||||
}
|
||||
|
||||
function releaseStreamObject(obj: any) {
|
||||
streamObjectPool.push(obj);
|
||||
}
|
||||
|
||||
var args: string[] = [];
|
||||
for (var i = 0; i < WScript.Arguments.length; i++) {
|
||||
args[i] = WScript.Arguments.Item(i);
|
||||
}
|
||||
|
||||
return {
|
||||
// On windows, the newline sequence is always "\r\n";
|
||||
newLine: "\r\n",
|
||||
|
||||
currentDirectory: (): string => {
|
||||
return (<any>WScript).CreateObject("WScript.Shell").CurrentDirectory;
|
||||
},
|
||||
|
||||
supportsCodePage: () => {
|
||||
return (<any>WScript).ReadFile;
|
||||
},
|
||||
|
||||
readFile: function (path: string, codepage: number): FileInformation {
|
||||
try {
|
||||
// If a codepage is requested, defer to our host to do the reading. If it
|
||||
// fails, fall back to our normal BOM/utf8 logic.
|
||||
if (codepage !== null && this.supportsCodePage()) {
|
||||
try {
|
||||
var contents = (<any>WScript).ReadFile(path, codepage);
|
||||
return new FileInformation(contents, ByteOrderMark.None);
|
||||
}
|
||||
catch (e) {
|
||||
// We couldn't read it with that code page. Fall back to the normal
|
||||
// BOM/utf8 logic below.
|
||||
}
|
||||
}
|
||||
|
||||
// Initially just read the first two bytes of the file to see if there's a bom.
|
||||
var streamObj = getStreamObject();
|
||||
streamObj.Open();
|
||||
streamObj.Type = 2; // Text data
|
||||
|
||||
// Start reading individual chars without any interpretation. That way we can check for a bom.
|
||||
streamObj.Charset = 'x-ansi';
|
||||
|
||||
streamObj.LoadFromFile(path);
|
||||
var bomChar = streamObj.ReadText(2); // Read the BOM char
|
||||
|
||||
// Position has to be at 0 before changing the encoding
|
||||
streamObj.Position = 0;
|
||||
|
||||
var byteOrderMark = ByteOrderMark.None;
|
||||
|
||||
if (bomChar.charCodeAt(0) === 0xFE && bomChar.charCodeAt(1) === 0xFF) {
|
||||
streamObj.Charset = 'unicode';
|
||||
byteOrderMark = ByteOrderMark.Utf16BigEndian;
|
||||
}
|
||||
else if (bomChar.charCodeAt(0) === 0xFF && bomChar.charCodeAt(1) === 0xFE) {
|
||||
streamObj.Charset = 'unicode';
|
||||
byteOrderMark = ByteOrderMark.Utf16LittleEndian;
|
||||
}
|
||||
else if (bomChar.charCodeAt(0) === 0xEF && bomChar.charCodeAt(1) === 0xBB) {
|
||||
streamObj.Charset = 'utf-8';
|
||||
byteOrderMark = ByteOrderMark.Utf8;
|
||||
}
|
||||
else {
|
||||
// Always read a file as utf8 if it has no bom.
|
||||
streamObj.Charset = 'utf-8';
|
||||
}
|
||||
|
||||
// Read the whole file
|
||||
var contents = streamObj.ReadText(-1 /* read from the current position to EOS */);
|
||||
streamObj.Close();
|
||||
releaseStreamObject(streamObj);
|
||||
return new FileInformation(contents, byteOrderMark);
|
||||
}
|
||||
catch (err) {
|
||||
// -2147024809 is the javascript value for 0x80070057 which is the HRESULT for
|
||||
// "the parameter is incorrect".
|
||||
var message: string;
|
||||
if (err.number === -2147024809) {
|
||||
message = TypeScript.getDiagnosticMessage(TypeScript.DiagnosticCode.Unsupported_file_encoding, null);
|
||||
}
|
||||
else {
|
||||
message = TypeScript.getDiagnosticMessage(TypeScript.DiagnosticCode.Cannot_read_file_0_1, [path, err.message]);
|
||||
}
|
||||
|
||||
throw new Error(message);
|
||||
}
|
||||
},
|
||||
|
||||
writeFile: function (path: string, contents: string, writeByteOrderMark: boolean) {
|
||||
// First, convert the text contents passed in to binary in UTF8 format.
|
||||
var textStream = getStreamObject();
|
||||
textStream.Charset = 'utf-8';
|
||||
textStream.Open();
|
||||
textStream.WriteText(contents, 0 /*do not add newline*/);
|
||||
|
||||
// If they don't want the BOM, then skip it (it will be added automatically
|
||||
// when we write the utf8 bytes out above).
|
||||
if (!writeByteOrderMark) {
|
||||
textStream.Position = 3;
|
||||
}
|
||||
else {
|
||||
textStream.Position = 0;
|
||||
}
|
||||
|
||||
// Now, write all those bytes out to a file.
|
||||
var fileStream = getStreamObject();
|
||||
fileStream.Type = 1; //binary data.
|
||||
fileStream.Open();
|
||||
|
||||
textStream.CopyTo(fileStream);
|
||||
|
||||
// Flush and save the file.
|
||||
fileStream.Flush();
|
||||
fileStream.SaveToFile(path, 2 /*overwrite*/);
|
||||
fileStream.Close();
|
||||
|
||||
textStream.Flush();
|
||||
textStream.Close();
|
||||
},
|
||||
|
||||
fileExists: function (path: string): boolean {
|
||||
return fso.FileExists(path);
|
||||
},
|
||||
|
||||
deleteFile: function (path: string): void {
|
||||
if (fso.FileExists(path)) {
|
||||
fso.DeleteFile(path, true); // true: delete read-only files
|
||||
}
|
||||
},
|
||||
|
||||
directoryExists: function (path) {
|
||||
return <boolean>fso.FolderExists(path);
|
||||
},
|
||||
|
||||
listFiles: function (path, spec?, options?) {
|
||||
options = options || <{ recursive?: boolean; }>{};
|
||||
function filesInFolder(folder: any, root: string): string[] {
|
||||
var paths: string[] = [];
|
||||
var fc: Enumerator;
|
||||
|
||||
if (options.recursive) {
|
||||
fc = new Enumerator(folder.subfolders);
|
||||
|
||||
for (; !fc.atEnd(); fc.moveNext()) {
|
||||
paths = paths.concat(filesInFolder(fc.item(), root + "\\" + fc.item().Name));
|
||||
}
|
||||
}
|
||||
|
||||
fc = new Enumerator(folder.files);
|
||||
|
||||
for (; !fc.atEnd(); fc.moveNext()) {
|
||||
if (!spec || fc.item().Name.match(spec)) {
|
||||
paths.push(root + "\\" + fc.item().Name);
|
||||
}
|
||||
}
|
||||
|
||||
return paths;
|
||||
}
|
||||
|
||||
var folder: any = fso.GetFolder(path);
|
||||
var paths: string[] = [];
|
||||
|
||||
return filesInFolder(folder, path);
|
||||
},
|
||||
|
||||
arguments: <string[]>args,
|
||||
|
||||
standardOut: WScript.StdOut,
|
||||
};
|
||||
};
|
||||
|
||||
function getNodeEnvironment(): IEnvironment {
|
||||
var _fs = require('fs');
|
||||
var _path = require('path');
|
||||
var _module = require('module');
|
||||
var _os = require('os');
|
||||
|
||||
return {
|
||||
// On node pick up the newline character from the OS
|
||||
newLine: _os.EOL,
|
||||
|
||||
currentDirectory: (): string => {
|
||||
return (<any>process).cwd();
|
||||
},
|
||||
|
||||
supportsCodePage: () => false,
|
||||
|
||||
readFile: function (file: string, codepage: number): FileInformation {
|
||||
if (codepage !== null) {
|
||||
throw new Error(TypeScript.getDiagnosticMessage(TypeScript.DiagnosticCode.codepage_option_not_supported_on_current_platform, null));
|
||||
}
|
||||
|
||||
var buffer = _fs.readFileSync(file);
|
||||
switch (buffer[0]) {
|
||||
case 0xFE:
|
||||
if (buffer[1] === 0xFF) {
|
||||
// utf16-be. Reading the buffer as big endian is not supported, so convert it to
|
||||
// Little Endian first
|
||||
var i = 0;
|
||||
while ((i + 1) < buffer.length) {
|
||||
var temp = buffer[i];
|
||||
buffer[i] = buffer[i + 1];
|
||||
buffer[i + 1] = temp;
|
||||
i += 2;
|
||||
}
|
||||
return new FileInformation(buffer.toString("ucs2", 2), ByteOrderMark.Utf16BigEndian);
|
||||
}
|
||||
break;
|
||||
case 0xFF:
|
||||
if (buffer[1] === 0xFE) {
|
||||
// utf16-le
|
||||
return new FileInformation(buffer.toString("ucs2", 2), ByteOrderMark.Utf16LittleEndian);
|
||||
}
|
||||
break;
|
||||
case 0xEF:
|
||||
if (buffer[1] === 0xBB) {
|
||||
// utf-8
|
||||
return new FileInformation(buffer.toString("utf8", 3), ByteOrderMark.Utf8);
|
||||
}
|
||||
}
|
||||
|
||||
// Default behaviour
|
||||
return new FileInformation(buffer.toString("utf8", 0), ByteOrderMark.None);
|
||||
},
|
||||
|
||||
writeFile: function (path: string, contents: string, writeByteOrderMark: boolean) {
|
||||
function mkdirRecursiveSync(path: string) {
|
||||
var stats = _fs.statSync(path);
|
||||
if (stats.isFile()) {
|
||||
throw "\"" + path + "\" exists but isn't a directory.";
|
||||
}
|
||||
else if (stats.isDirectory()) {
|
||||
return;
|
||||
}
|
||||
else {
|
||||
mkdirRecursiveSync(_path.dirname(path));
|
||||
_fs.mkdirSync(path, 509 /*775 in octal*/);
|
||||
}
|
||||
}
|
||||
var start = new Date().getTime();
|
||||
mkdirRecursiveSync(_path.dirname(path));
|
||||
TypeScript.nodeMakeDirectoryTime += new Date().getTime() - start;
|
||||
|
||||
if (writeByteOrderMark) {
|
||||
contents = '\uFEFF' + contents;
|
||||
}
|
||||
|
||||
var start = new Date().getTime();
|
||||
|
||||
var chunkLength = 4 * 1024;
|
||||
var fileDescriptor = _fs.openSync(path, "w");
|
||||
try {
|
||||
for (var index = 0; index < contents.length; index += chunkLength) {
|
||||
var bufferStart = new Date().getTime();
|
||||
var buffer = new Buffer(contents.substr(index, chunkLength), "utf8");
|
||||
TypeScript.nodeCreateBufferTime += new Date().getTime() - bufferStart;
|
||||
|
||||
_fs.writeSync(fileDescriptor, buffer, 0, buffer.length, null);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
_fs.closeSync(fileDescriptor);
|
||||
}
|
||||
|
||||
TypeScript.nodeWriteFileSyncTime += new Date().getTime() - start;
|
||||
},
|
||||
|
||||
fileExists: function (path: string): boolean {
|
||||
return _fs.existsSync(path);
|
||||
},
|
||||
|
||||
deleteFile: function (path) {
|
||||
try {
|
||||
_fs.unlinkSync(path);
|
||||
} catch (e) {
|
||||
}
|
||||
},
|
||||
|
||||
directoryExists: function (path: string): boolean {
|
||||
return _fs.existsSync(path) && _fs.statSync(path).isDirectory();
|
||||
},
|
||||
|
||||
listFiles: function dir(path, spec?, options?) {
|
||||
options = options || <{ recursive?: boolean; }>{};
|
||||
|
||||
function filesInFolder(folder: string): string[] {
|
||||
var paths: string[] = [];
|
||||
|
||||
var files = _fs.readdirSync(folder);
|
||||
for (var i = 0; i < files.length; i++) {
|
||||
var stat = _fs.statSync(folder + "\\" + files[i]);
|
||||
if (options.recursive && stat.isDirectory()) {
|
||||
paths = paths.concat(filesInFolder(folder + "\\" + files[i]));
|
||||
}
|
||||
else if (stat.isFile() && (!spec || files[i].match(spec))) {
|
||||
paths.push(folder + "\\" + files[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return paths;
|
||||
}
|
||||
|
||||
return filesInFolder(path);
|
||||
},
|
||||
|
||||
arguments: process.argv.slice(2),
|
||||
|
||||
standardOut: {
|
||||
Write: function (str) { process.stdout.write(str); },
|
||||
WriteLine: function (str) { process.stdout.write(str + '\n'); },
|
||||
Close: function () { }
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
if (typeof WScript !== "undefined" && typeof ActiveXObject === "function") {
|
||||
return getWindowsScriptHostEnvironment();
|
||||
}
|
||||
else if (typeof module !== 'undefined' && module.exports) {
|
||||
return getNodeEnvironment();
|
||||
}
|
||||
else {
|
||||
return null; // Unsupported host
|
||||
}
|
||||
})();
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export class Errors {
|
||||
public static argument(argument: string, message?: string): Error {
|
||||
return new Error("Invalid argument: " + argument + ". " + message);
|
||||
}
|
||||
|
||||
public static argumentOutOfRange(argument: string): Error {
|
||||
return new Error("Argument out of range: " + argument);
|
||||
}
|
||||
|
||||
public static argumentNull(argument: string): Error {
|
||||
return new Error("Argument null: " + argument);
|
||||
}
|
||||
|
||||
public static abstract(): Error {
|
||||
return new Error("Operation not implemented properly by subclass.");
|
||||
}
|
||||
|
||||
public static notYetImplemented(): Error {
|
||||
return new Error("Not yet implemented.");
|
||||
}
|
||||
|
||||
public static invalidOperation(message?: string): Error {
|
||||
return new Error("Invalid operation: " + message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export class Hash {
|
||||
// This table uses FNV1a as a string hash
|
||||
private static FNV_BASE = 2166136261;
|
||||
private static FNV_PRIME = 16777619;
|
||||
|
||||
private static computeFnv1aCharArrayHashCode(text: number[], start: number, len: number): number {
|
||||
var hashCode = Hash.FNV_BASE;
|
||||
var end = start + len;
|
||||
|
||||
for (var i = start; i < end; i++) {
|
||||
hashCode = IntegerUtilities.integerMultiplyLow32Bits(hashCode ^ text[i], Hash.FNV_PRIME);
|
||||
}
|
||||
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
public static computeSimple31BitCharArrayHashCode(key: number[], start: number, len: number): number {
|
||||
// Start with an int.
|
||||
var hash = 0;
|
||||
|
||||
for (var i = 0; i < len; i++) {
|
||||
var ch = key[start + i];
|
||||
|
||||
// Left shift keeps things as a 32bit int. And we're only doing two adds. Chakra and
|
||||
// V8 recognize this as not needing to go past the 53 bits needed for the float
|
||||
// mantissa. Or'ing with 0 keeps this 32 bits.
|
||||
hash = ((((hash << 5) - hash) | 0) + ch) | 0;
|
||||
}
|
||||
|
||||
// Ensure we fit in 31 bits. That way if/when this gets stored, it won't require any heap
|
||||
// allocation.
|
||||
return hash & 0x7FFFFFFF;
|
||||
}
|
||||
|
||||
public static computeSimple31BitStringHashCode(key: string): number {
|
||||
// Start with an int.
|
||||
var hash = 0;
|
||||
|
||||
var start = 0;
|
||||
var len = key.length;
|
||||
|
||||
for (var i = 0; i < len; i++) {
|
||||
var ch = key.charCodeAt(start + i);
|
||||
|
||||
// Left shift keeps things as a 32bit int. And we're only doing two adds. Chakra and
|
||||
// V8 recognize this as not needing to go past the 53 bits needed for the float
|
||||
// mantissa. Or'ing with 0 keeps this 32 bits.
|
||||
hash = ((((hash << 5) - hash) | 0) + ch) | 0;
|
||||
}
|
||||
|
||||
// Ensure we fit in 31 bits. That way if/when this gets stored, it won't require any heap
|
||||
// allocation.
|
||||
return hash & 0x7FFFFFFF;
|
||||
}
|
||||
|
||||
public static computeMurmur2StringHashCode(key: string, seed: number): number {
|
||||
// 'm' and 'r' are mixing constants generated offline.
|
||||
// They're not really 'magic', they just happen to work well.
|
||||
|
||||
var m: number = 0x5bd1e995;
|
||||
var r: number = 24;
|
||||
|
||||
// Initialize the hash to a 'random' value
|
||||
|
||||
var numberOfCharsLeft = key.length;
|
||||
var h = Math.abs(seed ^ numberOfCharsLeft);
|
||||
|
||||
// Mix 4 bytes at a time into the hash. NOTE: 4 bytes is two chars, so we iterate
|
||||
// through the string two chars at a time.
|
||||
var index = 0;
|
||||
while (numberOfCharsLeft >= 2) {
|
||||
var c1 = key.charCodeAt(index);
|
||||
var c2 = key.charCodeAt(index + 1);
|
||||
|
||||
var k = Math.abs(c1 | (c2 << 16));
|
||||
|
||||
k = IntegerUtilities.integerMultiplyLow32Bits(k, m);
|
||||
k ^= k >> r;
|
||||
k = IntegerUtilities.integerMultiplyLow32Bits(k, m);
|
||||
|
||||
h = IntegerUtilities.integerMultiplyLow32Bits(h, m);
|
||||
h ^= k;
|
||||
|
||||
index += 2;
|
||||
numberOfCharsLeft -= 2;
|
||||
}
|
||||
|
||||
// Handle the last char (or 2 bytes) if they exist. This happens if the original string had
|
||||
// odd length.
|
||||
if (numberOfCharsLeft === 1) {
|
||||
h ^= key.charCodeAt(index);
|
||||
h = IntegerUtilities.integerMultiplyLow32Bits(h, m);
|
||||
}
|
||||
|
||||
// Do a few final mixes of the hash to ensure the last few bytes are well-incorporated.
|
||||
|
||||
h ^= h >> 13;
|
||||
h = IntegerUtilities.integerMultiplyLow32Bits(h, m);
|
||||
h ^= h >> 15;
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
private static primes =
|
||||
[3, 7, 11, 17, 23, 29, 37, 47, 59, 71, 89, 107, 131, 163, 197, 239, 293, 353, 431, 521,
|
||||
631, 761, 919, 1103, 1327, 1597, 1931, 2333, 2801, 3371, 4049, 4861, 5839, 7013, 8419,
|
||||
10103, 12143, 14591, 17519, 21023, 25229, 30293, 36353, 43627, 52361, 62851, 75431,
|
||||
90523, 108631, 130363, 156437, 187751, 225307, 270371, 324449, 389357, 467237, 560689,
|
||||
672827, 807403, 968897, 1162687, 1395263, 1674319, 2009191, 2411033, 2893249, 3471899,
|
||||
4166287, 4999559, 5999471, 7199369];
|
||||
|
||||
public static getPrime(min: number): number {
|
||||
for (var i = 0; i < Hash.primes.length; i++) {
|
||||
var num = Hash.primes[i];
|
||||
if (num >= min) {
|
||||
return num;
|
||||
}
|
||||
}
|
||||
|
||||
throw Errors.notYetImplemented();
|
||||
}
|
||||
|
||||
public static expandPrime(oldSize: number): number {
|
||||
var num = oldSize << 1;
|
||||
if (num > 2146435069 && 2146435069 > oldSize) {
|
||||
// NOTE: 2146435069 fits in 31 bits.
|
||||
return 2146435069;
|
||||
}
|
||||
return Hash.getPrime(num);
|
||||
}
|
||||
|
||||
public static combine(value: number, currentHash: number): number {
|
||||
// Ensure we stay within 31 bits.
|
||||
return (((currentHash << 5) + currentHash) + value) & 0x7FFFFFFF;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript.Collections {
|
||||
export var DefaultHashTableCapacity = 1024;
|
||||
|
||||
class HashTableEntry<TEntryKey, TEntryValue> {
|
||||
constructor(public Key: TEntryKey,
|
||||
public Value: TEntryValue,
|
||||
public HashCode: number,
|
||||
public Next: HashTableEntry<TEntryKey,TEntryValue>) {
|
||||
}
|
||||
}
|
||||
|
||||
export class HashTable<TKey, TValue> {
|
||||
private entries: HashTableEntry<TKey, TValue>[];
|
||||
private count: number = 0;
|
||||
|
||||
constructor(capacity: number,
|
||||
private hash: (k: TKey) => number) {
|
||||
var size = Hash.getPrime(capacity);
|
||||
this.entries = ArrayUtilities.createArray<HashTableEntry<TKey, TValue>>(size, null);
|
||||
}
|
||||
|
||||
// Maps 'key' to 'value' in this table. Does not throw if 'key' is already in the table.
|
||||
public set (key: TKey, value: TValue): void {
|
||||
this.addOrSet(key, value, /*throwOnExistingEntry:*/ false);
|
||||
}
|
||||
|
||||
// Maps 'key' to 'value' in this table. Throws if 'key' is already in the table.
|
||||
public add(key: TKey, value: TValue): void {
|
||||
this.addOrSet(key, value, /*throwOnExistingEntry:*/ true);
|
||||
}
|
||||
|
||||
public containsKey(key: TKey): boolean {
|
||||
var hashCode = this.computeHashCode(key);
|
||||
var entry = this.findEntry(key, hashCode);
|
||||
return entry !== null;
|
||||
}
|
||||
|
||||
public get (key: TKey): TValue {
|
||||
var hashCode = this.computeHashCode(key);
|
||||
var entry = this.findEntry(key, hashCode);
|
||||
|
||||
return entry === null ? null : entry.Value;
|
||||
}
|
||||
|
||||
private computeHashCode(key: TKey): number {
|
||||
var hashCode: number = this.hash === null
|
||||
? (<any>key).hashCode
|
||||
: this.hash(key);
|
||||
|
||||
hashCode = hashCode & 0x7FFFFFFF;
|
||||
Debug.assert(hashCode >= 0);
|
||||
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
private addOrSet(key: TKey, value: TValue, throwOnExistingEntry: boolean): TKey {
|
||||
// Compute the hash for this key. Also ensure that it's non negative.
|
||||
var hashCode = this.computeHashCode(key);
|
||||
|
||||
var entry = this.findEntry(key, hashCode);
|
||||
if (entry !== null) {
|
||||
if (throwOnExistingEntry) {
|
||||
throw Errors.argument('key', "Key was already in table.");
|
||||
}
|
||||
|
||||
entry.Key = key;
|
||||
entry.Value = value;
|
||||
return;
|
||||
}
|
||||
|
||||
return this.addEntry(key, value, hashCode);
|
||||
}
|
||||
|
||||
private findEntry(key: TKey, hashCode: number): HashTableEntry<TKey, TValue> {
|
||||
for (var e = this.entries[hashCode % this.entries.length]; e !== null; e = e.Next) {
|
||||
if (e.HashCode === hashCode &&
|
||||
key === e.Key) {
|
||||
|
||||
return e;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private addEntry(key: TKey, value: TValue, hashCode: number): TKey {
|
||||
var index = hashCode % this.entries.length;
|
||||
|
||||
var e = new HashTableEntry(key, value, hashCode, this.entries[index]);
|
||||
|
||||
this.entries[index] = e;
|
||||
|
||||
if (this.count >= (this.entries.length / 2)) {
|
||||
this.grow();
|
||||
}
|
||||
|
||||
this.count++;
|
||||
return e.Key;
|
||||
}
|
||||
|
||||
//private dumpStats() {
|
||||
// var standardOut = Environment.standardOut;
|
||||
|
||||
// standardOut.WriteLine("----------------------")
|
||||
// standardOut.WriteLine("Hash table stats");
|
||||
// standardOut.WriteLine("Count : " + this.count);
|
||||
// standardOut.WriteLine("Entries Length : " + this.entries.length);
|
||||
|
||||
// var occupiedSlots = 0;
|
||||
// for (var i = 0; i < this.entries.length; i++) {
|
||||
// if (this.entries[i] !== null) {
|
||||
// occupiedSlots++;
|
||||
// }
|
||||
// }
|
||||
|
||||
// standardOut.WriteLine("Occupied slots : " + occupiedSlots);
|
||||
// standardOut.WriteLine("Avg Length/Slot : " + (this.count / occupiedSlots));
|
||||
// standardOut.WriteLine("----------------------");
|
||||
//}
|
||||
|
||||
private grow(): void {
|
||||
//this.dumpStats();
|
||||
|
||||
var newSize = Hash.expandPrime(this.entries.length);
|
||||
|
||||
var oldEntries = this.entries;
|
||||
var newEntries: HashTableEntry<TKey, TValue>[] = ArrayUtilities.createArray<HashTableEntry<TKey, TValue>>(newSize, null);
|
||||
|
||||
this.entries = newEntries;
|
||||
|
||||
for (var i = 0; i < oldEntries.length; i++) {
|
||||
var e = oldEntries[i];
|
||||
|
||||
while (e !== null) {
|
||||
var newIndex = e.HashCode % newSize;
|
||||
var tmp = e.Next;
|
||||
e.Next = newEntries[newIndex];
|
||||
newEntries[newIndex] = e;
|
||||
e = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
//this.dumpStats();
|
||||
}
|
||||
}
|
||||
|
||||
export function createHashTable<TKey,TValue>(capacity: number = DefaultHashTableCapacity,
|
||||
hash: (k: TKey) => number = null): HashTable<TKey,TValue> {
|
||||
return new HashTable<TKey,TValue>(capacity, hash);
|
||||
}
|
||||
|
||||
var currentHashCode = 1;
|
||||
export function identityHashCode(value: any): number {
|
||||
if (value.__hash === undefined) {
|
||||
value.__hash = currentHashCode;
|
||||
currentHashCode++;
|
||||
}
|
||||
|
||||
return value.__hash;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
///<reference path='references.ts'/>
|
||||
|
||||
module TypeScript {
|
||||
export interface IIndexable<T> {
|
||||
[s: string]: T;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export module IntegerUtilities {
|
||||
export function integerDivide(numerator: number, denominator: number): number {
|
||||
return (numerator / denominator) >> 0;
|
||||
}
|
||||
|
||||
export function integerMultiplyLow32Bits(n1: number, n2: number): number {
|
||||
var n1Low16 = n1 & 0x0000ffff;
|
||||
var n1High16 = n1 >>> 16;
|
||||
|
||||
var n2Low16 = n2 & 0x0000ffff;
|
||||
var n2High16 = n2 >>> 16;
|
||||
|
||||
var resultLow32 = (((n1 & 0xffff0000) * n2) >>> 0) + (((n1 & 0x0000ffff) * n2) >>> 0) >>> 0;
|
||||
return resultLow32;
|
||||
}
|
||||
|
||||
export function integerMultiplyHigh32Bits(n1: number, n2: number): number {
|
||||
var n1Low16 = n1 & 0x0000ffff;
|
||||
var n1High16 = n1 >>> 16;
|
||||
|
||||
var n2Low16 = n2 & 0x0000ffff;
|
||||
var n2High16 = n2 >>> 16;
|
||||
|
||||
var resultHigh32 = n1High16 * n2High16 + ((((n1Low16 * n2Low16) >>> 17) + n1Low16 * n2High16) >>> 15);
|
||||
return resultHigh32;
|
||||
}
|
||||
|
||||
export function isInteger(text: string): boolean {
|
||||
return /^[0-9]+$/.test(text);
|
||||
}
|
||||
|
||||
export function isHexInteger(text: string): boolean {
|
||||
return /^0(x|X)[0-9a-fA-F]+$/.test(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/// <reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export interface Iterator<T> {
|
||||
moveNext(): boolean;
|
||||
current(): T;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export interface ILineAndCharacter {
|
||||
line: number;
|
||||
character: number;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export class LineMap {
|
||||
public static empty = new LineMap(() => [0], 0);
|
||||
private _lineStarts: number[] = null;
|
||||
|
||||
constructor(private _computeLineStarts: () => number[], private length: number) {
|
||||
}
|
||||
|
||||
public toJSON(key: any) {
|
||||
return { lineStarts: this.lineStarts(), length: this.length };
|
||||
}
|
||||
|
||||
public equals(other: LineMap): boolean {
|
||||
return this.length === other.length &&
|
||||
ArrayUtilities.sequenceEquals(this.lineStarts(), other.lineStarts(), (v1, v2) => v1 === v2);
|
||||
}
|
||||
|
||||
public lineStarts(): number[] {
|
||||
if (this._lineStarts === null) {
|
||||
this._lineStarts = this._computeLineStarts();
|
||||
}
|
||||
|
||||
return this._lineStarts;
|
||||
}
|
||||
|
||||
public lineCount(): number {
|
||||
return this.lineStarts().length;
|
||||
}
|
||||
|
||||
public getPosition(line: number, character: number): number {
|
||||
return this.lineStarts()[line] + character;
|
||||
}
|
||||
|
||||
public getLineNumberFromPosition(position: number): number {
|
||||
if (position < 0 || position > this.length) {
|
||||
throw Errors.argumentOutOfRange("position");
|
||||
}
|
||||
|
||||
if (position === this.length) {
|
||||
// this can happen when the user tried to get the line of items
|
||||
// that are at the absolute end of this text (i.e. the EndOfLine
|
||||
// token, or missing tokens that are at the end of the text).
|
||||
// In this case, we want the last line in the text.
|
||||
return this.lineCount() - 1;
|
||||
}
|
||||
|
||||
// Binary search to find the right line
|
||||
var lineNumber = ArrayUtilities.binarySearch(this.lineStarts(), position);
|
||||
if (lineNumber < 0) {
|
||||
lineNumber = (~lineNumber) - 1;
|
||||
}
|
||||
|
||||
return lineNumber;
|
||||
}
|
||||
|
||||
public getLineStartPosition(lineNumber: number): number {
|
||||
return this.lineStarts()[lineNumber];
|
||||
}
|
||||
|
||||
public fillLineAndCharacterFromPosition(position: number, lineAndCharacter: ILineAndCharacter): void {
|
||||
if (position < 0 || position > this.length) {
|
||||
throw Errors.argumentOutOfRange("position");
|
||||
}
|
||||
|
||||
var lineNumber = this.getLineNumberFromPosition(position);
|
||||
lineAndCharacter.line = lineNumber;
|
||||
lineAndCharacter.character = position - this.lineStarts()[lineNumber];
|
||||
}
|
||||
|
||||
public getLineAndCharacterFromPosition(position: number): LineAndCharacter {
|
||||
if (position < 0 || position > this.length) {
|
||||
throw Errors.argumentOutOfRange("position");
|
||||
}
|
||||
|
||||
var lineNumber = this.getLineNumberFromPosition(position);
|
||||
|
||||
return new LineAndCharacter(lineNumber, position - this.lineStarts()[lineNumber]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export class LineAndCharacter {
|
||||
private _line: number = 0;
|
||||
private _character: number = 0;
|
||||
|
||||
/**
|
||||
* Initializes a new instance of a LinePosition with the given line and character. ArgumentOutOfRangeException if "line" or "character" is less than zero.
|
||||
* @param line The line of the line position. The first line in a file is defined as line 0 (zero based line numbering).
|
||||
* @param character The character position in the line.
|
||||
*/
|
||||
|
||||
constructor(line: number, character: number) {
|
||||
if (line < 0) {
|
||||
throw Errors.argumentOutOfRange("line");
|
||||
}
|
||||
|
||||
if (character < 0) {
|
||||
throw Errors.argumentOutOfRange("character");
|
||||
}
|
||||
|
||||
this._line = line;
|
||||
this._character = character;
|
||||
}
|
||||
|
||||
public line(): number {
|
||||
return this._line;
|
||||
}
|
||||
|
||||
public character(): number {
|
||||
return this._character;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export class MathPrototype {
|
||||
public static max(a: number, b: number): number {
|
||||
return a >= b ? a : b;
|
||||
}
|
||||
|
||||
public static min(a: number, b: number): number {
|
||||
return a <= b ? a : b;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
///<reference path='require.ts' />
|
||||
|
||||
///<reference path='..\resources\references.ts' />
|
||||
|
||||
///<reference path='arrayUtilities.ts' />
|
||||
///<reference path='bitVector.ts' />
|
||||
///<reference path='bitMatrix.ts' />
|
||||
///<reference path='constants.ts' />
|
||||
///<reference path='debug.ts' />
|
||||
///<reference path='diagnosticCategory.ts' />
|
||||
///<reference path='diagnosticCore.ts' />
|
||||
///<reference path='diagnosticInfo.ts' />
|
||||
///<reference path='errors.ts' />
|
||||
///<reference path='hash.ts' />
|
||||
///<reference path='hashTable.ts' />
|
||||
///<reference path='environment.ts' />
|
||||
///<reference path='indexable.ts' />
|
||||
///<reference path='integerUtilities.ts' />
|
||||
///<reference path='iterator.ts' />
|
||||
///<reference path='lineAndCharacter.ts' />
|
||||
///<reference path='lineMap.ts' />
|
||||
///<reference path='linePosition.ts' />
|
||||
///<reference path='mathPrototype.ts' />
|
||||
///<reference path='stringTable.ts' />
|
||||
///<reference path='stringUtilities.ts' />
|
||||
///<reference path='timer.ts' />
|
||||
@@ -0,0 +1,5 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
// Forward declarations of the variables we use from 'node'.
|
||||
declare var require: any;
|
||||
declare var module: any;
|
||||
@@ -0,0 +1,159 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript.Collections {
|
||||
export var DefaultStringTableCapacity = 256;
|
||||
|
||||
class StringTableEntry {
|
||||
constructor(public Text: string,
|
||||
public HashCode: number,
|
||||
public Next: StringTableEntry) {
|
||||
}
|
||||
}
|
||||
|
||||
// A table of interned strings. Faster and better than an arbitrary hashtable for the needs of the
|
||||
// scanner. Specifically, the scanner operates over a sliding window of characters, with a start
|
||||
// and end pointer for the current lexeme. The scanner then wants to get the *interned* string
|
||||
// represented by that subsection.
|
||||
//
|
||||
// Importantly, if the string is already interned, then it wants ask "is the string represented by
|
||||
// this section of a char array contained within the table" in a non-allocating fashion. i.e. if
|
||||
// you have "[' ', 'p', 'u', 'b', 'l', 'i', 'c', ' ']" and you ask to get the string represented by
|
||||
// range [1, 7), then this table will return "public" without any allocations if that value was
|
||||
// already in the table.
|
||||
//
|
||||
// Of course, if the value is not in the table then there will be an initial cost to allocate the
|
||||
// string and the bucket for the table. However, that is only incurred the first time each unique
|
||||
// string is added.
|
||||
export class StringTable {
|
||||
// TODO: uncomment this once typecheck bug is fixed.
|
||||
private entries: StringTableEntry[];
|
||||
private count: number = 0;
|
||||
|
||||
constructor(capacity: number) {
|
||||
var size = Hash.getPrime(capacity);
|
||||
this.entries = ArrayUtilities.createArray<StringTableEntry>(size, null);
|
||||
}
|
||||
|
||||
public addCharArray(key: number[], start: number, len: number): string {
|
||||
// Compute the hash for this key. Also ensure that it fits within 31 bits (so that it
|
||||
// stays a non-heap integer, and so we can index into the array safely).
|
||||
var hashCode = Hash.computeSimple31BitCharArrayHashCode(key, start, len) & 0x7FFFFFFF;
|
||||
// Debug.assert(hashCode > 0);
|
||||
|
||||
// First see if we already have the string represented by "key[start, start + len)" already
|
||||
// present in this table. If we do, just return that string. Do this without any
|
||||
// allocations
|
||||
var entry = this.findCharArrayEntry(key, start, len, hashCode);
|
||||
if (entry !== null) {
|
||||
return entry.Text;
|
||||
}
|
||||
|
||||
// We don't have an entry for that string in our table. Convert that
|
||||
var slice: number[] = key.slice(start, start + len);
|
||||
return this.addEntry(StringUtilities.fromCharCodeArray(slice), hashCode);
|
||||
}
|
||||
|
||||
private findCharArrayEntry(key: number[], start: number, len: number, hashCode: number) {
|
||||
for (var e = this.entries[hashCode % this.entries.length]; e !== null; e = e.Next) {
|
||||
if (e.HashCode === hashCode && StringTable.textCharArrayEquals(e.Text, key, start, len)) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private addEntry(text: string, hashCode: number): string {
|
||||
var index = hashCode % this.entries.length;
|
||||
|
||||
var e = new StringTableEntry(text, hashCode, this.entries[index]);
|
||||
|
||||
this.entries[index] = e;
|
||||
|
||||
// We grow when our load factor equals 1. I tried different load factors (like .75 and
|
||||
// .5), however they seemed to have no effect on running time. With a load factor of 1
|
||||
// we seem to get about 80% slot fill rate with an average of around 1.25 table entries
|
||||
// per slot.
|
||||
if (this.count === this.entries.length) {
|
||||
this.grow();
|
||||
}
|
||||
|
||||
this.count++;
|
||||
return e.Text;
|
||||
}
|
||||
|
||||
//private dumpStats() {
|
||||
// var standardOut = Environment.standardOut;
|
||||
|
||||
// standardOut.WriteLine("----------------------")
|
||||
// standardOut.WriteLine("String table stats");
|
||||
// standardOut.WriteLine("Count : " + this.count);
|
||||
// standardOut.WriteLine("Entries Length : " + this.entries.length);
|
||||
|
||||
// var longestSlot = 0;
|
||||
// var occupiedSlots = 0;
|
||||
// for (var i = 0; i < this.entries.length; i++) {
|
||||
// if (this.entries[i] !== null) {
|
||||
// occupiedSlots++;
|
||||
|
||||
// var current = this.entries[i];
|
||||
// var slotCount = 0;
|
||||
// while (current !== null) {
|
||||
// slotCount++;
|
||||
// current = current.Next;
|
||||
// }
|
||||
|
||||
// longestSlot = MathPrototype.max(longestSlot, slotCount);
|
||||
// }
|
||||
// }
|
||||
|
||||
// standardOut.WriteLine("Occupied slots : " + occupiedSlots);
|
||||
// standardOut.WriteLine("Longest slot : " + longestSlot);
|
||||
// standardOut.WriteLine("Avg Length/Slot : " + (this.count / occupiedSlots));
|
||||
// standardOut.WriteLine("----------------------");
|
||||
//}
|
||||
|
||||
private grow(): void {
|
||||
// this.dumpStats();
|
||||
|
||||
var newSize = Hash.expandPrime(this.entries.length);
|
||||
|
||||
var oldEntries = this.entries;
|
||||
var newEntries: StringTableEntry[] = ArrayUtilities.createArray<StringTableEntry>(newSize, null);
|
||||
|
||||
this.entries = newEntries;
|
||||
|
||||
for (var i = 0; i < oldEntries.length; i++) {
|
||||
var e = oldEntries[i];
|
||||
while (e !== null) {
|
||||
var newIndex = e.HashCode % newSize;
|
||||
var tmp = e.Next;
|
||||
e.Next = newEntries[newIndex];
|
||||
newEntries[newIndex] = e;
|
||||
e = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
// this.dumpStats();
|
||||
}
|
||||
|
||||
private static textCharArrayEquals(text: string, array: number[], start: number, length: number): boolean {
|
||||
if (text.length !== length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var s = start;
|
||||
for (var i = 0; i < length; i++) {
|
||||
if (text.charCodeAt(i) !== array[s]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
s++;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
export var DefaultStringTable = new StringTable(DefaultStringTableCapacity);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export class StringUtilities {
|
||||
public static isString(value: any): boolean {
|
||||
return Object.prototype.toString.apply(value, []) === '[object String]';
|
||||
}
|
||||
|
||||
public static fromCharCodeArray(array: number[]): string {
|
||||
return String.fromCharCode.apply(null, array);
|
||||
}
|
||||
|
||||
public static endsWith(string: string, value: string): boolean {
|
||||
return string.substring(string.length - value.length, string.length) === value;
|
||||
}
|
||||
|
||||
public static startsWith(string: string, value: string): boolean {
|
||||
return string.substr(0, value.length) === value;
|
||||
}
|
||||
|
||||
public static copyTo(source: string, sourceIndex: number, destination: number[], destinationIndex: number, count: number): void {
|
||||
for (var i = 0; i < count; i++) {
|
||||
destination[destinationIndex + i] = source.charCodeAt(sourceIndex + i);
|
||||
}
|
||||
}
|
||||
|
||||
public static repeat(value: string, count: number) {
|
||||
return Array(count + 1).join(value);
|
||||
}
|
||||
|
||||
public static stringEquals(val1: string, val2: string): boolean {
|
||||
return val1 === val2;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
var global: any = <any>Function("return this").call(null);
|
||||
|
||||
module TypeScript {
|
||||
module Clock {
|
||||
export var now: () => number;
|
||||
export var resolution: number;
|
||||
|
||||
declare module WScript {
|
||||
export function InitializeProjection(): void;
|
||||
}
|
||||
|
||||
declare module TestUtilities {
|
||||
export function QueryPerformanceCounter(): number;
|
||||
export function QueryPerformanceFrequency(): number;
|
||||
}
|
||||
|
||||
if (typeof WScript !== "undefined" && typeof global['WScript'].InitializeProjection !== "undefined") {
|
||||
// Running in JSHost.
|
||||
global['WScript'].InitializeProjection();
|
||||
|
||||
now = function () {
|
||||
return TestUtilities.QueryPerformanceCounter();
|
||||
};
|
||||
|
||||
resolution = TestUtilities.QueryPerformanceFrequency();
|
||||
}
|
||||
else {
|
||||
now = function () {
|
||||
return Date.now();
|
||||
};
|
||||
|
||||
resolution = 1000;
|
||||
}
|
||||
}
|
||||
|
||||
export class Timer {
|
||||
public startTime: number;
|
||||
public time = 0;
|
||||
|
||||
public start() {
|
||||
this.time = 0;
|
||||
this.startTime = Clock.now();
|
||||
}
|
||||
|
||||
public end() {
|
||||
// Set time to MS.
|
||||
this.time = (Clock.now() - this.startTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,79 @@
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export module CompilerDiagnostics {
|
||||
export var debug = false;
|
||||
export interface IDiagnosticWriter {
|
||||
Alert(output: string): void;
|
||||
}
|
||||
|
||||
export var diagnosticWriter: IDiagnosticWriter = null;
|
||||
|
||||
export var analysisPass: number = 0;
|
||||
|
||||
export function Alert(output: string) {
|
||||
if (diagnosticWriter) {
|
||||
diagnosticWriter.Alert(output);
|
||||
}
|
||||
}
|
||||
|
||||
export function debugPrint(s: string) {
|
||||
if (debug) {
|
||||
Alert(s);
|
||||
}
|
||||
}
|
||||
|
||||
export function assert(condition: boolean, s: string) {
|
||||
if (debug) {
|
||||
if (!condition) {
|
||||
Alert(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export interface ILogger {
|
||||
information(): boolean;
|
||||
debug(): boolean;
|
||||
warning(): boolean;
|
||||
error(): boolean;
|
||||
fatal(): boolean;
|
||||
log(s: string): void;
|
||||
}
|
||||
|
||||
export class NullLogger implements ILogger {
|
||||
public information(): boolean { return false; }
|
||||
public debug(): boolean { return false; }
|
||||
public warning(): boolean { return false; }
|
||||
public error(): boolean { return false; }
|
||||
public fatal(): boolean { return false; }
|
||||
public log(s: string): void {
|
||||
}
|
||||
}
|
||||
|
||||
export function timeFunction(logger: ILogger, funcDescription: string, func: () => any): any {
|
||||
var start = (new Date()).getTime();
|
||||
var result = func();
|
||||
var end = (new Date()).getTime();
|
||||
if (logger.information()) {
|
||||
logger.log(funcDescription + " completed in " + (end - start) + " msec");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,363 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export class Document {
|
||||
private _diagnostics: Diagnostic[] = null;
|
||||
private _bloomFilter: BloomFilter = null;
|
||||
private _sourceUnit: SourceUnit = null;
|
||||
private _lineMap: LineMap = null;
|
||||
|
||||
private _declASTMap: AST[] = [];
|
||||
private _astDeclMap: PullDecl[] = [];
|
||||
private _amdDependencies: string[] = undefined;
|
||||
|
||||
private _externalModuleIndicatorSpan: TextSpan = undefined;
|
||||
|
||||
constructor(private _compiler: TypeScriptCompiler,
|
||||
private _semanticInfoChain: SemanticInfoChain,
|
||||
public fileName: string,
|
||||
public referencedFiles: string[],
|
||||
private _scriptSnapshot: IScriptSnapshot,
|
||||
public byteOrderMark: ByteOrderMark,
|
||||
public version: number,
|
||||
public isOpen: boolean,
|
||||
private _syntaxTree: SyntaxTree,
|
||||
private _topLevelDecl: PullDecl) {
|
||||
}
|
||||
|
||||
// Only for use by the semantic info chain.
|
||||
public invalidate(): void {
|
||||
// Dump all information related to syntax. We'll have to recompute it when asked.
|
||||
this._declASTMap.length = 0;
|
||||
this._astDeclMap.length = 0;
|
||||
this._topLevelDecl = null;
|
||||
|
||||
this._syntaxTree = null;
|
||||
this._sourceUnit = null;
|
||||
this._diagnostics = null;
|
||||
this._bloomFilter = null;
|
||||
}
|
||||
|
||||
public isDeclareFile(): boolean {
|
||||
return isDTSFile(this.fileName);
|
||||
}
|
||||
|
||||
private cacheSyntaxTreeInfo(syntaxTree: SyntaxTree): void {
|
||||
// If we're not keeping around the syntax tree, store the diagnostics and line
|
||||
// map so they don't have to be recomputed.
|
||||
var start = new Date().getTime();
|
||||
this._diagnostics = syntaxTree.diagnostics();
|
||||
TypeScript.syntaxDiagnosticsTime += new Date().getTime() - start;
|
||||
|
||||
this._lineMap = syntaxTree.lineMap();
|
||||
|
||||
var sourceUnit = syntaxTree.sourceUnit();
|
||||
var leadingTrivia = sourceUnit.leadingTrivia();
|
||||
|
||||
this._externalModuleIndicatorSpan = this.getImplicitImportSpan(leadingTrivia) || this.getTopLevelImportOrExportSpan(sourceUnit);
|
||||
|
||||
var amdDependencies: string[] = [];
|
||||
for (var i = 0, n = leadingTrivia.count(); i < n; i++) {
|
||||
var trivia = leadingTrivia.syntaxTriviaAt(i);
|
||||
if (trivia.isComment()) {
|
||||
var amdDependency = this.getAmdDependency(trivia.fullText());
|
||||
if (amdDependency) {
|
||||
amdDependencies.push(amdDependency);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this._amdDependencies = amdDependencies;
|
||||
}
|
||||
|
||||
private getAmdDependency(comment: string): string {
|
||||
var amdDependencyRegEx = /^\/\/\/\s*<amd-dependency\s+path=('|")(.+?)\1/gim;
|
||||
var match = amdDependencyRegEx.exec(comment);
|
||||
return match ? match[2] : null;
|
||||
}
|
||||
|
||||
private getImplicitImportSpan(sourceUnitLeadingTrivia: ISyntaxTriviaList): TextSpan {
|
||||
var position = 0;
|
||||
|
||||
for (var i = 0, n = sourceUnitLeadingTrivia.count(); i < n; i++) {
|
||||
var trivia = sourceUnitLeadingTrivia.syntaxTriviaAt(i);
|
||||
|
||||
if (trivia.isComment()) {
|
||||
var span = this.getImplicitImportSpanWorker(trivia, position);
|
||||
if (span) {
|
||||
return span;
|
||||
}
|
||||
}
|
||||
|
||||
position += trivia.fullWidth();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private getImplicitImportSpanWorker(trivia: ISyntaxTrivia, position: number): TextSpan {
|
||||
var implicitImportRegEx = /^(\/\/\/\s*<implicit-import\s*)*\/>/gim;
|
||||
var match = implicitImportRegEx.exec(trivia.fullText());
|
||||
|
||||
if (match) {
|
||||
return new TextSpan(position, trivia.fullWidth());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private getTopLevelImportOrExportSpan(node: SourceUnitSyntax): TextSpan {
|
||||
var firstToken: ISyntaxToken;
|
||||
var position = 0;
|
||||
|
||||
for (var i = 0, n = node.moduleElements.childCount(); i < n; i++) {
|
||||
var moduleElement = node.moduleElements.childAt(i);
|
||||
|
||||
firstToken = moduleElement.firstToken();
|
||||
if (firstToken !== null && firstToken.tokenKind === SyntaxKind.ExportKeyword) {
|
||||
return new TextSpan(position + firstToken.leadingTriviaWidth(), firstToken.width());
|
||||
}
|
||||
|
||||
if (moduleElement.kind() === SyntaxKind.ImportDeclaration) {
|
||||
var importDecl = <ImportDeclarationSyntax>moduleElement;
|
||||
if (importDecl.moduleReference.kind() === SyntaxKind.ExternalModuleReference) {
|
||||
return new TextSpan(position + importDecl.leadingTriviaWidth(), importDecl.width());
|
||||
}
|
||||
}
|
||||
|
||||
position += moduleElement.fullWidth();
|
||||
}
|
||||
|
||||
return null;;
|
||||
}
|
||||
|
||||
public sourceUnit(): SourceUnit {
|
||||
// If we don't have a script, create one from our parse tree.
|
||||
if (!this._sourceUnit) {
|
||||
var start = new Date().getTime();
|
||||
var syntaxTree = this.syntaxTree();
|
||||
this._sourceUnit = SyntaxTreeToAstVisitor.visit(syntaxTree, this.fileName, this._compiler.compilationSettings(), /*incrementalAST:*/ this.isOpen);
|
||||
TypeScript.astTranslationTime += new Date().getTime() - start;
|
||||
|
||||
// If we're not open, then we can throw away our syntax tree. We don't need it from
|
||||
// now on.
|
||||
if (!this.isOpen) {
|
||||
this._syntaxTree = null;
|
||||
}
|
||||
}
|
||||
|
||||
return this._sourceUnit;
|
||||
}
|
||||
|
||||
public diagnostics(): Diagnostic[] {
|
||||
if (this._diagnostics === null) {
|
||||
// force the diagnostics to get created.
|
||||
this.syntaxTree();
|
||||
Debug.assert(this._diagnostics);
|
||||
}
|
||||
|
||||
return this._diagnostics;
|
||||
}
|
||||
|
||||
public lineMap(): LineMap {
|
||||
if (this._lineMap === null) {
|
||||
// force the line map to get created.
|
||||
this.syntaxTree();
|
||||
Debug.assert(this._lineMap);
|
||||
}
|
||||
|
||||
return this._lineMap;
|
||||
}
|
||||
|
||||
public isExternalModule(): boolean {
|
||||
return this.externalModuleIndicatorSpan() !== null;
|
||||
}
|
||||
|
||||
// TODO: remove this once we move entirely over to fidelity. Right now we don't have
|
||||
// enough information in the AST to reconstruct this span data, so we cache and store it
|
||||
// on the document. When we move to fidelity, we can just have the type checker determine
|
||||
// this in its own codepath.
|
||||
public externalModuleIndicatorSpan(): TextSpan {
|
||||
// October 11, 2013
|
||||
// External modules are written as separate source files that contain at least one
|
||||
// external import declaration, export assignment, or top-level exported declaration.
|
||||
if (this._externalModuleIndicatorSpan === undefined) {
|
||||
// force the info about isExternalModule to get created.
|
||||
this.syntaxTree();
|
||||
Debug.assert(this._externalModuleIndicatorSpan !== undefined);
|
||||
}
|
||||
|
||||
return this._externalModuleIndicatorSpan;
|
||||
}
|
||||
|
||||
public amdDependencies(): string[] {
|
||||
if (this._amdDependencies === undefined) {
|
||||
// force the info about the amd dependencies to get created.
|
||||
this.syntaxTree();
|
||||
Debug.assert(this._amdDependencies !== undefined);
|
||||
}
|
||||
|
||||
return this._amdDependencies;
|
||||
}
|
||||
|
||||
public syntaxTree(): SyntaxTree {
|
||||
var result = this._syntaxTree;
|
||||
if (!result) {
|
||||
var start = new Date().getTime();
|
||||
|
||||
result = Parser.parse(
|
||||
this.fileName,
|
||||
SimpleText.fromScriptSnapshot(this._scriptSnapshot),
|
||||
TypeScript.isDTSFile(this.fileName),
|
||||
getParseOptions(this._compiler.compilationSettings()));
|
||||
|
||||
TypeScript.syntaxTreeParseTime += new Date().getTime() - start;
|
||||
|
||||
// If the document is open, store the syntax tree for fast incremental updates.
|
||||
// Or, if we don't have a script, then store the syntax tree around so we won't
|
||||
// have to immediately regenerate it when we need the script.
|
||||
if (this.isOpen || !this._sourceUnit) {
|
||||
this._syntaxTree = result;
|
||||
}
|
||||
}
|
||||
|
||||
this.cacheSyntaxTreeInfo(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
public bloomFilter(): BloomFilter {
|
||||
if (!this._bloomFilter) {
|
||||
var identifiers = createIntrinsicsObject<boolean>();
|
||||
var pre = function (cur: TypeScript.AST) {
|
||||
if (ASTHelpers.isValidAstNode(cur)) {
|
||||
if (cur.kind() === SyntaxKind.IdentifierName) {
|
||||
var nodeText = (<TypeScript.Identifier>cur).valueText();
|
||||
|
||||
identifiers[nodeText] = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TypeScript.getAstWalkerFactory().simpleWalk(this.sourceUnit(), pre, null, identifiers);
|
||||
|
||||
var identifierCount = 0;
|
||||
for (var name in identifiers) {
|
||||
if (identifiers[name]) {
|
||||
identifierCount++;
|
||||
}
|
||||
}
|
||||
|
||||
this._bloomFilter = new BloomFilter(identifierCount);
|
||||
this._bloomFilter.addKeys(identifiers);
|
||||
}
|
||||
return this._bloomFilter;
|
||||
}
|
||||
|
||||
// Returns true if this file should get emitted into its own unique output file.
|
||||
// Otherwise, it should be written into a single output file along with the rest of hte
|
||||
// documents in the compilation.
|
||||
public emitToOwnOutputFile(): boolean {
|
||||
// If we haven't specified an output file in our settings, then we're definitely
|
||||
// emitting to our own file. Also, if we're an external module, then we're
|
||||
// definitely emitting to our own file.
|
||||
return !this._compiler.compilationSettings().outFileOption() || this.isExternalModule();
|
||||
}
|
||||
|
||||
public update(scriptSnapshot: IScriptSnapshot, version: number, isOpen: boolean, textChangeRange: TextChangeRange): Document {
|
||||
// See if we are currently holding onto a syntax tree. We may not be because we're
|
||||
// either a closed file, or we've just been lazy and haven't had to create the syntax
|
||||
// tree yet. Access the field instead of the method so we don't accidently realize
|
||||
// the old syntax tree.
|
||||
var oldSyntaxTree = this._syntaxTree;
|
||||
|
||||
if (textChangeRange !== null && Debug.shouldAssert(AssertionLevel.Normal)) {
|
||||
var oldText = this._scriptSnapshot;
|
||||
var newText = scriptSnapshot;
|
||||
|
||||
TypeScript.Debug.assert((oldText.getLength() - textChangeRange.span().length() + textChangeRange.newLength()) === newText.getLength());
|
||||
|
||||
if (Debug.shouldAssert(AssertionLevel.VeryAggressive)) {
|
||||
var oldTextPrefix = oldText.getText(0, textChangeRange.span().start());
|
||||
var newTextPrefix = newText.getText(0, textChangeRange.span().start());
|
||||
TypeScript.Debug.assert(oldTextPrefix === newTextPrefix);
|
||||
|
||||
var oldTextSuffix = oldText.getText(textChangeRange.span().end(), oldText.getLength());
|
||||
var newTextSuffix = newText.getText(textChangeRange.newSpan().end(), newText.getLength());
|
||||
TypeScript.Debug.assert(oldTextSuffix === newTextSuffix);
|
||||
}
|
||||
}
|
||||
|
||||
var text = SimpleText.fromScriptSnapshot(scriptSnapshot);
|
||||
|
||||
// If we don't have a text change, or we don't have an old syntax tree, then do a full
|
||||
// parse. Otherwise, do an incremental parse.
|
||||
var newSyntaxTree = textChangeRange === null || oldSyntaxTree === null
|
||||
? TypeScript.Parser.parse(this.fileName, text, TypeScript.isDTSFile(this.fileName), getParseOptions(this._compiler.compilationSettings()))
|
||||
: TypeScript.Parser.incrementalParse(oldSyntaxTree, textChangeRange, text);
|
||||
|
||||
return new Document(this._compiler, this._semanticInfoChain, this.fileName, this.referencedFiles, scriptSnapshot, this.byteOrderMark, version, isOpen, newSyntaxTree, /*topLevelDecl:*/ null);
|
||||
}
|
||||
|
||||
public static create(compiler: TypeScriptCompiler, semanticInfoChain: SemanticInfoChain, fileName: string, scriptSnapshot: IScriptSnapshot, byteOrderMark: ByteOrderMark, version: number, isOpen: boolean, referencedFiles: string[]): Document {
|
||||
return new Document(compiler, semanticInfoChain, fileName, referencedFiles, scriptSnapshot, byteOrderMark, version, isOpen, /*syntaxTree:*/ null, /*topLevelDecl:*/ null);
|
||||
}
|
||||
|
||||
public topLevelDecl(): PullDecl {
|
||||
if (this._topLevelDecl === null) {
|
||||
this._topLevelDecl = DeclarationCreator.create(this, this._semanticInfoChain, this._compiler.compilationSettings());
|
||||
}
|
||||
|
||||
return this._topLevelDecl;
|
||||
}
|
||||
|
||||
public _getDeclForAST(ast: AST): PullDecl {
|
||||
// Ensure we actually have created all our decls before we try to find a mathcing decl
|
||||
// for this ast.
|
||||
this.topLevelDecl();
|
||||
return this._astDeclMap[ast.syntaxID()];
|
||||
}
|
||||
|
||||
public getEnclosingDecl(ast: AST): PullDecl {
|
||||
if (ast.kind() === SyntaxKind.SourceUnit) {
|
||||
return this._getDeclForAST(ast);
|
||||
}
|
||||
|
||||
// First, walk up the AST, looking for a decl corresponding to that AST node.
|
||||
ast = ast.parent;
|
||||
var decl: PullDecl = null;
|
||||
while (ast) {
|
||||
//if (ast.kind() === SyntaxKind.ModuleDeclaration) {
|
||||
// var moduleDecl = <ModuleDeclaration>ast;
|
||||
// decl = this._getDeclForAST(<AST>moduleDecl.stringLiteral || ArrayUtilities.last(getModuleNames(moduleDecl.name)));
|
||||
//}
|
||||
//else {
|
||||
decl = this._getDeclForAST(ast);
|
||||
//}
|
||||
|
||||
if (decl) {
|
||||
break;
|
||||
}
|
||||
|
||||
ast = ast.parent;
|
||||
}
|
||||
|
||||
// Now, skip over certain decls. The resolver never considers these the 'enclosing'
|
||||
// decl for an AST node.
|
||||
return decl._getEnclosingDeclFromParentDecl();
|
||||
}
|
||||
|
||||
public _setDeclForAST(ast: AST, decl: PullDecl): void {
|
||||
Debug.assert(decl.fileName() === this.fileName);
|
||||
this._astDeclMap[ast.syntaxID()] = decl;
|
||||
}
|
||||
|
||||
public _getASTForDecl(decl: PullDecl): AST {
|
||||
return this._declASTMap[decl.declID];
|
||||
}
|
||||
|
||||
public _setASTForDecl(decl: PullDecl, ast: AST): void {
|
||||
Debug.assert(decl.fileName() === this.fileName);
|
||||
this._declASTMap[decl.declID] = ast;
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,6 @@
|
||||
declare class Enumerator {
|
||||
public atEnd(): boolean;
|
||||
public moveNext(): boolean;
|
||||
public item(): any;
|
||||
constructor (o: any);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export function hasFlag(val: number, flag: number): boolean {
|
||||
return (val & flag) !== 0;
|
||||
}
|
||||
|
||||
export enum TypeRelationshipFlags {
|
||||
SuccessfulComparison = 0,
|
||||
RequiredPropertyIsMissing = 1 << 1,
|
||||
IncompatibleSignatures = 1 << 2,
|
||||
SourceSignatureHasTooManyParameters = 3,
|
||||
IncompatibleReturnTypes = 1 << 4,
|
||||
IncompatiblePropertyTypes = 1 << 5,
|
||||
IncompatibleParameterTypes = 1 << 6,
|
||||
InconsistantPropertyAccesibility = 1 << 7,
|
||||
}
|
||||
|
||||
export enum ModuleGenTarget {
|
||||
Unspecified = 0,
|
||||
Synchronous = 1,
|
||||
Asynchronous = 2,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
var proto = "__proto__"
|
||||
|
||||
class BlockIntrinsics<T> {
|
||||
public prototype: T = undefined;
|
||||
public toString: T = undefined;
|
||||
public toLocaleString: T = undefined;
|
||||
public valueOf: T = undefined;
|
||||
public hasOwnProperty: T = undefined;
|
||||
public propertyIsEnumerable: T = undefined;
|
||||
public isPrototypeOf: T = undefined;
|
||||
[s: string]: T;
|
||||
|
||||
constructor() {
|
||||
// initialize the 'constructor' field
|
||||
this["constructor"] = undefined;
|
||||
|
||||
// First we set it to null, because that's the only way to erase the value in node. Then we set it to undefined in case we are not in node, since
|
||||
// in StringHashTable below, we check for undefined explicitly.
|
||||
this[proto] = null;
|
||||
this[proto] = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export function createIntrinsicsObject<T>(): IIndexable<T> {
|
||||
return new BlockIntrinsics<T>();
|
||||
}
|
||||
|
||||
export interface IHashTable<T> {
|
||||
getAllKeys(): string[];
|
||||
add(key: string, data: T): boolean;
|
||||
addOrUpdate(key: string, data: T): boolean;
|
||||
map(fn: (k: string, value: T, context: any) => void , context: any): void;
|
||||
every(fn: (k: string, value: T, context: any) => void , context: any): boolean;
|
||||
some(fn: (k: string, value: T, context: any) => void , context: any): boolean;
|
||||
count(): number;
|
||||
lookup(key: string): T;
|
||||
}
|
||||
|
||||
export class StringHashTable<T> implements IHashTable<T> {
|
||||
private itemCount = 0;
|
||||
private table: IIndexable<T> = createIntrinsicsObject<T>();
|
||||
|
||||
public getAllKeys(): string[] {
|
||||
var result: string[] = [];
|
||||
|
||||
for (var k in this.table) {
|
||||
if (this.table[k] !== undefined) {
|
||||
result.push(k);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public add(key: string, data: T): boolean {
|
||||
if (this.table[key] !== undefined) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.table[key] = data;
|
||||
this.itemCount++;
|
||||
return true;
|
||||
}
|
||||
|
||||
public addOrUpdate(key: string, data: T): boolean {
|
||||
if (this.table[key] !== undefined) {
|
||||
this.table[key] = data;
|
||||
return false;
|
||||
}
|
||||
|
||||
this.table[key] = data;
|
||||
this.itemCount++;
|
||||
return true;
|
||||
}
|
||||
|
||||
public map(fn: (k: string, value: T, context: any) => void , context: any) {
|
||||
for (var k in this.table) {
|
||||
var data = this.table[k];
|
||||
|
||||
if (data !== undefined) {
|
||||
fn(k, this.table[k], context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public every(fn: (k: string, value: T, context: any) => void , context: any) {
|
||||
for (var k in this.table) {
|
||||
var data = this.table[k];
|
||||
|
||||
if (data !== undefined) {
|
||||
if (!fn(k, this.table[k], context)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public some(fn: (k: string, value: T, context: any) => void , context: any) {
|
||||
for (var k in this.table) {
|
||||
var data = this.table[k];
|
||||
|
||||
if (data !== undefined) {
|
||||
if (fn(k, this.table[k], context)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public count(): number {
|
||||
return this.itemCount;
|
||||
}
|
||||
|
||||
public lookup(key: string) : T {
|
||||
var data = this.table[key];
|
||||
return data === undefined ? null : data;
|
||||
}
|
||||
|
||||
public remove(key: string): void {
|
||||
if (this.table[key] !== undefined) {
|
||||
this.table[key] = undefined;
|
||||
this.itemCount--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export class IdentiferNameHashTable<T> extends StringHashTable<T> {
|
||||
public getAllKeys(): string[]{
|
||||
var result: string[] = [];
|
||||
|
||||
super.map((k, v, c) => {
|
||||
if (v !== undefined) {
|
||||
result.push(k.substring(1));
|
||||
}
|
||||
}, null);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public add(key: string, data: T): boolean {
|
||||
return super.add("#" + key, data);
|
||||
}
|
||||
|
||||
public addOrUpdate(key: string, data: T): boolean {
|
||||
return super.addOrUpdate("#" + key, data);
|
||||
}
|
||||
|
||||
public map(fn: (k: string, value: T, context: any) => void , context: any) {
|
||||
return super.map((k, v, c) => fn(k.substring(1), v, c), context);
|
||||
}
|
||||
|
||||
public every(fn: (k: string, value: T, context: any) => void , context: any) {
|
||||
return super.every((k, v, c) => fn(k.substring(1), v, c), context);
|
||||
}
|
||||
|
||||
public some(fn: (k: string, value: any, context: any) => void , context: any) {
|
||||
return super.some((k, v, c) => fn(k.substring(1), v, c), context);
|
||||
}
|
||||
|
||||
public lookup(key: string): T {
|
||||
return super.lookup("#" + key);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
module TypeScript {
|
||||
export class IdentifierWalker extends SyntaxWalker {
|
||||
constructor(public list: IIndexable<boolean>) {
|
||||
super();
|
||||
}
|
||||
|
||||
public visitToken(token: ISyntaxToken): void {
|
||||
this.list[token.text()] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,463 @@
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
///<reference path='enumerator.ts' />
|
||||
///<reference path='process.ts' />
|
||||
///<reference path='core\references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
|
||||
export interface IFindFileResult {
|
||||
fileInformation: FileInformation;
|
||||
path: string;
|
||||
}
|
||||
|
||||
export interface IFileWatcher {
|
||||
close(): void;
|
||||
}
|
||||
|
||||
export interface IIO {
|
||||
readFile(path: string, codepage: number): FileInformation;
|
||||
appendFile(path: string, contents: string): void;
|
||||
writeFile(path: string, contents: string, writeByteOrderMark: boolean): void;
|
||||
deleteFile(path: string): void;
|
||||
dir(path: string, re?: RegExp, options?: { recursive?: boolean; }): string[];
|
||||
fileExists(path: string): boolean;
|
||||
directoryExists(path: string): boolean;
|
||||
createDirectory(path: string): void;
|
||||
resolvePath(path: string): string;
|
||||
dirName(path: string): string;
|
||||
findFile(rootPath: string, partialFilePath: string): IFindFileResult;
|
||||
print(str: string): void;
|
||||
printLine(str: string): void;
|
||||
arguments: string[];
|
||||
stderr: ITextWriter;
|
||||
stdout: ITextWriter;
|
||||
watchFile(fileName: string, callback: (x: string) => void): IFileWatcher;
|
||||
run(source: string, fileName: string): void;
|
||||
getExecutingFilePath(): string;
|
||||
quit(exitCode?: number): void;
|
||||
}
|
||||
|
||||
export module IOUtils {
|
||||
// Creates the directory including its parent if not already present
|
||||
function createDirectoryStructure(ioHost: IIO, dirName: string) {
|
||||
if (ioHost.directoryExists(dirName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var parentDirectory = ioHost.dirName(dirName);
|
||||
if (parentDirectory != "") {
|
||||
createDirectoryStructure(ioHost, parentDirectory);
|
||||
}
|
||||
ioHost.createDirectory(dirName);
|
||||
}
|
||||
|
||||
// Creates a file including its directory structure if not already present
|
||||
export function writeFileAndFolderStructure(ioHost: IIO, fileName: string, contents: string, writeByteOrderMark: boolean): void {
|
||||
var start = new Date().getTime();
|
||||
var path = ioHost.resolvePath(fileName);
|
||||
TypeScript.ioHostResolvePathTime += new Date().getTime() - start;
|
||||
|
||||
var start = new Date().getTime();
|
||||
var dirName = ioHost.dirName(path);
|
||||
TypeScript.ioHostDirectoryNameTime += new Date().getTime() - start;
|
||||
|
||||
var start = new Date().getTime();
|
||||
createDirectoryStructure(ioHost, dirName);
|
||||
TypeScript.ioHostCreateDirectoryStructureTime += new Date().getTime() - start;
|
||||
|
||||
var start = new Date().getTime();
|
||||
ioHost.writeFile(path, contents, writeByteOrderMark);
|
||||
TypeScript.ioHostWriteFileTime += new Date().getTime() - start;
|
||||
}
|
||||
|
||||
export function throwIOError(message: string, error: Error) {
|
||||
var errorMessage = message;
|
||||
if (error && error.message) {
|
||||
errorMessage += (" " + error.message);
|
||||
}
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
export function combine(prefix: string, suffix: string): string {
|
||||
return prefix + "/" + suffix;
|
||||
}
|
||||
|
||||
export class BufferedTextWriter implements ITextWriter {
|
||||
public buffer = "";
|
||||
// Inner writer does not need a WriteLine method, since the BufferedTextWriter wraps it itself
|
||||
constructor(public writer: { Write: (str: string) => void; Close: () => void; }, public capacity = 1024) { }
|
||||
Write(str: string) {
|
||||
this.buffer += str;
|
||||
if (this.buffer.length >= this.capacity) {
|
||||
this.writer.Write(this.buffer);
|
||||
this.buffer = "";
|
||||
}
|
||||
}
|
||||
WriteLine(str: string) {
|
||||
this.Write(str + '\r\n');
|
||||
}
|
||||
Close() {
|
||||
this.writer.Write(this.buffer);
|
||||
this.writer.Close();
|
||||
this.buffer = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export var IO = (function () {
|
||||
|
||||
// Create an IO object for use inside WindowsScriptHost hosts
|
||||
// Depends on WSCript and FileSystemObject
|
||||
function getWindowsScriptHostIO(): IIO {
|
||||
var fso = new ActiveXObject("Scripting.FileSystemObject");
|
||||
var streamObjectPool: any[] = [];
|
||||
|
||||
function getStreamObject(): any {
|
||||
if (streamObjectPool.length > 0) {
|
||||
return streamObjectPool.pop();
|
||||
} else {
|
||||
return new ActiveXObject("ADODB.Stream");
|
||||
}
|
||||
}
|
||||
|
||||
function releaseStreamObject(obj: any) {
|
||||
streamObjectPool.push(obj);
|
||||
}
|
||||
|
||||
var args: any[] = [];
|
||||
for (var i = 0; i < WScript.Arguments.length; i++) {
|
||||
args[i] = WScript.Arguments.Item(i);
|
||||
}
|
||||
|
||||
return {
|
||||
appendFile: function (path: string, content: string) {
|
||||
var txtFile = fso.OpenTextFile(path, 8 /* append */, true /* create if file doesn't exist */);
|
||||
txtFile.Write(content);
|
||||
txtFile.Close();
|
||||
},
|
||||
readFile: function (path: string, codepage: number): FileInformation {
|
||||
return Environment.readFile(path, codepage);
|
||||
},
|
||||
|
||||
writeFile: function (path: string, contents: string, writeByteOrderMark: boolean) {
|
||||
Environment.writeFile(path, contents, writeByteOrderMark);
|
||||
},
|
||||
|
||||
fileExists: function (path: string): boolean {
|
||||
return fso.FileExists(path);
|
||||
},
|
||||
|
||||
resolvePath: function (path: string): string {
|
||||
return fso.GetAbsolutePathName(path);
|
||||
},
|
||||
|
||||
dirName: function (path: string): string {
|
||||
return fso.GetParentFolderName(path);
|
||||
},
|
||||
|
||||
findFile: function (rootPath: string, partialFilePath: string): IFindFileResult {
|
||||
var path = fso.GetAbsolutePathName(rootPath) + "/" + partialFilePath;
|
||||
|
||||
while (true) {
|
||||
if (fso.FileExists(path)) {
|
||||
return { fileInformation: this.readFile(path), path: path };
|
||||
}
|
||||
else {
|
||||
rootPath = fso.GetParentFolderName(fso.GetAbsolutePathName(rootPath));
|
||||
|
||||
if (rootPath == "") {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
path = fso.BuildPath(rootPath, partialFilePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
deleteFile: function (path: string): void {
|
||||
try {
|
||||
if (fso.FileExists(path)) {
|
||||
fso.DeleteFile(path, true); // true: delete read-only files
|
||||
}
|
||||
} catch (e) {
|
||||
IOUtils.throwIOError(TypeScript.getDiagnosticMessage(TypeScript.DiagnosticCode.Could_not_delete_file_0, [path]), e);
|
||||
}
|
||||
},
|
||||
|
||||
directoryExists: function (path) {
|
||||
return <boolean>fso.FolderExists(path);
|
||||
},
|
||||
|
||||
createDirectory: function (path) {
|
||||
try {
|
||||
if (!this.directoryExists(path)) {
|
||||
fso.CreateFolder(path);
|
||||
}
|
||||
} catch (e) {
|
||||
IOUtils.throwIOError(TypeScript.getDiagnosticMessage(TypeScript.DiagnosticCode.Could_not_create_directory_0, [path]), e);
|
||||
}
|
||||
},
|
||||
|
||||
dir: function (path, spec?, options?) {
|
||||
options = options || <{ recursive?: boolean; }>{};
|
||||
function filesInFolder(folder: any, root: string): string[] {
|
||||
var paths: string[] = [];
|
||||
var fc: Enumerator;
|
||||
|
||||
if (options.recursive) {
|
||||
fc = new Enumerator(folder.subfolders);
|
||||
|
||||
for (; !fc.atEnd(); fc.moveNext()) {
|
||||
paths = paths.concat(filesInFolder(fc.item(), root + "/" + fc.item().Name));
|
||||
}
|
||||
}
|
||||
|
||||
fc = new Enumerator(folder.files);
|
||||
|
||||
for (; !fc.atEnd(); fc.moveNext()) {
|
||||
if (!spec || fc.item().Name.match(spec)) {
|
||||
paths.push(root + "/" + fc.item().Name);
|
||||
}
|
||||
}
|
||||
|
||||
return paths;
|
||||
}
|
||||
|
||||
var folder = fso.GetFolder(path);
|
||||
var paths: string[] = [];
|
||||
|
||||
return filesInFolder(folder, path);
|
||||
},
|
||||
|
||||
print: function (str) {
|
||||
WScript.StdOut.Write(str);
|
||||
},
|
||||
|
||||
printLine: function (str) {
|
||||
WScript.Echo(str);
|
||||
},
|
||||
|
||||
arguments: <string[]>args,
|
||||
stderr: WScript.StdErr,
|
||||
stdout: WScript.StdOut,
|
||||
watchFile: null,
|
||||
run: function (source, fileName) {
|
||||
try {
|
||||
eval(source);
|
||||
} catch (e) {
|
||||
IOUtils.throwIOError(TypeScript.getDiagnosticMessage(TypeScript.DiagnosticCode.Error_while_executing_file_0, [fileName]), e);
|
||||
}
|
||||
},
|
||||
getExecutingFilePath: function () {
|
||||
return WScript.ScriptFullName;
|
||||
},
|
||||
quit: function (exitCode: number = 0) {
|
||||
try {
|
||||
WScript.Quit(exitCode);
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
// Create an IO object for use inside Node.js hosts
|
||||
// Depends on 'fs' and 'path' modules
|
||||
function getNodeIO(): IIO {
|
||||
|
||||
var _fs = require('fs');
|
||||
var _path = require('path');
|
||||
var _module = require('module');
|
||||
|
||||
return {
|
||||
appendFile: function (path: string, content: string) {
|
||||
_fs.appendFileSync(path, content);
|
||||
},
|
||||
readFile: function (file: string, codepage: number): FileInformation {
|
||||
return Environment.readFile(file, codepage);
|
||||
},
|
||||
|
||||
writeFile: function (path: string, contents: string, writeByteOrderMark: boolean) {
|
||||
Environment.writeFile(path, contents, writeByteOrderMark);
|
||||
},
|
||||
|
||||
deleteFile: function (path) {
|
||||
try {
|
||||
_fs.unlinkSync(path);
|
||||
} catch (e) {
|
||||
IOUtils.throwIOError(TypeScript.getDiagnosticMessage(TypeScript.DiagnosticCode.Could_not_delete_file_0, [path]), e);
|
||||
}
|
||||
},
|
||||
fileExists: function (path: string): boolean {
|
||||
return _fs.existsSync(path);
|
||||
},
|
||||
|
||||
dir: function dir(path, spec?, options?) {
|
||||
options = options || <{ recursive?: boolean; }>{};
|
||||
|
||||
function filesInFolder(folder: string): string[] {
|
||||
var paths: string[] = [];
|
||||
|
||||
try {
|
||||
var files = _fs.readdirSync(folder);
|
||||
for (var i = 0; i < files.length; i++) {
|
||||
var stat = _fs.statSync(folder + "/" + files[i]);
|
||||
if (options.recursive && stat.isDirectory()) {
|
||||
paths = paths.concat(filesInFolder(folder + "/" + files[i]));
|
||||
} else if (stat.isFile() && (!spec || files[i].match(spec))) {
|
||||
paths.push(folder + "/" + files[i]);
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
/*
|
||||
* Skip folders that are inaccessible
|
||||
*/
|
||||
}
|
||||
|
||||
return paths;
|
||||
}
|
||||
|
||||
return filesInFolder(path);
|
||||
},
|
||||
createDirectory: function (path: string): void {
|
||||
try {
|
||||
if (!this.directoryExists(path)) {
|
||||
_fs.mkdirSync(path);
|
||||
}
|
||||
} catch (e) {
|
||||
IOUtils.throwIOError(TypeScript.getDiagnosticMessage(TypeScript.DiagnosticCode.Could_not_create_directory_0, [path]), e);
|
||||
}
|
||||
},
|
||||
|
||||
directoryExists: function (path: string): boolean {
|
||||
return _fs.existsSync(path) && _fs.statSync(path).isDirectory();
|
||||
},
|
||||
resolvePath: function (path: string): string {
|
||||
return _path.resolve(path);
|
||||
},
|
||||
dirName: function (path: string): string {
|
||||
var dirPath = _path.dirname(path);
|
||||
|
||||
// Node will just continue to repeat the root path, rather than return null
|
||||
if (dirPath === path) {
|
||||
dirPath = null;
|
||||
}
|
||||
|
||||
return dirPath;
|
||||
},
|
||||
findFile: function (rootPath: string, partialFilePath: string): IFindFileResult {
|
||||
var path = rootPath + "/" + partialFilePath;
|
||||
|
||||
while (true) {
|
||||
if (_fs.existsSync(path)) {
|
||||
return { fileInformation: this.readFile(path), path: path };
|
||||
}
|
||||
else {
|
||||
var parentPath = _path.resolve(rootPath, "..");
|
||||
|
||||
// Node will just continue to repeat the root path, rather than return null
|
||||
if (rootPath === parentPath) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
rootPath = parentPath;
|
||||
path = _path.resolve(rootPath, partialFilePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
print: function (str) { process.stdout.write(str); },
|
||||
printLine: function (str) { process.stdout.write(str + '\n') },
|
||||
arguments: process.argv.slice(2),
|
||||
stderr: {
|
||||
Write: function (str) { process.stderr.write(str); },
|
||||
WriteLine: function (str) { process.stderr.write(str + '\n'); },
|
||||
Close: function () { }
|
||||
},
|
||||
stdout: {
|
||||
Write: function (str) { process.stdout.write(str); },
|
||||
WriteLine: function (str) { process.stdout.write(str + '\n'); },
|
||||
Close: function () { }
|
||||
},
|
||||
watchFile: function (fileName: string, callback: (x: string) => void): IFileWatcher {
|
||||
var firstRun = true;
|
||||
var processingChange = false;
|
||||
|
||||
var fileChanged: any = function (curr: any, prev: any) {
|
||||
if (!firstRun) {
|
||||
if (curr.mtime < prev.mtime) {
|
||||
return;
|
||||
}
|
||||
|
||||
_fs.unwatchFile(fileName, fileChanged);
|
||||
if (!processingChange) {
|
||||
processingChange = true;
|
||||
callback(fileName);
|
||||
setTimeout(function () { processingChange = false; }, 100);
|
||||
}
|
||||
}
|
||||
firstRun = false;
|
||||
_fs.watchFile(fileName, { persistent: true, interval: 500 }, fileChanged);
|
||||
};
|
||||
|
||||
fileChanged();
|
||||
return {
|
||||
fileName: fileName,
|
||||
close: function () {
|
||||
_fs.unwatchFile(fileName, fileChanged);
|
||||
}
|
||||
};
|
||||
},
|
||||
run: function (source, fileName) {
|
||||
require.main.fileName = fileName;
|
||||
require.main.paths = _module._nodeModulePaths(_path.dirname(_fs.realpathSync(fileName)));
|
||||
require.main._compile(source, fileName);
|
||||
},
|
||||
getExecutingFilePath: function () {
|
||||
return process.mainModule.filename;
|
||||
},
|
||||
quit: function (code?: number) {
|
||||
var stderrFlushed = process.stderr.write('');
|
||||
var stdoutFlushed = process.stdout.write('');
|
||||
process.stderr.on('drain', function () {
|
||||
stderrFlushed = true;
|
||||
if (stdoutFlushed) {
|
||||
process.exit(code);
|
||||
}
|
||||
});
|
||||
process.stdout.on('drain', function () {
|
||||
stdoutFlushed = true;
|
||||
if (stderrFlushed) {
|
||||
process.exit(code);
|
||||
}
|
||||
});
|
||||
setTimeout(function () {
|
||||
process.exit(code);
|
||||
}, 5);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (typeof WScript !== "undefined" && typeof ActiveXObject === "function")
|
||||
return getWindowsScriptHostIO();
|
||||
else if (typeof module !== 'undefined' && module.exports)
|
||||
return getNodeIO();
|
||||
else
|
||||
return null; // Unsupported host
|
||||
})();
|
||||
}
|
||||
@@ -0,0 +1,266 @@
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
///<reference path="io.ts" />
|
||||
|
||||
module TypeScript {
|
||||
export interface IOptions {
|
||||
name?: string;
|
||||
flag?: boolean;
|
||||
short?: string;
|
||||
usage?: {
|
||||
locCode: string; // DiagnosticCode
|
||||
args: string[]
|
||||
};
|
||||
set?: (s: string) => void;
|
||||
type?: string; // DiagnosticCode
|
||||
experimental?: boolean;
|
||||
}
|
||||
|
||||
export class OptionsParser {
|
||||
private DEFAULT_SHORT_FLAG = "-";
|
||||
private DEFAULT_LONG_FLAG = "--";
|
||||
|
||||
private printedVersion: boolean = false;
|
||||
|
||||
// Find the option record for the given string. Returns null if not found.
|
||||
private findOption(arg: string) {
|
||||
var upperCaseArg = arg && arg.toUpperCase();
|
||||
|
||||
for (var i = 0; i < this.options.length; i++) {
|
||||
var current = this.options[i];
|
||||
|
||||
if (upperCaseArg === (current.short && current.short.toUpperCase()) ||
|
||||
upperCaseArg === (current.name && current.name.toUpperCase())) {
|
||||
return current;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public unnamed: string[] = [];
|
||||
|
||||
public options: IOptions[] = [];
|
||||
|
||||
constructor(public host: IIO, public version: string) {
|
||||
}
|
||||
|
||||
public printUsage() {
|
||||
this.printVersion();
|
||||
|
||||
var optionsWord = getLocalizedText(DiagnosticCode.options, null);
|
||||
var fileWord = getLocalizedText(DiagnosticCode.file1, null);
|
||||
var tscSyntax = "tsc [" + optionsWord + "] [" + fileWord + " ..]";
|
||||
var syntaxHelp = getLocalizedText(DiagnosticCode.Syntax_0, [tscSyntax]);
|
||||
this.host.printLine(syntaxHelp);
|
||||
this.host.printLine("");
|
||||
this.host.printLine(getLocalizedText(DiagnosticCode.Examples, null) + " tsc hello.ts");
|
||||
this.host.printLine(" tsc --out foo.js foo.ts");
|
||||
this.host.printLine(" tsc @args.txt");
|
||||
this.host.printLine("");
|
||||
this.host.printLine(getLocalizedText(DiagnosticCode.Options, null));
|
||||
|
||||
var output: string[][] = [];
|
||||
var maxLength = 0;
|
||||
var i = 0;
|
||||
|
||||
this.options = this.options.sort(function (a, b) {
|
||||
var aName = a.name.toLowerCase();
|
||||
var bName = b.name.toLowerCase();
|
||||
|
||||
if (aName > bName) {
|
||||
return 1;
|
||||
} else if (aName < bName) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
|
||||
// Build up output array
|
||||
for (i = 0; i < this.options.length; i++) {
|
||||
var option = this.options[i];
|
||||
|
||||
if (option.experimental) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!option.usage) {
|
||||
break;
|
||||
}
|
||||
|
||||
var usageString = " ";
|
||||
var type = option.type ? (" " + TypeScript.getLocalizedText(option.type, null)) : "";
|
||||
|
||||
if (option.short) {
|
||||
usageString += this.DEFAULT_SHORT_FLAG + option.short + type + ", ";
|
||||
}
|
||||
|
||||
usageString += this.DEFAULT_LONG_FLAG + option.name + type;
|
||||
|
||||
output.push([usageString, TypeScript.getLocalizedText(option.usage.locCode, option.usage.args)]);
|
||||
|
||||
if (usageString.length > maxLength) {
|
||||
maxLength = usageString.length;
|
||||
}
|
||||
}
|
||||
|
||||
var fileDescription = getLocalizedText(DiagnosticCode.Insert_command_line_options_and_files_from_a_file, null);
|
||||
output.push([" @<" + fileWord + ">", fileDescription]);
|
||||
|
||||
// Print padded output
|
||||
for (i = 0; i < output.length; i++) {
|
||||
this.host.printLine(output[i][0] + (new Array(maxLength - output[i][0].length + 3)).join(" ") + output[i][1]);
|
||||
}
|
||||
}
|
||||
|
||||
public printVersion() {
|
||||
if (!this.printedVersion) {
|
||||
this.host.printLine(getLocalizedText(DiagnosticCode.Version_0, [this.version]));
|
||||
this.printedVersion = true;
|
||||
}
|
||||
}
|
||||
|
||||
public option(name: string, config: IOptions, short?: string) {
|
||||
if (!config) {
|
||||
config = <any>short;
|
||||
short = null;
|
||||
}
|
||||
|
||||
config.name = name;
|
||||
config.short = short;
|
||||
config.flag = false;
|
||||
|
||||
this.options.push(config);
|
||||
}
|
||||
|
||||
public flag(name: string, config: IOptions, short?: string) {
|
||||
if (!config) {
|
||||
config = <any>short;
|
||||
short = null;
|
||||
}
|
||||
|
||||
config.name = name;
|
||||
config.short = short;
|
||||
config.flag = true
|
||||
|
||||
this.options.push(config);
|
||||
}
|
||||
|
||||
// Parse an arguments string
|
||||
public parseString(argString: string) {
|
||||
var position = 0;
|
||||
var tokens = argString.match(/\s+|"|[^\s"]+/g);
|
||||
|
||||
function peek() {
|
||||
return tokens[position];
|
||||
}
|
||||
|
||||
function consume() {
|
||||
return tokens[position++];
|
||||
}
|
||||
|
||||
function consumeQuotedString() {
|
||||
var value = '';
|
||||
consume(); // skip opening quote.
|
||||
|
||||
var token = peek();
|
||||
|
||||
while (token && token !== '"') {
|
||||
consume();
|
||||
|
||||
value += token;
|
||||
|
||||
token = peek();
|
||||
}
|
||||
|
||||
consume(); // skip ending quote;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
var args: string[] = [];
|
||||
var currentArg = '';
|
||||
|
||||
while (position < tokens.length) {
|
||||
var token = peek();
|
||||
|
||||
if (token === '"') {
|
||||
currentArg += consumeQuotedString();
|
||||
} else if (token.match(/\s/)) {
|
||||
if (currentArg.length > 0) {
|
||||
args.push(currentArg);
|
||||
currentArg = '';
|
||||
}
|
||||
|
||||
consume();
|
||||
} else {
|
||||
consume();
|
||||
currentArg += token;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentArg.length > 0) {
|
||||
args.push(currentArg);
|
||||
}
|
||||
|
||||
this.parse(args);
|
||||
}
|
||||
|
||||
// Parse arguments as they come from the platform: split into arguments.
|
||||
public parse(args: string[]) {
|
||||
var position = 0;
|
||||
|
||||
function consume() {
|
||||
return args[position++];
|
||||
}
|
||||
|
||||
while (position < args.length) {
|
||||
var current = consume();
|
||||
var match = current.match(/^(--?|@)(.*)/);
|
||||
var value: any = null;
|
||||
|
||||
if (match) {
|
||||
if (match[1] === '@') {
|
||||
this.parseString(this.host.readFile(match[2], null).contents);
|
||||
} else {
|
||||
var arg = match[2];
|
||||
var option = this.findOption(arg);
|
||||
|
||||
if (option === null) {
|
||||
this.host.printLine(getDiagnosticMessage(DiagnosticCode.Unknown_option_0, [arg]));
|
||||
this.host.printLine(getLocalizedText(DiagnosticCode.Use_the_0_flag_to_see_options, ["--help"]));
|
||||
} else {
|
||||
if (!option.flag) {
|
||||
value = consume();
|
||||
if (value === undefined) {
|
||||
// No value provided
|
||||
this.host.printLine(getDiagnosticMessage(DiagnosticCode.Option_0_specified_without_1, [arg, getLocalizedText(option.type, null)]));
|
||||
this.host.printLine(getLocalizedText(DiagnosticCode.Use_the_0_flag_to_see_options, ["--help"]));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
option.set(value);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.unnamed.push(current);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export function stripStartAndEndQuotes(str: string) {
|
||||
var firstCharCode = str && str.charCodeAt(0);
|
||||
if (str && str.length >= 2 && firstCharCode === str.charCodeAt(str.length - 1) && (firstCharCode === CharacterCodes.singleQuote || firstCharCode === CharacterCodes.doubleQuote)) {
|
||||
return str.substring(1, str.length - 1);
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
export function isSingleQuoted(str: string) {
|
||||
return str && str.length >= 2 && str.charCodeAt(0) === str.charCodeAt(str.length - 1) && str.charCodeAt(0) === CharacterCodes.singleQuote;
|
||||
}
|
||||
|
||||
export function isDoubleQuoted(str: string) {
|
||||
return str && str.length >= 2 && str.charCodeAt(0) === str.charCodeAt(str.length - 1) && str.charCodeAt(0) === CharacterCodes.doubleQuote;
|
||||
}
|
||||
|
||||
export function isQuoted(str: string) {
|
||||
return isDoubleQuoted(str) || isSingleQuoted(str);
|
||||
}
|
||||
|
||||
export function quoteStr(str: string) {
|
||||
return "\"" + str + "\"";
|
||||
}
|
||||
|
||||
var switchToForwardSlashesRegEx = /\\/g;
|
||||
export function switchToForwardSlashes(path: string) {
|
||||
return path.replace(switchToForwardSlashesRegEx, "/");
|
||||
}
|
||||
|
||||
export function trimModName(modName: string) {
|
||||
// in case's it's a declare file...
|
||||
if (modName.length > 5 && modName.substring(modName.length - 5, modName.length) === ".d.ts") {
|
||||
return modName.substring(0, modName.length - 5);
|
||||
}
|
||||
if (modName.length > 3 && modName.substring(modName.length - 3, modName.length) === ".ts") {
|
||||
return modName.substring(0, modName.length - 3);
|
||||
}
|
||||
// in case's it's a .js file
|
||||
if (modName.length > 3 && modName.substring(modName.length - 3, modName.length) === ".js") {
|
||||
return modName.substring(0, modName.length - 3);
|
||||
}
|
||||
|
||||
return modName;
|
||||
}
|
||||
|
||||
export function getDeclareFilePath(fname: string) {
|
||||
return isTSFile(fname) ? changePathToDTS(fname) : changePathToDTS(fname);
|
||||
}
|
||||
|
||||
function isFileOfExtension(fname: string, ext: string) {
|
||||
var invariantFname = fname.toLocaleUpperCase();
|
||||
var invariantExt = ext.toLocaleUpperCase();
|
||||
var extLength = invariantExt.length;
|
||||
return invariantFname.length > extLength && invariantFname.substring(invariantFname.length - extLength, invariantFname.length) === invariantExt;
|
||||
}
|
||||
|
||||
export function isTSFile(fname: string) {
|
||||
return isFileOfExtension(fname, ".ts");
|
||||
}
|
||||
|
||||
export function isDTSFile(fname: string) {
|
||||
return isFileOfExtension(fname, ".d.ts");
|
||||
}
|
||||
|
||||
export function getPrettyName(modPath: string, quote=true, treatAsFileName=false): any {
|
||||
var modName = treatAsFileName ? switchToForwardSlashes(modPath) : trimModName(stripStartAndEndQuotes(modPath));
|
||||
var components = this.getPathComponents(modName);
|
||||
return components.length ? (quote ? quoteStr(components[components.length - 1]) : components[components.length - 1]) : modPath;
|
||||
}
|
||||
|
||||
export function getPathComponents(path: string) {
|
||||
return path.split("/");
|
||||
}
|
||||
|
||||
export function getRelativePathToFixedPath(fixedModFilePath: string, absoluteModPath: string, isAbsoultePathURL = true) {
|
||||
absoluteModPath = switchToForwardSlashes(absoluteModPath);
|
||||
|
||||
var modComponents = this.getPathComponents(absoluteModPath);
|
||||
var fixedModComponents = this.getPathComponents(fixedModFilePath);
|
||||
|
||||
// Find the component that differs
|
||||
var joinStartIndex = 0;
|
||||
for (; joinStartIndex < modComponents.length && joinStartIndex < fixedModComponents.length ; joinStartIndex++) {
|
||||
if (fixedModComponents[joinStartIndex] !== modComponents[joinStartIndex]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Get the relative path
|
||||
if (joinStartIndex !== 0) {
|
||||
var relativePath = "";
|
||||
var relativePathComponents = modComponents.slice(joinStartIndex, modComponents.length);
|
||||
for (; joinStartIndex < fixedModComponents.length; joinStartIndex++) {
|
||||
if (fixedModComponents[joinStartIndex] !== "") {
|
||||
relativePath = relativePath + "../";
|
||||
}
|
||||
}
|
||||
|
||||
return relativePath + relativePathComponents.join("/");
|
||||
}
|
||||
|
||||
if (isAbsoultePathURL && absoluteModPath.indexOf("://") === -1) {
|
||||
absoluteModPath = "file:///" + absoluteModPath;
|
||||
}
|
||||
|
||||
return absoluteModPath;
|
||||
}
|
||||
|
||||
export function changePathToDTS(modPath: string) {
|
||||
return trimModName(stripStartAndEndQuotes(modPath)) + ".d.ts";
|
||||
}
|
||||
|
||||
export function isRelative(path: string) {
|
||||
return path.length > 0 && path.charAt(0) === ".";
|
||||
}
|
||||
export function isRooted(path: string) {
|
||||
return path.length > 0 && (path.charAt(0) === "\\" || path.charAt(0) === "/" || (path.indexOf(":\\") !== -1) || (path.indexOf(":/") !== -1));
|
||||
}
|
||||
|
||||
export function getRootFilePath(outFname: string) {
|
||||
if (outFname === "") {
|
||||
return outFname;
|
||||
}
|
||||
else {
|
||||
var isPath = outFname.indexOf("/") !== -1;
|
||||
return isPath ? filePath(outFname) : "";
|
||||
}
|
||||
}
|
||||
|
||||
export function filePathComponents(fullPath: string) {
|
||||
fullPath = switchToForwardSlashes(fullPath);
|
||||
var components = getPathComponents(fullPath);
|
||||
return components.slice(0, components.length - 1);
|
||||
}
|
||||
|
||||
export function filePath(fullPath: string) {
|
||||
var path = filePathComponents(fullPath);
|
||||
return path.join("/") + "/";
|
||||
}
|
||||
|
||||
export function convertToDirectoryPath(dirPath: string) {
|
||||
if (dirPath && dirPath.charAt(dirPath.length - 1) !== "/") {
|
||||
dirPath += "/";
|
||||
}
|
||||
|
||||
return dirPath;
|
||||
}
|
||||
|
||||
var normalizePathRegEx = /^\\\\[^\\]/;
|
||||
export function normalizePath(path: string): string {
|
||||
// If it's a UNC style path (i.e. \\server\share), convert to a URI style (i.e. file://server/share)
|
||||
if (normalizePathRegEx.test(path)) {
|
||||
path = "file:" + path;
|
||||
}
|
||||
var parts = this.getPathComponents(switchToForwardSlashes(path));
|
||||
var normalizedParts: string[] = [];
|
||||
|
||||
for (var i = 0; i < parts.length; i++) {
|
||||
var part = parts[i];
|
||||
if (part === ".") {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (normalizedParts.length > 0 && ArrayUtilities.last(normalizedParts) !== ".." && part === "..") {
|
||||
normalizedParts.pop();
|
||||
continue;
|
||||
}
|
||||
|
||||
normalizedParts.push(part);
|
||||
}
|
||||
|
||||
return normalizedParts.join("/");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
///
|
||||
/// Preprocessing
|
||||
///
|
||||
export interface IPreProcessedFileInfo {
|
||||
referencedFiles: IFileReference[];
|
||||
importedFiles: IFileReference[];
|
||||
diagnostics: Diagnostic[];
|
||||
isLibFile: boolean;
|
||||
}
|
||||
|
||||
interface ITripleSlashDirectiveProperties {
|
||||
noDefaultLib: boolean;
|
||||
diagnostics: Diagnostic[];
|
||||
referencedFiles: IFileReference[];
|
||||
}
|
||||
|
||||
function isNoDefaultLibMatch(comment: string): RegExpExecArray {
|
||||
var isNoDefaultLibRegex = /^(\/\/\/\s*<reference\s+no-default-lib=)('|")(.+?)\2\s*\/>/gim;
|
||||
return isNoDefaultLibRegex.exec(comment);
|
||||
}
|
||||
|
||||
export var tripleSlashReferenceRegExp = /^(\/\/\/\s*<reference\s+path=)('|")(.+?)\2\s*(static=('|")(.+?)\2\s*)*\/>/;
|
||||
|
||||
function getFileReferenceFromReferencePath(fileName: string, lineMap: LineMap, position: number, comment: string, diagnostics: Diagnostic[]): IFileReference {
|
||||
// First, just see if they've written: /// <reference\s+
|
||||
// If so, then we'll consider this a reference directive and we'll report errors if it's
|
||||
// malformed. Otherwise, we'll completely ignore this.
|
||||
|
||||
var simpleReferenceRegEx = /^\/\/\/\s*<reference\s+/gim;
|
||||
if (simpleReferenceRegEx.exec(comment)) {
|
||||
var isNoDefaultLib = isNoDefaultLibMatch(comment);
|
||||
|
||||
if (!isNoDefaultLib) {
|
||||
var fullReferenceRegEx = tripleSlashReferenceRegExp;
|
||||
var fullReference = fullReferenceRegEx.exec(comment);
|
||||
|
||||
if (!fullReference) {
|
||||
// It matched the start of a reference directive, but wasn't well formed. Report
|
||||
// an appropriate error to the user.
|
||||
diagnostics.push(new Diagnostic(fileName, lineMap, position, comment.length, DiagnosticCode.Invalid_reference_directive_syntax));
|
||||
}
|
||||
else {
|
||||
var path: string = normalizePath(fullReference[3]);
|
||||
var adjustedPath = normalizePath(path);
|
||||
|
||||
var isResident = fullReference.length >= 7 && fullReference[6] === "true";
|
||||
if (isResident) {
|
||||
CompilerDiagnostics.debugPrint(path + " is resident");
|
||||
}
|
||||
return {
|
||||
line: 0,
|
||||
character: 0,
|
||||
position: 0,
|
||||
length: 0,
|
||||
path: switchToForwardSlashes(adjustedPath),
|
||||
isResident: isResident
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
var scannerWindow = ArrayUtilities.createArray<number>(2048, 0);
|
||||
var scannerDiagnostics: any[] = [];
|
||||
|
||||
function processImports(lineMap: LineMap, scanner: Scanner, token: ISyntaxToken, importedFiles: IFileReference[]): void {
|
||||
var position = 0;
|
||||
var lineChar = { line: -1, character: -1 };
|
||||
|
||||
var start = new Date().getTime();
|
||||
// Look for:
|
||||
// import foo = module("foo")
|
||||
while (token.tokenKind !== SyntaxKind.EndOfFileToken) {
|
||||
if (token.tokenKind === SyntaxKind.ImportKeyword) {
|
||||
var importStart = position + token.leadingTriviaWidth();
|
||||
token = scanner.scan(scannerDiagnostics, /*allowRegularExpression:*/ false);
|
||||
|
||||
if (SyntaxFacts.isIdentifierNameOrAnyKeyword(token)) {
|
||||
token = scanner.scan(scannerDiagnostics, /*allowRegularExpression:*/ false);
|
||||
|
||||
if (token.tokenKind === SyntaxKind.EqualsToken) {
|
||||
token = scanner.scan(scannerDiagnostics, /*allowRegularExpression:*/ false);
|
||||
|
||||
if (token.tokenKind === SyntaxKind.ModuleKeyword || token.tokenKind === SyntaxKind.RequireKeyword) {
|
||||
token = scanner.scan(scannerDiagnostics, /*allowRegularExpression:*/ false);
|
||||
|
||||
if (token.tokenKind === SyntaxKind.OpenParenToken) {
|
||||
var afterOpenParenPosition = scanner.absoluteIndex();
|
||||
token = scanner.scan(scannerDiagnostics, /*allowRegularExpression:*/ false);
|
||||
|
||||
lineMap.fillLineAndCharacterFromPosition(importStart, lineChar);
|
||||
|
||||
if (token.tokenKind === SyntaxKind.StringLiteral) {
|
||||
var ref = {
|
||||
line: lineChar.line,
|
||||
character: lineChar.character,
|
||||
position: afterOpenParenPosition + token.leadingTriviaWidth(),
|
||||
length: token.width(),
|
||||
path: stripStartAndEndQuotes(switchToForwardSlashes(token.text())),
|
||||
isResident: false
|
||||
};
|
||||
importedFiles.push(ref);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
position = scanner.absoluteIndex();
|
||||
token = scanner.scan(scannerDiagnostics, /*allowRegularExpression:*/ false);
|
||||
}
|
||||
|
||||
var totalTime = new Date().getTime() - start;
|
||||
TypeScript.fileResolutionScanImportsTime += totalTime;
|
||||
}
|
||||
|
||||
function processTripleSlashDirectives(fileName: string, lineMap: LineMap, firstToken: ISyntaxToken): ITripleSlashDirectiveProperties {
|
||||
var leadingTrivia = firstToken.leadingTrivia();
|
||||
|
||||
var position = 0;
|
||||
var lineChar = { line: -1, character: -1 };
|
||||
var noDefaultLib = false;
|
||||
var diagnostics: Diagnostic[] = [];
|
||||
var referencedFiles: IFileReference[] = [];
|
||||
|
||||
for (var i = 0, n = leadingTrivia.count(); i < n; i++) {
|
||||
var trivia = leadingTrivia.syntaxTriviaAt(i);
|
||||
|
||||
if (trivia.kind() === SyntaxKind.SingleLineCommentTrivia) {
|
||||
var triviaText = trivia.fullText();
|
||||
var referencedCode = getFileReferenceFromReferencePath(fileName, lineMap, position, triviaText, diagnostics);
|
||||
|
||||
if (referencedCode) {
|
||||
lineMap.fillLineAndCharacterFromPosition(position, lineChar);
|
||||
referencedCode.position = position;
|
||||
referencedCode.length = trivia.fullWidth();
|
||||
referencedCode.line = lineChar.line;
|
||||
referencedCode.character = lineChar.character;
|
||||
|
||||
referencedFiles.push(referencedCode);
|
||||
}
|
||||
|
||||
// is it a lib file?
|
||||
var isNoDefaultLib = isNoDefaultLibMatch(triviaText);
|
||||
if (isNoDefaultLib) {
|
||||
noDefaultLib = isNoDefaultLib[3] === "true";
|
||||
}
|
||||
}
|
||||
|
||||
position += trivia.fullWidth();
|
||||
}
|
||||
|
||||
return { noDefaultLib: noDefaultLib, diagnostics: diagnostics, referencedFiles: referencedFiles };
|
||||
}
|
||||
|
||||
export function preProcessFile(fileName: string, sourceText: IScriptSnapshot, readImportFiles = true): IPreProcessedFileInfo {
|
||||
var text = SimpleText.fromScriptSnapshot(sourceText);
|
||||
var scanner = new Scanner(fileName, text, LanguageVersion.EcmaScript5, scannerWindow);
|
||||
|
||||
var firstToken = scanner.scan(scannerDiagnostics, /*allowRegularExpression:*/ false);
|
||||
|
||||
// only search out dynamic mods
|
||||
// if you find a dynamic mod, ignore every other mod inside, until you balance rcurlies
|
||||
// var position
|
||||
|
||||
var importedFiles: IFileReference[] = [];
|
||||
if (readImportFiles) {
|
||||
processImports(text.lineMap(), scanner, firstToken, importedFiles);
|
||||
}
|
||||
|
||||
var properties = processTripleSlashDirectives(fileName, text.lineMap(), firstToken);
|
||||
|
||||
scannerDiagnostics.length = 0;
|
||||
return { referencedFiles: properties.referencedFiles, importedFiles: importedFiles, isLibFile: properties.noDefaultLib, diagnostics: properties.diagnostics };
|
||||
}
|
||||
|
||||
export function getParseOptions(settings: ImmutableCompilationSettings): ParseOptions {
|
||||
return new ParseOptions(settings.codeGenTarget(), settings.allowAutomaticSemicolonInsertion());
|
||||
}
|
||||
|
||||
export function getReferencedFiles(fileName: string, sourceText: IScriptSnapshot): IFileReference[] {
|
||||
return preProcessFile(fileName, sourceText, false).referencedFiles;
|
||||
}
|
||||
} // Tools
|
||||
@@ -0,0 +1,17 @@
|
||||
declare module process {
|
||||
export var argv: string[];
|
||||
export var platform: string;
|
||||
export function on(event: string, handler: (arg: any) => void ): void;
|
||||
export module stdout {
|
||||
export function write(str: string): any;
|
||||
export function on(event: string, action: () => void ): void;
|
||||
}
|
||||
export module stderr {
|
||||
export function write(str: string): any;
|
||||
export function on(event: string, action: () => void): void;
|
||||
}
|
||||
export module mainModule {
|
||||
export var filename: string;
|
||||
}
|
||||
export function exit(exitCode?: number): any;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
|
||||
// Note: This is being using by the host (VS) and is marshaled back and forth. When changing this make sure the changes
|
||||
// are reflected in the managed side as well.
|
||||
export interface IFileReference extends ILineAndCharacter {
|
||||
path: string;
|
||||
isResident: boolean;
|
||||
position: number;
|
||||
length: number;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,255 @@
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export interface IResolvedFile {
|
||||
path: string;
|
||||
referencedFiles: string[];
|
||||
importedFiles: string[];
|
||||
}
|
||||
|
||||
export interface IReferenceResolverHost {
|
||||
getScriptSnapshot(fileName: string): TypeScript.IScriptSnapshot;
|
||||
resolveRelativePath(path: string, directory: string): string;
|
||||
fileExists(path: string): boolean;
|
||||
directoryExists(path: string): boolean;
|
||||
getParentDirectory(path: string): string;
|
||||
}
|
||||
|
||||
export class ReferenceResolutionResult {
|
||||
resolvedFiles: IResolvedFile[] = [];
|
||||
diagnostics: TypeScript.Diagnostic[] = [];
|
||||
seenNoDefaultLibTag: boolean = false;
|
||||
}
|
||||
|
||||
class ReferenceLocation {
|
||||
constructor(public filePath: string, public lineMap: LineMap, public position: number, public length: number, public isImported: boolean) {
|
||||
}
|
||||
}
|
||||
|
||||
export class ReferenceResolver {
|
||||
private inputFileNames: string[];
|
||||
private host: IReferenceResolverHost;
|
||||
private visited: IIndexable<string>;
|
||||
|
||||
constructor(inputFileNames: string[], host: IReferenceResolverHost, private useCaseSensitiveFileResolution: boolean) {
|
||||
this.inputFileNames = inputFileNames;
|
||||
this.host = host;
|
||||
this.visited = {};
|
||||
}
|
||||
|
||||
public static resolve(inputFileNames: string[], host: IReferenceResolverHost, useCaseSensitiveFileResolution: boolean): ReferenceResolutionResult {
|
||||
var resolver = new ReferenceResolver(inputFileNames, host, useCaseSensitiveFileResolution);
|
||||
return resolver.resolveInputFiles();
|
||||
}
|
||||
|
||||
public resolveInputFiles(): ReferenceResolutionResult {
|
||||
var result = new ReferenceResolutionResult();
|
||||
|
||||
if (!this.inputFileNames || this.inputFileNames.length <= 0) {
|
||||
// Nothing to do.
|
||||
return result;
|
||||
}
|
||||
|
||||
// Loop over the files and extract references
|
||||
var referenceLocation = new ReferenceLocation(null, null, 0, 0, false);
|
||||
this.inputFileNames.forEach(fileName =>
|
||||
this.resolveIncludedFile(fileName, referenceLocation, result));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private resolveIncludedFile(path: string, referenceLocation: ReferenceLocation, resolutionResult: ReferenceResolutionResult): string {
|
||||
var normalizedPath = this.getNormalizedFilePath(path, referenceLocation.filePath);
|
||||
|
||||
if (this.isSameFile(normalizedPath, referenceLocation.filePath)) {
|
||||
// Cannot reference self
|
||||
if (!referenceLocation.isImported) {
|
||||
resolutionResult.diagnostics.push(
|
||||
new TypeScript.Diagnostic(referenceLocation.filePath, referenceLocation.lineMap,
|
||||
referenceLocation.position, referenceLocation.length, DiagnosticCode.A_file_cannot_have_a_reference_to_itself, null));
|
||||
}
|
||||
|
||||
return normalizedPath;
|
||||
}
|
||||
|
||||
if (!isTSFile(normalizedPath) && !isDTSFile(normalizedPath)) {
|
||||
var dtsFile = normalizedPath + ".d.ts";
|
||||
var tsFile = normalizedPath + ".ts";
|
||||
|
||||
if (this.host.fileExists(tsFile)) {
|
||||
normalizedPath = tsFile;
|
||||
}
|
||||
else {
|
||||
normalizedPath = dtsFile;
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.host.fileExists(normalizedPath)) {
|
||||
if (!referenceLocation.isImported) {
|
||||
resolutionResult.diagnostics.push(
|
||||
new TypeScript.Diagnostic(referenceLocation.filePath, referenceLocation.lineMap,
|
||||
referenceLocation.position, referenceLocation.length, DiagnosticCode.Cannot_resolve_referenced_file_0, [path]));
|
||||
}
|
||||
|
||||
return normalizedPath;
|
||||
}
|
||||
|
||||
// Preprocess the file and resolve its imports/references
|
||||
return this.resolveFile(normalizedPath, resolutionResult);
|
||||
}
|
||||
|
||||
private resolveImportedFile(path: string, referenceLocation: ReferenceLocation, resolutionResult: ReferenceResolutionResult): string {
|
||||
var isRelativePath = TypeScript.isRelative(path);
|
||||
var isRootedPath = isRelativePath ? false : isRooted(path);
|
||||
|
||||
if (isRelativePath || isRootedPath) {
|
||||
// Handle as a normal include file
|
||||
return this.resolveIncludedFile(path, referenceLocation, resolutionResult);
|
||||
}
|
||||
else {
|
||||
// Search for the file
|
||||
var parentDirectory = this.host.getParentDirectory(referenceLocation.filePath);
|
||||
var searchFilePath: string = null;
|
||||
var dtsFileName = path + ".d.ts";
|
||||
var tsFilePath = path + ".ts";
|
||||
|
||||
var start = new Date().getTime();
|
||||
|
||||
// SPEC: Nov 18
|
||||
// An external import declaration that specifies a relative external module name (section 11.2.1) resolves the name
|
||||
// relative to the directory of the containing source file.
|
||||
// If a source file with the resulting path and file extension '.ts' exists, that file is added as a dependency.
|
||||
// Otherwise, if a source file with the resulting path and file extension '.d.ts' exists, that file is added as a dependency.
|
||||
do {
|
||||
// Search for ".ts" file first
|
||||
currentFilePath = this.host.resolveRelativePath(tsFilePath, parentDirectory);
|
||||
if (this.host.fileExists(currentFilePath)) {
|
||||
// Found the file
|
||||
searchFilePath = currentFilePath;
|
||||
break;
|
||||
}
|
||||
|
||||
// Search for ".d.ts" file
|
||||
var currentFilePath = this.host.resolveRelativePath(dtsFileName, parentDirectory);
|
||||
if (this.host.fileExists(currentFilePath)) {
|
||||
// Found the file
|
||||
searchFilePath = currentFilePath;
|
||||
break;
|
||||
}
|
||||
|
||||
parentDirectory = this.host.getParentDirectory(parentDirectory);
|
||||
}
|
||||
while (parentDirectory);
|
||||
|
||||
TypeScript.fileResolutionImportFileSearchTime += new Date().getTime() - start;
|
||||
|
||||
if (!searchFilePath) {
|
||||
// Cannot find file import, do not reprot an error, the typeChecker will report it later on
|
||||
return path;
|
||||
}
|
||||
|
||||
// Preprocess the file and resolve its imports/references
|
||||
return this.resolveFile(searchFilePath, resolutionResult);
|
||||
}
|
||||
}
|
||||
|
||||
private resolveFile(normalizedPath: string, resolutionResult: ReferenceResolutionResult): string {
|
||||
// If we have processed this file before, skip it
|
||||
var visitedPath = this.isVisited(normalizedPath);
|
||||
if (!visitedPath) {
|
||||
// Record that we have seen it
|
||||
this.recordVisitedFile(normalizedPath);
|
||||
|
||||
// Preprocess the file
|
||||
var start = new Date().getTime();
|
||||
var scriptSnapshot = this.host.getScriptSnapshot(normalizedPath);
|
||||
var totalTime = new Date().getTime() - start;
|
||||
TypeScript.fileResolutionIOTime += totalTime;
|
||||
|
||||
var lineMap = LineMap1.fromScriptSnapshot(scriptSnapshot);
|
||||
var preprocessedFileInformation = TypeScript.preProcessFile(normalizedPath, scriptSnapshot);
|
||||
resolutionResult.diagnostics.push.apply(resolutionResult.diagnostics, preprocessedFileInformation.diagnostics);
|
||||
|
||||
// If this file has a "no-default-lib = 'true'" tag
|
||||
if (preprocessedFileInformation.isLibFile) {
|
||||
resolutionResult.seenNoDefaultLibTag = true;
|
||||
}
|
||||
|
||||
// Resolve explicit references
|
||||
var normalizedReferencePaths: string[] = [];
|
||||
preprocessedFileInformation.referencedFiles.forEach(fileReference => {
|
||||
var currentReferenceLocation = new ReferenceLocation(normalizedPath, lineMap, fileReference.position, fileReference.length, /* isImported */ false);
|
||||
var normalizedReferencePath = this.resolveIncludedFile(fileReference.path, currentReferenceLocation, resolutionResult);
|
||||
normalizedReferencePaths.push(normalizedReferencePath);
|
||||
});
|
||||
|
||||
// Resolve imports
|
||||
var normalizedImportPaths: string[] = [];
|
||||
for (var i = 0; i < preprocessedFileInformation.importedFiles.length; i++) {
|
||||
var fileImport = preprocessedFileInformation.importedFiles[i];
|
||||
var currentReferenceLocation = new ReferenceLocation(normalizedPath, lineMap, fileImport.position, fileImport.length, /* isImported */ true);
|
||||
var normalizedImportPath = this.resolveImportedFile(fileImport.path, currentReferenceLocation, resolutionResult);
|
||||
normalizedImportPaths.push(normalizedImportPath);
|
||||
}
|
||||
|
||||
// Add the file to the result list
|
||||
resolutionResult.resolvedFiles.push({
|
||||
path: normalizedPath,
|
||||
referencedFiles: normalizedReferencePaths,
|
||||
importedFiles: normalizedImportPaths
|
||||
});
|
||||
}
|
||||
else {
|
||||
normalizedPath = visitedPath;
|
||||
}
|
||||
|
||||
return normalizedPath;
|
||||
}
|
||||
|
||||
private getNormalizedFilePath(path: string, parentFilePath: string): string {
|
||||
var parentFileDirectory = parentFilePath ? this.host.getParentDirectory(parentFilePath) : "";
|
||||
var normalizedPath = this.host.resolveRelativePath(path, parentFileDirectory);
|
||||
return normalizedPath;
|
||||
}
|
||||
|
||||
private getUniqueFileId(filePath: string): string {
|
||||
return this.useCaseSensitiveFileResolution ? filePath : filePath.toLocaleUpperCase();
|
||||
}
|
||||
|
||||
private recordVisitedFile(filePath: string): void {
|
||||
this.visited[this.getUniqueFileId(filePath)] = filePath;
|
||||
}
|
||||
|
||||
private isVisited(filePath: string): string {
|
||||
return this.visited[this.getUniqueFileId(filePath)];
|
||||
}
|
||||
|
||||
private isSameFile(filePath1: string, filePath2: string): boolean {
|
||||
if (!filePath1 || !filePath2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.useCaseSensitiveFileResolution) {
|
||||
return filePath1 === filePath2;
|
||||
}
|
||||
else {
|
||||
return filePath1.toLocaleUpperCase() === filePath2.toLocaleUpperCase();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
///<reference path='resources\references.ts' />
|
||||
///<reference path='core\references.ts' />
|
||||
///<reference path='text\references.ts' />
|
||||
///<reference path='syntax\references.ts' />
|
||||
///<reference path='diagnostics.ts' />
|
||||
///<reference path='document.ts' />
|
||||
///<reference path='flags.ts' />
|
||||
///<reference path='hashTable.ts' />
|
||||
///<reference path='ast.ts' />
|
||||
///<reference path='astHelpers.ts' />
|
||||
///<reference path='astWalker.ts' />
|
||||
///<reference path='base64.ts' />
|
||||
///<reference path='sourceMapping.ts' />
|
||||
///<reference path='emitter.ts' />
|
||||
///<reference path='types.ts' />
|
||||
///<reference path='pathUtils.ts' />
|
||||
///<reference path='referenceResolution.ts' />
|
||||
///<reference path='precompile.ts' />
|
||||
///<reference path='referenceResolver.ts' />
|
||||
///<reference path='declarationEmitter.ts' />
|
||||
///<reference path='bloomFilter.ts' />
|
||||
///<reference path='identifierWalker.ts' />
|
||||
///<reference path='settings.ts' />
|
||||
///<reference path='typecheck\pullFlags.ts' />
|
||||
///<reference path='typecheck\pullDecls.ts' />
|
||||
///<reference path='typecheck\pullSymbols.ts' />
|
||||
///<reference path='typecheck\pullTypeEnclosingTypeWalker.ts' />
|
||||
///<reference path='typecheck\pullTypeResolutionContext.ts' />
|
||||
///<reference path='typecheck\pullTypeResolution.ts' />
|
||||
///<reference path='typecheck\pullSemanticInfo.ts' />
|
||||
///<reference path='typecheck\pullDeclCollection.ts' />
|
||||
///<reference path='typecheck\pullSymbolBinder.ts' />
|
||||
///<reference path='typecheck\pullHelpers.ts' />
|
||||
///<reference path='typecheck\pullInstantiationHelpers.ts' />
|
||||
|
||||
///<reference path='typecheck\pullTypeInstantiation.ts' />
|
||||
///<reference path='syntaxTreeToAstVisitor.ts' />
|
||||
///<reference path='typescript.ts' />
|
||||
@@ -0,0 +1,367 @@
|
||||
var TypeScript;
|
||||
(function (TypeScript) {
|
||||
TypeScript.DiagnosticCode = {
|
||||
error_TS_0_1: "error TS{0}: {1}",
|
||||
warning_TS_0_1: "warning TS{0}: {1}",
|
||||
Unrecognized_escape_sequence: "Unrecognized escape sequence.",
|
||||
Unexpected_character_0: "Unexpected character {0}.",
|
||||
Missing_close_quote_character: "Missing close quote character.",
|
||||
Identifier_expected: "Identifier expected.",
|
||||
_0_keyword_expected: "'{0}' keyword expected.",
|
||||
_0_expected: "'{0}' expected.",
|
||||
Identifier_expected_0_is_a_keyword: "Identifier expected; '{0}' is a keyword.",
|
||||
Automatic_semicolon_insertion_not_allowed: "Automatic semicolon insertion not allowed.",
|
||||
Unexpected_token_0_expected: "Unexpected token; '{0}' expected.",
|
||||
Trailing_separator_not_allowed: "Trailing separator not allowed.",
|
||||
AsteriskSlash_expected: "'*/' expected.",
|
||||
public_or_private_modifier_must_precede_static: "'public' or 'private' modifier must precede 'static'.",
|
||||
Unexpected_token: "Unexpected token.",
|
||||
Catch_clause_parameter_cannot_have_a_type_annotation: "Catch clause parameter cannot have a type annotation.",
|
||||
Rest_parameter_must_be_last_in_list: "Rest parameter must be last in list.",
|
||||
Parameter_cannot_have_question_mark_and_initializer: "Parameter cannot have question mark and initializer.",
|
||||
Required_parameter_cannot_follow_optional_parameter: "Required parameter cannot follow optional parameter.",
|
||||
Index_signatures_cannot_have_rest_parameters: "Index signatures cannot have rest parameters.",
|
||||
Index_signature_parameter_cannot_have_accessibility_modifiers: "Index signature parameter cannot have accessibility modifiers.",
|
||||
Index_signature_parameter_cannot_have_a_question_mark: "Index signature parameter cannot have a question mark.",
|
||||
Index_signature_parameter_cannot_have_an_initializer: "Index signature parameter cannot have an initializer.",
|
||||
Index_signature_must_have_a_type_annotation: "Index signature must have a type annotation.",
|
||||
Index_signature_parameter_must_have_a_type_annotation: "Index signature parameter must have a type annotation.",
|
||||
Index_signature_parameter_type_must_be_string_or_number: "Index signature parameter type must be 'string' or 'number'.",
|
||||
extends_clause_already_seen: "'extends' clause already seen.",
|
||||
extends_clause_must_precede_implements_clause: "'extends' clause must precede 'implements' clause.",
|
||||
Classes_can_only_extend_a_single_class: "Classes can only extend a single class.",
|
||||
implements_clause_already_seen: "'implements' clause already seen.",
|
||||
Accessibility_modifier_already_seen: "Accessibility modifier already seen.",
|
||||
_0_modifier_must_precede_1_modifier: "'{0}' modifier must precede '{1}' modifier.",
|
||||
_0_modifier_already_seen: "'{0}' modifier already seen.",
|
||||
_0_modifier_cannot_appear_on_a_class_element: "'{0}' modifier cannot appear on a class element.",
|
||||
Interface_declaration_cannot_have_implements_clause: "Interface declaration cannot have 'implements' clause.",
|
||||
super_invocation_cannot_have_type_arguments: "'super' invocation cannot have type arguments.",
|
||||
Only_ambient_modules_can_use_quoted_names: "Only ambient modules can use quoted names.",
|
||||
Statements_are_not_allowed_in_ambient_contexts: "Statements are not allowed in ambient contexts.",
|
||||
Implementations_are_not_allowed_in_ambient_contexts: "Implementations are not allowed in ambient contexts.",
|
||||
declare_modifier_not_allowed_for_code_already_in_an_ambient_context: "'declare' modifier not allowed for code already in an ambient context.",
|
||||
Initializers_are_not_allowed_in_ambient_contexts: "Initializers are not allowed in ambient contexts.",
|
||||
Parameter_property_declarations_can_only_be_used_in_constructors: "Parameter property declarations can only be used in constructors.",
|
||||
Function_implementation_expected: "Function implementation expected.",
|
||||
Constructor_implementation_expected: "Constructor implementation expected.",
|
||||
Function_overload_name_must_be_0: "Function overload name must be '{0}'.",
|
||||
_0_modifier_cannot_appear_on_a_module_element: "'{0}' modifier cannot appear on a module element.",
|
||||
declare_modifier_cannot_appear_on_an_interface_declaration: "'declare' modifier cannot appear on an interface declaration.",
|
||||
declare_modifier_required_for_top_level_element: "'declare' modifier required for top level element.",
|
||||
Rest_parameter_cannot_be_optional: "Rest parameter cannot be optional.",
|
||||
Rest_parameter_cannot_have_an_initializer: "Rest parameter cannot have an initializer.",
|
||||
set_accessor_must_have_one_and_only_one_parameter: "'set' accessor must have one and only one parameter.",
|
||||
set_accessor_parameter_cannot_have_accessibility_modifier: "'set' accessor parameter cannot have accessibility modifier.",
|
||||
set_accessor_parameter_cannot_be_optional: "'set' accessor parameter cannot be optional.",
|
||||
set_accessor_parameter_cannot_have_an_initializer: "'set' accessor parameter cannot have an initializer.",
|
||||
set_accessor_cannot_have_rest_parameter: "'set' accessor cannot have rest parameter.",
|
||||
get_accessor_cannot_have_parameters: "'get' accessor cannot have parameters.",
|
||||
Modifiers_cannot_appear_here: "Modifiers cannot appear here.",
|
||||
Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher: "Accessors are only available when targeting ECMAScript 5 and higher.",
|
||||
Class_name_cannot_be_0: "Class name cannot be '{0}'.",
|
||||
Interface_name_cannot_be_0: "Interface name cannot be '{0}'.",
|
||||
Enum_name_cannot_be_0: "Enum name cannot be '{0}'.",
|
||||
Module_name_cannot_be_0: "Module name cannot be '{0}'.",
|
||||
Enum_member_must_have_initializer: "Enum member must have initializer.",
|
||||
module_is_deprecated_Use_require_instead: "'module(...)' is deprecated. Use 'require(...)' instead.",
|
||||
Export_assignment_cannot_be_used_in_internal_modules: "Export assignment cannot be used in internal modules.",
|
||||
Export_assignment_not_allowed_in_module_with_exported_element: "Export assignment not allowed in module with exported element.",
|
||||
Module_cannot_have_multiple_export_assignments: "Module cannot have multiple export assignments.",
|
||||
Ambient_enum_elements_can_only_have_integer_literal_initializers: "Ambient enum elements can only have integer literal initializers.",
|
||||
module_class_interface_enum_import_or_statement: "module, class, interface, enum, import or statement",
|
||||
constructor_function_accessor_or_variable: "constructor, function, accessor or variable",
|
||||
statement: "statement",
|
||||
case_or_default_clause: "case or default clause",
|
||||
identifier: "identifier",
|
||||
call_construct_index_property_or_function_signature: "call, construct, index, property or function signature",
|
||||
expression: "expression",
|
||||
type_name: "type name",
|
||||
property_or_accessor: "property or accessor",
|
||||
parameter: "parameter",
|
||||
type: "type",
|
||||
type_parameter: "type parameter",
|
||||
Duplicate_identifier_0: "Duplicate identifier '{0}'.",
|
||||
The_name_0_does_not_exist_in_the_current_scope: "The name '{0}' does not exist in the current scope.",
|
||||
The_name_0_does_not_refer_to_a_value: "The name '{0}' does not refer to a value.",
|
||||
super_can_only_be_used_inside_a_class_instance_method: "'super' can only be used inside a class instance method.",
|
||||
The_left_hand_side_of_an_assignment_expression_must_be_a_variable_property_or_indexer: "The left-hand side of an assignment expression must be a variable, property or indexer.",
|
||||
Value_of_type_0_is_not_callable_Did_you_mean_to_include_new: "Value of type '{0}' is not callable. Did you mean to include 'new'?",
|
||||
Value_of_type_0_is_not_callable: "Value of type '{0}' is not callable.",
|
||||
Value_of_type_0_is_not_newable: "Value of type '{0}' is not newable.",
|
||||
Value_of_type_0_is_not_indexable_by_type_1: "Value of type '{0}' is not indexable by type '{1}'.",
|
||||
Operator_0_cannot_be_applied_to_types_1_and_2: "Operator '{0}' cannot be applied to types '{1}' and '{2}'.",
|
||||
Operator_0_cannot_be_applied_to_types_1_and_2_3: "Operator '{0}' cannot be applied to types '{1}' and '{2}': {3}",
|
||||
Cannot_convert_0_to_1: "Cannot convert '{0}' to '{1}'.",
|
||||
Cannot_convert_0_to_1_NL_2: "Cannot convert '{0}' to '{1}':{NL}{2}",
|
||||
Expected_var_class_interface_or_module: "Expected var, class, interface, or module.",
|
||||
Operator_0_cannot_be_applied_to_type_1: "Operator '{0}' cannot be applied to type '{1}'.",
|
||||
Getter_0_already_declared: "Getter '{0}' already declared.",
|
||||
Setter_0_already_declared: "Setter '{0}' already declared.",
|
||||
Accessors_cannot_have_type_parameters: "Accessors cannot have type parameters.",
|
||||
Exported_class_0_extends_private_class_1: "Exported class '{0}' extends private class '{1}'.",
|
||||
Exported_class_0_implements_private_interface_1: "Exported class '{0}' implements private interface '{1}'.",
|
||||
Exported_interface_0_extends_private_interface_1: "Exported interface '{0}' extends private interface '{1}'.",
|
||||
Exported_class_0_extends_class_from_inaccessible_module_1: "Exported class '{0}' extends class from inaccessible module {1}.",
|
||||
Exported_class_0_implements_interface_from_inaccessible_module_1: "Exported class '{0}' implements interface from inaccessible module {1}.",
|
||||
Exported_interface_0_extends_interface_from_inaccessible_module_1: "Exported interface '{0}' extends interface from inaccessible module {1}.",
|
||||
Public_static_property_0_of_exported_class_has_or_is_using_private_type_1: "Public static property '{0}' of exported class has or is using private type '{1}'.",
|
||||
Public_property_0_of_exported_class_has_or_is_using_private_type_1: "Public property '{0}' of exported class has or is using private type '{1}'.",
|
||||
Property_0_of_exported_interface_has_or_is_using_private_type_1: "Property '{0}' of exported interface has or is using private type '{1}'.",
|
||||
Exported_variable_0_has_or_is_using_private_type_1: "Exported variable '{0}' has or is using private type '{1}'.",
|
||||
Public_static_property_0_of_exported_class_is_using_inaccessible_module_1: "Public static property '{0}' of exported class is using inaccessible module {1}.",
|
||||
Public_property_0_of_exported_class_is_using_inaccessible_module_1: "Public property '{0}' of exported class is using inaccessible module {1}.",
|
||||
Property_0_of_exported_interface_is_using_inaccessible_module_1: "Property '{0}' of exported interface is using inaccessible module {1}.",
|
||||
Exported_variable_0_is_using_inaccessible_module_1: "Exported variable '{0}' is using inaccessible module {1}.",
|
||||
Parameter_0_of_constructor_from_exported_class_has_or_is_using_private_type_1: "Parameter '{0}' of constructor from exported class has or is using private type '{1}'.",
|
||||
Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_private_type_1: "Parameter '{0}' of public static property setter from exported class has or is using private type '{1}'.",
|
||||
Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_private_type_1: "Parameter '{0}' of public property setter from exported class has or is using private type '{1}'.",
|
||||
Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_type_1: "Parameter '{0}' of constructor signature from exported interface has or is using private type '{1}'.",
|
||||
Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_type_1: "Parameter '{0}' of call signature from exported interface has or is using private type '{1}'.",
|
||||
Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_type_1: "Parameter '{0}' of public static method from exported class has or is using private type '{1}'.",
|
||||
Parameter_0_of_public_method_from_exported_class_has_or_is_using_private_type_1: "Parameter '{0}' of public method from exported class has or is using private type '{1}'.",
|
||||
Parameter_0_of_method_from_exported_interface_has_or_is_using_private_type_1: "Parameter '{0}' of method from exported interface has or is using private type '{1}'.",
|
||||
Parameter_0_of_exported_function_has_or_is_using_private_type_1: "Parameter '{0}' of exported function has or is using private type '{1}'.",
|
||||
Parameter_0_of_constructor_from_exported_class_is_using_inaccessible_module_1: "Parameter '{0}' of constructor from exported class is using inaccessible module {1}.",
|
||||
Parameter_0_of_public_static_property_setter_from_exported_class_is_using_inaccessible_module_1: "Parameter '{0}' of public static property setter from exported class is using inaccessible module {1}.",
|
||||
Parameter_0_of_public_property_setter_from_exported_class_is_using_inaccessible_module_1: "Parameter '{0}' of public property setter from exported class is using inaccessible module {1}.",
|
||||
Parameter_0_of_constructor_signature_from_exported_interface_is_using_inaccessible_module_1: "Parameter '{0}' of constructor signature from exported interface is using inaccessible module {1}.",
|
||||
Parameter_0_of_call_signature_from_exported_interface_is_using_inaccessible_module_1: "Parameter '{0}' of call signature from exported interface is using inaccessible module {1}",
|
||||
Parameter_0_of_public_static_method_from_exported_class_is_using_inaccessible_module_1: "Parameter '{0}' of public static method from exported class is using inaccessible module {1}.",
|
||||
Parameter_0_of_public_method_from_exported_class_is_using_inaccessible_module_1: "Parameter '{0}' of public method from exported class is using inaccessible module {1}.",
|
||||
Parameter_0_of_method_from_exported_interface_is_using_inaccessible_module_1: "Parameter '{0}' of method from exported interface is using inaccessible module {1}.",
|
||||
Parameter_0_of_exported_function_is_using_inaccessible_module_1: "Parameter '{0}' of exported function is using inaccessible module {1}.",
|
||||
Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_private_type_0: "Return type of public static property getter from exported class has or is using private type '{0}'.",
|
||||
Return_type_of_public_property_getter_from_exported_class_has_or_is_using_private_type_0: "Return type of public property getter from exported class has or is using private type '{0}'.",
|
||||
Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_private_type_0: "Return type of constructor signature from exported interface has or is using private type '{0}'.",
|
||||
Return_type_of_call_signature_from_exported_interface_has_or_is_using_private_type_0: "Return type of call signature from exported interface has or is using private type '{0}'.",
|
||||
Return_type_of_index_signature_from_exported_interface_has_or_is_using_private_type_0: "Return type of index signature from exported interface has or is using private type '{0}'.",
|
||||
Return_type_of_public_static_method_from_exported_class_has_or_is_using_private_type_0: "Return type of public static method from exported class has or is using private type '{0}'.",
|
||||
Return_type_of_public_method_from_exported_class_has_or_is_using_private_type_0: "Return type of public method from exported class has or is using private type '{0}'.",
|
||||
Return_type_of_method_from_exported_interface_has_or_is_using_private_type_0: "Return type of method from exported interface has or is using private type '{0}'.",
|
||||
Return_type_of_exported_function_has_or_is_using_private_type_0: "Return type of exported function has or is using private type '{0}'.",
|
||||
Return_type_of_public_static_property_getter_from_exported_class_is_using_inaccessible_module_0: "Return type of public static property getter from exported class is using inaccessible module {0}.",
|
||||
Return_type_of_public_property_getter_from_exported_class_is_using_inaccessible_module_0: "Return type of public property getter from exported class is using inaccessible module {0}.",
|
||||
Return_type_of_constructor_signature_from_exported_interface_is_using_inaccessible_module_0: "Return type of constructor signature from exported interface is using inaccessible module {0}.",
|
||||
Return_type_of_call_signature_from_exported_interface_is_using_inaccessible_module_0: "Return type of call signature from exported interface is using inaccessible module {0}.",
|
||||
Return_type_of_index_signature_from_exported_interface_is_using_inaccessible_module_0: "Return type of index signature from exported interface is using inaccessible module {0}.",
|
||||
Return_type_of_public_static_method_from_exported_class_is_using_inaccessible_module_0: "Return type of public static method from exported class is using inaccessible module {0}.",
|
||||
Return_type_of_public_method_from_exported_class_is_using_inaccessible_module_0: "Return type of public method from exported class is using inaccessible module {0}.",
|
||||
Return_type_of_method_from_exported_interface_is_using_inaccessible_module_0: "Return type of method from exported interface is using inaccessible module {0}.",
|
||||
Return_type_of_exported_function_is_using_inaccessible_module_0: "Return type of exported function is using inaccessible module {0}.",
|
||||
new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: "'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.",
|
||||
A_parameter_list_must_follow_a_generic_type_argument_list_expected: "A parameter list must follow a generic type argument list. '(' expected.",
|
||||
Multiple_constructor_implementations_are_not_allowed: "Multiple constructor implementations are not allowed.",
|
||||
Unable_to_resolve_external_module_0: "Unable to resolve external module '{0}'.",
|
||||
Module_cannot_be_aliased_to_a_non_module_type: "Module cannot be aliased to a non-module type.",
|
||||
A_class_may_only_extend_another_class: "A class may only extend another class.",
|
||||
A_class_may_only_implement_another_class_or_interface: "A class may only implement another class or interface.",
|
||||
An_interface_may_only_extend_another_class_or_interface: "An interface may only extend another class or interface.",
|
||||
An_interface_cannot_implement_another_type: "An interface cannot implement another type.",
|
||||
Unable_to_resolve_type: "Unable to resolve type.",
|
||||
Unable_to_resolve_type_of_0: "Unable to resolve type of '{0}'.",
|
||||
Unable_to_resolve_type_parameter_constraint: "Unable to resolve type parameter constraint.",
|
||||
Type_parameter_constraint_cannot_be_a_primitive_type: "Type parameter constraint cannot be a primitive type.",
|
||||
Supplied_parameters_do_not_match_any_signature_of_call_target: "Supplied parameters do not match any signature of call target.",
|
||||
Supplied_parameters_do_not_match_any_signature_of_call_target_NL_0: "Supplied parameters do not match any signature of call target:{NL}{0}",
|
||||
Invalid_new_expression: "Invalid 'new' expression.",
|
||||
Call_signatures_used_in_a_new_expression_must_have_a_void_return_type: "Call signatures used in a 'new' expression must have a 'void' return type.",
|
||||
Could_not_select_overload_for_new_expression: "Could not select overload for 'new' expression.",
|
||||
Type_0_does_not_satisfy_the_constraint_1_for_type_parameter_2: "Type '{0}' does not satisfy the constraint '{1}' for type parameter '{2}'.",
|
||||
Could_not_select_overload_for_call_expression: "Could not select overload for 'call' expression.",
|
||||
Cannot_invoke_an_expression_whose_type_lacks_a_call_signature: "Cannot invoke an expression whose type lacks a call signature.",
|
||||
Calls_to_super_are_only_valid_inside_a_class: "Calls to 'super' are only valid inside a class.",
|
||||
Generic_type_0_requires_1_type_argument_s: "Generic type '{0}' requires {1} type argument(s).",
|
||||
Type_of_conditional_expression_cannot_be_determined_Best_common_type_could_not_be_found_between_0_and_1: "Type of conditional expression cannot be determined. Best common type could not be found between '{0}' and '{1}'.",
|
||||
Type_of_array_literal_cannot_be_determined_Best_common_type_could_not_be_found_for_array_elements: "Type of array literal cannot be determined. Best common type could not be found for array elements.",
|
||||
Could_not_find_enclosing_symbol_for_dotted_name_0: "Could not find enclosing symbol for dotted name '{0}'.",
|
||||
The_property_0_does_not_exist_on_value_of_type_1: "The property '{0}' does not exist on value of type '{1}'.",
|
||||
Could_not_find_symbol_0: "Could not find symbol '{0}'.",
|
||||
get_and_set_accessor_must_have_the_same_type: "'get' and 'set' accessor must have the same type.",
|
||||
this_cannot_be_referenced_in_current_location: "'this' cannot be referenced in current location.",
|
||||
Static_methods_cannot_reference_class_type_parameters: "Static methods cannot reference class type parameters.",
|
||||
Class_0_is_recursively_referenced_as_a_base_type_of_itself: "Class '{0}' is recursively referenced as a base type of itself.",
|
||||
Interface_0_is_recursively_referenced_as_a_base_type_of_itself: "Interface '{0}' is recursively referenced as a base type of itself.",
|
||||
super_property_access_is_permitted_only_in_a_constructor_instance_member_function_or_instance_member_accessor_of_a_derived_class: "'super' property access is permitted only in a constructor, instance member function, or instance member accessor of a derived class.",
|
||||
super_cannot_be_referenced_in_non_derived_classes: "'super' cannot be referenced in non-derived classes.",
|
||||
A_super_call_must_be_the_first_statement_in_the_constructor_when_a_class_contains_initialized_properties_or_has_parameter_properties: "A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties.",
|
||||
Constructors_for_derived_classes_must_contain_a_super_call: "Constructors for derived classes must contain a 'super' call.",
|
||||
Super_calls_are_not_permitted_outside_constructors_or_in_local_functions_inside_constructors: "Super calls are not permitted outside constructors or in local functions inside constructors.",
|
||||
_0_1_is_inaccessible: "'{0}.{1}' is inaccessible.",
|
||||
this_cannot_be_referenced_within_module_bodies: "'this' cannot be referenced within module bodies.",
|
||||
Invalid_expression_types_not_known_to_support_the_addition_operator: "Invalid '+' expression - types not known to support the addition operator.",
|
||||
The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type: "The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.",
|
||||
The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type: "The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.",
|
||||
The_type_of_a_unary_arithmetic_operation_operand_must_be_of_type_any_number_or_an_enum_type: "The type of a unary arithmetic operation operand must be of type 'any', 'number' or an enum type.",
|
||||
Variable_declarations_of_a_for_statement_cannot_use_a_type_annotation: "Variable declarations of a 'for' statement cannot use a type annotation.",
|
||||
Variable_declarations_of_a_for_statement_must_be_of_types_string_or_any: "Variable declarations of a 'for' statement must be of types 'string' or 'any'.",
|
||||
The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter: "The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter.",
|
||||
The_left_hand_side_of_an_in_expression_must_be_of_types_string_or_any: "The left-hand side of an 'in' expression must be of types 'string' or 'any'.",
|
||||
The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter: "The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter.",
|
||||
The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter: "The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter.",
|
||||
The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_a_subtype_of_the_Function_interface_type: "The right-hand side of an 'instanceof' expression must be of type 'any' or a subtype of the 'Function' interface type.",
|
||||
Setters_cannot_return_a_value: "Setters cannot return a value.",
|
||||
Tried_to_query_type_of_uninitialized_module_0: "Tried to query type of uninitialized module '{0}'.",
|
||||
Tried_to_set_variable_type_to_uninitialized_module_type_0: "Tried to set variable type to uninitialized module type '{0}'.",
|
||||
Function_0_declared_a_non_void_return_type_but_has_no_return_expression: "Function '{0}' declared a non-void return type, but has no return expression.",
|
||||
Getters_must_return_a_value: "Getters must return a value.",
|
||||
Getter_and_setter_accessors_do_not_agree_in_visibility: "Getter and setter accessors do not agree in visibility.",
|
||||
Invalid_left_hand_side_of_assignment_expression: "Invalid left-hand side of assignment expression.",
|
||||
Function_declared_a_non_void_return_type_but_has_no_return_expression: "Function declared a non-void return type, but has no return expression.",
|
||||
Cannot_resolve_return_type_reference: "Cannot resolve return type reference.",
|
||||
Constructors_cannot_have_a_return_type_of_void: "Constructors cannot have a return type of 'void'.",
|
||||
Subsequent_variable_declarations_must_have_the_same_type_Variable_0_must_be_of_type_1_but_here_has_type_2: "Subsequent variable declarations must have the same type. Variable '{0}' must be of type '{1}', but here has type '{2}'.",
|
||||
All_symbols_within_a_with_block_will_be_resolved_to_any: "All symbols within a with block will be resolved to 'any'.",
|
||||
Import_declarations_in_an_internal_module_cannot_reference_an_external_module: "Import declarations in an internal module cannot reference an external module.",
|
||||
Class_0_declares_interface_1_but_does_not_implement_it_NL_2: "Class {0} declares interface {1} but does not implement it:{NL}{2}",
|
||||
Class_0_declares_class_1_as_an_interface_but_does_not_implement_it_NL_2: "Class {0} declares class {1} as an interface but does not implement it:{NL}{2}",
|
||||
The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_property_or_indexer: "The operand of an increment or decrement operator must be a variable, property or indexer.",
|
||||
this_cannot_be_referenced_in_static_initializers_in_a_class_body: "'this' cannot be referenced in static initializers in a class body.",
|
||||
Class_0_cannot_extend_class_1_NL_2: "Class '{0}' cannot extend class '{1}':{NL}{2}",
|
||||
Interface_0_cannot_extend_class_1_NL_2: "Interface '{0}' cannot extend class '{1}':{NL}{2}",
|
||||
Interface_0_cannot_extend_interface_1_NL_2: "Interface '{0}' cannot extend interface '{1}':{NL}{2}",
|
||||
Duplicate_overload_signature_for_0: "Duplicate overload signature for '{0}'.",
|
||||
Duplicate_constructor_overload_signature: "Duplicate constructor overload signature.",
|
||||
Duplicate_overload_call_signature: "Duplicate overload call signature.",
|
||||
Duplicate_overload_construct_signature: "Duplicate overload construct signature.",
|
||||
Overload_signature_is_not_compatible_with_function_definition: "Overload signature is not compatible with function definition.",
|
||||
Overload_signature_is_not_compatible_with_function_definition_NL_0: "Overload signature is not compatible with function definition:{NL}{0}",
|
||||
Overload_signatures_must_all_be_public_or_private: "Overload signatures must all be public or private.",
|
||||
Overload_signatures_must_all_be_exported_or_local: "Overload signatures must all be exported or local.",
|
||||
Overload_signatures_must_all_be_ambient_or_non_ambient: "Overload signatures must all be ambient or non-ambient.",
|
||||
Overload_signatures_must_all_be_optional_or_required: "Overload signatures must all be optional or required.",
|
||||
Specialized_overload_signature_is_not_subtype_of_any_non_specialized_signature: "Specialized overload signature is not subtype of any non-specialized signature.",
|
||||
this_cannot_be_referenced_in_constructor_arguments: "'this' cannot be referenced in constructor arguments.",
|
||||
Static_member_cannot_be_accessed_off_an_instance_variable: "Static member cannot be accessed off an instance variable.",
|
||||
Instance_member_cannot_be_accessed_off_a_class: "Instance member cannot be accessed off a class.",
|
||||
Untyped_function_calls_may_not_accept_type_arguments: "Untyped function calls may not accept type arguments.",
|
||||
Non_generic_functions_may_not_accept_type_arguments: "Non-generic functions may not accept type arguments.",
|
||||
A_generic_type_may_not_reference_itself_with_a_wrapped_form_of_its_own_type_parameters: "A generic type may not reference itself with a wrapped form of its own type parameters.",
|
||||
Rest_parameters_must_be_array_types: "Rest parameters must be array types.",
|
||||
Overload_signature_implementation_cannot_use_specialized_type: "Overload signature implementation cannot use specialized type.",
|
||||
Export_assignments_may_only_be_used_at_the_top_level_of_external_modules: "Export assignments may only be used at the top-level of external modules.",
|
||||
Export_assignments_may_only_be_made_with_variables_functions_classes_interfaces_enums_and_internal_modules: "Export assignments may only be made with variables, functions, classes, interfaces, enums and internal modules",
|
||||
Only_public_instance_methods_of_the_base_class_are_accessible_via_the_super_keyword: "Only public instance methods of the base class are accessible via the 'super' keyword.",
|
||||
Numeric_indexer_type_0_must_be_a_subtype_of_string_indexer_type_1: "Numeric indexer type '{0}' must be a subtype of string indexer type '{1}'.",
|
||||
Numeric_indexer_type_0_must_be_a_subtype_of_string_indexer_type_1_NL_2: "Numeric indexer type '{0}' must be a subtype of string indexer type '{1}':{NL}{2}",
|
||||
All_numerically_named_properties_must_be_subtypes_of_numeric_indexer_type_0: "All numerically named properties must be subtypes of numeric indexer type '{0}'.",
|
||||
All_numerically_named_properties_must_be_subtypes_of_numeric_indexer_type_0_NL_1: "All numerically named properties must be subtypes of numeric indexer type '{0}':{NL}{1}",
|
||||
All_named_properties_must_be_subtypes_of_string_indexer_type_0: "All named properties must be subtypes of string indexer type '{0}'.",
|
||||
All_named_properties_must_be_subtypes_of_string_indexer_type_0_NL_1: "All named properties must be subtypes of string indexer type '{0}':{NL}{1}",
|
||||
Generic_type_references_must_include_all_type_arguments: "Generic type references must include all type arguments.",
|
||||
Default_arguments_are_not_allowed_in_an_overload_parameter: "Default arguments are not allowed in an overload parameter.",
|
||||
Overloads_cannot_differ_only_by_return_type: "Overloads cannot differ only by return type.",
|
||||
Function_expression_declared_a_non_void_return_type_but_has_no_return_expression: "Function expression declared a non-void return type, but has no return expression.",
|
||||
Type_0_is_missing_property_1_from_type_2: "Type '{0}' is missing property '{1}' from type '{2}'.",
|
||||
Types_of_property_0_of_types_1_and_2_are_incompatible: "Types of property '{0}' of types '{1}' and '{2}' are incompatible.",
|
||||
Types_of_property_0_of_types_1_and_2_are_incompatible_NL_3: "Types of property '{0}' of types '{1}' and '{2}' are incompatible:{NL}{3}",
|
||||
Property_0_defined_as_private_in_type_1_is_defined_as_public_in_type_2: "Property '{0}' defined as private in type '{1}' is defined as public in type '{2}'.",
|
||||
Property_0_defined_as_public_in_type_1_is_defined_as_private_in_type_2: "Property '{0}' defined as public in type '{1}' is defined as private in type '{2}'.",
|
||||
Types_0_and_1_define_property_2_as_private: "Types '{0}' and '{1}' define property '{2}' as private.",
|
||||
Call_signatures_of_types_0_and_1_are_incompatible: "Call signatures of types '{0}' and '{1}' are incompatible.",
|
||||
Call_signatures_of_types_0_and_1_are_incompatible_NL_2: "Call signatures of types '{0}' and '{1}' are incompatible:{NL}{2}",
|
||||
Type_0_requires_a_call_signature_but_type_1_lacks_one: "Type '{0}' requires a call signature, but type '{1}' lacks one.",
|
||||
Construct_signatures_of_types_0_and_1_are_incompatible: "Construct signatures of types '{0}' and '{1}' are incompatible.",
|
||||
Construct_signatures_of_types_0_and_1_are_incompatible_NL_2: "Construct signatures of types '{0}' and '{1}' are incompatible:{NL}{2}",
|
||||
Type_0_requires_a_construct_signature_but_type_1_lacks_one: "Type '{0}' requires a construct signature, but type '{1}' lacks one.",
|
||||
Index_signatures_of_types_0_and_1_are_incompatible: "Index signatures of types '{0}' and '{1}' are incompatible.",
|
||||
Index_signatures_of_types_0_and_1_are_incompatible_NL_2: "Index signatures of types '{0}' and '{1}' are incompatible:{NL}{2}",
|
||||
Call_signature_expects_0_or_fewer_parameters: "Call signature expects {0} or fewer parameters.",
|
||||
Could_not_apply_type_0_to_argument_1_which_is_of_type_2: "Could not apply type '{0}' to argument {1} which is of type '{2}'.",
|
||||
Class_0_defines_instance_member_accessor_1_but_extended_class_2_defines_it_as_instance_member_function: "Class '{0}' defines instance member accessor '{1}', but extended class '{2}' defines it as instance member function.",
|
||||
Class_0_defines_instance_member_property_1_but_extended_class_2_defines_it_as_instance_member_function: "Class '{0}' defines instance member property '{1}', but extended class '{2}' defines it as instance member function.",
|
||||
Class_0_defines_instance_member_function_1_but_extended_class_2_defines_it_as_instance_member_accessor: "Class '{0}' defines instance member function '{1}', but extended class '{2}' defines it as instance member accessor.",
|
||||
Class_0_defines_instance_member_function_1_but_extended_class_2_defines_it_as_instance_member_property: "Class '{0}' defines instance member function '{1}', but extended class '{2}' defines it as instance member property.",
|
||||
Types_of_static_property_0_of_class_1_and_class_2_are_incompatible: "Types of static property '{0}' of class '{1}' and class '{2}' are incompatible.",
|
||||
Types_of_static_property_0_of_class_1_and_class_2_are_incompatible_NL_3: "Types of static property '{0}' of class '{1}' and class '{2}' are incompatible:{NL}{3}",
|
||||
Type_reference_cannot_refer_to_container_0: "Type reference cannot refer to container '{0}'.",
|
||||
Type_reference_must_refer_to_type: "Type reference must refer to type.",
|
||||
Enums_with_multiple_declarations_must_provide_an_initializer_for_the_first_enum_element: "Enums with multiple declarations must provide an initializer for the first enum element.",
|
||||
_0_overload_s: " (+ {0} overload(s))",
|
||||
Current_host_does_not_support_0_option: "Current host does not support '{0}' option.",
|
||||
ECMAScript_target_version_0_not_supported_Using_default_1_code_generation: "ECMAScript target version '{0}' not supported. Using default '{1}' code generation.",
|
||||
Module_code_generation_0_not_supported_Using_default_1_code_generation: "Module code generation '{0}' not supported. Using default '{1}' code generation.",
|
||||
Could_not_find_file_0: "Could not find file: '{0}'.",
|
||||
A_file_cannot_have_a_reference_to_itself: "A file cannot have a reference to itself.",
|
||||
Cannot_resolve_referenced_file_0: "Cannot resolve referenced file: '{0}'.",
|
||||
Cannot_find_the_common_subdirectory_path_for_the_input_files: "Cannot find the common subdirectory path for the input files.",
|
||||
Cannot_compile_external_modules_when_emitting_into_single_file: "Cannot compile external modules when emitting into single file.",
|
||||
Emit_Error_0: "Emit Error: {0}.",
|
||||
Cannot_read_file_0_1: "Cannot read file '{0}': {1}",
|
||||
Unsupported_file_encoding: "Unsupported file encoding.",
|
||||
Locale_must_be_of_the_form_language_or_language_territory_For_example_0_or_1: "Locale must be of the form <language> or <language>-<territory>. For example '{0}' or '{1}'.",
|
||||
Unsupported_locale_0: "Unsupported locale: '{0}'.",
|
||||
Execution_Failed_NL: "Execution Failed.{NL}",
|
||||
Should_not_emit_a_type_query: "Should not emit a type query",
|
||||
Should_not_emit_a_type_reference: "Should not emit a type reference",
|
||||
Invalid_call_to_up: "Invalid call to 'up'",
|
||||
Invalid_call_to_down: "Invalid call to 'down'",
|
||||
Base64_value_0_finished_with_a_continuation_bit: "Base64 value '{0}' finished with a continuation bit",
|
||||
Key_was_already_in_table: "Key was already in table",
|
||||
Unknown_option_0: "Unknown option '{0}'",
|
||||
Expected_0_arguments_to_message_got_1_instead: "Expected {0} arguments to message, got {1} instead",
|
||||
Expected_the_message_0_to_have_1_arguments_but_it_had_2: "Expected the message '{0}' to have {1} arguments, but it had {2}",
|
||||
Invalid_argument_0_1: "Invalid argument: {0}. {1}",
|
||||
Invalid_argument_0: "Invalid argument: {0}.",
|
||||
Argument_out_of_range_0: "Argument out of range: {0}.",
|
||||
Argument_null_0: "Argument null: {0}.",
|
||||
Operation_not_implemented_properly_by_subclass: "Operation not implemented properly by subclass.",
|
||||
Not_yet_implemented: "Not yet implemented.",
|
||||
Invalid_operation_0: "Invalid operation: {0}",
|
||||
Invalid_operation: "Invalid operation.",
|
||||
Couldn_t_delete_file_0: "Couldn't delete file '{0}'",
|
||||
Couldn_t_create_directory_0: "Couldn't create directory '{0}'",
|
||||
Error_while_executing_file_0: "Error while executing file '{0}': ",
|
||||
Concatenate_and_emit_output_to_single_file_Redirect_output_structure_to_the_directory: "Concatenate and emit output to single file | Redirect output structure to the directory",
|
||||
Generates_corresponding_0_file: "Generates corresponding {0} file",
|
||||
Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations: "Specifies the location where debugger should locate map files instead of generated locations.",
|
||||
Specifies_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations: "Specifies the location where debugger should locate TypeScript files instead of source locations.",
|
||||
Watch_input_files: "Watch input files",
|
||||
Execute_the_script_after_compilation: "Execute the script after compilation",
|
||||
Minimize_whitespace: "Minimize whitespace",
|
||||
Propagate_constants_to_emitted_code: "Propagate constants to emitted code",
|
||||
Emit_comments_to_output: "Emit comments to output",
|
||||
Skip_resolution_and_preprocessing: "Skip resolution and preprocessing",
|
||||
Print_debug_output: "Print debug output",
|
||||
Do_not_include_a_default_0_with_global_declarations: "Do not include a default {0} with global declarations",
|
||||
Gather_diagnostic_info_about_the_compilation_process: "Gather diagnostic info about the compilation process",
|
||||
Typecheck_each_file_as_an_update_on_the_first: "Typecheck each file as an update on the first",
|
||||
Specify_ECMAScript_target_version_0_default_or_1: "Specify ECMAScript target version: \"{0}\" (default), or \"{1}\"",
|
||||
Specify_module_code_generation_0_default_or_1: "Specify module code generation: \"{0}\" (default) or \"{1}\"",
|
||||
Print_this_message: "Print this message",
|
||||
Force_file_resolution_to_be_case_sensitive: "Force file resolution to be case sensitive",
|
||||
Print_the_compiler_s_version_0: "Print the compiler's version: {0}",
|
||||
Allow_use_of_deprecated_0_type: "Allow use of deprecated \"{0}\" type",
|
||||
Allow_use_of_deprecated_0_keyword_when_referencing_an_external_module: "Allow use of deprecated \"{0}\" keyword when referencing an external module",
|
||||
Specify_locale_for_errors_and_messages_For_example_0_or_1: "Specify locale for errors and messages. For example '{0}' or '{1}'",
|
||||
Syntax_0: "Syntax: {0}",
|
||||
options: "options",
|
||||
file: "file",
|
||||
Examples: "Examples:",
|
||||
Options: "Options:",
|
||||
Insert_command_line_options_and_files_from_a_file: "Insert command line options and files from a file.",
|
||||
Version_0: "Version {0}",
|
||||
Use_the_0_flag_to_see_options: "Use the '{0}' flag to see options",
|
||||
NL_Recompiling_0: "{NL}Recompiling ({0}):",
|
||||
STRING: "STRING",
|
||||
KIND: "KIND",
|
||||
FILE_DIRECTORY: "FILE|DIRECTORY",
|
||||
VERSION: "VERSION",
|
||||
This_version_of_the_Javascript_runtime_doesn_t_support_the_0_function: "This version of the Javascript runtime doesn't support the '{0}' function.",
|
||||
Looking_up_path_for_identifier_token_did_not_result_in_an_identifer: "Looking up path for identifier token did not result in an identifer.",
|
||||
Unknown_rule: "Unknown rule",
|
||||
Invalid_line_number_0: "Invalid line number ({0})",
|
||||
Warn_on_expressions_and_declarations_with_an_implied_any_type: "Warn on expressions and declarations with an implied 'any' type.",
|
||||
Variable_0_implicitly_has_an_any_type: "Variable '{0}' implicitly has an 'any' type.",
|
||||
Parameter_0_of_1_implicitly_has_an_any_type: "Parameter '{0}' of '{1}' implicitly has an 'any' type.",
|
||||
Parameter_0_of_function_type_implicitly_has_an_any_type: "Parameter '{0}' of function type implicitly has an 'any' type.",
|
||||
Member_0_of_object_type_implicitly_has_an_any_type: "Member '{0}' of object type implicitly has an 'any' type.",
|
||||
New_expression_which_lacks_a_constructor_signature_implicitly_has_an_any_type: "\"New\" expression, which lacks a constructor signature, implicitly has an 'any' type.",
|
||||
_0_which_lacks_return_type_annotation_implicitly_has_an_any_return_type: "'{0}', which lacks return-type annotation, implicitly has an 'any' return type.",
|
||||
Function_expression_which_lacks_return_type_annotation_implicitly_has_an_any_return_type: "Function expression, which lacks return-type annotation, implicitly has an 'any' return type.",
|
||||
Parameter_0_of_lambda_function_implicitly_has_an_any_type: "Parameter '{0}' of lambda function implicitly has an 'any' type.",
|
||||
Constructor_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type: "Constructor signature, which lacks return-type annotation, implicitly has an 'any' return type.",
|
||||
Lambda_Function_which_lacks_return_type_annotation_implicitly_has_an_any_return_type: "Lambda Function, which lacks return-type annotation, implicitly has an 'any' return type.",
|
||||
Array_Literal_implicitly_has_an_any_type_from_widening: "Array Literal implicitly has an 'any' type from widening."
|
||||
};
|
||||
})(TypeScript || (TypeScript = {}));
|
||||
@@ -0,0 +1,440 @@
|
||||
// <auto-generated />
|
||||
module TypeScript {
|
||||
export var DiagnosticCode = {
|
||||
error_TS_0_1: "error TS{0}: {1}",
|
||||
warning_TS_0_1: "warning TS{0}: {1}",
|
||||
Unrecognized_escape_sequence: "Unrecognized escape sequence.",
|
||||
Unexpected_character_0: "Unexpected character {0}.",
|
||||
Missing_close_quote_character: "Missing close quote character.",
|
||||
Identifier_expected: "Identifier expected.",
|
||||
_0_keyword_expected: "'{0}' keyword expected.",
|
||||
_0_expected: "'{0}' expected.",
|
||||
Identifier_expected_0_is_a_keyword: "Identifier expected; '{0}' is a keyword.",
|
||||
Automatic_semicolon_insertion_not_allowed: "Automatic semicolon insertion not allowed.",
|
||||
Unexpected_token_0_expected: "Unexpected token; '{0}' expected.",
|
||||
Trailing_separator_not_allowed: "Trailing separator not allowed.",
|
||||
AsteriskSlash_expected: "'*/' expected.",
|
||||
public_or_private_modifier_must_precede_static: "'public' or 'private' modifier must precede 'static'.",
|
||||
Unexpected_token: "Unexpected token.",
|
||||
Catch_clause_parameter_cannot_have_a_type_annotation: "Catch clause parameter cannot have a type annotation.",
|
||||
Rest_parameter_must_be_last_in_list: "Rest parameter must be last in list.",
|
||||
Parameter_cannot_have_question_mark_and_initializer: "Parameter cannot have question mark and initializer.",
|
||||
Required_parameter_cannot_follow_optional_parameter: "Required parameter cannot follow optional parameter.",
|
||||
Index_signatures_cannot_have_rest_parameters: "Index signatures cannot have rest parameters.",
|
||||
Index_signature_parameter_cannot_have_accessibility_modifiers: "Index signature parameter cannot have accessibility modifiers.",
|
||||
Index_signature_parameter_cannot_have_a_question_mark: "Index signature parameter cannot have a question mark.",
|
||||
Index_signature_parameter_cannot_have_an_initializer: "Index signature parameter cannot have an initializer.",
|
||||
Index_signature_must_have_a_type_annotation: "Index signature must have a type annotation.",
|
||||
Index_signature_parameter_must_have_a_type_annotation: "Index signature parameter must have a type annotation.",
|
||||
Index_signature_parameter_type_must_be_string_or_number: "Index signature parameter type must be 'string' or 'number'.",
|
||||
extends_clause_already_seen: "'extends' clause already seen.",
|
||||
extends_clause_must_precede_implements_clause: "'extends' clause must precede 'implements' clause.",
|
||||
Classes_can_only_extend_a_single_class: "Classes can only extend a single class.",
|
||||
implements_clause_already_seen: "'implements' clause already seen.",
|
||||
Accessibility_modifier_already_seen: "Accessibility modifier already seen.",
|
||||
_0_modifier_must_precede_1_modifier: "'{0}' modifier must precede '{1}' modifier.",
|
||||
_0_modifier_already_seen: "'{0}' modifier already seen.",
|
||||
_0_modifier_cannot_appear_on_a_class_element: "'{0}' modifier cannot appear on a class element.",
|
||||
Interface_declaration_cannot_have_implements_clause: "Interface declaration cannot have 'implements' clause.",
|
||||
super_invocation_cannot_have_type_arguments: "'super' invocation cannot have type arguments.",
|
||||
Only_ambient_modules_can_use_quoted_names: "Only ambient modules can use quoted names.",
|
||||
Statements_are_not_allowed_in_ambient_contexts: "Statements are not allowed in ambient contexts.",
|
||||
Implementations_are_not_allowed_in_ambient_contexts: "Implementations are not allowed in ambient contexts.",
|
||||
declare_modifier_not_allowed_for_code_already_in_an_ambient_context: "'declare' modifier not allowed for code already in an ambient context.",
|
||||
Initializers_are_not_allowed_in_ambient_contexts: "Initializers are not allowed in ambient contexts.",
|
||||
Parameter_property_declarations_can_only_be_used_in_a_non_ambient_constructor_declaration: "Parameter property declarations can only be used in a non-ambient constructor declaration.",
|
||||
Function_implementation_expected: "Function implementation expected.",
|
||||
Constructor_implementation_expected: "Constructor implementation expected.",
|
||||
Function_overload_name_must_be_0: "Function overload name must be '{0}'.",
|
||||
_0_modifier_cannot_appear_on_a_module_element: "'{0}' modifier cannot appear on a module element.",
|
||||
declare_modifier_cannot_appear_on_an_interface_declaration: "'declare' modifier cannot appear on an interface declaration.",
|
||||
declare_modifier_required_for_top_level_element: "'declare' modifier required for top level element.",
|
||||
Rest_parameter_cannot_be_optional: "Rest parameter cannot be optional.",
|
||||
Rest_parameter_cannot_have_an_initializer: "Rest parameter cannot have an initializer.",
|
||||
set_accessor_must_have_one_and_only_one_parameter: "'set' accessor must have one and only one parameter.",
|
||||
set_accessor_parameter_cannot_be_optional: "'set' accessor parameter cannot be optional.",
|
||||
set_accessor_parameter_cannot_have_an_initializer: "'set' accessor parameter cannot have an initializer.",
|
||||
set_accessor_cannot_have_rest_parameter: "'set' accessor cannot have rest parameter.",
|
||||
get_accessor_cannot_have_parameters: "'get' accessor cannot have parameters.",
|
||||
Modifiers_cannot_appear_here: "Modifiers cannot appear here.",
|
||||
Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher: "Accessors are only available when targeting ECMAScript 5 and higher.",
|
||||
Class_name_cannot_be_0: "Class name cannot be '{0}'.",
|
||||
Interface_name_cannot_be_0: "Interface name cannot be '{0}'.",
|
||||
Enum_name_cannot_be_0: "Enum name cannot be '{0}'.",
|
||||
Module_name_cannot_be_0: "Module name cannot be '{0}'.",
|
||||
Enum_member_must_have_initializer: "Enum member must have initializer.",
|
||||
Export_assignment_cannot_be_used_in_internal_modules: "Export assignment cannot be used in internal modules.",
|
||||
Export_assignment_not_allowed_in_module_with_exported_element: "Export assignment not allowed in module with exported element.",
|
||||
Module_cannot_have_multiple_export_assignments: "Module cannot have multiple export assignments.",
|
||||
Ambient_enum_elements_can_only_have_integer_literal_initializers: "Ambient enum elements can only have integer literal initializers.",
|
||||
module_class_interface_enum_import_or_statement: "module, class, interface, enum, import or statement",
|
||||
constructor_function_accessor_or_variable: "constructor, function, accessor or variable",
|
||||
statement: "statement",
|
||||
case_or_default_clause: "case or default clause",
|
||||
identifier: "identifier",
|
||||
call_construct_index_property_or_function_signature: "call, construct, index, property or function signature",
|
||||
expression: "expression",
|
||||
type_name: "type name",
|
||||
property_or_accessor: "property or accessor",
|
||||
parameter: "parameter",
|
||||
type: "type",
|
||||
type_parameter: "type parameter",
|
||||
declare_modifier_not_allowed_on_import_declaration: "'declare' modifier not allowed on import declaration.",
|
||||
Function_overload_must_be_static: "Function overload must be static.",
|
||||
Function_overload_must_not_be_static: "Function overload must not be static.",
|
||||
Parameter_property_declarations_cannot_be_used_in_a_constructor_overload: "Parameter property declarations cannot be used in a constructor overload.",
|
||||
Invalid_reference_directive_syntax: "Invalid 'reference' directive syntax.",
|
||||
Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher: "Octal literals are not available when targeting ECMAScript 5 and higher.",
|
||||
Accessors_are_not_allowed_in_ambient_contexts: "Accessors are not allowed in ambient contexts.",
|
||||
_0_modifier_cannot_appear_on_a_constructor_declaration: "'{0}' modifier cannot appear on a constructor declaration.",
|
||||
_0_modifier_cannot_appear_on_a_parameter: "'{0}' modifier cannot appear on a parameter.",
|
||||
Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement: "Only a single variable declaration is allowed in a 'for...in' statement.",
|
||||
Type_parameters_cannot_appear_on_a_constructor_declaration: "Type parameters cannot appear on a constructor declaration.",
|
||||
Type_annotation_cannot_appear_on_a_constructor_declaration: "Type annotation cannot appear on a constructor declaration.",
|
||||
Duplicate_identifier_0: "Duplicate identifier '{0}'.",
|
||||
The_name_0_does_not_exist_in_the_current_scope: "The name '{0}' does not exist in the current scope.",
|
||||
The_name_0_does_not_refer_to_a_value: "The name '{0}' does not refer to a value.",
|
||||
super_can_only_be_used_inside_a_class_instance_method: "'super' can only be used inside a class instance method.",
|
||||
The_left_hand_side_of_an_assignment_expression_must_be_a_variable_property_or_indexer: "The left-hand side of an assignment expression must be a variable, property or indexer.",
|
||||
Value_of_type_0_is_not_callable_Did_you_mean_to_include_new: "Value of type '{0}' is not callable. Did you mean to include 'new'?",
|
||||
Value_of_type_0_is_not_callable: "Value of type '{0}' is not callable.",
|
||||
Value_of_type_0_is_not_newable: "Value of type '{0}' is not newable.",
|
||||
Value_of_type_0_is_not_indexable_by_type_1: "Value of type '{0}' is not indexable by type '{1}'.",
|
||||
Operator_0_cannot_be_applied_to_types_1_and_2: "Operator '{0}' cannot be applied to types '{1}' and '{2}'.",
|
||||
Operator_0_cannot_be_applied_to_types_1_and_2_3: "Operator '{0}' cannot be applied to types '{1}' and '{2}': {3}",
|
||||
Cannot_convert_0_to_1: "Cannot convert '{0}' to '{1}'.",
|
||||
Cannot_convert_0_to_1_NL_2: "Cannot convert '{0}' to '{1}':{NL}{2}",
|
||||
Expected_var_class_interface_or_module: "Expected var, class, interface, or module.",
|
||||
Operator_0_cannot_be_applied_to_type_1: "Operator '{0}' cannot be applied to type '{1}'.",
|
||||
Getter_0_already_declared: "Getter '{0}' already declared.",
|
||||
Setter_0_already_declared: "Setter '{0}' already declared.",
|
||||
Exported_class_0_extends_private_class_1: "Exported class '{0}' extends private class '{1}'.",
|
||||
Exported_class_0_implements_private_interface_1: "Exported class '{0}' implements private interface '{1}'.",
|
||||
Exported_interface_0_extends_private_interface_1: "Exported interface '{0}' extends private interface '{1}'.",
|
||||
Exported_class_0_extends_class_from_inaccessible_module_1: "Exported class '{0}' extends class from inaccessible module {1}.",
|
||||
Exported_class_0_implements_interface_from_inaccessible_module_1: "Exported class '{0}' implements interface from inaccessible module {1}.",
|
||||
Exported_interface_0_extends_interface_from_inaccessible_module_1: "Exported interface '{0}' extends interface from inaccessible module {1}.",
|
||||
Public_static_property_0_of_exported_class_has_or_is_using_private_type_1: "Public static property '{0}' of exported class has or is using private type '{1}'.",
|
||||
Public_property_0_of_exported_class_has_or_is_using_private_type_1: "Public property '{0}' of exported class has or is using private type '{1}'.",
|
||||
Property_0_of_exported_interface_has_or_is_using_private_type_1: "Property '{0}' of exported interface has or is using private type '{1}'.",
|
||||
Exported_variable_0_has_or_is_using_private_type_1: "Exported variable '{0}' has or is using private type '{1}'.",
|
||||
Public_static_property_0_of_exported_class_is_using_inaccessible_module_1: "Public static property '{0}' of exported class is using inaccessible module {1}.",
|
||||
Public_property_0_of_exported_class_is_using_inaccessible_module_1: "Public property '{0}' of exported class is using inaccessible module {1}.",
|
||||
Property_0_of_exported_interface_is_using_inaccessible_module_1: "Property '{0}' of exported interface is using inaccessible module {1}.",
|
||||
Exported_variable_0_is_using_inaccessible_module_1: "Exported variable '{0}' is using inaccessible module {1}.",
|
||||
Parameter_0_of_constructor_from_exported_class_has_or_is_using_private_type_1: "Parameter '{0}' of constructor from exported class has or is using private type '{1}'.",
|
||||
Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_private_type_1: "Parameter '{0}' of public static property setter from exported class has or is using private type '{1}'.",
|
||||
Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_private_type_1: "Parameter '{0}' of public property setter from exported class has or is using private type '{1}'.",
|
||||
Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_type_1: "Parameter '{0}' of constructor signature from exported interface has or is using private type '{1}'.",
|
||||
Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_type_1: "Parameter '{0}' of call signature from exported interface has or is using private type '{1}'.",
|
||||
Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_type_1: "Parameter '{0}' of public static method from exported class has or is using private type '{1}'.",
|
||||
Parameter_0_of_public_method_from_exported_class_has_or_is_using_private_type_1: "Parameter '{0}' of public method from exported class has or is using private type '{1}'.",
|
||||
Parameter_0_of_method_from_exported_interface_has_or_is_using_private_type_1: "Parameter '{0}' of method from exported interface has or is using private type '{1}'.",
|
||||
Parameter_0_of_exported_function_has_or_is_using_private_type_1: "Parameter '{0}' of exported function has or is using private type '{1}'.",
|
||||
Parameter_0_of_constructor_from_exported_class_is_using_inaccessible_module_1: "Parameter '{0}' of constructor from exported class is using inaccessible module {1}.",
|
||||
Parameter_0_of_public_static_property_setter_from_exported_class_is_using_inaccessible_module_1: "Parameter '{0}' of public static property setter from exported class is using inaccessible module {1}.",
|
||||
Parameter_0_of_public_property_setter_from_exported_class_is_using_inaccessible_module_1: "Parameter '{0}' of public property setter from exported class is using inaccessible module {1}.",
|
||||
Parameter_0_of_constructor_signature_from_exported_interface_is_using_inaccessible_module_1: "Parameter '{0}' of constructor signature from exported interface is using inaccessible module {1}.",
|
||||
Parameter_0_of_call_signature_from_exported_interface_is_using_inaccessible_module_1: "Parameter '{0}' of call signature from exported interface is using inaccessible module {1}",
|
||||
Parameter_0_of_public_static_method_from_exported_class_is_using_inaccessible_module_1: "Parameter '{0}' of public static method from exported class is using inaccessible module {1}.",
|
||||
Parameter_0_of_public_method_from_exported_class_is_using_inaccessible_module_1: "Parameter '{0}' of public method from exported class is using inaccessible module {1}.",
|
||||
Parameter_0_of_method_from_exported_interface_is_using_inaccessible_module_1: "Parameter '{0}' of method from exported interface is using inaccessible module {1}.",
|
||||
Parameter_0_of_exported_function_is_using_inaccessible_module_1: "Parameter '{0}' of exported function is using inaccessible module {1}.",
|
||||
Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_private_type_0: "Return type of public static property getter from exported class has or is using private type '{0}'.",
|
||||
Return_type_of_public_property_getter_from_exported_class_has_or_is_using_private_type_0: "Return type of public property getter from exported class has or is using private type '{0}'.",
|
||||
Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_private_type_0: "Return type of constructor signature from exported interface has or is using private type '{0}'.",
|
||||
Return_type_of_call_signature_from_exported_interface_has_or_is_using_private_type_0: "Return type of call signature from exported interface has or is using private type '{0}'.",
|
||||
Return_type_of_index_signature_from_exported_interface_has_or_is_using_private_type_0: "Return type of index signature from exported interface has or is using private type '{0}'.",
|
||||
Return_type_of_public_static_method_from_exported_class_has_or_is_using_private_type_0: "Return type of public static method from exported class has or is using private type '{0}'.",
|
||||
Return_type_of_public_method_from_exported_class_has_or_is_using_private_type_0: "Return type of public method from exported class has or is using private type '{0}'.",
|
||||
Return_type_of_method_from_exported_interface_has_or_is_using_private_type_0: "Return type of method from exported interface has or is using private type '{0}'.",
|
||||
Return_type_of_exported_function_has_or_is_using_private_type_0: "Return type of exported function has or is using private type '{0}'.",
|
||||
Return_type_of_public_static_property_getter_from_exported_class_is_using_inaccessible_module_0: "Return type of public static property getter from exported class is using inaccessible module {0}.",
|
||||
Return_type_of_public_property_getter_from_exported_class_is_using_inaccessible_module_0: "Return type of public property getter from exported class is using inaccessible module {0}.",
|
||||
Return_type_of_constructor_signature_from_exported_interface_is_using_inaccessible_module_0: "Return type of constructor signature from exported interface is using inaccessible module {0}.",
|
||||
Return_type_of_call_signature_from_exported_interface_is_using_inaccessible_module_0: "Return type of call signature from exported interface is using inaccessible module {0}.",
|
||||
Return_type_of_index_signature_from_exported_interface_is_using_inaccessible_module_0: "Return type of index signature from exported interface is using inaccessible module {0}.",
|
||||
Return_type_of_public_static_method_from_exported_class_is_using_inaccessible_module_0: "Return type of public static method from exported class is using inaccessible module {0}.",
|
||||
Return_type_of_public_method_from_exported_class_is_using_inaccessible_module_0: "Return type of public method from exported class is using inaccessible module {0}.",
|
||||
Return_type_of_method_from_exported_interface_is_using_inaccessible_module_0: "Return type of method from exported interface is using inaccessible module {0}.",
|
||||
Return_type_of_exported_function_is_using_inaccessible_module_0: "Return type of exported function is using inaccessible module {0}.",
|
||||
new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: "'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.",
|
||||
A_parameter_list_must_follow_a_generic_type_argument_list_expected: "A parameter list must follow a generic type argument list. '(' expected.",
|
||||
Multiple_constructor_implementations_are_not_allowed: "Multiple constructor implementations are not allowed.",
|
||||
Unable_to_resolve_external_module_0: "Unable to resolve external module '{0}'.",
|
||||
Module_cannot_be_aliased_to_a_non_module_type: "Module cannot be aliased to a non-module type.",
|
||||
A_class_may_only_extend_another_class: "A class may only extend another class.",
|
||||
A_class_may_only_implement_another_class_or_interface: "A class may only implement another class or interface.",
|
||||
An_interface_may_only_extend_another_class_or_interface: "An interface may only extend another class or interface.",
|
||||
Unable_to_resolve_type: "Unable to resolve type.",
|
||||
Unable_to_resolve_type_of_0: "Unable to resolve type of '{0}'.",
|
||||
Unable_to_resolve_type_parameter_constraint: "Unable to resolve type parameter constraint.",
|
||||
Type_parameter_constraint_cannot_be_a_primitive_type: "Type parameter constraint cannot be a primitive type.",
|
||||
Supplied_parameters_do_not_match_any_signature_of_call_target: "Supplied parameters do not match any signature of call target.",
|
||||
Supplied_parameters_do_not_match_any_signature_of_call_target_NL_0: "Supplied parameters do not match any signature of call target:{NL}{0}",
|
||||
Invalid_new_expression: "Invalid 'new' expression.",
|
||||
Call_signatures_used_in_a_new_expression_must_have_a_void_return_type: "Call signatures used in a 'new' expression must have a 'void' return type.",
|
||||
Could_not_select_overload_for_new_expression: "Could not select overload for 'new' expression.",
|
||||
Type_0_does_not_satisfy_the_constraint_1_for_type_parameter_2: "Type '{0}' does not satisfy the constraint '{1}' for type parameter '{2}'.",
|
||||
Could_not_select_overload_for_call_expression: "Could not select overload for 'call' expression.",
|
||||
Cannot_invoke_an_expression_whose_type_lacks_a_call_signature: "Cannot invoke an expression whose type lacks a call signature.",
|
||||
Calls_to_super_are_only_valid_inside_a_class: "Calls to 'super' are only valid inside a class.",
|
||||
Generic_type_0_requires_1_type_argument_s: "Generic type '{0}' requires {1} type argument(s).",
|
||||
Type_of_array_literal_cannot_be_determined_Best_common_type_could_not_be_found_for_array_elements: "Type of array literal cannot be determined. Best common type could not be found for array elements.",
|
||||
Could_not_find_enclosing_symbol_for_dotted_name_0: "Could not find enclosing symbol for dotted name '{0}'.",
|
||||
The_property_0_does_not_exist_on_value_of_type_1: "The property '{0}' does not exist on value of type '{1}'.",
|
||||
Could_not_find_symbol_0: "Could not find symbol '{0}'.",
|
||||
get_and_set_accessor_must_have_the_same_type: "'get' and 'set' accessor must have the same type.",
|
||||
this_cannot_be_referenced_in_current_location: "'this' cannot be referenced in current location.",
|
||||
Static_members_cannot_reference_class_type_parameters: "Static members cannot reference class type parameters.",
|
||||
Class_0_is_recursively_referenced_as_a_base_type_of_itself: "Class '{0}' is recursively referenced as a base type of itself.",
|
||||
Interface_0_is_recursively_referenced_as_a_base_type_of_itself: "Interface '{0}' is recursively referenced as a base type of itself.",
|
||||
super_property_access_is_permitted_only_in_a_constructor_member_function_or_member_accessor_of_a_derived_class: "'super' property access is permitted only in a constructor, member function, or member accessor of a derived class.",
|
||||
super_cannot_be_referenced_in_non_derived_classes: "'super' cannot be referenced in non-derived classes.",
|
||||
A_super_call_must_be_the_first_statement_in_the_constructor_when_a_class_contains_initialized_properties_or_has_parameter_properties: "A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties.",
|
||||
Constructors_for_derived_classes_must_contain_a_super_call: "Constructors for derived classes must contain a 'super' call.",
|
||||
Super_calls_are_not_permitted_outside_constructors_or_in_nested_functions_inside_constructors: "Super calls are not permitted outside constructors or in nested functions inside constructors.",
|
||||
_0_1_is_inaccessible: "'{0}.{1}' is inaccessible.",
|
||||
this_cannot_be_referenced_within_module_bodies: "'this' cannot be referenced within module bodies.",
|
||||
Invalid_expression_types_not_known_to_support_the_addition_operator: "Invalid '+' expression - types not known to support the addition operator.",
|
||||
The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type: "The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.",
|
||||
The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_or_an_enum_type: "The left-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type.",
|
||||
The_type_of_a_unary_arithmetic_operation_operand_must_be_of_type_any_number_or_an_enum_type: "The type of a unary arithmetic operation operand must be of type 'any', 'number' or an enum type.",
|
||||
Variable_declarations_of_a_for_statement_cannot_use_a_type_annotation: "Variable declarations of a 'for' statement cannot use a type annotation.",
|
||||
Variable_declarations_of_a_for_statement_must_be_of_types_string_or_any: "Variable declarations of a 'for' statement must be of types 'string' or 'any'.",
|
||||
The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter: "The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter.",
|
||||
The_left_hand_side_of_an_in_expression_must_be_of_types_any_string_or_number: "The left-hand side of an 'in' expression must be of types 'any', 'string' or 'number'.",
|
||||
The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter: "The right-hand side of an 'in' expression must be of type 'any', an object type or a type parameter.",
|
||||
The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter: "The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter.",
|
||||
The_right_hand_side_of_an_instanceof_expression_must_be_of_type_any_or_of_a_type_assignable_to_the_Function_interface_type: "The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type.",
|
||||
Setters_cannot_return_a_value: "Setters cannot return a value.",
|
||||
Tried_to_query_type_of_uninitialized_module_0: "Tried to query type of uninitialized module '{0}'.",
|
||||
Tried_to_set_variable_type_to_uninitialized_module_type_0: "Tried to set variable type to uninitialized module type '{0}'.",
|
||||
Type_0_does_not_have_type_parameters: "Type '{0}' does not have type parameters.",
|
||||
Getters_must_return_a_value: "Getters must return a value.",
|
||||
Getter_and_setter_accessors_do_not_agree_in_visibility: "Getter and setter accessors do not agree in visibility.",
|
||||
Invalid_left_hand_side_of_assignment_expression: "Invalid left-hand side of assignment expression.",
|
||||
Function_declared_a_non_void_return_type_but_has_no_return_expression: "Function declared a non-void return type, but has no return expression.",
|
||||
Cannot_resolve_return_type_reference: "Cannot resolve return type reference.",
|
||||
Constructors_cannot_have_a_return_type_of_void: "Constructors cannot have a return type of 'void'.",
|
||||
Subsequent_variable_declarations_must_have_the_same_type_Variable_0_must_be_of_type_1_but_here_has_type_2: "Subsequent variable declarations must have the same type. Variable '{0}' must be of type '{1}', but here has type '{2}'.",
|
||||
All_symbols_within_a_with_block_will_be_resolved_to_any: "All symbols within a with block will be resolved to 'any'.",
|
||||
Import_declarations_in_an_internal_module_cannot_reference_an_external_module: "Import declarations in an internal module cannot reference an external module.",
|
||||
Class_0_declares_interface_1_but_does_not_implement_it_NL_2: "Class {0} declares interface {1} but does not implement it:{NL}{2}",
|
||||
Class_0_declares_class_1_as_an_interface_but_does_not_implement_it_NL_2: "Class {0} declares class {1} as an interface but does not implement it:{NL}{2}",
|
||||
The_operand_of_an_increment_or_decrement_operator_must_be_a_variable_property_or_indexer: "The operand of an increment or decrement operator must be a variable, property or indexer.",
|
||||
this_cannot_be_referenced_in_static_initializers_in_a_class_body: "'this' cannot be referenced in static initializers in a class body.",
|
||||
Class_0_cannot_extend_class_1_NL_2: "Class '{0}' cannot extend class '{1}':{NL}{2}",
|
||||
Interface_0_cannot_extend_class_1_NL_2: "Interface '{0}' cannot extend class '{1}':{NL}{2}",
|
||||
Interface_0_cannot_extend_interface_1_NL_2: "Interface '{0}' cannot extend interface '{1}':{NL}{2}",
|
||||
Duplicate_overload_signature_for_0: "Duplicate overload signature for '{0}'.",
|
||||
Duplicate_constructor_overload_signature: "Duplicate constructor overload signature.",
|
||||
Duplicate_overload_call_signature: "Duplicate overload call signature.",
|
||||
Duplicate_overload_construct_signature: "Duplicate overload construct signature.",
|
||||
Overload_signature_is_not_compatible_with_function_definition: "Overload signature is not compatible with function definition.",
|
||||
Overload_signature_is_not_compatible_with_function_definition_NL_0: "Overload signature is not compatible with function definition:{NL}{0}",
|
||||
Overload_signatures_must_all_be_public_or_private: "Overload signatures must all be public or private.",
|
||||
Overload_signatures_must_all_be_exported_or_not_exported: "Overload signatures must all be exported or not exported.",
|
||||
Overload_signatures_must_all_be_ambient_or_non_ambient: "Overload signatures must all be ambient or non-ambient.",
|
||||
Overload_signatures_must_all_be_optional_or_required: "Overload signatures must all be optional or required.",
|
||||
Specialized_overload_signature_is_not_assignable_to_any_non_specialized_signature: "Specialized overload signature is not assignable to any non-specialized signature.",
|
||||
this_cannot_be_referenced_in_constructor_arguments: "'this' cannot be referenced in constructor arguments.",
|
||||
Instance_member_cannot_be_accessed_off_a_class: "Instance member cannot be accessed off a class.",
|
||||
Untyped_function_calls_may_not_accept_type_arguments: "Untyped function calls may not accept type arguments.",
|
||||
Non_generic_functions_may_not_accept_type_arguments: "Non-generic functions may not accept type arguments.",
|
||||
A_generic_type_may_not_reference_itself_with_a_wrapped_form_of_its_own_type_parameters: "A generic type may not reference itself with a wrapped form of its own type parameters.",
|
||||
Rest_parameters_must_be_array_types: "Rest parameters must be array types.",
|
||||
Overload_signature_implementation_cannot_use_specialized_type: "Overload signature implementation cannot use specialized type.",
|
||||
Export_assignments_may_only_be_used_at_the_top_level_of_external_modules: "Export assignments may only be used at the top-level of external modules.",
|
||||
Export_assignments_may_only_be_made_with_variables_functions_classes_interfaces_enums_and_internal_modules: "Export assignments may only be made with variables, functions, classes, interfaces, enums and internal modules.",
|
||||
Only_public_methods_of_the_base_class_are_accessible_via_the_super_keyword: "Only public methods of the base class are accessible via the 'super' keyword.",
|
||||
Numeric_indexer_type_0_must_be_assignable_to_string_indexer_type_1: "Numeric indexer type '{0}' must be assignable to string indexer type '{1}'.",
|
||||
Numeric_indexer_type_0_must_be_assignable_to_string_indexer_type_1_NL_2: "Numeric indexer type '{0}' must be assignable to string indexer type '{1}':{NL}{2}",
|
||||
All_numerically_named_properties_must_be_assignable_to_numeric_indexer_type_0: "All numerically named properties must be assignable to numeric indexer type '{0}'.",
|
||||
All_numerically_named_properties_must_be_assignable_to_numeric_indexer_type_0_NL_1: "All numerically named properties must be assignable to numeric indexer type '{0}':{NL}{1}",
|
||||
All_named_properties_must_be_assignable_to_string_indexer_type_0: "All named properties must be assignable to string indexer type '{0}'.",
|
||||
All_named_properties_must_be_assignable_to_string_indexer_type_0_NL_1: "All named properties must be assignable to string indexer type '{0}':{NL}{1}",
|
||||
Generic_type_references_must_include_all_type_arguments: "Generic type references must include all type arguments.",
|
||||
Default_arguments_are_only_allowed_in_implementation: "Default arguments are only allowed in implementation.",
|
||||
Overloads_cannot_differ_only_by_return_type: "Overloads cannot differ only by return type.",
|
||||
Function_expression_declared_a_non_void_return_type_but_has_no_return_expression: "Function expression declared a non-void return type, but has no return expression.",
|
||||
Import_declaration_referencing_identifier_from_internal_module_can_only_be_made_with_variables_functions_classes_interfaces_enums_and_internal_modules: "Import declaration referencing identifier from internal module can only be made with variables, functions, classes, interfaces, enums and internal modules.",
|
||||
Could_not_find_symbol_0_in_module_1: "Could not find symbol '{0}' in module '{1}'.",
|
||||
Unable_to_resolve_module_reference_0: "Unable to resolve module reference '{0}'.",
|
||||
Could_not_find_module_0_in_module_1: "Could not find module '{0}' in module '{1}'.",
|
||||
Exported_import_declaration_0_is_assigned_value_with_type_that_has_or_is_using_private_type_1: "Exported import declaration '{0}' is assigned value with type that has or is using private type '{1}'.",
|
||||
Exported_import_declaration_0_is_assigned_value_with_type_that_is_using_inaccessible_module_1: "Exported import declaration '{0}' is assigned value with type that is using inaccessible module '{1}'.",
|
||||
Exported_import_declaration_0_is_assigned_type_that_has_or_is_using_private_type_1: "Exported import declaration '{0}' is assigned type that has or is using private type '{1}'.",
|
||||
Exported_import_declaration_0_is_assigned_type_that_is_using_inaccessible_module_1: "Exported import declaration '{0}' is assigned type that is using inaccessible module '{1}'.",
|
||||
Exported_import_declaration_0_is_assigned_container_that_is_or_is_using_inaccessible_module_1: "Exported import declaration '{0}' is assigned container that is or is using inaccessible module '{1}'.",
|
||||
Type_name_0_in_extends_clause_does_not_reference_constructor_function_for_1: "Type name '{0}' in extends clause does not reference constructor function for '{1}'.",
|
||||
Internal_module_reference_0_in_import_declaration_does_not_reference_module_instance_for_1: "Internal module reference '{0}' in import declaration does not reference module instance for '{1}'.",
|
||||
Module_0_cannot_merge_with_previous_declaration_of_1_in_a_different_file_2: "Module '{0}' cannot merge with previous declaration of '{1}' in a different file '{2}'.",
|
||||
Interface_0_cannot_simultaneously_extend_types_1_and_2_NL_3: "Interface '{0}' cannot simultaneously extend types '{1}' and '{2}':{NL}{3}",
|
||||
Initializer_of_parameter_0_cannot_reference_identifier_1_declared_after_it: "Initializer of parameter '{0}' cannot reference identifier '{1}' declared after it.",
|
||||
Ambient_external_module_declaration_cannot_be_reopened: "Ambient external module declaration cannot be reopened.",
|
||||
All_declarations_of_merged_declaration_0_must_be_exported_or_not_exported: "All declarations of merged declaration '{0}' must be exported or not exported.",
|
||||
super_cannot_be_referenced_in_constructor_arguments: "'super' cannot be referenced in constructor arguments.",
|
||||
Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class: "Return type of constructor signature must be assignable to the instance type of the class.",
|
||||
Ambient_external_module_declaration_must_be_defined_in_global_context: "Ambient external module declaration must be defined in global context.",
|
||||
Ambient_external_module_declaration_cannot_specify_relative_module_name: "Ambient external module declaration cannot specify relative module name.",
|
||||
Import_declaration_in_an_ambient_external_module_declaration_cannot_reference_external_module_through_relative_external_module_name: "Import declaration in an ambient external module declaration cannot reference external module through relative external module name.",
|
||||
Could_not_find_the_best_common_type_of_types_of_all_return_statement_expressions: "Could not find the best common type of types of all return statement expressions.",
|
||||
Import_declaration_cannot_refer_to_external_module_reference_when_noResolve_option_is_set: "Import declaration cannot refer to external module reference when --noResolve option is set.",
|
||||
Duplicate_identifier_this_Compiler_uses_variable_declaration_this_to_capture_this_reference: "Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference.",
|
||||
continue_statement_can_only_be_used_within_an_enclosing_iteration_statement: "'continue' statement can only be used within an enclosing iteration statement.",
|
||||
break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement: "'break' statement can only be used within an enclosing iteration or switch statement.",
|
||||
Jump_target_not_found: "Jump target not found.",
|
||||
Jump_target_cannot_cross_function_boundary: "Jump target cannot cross function boundary.",
|
||||
Duplicate_identifier_super_Compiler_uses_super_to_capture_base_class_reference: "Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference.",
|
||||
Expression_resolves_to_variable_declaration_this_that_compiler_uses_to_capture_this_reference: "Expression resolves to variable declaration '_this' that compiler uses to capture 'this' reference.",
|
||||
Expression_resolves_to_super_that_compiler_uses_to_capture_base_class_reference: "Expression resolves to '_super' that compiler uses to capture base class reference.",
|
||||
TypeParameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_type_1: "TypeParameter '{0}' of constructor signature from exported interface has or is using private type '{1}'.",
|
||||
TypeParameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_type_1: "TypeParameter '{0}' of call signature from exported interface has or is using private type '{1}'.",
|
||||
TypeParameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_type_1: "TypeParameter '{0}' of public static method from exported class has or is using private type '{1}'.",
|
||||
TypeParameter_0_of_public_method_from_exported_class_has_or_is_using_private_type_1: "TypeParameter '{0}' of public method from exported class has or is using private type '{1}'.",
|
||||
TypeParameter_0_of_method_from_exported_interface_has_or_is_using_private_type_1: "TypeParameter '{0}' of method from exported interface has or is using private type '{1}'.",
|
||||
TypeParameter_0_of_exported_function_has_or_is_using_private_type_1: "TypeParameter '{0}' of exported function has or is using private type '{1}'.",
|
||||
TypeParameter_0_of_constructor_signature_from_exported_interface_is_using_inaccessible_module_1: "TypeParameter '{0}' of constructor signature from exported interface is using inaccessible module {1}.",
|
||||
TypeParameter_0_of_call_signature_from_exported_interface_is_using_inaccessible_module_1: "TypeParameter '{0}' of call signature from exported interface is using inaccessible module {1}",
|
||||
TypeParameter_0_of_public_static_method_from_exported_class_is_using_inaccessible_module_1: "TypeParameter '{0}' of public static method from exported class is using inaccessible module {1}.",
|
||||
TypeParameter_0_of_public_method_from_exported_class_is_using_inaccessible_module_1: "TypeParameter '{0}' of public method from exported class is using inaccessible module {1}.",
|
||||
TypeParameter_0_of_method_from_exported_interface_is_using_inaccessible_module_1: "TypeParameter '{0}' of method from exported interface is using inaccessible module {1}.",
|
||||
TypeParameter_0_of_exported_function_is_using_inaccessible_module_1: "TypeParameter '{0}' of exported function is using inaccessible module {1}.",
|
||||
TypeParameter_0_of_exported_class_has_or_is_using_private_type_1: "TypeParameter '{0}' of exported class has or is using private type '{1}'.",
|
||||
TypeParameter_0_of_exported_interface_has_or_is_using_private_type_1: "TypeParameter '{0}' of exported interface has or is using private type '{1}'.",
|
||||
TypeParameter_0_of_exported_class_is_using_inaccessible_module_1: "TypeParameter '{0}' of exported class is using inaccessible module {1}.",
|
||||
TypeParameter_0_of_exported_interface_is_using_inaccessible_module_1: "TypeParameter '{0}' of exported interface is using inaccessible module {1}.",
|
||||
Duplicate_identifier_i_Compiler_uses_i_to_initialize_rest_parameter: "Duplicate identifier '_i'. Compiler uses '_i' to initialize rest parameter.",
|
||||
Duplicate_identifier_arguments_Compiler_uses_arguments_to_initialize_rest_parameters: "Duplicate identifier 'arguments'. Compiler uses 'arguments' to initialize rest parameters.",
|
||||
Type_of_conditional_0_must_be_identical_to_1_or_2: "Type of conditional '{0}' must be identical to '{1}' or '{2}'.",
|
||||
Type_of_conditional_0_must_be_identical_to_1_2_or_3: "Type of conditional '{0}' must be identical to '{1}', '{2}' or '{3}'.",
|
||||
Duplicate_identifier_0_Compiler_reserves_name_1_in_top_level_scope_of_an_external_module: "Duplicate identifier '{0}'. Compiler reserves name '{1}' in top level scope of an external module.",
|
||||
Constraint_of_a_type_parameter_cannot_reference_any_type_parameter_from_the_same_type_parameter_list: "Constraint of a type parameter cannot reference any type parameter from the same type parameter list.",
|
||||
Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor.",
|
||||
Parameter_0_cannot_be_referenced_in_its_initializer: "Parameter '{0}' cannot be referenced in its initializer.",
|
||||
Duplicate_string_index_signature: "Duplicate string index signature.",
|
||||
Duplicate_number_index_signature: "Duplicate number index signature.",
|
||||
All_declarations_of_an_interface_must_have_identical_type_parameters: "All declarations of an interface must have identical type parameters.",
|
||||
Expression_resolves_to_variable_declaration_i_that_compiler_uses_to_initialize_rest_parameter: "Expression resolves to variable declaration '_i' that compiler uses to initialize rest parameter.",
|
||||
Type_0_is_missing_property_1_from_type_2: "Type '{0}' is missing property '{1}' from type '{2}'.",
|
||||
Types_of_property_0_of_types_1_and_2_are_incompatible: "Types of property '{0}' of types '{1}' and '{2}' are incompatible.",
|
||||
Types_of_property_0_of_types_1_and_2_are_incompatible_NL_3: "Types of property '{0}' of types '{1}' and '{2}' are incompatible:{NL}{3}",
|
||||
Property_0_defined_as_private_in_type_1_is_defined_as_public_in_type_2: "Property '{0}' defined as private in type '{1}' is defined as public in type '{2}'.",
|
||||
Property_0_defined_as_public_in_type_1_is_defined_as_private_in_type_2: "Property '{0}' defined as public in type '{1}' is defined as private in type '{2}'.",
|
||||
Types_0_and_1_define_property_2_as_private: "Types '{0}' and '{1}' define property '{2}' as private.",
|
||||
Call_signatures_of_types_0_and_1_are_incompatible: "Call signatures of types '{0}' and '{1}' are incompatible.",
|
||||
Call_signatures_of_types_0_and_1_are_incompatible_NL_2: "Call signatures of types '{0}' and '{1}' are incompatible:{NL}{2}",
|
||||
Type_0_requires_a_call_signature_but_type_1_lacks_one: "Type '{0}' requires a call signature, but type '{1}' lacks one.",
|
||||
Construct_signatures_of_types_0_and_1_are_incompatible: "Construct signatures of types '{0}' and '{1}' are incompatible.",
|
||||
Construct_signatures_of_types_0_and_1_are_incompatible_NL_2: "Construct signatures of types '{0}' and '{1}' are incompatible:{NL}{2}",
|
||||
Type_0_requires_a_construct_signature_but_type_1_lacks_one: "Type '{0}' requires a construct signature, but type '{1}' lacks one.",
|
||||
Index_signatures_of_types_0_and_1_are_incompatible: "Index signatures of types '{0}' and '{1}' are incompatible.",
|
||||
Index_signatures_of_types_0_and_1_are_incompatible_NL_2: "Index signatures of types '{0}' and '{1}' are incompatible:{NL}{2}",
|
||||
Call_signature_expects_0_or_fewer_parameters: "Call signature expects {0} or fewer parameters.",
|
||||
Could_not_apply_type_0_to_argument_1_which_is_of_type_2: "Could not apply type '{0}' to argument {1} which is of type '{2}'.",
|
||||
Class_0_defines_instance_member_accessor_1_but_extended_class_2_defines_it_as_instance_member_function: "Class '{0}' defines instance member accessor '{1}', but extended class '{2}' defines it as instance member function.",
|
||||
Class_0_defines_instance_member_property_1_but_extended_class_2_defines_it_as_instance_member_function: "Class '{0}' defines instance member property '{1}', but extended class '{2}' defines it as instance member function.",
|
||||
Class_0_defines_instance_member_function_1_but_extended_class_2_defines_it_as_instance_member_accessor: "Class '{0}' defines instance member function '{1}', but extended class '{2}' defines it as instance member accessor.",
|
||||
Class_0_defines_instance_member_function_1_but_extended_class_2_defines_it_as_instance_member_property: "Class '{0}' defines instance member function '{1}', but extended class '{2}' defines it as instance member property.",
|
||||
Types_of_static_property_0_of_class_1_and_class_2_are_incompatible: "Types of static property '{0}' of class '{1}' and class '{2}' are incompatible.",
|
||||
Types_of_static_property_0_of_class_1_and_class_2_are_incompatible_NL_3: "Types of static property '{0}' of class '{1}' and class '{2}' are incompatible:{NL}{3}",
|
||||
Type_reference_cannot_refer_to_container_0: "Type reference cannot refer to container '{0}'.",
|
||||
Type_reference_must_refer_to_type: "Type reference must refer to type.",
|
||||
In_enums_with_multiple_declarations_only_one_declaration_can_omit_an_initializer_for_the_first_enum_element: "In enums with multiple declarations only one declaration can omit an initializer for the first enum element.",
|
||||
_0_overload_s: " (+ {0} overload(s))",
|
||||
Variable_declaration_cannot_have_the_same_name_as_an_import_declaration: "Variable declaration cannot have the same name as an import declaration.",
|
||||
Signature_expected_0_type_arguments_got_1_instead: "Signature expected {0} type arguments, got {1} instead.",
|
||||
Property_0_defined_as_optional_in_type_1_but_is_required_in_type_2: "Property '{0}' defined as optional in type '{1}', but is required in type '{2}'.",
|
||||
Types_0_and_1_originating_in_infinitely_expanding_type_reference_do_not_refer_to_same_named_type: "Types '{0}' and '{1}' originating in infinitely expanding type reference do not refer to same named type.",
|
||||
Types_0_and_1_originating_in_infinitely_expanding_type_reference_have_incompatible_type_arguments: "Types '{0}' and '{1}' originating in infinitely expanding type reference have incompatible type arguments.",
|
||||
Types_0_and_1_originating_in_infinitely_expanding_type_reference_have_incompatible_type_arguments_NL_2: "Types '{0}' and '{1}' originating in infinitely expanding type reference have incompatible type arguments:{NL}{2}",
|
||||
Named_properties_0_of_types_1_and_2_are_not_identical: "Named properties '{0}' of types '{1}' and '{2}' are not identical.",
|
||||
Types_of_string_indexer_of_types_0_and_1_are_not_identical: "Types of string indexer of types '{0}' and '{1}' are not identical.",
|
||||
Types_of_number_indexer_of_types_0_and_1_are_not_identical: "Types of number indexer of types '{0}' and '{1}' are not identical.",
|
||||
Type_of_number_indexer_in_type_0_is_not_assignable_to_string_indexer_type_in_type_1_NL_2: "Type of number indexer in type '{0}' is not assignable to string indexer type in type '{1}'.{NL}{2}",
|
||||
Type_of_property_0_in_type_1_is_not_assignable_to_string_indexer_type_in_type_2_NL_3: "Type of property '{0}' in type '{1}' is not assignable to string indexer type in type '{2}'.{NL}{3}",
|
||||
Type_of_property_0_in_type_1_is_not_assignable_to_number_indexer_type_in_type_2_NL_3: "Type of property '{0}' in type '{1}' is not assignable to number indexer type in type '{2}'.{NL}{3}",
|
||||
Static_property_0_defined_as_private_in_type_1_is_defined_as_public_in_type_2: "Static property '{0}' defined as private in type '{1}' is defined as public in type '{2}'.",
|
||||
Static_property_0_defined_as_public_in_type_1_is_defined_as_private_in_type_2: "Static property '{0}' defined as public in type '{1}' is defined as private in type '{2}'.",
|
||||
Types_0_and_1_define_static_property_2_as_private: "Types '{0}' and '{1}' define static property '{2}' as private.",
|
||||
Current_host_does_not_support_0_option: "Current host does not support '{0}' option.",
|
||||
ECMAScript_target_version_0_not_supported_Specify_a_valid_target_version_1_default_or_2: "ECMAScript target version '{0}' not supported. Specify a valid target version: '{1}' (default), or '{2}'",
|
||||
Module_code_generation_0_not_supported: "Module code generation '{0}' not supported.",
|
||||
Could_not_find_file_0: "Could not find file: '{0}'.",
|
||||
A_file_cannot_have_a_reference_to_itself: "A file cannot have a reference to itself.",
|
||||
Cannot_resolve_referenced_file_0: "Cannot resolve referenced file: '{0}'.",
|
||||
Cannot_find_the_common_subdirectory_path_for_the_input_files: "Cannot find the common subdirectory path for the input files.",
|
||||
Emit_Error_0: "Emit Error: {0}.",
|
||||
Cannot_read_file_0_1: "Cannot read file '{0}': {1}",
|
||||
Unsupported_file_encoding: "Unsupported file encoding.",
|
||||
Locale_must_be_of_the_form_language_or_language_territory_For_example_0_or_1: "Locale must be of the form <language> or <language>-<territory>. For example '{0}' or '{1}'.",
|
||||
Unsupported_locale_0: "Unsupported locale: '{0}'.",
|
||||
Execution_Failed_NL: "Execution Failed.{NL}",
|
||||
Invalid_call_to_up: "Invalid call to 'up'",
|
||||
Invalid_call_to_down: "Invalid call to 'down'",
|
||||
Base64_value_0_finished_with_a_continuation_bit: "Base64 value '{0}' finished with a continuation bit.",
|
||||
Unknown_option_0: "Unknown option '{0}'",
|
||||
Expected_0_arguments_to_message_got_1_instead: "Expected {0} arguments to message, got {1} instead.",
|
||||
Expected_the_message_0_to_have_1_arguments_but_it_had_2: "Expected the message '{0}' to have {1} arguments, but it had {2}",
|
||||
Could_not_delete_file_0: "Could not delete file '{0}'",
|
||||
Could_not_create_directory_0: "Could not create directory '{0}'",
|
||||
Error_while_executing_file_0: "Error while executing file '{0}': ",
|
||||
Cannot_compile_external_modules_unless_the_module_flag_is_provided: "Cannot compile external modules unless the '--module' flag is provided.",
|
||||
Option_mapRoot_cannot_be_specified_without_specifying_sourcemap_option: "Option mapRoot cannot be specified without specifying sourcemap option.",
|
||||
Option_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option: "Option sourceRoot cannot be specified without specifying sourcemap option.",
|
||||
Options_mapRoot_and_sourceRoot_cannot_be_specified_without_specifying_sourcemap_option: "Options mapRoot and sourceRoot cannot be specified without specifying sourcemap option.",
|
||||
Option_0_specified_without_1: "Option '{0}' specified without '{1}'",
|
||||
codepage_option_not_supported_on_current_platform: "'codepage' option not supported on current platform.",
|
||||
Concatenate_and_emit_output_to_single_file: "Concatenate and emit output to single file.",
|
||||
Generates_corresponding_0_file: "Generates corresponding {0} file.",
|
||||
Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations: "Specifies the location where debugger should locate map files instead of generated locations.",
|
||||
Specifies_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations: "Specifies the location where debugger should locate TypeScript files instead of source locations.",
|
||||
Watch_input_files: "Watch input files.",
|
||||
Redirect_output_structure_to_the_directory: "Redirect output structure to the directory.",
|
||||
Do_not_emit_comments_to_output: "Do not emit comments to output.",
|
||||
Skip_resolution_and_preprocessing: "Skip resolution and preprocessing.",
|
||||
Specify_ECMAScript_target_version_0_default_or_1: "Specify ECMAScript target version: '{0}' (default), or '{1}'",
|
||||
Specify_module_code_generation_0_or_1: "Specify module code generation: '{0}' or '{1}'",
|
||||
Print_this_message: "Print this message.",
|
||||
Print_the_compiler_s_version_0: "Print the compiler's version: {0}",
|
||||
Allow_use_of_deprecated_0_keyword_when_referencing_an_external_module: "Allow use of deprecated '{0}' keyword when referencing an external module.",
|
||||
Specify_locale_for_errors_and_messages_For_example_0_or_1: "Specify locale for errors and messages. For example '{0}' or '{1}'",
|
||||
Syntax_0: "Syntax: {0}",
|
||||
options: "options",
|
||||
file1: "file",
|
||||
Examples: "Examples:",
|
||||
Options: "Options:",
|
||||
Insert_command_line_options_and_files_from_a_file: "Insert command line options and files from a file.",
|
||||
Version_0: "Version {0}",
|
||||
Use_the_0_flag_to_see_options: "Use the '{0}' flag to see options.",
|
||||
NL_Recompiling_0: "{NL}Recompiling ({0}):",
|
||||
STRING: "STRING",
|
||||
KIND: "KIND",
|
||||
file2: "FILE",
|
||||
VERSION: "VERSION",
|
||||
LOCATION: "LOCATION",
|
||||
DIRECTORY: "DIRECTORY",
|
||||
NUMBER: "NUMBER",
|
||||
Specify_the_codepage_to_use_when_opening_source_files: "Specify the codepage to use when opening source files.",
|
||||
Additional_locations: "Additional locations:",
|
||||
This_version_of_the_Javascript_runtime_does_not_support_the_0_function: "This version of the Javascript runtime does not support the '{0}' function.",
|
||||
Unknown_rule: "Unknown rule.",
|
||||
Invalid_line_number_0: "Invalid line number ({0})",
|
||||
Warn_on_expressions_and_declarations_with_an_implied_any_type: "Warn on expressions and declarations with an implied 'any' type.",
|
||||
Variable_0_implicitly_has_an_any_type: "Variable '{0}' implicitly has an 'any' type.",
|
||||
Parameter_0_of_1_implicitly_has_an_any_type: "Parameter '{0}' of '{1}' implicitly has an 'any' type.",
|
||||
Parameter_0_of_function_type_implicitly_has_an_any_type: "Parameter '{0}' of function type implicitly has an 'any' type.",
|
||||
Member_0_of_object_type_implicitly_has_an_any_type: "Member '{0}' of object type implicitly has an 'any' type.",
|
||||
new_expression_which_lacks_a_constructor_signature_implicitly_has_an_any_type: "'new' expression, which lacks a constructor signature, implicitly has an 'any' type.",
|
||||
_0_which_lacks_return_type_annotation_implicitly_has_an_any_return_type: "'{0}', which lacks return-type annotation, implicitly has an 'any' return type.",
|
||||
Function_expression_which_lacks_return_type_annotation_implicitly_has_an_any_return_type: "Function expression, which lacks return-type annotation, implicitly has an 'any' return type.",
|
||||
Parameter_0_of_lambda_function_implicitly_has_an_any_type: "Parameter '{0}' of lambda function implicitly has an 'any' type.",
|
||||
Constructor_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type: "Constructor signature, which lacks return-type annotation, implicitly has an 'any' return type.",
|
||||
Lambda_Function_which_lacks_return_type_annotation_implicitly_has_an_any_return_type: "Lambda Function, which lacks return-type annotation, implicitly has an 'any' return type.",
|
||||
Array_Literal_implicitly_has_an_any_type_from_widening: "Array Literal implicitly has an 'any' type from widening.",
|
||||
_0_which_lacks_get_accessor_and_parameter_type_annotation_on_set_accessor_implicitly_has_an_any_type: "'{0}', which lacks 'get' accessor and parameter type annotation on 'set' accessor, implicitly has an 'any' type.",
|
||||
Index_signature_of_object_type_implicitly_has_an_any_type: "Index signature of object type implicitly has an 'any' type.",
|
||||
Object_literal_s_property_0_implicitly_has_an_any_type_from_widening: "Object literal's property '{0}' implicitly has an 'any' type from widening.",
|
||||
};
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,2 @@
|
||||
/// <reference path='diagnosticCode.generated.ts' />
|
||||
/// <reference path='diagnosticInformationMap.generated.ts' />
|
||||
@@ -0,0 +1,157 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
/// Compiler settings
|
||||
export class CompilationSettings {
|
||||
public propagateEnumConstants: boolean = false;
|
||||
public removeComments: boolean = false;
|
||||
public watch: boolean = false;
|
||||
public noResolve: boolean = false;
|
||||
public allowAutomaticSemicolonInsertion: boolean = true;
|
||||
public noImplicitAny: boolean = false;
|
||||
public noLib: boolean = false;
|
||||
public codeGenTarget: LanguageVersion = LanguageVersion.EcmaScript3;
|
||||
public moduleGenTarget: ModuleGenTarget = ModuleGenTarget.Unspecified;
|
||||
public outFileOption: string = "";
|
||||
public outDirOption: string = "";
|
||||
public mapSourceFiles: boolean = false;
|
||||
public mapRoot: string = "";
|
||||
public sourceRoot: string = "";
|
||||
public generateDeclarationFiles: boolean = false;
|
||||
public useCaseSensitiveFileResolution: boolean = false;
|
||||
public gatherDiagnostics: boolean = false;
|
||||
public codepage: number = null
|
||||
public createFileLog: boolean = false;
|
||||
}
|
||||
|
||||
export class ImmutableCompilationSettings {
|
||||
private static _defaultSettings: ImmutableCompilationSettings;
|
||||
|
||||
private _propagateEnumConstants: boolean;
|
||||
private _removeComments: boolean;
|
||||
private _watch: boolean;
|
||||
private _noResolve: boolean;
|
||||
private _allowAutomaticSemicolonInsertion: boolean;
|
||||
private _noImplicitAny: boolean;
|
||||
private _noLib: boolean;
|
||||
private _codeGenTarget: LanguageVersion;
|
||||
private _moduleGenTarget: ModuleGenTarget;
|
||||
private _outFileOption: string;
|
||||
private _outDirOption: string;
|
||||
private _mapSourceFiles: boolean;
|
||||
private _mapRoot: string;
|
||||
private _sourceRoot: string;
|
||||
private _generateDeclarationFiles: boolean;
|
||||
private _useCaseSensitiveFileResolution: boolean;
|
||||
private _gatherDiagnostics: boolean;
|
||||
private _codepage: number;
|
||||
private _createFileLog: boolean;
|
||||
|
||||
public propagateEnumConstants() { return this._propagateEnumConstants; }
|
||||
public removeComments() { return this._removeComments; }
|
||||
public watch() { return this._watch; }
|
||||
public noResolve() { return this._noResolve; }
|
||||
public allowAutomaticSemicolonInsertion() { return this._allowAutomaticSemicolonInsertion; }
|
||||
public noImplicitAny() { return this._noImplicitAny; }
|
||||
public noLib() { return this._noLib; }
|
||||
public codeGenTarget() { return this._codeGenTarget; }
|
||||
public moduleGenTarget() { return this._moduleGenTarget; }
|
||||
public outFileOption() { return this._outFileOption; }
|
||||
public outDirOption() { return this._outDirOption; }
|
||||
public mapSourceFiles() { return this._mapSourceFiles; }
|
||||
public mapRoot() { return this._mapRoot; }
|
||||
public sourceRoot() { return this._sourceRoot; }
|
||||
public generateDeclarationFiles() { return this._generateDeclarationFiles; }
|
||||
public useCaseSensitiveFileResolution() { return this._useCaseSensitiveFileResolution; }
|
||||
public gatherDiagnostics() { return this._gatherDiagnostics; }
|
||||
public codepage() { return this._codepage; }
|
||||
public createFileLog() { return this._createFileLog; }
|
||||
|
||||
constructor(
|
||||
propagateEnumConstants: boolean,
|
||||
removeComments: boolean,
|
||||
watch: boolean,
|
||||
noResolve: boolean,
|
||||
allowAutomaticSemicolonInsertion: boolean,
|
||||
noImplicitAny: boolean,
|
||||
noLib: boolean,
|
||||
codeGenTarget: LanguageVersion,
|
||||
moduleGenTarget: ModuleGenTarget,
|
||||
outFileOption: string,
|
||||
outDirOption: string,
|
||||
mapSourceFiles: boolean,
|
||||
mapRoot: string,
|
||||
sourceRoot: string,
|
||||
generateDeclarationFiles: boolean,
|
||||
useCaseSensitiveFileResolution: boolean,
|
||||
gatherDiagnostics: boolean,
|
||||
codepage: number,
|
||||
createFileLog: boolean) {
|
||||
|
||||
this._propagateEnumConstants = propagateEnumConstants;
|
||||
this._removeComments = removeComments;
|
||||
this._watch = watch;
|
||||
this._noResolve = noResolve;
|
||||
this._allowAutomaticSemicolonInsertion = allowAutomaticSemicolonInsertion;
|
||||
this._noImplicitAny = noImplicitAny;
|
||||
this._noLib = noLib;
|
||||
this._codeGenTarget = codeGenTarget;
|
||||
this._moduleGenTarget = moduleGenTarget;
|
||||
this._outFileOption = outFileOption;
|
||||
this._outDirOption = outDirOption;
|
||||
this._mapSourceFiles = mapSourceFiles;
|
||||
this._mapRoot = mapRoot;
|
||||
this._sourceRoot = sourceRoot;
|
||||
this._generateDeclarationFiles = generateDeclarationFiles;
|
||||
this._useCaseSensitiveFileResolution = useCaseSensitiveFileResolution;
|
||||
this._gatherDiagnostics = gatherDiagnostics;
|
||||
this._codepage = codepage;
|
||||
this._createFileLog = createFileLog;
|
||||
}
|
||||
|
||||
public static defaultSettings() {
|
||||
if (!ImmutableCompilationSettings._defaultSettings) {
|
||||
ImmutableCompilationSettings._defaultSettings = ImmutableCompilationSettings.fromCompilationSettings(new CompilationSettings());
|
||||
}
|
||||
|
||||
return ImmutableCompilationSettings._defaultSettings;
|
||||
}
|
||||
|
||||
public static fromCompilationSettings(settings: CompilationSettings): ImmutableCompilationSettings {
|
||||
return new ImmutableCompilationSettings(
|
||||
settings.propagateEnumConstants,
|
||||
settings.removeComments,
|
||||
settings.watch,
|
||||
settings.noResolve,
|
||||
settings.allowAutomaticSemicolonInsertion,
|
||||
settings.noImplicitAny,
|
||||
settings.noLib,
|
||||
settings.codeGenTarget,
|
||||
settings.moduleGenTarget,
|
||||
settings.outFileOption,
|
||||
settings.outDirOption,
|
||||
settings.mapSourceFiles,
|
||||
settings.mapRoot,
|
||||
settings.sourceRoot,
|
||||
settings.generateDeclarationFiles,
|
||||
settings.useCaseSensitiveFileResolution,
|
||||
settings.gatherDiagnostics,
|
||||
settings.codepage,
|
||||
settings.createFileLog);
|
||||
}
|
||||
|
||||
public toCompilationSettings(): any {
|
||||
var result = new CompilationSettings();
|
||||
|
||||
var thisAsIndexable: IIndexable<any> = <any>this;
|
||||
var resultAsIndexable: IIndexable<any> = <any>result
|
||||
for (var name in this) {
|
||||
if (this.hasOwnProperty(name) && StringUtilities.startsWith(name, "_")) {
|
||||
resultAsIndexable[name.substr(1)] = thisAsIndexable[name];
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,268 @@
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export class SourceMapPosition {
|
||||
public sourceLine: number;
|
||||
public sourceColumn: number;
|
||||
public emittedLine: number;
|
||||
public emittedColumn: number;
|
||||
}
|
||||
|
||||
export class SourceMapping {
|
||||
public start = new SourceMapPosition();
|
||||
public end = new SourceMapPosition();
|
||||
public nameIndex: number = -1;
|
||||
public childMappings: SourceMapping[] = [];
|
||||
}
|
||||
|
||||
export class SourceMapEntry {
|
||||
constructor(
|
||||
public emittedFile: string,
|
||||
public emittedLine: number,
|
||||
public emittedColumn: number,
|
||||
public sourceFile: string,
|
||||
public sourceLine: number,
|
||||
public sourceColumn: number,
|
||||
public sourceName: string) {
|
||||
|
||||
Debug.assert(isFinite(emittedLine));
|
||||
Debug.assert(isFinite(emittedColumn));
|
||||
Debug.assert(isFinite(sourceColumn));
|
||||
Debug.assert(isFinite(sourceLine));
|
||||
}
|
||||
}
|
||||
|
||||
export class SourceMapper {
|
||||
static MapFileExtension = ".map";
|
||||
|
||||
private jsFileName: string;
|
||||
private sourceMapPath: string;
|
||||
private sourceMapDirectory: string;
|
||||
private sourceRoot: string;
|
||||
|
||||
public names: string[] = [];
|
||||
|
||||
private mappingLevel: IASTSpan[] = [];
|
||||
|
||||
// Below two arrays represent the information about sourceFile at that index.
|
||||
private tsFilePaths: string[] = [];
|
||||
private allSourceMappings: SourceMapping[][] = [];
|
||||
|
||||
public currentMappings: SourceMapping[][];
|
||||
public currentNameIndex: number[];
|
||||
|
||||
private sourceMapEntries: SourceMapEntry[] = [];
|
||||
|
||||
constructor(private jsFile: TextWriter,
|
||||
private sourceMapOut: TextWriter,
|
||||
document: Document,
|
||||
jsFilePath: string,
|
||||
emitOptions: EmitOptions,
|
||||
resolvePath: (path: string) => string) {
|
||||
this.setSourceMapOptions(document, jsFilePath, emitOptions, resolvePath);
|
||||
this.setNewSourceFile(document, emitOptions);
|
||||
}
|
||||
|
||||
public getOutputFile(): OutputFile {
|
||||
var result = this.sourceMapOut.getOutputFile();
|
||||
result.sourceMapEntries = this.sourceMapEntries;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public increaseMappingLevel(ast: IASTSpan) {
|
||||
this.mappingLevel.push(ast);
|
||||
}
|
||||
|
||||
public decreaseMappingLevel(ast: IASTSpan) {
|
||||
Debug.assert(this.mappingLevel.length > 0, "Mapping level should never be less than 0. This suggests a missing start call.");
|
||||
var expectedAst = this.mappingLevel.pop();
|
||||
var expectedAstInfo: any = (<AST>expectedAst).kind ? SyntaxKind[(<AST>expectedAst).kind()] : [expectedAst.start(), expectedAst.end()];
|
||||
var astInfo: any = (<AST>ast).kind ? SyntaxKind[(<AST>ast).kind()] : [ast.start(), ast.end()]
|
||||
Debug.assert(
|
||||
ast === expectedAst,
|
||||
"Provided ast is not the expected AST, Expected: " + expectedAstInfo + " Given: " + astInfo)
|
||||
}
|
||||
|
||||
public setNewSourceFile(document: Document, emitOptions: EmitOptions) {
|
||||
// Set new mappings
|
||||
var sourceMappings: SourceMapping[] = [];
|
||||
this.allSourceMappings.push(sourceMappings);
|
||||
this.currentMappings = [sourceMappings];
|
||||
this.currentNameIndex = [];
|
||||
|
||||
// Set new source file path
|
||||
this.setNewSourceFilePath(document, emitOptions);
|
||||
}
|
||||
|
||||
private setSourceMapOptions(document: Document, jsFilePath: string, emitOptions: EmitOptions, resolvePath: (path: string) => string) {
|
||||
// Decode mapRoot and sourceRoot
|
||||
|
||||
// Js File Name = pretty name of js file
|
||||
var prettyJsFileName = TypeScript.getPrettyName(jsFilePath, false, true);
|
||||
var prettyMapFileName = prettyJsFileName + SourceMapper.MapFileExtension;
|
||||
this.jsFileName = prettyJsFileName;
|
||||
|
||||
// Figure out sourceMapPath and sourceMapDirectory
|
||||
if (emitOptions.sourceMapRootDirectory()) {
|
||||
// Get the sourceMap Directory
|
||||
this.sourceMapDirectory = emitOptions.sourceMapRootDirectory();
|
||||
if (document.emitToOwnOutputFile()) {
|
||||
// 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
|
||||
this.sourceMapDirectory = this.sourceMapDirectory + switchToForwardSlashes(getRootFilePath((document.fileName)).replace(emitOptions.commonDirectoryPath(), ""));
|
||||
}
|
||||
|
||||
if (isRelative(this.sourceMapDirectory)) {
|
||||
// The relative paths are relative to the common directory
|
||||
this.sourceMapDirectory = emitOptions.commonDirectoryPath() + this.sourceMapDirectory;
|
||||
this.sourceMapDirectory = convertToDirectoryPath(switchToForwardSlashes(resolvePath(this.sourceMapDirectory)));
|
||||
this.sourceMapPath = getRelativePathToFixedPath(getRootFilePath(jsFilePath), this.sourceMapDirectory + prettyMapFileName);
|
||||
}
|
||||
else {
|
||||
this.sourceMapPath = this.sourceMapDirectory + prettyMapFileName;
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.sourceMapPath = prettyMapFileName;
|
||||
this.sourceMapDirectory = getRootFilePath(jsFilePath);
|
||||
}
|
||||
this.sourceRoot = emitOptions.sourceRootDirectory();
|
||||
}
|
||||
|
||||
private setNewSourceFilePath(document: Document, emitOptions: EmitOptions) {
|
||||
var tsFilePath = switchToForwardSlashes(document.fileName);
|
||||
if (emitOptions.sourceRootDirectory()) {
|
||||
// Use the relative path corresponding to the common directory path
|
||||
tsFilePath = getRelativePathToFixedPath(emitOptions.commonDirectoryPath(), tsFilePath);
|
||||
}
|
||||
else {
|
||||
// Source locations relative to map file location
|
||||
tsFilePath = getRelativePathToFixedPath(this.sourceMapDirectory, tsFilePath);
|
||||
}
|
||||
this.tsFilePaths.push(tsFilePath);
|
||||
}
|
||||
|
||||
// Generate source mapping.
|
||||
// Creating files can cause exceptions, they will be caught higher up in TypeScriptCompiler.emit
|
||||
public emitSourceMapping(): void {
|
||||
Debug.assert(
|
||||
this.mappingLevel.length === 0,
|
||||
"Mapping level is not 0. This suggest a missing end call. Value: " +
|
||||
this.mappingLevel.map(item => ['Node of type', SyntaxKind[(<AST>item).kind()], 'at', item.start(), 'to', item.end()].join(' ')).join(', '));
|
||||
// Output map file name into the js file
|
||||
this.jsFile.WriteLine("//# sourceMappingURL=" + this.sourceMapPath);
|
||||
|
||||
// Now output map file
|
||||
var mappingsString = "";
|
||||
|
||||
var prevEmittedColumn = 0;
|
||||
var prevEmittedLine = 0;
|
||||
var prevSourceColumn = 0;
|
||||
var prevSourceLine = 0;
|
||||
var prevSourceIndex = 0;
|
||||
var prevNameIndex = 0;
|
||||
var emitComma = false;
|
||||
|
||||
var recordedPosition: SourceMapPosition = null;
|
||||
for (var sourceIndex = 0; sourceIndex < this.tsFilePaths.length; sourceIndex++) {
|
||||
var recordSourceMapping = (mappedPosition: SourceMapPosition, nameIndex: number) => {
|
||||
|
||||
if (recordedPosition !== null &&
|
||||
recordedPosition.emittedColumn === mappedPosition.emittedColumn &&
|
||||
recordedPosition.emittedLine === mappedPosition.emittedLine) {
|
||||
// This position is already recorded
|
||||
return;
|
||||
}
|
||||
|
||||
// Record this position
|
||||
if (prevEmittedLine !== mappedPosition.emittedLine) {
|
||||
while (prevEmittedLine < mappedPosition.emittedLine) {
|
||||
prevEmittedColumn = 0;
|
||||
mappingsString = mappingsString + ";";
|
||||
prevEmittedLine++;
|
||||
}
|
||||
emitComma = false;
|
||||
}
|
||||
else if (emitComma) {
|
||||
mappingsString = mappingsString + ",";
|
||||
}
|
||||
|
||||
this.sourceMapEntries.push(new SourceMapEntry(
|
||||
this.jsFileName,
|
||||
mappedPosition.emittedLine + 1,
|
||||
mappedPosition.emittedColumn + 1,
|
||||
this.tsFilePaths[sourceIndex],
|
||||
mappedPosition.sourceLine,
|
||||
mappedPosition.sourceColumn + 1,
|
||||
nameIndex >= 0 ? this.names[nameIndex] : undefined));
|
||||
|
||||
// 1. Relative Column
|
||||
mappingsString = mappingsString + Base64VLQFormat.encode(mappedPosition.emittedColumn - prevEmittedColumn);
|
||||
prevEmittedColumn = mappedPosition.emittedColumn;
|
||||
|
||||
// 2. Relative sourceIndex
|
||||
mappingsString = mappingsString + Base64VLQFormat.encode(sourceIndex - prevSourceIndex);
|
||||
prevSourceIndex = sourceIndex;
|
||||
|
||||
// 3. Relative sourceLine 0 based
|
||||
mappingsString = mappingsString + Base64VLQFormat.encode(mappedPosition.sourceLine - 1 - prevSourceLine);
|
||||
prevSourceLine = mappedPosition.sourceLine - 1;
|
||||
|
||||
// 4. Relative sourceColumn 0 based
|
||||
mappingsString = mappingsString + Base64VLQFormat.encode(mappedPosition.sourceColumn - prevSourceColumn);
|
||||
prevSourceColumn = mappedPosition.sourceColumn;
|
||||
|
||||
// 5. Relative namePosition 0 based
|
||||
if (nameIndex >= 0) {
|
||||
mappingsString = mappingsString + Base64VLQFormat.encode(nameIndex - prevNameIndex);
|
||||
prevNameIndex = nameIndex;
|
||||
}
|
||||
|
||||
emitComma = true;
|
||||
recordedPosition = mappedPosition;
|
||||
};
|
||||
|
||||
// Record starting spans
|
||||
var recordSourceMappingSiblings = (sourceMappings: SourceMapping[]) => {
|
||||
for (var i = 0; i < sourceMappings.length; i++) {
|
||||
var sourceMapping = sourceMappings[i];
|
||||
recordSourceMapping(sourceMapping.start, sourceMapping.nameIndex);
|
||||
recordSourceMappingSiblings(sourceMapping.childMappings);
|
||||
recordSourceMapping(sourceMapping.end, sourceMapping.nameIndex);
|
||||
}
|
||||
};
|
||||
|
||||
recordSourceMappingSiblings(this.allSourceMappings[sourceIndex]);
|
||||
}
|
||||
|
||||
// Write the actual map file
|
||||
this.sourceMapOut.Write(JSON.stringify({
|
||||
version: 3,
|
||||
file: this.jsFileName,
|
||||
sourceRoot: this.sourceRoot,
|
||||
sources: this.tsFilePaths,
|
||||
names: this.names,
|
||||
mappings: mappingsString
|
||||
}));
|
||||
|
||||
// Closing files could result in exceptions, report them if they occur
|
||||
this.sourceMapOut.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
enum Accessibility {
|
||||
NotApplicable,
|
||||
Private,
|
||||
Public
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
///<reference path='..\Syntax\SyntaxTree.ts' />
|
||||
///<reference path='..\Core\ICancellationToken.ts' />
|
||||
///<reference path='ISemanticModel.ts' />
|
||||
///<reference path='ISymbol.ts' />
|
||||
|
||||
interface ICompilation {
|
||||
/**
|
||||
* Gets the syntax trees (parsed from source code) that this compilation was created with.
|
||||
*/
|
||||
syntaxTrees(): SyntaxTree[];
|
||||
|
||||
getSemanticModel(syntaxTree: SyntaxTree): ISemanticModel;
|
||||
|
||||
addSyntaxTrees(...syntaxTrees: SyntaxTree[]): void;
|
||||
|
||||
removeSyntaxTrees(...syntaxTrees: SyntaxTree[]): void;
|
||||
|
||||
replaceSyntaxTree(oldSyntaxTree: SyntaxTree, newSyntaxTree: SyntaxTree): void;
|
||||
|
||||
containsSyntaxTree(syntaxTree: SyntaxTree): boolean;
|
||||
|
||||
globalModule(): IModuleSymbol;
|
||||
|
||||
anyType(): IAnyTypeSymbol;
|
||||
|
||||
numberType(): INumberTypeSymbol;
|
||||
booleanType(): IBooleanTypeSymbol;
|
||||
stringType(): IStringTypeSymbol;
|
||||
voidType(): IVoidTypeSymbol;
|
||||
nullType(): INullTypeSymbol;
|
||||
undefinedType(): IUndefinedTypeSymbol;
|
||||
|
||||
/**
|
||||
* Gets all the diagnostics for the compilation, including syntax, declaration, and
|
||||
* binding. Does not include any diagnostics that might be produced during emit.
|
||||
*/
|
||||
getDiagnostics(cancellationToken: ICancellationToken): Diagnostic[];
|
||||
|
||||
// TODO: add parameters here to control emitting.
|
||||
emit(): void;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
///<reference path='ISymbol.ts' />
|
||||
///<reference path='ITypeSymbol.ts' />
|
||||
|
||||
interface IMemberSymbol extends ISymbol {
|
||||
}
|
||||
|
||||
interface IConstructorSymbol extends IMemberSymbol, IParameterizedSymbol {
|
||||
}
|
||||
|
||||
interface IFunctionSymbol extends IMemberSymbol, IParameterizedSymbol, IGenericSymbol {
|
||||
returnType(): ITypeSymbol;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a variable in a class, module or enum.
|
||||
*/
|
||||
interface IVariableSymbol extends IMemberSymbol {
|
||||
/**
|
||||
* Gets the type of this field.
|
||||
*/
|
||||
type(): ITypeSymbol;
|
||||
|
||||
hasValue(): boolean;
|
||||
|
||||
/**
|
||||
* Gets the constant value of this field.
|
||||
*/
|
||||
value(): any;
|
||||
|
||||
/// The parameter this variable was created from if it was created from a parameter.
|
||||
associatedParameter(): IParameterSymbol;
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
///<reference path='ICompilation.ts' />
|
||||
///<reference path='ISymbolInfo.ts' />
|
||||
///<reference path='ITypeInfo.ts' />
|
||||
|
||||
enum LookupOptions {
|
||||
/**
|
||||
* Consider all symbols.
|
||||
*/
|
||||
Default = 0,
|
||||
|
||||
/**
|
||||
* Consider only namespaces and types.
|
||||
*/
|
||||
ModulesOrTypesOnly = 1 << 1,
|
||||
}
|
||||
|
||||
interface ISemanticModel {
|
||||
compilation(): ICompilation;
|
||||
syntaxTree(): SyntaxTree;
|
||||
|
||||
getSymbolInfo(syntaxNode: SyntaxNode, cancellationToken: ICancellationToken): ISymbolInfo;
|
||||
getTypeInfo(syntaxNode: SyntaxNode, cancellationToken: ICancellationToken): ITypeInfo;
|
||||
|
||||
getDiagnostics(cancellationToken: ICancellationToken): Diagnostic[];
|
||||
|
||||
/**
|
||||
* Gets the symbol associated with a declaration syntax node. Returns the symbol declared by the node or null if the node is not a declaration.
|
||||
* @param declaration A syntax node that is a declaration. This can be any type
|
||||
* derived from MemberDeclarationSyntax, TypeDeclarationSyntax, EnumDeclarationSyntax,
|
||||
* NamespaceDeclarationSyntax, ParameterSyntax, TypeParameterSyntax, or the alias part of a
|
||||
* UsingDirectiveSyntax
|
||||
* @param cancellationToken The cancellation token.
|
||||
*/
|
||||
getDeclaredSymbol(declaration: SyntaxNode, cancellationToken: ICancellationToken): ISymbol;
|
||||
/**
|
||||
* Gets the symbol associated with a declaration syntax node. Returns the symbol declared by the node or null if the node is not a declaration.
|
||||
* @param declaration A syntax node that is a declaration. This can be any type
|
||||
* derived from MemberDeclarationSyntax, TypeDeclarationSyntax, EnumDeclarationSyntax,
|
||||
* NamespaceDeclarationSyntax, ParameterSyntax, TypeParameterSyntax, or the alias part of a
|
||||
* UsingDirectiveSyntax
|
||||
* @param cancellationToken The cancellation token.
|
||||
*/
|
||||
getDeclaredSymbol(declaration: ModuleDeclarationSyntax, cancellationToken: ICancellationToken): IModuleSymbol;
|
||||
/**
|
||||
* Gets the symbol associated with a declaration syntax node. Returns the symbol declared by the node or null if the node is not a declaration.
|
||||
* @param declaration A syntax node that is a declaration. This can be any type
|
||||
* derived from MemberDeclarationSyntax, TypeDeclarationSyntax, EnumDeclarationSyntax,
|
||||
* NamespaceDeclarationSyntax, ParameterSyntax, TypeParameterSyntax, or the alias part of a
|
||||
* UsingDirectiveSyntax
|
||||
* @param cancellationToken The cancellation token.
|
||||
*/
|
||||
getDeclaredSymbol(declaration: SourceUnitSyntax, cancellationToken: ICancellationToken): IModuleSymbol;
|
||||
/**
|
||||
* Gets the symbol associated with a declaration syntax node. Returns the symbol declared by the node or null if the node is not a declaration.
|
||||
* @param declaration A syntax node that is a declaration. This can be any type
|
||||
* derived from MemberDeclarationSyntax, TypeDeclarationSyntax, EnumDeclarationSyntax,
|
||||
* NamespaceDeclarationSyntax, ParameterSyntax, TypeParameterSyntax, or the alias part of a
|
||||
* UsingDirectiveSyntax
|
||||
* @param cancellationToken The cancellation token.
|
||||
*/
|
||||
getDeclaredSymbol(declaration: ClassDeclarationSyntax, cancellationToken: ICancellationToken): IObjectTypeSymbol;
|
||||
/**
|
||||
* Gets the symbol associated with a declaration syntax node. Returns the symbol declared by the node or null if the node is not a declaration.
|
||||
* @param declaration A syntax node that is a declaration. This can be any type
|
||||
* derived from MemberDeclarationSyntax, TypeDeclarationSyntax, EnumDeclarationSyntax,
|
||||
* NamespaceDeclarationSyntax, ParameterSyntax, TypeParameterSyntax, or the alias part of a
|
||||
* UsingDirectiveSyntax
|
||||
* @param cancellationToken The cancellation token.
|
||||
*/
|
||||
getDeclaredSymbol(declaration: InterfaceDeclarationSyntax, cancellationToken: ICancellationToken): IObjectTypeSymbol;
|
||||
/**
|
||||
* Gets the symbol associated with a declaration syntax node. Returns the symbol declared by the node or null if the node is not a declaration.
|
||||
* @param declaration A syntax node that is a declaration. This can be any type
|
||||
* derived from MemberDeclarationSyntax, TypeDeclarationSyntax, EnumDeclarationSyntax,
|
||||
* NamespaceDeclarationSyntax, ParameterSyntax, TypeParameterSyntax, or the alias part of a
|
||||
* UsingDirectiveSyntax
|
||||
* @param cancellationToken The cancellation token.
|
||||
*/
|
||||
getDeclaredSymbol(declaration: EnumDeclarationSyntax, cancellationToken: ICancellationToken): IObjectTypeSymbol;
|
||||
/**
|
||||
* Gets the symbol associated with a declaration syntax node. Returns the symbol declared by the node or null if the node is not a declaration.
|
||||
* @param declaration A syntax node that is a declaration. This can be any type
|
||||
* derived from MemberDeclarationSyntax, TypeDeclarationSyntax, EnumDeclarationSyntax,
|
||||
* NamespaceDeclarationSyntax, ParameterSyntax, TypeParameterSyntax, or the alias part of a
|
||||
* UsingDirectiveSyntax
|
||||
* @param cancellationToken The cancellation token.
|
||||
*/
|
||||
getDeclaredSymbol(declarator: VariableDeclaratorSyntax, cancellationToken: ICancellationToken): IVariableSymbol;
|
||||
|
||||
// TODO: add more getDeclaredSymbol overloads.
|
||||
|
||||
/**
|
||||
* Gets the list of available named symbols in the context of the specified location and optional container.
|
||||
* Only symbols that are accessible and visible from the given location are returned, if no symbols were found, an empty list is returned.
|
||||
* The "position" is used to determine what variables are visible and accessible. Even if "container" is
|
||||
* specified, the "position" location is significant for determining which members of "containing" are
|
||||
* accessible.
|
||||
* @param position The character position for determining the enclosing declaration scope and
|
||||
* accessibility.
|
||||
*/
|
||||
lookupSymbols(position: number): ISymbol[];
|
||||
/**
|
||||
* Gets the list of available named symbols in the context of the specified location and optional container.
|
||||
* Only symbols that are accessible and visible from the given location are returned, if no symbols were found, an empty list is returned.
|
||||
* The "position" is used to determine what variables are visible and accessible. Even if "container" is
|
||||
* specified, the "position" location is significant for determining which members of "containing" are
|
||||
* accessible.
|
||||
* @param position The character position for determining the enclosing declaration scope and
|
||||
* accessibility.
|
||||
* @param container The container to search for symbols within. If null then the enclosing declaration
|
||||
* scope around position is used.
|
||||
*/
|
||||
lookupSymbols(position: number, container: IModuleOrTypeSymbol): ISymbol[];
|
||||
/**
|
||||
* Gets the list of available named symbols in the context of the specified location and optional container.
|
||||
* Only symbols that are accessible and visible from the given location are returned, if no symbols were found, an empty list is returned.
|
||||
* The "position" is used to determine what variables are visible and accessible. Even if "container" is
|
||||
* specified, the "position" location is significant for determining which members of "containing" are
|
||||
* accessible.
|
||||
* @param position The character position for determining the enclosing declaration scope and
|
||||
* accessibility.
|
||||
* @param container The container to search for symbols within. If null then the enclosing declaration
|
||||
* scope around position is used.
|
||||
* @param name The name of the symbol to find. If null is specified then symbols
|
||||
* with any names are returned.
|
||||
*/
|
||||
lookupSymbols(position: number, container: IModuleOrTypeSymbol, name: string): ISymbol[];
|
||||
/**
|
||||
* Gets the list of available named symbols in the context of the specified location and optional container.
|
||||
* Only symbols that are accessible and visible from the given location are returned, if no symbols were found, an empty list is returned.
|
||||
* The "position" is used to determine what variables are visible and accessible. Even if "container" is
|
||||
* specified, the "position" location is significant for determining which members of "containing" are
|
||||
* accessible.
|
||||
* @param position The character position for determining the enclosing declaration scope and
|
||||
* accessibility.
|
||||
* @param container The container to search for symbols within. If null then the enclosing declaration
|
||||
* scope around position is used.
|
||||
* @param name The name of the symbol to find. If null is specified then symbols
|
||||
* with any names are returned.
|
||||
* @param arity The number of generic type parameters the symbol has. If null is specified then symbols
|
||||
* with any arity are returned.
|
||||
*/
|
||||
lookupSymbols(position: number, container: IModuleOrTypeSymbol, name: string, arity: number): ISymbol[];
|
||||
/**
|
||||
* Gets the list of available named symbols in the context of the specified location and optional container.
|
||||
* Only symbols that are accessible and visible from the given location are returned, if no symbols were found, an empty list is returned.
|
||||
* The "position" is used to determine what variables are visible and accessible. Even if "container" is
|
||||
* specified, the "position" location is significant for determining which members of "containing" are
|
||||
* accessible.
|
||||
* @param position The character position for determining the enclosing declaration scope and
|
||||
* accessibility.
|
||||
* @param container The container to search for symbols within. If null then the enclosing declaration
|
||||
* scope around position is used.
|
||||
* @param name The name of the symbol to find. If null is specified then symbols
|
||||
* with any names are returned.
|
||||
* @param arity The number of generic type parameters the symbol has. If null is specified then symbols
|
||||
* with any arity are returned.
|
||||
* @param options Additional options that affect the lookup process.
|
||||
*/
|
||||
lookupSymbols(position: number, container: IModuleOrTypeSymbol, name: string, arity: number, options: LookupOptions): ISymbol[];
|
||||
|
||||
getMethodGroup(node: SyntaxNode, cancellationToken: ICancellationToken): ISymbol[];
|
||||
|
||||
/**
|
||||
* Given a position in the SyntaxTree for this ISemanticModel returns the innermost ISymbol
|
||||
* that the position is considered inside of.
|
||||
*/
|
||||
getEnclosingSymbol(position: number, cancellationToken: ICancellationToken): ISymbol;
|
||||
|
||||
/**
|
||||
* Determines if the symbol is accessible from the specified location. Returns true if "symbol is accessible, false otherwise.
|
||||
* @param position A character position used to identify a declaration scope and
|
||||
* accessibility. This character position must be within the FullSpan of the Root syntax
|
||||
* node in this SemanticModel.
|
||||
* @param symbol The symbol that we are checking to see if it accessible.
|
||||
*/
|
||||
isAccessible(position: number, symbol: ISymbol): boolean;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
///<reference path='ISymbol.ts' />
|
||||
///<reference path='ITypeSymbol.ts' />
|
||||
|
||||
interface ISignatureSymbol extends ISymbol {
|
||||
type(): ITypeSymbol;
|
||||
}
|
||||
|
||||
interface ICallSignatureSymbol extends IParameterizedSymbol, IGenericSymbol {
|
||||
}
|
||||
|
||||
interface IConstructSignatureSymbol extends IParameterizedSymbol, IGenericSymbol {
|
||||
}
|
||||
|
||||
interface IIndexSignatureSymbol extends IParameterizedSymbol {
|
||||
}
|
||||
|
||||
interface IPropertySignature extends ISignatureSymbol {
|
||||
isOptional(): boolean;
|
||||
|
||||
/// True if this property's type is an anonymous type that is a function type.
|
||||
isFunctionSignature(): boolean;
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
///<reference path='..\Syntax\SyntaxNode.ts' />
|
||||
///<reference path='Accessibility.ts' />
|
||||
///<reference path='MethodKind.ts' />
|
||||
///<reference path='IMemberSymbol.ts' />
|
||||
///<reference path='ISymbolVisitor.ts' />
|
||||
///<reference path='SymbolDisplay.ts' />
|
||||
///<reference path='SymbolDisplay.Format.ts' />
|
||||
///<reference path='SymbolKind.ts' />
|
||||
///<reference path='TypeKind.ts' />
|
||||
|
||||
interface ISymbol {
|
||||
kind(): SymbolKind;
|
||||
|
||||
/**
|
||||
* Gets the symbol name. Returns the empty string if unnamed.
|
||||
*/
|
||||
name(): string;
|
||||
|
||||
/**
|
||||
* Gets the immediately containing symbol.
|
||||
*/
|
||||
containingSymbol(): ISymbol;
|
||||
|
||||
/**
|
||||
* Gets the containing type. Returns null if the symbol is not contained within a type.
|
||||
*/
|
||||
containingType(): IObjectTypeSymbol;
|
||||
|
||||
/**
|
||||
* Gets the nearest enclosing module. Returns null if the symbol isn't contained in a module.
|
||||
*/
|
||||
containingModule(): IModuleSymbol;
|
||||
|
||||
locations(): ILocation[];
|
||||
|
||||
// True if this symbol is a definition. False if it not (i.e. it is a constructed generic
|
||||
// symbol).
|
||||
isDefinition(): boolean;
|
||||
|
||||
/**
|
||||
* Gets the the original definition of the symbol. If this symbol is derived from another symbol,
|
||||
* by type substitution for instance, this gets the original symbol, as it was defined in source.
|
||||
*/
|
||||
originalDefinition(): ISymbol;
|
||||
|
||||
// True if this symbol was automatically generated based on the absense of the normal construct
|
||||
// that would usually cause it to be created. For example, a class with no 'constructor'
|
||||
// node will still have a symbol for the constructor synthesized.
|
||||
isImplicitlyDeclared(): boolean;
|
||||
|
||||
// Returns true if this symbol can be referenced by its name in code.
|
||||
canBeReferencedByName(): boolean;
|
||||
|
||||
accessibility(): Accessibility;
|
||||
|
||||
accept(visitor: ISymbolVisitor): any;
|
||||
|
||||
toSymbolDisplayParts(format: SymbolDisplay.Format): SymbolDisplay.Part[];
|
||||
|
||||
isStatic(): boolean;
|
||||
|
||||
isType(): boolean;
|
||||
isSignature(): boolean;
|
||||
isMember(): boolean;
|
||||
isPrimitiveType(): boolean;
|
||||
isObjectType(): boolean;
|
||||
isArrayType(): boolean;
|
||||
}
|
||||
|
||||
/// Represents any symbol that has type parameters.
|
||||
interface IGenericSymbol extends ISymbol {
|
||||
/**
|
||||
* Returns the type parameters that this type has. If this is a non-generic type,
|
||||
* returns an empty ReadOnlyArray.
|
||||
*/
|
||||
typeParameters(): ITypeParameterSymbol[];
|
||||
|
||||
/**
|
||||
* Returns the type arguments that have been substituted for the type parameters.
|
||||
* If nothing has been substituted for a give type parameters,
|
||||
* then the type parameter itself is consider the type argument.
|
||||
*/
|
||||
typeArguments(): ITypeSymbol[];
|
||||
|
||||
/**
|
||||
* Get the original definition of this type symbol. If this symbol is derived from another
|
||||
* symbol by (say) type substitution, this gets the original symbol, as it was defined in
|
||||
* source.
|
||||
*/
|
||||
originalDefinition(): IGenericSymbol;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a parameter of a method or property.
|
||||
*/
|
||||
interface IParameterSymbol extends ISymbol {
|
||||
/**
|
||||
* Returns true if the parameter was declared as a parameter array.
|
||||
*/
|
||||
isRest(): boolean;
|
||||
|
||||
/**
|
||||
* Returns true if the parameter is optional.
|
||||
*/
|
||||
isOptional(): boolean;
|
||||
|
||||
/**
|
||||
* Gets the type of the parameter.
|
||||
*/
|
||||
type(): ITypeSymbol;
|
||||
|
||||
/**
|
||||
* Gets the ordinal position of the parameter. The first parameter has ordinal zero.
|
||||
*/
|
||||
ordinal(): number;
|
||||
|
||||
/**
|
||||
* Returns true if the parameter specifies a default value to be passed
|
||||
* when no value is provided as an argument to a call. The default value
|
||||
* can be obtained with the DefaultValue property.
|
||||
*/
|
||||
hasValue(): boolean;
|
||||
|
||||
/**
|
||||
* Returns the default value of the parameter.
|
||||
*/
|
||||
value(): any;
|
||||
|
||||
/// The associated variable if this parameter caused a field to be generated.
|
||||
associatedVariable(): IVariableSymbol;
|
||||
}
|
||||
|
||||
/// Represents any symbol that takes parameters.
|
||||
interface IParameterizedSymbol extends ISymbol {
|
||||
parameters(): IParameterSymbol[];
|
||||
}
|
||||
|
||||
interface IModuleOrTypeSymbol extends ISymbol {
|
||||
}
|
||||
|
||||
interface IModuleSymbol extends IMemberSymbol, IModuleOrTypeSymbol {
|
||||
isGlobalModule(): boolean;
|
||||
|
||||
memberCount(): number;
|
||||
memberAt(index: number): IMemberSymbol;
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
///<reference path='ISymbol.ts' />
|
||||
|
||||
/**
|
||||
* Indicates the reasons why a candidate (or set of candidate) symbols were not considered
|
||||
* correct in SemanticInfo. Higher values take precedence over lower values, so if, for
|
||||
* example, there a symbol with a given name that was inaccessible, and other with the wrong
|
||||
* arity, only the inaccessible one would be reported in the SemanticInfo.
|
||||
*/
|
||||
enum CandidateReason {
|
||||
// Implementation note. Values in this enumeration should generally be kept in sync with the
|
||||
// language-specific LookupResultKind enumeration.
|
||||
|
||||
/**
|
||||
* No CandidateSymbols.
|
||||
*/
|
||||
None,
|
||||
|
||||
/**
|
||||
* Only a type or module was valid in the given location, but the candidate symbols was
|
||||
* of the wrong kind.
|
||||
*/
|
||||
NotATypeOrModule,
|
||||
|
||||
/**
|
||||
* The candidate symbol takes a different number of type parameters that was required.
|
||||
*/
|
||||
WrongArity,
|
||||
|
||||
/**
|
||||
* The candidate symbol existed, but was not allowed to be created in a new expression.
|
||||
* For example, interfaces, and type parameters.
|
||||
*/
|
||||
NotCreatable,
|
||||
|
||||
/**
|
||||
* The candidate symbol existed, but was not allowed to be referenced.
|
||||
*/
|
||||
NotReferencable,
|
||||
|
||||
/**
|
||||
* The candidate symbol had an accessibility modifier that made it inaccessible.
|
||||
*/
|
||||
Inaccessible,
|
||||
|
||||
/**
|
||||
* The candidate symbol was in a place where a value was required, but was not a value
|
||||
* (e.g., was a a type or module).
|
||||
*/
|
||||
NotAValue,
|
||||
|
||||
/**
|
||||
* The candidate symbol was in a place where a variable was required, but was not allowed there
|
||||
* because it isn't a symbol that can be assigned to. For example, the left hand side of an
|
||||
* assignment.
|
||||
*/
|
||||
NotAVariable,
|
||||
|
||||
/**
|
||||
* The candidate symbol was used in a way that an invocable member (method, function type)
|
||||
* was required, but the candidate symbol was not invocable.
|
||||
*/
|
||||
NotInvocable,
|
||||
|
||||
/**
|
||||
* The candidate symbol must be an instance variable, but was used as static, or the
|
||||
* reverse. Also occurs if "this" is used in a context (i.e. static method) where "this"
|
||||
* is not available.
|
||||
*/
|
||||
StaticInstanceMismatch,
|
||||
|
||||
/**
|
||||
* Overload resolution did not choose a method. The candidate symbols are the methods there
|
||||
* were considered during overload resolution (which may or may not be applicable methods).
|
||||
*/
|
||||
OverloadResolutionFailure,
|
||||
|
||||
/**
|
||||
* Multiple ambiguous symbols were available with the same name. This can occur if "using"
|
||||
* statements bring multiple namespaces into scope, and the same type is available in
|
||||
* multiple. This can also occur if multiple properties of the same name are available in a
|
||||
* multiple interface inheritance situation.
|
||||
*/
|
||||
Ambiguous,
|
||||
}
|
||||
|
||||
interface ISymbolInfo {
|
||||
/**
|
||||
* The symbol that was referred to by the syntax node, if any. Returns null if the given
|
||||
* expression did not bind successfully to a single symbol. If null is returned, it may
|
||||
* still be that case that we have one or more "best guesses" as to what symbol was
|
||||
* intended. These best guesses are available via the CandidateSymbols property.
|
||||
*/
|
||||
symbol(): ISymbol;
|
||||
|
||||
/**
|
||||
* If the expression did not successfully resolve to a symbol, but there were one or more
|
||||
* symbols that may have been considered but discarded, this property returns those
|
||||
* symbols. The reason that the symbols did not successfully resolve to a symbol are
|
||||
* available in the CandidateReason property. For example, if the symbol was inaccessible,
|
||||
* ambiguous, or used in the wrong context.
|
||||
*/
|
||||
candidateSymbols(): ISymbol[];
|
||||
|
||||
/*
|
||||
* If the expression did not successfully resolve to a symbol, but there were one or more
|
||||
* symbols that may have been considered but discarded, this property describes why those
|
||||
* symbol or symbols were not considered suitable.
|
||||
*/
|
||||
candidateReason(): CandidateReason;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
///<reference path='ISymbol.ts' />
|
||||
|
||||
interface ISymbolVisitor {
|
||||
visitAnyType(symbol: IAnyTypeSymbol): any;
|
||||
|
||||
// Primitive types
|
||||
visitNumberType(symbol: INumberTypeSymbol): any;
|
||||
visitBooleanType(symbol: IBooleanTypeSymbol): any;
|
||||
visitStringType(symbol: IStringTypeSymbol): any;
|
||||
visitVoidType(symbol: IVoidTypeSymbol): any;
|
||||
visitNullType(symbol: INullTypeSymbol): any;
|
||||
visitUndefinedType(symbol: IUndefinedTypeSymbol): any;
|
||||
|
||||
// Object types
|
||||
visitClassType(symbol: IClassTypeSymbol): any;
|
||||
visitInterfaceType(symbol: IInterfaceTypeSymbol): any;
|
||||
visitAnonymousType(symbol: IAnonymousTypeSymbol): any;
|
||||
// visitEnumType(symbol: IEnumTypeSymbol): any;
|
||||
// visitFunctionType(symbol: IFunctionTypeSymbol): any;
|
||||
// visitConstructorType(symbol: IConstructorTypeSymbol): any;
|
||||
|
||||
visitTypeParameter(symbol: ITypeParameterSymbol): any;
|
||||
|
||||
|
||||
visitVariable(symbol: IVariableSymbol): any;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
///<reference path='ISymbol.ts' />
|
||||
|
||||
interface ITypeInfo {
|
||||
/**
|
||||
* The type of the expression represented by the syntax node. For expressions that do not
|
||||
* have a type, null is returned. If the type could not be determined due to an error, than
|
||||
* an ErrorTypeSymbol is returned.
|
||||
*/
|
||||
type(): ITypeSymbol;
|
||||
|
||||
/**
|
||||
* The type of the expression after it has undergone an implicit conversion. If the type
|
||||
* did not undergo an implicit conversion, returns the same as Type.
|
||||
*/
|
||||
convertedType(): ITypeSymbol;
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
///<reference path='ISymbol.ts' />
|
||||
///<reference path='ISignatureSymbol.ts' />
|
||||
|
||||
interface ITypeSymbol extends IModuleOrTypeSymbol {
|
||||
/**
|
||||
* An enumerated value that identifies what kind of type this is.
|
||||
*/
|
||||
typeKind(): TypeKind;
|
||||
|
||||
/**
|
||||
* The declared base type of this type, or null.
|
||||
*/
|
||||
baseType(): IClassTypeSymbol;
|
||||
|
||||
/**
|
||||
* Gets the set of interfaces that this type directly implements. This set does not include
|
||||
* interfaces that are base interfaces of directly implemented interfaces.
|
||||
*/
|
||||
interfaces(): IInterfaceTypeSymbol[];
|
||||
|
||||
/**
|
||||
* The list of all interfaces of which this type is a declared subtype, excluding this type
|
||||
* itself. This includes all declared base interfaces, all declared base interfaces of base
|
||||
* types, and all declared base interfaces of those results (recursively). This also is the effective
|
||||
* interface set of a type parameter. Each result
|
||||
* appears exactly once in the list. This list is topologically sorted by the inheritance
|
||||
* relationship: if interface type A extends interface type B, then A precedes B in the
|
||||
* list.
|
||||
*/
|
||||
allInterfaces(): IInterfaceTypeSymbol[];
|
||||
|
||||
originalDefinition(): ITypeSymbol;
|
||||
|
||||
// isSubTypeOf(type: ITypeSymbol): boolean;
|
||||
// isSuperTypeOf(type: ITypeSymbol): boolean;
|
||||
// isIdenticalTo(type: ITypeSymbol): boolean;
|
||||
// isAssignableTo(type: ITypeSymbol): boolean;
|
||||
// isAssignableFrom(type: ITypeSymbol): boolean;
|
||||
}
|
||||
|
||||
interface IAnyTypeSymbol extends ITypeSymbol {
|
||||
}
|
||||
|
||||
interface IPrimitiveTypeSymbol extends ITypeSymbol {
|
||||
}
|
||||
|
||||
interface INumberTypeSymbol extends IPrimitiveTypeSymbol {
|
||||
}
|
||||
|
||||
interface IBooleanTypeSymbol extends IPrimitiveTypeSymbol {
|
||||
}
|
||||
|
||||
interface IStringTypeSymbol extends IPrimitiveTypeSymbol {
|
||||
}
|
||||
|
||||
interface IVoidTypeSymbol extends IPrimitiveTypeSymbol {
|
||||
}
|
||||
|
||||
interface INullTypeSymbol extends IPrimitiveTypeSymbol {
|
||||
}
|
||||
|
||||
interface IUndefinedTypeSymbol extends IPrimitiveTypeSymbol {
|
||||
}
|
||||
|
||||
interface IObjectTypeSymbol extends ITypeSymbol {
|
||||
/// An object type containing call signatures is said to be a function type.
|
||||
isFunctionType(): boolean;
|
||||
|
||||
/// A type containing construct signatures is said to be a constructor type.
|
||||
isConstructorType(): boolean;
|
||||
}
|
||||
|
||||
interface IClassTypeSymbol extends IMemberSymbol, IObjectTypeSymbol, IGenericSymbol {
|
||||
memberCount(): number;
|
||||
memberAt(index: number): IMemberSymbol;
|
||||
|
||||
/**
|
||||
* Get the original definition of this type symbol. If this symbol is derived from another
|
||||
* symbol by (say) type substitution, this gets the original symbol, as it was defined in
|
||||
* source.
|
||||
*/
|
||||
originalDefinition(): IClassTypeSymbol;
|
||||
|
||||
/**
|
||||
* Get the constructor for this type.
|
||||
*/
|
||||
constructorSymbol(): IConstructorSymbol;
|
||||
}
|
||||
|
||||
interface IInterfaceTypeSymbol extends IMemberSymbol, IObjectTypeSymbol, IGenericSymbol {
|
||||
signatureCount(): number;
|
||||
signatureAt(index: number): ISignatureSymbol;
|
||||
|
||||
/**
|
||||
* Get the original definition of this type symbol. If this symbol is derived from another
|
||||
* symbol by (say) type substitution, this gets the original symbol, as it was defined in
|
||||
* source.
|
||||
*/
|
||||
originalDefinition(): IInterfaceTypeSymbol;
|
||||
}
|
||||
|
||||
interface IAnonymousTypeSymbol extends IObjectTypeSymbol {
|
||||
signatureCount(): number;
|
||||
signatureAt(index: number): ISignatureSymbol;
|
||||
}
|
||||
|
||||
interface IEnumTypeSymbol extends IMemberSymbol, IObjectTypeSymbol {
|
||||
variableCount(): number;
|
||||
variableAt(index: number): IVariableSymbol;
|
||||
}
|
||||
|
||||
interface ITypeParameterSymbol extends ITypeSymbol {
|
||||
/**
|
||||
* The ordinal position of the type parameter in the parameter list which declares
|
||||
* it. The first type parameter has ordinal zero.
|
||||
*/
|
||||
ordinal(): number;
|
||||
|
||||
/**
|
||||
* The type that were directly specified as a constraint on the type parameter.
|
||||
*/
|
||||
constraintType(): ITypeSymbol;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Enumeration for possible kinds of method symbols.
|
||||
*/
|
||||
enum MethodKind
|
||||
{
|
||||
/**
|
||||
* An anonymous method or lambda expression
|
||||
*/
|
||||
ArrowFunction = 0,
|
||||
|
||||
/**
|
||||
* Method is a constructor.
|
||||
*/
|
||||
Constructor = 1,
|
||||
|
||||
/**
|
||||
* Method is an ordinary method.
|
||||
*/
|
||||
Ordinary = 10,
|
||||
|
||||
/**
|
||||
* Method is a property get.
|
||||
*/
|
||||
GetAccessor = 11,
|
||||
|
||||
/**
|
||||
* Method is a property set.
|
||||
*/
|
||||
SetAccessor = 12,
|
||||
}
|
||||
@@ -0,0 +1,263 @@
|
||||
|
||||
module SymbolDisplay {
|
||||
/**
|
||||
* Specifies the options for whether types are qualified when displayed in the description of a symbol.
|
||||
*/
|
||||
export enum TypeQualificationStyle {
|
||||
/**
|
||||
* e.g. Class1
|
||||
*/
|
||||
NameOnly,
|
||||
|
||||
/**
|
||||
* ParentClass.NestedClass
|
||||
*/
|
||||
NameAndContainingModules,
|
||||
}
|
||||
|
||||
export enum TypeOptions {
|
||||
None = 0,
|
||||
InlineAnonymousTypes = 1 << 0,
|
||||
}
|
||||
|
||||
export enum GenericsOptions {
|
||||
/**
|
||||
* Omit generics entirely.
|
||||
*/
|
||||
None = 0,
|
||||
|
||||
/**
|
||||
* Type parameters. e.g. "Foo<T>".
|
||||
*/
|
||||
IncludeTypeArguments = 1 << 0,
|
||||
|
||||
/**
|
||||
* Type parameter constraints. e.g. "<T extends Foo>".
|
||||
*/
|
||||
IncludeTypeConstraints = 1 << 1,
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the options for how members are displayed in the description of a symbol.
|
||||
*/
|
||||
export enum MemberOptions {
|
||||
/**
|
||||
* Display only the name of the member.
|
||||
*/
|
||||
None = 0,
|
||||
|
||||
/**
|
||||
* Include the (return) type of the method/field/property.
|
||||
*/
|
||||
IncludeType = 1 << 0,
|
||||
|
||||
/**
|
||||
* Include modifiers. e.g. "static"
|
||||
*/
|
||||
IncludeModifiers = 1 << 1,
|
||||
|
||||
/**
|
||||
* Include accessibility. e.g. "public"
|
||||
*/
|
||||
IncludeAccessibility = 1 << 2,
|
||||
|
||||
/**
|
||||
* Include method/indexer parameters. (See ParameterFlags for fine-grained settings.)
|
||||
*/
|
||||
IncludeParameters = 1 << 4,
|
||||
|
||||
/**
|
||||
* Include the name of the containing type.
|
||||
*/
|
||||
IncludeContainingType = 1 << 5,
|
||||
|
||||
/**
|
||||
* Include the value of the member if is a constant.
|
||||
*/
|
||||
IncludeConstantValue = 1 << 6,
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the options for how parameters are displayed in the description of a symbol.
|
||||
*/
|
||||
export enum ParameterOptions {
|
||||
/**
|
||||
* If MemberFlags.IncludeParameters is set, but this value is used, then only the parentheses will be shown
|
||||
* (e.g. M()).
|
||||
*/
|
||||
None = 0,
|
||||
|
||||
/**
|
||||
* Include the params/public/.../etc. parameters.
|
||||
*/
|
||||
IncludeModifiers = 1 << 1,
|
||||
|
||||
/**
|
||||
* Include the parameter type.
|
||||
*/
|
||||
IncludeType = 1 << 2,
|
||||
|
||||
/**
|
||||
* Include the parameter name.
|
||||
*/
|
||||
IncludeName = 1 << 3,
|
||||
|
||||
/**
|
||||
* Include the parameter default value.
|
||||
*/
|
||||
IncludeDefaultValue = 1 << 4,
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the options for how property/event accessors are displayed in the description of a symbol.
|
||||
*/
|
||||
export enum AccessorStyle {
|
||||
/**
|
||||
* Only show the name of the property (formatted using MemberFlags).
|
||||
*/
|
||||
NameOnly,
|
||||
|
||||
/**
|
||||
* Show the getter and/or setter of the property.
|
||||
*/
|
||||
ShowAccessors,
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the options for how locals are displayed in the description of a symbol.
|
||||
*/
|
||||
export enum LocalOptions {
|
||||
/**
|
||||
* Only show the name of the local. (e.g. "x").
|
||||
*/
|
||||
None = 0,
|
||||
|
||||
/**
|
||||
* Include the type of the local. (e.g. "x : number").
|
||||
*/
|
||||
IncludeType = 1 << 0,
|
||||
|
||||
/**
|
||||
* Include the value of the local if is a constant. (e.g. "x : number = 1").
|
||||
*/
|
||||
IncludeConstantValue = 1 << 1,
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the options for whether the type's kind should be displayed in the description of a symbol.
|
||||
*/
|
||||
export enum KindOptions {
|
||||
/**
|
||||
* None
|
||||
*/
|
||||
None = 0,
|
||||
|
||||
/**
|
||||
* Use the type's kind. e.g. "class M1.C1" instead of "M1.C1"
|
||||
*/
|
||||
IncludeKind = 1 << 0,
|
||||
}
|
||||
|
||||
export class Format {
|
||||
/**
|
||||
* Determines how types are qualified (e.g. Nested vs Containing.Nested vs Namespace.Containing.Nested).
|
||||
*/
|
||||
private _typeQualificationStyle: TypeQualificationStyle;
|
||||
|
||||
private _typeOptions: TypeOptions;
|
||||
|
||||
/**
|
||||
* Determines how generics (on types and methods) should be described (i.e. level of detail).
|
||||
*/
|
||||
private _genericsOptions: GenericsOptions;
|
||||
|
||||
/**
|
||||
* Formatting options that apply to fields, properties, and methods.
|
||||
*/
|
||||
private _memberOptions: MemberOptions;
|
||||
|
||||
/**
|
||||
* Formatting options that apply to method and indexer parameters (i.e. level of detail).
|
||||
*/
|
||||
private _parameterOptions: ParameterOptions;
|
||||
|
||||
/**
|
||||
* Determines how properties are displayed. "Prop" vs "Prop { get; set; }"
|
||||
*/
|
||||
private _accessorStyle: AccessorStyle;
|
||||
|
||||
/**
|
||||
* Determines how local variables are displayed.
|
||||
*/
|
||||
private _localOptions: LocalOptions;
|
||||
|
||||
/**
|
||||
* Formatting options that apply to types.
|
||||
*/
|
||||
private _kindOptions: KindOptions;
|
||||
|
||||
constructor(typeQualificationStyle: TypeQualificationStyle = TypeQualificationStyle.NameOnly,
|
||||
typeOptions: TypeOptions = TypeOptions.None,
|
||||
genericsOptions: GenericsOptions = GenericsOptions.None,
|
||||
memberOptions: MemberOptions = MemberOptions.None,
|
||||
parameterOptions: ParameterOptions = ParameterOptions.None,
|
||||
accessorStyle: AccessorStyle = AccessorStyle.NameOnly,
|
||||
localOptions: LocalOptions = LocalOptions.None,
|
||||
kindOptions: KindOptions = KindOptions.None) {
|
||||
this._typeQualificationStyle = typeQualificationStyle;
|
||||
this._typeOptions = typeOptions;
|
||||
this._genericsOptions = genericsOptions;
|
||||
this._memberOptions = memberOptions;
|
||||
this._parameterOptions = parameterOptions;
|
||||
this._accessorStyle = accessorStyle;
|
||||
this._localOptions = localOptions;
|
||||
this._kindOptions = kindOptions;
|
||||
}
|
||||
|
||||
public typeQualificationStyle(): TypeQualificationStyle {
|
||||
return this._typeQualificationStyle;
|
||||
}
|
||||
|
||||
public typeOptions(): TypeOptions {
|
||||
return this._typeOptions;
|
||||
}
|
||||
|
||||
public genericsOptions(): GenericsOptions {
|
||||
return this._genericsOptions;
|
||||
}
|
||||
|
||||
public memberOptions(): MemberOptions {
|
||||
return this._memberOptions;
|
||||
}
|
||||
}
|
||||
|
||||
export var errorMessageFormat: Format =
|
||||
new Format(
|
||||
TypeQualificationStyle.NameAndContainingModules,
|
||||
TypeOptions.InlineAnonymousTypes,
|
||||
GenericsOptions.IncludeTypeArguments,
|
||||
MemberOptions.IncludeParameters | MemberOptions.IncludeContainingType,
|
||||
ParameterOptions.IncludeModifiers | ParameterOptions.IncludeType,
|
||||
AccessorStyle.NameOnly);
|
||||
|
||||
/**
|
||||
* Fully qualified name format.
|
||||
*/
|
||||
//export var fullyQualifiedFormat: Format =
|
||||
// new Format(
|
||||
// TypeQualificationStyle.NameAndContainingModules,
|
||||
// GenericsOptions.IncludeTypeParameters);
|
||||
|
||||
/**
|
||||
* Format used by default when asking to minimally qualify a symbol.
|
||||
*/
|
||||
export var minimallyQualifiedFormat: Format =
|
||||
new Format(
|
||||
TypeQualificationStyle.NameOnly,
|
||||
TypeOptions.None,
|
||||
GenericsOptions.IncludeTypeArguments,
|
||||
MemberOptions.IncludeParameters | MemberOptions.IncludeType | MemberOptions.IncludeContainingType,
|
||||
ParameterOptions.IncludeName | ParameterOptions.IncludeType | ParameterOptions.IncludeModifiers | ParameterOptions.IncludeDefaultValue,
|
||||
AccessorStyle.NameOnly,
|
||||
LocalOptions.IncludeType);
|
||||
}
|
||||
@@ -0,0 +1,511 @@
|
||||
///<reference path='..\Core\EnumUtilities.ts' />
|
||||
///<reference path='ISemanticModel.ts' />
|
||||
///<reference path='..\Syntax\Location.ts' />
|
||||
|
||||
module SymbolDisplay {
|
||||
export enum PartKind {
|
||||
ClassName,
|
||||
EnumName,
|
||||
ErrorTypeName,
|
||||
FieldName,
|
||||
InterfaceName,
|
||||
Keyword,
|
||||
LineBreak,
|
||||
NumericLiteral,
|
||||
StringLiteral,
|
||||
LocalName,
|
||||
MethodName,
|
||||
ModuleName,
|
||||
Operator,
|
||||
ParameterName,
|
||||
PropertyName,
|
||||
Punctuation,
|
||||
Space,
|
||||
Text,
|
||||
TypeParameterName,
|
||||
}
|
||||
|
||||
export class Part {
|
||||
private _kind: PartKind;
|
||||
private _text: string;
|
||||
private _symbol: ISymbol;
|
||||
|
||||
constructor(kind: PartKind, text: string, symbol: ISymbol = null) {
|
||||
this._kind = kind;
|
||||
this._text = text;
|
||||
this._symbol = symbol;
|
||||
}
|
||||
|
||||
public kind(): PartKind {
|
||||
return this._kind;
|
||||
}
|
||||
|
||||
public text(): string {
|
||||
return this._text;
|
||||
}
|
||||
|
||||
public symbol(): ISymbol {
|
||||
return this._symbol;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a symbol to an array of string parts, each of which has a kind. Useful for
|
||||
* colorizing the display string. Returns a read-only array of string parts.
|
||||
* @param symbol Symbol to be displayed.
|
||||
* @param format Formatting rules - null implies Format.ErrorMessageFormat.
|
||||
*/
|
||||
export function toDisplayParts(symbol: ISymbol, format: Format = null): Part[] {
|
||||
// null indicates the default format (as in IFormattable.ToString)
|
||||
format = format || errorMessageFormat;
|
||||
return toDisplayPartsWorker(
|
||||
symbol, /*location:*/ null, /*semanticModel:*/ null, format, /*minimal:*/ false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a symbol to an array of string parts, each of which has a kind. May be tailored
|
||||
* to a specific location in the source code. Useful for colorizing the display string. Returns a read-only array of string parts.
|
||||
* @param symbol Symbol to be displayed.
|
||||
* @param location A location in the source code (context).
|
||||
* @param semanticModel Binding information (for determining names appropriate to the context).
|
||||
* @param format Formatting rules - null implies Format.MinimallyQualifiedFormat.
|
||||
*/
|
||||
export function toMinimalDisplayParts(symbol: ISymbol,
|
||||
location: ILocation,
|
||||
semanticModel: ISemanticModel,
|
||||
format: Format = null): Part[] {
|
||||
format = format || minimallyQualifiedFormat;
|
||||
return toDisplayPartsWorker(symbol, location, semanticModel, format, /*minimal:*/ true);
|
||||
}
|
||||
|
||||
function toDisplayPartsWorker(symbol: ISymbol,
|
||||
location: ILocation,
|
||||
semanticModel: ISemanticModel,
|
||||
format: Format,
|
||||
minimal: boolean): Part[] {
|
||||
if (minimal) {
|
||||
if (location == null) {
|
||||
// TODO(cyrusn): Localize
|
||||
throw Errors.argument("location", "Location must be provided in order to provide minimal type qualification.");
|
||||
}
|
||||
|
||||
if (semanticModel == null) {
|
||||
// TODO(cyrusn): Localize
|
||||
throw Errors.argument("semanticModel", "Semantic model must be provided in order to provide minimal type qualification.");
|
||||
}
|
||||
}
|
||||
|
||||
var result: Part[] = [];
|
||||
symbol.accept(new Visitor(format, location, semanticModel, minimal, result));
|
||||
return result;
|
||||
}
|
||||
|
||||
class Visitor implements ISymbolVisitor {
|
||||
private location: ILocation;
|
||||
private semanticModel: ISemanticModel;
|
||||
private format: Format;
|
||||
private builder: Part[];
|
||||
private isFirstSymbolVisited: boolean;
|
||||
private minimal: boolean;
|
||||
|
||||
private notFirstVisitor: Visitor;
|
||||
|
||||
constructor(format: Format,
|
||||
location: ILocation,
|
||||
semanticModel: ISemanticModel,
|
||||
minimal: boolean,
|
||||
builder: Part[],
|
||||
isFirstSymbolVisited: boolean = true) {
|
||||
this.location = location;
|
||||
this.semanticModel = semanticModel;
|
||||
|
||||
this.format = format;
|
||||
this.minimal = minimal;
|
||||
this.builder = builder;
|
||||
this.isFirstSymbolVisited = isFirstSymbolVisited;
|
||||
|
||||
if (isFirstSymbolVisited) {
|
||||
this.notFirstVisitor = new Visitor(format, location, semanticModel, minimal, builder, !isFirstSymbolVisited);
|
||||
}
|
||||
else {
|
||||
this.notFirstVisitor = this;
|
||||
}
|
||||
}
|
||||
|
||||
private addKeyword(kind: SyntaxKind): void {
|
||||
this.builder.push(new Part(PartKind.Keyword, SyntaxFacts.getText(kind), null));
|
||||
}
|
||||
|
||||
private addPunctuation(kind: SyntaxKind): void {
|
||||
this.builder.push(new Part(PartKind.Punctuation, SyntaxFacts.getText(kind), null));
|
||||
}
|
||||
|
||||
private addSpace(): void {
|
||||
this.builder.push(new Part(PartKind.Keyword, " ", null));
|
||||
}
|
||||
|
||||
private visitAnyType(symbol: IAnyTypeSymbol): void {
|
||||
this.addKeyword(SyntaxKind.AnyKeyword);
|
||||
}
|
||||
|
||||
private visitNumberType(symbol: INumberTypeSymbol): void {
|
||||
this.addKeyword(SyntaxKind.NumberKeyword);
|
||||
}
|
||||
|
||||
private visitBooleanType(symbol: IBooleanTypeSymbol): void {
|
||||
this.addKeyword(SyntaxKind.BooleanKeyword);
|
||||
}
|
||||
|
||||
private visitStringType(symbol: IStringTypeSymbol): void {
|
||||
this.addKeyword(SyntaxKind.StringKeyword);
|
||||
}
|
||||
|
||||
private visitVoidType(symbol: IVoidTypeSymbol): void {
|
||||
this.addKeyword(SyntaxKind.VoidKeyword);
|
||||
}
|
||||
|
||||
private visitNullType(symbol: INullTypeSymbol): void {
|
||||
this.addKeyword(SyntaxKind.NullKeyword);
|
||||
}
|
||||
|
||||
private visitUndefinedType(symbol: IUndefinedTypeSymbol): void {
|
||||
this.builder.push(new Part(PartKind.Text, "undefined", symbol));
|
||||
}
|
||||
|
||||
private visitTypeParameter(symbol: ITypeParameterSymbol): void {
|
||||
this.builder.push(new Part(PartKind.TypeParameterName, symbol.name(), symbol));
|
||||
}
|
||||
|
||||
private addContainingModuleIfRequired(symbol: ISymbol): void {
|
||||
var containingModule = symbol.containingModule();
|
||||
if (this.shouldVisitModule(containingModule)) {
|
||||
containingModule.accept(this.notFirstVisitor);
|
||||
this.addPunctuation(SyntaxKind.DotToken);
|
||||
}
|
||||
}
|
||||
|
||||
private visitArrayType(symbol: IClassTypeSymbol): void {
|
||||
var brackets = 1;
|
||||
|
||||
var elementType = symbol.typeArguments()[0];
|
||||
while (elementType.isArrayType()) {
|
||||
elementType = (<IClassTypeSymbol>elementType).typeArguments()[0];
|
||||
brackets++;
|
||||
}
|
||||
|
||||
elementType.accept(this.notFirstVisitor);
|
||||
|
||||
for (var i = 0; i < brackets; i++) {
|
||||
this.addPunctuation(SyntaxKind.OpenBracketToken);
|
||||
this.addPunctuation(SyntaxKind.CloseBracketToken);
|
||||
}
|
||||
}
|
||||
|
||||
private visitClassType(symbol: IClassTypeSymbol): void {
|
||||
if (symbol.isArrayType()) {
|
||||
this.visitArrayType(symbol);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.minimal) {
|
||||
this.minimallyQualify(symbol, symbol.typeParameters().length);
|
||||
return;
|
||||
}
|
||||
|
||||
this.addTypeKind(symbol);
|
||||
this.addContainingModuleIfRequired(symbol);
|
||||
this.addNameAndTypeArguments(symbol, symbol.typeArguments());
|
||||
}
|
||||
|
||||
private visitInterfaceType(symbol: IInterfaceTypeSymbol): void {
|
||||
if (this.minimal) {
|
||||
this.minimallyQualify(symbol, symbol.typeParameters().length);
|
||||
return;
|
||||
}
|
||||
|
||||
this.addTypeKind(symbol);
|
||||
this.addContainingModuleIfRequired(symbol);
|
||||
this.addNameAndTypeArguments(symbol, symbol.typeArguments());
|
||||
}
|
||||
|
||||
private visitEnumType(symbol: IEnumTypeSymbol): void {
|
||||
if (this.minimal) {
|
||||
this.minimallyQualify(symbol, /*arity:*/ 0);
|
||||
return;
|
||||
}
|
||||
|
||||
this.addTypeKind(symbol);
|
||||
this.addContainingModuleIfRequired(symbol);
|
||||
|
||||
this.builder.push(new Part(this.getPartKind(symbol), symbol.name(), symbol));
|
||||
}
|
||||
|
||||
private addTypeKind(symbol: ITypeSymbol): void {
|
||||
if (this.isFirstSymbolVisited) {
|
||||
var kindKeyword = this.getKindKeyword(symbol.typeKind());
|
||||
if (kindKeyword !== SyntaxKind.None) {
|
||||
this.addKeyword(kindKeyword);
|
||||
this.addSpace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private getKindKeyword(typeKind: TypeKind): SyntaxKind {
|
||||
switch (typeKind) {
|
||||
case TypeKind.Class:
|
||||
return SyntaxKind.ClassKeyword;
|
||||
case TypeKind.Enum:
|
||||
return SyntaxKind.EnumKeyword;
|
||||
case TypeKind.Interface:
|
||||
return SyntaxKind.InterfaceKeyword;
|
||||
default:
|
||||
return SyntaxKind.None;
|
||||
}
|
||||
}
|
||||
|
||||
private shouldVisitModule(moduleSymbol: IModuleSymbol): boolean {
|
||||
if (this.format.typeQualificationStyle() !== TypeQualificationStyle.NameAndContainingModules) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !moduleSymbol.isGlobalModule();
|
||||
}
|
||||
|
||||
private addNameAndTypeArguments(symbol: ISymbol, typeArguments: ITypeSymbol[]): void {
|
||||
this.builder.push(new Part(this.getPartKind(symbol), symbol.name(), symbol));
|
||||
this.addTypeArguments(typeArguments);
|
||||
}
|
||||
|
||||
private visitAnonymousType(symbol: IAnonymousTypeSymbol): void {
|
||||
// If there's only one signature in the anonymous type, and it's a construct or function
|
||||
// signature, then just display that single member.
|
||||
if (symbol.signatureCount() === 1) {
|
||||
var signature = symbol.signatureAt(0);
|
||||
|
||||
if (signature.kind() === SymbolKind.ConstructSignature ||
|
||||
signature.kind() === SymbolKind.CallSignature) {
|
||||
|
||||
signature.accept(this);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (EnumUtilities.hasFlag(this.format.typeOptions(), TypeOptions.InlineAnonymousTypes)) {
|
||||
this.addPunctuation(SyntaxKind.OpenBraceToken);
|
||||
this.addSpace();
|
||||
|
||||
for (var i = 0, n = symbol.signatureCount(); i < n; i++) {
|
||||
if (i > 0) {
|
||||
this.addPunctuation(SyntaxKind.SemicolonToken);
|
||||
this.addSpace();
|
||||
}
|
||||
|
||||
symbol.signatureAt(i).accept(this.notFirstVisitor);
|
||||
}
|
||||
|
||||
this.addPunctuation(SyntaxKind.CloseBraceToken);
|
||||
}
|
||||
else {
|
||||
// Note: higher up level services will determine how to display this.
|
||||
|
||||
var name = "<anonymous type>";
|
||||
this.builder.push(new Part(PartKind.ClassName, name, symbol));
|
||||
}
|
||||
}
|
||||
|
||||
private getPartKind(symbol: ISymbol): PartKind {
|
||||
switch (symbol.kind()) {
|
||||
case SymbolKind.ClassType:
|
||||
return PartKind.ClassName;
|
||||
case SymbolKind.EnumType:
|
||||
return PartKind.EnumName;
|
||||
case SymbolKind.InterfaceType:
|
||||
return PartKind.InterfaceName;
|
||||
default:
|
||||
throw Errors.invalidOperation();
|
||||
}
|
||||
}
|
||||
|
||||
private addTypeArguments(typeArguments: ITypeSymbol[]): void {
|
||||
if (typeArguments !== null &&
|
||||
typeArguments.length > 0 &&
|
||||
EnumUtilities.hasFlag(this.format.genericsOptions(), GenericsOptions.IncludeTypeArguments)) {
|
||||
|
||||
this.addPunctuation(SyntaxKind.LessThanToken);
|
||||
|
||||
for (var i = 0, n = typeArguments.length; i < n; i++) {
|
||||
var typeArg = typeArguments[i];
|
||||
|
||||
if (i > 0) {
|
||||
this.addPunctuation(SyntaxKind.CommaToken);
|
||||
this.addSpace();
|
||||
}
|
||||
|
||||
typeArg.accept(this.notFirstVisitor);
|
||||
|
||||
if (typeArg.kind() === SymbolKind.TypeParameter) {
|
||||
var typeParam = <ITypeParameterSymbol>typeArg;
|
||||
this.addTypeParameterConstraint(typeParam);
|
||||
}
|
||||
}
|
||||
|
||||
this.addPunctuation(SyntaxKind.GreaterThanToken);
|
||||
}
|
||||
}
|
||||
|
||||
private addTypeParameterConstraint(typeParameter: ITypeParameterSymbol): void {
|
||||
if (this.isFirstSymbolVisited && typeParameter.constraintType() !== null &&
|
||||
EnumUtilities.hasFlag(this.format.genericsOptions(), GenericsOptions.IncludeTypeConstraints)) {
|
||||
this.addSpace();
|
||||
this.addKeyword(SyntaxKind.ExtendsKeyword);
|
||||
this.addSpace();
|
||||
typeParameter.constraintType().accept(this.notFirstVisitor);
|
||||
}
|
||||
}
|
||||
|
||||
private minimallyQualify(symbol: ISymbol, arity: number): void {
|
||||
// We first start by trying to bind just our name and type arguments. If they bind to
|
||||
// the symbol that we were constructed from, then we have our minimal name. Otherwise,
|
||||
// we get the minimal name of our parent, add a dot, and then add ourselves.
|
||||
if (!this.nameBoundSuccessfullyToSameSymbol(symbol, arity)) {
|
||||
// Just the name alone didn't bind properly. Add our minimally qualified parent (if
|
||||
// we have one), a dot, and then our name.
|
||||
if (this.shouldVisitModule(symbol.containingModule())) {
|
||||
symbol.containingModule().accept(this.notFirstVisitor);
|
||||
this.addPunctuation(SyntaxKind.DotToken);
|
||||
}
|
||||
}
|
||||
|
||||
var typeArguments = arity === 0 ? null : (<any>symbol).typeArguments();
|
||||
this.addNameAndTypeArguments(symbol, typeArguments);
|
||||
}
|
||||
|
||||
private nameBoundSuccessfullyToSameSymbol(symbol: ISymbol, arity: number): boolean {
|
||||
var normalSymbols = this.semanticModel.lookupSymbols(
|
||||
this.location.textSpan().start(),
|
||||
/*container:*/ null,
|
||||
/*name:*/ symbol.name(),
|
||||
/*arity: */arity,
|
||||
/*options: */ this.getMinimallyQualifyLookupOptions());
|
||||
|
||||
if (normalSymbols.length === 1) {
|
||||
// Binding normally ended up with the right symbol. We can definitely use hte
|
||||
// simplified name.
|
||||
if (normalSymbols[0] === symbol.originalDefinition()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private getMinimallyQualifyLookupOptions(): LookupOptions {
|
||||
var token = this.location.syntaxTree().sourceUnit().findToken(this.location.textSpan().start());
|
||||
|
||||
return Syntax.isInModuleOrTypeContext(token)
|
||||
? LookupOptions.ModulesOrTypesOnly
|
||||
: LookupOptions.Default;
|
||||
}
|
||||
|
||||
private visitVariable(symbol: IVariableSymbol): void {
|
||||
this.addAccessibilityIfRequired(symbol);
|
||||
this.addMemberModifiersIfRequired(symbol);
|
||||
|
||||
if (EnumUtilities.hasFlag(this.format.memberOptions(), MemberOptions.IncludeContainingType)) {
|
||||
symbol.containingType().accept(this.notFirstVisitor);
|
||||
this.addPunctuation(SyntaxKind.DotToken);
|
||||
}
|
||||
|
||||
this.builder.push(new Part(PartKind.FieldName, symbol.name(), symbol));
|
||||
|
||||
if (EnumUtilities.hasFlag(this.format.memberOptions(), MemberOptions.IncludeType) && this.isFirstSymbolVisited) {
|
||||
this.addPunctuation(SyntaxKind.ColonToken);
|
||||
this.addSpace();
|
||||
symbol.type().accept(this.notFirstVisitor);
|
||||
}
|
||||
|
||||
|
||||
if (this.isFirstSymbolVisited &&
|
||||
EnumUtilities.hasFlag(this.format.memberOptions(), MemberOptions.IncludeConstantValue) &&
|
||||
symbol.hasValue() &&
|
||||
this.canAddConstant(symbol.type(), symbol.value())) {
|
||||
this.addSpace();
|
||||
this.addPunctuation(SyntaxKind.EqualsToken);
|
||||
this.addSpace();
|
||||
this.addValue(symbol.type(), symbol.value());
|
||||
}
|
||||
}
|
||||
|
||||
private canAddConstant(type: ITypeSymbol, value: any): boolean {
|
||||
if (type.typeKind() === TypeKind.Enum) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (value === null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return typeof value === 'number' ||
|
||||
typeof value === 'string';
|
||||
}
|
||||
|
||||
private addAccessibilityIfRequired(symbol: ISymbol): void {
|
||||
var containingType = symbol.containingType();
|
||||
|
||||
if (EnumUtilities.hasFlag(this.format.memberOptions(), MemberOptions.IncludeAccessibility) &&
|
||||
(containingType === null || containingType.typeKind() !== TypeKind.Interface)) {
|
||||
switch (symbol.accessibility()) {
|
||||
case Accessibility.Private:
|
||||
this.addKeyword(SyntaxKind.PrivateKeyword);
|
||||
this.addSpace();
|
||||
break;
|
||||
case Accessibility.Public:
|
||||
this.addKeyword(SyntaxKind.PublicKeyword);
|
||||
this.addSpace();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private addMemberModifiersIfRequired(symbol: ISymbol): void {
|
||||
var containingType = symbol.containingType();
|
||||
if (EnumUtilities.hasFlag(this.format.memberOptions(), MemberOptions.IncludeModifiers) &&
|
||||
(containingType == null || containingType.typeKind() !== TypeKind.Interface)) {
|
||||
|
||||
if (symbol.isStatic()) {
|
||||
this.addKeyword(SyntaxKind.StaticKeyword);
|
||||
this.addSpace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private addValue(type: ITypeSymbol, value: any): void {
|
||||
if (value != null) {
|
||||
this.addNonNullValue(type, value);
|
||||
}
|
||||
else {
|
||||
this.addKeyword(SyntaxKind.NullKeyword);
|
||||
}
|
||||
}
|
||||
|
||||
private addNonNullValue(type: ITypeSymbol, value: any): void {
|
||||
if (type.typeKind() === TypeKind.Enum) {
|
||||
this.addEnumConstantValue(<IObjectTypeSymbol> type, value);
|
||||
}
|
||||
else {
|
||||
this.addLiteralValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
private addEnumConstantValue(enumType: IObjectTypeSymbol, value: any): void {
|
||||
// TODO: better enum presentation.
|
||||
this.addLiteralValue(value);
|
||||
}
|
||||
|
||||
private addLiteralValue(value: any): void {
|
||||
var stringified = JSON.stringify(value);
|
||||
this.builder.push(new Part(typeof value === 'number' ? PartKind.NumericLiteral : PartKind.StringLiteral,
|
||||
stringified, null));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
enum SymbolKind {
|
||||
Module,
|
||||
Parameter,
|
||||
|
||||
// Types
|
||||
AnyType,
|
||||
NumberType,
|
||||
BooleanType,
|
||||
StringType,
|
||||
VoidType,
|
||||
NullType,
|
||||
UndefinedType,
|
||||
ClassType,
|
||||
InterfaceType,
|
||||
// ArrayType,
|
||||
AnonymousType,
|
||||
EnumType,
|
||||
TypeParameter,
|
||||
|
||||
// Members
|
||||
Constructor,
|
||||
Function,
|
||||
Variable,
|
||||
|
||||
// Signatures
|
||||
CallSignature,
|
||||
ConstructSignature,
|
||||
IndexSignature,
|
||||
PropertySignature,
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* Enumeration for possible kinds of type symbols.
|
||||
*/
|
||||
enum TypeKind {
|
||||
Any,
|
||||
Number,
|
||||
Boolean,
|
||||
String,
|
||||
Void,
|
||||
Null,
|
||||
Undefined,
|
||||
Class,
|
||||
Interface,
|
||||
// Array,
|
||||
Anonymous,
|
||||
Enum,
|
||||
TypeParameter,
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export class CharacterInfo {
|
||||
public static isDecimalDigit(c: number): boolean {
|
||||
return c >= CharacterCodes._0 && c <= CharacterCodes._9;
|
||||
}
|
||||
public static isOctalDigit(c: number): boolean {
|
||||
return c >= CharacterCodes._0 && c <= CharacterCodes._7;
|
||||
}
|
||||
|
||||
public static isHexDigit(c: number): boolean {
|
||||
return CharacterInfo.isDecimalDigit(c) ||
|
||||
(c >= CharacterCodes.A && c <= CharacterCodes.F) ||
|
||||
(c >= CharacterCodes.a && c <= CharacterCodes.f);
|
||||
}
|
||||
|
||||
public static hexValue(c: number): number {
|
||||
// Debug.assert(isHexDigit(c));
|
||||
return CharacterInfo.isDecimalDigit(c)
|
||||
? (c - CharacterCodes._0)
|
||||
: (c >= CharacterCodes.A && c <= CharacterCodes.F)
|
||||
? c - CharacterCodes.A + 10
|
||||
: c - CharacterCodes.a + 10;
|
||||
}
|
||||
|
||||
public static isWhitespace(ch: number): boolean {
|
||||
switch (ch) {
|
||||
// Unicode 3.0 space characters.
|
||||
case CharacterCodes.space:
|
||||
case CharacterCodes.nonBreakingSpace:
|
||||
case CharacterCodes.enQuad:
|
||||
case CharacterCodes.emQuad:
|
||||
case CharacterCodes.enSpace:
|
||||
case CharacterCodes.emSpace:
|
||||
case CharacterCodes.threePerEmSpace:
|
||||
case CharacterCodes.fourPerEmSpace:
|
||||
case CharacterCodes.sixPerEmSpace:
|
||||
case CharacterCodes.figureSpace:
|
||||
case CharacterCodes.punctuationSpace:
|
||||
case CharacterCodes.thinSpace:
|
||||
case CharacterCodes.hairSpace:
|
||||
case CharacterCodes.zeroWidthSpace:
|
||||
case CharacterCodes.narrowNoBreakSpace:
|
||||
case CharacterCodes.ideographicSpace:
|
||||
|
||||
case CharacterCodes.tab:
|
||||
case CharacterCodes.verticalTab:
|
||||
case CharacterCodes.formFeed:
|
||||
case CharacterCodes.byteOrderMark:
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static isLineTerminator(ch: number): boolean {
|
||||
switch (ch) {
|
||||
case CharacterCodes.carriageReturn:
|
||||
case CharacterCodes.lineFeed:
|
||||
case CharacterCodes.paragraphSeparator:
|
||||
case CharacterCodes.lineSeparator:
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export enum SyntaxConstants {
|
||||
// Masks that we use to place information about trivia into a single int. The first two flags
|
||||
// mark bools that tell us if the trivia contains a comment or a newline. The width of the
|
||||
// trivia is then stored in the rest of the int. This allows trivia of nearly any length.
|
||||
// However, nearly all of the time the trivia will be less than 511MB, and will fit into 31
|
||||
// bits (which will only be stored a a single 32bit int in chakra).
|
||||
TriviaNewLineMask = 0x00000001, // 0000 0000 0000 0000 0000 0000 0000 0001
|
||||
TriviaCommentMask = 0x00000002, // 0000 0100 0000 0000 0000 0000 0000 0010
|
||||
TriviaFullWidthShift = 2, // 1111 1111 1111 1111 1111 1111 1111 1100
|
||||
|
||||
// Masks that we use to place information about a node into a single int. The first bit tells
|
||||
// us if we've computed the data for a node.
|
||||
//
|
||||
// The second bit tells us if the node is incrementally reusable if it does not
|
||||
// containe any skipped tokens, zero width tokens, regex tokens in it ("/", "/=" or "/.../"),
|
||||
// and contains no tokens that were parser generated.
|
||||
//
|
||||
// The next bit lets us know if the nodes was parsed in a strict context or node. A node can
|
||||
// only be used by the incremental parser if it is parsed in the same strict context as before.
|
||||
// last masks off the part of the int
|
||||
//
|
||||
// The width of the node is stored in the remainder of the int. This allows us up to 512MB
|
||||
// for a node by using all 29 bits. However, in the common case, we'll use less than 29 bits
|
||||
// for the width. Thus, the info will be stored in a single int in chakra.
|
||||
NodeDataComputed = 0x00000001, // 0000 0000 0000 0000 0000 0000 0000 0001
|
||||
NodeIncrementallyUnusableMask = 0x00000002, // 0000 0000 0000 0000 0000 0000 0000 0010
|
||||
NodeParsedInStrictModeMask = 0x00000004, // 0000 0000 0000 0000 0000 0000 0000 0100
|
||||
NodeFullWidthShift = 3, // 1111 1111 1111 1111 1111 1111 1111 1000
|
||||
|
||||
// Set when the scanner sees a keyword that isn't fixed width. i.e. a keyword like: \u0076ar
|
||||
IsVariableWidthKeyword = 1 << 31
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export class DepthLimitedWalker extends PositionTrackingWalker {
|
||||
private _depth: number = 0;
|
||||
private _maximumDepth: number = 0;
|
||||
|
||||
constructor(maximumDepth: number) {
|
||||
super();
|
||||
this._maximumDepth = maximumDepth;
|
||||
}
|
||||
|
||||
public visitNode(node: SyntaxNode): void {
|
||||
if (this._depth < this._maximumDepth) {
|
||||
this._depth++;
|
||||
super.visitNode(node);
|
||||
this._depth--;
|
||||
}
|
||||
else {
|
||||
// update the position
|
||||
this.skip(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
class FormattingOptions {
|
||||
constructor(public useTabs: boolean,
|
||||
public spacesPerTab: number,
|
||||
public indentSpaces: number,
|
||||
public newLineCharacter: string) {
|
||||
}
|
||||
|
||||
public static defaultOptions = new FormattingOptions(/*useTabs:*/ false, /*spacesPerTab:*/ 4, /*indentSpaces:*/ 4, /*newLineCharacter*/ "\r\n");
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript.Indentation {
|
||||
export function columnForEndOfToken(token: ISyntaxToken,
|
||||
syntaxInformationMap: SyntaxInformationMap,
|
||||
options: FormattingOptions): number {
|
||||
return columnForStartOfToken(token, syntaxInformationMap, options) + token.width();
|
||||
}
|
||||
|
||||
export function columnForStartOfToken(token: ISyntaxToken,
|
||||
syntaxInformationMap: SyntaxInformationMap,
|
||||
options: FormattingOptions): number {
|
||||
// Walk backward from this token until we find the first token in the line. For each token
|
||||
// we see (that is not the first tokem in line), push the entirety of the text into the text
|
||||
// array. Then, for the first token, add its text (without its leading trivia) to the text
|
||||
// array. i.e. if we have:
|
||||
//
|
||||
// var foo = a => bar();
|
||||
//
|
||||
// And we want the column for the start of 'bar', then we'll add the underlinded portions to
|
||||
// the text array:
|
||||
//
|
||||
// var foo = a => bar();
|
||||
// _
|
||||
// __
|
||||
// __
|
||||
// ____
|
||||
// ____
|
||||
var firstTokenInLine = syntaxInformationMap.firstTokenInLineContainingToken(token);
|
||||
var leadingTextInReverse: string[] = [];
|
||||
|
||||
var current = token;
|
||||
while (current !== firstTokenInLine) {
|
||||
current = syntaxInformationMap.previousToken(current);
|
||||
|
||||
if (current === firstTokenInLine) {
|
||||
// We're at the first token in teh line.
|
||||
// We don't want the leading trivia for this token. That will be taken care of in
|
||||
// columnForFirstNonWhitespaceCharacterInLine. So just push the trailing trivia
|
||||
// and then the token text.
|
||||
leadingTextInReverse.push(current.trailingTrivia().fullText());
|
||||
leadingTextInReverse.push(current.text());
|
||||
}
|
||||
else {
|
||||
// We're at an intermediate token on the line. Just push all its text into the array.
|
||||
leadingTextInReverse.push(current.fullText());
|
||||
}
|
||||
}
|
||||
|
||||
// Now, add all trivia to the start of the line on the first token in the list.
|
||||
collectLeadingTriviaTextToStartOfLine(firstTokenInLine, leadingTextInReverse);
|
||||
|
||||
return columnForLeadingTextInReverse(leadingTextInReverse, options);
|
||||
}
|
||||
|
||||
export function columnForStartOfFirstTokenInLineContainingToken(
|
||||
token: ISyntaxToken,
|
||||
syntaxInformationMap: SyntaxInformationMap,
|
||||
options: FormattingOptions): number {
|
||||
// Walk backward through the tokens until we find the first one on the line.
|
||||
var firstTokenInLine = syntaxInformationMap.firstTokenInLineContainingToken(token);
|
||||
var leadingTextInReverse: string[] = [];
|
||||
|
||||
// Now, add all trivia to the start of the line on the first token in the list.
|
||||
collectLeadingTriviaTextToStartOfLine(firstTokenInLine, leadingTextInReverse);
|
||||
|
||||
return columnForLeadingTextInReverse(leadingTextInReverse, options);
|
||||
}
|
||||
|
||||
// Collect all the trivia that precedes this token. Stopping when we hit a newline trivia
|
||||
// or a multiline comment that spans multiple lines. This is meant to be called on the first
|
||||
// token in a line.
|
||||
function collectLeadingTriviaTextToStartOfLine(firstTokenInLine: ISyntaxToken,
|
||||
leadingTextInReverse: string[]) {
|
||||
var leadingTrivia = firstTokenInLine.leadingTrivia();
|
||||
|
||||
for (var i = leadingTrivia.count() - 1; i >= 0; i--) {
|
||||
var trivia = leadingTrivia.syntaxTriviaAt(i);
|
||||
if (trivia.kind() === SyntaxKind.NewLineTrivia) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (trivia.kind() === SyntaxKind.MultiLineCommentTrivia) {
|
||||
var lineSegments = Syntax.splitMultiLineCommentTriviaIntoMultipleLines(trivia);
|
||||
leadingTextInReverse.push(ArrayUtilities.last(lineSegments));
|
||||
|
||||
if (lineSegments.length > 0) {
|
||||
// This multiline comment actually spanned multiple lines. So we're done.
|
||||
break;
|
||||
}
|
||||
|
||||
// It was only on a single line, so keep on going.
|
||||
}
|
||||
|
||||
leadingTextInReverse.push(trivia.fullText());
|
||||
}
|
||||
}
|
||||
|
||||
function columnForLeadingTextInReverse(leadingTextInReverse: string[],
|
||||
options: FormattingOptions): number {
|
||||
var column = 0;
|
||||
|
||||
// walk backwards. This means we're actually walking forward from column 0 to the start of
|
||||
// the token.
|
||||
for (var i = leadingTextInReverse.length - 1; i >= 0; i--) {
|
||||
var text = leadingTextInReverse[i];
|
||||
column = columnForPositionInStringWorker(text, text.length, column, options);
|
||||
}
|
||||
|
||||
return column;
|
||||
}
|
||||
|
||||
// Returns the column that this input string ends at (assuming it starts at column 0).
|
||||
export function columnForPositionInString(input: string, position: number, options: FormattingOptions): number {
|
||||
return columnForPositionInStringWorker(input, position, 0, options);
|
||||
}
|
||||
|
||||
function columnForPositionInStringWorker(input: string, position: number, startColumn: number, options: FormattingOptions): number {
|
||||
var column = startColumn;
|
||||
var spacesPerTab = options.spacesPerTab;
|
||||
|
||||
for (var j = 0; j < position; j++) {
|
||||
var ch = input.charCodeAt(j);
|
||||
|
||||
if (ch === CharacterCodes.tab) {
|
||||
column += spacesPerTab - column % spacesPerTab;
|
||||
}
|
||||
else {
|
||||
column++;
|
||||
}
|
||||
}
|
||||
|
||||
return column;
|
||||
}
|
||||
|
||||
export function indentationString(column: number, options: FormattingOptions): string {
|
||||
var numberOfTabs = 0;
|
||||
var numberOfSpaces = MathPrototype.max(0, column);
|
||||
|
||||
if (options.useTabs) {
|
||||
numberOfTabs = Math.floor(column / options.spacesPerTab);
|
||||
numberOfSpaces -= numberOfTabs * options.spacesPerTab;
|
||||
}
|
||||
|
||||
return StringUtilities.repeat('\t', numberOfTabs) +
|
||||
StringUtilities.repeat(' ', numberOfSpaces);
|
||||
}
|
||||
|
||||
export function indentationTrivia(column: number, options: FormattingOptions): ISyntaxTrivia {
|
||||
return Syntax.whitespace(this.indentationString(column, options));
|
||||
}
|
||||
|
||||
export function firstNonWhitespacePosition(value: string): number {
|
||||
for (var i = 0; i < value.length; i++) {
|
||||
var ch = value.charCodeAt(i);
|
||||
if (!CharacterInfo.isWhitespace(ch)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return value.length;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
module TypeScript {
|
||||
export enum LanguageVersion {
|
||||
EcmaScript3 = 0,
|
||||
EcmaScript5 = 1,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export class ParseOptions {
|
||||
private _languageVersion: LanguageVersion;
|
||||
private _allowAutomaticSemicolonInsertion: boolean;
|
||||
|
||||
constructor(languageVersion: LanguageVersion,
|
||||
allowAutomaticSemicolonInsertion: boolean) {
|
||||
this._languageVersion = languageVersion;
|
||||
this._allowAutomaticSemicolonInsertion = allowAutomaticSemicolonInsertion;
|
||||
}
|
||||
|
||||
|
||||
public toJSON(key: any) {
|
||||
return { allowAutomaticSemicolonInsertion: this._allowAutomaticSemicolonInsertion };
|
||||
}
|
||||
|
||||
public languageVersion(): LanguageVersion {
|
||||
return this._languageVersion;
|
||||
}
|
||||
|
||||
public allowAutomaticSemicolonInsertion(): boolean {
|
||||
return this._allowAutomaticSemicolonInsertion;
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,19 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export class PositionTrackingWalker extends SyntaxWalker {
|
||||
private _position: number = 0;
|
||||
|
||||
public visitToken(token: ISyntaxToken): void {
|
||||
this._position += token.fullWidth();
|
||||
}
|
||||
|
||||
public position(): number {
|
||||
return this._position;
|
||||
}
|
||||
|
||||
public skip(element: ISyntaxElement): void {
|
||||
this._position += element.fullWidth();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,307 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export class PositionedElement {
|
||||
private _parent: PositionedElement;
|
||||
private _element: ISyntaxElement;
|
||||
private _fullStart: number;
|
||||
|
||||
constructor(parent: PositionedElement, element: ISyntaxElement, fullStart: number) {
|
||||
this._parent = parent;
|
||||
this._element = element;
|
||||
this._fullStart = fullStart;
|
||||
}
|
||||
|
||||
public static create(parent: PositionedElement, element: ISyntaxElement, fullStart: number): PositionedElement {
|
||||
if (element === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (element.isNode()) {
|
||||
return new PositionedNode(parent, <SyntaxNode>element, fullStart);
|
||||
}
|
||||
else if (element.isToken()) {
|
||||
return new PositionedToken(parent, <ISyntaxToken>element, fullStart);
|
||||
}
|
||||
else if (element.isList()) {
|
||||
return new PositionedList(parent, <ISyntaxList>element, fullStart);
|
||||
}
|
||||
else if (element.isSeparatedList()) {
|
||||
return new PositionedSeparatedList(parent, <ISeparatedSyntaxList>element, fullStart);
|
||||
}
|
||||
else {
|
||||
throw Errors.invalidOperation();
|
||||
}
|
||||
}
|
||||
|
||||
public parent(): PositionedElement {
|
||||
return this._parent;
|
||||
}
|
||||
|
||||
public parentElement(): ISyntaxElement {
|
||||
return this._parent && this._parent._element;
|
||||
}
|
||||
|
||||
public element(): ISyntaxElement {
|
||||
return this._element;
|
||||
}
|
||||
|
||||
public kind(): SyntaxKind {
|
||||
return this.element().kind();
|
||||
}
|
||||
|
||||
public childIndex(child: ISyntaxElement) {
|
||||
return Syntax.childIndex(this.element(), child);
|
||||
}
|
||||
|
||||
public childCount(): number {
|
||||
return this.element().childCount();
|
||||
}
|
||||
|
||||
public childAt(index: number): PositionedElement {
|
||||
var offset = Syntax.childOffsetAt(this.element(), index);
|
||||
return PositionedElement.create(this, this.element().childAt(index), this.fullStart() + offset);
|
||||
}
|
||||
|
||||
public childStart(child: ISyntaxElement): number {
|
||||
var offset = Syntax.childOffset(this.element(), child);
|
||||
return this.fullStart() + offset + child.leadingTriviaWidth();
|
||||
}
|
||||
|
||||
public childEnd(child: ISyntaxElement): number {
|
||||
var offset = Syntax.childOffset(this.element(), child);
|
||||
return this.fullStart() + offset + child.leadingTriviaWidth() + child.width();
|
||||
}
|
||||
|
||||
public childStartAt(index: number): number {
|
||||
var offset = Syntax.childOffsetAt(this.element(), index);
|
||||
var child = this.element().childAt(index);
|
||||
return this.fullStart() + offset + child.leadingTriviaWidth();
|
||||
}
|
||||
|
||||
public childEndAt(index: number): number {
|
||||
var offset = Syntax.childOffsetAt(this.element(), index);
|
||||
var child = this.element().childAt(index);
|
||||
return this.fullStart() + offset + child.leadingTriviaWidth() + child.width();
|
||||
}
|
||||
|
||||
public getPositionedChild(child: ISyntaxElement) {
|
||||
var offset = Syntax.childOffset(this.element(), child);
|
||||
return PositionedElement.create(this, child, this.fullStart() + offset);
|
||||
}
|
||||
|
||||
public fullStart(): number {
|
||||
return this._fullStart;
|
||||
}
|
||||
|
||||
public fullEnd(): number {
|
||||
return this.fullStart() + this.element().fullWidth();
|
||||
}
|
||||
|
||||
public fullWidth(): number {
|
||||
return this.element().fullWidth();
|
||||
}
|
||||
|
||||
public start(): number {
|
||||
return this.fullStart() + this.element().leadingTriviaWidth();
|
||||
}
|
||||
|
||||
public end(): number {
|
||||
return this.fullStart() + this.element().leadingTriviaWidth() + this.element().width();
|
||||
}
|
||||
|
||||
public root(): PositionedNode {
|
||||
var current = this;
|
||||
while (current.parent() !== null) {
|
||||
current = current.parent();
|
||||
}
|
||||
|
||||
return <PositionedNode>current;
|
||||
}
|
||||
|
||||
public containingNode(): PositionedNode {
|
||||
var current = this.parent();
|
||||
|
||||
while (current !== null && !current.element().isNode()) {
|
||||
current = current.parent();
|
||||
}
|
||||
|
||||
return <PositionedNode>current;
|
||||
}
|
||||
}
|
||||
|
||||
export class PositionedNodeOrToken extends PositionedElement {
|
||||
constructor(parent: PositionedElement, nodeOrToken: ISyntaxNodeOrToken, fullStart: number) {
|
||||
super(parent, nodeOrToken, fullStart);
|
||||
}
|
||||
|
||||
public nodeOrToken(): ISyntaxNodeOrToken {
|
||||
return <ISyntaxNodeOrToken>this.element();
|
||||
}
|
||||
}
|
||||
|
||||
export class PositionedNode extends PositionedNodeOrToken {
|
||||
constructor(parent: PositionedElement, node: SyntaxNode, fullStart: number) {
|
||||
super(parent, node, fullStart);
|
||||
}
|
||||
|
||||
public node(): SyntaxNode {
|
||||
return <SyntaxNode>this.element();
|
||||
}
|
||||
}
|
||||
|
||||
export class PositionedToken extends PositionedNodeOrToken {
|
||||
constructor(parent: PositionedElement, token: ISyntaxToken, fullStart: number) {
|
||||
super(parent, token, fullStart);
|
||||
}
|
||||
|
||||
public token(): ISyntaxToken {
|
||||
return <ISyntaxToken>this.element();
|
||||
}
|
||||
|
||||
public previousToken(includeSkippedTokens: boolean = false): PositionedToken {
|
||||
var triviaList = this.token().leadingTrivia();
|
||||
if (includeSkippedTokens && triviaList && triviaList.hasSkippedToken()) {
|
||||
var currentTriviaEndPosition = this.start();
|
||||
for (var i = triviaList.count() - 1; i >= 0; i--) {
|
||||
var trivia = triviaList.syntaxTriviaAt(i);
|
||||
if (trivia.isSkippedToken()) {
|
||||
return new PositionedSkippedToken(this, trivia.skippedToken(), currentTriviaEndPosition - trivia.fullWidth());
|
||||
}
|
||||
|
||||
currentTriviaEndPosition -= trivia.fullWidth();
|
||||
}
|
||||
}
|
||||
|
||||
var start = this.fullStart();
|
||||
if (start === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.root().node().findToken(start - 1, includeSkippedTokens);
|
||||
}
|
||||
|
||||
public nextToken(includeSkippedTokens: boolean = false): PositionedToken {
|
||||
if (this.token().tokenKind === SyntaxKind.EndOfFileToken) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var triviaList = this.token().trailingTrivia();
|
||||
if (includeSkippedTokens && triviaList && triviaList.hasSkippedToken()) {
|
||||
var fullStart = this.end();
|
||||
for (var i =0, n = triviaList.count(); i < n; i++) {
|
||||
var trivia = triviaList.syntaxTriviaAt(i);
|
||||
if (trivia.isSkippedToken()) {
|
||||
return new PositionedSkippedToken(this, trivia.skippedToken(), fullStart);
|
||||
}
|
||||
|
||||
fullStart += trivia.fullWidth();
|
||||
}
|
||||
}
|
||||
|
||||
return this.root().node().findToken(this.fullEnd(), includeSkippedTokens);
|
||||
}
|
||||
}
|
||||
|
||||
export class PositionedList extends PositionedElement {
|
||||
constructor(parent: PositionedElement, list: ISyntaxList, fullStart: number) {
|
||||
super(parent, list, fullStart);
|
||||
}
|
||||
|
||||
public list(): ISyntaxList {
|
||||
return <ISyntaxList>this.element();
|
||||
}
|
||||
}
|
||||
|
||||
export class PositionedSeparatedList extends PositionedElement {
|
||||
constructor(parent: PositionedElement, list: ISeparatedSyntaxList, fullStart: number) {
|
||||
super(parent, list, fullStart);
|
||||
}
|
||||
|
||||
public list(): ISeparatedSyntaxList {
|
||||
return <ISeparatedSyntaxList>this.element();
|
||||
}
|
||||
}
|
||||
|
||||
export class PositionedSkippedToken extends PositionedToken {
|
||||
private _parentToken: PositionedToken;
|
||||
|
||||
constructor(parentToken: PositionedToken, token: ISyntaxToken, fullStart: number) {
|
||||
super(parentToken.parent(), token, fullStart);
|
||||
this._parentToken = parentToken;
|
||||
}
|
||||
|
||||
public parentToken(): PositionedToken {
|
||||
return this._parentToken;
|
||||
}
|
||||
|
||||
public previousToken(includeSkippedTokens: boolean = false): PositionedToken {
|
||||
var start = this.fullStart();
|
||||
|
||||
// find previous skipped token within the same parent
|
||||
if (includeSkippedTokens) {
|
||||
var previousToken: PositionedToken;
|
||||
|
||||
if (start >= this.parentToken().end()) {
|
||||
// This skipped token was on the right of positioned token, the skipped token found before it in the
|
||||
// trailing trivia, if the search for a previous skipped token in the same trivia list return it,
|
||||
// else return the parent token as the previous token
|
||||
previousToken = Syntax.findSkippedTokenInTrailingTriviaList(this.parentToken(), start - 1);
|
||||
|
||||
if (previousToken) {
|
||||
return previousToken;
|
||||
}
|
||||
|
||||
return this.parentToken();
|
||||
}
|
||||
else {
|
||||
previousToken = Syntax.findSkippedTokenInLeadingTriviaList(this.parentToken(), start - 1);
|
||||
|
||||
if (previousToken) {
|
||||
return previousToken;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var start = this.parentToken().fullStart();
|
||||
if (start === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.root().node().findToken(start - 1, includeSkippedTokens);
|
||||
}
|
||||
|
||||
public nextToken(includeSkippedTokens: boolean = false): PositionedToken {
|
||||
if (this.token().tokenKind === SyntaxKind.EndOfFileToken) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (includeSkippedTokens) {
|
||||
var end = this.end();
|
||||
var nextToken: PositionedToken;
|
||||
|
||||
if (end <= this.parentToken().start()) {
|
||||
// This skipped token was on the left of positioned token, the skipped token found after it in the
|
||||
// leading trivia, if the search for a next skipped token in the same trivia list return it,
|
||||
// else return the parent token as the next token
|
||||
nextToken = Syntax.findSkippedTokenInLeadingTriviaList(this.parentToken(), end);
|
||||
|
||||
if (nextToken) {
|
||||
return nextToken;
|
||||
}
|
||||
|
||||
return this.parentToken();
|
||||
}
|
||||
else {
|
||||
nextToken = Syntax.findSkippedTokenInTrailingTriviaList(this.parentToken(), end);
|
||||
|
||||
if (nextToken) {
|
||||
return nextToken;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.root().node().findToken(this.parentToken().fullEnd(), includeSkippedTokens);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,995 @@
|
||||
///<reference path='References.ts' />
|
||||
|
||||
module TypeScript.PrettyPrinter {
|
||||
export function prettyPrint(node: SyntaxNode, indentWhitespace: string = " "): string {
|
||||
var impl = new PrettyPrinterImpl(indentWhitespace);
|
||||
node.accept(impl);
|
||||
return impl.result.join("");
|
||||
}
|
||||
|
||||
class PrettyPrinterImpl implements ISyntaxVisitor {
|
||||
public result: string[] = [];
|
||||
private indentations: string[] = [];
|
||||
private indentation: number = 0;
|
||||
|
||||
constructor(private indentWhitespace: string) {
|
||||
}
|
||||
|
||||
private newLineCountBetweenModuleElements(element1: IModuleElementSyntax, element2: IModuleElementSyntax): number {
|
||||
if (element1 === null || element2 === null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (element1.lastToken().kind() === SyntaxKind.CloseBraceToken) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
private newLineCountBetweenClassElements(element1: IClassElementSyntax, element2: IClassElementSyntax): number {
|
||||
if (element1 === null || element2 === null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
private newLineCountBetweenStatements(element1: IClassElementSyntax, element2: IClassElementSyntax): number {
|
||||
if (element1 === null || element2 === null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (element1.lastToken().kind() === SyntaxKind.CloseBraceToken) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
private newLineCountBetweenSwitchClauses(element1: ISwitchClauseSyntax, element2: ISwitchClauseSyntax): number {
|
||||
if (element1 === null || element2 === null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (element1.statements.childCount() === 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
private ensureSpace(): void {
|
||||
if (this.result.length > 0) {
|
||||
var last = ArrayUtilities.last(this.result);
|
||||
if (last !== " " && last !== "\r\n") {
|
||||
this.appendText(" ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ensureNewLine(): void {
|
||||
if (this.result.length > 0) {
|
||||
var last = ArrayUtilities.last(this.result);
|
||||
if (last !== "\r\n") {
|
||||
this.appendText("\r\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private appendNewLines(count: number): void {
|
||||
for (var i = 0; i < count; i++) {
|
||||
this.appendText("\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
private getIndentation(count: number): string {
|
||||
for (var i = this.indentations.length; i <= count; i++) {
|
||||
var text = i === 0
|
||||
? ""
|
||||
: this.indentations[i - 1] + this.indentWhitespace;
|
||||
this.indentations[i] = text;
|
||||
}
|
||||
|
||||
return this.indentations[count];
|
||||
}
|
||||
|
||||
private appendIndentationIfAfterNewLine(): void {
|
||||
if (this.result.length > 0) {
|
||||
if (ArrayUtilities.last(this.result) === "\r\n") {
|
||||
this.result.push(this.getIndentation(this.indentation));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private appendText(text: string): void {
|
||||
this.result.push(text);
|
||||
}
|
||||
|
||||
private appendNode(node: ISyntaxNode): void {
|
||||
if (node !== null) {
|
||||
node.accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
private appendToken(token: ISyntaxToken): void {
|
||||
if (token !== null && token.fullWidth() > 0) {
|
||||
this.appendIndentationIfAfterNewLine();
|
||||
this.appendText(token.text());
|
||||
}
|
||||
}
|
||||
|
||||
public visitToken(token: ISyntaxToken): void {
|
||||
this.appendToken(token);
|
||||
}
|
||||
|
||||
private appendSpaceList(list: ISyntaxList): void {
|
||||
for (var i = 0, n = list.childCount(); i < n; i++) {
|
||||
this.appendToken(<ISyntaxToken>list.childAt(i));
|
||||
this.ensureSpace();
|
||||
}
|
||||
}
|
||||
|
||||
private appendSeparatorSpaceList(list: ISeparatedSyntaxList): void {
|
||||
for (var i = 0, n = list.childCount(); i < n; i++) {
|
||||
if (i % 2 === 0) {
|
||||
if (i > 0) {
|
||||
this.ensureSpace();
|
||||
}
|
||||
|
||||
list.childAt(i).accept(this);
|
||||
}
|
||||
else {
|
||||
this.appendToken(<ISyntaxToken>list.childAt(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private appendSeparatorNewLineList(list: ISeparatedSyntaxList): void {
|
||||
for (var i = 0, n = list.childCount(); i < n; i++) {
|
||||
if (i % 2 === 0) {
|
||||
if (i > 0) {
|
||||
this.ensureNewLine();
|
||||
}
|
||||
|
||||
list.childAt(i).accept(this);
|
||||
}
|
||||
else {
|
||||
this.appendToken(<ISyntaxToken>list.childAt(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private appendModuleElements(list: ISyntaxList): void {
|
||||
var lastModuleElement: IModuleElementSyntax = null;
|
||||
for (var i = 0, n = list.childCount(); i < n; i++) {
|
||||
var moduleElement = <IModuleElementSyntax>list.childAt(i);
|
||||
var newLineCount = this.newLineCountBetweenModuleElements(lastModuleElement, moduleElement);
|
||||
|
||||
this.appendNewLines(newLineCount);
|
||||
moduleElement.accept(this);
|
||||
|
||||
lastModuleElement = moduleElement;
|
||||
}
|
||||
}
|
||||
|
||||
public visitSourceUnit(node: SourceUnitSyntax): void {
|
||||
this.appendModuleElements(node.moduleElements);
|
||||
}
|
||||
|
||||
public visitExternalModuleReference(node: ExternalModuleReferenceSyntax): void {
|
||||
this.appendToken(node.requireKeyword);
|
||||
this.appendToken(node.openParenToken);
|
||||
this.appendToken(node.stringLiteral);
|
||||
this.appendToken(node.closeParenToken);
|
||||
}
|
||||
|
||||
public visitModuleNameModuleReference(node: ModuleNameModuleReferenceSyntax): void {
|
||||
node.moduleName.accept(this);
|
||||
}
|
||||
|
||||
public visitImportDeclaration(node: ImportDeclarationSyntax): void {
|
||||
this.appendToken(node.importKeyword);
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.identifier);
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.equalsToken);
|
||||
this.ensureSpace();
|
||||
node.moduleReference.accept(this);
|
||||
this.appendToken(node.semicolonToken);
|
||||
}
|
||||
|
||||
public visitExportAssignment(node: ExportAssignmentSyntax): void {
|
||||
this.appendToken(node.exportKeyword);
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.equalsToken);
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.identifier);
|
||||
this.appendToken(node.semicolonToken);
|
||||
}
|
||||
|
||||
public visitClassDeclaration(node: ClassDeclarationSyntax): void {
|
||||
this.appendSpaceList(node.modifiers);
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.classKeyword);
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.identifier);
|
||||
this.appendNode(node.typeParameterList);
|
||||
this.ensureSpace();
|
||||
this.appendSpaceList(node.heritageClauses);
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.openBraceToken);
|
||||
this.ensureNewLine();
|
||||
|
||||
this.indentation++;
|
||||
|
||||
var lastClassElement: IClassElementSyntax = null;
|
||||
for (var i = 0, n = node.classElements.childCount(); i < n; i++) {
|
||||
var classElement = <IClassElementSyntax>node.classElements.childAt(i);
|
||||
var newLineCount = this.newLineCountBetweenClassElements(lastClassElement, classElement);
|
||||
|
||||
this.appendNewLines(newLineCount);
|
||||
classElement.accept(this);
|
||||
|
||||
lastClassElement = classElement;
|
||||
}
|
||||
|
||||
this.indentation--;
|
||||
|
||||
this.ensureNewLine();
|
||||
this.appendToken(node.closeBraceToken);
|
||||
}
|
||||
|
||||
public visitInterfaceDeclaration(node: InterfaceDeclarationSyntax): void {
|
||||
this.appendSpaceList(node.modifiers);
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.interfaceKeyword);
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.identifier);
|
||||
this.appendNode(node.typeParameterList);
|
||||
this.ensureSpace();
|
||||
this.appendSpaceList(node.heritageClauses);
|
||||
this.ensureSpace();
|
||||
this.appendObjectType(node.body, /*appendNewLines:*/ true);
|
||||
}
|
||||
|
||||
private appendObjectType(node: ObjectTypeSyntax, appendNewLines: boolean): void {
|
||||
this.appendToken(node.openBraceToken);
|
||||
|
||||
if (appendNewLines) {
|
||||
this.ensureNewLine();
|
||||
this.indentation++;
|
||||
}
|
||||
else {
|
||||
this.ensureSpace();
|
||||
}
|
||||
|
||||
for (var i = 0, n = node.typeMembers.childCount(); i < n; i++) {
|
||||
node.typeMembers.childAt(i).accept(this);
|
||||
|
||||
if (appendNewLines) {
|
||||
this.ensureNewLine();
|
||||
}
|
||||
else {
|
||||
this.ensureSpace();
|
||||
}
|
||||
}
|
||||
|
||||
this.indentation--;
|
||||
this.appendToken(node.closeBraceToken);
|
||||
}
|
||||
|
||||
public visitHeritageClause(node: HeritageClauseSyntax): void {
|
||||
this.appendToken(node.extendsOrImplementsKeyword);
|
||||
this.ensureSpace();
|
||||
this.appendSeparatorSpaceList(node.typeNames);
|
||||
}
|
||||
|
||||
public visitModuleDeclaration(node: ModuleDeclarationSyntax): void {
|
||||
this.appendSpaceList(node.modifiers);
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.moduleKeyword);
|
||||
this.ensureSpace();
|
||||
this.appendNode(node.name);
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.stringLiteral);
|
||||
this.ensureSpace();
|
||||
|
||||
this.appendToken(node.openBraceToken);
|
||||
this.ensureNewLine();
|
||||
|
||||
this.indentation++;
|
||||
|
||||
this.appendModuleElements(node.moduleElements);
|
||||
|
||||
this.indentation--;
|
||||
this.appendToken(node.closeBraceToken);
|
||||
}
|
||||
|
||||
private appendBlockOrSemicolon(block: BlockSyntax, semicolonToken: ISyntaxToken) {
|
||||
if (block) {
|
||||
this.ensureSpace();
|
||||
block.accept(this);
|
||||
}
|
||||
else {
|
||||
this.appendToken(semicolonToken);
|
||||
}
|
||||
}
|
||||
|
||||
public visitFunctionDeclaration(node: FunctionDeclarationSyntax): void {
|
||||
this.appendSpaceList(node.modifiers);
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.functionKeyword);
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.identifier);
|
||||
this.appendNode(node.callSignature);
|
||||
this.appendBlockOrSemicolon(node.block, node.semicolonToken);
|
||||
}
|
||||
|
||||
public visitVariableStatement(node: VariableStatementSyntax): void {
|
||||
this.appendSpaceList(node.modifiers);
|
||||
this.ensureSpace();
|
||||
node.variableDeclaration.accept(this);
|
||||
this.appendToken(node.semicolonToken);
|
||||
}
|
||||
|
||||
public visitVariableDeclaration(node: VariableDeclarationSyntax): void {
|
||||
this.appendToken(node.varKeyword);
|
||||
this.ensureSpace();
|
||||
this.appendSeparatorSpaceList(node.variableDeclarators);
|
||||
}
|
||||
|
||||
public visitVariableDeclarator(node: VariableDeclaratorSyntax): void {
|
||||
this.appendToken(node.propertyName);
|
||||
this.appendNode(node.equalsValueClause);
|
||||
}
|
||||
|
||||
public visitEqualsValueClause(node: EqualsValueClauseSyntax): void {
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.equalsToken);
|
||||
this.ensureSpace();
|
||||
node.value.accept(this);
|
||||
}
|
||||
|
||||
public visitPrefixUnaryExpression(node: PrefixUnaryExpressionSyntax): void {
|
||||
this.appendToken(node.operatorToken);
|
||||
node.operand.accept(this);
|
||||
}
|
||||
|
||||
public visitArrayLiteralExpression(node: ArrayLiteralExpressionSyntax): void {
|
||||
this.appendToken(node.openBracketToken);
|
||||
this.appendSeparatorSpaceList(node.expressions);
|
||||
this.appendToken(node.closeBracketToken);
|
||||
}
|
||||
|
||||
public visitOmittedExpression(node: OmittedExpressionSyntax): void {
|
||||
// Nothing to do.
|
||||
}
|
||||
|
||||
public visitParenthesizedExpression(node: ParenthesizedExpressionSyntax): void {
|
||||
this.appendToken(node.openParenToken);
|
||||
node.expression.accept(this);
|
||||
this.appendToken(node.closeParenToken);
|
||||
}
|
||||
|
||||
public visitSimpleArrowFunctionExpression(node: SimpleArrowFunctionExpressionSyntax): void {
|
||||
this.appendToken(node.identifier);
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.equalsGreaterThanToken);
|
||||
this.ensureSpace();
|
||||
this.appendNode(node.block);
|
||||
this.appendNode(node.expression);
|
||||
}
|
||||
|
||||
public visitParenthesizedArrowFunctionExpression(node: ParenthesizedArrowFunctionExpressionSyntax): void {
|
||||
node.callSignature.accept(this);
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.equalsGreaterThanToken);
|
||||
this.ensureSpace();
|
||||
this.appendNode(node.block);
|
||||
this.appendNode(node.expression);
|
||||
}
|
||||
|
||||
public visitQualifiedName(node: QualifiedNameSyntax): void {
|
||||
node.left.accept(this);
|
||||
this.appendToken(node.dotToken);
|
||||
this.appendToken(node.right);
|
||||
}
|
||||
|
||||
public visitTypeQuery(node: TypeQuerySyntax): void {
|
||||
this.appendToken(node.typeOfKeyword);
|
||||
this.ensureSpace();
|
||||
node.name.accept(this);
|
||||
}
|
||||
|
||||
public visitTypeArgumentList(node: TypeArgumentListSyntax): void {
|
||||
this.appendToken(node.lessThanToken);
|
||||
this.appendSeparatorSpaceList(node.typeArguments);
|
||||
this.appendToken(node.greaterThanToken);
|
||||
}
|
||||
|
||||
public visitConstructorType(node: ConstructorTypeSyntax): void {
|
||||
this.appendToken(node.newKeyword);
|
||||
this.ensureSpace();
|
||||
this.appendNode(node.typeParameterList);
|
||||
node.parameterList.accept(this);
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.equalsGreaterThanToken);
|
||||
this.ensureSpace();
|
||||
node.type.accept(this);
|
||||
}
|
||||
|
||||
public visitFunctionType(node: FunctionTypeSyntax): void {
|
||||
this.appendNode(node.typeParameterList);
|
||||
node.parameterList.accept(this);
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.equalsGreaterThanToken);
|
||||
this.ensureSpace();
|
||||
node.type.accept(this);
|
||||
}
|
||||
|
||||
public visitObjectType(node: ObjectTypeSyntax): void {
|
||||
this.appendToken(node.openBraceToken);
|
||||
this.ensureSpace();
|
||||
this.appendSeparatorSpaceList(node.typeMembers);
|
||||
this.appendToken(node.closeBraceToken);
|
||||
}
|
||||
|
||||
public visitArrayType(node: ArrayTypeSyntax): void {
|
||||
node.type.accept(this);
|
||||
this.appendToken(node.openBracketToken);
|
||||
this.appendToken(node.closeBracketToken);
|
||||
}
|
||||
|
||||
public visitGenericType(node: GenericTypeSyntax): void {
|
||||
node.name.accept(this);
|
||||
node.typeArgumentList.accept(this);
|
||||
}
|
||||
|
||||
public visitTypeAnnotation(node: TypeAnnotationSyntax): void {
|
||||
this.appendToken(node.colonToken);
|
||||
this.ensureSpace();
|
||||
node.type.accept(this);
|
||||
}
|
||||
|
||||
private appendStatements(statements: ISyntaxList): void {
|
||||
var lastStatement: IStatementSyntax = null;
|
||||
for (var i = 0, n = statements.childCount(); i < n; i++) {
|
||||
var statement = <IStatementSyntax>statements.childAt(i);
|
||||
|
||||
var newLineCount = this.newLineCountBetweenStatements(lastStatement, statement);
|
||||
|
||||
this.appendNewLines(newLineCount);
|
||||
statement.accept(this);
|
||||
|
||||
lastStatement = statement;
|
||||
}
|
||||
}
|
||||
|
||||
public visitBlock(node: BlockSyntax): void {
|
||||
this.appendToken(node.openBraceToken);
|
||||
this.ensureNewLine();
|
||||
this.indentation++;
|
||||
|
||||
this.appendStatements(node.statements);
|
||||
|
||||
this.indentation--;
|
||||
this.ensureNewLine();
|
||||
this.appendToken(node.closeBraceToken);
|
||||
}
|
||||
|
||||
public visitParameter(node: ParameterSyntax): void {
|
||||
this.appendToken(node.dotDotDotToken);
|
||||
this.appendSpaceList(node.modifiers);
|
||||
this.appendToken(node.identifier);
|
||||
this.appendToken(node.questionToken);
|
||||
this.appendNode(node.typeAnnotation);
|
||||
this.appendNode(node.equalsValueClause);
|
||||
}
|
||||
|
||||
public visitMemberAccessExpression(node: MemberAccessExpressionSyntax): void {
|
||||
node.expression.accept(this);
|
||||
this.appendToken(node.dotToken);
|
||||
this.appendToken(node.name);
|
||||
}
|
||||
|
||||
public visitPostfixUnaryExpression(node: PostfixUnaryExpressionSyntax): void {
|
||||
node.operand.accept(this);
|
||||
this.appendToken(node.operatorToken);
|
||||
}
|
||||
|
||||
public visitElementAccessExpression(node: ElementAccessExpressionSyntax): void {
|
||||
node.expression.accept(this);
|
||||
this.appendToken(node.openBracketToken);
|
||||
node.argumentExpression.accept(this);
|
||||
this.appendToken(node.closeBracketToken);
|
||||
}
|
||||
|
||||
public visitInvocationExpression(node: InvocationExpressionSyntax): void {
|
||||
node.expression.accept(this);
|
||||
node.argumentList.accept(this);
|
||||
}
|
||||
|
||||
public visitArgumentList(node: ArgumentListSyntax): void {
|
||||
this.appendToken(node.openParenToken);
|
||||
this.appendSeparatorSpaceList(node.arguments);
|
||||
this.appendToken(node.closeParenToken);
|
||||
}
|
||||
|
||||
public visitBinaryExpression(node: BinaryExpressionSyntax): void {
|
||||
node.left.accept(this);
|
||||
|
||||
if (node.kind() !== SyntaxKind.CommaExpression) {
|
||||
this.ensureSpace();
|
||||
}
|
||||
|
||||
this.appendToken(node.operatorToken);
|
||||
this.ensureSpace();
|
||||
node.right.accept(this);
|
||||
}
|
||||
|
||||
public visitConditionalExpression(node: ConditionalExpressionSyntax): void {
|
||||
node.condition.accept(this);
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.questionToken);
|
||||
this.ensureSpace();
|
||||
node.whenTrue.accept(this);
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.colonToken);
|
||||
this.ensureSpace();
|
||||
node.whenFalse.accept(this);
|
||||
}
|
||||
|
||||
public visitConstructSignature(node: ConstructSignatureSyntax): void {
|
||||
this.appendToken(node.newKeyword);
|
||||
node.callSignature.accept(this);
|
||||
}
|
||||
|
||||
public visitMethodSignature(node: MethodSignatureSyntax): void {
|
||||
this.appendToken(node.propertyName);
|
||||
this.appendToken(node.questionToken);
|
||||
node.callSignature.accept(this);
|
||||
}
|
||||
|
||||
public visitIndexSignature(node: IndexSignatureSyntax): void {
|
||||
this.appendToken(node.openBracketToken);
|
||||
this.appendNode(node.parameter);
|
||||
this.appendToken(node.closeBracketToken);
|
||||
this.appendNode(node.typeAnnotation);
|
||||
}
|
||||
|
||||
public visitPropertySignature(node: PropertySignatureSyntax): void {
|
||||
this.appendToken(node.propertyName);
|
||||
this.appendToken(node.questionToken);
|
||||
this.appendNode(node.typeAnnotation);
|
||||
}
|
||||
|
||||
public visitParameterList(node: ParameterListSyntax): void {
|
||||
this.appendToken(node.openParenToken);
|
||||
this.appendSeparatorSpaceList(node.parameters);
|
||||
this.appendToken(node.closeParenToken);
|
||||
}
|
||||
|
||||
public visitCallSignature(node: CallSignatureSyntax): void {
|
||||
this.appendNode(node.typeParameterList);
|
||||
node.parameterList.accept(this);
|
||||
this.appendNode(node.typeAnnotation);
|
||||
}
|
||||
|
||||
public visitTypeParameterList(node: TypeParameterListSyntax): void {
|
||||
this.appendToken(node.lessThanToken);
|
||||
this.appendSeparatorSpaceList(node.typeParameters);
|
||||
this.appendToken(node.greaterThanToken);
|
||||
}
|
||||
|
||||
public visitTypeParameter(node: TypeParameterSyntax): void {
|
||||
this.appendToken(node.identifier);
|
||||
this.appendNode(node.constraint);
|
||||
}
|
||||
|
||||
public visitConstraint(node: ConstraintSyntax): void {
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.extendsKeyword);
|
||||
this.ensureSpace();
|
||||
node.type.accept(this);
|
||||
}
|
||||
|
||||
private appendBlockOrStatement(node: IStatementSyntax): void {
|
||||
if (node.kind() === SyntaxKind.Block) {
|
||||
this.ensureSpace();
|
||||
node.accept(this);
|
||||
}
|
||||
else {
|
||||
this.ensureNewLine();
|
||||
this.indentation++;
|
||||
node.accept(this);
|
||||
this.indentation--;
|
||||
}
|
||||
}
|
||||
|
||||
public visitIfStatement(node: IfStatementSyntax): void {
|
||||
this.appendToken(node.ifKeyword);
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.openParenToken);
|
||||
node.condition.accept(this);
|
||||
this.appendToken(node.closeParenToken);
|
||||
this.appendBlockOrStatement(node.statement);
|
||||
this.appendNode(node.elseClause);
|
||||
}
|
||||
|
||||
public visitElseClause(node: ElseClauseSyntax): void {
|
||||
this.ensureNewLine();
|
||||
this.appendToken(node.elseKeyword);
|
||||
|
||||
if (node.statement.kind() === SyntaxKind.IfStatement) {
|
||||
this.ensureSpace();
|
||||
node.statement.accept(this);
|
||||
}
|
||||
else {
|
||||
this.appendBlockOrStatement(node.statement);
|
||||
}
|
||||
}
|
||||
|
||||
public visitExpressionStatement(node: ExpressionStatementSyntax): void {
|
||||
node.expression.accept(this);
|
||||
this.appendToken(node.semicolonToken);
|
||||
}
|
||||
|
||||
public visitConstructorDeclaration(node: ConstructorDeclarationSyntax): void {
|
||||
this.appendToken(node.constructorKeyword);
|
||||
node.callSignature.accept(this);
|
||||
this.appendBlockOrSemicolon(node.block, node.semicolonToken);
|
||||
}
|
||||
|
||||
public visitIndexMemberDeclaration(node: IndexMemberDeclarationSyntax): void {
|
||||
this.appendSpaceList(node.modifiers);
|
||||
this.ensureSpace();
|
||||
node.indexSignature.accept(this);
|
||||
this.appendToken(node.semicolonToken);
|
||||
}
|
||||
|
||||
public visitMemberFunctionDeclaration(node: MemberFunctionDeclarationSyntax): void {
|
||||
this.appendSpaceList(node.modifiers);
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.propertyName);
|
||||
node.callSignature.accept(this);
|
||||
this.appendBlockOrSemicolon(node.block, node.semicolonToken);
|
||||
}
|
||||
|
||||
public visitGetAccessor(node: GetAccessorSyntax): void {
|
||||
this.appendSpaceList(node.modifiers);
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.getKeyword);
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.propertyName);
|
||||
node.parameterList.accept(this);
|
||||
this.appendNode(node.typeAnnotation);
|
||||
this.ensureSpace();
|
||||
node.block.accept(this);
|
||||
}
|
||||
|
||||
public visitSetAccessor(node: SetAccessorSyntax): void {
|
||||
this.appendSpaceList(node.modifiers);
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.setKeyword);
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.propertyName);
|
||||
node.parameterList.accept(this);
|
||||
this.ensureSpace();
|
||||
node.block.accept(this);
|
||||
}
|
||||
|
||||
public visitMemberVariableDeclaration(node: MemberVariableDeclarationSyntax): void {
|
||||
this.appendSpaceList(node.modifiers);
|
||||
this.ensureSpace();
|
||||
node.variableDeclarator.accept(this);
|
||||
this.appendToken(node.semicolonToken);
|
||||
}
|
||||
|
||||
public visitThrowStatement(node: ThrowStatementSyntax): void {
|
||||
this.appendToken(node.throwKeyword);
|
||||
|
||||
if (node.expression) {
|
||||
this.ensureSpace();
|
||||
node.expression.accept(this);
|
||||
}
|
||||
|
||||
this.appendToken(node.semicolonToken);
|
||||
}
|
||||
|
||||
public visitReturnStatement(node: ReturnStatementSyntax): void {
|
||||
this.appendToken(node.returnKeyword);
|
||||
|
||||
if (node.expression) {
|
||||
this.ensureSpace();
|
||||
node.expression.accept(this);
|
||||
}
|
||||
|
||||
this.appendToken(node.semicolonToken);
|
||||
}
|
||||
|
||||
public visitObjectCreationExpression(node: ObjectCreationExpressionSyntax): void {
|
||||
this.appendToken(node.newKeyword);
|
||||
this.ensureSpace();
|
||||
node.expression.accept(this);
|
||||
this.appendNode(node.argumentList);
|
||||
}
|
||||
|
||||
public visitSwitchStatement(node: SwitchStatementSyntax): void {
|
||||
this.appendToken(node.switchKeyword);
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.openParenToken);
|
||||
node.expression.accept(this);
|
||||
this.appendToken(node.closeParenToken);
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.openBraceToken);
|
||||
this.ensureNewLine();
|
||||
|
||||
var lastSwitchClause: ISwitchClauseSyntax = null;
|
||||
for (var i = 0, n = node.switchClauses.childCount(); i < n; i++) {
|
||||
var switchClause = <ISwitchClauseSyntax>node.switchClauses.childAt(i);
|
||||
|
||||
var newLineCount = this.newLineCountBetweenSwitchClauses(lastSwitchClause, switchClause);
|
||||
|
||||
this.appendNewLines(newLineCount);
|
||||
switchClause.accept(this);
|
||||
|
||||
lastSwitchClause = switchClause;
|
||||
}
|
||||
|
||||
this.ensureNewLine();
|
||||
this.appendToken(node.closeBraceToken);
|
||||
}
|
||||
|
||||
private appendSwitchClauseStatements(node: ISwitchClauseSyntax): void {
|
||||
if (node.statements.childCount() === 1 && node.statements.childAt(0).kind() === SyntaxKind.Block) {
|
||||
this.ensureSpace();
|
||||
node.statements.childAt(0).accept(this);
|
||||
}
|
||||
else if (node.statements.childCount() > 0) {
|
||||
this.ensureNewLine();
|
||||
|
||||
this.indentation++;
|
||||
this.appendStatements(node.statements);
|
||||
this.indentation--;
|
||||
}
|
||||
}
|
||||
|
||||
public visitCaseSwitchClause(node: CaseSwitchClauseSyntax): void {
|
||||
this.appendToken(node.caseKeyword);
|
||||
this.ensureSpace();
|
||||
node.expression.accept(this);
|
||||
this.appendToken(node.colonToken);
|
||||
this.appendSwitchClauseStatements(node);
|
||||
}
|
||||
|
||||
public visitDefaultSwitchClause(node: DefaultSwitchClauseSyntax): void {
|
||||
this.appendToken(node.defaultKeyword);
|
||||
this.appendToken(node.colonToken);
|
||||
this.appendSwitchClauseStatements(node);
|
||||
}
|
||||
|
||||
public visitBreakStatement(node: BreakStatementSyntax): void {
|
||||
this.appendToken(node.breakKeyword);
|
||||
if (node.identifier) {
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.identifier);
|
||||
}
|
||||
|
||||
this.appendToken(node.semicolonToken);
|
||||
}
|
||||
|
||||
public visitContinueStatement(node: ContinueStatementSyntax): void {
|
||||
this.appendToken(node.continueKeyword);
|
||||
if (node.identifier) {
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.identifier);
|
||||
}
|
||||
|
||||
this.appendToken(node.semicolonToken);
|
||||
}
|
||||
|
||||
public visitForStatement(node: ForStatementSyntax): void {
|
||||
this.appendToken(node.forKeyword);
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.openParenToken);
|
||||
this.appendNode(node.variableDeclaration);
|
||||
this.appendNode(node.initializer);
|
||||
this.appendToken(node.firstSemicolonToken);
|
||||
|
||||
if (node.condition) {
|
||||
this.ensureSpace();
|
||||
node.condition.accept(this);
|
||||
}
|
||||
|
||||
this.appendToken(node.secondSemicolonToken);
|
||||
|
||||
if (node.incrementor) {
|
||||
this.ensureSpace();
|
||||
node.incrementor.accept(this);
|
||||
}
|
||||
|
||||
this.appendToken(node.closeParenToken);
|
||||
this.appendBlockOrStatement(node.statement);
|
||||
}
|
||||
|
||||
public visitForInStatement(node: ForInStatementSyntax): void {
|
||||
this.appendToken(node.forKeyword);
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.openParenToken);
|
||||
this.appendNode(node.variableDeclaration);
|
||||
this.appendNode(node.left);
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.inKeyword);
|
||||
this.ensureSpace();
|
||||
this.appendNode(node.expression);
|
||||
this.appendToken(node.closeParenToken);
|
||||
this.appendBlockOrStatement(node.statement);
|
||||
}
|
||||
|
||||
public visitWhileStatement(node: WhileStatementSyntax): void {
|
||||
this.appendToken(node.whileKeyword);
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.openParenToken);
|
||||
node.condition.accept(this);
|
||||
this.appendToken(node.closeParenToken);
|
||||
this.appendBlockOrStatement(node.statement);
|
||||
}
|
||||
|
||||
public visitWithStatement(node: WithStatementSyntax): void {
|
||||
this.appendToken(node.withKeyword);
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.openParenToken);
|
||||
node.condition.accept(this);
|
||||
this.appendToken(node.closeParenToken);
|
||||
this.appendBlockOrStatement(node.statement);
|
||||
}
|
||||
|
||||
public visitEnumDeclaration(node: EnumDeclarationSyntax): void {
|
||||
this.appendSpaceList(node.modifiers);
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.enumKeyword);
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.identifier);
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.openBraceToken);
|
||||
this.ensureNewLine();
|
||||
|
||||
this.indentation++;
|
||||
this.appendSeparatorNewLineList(node.enumElements);
|
||||
this.indentation--;
|
||||
|
||||
this.appendToken(node.closeBraceToken);
|
||||
}
|
||||
|
||||
public visitEnumElement(node: EnumElementSyntax): void {
|
||||
this.appendToken(node.propertyName);
|
||||
this.ensureSpace();
|
||||
this.appendNode(node.equalsValueClause);
|
||||
}
|
||||
|
||||
public visitCastExpression(node: CastExpressionSyntax): void {
|
||||
this.appendToken(node.lessThanToken);
|
||||
node.type.accept(this);
|
||||
this.appendToken(node.greaterThanToken);
|
||||
node.expression.accept(this);
|
||||
}
|
||||
|
||||
public visitObjectLiteralExpression(node: ObjectLiteralExpressionSyntax): void {
|
||||
this.appendToken(node.openBraceToken);
|
||||
|
||||
if (node.propertyAssignments.childCount() === 1) {
|
||||
this.ensureSpace();
|
||||
node.propertyAssignments.childAt(0).accept(this);
|
||||
this.ensureSpace();
|
||||
}
|
||||
else if (node.propertyAssignments.childCount() > 0) {
|
||||
this.indentation++;
|
||||
this.ensureNewLine();
|
||||
this.appendSeparatorNewLineList(node.propertyAssignments);
|
||||
this.ensureNewLine();
|
||||
this.indentation--;
|
||||
}
|
||||
|
||||
this.appendToken(node.closeBraceToken);
|
||||
}
|
||||
|
||||
public visitSimplePropertyAssignment(node: SimplePropertyAssignmentSyntax): void {
|
||||
this.appendToken(node.propertyName);
|
||||
this.appendToken(node.colonToken);
|
||||
this.ensureSpace();
|
||||
node.expression.accept(this);
|
||||
}
|
||||
|
||||
public visitFunctionPropertyAssignment(node: FunctionPropertyAssignmentSyntax): void {
|
||||
this.appendToken(node.propertyName);
|
||||
node.callSignature.accept(this);
|
||||
this.ensureSpace();
|
||||
node.block.accept(this);
|
||||
}
|
||||
|
||||
public visitFunctionExpression(node: FunctionExpressionSyntax): void {
|
||||
this.appendToken(node.functionKeyword);
|
||||
|
||||
if (node.identifier) {
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.identifier);
|
||||
}
|
||||
|
||||
node.callSignature.accept(this);
|
||||
this.ensureSpace();
|
||||
node.block.accept(this);
|
||||
}
|
||||
|
||||
public visitEmptyStatement(node: EmptyStatementSyntax): void {
|
||||
this.appendToken(node.semicolonToken);
|
||||
}
|
||||
|
||||
public visitTryStatement(node: TryStatementSyntax): void {
|
||||
this.appendToken(node.tryKeyword);
|
||||
this.ensureSpace();
|
||||
node.block.accept(this);
|
||||
this.appendNode(node.catchClause);
|
||||
this.appendNode(node.finallyClause);
|
||||
}
|
||||
|
||||
public visitCatchClause(node: CatchClauseSyntax): void {
|
||||
this.ensureNewLine();
|
||||
this.appendToken(node.catchKeyword);
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.openParenToken);
|
||||
this.appendToken(node.identifier);
|
||||
this.appendToken(node.closeParenToken);
|
||||
this.ensureSpace();
|
||||
node.block.accept(this);
|
||||
}
|
||||
|
||||
public visitFinallyClause(node: FinallyClauseSyntax): void {
|
||||
this.ensureNewLine();
|
||||
this.appendToken(node.finallyKeyword);
|
||||
this.ensureNewLine();
|
||||
node.block.accept(this);
|
||||
}
|
||||
|
||||
public visitLabeledStatement(node: LabeledStatementSyntax): void {
|
||||
this.appendToken(node.identifier);
|
||||
this.appendToken(node.colonToken);
|
||||
this.appendBlockOrStatement(node.statement);
|
||||
}
|
||||
|
||||
public visitDoStatement(node: DoStatementSyntax): void {
|
||||
this.appendToken(node.doKeyword);
|
||||
this.appendBlockOrStatement(node.statement);
|
||||
this.ensureNewLine();
|
||||
this.appendToken(node.whileKeyword);
|
||||
this.ensureSpace();
|
||||
this.appendToken(node.openParenToken);
|
||||
node.condition.accept(this);
|
||||
this.appendToken(node.closeParenToken);
|
||||
this.appendToken(node.semicolonToken);
|
||||
}
|
||||
|
||||
public visitTypeOfExpression(node: TypeOfExpressionSyntax): void {
|
||||
this.appendToken(node.typeOfKeyword);
|
||||
this.ensureSpace();
|
||||
node.expression.accept(this);
|
||||
}
|
||||
|
||||
public visitDeleteExpression(node: DeleteExpressionSyntax): void {
|
||||
this.appendToken(node.deleteKeyword);
|
||||
this.ensureSpace();
|
||||
node.expression.accept(this);
|
||||
}
|
||||
|
||||
public visitVoidExpression(node: VoidExpressionSyntax): void {
|
||||
this.appendToken(node.voidKeyword);
|
||||
this.ensureSpace();
|
||||
node.expression.accept(this);
|
||||
}
|
||||
|
||||
public visitDebuggerStatement(node: DebuggerStatementSyntax): void {
|
||||
this.appendToken(node.debuggerKeyword);
|
||||
this.appendToken(node.semicolonToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
///<reference path='..\text\references.ts' />
|
||||
|
||||
///<reference path='characterInfo.ts' />
|
||||
///<reference path='constants.ts' />
|
||||
///<reference path='formattingOptions.ts' />
|
||||
///<reference path='indentation.ts' />
|
||||
///<reference path='languageVersion.ts' />
|
||||
///<reference path='parseOptions.ts' />
|
||||
///<reference path='positionedElement.ts' />
|
||||
|
||||
// Scanner depends on SyntaxKind and SyntaxFacts
|
||||
///<reference path='syntaxKind.ts' />
|
||||
///<reference path='syntaxFacts.ts' />
|
||||
///<reference path='scanner.ts' />
|
||||
|
||||
///<reference path='scannerUtilities.generated.ts' />
|
||||
///<reference path='separatedSyntaxList.ts' />
|
||||
///<reference path='slidingWindow.ts' />
|
||||
///<reference path='strings.ts' />
|
||||
///<reference path='syntax.ts' />
|
||||
///<reference path='syntaxElement.ts' />
|
||||
///<reference path='syntaxFactory.generated.ts' />
|
||||
///<reference path='syntaxFacts2.ts' />
|
||||
///<reference path='syntaxList.ts' />
|
||||
///<reference path='syntaxNode.ts' />
|
||||
///<reference path='syntaxNodeOrToken.ts' />
|
||||
///<reference path='syntaxNodes.generated.ts' />
|
||||
///<reference path='syntaxRewriter.generated.ts' />
|
||||
|
||||
// SyntaxDedenter depends on SyntaxRewriter
|
||||
///<reference path='syntaxDedenter.ts' />
|
||||
// SyntaxIndenter depends on SyntaxRewriter
|
||||
///<reference path='syntaxIndenter.ts' />
|
||||
|
||||
///<reference path='syntaxToken.generated.ts' />
|
||||
///<reference path='syntaxToken.ts' />
|
||||
///<reference path='syntaxTokenReplacer.ts' />
|
||||
///<reference path='syntaxTrivia.ts' />
|
||||
///<reference path='syntaxTriviaList.ts' />
|
||||
///<reference path='syntaxUtilities.ts' />
|
||||
///<reference path='syntaxVisitor.generated.ts' />
|
||||
///<reference path='syntaxWalker.generated.ts' />
|
||||
|
||||
// PositionTrackingWalker depends on SyntaxWalker
|
||||
///<reference path='positionTrackingWalker.ts' />
|
||||
|
||||
// SyntaxInformationMap depends on SyntaxWalker
|
||||
///<reference path='syntaxInformationMap.ts' />
|
||||
|
||||
// SyntaxInformationMap depends on SyntaxWalker
|
||||
///<reference path='syntaxNodeInvariantsChecker.ts' />
|
||||
|
||||
// DepthLimitedWalker depends on PositionTrackingWalker
|
||||
///<reference path='depthLimitedWalker.ts' />
|
||||
|
||||
// Parser depends on PositionTrackingWalker
|
||||
///<reference path='parser.ts' />
|
||||
|
||||
// SyntaxTree depends on PositionTrackingWalker
|
||||
///<reference path='syntaxTree.ts' />
|
||||
|
||||
///<reference path='unicode.ts' />
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,310 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export class ScannerUtilities {
|
||||
public static identifierKind(array: number[], startIndex: number, length: number): SyntaxKind {
|
||||
switch (length) {
|
||||
case 2:
|
||||
// do, if, in
|
||||
switch(array[startIndex]) {
|
||||
case CharacterCodes.d:
|
||||
// do
|
||||
return (array[startIndex + 1] === CharacterCodes.o) ? SyntaxKind.DoKeyword : SyntaxKind.IdentifierName;
|
||||
case CharacterCodes.i:
|
||||
// if, in
|
||||
switch(array[startIndex + 1]) {
|
||||
case CharacterCodes.f:
|
||||
// if
|
||||
return SyntaxKind.IfKeyword;
|
||||
case CharacterCodes.n:
|
||||
// in
|
||||
return SyntaxKind.InKeyword;
|
||||
default:
|
||||
return SyntaxKind.IdentifierName;
|
||||
}
|
||||
|
||||
default:
|
||||
return SyntaxKind.IdentifierName;
|
||||
}
|
||||
|
||||
case 3:
|
||||
// for, new, try, var, let, any, get, set
|
||||
switch(array[startIndex]) {
|
||||
case CharacterCodes.f:
|
||||
// for
|
||||
return (array[startIndex + 1] === CharacterCodes.o && array[startIndex + 2] === CharacterCodes.r) ? SyntaxKind.ForKeyword : SyntaxKind.IdentifierName;
|
||||
case CharacterCodes.n:
|
||||
// new
|
||||
return (array[startIndex + 1] === CharacterCodes.e && array[startIndex + 2] === CharacterCodes.w) ? SyntaxKind.NewKeyword : SyntaxKind.IdentifierName;
|
||||
case CharacterCodes.t:
|
||||
// try
|
||||
return (array[startIndex + 1] === CharacterCodes.r && array[startIndex + 2] === CharacterCodes.y) ? SyntaxKind.TryKeyword : SyntaxKind.IdentifierName;
|
||||
case CharacterCodes.v:
|
||||
// var
|
||||
return (array[startIndex + 1] === CharacterCodes.a && array[startIndex + 2] === CharacterCodes.r) ? SyntaxKind.VarKeyword : SyntaxKind.IdentifierName;
|
||||
case CharacterCodes.l:
|
||||
// let
|
||||
return (array[startIndex + 1] === CharacterCodes.e && array[startIndex + 2] === CharacterCodes.t) ? SyntaxKind.LetKeyword : SyntaxKind.IdentifierName;
|
||||
case CharacterCodes.a:
|
||||
// any
|
||||
return (array[startIndex + 1] === CharacterCodes.n && array[startIndex + 2] === CharacterCodes.y) ? SyntaxKind.AnyKeyword : SyntaxKind.IdentifierName;
|
||||
case CharacterCodes.g:
|
||||
// get
|
||||
return (array[startIndex + 1] === CharacterCodes.e && array[startIndex + 2] === CharacterCodes.t) ? SyntaxKind.GetKeyword : SyntaxKind.IdentifierName;
|
||||
case CharacterCodes.s:
|
||||
// set
|
||||
return (array[startIndex + 1] === CharacterCodes.e && array[startIndex + 2] === CharacterCodes.t) ? SyntaxKind.SetKeyword : SyntaxKind.IdentifierName;
|
||||
default:
|
||||
return SyntaxKind.IdentifierName;
|
||||
}
|
||||
|
||||
case 4:
|
||||
// case, else, null, this, true, void, with, enum
|
||||
switch(array[startIndex]) {
|
||||
case CharacterCodes.c:
|
||||
// case
|
||||
return (array[startIndex + 1] === CharacterCodes.a && array[startIndex + 2] === CharacterCodes.s && array[startIndex + 3] === CharacterCodes.e) ? SyntaxKind.CaseKeyword : SyntaxKind.IdentifierName;
|
||||
case CharacterCodes.e:
|
||||
// else, enum
|
||||
switch(array[startIndex + 1]) {
|
||||
case CharacterCodes.l:
|
||||
// else
|
||||
return (array[startIndex + 2] === CharacterCodes.s && array[startIndex + 3] === CharacterCodes.e) ? SyntaxKind.ElseKeyword : SyntaxKind.IdentifierName;
|
||||
case CharacterCodes.n:
|
||||
// enum
|
||||
return (array[startIndex + 2] === CharacterCodes.u && array[startIndex + 3] === CharacterCodes.m) ? SyntaxKind.EnumKeyword : SyntaxKind.IdentifierName;
|
||||
default:
|
||||
return SyntaxKind.IdentifierName;
|
||||
}
|
||||
|
||||
case CharacterCodes.n:
|
||||
// null
|
||||
return (array[startIndex + 1] === CharacterCodes.u && array[startIndex + 2] === CharacterCodes.l && array[startIndex + 3] === CharacterCodes.l) ? SyntaxKind.NullKeyword : SyntaxKind.IdentifierName;
|
||||
case CharacterCodes.t:
|
||||
// this, true
|
||||
switch(array[startIndex + 1]) {
|
||||
case CharacterCodes.h:
|
||||
// this
|
||||
return (array[startIndex + 2] === CharacterCodes.i && array[startIndex + 3] === CharacterCodes.s) ? SyntaxKind.ThisKeyword : SyntaxKind.IdentifierName;
|
||||
case CharacterCodes.r:
|
||||
// true
|
||||
return (array[startIndex + 2] === CharacterCodes.u && array[startIndex + 3] === CharacterCodes.e) ? SyntaxKind.TrueKeyword : SyntaxKind.IdentifierName;
|
||||
default:
|
||||
return SyntaxKind.IdentifierName;
|
||||
}
|
||||
|
||||
case CharacterCodes.v:
|
||||
// void
|
||||
return (array[startIndex + 1] === CharacterCodes.o && array[startIndex + 2] === CharacterCodes.i && array[startIndex + 3] === CharacterCodes.d) ? SyntaxKind.VoidKeyword : SyntaxKind.IdentifierName;
|
||||
case CharacterCodes.w:
|
||||
// with
|
||||
return (array[startIndex + 1] === CharacterCodes.i && array[startIndex + 2] === CharacterCodes.t && array[startIndex + 3] === CharacterCodes.h) ? SyntaxKind.WithKeyword : SyntaxKind.IdentifierName;
|
||||
default:
|
||||
return SyntaxKind.IdentifierName;
|
||||
}
|
||||
|
||||
case 5:
|
||||
// break, catch, false, throw, while, class, const, super, yield
|
||||
switch(array[startIndex]) {
|
||||
case CharacterCodes.b:
|
||||
// break
|
||||
return (array[startIndex + 1] === CharacterCodes.r && array[startIndex + 2] === CharacterCodes.e && array[startIndex + 3] === CharacterCodes.a && array[startIndex + 4] === CharacterCodes.k) ? SyntaxKind.BreakKeyword : SyntaxKind.IdentifierName;
|
||||
case CharacterCodes.c:
|
||||
// catch, class, const
|
||||
switch(array[startIndex + 1]) {
|
||||
case CharacterCodes.a:
|
||||
// catch
|
||||
return (array[startIndex + 2] === CharacterCodes.t && array[startIndex + 3] === CharacterCodes.c && array[startIndex + 4] === CharacterCodes.h) ? SyntaxKind.CatchKeyword : SyntaxKind.IdentifierName;
|
||||
case CharacterCodes.l:
|
||||
// class
|
||||
return (array[startIndex + 2] === CharacterCodes.a && array[startIndex + 3] === CharacterCodes.s && array[startIndex + 4] === CharacterCodes.s) ? SyntaxKind.ClassKeyword : SyntaxKind.IdentifierName;
|
||||
case CharacterCodes.o:
|
||||
// const
|
||||
return (array[startIndex + 2] === CharacterCodes.n && array[startIndex + 3] === CharacterCodes.s && array[startIndex + 4] === CharacterCodes.t) ? SyntaxKind.ConstKeyword : SyntaxKind.IdentifierName;
|
||||
default:
|
||||
return SyntaxKind.IdentifierName;
|
||||
}
|
||||
|
||||
case CharacterCodes.f:
|
||||
// false
|
||||
return (array[startIndex + 1] === CharacterCodes.a && array[startIndex + 2] === CharacterCodes.l && array[startIndex + 3] === CharacterCodes.s && array[startIndex + 4] === CharacterCodes.e) ? SyntaxKind.FalseKeyword : SyntaxKind.IdentifierName;
|
||||
case CharacterCodes.t:
|
||||
// throw
|
||||
return (array[startIndex + 1] === CharacterCodes.h && array[startIndex + 2] === CharacterCodes.r && array[startIndex + 3] === CharacterCodes.o && array[startIndex + 4] === CharacterCodes.w) ? SyntaxKind.ThrowKeyword : SyntaxKind.IdentifierName;
|
||||
case CharacterCodes.w:
|
||||
// while
|
||||
return (array[startIndex + 1] === CharacterCodes.h && array[startIndex + 2] === CharacterCodes.i && array[startIndex + 3] === CharacterCodes.l && array[startIndex + 4] === CharacterCodes.e) ? SyntaxKind.WhileKeyword : SyntaxKind.IdentifierName;
|
||||
case CharacterCodes.s:
|
||||
// super
|
||||
return (array[startIndex + 1] === CharacterCodes.u && array[startIndex + 2] === CharacterCodes.p && array[startIndex + 3] === CharacterCodes.e && array[startIndex + 4] === CharacterCodes.r) ? SyntaxKind.SuperKeyword : SyntaxKind.IdentifierName;
|
||||
case CharacterCodes.y:
|
||||
// yield
|
||||
return (array[startIndex + 1] === CharacterCodes.i && array[startIndex + 2] === CharacterCodes.e && array[startIndex + 3] === CharacterCodes.l && array[startIndex + 4] === CharacterCodes.d) ? SyntaxKind.YieldKeyword : SyntaxKind.IdentifierName;
|
||||
default:
|
||||
return SyntaxKind.IdentifierName;
|
||||
}
|
||||
|
||||
case 6:
|
||||
// delete, return, switch, typeof, export, import, public, static, module, number, string
|
||||
switch(array[startIndex]) {
|
||||
case CharacterCodes.d:
|
||||
// delete
|
||||
return (array[startIndex + 1] === CharacterCodes.e && array[startIndex + 2] === CharacterCodes.l && array[startIndex + 3] === CharacterCodes.e && array[startIndex + 4] === CharacterCodes.t && array[startIndex + 5] === CharacterCodes.e) ? SyntaxKind.DeleteKeyword : SyntaxKind.IdentifierName;
|
||||
case CharacterCodes.r:
|
||||
// return
|
||||
return (array[startIndex + 1] === CharacterCodes.e && array[startIndex + 2] === CharacterCodes.t && array[startIndex + 3] === CharacterCodes.u && array[startIndex + 4] === CharacterCodes.r && array[startIndex + 5] === CharacterCodes.n) ? SyntaxKind.ReturnKeyword : SyntaxKind.IdentifierName;
|
||||
case CharacterCodes.s:
|
||||
// switch, static, string
|
||||
switch(array[startIndex + 1]) {
|
||||
case CharacterCodes.w:
|
||||
// switch
|
||||
return (array[startIndex + 2] === CharacterCodes.i && array[startIndex + 3] === CharacterCodes.t && array[startIndex + 4] === CharacterCodes.c && array[startIndex + 5] === CharacterCodes.h) ? SyntaxKind.SwitchKeyword : SyntaxKind.IdentifierName;
|
||||
case CharacterCodes.t:
|
||||
// static, string
|
||||
switch(array[startIndex + 2]) {
|
||||
case CharacterCodes.a:
|
||||
// static
|
||||
return (array[startIndex + 3] === CharacterCodes.t && array[startIndex + 4] === CharacterCodes.i && array[startIndex + 5] === CharacterCodes.c) ? SyntaxKind.StaticKeyword : SyntaxKind.IdentifierName;
|
||||
case CharacterCodes.r:
|
||||
// string
|
||||
return (array[startIndex + 3] === CharacterCodes.i && array[startIndex + 4] === CharacterCodes.n && array[startIndex + 5] === CharacterCodes.g) ? SyntaxKind.StringKeyword : SyntaxKind.IdentifierName;
|
||||
default:
|
||||
return SyntaxKind.IdentifierName;
|
||||
}
|
||||
|
||||
default:
|
||||
return SyntaxKind.IdentifierName;
|
||||
}
|
||||
|
||||
case CharacterCodes.t:
|
||||
// typeof
|
||||
return (array[startIndex + 1] === CharacterCodes.y && array[startIndex + 2] === CharacterCodes.p && array[startIndex + 3] === CharacterCodes.e && array[startIndex + 4] === CharacterCodes.o && array[startIndex + 5] === CharacterCodes.f) ? SyntaxKind.TypeOfKeyword : SyntaxKind.IdentifierName;
|
||||
case CharacterCodes.e:
|
||||
// export
|
||||
return (array[startIndex + 1] === CharacterCodes.x && array[startIndex + 2] === CharacterCodes.p && array[startIndex + 3] === CharacterCodes.o && array[startIndex + 4] === CharacterCodes.r && array[startIndex + 5] === CharacterCodes.t) ? SyntaxKind.ExportKeyword : SyntaxKind.IdentifierName;
|
||||
case CharacterCodes.i:
|
||||
// import
|
||||
return (array[startIndex + 1] === CharacterCodes.m && array[startIndex + 2] === CharacterCodes.p && array[startIndex + 3] === CharacterCodes.o && array[startIndex + 4] === CharacterCodes.r && array[startIndex + 5] === CharacterCodes.t) ? SyntaxKind.ImportKeyword : SyntaxKind.IdentifierName;
|
||||
case CharacterCodes.p:
|
||||
// public
|
||||
return (array[startIndex + 1] === CharacterCodes.u && array[startIndex + 2] === CharacterCodes.b && array[startIndex + 3] === CharacterCodes.l && array[startIndex + 4] === CharacterCodes.i && array[startIndex + 5] === CharacterCodes.c) ? SyntaxKind.PublicKeyword : SyntaxKind.IdentifierName;
|
||||
case CharacterCodes.m:
|
||||
// module
|
||||
return (array[startIndex + 1] === CharacterCodes.o && array[startIndex + 2] === CharacterCodes.d && array[startIndex + 3] === CharacterCodes.u && array[startIndex + 4] === CharacterCodes.l && array[startIndex + 5] === CharacterCodes.e) ? SyntaxKind.ModuleKeyword : SyntaxKind.IdentifierName;
|
||||
case CharacterCodes.n:
|
||||
// number
|
||||
return (array[startIndex + 1] === CharacterCodes.u && array[startIndex + 2] === CharacterCodes.m && array[startIndex + 3] === CharacterCodes.b && array[startIndex + 4] === CharacterCodes.e && array[startIndex + 5] === CharacterCodes.r) ? SyntaxKind.NumberKeyword : SyntaxKind.IdentifierName;
|
||||
default:
|
||||
return SyntaxKind.IdentifierName;
|
||||
}
|
||||
|
||||
case 7:
|
||||
// default, finally, extends, package, private, boolean, declare, require
|
||||
switch(array[startIndex]) {
|
||||
case CharacterCodes.d:
|
||||
// default, declare
|
||||
switch(array[startIndex + 1]) {
|
||||
case CharacterCodes.e:
|
||||
// default, declare
|
||||
switch(array[startIndex + 2]) {
|
||||
case CharacterCodes.f:
|
||||
// default
|
||||
return (array[startIndex + 3] === CharacterCodes.a && array[startIndex + 4] === CharacterCodes.u && array[startIndex + 5] === CharacterCodes.l && array[startIndex + 6] === CharacterCodes.t) ? SyntaxKind.DefaultKeyword : SyntaxKind.IdentifierName;
|
||||
case CharacterCodes.c:
|
||||
// declare
|
||||
return (array[startIndex + 3] === CharacterCodes.l && array[startIndex + 4] === CharacterCodes.a && array[startIndex + 5] === CharacterCodes.r && array[startIndex + 6] === CharacterCodes.e) ? SyntaxKind.DeclareKeyword : SyntaxKind.IdentifierName;
|
||||
default:
|
||||
return SyntaxKind.IdentifierName;
|
||||
}
|
||||
|
||||
default:
|
||||
return SyntaxKind.IdentifierName;
|
||||
}
|
||||
|
||||
case CharacterCodes.f:
|
||||
// finally
|
||||
return (array[startIndex + 1] === CharacterCodes.i && array[startIndex + 2] === CharacterCodes.n && array[startIndex + 3] === CharacterCodes.a && array[startIndex + 4] === CharacterCodes.l && array[startIndex + 5] === CharacterCodes.l && array[startIndex + 6] === CharacterCodes.y) ? SyntaxKind.FinallyKeyword : SyntaxKind.IdentifierName;
|
||||
case CharacterCodes.e:
|
||||
// extends
|
||||
return (array[startIndex + 1] === CharacterCodes.x && array[startIndex + 2] === CharacterCodes.t && array[startIndex + 3] === CharacterCodes.e && array[startIndex + 4] === CharacterCodes.n && array[startIndex + 5] === CharacterCodes.d && array[startIndex + 6] === CharacterCodes.s) ? SyntaxKind.ExtendsKeyword : SyntaxKind.IdentifierName;
|
||||
case CharacterCodes.p:
|
||||
// package, private
|
||||
switch(array[startIndex + 1]) {
|
||||
case CharacterCodes.a:
|
||||
// package
|
||||
return (array[startIndex + 2] === CharacterCodes.c && array[startIndex + 3] === CharacterCodes.k && array[startIndex + 4] === CharacterCodes.a && array[startIndex + 5] === CharacterCodes.g && array[startIndex + 6] === CharacterCodes.e) ? SyntaxKind.PackageKeyword : SyntaxKind.IdentifierName;
|
||||
case CharacterCodes.r:
|
||||
// private
|
||||
return (array[startIndex + 2] === CharacterCodes.i && array[startIndex + 3] === CharacterCodes.v && array[startIndex + 4] === CharacterCodes.a && array[startIndex + 5] === CharacterCodes.t && array[startIndex + 6] === CharacterCodes.e) ? SyntaxKind.PrivateKeyword : SyntaxKind.IdentifierName;
|
||||
default:
|
||||
return SyntaxKind.IdentifierName;
|
||||
}
|
||||
|
||||
case CharacterCodes.b:
|
||||
// boolean
|
||||
return (array[startIndex + 1] === CharacterCodes.o && array[startIndex + 2] === CharacterCodes.o && array[startIndex + 3] === CharacterCodes.l && array[startIndex + 4] === CharacterCodes.e && array[startIndex + 5] === CharacterCodes.a && array[startIndex + 6] === CharacterCodes.n) ? SyntaxKind.BooleanKeyword : SyntaxKind.IdentifierName;
|
||||
case CharacterCodes.r:
|
||||
// require
|
||||
return (array[startIndex + 1] === CharacterCodes.e && array[startIndex + 2] === CharacterCodes.q && array[startIndex + 3] === CharacterCodes.u && array[startIndex + 4] === CharacterCodes.i && array[startIndex + 5] === CharacterCodes.r && array[startIndex + 6] === CharacterCodes.e) ? SyntaxKind.RequireKeyword : SyntaxKind.IdentifierName;
|
||||
default:
|
||||
return SyntaxKind.IdentifierName;
|
||||
}
|
||||
|
||||
case 8:
|
||||
// continue, debugger, function
|
||||
switch(array[startIndex]) {
|
||||
case CharacterCodes.c:
|
||||
// continue
|
||||
return (array[startIndex + 1] === CharacterCodes.o && array[startIndex + 2] === CharacterCodes.n && array[startIndex + 3] === CharacterCodes.t && array[startIndex + 4] === CharacterCodes.i && array[startIndex + 5] === CharacterCodes.n && array[startIndex + 6] === CharacterCodes.u && array[startIndex + 7] === CharacterCodes.e) ? SyntaxKind.ContinueKeyword : SyntaxKind.IdentifierName;
|
||||
case CharacterCodes.d:
|
||||
// debugger
|
||||
return (array[startIndex + 1] === CharacterCodes.e && array[startIndex + 2] === CharacterCodes.b && array[startIndex + 3] === CharacterCodes.u && array[startIndex + 4] === CharacterCodes.g && array[startIndex + 5] === CharacterCodes.g && array[startIndex + 6] === CharacterCodes.e && array[startIndex + 7] === CharacterCodes.r) ? SyntaxKind.DebuggerKeyword : SyntaxKind.IdentifierName;
|
||||
case CharacterCodes.f:
|
||||
// function
|
||||
return (array[startIndex + 1] === CharacterCodes.u && array[startIndex + 2] === CharacterCodes.n && array[startIndex + 3] === CharacterCodes.c && array[startIndex + 4] === CharacterCodes.t && array[startIndex + 5] === CharacterCodes.i && array[startIndex + 6] === CharacterCodes.o && array[startIndex + 7] === CharacterCodes.n) ? SyntaxKind.FunctionKeyword : SyntaxKind.IdentifierName;
|
||||
default:
|
||||
return SyntaxKind.IdentifierName;
|
||||
}
|
||||
|
||||
case 9:
|
||||
// interface, protected
|
||||
switch(array[startIndex]) {
|
||||
case CharacterCodes.i:
|
||||
// interface
|
||||
return (array[startIndex + 1] === CharacterCodes.n && array[startIndex + 2] === CharacterCodes.t && array[startIndex + 3] === CharacterCodes.e && array[startIndex + 4] === CharacterCodes.r && array[startIndex + 5] === CharacterCodes.f && array[startIndex + 6] === CharacterCodes.a && array[startIndex + 7] === CharacterCodes.c && array[startIndex + 8] === CharacterCodes.e) ? SyntaxKind.InterfaceKeyword : SyntaxKind.IdentifierName;
|
||||
case CharacterCodes.p:
|
||||
// protected
|
||||
return (array[startIndex + 1] === CharacterCodes.r && array[startIndex + 2] === CharacterCodes.o && array[startIndex + 3] === CharacterCodes.t && array[startIndex + 4] === CharacterCodes.e && array[startIndex + 5] === CharacterCodes.c && array[startIndex + 6] === CharacterCodes.t && array[startIndex + 7] === CharacterCodes.e && array[startIndex + 8] === CharacterCodes.d) ? SyntaxKind.ProtectedKeyword : SyntaxKind.IdentifierName;
|
||||
default:
|
||||
return SyntaxKind.IdentifierName;
|
||||
}
|
||||
|
||||
case 10:
|
||||
// instanceof, implements
|
||||
switch(array[startIndex]) {
|
||||
case CharacterCodes.i:
|
||||
// instanceof, implements
|
||||
switch(array[startIndex + 1]) {
|
||||
case CharacterCodes.n:
|
||||
// instanceof
|
||||
return (array[startIndex + 2] === CharacterCodes.s && array[startIndex + 3] === CharacterCodes.t && array[startIndex + 4] === CharacterCodes.a && array[startIndex + 5] === CharacterCodes.n && array[startIndex + 6] === CharacterCodes.c && array[startIndex + 7] === CharacterCodes.e && array[startIndex + 8] === CharacterCodes.o && array[startIndex + 9] === CharacterCodes.f) ? SyntaxKind.InstanceOfKeyword : SyntaxKind.IdentifierName;
|
||||
case CharacterCodes.m:
|
||||
// implements
|
||||
return (array[startIndex + 2] === CharacterCodes.p && array[startIndex + 3] === CharacterCodes.l && array[startIndex + 4] === CharacterCodes.e && array[startIndex + 5] === CharacterCodes.m && array[startIndex + 6] === CharacterCodes.e && array[startIndex + 7] === CharacterCodes.n && array[startIndex + 8] === CharacterCodes.t && array[startIndex + 9] === CharacterCodes.s) ? SyntaxKind.ImplementsKeyword : SyntaxKind.IdentifierName;
|
||||
default:
|
||||
return SyntaxKind.IdentifierName;
|
||||
}
|
||||
|
||||
default:
|
||||
return SyntaxKind.IdentifierName;
|
||||
}
|
||||
|
||||
case 11:
|
||||
// constructor
|
||||
return (array[startIndex] === CharacterCodes.c && array[startIndex + 1] === CharacterCodes.o && array[startIndex + 2] === CharacterCodes.n && array[startIndex + 3] === CharacterCodes.s && array[startIndex + 4] === CharacterCodes.t && array[startIndex + 5] === CharacterCodes.r && array[startIndex + 6] === CharacterCodes.u && array[startIndex + 7] === CharacterCodes.c && array[startIndex + 8] === CharacterCodes.t && array[startIndex + 9] === CharacterCodes.o && array[startIndex + 10] === CharacterCodes.r) ? SyntaxKind.ConstructorKeyword : SyntaxKind.IdentifierName;
|
||||
default:
|
||||
return SyntaxKind.IdentifierName;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,471 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export interface ISeparatedSyntaxList extends ISyntaxElement {
|
||||
childAt(index: number): ISyntaxNodeOrToken;
|
||||
|
||||
toArray(): ISyntaxNodeOrToken[];
|
||||
toNonSeparatorArray(): ISyntaxNodeOrToken[];
|
||||
|
||||
separatorCount(): number;
|
||||
separatorAt(index: number): ISyntaxToken;
|
||||
|
||||
nonSeparatorCount(): number;
|
||||
nonSeparatorAt(index: number): ISyntaxNodeOrToken;
|
||||
|
||||
insertChildrenInto(array: ISyntaxElement[], index: number): void;
|
||||
}
|
||||
}
|
||||
|
||||
module TypeScript.Syntax {
|
||||
class EmptySeparatedSyntaxList implements ISeparatedSyntaxList {
|
||||
public kind() {
|
||||
return SyntaxKind.SeparatedList;
|
||||
}
|
||||
|
||||
public isNode() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public isToken() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public isList() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public isSeparatedList() {
|
||||
return true;
|
||||
}
|
||||
|
||||
toJSON(key: any): any[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
public childCount() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public nonSeparatorCount() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public separatorCount() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public toArray(): ISyntaxNodeOrToken[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
public toNonSeparatorArray(): ISyntaxNodeOrToken[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
public childAt(index: number): ISyntaxNodeOrToken {
|
||||
throw Errors.argumentOutOfRange("index");
|
||||
}
|
||||
|
||||
public nonSeparatorAt(index: number): ISyntaxNodeOrToken {
|
||||
throw Errors.argumentOutOfRange("index");
|
||||
}
|
||||
|
||||
public separatorAt(index: number): ISyntaxToken {
|
||||
throw Errors.argumentOutOfRange("index");
|
||||
}
|
||||
|
||||
collectTextElements(elements: string[]): void {
|
||||
}
|
||||
|
||||
firstToken(): ISyntaxToken {
|
||||
return null;
|
||||
}
|
||||
|
||||
lastToken(): ISyntaxToken {
|
||||
return null;
|
||||
}
|
||||
|
||||
fullWidth() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
fullText() {
|
||||
return "";
|
||||
}
|
||||
|
||||
width() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
isTypeScriptSpecific() {
|
||||
return false;
|
||||
}
|
||||
|
||||
isIncrementallyUnusable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
findTokenInternal(parent: PositionedElement, position: number, fullStart: number): PositionedToken {
|
||||
// This should never have been called on this list. It has a 0 width, so the client
|
||||
// should have skipped over this.
|
||||
throw Errors.invalidOperation();
|
||||
}
|
||||
|
||||
insertChildrenInto(array: ISyntaxElement[], index: number): void {
|
||||
}
|
||||
|
||||
leadingTrivia() {
|
||||
return Syntax.emptyTriviaList;
|
||||
}
|
||||
|
||||
trailingTrivia() {
|
||||
return Syntax.emptyTriviaList;
|
||||
}
|
||||
|
||||
leadingTriviaWidth() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
trailingTriviaWidth() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
export var emptySeparatedList: ISeparatedSyntaxList = new EmptySeparatedSyntaxList();
|
||||
|
||||
class SingletonSeparatedSyntaxList implements ISeparatedSyntaxList {
|
||||
private item: ISyntaxNodeOrToken;
|
||||
|
||||
constructor(item: ISyntaxNodeOrToken) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
public toJSON(key: any) {
|
||||
return [this.item];
|
||||
}
|
||||
|
||||
public kind() { return SyntaxKind.SeparatedList; }
|
||||
|
||||
public isNode(): boolean { return false; }
|
||||
public isToken(): boolean { return false; }
|
||||
public isList(): boolean { return false; }
|
||||
public isSeparatedList(): boolean { return true; }
|
||||
|
||||
public childCount() { return 1; }
|
||||
public nonSeparatorCount() { return 1; }
|
||||
public separatorCount() { return 0; }
|
||||
|
||||
public toArray() { return [this.item]; }
|
||||
public toNonSeparatorArray() { return [this.item]; }
|
||||
|
||||
public childAt(index: number): ISyntaxNodeOrToken {
|
||||
if (index !== 0) {
|
||||
throw Errors.argumentOutOfRange("index");
|
||||
}
|
||||
|
||||
return this.item;
|
||||
}
|
||||
|
||||
public nonSeparatorAt(index: number): ISyntaxNodeOrToken {
|
||||
if (index !== 0) {
|
||||
throw Errors.argumentOutOfRange("index");
|
||||
}
|
||||
|
||||
return this.item;
|
||||
}
|
||||
|
||||
public separatorAt(index: number): ISyntaxToken {
|
||||
throw Errors.argumentOutOfRange("index");
|
||||
}
|
||||
|
||||
public collectTextElements(elements: string[]): void {
|
||||
this.item.collectTextElements(elements);
|
||||
}
|
||||
|
||||
public firstToken(): ISyntaxToken {
|
||||
return this.item.firstToken();
|
||||
}
|
||||
|
||||
public lastToken(): ISyntaxToken {
|
||||
return this.item.lastToken();
|
||||
}
|
||||
|
||||
public fullWidth(): number {
|
||||
return this.item.fullWidth();
|
||||
}
|
||||
|
||||
public width(): number {
|
||||
return this.item.width();
|
||||
}
|
||||
|
||||
public fullText(): string {
|
||||
return this.item.fullText();
|
||||
}
|
||||
|
||||
public leadingTrivia(): ISyntaxTriviaList {
|
||||
return this.item.leadingTrivia();
|
||||
}
|
||||
|
||||
public trailingTrivia(): ISyntaxTriviaList {
|
||||
return this.item.trailingTrivia();
|
||||
}
|
||||
|
||||
public leadingTriviaWidth(): number {
|
||||
return this.item.leadingTriviaWidth();
|
||||
}
|
||||
|
||||
public trailingTriviaWidth(): number {
|
||||
return this.item.trailingTriviaWidth();
|
||||
}
|
||||
|
||||
public isTypeScriptSpecific(): boolean {
|
||||
return this.item.isTypeScriptSpecific();
|
||||
}
|
||||
|
||||
public isIncrementallyUnusable(): boolean {
|
||||
return this.item.isIncrementallyUnusable();
|
||||
}
|
||||
|
||||
public findTokenInternal(parent: PositionedElement, position: number, fullStart: number): PositionedToken {
|
||||
// Debug.assert(position >= 0 && position < this.item.fullWidth());
|
||||
return (<any>this.item).findTokenInternal(
|
||||
new PositionedSeparatedList(parent, this, fullStart), position, fullStart);
|
||||
}
|
||||
|
||||
public insertChildrenInto(array: ISyntaxElement[], index: number): void {
|
||||
array.splice(index, 0, this.item);
|
||||
}
|
||||
}
|
||||
|
||||
class NormalSeparatedSyntaxList implements ISeparatedSyntaxList {
|
||||
private elements: ISyntaxNodeOrToken[];
|
||||
private _data: number = 0;
|
||||
|
||||
constructor(elements: ISyntaxNodeOrToken[]) {
|
||||
this.elements = elements;
|
||||
}
|
||||
|
||||
public kind() { return SyntaxKind.SeparatedList; }
|
||||
|
||||
public isToken(): boolean { return false; }
|
||||
public isNode(): boolean { return false; }
|
||||
public isList(): boolean { return false; }
|
||||
public isSeparatedList(): boolean { return true; }
|
||||
public toJSON(key: any) { return this.elements; }
|
||||
|
||||
public childCount() { return this.elements.length; }
|
||||
public nonSeparatorCount() { return IntegerUtilities.integerDivide(this.elements.length + 1, 2); }
|
||||
public separatorCount() { return IntegerUtilities.integerDivide(this.elements.length, 2); }
|
||||
|
||||
public toArray(): ISyntaxNodeOrToken[] { return this.elements.slice(0); }
|
||||
|
||||
public toNonSeparatorArray(): ISyntaxNodeOrToken[] {
|
||||
var result: ISyntaxNodeOrToken[] = [];
|
||||
for (var i = 0, n = this.nonSeparatorCount(); i < n; i++) {
|
||||
result.push(this.nonSeparatorAt(i));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public childAt(index: number): ISyntaxNodeOrToken {
|
||||
if (index < 0 || index >= this.elements.length) {
|
||||
throw Errors.argumentOutOfRange("index");
|
||||
}
|
||||
|
||||
return this.elements[index];
|
||||
}
|
||||
|
||||
public nonSeparatorAt(index: number): ISyntaxNodeOrToken {
|
||||
var value = index * 2;
|
||||
if (value < 0 || value >= this.elements.length) {
|
||||
throw Errors.argumentOutOfRange("index");
|
||||
}
|
||||
|
||||
return this.elements[value];
|
||||
}
|
||||
|
||||
public separatorAt(index: number): ISyntaxToken {
|
||||
var value = index * 2 + 1;
|
||||
if (value < 0 || value >= this.elements.length) {
|
||||
throw Errors.argumentOutOfRange("index");
|
||||
}
|
||||
|
||||
return <ISyntaxToken>this.elements[value];
|
||||
}
|
||||
|
||||
public firstToken(): ISyntaxToken {
|
||||
var token: ISyntaxToken;
|
||||
for (var i = 0, n = this.elements.length; i < n; i++) {
|
||||
if (i % 2 === 0) {
|
||||
var nodeOrToken = this.elements[i];
|
||||
token = nodeOrToken.firstToken();
|
||||
if (token !== null) {
|
||||
return token;
|
||||
}
|
||||
}
|
||||
else {
|
||||
token = <ISyntaxToken>this.elements[i];
|
||||
if (token.width() > 0) {
|
||||
return token;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public lastToken(): ISyntaxToken {
|
||||
var token: ISyntaxToken;
|
||||
for (var i = this.elements.length - 1; i >= 0; i--) {
|
||||
if (i % 2 === 0) {
|
||||
var nodeOrToken = this.elements[i];
|
||||
token = nodeOrToken.lastToken();
|
||||
if (token !== null) {
|
||||
return token;
|
||||
}
|
||||
}
|
||||
else {
|
||||
token = <ISyntaxToken>this.elements[i];
|
||||
if (token.width() > 0) {
|
||||
return token;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public fullText(): string {
|
||||
var elements: string[] = [];
|
||||
this.collectTextElements(elements);
|
||||
return elements.join("");
|
||||
}
|
||||
|
||||
public isTypeScriptSpecific(): boolean {
|
||||
for (var i = 0, n = this.nonSeparatorCount(); i < n; i++) {
|
||||
if (this.nonSeparatorAt(i).isTypeScriptSpecific()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public isIncrementallyUnusable(): boolean {
|
||||
return (this.data() & SyntaxConstants.NodeIncrementallyUnusableMask) !== 0;
|
||||
}
|
||||
|
||||
public fullWidth(): number {
|
||||
return this.data() >>> SyntaxConstants.NodeFullWidthShift;
|
||||
}
|
||||
|
||||
public width(): number {
|
||||
var fullWidth = this.fullWidth();
|
||||
return fullWidth - this.leadingTriviaWidth() - this.trailingTriviaWidth();
|
||||
}
|
||||
|
||||
public leadingTrivia(): ISyntaxTriviaList {
|
||||
return this.firstToken().leadingTrivia();
|
||||
}
|
||||
|
||||
public trailingTrivia(): ISyntaxTriviaList {
|
||||
return this.lastToken().trailingTrivia();
|
||||
}
|
||||
|
||||
public leadingTriviaWidth(): number {
|
||||
return this.firstToken().leadingTriviaWidth();
|
||||
}
|
||||
|
||||
public trailingTriviaWidth(): number {
|
||||
return this.lastToken().trailingTriviaWidth();
|
||||
}
|
||||
|
||||
private computeData(): number {
|
||||
var fullWidth = 0;
|
||||
var isIncrementallyUnusable = false;
|
||||
|
||||
for (var i = 0, n = this.elements.length; i < n; i++) {
|
||||
var element = this.elements[i];
|
||||
|
||||
var childWidth = element.fullWidth();
|
||||
fullWidth += childWidth;
|
||||
|
||||
isIncrementallyUnusable = isIncrementallyUnusable || element.isIncrementallyUnusable();
|
||||
}
|
||||
|
||||
return (fullWidth << SyntaxConstants.NodeFullWidthShift)
|
||||
| (isIncrementallyUnusable ? SyntaxConstants.NodeIncrementallyUnusableMask : 0)
|
||||
| SyntaxConstants.NodeDataComputed;
|
||||
}
|
||||
|
||||
private data(): number {
|
||||
if ((this._data & SyntaxConstants.NodeDataComputed) === 0) {
|
||||
this._data = this.computeData();
|
||||
}
|
||||
|
||||
return this._data;
|
||||
}
|
||||
|
||||
public findTokenInternal(parent: PositionedElement, position: number, fullStart: number): PositionedToken {
|
||||
parent = new PositionedSeparatedList(parent, this, fullStart);
|
||||
for (var i = 0, n = this.elements.length; i < n; i++) {
|
||||
var element = this.elements[i];
|
||||
|
||||
var childWidth = element.fullWidth();
|
||||
if (position < childWidth) {
|
||||
return (<any>element).findTokenInternal(parent, position, fullStart);
|
||||
}
|
||||
|
||||
position -= childWidth;
|
||||
fullStart += childWidth;
|
||||
}
|
||||
|
||||
throw Errors.invalidOperation();
|
||||
}
|
||||
|
||||
public collectTextElements(elements: string[]): void {
|
||||
for (var i = 0, n = this.elements.length; i < n; i++) {
|
||||
var element = this.elements[i];
|
||||
element.collectTextElements(elements);
|
||||
}
|
||||
}
|
||||
|
||||
public insertChildrenInto(array: ISyntaxElement[], index: number): void {
|
||||
if (index === 0) {
|
||||
array.unshift.apply(array, this.elements);
|
||||
}
|
||||
else {
|
||||
// TODO: this seems awfully innefficient. Can we do better here?
|
||||
array.splice.apply(array, [index, <any>0].concat(this.elements));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function separatedList(nodes: ISyntaxNodeOrToken[]): ISeparatedSyntaxList {
|
||||
return separatedListAndValidate(nodes, false);
|
||||
}
|
||||
|
||||
function separatedListAndValidate(nodes: ISyntaxNodeOrToken[], validate: boolean): ISeparatedSyntaxList {
|
||||
if (nodes === undefined || nodes === null || nodes.length === 0) {
|
||||
return emptySeparatedList;
|
||||
}
|
||||
|
||||
if (validate) {
|
||||
for (var i = 0; i < nodes.length; i++) {
|
||||
var item = nodes[i];
|
||||
|
||||
if (i % 2 === 1) {
|
||||
// Debug.assert(SyntaxFacts.isTokenKind(item.kind()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (nodes.length === 1) {
|
||||
return new SingletonSeparatedSyntaxList(nodes[0]);
|
||||
}
|
||||
|
||||
return new NormalSeparatedSyntaxList(nodes);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,228 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export interface ISlidingWindowSource {
|
||||
// Asks the source to copy items starting at sourceIndex into the window at 'destinationIndex'
|
||||
// with up to 'spaceAvailable' items. The actual number of items fetched should be given as
|
||||
// the return value.
|
||||
fetchMoreItems(argument: any, sourceIndex: number, window: any[], destinationIndex: number, spaceAvailable: number): number;
|
||||
}
|
||||
|
||||
export class SlidingWindow {
|
||||
|
||||
// The number of valid items in window.
|
||||
public windowCount: number = 0;
|
||||
|
||||
// The *absolute* index in the *full* array of items the *window* array starts at. i.e.
|
||||
// if there were 100 items, and window contains tokens [70, 80), then this value would be
|
||||
// 70.
|
||||
public windowAbsoluteStartIndex: number = 0;
|
||||
|
||||
// The index in the window array that we're at. i.e. if there 100 items and
|
||||
// window contains tokens [70, 80), and we're on item 75, then this value would be '5'.
|
||||
// Note: it is not absolute. It is relative to the start of the window.
|
||||
public currentRelativeItemIndex: number = 0;
|
||||
|
||||
// The number of pinned points there are. As long as there is at least one pinned point, we
|
||||
// will not advance the start of the window array past the item marked by that pin point.
|
||||
private _pinCount: number = 0;
|
||||
|
||||
// If there are any outstanding rewind points, this is index in the full array of items
|
||||
// that the first rewind point points to. If this is not -1, then we will not shift the
|
||||
// start of the items array past this point.
|
||||
private firstPinnedAbsoluteIndex: number = -1;
|
||||
|
||||
constructor(// Underlying source that we retrieve items from.
|
||||
private source: ISlidingWindowSource,
|
||||
// A window of items that has been read in from the underlying source.
|
||||
public window: any[],
|
||||
// The default value to return when there are no more items left in the window.
|
||||
private defaultValue: any,
|
||||
// The length of the source we're reading from if we know it up front. -1 if we do not.
|
||||
private sourceLength = -1) {
|
||||
}
|
||||
|
||||
// The last legal index of the window (exclusive).
|
||||
private windowAbsoluteEndIndex(): number {
|
||||
return this.windowAbsoluteStartIndex + this.windowCount;
|
||||
}
|
||||
|
||||
private addMoreItemsToWindow(argument: any): boolean {
|
||||
if (this.sourceLength >= 0 && this.absoluteIndex() >= this.sourceLength) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// First, make room for the new items if we're out of room.
|
||||
if (this.windowCount >= this.window.length) {
|
||||
this.tryShiftOrGrowWindow();
|
||||
}
|
||||
|
||||
var spaceAvailable = this.window.length - this.windowCount;
|
||||
var amountFetched = this.source.fetchMoreItems(argument, this.windowAbsoluteEndIndex(), this.window, this.windowCount, spaceAvailable);
|
||||
|
||||
// Assert disabled because it is actually expensive enugh to affect perf.
|
||||
|
||||
this.windowCount += amountFetched;
|
||||
return amountFetched > 0;
|
||||
}
|
||||
|
||||
private tryShiftOrGrowWindow(): void {
|
||||
// We want to shift if our current item is past the halfway point of the current item window.
|
||||
var currentIndexIsPastWindowHalfwayPoint = this.currentRelativeItemIndex > (this.window.length >>> 1);
|
||||
|
||||
// However, we can only shift if we have no outstanding rewind points. Or, if we have an
|
||||
// outstanding rewind point, that it points to some point after the start of the window.
|
||||
var isAllowedToShift =
|
||||
this.firstPinnedAbsoluteIndex === -1 ||
|
||||
this.firstPinnedAbsoluteIndex > this.windowAbsoluteStartIndex;
|
||||
|
||||
if (currentIndexIsPastWindowHalfwayPoint && isAllowedToShift) {
|
||||
// Figure out where we're going to start shifting from. If we have no oustanding rewind
|
||||
// points, then we'll start shifting over all the items starting from the current
|
||||
// token we're point out. Otherwise, we'll shift starting from the first item that
|
||||
// the rewind point is pointing at.
|
||||
//
|
||||
// We'll call that point 'N' from now on.
|
||||
var shiftStartIndex = this.firstPinnedAbsoluteIndex === -1
|
||||
? this.currentRelativeItemIndex
|
||||
: this.firstPinnedAbsoluteIndex - this.windowAbsoluteStartIndex;
|
||||
|
||||
// We have to shift the number of elements between the start index and the number of
|
||||
// items in the window.
|
||||
var shiftCount = this.windowCount - shiftStartIndex;
|
||||
|
||||
// Debug.assert(shiftStartIndex > 0);
|
||||
if (shiftCount > 0) {
|
||||
ArrayUtilities.copy(this.window, shiftStartIndex, this.window, 0, shiftCount);
|
||||
}
|
||||
|
||||
// The window has now moved over to the right by N.
|
||||
this.windowAbsoluteStartIndex += shiftStartIndex;
|
||||
|
||||
// The number of valid items in the window has now decreased by N.
|
||||
this.windowCount -= shiftStartIndex;
|
||||
|
||||
// The current item now starts further to the left in the window.
|
||||
this.currentRelativeItemIndex -= shiftStartIndex;
|
||||
}
|
||||
else {
|
||||
// Grow the exisitng array.
|
||||
// this.window[this.window.length * 2 - 1] = this.defaultValue;
|
||||
ArrayUtilities.grow(this.window, this.window.length * 2, this.defaultValue);
|
||||
}
|
||||
}
|
||||
|
||||
public absoluteIndex(): number {
|
||||
return this.windowAbsoluteStartIndex + this.currentRelativeItemIndex;
|
||||
}
|
||||
|
||||
public isAtEndOfSource(): boolean {
|
||||
return this.absoluteIndex() >= this.sourceLength;
|
||||
}
|
||||
|
||||
public getAndPinAbsoluteIndex(): number {
|
||||
// Find the absolute index of this pin point. i.e. it's the index as if we had an
|
||||
// array containing *all* tokens.
|
||||
var absoluteIndex = this.absoluteIndex();
|
||||
var pinCount = this._pinCount++;
|
||||
if (pinCount === 0) {
|
||||
// If this is the first pinned point, then store off this index. We will ensure that
|
||||
// we never shift the window past this point.
|
||||
this.firstPinnedAbsoluteIndex = absoluteIndex;
|
||||
}
|
||||
|
||||
return absoluteIndex;
|
||||
}
|
||||
|
||||
public releaseAndUnpinAbsoluteIndex(absoluteIndex: number) {
|
||||
this._pinCount--;
|
||||
if (this._pinCount === 0) {
|
||||
// If we just released the last outstanding pin, then we no longer need to 'fix' the
|
||||
// token window so it can't move forward. Set the index to -1 so that we can shift
|
||||
// things over the next time we read past the end of the array.
|
||||
this.firstPinnedAbsoluteIndex = -1;
|
||||
}
|
||||
}
|
||||
|
||||
public rewindToPinnedIndex(absoluteIndex: number): void {
|
||||
// The rewind point shows which absolute item we want to rewind to. Get the relative
|
||||
// index in the actual array that we want to point to.
|
||||
var relativeIndex = absoluteIndex - this.windowAbsoluteStartIndex;
|
||||
|
||||
// Make sure we haven't screwed anything up.
|
||||
// Debug.assert(relativeIndex >= 0 && relativeIndex < this.windowCount);
|
||||
|
||||
// Set ourselves back to that point.
|
||||
this.currentRelativeItemIndex = relativeIndex;
|
||||
}
|
||||
|
||||
public currentItem(argument: any): any {
|
||||
if (this.currentRelativeItemIndex >= this.windowCount) {
|
||||
if (!this.addMoreItemsToWindow(argument)) {
|
||||
return this.defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
return this.window[this.currentRelativeItemIndex];
|
||||
}
|
||||
|
||||
public peekItemN(n: number): any {
|
||||
// Assert disabled because it is actually expensive enugh to affect perf.
|
||||
// Debug.assert(n >= 0);
|
||||
while (this.currentRelativeItemIndex + n >= this.windowCount) {
|
||||
if (!this.addMoreItemsToWindow(/*argument:*/ null)) {
|
||||
return this.defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
return this.window[this.currentRelativeItemIndex + n];
|
||||
}
|
||||
|
||||
public moveToNextItem(): void {
|
||||
this.currentRelativeItemIndex++;
|
||||
}
|
||||
|
||||
public disgardAllItemsFromCurrentIndexOnwards(): void {
|
||||
// By setting the window count to the current relative offset, we are effectively making
|
||||
// any items we added to the window from the current offset onwards unusable. When we
|
||||
// try to get the next item, we'll be forced to refetch them from the underlying source.
|
||||
this.windowCount = this.currentRelativeItemIndex;
|
||||
}
|
||||
|
||||
public setAbsoluteIndex(absoluteIndex: number): void {
|
||||
if (this.absoluteIndex() === absoluteIndex) {
|
||||
// Nothing to do if we're setting hte absolute index to where we current are.
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._pinCount > 0) {
|
||||
// If we have any active pins, then the caller better be setting the index somewhere
|
||||
// inside our active window.
|
||||
// Debug.assert(absoluteIndex >= this.windowAbsoluteStartIndex && absoluteIndex < this.windowAbsoluteEndIndex());
|
||||
}
|
||||
|
||||
if (absoluteIndex >= this.windowAbsoluteStartIndex && absoluteIndex < this.windowAbsoluteEndIndex()) {
|
||||
// The caller is setting the index to some place inside our current window. This is
|
||||
// easy to handle (and should be the common case).
|
||||
this.currentRelativeItemIndex = (absoluteIndex - this.windowAbsoluteStartIndex);
|
||||
}
|
||||
else {
|
||||
// The caller is setting the index to a place not in the window. Just throw away
|
||||
// everything we've got.
|
||||
|
||||
// First, set the window start to that index.
|
||||
this.windowAbsoluteStartIndex = absoluteIndex;
|
||||
|
||||
// Now, set the count to 0. So we'll be forced to fetch more items.
|
||||
this.windowCount = 0;
|
||||
|
||||
// And set us back to the start of the window.
|
||||
this.currentRelativeItemIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public pinCount(): number {
|
||||
return this._pinCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// Localizable string constants. TODO: Figure out a way to actually localize things.
|
||||
|
||||
module TypeScript {
|
||||
//export class Strings {
|
||||
// public static module__class__interface__enum__import_or_statement: string = "module, class, interface, enum, import or statement";
|
||||
// public static constructor__function__accessor_or_variable: string = "constructor, function, accessor or variable";
|
||||
// public static statement: string = "statement";
|
||||
// public static case_or_default_clause: string = "case or default clause";
|
||||
// public static identifier: string = "identifier";
|
||||
// public static call__construct__index__property_or_function_signature: string = "call, construct, index, property or function signature";
|
||||
// public static expression: string = "expression";
|
||||
// public static type_name: string = "type name";
|
||||
// public static property_or_accessor: string = "property or accessor";
|
||||
// public static parameter: string = "parameter";
|
||||
// public static type: string = "type";
|
||||
// public static type_parameter: string = "type parameter";
|
||||
//}
|
||||
}
|
||||
@@ -0,0 +1,510 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript.Syntax {
|
||||
export function emptySourceUnit() {
|
||||
return Syntax.normalModeFactory.sourceUnit(Syntax.emptyList, Syntax.token(SyntaxKind.EndOfFileToken, { text: "" }));
|
||||
}
|
||||
|
||||
export function getStandaloneExpression(positionedToken: PositionedToken): PositionedNodeOrToken {
|
||||
var token = positionedToken.token();
|
||||
if (positionedToken !== null && positionedToken.kind() === SyntaxKind.IdentifierName) {
|
||||
var parentPositionedNode = positionedToken.containingNode();
|
||||
var parentNode = parentPositionedNode.node();
|
||||
|
||||
if (parentNode.kind() === SyntaxKind.QualifiedName && (<QualifiedNameSyntax>parentNode).right === token) {
|
||||
return parentPositionedNode;
|
||||
}
|
||||
else if (parentNode.kind() === SyntaxKind.MemberAccessExpression && (<MemberAccessExpressionSyntax>parentNode).name === token) {
|
||||
return parentPositionedNode;
|
||||
}
|
||||
}
|
||||
|
||||
return positionedToken;
|
||||
}
|
||||
|
||||
export function isInModuleOrTypeContext(positionedToken: PositionedToken): boolean {
|
||||
if (positionedToken !== null) {
|
||||
var positionedNodeOrToken = Syntax.getStandaloneExpression(positionedToken);
|
||||
var parent = positionedNodeOrToken.containingNode();
|
||||
|
||||
if (parent !== null) {
|
||||
switch (parent.kind()) {
|
||||
case SyntaxKind.ModuleNameModuleReference:
|
||||
return true;
|
||||
case SyntaxKind.QualifiedName:
|
||||
// left of QN is namespace or type. Note: when you have "a.b.c()", then
|
||||
// "a.b" is not a qualified name, it is a member access expression.
|
||||
// Qualified names are only parsed when the parser knows it's a type only
|
||||
// context.
|
||||
return true;
|
||||
default:
|
||||
return isInTypeOnlyContext(positionedToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export function isInTypeOnlyContext(positionedToken: PositionedToken): boolean {
|
||||
var positionedNodeOrToken = Syntax.getStandaloneExpression(positionedToken);
|
||||
var positionedParent = positionedNodeOrToken.containingNode();
|
||||
|
||||
var parent = positionedParent.node();
|
||||
var nodeOrToken = positionedNodeOrToken.nodeOrToken();
|
||||
|
||||
if (parent !== null) {
|
||||
switch (parent.kind()) {
|
||||
case SyntaxKind.ArrayType:
|
||||
return (<ArrayTypeSyntax>parent).type === nodeOrToken;
|
||||
case SyntaxKind.CastExpression:
|
||||
return (<CastExpressionSyntax>parent).type === nodeOrToken;
|
||||
case SyntaxKind.TypeAnnotation:
|
||||
case SyntaxKind.ExtendsHeritageClause:
|
||||
case SyntaxKind.ImplementsHeritageClause:
|
||||
case SyntaxKind.TypeArgumentList:
|
||||
return true;
|
||||
// TODO: add more cases if necessary. This list may not be complete.
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export function childOffset(parent: ISyntaxElement, child: ISyntaxElement) {
|
||||
var offset = 0;
|
||||
for (var i = 0, n = parent.childCount(); i < n; i++) {
|
||||
var current = parent.childAt(i);
|
||||
if (current === child) {
|
||||
return offset;
|
||||
}
|
||||
|
||||
if (current !== null) {
|
||||
offset += current.fullWidth();
|
||||
}
|
||||
}
|
||||
|
||||
throw Errors.invalidOperation();
|
||||
}
|
||||
|
||||
export function childOffsetAt(parent: ISyntaxElement, index: number) {
|
||||
var offset = 0;
|
||||
for (var i = 0; i < index; i++) {
|
||||
var current = parent.childAt(i);
|
||||
if (current !== null) {
|
||||
offset += current.fullWidth();
|
||||
}
|
||||
}
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
||||
export function childIndex(parent: ISyntaxElement, child: ISyntaxElement) {
|
||||
for (var i = 0, n = parent.childCount(); i < n; i++) {
|
||||
var current = parent.childAt(i);
|
||||
if (current === child) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
throw Errors.invalidOperation();
|
||||
}
|
||||
|
||||
export function nodeStructuralEquals(node1: SyntaxNode, node2: SyntaxNode): boolean {
|
||||
if (node1 === null) {
|
||||
return node2 === null;
|
||||
}
|
||||
|
||||
return node1.structuralEquals(node2);
|
||||
}
|
||||
|
||||
export function nodeOrTokenStructuralEquals(node1: ISyntaxNodeOrToken, node2: ISyntaxNodeOrToken): boolean {
|
||||
if (node1 === node2) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (node1 === null || node2 === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (node1.isToken()) {
|
||||
return node2.isToken() ? tokenStructuralEquals(<ISyntaxToken>node1, <ISyntaxToken>node2) : false;
|
||||
}
|
||||
|
||||
return node2.isNode() ? nodeStructuralEquals(<SyntaxNode>node1, <SyntaxNode>node2) : false;
|
||||
}
|
||||
|
||||
export function tokenStructuralEquals(token1: ISyntaxToken, token2: ISyntaxToken): boolean {
|
||||
if (token1 === token2) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (token1 === null || token2 === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return token1.kind() === token2.kind() &&
|
||||
token1.width() === token2.width() &&
|
||||
token1.fullWidth() === token2.fullWidth() &&
|
||||
token1.text() === token2.text() &&
|
||||
Syntax.triviaListStructuralEquals(token1.leadingTrivia(), token2.leadingTrivia()) &&
|
||||
Syntax.triviaListStructuralEquals(token1.trailingTrivia(), token2.trailingTrivia());
|
||||
}
|
||||
|
||||
export function triviaListStructuralEquals(triviaList1: ISyntaxTriviaList, triviaList2: ISyntaxTriviaList): boolean {
|
||||
if (triviaList1.count() !== triviaList2.count()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (var i = 0, n = triviaList1.count(); i < n; i++) {
|
||||
if (!Syntax.triviaStructuralEquals(triviaList1.syntaxTriviaAt(i), triviaList2.syntaxTriviaAt(i))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
export function triviaStructuralEquals(trivia1: ISyntaxTrivia, trivia2: ISyntaxTrivia): boolean {
|
||||
return trivia1.kind() === trivia2.kind() &&
|
||||
trivia1.fullWidth() === trivia2.fullWidth() &&
|
||||
trivia1.fullText() === trivia2.fullText();
|
||||
}
|
||||
|
||||
export function listStructuralEquals(list1: ISyntaxList, list2: ISyntaxList): boolean {
|
||||
if (list1.childCount() !== list2.childCount()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (var i = 0, n = list1.childCount(); i < n; i++) {
|
||||
var child1 = list1.childAt(i);
|
||||
var child2 = list2.childAt(i);
|
||||
|
||||
if (!Syntax.nodeOrTokenStructuralEquals(<any>child1, <any>child2)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
export function separatedListStructuralEquals(list1: ISeparatedSyntaxList, list2: ISeparatedSyntaxList): boolean {
|
||||
if (list1.childCount() !== list2.childCount()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (var i = 0, n = list1.childCount(); i < n; i++) {
|
||||
var element1 = list1.childAt(i);
|
||||
var element2 = list2.childAt(i);
|
||||
if (!Syntax.nodeOrTokenStructuralEquals(<any>element1, <any>element2)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
export function elementStructuralEquals(element1: ISyntaxElement, element2: ISyntaxElement) {
|
||||
if (element1 === element2) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (element1 === null || element2 === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (element2.kind() !== element2.kind()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (element1.isToken()) {
|
||||
return tokenStructuralEquals(<ISyntaxToken>element1, <ISyntaxToken>element2);
|
||||
}
|
||||
else if (element1.isNode()) {
|
||||
return nodeStructuralEquals(<SyntaxNode>element1, <SyntaxNode>element2) ;
|
||||
}
|
||||
else if (element1.isList()) {
|
||||
return listStructuralEquals(<ISyntaxList>element1, <ISyntaxList>element2);
|
||||
}
|
||||
else if (element1.isSeparatedList()) {
|
||||
return separatedListStructuralEquals(<ISeparatedSyntaxList>element1, <ISeparatedSyntaxList>element2);
|
||||
}
|
||||
|
||||
throw Errors.invalidOperation();
|
||||
}
|
||||
|
||||
export function identifierName(text: string, info: ITokenInfo = null): ISyntaxToken {
|
||||
return identifier(text);
|
||||
}
|
||||
|
||||
export function trueExpression(): IUnaryExpressionSyntax {
|
||||
return Syntax.token(SyntaxKind.TrueKeyword);
|
||||
}
|
||||
|
||||
export function falseExpression(): IUnaryExpressionSyntax {
|
||||
return Syntax.token(SyntaxKind.FalseKeyword);
|
||||
}
|
||||
|
||||
export function numericLiteralExpression(text: string): IUnaryExpressionSyntax {
|
||||
return Syntax.token(SyntaxKind.NumericLiteral, { text: text });
|
||||
}
|
||||
|
||||
export function stringLiteralExpression(text: string): IUnaryExpressionSyntax {
|
||||
return Syntax.token(SyntaxKind.StringLiteral, { text: text });
|
||||
}
|
||||
|
||||
export function isSuperInvocationExpression(node: IExpressionSyntax): boolean {
|
||||
return node.kind() === SyntaxKind.InvocationExpression &&
|
||||
(<InvocationExpressionSyntax>node).expression.kind() === SyntaxKind.SuperKeyword;
|
||||
}
|
||||
|
||||
export function isSuperInvocationExpressionStatement(node: SyntaxNode): boolean {
|
||||
return node.kind() === SyntaxKind.ExpressionStatement &&
|
||||
isSuperInvocationExpression((<ExpressionStatementSyntax>node).expression);
|
||||
}
|
||||
|
||||
export function isSuperMemberAccessExpression(node: IExpressionSyntax): boolean {
|
||||
return node.kind() === SyntaxKind.MemberAccessExpression &&
|
||||
(<MemberAccessExpressionSyntax>node).expression.kind() === SyntaxKind.SuperKeyword;
|
||||
}
|
||||
|
||||
export function isSuperMemberAccessInvocationExpression(node: SyntaxNode): boolean {
|
||||
return node.kind() === SyntaxKind.InvocationExpression &&
|
||||
isSuperMemberAccessExpression((<InvocationExpressionSyntax>node).expression);
|
||||
}
|
||||
|
||||
export function assignmentExpression(left: IExpressionSyntax, token: ISyntaxToken, right: IExpressionSyntax): BinaryExpressionSyntax {
|
||||
return Syntax.normalModeFactory.binaryExpression(SyntaxKind.AssignmentExpression, left, token, right);
|
||||
}
|
||||
|
||||
export function nodeHasSkippedOrMissingTokens(node: SyntaxNode): boolean {
|
||||
for (var i = 0; i < node.childCount(); i++) {
|
||||
var child = node.childAt(i);
|
||||
if (child !== null && child.isToken()) {
|
||||
var token = <ISyntaxToken>child;
|
||||
// If a token is skipped, return true. Or if it is a missing token. The only empty token that is not missing is EOF
|
||||
if (token.hasSkippedToken() || (token.width() === 0 && token.kind() !== SyntaxKind.EndOfFileToken)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function isUnterminatedStringLiteral(token: ISyntaxToken): boolean {
|
||||
if (token && token.kind() === SyntaxKind.StringLiteral) {
|
||||
var text = token.text();
|
||||
return text.length < 2 || text.charCodeAt(text.length - 1) !== text.charCodeAt(0);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export function isUnterminatedMultilineCommentTrivia(trivia: ISyntaxTrivia): boolean {
|
||||
if (trivia && trivia.kind() === SyntaxKind.MultiLineCommentTrivia) {
|
||||
var text = trivia.fullText();
|
||||
return text.length < 4 || text.substring(text.length - 2) !== "*/";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function isEntirelyInsideCommentTrivia(trivia: ISyntaxTrivia, fullStart: number, position: number): boolean {
|
||||
if (trivia && trivia.isComment() && position > fullStart) {
|
||||
var end = fullStart + trivia.fullWidth();
|
||||
if (position < end) {
|
||||
return true;
|
||||
}
|
||||
else if (position === end) {
|
||||
return trivia.kind() === SyntaxKind.SingleLineCommentTrivia || isUnterminatedMultilineCommentTrivia(trivia);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export function isEntirelyInsideComment(sourceUnit: SourceUnitSyntax, position: number): boolean {
|
||||
var positionedToken = sourceUnit.findToken(position);
|
||||
var fullStart = positionedToken.fullStart();
|
||||
var triviaList: ISyntaxTriviaList = null;
|
||||
var lastTriviaBeforeToken: ISyntaxTrivia = null;
|
||||
|
||||
if (positionedToken.kind() === SyntaxKind.EndOfFileToken) {
|
||||
// Check if the trivia is leading on the EndOfFile token
|
||||
if (positionedToken.token().hasLeadingTrivia()) {
|
||||
triviaList = positionedToken.token().leadingTrivia();
|
||||
}
|
||||
// Or trailing on the previous token
|
||||
else {
|
||||
positionedToken = positionedToken.previousToken();
|
||||
if (positionedToken) {
|
||||
if (positionedToken && positionedToken.token().hasTrailingTrivia()) {
|
||||
triviaList = positionedToken.token().trailingTrivia();
|
||||
fullStart = positionedToken.end();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (position <= (fullStart + positionedToken.token().leadingTriviaWidth())) {
|
||||
triviaList = positionedToken.token().leadingTrivia();
|
||||
}
|
||||
else if (position >= (fullStart + positionedToken.token().width())) {
|
||||
triviaList = positionedToken.token().trailingTrivia();
|
||||
fullStart = positionedToken.end();
|
||||
}
|
||||
}
|
||||
|
||||
if (triviaList) {
|
||||
// Try to find the trivia matching the position
|
||||
for (var i = 0, n = triviaList.count(); i < n; i++) {
|
||||
var trivia = triviaList.syntaxTriviaAt(i);
|
||||
if (position <= fullStart) {
|
||||
// Moved passed the trivia we need
|
||||
break;
|
||||
}
|
||||
else if (position <= fullStart + trivia.fullWidth() && trivia.isComment()) {
|
||||
// Found the comment trivia we were looking for
|
||||
lastTriviaBeforeToken = trivia;
|
||||
break;
|
||||
}
|
||||
|
||||
fullStart += trivia.fullWidth();
|
||||
}
|
||||
}
|
||||
|
||||
return lastTriviaBeforeToken && isEntirelyInsideCommentTrivia(lastTriviaBeforeToken, fullStart, position);
|
||||
}
|
||||
|
||||
export function isEntirelyInStringOrRegularExpressionLiteral(sourceUnit: SourceUnitSyntax, position: number): boolean {
|
||||
var positionedToken = sourceUnit.findToken(position);
|
||||
|
||||
if (positionedToken) {
|
||||
if (positionedToken.kind() === SyntaxKind.EndOfFileToken) {
|
||||
// EndOfFile token, enusre it did not follow an unterminated string literal
|
||||
positionedToken = positionedToken.previousToken();
|
||||
return positionedToken && positionedToken.token().trailingTriviaWidth() === 0 && isUnterminatedStringLiteral(positionedToken.token());
|
||||
}
|
||||
else if (position > positionedToken.start()) {
|
||||
// Ensure position falls enterily within the literal if it is terminated, or the line if it is not
|
||||
return (position < positionedToken.end() && (positionedToken.kind() === TypeScript.SyntaxKind.StringLiteral || positionedToken.kind() === TypeScript.SyntaxKind.RegularExpressionLiteral)) ||
|
||||
(position <= positionedToken.end() && isUnterminatedStringLiteral(positionedToken.token()));
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function findSkippedTokenInTriviaList(positionedToken: PositionedToken, position: number, lookInLeadingTriviaList: boolean): PositionedSkippedToken {
|
||||
var triviaList: TypeScript.ISyntaxTriviaList = null;
|
||||
var fullStart: number;
|
||||
|
||||
if (lookInLeadingTriviaList) {
|
||||
triviaList = positionedToken.token().leadingTrivia();
|
||||
fullStart = positionedToken.fullStart();
|
||||
}
|
||||
else {
|
||||
triviaList = positionedToken.token().trailingTrivia();
|
||||
fullStart = positionedToken.end();
|
||||
}
|
||||
|
||||
if (triviaList && triviaList.hasSkippedToken()) {
|
||||
for (var i = 0, n = triviaList.count(); i < n; i++) {
|
||||
var trivia = triviaList.syntaxTriviaAt(i);
|
||||
var triviaWidth = trivia.fullWidth();
|
||||
|
||||
if (trivia.isSkippedToken() && position >= fullStart && position <= fullStart + triviaWidth) {
|
||||
return new PositionedSkippedToken(positionedToken, trivia.skippedToken(), fullStart);
|
||||
}
|
||||
|
||||
fullStart += triviaWidth;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function findSkippedTokenOnLeftInTriviaList(positionedToken: PositionedToken, position: number, lookInLeadingTriviaList: boolean): PositionedSkippedToken {
|
||||
var triviaList: TypeScript.ISyntaxTriviaList = null;
|
||||
var fullEnd: number;
|
||||
|
||||
if (lookInLeadingTriviaList) {
|
||||
triviaList = positionedToken.token().leadingTrivia();
|
||||
fullEnd = positionedToken.fullStart() + triviaList.fullWidth();
|
||||
}
|
||||
else {
|
||||
triviaList = positionedToken.token().trailingTrivia();
|
||||
fullEnd = positionedToken.fullEnd();
|
||||
}
|
||||
|
||||
if (triviaList && triviaList.hasSkippedToken()) {
|
||||
for (var i = triviaList.count() - 1; i >= 0; i--) {
|
||||
var trivia = triviaList.syntaxTriviaAt(i);
|
||||
var triviaWidth = trivia.fullWidth();
|
||||
|
||||
if (trivia.isSkippedToken() && position >= fullEnd) {
|
||||
return new PositionedSkippedToken(positionedToken, trivia.skippedToken(), fullEnd - triviaWidth);
|
||||
}
|
||||
|
||||
fullEnd -= triviaWidth;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function findSkippedTokenInLeadingTriviaList(positionedToken: PositionedToken, position: number): PositionedSkippedToken {
|
||||
return findSkippedTokenInTriviaList(positionedToken, position, /*lookInLeadingTriviaList*/ true);
|
||||
}
|
||||
|
||||
export function findSkippedTokenInTrailingTriviaList(positionedToken: PositionedToken, position: number): PositionedSkippedToken {
|
||||
return findSkippedTokenInTriviaList(positionedToken, position, /*lookInLeadingTriviaList*/ false);
|
||||
}
|
||||
|
||||
export function findSkippedTokenInPositionedToken(positionedToken: PositionedToken, position: number): PositionedSkippedToken {
|
||||
var positionInLeadingTriviaList = (position < positionedToken.start());
|
||||
return findSkippedTokenInTriviaList(positionedToken, position, /*lookInLeadingTriviaList*/ positionInLeadingTriviaList);
|
||||
}
|
||||
|
||||
export function findSkippedTokenOnLeft(positionedToken: PositionedToken, position: number): PositionedSkippedToken {
|
||||
var positionInLeadingTriviaList = (position < positionedToken.start());
|
||||
return findSkippedTokenOnLeftInTriviaList(positionedToken, position, /*lookInLeadingTriviaList*/ positionInLeadingTriviaList);
|
||||
}
|
||||
|
||||
export function getAncestorOfKind(positionedToken: PositionedElement, kind: SyntaxKind): PositionedElement {
|
||||
while (positionedToken && positionedToken.parent()) {
|
||||
if (positionedToken.parent().kind() === kind) {
|
||||
return positionedToken.parent();
|
||||
}
|
||||
|
||||
positionedToken = positionedToken.parent();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function hasAncestorOfKind(positionedToken: PositionedElement, kind: SyntaxKind): boolean {
|
||||
return Syntax.getAncestorOfKind(positionedToken, kind) !== null;
|
||||
}
|
||||
|
||||
export function isIntegerLiteral(expression: IExpressionSyntax): boolean {
|
||||
if (expression) {
|
||||
switch (expression.kind()) {
|
||||
case SyntaxKind.PlusExpression:
|
||||
case SyntaxKind.NegateExpression:
|
||||
// Note: if there is a + or - sign, we can only allow a normal integer following
|
||||
// (and not a hex integer). i.e. -0xA is a legal expression, but it is not a
|
||||
// *literal*.
|
||||
expression = (<PrefixUnaryExpressionSyntax>expression).operand;
|
||||
return expression.isToken() && IntegerUtilities.isInteger((<ISyntaxToken>expression).text());
|
||||
|
||||
case SyntaxKind.NumericLiteral:
|
||||
// If it doesn't have a + or -, then either an integer literal or a hex literal
|
||||
// is acceptable.
|
||||
var text = (<ISyntaxToken> expression).text();
|
||||
return IntegerUtilities.isInteger(text) || IntegerUtilities.isHexInteger(text);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export class SyntaxDedenter extends SyntaxRewriter {
|
||||
private lastTriviaWasNewLine: boolean;
|
||||
|
||||
constructor(dedentFirstToken: boolean,
|
||||
private dedentationAmount: number,
|
||||
private minimumIndent: number,
|
||||
private options: FormattingOptions) {
|
||||
super();
|
||||
this.lastTriviaWasNewLine = dedentFirstToken;
|
||||
}
|
||||
|
||||
private abort(): void {
|
||||
this.lastTriviaWasNewLine = false;
|
||||
this.dedentationAmount = 0;
|
||||
}
|
||||
|
||||
private isAborted(): boolean {
|
||||
return this.dedentationAmount === 0;
|
||||
}
|
||||
|
||||
public visitToken(token: ISyntaxToken): ISyntaxToken {
|
||||
if (token.width() === 0) {
|
||||
return token;
|
||||
}
|
||||
|
||||
var result = token;
|
||||
if (this.lastTriviaWasNewLine) {
|
||||
// have to add our indentation to every line that this token hits.
|
||||
result = token.withLeadingTrivia(this.dedentTriviaList(token.leadingTrivia()));
|
||||
}
|
||||
|
||||
if (this.isAborted()) {
|
||||
// If we've decided to stop dedenting. Then just return immediately.
|
||||
return token;
|
||||
}
|
||||
|
||||
this.lastTriviaWasNewLine = token.hasTrailingNewLine();
|
||||
return result;
|
||||
}
|
||||
|
||||
private dedentTriviaList(triviaList: ISyntaxTriviaList): ISyntaxTriviaList {
|
||||
var result: ISyntaxTrivia[] = [];
|
||||
var dedentNextWhitespace = true;
|
||||
|
||||
// Keep walking through all our trivia (as long as we haven't decided to stop dedenting).
|
||||
// Adjust the indentation on any whitespace trivia at the start of a line, or any multi-line
|
||||
// trivia that span multiple lines.
|
||||
for (var i = 0, n = triviaList.count(); i < n && !this.isAborted(); i++) {
|
||||
var trivia = triviaList.syntaxTriviaAt(i);
|
||||
|
||||
var dedentThisTrivia = dedentNextWhitespace;
|
||||
dedentNextWhitespace = false;
|
||||
|
||||
if (dedentThisTrivia) {
|
||||
if (trivia.kind() === SyntaxKind.WhitespaceTrivia) {
|
||||
// We pass in if there was a following newline after this whitespace. If there
|
||||
// is, then it's fine if we dedent this newline all the way to 0. Otherwise,
|
||||
// if the whitespace is followed by something, then we need to determine how
|
||||
// much of the whitespace we can remove. If we can't remove all that we want,
|
||||
// we'll need to adjust the dedentAmount. And, if we can't remove at all, then
|
||||
// we need to stop dedenting entirely.
|
||||
var hasFollowingNewLine = (i < triviaList.count() - 1) &&
|
||||
triviaList.syntaxTriviaAt(i + 1).kind() === SyntaxKind.NewLineTrivia;
|
||||
result.push(this.dedentWhitespace(trivia, hasFollowingNewLine));
|
||||
continue;
|
||||
}
|
||||
else if (trivia.kind() !== SyntaxKind.NewLineTrivia) {
|
||||
// We wanted to dedent, but the trivia we're on isn't whitespace and wasn't a
|
||||
// newline. That means that we have something like a comment at the beginning
|
||||
// of the line that we can't dedent. And, if we can't dedent it, then we
|
||||
// shouldn't dedent this token or any more tokens.
|
||||
this.abort();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (trivia.kind() === SyntaxKind.MultiLineCommentTrivia) {
|
||||
// This trivia may span multiple lines. If it does, we need to dedent each
|
||||
// successive line of it until it terminates.
|
||||
result.push(this.dedentMultiLineComment(trivia));
|
||||
continue;
|
||||
}
|
||||
|
||||
// All other trivia we just append to the list.
|
||||
result.push(trivia);
|
||||
if (trivia.kind() === SyntaxKind.NewLineTrivia) {
|
||||
// We hit a newline processing the trivia. We need to add the indentation to the
|
||||
// next line as well.
|
||||
dedentNextWhitespace = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (dedentNextWhitespace) {
|
||||
// We hit a new line as the last trivia (or there was no trivia). We want to dedent
|
||||
// the next trivia, but we can't (because the token starts at the start of the line).
|
||||
// If we can't dedent this, then we shouldn't dedent anymore.
|
||||
this.abort();
|
||||
}
|
||||
|
||||
if (this.isAborted()) {
|
||||
return triviaList;
|
||||
}
|
||||
|
||||
return Syntax.triviaList(result);
|
||||
}
|
||||
|
||||
private dedentSegment(segment: string, hasFollowingNewLineTrivia: boolean): string {
|
||||
// Find the position of the first non whitespace character in the segment.
|
||||
var firstNonWhitespacePosition = Indentation.firstNonWhitespacePosition(segment);
|
||||
|
||||
if (firstNonWhitespacePosition === segment.length) {
|
||||
if (hasFollowingNewLineTrivia) {
|
||||
// It was entirely whitespace trivia, with a newline after it. Just trim this down
|
||||
// to an empty string.
|
||||
return "";
|
||||
}
|
||||
}
|
||||
else if (CharacterInfo.isLineTerminator(segment.charCodeAt(firstNonWhitespacePosition))) {
|
||||
// It was entirely whitespace, with a newline after it. Just trim this down to
|
||||
// the newline
|
||||
return segment.substring(firstNonWhitespacePosition);
|
||||
}
|
||||
|
||||
// It was whitespace without a newline following it. We need to try to dedent this a bit.
|
||||
|
||||
// Convert that position to a column.
|
||||
var firstNonWhitespaceColumn = Indentation.columnForPositionInString(segment, firstNonWhitespacePosition, this.options);
|
||||
|
||||
// Find the new column we want the nonwhitespace text to start at. Ideally it would be
|
||||
// whatever column it was minus the dedentation amount. However, we won't go below a
|
||||
// specified minimum indent (hence, max(initial - dedentAmount, minIndent). *But* if
|
||||
// the initial column was less than that minimum indent, then we'll keep it at that column.
|
||||
// (hence min(initial, desired)).
|
||||
var newFirstNonWhitespaceColumn =
|
||||
MathPrototype.min(firstNonWhitespaceColumn,
|
||||
MathPrototype.max(firstNonWhitespaceColumn - this.dedentationAmount, this.minimumIndent));
|
||||
|
||||
if (newFirstNonWhitespaceColumn === firstNonWhitespaceColumn) {
|
||||
// We aren't able to detent this token. Abort what we're doing
|
||||
this.abort();
|
||||
return segment;
|
||||
}
|
||||
|
||||
// Update the dedentation amount for all subsequent tokens we run into.
|
||||
this.dedentationAmount = firstNonWhitespaceColumn - newFirstNonWhitespaceColumn;
|
||||
Debug.assert(this.dedentationAmount >= 0);
|
||||
|
||||
// Compute an indentation string for that.
|
||||
var indentationString = Indentation.indentationString(newFirstNonWhitespaceColumn, this.options);
|
||||
|
||||
// Join the new indentation and the original string without its indentation.
|
||||
return indentationString + segment.substring(firstNonWhitespacePosition);
|
||||
}
|
||||
|
||||
private dedentWhitespace(trivia: ISyntaxTrivia, hasFollowingNewLineTrivia: boolean): ISyntaxTrivia {
|
||||
var newIndentation = this.dedentSegment(trivia.fullText(), hasFollowingNewLineTrivia);
|
||||
return Syntax.whitespace(newIndentation);
|
||||
}
|
||||
|
||||
private dedentMultiLineComment(trivia: ISyntaxTrivia): ISyntaxTrivia {
|
||||
var segments = Syntax.splitMultiLineCommentTriviaIntoMultipleLines(trivia);
|
||||
if (segments.length === 1) {
|
||||
// If there was only one segment, then this wasn't multiline.
|
||||
return trivia;
|
||||
}
|
||||
|
||||
for (var i = 1; i < segments.length; i++) {
|
||||
var segment = segments[i];
|
||||
segments[i] = this.dedentSegment(segment, /*hasFollowingNewLineTrivia*/ false);
|
||||
}
|
||||
|
||||
var result = segments.join("");
|
||||
|
||||
// Create a new trivia token out of the indented lines.
|
||||
return Syntax.multiLineComment(result);
|
||||
}
|
||||
|
||||
public static dedentNode(node: ISyntaxNode, dedentFirstToken: boolean, dedentAmount: number, minimumIndent: number, options: FormattingOptions): ISyntaxNode {
|
||||
var dedenter = new SyntaxDedenter(dedentFirstToken, dedentAmount, minimumIndent, options);
|
||||
var result = node.accept(dedenter);
|
||||
|
||||
if (dedenter.isAborted()) {
|
||||
// We failed to dedent a token in this node. Return the original node as is.
|
||||
return node;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export interface ISyntaxElement {
|
||||
kind(): SyntaxKind;
|
||||
|
||||
isNode(): boolean;
|
||||
isToken(): boolean;
|
||||
isList(): boolean;
|
||||
isSeparatedList(): boolean;
|
||||
|
||||
childCount(): number;
|
||||
childAt(index: number): ISyntaxElement;
|
||||
|
||||
// True if this element is typescript specific and would not be legal in pure javascript.
|
||||
isTypeScriptSpecific(): boolean;
|
||||
|
||||
// True if this element cannot be reused in incremental parsing. There are several situations
|
||||
// in which an element can not be reused. They are:
|
||||
//
|
||||
// 1) The element contained skipped text.
|
||||
// 2) The element contained zero width tokens.
|
||||
// 3) The element contains tokens generated by the parser (like >> or a keyword -> identifier
|
||||
// conversion).
|
||||
// 4) The element contains a regex token somewhere under it. A regex token is either a
|
||||
// regex itself (i.e. /foo/), or is a token which could start a regex (i.e. "/" or "/="). This
|
||||
// data is used by the incremental parser to decide if a node can be reused. Due to the
|
||||
// lookahead nature of regex tokens, a node containing a regex token cannot be reused. Normally,
|
||||
// changes to text only affect the tokens directly intersected. However, because regex tokens
|
||||
// have such unbounded lookahead (technically bounded at the end of a line, but htat's minor),
|
||||
// we need to recheck them to see if they've changed due to the edit. For example, if you had:
|
||||
//
|
||||
// while (true) /3; return;
|
||||
//
|
||||
// And you changed it to:
|
||||
//
|
||||
// while (true) /3; return/;
|
||||
//
|
||||
// Then even though only the 'return' and ';' colons were touched, we'd want to rescan the '/'
|
||||
// token which we would then realize was a regex.
|
||||
isIncrementallyUnusable(): boolean;
|
||||
|
||||
// With of this element, including leading and trailing trivia.
|
||||
fullWidth(): number;
|
||||
|
||||
// Width of this element, not including leading and trailing trivia.
|
||||
width(): number;
|
||||
|
||||
// Text for this element, including leading and trailing trivia.
|
||||
fullText(): string;
|
||||
|
||||
leadingTrivia(): ISyntaxTriviaList;
|
||||
trailingTrivia(): ISyntaxTriviaList;
|
||||
|
||||
leadingTriviaWidth(): number;
|
||||
trailingTriviaWidth(): number;
|
||||
|
||||
firstToken(): ISyntaxToken;
|
||||
lastToken(): ISyntaxToken;
|
||||
|
||||
collectTextElements(elements: string[]): void;
|
||||
}
|
||||
|
||||
export interface ISyntaxNode extends ISyntaxNodeOrToken {
|
||||
}
|
||||
|
||||
export interface IModuleReferenceSyntax extends ISyntaxNode {
|
||||
isModuleReference(): boolean;
|
||||
}
|
||||
|
||||
export interface IModuleElementSyntax extends ISyntaxNode {
|
||||
}
|
||||
|
||||
export interface IStatementSyntax extends IModuleElementSyntax {
|
||||
isStatement(): boolean;
|
||||
}
|
||||
|
||||
export interface IIterationStatementSyntax extends IStatementSyntax {
|
||||
isIterationStatement(): boolean;
|
||||
}
|
||||
|
||||
export interface ITypeMemberSyntax extends ISyntaxNode {
|
||||
}
|
||||
|
||||
export interface IClassElementSyntax extends ISyntaxNode {
|
||||
}
|
||||
|
||||
export interface IMemberDeclarationSyntax extends IClassElementSyntax {
|
||||
}
|
||||
|
||||
export interface IPropertyAssignmentSyntax extends IClassElementSyntax {
|
||||
}
|
||||
|
||||
export interface ISwitchClauseSyntax extends ISyntaxNode {
|
||||
isSwitchClause(): boolean;
|
||||
statements: ISyntaxList;
|
||||
}
|
||||
|
||||
export interface IExpressionSyntax extends ISyntaxNodeOrToken {
|
||||
isExpression(): boolean;
|
||||
withLeadingTrivia(trivia: ISyntaxTriviaList): IExpressionSyntax;
|
||||
withTrailingTrivia(trivia: ISyntaxTriviaList): IExpressionSyntax;
|
||||
}
|
||||
|
||||
export interface IUnaryExpressionSyntax extends IExpressionSyntax {
|
||||
isUnaryExpression(): boolean;
|
||||
}
|
||||
|
||||
export interface IArrowFunctionExpressionSyntax extends IUnaryExpressionSyntax {
|
||||
isArrowFunctionExpression(): boolean;
|
||||
equalsGreaterThanToken: ISyntaxToken;
|
||||
block: BlockSyntax;
|
||||
expression: IExpressionSyntax;
|
||||
}
|
||||
|
||||
export interface IPostfixExpressionSyntax extends IUnaryExpressionSyntax {
|
||||
isPostfixExpression(): boolean;
|
||||
}
|
||||
|
||||
export interface IMemberExpressionSyntax extends IPostfixExpressionSyntax {
|
||||
isMemberExpression(): boolean;
|
||||
}
|
||||
|
||||
export interface IPrimaryExpressionSyntax extends IMemberExpressionSyntax {
|
||||
isPrimaryExpression(): boolean;
|
||||
}
|
||||
|
||||
export interface ITypeSyntax extends ISyntaxNodeOrToken {
|
||||
}
|
||||
|
||||
export interface INameSyntax extends ITypeSyntax {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,610 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript.Syntax {
|
||||
export interface IFactory {
|
||||
sourceUnit(moduleElements: ISyntaxList, endOfFileToken: ISyntaxToken): SourceUnitSyntax;
|
||||
externalModuleReference(requireKeyword: ISyntaxToken, openParenToken: ISyntaxToken, stringLiteral: ISyntaxToken, closeParenToken: ISyntaxToken): ExternalModuleReferenceSyntax;
|
||||
moduleNameModuleReference(moduleName: INameSyntax): ModuleNameModuleReferenceSyntax;
|
||||
importDeclaration(modifiers: ISyntaxList, importKeyword: ISyntaxToken, identifier: ISyntaxToken, equalsToken: ISyntaxToken, moduleReference: IModuleReferenceSyntax, semicolonToken: ISyntaxToken): ImportDeclarationSyntax;
|
||||
exportAssignment(exportKeyword: ISyntaxToken, equalsToken: ISyntaxToken, identifier: ISyntaxToken, semicolonToken: ISyntaxToken): ExportAssignmentSyntax;
|
||||
classDeclaration(modifiers: ISyntaxList, classKeyword: ISyntaxToken, identifier: ISyntaxToken, typeParameterList: TypeParameterListSyntax, heritageClauses: ISyntaxList, openBraceToken: ISyntaxToken, classElements: ISyntaxList, closeBraceToken: ISyntaxToken): ClassDeclarationSyntax;
|
||||
interfaceDeclaration(modifiers: ISyntaxList, interfaceKeyword: ISyntaxToken, identifier: ISyntaxToken, typeParameterList: TypeParameterListSyntax, heritageClauses: ISyntaxList, body: ObjectTypeSyntax): InterfaceDeclarationSyntax;
|
||||
heritageClause(kind: SyntaxKind, extendsOrImplementsKeyword: ISyntaxToken, typeNames: ISeparatedSyntaxList): HeritageClauseSyntax;
|
||||
moduleDeclaration(modifiers: ISyntaxList, moduleKeyword: ISyntaxToken, name: INameSyntax, stringLiteral: ISyntaxToken, openBraceToken: ISyntaxToken, moduleElements: ISyntaxList, closeBraceToken: ISyntaxToken): ModuleDeclarationSyntax;
|
||||
functionDeclaration(modifiers: ISyntaxList, functionKeyword: ISyntaxToken, identifier: ISyntaxToken, callSignature: CallSignatureSyntax, block: BlockSyntax, semicolonToken: ISyntaxToken): FunctionDeclarationSyntax;
|
||||
variableStatement(modifiers: ISyntaxList, variableDeclaration: VariableDeclarationSyntax, semicolonToken: ISyntaxToken): VariableStatementSyntax;
|
||||
variableDeclaration(varKeyword: ISyntaxToken, variableDeclarators: ISeparatedSyntaxList): VariableDeclarationSyntax;
|
||||
variableDeclarator(propertyName: ISyntaxToken, typeAnnotation: TypeAnnotationSyntax, equalsValueClause: EqualsValueClauseSyntax): VariableDeclaratorSyntax;
|
||||
equalsValueClause(equalsToken: ISyntaxToken, value: IExpressionSyntax): EqualsValueClauseSyntax;
|
||||
prefixUnaryExpression(kind: SyntaxKind, operatorToken: ISyntaxToken, operand: IUnaryExpressionSyntax): PrefixUnaryExpressionSyntax;
|
||||
arrayLiteralExpression(openBracketToken: ISyntaxToken, expressions: ISeparatedSyntaxList, closeBracketToken: ISyntaxToken): ArrayLiteralExpressionSyntax;
|
||||
omittedExpression(): OmittedExpressionSyntax;
|
||||
parenthesizedExpression(openParenToken: ISyntaxToken, expression: IExpressionSyntax, closeParenToken: ISyntaxToken): ParenthesizedExpressionSyntax;
|
||||
simpleArrowFunctionExpression(identifier: ISyntaxToken, equalsGreaterThanToken: ISyntaxToken, block: BlockSyntax, expression: IExpressionSyntax): SimpleArrowFunctionExpressionSyntax;
|
||||
parenthesizedArrowFunctionExpression(callSignature: CallSignatureSyntax, equalsGreaterThanToken: ISyntaxToken, block: BlockSyntax, expression: IExpressionSyntax): ParenthesizedArrowFunctionExpressionSyntax;
|
||||
qualifiedName(left: INameSyntax, dotToken: ISyntaxToken, right: ISyntaxToken): QualifiedNameSyntax;
|
||||
typeArgumentList(lessThanToken: ISyntaxToken, typeArguments: ISeparatedSyntaxList, greaterThanToken: ISyntaxToken): TypeArgumentListSyntax;
|
||||
constructorType(newKeyword: ISyntaxToken, typeParameterList: TypeParameterListSyntax, parameterList: ParameterListSyntax, equalsGreaterThanToken: ISyntaxToken, type: ITypeSyntax): ConstructorTypeSyntax;
|
||||
functionType(typeParameterList: TypeParameterListSyntax, parameterList: ParameterListSyntax, equalsGreaterThanToken: ISyntaxToken, type: ITypeSyntax): FunctionTypeSyntax;
|
||||
objectType(openBraceToken: ISyntaxToken, typeMembers: ISeparatedSyntaxList, closeBraceToken: ISyntaxToken): ObjectTypeSyntax;
|
||||
arrayType(type: ITypeSyntax, openBracketToken: ISyntaxToken, closeBracketToken: ISyntaxToken): ArrayTypeSyntax;
|
||||
genericType(name: INameSyntax, typeArgumentList: TypeArgumentListSyntax): GenericTypeSyntax;
|
||||
typeQuery(typeOfKeyword: ISyntaxToken, name: INameSyntax): TypeQuerySyntax;
|
||||
typeAnnotation(colonToken: ISyntaxToken, type: ITypeSyntax): TypeAnnotationSyntax;
|
||||
block(openBraceToken: ISyntaxToken, statements: ISyntaxList, closeBraceToken: ISyntaxToken): BlockSyntax;
|
||||
parameter(dotDotDotToken: ISyntaxToken, modifiers: ISyntaxList, identifier: ISyntaxToken, questionToken: ISyntaxToken, typeAnnotation: TypeAnnotationSyntax, equalsValueClause: EqualsValueClauseSyntax): ParameterSyntax;
|
||||
memberAccessExpression(expression: IExpressionSyntax, dotToken: ISyntaxToken, name: ISyntaxToken): MemberAccessExpressionSyntax;
|
||||
postfixUnaryExpression(kind: SyntaxKind, operand: IMemberExpressionSyntax, operatorToken: ISyntaxToken): PostfixUnaryExpressionSyntax;
|
||||
elementAccessExpression(expression: IExpressionSyntax, openBracketToken: ISyntaxToken, argumentExpression: IExpressionSyntax, closeBracketToken: ISyntaxToken): ElementAccessExpressionSyntax;
|
||||
invocationExpression(expression: IMemberExpressionSyntax, argumentList: ArgumentListSyntax): InvocationExpressionSyntax;
|
||||
argumentList(typeArgumentList: TypeArgumentListSyntax, openParenToken: ISyntaxToken, arguments: ISeparatedSyntaxList, closeParenToken: ISyntaxToken): ArgumentListSyntax;
|
||||
binaryExpression(kind: SyntaxKind, left: IExpressionSyntax, operatorToken: ISyntaxToken, right: IExpressionSyntax): BinaryExpressionSyntax;
|
||||
conditionalExpression(condition: IExpressionSyntax, questionToken: ISyntaxToken, whenTrue: IExpressionSyntax, colonToken: ISyntaxToken, whenFalse: IExpressionSyntax): ConditionalExpressionSyntax;
|
||||
constructSignature(newKeyword: ISyntaxToken, callSignature: CallSignatureSyntax): ConstructSignatureSyntax;
|
||||
methodSignature(propertyName: ISyntaxToken, questionToken: ISyntaxToken, callSignature: CallSignatureSyntax): MethodSignatureSyntax;
|
||||
indexSignature(openBracketToken: ISyntaxToken, parameter: ParameterSyntax, closeBracketToken: ISyntaxToken, typeAnnotation: TypeAnnotationSyntax): IndexSignatureSyntax;
|
||||
propertySignature(propertyName: ISyntaxToken, questionToken: ISyntaxToken, typeAnnotation: TypeAnnotationSyntax): PropertySignatureSyntax;
|
||||
callSignature(typeParameterList: TypeParameterListSyntax, parameterList: ParameterListSyntax, typeAnnotation: TypeAnnotationSyntax): CallSignatureSyntax;
|
||||
parameterList(openParenToken: ISyntaxToken, parameters: ISeparatedSyntaxList, closeParenToken: ISyntaxToken): ParameterListSyntax;
|
||||
typeParameterList(lessThanToken: ISyntaxToken, typeParameters: ISeparatedSyntaxList, greaterThanToken: ISyntaxToken): TypeParameterListSyntax;
|
||||
typeParameter(identifier: ISyntaxToken, constraint: ConstraintSyntax): TypeParameterSyntax;
|
||||
constraint(extendsKeyword: ISyntaxToken, type: ITypeSyntax): ConstraintSyntax;
|
||||
elseClause(elseKeyword: ISyntaxToken, statement: IStatementSyntax): ElseClauseSyntax;
|
||||
ifStatement(ifKeyword: ISyntaxToken, openParenToken: ISyntaxToken, condition: IExpressionSyntax, closeParenToken: ISyntaxToken, statement: IStatementSyntax, elseClause: ElseClauseSyntax): IfStatementSyntax;
|
||||
expressionStatement(expression: IExpressionSyntax, semicolonToken: ISyntaxToken): ExpressionStatementSyntax;
|
||||
constructorDeclaration(modifiers: ISyntaxList, constructorKeyword: ISyntaxToken, callSignature: CallSignatureSyntax, block: BlockSyntax, semicolonToken: ISyntaxToken): ConstructorDeclarationSyntax;
|
||||
memberFunctionDeclaration(modifiers: ISyntaxList, propertyName: ISyntaxToken, callSignature: CallSignatureSyntax, block: BlockSyntax, semicolonToken: ISyntaxToken): MemberFunctionDeclarationSyntax;
|
||||
getAccessor(modifiers: ISyntaxList, getKeyword: ISyntaxToken, propertyName: ISyntaxToken, parameterList: ParameterListSyntax, typeAnnotation: TypeAnnotationSyntax, block: BlockSyntax): GetAccessorSyntax;
|
||||
setAccessor(modifiers: ISyntaxList, setKeyword: ISyntaxToken, propertyName: ISyntaxToken, parameterList: ParameterListSyntax, block: BlockSyntax): SetAccessorSyntax;
|
||||
memberVariableDeclaration(modifiers: ISyntaxList, variableDeclarator: VariableDeclaratorSyntax, semicolonToken: ISyntaxToken): MemberVariableDeclarationSyntax;
|
||||
indexMemberDeclaration(modifiers: ISyntaxList, indexSignature: IndexSignatureSyntax, semicolonToken: ISyntaxToken): IndexMemberDeclarationSyntax;
|
||||
throwStatement(throwKeyword: ISyntaxToken, expression: IExpressionSyntax, semicolonToken: ISyntaxToken): ThrowStatementSyntax;
|
||||
returnStatement(returnKeyword: ISyntaxToken, expression: IExpressionSyntax, semicolonToken: ISyntaxToken): ReturnStatementSyntax;
|
||||
objectCreationExpression(newKeyword: ISyntaxToken, expression: IMemberExpressionSyntax, argumentList: ArgumentListSyntax): ObjectCreationExpressionSyntax;
|
||||
switchStatement(switchKeyword: ISyntaxToken, openParenToken: ISyntaxToken, expression: IExpressionSyntax, closeParenToken: ISyntaxToken, openBraceToken: ISyntaxToken, switchClauses: ISyntaxList, closeBraceToken: ISyntaxToken): SwitchStatementSyntax;
|
||||
caseSwitchClause(caseKeyword: ISyntaxToken, expression: IExpressionSyntax, colonToken: ISyntaxToken, statements: ISyntaxList): CaseSwitchClauseSyntax;
|
||||
defaultSwitchClause(defaultKeyword: ISyntaxToken, colonToken: ISyntaxToken, statements: ISyntaxList): DefaultSwitchClauseSyntax;
|
||||
breakStatement(breakKeyword: ISyntaxToken, identifier: ISyntaxToken, semicolonToken: ISyntaxToken): BreakStatementSyntax;
|
||||
continueStatement(continueKeyword: ISyntaxToken, identifier: ISyntaxToken, semicolonToken: ISyntaxToken): ContinueStatementSyntax;
|
||||
forStatement(forKeyword: ISyntaxToken, openParenToken: ISyntaxToken, variableDeclaration: VariableDeclarationSyntax, initializer: IExpressionSyntax, firstSemicolonToken: ISyntaxToken, condition: IExpressionSyntax, secondSemicolonToken: ISyntaxToken, incrementor: IExpressionSyntax, closeParenToken: ISyntaxToken, statement: IStatementSyntax): ForStatementSyntax;
|
||||
forInStatement(forKeyword: ISyntaxToken, openParenToken: ISyntaxToken, variableDeclaration: VariableDeclarationSyntax, left: IExpressionSyntax, inKeyword: ISyntaxToken, expression: IExpressionSyntax, closeParenToken: ISyntaxToken, statement: IStatementSyntax): ForInStatementSyntax;
|
||||
whileStatement(whileKeyword: ISyntaxToken, openParenToken: ISyntaxToken, condition: IExpressionSyntax, closeParenToken: ISyntaxToken, statement: IStatementSyntax): WhileStatementSyntax;
|
||||
withStatement(withKeyword: ISyntaxToken, openParenToken: ISyntaxToken, condition: IExpressionSyntax, closeParenToken: ISyntaxToken, statement: IStatementSyntax): WithStatementSyntax;
|
||||
enumDeclaration(modifiers: ISyntaxList, enumKeyword: ISyntaxToken, identifier: ISyntaxToken, openBraceToken: ISyntaxToken, enumElements: ISeparatedSyntaxList, closeBraceToken: ISyntaxToken): EnumDeclarationSyntax;
|
||||
enumElement(propertyName: ISyntaxToken, equalsValueClause: EqualsValueClauseSyntax): EnumElementSyntax;
|
||||
castExpression(lessThanToken: ISyntaxToken, type: ITypeSyntax, greaterThanToken: ISyntaxToken, expression: IUnaryExpressionSyntax): CastExpressionSyntax;
|
||||
objectLiteralExpression(openBraceToken: ISyntaxToken, propertyAssignments: ISeparatedSyntaxList, closeBraceToken: ISyntaxToken): ObjectLiteralExpressionSyntax;
|
||||
simplePropertyAssignment(propertyName: ISyntaxToken, colonToken: ISyntaxToken, expression: IExpressionSyntax): SimplePropertyAssignmentSyntax;
|
||||
functionPropertyAssignment(propertyName: ISyntaxToken, callSignature: CallSignatureSyntax, block: BlockSyntax): FunctionPropertyAssignmentSyntax;
|
||||
functionExpression(functionKeyword: ISyntaxToken, identifier: ISyntaxToken, callSignature: CallSignatureSyntax, block: BlockSyntax): FunctionExpressionSyntax;
|
||||
emptyStatement(semicolonToken: ISyntaxToken): EmptyStatementSyntax;
|
||||
tryStatement(tryKeyword: ISyntaxToken, block: BlockSyntax, catchClause: CatchClauseSyntax, finallyClause: FinallyClauseSyntax): TryStatementSyntax;
|
||||
catchClause(catchKeyword: ISyntaxToken, openParenToken: ISyntaxToken, identifier: ISyntaxToken, typeAnnotation: TypeAnnotationSyntax, closeParenToken: ISyntaxToken, block: BlockSyntax): CatchClauseSyntax;
|
||||
finallyClause(finallyKeyword: ISyntaxToken, block: BlockSyntax): FinallyClauseSyntax;
|
||||
labeledStatement(identifier: ISyntaxToken, colonToken: ISyntaxToken, statement: IStatementSyntax): LabeledStatementSyntax;
|
||||
doStatement(doKeyword: ISyntaxToken, statement: IStatementSyntax, whileKeyword: ISyntaxToken, openParenToken: ISyntaxToken, condition: IExpressionSyntax, closeParenToken: ISyntaxToken, semicolonToken: ISyntaxToken): DoStatementSyntax;
|
||||
typeOfExpression(typeOfKeyword: ISyntaxToken, expression: IUnaryExpressionSyntax): TypeOfExpressionSyntax;
|
||||
deleteExpression(deleteKeyword: ISyntaxToken, expression: IUnaryExpressionSyntax): DeleteExpressionSyntax;
|
||||
voidExpression(voidKeyword: ISyntaxToken, expression: IUnaryExpressionSyntax): VoidExpressionSyntax;
|
||||
debuggerStatement(debuggerKeyword: ISyntaxToken, semicolonToken: ISyntaxToken): DebuggerStatementSyntax;
|
||||
}
|
||||
|
||||
export class NormalModeFactory implements IFactory {
|
||||
sourceUnit(moduleElements: ISyntaxList, endOfFileToken: ISyntaxToken): SourceUnitSyntax {
|
||||
return new SourceUnitSyntax(moduleElements, endOfFileToken, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
externalModuleReference(requireKeyword: ISyntaxToken, openParenToken: ISyntaxToken, stringLiteral: ISyntaxToken, closeParenToken: ISyntaxToken): ExternalModuleReferenceSyntax {
|
||||
return new ExternalModuleReferenceSyntax(requireKeyword, openParenToken, stringLiteral, closeParenToken, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
moduleNameModuleReference(moduleName: INameSyntax): ModuleNameModuleReferenceSyntax {
|
||||
return new ModuleNameModuleReferenceSyntax(moduleName, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
importDeclaration(modifiers: ISyntaxList, importKeyword: ISyntaxToken, identifier: ISyntaxToken, equalsToken: ISyntaxToken, moduleReference: IModuleReferenceSyntax, semicolonToken: ISyntaxToken): ImportDeclarationSyntax {
|
||||
return new ImportDeclarationSyntax(modifiers, importKeyword, identifier, equalsToken, moduleReference, semicolonToken, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
exportAssignment(exportKeyword: ISyntaxToken, equalsToken: ISyntaxToken, identifier: ISyntaxToken, semicolonToken: ISyntaxToken): ExportAssignmentSyntax {
|
||||
return new ExportAssignmentSyntax(exportKeyword, equalsToken, identifier, semicolonToken, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
classDeclaration(modifiers: ISyntaxList, classKeyword: ISyntaxToken, identifier: ISyntaxToken, typeParameterList: TypeParameterListSyntax, heritageClauses: ISyntaxList, openBraceToken: ISyntaxToken, classElements: ISyntaxList, closeBraceToken: ISyntaxToken): ClassDeclarationSyntax {
|
||||
return new ClassDeclarationSyntax(modifiers, classKeyword, identifier, typeParameterList, heritageClauses, openBraceToken, classElements, closeBraceToken, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
interfaceDeclaration(modifiers: ISyntaxList, interfaceKeyword: ISyntaxToken, identifier: ISyntaxToken, typeParameterList: TypeParameterListSyntax, heritageClauses: ISyntaxList, body: ObjectTypeSyntax): InterfaceDeclarationSyntax {
|
||||
return new InterfaceDeclarationSyntax(modifiers, interfaceKeyword, identifier, typeParameterList, heritageClauses, body, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
heritageClause(kind: SyntaxKind, extendsOrImplementsKeyword: ISyntaxToken, typeNames: ISeparatedSyntaxList): HeritageClauseSyntax {
|
||||
return new HeritageClauseSyntax(kind, extendsOrImplementsKeyword, typeNames, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
moduleDeclaration(modifiers: ISyntaxList, moduleKeyword: ISyntaxToken, name: INameSyntax, stringLiteral: ISyntaxToken, openBraceToken: ISyntaxToken, moduleElements: ISyntaxList, closeBraceToken: ISyntaxToken): ModuleDeclarationSyntax {
|
||||
return new ModuleDeclarationSyntax(modifiers, moduleKeyword, name, stringLiteral, openBraceToken, moduleElements, closeBraceToken, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
functionDeclaration(modifiers: ISyntaxList, functionKeyword: ISyntaxToken, identifier: ISyntaxToken, callSignature: CallSignatureSyntax, block: BlockSyntax, semicolonToken: ISyntaxToken): FunctionDeclarationSyntax {
|
||||
return new FunctionDeclarationSyntax(modifiers, functionKeyword, identifier, callSignature, block, semicolonToken, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
variableStatement(modifiers: ISyntaxList, variableDeclaration: VariableDeclarationSyntax, semicolonToken: ISyntaxToken): VariableStatementSyntax {
|
||||
return new VariableStatementSyntax(modifiers, variableDeclaration, semicolonToken, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
variableDeclaration(varKeyword: ISyntaxToken, variableDeclarators: ISeparatedSyntaxList): VariableDeclarationSyntax {
|
||||
return new VariableDeclarationSyntax(varKeyword, variableDeclarators, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
variableDeclarator(propertyName: ISyntaxToken, typeAnnotation: TypeAnnotationSyntax, equalsValueClause: EqualsValueClauseSyntax): VariableDeclaratorSyntax {
|
||||
return new VariableDeclaratorSyntax(propertyName, typeAnnotation, equalsValueClause, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
equalsValueClause(equalsToken: ISyntaxToken, value: IExpressionSyntax): EqualsValueClauseSyntax {
|
||||
return new EqualsValueClauseSyntax(equalsToken, value, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
prefixUnaryExpression(kind: SyntaxKind, operatorToken: ISyntaxToken, operand: IUnaryExpressionSyntax): PrefixUnaryExpressionSyntax {
|
||||
return new PrefixUnaryExpressionSyntax(kind, operatorToken, operand, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
arrayLiteralExpression(openBracketToken: ISyntaxToken, expressions: ISeparatedSyntaxList, closeBracketToken: ISyntaxToken): ArrayLiteralExpressionSyntax {
|
||||
return new ArrayLiteralExpressionSyntax(openBracketToken, expressions, closeBracketToken, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
omittedExpression(): OmittedExpressionSyntax {
|
||||
return new OmittedExpressionSyntax(/*parsedInStrictMode:*/ false);
|
||||
}
|
||||
parenthesizedExpression(openParenToken: ISyntaxToken, expression: IExpressionSyntax, closeParenToken: ISyntaxToken): ParenthesizedExpressionSyntax {
|
||||
return new ParenthesizedExpressionSyntax(openParenToken, expression, closeParenToken, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
simpleArrowFunctionExpression(identifier: ISyntaxToken, equalsGreaterThanToken: ISyntaxToken, block: BlockSyntax, expression: IExpressionSyntax): SimpleArrowFunctionExpressionSyntax {
|
||||
return new SimpleArrowFunctionExpressionSyntax(identifier, equalsGreaterThanToken, block, expression, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
parenthesizedArrowFunctionExpression(callSignature: CallSignatureSyntax, equalsGreaterThanToken: ISyntaxToken, block: BlockSyntax, expression: IExpressionSyntax): ParenthesizedArrowFunctionExpressionSyntax {
|
||||
return new ParenthesizedArrowFunctionExpressionSyntax(callSignature, equalsGreaterThanToken, block, expression, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
qualifiedName(left: INameSyntax, dotToken: ISyntaxToken, right: ISyntaxToken): QualifiedNameSyntax {
|
||||
return new QualifiedNameSyntax(left, dotToken, right, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
typeArgumentList(lessThanToken: ISyntaxToken, typeArguments: ISeparatedSyntaxList, greaterThanToken: ISyntaxToken): TypeArgumentListSyntax {
|
||||
return new TypeArgumentListSyntax(lessThanToken, typeArguments, greaterThanToken, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
constructorType(newKeyword: ISyntaxToken, typeParameterList: TypeParameterListSyntax, parameterList: ParameterListSyntax, equalsGreaterThanToken: ISyntaxToken, type: ITypeSyntax): ConstructorTypeSyntax {
|
||||
return new ConstructorTypeSyntax(newKeyword, typeParameterList, parameterList, equalsGreaterThanToken, type, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
functionType(typeParameterList: TypeParameterListSyntax, parameterList: ParameterListSyntax, equalsGreaterThanToken: ISyntaxToken, type: ITypeSyntax): FunctionTypeSyntax {
|
||||
return new FunctionTypeSyntax(typeParameterList, parameterList, equalsGreaterThanToken, type, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
objectType(openBraceToken: ISyntaxToken, typeMembers: ISeparatedSyntaxList, closeBraceToken: ISyntaxToken): ObjectTypeSyntax {
|
||||
return new ObjectTypeSyntax(openBraceToken, typeMembers, closeBraceToken, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
arrayType(type: ITypeSyntax, openBracketToken: ISyntaxToken, closeBracketToken: ISyntaxToken): ArrayTypeSyntax {
|
||||
return new ArrayTypeSyntax(type, openBracketToken, closeBracketToken, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
genericType(name: INameSyntax, typeArgumentList: TypeArgumentListSyntax): GenericTypeSyntax {
|
||||
return new GenericTypeSyntax(name, typeArgumentList, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
typeQuery(typeOfKeyword: ISyntaxToken, name: INameSyntax): TypeQuerySyntax {
|
||||
return new TypeQuerySyntax(typeOfKeyword, name, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
typeAnnotation(colonToken: ISyntaxToken, type: ITypeSyntax): TypeAnnotationSyntax {
|
||||
return new TypeAnnotationSyntax(colonToken, type, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
block(openBraceToken: ISyntaxToken, statements: ISyntaxList, closeBraceToken: ISyntaxToken): BlockSyntax {
|
||||
return new BlockSyntax(openBraceToken, statements, closeBraceToken, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
parameter(dotDotDotToken: ISyntaxToken, modifiers: ISyntaxList, identifier: ISyntaxToken, questionToken: ISyntaxToken, typeAnnotation: TypeAnnotationSyntax, equalsValueClause: EqualsValueClauseSyntax): ParameterSyntax {
|
||||
return new ParameterSyntax(dotDotDotToken, modifiers, identifier, questionToken, typeAnnotation, equalsValueClause, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
memberAccessExpression(expression: IExpressionSyntax, dotToken: ISyntaxToken, name: ISyntaxToken): MemberAccessExpressionSyntax {
|
||||
return new MemberAccessExpressionSyntax(expression, dotToken, name, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
postfixUnaryExpression(kind: SyntaxKind, operand: IMemberExpressionSyntax, operatorToken: ISyntaxToken): PostfixUnaryExpressionSyntax {
|
||||
return new PostfixUnaryExpressionSyntax(kind, operand, operatorToken, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
elementAccessExpression(expression: IExpressionSyntax, openBracketToken: ISyntaxToken, argumentExpression: IExpressionSyntax, closeBracketToken: ISyntaxToken): ElementAccessExpressionSyntax {
|
||||
return new ElementAccessExpressionSyntax(expression, openBracketToken, argumentExpression, closeBracketToken, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
invocationExpression(expression: IMemberExpressionSyntax, argumentList: ArgumentListSyntax): InvocationExpressionSyntax {
|
||||
return new InvocationExpressionSyntax(expression, argumentList, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
argumentList(typeArgumentList: TypeArgumentListSyntax, openParenToken: ISyntaxToken, _arguments: ISeparatedSyntaxList, closeParenToken: ISyntaxToken): ArgumentListSyntax {
|
||||
return new ArgumentListSyntax(typeArgumentList, openParenToken, _arguments, closeParenToken, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
binaryExpression(kind: SyntaxKind, left: IExpressionSyntax, operatorToken: ISyntaxToken, right: IExpressionSyntax): BinaryExpressionSyntax {
|
||||
return new BinaryExpressionSyntax(kind, left, operatorToken, right, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
conditionalExpression(condition: IExpressionSyntax, questionToken: ISyntaxToken, whenTrue: IExpressionSyntax, colonToken: ISyntaxToken, whenFalse: IExpressionSyntax): ConditionalExpressionSyntax {
|
||||
return new ConditionalExpressionSyntax(condition, questionToken, whenTrue, colonToken, whenFalse, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
constructSignature(newKeyword: ISyntaxToken, callSignature: CallSignatureSyntax): ConstructSignatureSyntax {
|
||||
return new ConstructSignatureSyntax(newKeyword, callSignature, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
methodSignature(propertyName: ISyntaxToken, questionToken: ISyntaxToken, callSignature: CallSignatureSyntax): MethodSignatureSyntax {
|
||||
return new MethodSignatureSyntax(propertyName, questionToken, callSignature, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
indexSignature(openBracketToken: ISyntaxToken, parameter: ParameterSyntax, closeBracketToken: ISyntaxToken, typeAnnotation: TypeAnnotationSyntax): IndexSignatureSyntax {
|
||||
return new IndexSignatureSyntax(openBracketToken, parameter, closeBracketToken, typeAnnotation, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
propertySignature(propertyName: ISyntaxToken, questionToken: ISyntaxToken, typeAnnotation: TypeAnnotationSyntax): PropertySignatureSyntax {
|
||||
return new PropertySignatureSyntax(propertyName, questionToken, typeAnnotation, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
callSignature(typeParameterList: TypeParameterListSyntax, parameterList: ParameterListSyntax, typeAnnotation: TypeAnnotationSyntax): CallSignatureSyntax {
|
||||
return new CallSignatureSyntax(typeParameterList, parameterList, typeAnnotation, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
parameterList(openParenToken: ISyntaxToken, parameters: ISeparatedSyntaxList, closeParenToken: ISyntaxToken): ParameterListSyntax {
|
||||
return new ParameterListSyntax(openParenToken, parameters, closeParenToken, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
typeParameterList(lessThanToken: ISyntaxToken, typeParameters: ISeparatedSyntaxList, greaterThanToken: ISyntaxToken): TypeParameterListSyntax {
|
||||
return new TypeParameterListSyntax(lessThanToken, typeParameters, greaterThanToken, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
typeParameter(identifier: ISyntaxToken, constraint: ConstraintSyntax): TypeParameterSyntax {
|
||||
return new TypeParameterSyntax(identifier, constraint, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
constraint(extendsKeyword: ISyntaxToken, type: ITypeSyntax): ConstraintSyntax {
|
||||
return new ConstraintSyntax(extendsKeyword, type, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
elseClause(elseKeyword: ISyntaxToken, statement: IStatementSyntax): ElseClauseSyntax {
|
||||
return new ElseClauseSyntax(elseKeyword, statement, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
ifStatement(ifKeyword: ISyntaxToken, openParenToken: ISyntaxToken, condition: IExpressionSyntax, closeParenToken: ISyntaxToken, statement: IStatementSyntax, elseClause: ElseClauseSyntax): IfStatementSyntax {
|
||||
return new IfStatementSyntax(ifKeyword, openParenToken, condition, closeParenToken, statement, elseClause, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
expressionStatement(expression: IExpressionSyntax, semicolonToken: ISyntaxToken): ExpressionStatementSyntax {
|
||||
return new ExpressionStatementSyntax(expression, semicolonToken, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
constructorDeclaration(modifiers: ISyntaxList, constructorKeyword: ISyntaxToken, callSignature: CallSignatureSyntax, block: BlockSyntax, semicolonToken: ISyntaxToken): ConstructorDeclarationSyntax {
|
||||
return new ConstructorDeclarationSyntax(modifiers, constructorKeyword, callSignature, block, semicolonToken, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
memberFunctionDeclaration(modifiers: ISyntaxList, propertyName: ISyntaxToken, callSignature: CallSignatureSyntax, block: BlockSyntax, semicolonToken: ISyntaxToken): MemberFunctionDeclarationSyntax {
|
||||
return new MemberFunctionDeclarationSyntax(modifiers, propertyName, callSignature, block, semicolonToken, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
getAccessor(modifiers: ISyntaxList, getKeyword: ISyntaxToken, propertyName: ISyntaxToken, parameterList: ParameterListSyntax, typeAnnotation: TypeAnnotationSyntax, block: BlockSyntax): GetAccessorSyntax {
|
||||
return new GetAccessorSyntax(modifiers, getKeyword, propertyName, parameterList, typeAnnotation, block, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
setAccessor(modifiers: ISyntaxList, setKeyword: ISyntaxToken, propertyName: ISyntaxToken, parameterList: ParameterListSyntax, block: BlockSyntax): SetAccessorSyntax {
|
||||
return new SetAccessorSyntax(modifiers, setKeyword, propertyName, parameterList, block, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
memberVariableDeclaration(modifiers: ISyntaxList, variableDeclarator: VariableDeclaratorSyntax, semicolonToken: ISyntaxToken): MemberVariableDeclarationSyntax {
|
||||
return new MemberVariableDeclarationSyntax(modifiers, variableDeclarator, semicolonToken, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
indexMemberDeclaration(modifiers: ISyntaxList, indexSignature: IndexSignatureSyntax, semicolonToken: ISyntaxToken): IndexMemberDeclarationSyntax {
|
||||
return new IndexMemberDeclarationSyntax(modifiers, indexSignature, semicolonToken, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
throwStatement(throwKeyword: ISyntaxToken, expression: IExpressionSyntax, semicolonToken: ISyntaxToken): ThrowStatementSyntax {
|
||||
return new ThrowStatementSyntax(throwKeyword, expression, semicolonToken, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
returnStatement(returnKeyword: ISyntaxToken, expression: IExpressionSyntax, semicolonToken: ISyntaxToken): ReturnStatementSyntax {
|
||||
return new ReturnStatementSyntax(returnKeyword, expression, semicolonToken, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
objectCreationExpression(newKeyword: ISyntaxToken, expression: IMemberExpressionSyntax, argumentList: ArgumentListSyntax): ObjectCreationExpressionSyntax {
|
||||
return new ObjectCreationExpressionSyntax(newKeyword, expression, argumentList, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
switchStatement(switchKeyword: ISyntaxToken, openParenToken: ISyntaxToken, expression: IExpressionSyntax, closeParenToken: ISyntaxToken, openBraceToken: ISyntaxToken, switchClauses: ISyntaxList, closeBraceToken: ISyntaxToken): SwitchStatementSyntax {
|
||||
return new SwitchStatementSyntax(switchKeyword, openParenToken, expression, closeParenToken, openBraceToken, switchClauses, closeBraceToken, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
caseSwitchClause(caseKeyword: ISyntaxToken, expression: IExpressionSyntax, colonToken: ISyntaxToken, statements: ISyntaxList): CaseSwitchClauseSyntax {
|
||||
return new CaseSwitchClauseSyntax(caseKeyword, expression, colonToken, statements, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
defaultSwitchClause(defaultKeyword: ISyntaxToken, colonToken: ISyntaxToken, statements: ISyntaxList): DefaultSwitchClauseSyntax {
|
||||
return new DefaultSwitchClauseSyntax(defaultKeyword, colonToken, statements, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
breakStatement(breakKeyword: ISyntaxToken, identifier: ISyntaxToken, semicolonToken: ISyntaxToken): BreakStatementSyntax {
|
||||
return new BreakStatementSyntax(breakKeyword, identifier, semicolonToken, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
continueStatement(continueKeyword: ISyntaxToken, identifier: ISyntaxToken, semicolonToken: ISyntaxToken): ContinueStatementSyntax {
|
||||
return new ContinueStatementSyntax(continueKeyword, identifier, semicolonToken, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
forStatement(forKeyword: ISyntaxToken, openParenToken: ISyntaxToken, variableDeclaration: VariableDeclarationSyntax, initializer: IExpressionSyntax, firstSemicolonToken: ISyntaxToken, condition: IExpressionSyntax, secondSemicolonToken: ISyntaxToken, incrementor: IExpressionSyntax, closeParenToken: ISyntaxToken, statement: IStatementSyntax): ForStatementSyntax {
|
||||
return new ForStatementSyntax(forKeyword, openParenToken, variableDeclaration, initializer, firstSemicolonToken, condition, secondSemicolonToken, incrementor, closeParenToken, statement, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
forInStatement(forKeyword: ISyntaxToken, openParenToken: ISyntaxToken, variableDeclaration: VariableDeclarationSyntax, left: IExpressionSyntax, inKeyword: ISyntaxToken, expression: IExpressionSyntax, closeParenToken: ISyntaxToken, statement: IStatementSyntax): ForInStatementSyntax {
|
||||
return new ForInStatementSyntax(forKeyword, openParenToken, variableDeclaration, left, inKeyword, expression, closeParenToken, statement, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
whileStatement(whileKeyword: ISyntaxToken, openParenToken: ISyntaxToken, condition: IExpressionSyntax, closeParenToken: ISyntaxToken, statement: IStatementSyntax): WhileStatementSyntax {
|
||||
return new WhileStatementSyntax(whileKeyword, openParenToken, condition, closeParenToken, statement, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
withStatement(withKeyword: ISyntaxToken, openParenToken: ISyntaxToken, condition: IExpressionSyntax, closeParenToken: ISyntaxToken, statement: IStatementSyntax): WithStatementSyntax {
|
||||
return new WithStatementSyntax(withKeyword, openParenToken, condition, closeParenToken, statement, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
enumDeclaration(modifiers: ISyntaxList, enumKeyword: ISyntaxToken, identifier: ISyntaxToken, openBraceToken: ISyntaxToken, enumElements: ISeparatedSyntaxList, closeBraceToken: ISyntaxToken): EnumDeclarationSyntax {
|
||||
return new EnumDeclarationSyntax(modifiers, enumKeyword, identifier, openBraceToken, enumElements, closeBraceToken, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
enumElement(propertyName: ISyntaxToken, equalsValueClause: EqualsValueClauseSyntax): EnumElementSyntax {
|
||||
return new EnumElementSyntax(propertyName, equalsValueClause, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
castExpression(lessThanToken: ISyntaxToken, type: ITypeSyntax, greaterThanToken: ISyntaxToken, expression: IUnaryExpressionSyntax): CastExpressionSyntax {
|
||||
return new CastExpressionSyntax(lessThanToken, type, greaterThanToken, expression, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
objectLiteralExpression(openBraceToken: ISyntaxToken, propertyAssignments: ISeparatedSyntaxList, closeBraceToken: ISyntaxToken): ObjectLiteralExpressionSyntax {
|
||||
return new ObjectLiteralExpressionSyntax(openBraceToken, propertyAssignments, closeBraceToken, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
simplePropertyAssignment(propertyName: ISyntaxToken, colonToken: ISyntaxToken, expression: IExpressionSyntax): SimplePropertyAssignmentSyntax {
|
||||
return new SimplePropertyAssignmentSyntax(propertyName, colonToken, expression, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
functionPropertyAssignment(propertyName: ISyntaxToken, callSignature: CallSignatureSyntax, block: BlockSyntax): FunctionPropertyAssignmentSyntax {
|
||||
return new FunctionPropertyAssignmentSyntax(propertyName, callSignature, block, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
functionExpression(functionKeyword: ISyntaxToken, identifier: ISyntaxToken, callSignature: CallSignatureSyntax, block: BlockSyntax): FunctionExpressionSyntax {
|
||||
return new FunctionExpressionSyntax(functionKeyword, identifier, callSignature, block, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
emptyStatement(semicolonToken: ISyntaxToken): EmptyStatementSyntax {
|
||||
return new EmptyStatementSyntax(semicolonToken, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
tryStatement(tryKeyword: ISyntaxToken, block: BlockSyntax, catchClause: CatchClauseSyntax, finallyClause: FinallyClauseSyntax): TryStatementSyntax {
|
||||
return new TryStatementSyntax(tryKeyword, block, catchClause, finallyClause, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
catchClause(catchKeyword: ISyntaxToken, openParenToken: ISyntaxToken, identifier: ISyntaxToken, typeAnnotation: TypeAnnotationSyntax, closeParenToken: ISyntaxToken, block: BlockSyntax): CatchClauseSyntax {
|
||||
return new CatchClauseSyntax(catchKeyword, openParenToken, identifier, typeAnnotation, closeParenToken, block, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
finallyClause(finallyKeyword: ISyntaxToken, block: BlockSyntax): FinallyClauseSyntax {
|
||||
return new FinallyClauseSyntax(finallyKeyword, block, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
labeledStatement(identifier: ISyntaxToken, colonToken: ISyntaxToken, statement: IStatementSyntax): LabeledStatementSyntax {
|
||||
return new LabeledStatementSyntax(identifier, colonToken, statement, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
doStatement(doKeyword: ISyntaxToken, statement: IStatementSyntax, whileKeyword: ISyntaxToken, openParenToken: ISyntaxToken, condition: IExpressionSyntax, closeParenToken: ISyntaxToken, semicolonToken: ISyntaxToken): DoStatementSyntax {
|
||||
return new DoStatementSyntax(doKeyword, statement, whileKeyword, openParenToken, condition, closeParenToken, semicolonToken, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
typeOfExpression(typeOfKeyword: ISyntaxToken, expression: IUnaryExpressionSyntax): TypeOfExpressionSyntax {
|
||||
return new TypeOfExpressionSyntax(typeOfKeyword, expression, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
deleteExpression(deleteKeyword: ISyntaxToken, expression: IUnaryExpressionSyntax): DeleteExpressionSyntax {
|
||||
return new DeleteExpressionSyntax(deleteKeyword, expression, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
voidExpression(voidKeyword: ISyntaxToken, expression: IUnaryExpressionSyntax): VoidExpressionSyntax {
|
||||
return new VoidExpressionSyntax(voidKeyword, expression, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
debuggerStatement(debuggerKeyword: ISyntaxToken, semicolonToken: ISyntaxToken): DebuggerStatementSyntax {
|
||||
return new DebuggerStatementSyntax(debuggerKeyword, semicolonToken, /*parsedInStrictMode:*/ false);
|
||||
}
|
||||
}
|
||||
|
||||
export class StrictModeFactory implements IFactory {
|
||||
sourceUnit(moduleElements: ISyntaxList, endOfFileToken: ISyntaxToken): SourceUnitSyntax {
|
||||
return new SourceUnitSyntax(moduleElements, endOfFileToken, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
externalModuleReference(requireKeyword: ISyntaxToken, openParenToken: ISyntaxToken, stringLiteral: ISyntaxToken, closeParenToken: ISyntaxToken): ExternalModuleReferenceSyntax {
|
||||
return new ExternalModuleReferenceSyntax(requireKeyword, openParenToken, stringLiteral, closeParenToken, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
moduleNameModuleReference(moduleName: INameSyntax): ModuleNameModuleReferenceSyntax {
|
||||
return new ModuleNameModuleReferenceSyntax(moduleName, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
importDeclaration(modifiers: ISyntaxList, importKeyword: ISyntaxToken, identifier: ISyntaxToken, equalsToken: ISyntaxToken, moduleReference: IModuleReferenceSyntax, semicolonToken: ISyntaxToken): ImportDeclarationSyntax {
|
||||
return new ImportDeclarationSyntax(modifiers, importKeyword, identifier, equalsToken, moduleReference, semicolonToken, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
exportAssignment(exportKeyword: ISyntaxToken, equalsToken: ISyntaxToken, identifier: ISyntaxToken, semicolonToken: ISyntaxToken): ExportAssignmentSyntax {
|
||||
return new ExportAssignmentSyntax(exportKeyword, equalsToken, identifier, semicolonToken, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
classDeclaration(modifiers: ISyntaxList, classKeyword: ISyntaxToken, identifier: ISyntaxToken, typeParameterList: TypeParameterListSyntax, heritageClauses: ISyntaxList, openBraceToken: ISyntaxToken, classElements: ISyntaxList, closeBraceToken: ISyntaxToken): ClassDeclarationSyntax {
|
||||
return new ClassDeclarationSyntax(modifiers, classKeyword, identifier, typeParameterList, heritageClauses, openBraceToken, classElements, closeBraceToken, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
interfaceDeclaration(modifiers: ISyntaxList, interfaceKeyword: ISyntaxToken, identifier: ISyntaxToken, typeParameterList: TypeParameterListSyntax, heritageClauses: ISyntaxList, body: ObjectTypeSyntax): InterfaceDeclarationSyntax {
|
||||
return new InterfaceDeclarationSyntax(modifiers, interfaceKeyword, identifier, typeParameterList, heritageClauses, body, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
heritageClause(kind: SyntaxKind, extendsOrImplementsKeyword: ISyntaxToken, typeNames: ISeparatedSyntaxList): HeritageClauseSyntax {
|
||||
return new HeritageClauseSyntax(kind, extendsOrImplementsKeyword, typeNames, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
moduleDeclaration(modifiers: ISyntaxList, moduleKeyword: ISyntaxToken, name: INameSyntax, stringLiteral: ISyntaxToken, openBraceToken: ISyntaxToken, moduleElements: ISyntaxList, closeBraceToken: ISyntaxToken): ModuleDeclarationSyntax {
|
||||
return new ModuleDeclarationSyntax(modifiers, moduleKeyword, name, stringLiteral, openBraceToken, moduleElements, closeBraceToken, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
functionDeclaration(modifiers: ISyntaxList, functionKeyword: ISyntaxToken, identifier: ISyntaxToken, callSignature: CallSignatureSyntax, block: BlockSyntax, semicolonToken: ISyntaxToken): FunctionDeclarationSyntax {
|
||||
return new FunctionDeclarationSyntax(modifiers, functionKeyword, identifier, callSignature, block, semicolonToken, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
variableStatement(modifiers: ISyntaxList, variableDeclaration: VariableDeclarationSyntax, semicolonToken: ISyntaxToken): VariableStatementSyntax {
|
||||
return new VariableStatementSyntax(modifiers, variableDeclaration, semicolonToken, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
variableDeclaration(varKeyword: ISyntaxToken, variableDeclarators: ISeparatedSyntaxList): VariableDeclarationSyntax {
|
||||
return new VariableDeclarationSyntax(varKeyword, variableDeclarators, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
variableDeclarator(propertyName: ISyntaxToken, typeAnnotation: TypeAnnotationSyntax, equalsValueClause: EqualsValueClauseSyntax): VariableDeclaratorSyntax {
|
||||
return new VariableDeclaratorSyntax(propertyName, typeAnnotation, equalsValueClause, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
equalsValueClause(equalsToken: ISyntaxToken, value: IExpressionSyntax): EqualsValueClauseSyntax {
|
||||
return new EqualsValueClauseSyntax(equalsToken, value, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
prefixUnaryExpression(kind: SyntaxKind, operatorToken: ISyntaxToken, operand: IUnaryExpressionSyntax): PrefixUnaryExpressionSyntax {
|
||||
return new PrefixUnaryExpressionSyntax(kind, operatorToken, operand, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
arrayLiteralExpression(openBracketToken: ISyntaxToken, expressions: ISeparatedSyntaxList, closeBracketToken: ISyntaxToken): ArrayLiteralExpressionSyntax {
|
||||
return new ArrayLiteralExpressionSyntax(openBracketToken, expressions, closeBracketToken, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
omittedExpression(): OmittedExpressionSyntax {
|
||||
return new OmittedExpressionSyntax(/*parsedInStrictMode:*/ true);
|
||||
}
|
||||
parenthesizedExpression(openParenToken: ISyntaxToken, expression: IExpressionSyntax, closeParenToken: ISyntaxToken): ParenthesizedExpressionSyntax {
|
||||
return new ParenthesizedExpressionSyntax(openParenToken, expression, closeParenToken, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
simpleArrowFunctionExpression(identifier: ISyntaxToken, equalsGreaterThanToken: ISyntaxToken, block: BlockSyntax, expression: IExpressionSyntax): SimpleArrowFunctionExpressionSyntax {
|
||||
return new SimpleArrowFunctionExpressionSyntax(identifier, equalsGreaterThanToken, block, expression, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
parenthesizedArrowFunctionExpression(callSignature: CallSignatureSyntax, equalsGreaterThanToken: ISyntaxToken, block: BlockSyntax, expression: IExpressionSyntax): ParenthesizedArrowFunctionExpressionSyntax {
|
||||
return new ParenthesizedArrowFunctionExpressionSyntax(callSignature, equalsGreaterThanToken, block, expression, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
qualifiedName(left: INameSyntax, dotToken: ISyntaxToken, right: ISyntaxToken): QualifiedNameSyntax {
|
||||
return new QualifiedNameSyntax(left, dotToken, right, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
typeArgumentList(lessThanToken: ISyntaxToken, typeArguments: ISeparatedSyntaxList, greaterThanToken: ISyntaxToken): TypeArgumentListSyntax {
|
||||
return new TypeArgumentListSyntax(lessThanToken, typeArguments, greaterThanToken, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
constructorType(newKeyword: ISyntaxToken, typeParameterList: TypeParameterListSyntax, parameterList: ParameterListSyntax, equalsGreaterThanToken: ISyntaxToken, type: ITypeSyntax): ConstructorTypeSyntax {
|
||||
return new ConstructorTypeSyntax(newKeyword, typeParameterList, parameterList, equalsGreaterThanToken, type, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
functionType(typeParameterList: TypeParameterListSyntax, parameterList: ParameterListSyntax, equalsGreaterThanToken: ISyntaxToken, type: ITypeSyntax): FunctionTypeSyntax {
|
||||
return new FunctionTypeSyntax(typeParameterList, parameterList, equalsGreaterThanToken, type, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
objectType(openBraceToken: ISyntaxToken, typeMembers: ISeparatedSyntaxList, closeBraceToken: ISyntaxToken): ObjectTypeSyntax {
|
||||
return new ObjectTypeSyntax(openBraceToken, typeMembers, closeBraceToken, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
arrayType(type: ITypeSyntax, openBracketToken: ISyntaxToken, closeBracketToken: ISyntaxToken): ArrayTypeSyntax {
|
||||
return new ArrayTypeSyntax(type, openBracketToken, closeBracketToken, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
genericType(name: INameSyntax, typeArgumentList: TypeArgumentListSyntax): GenericTypeSyntax {
|
||||
return new GenericTypeSyntax(name, typeArgumentList, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
typeQuery(typeOfKeyword: ISyntaxToken, name: INameSyntax): TypeQuerySyntax {
|
||||
return new TypeQuerySyntax(typeOfKeyword, name, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
typeAnnotation(colonToken: ISyntaxToken, type: ITypeSyntax): TypeAnnotationSyntax {
|
||||
return new TypeAnnotationSyntax(colonToken, type, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
block(openBraceToken: ISyntaxToken, statements: ISyntaxList, closeBraceToken: ISyntaxToken): BlockSyntax {
|
||||
return new BlockSyntax(openBraceToken, statements, closeBraceToken, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
parameter(dotDotDotToken: ISyntaxToken, modifiers: ISyntaxList, identifier: ISyntaxToken, questionToken: ISyntaxToken, typeAnnotation: TypeAnnotationSyntax, equalsValueClause: EqualsValueClauseSyntax): ParameterSyntax {
|
||||
return new ParameterSyntax(dotDotDotToken, modifiers, identifier, questionToken, typeAnnotation, equalsValueClause, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
memberAccessExpression(expression: IExpressionSyntax, dotToken: ISyntaxToken, name: ISyntaxToken): MemberAccessExpressionSyntax {
|
||||
return new MemberAccessExpressionSyntax(expression, dotToken, name, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
postfixUnaryExpression(kind: SyntaxKind, operand: IMemberExpressionSyntax, operatorToken: ISyntaxToken): PostfixUnaryExpressionSyntax {
|
||||
return new PostfixUnaryExpressionSyntax(kind, operand, operatorToken, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
elementAccessExpression(expression: IExpressionSyntax, openBracketToken: ISyntaxToken, argumentExpression: IExpressionSyntax, closeBracketToken: ISyntaxToken): ElementAccessExpressionSyntax {
|
||||
return new ElementAccessExpressionSyntax(expression, openBracketToken, argumentExpression, closeBracketToken, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
invocationExpression(expression: IMemberExpressionSyntax, argumentList: ArgumentListSyntax): InvocationExpressionSyntax {
|
||||
return new InvocationExpressionSyntax(expression, argumentList, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
argumentList(typeArgumentList: TypeArgumentListSyntax, openParenToken: ISyntaxToken, _arguments: ISeparatedSyntaxList, closeParenToken: ISyntaxToken): ArgumentListSyntax {
|
||||
return new ArgumentListSyntax(typeArgumentList, openParenToken, _arguments, closeParenToken, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
binaryExpression(kind: SyntaxKind, left: IExpressionSyntax, operatorToken: ISyntaxToken, right: IExpressionSyntax): BinaryExpressionSyntax {
|
||||
return new BinaryExpressionSyntax(kind, left, operatorToken, right, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
conditionalExpression(condition: IExpressionSyntax, questionToken: ISyntaxToken, whenTrue: IExpressionSyntax, colonToken: ISyntaxToken, whenFalse: IExpressionSyntax): ConditionalExpressionSyntax {
|
||||
return new ConditionalExpressionSyntax(condition, questionToken, whenTrue, colonToken, whenFalse, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
constructSignature(newKeyword: ISyntaxToken, callSignature: CallSignatureSyntax): ConstructSignatureSyntax {
|
||||
return new ConstructSignatureSyntax(newKeyword, callSignature, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
methodSignature(propertyName: ISyntaxToken, questionToken: ISyntaxToken, callSignature: CallSignatureSyntax): MethodSignatureSyntax {
|
||||
return new MethodSignatureSyntax(propertyName, questionToken, callSignature, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
indexSignature(openBracketToken: ISyntaxToken, parameter: ParameterSyntax, closeBracketToken: ISyntaxToken, typeAnnotation: TypeAnnotationSyntax): IndexSignatureSyntax {
|
||||
return new IndexSignatureSyntax(openBracketToken, parameter, closeBracketToken, typeAnnotation, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
propertySignature(propertyName: ISyntaxToken, questionToken: ISyntaxToken, typeAnnotation: TypeAnnotationSyntax): PropertySignatureSyntax {
|
||||
return new PropertySignatureSyntax(propertyName, questionToken, typeAnnotation, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
callSignature(typeParameterList: TypeParameterListSyntax, parameterList: ParameterListSyntax, typeAnnotation: TypeAnnotationSyntax): CallSignatureSyntax {
|
||||
return new CallSignatureSyntax(typeParameterList, parameterList, typeAnnotation, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
parameterList(openParenToken: ISyntaxToken, parameters: ISeparatedSyntaxList, closeParenToken: ISyntaxToken): ParameterListSyntax {
|
||||
return new ParameterListSyntax(openParenToken, parameters, closeParenToken, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
typeParameterList(lessThanToken: ISyntaxToken, typeParameters: ISeparatedSyntaxList, greaterThanToken: ISyntaxToken): TypeParameterListSyntax {
|
||||
return new TypeParameterListSyntax(lessThanToken, typeParameters, greaterThanToken, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
typeParameter(identifier: ISyntaxToken, constraint: ConstraintSyntax): TypeParameterSyntax {
|
||||
return new TypeParameterSyntax(identifier, constraint, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
constraint(extendsKeyword: ISyntaxToken, type: ITypeSyntax): ConstraintSyntax {
|
||||
return new ConstraintSyntax(extendsKeyword, type, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
elseClause(elseKeyword: ISyntaxToken, statement: IStatementSyntax): ElseClauseSyntax {
|
||||
return new ElseClauseSyntax(elseKeyword, statement, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
ifStatement(ifKeyword: ISyntaxToken, openParenToken: ISyntaxToken, condition: IExpressionSyntax, closeParenToken: ISyntaxToken, statement: IStatementSyntax, elseClause: ElseClauseSyntax): IfStatementSyntax {
|
||||
return new IfStatementSyntax(ifKeyword, openParenToken, condition, closeParenToken, statement, elseClause, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
expressionStatement(expression: IExpressionSyntax, semicolonToken: ISyntaxToken): ExpressionStatementSyntax {
|
||||
return new ExpressionStatementSyntax(expression, semicolonToken, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
constructorDeclaration(modifiers: ISyntaxList, constructorKeyword: ISyntaxToken, callSignature: CallSignatureSyntax, block: BlockSyntax, semicolonToken: ISyntaxToken): ConstructorDeclarationSyntax {
|
||||
return new ConstructorDeclarationSyntax(modifiers, constructorKeyword, callSignature, block, semicolonToken, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
memberFunctionDeclaration(modifiers: ISyntaxList, propertyName: ISyntaxToken, callSignature: CallSignatureSyntax, block: BlockSyntax, semicolonToken: ISyntaxToken): MemberFunctionDeclarationSyntax {
|
||||
return new MemberFunctionDeclarationSyntax(modifiers, propertyName, callSignature, block, semicolonToken, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
getAccessor(modifiers: ISyntaxList, getKeyword: ISyntaxToken, propertyName: ISyntaxToken, parameterList: ParameterListSyntax, typeAnnotation: TypeAnnotationSyntax, block: BlockSyntax): GetAccessorSyntax {
|
||||
return new GetAccessorSyntax(modifiers, getKeyword, propertyName, parameterList, typeAnnotation, block, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
setAccessor(modifiers: ISyntaxList, setKeyword: ISyntaxToken, propertyName: ISyntaxToken, parameterList: ParameterListSyntax, block: BlockSyntax): SetAccessorSyntax {
|
||||
return new SetAccessorSyntax(modifiers, setKeyword, propertyName, parameterList, block, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
memberVariableDeclaration(modifiers: ISyntaxList, variableDeclarator: VariableDeclaratorSyntax, semicolonToken: ISyntaxToken): MemberVariableDeclarationSyntax {
|
||||
return new MemberVariableDeclarationSyntax(modifiers, variableDeclarator, semicolonToken, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
indexMemberDeclaration(modifiers: ISyntaxList, indexSignature: IndexSignatureSyntax, semicolonToken: ISyntaxToken): IndexMemberDeclarationSyntax {
|
||||
return new IndexMemberDeclarationSyntax(modifiers, indexSignature, semicolonToken, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
throwStatement(throwKeyword: ISyntaxToken, expression: IExpressionSyntax, semicolonToken: ISyntaxToken): ThrowStatementSyntax {
|
||||
return new ThrowStatementSyntax(throwKeyword, expression, semicolonToken, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
returnStatement(returnKeyword: ISyntaxToken, expression: IExpressionSyntax, semicolonToken: ISyntaxToken): ReturnStatementSyntax {
|
||||
return new ReturnStatementSyntax(returnKeyword, expression, semicolonToken, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
objectCreationExpression(newKeyword: ISyntaxToken, expression: IMemberExpressionSyntax, argumentList: ArgumentListSyntax): ObjectCreationExpressionSyntax {
|
||||
return new ObjectCreationExpressionSyntax(newKeyword, expression, argumentList, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
switchStatement(switchKeyword: ISyntaxToken, openParenToken: ISyntaxToken, expression: IExpressionSyntax, closeParenToken: ISyntaxToken, openBraceToken: ISyntaxToken, switchClauses: ISyntaxList, closeBraceToken: ISyntaxToken): SwitchStatementSyntax {
|
||||
return new SwitchStatementSyntax(switchKeyword, openParenToken, expression, closeParenToken, openBraceToken, switchClauses, closeBraceToken, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
caseSwitchClause(caseKeyword: ISyntaxToken, expression: IExpressionSyntax, colonToken: ISyntaxToken, statements: ISyntaxList): CaseSwitchClauseSyntax {
|
||||
return new CaseSwitchClauseSyntax(caseKeyword, expression, colonToken, statements, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
defaultSwitchClause(defaultKeyword: ISyntaxToken, colonToken: ISyntaxToken, statements: ISyntaxList): DefaultSwitchClauseSyntax {
|
||||
return new DefaultSwitchClauseSyntax(defaultKeyword, colonToken, statements, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
breakStatement(breakKeyword: ISyntaxToken, identifier: ISyntaxToken, semicolonToken: ISyntaxToken): BreakStatementSyntax {
|
||||
return new BreakStatementSyntax(breakKeyword, identifier, semicolonToken, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
continueStatement(continueKeyword: ISyntaxToken, identifier: ISyntaxToken, semicolonToken: ISyntaxToken): ContinueStatementSyntax {
|
||||
return new ContinueStatementSyntax(continueKeyword, identifier, semicolonToken, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
forStatement(forKeyword: ISyntaxToken, openParenToken: ISyntaxToken, variableDeclaration: VariableDeclarationSyntax, initializer: IExpressionSyntax, firstSemicolonToken: ISyntaxToken, condition: IExpressionSyntax, secondSemicolonToken: ISyntaxToken, incrementor: IExpressionSyntax, closeParenToken: ISyntaxToken, statement: IStatementSyntax): ForStatementSyntax {
|
||||
return new ForStatementSyntax(forKeyword, openParenToken, variableDeclaration, initializer, firstSemicolonToken, condition, secondSemicolonToken, incrementor, closeParenToken, statement, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
forInStatement(forKeyword: ISyntaxToken, openParenToken: ISyntaxToken, variableDeclaration: VariableDeclarationSyntax, left: IExpressionSyntax, inKeyword: ISyntaxToken, expression: IExpressionSyntax, closeParenToken: ISyntaxToken, statement: IStatementSyntax): ForInStatementSyntax {
|
||||
return new ForInStatementSyntax(forKeyword, openParenToken, variableDeclaration, left, inKeyword, expression, closeParenToken, statement, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
whileStatement(whileKeyword: ISyntaxToken, openParenToken: ISyntaxToken, condition: IExpressionSyntax, closeParenToken: ISyntaxToken, statement: IStatementSyntax): WhileStatementSyntax {
|
||||
return new WhileStatementSyntax(whileKeyword, openParenToken, condition, closeParenToken, statement, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
withStatement(withKeyword: ISyntaxToken, openParenToken: ISyntaxToken, condition: IExpressionSyntax, closeParenToken: ISyntaxToken, statement: IStatementSyntax): WithStatementSyntax {
|
||||
return new WithStatementSyntax(withKeyword, openParenToken, condition, closeParenToken, statement, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
enumDeclaration(modifiers: ISyntaxList, enumKeyword: ISyntaxToken, identifier: ISyntaxToken, openBraceToken: ISyntaxToken, enumElements: ISeparatedSyntaxList, closeBraceToken: ISyntaxToken): EnumDeclarationSyntax {
|
||||
return new EnumDeclarationSyntax(modifiers, enumKeyword, identifier, openBraceToken, enumElements, closeBraceToken, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
enumElement(propertyName: ISyntaxToken, equalsValueClause: EqualsValueClauseSyntax): EnumElementSyntax {
|
||||
return new EnumElementSyntax(propertyName, equalsValueClause, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
castExpression(lessThanToken: ISyntaxToken, type: ITypeSyntax, greaterThanToken: ISyntaxToken, expression: IUnaryExpressionSyntax): CastExpressionSyntax {
|
||||
return new CastExpressionSyntax(lessThanToken, type, greaterThanToken, expression, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
objectLiteralExpression(openBraceToken: ISyntaxToken, propertyAssignments: ISeparatedSyntaxList, closeBraceToken: ISyntaxToken): ObjectLiteralExpressionSyntax {
|
||||
return new ObjectLiteralExpressionSyntax(openBraceToken, propertyAssignments, closeBraceToken, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
simplePropertyAssignment(propertyName: ISyntaxToken, colonToken: ISyntaxToken, expression: IExpressionSyntax): SimplePropertyAssignmentSyntax {
|
||||
return new SimplePropertyAssignmentSyntax(propertyName, colonToken, expression, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
functionPropertyAssignment(propertyName: ISyntaxToken, callSignature: CallSignatureSyntax, block: BlockSyntax): FunctionPropertyAssignmentSyntax {
|
||||
return new FunctionPropertyAssignmentSyntax(propertyName, callSignature, block, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
functionExpression(functionKeyword: ISyntaxToken, identifier: ISyntaxToken, callSignature: CallSignatureSyntax, block: BlockSyntax): FunctionExpressionSyntax {
|
||||
return new FunctionExpressionSyntax(functionKeyword, identifier, callSignature, block, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
emptyStatement(semicolonToken: ISyntaxToken): EmptyStatementSyntax {
|
||||
return new EmptyStatementSyntax(semicolonToken, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
tryStatement(tryKeyword: ISyntaxToken, block: BlockSyntax, catchClause: CatchClauseSyntax, finallyClause: FinallyClauseSyntax): TryStatementSyntax {
|
||||
return new TryStatementSyntax(tryKeyword, block, catchClause, finallyClause, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
catchClause(catchKeyword: ISyntaxToken, openParenToken: ISyntaxToken, identifier: ISyntaxToken, typeAnnotation: TypeAnnotationSyntax, closeParenToken: ISyntaxToken, block: BlockSyntax): CatchClauseSyntax {
|
||||
return new CatchClauseSyntax(catchKeyword, openParenToken, identifier, typeAnnotation, closeParenToken, block, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
finallyClause(finallyKeyword: ISyntaxToken, block: BlockSyntax): FinallyClauseSyntax {
|
||||
return new FinallyClauseSyntax(finallyKeyword, block, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
labeledStatement(identifier: ISyntaxToken, colonToken: ISyntaxToken, statement: IStatementSyntax): LabeledStatementSyntax {
|
||||
return new LabeledStatementSyntax(identifier, colonToken, statement, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
doStatement(doKeyword: ISyntaxToken, statement: IStatementSyntax, whileKeyword: ISyntaxToken, openParenToken: ISyntaxToken, condition: IExpressionSyntax, closeParenToken: ISyntaxToken, semicolonToken: ISyntaxToken): DoStatementSyntax {
|
||||
return new DoStatementSyntax(doKeyword, statement, whileKeyword, openParenToken, condition, closeParenToken, semicolonToken, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
typeOfExpression(typeOfKeyword: ISyntaxToken, expression: IUnaryExpressionSyntax): TypeOfExpressionSyntax {
|
||||
return new TypeOfExpressionSyntax(typeOfKeyword, expression, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
deleteExpression(deleteKeyword: ISyntaxToken, expression: IUnaryExpressionSyntax): DeleteExpressionSyntax {
|
||||
return new DeleteExpressionSyntax(deleteKeyword, expression, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
voidExpression(voidKeyword: ISyntaxToken, expression: IUnaryExpressionSyntax): VoidExpressionSyntax {
|
||||
return new VoidExpressionSyntax(voidKeyword, expression, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
debuggerStatement(debuggerKeyword: ISyntaxToken, semicolonToken: ISyntaxToken): DebuggerStatementSyntax {
|
||||
return new DebuggerStatementSyntax(debuggerKeyword, semicolonToken, /*parsedInStrictMode:*/ true);
|
||||
}
|
||||
}
|
||||
|
||||
export var normalModeFactory: IFactory = new NormalModeFactory();
|
||||
export var strictModeFactory: IFactory = new StrictModeFactory();
|
||||
}
|
||||
@@ -0,0 +1,458 @@
|
||||
///<reference path='syntaxKind.ts' />
|
||||
|
||||
module TypeScript.SyntaxFacts {
|
||||
var textToKeywordKind: any = {
|
||||
"any": SyntaxKind.AnyKeyword,
|
||||
"boolean": SyntaxKind.BooleanKeyword,
|
||||
"break": SyntaxKind.BreakKeyword,
|
||||
"case": SyntaxKind.CaseKeyword,
|
||||
"catch": SyntaxKind.CatchKeyword,
|
||||
"class": SyntaxKind.ClassKeyword,
|
||||
"continue": SyntaxKind.ContinueKeyword,
|
||||
"const": SyntaxKind.ConstKeyword,
|
||||
"constructor": SyntaxKind.ConstructorKeyword,
|
||||
"debugger": SyntaxKind.DebuggerKeyword,
|
||||
"declare": SyntaxKind.DeclareKeyword,
|
||||
"default": SyntaxKind.DefaultKeyword,
|
||||
"delete": SyntaxKind.DeleteKeyword,
|
||||
"do": SyntaxKind.DoKeyword,
|
||||
"else": SyntaxKind.ElseKeyword,
|
||||
"enum": SyntaxKind.EnumKeyword,
|
||||
"export": SyntaxKind.ExportKeyword,
|
||||
"extends": SyntaxKind.ExtendsKeyword,
|
||||
"false": SyntaxKind.FalseKeyword,
|
||||
"finally": SyntaxKind.FinallyKeyword,
|
||||
"for": SyntaxKind.ForKeyword,
|
||||
"function": SyntaxKind.FunctionKeyword,
|
||||
"get": SyntaxKind.GetKeyword,
|
||||
"if": SyntaxKind.IfKeyword,
|
||||
"implements": SyntaxKind.ImplementsKeyword,
|
||||
"import": SyntaxKind.ImportKeyword,
|
||||
"in": SyntaxKind.InKeyword,
|
||||
"instanceof": SyntaxKind.InstanceOfKeyword,
|
||||
"interface": SyntaxKind.InterfaceKeyword,
|
||||
"let": SyntaxKind.LetKeyword,
|
||||
"module": SyntaxKind.ModuleKeyword,
|
||||
"new": SyntaxKind.NewKeyword,
|
||||
"null": SyntaxKind.NullKeyword,
|
||||
"number":SyntaxKind.NumberKeyword,
|
||||
"package": SyntaxKind.PackageKeyword,
|
||||
"private": SyntaxKind.PrivateKeyword,
|
||||
"protected": SyntaxKind.ProtectedKeyword,
|
||||
"public": SyntaxKind.PublicKeyword,
|
||||
"require": SyntaxKind.RequireKeyword,
|
||||
"return": SyntaxKind.ReturnKeyword,
|
||||
"set": SyntaxKind.SetKeyword,
|
||||
"static": SyntaxKind.StaticKeyword,
|
||||
"string": SyntaxKind.StringKeyword,
|
||||
"super": SyntaxKind.SuperKeyword,
|
||||
"switch": SyntaxKind.SwitchKeyword,
|
||||
"this": SyntaxKind.ThisKeyword,
|
||||
"throw": SyntaxKind.ThrowKeyword,
|
||||
"true": SyntaxKind.TrueKeyword,
|
||||
"try": SyntaxKind.TryKeyword,
|
||||
"typeof": SyntaxKind.TypeOfKeyword,
|
||||
"var": SyntaxKind.VarKeyword,
|
||||
"void": SyntaxKind.VoidKeyword,
|
||||
"while": SyntaxKind.WhileKeyword,
|
||||
"with": SyntaxKind.WithKeyword,
|
||||
"yield": SyntaxKind.YieldKeyword,
|
||||
|
||||
"{": SyntaxKind.OpenBraceToken,
|
||||
"}": SyntaxKind.CloseBraceToken,
|
||||
"(": SyntaxKind.OpenParenToken,
|
||||
")": SyntaxKind.CloseParenToken,
|
||||
"[": SyntaxKind.OpenBracketToken,
|
||||
"]": SyntaxKind.CloseBracketToken,
|
||||
".": SyntaxKind.DotToken,
|
||||
"...": SyntaxKind.DotDotDotToken,
|
||||
";": SyntaxKind.SemicolonToken,
|
||||
",": SyntaxKind.CommaToken,
|
||||
"<": SyntaxKind.LessThanToken,
|
||||
">": SyntaxKind.GreaterThanToken,
|
||||
"<=": SyntaxKind.LessThanEqualsToken,
|
||||
">=": SyntaxKind.GreaterThanEqualsToken,
|
||||
"==": SyntaxKind.EqualsEqualsToken,
|
||||
"=>": SyntaxKind.EqualsGreaterThanToken,
|
||||
"!=": SyntaxKind.ExclamationEqualsToken,
|
||||
"===": SyntaxKind.EqualsEqualsEqualsToken,
|
||||
"!==": SyntaxKind.ExclamationEqualsEqualsToken,
|
||||
"+": SyntaxKind.PlusToken,
|
||||
"-": SyntaxKind.MinusToken,
|
||||
"*": SyntaxKind.AsteriskToken,
|
||||
"%": SyntaxKind.PercentToken,
|
||||
"++": SyntaxKind.PlusPlusToken,
|
||||
"--": SyntaxKind.MinusMinusToken,
|
||||
"<<": SyntaxKind.LessThanLessThanToken,
|
||||
">>": SyntaxKind.GreaterThanGreaterThanToken,
|
||||
">>>": SyntaxKind.GreaterThanGreaterThanGreaterThanToken,
|
||||
"&": SyntaxKind.AmpersandToken,
|
||||
"|": SyntaxKind.BarToken,
|
||||
"^": SyntaxKind.CaretToken,
|
||||
"!": SyntaxKind.ExclamationToken,
|
||||
"~": SyntaxKind.TildeToken,
|
||||
"&&": SyntaxKind.AmpersandAmpersandToken,
|
||||
"||": SyntaxKind.BarBarToken,
|
||||
"?": SyntaxKind.QuestionToken,
|
||||
":": SyntaxKind.ColonToken,
|
||||
"=": SyntaxKind.EqualsToken,
|
||||
"+=": SyntaxKind.PlusEqualsToken,
|
||||
"-=": SyntaxKind.MinusEqualsToken,
|
||||
"*=": SyntaxKind.AsteriskEqualsToken,
|
||||
"%=": SyntaxKind.PercentEqualsToken,
|
||||
"<<=": SyntaxKind.LessThanLessThanEqualsToken,
|
||||
">>=": SyntaxKind.GreaterThanGreaterThanEqualsToken,
|
||||
">>>=": SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken,
|
||||
"&=": SyntaxKind.AmpersandEqualsToken,
|
||||
"|=": SyntaxKind.BarEqualsToken,
|
||||
"^=": SyntaxKind.CaretEqualsToken,
|
||||
"/": SyntaxKind.SlashToken,
|
||||
"/=": SyntaxKind.SlashEqualsToken,
|
||||
};
|
||||
|
||||
var kindToText = new Array<string>();
|
||||
|
||||
for (var name in textToKeywordKind) {
|
||||
if (textToKeywordKind.hasOwnProperty(name)) {
|
||||
// Debug.assert(kindToText[textToKeywordKind[name]] === undefined);
|
||||
kindToText[textToKeywordKind[name]] = name;
|
||||
}
|
||||
}
|
||||
|
||||
// Manually work around a bug in the CScript 5.8 runtime where 'constructor' is not
|
||||
// listed when SyntaxFacts.textToKeywordKind is enumerated because it is the name of
|
||||
// the constructor function.
|
||||
kindToText[SyntaxKind.ConstructorKeyword] = "constructor";
|
||||
|
||||
export function getTokenKind(text: string): SyntaxKind {
|
||||
if (textToKeywordKind.hasOwnProperty(text)) {
|
||||
return textToKeywordKind[text];
|
||||
}
|
||||
|
||||
return SyntaxKind.None;
|
||||
}
|
||||
|
||||
export function getText(kind: SyntaxKind): string {
|
||||
var result = kindToText[kind];
|
||||
return result !== undefined ? result : null;
|
||||
}
|
||||
|
||||
export function isTokenKind(kind: SyntaxKind): boolean {
|
||||
return kind >= SyntaxKind.FirstToken && kind <= SyntaxKind.LastToken;
|
||||
}
|
||||
|
||||
export function isAnyKeyword(kind: SyntaxKind): boolean {
|
||||
return kind >= SyntaxKind.FirstKeyword && kind <= SyntaxKind.LastKeyword;
|
||||
}
|
||||
|
||||
export function isStandardKeyword(kind: SyntaxKind): boolean {
|
||||
return kind >= SyntaxKind.FirstStandardKeyword && kind <= SyntaxKind.LastStandardKeyword;
|
||||
}
|
||||
|
||||
export function isFutureReservedKeyword(kind: SyntaxKind): boolean {
|
||||
return kind >= SyntaxKind.FirstFutureReservedKeyword && kind <= SyntaxKind.LastFutureReservedKeyword;
|
||||
}
|
||||
|
||||
export function isFutureReservedStrictKeyword(kind: SyntaxKind): boolean {
|
||||
return kind >= SyntaxKind.FirstFutureReservedStrictKeyword && kind <= SyntaxKind.LastFutureReservedStrictKeyword;
|
||||
}
|
||||
|
||||
export function isAnyPunctuation(kind: SyntaxKind): boolean {
|
||||
return kind >= SyntaxKind.FirstPunctuation && kind <= SyntaxKind.LastPunctuation;
|
||||
}
|
||||
|
||||
export function isPrefixUnaryExpressionOperatorToken(tokenKind: SyntaxKind): boolean {
|
||||
return getPrefixUnaryExpressionFromOperatorToken(tokenKind) !== SyntaxKind.None;
|
||||
}
|
||||
|
||||
export function isBinaryExpressionOperatorToken(tokenKind: SyntaxKind): boolean {
|
||||
return getBinaryExpressionFromOperatorToken(tokenKind) !== SyntaxKind.None;
|
||||
}
|
||||
|
||||
export function getPrefixUnaryExpressionFromOperatorToken(tokenKind: SyntaxKind): SyntaxKind {
|
||||
switch (tokenKind) {
|
||||
case SyntaxKind.PlusToken:
|
||||
return SyntaxKind.PlusExpression;
|
||||
case SyntaxKind.MinusToken:
|
||||
return SyntaxKind.NegateExpression;
|
||||
case SyntaxKind.TildeToken:
|
||||
return SyntaxKind.BitwiseNotExpression;
|
||||
case SyntaxKind.ExclamationToken:
|
||||
return SyntaxKind.LogicalNotExpression;
|
||||
case SyntaxKind.PlusPlusToken:
|
||||
return SyntaxKind.PreIncrementExpression;
|
||||
case SyntaxKind.MinusMinusToken:
|
||||
return SyntaxKind.PreDecrementExpression;
|
||||
//case SyntaxKind.DeleteKeyword:
|
||||
// return SyntaxKind.DeleteExpression;
|
||||
//case SyntaxKind.TypeOfKeyword:
|
||||
// return SyntaxKind.TypeOfExpression;
|
||||
//case SyntaxKind.VoidKeyword:
|
||||
// return SyntaxKind.VoidExpression;
|
||||
default:
|
||||
return SyntaxKind.None;
|
||||
}
|
||||
}
|
||||
|
||||
export function getPostfixUnaryExpressionFromOperatorToken(tokenKind: SyntaxKind): SyntaxKind {
|
||||
switch (tokenKind) {
|
||||
case SyntaxKind.PlusPlusToken:
|
||||
return SyntaxKind.PostIncrementExpression;
|
||||
case SyntaxKind.MinusMinusToken:
|
||||
return SyntaxKind.PostDecrementExpression;
|
||||
default:
|
||||
return SyntaxKind.None;
|
||||
}
|
||||
}
|
||||
|
||||
export function getBinaryExpressionFromOperatorToken(tokenKind: SyntaxKind): SyntaxKind {
|
||||
switch (tokenKind) {
|
||||
case SyntaxKind.AsteriskToken:
|
||||
return SyntaxKind.MultiplyExpression;
|
||||
|
||||
case SyntaxKind.SlashToken:
|
||||
return SyntaxKind.DivideExpression;
|
||||
|
||||
case SyntaxKind.PercentToken:
|
||||
return SyntaxKind.ModuloExpression;
|
||||
|
||||
case SyntaxKind.PlusToken:
|
||||
return SyntaxKind.AddExpression;
|
||||
|
||||
case SyntaxKind.MinusToken:
|
||||
return SyntaxKind.SubtractExpression;
|
||||
|
||||
case SyntaxKind.LessThanLessThanToken:
|
||||
return SyntaxKind.LeftShiftExpression;
|
||||
|
||||
case SyntaxKind.GreaterThanGreaterThanToken:
|
||||
return SyntaxKind.SignedRightShiftExpression;
|
||||
|
||||
case SyntaxKind.GreaterThanGreaterThanGreaterThanToken:
|
||||
return SyntaxKind.UnsignedRightShiftExpression;
|
||||
|
||||
case SyntaxKind.LessThanToken:
|
||||
return SyntaxKind.LessThanExpression;
|
||||
|
||||
case SyntaxKind.GreaterThanToken:
|
||||
return SyntaxKind.GreaterThanExpression;
|
||||
|
||||
case SyntaxKind.LessThanEqualsToken:
|
||||
return SyntaxKind.LessThanOrEqualExpression;
|
||||
|
||||
case SyntaxKind.GreaterThanEqualsToken:
|
||||
return SyntaxKind.GreaterThanOrEqualExpression;
|
||||
|
||||
case SyntaxKind.InstanceOfKeyword:
|
||||
return SyntaxKind.InstanceOfExpression;
|
||||
|
||||
case SyntaxKind.InKeyword:
|
||||
return SyntaxKind.InExpression;
|
||||
|
||||
case SyntaxKind.EqualsEqualsToken:
|
||||
return SyntaxKind.EqualsWithTypeConversionExpression;
|
||||
|
||||
case SyntaxKind.ExclamationEqualsToken:
|
||||
return SyntaxKind.NotEqualsWithTypeConversionExpression;
|
||||
|
||||
case SyntaxKind.EqualsEqualsEqualsToken:
|
||||
return SyntaxKind.EqualsExpression;
|
||||
|
||||
case SyntaxKind.ExclamationEqualsEqualsToken:
|
||||
return SyntaxKind.NotEqualsExpression;
|
||||
|
||||
case SyntaxKind.AmpersandToken:
|
||||
return SyntaxKind.BitwiseAndExpression;
|
||||
|
||||
case SyntaxKind.CaretToken:
|
||||
return SyntaxKind.BitwiseExclusiveOrExpression;
|
||||
|
||||
case SyntaxKind.BarToken:
|
||||
return SyntaxKind.BitwiseOrExpression;
|
||||
|
||||
case SyntaxKind.AmpersandAmpersandToken:
|
||||
return SyntaxKind.LogicalAndExpression;
|
||||
|
||||
case SyntaxKind.BarBarToken:
|
||||
return SyntaxKind.LogicalOrExpression;
|
||||
|
||||
case SyntaxKind.BarEqualsToken:
|
||||
return SyntaxKind.OrAssignmentExpression;
|
||||
|
||||
case SyntaxKind.AmpersandEqualsToken:
|
||||
return SyntaxKind.AndAssignmentExpression;
|
||||
|
||||
case SyntaxKind.CaretEqualsToken:
|
||||
return SyntaxKind.ExclusiveOrAssignmentExpression;
|
||||
|
||||
case SyntaxKind.LessThanLessThanEqualsToken:
|
||||
return SyntaxKind.LeftShiftAssignmentExpression;
|
||||
|
||||
case SyntaxKind.GreaterThanGreaterThanEqualsToken:
|
||||
return SyntaxKind.SignedRightShiftAssignmentExpression;
|
||||
|
||||
case SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken:
|
||||
return SyntaxKind.UnsignedRightShiftAssignmentExpression;
|
||||
|
||||
case SyntaxKind.PlusEqualsToken:
|
||||
return SyntaxKind.AddAssignmentExpression;
|
||||
|
||||
case SyntaxKind.MinusEqualsToken:
|
||||
return SyntaxKind.SubtractAssignmentExpression;
|
||||
|
||||
case SyntaxKind.AsteriskEqualsToken:
|
||||
return SyntaxKind.MultiplyAssignmentExpression;
|
||||
|
||||
case SyntaxKind.SlashEqualsToken:
|
||||
return SyntaxKind.DivideAssignmentExpression;
|
||||
|
||||
case SyntaxKind.PercentEqualsToken:
|
||||
return SyntaxKind.ModuloAssignmentExpression;
|
||||
|
||||
case SyntaxKind.EqualsToken:
|
||||
return SyntaxKind.AssignmentExpression;
|
||||
|
||||
case SyntaxKind.CommaToken:
|
||||
return SyntaxKind.CommaExpression;
|
||||
|
||||
default:
|
||||
return SyntaxKind.None;
|
||||
}
|
||||
}
|
||||
|
||||
export function getOperatorTokenFromBinaryExpression(tokenKind: SyntaxKind): SyntaxKind {
|
||||
switch (tokenKind) {
|
||||
case SyntaxKind.MultiplyExpression:
|
||||
return SyntaxKind.AsteriskToken;
|
||||
|
||||
case SyntaxKind.DivideExpression:
|
||||
return SyntaxKind.SlashToken;
|
||||
|
||||
case SyntaxKind.ModuloExpression:
|
||||
return SyntaxKind.PercentToken;
|
||||
|
||||
case SyntaxKind.AddExpression:
|
||||
return SyntaxKind.PlusToken;
|
||||
|
||||
case SyntaxKind.SubtractExpression:
|
||||
return SyntaxKind.MinusToken;
|
||||
|
||||
case SyntaxKind.LeftShiftExpression:
|
||||
return SyntaxKind.LessThanLessThanToken;
|
||||
|
||||
case SyntaxKind.SignedRightShiftExpression:
|
||||
return SyntaxKind.GreaterThanGreaterThanToken;
|
||||
|
||||
case SyntaxKind.UnsignedRightShiftExpression:
|
||||
return SyntaxKind.GreaterThanGreaterThanGreaterThanToken;
|
||||
|
||||
case SyntaxKind.LessThanExpression:
|
||||
return SyntaxKind.LessThanToken;
|
||||
|
||||
case SyntaxKind.GreaterThanExpression:
|
||||
return SyntaxKind.GreaterThanToken;
|
||||
|
||||
case SyntaxKind.LessThanOrEqualExpression:
|
||||
return SyntaxKind.LessThanEqualsToken;
|
||||
|
||||
case SyntaxKind.GreaterThanOrEqualExpression:
|
||||
return SyntaxKind.GreaterThanEqualsToken;
|
||||
|
||||
case SyntaxKind.InstanceOfExpression:
|
||||
return SyntaxKind.InstanceOfKeyword;
|
||||
|
||||
case SyntaxKind.InExpression:
|
||||
return SyntaxKind.InKeyword;
|
||||
|
||||
case SyntaxKind.EqualsWithTypeConversionExpression:
|
||||
return SyntaxKind.EqualsEqualsToken;
|
||||
|
||||
case SyntaxKind.NotEqualsWithTypeConversionExpression:
|
||||
return SyntaxKind.ExclamationEqualsToken;
|
||||
|
||||
case SyntaxKind.EqualsExpression:
|
||||
return SyntaxKind.EqualsEqualsEqualsToken;
|
||||
|
||||
case SyntaxKind.NotEqualsExpression:
|
||||
return SyntaxKind.ExclamationEqualsEqualsToken;
|
||||
|
||||
case SyntaxKind.BitwiseAndExpression:
|
||||
return SyntaxKind.AmpersandToken;
|
||||
|
||||
case SyntaxKind.BitwiseExclusiveOrExpression:
|
||||
return SyntaxKind.CaretToken;
|
||||
|
||||
case SyntaxKind.BitwiseOrExpression:
|
||||
return SyntaxKind.BarToken;
|
||||
|
||||
case SyntaxKind.LogicalAndExpression:
|
||||
return SyntaxKind.AmpersandAmpersandToken;
|
||||
|
||||
case SyntaxKind.LogicalOrExpression:
|
||||
return SyntaxKind.BarBarToken;
|
||||
|
||||
case SyntaxKind.OrAssignmentExpression:
|
||||
return SyntaxKind.BarEqualsToken;
|
||||
|
||||
case SyntaxKind.AndAssignmentExpression:
|
||||
return SyntaxKind.AmpersandEqualsToken;
|
||||
|
||||
case SyntaxKind.ExclusiveOrAssignmentExpression:
|
||||
return SyntaxKind.CaretEqualsToken;
|
||||
|
||||
case SyntaxKind.LeftShiftAssignmentExpression:
|
||||
return SyntaxKind.LessThanLessThanEqualsToken;
|
||||
|
||||
case SyntaxKind.SignedRightShiftAssignmentExpression:
|
||||
return SyntaxKind.GreaterThanGreaterThanEqualsToken;
|
||||
|
||||
case SyntaxKind.UnsignedRightShiftAssignmentExpression:
|
||||
return SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken;
|
||||
|
||||
case SyntaxKind.AddAssignmentExpression:
|
||||
return SyntaxKind.PlusEqualsToken;
|
||||
|
||||
case SyntaxKind.SubtractAssignmentExpression:
|
||||
return SyntaxKind.MinusEqualsToken;
|
||||
|
||||
case SyntaxKind.MultiplyAssignmentExpression:
|
||||
return SyntaxKind.AsteriskEqualsToken;
|
||||
|
||||
case SyntaxKind.DivideAssignmentExpression:
|
||||
return SyntaxKind.SlashEqualsToken;
|
||||
|
||||
case SyntaxKind.ModuloAssignmentExpression:
|
||||
return SyntaxKind.PercentEqualsToken;
|
||||
|
||||
case SyntaxKind.AssignmentExpression:
|
||||
return SyntaxKind.EqualsToken;
|
||||
|
||||
case SyntaxKind.CommaExpression:
|
||||
return SyntaxKind.CommaToken;
|
||||
|
||||
default:
|
||||
return SyntaxKind.None;
|
||||
}
|
||||
}
|
||||
|
||||
export function isAnyDivideToken(kind: SyntaxKind): boolean {
|
||||
switch (kind) {
|
||||
case SyntaxKind.SlashToken:
|
||||
case SyntaxKind.SlashEqualsToken:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function isAnyDivideOrRegularExpressionToken(kind: SyntaxKind): boolean {
|
||||
switch (kind) {
|
||||
case SyntaxKind.SlashToken:
|
||||
case SyntaxKind.SlashEqualsToken:
|
||||
case SyntaxKind.RegularExpressionLiteral:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript.SyntaxFacts {
|
||||
export function isDirectivePrologueElement(node: ISyntaxNodeOrToken): boolean {
|
||||
if (node.kind() === SyntaxKind.ExpressionStatement) {
|
||||
var expressionStatement = <ExpressionStatementSyntax>node;
|
||||
var expression = expressionStatement.expression;
|
||||
|
||||
if (expression.kind() === SyntaxKind.StringLiteral) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export function isUseStrictDirective(node: ISyntaxNodeOrToken): boolean {
|
||||
var expressionStatement = <ExpressionStatementSyntax>node;
|
||||
var stringLiteral = <ISyntaxToken>expressionStatement.expression;
|
||||
|
||||
var text = stringLiteral.text();
|
||||
return text === '"use strict"' || text === "'use strict'";
|
||||
}
|
||||
|
||||
export function isIdentifierNameOrAnyKeyword(token: ISyntaxToken): boolean {
|
||||
var tokenKind = token.tokenKind;
|
||||
return tokenKind === SyntaxKind.IdentifierName || SyntaxFacts.isAnyKeyword(tokenKind);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,164 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export class SyntaxIndenter extends SyntaxRewriter {
|
||||
private lastTriviaWasNewLine: boolean;
|
||||
private indentationTrivia: ISyntaxTrivia;
|
||||
|
||||
constructor(indentFirstToken: boolean,
|
||||
private indentationAmount: number,
|
||||
private options: FormattingOptions) {
|
||||
super();
|
||||
this.lastTriviaWasNewLine = indentFirstToken;
|
||||
this.indentationTrivia = Indentation.indentationTrivia(this.indentationAmount, this.options);
|
||||
}
|
||||
|
||||
public visitToken(token: ISyntaxToken): ISyntaxToken {
|
||||
if (token.width() === 0) {
|
||||
return token;
|
||||
}
|
||||
|
||||
var result = token;
|
||||
if (this.lastTriviaWasNewLine) {
|
||||
// have to add our indentation to every line that this token hits.
|
||||
result = token.withLeadingTrivia(this.indentTriviaList(token.leadingTrivia()));
|
||||
}
|
||||
|
||||
this.lastTriviaWasNewLine = token.hasTrailingNewLine();
|
||||
return result;
|
||||
}
|
||||
|
||||
public indentTriviaList(triviaList: ISyntaxTriviaList): ISyntaxTriviaList {
|
||||
var result: ISyntaxTrivia[] = [];
|
||||
|
||||
// First, update any existing trivia with the indent amount. For example, combine the
|
||||
// indent with any whitespace trivia, or prepend any comments with the trivia.
|
||||
var indentNextTrivia = true;
|
||||
for (var i = 0, n = triviaList.count(); i < n; i++) {
|
||||
var trivia = triviaList.syntaxTriviaAt(i);
|
||||
|
||||
var indentThisTrivia = indentNextTrivia;
|
||||
indentNextTrivia = false;
|
||||
|
||||
switch (trivia.kind()) {
|
||||
case SyntaxKind.MultiLineCommentTrivia:
|
||||
this.indentMultiLineComment(trivia, indentThisTrivia, result);
|
||||
continue;
|
||||
|
||||
case SyntaxKind.SingleLineCommentTrivia:
|
||||
case SyntaxKind.SkippedTokenTrivia:
|
||||
this.indentSingleLineOrSkippedText(trivia, indentThisTrivia, result);
|
||||
continue;
|
||||
|
||||
case SyntaxKind.WhitespaceTrivia:
|
||||
this.indentWhitespace(trivia, indentThisTrivia, result);
|
||||
continue;
|
||||
|
||||
case SyntaxKind.NewLineTrivia:
|
||||
// We hit a newline processing the trivia. We need to add the indentation to the
|
||||
// next line as well. Note: don't bother indenting the newline itself. This will
|
||||
// just insert ugly whitespace that most users probably will not want.
|
||||
result.push(trivia);
|
||||
indentNextTrivia = true;
|
||||
continue;
|
||||
|
||||
default:
|
||||
throw Errors.invalidOperation();
|
||||
}
|
||||
}
|
||||
|
||||
// Then, if the last trivia was a newline (or there was no trivia at all), then just add the
|
||||
// indentation in right before the token.
|
||||
if (indentNextTrivia) {
|
||||
result.push(this.indentationTrivia);
|
||||
}
|
||||
|
||||
return Syntax.triviaList(result);
|
||||
}
|
||||
|
||||
private indentSegment(segment: string): string {
|
||||
// Find the position of the first non whitespace character in the segment.
|
||||
var firstNonWhitespacePosition = Indentation.firstNonWhitespacePosition(segment);
|
||||
|
||||
if (firstNonWhitespacePosition < segment.length &&
|
||||
CharacterInfo.isLineTerminator(segment.charCodeAt(firstNonWhitespacePosition))) {
|
||||
|
||||
// If this segment was just a newline, then don't bother indenting it. That will just
|
||||
// leave the user with an ugly indent in their output that they probably do not want.
|
||||
return segment;
|
||||
}
|
||||
|
||||
// Convert that position to a column.
|
||||
var firstNonWhitespaceColumn = Indentation.columnForPositionInString(segment, firstNonWhitespacePosition, this.options);
|
||||
|
||||
// Find the new column we want the nonwhitespace text to start at.
|
||||
var newFirstNonWhitespaceColumn = firstNonWhitespaceColumn + this.indentationAmount;
|
||||
|
||||
// Compute an indentation string for that.
|
||||
var indentationString = Indentation.indentationString(newFirstNonWhitespaceColumn, this.options);
|
||||
|
||||
// Join the new indentation and the original string without its indentation.
|
||||
return indentationString + segment.substring(firstNonWhitespacePosition);
|
||||
}
|
||||
|
||||
private indentWhitespace(trivia: ISyntaxTrivia, indentThisTrivia: boolean, result: ISyntaxTrivia[]): void {
|
||||
if (!indentThisTrivia) {
|
||||
// Line didn't start with this trivia. So no need to touch it. Just add to the result
|
||||
// and continue on.
|
||||
result.push(trivia);
|
||||
return;
|
||||
}
|
||||
|
||||
// Line started with this trivia. We want to figure out what the final column this
|
||||
// whitespace goes to will be. To do that we add the column it is at now to the column we
|
||||
// want to indent to. We then compute the final tabs+whitespace string for that.
|
||||
var newIndentation = this.indentSegment(trivia.fullText());
|
||||
result.push(Syntax.whitespace(newIndentation));
|
||||
}
|
||||
|
||||
private indentSingleLineOrSkippedText(trivia: ISyntaxTrivia, indentThisTrivia: boolean, result: ISyntaxTrivia[]): void {
|
||||
if (indentThisTrivia) {
|
||||
// The line started with a comment or skipped text. Add an indentation based
|
||||
// on the desired settings, and then add the trivia itself.
|
||||
result.push(this.indentationTrivia);
|
||||
}
|
||||
|
||||
result.push(trivia);
|
||||
}
|
||||
|
||||
private indentMultiLineComment(trivia: ISyntaxTrivia, indentThisTrivia: boolean, result: ISyntaxTrivia[]): void {
|
||||
if (indentThisTrivia) {
|
||||
// The line started with a multiline comment. Add an indentation based
|
||||
// on the desired settings, and then add the trivia itself.
|
||||
result.push(this.indentationTrivia);
|
||||
}
|
||||
|
||||
// If the multiline comment spans multiple lines, we need to add the right indent amount to
|
||||
// each successive line segment as well.
|
||||
var segments = Syntax.splitMultiLineCommentTriviaIntoMultipleLines(trivia);
|
||||
|
||||
for (var i = 1; i < segments.length; i++) {
|
||||
segments[i] = this.indentSegment(segments[i]);
|
||||
}
|
||||
|
||||
var newText = segments.join("");
|
||||
result.push(Syntax.multiLineComment(newText));
|
||||
}
|
||||
|
||||
public static indentNode(node: ISyntaxNode, indentFirstToken: boolean, indentAmount: number, options: FormattingOptions): SyntaxNode {
|
||||
var indenter = new SyntaxIndenter(indentFirstToken, indentAmount, options);
|
||||
return node.accept(indenter);
|
||||
}
|
||||
|
||||
public static indentNodes(nodes: SyntaxNode[], indentFirstToken: boolean, indentAmount: number, options: FormattingOptions): SyntaxNode[] {
|
||||
// Note: it is necessary for correctness that we reuse the same SyntaxIndenter here.
|
||||
// That's because when working on nodes 1-N, we need to know if the previous node ended
|
||||
// with a newline. The indenter will track that for us.
|
||||
|
||||
var indenter = new SyntaxIndenter(indentFirstToken, indentAmount, options);
|
||||
var result: SyntaxNode[] = ArrayUtilities.select<any, any>(nodes, n => n.accept(indenter));
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export interface ITokenInformation {
|
||||
previousToken: ISyntaxToken;
|
||||
nextToken: ISyntaxToken;
|
||||
}
|
||||
|
||||
export class SyntaxInformationMap extends SyntaxWalker {
|
||||
private tokenToInformation = Collections.createHashTable<any, any>(Collections.DefaultHashTableCapacity, Collections.identityHashCode);
|
||||
private elementToPosition = Collections.createHashTable<any, any>(Collections.DefaultHashTableCapacity, Collections.identityHashCode);
|
||||
|
||||
private _previousToken: ISyntaxToken = null;
|
||||
private _previousTokenInformation: ITokenInformation = null;
|
||||
private _currentPosition = 0;
|
||||
private _elementToParent = Collections.createHashTable<any, any>(Collections.DefaultHashTableCapacity, Collections.identityHashCode);
|
||||
|
||||
private _parentStack: SyntaxNode[] = [];
|
||||
|
||||
constructor(private trackParents: boolean, private trackPreviousToken: boolean) {
|
||||
super();
|
||||
this._parentStack.push(null);
|
||||
}
|
||||
|
||||
public static create(node: SyntaxNode, trackParents: boolean, trackPreviousToken: boolean): SyntaxInformationMap {
|
||||
var map = new SyntaxInformationMap(trackParents, trackPreviousToken);
|
||||
map.visitNode(node);
|
||||
return map;
|
||||
}
|
||||
|
||||
public visitNode(node: SyntaxNode): void {
|
||||
this.trackParents && this._elementToParent.add(node, ArrayUtilities.last(this._parentStack));
|
||||
this.elementToPosition.add(node, this._currentPosition);
|
||||
|
||||
this.trackParents && this._parentStack.push(node);
|
||||
super.visitNode(node);
|
||||
this.trackParents && this._parentStack.pop();
|
||||
}
|
||||
|
||||
public visitToken(token: ISyntaxToken): void {
|
||||
this.trackParents && this._elementToParent.add(token, ArrayUtilities.last(this._parentStack));
|
||||
|
||||
if (this.trackPreviousToken) {
|
||||
var tokenInformation: ITokenInformation = {
|
||||
previousToken: this._previousToken,
|
||||
nextToken: null
|
||||
};
|
||||
|
||||
if (this._previousTokenInformation !== null) {
|
||||
this._previousTokenInformation.nextToken = token;
|
||||
}
|
||||
|
||||
this._previousToken = token;
|
||||
this._previousTokenInformation = tokenInformation;
|
||||
|
||||
this.tokenToInformation.add(token, tokenInformation);
|
||||
}
|
||||
|
||||
this.elementToPosition.add(token, this._currentPosition);
|
||||
this._currentPosition += token.fullWidth();
|
||||
}
|
||||
|
||||
public parent(element: ISyntaxElement): SyntaxNode {
|
||||
return this._elementToParent.get(element);
|
||||
}
|
||||
|
||||
public fullStart(element: ISyntaxElement): number {
|
||||
return this.elementToPosition.get(element);
|
||||
}
|
||||
|
||||
public start(element: ISyntaxElement): number {
|
||||
return this.fullStart(element) + element.leadingTriviaWidth();
|
||||
}
|
||||
|
||||
public end(element: ISyntaxElement): number {
|
||||
return this.start(element) + element.width();
|
||||
}
|
||||
|
||||
public previousToken(token: ISyntaxToken): ISyntaxToken {
|
||||
return this.tokenInformation(token).previousToken;
|
||||
}
|
||||
|
||||
public tokenInformation(token: ISyntaxToken): ITokenInformation {
|
||||
return this.tokenToInformation.get(token);
|
||||
}
|
||||
|
||||
public firstTokenInLineContainingToken(token: ISyntaxToken): ISyntaxToken {
|
||||
var current = token;
|
||||
while (true) {
|
||||
var information = this.tokenInformation(current);
|
||||
if (this.isFirstTokenInLineWorker(information)) {
|
||||
break;
|
||||
}
|
||||
|
||||
current = information.previousToken;
|
||||
}
|
||||
|
||||
return current;
|
||||
}
|
||||
|
||||
public isFirstTokenInLine(token: ISyntaxToken): boolean {
|
||||
var information = this.tokenInformation(token);
|
||||
return this.isFirstTokenInLineWorker(information);
|
||||
|
||||
}
|
||||
|
||||
private isFirstTokenInLineWorker(information: ITokenInformation): boolean {
|
||||
return information.previousToken === null || information.previousToken.hasTrailingNewLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,335 @@
|
||||
// If you change anything in this enum, make sure you run SyntaxGenerator again!
|
||||
|
||||
module TypeScript {
|
||||
export enum SyntaxKind {
|
||||
// Variable width tokens, trivia and lists.
|
||||
None,
|
||||
List,
|
||||
SeparatedList,
|
||||
TriviaList,
|
||||
|
||||
// Trivia
|
||||
WhitespaceTrivia,
|
||||
NewLineTrivia,
|
||||
MultiLineCommentTrivia,
|
||||
SingleLineCommentTrivia,
|
||||
SkippedTokenTrivia,
|
||||
|
||||
// Note: all variable width tokens must come before all fixed width tokens.
|
||||
|
||||
ErrorToken,
|
||||
EndOfFileToken,
|
||||
|
||||
// Tokens
|
||||
IdentifierName,
|
||||
|
||||
// LiteralTokens
|
||||
RegularExpressionLiteral,
|
||||
NumericLiteral,
|
||||
StringLiteral,
|
||||
|
||||
// All fixed width tokens follow.
|
||||
|
||||
// Keywords
|
||||
BreakKeyword,
|
||||
CaseKeyword,
|
||||
CatchKeyword,
|
||||
ContinueKeyword,
|
||||
DebuggerKeyword,
|
||||
DefaultKeyword,
|
||||
DeleteKeyword,
|
||||
DoKeyword,
|
||||
ElseKeyword,
|
||||
FalseKeyword,
|
||||
FinallyKeyword,
|
||||
ForKeyword,
|
||||
FunctionKeyword,
|
||||
IfKeyword,
|
||||
InKeyword,
|
||||
InstanceOfKeyword,
|
||||
NewKeyword,
|
||||
NullKeyword,
|
||||
ReturnKeyword,
|
||||
SwitchKeyword,
|
||||
ThisKeyword,
|
||||
ThrowKeyword,
|
||||
TrueKeyword,
|
||||
TryKeyword,
|
||||
TypeOfKeyword,
|
||||
VarKeyword,
|
||||
VoidKeyword,
|
||||
WhileKeyword,
|
||||
WithKeyword,
|
||||
|
||||
// FutureReservedWords.
|
||||
ClassKeyword,
|
||||
ConstKeyword,
|
||||
EnumKeyword,
|
||||
ExportKeyword,
|
||||
ExtendsKeyword,
|
||||
ImportKeyword,
|
||||
SuperKeyword,
|
||||
|
||||
// FutureReservedStrictWords.
|
||||
ImplementsKeyword,
|
||||
InterfaceKeyword,
|
||||
LetKeyword,
|
||||
PackageKeyword,
|
||||
PrivateKeyword,
|
||||
ProtectedKeyword,
|
||||
PublicKeyword,
|
||||
StaticKeyword,
|
||||
YieldKeyword,
|
||||
|
||||
// TypeScript keywords.
|
||||
AnyKeyword,
|
||||
BooleanKeyword,
|
||||
ConstructorKeyword,
|
||||
DeclareKeyword,
|
||||
GetKeyword,
|
||||
ModuleKeyword,
|
||||
RequireKeyword,
|
||||
NumberKeyword,
|
||||
SetKeyword,
|
||||
StringKeyword,
|
||||
|
||||
// Punctuators
|
||||
OpenBraceToken,
|
||||
CloseBraceToken,
|
||||
OpenParenToken,
|
||||
CloseParenToken,
|
||||
OpenBracketToken,
|
||||
CloseBracketToken,
|
||||
DotToken,
|
||||
DotDotDotToken,
|
||||
SemicolonToken,
|
||||
CommaToken,
|
||||
LessThanToken,
|
||||
GreaterThanToken,
|
||||
LessThanEqualsToken,
|
||||
GreaterThanEqualsToken,
|
||||
EqualsEqualsToken,
|
||||
EqualsGreaterThanToken,
|
||||
ExclamationEqualsToken,
|
||||
EqualsEqualsEqualsToken,
|
||||
ExclamationEqualsEqualsToken,
|
||||
PlusToken,
|
||||
MinusToken,
|
||||
AsteriskToken,
|
||||
PercentToken,
|
||||
PlusPlusToken,
|
||||
MinusMinusToken,
|
||||
LessThanLessThanToken,
|
||||
GreaterThanGreaterThanToken,
|
||||
GreaterThanGreaterThanGreaterThanToken,
|
||||
AmpersandToken,
|
||||
BarToken,
|
||||
CaretToken,
|
||||
ExclamationToken,
|
||||
TildeToken,
|
||||
AmpersandAmpersandToken,
|
||||
BarBarToken,
|
||||
QuestionToken,
|
||||
ColonToken,
|
||||
EqualsToken,
|
||||
PlusEqualsToken,
|
||||
MinusEqualsToken,
|
||||
AsteriskEqualsToken,
|
||||
PercentEqualsToken,
|
||||
LessThanLessThanEqualsToken,
|
||||
GreaterThanGreaterThanEqualsToken,
|
||||
GreaterThanGreaterThanGreaterThanEqualsToken,
|
||||
AmpersandEqualsToken,
|
||||
BarEqualsToken,
|
||||
CaretEqualsToken,
|
||||
SlashToken,
|
||||
SlashEqualsToken,
|
||||
|
||||
// SyntaxNodes
|
||||
SourceUnit,
|
||||
|
||||
// Names
|
||||
QualifiedName,
|
||||
|
||||
// Types
|
||||
ObjectType,
|
||||
FunctionType,
|
||||
ArrayType,
|
||||
ConstructorType,
|
||||
GenericType,
|
||||
TypeQuery,
|
||||
|
||||
// Module elements.
|
||||
InterfaceDeclaration,
|
||||
FunctionDeclaration,
|
||||
ModuleDeclaration,
|
||||
ClassDeclaration,
|
||||
EnumDeclaration,
|
||||
ImportDeclaration,
|
||||
ExportAssignment,
|
||||
|
||||
// ClassElements
|
||||
MemberFunctionDeclaration,
|
||||
MemberVariableDeclaration,
|
||||
ConstructorDeclaration,
|
||||
IndexMemberDeclaration,
|
||||
|
||||
// ClassElement and PropertyAssignment
|
||||
GetAccessor,
|
||||
SetAccessor,
|
||||
|
||||
// Type members.
|
||||
PropertySignature,
|
||||
CallSignature,
|
||||
ConstructSignature,
|
||||
IndexSignature,
|
||||
MethodSignature,
|
||||
|
||||
// Statements
|
||||
Block,
|
||||
IfStatement,
|
||||
VariableStatement,
|
||||
ExpressionStatement,
|
||||
ReturnStatement,
|
||||
SwitchStatement,
|
||||
BreakStatement,
|
||||
ContinueStatement,
|
||||
ForStatement,
|
||||
ForInStatement,
|
||||
EmptyStatement,
|
||||
ThrowStatement,
|
||||
WhileStatement,
|
||||
TryStatement,
|
||||
LabeledStatement,
|
||||
DoStatement,
|
||||
DebuggerStatement,
|
||||
WithStatement,
|
||||
|
||||
// Expressions
|
||||
PlusExpression,
|
||||
NegateExpression,
|
||||
BitwiseNotExpression,
|
||||
LogicalNotExpression,
|
||||
PreIncrementExpression,
|
||||
PreDecrementExpression,
|
||||
DeleteExpression,
|
||||
TypeOfExpression,
|
||||
VoidExpression,
|
||||
CommaExpression,
|
||||
AssignmentExpression,
|
||||
AddAssignmentExpression,
|
||||
SubtractAssignmentExpression,
|
||||
MultiplyAssignmentExpression,
|
||||
DivideAssignmentExpression,
|
||||
ModuloAssignmentExpression,
|
||||
AndAssignmentExpression,
|
||||
ExclusiveOrAssignmentExpression,
|
||||
OrAssignmentExpression,
|
||||
LeftShiftAssignmentExpression,
|
||||
SignedRightShiftAssignmentExpression,
|
||||
UnsignedRightShiftAssignmentExpression,
|
||||
ConditionalExpression,
|
||||
LogicalOrExpression,
|
||||
LogicalAndExpression,
|
||||
BitwiseOrExpression,
|
||||
BitwiseExclusiveOrExpression,
|
||||
BitwiseAndExpression,
|
||||
EqualsWithTypeConversionExpression,
|
||||
NotEqualsWithTypeConversionExpression,
|
||||
EqualsExpression,
|
||||
NotEqualsExpression,
|
||||
LessThanExpression,
|
||||
GreaterThanExpression,
|
||||
LessThanOrEqualExpression,
|
||||
GreaterThanOrEqualExpression,
|
||||
InstanceOfExpression,
|
||||
InExpression,
|
||||
LeftShiftExpression,
|
||||
SignedRightShiftExpression,
|
||||
UnsignedRightShiftExpression,
|
||||
MultiplyExpression,
|
||||
DivideExpression,
|
||||
ModuloExpression,
|
||||
AddExpression,
|
||||
SubtractExpression,
|
||||
PostIncrementExpression,
|
||||
PostDecrementExpression,
|
||||
MemberAccessExpression,
|
||||
InvocationExpression,
|
||||
ArrayLiteralExpression,
|
||||
ObjectLiteralExpression,
|
||||
ObjectCreationExpression,
|
||||
ParenthesizedExpression,
|
||||
ParenthesizedArrowFunctionExpression,
|
||||
SimpleArrowFunctionExpression,
|
||||
CastExpression,
|
||||
ElementAccessExpression,
|
||||
FunctionExpression,
|
||||
OmittedExpression,
|
||||
|
||||
// Variable declarations
|
||||
VariableDeclaration,
|
||||
VariableDeclarator,
|
||||
|
||||
// Lists
|
||||
ArgumentList,
|
||||
ParameterList,
|
||||
TypeArgumentList,
|
||||
TypeParameterList,
|
||||
|
||||
// Clauses
|
||||
ExtendsHeritageClause,
|
||||
ImplementsHeritageClause,
|
||||
EqualsValueClause,
|
||||
CaseSwitchClause,
|
||||
DefaultSwitchClause,
|
||||
ElseClause,
|
||||
CatchClause,
|
||||
FinallyClause,
|
||||
|
||||
// Generics
|
||||
TypeParameter,
|
||||
Constraint,
|
||||
|
||||
// Property Assignment
|
||||
SimplePropertyAssignment,
|
||||
// GetAccessorPropertyAssignment,
|
||||
// SetAccessorPropertyAssignment,
|
||||
FunctionPropertyAssignment,
|
||||
|
||||
// Misc.
|
||||
Parameter,
|
||||
EnumElement,
|
||||
TypeAnnotation,
|
||||
ExternalModuleReference,
|
||||
ModuleNameModuleReference,
|
||||
Last = ModuleNameModuleReference,
|
||||
|
||||
FirstStandardKeyword = BreakKeyword,
|
||||
LastStandardKeyword = WithKeyword,
|
||||
|
||||
FirstFutureReservedKeyword = ClassKeyword,
|
||||
LastFutureReservedKeyword = SuperKeyword,
|
||||
|
||||
FirstFutureReservedStrictKeyword = ImplementsKeyword,
|
||||
LastFutureReservedStrictKeyword = YieldKeyword,
|
||||
|
||||
FirstTypeScriptKeyword = AnyKeyword,
|
||||
LastTypeScriptKeyword = StringKeyword,
|
||||
|
||||
FirstKeyword = FirstStandardKeyword,
|
||||
LastKeyword = LastTypeScriptKeyword,
|
||||
|
||||
FirstToken = ErrorToken,
|
||||
LastToken = SlashEqualsToken,
|
||||
|
||||
FirstPunctuation = OpenBraceToken,
|
||||
LastPunctuation = SlashEqualsToken,
|
||||
|
||||
FirstFixedWidth = FirstKeyword,
|
||||
LastFixedWidth = LastPunctuation,
|
||||
|
||||
FirstTrivia = WhitespaceTrivia,
|
||||
LastTrivia = SkippedTokenTrivia,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,364 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export interface ISyntaxList extends ISyntaxElement {
|
||||
childAt(index: number): ISyntaxNodeOrToken;
|
||||
toArray(): ISyntaxNodeOrToken[];
|
||||
|
||||
insertChildrenInto(array: ISyntaxElement[], index: number): void;
|
||||
}
|
||||
}
|
||||
|
||||
module TypeScript.Syntax {
|
||||
// TODO: stop exporting this once typecheck bug is fixed.
|
||||
export class EmptySyntaxList implements ISyntaxList {
|
||||
public kind(): SyntaxKind { return SyntaxKind.List; }
|
||||
|
||||
public isNode(): boolean { return false; }
|
||||
public isToken(): boolean { return false; }
|
||||
public isList(): boolean { return true; }
|
||||
public isSeparatedList(): boolean { return false; }
|
||||
|
||||
public toJSON(key: any): any {
|
||||
return [];
|
||||
}
|
||||
|
||||
public childCount(): number {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public childAt(index: number): ISyntaxNodeOrToken {
|
||||
throw Errors.argumentOutOfRange("index");
|
||||
}
|
||||
|
||||
public toArray(): ISyntaxNodeOrToken[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
public collectTextElements(elements: string[]): void {
|
||||
}
|
||||
|
||||
public firstToken(): ISyntaxToken {
|
||||
return null;
|
||||
}
|
||||
|
||||
public lastToken(): ISyntaxToken {
|
||||
return null;
|
||||
}
|
||||
|
||||
public fullWidth(): number {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public width(): number {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public leadingTrivia(): ISyntaxTriviaList {
|
||||
return Syntax.emptyTriviaList;
|
||||
}
|
||||
|
||||
public trailingTrivia(): ISyntaxTriviaList {
|
||||
return Syntax.emptyTriviaList;
|
||||
}
|
||||
|
||||
public leadingTriviaWidth(): number {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public trailingTriviaWidth(): number {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public fullText(): string {
|
||||
return "";
|
||||
}
|
||||
|
||||
public isTypeScriptSpecific(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
public isIncrementallyUnusable(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
public findTokenInternal(parent: PositionedElement, position: number, fullStart: number): PositionedToken {
|
||||
// This should never have been called on this list. It has a 0 width, so the client
|
||||
// should have skipped over this.
|
||||
throw Errors.invalidOperation();
|
||||
}
|
||||
|
||||
public insertChildrenInto(array: ISyntaxElement[], index: number): void {
|
||||
}
|
||||
}
|
||||
|
||||
export var emptyList: ISyntaxList = new EmptySyntaxList();
|
||||
|
||||
class SingletonSyntaxList implements ISyntaxList {
|
||||
private item: ISyntaxNodeOrToken;
|
||||
|
||||
constructor(item: ISyntaxNodeOrToken) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
public kind(): SyntaxKind { return SyntaxKind.List; }
|
||||
|
||||
public isToken(): boolean { return false; }
|
||||
public isNode(): boolean { return false; }
|
||||
public isList(): boolean { return true; }
|
||||
public isSeparatedList(): boolean { return false; }
|
||||
|
||||
public toJSON(key: any) {
|
||||
return [this.item];
|
||||
}
|
||||
|
||||
public childCount() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public childAt(index: number): ISyntaxNodeOrToken {
|
||||
if (index !== 0) {
|
||||
throw Errors.argumentOutOfRange("index");
|
||||
}
|
||||
|
||||
return this.item;
|
||||
}
|
||||
|
||||
public toArray(): ISyntaxNodeOrToken[] {
|
||||
return [this.item];
|
||||
}
|
||||
|
||||
public collectTextElements(elements: string[]): void {
|
||||
this.item.collectTextElements(elements);
|
||||
}
|
||||
|
||||
public firstToken(): ISyntaxToken {
|
||||
return this.item.firstToken();
|
||||
}
|
||||
|
||||
public lastToken(): ISyntaxToken {
|
||||
return this.item.lastToken();
|
||||
}
|
||||
|
||||
public fullWidth(): number {
|
||||
return this.item.fullWidth();
|
||||
}
|
||||
|
||||
public width(): number {
|
||||
return this.item.width();
|
||||
}
|
||||
|
||||
public leadingTrivia(): ISyntaxTriviaList {
|
||||
return this.item.leadingTrivia();
|
||||
}
|
||||
|
||||
public trailingTrivia(): ISyntaxTriviaList {
|
||||
return this.item.trailingTrivia();
|
||||
}
|
||||
|
||||
public leadingTriviaWidth(): number {
|
||||
return this.item.leadingTriviaWidth();
|
||||
}
|
||||
|
||||
public trailingTriviaWidth(): number {
|
||||
return this.item.trailingTriviaWidth();
|
||||
}
|
||||
|
||||
public fullText(): string {
|
||||
return this.item.fullText();
|
||||
}
|
||||
|
||||
public isTypeScriptSpecific(): boolean {
|
||||
return this.item.isTypeScriptSpecific();
|
||||
}
|
||||
|
||||
public isIncrementallyUnusable(): boolean {
|
||||
return this.item.isIncrementallyUnusable();
|
||||
}
|
||||
|
||||
public findTokenInternal(parent: PositionedElement, position: number, fullStart: number): PositionedToken {
|
||||
// Debug.assert(position >= 0 && position < this.item.fullWidth());
|
||||
return (<any>this.item).findTokenInternal(
|
||||
new PositionedList(parent, this, fullStart), position, fullStart);
|
||||
}
|
||||
|
||||
public insertChildrenInto(array: ISyntaxElement[], index: number): void {
|
||||
array.splice(index, 0, this.item);
|
||||
}
|
||||
}
|
||||
|
||||
class NormalSyntaxList implements ISyntaxList {
|
||||
private nodeOrTokens: ISyntaxNodeOrToken[];
|
||||
private _data: number = 0;
|
||||
|
||||
constructor(nodeOrTokens: ISyntaxNodeOrToken[]) {
|
||||
this.nodeOrTokens = nodeOrTokens;
|
||||
}
|
||||
|
||||
public kind(): SyntaxKind { return SyntaxKind.List; }
|
||||
|
||||
public isNode(): boolean { return false; }
|
||||
public isToken(): boolean { return false; }
|
||||
public isList(): boolean { return true; }
|
||||
public isSeparatedList(): boolean { return false; }
|
||||
|
||||
public toJSON(key: any) {
|
||||
return this.nodeOrTokens;
|
||||
}
|
||||
|
||||
public childCount() {
|
||||
return this.nodeOrTokens.length;
|
||||
}
|
||||
|
||||
public childAt(index: number): ISyntaxNodeOrToken {
|
||||
if (index < 0 || index >= this.nodeOrTokens.length) {
|
||||
throw Errors.argumentOutOfRange("index");
|
||||
}
|
||||
|
||||
return this.nodeOrTokens[index];
|
||||
}
|
||||
|
||||
public toArray(): ISyntaxNodeOrToken[] {
|
||||
return this.nodeOrTokens.slice(0);
|
||||
}
|
||||
|
||||
public collectTextElements(elements: string[]): void {
|
||||
for (var i = 0, n = this.nodeOrTokens.length; i < n; i++) {
|
||||
var element = this.nodeOrTokens[i];
|
||||
element.collectTextElements(elements);
|
||||
}
|
||||
}
|
||||
|
||||
public firstToken(): ISyntaxToken {
|
||||
for (var i = 0, n = this.nodeOrTokens.length; i < n; i++) {
|
||||
var token = this.nodeOrTokens[i].firstToken();
|
||||
if (token !== null) {
|
||||
return token;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public lastToken(): ISyntaxToken {
|
||||
for (var i = this.nodeOrTokens.length - 1; i >= 0; i--) {
|
||||
var token = this.nodeOrTokens[i].lastToken();
|
||||
if (token !== null) {
|
||||
return token;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public fullText(): string {
|
||||
var elements = new Array<string>();
|
||||
this.collectTextElements(elements);
|
||||
return elements.join("");
|
||||
}
|
||||
|
||||
public isTypeScriptSpecific(): boolean {
|
||||
for (var i = 0, n = this.nodeOrTokens.length; i < n; i++) {
|
||||
if (this.nodeOrTokens[i].isTypeScriptSpecific()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public isIncrementallyUnusable(): boolean {
|
||||
return (this.data() & SyntaxConstants.NodeIncrementallyUnusableMask) !== 0;
|
||||
}
|
||||
|
||||
public fullWidth(): number {
|
||||
return this.data() >>> SyntaxConstants.NodeFullWidthShift;
|
||||
}
|
||||
|
||||
public width(): number {
|
||||
var fullWidth = this.fullWidth();
|
||||
return fullWidth - this.leadingTriviaWidth() - this.trailingTriviaWidth();
|
||||
}
|
||||
|
||||
public leadingTrivia(): ISyntaxTriviaList {
|
||||
return this.firstToken().leadingTrivia();
|
||||
}
|
||||
|
||||
public trailingTrivia(): ISyntaxTriviaList {
|
||||
return this.lastToken().trailingTrivia();
|
||||
}
|
||||
|
||||
public leadingTriviaWidth(): number {
|
||||
return this.firstToken().leadingTriviaWidth();
|
||||
}
|
||||
|
||||
public trailingTriviaWidth(): number {
|
||||
return this.lastToken().trailingTriviaWidth();
|
||||
}
|
||||
|
||||
private computeData(): number {
|
||||
var fullWidth = 0;
|
||||
var isIncrementallyUnusable = false;
|
||||
|
||||
for (var i = 0, n = this.nodeOrTokens.length; i < n; i++) {
|
||||
var node = this.nodeOrTokens[i];
|
||||
fullWidth += node.fullWidth();
|
||||
isIncrementallyUnusable = isIncrementallyUnusable || node.isIncrementallyUnusable();
|
||||
}
|
||||
|
||||
return (fullWidth << SyntaxConstants.NodeFullWidthShift)
|
||||
| (isIncrementallyUnusable ? SyntaxConstants.NodeIncrementallyUnusableMask : 0)
|
||||
| SyntaxConstants.NodeDataComputed;
|
||||
}
|
||||
|
||||
private data(): number {
|
||||
if ((this._data & SyntaxConstants.NodeDataComputed) === 0) {
|
||||
this._data = this.computeData();
|
||||
}
|
||||
|
||||
return this._data;
|
||||
}
|
||||
|
||||
public findTokenInternal(parent: PositionedElement, position: number, fullStart: number): PositionedToken {
|
||||
// Debug.assert(position >= 0 && position < this.fullWidth());
|
||||
|
||||
parent = new PositionedList(parent, this, fullStart);
|
||||
for (var i = 0, n = this.nodeOrTokens.length; i < n; i++) {
|
||||
var nodeOrToken = this.nodeOrTokens[i];
|
||||
|
||||
var childWidth = nodeOrToken.fullWidth();
|
||||
if (position < childWidth) {
|
||||
return (<any>nodeOrToken).findTokenInternal(parent, position, fullStart);
|
||||
}
|
||||
|
||||
position -= childWidth;
|
||||
fullStart += childWidth;
|
||||
}
|
||||
|
||||
throw Errors.invalidOperation();
|
||||
}
|
||||
|
||||
public insertChildrenInto(array: ISyntaxElement[], index: number): void {
|
||||
if (index === 0) {
|
||||
array.unshift.apply(array, this.nodeOrTokens);
|
||||
}
|
||||
else {
|
||||
// TODO: this seems awfully innefficient. Can we do better here?
|
||||
array.splice.apply(array, [index, <any>0].concat(this.nodeOrTokens));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function list(nodes: ISyntaxNodeOrToken[]): ISyntaxList {
|
||||
if (nodes === undefined || nodes === null || nodes.length === 0) {
|
||||
return emptyList;
|
||||
}
|
||||
|
||||
if (nodes.length === 1) {
|
||||
var item = nodes[0];
|
||||
return new SingletonSyntaxList(item);
|
||||
}
|
||||
|
||||
return new NormalSyntaxList(nodes);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,387 @@
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export class SyntaxNode implements ISyntaxNodeOrToken {
|
||||
private _data: number;
|
||||
|
||||
constructor(parsedInStrictMode: boolean) {
|
||||
this._data = parsedInStrictMode ? SyntaxConstants.NodeParsedInStrictModeMask : 0;
|
||||
}
|
||||
|
||||
public isNode(): boolean { return true; }
|
||||
public isToken(): boolean { return false; }
|
||||
public isList(): boolean { return false; }
|
||||
public isSeparatedList(): boolean { return false; }
|
||||
|
||||
public kind(): SyntaxKind {
|
||||
throw Errors.abstract();
|
||||
}
|
||||
|
||||
public childCount(): number {
|
||||
throw Errors.abstract();
|
||||
}
|
||||
|
||||
public childAt(slot: number): ISyntaxElement {
|
||||
throw Errors.abstract();
|
||||
}
|
||||
|
||||
// Returns the first non-missing token inside this node (or null if there are no such token).
|
||||
public firstToken(): ISyntaxToken {
|
||||
for (var i = 0, n = this.childCount(); i < n; i++) {
|
||||
var element = this.childAt(i);
|
||||
|
||||
if (element !== null) {
|
||||
if (element.fullWidth() > 0 || element.kind() === SyntaxKind.EndOfFileToken) {
|
||||
return element.firstToken();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// Returns the last non-missing token inside this node (or null if there are no such token).
|
||||
public lastToken(): ISyntaxToken {
|
||||
for (var i = this.childCount() - 1; i >= 0; i--) {
|
||||
var element = this.childAt(i);
|
||||
|
||||
if (element !== null) {
|
||||
if (element.fullWidth() > 0 || element.kind() === SyntaxKind.EndOfFileToken) {
|
||||
return element.lastToken();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public insertChildrenInto(array: ISyntaxElement[], index: number) {
|
||||
for (var i = this.childCount() - 1; i >= 0; i--) {
|
||||
var element = this.childAt(i);
|
||||
|
||||
if (element !== null) {
|
||||
if (element.isNode() || element.isToken()) {
|
||||
array.splice(index, 0, element);
|
||||
}
|
||||
else if (element.isList()) {
|
||||
(<ISyntaxList>element).insertChildrenInto(array, index);
|
||||
}
|
||||
else if (element.isSeparatedList()) {
|
||||
(<ISeparatedSyntaxList>element).insertChildrenInto(array, index);
|
||||
}
|
||||
else {
|
||||
throw Errors.invalidOperation();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public leadingTrivia(): ISyntaxTriviaList {
|
||||
var firstToken = this.firstToken();
|
||||
return firstToken ? firstToken.leadingTrivia() : Syntax.emptyTriviaList;
|
||||
}
|
||||
|
||||
public trailingTrivia(): ISyntaxTriviaList {
|
||||
var lastToken = this.lastToken();
|
||||
return lastToken ? lastToken.trailingTrivia() : Syntax.emptyTriviaList;
|
||||
}
|
||||
|
||||
public toJSON(key: any): any {
|
||||
var result: any = {
|
||||
kind: SyntaxKind[this.kind()],
|
||||
fullWidth: this.fullWidth()
|
||||
};
|
||||
|
||||
if (this.isIncrementallyUnusable()) {
|
||||
result.isIncrementallyUnusable = true;
|
||||
}
|
||||
|
||||
if (this.parsedInStrictMode()) {
|
||||
result.parsedInStrictMode = true;
|
||||
}
|
||||
|
||||
var thisAsIndexable: IIndexable<any> = <any>this;
|
||||
for (var i = 0, n = this.childCount(); i < n; i++) {
|
||||
var value = this.childAt(i);
|
||||
|
||||
if (value) {
|
||||
for (var name in this) {
|
||||
if (value === thisAsIndexable[name]) {
|
||||
result[name] = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public accept(visitor: ISyntaxVisitor): any {
|
||||
throw Errors.abstract();
|
||||
}
|
||||
|
||||
public fullText(): string {
|
||||
var elements: string[] = [];
|
||||
this.collectTextElements(elements);
|
||||
return elements.join("");
|
||||
}
|
||||
|
||||
public collectTextElements(elements: string[]): void {
|
||||
for (var i = 0, n = this.childCount(); i < n; i++) {
|
||||
var element = this.childAt(i);
|
||||
|
||||
if (element !== null) {
|
||||
element.collectTextElements(elements);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public replaceToken(token1: ISyntaxToken, token2: ISyntaxToken): SyntaxNode {
|
||||
if (token1 === token2) {
|
||||
return this;
|
||||
}
|
||||
|
||||
return this.accept(new SyntaxTokenReplacer(token1, token2));
|
||||
}
|
||||
|
||||
public withLeadingTrivia(trivia: ISyntaxTriviaList): SyntaxNode {
|
||||
return this.replaceToken(this.firstToken(), this.firstToken().withLeadingTrivia(trivia));
|
||||
}
|
||||
|
||||
public withTrailingTrivia(trivia: ISyntaxTriviaList): SyntaxNode {
|
||||
return this.replaceToken(this.lastToken(), this.lastToken().withTrailingTrivia(trivia));
|
||||
}
|
||||
|
||||
public hasLeadingTrivia(): boolean {
|
||||
return this.lastToken().hasLeadingTrivia();
|
||||
}
|
||||
|
||||
public hasTrailingTrivia(): boolean {
|
||||
return this.lastToken().hasTrailingTrivia();
|
||||
}
|
||||
|
||||
public isTypeScriptSpecific(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
public isIncrementallyUnusable(): boolean {
|
||||
return (this.data() & SyntaxConstants.NodeIncrementallyUnusableMask) !== 0;
|
||||
}
|
||||
|
||||
// True if this node was parsed while the parser was in 'strict' mode. A node parsed in strict
|
||||
// mode cannot be reused if the parser is non-strict mode (and vice versa). This is because
|
||||
// the parser parses things differently in strict mode and thus the tokens may be interpretted
|
||||
// differently if the mode is changed.
|
||||
public parsedInStrictMode(): boolean {
|
||||
return (this.data() & SyntaxConstants.NodeParsedInStrictModeMask) !== 0;
|
||||
}
|
||||
|
||||
public fullWidth(): number {
|
||||
return this.data() >>> SyntaxConstants.NodeFullWidthShift;
|
||||
}
|
||||
|
||||
private computeData(): number {
|
||||
var slotCount = this.childCount();
|
||||
|
||||
var fullWidth = 0;
|
||||
var childWidth = 0;
|
||||
|
||||
// If we're already set as incrementally unusable, then don't need to check children.
|
||||
// If we have no children (like an OmmittedExpressionSyntax), we're automatically not reusable.
|
||||
var isIncrementallyUnusable = ((this._data & SyntaxConstants.NodeIncrementallyUnusableMask) !== 0) || slotCount === 0;
|
||||
|
||||
for (var i = 0, n = slotCount; i < n; i++) {
|
||||
var element = this.childAt(i);
|
||||
|
||||
if (element !== null) {
|
||||
childWidth = element.fullWidth();
|
||||
fullWidth += childWidth;
|
||||
|
||||
if (!isIncrementallyUnusable) {
|
||||
isIncrementallyUnusable = element.isIncrementallyUnusable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (fullWidth << SyntaxConstants.NodeFullWidthShift)
|
||||
| (isIncrementallyUnusable ? SyntaxConstants.NodeIncrementallyUnusableMask : 0)
|
||||
| SyntaxConstants.NodeDataComputed;
|
||||
}
|
||||
|
||||
private data(): number {
|
||||
if ((this._data & SyntaxConstants.NodeDataComputed) === 0) {
|
||||
this._data |= this.computeData();
|
||||
}
|
||||
|
||||
return this._data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a token according to the following rules:
|
||||
* 1) If position matches the End of the node/s FullSpan and the node is SourceUnit,
|
||||
* then the EOF token is returned.
|
||||
*
|
||||
* 2) If node.FullSpan.Contains(position) then the token that contains given position is
|
||||
* returned.
|
||||
*
|
||||
* 3) Otherwise an ArgumentOutOfRangeException is thrown
|
||||
*
|
||||
* Note: findToken will always return a non-missing token with width greater than or equal to
|
||||
* 1 (except for EOF). Empty tokens synthesized by the parser are never returned.
|
||||
*/
|
||||
public findToken(position: number, includeSkippedTokens: boolean = false): PositionedToken {
|
||||
var endOfFileToken = this.tryGetEndOfFileAt(position);
|
||||
if (endOfFileToken !== null) {
|
||||
return endOfFileToken;
|
||||
}
|
||||
|
||||
if (position < 0 || position >= this.fullWidth()) {
|
||||
throw Errors.argumentOutOfRange("position");
|
||||
}
|
||||
|
||||
var positionedToken= this.findTokenInternal(null, position, 0);
|
||||
|
||||
if (includeSkippedTokens) {
|
||||
return Syntax.findSkippedTokenInPositionedToken(positionedToken, position) || positionedToken;
|
||||
}
|
||||
|
||||
// Could not find a better match
|
||||
return positionedToken;
|
||||
|
||||
}
|
||||
|
||||
private tryGetEndOfFileAt(position: number): PositionedToken {
|
||||
if (this.kind() === SyntaxKind.SourceUnit && position === this.fullWidth()) {
|
||||
var sourceUnit = <SourceUnitSyntax>this;
|
||||
return new PositionedToken(
|
||||
new PositionedNode(null, sourceUnit, 0),
|
||||
sourceUnit.endOfFileToken, sourceUnit.moduleElements.fullWidth());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private findTokenInternal(parent: PositionedElement, position: number, fullStart: number): PositionedToken {
|
||||
// Debug.assert(position >= 0 && position < this.fullWidth());
|
||||
|
||||
parent = new PositionedNode(parent, this, fullStart);
|
||||
for (var i = 0, n = this.childCount(); i < n; i++) {
|
||||
var element = this.childAt(i);
|
||||
|
||||
if (element !== null) {
|
||||
var childWidth = element.fullWidth();
|
||||
|
||||
if (position < childWidth) {
|
||||
return (<any>element).findTokenInternal(parent, position, fullStart);
|
||||
}
|
||||
|
||||
position -= childWidth;
|
||||
fullStart += childWidth;
|
||||
}
|
||||
}
|
||||
|
||||
throw Errors.invalidOperation();
|
||||
}
|
||||
|
||||
public findTokenOnLeft(position: number, includeSkippedTokens: boolean = false): PositionedToken {
|
||||
var positionedToken = this.findToken(position, /*includeSkippedTokens*/ false);
|
||||
var start = positionedToken.start();
|
||||
|
||||
// Position better fall within this token.
|
||||
// Debug.assert(position >= positionedToken.fullStart());
|
||||
// Debug.assert(position < positionedToken.fullEnd() || positionedToken.token().tokenKind === SyntaxKind.EndOfFileToken);
|
||||
|
||||
if (includeSkippedTokens) {
|
||||
positionedToken = Syntax.findSkippedTokenOnLeft(positionedToken, position) || positionedToken;
|
||||
}
|
||||
|
||||
// if position is after the start of the token, then this token is the token on the left.
|
||||
if (position > start) {
|
||||
return positionedToken;
|
||||
}
|
||||
|
||||
// we're in the trivia before the start of the token. Need to return the previous token.
|
||||
if (positionedToken.fullStart() === 0) {
|
||||
// Already on the first token. Nothing before us.
|
||||
return null;
|
||||
}
|
||||
|
||||
return positionedToken.previousToken(includeSkippedTokens);
|
||||
}
|
||||
|
||||
public findCompleteTokenOnLeft(position: number, includeSkippedTokens: boolean = false): PositionedToken {
|
||||
var positionedToken = this.findToken(position, /*includeSkippedTokens*/ false);
|
||||
|
||||
// Position better fall within this token.
|
||||
// Debug.assert(position >= positionedToken.fullStart());
|
||||
// Debug.assert(position < positionedToken.fullEnd() || positionedToken.token().tokenKind === SyntaxKind.EndOfFileToken);
|
||||
|
||||
if (includeSkippedTokens) {
|
||||
positionedToken = Syntax.findSkippedTokenOnLeft(positionedToken, position) || positionedToken;
|
||||
}
|
||||
|
||||
// if position is after the end of the token, then this token is the token on the left.
|
||||
if (positionedToken.token().width() > 0 && position >= positionedToken.end()) {
|
||||
return positionedToken;
|
||||
}
|
||||
|
||||
return positionedToken.previousToken(includeSkippedTokens);
|
||||
}
|
||||
|
||||
public isModuleElement(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
public isClassElement(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
public isTypeMember(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
public isStatement(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
public isExpression(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
public isSwitchClause(): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
public structuralEquals(node: SyntaxNode): boolean {
|
||||
if (this === node) { return true; }
|
||||
if (node === null) { return false; }
|
||||
if (this.kind() !== node.kind()) { return false; }
|
||||
|
||||
for (var i = 0, n = this.childCount(); i < n; i++) {
|
||||
var element1 = this.childAt(i);
|
||||
var element2 = node.childAt(i);
|
||||
|
||||
if (!Syntax.elementStructuralEquals(element1, element2)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public width(): number {
|
||||
return this.fullWidth() - this.leadingTriviaWidth() - this.trailingTriviaWidth();
|
||||
}
|
||||
|
||||
public leadingTriviaWidth() {
|
||||
var firstToken = this.firstToken();
|
||||
return firstToken === null ? 0 : firstToken.leadingTriviaWidth();
|
||||
}
|
||||
|
||||
public trailingTriviaWidth() {
|
||||
var lastToken = this.lastToken();
|
||||
return lastToken === null ? 0 : lastToken.trailingTriviaWidth();
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user