code
stringlengths 24
2.07M
| docstring
stringlengths 25
85.3k
| func_name
stringlengths 1
92
| language
stringclasses 1
value | repo
stringlengths 5
64
| path
stringlengths 4
172
| url
stringlengths 44
218
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
function isJSDocType() {
switch (token) {
case 37 /* AsteriskToken */:
case 53 /* QuestionToken */:
case 17 /* OpenParenToken */:
case 19 /* OpenBracketToken */:
case 49 /* ExclamationToken */:
case 15 /* OpenBraceToken */:
case 87 /* FunctionKeyword */:
case 22 /* DotDotDotToken */:
case 92 /* NewKeyword */:
case 97 /* ThisKeyword */:
return true;
}
return ts.tokenIsIdentifierOrKeyword(token);
} | Parse ES7 IncrementExpression. IncrementExpression is used instead of ES6's PostFixExpression.
ES7 IncrementExpression[yield]:
1) LeftHandSideExpression[?yield]
2) LeftHandSideExpression[?yield] [[no LineTerminator here]]++
3) LeftHandSideExpression[?yield] [[no LineTerminator here]]--
4) ++LeftHandSideExpression[?yield]
5) --LeftHandSideExpression[?yield]
In TypeScript (2), (3) are parsed as PostfixUnaryExpression. (4), (5) are parsed as PrefixUnaryExpression | isJSDocType | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function parseJSDocTypeExpressionForTests(content, start, length) {
initializeState("file.js", content, 2 /* Latest */, /*isJavaScriptFile*/ true, /*_syntaxCursor:*/ undefined);
var jsDocTypeExpression = parseJSDocTypeExpression(start, length);
var diagnostics = parseDiagnostics;
clearState();
return jsDocTypeExpression ? { jsDocTypeExpression: jsDocTypeExpression, diagnostics: diagnostics } : undefined;
} | Parse ES7 IncrementExpression. IncrementExpression is used instead of ES6's PostFixExpression.
ES7 IncrementExpression[yield]:
1) LeftHandSideExpression[?yield]
2) LeftHandSideExpression[?yield] [[no LineTerminator here]]++
3) LeftHandSideExpression[?yield] [[no LineTerminator here]]--
4) ++LeftHandSideExpression[?yield]
5) --LeftHandSideExpression[?yield]
In TypeScript (2), (3) are parsed as PostfixUnaryExpression. (4), (5) are parsed as PrefixUnaryExpression | parseJSDocTypeExpressionForTests | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function parseJSDocTopLevelType() {
var type = parseJSDocType();
if (token === 47 /* BarToken */) {
var unionType = createNode(253 /* JSDocUnionType */, type.pos);
unionType.types = parseJSDocTypeList(type);
type = finishNode(unionType);
}
if (token === 56 /* EqualsToken */) {
var optionalType = createNode(260 /* JSDocOptionalType */, type.pos);
nextToken();
optionalType.type = type;
type = finishNode(optionalType);
}
return type;
} | Parse ES7 IncrementExpression. IncrementExpression is used instead of ES6's PostFixExpression.
ES7 IncrementExpression[yield]:
1) LeftHandSideExpression[?yield]
2) LeftHandSideExpression[?yield] [[no LineTerminator here]]++
3) LeftHandSideExpression[?yield] [[no LineTerminator here]]--
4) ++LeftHandSideExpression[?yield]
5) --LeftHandSideExpression[?yield]
In TypeScript (2), (3) are parsed as PostfixUnaryExpression. (4), (5) are parsed as PrefixUnaryExpression | parseJSDocTopLevelType | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function parseJSDocType() {
var type = parseBasicTypeExpression();
while (true) {
if (token === 19 /* OpenBracketToken */) {
var arrayType = createNode(252 /* JSDocArrayType */, type.pos);
arrayType.elementType = type;
nextToken();
parseExpected(20 /* CloseBracketToken */);
type = finishNode(arrayType);
}
else if (token === 53 /* QuestionToken */) {
var nullableType = createNode(255 /* JSDocNullableType */, type.pos);
nullableType.type = type;
nextToken();
type = finishNode(nullableType);
}
else if (token === 49 /* ExclamationToken */) {
var nonNullableType = createNode(256 /* JSDocNonNullableType */, type.pos);
nonNullableType.type = type;
nextToken();
type = finishNode(nonNullableType);
}
else {
break;
}
}
return type;
} | Parse ES7 IncrementExpression. IncrementExpression is used instead of ES6's PostFixExpression.
ES7 IncrementExpression[yield]:
1) LeftHandSideExpression[?yield]
2) LeftHandSideExpression[?yield] [[no LineTerminator here]]++
3) LeftHandSideExpression[?yield] [[no LineTerminator here]]--
4) ++LeftHandSideExpression[?yield]
5) --LeftHandSideExpression[?yield]
In TypeScript (2), (3) are parsed as PostfixUnaryExpression. (4), (5) are parsed as PrefixUnaryExpression | parseJSDocType | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function parseBasicTypeExpression() {
switch (token) {
case 37 /* AsteriskToken */:
return parseJSDocAllType();
case 53 /* QuestionToken */:
return parseJSDocUnknownOrNullableType();
case 17 /* OpenParenToken */:
return parseJSDocUnionType();
case 19 /* OpenBracketToken */:
return parseJSDocTupleType();
case 49 /* ExclamationToken */:
return parseJSDocNonNullableType();
case 15 /* OpenBraceToken */:
return parseJSDocRecordType();
case 87 /* FunctionKeyword */:
return parseJSDocFunctionType();
case 22 /* DotDotDotToken */:
return parseJSDocVariadicType();
case 92 /* NewKeyword */:
return parseJSDocConstructorType();
case 97 /* ThisKeyword */:
return parseJSDocThisType();
case 117 /* AnyKeyword */:
case 130 /* StringKeyword */:
case 128 /* NumberKeyword */:
case 120 /* BooleanKeyword */:
case 131 /* SymbolKeyword */:
case 103 /* VoidKeyword */:
return parseTokenNode();
}
// TODO (drosen): Parse string literal types in JSDoc as well.
return parseJSDocTypeReference();
} | Parse ES7 IncrementExpression. IncrementExpression is used instead of ES6's PostFixExpression.
ES7 IncrementExpression[yield]:
1) LeftHandSideExpression[?yield]
2) LeftHandSideExpression[?yield] [[no LineTerminator here]]++
3) LeftHandSideExpression[?yield] [[no LineTerminator here]]--
4) ++LeftHandSideExpression[?yield]
5) --LeftHandSideExpression[?yield]
In TypeScript (2), (3) are parsed as PostfixUnaryExpression. (4), (5) are parsed as PrefixUnaryExpression | parseBasicTypeExpression | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function parseJSDocThisType() {
var result = createNode(264 /* JSDocThisType */);
nextToken();
parseExpected(54 /* ColonToken */);
result.type = parseJSDocType();
return finishNode(result);
} | Parse ES7 IncrementExpression. IncrementExpression is used instead of ES6's PostFixExpression.
ES7 IncrementExpression[yield]:
1) LeftHandSideExpression[?yield]
2) LeftHandSideExpression[?yield] [[no LineTerminator here]]++
3) LeftHandSideExpression[?yield] [[no LineTerminator here]]--
4) ++LeftHandSideExpression[?yield]
5) --LeftHandSideExpression[?yield]
In TypeScript (2), (3) are parsed as PostfixUnaryExpression. (4), (5) are parsed as PrefixUnaryExpression | parseJSDocThisType | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function parseJSDocConstructorType() {
var result = createNode(263 /* JSDocConstructorType */);
nextToken();
parseExpected(54 /* ColonToken */);
result.type = parseJSDocType();
return finishNode(result);
} | Parse ES7 IncrementExpression. IncrementExpression is used instead of ES6's PostFixExpression.
ES7 IncrementExpression[yield]:
1) LeftHandSideExpression[?yield]
2) LeftHandSideExpression[?yield] [[no LineTerminator here]]++
3) LeftHandSideExpression[?yield] [[no LineTerminator here]]--
4) ++LeftHandSideExpression[?yield]
5) --LeftHandSideExpression[?yield]
In TypeScript (2), (3) are parsed as PostfixUnaryExpression. (4), (5) are parsed as PrefixUnaryExpression | parseJSDocConstructorType | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function parseJSDocVariadicType() {
var result = createNode(262 /* JSDocVariadicType */);
nextToken();
result.type = parseJSDocType();
return finishNode(result);
} | Parse ES7 IncrementExpression. IncrementExpression is used instead of ES6's PostFixExpression.
ES7 IncrementExpression[yield]:
1) LeftHandSideExpression[?yield]
2) LeftHandSideExpression[?yield] [[no LineTerminator here]]++
3) LeftHandSideExpression[?yield] [[no LineTerminator here]]--
4) ++LeftHandSideExpression[?yield]
5) --LeftHandSideExpression[?yield]
In TypeScript (2), (3) are parsed as PostfixUnaryExpression. (4), (5) are parsed as PrefixUnaryExpression | parseJSDocVariadicType | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function parseJSDocFunctionType() {
var result = createNode(261 /* JSDocFunctionType */);
nextToken();
parseExpected(17 /* OpenParenToken */);
result.parameters = parseDelimitedList(22 /* JSDocFunctionParameters */, parseJSDocParameter);
checkForTrailingComma(result.parameters);
parseExpected(18 /* CloseParenToken */);
if (token === 54 /* ColonToken */) {
nextToken();
result.type = parseJSDocType();
}
return finishNode(result);
} | Parse ES7 IncrementExpression. IncrementExpression is used instead of ES6's PostFixExpression.
ES7 IncrementExpression[yield]:
1) LeftHandSideExpression[?yield]
2) LeftHandSideExpression[?yield] [[no LineTerminator here]]++
3) LeftHandSideExpression[?yield] [[no LineTerminator here]]--
4) ++LeftHandSideExpression[?yield]
5) --LeftHandSideExpression[?yield]
In TypeScript (2), (3) are parsed as PostfixUnaryExpression. (4), (5) are parsed as PrefixUnaryExpression | parseJSDocFunctionType | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function parseJSDocParameter() {
var parameter = createNode(138 /* Parameter */);
parameter.type = parseJSDocType();
return finishNode(parameter);
} | Parse ES7 IncrementExpression. IncrementExpression is used instead of ES6's PostFixExpression.
ES7 IncrementExpression[yield]:
1) LeftHandSideExpression[?yield]
2) LeftHandSideExpression[?yield] [[no LineTerminator here]]++
3) LeftHandSideExpression[?yield] [[no LineTerminator here]]--
4) ++LeftHandSideExpression[?yield]
5) --LeftHandSideExpression[?yield]
In TypeScript (2), (3) are parsed as PostfixUnaryExpression. (4), (5) are parsed as PrefixUnaryExpression | parseJSDocParameter | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function parseJSDocOptionalType(type) {
var result = createNode(260 /* JSDocOptionalType */, type.pos);
nextToken();
result.type = type;
return finishNode(result);
} | Parse ES7 IncrementExpression. IncrementExpression is used instead of ES6's PostFixExpression.
ES7 IncrementExpression[yield]:
1) LeftHandSideExpression[?yield]
2) LeftHandSideExpression[?yield] [[no LineTerminator here]]++
3) LeftHandSideExpression[?yield] [[no LineTerminator here]]--
4) ++LeftHandSideExpression[?yield]
5) --LeftHandSideExpression[?yield]
In TypeScript (2), (3) are parsed as PostfixUnaryExpression. (4), (5) are parsed as PrefixUnaryExpression | parseJSDocOptionalType | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function parseJSDocTypeReference() {
var result = createNode(259 /* JSDocTypeReference */);
result.name = parseSimplePropertyName();
while (parseOptional(21 /* DotToken */)) {
if (token === 25 /* LessThanToken */) {
result.typeArguments = parseTypeArguments();
break;
}
else {
result.name = parseQualifiedName(result.name);
}
}
return finishNode(result);
} | Parse ES7 IncrementExpression. IncrementExpression is used instead of ES6's PostFixExpression.
ES7 IncrementExpression[yield]:
1) LeftHandSideExpression[?yield]
2) LeftHandSideExpression[?yield] [[no LineTerminator here]]++
3) LeftHandSideExpression[?yield] [[no LineTerminator here]]--
4) ++LeftHandSideExpression[?yield]
5) --LeftHandSideExpression[?yield]
In TypeScript (2), (3) are parsed as PostfixUnaryExpression. (4), (5) are parsed as PrefixUnaryExpression | parseJSDocTypeReference | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function parseTypeArguments() {
// Move past the <
nextToken();
var typeArguments = parseDelimitedList(23 /* JSDocTypeArguments */, parseJSDocType);
checkForTrailingComma(typeArguments);
checkForEmptyTypeArgumentList(typeArguments);
parseExpected(27 /* GreaterThanToken */);
return typeArguments;
} | Parse ES7 IncrementExpression. IncrementExpression is used instead of ES6's PostFixExpression.
ES7 IncrementExpression[yield]:
1) LeftHandSideExpression[?yield]
2) LeftHandSideExpression[?yield] [[no LineTerminator here]]++
3) LeftHandSideExpression[?yield] [[no LineTerminator here]]--
4) ++LeftHandSideExpression[?yield]
5) --LeftHandSideExpression[?yield]
In TypeScript (2), (3) are parsed as PostfixUnaryExpression. (4), (5) are parsed as PrefixUnaryExpression | parseTypeArguments | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function checkForEmptyTypeArgumentList(typeArguments) {
if (parseDiagnostics.length === 0 && typeArguments && typeArguments.length === 0) {
var start = typeArguments.pos - "<".length;
var end = ts.skipTrivia(sourceText, typeArguments.end) + ">".length;
return parseErrorAtPosition(start, end - start, ts.Diagnostics.Type_argument_list_cannot_be_empty);
}
} | Parse ES7 IncrementExpression. IncrementExpression is used instead of ES6's PostFixExpression.
ES7 IncrementExpression[yield]:
1) LeftHandSideExpression[?yield]
2) LeftHandSideExpression[?yield] [[no LineTerminator here]]++
3) LeftHandSideExpression[?yield] [[no LineTerminator here]]--
4) ++LeftHandSideExpression[?yield]
5) --LeftHandSideExpression[?yield]
In TypeScript (2), (3) are parsed as PostfixUnaryExpression. (4), (5) are parsed as PrefixUnaryExpression | checkForEmptyTypeArgumentList | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function parseQualifiedName(left) {
var result = createNode(135 /* QualifiedName */, left.pos);
result.left = left;
result.right = parseIdentifierName();
return finishNode(result);
} | Parse ES7 IncrementExpression. IncrementExpression is used instead of ES6's PostFixExpression.
ES7 IncrementExpression[yield]:
1) LeftHandSideExpression[?yield]
2) LeftHandSideExpression[?yield] [[no LineTerminator here]]++
3) LeftHandSideExpression[?yield] [[no LineTerminator here]]--
4) ++LeftHandSideExpression[?yield]
5) --LeftHandSideExpression[?yield]
In TypeScript (2), (3) are parsed as PostfixUnaryExpression. (4), (5) are parsed as PrefixUnaryExpression | parseQualifiedName | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function parseJSDocRecordType() {
var result = createNode(257 /* JSDocRecordType */);
nextToken();
result.members = parseDelimitedList(24 /* JSDocRecordMembers */, parseJSDocRecordMember);
checkForTrailingComma(result.members);
parseExpected(16 /* CloseBraceToken */);
return finishNode(result);
} | Parse ES7 IncrementExpression. IncrementExpression is used instead of ES6's PostFixExpression.
ES7 IncrementExpression[yield]:
1) LeftHandSideExpression[?yield]
2) LeftHandSideExpression[?yield] [[no LineTerminator here]]++
3) LeftHandSideExpression[?yield] [[no LineTerminator here]]--
4) ++LeftHandSideExpression[?yield]
5) --LeftHandSideExpression[?yield]
In TypeScript (2), (3) are parsed as PostfixUnaryExpression. (4), (5) are parsed as PrefixUnaryExpression | parseJSDocRecordType | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function parseJSDocRecordMember() {
var result = createNode(258 /* JSDocRecordMember */);
result.name = parseSimplePropertyName();
if (token === 54 /* ColonToken */) {
nextToken();
result.type = parseJSDocType();
}
return finishNode(result);
} | Parse ES7 IncrementExpression. IncrementExpression is used instead of ES6's PostFixExpression.
ES7 IncrementExpression[yield]:
1) LeftHandSideExpression[?yield]
2) LeftHandSideExpression[?yield] [[no LineTerminator here]]++
3) LeftHandSideExpression[?yield] [[no LineTerminator here]]--
4) ++LeftHandSideExpression[?yield]
5) --LeftHandSideExpression[?yield]
In TypeScript (2), (3) are parsed as PostfixUnaryExpression. (4), (5) are parsed as PrefixUnaryExpression | parseJSDocRecordMember | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function parseJSDocNonNullableType() {
var result = createNode(256 /* JSDocNonNullableType */);
nextToken();
result.type = parseJSDocType();
return finishNode(result);
} | Parse ES7 IncrementExpression. IncrementExpression is used instead of ES6's PostFixExpression.
ES7 IncrementExpression[yield]:
1) LeftHandSideExpression[?yield]
2) LeftHandSideExpression[?yield] [[no LineTerminator here]]++
3) LeftHandSideExpression[?yield] [[no LineTerminator here]]--
4) ++LeftHandSideExpression[?yield]
5) --LeftHandSideExpression[?yield]
In TypeScript (2), (3) are parsed as PostfixUnaryExpression. (4), (5) are parsed as PrefixUnaryExpression | parseJSDocNonNullableType | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function parseJSDocTupleType() {
var result = createNode(254 /* JSDocTupleType */);
nextToken();
result.types = parseDelimitedList(25 /* JSDocTupleTypes */, parseJSDocType);
checkForTrailingComma(result.types);
parseExpected(20 /* CloseBracketToken */);
return finishNode(result);
} | Parse ES7 IncrementExpression. IncrementExpression is used instead of ES6's PostFixExpression.
ES7 IncrementExpression[yield]:
1) LeftHandSideExpression[?yield]
2) LeftHandSideExpression[?yield] [[no LineTerminator here]]++
3) LeftHandSideExpression[?yield] [[no LineTerminator here]]--
4) ++LeftHandSideExpression[?yield]
5) --LeftHandSideExpression[?yield]
In TypeScript (2), (3) are parsed as PostfixUnaryExpression. (4), (5) are parsed as PrefixUnaryExpression | parseJSDocTupleType | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function checkForTrailingComma(list) {
if (parseDiagnostics.length === 0 && list.hasTrailingComma) {
var start = list.end - ",".length;
parseErrorAtPosition(start, ",".length, ts.Diagnostics.Trailing_comma_not_allowed);
}
} | Parse ES7 IncrementExpression. IncrementExpression is used instead of ES6's PostFixExpression.
ES7 IncrementExpression[yield]:
1) LeftHandSideExpression[?yield]
2) LeftHandSideExpression[?yield] [[no LineTerminator here]]++
3) LeftHandSideExpression[?yield] [[no LineTerminator here]]--
4) ++LeftHandSideExpression[?yield]
5) --LeftHandSideExpression[?yield]
In TypeScript (2), (3) are parsed as PostfixUnaryExpression. (4), (5) are parsed as PrefixUnaryExpression | checkForTrailingComma | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function parseJSDocUnionType() {
var result = createNode(253 /* JSDocUnionType */);
nextToken();
result.types = parseJSDocTypeList(parseJSDocType());
parseExpected(18 /* CloseParenToken */);
return finishNode(result);
} | Parse ES7 IncrementExpression. IncrementExpression is used instead of ES6's PostFixExpression.
ES7 IncrementExpression[yield]:
1) LeftHandSideExpression[?yield]
2) LeftHandSideExpression[?yield] [[no LineTerminator here]]++
3) LeftHandSideExpression[?yield] [[no LineTerminator here]]--
4) ++LeftHandSideExpression[?yield]
5) --LeftHandSideExpression[?yield]
In TypeScript (2), (3) are parsed as PostfixUnaryExpression. (4), (5) are parsed as PrefixUnaryExpression | parseJSDocUnionType | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function parseJSDocTypeList(firstType) {
ts.Debug.assert(!!firstType);
var types = [];
types.pos = firstType.pos;
types.push(firstType);
while (parseOptional(47 /* BarToken */)) {
types.push(parseJSDocType());
}
types.end = scanner.getStartPos();
return types;
} | Parse ES7 IncrementExpression. IncrementExpression is used instead of ES6's PostFixExpression.
ES7 IncrementExpression[yield]:
1) LeftHandSideExpression[?yield]
2) LeftHandSideExpression[?yield] [[no LineTerminator here]]++
3) LeftHandSideExpression[?yield] [[no LineTerminator here]]--
4) ++LeftHandSideExpression[?yield]
5) --LeftHandSideExpression[?yield]
In TypeScript (2), (3) are parsed as PostfixUnaryExpression. (4), (5) are parsed as PrefixUnaryExpression | parseJSDocTypeList | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function parseJSDocAllType() {
var result = createNode(250 /* JSDocAllType */);
nextToken();
return finishNode(result);
} | Parse ES7 IncrementExpression. IncrementExpression is used instead of ES6's PostFixExpression.
ES7 IncrementExpression[yield]:
1) LeftHandSideExpression[?yield]
2) LeftHandSideExpression[?yield] [[no LineTerminator here]]++
3) LeftHandSideExpression[?yield] [[no LineTerminator here]]--
4) ++LeftHandSideExpression[?yield]
5) --LeftHandSideExpression[?yield]
In TypeScript (2), (3) are parsed as PostfixUnaryExpression. (4), (5) are parsed as PrefixUnaryExpression | parseJSDocAllType | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function parseJSDocUnknownOrNullableType() {
var pos = scanner.getStartPos();
// skip the ?
nextToken();
// Need to lookahead to decide if this is a nullable or unknown type.
// Here are cases where we'll pick the unknown type:
//
// Foo(?,
// { a: ? }
// Foo(?)
// Foo<?>
// Foo(?=
// (?|
if (token === 24 /* CommaToken */ ||
token === 16 /* CloseBraceToken */ ||
token === 18 /* CloseParenToken */ ||
token === 27 /* GreaterThanToken */ ||
token === 56 /* EqualsToken */ ||
token === 47 /* BarToken */) {
var result = createNode(251 /* JSDocUnknownType */, pos);
return finishNode(result);
}
else {
var result = createNode(255 /* JSDocNullableType */, pos);
result.type = parseJSDocType();
return finishNode(result);
}
} | Parse ES7 IncrementExpression. IncrementExpression is used instead of ES6's PostFixExpression.
ES7 IncrementExpression[yield]:
1) LeftHandSideExpression[?yield]
2) LeftHandSideExpression[?yield] [[no LineTerminator here]]++
3) LeftHandSideExpression[?yield] [[no LineTerminator here]]--
4) ++LeftHandSideExpression[?yield]
5) --LeftHandSideExpression[?yield]
In TypeScript (2), (3) are parsed as PostfixUnaryExpression. (4), (5) are parsed as PrefixUnaryExpression | parseJSDocUnknownOrNullableType | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function parseIsolatedJSDocComment(content, start, length) {
initializeState("file.js", content, 2 /* Latest */, /*isJavaScriptFile*/ true, /*_syntaxCursor:*/ undefined);
var jsDocComment = parseJSDocComment(/*parent:*/ undefined, start, length);
var diagnostics = parseDiagnostics;
clearState();
return jsDocComment ? { jsDocComment: jsDocComment, diagnostics: diagnostics } : undefined;
} | Parse ES7 IncrementExpression. IncrementExpression is used instead of ES6's PostFixExpression.
ES7 IncrementExpression[yield]:
1) LeftHandSideExpression[?yield]
2) LeftHandSideExpression[?yield] [[no LineTerminator here]]++
3) LeftHandSideExpression[?yield] [[no LineTerminator here]]--
4) ++LeftHandSideExpression[?yield]
5) --LeftHandSideExpression[?yield]
In TypeScript (2), (3) are parsed as PostfixUnaryExpression. (4), (5) are parsed as PrefixUnaryExpression | parseIsolatedJSDocComment | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function parseJSDocComment(parent, start, length) {
var comment = parseJSDocCommentWorker(start, length);
if (comment) {
fixupParentReferences(comment);
comment.parent = parent;
}
return comment;
} | Parse ES7 IncrementExpression. IncrementExpression is used instead of ES6's PostFixExpression.
ES7 IncrementExpression[yield]:
1) LeftHandSideExpression[?yield]
2) LeftHandSideExpression[?yield] [[no LineTerminator here]]++
3) LeftHandSideExpression[?yield] [[no LineTerminator here]]--
4) ++LeftHandSideExpression[?yield]
5) --LeftHandSideExpression[?yield]
In TypeScript (2), (3) are parsed as PostfixUnaryExpression. (4), (5) are parsed as PrefixUnaryExpression | parseJSDocComment | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function parseJSDocCommentWorker(start, length) {
var content = sourceText;
start = start || 0;
var end = length === undefined ? content.length : start + length;
length = end - start;
ts.Debug.assert(start >= 0);
ts.Debug.assert(start <= end);
ts.Debug.assert(end <= content.length);
var tags;
var pos;
// NOTE(cyrusn): This is essentially a handwritten scanner for JSDocComments. I
// considered using an actual Scanner, but this would complicate things. The
// scanner would need to know it was in a Doc Comment. Otherwise, it would then
// produce comments *inside* the doc comment. In the end it was just easier to
// write a simple scanner rather than go that route.
if (length >= "/** */".length) {
if (content.charCodeAt(start) === 47 /* slash */ &&
content.charCodeAt(start + 1) === 42 /* asterisk */ &&
content.charCodeAt(start + 2) === 42 /* asterisk */ &&
content.charCodeAt(start + 3) !== 42 /* asterisk */) {
// Initially we can parse out a tag. We also have seen a starting asterisk.
// This is so that /** * @type */ doesn't parse.
var canParseTag = true;
var seenAsterisk = true;
for (pos = start + "/**".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at */ && canParseTag) {
parseTag();
// Once we parse out a tag, we cannot keep parsing out tags on this line.
canParseTag = false;
continue;
}
if (ts.isLineBreak(ch)) {
// After a line break, we can parse a tag, and we haven't seen as asterisk
// on the next line yet.
canParseTag = true;
seenAsterisk = false;
continue;
}
if (ts.isWhiteSpace(ch)) {
// Whitespace doesn't affect any of our parsing.
continue;
}
// Ignore the first asterisk on a line.
if (ch === 42 /* asterisk */) {
if (seenAsterisk) {
// If we've already seen an asterisk, then we can no longer parse a tag
// on this line.
canParseTag = false;
}
seenAsterisk = true;
continue;
}
// Anything else is doc comment text. We can't do anything with it. Because it
// wasn't a tag, we can no longer parse a tag on this line until we hit the next
// line break.
canParseTag = false;
}
}
}
return createJSDocComment();
function createJSDocComment() {
if (!tags) {
return undefined;
}
var result = createNode(265 /* JSDocComment */, start);
result.tags = tags;
return finishNode(result, end);
}
function skipWhitespace() {
while (pos < end && ts.isWhiteSpace(content.charCodeAt(pos))) {
pos++;
}
}
function parseTag() {
ts.Debug.assert(content.charCodeAt(pos - 1) === 64 /* at */);
var atToken = createNode(55 /* AtToken */, pos - 1);
atToken.end = pos;
var tagName = scanIdentifier();
if (!tagName) {
return;
}
var tag = handleTag(atToken, tagName) || handleUnknownTag(atToken, tagName);
addTag(tag);
}
function handleTag(atToken, tagName) {
if (tagName) {
switch (tagName.text) {
case "param":
return handleParamTag(atToken, tagName);
case "return":
case "returns":
return handleReturnTag(atToken, tagName);
case "template":
return handleTemplateTag(atToken, tagName);
case "type":
return handleTypeTag(atToken, tagName);
}
}
return undefined;
}
function handleUnknownTag(atToken, tagName) {
var result = createNode(266 /* JSDocTag */, atToken.pos);
result.atToken = atToken;
result.tagName = tagName;
return finishNode(result, pos);
}
function addTag(tag) {
if (tag) {
if (!tags) {
tags = [];
tags.pos = tag.pos;
}
tags.push(tag);
tags.end = tag.end;
}
}
function tryParseTypeExpression() {
skipWhitespace();
if (content.charCodeAt(pos) !== 123 /* openBrace */) {
return undefined;
}
var typeExpression = parseJSDocTypeExpression(pos, end - pos);
pos = typeExpression.end;
return typeExpression;
}
function handleParamTag(atToken, tagName) {
var typeExpression = tryParseTypeExpression();
skipWhitespace();
var name;
var isBracketed;
if (content.charCodeAt(pos) === 91 /* openBracket */) {
pos++;
skipWhitespace();
name = scanIdentifier();
isBracketed = true;
}
else {
name = scanIdentifier();
}
if (!name) {
parseErrorAtPosition(pos, 0, ts.Diagnostics.Identifier_expected);
}
var preName, postName;
if (typeExpression) {
postName = name;
}
else {
preName = name;
}
if (!typeExpression) {
typeExpression = tryParseTypeExpression();
}
var result = createNode(267 /* JSDocParameterTag */, atToken.pos);
result.atToken = atToken;
result.tagName = tagName;
result.preParameterName = preName;
result.typeExpression = typeExpression;
result.postParameterName = postName;
result.isBracketed = isBracketed;
return finishNode(result, pos);
}
function handleReturnTag(atToken, tagName) {
if (ts.forEach(tags, function (t) { return t.kind === 268 /* JSDocReturnTag */; })) {
parseErrorAtPosition(tagName.pos, pos - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text);
}
var result = createNode(268 /* JSDocReturnTag */, atToken.pos);
result.atToken = atToken;
result.tagName = tagName;
result.typeExpression = tryParseTypeExpression();
return finishNode(result, pos);
}
function handleTypeTag(atToken, tagName) {
if (ts.forEach(tags, function (t) { return t.kind === 269 /* JSDocTypeTag */; })) {
parseErrorAtPosition(tagName.pos, pos - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text);
}
var result = createNode(269 /* JSDocTypeTag */, atToken.pos);
result.atToken = atToken;
result.tagName = tagName;
result.typeExpression = tryParseTypeExpression();
return finishNode(result, pos);
}
function handleTemplateTag(atToken, tagName) {
if (ts.forEach(tags, function (t) { return t.kind === 270 /* JSDocTemplateTag */; })) {
parseErrorAtPosition(tagName.pos, pos - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text);
}
var typeParameters = [];
typeParameters.pos = pos;
while (true) {
skipWhitespace();
var startPos = pos;
var name_8 = scanIdentifier();
if (!name_8) {
parseErrorAtPosition(startPos, 0, ts.Diagnostics.Identifier_expected);
return undefined;
}
var typeParameter = createNode(137 /* TypeParameter */, name_8.pos);
typeParameter.name = name_8;
finishNode(typeParameter, pos);
typeParameters.push(typeParameter);
skipWhitespace();
if (content.charCodeAt(pos) !== 44 /* comma */) {
break;
}
pos++;
}
typeParameters.end = pos;
var result = createNode(270 /* JSDocTemplateTag */, atToken.pos);
result.atToken = atToken;
result.tagName = tagName;
result.typeParameters = typeParameters;
return finishNode(result, pos);
}
function scanIdentifier() {
var startPos = pos;
for (; pos < end; pos++) {
var ch = content.charCodeAt(pos);
if (pos === startPos && ts.isIdentifierStart(ch, 2 /* Latest */)) {
continue;
}
else if (pos > startPos && ts.isIdentifierPart(ch, 2 /* Latest */)) {
continue;
}
break;
}
if (startPos === pos) {
return undefined;
}
var result = createNode(69 /* Identifier */, startPos);
result.text = content.substring(startPos, pos);
return finishNode(result, pos);
}
} | Parse ES7 IncrementExpression. IncrementExpression is used instead of ES6's PostFixExpression.
ES7 IncrementExpression[yield]:
1) LeftHandSideExpression[?yield]
2) LeftHandSideExpression[?yield] [[no LineTerminator here]]++
3) LeftHandSideExpression[?yield] [[no LineTerminator here]]--
4) ++LeftHandSideExpression[?yield]
5) --LeftHandSideExpression[?yield]
In TypeScript (2), (3) are parsed as PostfixUnaryExpression. (4), (5) are parsed as PrefixUnaryExpression | parseJSDocCommentWorker | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function createJSDocComment() {
if (!tags) {
return undefined;
}
var result = createNode(265 /* JSDocComment */, start);
result.tags = tags;
return finishNode(result, end);
} | ".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at | createJSDocComment | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function skipWhitespace() {
while (pos < end && ts.isWhiteSpace(content.charCodeAt(pos))) {
pos++;
}
} | ".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at | skipWhitespace | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function parseTag() {
ts.Debug.assert(content.charCodeAt(pos - 1) === 64 /* at */);
var atToken = createNode(55 /* AtToken */, pos - 1);
atToken.end = pos;
var tagName = scanIdentifier();
if (!tagName) {
return;
}
var tag = handleTag(atToken, tagName) || handleUnknownTag(atToken, tagName);
addTag(tag);
} | ".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at | parseTag | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function handleTag(atToken, tagName) {
if (tagName) {
switch (tagName.text) {
case "param":
return handleParamTag(atToken, tagName);
case "return":
case "returns":
return handleReturnTag(atToken, tagName);
case "template":
return handleTemplateTag(atToken, tagName);
case "type":
return handleTypeTag(atToken, tagName);
}
}
return undefined;
} | ".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at | handleTag | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function handleUnknownTag(atToken, tagName) {
var result = createNode(266 /* JSDocTag */, atToken.pos);
result.atToken = atToken;
result.tagName = tagName;
return finishNode(result, pos);
} | ".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at | handleUnknownTag | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function addTag(tag) {
if (tag) {
if (!tags) {
tags = [];
tags.pos = tag.pos;
}
tags.push(tag);
tags.end = tag.end;
}
} | ".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at | addTag | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function tryParseTypeExpression() {
skipWhitespace();
if (content.charCodeAt(pos) !== 123 /* openBrace */) {
return undefined;
}
var typeExpression = parseJSDocTypeExpression(pos, end - pos);
pos = typeExpression.end;
return typeExpression;
} | ".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at | tryParseTypeExpression | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function handleParamTag(atToken, tagName) {
var typeExpression = tryParseTypeExpression();
skipWhitespace();
var name;
var isBracketed;
if (content.charCodeAt(pos) === 91 /* openBracket */) {
pos++;
skipWhitespace();
name = scanIdentifier();
isBracketed = true;
}
else {
name = scanIdentifier();
}
if (!name) {
parseErrorAtPosition(pos, 0, ts.Diagnostics.Identifier_expected);
}
var preName, postName;
if (typeExpression) {
postName = name;
}
else {
preName = name;
}
if (!typeExpression) {
typeExpression = tryParseTypeExpression();
}
var result = createNode(267 /* JSDocParameterTag */, atToken.pos);
result.atToken = atToken;
result.tagName = tagName;
result.preParameterName = preName;
result.typeExpression = typeExpression;
result.postParameterName = postName;
result.isBracketed = isBracketed;
return finishNode(result, pos);
} | ".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at | handleParamTag | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function handleReturnTag(atToken, tagName) {
if (ts.forEach(tags, function (t) { return t.kind === 268 /* JSDocReturnTag */; })) {
parseErrorAtPosition(tagName.pos, pos - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text);
}
var result = createNode(268 /* JSDocReturnTag */, atToken.pos);
result.atToken = atToken;
result.tagName = tagName;
result.typeExpression = tryParseTypeExpression();
return finishNode(result, pos);
} | ".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at | handleReturnTag | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function handleTypeTag(atToken, tagName) {
if (ts.forEach(tags, function (t) { return t.kind === 269 /* JSDocTypeTag */; })) {
parseErrorAtPosition(tagName.pos, pos - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text);
}
var result = createNode(269 /* JSDocTypeTag */, atToken.pos);
result.atToken = atToken;
result.tagName = tagName;
result.typeExpression = tryParseTypeExpression();
return finishNode(result, pos);
} | ".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at | handleTypeTag | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function handleTemplateTag(atToken, tagName) {
if (ts.forEach(tags, function (t) { return t.kind === 270 /* JSDocTemplateTag */; })) {
parseErrorAtPosition(tagName.pos, pos - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text);
}
var typeParameters = [];
typeParameters.pos = pos;
while (true) {
skipWhitespace();
var startPos = pos;
var name_8 = scanIdentifier();
if (!name_8) {
parseErrorAtPosition(startPos, 0, ts.Diagnostics.Identifier_expected);
return undefined;
}
var typeParameter = createNode(137 /* TypeParameter */, name_8.pos);
typeParameter.name = name_8;
finishNode(typeParameter, pos);
typeParameters.push(typeParameter);
skipWhitespace();
if (content.charCodeAt(pos) !== 44 /* comma */) {
break;
}
pos++;
}
typeParameters.end = pos;
var result = createNode(270 /* JSDocTemplateTag */, atToken.pos);
result.atToken = atToken;
result.tagName = tagName;
result.typeParameters = typeParameters;
return finishNode(result, pos);
} | ".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at | handleTemplateTag | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function scanIdentifier() {
var startPos = pos;
for (; pos < end; pos++) {
var ch = content.charCodeAt(pos);
if (pos === startPos && ts.isIdentifierStart(ch, 2 /* Latest */)) {
continue;
}
else if (pos > startPos && ts.isIdentifierPart(ch, 2 /* Latest */)) {
continue;
}
break;
}
if (startPos === pos) {
return undefined;
}
var result = createNode(69 /* Identifier */, startPos);
result.text = content.substring(startPos, pos);
return finishNode(result, pos);
} | ".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at | scanIdentifier | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function updateSourceFile(sourceFile, newText, textChangeRange, aggressiveChecks) {
aggressiveChecks = aggressiveChecks || ts.Debug.shouldAssert(2 /* Aggressive */);
checkChangeRange(sourceFile, newText, textChangeRange, aggressiveChecks);
if (ts.textChangeRangeIsUnchanged(textChangeRange)) {
// if the text didn't change, then we can just return our current source file as-is.
return sourceFile;
}
if (sourceFile.statements.length === 0) {
// If we don't have any statements in the current source file, then there's no real
// way to incrementally parse. So just do a full parse instead.
return Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, /*syntaxCursor*/ undefined, /*setNodeParents*/ true);
}
// Make sure we're not trying to incrementally update a source file more than once. Once
// we do an update the original source file is considered unusbale from that point onwards.
//
// This is because we do incremental parsing in-place. i.e. we take nodes from the old
// tree and give them new positions and parents. From that point on, trusting the old
// tree at all is not possible as far too much of it may violate invariants.
var incrementalSourceFile = sourceFile;
ts.Debug.assert(!incrementalSourceFile.hasBeenIncrementallyParsed);
incrementalSourceFile.hasBeenIncrementallyParsed = true;
var oldText = sourceFile.text;
var syntaxCursor = createSyntaxCursor(sourceFile);
// Make the actual change larger so that we know to reparse anything whose lookahead
// might have intersected the change.
var changeRange = extendToAffectedRange(sourceFile, textChangeRange);
checkChangeRange(sourceFile, newText, changeRange, aggressiveChecks);
// Ensure that extending the affected range only moved the start of the change range
// earlier in the file.
ts.Debug.assert(changeRange.span.start <= textChangeRange.span.start);
ts.Debug.assert(ts.textSpanEnd(changeRange.span) === ts.textSpanEnd(textChangeRange.span));
ts.Debug.assert(ts.textSpanEnd(ts.textChangeRangeNewSpan(changeRange)) === ts.textSpanEnd(ts.textChangeRangeNewSpan(textChangeRange)));
// The is the amount the nodes after the edit range need to be adjusted. It can be
// positive (if the edit added characters), negative (if the edit deleted characters)
// or zero (if this was a pure overwrite with nothing added/removed).
var delta = ts.textChangeRangeNewSpan(changeRange).length - changeRange.span.length;
// If we added or removed characters during the edit, then we need to go and adjust all
// the nodes after the edit. Those nodes may move forward (if we inserted chars) or they
// may move backward (if we deleted chars).
//
// Doing this helps us out in two ways. First, it means that any nodes/tokens we want
// to reuse are already at the appropriate position in the new text. That way when we
// reuse them, we don't have to figure out if they need to be adjusted. Second, it makes
// it very easy to determine if we can reuse a node. If the node's position is at where
// we are in the text, then we can reuse it. Otherwise we can't. If the node's position
// is ahead of us, then we'll need to rescan tokens. If the node's position is behind
// us, then we'll need to skip it or crumble it as appropriate
//
// We will also adjust the positions of nodes that intersect the change range as well.
// By doing this, we ensure that all the positions in the old tree are consistent, not
// just the positions of nodes entirely before/after the change range. By being
// consistent, we can then easily map from positions to nodes in the old tree easily.
//
// Also, mark any syntax elements that intersect the changed span. We know, up front,
// that we cannot reuse these elements.
updateTokenPositionsAndMarkElements(incrementalSourceFile, changeRange.span.start, ts.textSpanEnd(changeRange.span), ts.textSpanEnd(ts.textChangeRangeNewSpan(changeRange)), delta, oldText, newText, aggressiveChecks);
// Now that we've set up our internal incremental state just proceed and parse the
// source file in the normal fashion. When possible the parser will retrieve and
// reuse nodes from the old tree.
//
// Note: passing in 'true' for setNodeParents is very important. When incrementally
// parsing, we will be reusing nodes from the old tree, and placing it into new
// parents. If we don't set the parents now, we'll end up with an observably
// inconsistent tree. Setting the parents on the new tree should be very fast. We
// will immediately bail out of walking any subtrees when we can see that their parents
// are already correct.
var result = Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, syntaxCursor, /* setParentNode */ true);
return result;
} | ".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at | updateSourceFile | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function moveElementEntirelyPastChangeRange(element, isArray, delta, oldText, newText, aggressiveChecks) {
if (isArray) {
visitArray(element);
}
else {
visitNode(element);
}
return;
function visitNode(node) {
var text = "";
if (aggressiveChecks && shouldCheckNode(node)) {
text = oldText.substring(node.pos, node.end);
}
// Ditch any existing LS children we may have created. This way we can avoid
// moving them forward.
if (node._children) {
node._children = undefined;
}
if (node.jsDocComment) {
node.jsDocComment = undefined;
}
node.pos += delta;
node.end += delta;
if (aggressiveChecks && shouldCheckNode(node)) {
ts.Debug.assert(text === newText.substring(node.pos, node.end));
}
forEachChild(node, visitNode, visitArray);
checkNodePositions(node, aggressiveChecks);
}
function visitArray(array) {
array._children = undefined;
array.pos += delta;
array.end += delta;
for (var _i = 0, array_7 = array; _i < array_7.length; _i++) {
var node = array_7[_i];
visitNode(node);
}
}
} | ".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at | moveElementEntirelyPastChangeRange | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function visitNode(node) {
var text = "";
if (aggressiveChecks && shouldCheckNode(node)) {
text = oldText.substring(node.pos, node.end);
}
// Ditch any existing LS children we may have created. This way we can avoid
// moving them forward.
if (node._children) {
node._children = undefined;
}
if (node.jsDocComment) {
node.jsDocComment = undefined;
}
node.pos += delta;
node.end += delta;
if (aggressiveChecks && shouldCheckNode(node)) {
ts.Debug.assert(text === newText.substring(node.pos, node.end));
}
forEachChild(node, visitNode, visitArray);
checkNodePositions(node, aggressiveChecks);
} | ".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at | visitNode | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function visitArray(array) {
array._children = undefined;
array.pos += delta;
array.end += delta;
for (var _i = 0, array_7 = array; _i < array_7.length; _i++) {
var node = array_7[_i];
visitNode(node);
}
} | ".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at | visitArray | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function shouldCheckNode(node) {
switch (node.kind) {
case 9 /* StringLiteral */:
case 8 /* NumericLiteral */:
case 69 /* Identifier */:
return true;
}
return false;
} | ".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at | shouldCheckNode | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function adjustIntersectingElement(element, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta) {
ts.Debug.assert(element.end >= changeStart, "Adjusting an element that was entirely before the change range");
ts.Debug.assert(element.pos <= changeRangeOldEnd, "Adjusting an element that was entirely after the change range");
ts.Debug.assert(element.pos <= element.end);
// We have an element that intersects the change range in some way. It may have its
// start, or its end (or both) in the changed range. We want to adjust any part
// that intersects such that the final tree is in a consistent state. i.e. all
// chlidren have spans within the span of their parent, and all siblings are ordered
// properly.
// We may need to update both the 'pos' and the 'end' of the element.
// If the 'pos' is before the start of the change, then we don't need to touch it.
// If it isn't, then the 'pos' must be inside the change. How we update it will
// depend if delta is positive or negative. If delta is positive then we have
// something like:
//
// -------------------AAA-----------------
// -------------------BBBCCCCCCC-----------------
//
// In this case, we consider any node that started in the change range to still be
// starting at the same position.
//
// however, if the delta is negative, then we instead have something like this:
//
// -------------------XXXYYYYYYY-----------------
// -------------------ZZZ-----------------
//
// In this case, any element that started in the 'X' range will keep its position.
// However any element htat started after that will have their pos adjusted to be
// at the end of the new range. i.e. any node that started in the 'Y' range will
// be adjusted to have their start at the end of the 'Z' range.
//
// The element will keep its position if possible. Or Move backward to the new-end
// if it's in the 'Y' range.
element.pos = Math.min(element.pos, changeRangeNewEnd);
// If the 'end' is after the change range, then we always adjust it by the delta
// amount. However, if the end is in the change range, then how we adjust it
// will depend on if delta is positive or negative. If delta is positive then we
// have something like:
//
// -------------------AAA-----------------
// -------------------BBBCCCCCCC-----------------
//
// In this case, we consider any node that ended inside the change range to keep its
// end position.
//
// however, if the delta is negative, then we instead have something like this:
//
// -------------------XXXYYYYYYY-----------------
// -------------------ZZZ-----------------
//
// In this case, any element that ended in the 'X' range will keep its position.
// However any element htat ended after that will have their pos adjusted to be
// at the end of the new range. i.e. any node that ended in the 'Y' range will
// be adjusted to have their end at the end of the 'Z' range.
if (element.end >= changeRangeOldEnd) {
// Element ends after the change range. Always adjust the end pos.
element.end += delta;
}
else {
// Element ends in the change range. The element will keep its position if
// possible. Or Move backward to the new-end if it's in the 'Y' range.
element.end = Math.min(element.end, changeRangeNewEnd);
}
ts.Debug.assert(element.pos <= element.end);
if (element.parent) {
ts.Debug.assert(element.pos >= element.parent.pos);
ts.Debug.assert(element.end <= element.parent.end);
}
} | ".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at | adjustIntersectingElement | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function checkNodePositions(node, aggressiveChecks) {
if (aggressiveChecks) {
var pos = node.pos;
forEachChild(node, function (child) {
ts.Debug.assert(child.pos >= pos);
pos = child.end;
});
ts.Debug.assert(pos <= node.end);
}
} | ".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at | checkNodePositions | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function updateTokenPositionsAndMarkElements(sourceFile, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta, oldText, newText, aggressiveChecks) {
visitNode(sourceFile);
return;
function visitNode(child) {
ts.Debug.assert(child.pos <= child.end);
if (child.pos > changeRangeOldEnd) {
// Node is entirely past the change range. We need to move both its pos and
// end, forward or backward appropriately.
moveElementEntirelyPastChangeRange(child, /*isArray*/ false, delta, oldText, newText, aggressiveChecks);
return;
}
// Check if the element intersects the change range. If it does, then it is not
// reusable. Also, we'll need to recurse to see what constituent portions we may
// be able to use.
var fullEnd = child.end;
if (fullEnd >= changeStart) {
child.intersectsChange = true;
child._children = undefined;
// Adjust the pos or end (or both) of the intersecting element accordingly.
adjustIntersectingElement(child, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta);
forEachChild(child, visitNode, visitArray);
checkNodePositions(child, aggressiveChecks);
return;
}
// Otherwise, the node is entirely before the change range. No need to do anything with it.
ts.Debug.assert(fullEnd < changeStart);
}
function visitArray(array) {
ts.Debug.assert(array.pos <= array.end);
if (array.pos > changeRangeOldEnd) {
// Array is entirely after the change range. We need to move it, and move any of
// its children.
moveElementEntirelyPastChangeRange(array, /*isArray*/ true, delta, oldText, newText, aggressiveChecks);
return;
}
// Check if the element intersects the change range. If it does, then it is not
// reusable. Also, we'll need to recurse to see what constituent portions we may
// be able to use.
var fullEnd = array.end;
if (fullEnd >= changeStart) {
array.intersectsChange = true;
array._children = undefined;
// Adjust the pos or end (or both) of the intersecting array accordingly.
adjustIntersectingElement(array, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta);
for (var _i = 0, array_8 = array; _i < array_8.length; _i++) {
var node = array_8[_i];
visitNode(node);
}
return;
}
// Otherwise, the array is entirely before the change range. No need to do anything with it.
ts.Debug.assert(fullEnd < changeStart);
}
} | ".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at | updateTokenPositionsAndMarkElements | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function visitNode(child) {
ts.Debug.assert(child.pos <= child.end);
if (child.pos > changeRangeOldEnd) {
// Node is entirely past the change range. We need to move both its pos and
// end, forward or backward appropriately.
moveElementEntirelyPastChangeRange(child, /*isArray*/ false, delta, oldText, newText, aggressiveChecks);
return;
}
// Check if the element intersects the change range. If it does, then it is not
// reusable. Also, we'll need to recurse to see what constituent portions we may
// be able to use.
var fullEnd = child.end;
if (fullEnd >= changeStart) {
child.intersectsChange = true;
child._children = undefined;
// Adjust the pos or end (or both) of the intersecting element accordingly.
adjustIntersectingElement(child, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta);
forEachChild(child, visitNode, visitArray);
checkNodePositions(child, aggressiveChecks);
return;
}
// Otherwise, the node is entirely before the change range. No need to do anything with it.
ts.Debug.assert(fullEnd < changeStart);
} | ".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at | visitNode | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function visitArray(array) {
ts.Debug.assert(array.pos <= array.end);
if (array.pos > changeRangeOldEnd) {
// Array is entirely after the change range. We need to move it, and move any of
// its children.
moveElementEntirelyPastChangeRange(array, /*isArray*/ true, delta, oldText, newText, aggressiveChecks);
return;
}
// Check if the element intersects the change range. If it does, then it is not
// reusable. Also, we'll need to recurse to see what constituent portions we may
// be able to use.
var fullEnd = array.end;
if (fullEnd >= changeStart) {
array.intersectsChange = true;
array._children = undefined;
// Adjust the pos or end (or both) of the intersecting array accordingly.
adjustIntersectingElement(array, changeStart, changeRangeOldEnd, changeRangeNewEnd, delta);
for (var _i = 0, array_8 = array; _i < array_8.length; _i++) {
var node = array_8[_i];
visitNode(node);
}
return;
}
// Otherwise, the array is entirely before the change range. No need to do anything with it.
ts.Debug.assert(fullEnd < changeStart);
} | ".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at | visitArray | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function extendToAffectedRange(sourceFile, changeRange) {
// Consider the following code:
// void foo() { /; }
//
// If the text changes with an insertion of / just before the semicolon then we end up with:
// void foo() { //; }
//
// If we were to just use the changeRange a is, then we would not rescan the { token
// (as it does not intersect the actual original change range). Because an edit may
// change the token touching it, we actually need to look back *at least* one token so
// that the prior token sees that change.
var maxLookahead = 1;
var start = changeRange.span.start;
// the first iteration aligns us with the change start. subsequent iteration move us to
// the left by maxLookahead tokens. We only need to do this as long as we're not at the
// start of the tree.
for (var i = 0; start > 0 && i <= maxLookahead; i++) {
var nearestNode = findNearestNodeStartingBeforeOrAtPosition(sourceFile, start);
ts.Debug.assert(nearestNode.pos <= start);
var position = nearestNode.pos;
start = Math.max(0, position - 1);
}
var finalSpan = ts.createTextSpanFromBounds(start, ts.textSpanEnd(changeRange.span));
var finalLength = changeRange.newLength + (changeRange.span.start - start);
return ts.createTextChangeRange(finalSpan, finalLength);
} | ".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at | extendToAffectedRange | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function findNearestNodeStartingBeforeOrAtPosition(sourceFile, position) {
var bestResult = sourceFile;
var lastNodeEntirelyBeforePosition;
forEachChild(sourceFile, visit);
if (lastNodeEntirelyBeforePosition) {
var lastChildOfLastEntireNodeBeforePosition = getLastChild(lastNodeEntirelyBeforePosition);
if (lastChildOfLastEntireNodeBeforePosition.pos > bestResult.pos) {
bestResult = lastChildOfLastEntireNodeBeforePosition;
}
}
return bestResult;
function getLastChild(node) {
while (true) {
var lastChild = getLastChildWorker(node);
if (lastChild) {
node = lastChild;
}
else {
return node;
}
}
}
function getLastChildWorker(node) {
var last = undefined;
forEachChild(node, function (child) {
if (ts.nodeIsPresent(child)) {
last = child;
}
});
return last;
}
function visit(child) {
if (ts.nodeIsMissing(child)) {
// Missing nodes are effectively invisible to us. We never even consider them
// When trying to find the nearest node before us.
return;
}
// If the child intersects this position, then this node is currently the nearest
// node that starts before the position.
if (child.pos <= position) {
if (child.pos >= bestResult.pos) {
// This node starts before the position, and is closer to the position than
// the previous best node we found. It is now the new best node.
bestResult = child;
}
// Now, the node may overlap the position, or it may end entirely before the
// position. If it overlaps with the position, then either it, or one of its
// children must be the nearest node before the position. So we can just
// recurse into this child to see if we can find something better.
if (position < child.end) {
// The nearest node is either this child, or one of the children inside
// of it. We've already marked this child as the best so far. Recurse
// in case one of the children is better.
forEachChild(child, visit);
// Once we look at the children of this node, then there's no need to
// continue any further.
return true;
}
else {
ts.Debug.assert(child.end <= position);
// The child ends entirely before this position. Say you have the following
// (where $ is the position)
//
// <complex expr 1> ? <complex expr 2> $ : <...> <...>
//
// We would want to find the nearest preceding node in "complex expr 2".
// To support that, we keep track of this node, and once we're done searching
// for a best node, we recurse down this node to see if we can find a good
// result in it.
//
// This approach allows us to quickly skip over nodes that are entirely
// before the position, while still allowing us to find any nodes in the
// last one that might be what we want.
lastNodeEntirelyBeforePosition = child;
}
}
else {
ts.Debug.assert(child.pos > position);
// We're now at a node that is entirely past the position we're searching for.
// This node (and all following nodes) could never contribute to the result,
// so just skip them by returning 'true' here.
return true;
}
}
} | ".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at | findNearestNodeStartingBeforeOrAtPosition | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function getLastChild(node) {
while (true) {
var lastChild = getLastChildWorker(node);
if (lastChild) {
node = lastChild;
}
else {
return node;
}
}
} | ".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at | getLastChild | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function getLastChildWorker(node) {
var last = undefined;
forEachChild(node, function (child) {
if (ts.nodeIsPresent(child)) {
last = child;
}
});
return last;
} | ".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at | getLastChildWorker | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function visit(child) {
if (ts.nodeIsMissing(child)) {
// Missing nodes are effectively invisible to us. We never even consider them
// When trying to find the nearest node before us.
return;
}
// If the child intersects this position, then this node is currently the nearest
// node that starts before the position.
if (child.pos <= position) {
if (child.pos >= bestResult.pos) {
// This node starts before the position, and is closer to the position than
// the previous best node we found. It is now the new best node.
bestResult = child;
}
// Now, the node may overlap the position, or it may end entirely before the
// position. If it overlaps with the position, then either it, or one of its
// children must be the nearest node before the position. So we can just
// recurse into this child to see if we can find something better.
if (position < child.end) {
// The nearest node is either this child, or one of the children inside
// of it. We've already marked this child as the best so far. Recurse
// in case one of the children is better.
forEachChild(child, visit);
// Once we look at the children of this node, then there's no need to
// continue any further.
return true;
}
else {
ts.Debug.assert(child.end <= position);
// The child ends entirely before this position. Say you have the following
// (where $ is the position)
//
// <complex expr 1> ? <complex expr 2> $ : <...> <...>
//
// We would want to find the nearest preceding node in "complex expr 2".
// To support that, we keep track of this node, and once we're done searching
// for a best node, we recurse down this node to see if we can find a good
// result in it.
//
// This approach allows us to quickly skip over nodes that are entirely
// before the position, while still allowing us to find any nodes in the
// last one that might be what we want.
lastNodeEntirelyBeforePosition = child;
}
}
else {
ts.Debug.assert(child.pos > position);
// We're now at a node that is entirely past the position we're searching for.
// This node (and all following nodes) could never contribute to the result,
// so just skip them by returning 'true' here.
return true;
}
} | ".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at | visit | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function checkChangeRange(sourceFile, newText, textChangeRange, aggressiveChecks) {
var oldText = sourceFile.text;
if (textChangeRange) {
ts.Debug.assert((oldText.length - textChangeRange.span.length + textChangeRange.newLength) === newText.length);
if (aggressiveChecks || ts.Debug.shouldAssert(3 /* VeryAggressive */)) {
var oldTextPrefix = oldText.substr(0, textChangeRange.span.start);
var newTextPrefix = newText.substr(0, textChangeRange.span.start);
ts.Debug.assert(oldTextPrefix === newTextPrefix);
var oldTextSuffix = oldText.substring(ts.textSpanEnd(textChangeRange.span), oldText.length);
var newTextSuffix = newText.substring(ts.textSpanEnd(ts.textChangeRangeNewSpan(textChangeRange)), newText.length);
ts.Debug.assert(oldTextSuffix === newTextSuffix);
}
}
} | ".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at | checkChangeRange | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function createSyntaxCursor(sourceFile) {
var currentArray = sourceFile.statements;
var currentArrayIndex = 0;
ts.Debug.assert(currentArrayIndex < currentArray.length);
var current = currentArray[currentArrayIndex];
var lastQueriedPosition = -1 /* Value */;
return {
currentNode: function (position) {
// Only compute the current node if the position is different than the last time
// we were asked. The parser commonly asks for the node at the same position
// twice. Once to know if can read an appropriate list element at a certain point,
// and then to actually read and consume the node.
if (position !== lastQueriedPosition) {
// Much of the time the parser will need the very next node in the array that
// we just returned a node from.So just simply check for that case and move
// forward in the array instead of searching for the node again.
if (current && current.end === position && currentArrayIndex < (currentArray.length - 1)) {
currentArrayIndex++;
current = currentArray[currentArrayIndex];
}
// If we don't have a node, or the node we have isn't in the right position,
// then try to find a viable node at the position requested.
if (!current || current.pos !== position) {
findHighestListElementThatStartsAtPosition(position);
}
}
// Cache this query so that we don't do any extra work if the parser calls back
// into us. Note: this is very common as the parser will make pairs of calls like
// 'isListElement -> parseListElement'. If we were unable to find a node when
// called with 'isListElement', we don't want to redo the work when parseListElement
// is called immediately after.
lastQueriedPosition = position;
// Either we don'd have a node, or we have a node at the position being asked for.
ts.Debug.assert(!current || current.pos === position);
return current;
}
};
// Finds the highest element in the tree we can find that starts at the provided position.
// The element must be a direct child of some node list in the tree. This way after we
// return it, we can easily return its next sibling in the list.
function findHighestListElementThatStartsAtPosition(position) {
// Clear out any cached state about the last node we found.
currentArray = undefined;
currentArrayIndex = -1 /* Value */;
current = undefined;
// Recurse into the source file to find the highest node at this position.
forEachChild(sourceFile, visitNode, visitArray);
return;
function visitNode(node) {
if (position >= node.pos && position < node.end) {
// Position was within this node. Keep searching deeper to find the node.
forEachChild(node, visitNode, visitArray);
// don't procede any futher in the search.
return true;
}
// position wasn't in this node, have to keep searching.
return false;
}
function visitArray(array) {
if (position >= array.pos && position < array.end) {
// position was in this array. Search through this array to see if we find a
// viable element.
for (var i = 0, n = array.length; i < n; i++) {
var child = array[i];
if (child) {
if (child.pos === position) {
// Found the right node. We're done.
currentArray = array;
currentArrayIndex = i;
current = child;
return true;
}
else {
if (child.pos < position && position < child.end) {
// Position in somewhere within this child. Search in it and
// stop searching in this array.
forEachChild(child, visitNode, visitArray);
return true;
}
}
}
}
}
// position wasn't in this array, have to keep searching.
return false;
}
}
} | ".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at | createSyntaxCursor | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function visitNode(node) {
if (position >= node.pos && position < node.end) {
// Position was within this node. Keep searching deeper to find the node.
forEachChild(node, visitNode, visitArray);
// don't procede any futher in the search.
return true;
}
// position wasn't in this node, have to keep searching.
return false;
} | ".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at | visitNode | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function visitArray(array) {
if (position >= array.pos && position < array.end) {
// position was in this array. Search through this array to see if we find a
// viable element.
for (var i = 0, n = array.length; i < n; i++) {
var child = array[i];
if (child) {
if (child.pos === position) {
// Found the right node. We're done.
currentArray = array;
currentArrayIndex = i;
current = child;
return true;
}
else {
if (child.pos < position && position < child.end) {
// Position in somewhere within this child. Search in it and
// stop searching in this array.
forEachChild(child, visitNode, visitArray);
return true;
}
}
}
}
}
// position wasn't in this array, have to keep searching.
return false;
} | ".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at | visitArray | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function or(state1, state2) {
return (state1 | state2) & 2 /* Reachable */
? 2 /* Reachable */
: (state1 & state2) & 8 /* ReportedUnreachable */
? 8 /* ReportedUnreachable */
: 4 /* Unreachable */;
} | ".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at | or | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function getModuleInstanceState(node) {
// A module is uninstantiated if it contains only
// 1. interface declarations, type alias declarations
if (node.kind === 215 /* InterfaceDeclaration */ || node.kind === 216 /* TypeAliasDeclaration */) {
return 0 /* NonInstantiated */;
}
else if (ts.isConstEnumDeclaration(node)) {
return 2 /* ConstEnumOnly */;
}
else if ((node.kind === 222 /* ImportDeclaration */ || node.kind === 221 /* ImportEqualsDeclaration */) && !(node.flags & 2 /* Export */)) {
return 0 /* NonInstantiated */;
}
else if (node.kind === 219 /* ModuleBlock */) {
var state = 0 /* NonInstantiated */;
ts.forEachChild(node, function (n) {
switch (getModuleInstanceState(n)) {
case 0 /* NonInstantiated */:
// child is non-instantiated - continue searching
return false;
case 2 /* ConstEnumOnly */:
// child is const enum only - record state and continue searching
state = 2 /* ConstEnumOnly */;
return false;
case 1 /* Instantiated */:
// child is instantiated - record state and stop
state = 1 /* Instantiated */;
return true;
}
});
return state;
}
else if (node.kind === 218 /* ModuleDeclaration */) {
return getModuleInstanceState(node.body);
}
else {
return 1 /* Instantiated */;
}
} | ".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at | getModuleInstanceState | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function bindSourceFile(file, options) {
var start = new Date().getTime();
binder(file, options);
ts.bindTime += new Date().getTime() - start;
} | ".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at | bindSourceFile | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function createBinder() {
var file;
var options;
var parent;
var container;
var blockScopeContainer;
var lastContainer;
var seenThisKeyword;
// state used by reachability checks
var hasExplicitReturn;
var currentReachabilityState;
var labelStack;
var labelIndexMap;
var implicitLabels;
// If this file is an external module, then it is automatically in strict-mode according to
// ES6. If it is not an external module, then we'll determine if it is in strict mode or
// not depending on if we see "use strict" in certain places (or if we hit a class/namespace).
var inStrictMode;
var symbolCount = 0;
var Symbol;
var classifiableNames;
function bindSourceFile(f, opts) {
file = f;
options = opts;
inStrictMode = !!file.externalModuleIndicator;
classifiableNames = {};
Symbol = ts.objectAllocator.getSymbolConstructor();
if (!file.locals) {
bind(file);
file.symbolCount = symbolCount;
file.classifiableNames = classifiableNames;
}
parent = undefined;
container = undefined;
blockScopeContainer = undefined;
lastContainer = undefined;
seenThisKeyword = false;
hasExplicitReturn = false;
labelStack = undefined;
labelIndexMap = undefined;
implicitLabels = undefined;
}
return bindSourceFile;
function createSymbol(flags, name) {
symbolCount++;
return new Symbol(flags, name);
}
function addDeclarationToSymbol(symbol, node, symbolFlags) {
symbol.flags |= symbolFlags;
node.symbol = symbol;
if (!symbol.declarations) {
symbol.declarations = [];
}
symbol.declarations.push(node);
if (symbolFlags & 1952 /* HasExports */ && !symbol.exports) {
symbol.exports = {};
}
if (symbolFlags & 6240 /* HasMembers */ && !symbol.members) {
symbol.members = {};
}
if (symbolFlags & 107455 /* Value */ && !symbol.valueDeclaration) {
symbol.valueDeclaration = node;
}
}
// Should not be called on a declaration with a computed property name,
// unless it is a well known Symbol.
function getDeclarationName(node) {
if (node.name) {
if (node.kind === 218 /* ModuleDeclaration */ && node.name.kind === 9 /* StringLiteral */) {
return "\"" + node.name.text + "\"";
}
if (node.name.kind === 136 /* ComputedPropertyName */) {
var nameExpression = node.name.expression;
// treat computed property names where expression is string/numeric literal as just string/numeric literal
if (ts.isStringOrNumericLiteral(nameExpression.kind)) {
return nameExpression.text;
}
ts.Debug.assert(ts.isWellKnownSymbolSyntactically(nameExpression));
return ts.getPropertyNameForKnownSymbolName(nameExpression.name.text);
}
return node.name.text;
}
switch (node.kind) {
case 144 /* Constructor */:
return "__constructor";
case 152 /* FunctionType */:
case 147 /* CallSignature */:
return "__call";
case 153 /* ConstructorType */:
case 148 /* ConstructSignature */:
return "__new";
case 149 /* IndexSignature */:
return "__index";
case 228 /* ExportDeclaration */:
return "__export";
case 227 /* ExportAssignment */:
return node.isExportEquals ? "export=" : "default";
case 181 /* BinaryExpression */:
// Binary expression case is for JS module 'module.exports = expr'
return "export=";
case 213 /* FunctionDeclaration */:
case 214 /* ClassDeclaration */:
return node.flags & 512 /* Default */ ? "default" : undefined;
}
}
function getDisplayName(node) {
return node.name ? ts.declarationNameToString(node.name) : getDeclarationName(node);
}
/**
* Declares a Symbol for the node and adds it to symbols. Reports errors for conflicting identifier names.
* @param symbolTable - The symbol table which node will be added to.
* @param parent - node's parent declaration.
* @param node - The declaration to be added to the symbol table
* @param includes - The SymbolFlags that node has in addition to its declaration type (eg: export, ambient, etc.)
* @param excludes - The flags which node cannot be declared alongside in a symbol table. Used to report forbidden declarations.
*/
function declareSymbol(symbolTable, parent, node, includes, excludes) {
ts.Debug.assert(!ts.hasDynamicName(node));
var isDefaultExport = node.flags & 512 /* Default */;
// The exported symbol for an export default function/class node is always named "default"
var name = isDefaultExport && parent ? "default" : getDeclarationName(node);
var symbol;
if (name !== undefined) {
// Check and see if the symbol table already has a symbol with this name. If not,
// create a new symbol with this name and add it to the table. Note that we don't
// give the new symbol any flags *yet*. This ensures that it will not conflict
// with the 'excludes' flags we pass in.
//
// If we do get an existing symbol, see if it conflicts with the new symbol we're
// creating. For example, a 'var' symbol and a 'class' symbol will conflict within
// the same symbol table. If we have a conflict, report the issue on each
// declaration we have for this symbol, and then create a new symbol for this
// declaration.
//
// If we created a new symbol, either because we didn't have a symbol with this name
// in the symbol table, or we conflicted with an existing symbol, then just add this
// node as the sole declaration of the new symbol.
//
// Otherwise, we'll be merging into a compatible existing symbol (for example when
// you have multiple 'vars' with the same name in the same container). In this case
// just add this node into the declarations list of the symbol.
symbol = ts.hasProperty(symbolTable, name)
? symbolTable[name]
: (symbolTable[name] = createSymbol(0 /* None */, name));
if (name && (includes & 788448 /* Classifiable */)) {
classifiableNames[name] = name;
}
if (symbol.flags & excludes) {
if (node.name) {
node.name.parent = node;
}
// Report errors every position with duplicate declaration
// Report errors on previous encountered declarations
var message = symbol.flags & 2 /* BlockScopedVariable */
? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0
: ts.Diagnostics.Duplicate_identifier_0;
ts.forEach(symbol.declarations, function (declaration) {
if (declaration.flags & 512 /* Default */) {
message = ts.Diagnostics.A_module_cannot_have_multiple_default_exports;
}
});
ts.forEach(symbol.declarations, function (declaration) {
file.bindDiagnostics.push(ts.createDiagnosticForNode(declaration.name || declaration, message, getDisplayName(declaration)));
});
file.bindDiagnostics.push(ts.createDiagnosticForNode(node.name || node, message, getDisplayName(node)));
symbol = createSymbol(0 /* None */, name);
}
}
else {
symbol = createSymbol(0 /* None */, "__missing");
}
addDeclarationToSymbol(symbol, node, includes);
symbol.parent = parent;
return symbol;
}
function declareModuleMember(node, symbolFlags, symbolExcludes) {
var hasExportModifier = ts.getCombinedNodeFlags(node) & 2 /* Export */;
if (symbolFlags & 8388608 /* Alias */) {
if (node.kind === 230 /* ExportSpecifier */ || (node.kind === 221 /* ImportEqualsDeclaration */ && hasExportModifier)) {
return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes);
}
else {
return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes);
}
}
else {
// Exported module members are given 2 symbols: A local symbol that is classified with an ExportValue,
// ExportType, or ExportContainer flag, and an associated export symbol with all the correct flags set
// on it. There are 2 main reasons:
//
// 1. We treat locals and exports of the same name as mutually exclusive within a container.
// That means the binder will issue a Duplicate Identifier error if you mix locals and exports
// with the same name in the same container.
// TODO: Make this a more specific error and decouple it from the exclusion logic.
// 2. When we checkIdentifier in the checker, we set its resolved symbol to the local symbol,
// but return the export symbol (by calling getExportSymbolOfValueSymbolIfExported). That way
// when the emitter comes back to it, it knows not to qualify the name if it was found in a containing scope.
if (hasExportModifier || container.flags & 131072 /* ExportContext */) {
var exportKind = (symbolFlags & 107455 /* Value */ ? 1048576 /* ExportValue */ : 0) |
(symbolFlags & 793056 /* Type */ ? 2097152 /* ExportType */ : 0) |
(symbolFlags & 1536 /* Namespace */ ? 4194304 /* ExportNamespace */ : 0);
var local = declareSymbol(container.locals, undefined, node, exportKind, symbolExcludes);
local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes);
node.localSymbol = local;
return local;
}
else {
return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes);
}
}
}
// All container nodes are kept on a linked list in declaration order. This list is used by
// the getLocalNameOfContainer function in the type checker to validate that the local name
// used for a container is unique.
function bindChildren(node) {
// Before we recurse into a node's chilren, we first save the existing parent, container
// and block-container. Then after we pop out of processing the children, we restore
// these saved values.
var saveParent = parent;
var saveContainer = container;
var savedBlockScopeContainer = blockScopeContainer;
// This node will now be set as the parent of all of its children as we recurse into them.
parent = node;
// Depending on what kind of node this is, we may have to adjust the current container
// and block-container. If the current node is a container, then it is automatically
// considered the current block-container as well. Also, for containers that we know
// may contain locals, we proactively initialize the .locals field. We do this because
// it's highly likely that the .locals will be needed to place some child in (for example,
// a parameter, or variable declaration).
//
// However, we do not proactively create the .locals for block-containers because it's
// totally normal and common for block-containers to never actually have a block-scoped
// variable in them. We don't want to end up allocating an object for every 'block' we
// run into when most of them won't be necessary.
//
// Finally, if this is a block-container, then we clear out any existing .locals object
// it may contain within it. This happens in incremental scenarios. Because we can be
// reusing a node from a previous compilation, that node may have had 'locals' created
// for it. We must clear this so we don't accidently move any stale data forward from
// a previous compilation.
var containerFlags = getContainerFlags(node);
if (containerFlags & 1 /* IsContainer */) {
container = blockScopeContainer = node;
if (containerFlags & 4 /* HasLocals */) {
container.locals = {};
}
addToContainerChain(container);
}
else if (containerFlags & 2 /* IsBlockScopedContainer */) {
blockScopeContainer = node;
blockScopeContainer.locals = undefined;
}
var savedReachabilityState;
var savedLabelStack;
var savedLabels;
var savedImplicitLabels;
var savedHasExplicitReturn;
var kind = node.kind;
var flags = node.flags;
// reset all reachability check related flags on node (for incremental scenarios)
flags &= ~1572864 /* ReachabilityCheckFlags */;
if (kind === 215 /* InterfaceDeclaration */) {
seenThisKeyword = false;
}
var saveState = kind === 248 /* SourceFile */ || kind === 219 /* ModuleBlock */ || ts.isFunctionLikeKind(kind);
if (saveState) {
savedReachabilityState = currentReachabilityState;
savedLabelStack = labelStack;
savedLabels = labelIndexMap;
savedImplicitLabels = implicitLabels;
savedHasExplicitReturn = hasExplicitReturn;
currentReachabilityState = 2 /* Reachable */;
hasExplicitReturn = false;
labelStack = labelIndexMap = implicitLabels = undefined;
}
bindReachableStatement(node);
if (currentReachabilityState === 2 /* Reachable */ && ts.isFunctionLikeKind(kind) && ts.nodeIsPresent(node.body)) {
flags |= 524288 /* HasImplicitReturn */;
if (hasExplicitReturn) {
flags |= 1048576 /* HasExplicitReturn */;
}
}
if (kind === 215 /* InterfaceDeclaration */) {
flags = seenThisKeyword ? flags | 262144 /* ContainsThis */ : flags & ~262144 /* ContainsThis */;
}
node.flags = flags;
if (saveState) {
hasExplicitReturn = savedHasExplicitReturn;
currentReachabilityState = savedReachabilityState;
labelStack = savedLabelStack;
labelIndexMap = savedLabels;
implicitLabels = savedImplicitLabels;
}
container = saveContainer;
parent = saveParent;
blockScopeContainer = savedBlockScopeContainer;
}
/**
* Returns true if node and its subnodes were successfully traversed.
* Returning false means that node was not examined and caller needs to dive into the node himself.
*/
function bindReachableStatement(node) {
if (checkUnreachable(node)) {
ts.forEachChild(node, bind);
return;
}
switch (node.kind) {
case 198 /* WhileStatement */:
bindWhileStatement(node);
break;
case 197 /* DoStatement */:
bindDoStatement(node);
break;
case 199 /* ForStatement */:
bindForStatement(node);
break;
case 200 /* ForInStatement */:
case 201 /* ForOfStatement */:
bindForInOrForOfStatement(node);
break;
case 196 /* IfStatement */:
bindIfStatement(node);
break;
case 204 /* ReturnStatement */:
case 208 /* ThrowStatement */:
bindReturnOrThrow(node);
break;
case 203 /* BreakStatement */:
case 202 /* ContinueStatement */:
bindBreakOrContinueStatement(node);
break;
case 209 /* TryStatement */:
bindTryStatement(node);
break;
case 206 /* SwitchStatement */:
bindSwitchStatement(node);
break;
case 220 /* CaseBlock */:
bindCaseBlock(node);
break;
case 207 /* LabeledStatement */:
bindLabeledStatement(node);
break;
default:
ts.forEachChild(node, bind);
break;
}
}
function bindWhileStatement(n) {
var preWhileState = n.expression.kind === 84 /* FalseKeyword */ ? 4 /* Unreachable */ : currentReachabilityState;
var postWhileState = n.expression.kind === 99 /* TrueKeyword */ ? 4 /* Unreachable */ : currentReachabilityState;
// bind expressions (don't affect reachability)
bind(n.expression);
currentReachabilityState = preWhileState;
var postWhileLabel = pushImplicitLabel();
bind(n.statement);
popImplicitLabel(postWhileLabel, postWhileState);
}
function bindDoStatement(n) {
var preDoState = currentReachabilityState;
var postDoLabel = pushImplicitLabel();
bind(n.statement);
var postDoState = n.expression.kind === 99 /* TrueKeyword */ ? 4 /* Unreachable */ : preDoState;
popImplicitLabel(postDoLabel, postDoState);
// bind expressions (don't affect reachability)
bind(n.expression);
}
function bindForStatement(n) {
var preForState = currentReachabilityState;
var postForLabel = pushImplicitLabel();
// bind expressions (don't affect reachability)
bind(n.initializer);
bind(n.condition);
bind(n.incrementor);
bind(n.statement);
// for statement is considered infinite when it condition is either omitted or is true keyword
// - for(..;;..)
// - for(..;true;..)
var isInfiniteLoop = (!n.condition || n.condition.kind === 99 /* TrueKeyword */);
var postForState = isInfiniteLoop ? 4 /* Unreachable */ : preForState;
popImplicitLabel(postForLabel, postForState);
}
function bindForInOrForOfStatement(n) {
var preStatementState = currentReachabilityState;
var postStatementLabel = pushImplicitLabel();
// bind expressions (don't affect reachability)
bind(n.initializer);
bind(n.expression);
bind(n.statement);
popImplicitLabel(postStatementLabel, preStatementState);
}
function bindIfStatement(n) {
// denotes reachability state when entering 'thenStatement' part of the if statement:
// i.e. if condition is false then thenStatement is unreachable
var ifTrueState = n.expression.kind === 84 /* FalseKeyword */ ? 4 /* Unreachable */ : currentReachabilityState;
// denotes reachability state when entering 'elseStatement':
// i.e. if condition is true then elseStatement is unreachable
var ifFalseState = n.expression.kind === 99 /* TrueKeyword */ ? 4 /* Unreachable */ : currentReachabilityState;
currentReachabilityState = ifTrueState;
// bind expression (don't affect reachability)
bind(n.expression);
bind(n.thenStatement);
if (n.elseStatement) {
var preElseState = currentReachabilityState;
currentReachabilityState = ifFalseState;
bind(n.elseStatement);
currentReachabilityState = or(currentReachabilityState, preElseState);
}
else {
currentReachabilityState = or(currentReachabilityState, ifFalseState);
}
}
function bindReturnOrThrow(n) {
// bind expression (don't affect reachability)
bind(n.expression);
if (n.kind === 204 /* ReturnStatement */) {
hasExplicitReturn = true;
}
currentReachabilityState = 4 /* Unreachable */;
}
function bindBreakOrContinueStatement(n) {
// call bind on label (don't affect reachability)
bind(n.label);
// for continue case touch label so it will be marked a used
var isValidJump = jumpToLabel(n.label, n.kind === 203 /* BreakStatement */ ? currentReachabilityState : 4 /* Unreachable */);
if (isValidJump) {
currentReachabilityState = 4 /* Unreachable */;
}
}
function bindTryStatement(n) {
// catch\finally blocks has the same reachability as try block
var preTryState = currentReachabilityState;
bind(n.tryBlock);
var postTryState = currentReachabilityState;
currentReachabilityState = preTryState;
bind(n.catchClause);
var postCatchState = currentReachabilityState;
currentReachabilityState = preTryState;
bind(n.finallyBlock);
// post catch/finally state is reachable if
// - post try state is reachable - control flow can fall out of try block
// - post catch state is reachable - control flow can fall out of catch block
currentReachabilityState = or(postTryState, postCatchState);
}
function bindSwitchStatement(n) {
var preSwitchState = currentReachabilityState;
var postSwitchLabel = pushImplicitLabel();
// bind expression (don't affect reachability)
bind(n.expression);
bind(n.caseBlock);
var hasDefault = ts.forEach(n.caseBlock.clauses, function (c) { return c.kind === 242 /* DefaultClause */; });
// post switch state is unreachable if switch is exaustive (has a default case ) and does not have fallthrough from the last case
var postSwitchState = hasDefault && currentReachabilityState !== 2 /* Reachable */ ? 4 /* Unreachable */ : preSwitchState;
popImplicitLabel(postSwitchLabel, postSwitchState);
}
function bindCaseBlock(n) {
var startState = currentReachabilityState;
for (var _i = 0, _a = n.clauses; _i < _a.length; _i++) {
var clause = _a[_i];
currentReachabilityState = startState;
bind(clause);
if (clause.statements.length && currentReachabilityState === 2 /* Reachable */ && options.noFallthroughCasesInSwitch) {
errorOnFirstToken(clause, ts.Diagnostics.Fallthrough_case_in_switch);
}
}
}
function bindLabeledStatement(n) {
// call bind on label (don't affect reachability)
bind(n.label);
var ok = pushNamedLabel(n.label);
bind(n.statement);
if (ok) {
popNamedLabel(n.label, currentReachabilityState);
}
}
function getContainerFlags(node) {
switch (node.kind) {
case 186 /* ClassExpression */:
case 214 /* ClassDeclaration */:
case 215 /* InterfaceDeclaration */:
case 217 /* EnumDeclaration */:
case 155 /* TypeLiteral */:
case 165 /* ObjectLiteralExpression */:
return 1 /* IsContainer */;
case 147 /* CallSignature */:
case 148 /* ConstructSignature */:
case 149 /* IndexSignature */:
case 143 /* MethodDeclaration */:
case 142 /* MethodSignature */:
case 213 /* FunctionDeclaration */:
case 144 /* Constructor */:
case 145 /* GetAccessor */:
case 146 /* SetAccessor */:
case 152 /* FunctionType */:
case 153 /* ConstructorType */:
case 173 /* FunctionExpression */:
case 174 /* ArrowFunction */:
case 218 /* ModuleDeclaration */:
case 248 /* SourceFile */:
case 216 /* TypeAliasDeclaration */:
return 5 /* IsContainerWithLocals */;
case 244 /* CatchClause */:
case 199 /* ForStatement */:
case 200 /* ForInStatement */:
case 201 /* ForOfStatement */:
case 220 /* CaseBlock */:
return 2 /* IsBlockScopedContainer */;
case 192 /* Block */:
// do not treat blocks directly inside a function as a block-scoped-container.
// Locals that reside in this block should go to the function locals. Othewise 'x'
// would not appear to be a redeclaration of a block scoped local in the following
// example:
//
// function foo() {
// var x;
// let x;
// }
//
// If we placed 'var x' into the function locals and 'let x' into the locals of
// the block, then there would be no collision.
//
// By not creating a new block-scoped-container here, we ensure that both 'var x'
// and 'let x' go into the Function-container's locals, and we do get a collision
// conflict.
return ts.isFunctionLike(node.parent) ? 0 /* None */ : 2 /* IsBlockScopedContainer */;
}
return 0 /* None */;
}
function addToContainerChain(next) {
if (lastContainer) {
lastContainer.nextContainer = next;
}
lastContainer = next;
}
function declareSymbolAndAddToSymbolTable(node, symbolFlags, symbolExcludes) {
// Just call this directly so that the return type of this function stays "void".
declareSymbolAndAddToSymbolTableWorker(node, symbolFlags, symbolExcludes);
}
function declareSymbolAndAddToSymbolTableWorker(node, symbolFlags, symbolExcludes) {
switch (container.kind) {
// Modules, source files, and classes need specialized handling for how their
// members are declared (for example, a member of a class will go into a specific
// symbol table depending on if it is static or not). We defer to specialized
// handlers to take care of declaring these child members.
case 218 /* ModuleDeclaration */:
return declareModuleMember(node, symbolFlags, symbolExcludes);
case 248 /* SourceFile */:
return declareSourceFileMember(node, symbolFlags, symbolExcludes);
case 186 /* ClassExpression */:
case 214 /* ClassDeclaration */:
return declareClassMember(node, symbolFlags, symbolExcludes);
case 217 /* EnumDeclaration */:
return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes);
case 155 /* TypeLiteral */:
case 165 /* ObjectLiteralExpression */:
case 215 /* InterfaceDeclaration */:
// Interface/Object-types always have their children added to the 'members' of
// their container. They are only accessible through an instance of their
// container, and are never in scope otherwise (even inside the body of the
// object / type / interface declaring them). An exception is type parameters,
// which are in scope without qualification (similar to 'locals').
return declareSymbol(container.symbol.members, container.symbol, node, symbolFlags, symbolExcludes);
case 152 /* FunctionType */:
case 153 /* ConstructorType */:
case 147 /* CallSignature */:
case 148 /* ConstructSignature */:
case 149 /* IndexSignature */:
case 143 /* MethodDeclaration */:
case 142 /* MethodSignature */:
case 144 /* Constructor */:
case 145 /* GetAccessor */:
case 146 /* SetAccessor */:
case 213 /* FunctionDeclaration */:
case 173 /* FunctionExpression */:
case 174 /* ArrowFunction */:
case 216 /* TypeAliasDeclaration */:
// All the children of these container types are never visible through another
// symbol (i.e. through another symbol's 'exports' or 'members'). Instead,
// they're only accessed 'lexically' (i.e. from code that exists underneath
// their container in the tree. To accomplish this, we simply add their declared
// symbol to the 'locals' of the container. These symbols can then be found as
// the type checker walks up the containers, checking them for matching names.
return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes);
}
}
function declareClassMember(node, symbolFlags, symbolExcludes) {
return node.flags & 64 /* Static */
? declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes)
: declareSymbol(container.symbol.members, container.symbol, node, symbolFlags, symbolExcludes);
}
function declareSourceFileMember(node, symbolFlags, symbolExcludes) {
return ts.isExternalModule(file)
? declareModuleMember(node, symbolFlags, symbolExcludes)
: declareSymbol(file.locals, undefined, node, symbolFlags, symbolExcludes);
}
function hasExportDeclarations(node) {
var body = node.kind === 248 /* SourceFile */ ? node : node.body;
if (body.kind === 248 /* SourceFile */ || body.kind === 219 /* ModuleBlock */) {
for (var _i = 0, _a = body.statements; _i < _a.length; _i++) {
var stat = _a[_i];
if (stat.kind === 228 /* ExportDeclaration */ || stat.kind === 227 /* ExportAssignment */) {
return true;
}
}
}
return false;
}
function setExportContextFlag(node) {
// A declaration source file or ambient module declaration that contains no export declarations (but possibly regular
// declarations with export modifiers) is an export context in which declarations are implicitly exported.
if (ts.isInAmbientContext(node) && !hasExportDeclarations(node)) {
node.flags |= 131072 /* ExportContext */;
}
else {
node.flags &= ~131072 /* ExportContext */;
}
}
function bindModuleDeclaration(node) {
setExportContextFlag(node);
if (node.name.kind === 9 /* StringLiteral */) {
declareSymbolAndAddToSymbolTable(node, 512 /* ValueModule */, 106639 /* ValueModuleExcludes */);
}
else {
var state = getModuleInstanceState(node);
if (state === 0 /* NonInstantiated */) {
declareSymbolAndAddToSymbolTable(node, 1024 /* NamespaceModule */, 0 /* NamespaceModuleExcludes */);
}
else {
declareSymbolAndAddToSymbolTable(node, 512 /* ValueModule */, 106639 /* ValueModuleExcludes */);
if (node.symbol.flags & (16 /* Function */ | 32 /* Class */ | 256 /* RegularEnum */)) {
// if module was already merged with some function, class or non-const enum
// treat is a non-const-enum-only
node.symbol.constEnumOnlyModule = false;
}
else {
var currentModuleIsConstEnumOnly = state === 2 /* ConstEnumOnly */;
if (node.symbol.constEnumOnlyModule === undefined) {
// non-merged case - use the current state
node.symbol.constEnumOnlyModule = currentModuleIsConstEnumOnly;
}
else {
// merged case: module is const enum only if all its pieces are non-instantiated or const enum
node.symbol.constEnumOnlyModule = node.symbol.constEnumOnlyModule && currentModuleIsConstEnumOnly;
}
}
}
}
}
function bindFunctionOrConstructorType(node) {
// For a given function symbol "<...>(...) => T" we want to generate a symbol identical
// to the one we would get for: { <...>(...): T }
//
// We do that by making an anonymous type literal symbol, and then setting the function
// symbol as its sole member. To the rest of the system, this symbol will be indistinguishable
// from an actual type literal symbol you would have gotten had you used the long form.
var symbol = createSymbol(131072 /* Signature */, getDeclarationName(node));
addDeclarationToSymbol(symbol, node, 131072 /* Signature */);
var typeLiteralSymbol = createSymbol(2048 /* TypeLiteral */, "__type");
addDeclarationToSymbol(typeLiteralSymbol, node, 2048 /* TypeLiteral */);
typeLiteralSymbol.members = (_a = {}, _a[symbol.name] = symbol, _a);
var _a;
}
function bindObjectLiteralExpression(node) {
var ElementKind;
(function (ElementKind) {
ElementKind[ElementKind["Property"] = 1] = "Property";
ElementKind[ElementKind["Accessor"] = 2] = "Accessor";
})(ElementKind || (ElementKind = {}));
if (inStrictMode) {
var seen = {};
for (var _i = 0, _a = node.properties; _i < _a.length; _i++) {
var prop = _a[_i];
if (prop.name.kind !== 69 /* Identifier */) {
continue;
}
var identifier = prop.name;
// ECMA-262 11.1.5 Object Initialiser
// If previous is not undefined then throw a SyntaxError exception if any of the following conditions are true
// a.This production is contained in strict code and IsDataDescriptor(previous) is true and
// IsDataDescriptor(propId.descriptor) is true.
// b.IsDataDescriptor(previous) is true and IsAccessorDescriptor(propId.descriptor) is true.
// c.IsAccessorDescriptor(previous) is true and IsDataDescriptor(propId.descriptor) is true.
// d.IsAccessorDescriptor(previous) is true and IsAccessorDescriptor(propId.descriptor) is true
// and either both previous and propId.descriptor have[[Get]] fields or both previous and propId.descriptor have[[Set]] fields
var currentKind = prop.kind === 245 /* PropertyAssignment */ || prop.kind === 246 /* ShorthandPropertyAssignment */ || prop.kind === 143 /* MethodDeclaration */
? 1 /* Property */
: 2 /* Accessor */;
var existingKind = seen[identifier.text];
if (!existingKind) {
seen[identifier.text] = currentKind;
continue;
}
if (currentKind === 1 /* Property */ && existingKind === 1 /* Property */) {
var span = ts.getErrorSpanForNode(file, identifier);
file.bindDiagnostics.push(ts.createFileDiagnostic(file, span.start, span.length, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode));
}
}
}
return bindAnonymousDeclaration(node, 4096 /* ObjectLiteral */, "__object");
}
function bindAnonymousDeclaration(node, symbolFlags, name) {
var symbol = createSymbol(symbolFlags, name);
addDeclarationToSymbol(symbol, node, symbolFlags);
}
function bindBlockScopedDeclaration(node, symbolFlags, symbolExcludes) {
switch (blockScopeContainer.kind) {
case 218 /* ModuleDeclaration */:
declareModuleMember(node, symbolFlags, symbolExcludes);
break;
case 248 /* SourceFile */:
if (ts.isExternalModule(container)) {
declareModuleMember(node, symbolFlags, symbolExcludes);
break;
}
// fall through.
default:
if (!blockScopeContainer.locals) {
blockScopeContainer.locals = {};
addToContainerChain(blockScopeContainer);
}
declareSymbol(blockScopeContainer.locals, undefined, node, symbolFlags, symbolExcludes);
}
}
function bindBlockScopedVariableDeclaration(node) {
bindBlockScopedDeclaration(node, 2 /* BlockScopedVariable */, 107455 /* BlockScopedVariableExcludes */);
}
// The binder visits every node in the syntax tree so it is a convenient place to perform a single localized
// check for reserved words used as identifiers in strict mode code.
function checkStrictModeIdentifier(node) {
if (inStrictMode &&
node.originalKeywordKind >= 106 /* FirstFutureReservedWord */ &&
node.originalKeywordKind <= 114 /* LastFutureReservedWord */ &&
!ts.isIdentifierName(node)) {
// Report error only if there are no parse errors in file
if (!file.parseDiagnostics.length) {
file.bindDiagnostics.push(ts.createDiagnosticForNode(node, getStrictModeIdentifierMessage(node), ts.declarationNameToString(node)));
}
}
}
function getStrictModeIdentifierMessage(node) {
// Provide specialized messages to help the user understand why we think they're in
// strict mode.
if (ts.getContainingClass(node)) {
return ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode;
}
if (file.externalModuleIndicator) {
return ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Modules_are_automatically_in_strict_mode;
}
return ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode;
}
function checkStrictModeBinaryExpression(node) {
if (inStrictMode && ts.isLeftHandSideExpression(node.left) && ts.isAssignmentOperator(node.operatorToken.kind)) {
// ECMA 262 (Annex C) The identifier eval or arguments may not appear as the LeftHandSideExpression of an
// Assignment operator(11.13) or of a PostfixExpression(11.3)
checkStrictModeEvalOrArguments(node, node.left);
}
}
function checkStrictModeCatchClause(node) {
// It is a SyntaxError if a TryStatement with a Catch occurs within strict code and the Identifier of the
// Catch production is eval or arguments
if (inStrictMode && node.variableDeclaration) {
checkStrictModeEvalOrArguments(node, node.variableDeclaration.name);
}
}
function checkStrictModeDeleteExpression(node) {
// Grammar checking
if (inStrictMode && node.expression.kind === 69 /* Identifier */) {
// When a delete operator occurs within strict mode code, a SyntaxError is thrown if its
// UnaryExpression is a direct reference to a variable, function argument, or function name
var span = ts.getErrorSpanForNode(file, node.expression);
file.bindDiagnostics.push(ts.createFileDiagnostic(file, span.start, span.length, ts.Diagnostics.delete_cannot_be_called_on_an_identifier_in_strict_mode));
}
}
function isEvalOrArgumentsIdentifier(node) {
return node.kind === 69 /* Identifier */ &&
(node.text === "eval" || node.text === "arguments");
}
function checkStrictModeEvalOrArguments(contextNode, name) {
if (name && name.kind === 69 /* Identifier */) {
var identifier = name;
if (isEvalOrArgumentsIdentifier(identifier)) {
// We check first if the name is inside class declaration or class expression; if so give explicit message
// otherwise report generic error message.
var span = ts.getErrorSpanForNode(file, name);
file.bindDiagnostics.push(ts.createFileDiagnostic(file, span.start, span.length, getStrictModeEvalOrArgumentsMessage(contextNode), identifier.text));
}
}
}
function getStrictModeEvalOrArgumentsMessage(node) {
// Provide specialized messages to help the user understand why we think they're in
// strict mode.
if (ts.getContainingClass(node)) {
return ts.Diagnostics.Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode;
}
if (file.externalModuleIndicator) {
return ts.Diagnostics.Invalid_use_of_0_Modules_are_automatically_in_strict_mode;
}
return ts.Diagnostics.Invalid_use_of_0_in_strict_mode;
}
function checkStrictModeFunctionName(node) {
if (inStrictMode) {
// It is a SyntaxError if the identifier eval or arguments appears within a FormalParameterList of a strict mode FunctionDeclaration or FunctionExpression (13.1))
checkStrictModeEvalOrArguments(node, node.name);
}
}
function checkStrictModeNumericLiteral(node) {
if (inStrictMode && node.flags & 32768 /* OctalLiteral */) {
file.bindDiagnostics.push(ts.createDiagnosticForNode(node, ts.Diagnostics.Octal_literals_are_not_allowed_in_strict_mode));
}
}
function checkStrictModePostfixUnaryExpression(node) {
// Grammar checking
// The identifier eval or arguments may not appear as the LeftHandSideExpression of an
// Assignment operator(11.13) or of a PostfixExpression(11.3) or as the UnaryExpression
// operated upon by a Prefix Increment(11.4.4) or a Prefix Decrement(11.4.5) operator.
if (inStrictMode) {
checkStrictModeEvalOrArguments(node, node.operand);
}
}
function checkStrictModePrefixUnaryExpression(node) {
// Grammar checking
if (inStrictMode) {
if (node.operator === 41 /* PlusPlusToken */ || node.operator === 42 /* MinusMinusToken */) {
checkStrictModeEvalOrArguments(node, node.operand);
}
}
}
function checkStrictModeWithStatement(node) {
// Grammar checking for withStatement
if (inStrictMode) {
errorOnFirstToken(node, ts.Diagnostics.with_statements_are_not_allowed_in_strict_mode);
}
}
function errorOnFirstToken(node, message, arg0, arg1, arg2) {
var span = ts.getSpanOfTokenAtPosition(file, node.pos);
file.bindDiagnostics.push(ts.createFileDiagnostic(file, span.start, span.length, message, arg0, arg1, arg2));
}
function getDestructuringParameterName(node) {
return "__" + ts.indexOf(node.parent.parameters, node);
}
function bind(node) {
if (!node) {
return;
}
node.parent = parent;
var savedInStrictMode = inStrictMode;
if (!savedInStrictMode) {
updateStrictMode(node);
}
// First we bind declaration nodes to a symbol if possible. We'll both create a symbol
// and then potentially add the symbol to an appropriate symbol table. Possible
// destination symbol tables are:
//
// 1) The 'exports' table of the current container's symbol.
// 2) The 'members' table of the current container's symbol.
// 3) The 'locals' table of the current container.
//
// However, not all symbols will end up in any of these tables. 'Anonymous' symbols
// (like TypeLiterals for example) will not be put in any table.
bindWorker(node);
// Then we recurse into the children of the node to bind them as well. For certain
// symbols we do specialized work when we recurse. For example, we'll keep track of
// the current 'container' node when it changes. This helps us know which symbol table
// a local should go into for example.
bindChildren(node);
inStrictMode = savedInStrictMode;
}
function updateStrictMode(node) {
switch (node.kind) {
case 248 /* SourceFile */:
case 219 /* ModuleBlock */:
updateStrictModeStatementList(node.statements);
return;
case 192 /* Block */:
if (ts.isFunctionLike(node.parent)) {
updateStrictModeStatementList(node.statements);
}
return;
case 214 /* ClassDeclaration */:
case 186 /* ClassExpression */:
// All classes are automatically in strict mode in ES6.
inStrictMode = true;
return;
}
}
function updateStrictModeStatementList(statements) {
for (var _i = 0, statements_1 = statements; _i < statements_1.length; _i++) {
var statement = statements_1[_i];
if (!ts.isPrologueDirective(statement)) {
return;
}
if (isUseStrictPrologueDirective(statement)) {
inStrictMode = true;
return;
}
}
}
/// Should be called only on prologue directives (isPrologueDirective(node) should be true)
function isUseStrictPrologueDirective(node) {
var nodeText = ts.getTextOfNodeFromSourceText(file.text, node.expression);
// Note: the node text must be exactly "use strict" or 'use strict'. It is not ok for the
// string to contain unicode escapes (as per ES5).
return nodeText === "\"use strict\"" || nodeText === "'use strict'";
}
function bindWorker(node) {
switch (node.kind) {
/* Strict mode checks */
case 69 /* Identifier */:
return checkStrictModeIdentifier(node);
case 181 /* BinaryExpression */:
if (ts.isInJavaScriptFile(node)) {
if (ts.isExportsPropertyAssignment(node)) {
bindExportsPropertyAssignment(node);
}
else if (ts.isModuleExportsAssignment(node)) {
bindModuleExportsAssignment(node);
}
}
return checkStrictModeBinaryExpression(node);
case 244 /* CatchClause */:
return checkStrictModeCatchClause(node);
case 175 /* DeleteExpression */:
return checkStrictModeDeleteExpression(node);
case 8 /* NumericLiteral */:
return checkStrictModeNumericLiteral(node);
case 180 /* PostfixUnaryExpression */:
return checkStrictModePostfixUnaryExpression(node);
case 179 /* PrefixUnaryExpression */:
return checkStrictModePrefixUnaryExpression(node);
case 205 /* WithStatement */:
return checkStrictModeWithStatement(node);
case 97 /* ThisKeyword */:
seenThisKeyword = true;
return;
case 137 /* TypeParameter */:
return declareSymbolAndAddToSymbolTable(node, 262144 /* TypeParameter */, 530912 /* TypeParameterExcludes */);
case 138 /* Parameter */:
return bindParameter(node);
case 211 /* VariableDeclaration */:
case 163 /* BindingElement */:
return bindVariableDeclarationOrBindingElement(node);
case 141 /* PropertyDeclaration */:
case 140 /* PropertySignature */:
return bindPropertyOrMethodOrAccessor(node, 4 /* Property */ | (node.questionToken ? 536870912 /* Optional */ : 0 /* None */), 107455 /* PropertyExcludes */);
case 245 /* PropertyAssignment */:
case 246 /* ShorthandPropertyAssignment */:
return bindPropertyOrMethodOrAccessor(node, 4 /* Property */, 107455 /* PropertyExcludes */);
case 247 /* EnumMember */:
return bindPropertyOrMethodOrAccessor(node, 8 /* EnumMember */, 107455 /* EnumMemberExcludes */);
case 147 /* CallSignature */:
case 148 /* ConstructSignature */:
case 149 /* IndexSignature */:
return declareSymbolAndAddToSymbolTable(node, 131072 /* Signature */, 0 /* None */);
case 143 /* MethodDeclaration */:
case 142 /* MethodSignature */:
// If this is an ObjectLiteralExpression method, then it sits in the same space
// as other properties in the object literal. So we use SymbolFlags.PropertyExcludes
// so that it will conflict with any other object literal members with the same
// name.
return bindPropertyOrMethodOrAccessor(node, 8192 /* Method */ | (node.questionToken ? 536870912 /* Optional */ : 0 /* None */), ts.isObjectLiteralMethod(node) ? 107455 /* PropertyExcludes */ : 99263 /* MethodExcludes */);
case 213 /* FunctionDeclaration */:
checkStrictModeFunctionName(node);
return declareSymbolAndAddToSymbolTable(node, 16 /* Function */, 106927 /* FunctionExcludes */);
case 144 /* Constructor */:
return declareSymbolAndAddToSymbolTable(node, 16384 /* Constructor */, /*symbolExcludes:*/ 0 /* None */);
case 145 /* GetAccessor */:
return bindPropertyOrMethodOrAccessor(node, 32768 /* GetAccessor */, 41919 /* GetAccessorExcludes */);
case 146 /* SetAccessor */:
return bindPropertyOrMethodOrAccessor(node, 65536 /* SetAccessor */, 74687 /* SetAccessorExcludes */);
case 152 /* FunctionType */:
case 153 /* ConstructorType */:
return bindFunctionOrConstructorType(node);
case 155 /* TypeLiteral */:
return bindAnonymousDeclaration(node, 2048 /* TypeLiteral */, "__type");
case 165 /* ObjectLiteralExpression */:
return bindObjectLiteralExpression(node);
case 173 /* FunctionExpression */:
case 174 /* ArrowFunction */:
checkStrictModeFunctionName(node);
var bindingName = node.name ? node.name.text : "__function";
return bindAnonymousDeclaration(node, 16 /* Function */, bindingName);
case 168 /* CallExpression */:
if (ts.isInJavaScriptFile(node)) {
bindCallExpression(node);
}
break;
// Members of classes, interfaces, and modules
case 186 /* ClassExpression */:
case 214 /* ClassDeclaration */:
return bindClassLikeDeclaration(node);
case 215 /* InterfaceDeclaration */:
return bindBlockScopedDeclaration(node, 64 /* Interface */, 792960 /* InterfaceExcludes */);
case 216 /* TypeAliasDeclaration */:
return bindBlockScopedDeclaration(node, 524288 /* TypeAlias */, 793056 /* TypeAliasExcludes */);
case 217 /* EnumDeclaration */:
return bindEnumDeclaration(node);
case 218 /* ModuleDeclaration */:
return bindModuleDeclaration(node);
// Imports and exports
case 221 /* ImportEqualsDeclaration */:
case 224 /* NamespaceImport */:
case 226 /* ImportSpecifier */:
case 230 /* ExportSpecifier */:
return declareSymbolAndAddToSymbolTable(node, 8388608 /* Alias */, 8388608 /* AliasExcludes */);
case 223 /* ImportClause */:
return bindImportClause(node);
case 228 /* ExportDeclaration */:
return bindExportDeclaration(node);
case 227 /* ExportAssignment */:
return bindExportAssignment(node);
case 248 /* SourceFile */:
return bindSourceFileIfExternalModule();
}
}
function bindSourceFileIfExternalModule() {
setExportContextFlag(file);
if (ts.isExternalModule(file)) {
bindSourceFileAsExternalModule();
}
}
function bindSourceFileAsExternalModule() {
bindAnonymousDeclaration(file, 512 /* ValueModule */, "\"" + ts.removeFileExtension(file.fileName) + "\"");
}
function bindExportAssignment(node) {
var boundExpression = node.kind === 227 /* ExportAssignment */ ? node.expression : node.right;
if (!container.symbol || !container.symbol.exports) {
// Export assignment in some sort of block construct
bindAnonymousDeclaration(node, 8388608 /* Alias */, getDeclarationName(node));
}
else if (boundExpression.kind === 69 /* Identifier */) {
// An export default clause with an identifier exports all meanings of that identifier
declareSymbol(container.symbol.exports, container.symbol, node, 8388608 /* Alias */, 107455 /* PropertyExcludes */ | 8388608 /* AliasExcludes */);
}
else {
// An export default clause with an expression exports a value
declareSymbol(container.symbol.exports, container.symbol, node, 4 /* Property */, 107455 /* PropertyExcludes */ | 8388608 /* AliasExcludes */);
}
}
function bindExportDeclaration(node) {
if (!container.symbol || !container.symbol.exports) {
// Export * in some sort of block construct
bindAnonymousDeclaration(node, 1073741824 /* ExportStar */, getDeclarationName(node));
}
else if (!node.exportClause) {
// All export * declarations are collected in an __export symbol
declareSymbol(container.symbol.exports, container.symbol, node, 1073741824 /* ExportStar */, 0 /* None */);
}
}
function bindImportClause(node) {
if (node.name) {
declareSymbolAndAddToSymbolTable(node, 8388608 /* Alias */, 8388608 /* AliasExcludes */);
}
}
function setCommonJsModuleIndicator(node) {
if (!file.commonJsModuleIndicator) {
file.commonJsModuleIndicator = node;
bindSourceFileAsExternalModule();
}
}
function bindExportsPropertyAssignment(node) {
// When we create a property via 'exports.foo = bar', the 'exports.foo' property access
// expression is the declaration
setCommonJsModuleIndicator(node);
declareSymbol(file.symbol.exports, file.symbol, node.left, 4 /* Property */ | 7340032 /* Export */, 0 /* None */);
}
function bindModuleExportsAssignment(node) {
// 'module.exports = expr' assignment
setCommonJsModuleIndicator(node);
bindExportAssignment(node);
}
function bindCallExpression(node) {
// We're only inspecting call expressions to detect CommonJS modules, so we can skip
// this check if we've already seen the module indicator
if (!file.commonJsModuleIndicator && ts.isRequireCall(node)) {
setCommonJsModuleIndicator(node);
}
}
function bindClassLikeDeclaration(node) {
if (node.kind === 214 /* ClassDeclaration */) {
bindBlockScopedDeclaration(node, 32 /* Class */, 899519 /* ClassExcludes */);
}
else {
var bindingName = node.name ? node.name.text : "__class";
bindAnonymousDeclaration(node, 32 /* Class */, bindingName);
// Add name of class expression into the map for semantic classifier
if (node.name) {
classifiableNames[node.name.text] = node.name.text;
}
}
var symbol = node.symbol;
// TypeScript 1.0 spec (April 2014): 8.4
// Every class automatically contains a static property member named 'prototype', the
// type of which is an instantiation of the class type with type Any supplied as a type
// argument for each type parameter. It is an error to explicitly declare a static
// property member with the name 'prototype'.
//
// Note: we check for this here because this class may be merging into a module. The
// module might have an exported variable called 'prototype'. We can't allow that as
// that would clash with the built-in 'prototype' for the class.
var prototypeSymbol = createSymbol(4 /* Property */ | 134217728 /* Prototype */, "prototype");
if (ts.hasProperty(symbol.exports, prototypeSymbol.name)) {
if (node.name) {
node.name.parent = node;
}
file.bindDiagnostics.push(ts.createDiagnosticForNode(symbol.exports[prototypeSymbol.name].declarations[0], ts.Diagnostics.Duplicate_identifier_0, prototypeSymbol.name));
}
symbol.exports[prototypeSymbol.name] = prototypeSymbol;
prototypeSymbol.parent = symbol;
}
function bindEnumDeclaration(node) {
return ts.isConst(node)
? bindBlockScopedDeclaration(node, 128 /* ConstEnum */, 899967 /* ConstEnumExcludes */)
: bindBlockScopedDeclaration(node, 256 /* RegularEnum */, 899327 /* RegularEnumExcludes */);
}
function bindVariableDeclarationOrBindingElement(node) {
if (inStrictMode) {
checkStrictModeEvalOrArguments(node, node.name);
}
if (!ts.isBindingPattern(node.name)) {
if (ts.isBlockOrCatchScoped(node)) {
bindBlockScopedVariableDeclaration(node);
}
else if (ts.isParameterDeclaration(node)) {
// It is safe to walk up parent chain to find whether the node is a destructing parameter declaration
// because its parent chain has already been set up, since parents are set before descending into children.
//
// If node is a binding element in parameter declaration, we need to use ParameterExcludes.
// Using ParameterExcludes flag allows the compiler to report an error on duplicate identifiers in Parameter Declaration
// For example:
// function foo([a,a]) {} // Duplicate Identifier error
// function bar(a,a) {} // Duplicate Identifier error, parameter declaration in this case is handled in bindParameter
// // which correctly set excluded symbols
declareSymbolAndAddToSymbolTable(node, 1 /* FunctionScopedVariable */, 107455 /* ParameterExcludes */);
}
else {
declareSymbolAndAddToSymbolTable(node, 1 /* FunctionScopedVariable */, 107454 /* FunctionScopedVariableExcludes */);
}
}
}
function bindParameter(node) {
if (inStrictMode) {
// It is a SyntaxError if the identifier eval or arguments appears within a FormalParameterList of a
// strict mode FunctionLikeDeclaration or FunctionExpression(13.1)
checkStrictModeEvalOrArguments(node, node.name);
}
if (ts.isBindingPattern(node.name)) {
bindAnonymousDeclaration(node, 1 /* FunctionScopedVariable */, getDestructuringParameterName(node));
}
else {
declareSymbolAndAddToSymbolTable(node, 1 /* FunctionScopedVariable */, 107455 /* ParameterExcludes */);
}
// If this is a property-parameter, then also declare the property symbol into the
// containing class.
if (node.flags & 56 /* AccessibilityModifier */ &&
node.parent.kind === 144 /* Constructor */ &&
ts.isClassLike(node.parent.parent)) {
var classDeclaration = node.parent.parent;
declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4 /* Property */, 107455 /* PropertyExcludes */);
}
}
function bindPropertyOrMethodOrAccessor(node, symbolFlags, symbolExcludes) {
return ts.hasDynamicName(node)
? bindAnonymousDeclaration(node, symbolFlags, "__computed")
: declareSymbolAndAddToSymbolTable(node, symbolFlags, symbolExcludes);
}
// reachability checks
function pushNamedLabel(name) {
initializeReachabilityStateIfNecessary();
if (ts.hasProperty(labelIndexMap, name.text)) {
return false;
}
labelIndexMap[name.text] = labelStack.push(1 /* Unintialized */) - 1;
return true;
}
function pushImplicitLabel() {
initializeReachabilityStateIfNecessary();
var index = labelStack.push(1 /* Unintialized */) - 1;
implicitLabels.push(index);
return index;
}
function popNamedLabel(label, outerState) {
var index = labelIndexMap[label.text];
ts.Debug.assert(index !== undefined);
ts.Debug.assert(labelStack.length == index + 1);
labelIndexMap[label.text] = undefined;
setCurrentStateAtLabel(labelStack.pop(), outerState, label);
}
function popImplicitLabel(implicitLabelIndex, outerState) {
if (labelStack.length !== implicitLabelIndex + 1) {
ts.Debug.assert(false, "Label stack: " + labelStack.length + ", index:" + implicitLabelIndex);
}
var i = implicitLabels.pop();
if (implicitLabelIndex !== i) {
ts.Debug.assert(false, "i: " + i + ", index: " + implicitLabelIndex);
}
setCurrentStateAtLabel(labelStack.pop(), outerState, /*name*/ undefined);
}
function setCurrentStateAtLabel(innerMergedState, outerState, label) {
if (innerMergedState === 1 /* Unintialized */) {
if (label && !options.allowUnusedLabels) {
file.bindDiagnostics.push(ts.createDiagnosticForNode(label, ts.Diagnostics.Unused_label));
}
currentReachabilityState = outerState;
}
else {
currentReachabilityState = or(innerMergedState, outerState);
}
}
function jumpToLabel(label, outerState) {
initializeReachabilityStateIfNecessary();
var index = label ? labelIndexMap[label.text] : ts.lastOrUndefined(implicitLabels);
if (index === undefined) {
// reference to unknown label or
// break/continue used outside of loops
return false;
}
var stateAtLabel = labelStack[index];
labelStack[index] = stateAtLabel === 1 /* Unintialized */ ? outerState : or(stateAtLabel, outerState);
return true;
}
function checkUnreachable(node) {
switch (currentReachabilityState) {
case 4 /* Unreachable */:
var reportError =
// report error on all statements except empty ones
(ts.isStatement(node) && node.kind !== 194 /* EmptyStatement */) ||
// report error on class declarations
node.kind === 214 /* ClassDeclaration */ ||
// report error on instantiated modules or const-enums only modules if preserveConstEnums is set
(node.kind === 218 /* ModuleDeclaration */ && shouldReportErrorOnModuleDeclaration(node)) ||
// report error on regular enums and const enums if preserveConstEnums is set
(node.kind === 217 /* EnumDeclaration */ && (!ts.isConstEnumDeclaration(node) || options.preserveConstEnums));
if (reportError) {
currentReachabilityState = 8 /* ReportedUnreachable */;
// unreachable code is reported if
// - user has explicitly asked about it AND
// - statement is in not ambient context (statements in ambient context is already an error
// so we should not report extras) AND
// - node is not variable statement OR
// - node is block scoped variable statement OR
// - node is not block scoped variable statement and at least one variable declaration has initializer
// Rationale: we don't want to report errors on non-initialized var's since they are hoisted
// On the other side we do want to report errors on non-initialized 'lets' because of TDZ
var reportUnreachableCode = !options.allowUnreachableCode &&
!ts.isInAmbientContext(node) &&
(node.kind !== 193 /* VariableStatement */ ||
ts.getCombinedNodeFlags(node.declarationList) & 24576 /* BlockScoped */ ||
ts.forEach(node.declarationList.declarations, function (d) { return d.initializer; }));
if (reportUnreachableCode) {
errorOnFirstToken(node, ts.Diagnostics.Unreachable_code_detected);
}
}
case 8 /* ReportedUnreachable */:
return true;
default:
return false;
}
function shouldReportErrorOnModuleDeclaration(node) {
var instanceState = getModuleInstanceState(node);
return instanceState === 1 /* Instantiated */ || (instanceState === 2 /* ConstEnumOnly */ && options.preserveConstEnums);
}
}
function initializeReachabilityStateIfNecessary() {
if (labelIndexMap) {
return;
}
currentReachabilityState = 2 /* Reachable */;
labelIndexMap = {};
labelStack = [];
implicitLabels = [];
}
} | ".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at | createBinder | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function bindSourceFile(f, opts) {
file = f;
options = opts;
inStrictMode = !!file.externalModuleIndicator;
classifiableNames = {};
Symbol = ts.objectAllocator.getSymbolConstructor();
if (!file.locals) {
bind(file);
file.symbolCount = symbolCount;
file.classifiableNames = classifiableNames;
}
parent = undefined;
container = undefined;
blockScopeContainer = undefined;
lastContainer = undefined;
seenThisKeyword = false;
hasExplicitReturn = false;
labelStack = undefined;
labelIndexMap = undefined;
implicitLabels = undefined;
} | ".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at | bindSourceFile | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function createSymbol(flags, name) {
symbolCount++;
return new Symbol(flags, name);
} | ".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at | createSymbol | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function addDeclarationToSymbol(symbol, node, symbolFlags) {
symbol.flags |= symbolFlags;
node.symbol = symbol;
if (!symbol.declarations) {
symbol.declarations = [];
}
symbol.declarations.push(node);
if (symbolFlags & 1952 /* HasExports */ && !symbol.exports) {
symbol.exports = {};
}
if (symbolFlags & 6240 /* HasMembers */ && !symbol.members) {
symbol.members = {};
}
if (symbolFlags & 107455 /* Value */ && !symbol.valueDeclaration) {
symbol.valueDeclaration = node;
}
} | ".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at | addDeclarationToSymbol | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function getDeclarationName(node) {
if (node.name) {
if (node.kind === 218 /* ModuleDeclaration */ && node.name.kind === 9 /* StringLiteral */) {
return "\"" + node.name.text + "\"";
}
if (node.name.kind === 136 /* ComputedPropertyName */) {
var nameExpression = node.name.expression;
// treat computed property names where expression is string/numeric literal as just string/numeric literal
if (ts.isStringOrNumericLiteral(nameExpression.kind)) {
return nameExpression.text;
}
ts.Debug.assert(ts.isWellKnownSymbolSyntactically(nameExpression));
return ts.getPropertyNameForKnownSymbolName(nameExpression.name.text);
}
return node.name.text;
}
switch (node.kind) {
case 144 /* Constructor */:
return "__constructor";
case 152 /* FunctionType */:
case 147 /* CallSignature */:
return "__call";
case 153 /* ConstructorType */:
case 148 /* ConstructSignature */:
return "__new";
case 149 /* IndexSignature */:
return "__index";
case 228 /* ExportDeclaration */:
return "__export";
case 227 /* ExportAssignment */:
return node.isExportEquals ? "export=" : "default";
case 181 /* BinaryExpression */:
// Binary expression case is for JS module 'module.exports = expr'
return "export=";
case 213 /* FunctionDeclaration */:
case 214 /* ClassDeclaration */:
return node.flags & 512 /* Default */ ? "default" : undefined;
}
} | ".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at | getDeclarationName | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function getDisplayName(node) {
return node.name ? ts.declarationNameToString(node.name) : getDeclarationName(node);
} | ".length; pos < end;) {
var ch = content.charCodeAt(pos);
pos++;
if (ch === 64 /* at | getDisplayName | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function declareSymbol(symbolTable, parent, node, includes, excludes) {
ts.Debug.assert(!ts.hasDynamicName(node));
var isDefaultExport = node.flags & 512 /* Default */;
// The exported symbol for an export default function/class node is always named "default"
var name = isDefaultExport && parent ? "default" : getDeclarationName(node);
var symbol;
if (name !== undefined) {
// Check and see if the symbol table already has a symbol with this name. If not,
// create a new symbol with this name and add it to the table. Note that we don't
// give the new symbol any flags *yet*. This ensures that it will not conflict
// with the 'excludes' flags we pass in.
//
// If we do get an existing symbol, see if it conflicts with the new symbol we're
// creating. For example, a 'var' symbol and a 'class' symbol will conflict within
// the same symbol table. If we have a conflict, report the issue on each
// declaration we have for this symbol, and then create a new symbol for this
// declaration.
//
// If we created a new symbol, either because we didn't have a symbol with this name
// in the symbol table, or we conflicted with an existing symbol, then just add this
// node as the sole declaration of the new symbol.
//
// Otherwise, we'll be merging into a compatible existing symbol (for example when
// you have multiple 'vars' with the same name in the same container). In this case
// just add this node into the declarations list of the symbol.
symbol = ts.hasProperty(symbolTable, name)
? symbolTable[name]
: (symbolTable[name] = createSymbol(0 /* None */, name));
if (name && (includes & 788448 /* Classifiable */)) {
classifiableNames[name] = name;
}
if (symbol.flags & excludes) {
if (node.name) {
node.name.parent = node;
}
// Report errors every position with duplicate declaration
// Report errors on previous encountered declarations
var message = symbol.flags & 2 /* BlockScopedVariable */
? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0
: ts.Diagnostics.Duplicate_identifier_0;
ts.forEach(symbol.declarations, function (declaration) {
if (declaration.flags & 512 /* Default */) {
message = ts.Diagnostics.A_module_cannot_have_multiple_default_exports;
}
});
ts.forEach(symbol.declarations, function (declaration) {
file.bindDiagnostics.push(ts.createDiagnosticForNode(declaration.name || declaration, message, getDisplayName(declaration)));
});
file.bindDiagnostics.push(ts.createDiagnosticForNode(node.name || node, message, getDisplayName(node)));
symbol = createSymbol(0 /* None */, name);
}
}
else {
symbol = createSymbol(0 /* None */, "__missing");
}
addDeclarationToSymbol(symbol, node, includes);
symbol.parent = parent;
return symbol;
} | Declares a Symbol for the node and adds it to symbols. Reports errors for conflicting identifier names.
@param symbolTable - The symbol table which node will be added to.
@param parent - node's parent declaration.
@param node - The declaration to be added to the symbol table
@param includes - The SymbolFlags that node has in addition to its declaration type (eg: export, ambient, etc.)
@param excludes - The flags which node cannot be declared alongside in a symbol table. Used to report forbidden declarations. | declareSymbol | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function declareModuleMember(node, symbolFlags, symbolExcludes) {
var hasExportModifier = ts.getCombinedNodeFlags(node) & 2 /* Export */;
if (symbolFlags & 8388608 /* Alias */) {
if (node.kind === 230 /* ExportSpecifier */ || (node.kind === 221 /* ImportEqualsDeclaration */ && hasExportModifier)) {
return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes);
}
else {
return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes);
}
}
else {
// Exported module members are given 2 symbols: A local symbol that is classified with an ExportValue,
// ExportType, or ExportContainer flag, and an associated export symbol with all the correct flags set
// on it. There are 2 main reasons:
//
// 1. We treat locals and exports of the same name as mutually exclusive within a container.
// That means the binder will issue a Duplicate Identifier error if you mix locals and exports
// with the same name in the same container.
// TODO: Make this a more specific error and decouple it from the exclusion logic.
// 2. When we checkIdentifier in the checker, we set its resolved symbol to the local symbol,
// but return the export symbol (by calling getExportSymbolOfValueSymbolIfExported). That way
// when the emitter comes back to it, it knows not to qualify the name if it was found in a containing scope.
if (hasExportModifier || container.flags & 131072 /* ExportContext */) {
var exportKind = (symbolFlags & 107455 /* Value */ ? 1048576 /* ExportValue */ : 0) |
(symbolFlags & 793056 /* Type */ ? 2097152 /* ExportType */ : 0) |
(symbolFlags & 1536 /* Namespace */ ? 4194304 /* ExportNamespace */ : 0);
var local = declareSymbol(container.locals, undefined, node, exportKind, symbolExcludes);
local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes);
node.localSymbol = local;
return local;
}
else {
return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes);
}
}
} | Declares a Symbol for the node and adds it to symbols. Reports errors for conflicting identifier names.
@param symbolTable - The symbol table which node will be added to.
@param parent - node's parent declaration.
@param node - The declaration to be added to the symbol table
@param includes - The SymbolFlags that node has in addition to its declaration type (eg: export, ambient, etc.)
@param excludes - The flags which node cannot be declared alongside in a symbol table. Used to report forbidden declarations. | declareModuleMember | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function bindChildren(node) {
// Before we recurse into a node's chilren, we first save the existing parent, container
// and block-container. Then after we pop out of processing the children, we restore
// these saved values.
var saveParent = parent;
var saveContainer = container;
var savedBlockScopeContainer = blockScopeContainer;
// This node will now be set as the parent of all of its children as we recurse into them.
parent = node;
// Depending on what kind of node this is, we may have to adjust the current container
// and block-container. If the current node is a container, then it is automatically
// considered the current block-container as well. Also, for containers that we know
// may contain locals, we proactively initialize the .locals field. We do this because
// it's highly likely that the .locals will be needed to place some child in (for example,
// a parameter, or variable declaration).
//
// However, we do not proactively create the .locals for block-containers because it's
// totally normal and common for block-containers to never actually have a block-scoped
// variable in them. We don't want to end up allocating an object for every 'block' we
// run into when most of them won't be necessary.
//
// Finally, if this is a block-container, then we clear out any existing .locals object
// it may contain within it. This happens in incremental scenarios. Because we can be
// reusing a node from a previous compilation, that node may have had 'locals' created
// for it. We must clear this so we don't accidently move any stale data forward from
// a previous compilation.
var containerFlags = getContainerFlags(node);
if (containerFlags & 1 /* IsContainer */) {
container = blockScopeContainer = node;
if (containerFlags & 4 /* HasLocals */) {
container.locals = {};
}
addToContainerChain(container);
}
else if (containerFlags & 2 /* IsBlockScopedContainer */) {
blockScopeContainer = node;
blockScopeContainer.locals = undefined;
}
var savedReachabilityState;
var savedLabelStack;
var savedLabels;
var savedImplicitLabels;
var savedHasExplicitReturn;
var kind = node.kind;
var flags = node.flags;
// reset all reachability check related flags on node (for incremental scenarios)
flags &= ~1572864 /* ReachabilityCheckFlags */;
if (kind === 215 /* InterfaceDeclaration */) {
seenThisKeyword = false;
}
var saveState = kind === 248 /* SourceFile */ || kind === 219 /* ModuleBlock */ || ts.isFunctionLikeKind(kind);
if (saveState) {
savedReachabilityState = currentReachabilityState;
savedLabelStack = labelStack;
savedLabels = labelIndexMap;
savedImplicitLabels = implicitLabels;
savedHasExplicitReturn = hasExplicitReturn;
currentReachabilityState = 2 /* Reachable */;
hasExplicitReturn = false;
labelStack = labelIndexMap = implicitLabels = undefined;
}
bindReachableStatement(node);
if (currentReachabilityState === 2 /* Reachable */ && ts.isFunctionLikeKind(kind) && ts.nodeIsPresent(node.body)) {
flags |= 524288 /* HasImplicitReturn */;
if (hasExplicitReturn) {
flags |= 1048576 /* HasExplicitReturn */;
}
}
if (kind === 215 /* InterfaceDeclaration */) {
flags = seenThisKeyword ? flags | 262144 /* ContainsThis */ : flags & ~262144 /* ContainsThis */;
}
node.flags = flags;
if (saveState) {
hasExplicitReturn = savedHasExplicitReturn;
currentReachabilityState = savedReachabilityState;
labelStack = savedLabelStack;
labelIndexMap = savedLabels;
implicitLabels = savedImplicitLabels;
}
container = saveContainer;
parent = saveParent;
blockScopeContainer = savedBlockScopeContainer;
} | Declares a Symbol for the node and adds it to symbols. Reports errors for conflicting identifier names.
@param symbolTable - The symbol table which node will be added to.
@param parent - node's parent declaration.
@param node - The declaration to be added to the symbol table
@param includes - The SymbolFlags that node has in addition to its declaration type (eg: export, ambient, etc.)
@param excludes - The flags which node cannot be declared alongside in a symbol table. Used to report forbidden declarations. | bindChildren | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function bindReachableStatement(node) {
if (checkUnreachable(node)) {
ts.forEachChild(node, bind);
return;
}
switch (node.kind) {
case 198 /* WhileStatement */:
bindWhileStatement(node);
break;
case 197 /* DoStatement */:
bindDoStatement(node);
break;
case 199 /* ForStatement */:
bindForStatement(node);
break;
case 200 /* ForInStatement */:
case 201 /* ForOfStatement */:
bindForInOrForOfStatement(node);
break;
case 196 /* IfStatement */:
bindIfStatement(node);
break;
case 204 /* ReturnStatement */:
case 208 /* ThrowStatement */:
bindReturnOrThrow(node);
break;
case 203 /* BreakStatement */:
case 202 /* ContinueStatement */:
bindBreakOrContinueStatement(node);
break;
case 209 /* TryStatement */:
bindTryStatement(node);
break;
case 206 /* SwitchStatement */:
bindSwitchStatement(node);
break;
case 220 /* CaseBlock */:
bindCaseBlock(node);
break;
case 207 /* LabeledStatement */:
bindLabeledStatement(node);
break;
default:
ts.forEachChild(node, bind);
break;
}
} | Returns true if node and its subnodes were successfully traversed.
Returning false means that node was not examined and caller needs to dive into the node himself. | bindReachableStatement | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function bindWhileStatement(n) {
var preWhileState = n.expression.kind === 84 /* FalseKeyword */ ? 4 /* Unreachable */ : currentReachabilityState;
var postWhileState = n.expression.kind === 99 /* TrueKeyword */ ? 4 /* Unreachable */ : currentReachabilityState;
// bind expressions (don't affect reachability)
bind(n.expression);
currentReachabilityState = preWhileState;
var postWhileLabel = pushImplicitLabel();
bind(n.statement);
popImplicitLabel(postWhileLabel, postWhileState);
} | Returns true if node and its subnodes were successfully traversed.
Returning false means that node was not examined and caller needs to dive into the node himself. | bindWhileStatement | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function bindDoStatement(n) {
var preDoState = currentReachabilityState;
var postDoLabel = pushImplicitLabel();
bind(n.statement);
var postDoState = n.expression.kind === 99 /* TrueKeyword */ ? 4 /* Unreachable */ : preDoState;
popImplicitLabel(postDoLabel, postDoState);
// bind expressions (don't affect reachability)
bind(n.expression);
} | Returns true if node and its subnodes were successfully traversed.
Returning false means that node was not examined and caller needs to dive into the node himself. | bindDoStatement | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function bindForStatement(n) {
var preForState = currentReachabilityState;
var postForLabel = pushImplicitLabel();
// bind expressions (don't affect reachability)
bind(n.initializer);
bind(n.condition);
bind(n.incrementor);
bind(n.statement);
// for statement is considered infinite when it condition is either omitted or is true keyword
// - for(..;;..)
// - for(..;true;..)
var isInfiniteLoop = (!n.condition || n.condition.kind === 99 /* TrueKeyword */);
var postForState = isInfiniteLoop ? 4 /* Unreachable */ : preForState;
popImplicitLabel(postForLabel, postForState);
} | Returns true if node and its subnodes were successfully traversed.
Returning false means that node was not examined and caller needs to dive into the node himself. | bindForStatement | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function bindForInOrForOfStatement(n) {
var preStatementState = currentReachabilityState;
var postStatementLabel = pushImplicitLabel();
// bind expressions (don't affect reachability)
bind(n.initializer);
bind(n.expression);
bind(n.statement);
popImplicitLabel(postStatementLabel, preStatementState);
} | Returns true if node and its subnodes were successfully traversed.
Returning false means that node was not examined and caller needs to dive into the node himself. | bindForInOrForOfStatement | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function bindIfStatement(n) {
// denotes reachability state when entering 'thenStatement' part of the if statement:
// i.e. if condition is false then thenStatement is unreachable
var ifTrueState = n.expression.kind === 84 /* FalseKeyword */ ? 4 /* Unreachable */ : currentReachabilityState;
// denotes reachability state when entering 'elseStatement':
// i.e. if condition is true then elseStatement is unreachable
var ifFalseState = n.expression.kind === 99 /* TrueKeyword */ ? 4 /* Unreachable */ : currentReachabilityState;
currentReachabilityState = ifTrueState;
// bind expression (don't affect reachability)
bind(n.expression);
bind(n.thenStatement);
if (n.elseStatement) {
var preElseState = currentReachabilityState;
currentReachabilityState = ifFalseState;
bind(n.elseStatement);
currentReachabilityState = or(currentReachabilityState, preElseState);
}
else {
currentReachabilityState = or(currentReachabilityState, ifFalseState);
}
} | Returns true if node and its subnodes were successfully traversed.
Returning false means that node was not examined and caller needs to dive into the node himself. | bindIfStatement | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function bindReturnOrThrow(n) {
// bind expression (don't affect reachability)
bind(n.expression);
if (n.kind === 204 /* ReturnStatement */) {
hasExplicitReturn = true;
}
currentReachabilityState = 4 /* Unreachable */;
} | Returns true if node and its subnodes were successfully traversed.
Returning false means that node was not examined and caller needs to dive into the node himself. | bindReturnOrThrow | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function bindBreakOrContinueStatement(n) {
// call bind on label (don't affect reachability)
bind(n.label);
// for continue case touch label so it will be marked a used
var isValidJump = jumpToLabel(n.label, n.kind === 203 /* BreakStatement */ ? currentReachabilityState : 4 /* Unreachable */);
if (isValidJump) {
currentReachabilityState = 4 /* Unreachable */;
}
} | Returns true if node and its subnodes were successfully traversed.
Returning false means that node was not examined and caller needs to dive into the node himself. | bindBreakOrContinueStatement | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function bindTryStatement(n) {
// catch\finally blocks has the same reachability as try block
var preTryState = currentReachabilityState;
bind(n.tryBlock);
var postTryState = currentReachabilityState;
currentReachabilityState = preTryState;
bind(n.catchClause);
var postCatchState = currentReachabilityState;
currentReachabilityState = preTryState;
bind(n.finallyBlock);
// post catch/finally state is reachable if
// - post try state is reachable - control flow can fall out of try block
// - post catch state is reachable - control flow can fall out of catch block
currentReachabilityState = or(postTryState, postCatchState);
} | Returns true if node and its subnodes were successfully traversed.
Returning false means that node was not examined and caller needs to dive into the node himself. | bindTryStatement | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function bindSwitchStatement(n) {
var preSwitchState = currentReachabilityState;
var postSwitchLabel = pushImplicitLabel();
// bind expression (don't affect reachability)
bind(n.expression);
bind(n.caseBlock);
var hasDefault = ts.forEach(n.caseBlock.clauses, function (c) { return c.kind === 242 /* DefaultClause */; });
// post switch state is unreachable if switch is exaustive (has a default case ) and does not have fallthrough from the last case
var postSwitchState = hasDefault && currentReachabilityState !== 2 /* Reachable */ ? 4 /* Unreachable */ : preSwitchState;
popImplicitLabel(postSwitchLabel, postSwitchState);
} | Returns true if node and its subnodes were successfully traversed.
Returning false means that node was not examined and caller needs to dive into the node himself. | bindSwitchStatement | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function bindCaseBlock(n) {
var startState = currentReachabilityState;
for (var _i = 0, _a = n.clauses; _i < _a.length; _i++) {
var clause = _a[_i];
currentReachabilityState = startState;
bind(clause);
if (clause.statements.length && currentReachabilityState === 2 /* Reachable */ && options.noFallthroughCasesInSwitch) {
errorOnFirstToken(clause, ts.Diagnostics.Fallthrough_case_in_switch);
}
}
} | Returns true if node and its subnodes were successfully traversed.
Returning false means that node was not examined and caller needs to dive into the node himself. | bindCaseBlock | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function bindLabeledStatement(n) {
// call bind on label (don't affect reachability)
bind(n.label);
var ok = pushNamedLabel(n.label);
bind(n.statement);
if (ok) {
popNamedLabel(n.label, currentReachabilityState);
}
} | Returns true if node and its subnodes were successfully traversed.
Returning false means that node was not examined and caller needs to dive into the node himself. | bindLabeledStatement | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function getContainerFlags(node) {
switch (node.kind) {
case 186 /* ClassExpression */:
case 214 /* ClassDeclaration */:
case 215 /* InterfaceDeclaration */:
case 217 /* EnumDeclaration */:
case 155 /* TypeLiteral */:
case 165 /* ObjectLiteralExpression */:
return 1 /* IsContainer */;
case 147 /* CallSignature */:
case 148 /* ConstructSignature */:
case 149 /* IndexSignature */:
case 143 /* MethodDeclaration */:
case 142 /* MethodSignature */:
case 213 /* FunctionDeclaration */:
case 144 /* Constructor */:
case 145 /* GetAccessor */:
case 146 /* SetAccessor */:
case 152 /* FunctionType */:
case 153 /* ConstructorType */:
case 173 /* FunctionExpression */:
case 174 /* ArrowFunction */:
case 218 /* ModuleDeclaration */:
case 248 /* SourceFile */:
case 216 /* TypeAliasDeclaration */:
return 5 /* IsContainerWithLocals */;
case 244 /* CatchClause */:
case 199 /* ForStatement */:
case 200 /* ForInStatement */:
case 201 /* ForOfStatement */:
case 220 /* CaseBlock */:
return 2 /* IsBlockScopedContainer */;
case 192 /* Block */:
// do not treat blocks directly inside a function as a block-scoped-container.
// Locals that reside in this block should go to the function locals. Othewise 'x'
// would not appear to be a redeclaration of a block scoped local in the following
// example:
//
// function foo() {
// var x;
// let x;
// }
//
// If we placed 'var x' into the function locals and 'let x' into the locals of
// the block, then there would be no collision.
//
// By not creating a new block-scoped-container here, we ensure that both 'var x'
// and 'let x' go into the Function-container's locals, and we do get a collision
// conflict.
return ts.isFunctionLike(node.parent) ? 0 /* None */ : 2 /* IsBlockScopedContainer */;
}
return 0 /* None */;
} | Returns true if node and its subnodes were successfully traversed.
Returning false means that node was not examined and caller needs to dive into the node himself. | getContainerFlags | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function addToContainerChain(next) {
if (lastContainer) {
lastContainer.nextContainer = next;
}
lastContainer = next;
} | Returns true if node and its subnodes were successfully traversed.
Returning false means that node was not examined and caller needs to dive into the node himself. | addToContainerChain | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function declareSymbolAndAddToSymbolTable(node, symbolFlags, symbolExcludes) {
// Just call this directly so that the return type of this function stays "void".
declareSymbolAndAddToSymbolTableWorker(node, symbolFlags, symbolExcludes);
} | Returns true if node and its subnodes were successfully traversed.
Returning false means that node was not examined and caller needs to dive into the node himself. | declareSymbolAndAddToSymbolTable | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function declareSymbolAndAddToSymbolTableWorker(node, symbolFlags, symbolExcludes) {
switch (container.kind) {
// Modules, source files, and classes need specialized handling for how their
// members are declared (for example, a member of a class will go into a specific
// symbol table depending on if it is static or not). We defer to specialized
// handlers to take care of declaring these child members.
case 218 /* ModuleDeclaration */:
return declareModuleMember(node, symbolFlags, symbolExcludes);
case 248 /* SourceFile */:
return declareSourceFileMember(node, symbolFlags, symbolExcludes);
case 186 /* ClassExpression */:
case 214 /* ClassDeclaration */:
return declareClassMember(node, symbolFlags, symbolExcludes);
case 217 /* EnumDeclaration */:
return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes);
case 155 /* TypeLiteral */:
case 165 /* ObjectLiteralExpression */:
case 215 /* InterfaceDeclaration */:
// Interface/Object-types always have their children added to the 'members' of
// their container. They are only accessible through an instance of their
// container, and are never in scope otherwise (even inside the body of the
// object / type / interface declaring them). An exception is type parameters,
// which are in scope without qualification (similar to 'locals').
return declareSymbol(container.symbol.members, container.symbol, node, symbolFlags, symbolExcludes);
case 152 /* FunctionType */:
case 153 /* ConstructorType */:
case 147 /* CallSignature */:
case 148 /* ConstructSignature */:
case 149 /* IndexSignature */:
case 143 /* MethodDeclaration */:
case 142 /* MethodSignature */:
case 144 /* Constructor */:
case 145 /* GetAccessor */:
case 146 /* SetAccessor */:
case 213 /* FunctionDeclaration */:
case 173 /* FunctionExpression */:
case 174 /* ArrowFunction */:
case 216 /* TypeAliasDeclaration */:
// All the children of these container types are never visible through another
// symbol (i.e. through another symbol's 'exports' or 'members'). Instead,
// they're only accessed 'lexically' (i.e. from code that exists underneath
// their container in the tree. To accomplish this, we simply add their declared
// symbol to the 'locals' of the container. These symbols can then be found as
// the type checker walks up the containers, checking them for matching names.
return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes);
}
} | Returns true if node and its subnodes were successfully traversed.
Returning false means that node was not examined and caller needs to dive into the node himself. | declareSymbolAndAddToSymbolTableWorker | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function declareClassMember(node, symbolFlags, symbolExcludes) {
return node.flags & 64 /* Static */
? declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes)
: declareSymbol(container.symbol.members, container.symbol, node, symbolFlags, symbolExcludes);
} | Returns true if node and its subnodes were successfully traversed.
Returning false means that node was not examined and caller needs to dive into the node himself. | declareClassMember | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function declareSourceFileMember(node, symbolFlags, symbolExcludes) {
return ts.isExternalModule(file)
? declareModuleMember(node, symbolFlags, symbolExcludes)
: declareSymbol(file.locals, undefined, node, symbolFlags, symbolExcludes);
} | Returns true if node and its subnodes were successfully traversed.
Returning false means that node was not examined and caller needs to dive into the node himself. | declareSourceFileMember | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function hasExportDeclarations(node) {
var body = node.kind === 248 /* SourceFile */ ? node : node.body;
if (body.kind === 248 /* SourceFile */ || body.kind === 219 /* ModuleBlock */) {
for (var _i = 0, _a = body.statements; _i < _a.length; _i++) {
var stat = _a[_i];
if (stat.kind === 228 /* ExportDeclaration */ || stat.kind === 227 /* ExportAssignment */) {
return true;
}
}
}
return false;
} | Returns true if node and its subnodes were successfully traversed.
Returning false means that node was not examined and caller needs to dive into the node himself. | hasExportDeclarations | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function setExportContextFlag(node) {
// A declaration source file or ambient module declaration that contains no export declarations (but possibly regular
// declarations with export modifiers) is an export context in which declarations are implicitly exported.
if (ts.isInAmbientContext(node) && !hasExportDeclarations(node)) {
node.flags |= 131072 /* ExportContext */;
}
else {
node.flags &= ~131072 /* ExportContext */;
}
} | Returns true if node and its subnodes were successfully traversed.
Returning false means that node was not examined and caller needs to dive into the node himself. | setExportContextFlag | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function bindModuleDeclaration(node) {
setExportContextFlag(node);
if (node.name.kind === 9 /* StringLiteral */) {
declareSymbolAndAddToSymbolTable(node, 512 /* ValueModule */, 106639 /* ValueModuleExcludes */);
}
else {
var state = getModuleInstanceState(node);
if (state === 0 /* NonInstantiated */) {
declareSymbolAndAddToSymbolTable(node, 1024 /* NamespaceModule */, 0 /* NamespaceModuleExcludes */);
}
else {
declareSymbolAndAddToSymbolTable(node, 512 /* ValueModule */, 106639 /* ValueModuleExcludes */);
if (node.symbol.flags & (16 /* Function */ | 32 /* Class */ | 256 /* RegularEnum */)) {
// if module was already merged with some function, class or non-const enum
// treat is a non-const-enum-only
node.symbol.constEnumOnlyModule = false;
}
else {
var currentModuleIsConstEnumOnly = state === 2 /* ConstEnumOnly */;
if (node.symbol.constEnumOnlyModule === undefined) {
// non-merged case - use the current state
node.symbol.constEnumOnlyModule = currentModuleIsConstEnumOnly;
}
else {
// merged case: module is const enum only if all its pieces are non-instantiated or const enum
node.symbol.constEnumOnlyModule = node.symbol.constEnumOnlyModule && currentModuleIsConstEnumOnly;
}
}
}
}
} | Returns true if node and its subnodes were successfully traversed.
Returning false means that node was not examined and caller needs to dive into the node himself. | bindModuleDeclaration | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function bindFunctionOrConstructorType(node) {
// For a given function symbol "<...>(...) => T" we want to generate a symbol identical
// to the one we would get for: { <...>(...): T }
//
// We do that by making an anonymous type literal symbol, and then setting the function
// symbol as its sole member. To the rest of the system, this symbol will be indistinguishable
// from an actual type literal symbol you would have gotten had you used the long form.
var symbol = createSymbol(131072 /* Signature */, getDeclarationName(node));
addDeclarationToSymbol(symbol, node, 131072 /* Signature */);
var typeLiteralSymbol = createSymbol(2048 /* TypeLiteral */, "__type");
addDeclarationToSymbol(typeLiteralSymbol, node, 2048 /* TypeLiteral */);
typeLiteralSymbol.members = (_a = {}, _a[symbol.name] = symbol, _a);
var _a;
} | Returns true if node and its subnodes were successfully traversed.
Returning false means that node was not examined and caller needs to dive into the node himself. | bindFunctionOrConstructorType | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function bindObjectLiteralExpression(node) {
var ElementKind;
(function (ElementKind) {
ElementKind[ElementKind["Property"] = 1] = "Property";
ElementKind[ElementKind["Accessor"] = 2] = "Accessor";
})(ElementKind || (ElementKind = {}));
if (inStrictMode) {
var seen = {};
for (var _i = 0, _a = node.properties; _i < _a.length; _i++) {
var prop = _a[_i];
if (prop.name.kind !== 69 /* Identifier */) {
continue;
}
var identifier = prop.name;
// ECMA-262 11.1.5 Object Initialiser
// If previous is not undefined then throw a SyntaxError exception if any of the following conditions are true
// a.This production is contained in strict code and IsDataDescriptor(previous) is true and
// IsDataDescriptor(propId.descriptor) is true.
// b.IsDataDescriptor(previous) is true and IsAccessorDescriptor(propId.descriptor) is true.
// c.IsAccessorDescriptor(previous) is true and IsDataDescriptor(propId.descriptor) is true.
// d.IsAccessorDescriptor(previous) is true and IsAccessorDescriptor(propId.descriptor) is true
// and either both previous and propId.descriptor have[[Get]] fields or both previous and propId.descriptor have[[Set]] fields
var currentKind = prop.kind === 245 /* PropertyAssignment */ || prop.kind === 246 /* ShorthandPropertyAssignment */ || prop.kind === 143 /* MethodDeclaration */
? 1 /* Property */
: 2 /* Accessor */;
var existingKind = seen[identifier.text];
if (!existingKind) {
seen[identifier.text] = currentKind;
continue;
}
if (currentKind === 1 /* Property */ && existingKind === 1 /* Property */) {
var span = ts.getErrorSpanForNode(file, identifier);
file.bindDiagnostics.push(ts.createFileDiagnostic(file, span.start, span.length, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode));
}
}
}
return bindAnonymousDeclaration(node, 4096 /* ObjectLiteral */, "__object");
} | Returns true if node and its subnodes were successfully traversed.
Returning false means that node was not examined and caller needs to dive into the node himself. | bindObjectLiteralExpression | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function bindAnonymousDeclaration(node, symbolFlags, name) {
var symbol = createSymbol(symbolFlags, name);
addDeclarationToSymbol(symbol, node, symbolFlags);
} | Returns true if node and its subnodes were successfully traversed.
Returning false means that node was not examined and caller needs to dive into the node himself. | bindAnonymousDeclaration | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function bindBlockScopedDeclaration(node, symbolFlags, symbolExcludes) {
switch (blockScopeContainer.kind) {
case 218 /* ModuleDeclaration */:
declareModuleMember(node, symbolFlags, symbolExcludes);
break;
case 248 /* SourceFile */:
if (ts.isExternalModule(container)) {
declareModuleMember(node, symbolFlags, symbolExcludes);
break;
}
// fall through.
default:
if (!blockScopeContainer.locals) {
blockScopeContainer.locals = {};
addToContainerChain(blockScopeContainer);
}
declareSymbol(blockScopeContainer.locals, undefined, node, symbolFlags, symbolExcludes);
}
} | Returns true if node and its subnodes were successfully traversed.
Returning false means that node was not examined and caller needs to dive into the node himself. | bindBlockScopedDeclaration | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function bindBlockScopedVariableDeclaration(node) {
bindBlockScopedDeclaration(node, 2 /* BlockScopedVariable */, 107455 /* BlockScopedVariableExcludes */);
} | Returns true if node and its subnodes were successfully traversed.
Returning false means that node was not examined and caller needs to dive into the node himself. | bindBlockScopedVariableDeclaration | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function checkStrictModeIdentifier(node) {
if (inStrictMode &&
node.originalKeywordKind >= 106 /* FirstFutureReservedWord */ &&
node.originalKeywordKind <= 114 /* LastFutureReservedWord */ &&
!ts.isIdentifierName(node)) {
// Report error only if there are no parse errors in file
if (!file.parseDiagnostics.length) {
file.bindDiagnostics.push(ts.createDiagnosticForNode(node, getStrictModeIdentifierMessage(node), ts.declarationNameToString(node)));
}
}
} | Returns true if node and its subnodes were successfully traversed.
Returning false means that node was not examined and caller needs to dive into the node himself. | checkStrictModeIdentifier | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function getStrictModeIdentifierMessage(node) {
// Provide specialized messages to help the user understand why we think they're in
// strict mode.
if (ts.getContainingClass(node)) {
return ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode;
}
if (file.externalModuleIndicator) {
return ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Modules_are_automatically_in_strict_mode;
}
return ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode;
} | Returns true if node and its subnodes were successfully traversed.
Returning false means that node was not examined and caller needs to dive into the node himself. | getStrictModeIdentifierMessage | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function checkStrictModeBinaryExpression(node) {
if (inStrictMode && ts.isLeftHandSideExpression(node.left) && ts.isAssignmentOperator(node.operatorToken.kind)) {
// ECMA 262 (Annex C) The identifier eval or arguments may not appear as the LeftHandSideExpression of an
// Assignment operator(11.13) or of a PostfixExpression(11.3)
checkStrictModeEvalOrArguments(node, node.left);
}
} | Returns true if node and its subnodes were successfully traversed.
Returning false means that node was not examined and caller needs to dive into the node himself. | checkStrictModeBinaryExpression | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
function checkStrictModeCatchClause(node) {
// It is a SyntaxError if a TryStatement with a Catch occurs within strict code and the Identifier of the
// Catch production is eval or arguments
if (inStrictMode && node.variableDeclaration) {
checkStrictModeEvalOrArguments(node, node.variableDeclaration.name);
}
} | Returns true if node and its subnodes were successfully traversed.
Returning false means that node was not examined and caller needs to dive into the node himself. | checkStrictModeCatchClause | javascript | amol-/dukpy | dukpy/jsmodules/typescriptServices.js | https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.