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 checkSpecializedSignatureDeclaration(signatureDeclarationNode) {
if (!produceDiagnostics) {
return;
}
var signature = getSignatureFromDeclaration(signatureDeclarationNode);
if (!signature.hasStringLiterals) {
return;
}
// TypeScript 1.0 spec (April 2014): 3.7.2.2
// Specialized signatures are not permitted in conjunction with a function body
if (ts.nodeIsPresent(signatureDeclarationNode.body)) {
error(signatureDeclarationNode, ts.Diagnostics.A_signature_with_an_implementation_cannot_use_a_string_literal_type);
return;
}
// TypeScript 1.0 spec (April 2014): 3.7.2.4
// Every specialized call or construct signature in an object type must be assignable
// to at least one non-specialized call or construct signature in the same object type
var signaturesToCheck;
// Unnamed (call\construct) signatures in interfaces are inherited and not shadowed so examining just node symbol won't give complete answer.
// Use declaring type to obtain full list of signatures.
if (!signatureDeclarationNode.name && signatureDeclarationNode.parent && signatureDeclarationNode.parent.kind === 215 /* InterfaceDeclaration */) {
ts.Debug.assert(signatureDeclarationNode.kind === 147 /* CallSignature */ || signatureDeclarationNode.kind === 148 /* ConstructSignature */);
var signatureKind = signatureDeclarationNode.kind === 147 /* CallSignature */ ? 0 /* Call */ : 1 /* Construct */;
var containingSymbol = getSymbolOfNode(signatureDeclarationNode.parent);
var containingType = getDeclaredTypeOfSymbol(containingSymbol);
signaturesToCheck = getSignaturesOfType(containingType, signatureKind);
}
else {
signaturesToCheck = getSignaturesOfSymbol(getSymbolOfNode(signatureDeclarationNode));
}
for (var _i = 0, signaturesToCheck_1 = signaturesToCheck; _i < signaturesToCheck_1.length; _i++) {
var otherSignature = signaturesToCheck_1[_i];
if (!otherSignature.hasStringLiterals && isSignatureAssignableTo(signature, otherSignature)) {
return;
}
}
error(signatureDeclarationNode, ts.Diagnostics.Specialized_overload_signature_is_not_assignable_to_any_non_specialized_signature);
}
|
Syntactically and semantically checks a call or new expression.
@param node The call/new expression to be checked.
@returns On success, the expression's signature's return type. On failure, anyType.
|
checkSpecializedSignatureDeclaration
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getEffectiveDeclarationFlags(n, flagsToCheck) {
var flags = ts.getCombinedNodeFlags(n);
// children of classes (even ambient classes) should not be marked as ambient or export
// because those flags have no useful semantics there.
if (n.parent.kind !== 215 /* InterfaceDeclaration */ &&
n.parent.kind !== 214 /* ClassDeclaration */ &&
n.parent.kind !== 186 /* ClassExpression */ &&
ts.isInAmbientContext(n)) {
if (!(flags & 4 /* Ambient */)) {
// It is nested in an ambient context, which means it is automatically exported
flags |= 2 /* Export */;
}
flags |= 4 /* Ambient */;
}
return flags & flagsToCheck;
}
|
Syntactically and semantically checks a call or new expression.
@param node The call/new expression to be checked.
@returns On success, the expression's signature's return type. On failure, anyType.
|
getEffectiveDeclarationFlags
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkFunctionOrConstructorSymbol(symbol) {
if (!produceDiagnostics) {
return;
}
function getCanonicalOverload(overloads, implementation) {
// Consider the canonical set of flags to be the flags of the bodyDeclaration or the first declaration
// Error on all deviations from this canonical set of flags
// The caveat is that if some overloads are defined in lib.d.ts, we don't want to
// report the errors on those. To achieve this, we will say that the implementation is
// the canonical signature only if it is in the same container as the first overload
var implementationSharesContainerWithFirstOverload = implementation !== undefined && implementation.parent === overloads[0].parent;
return implementationSharesContainerWithFirstOverload ? implementation : overloads[0];
}
function checkFlagAgreementBetweenOverloads(overloads, implementation, flagsToCheck, someOverloadFlags, allOverloadFlags) {
// Error if some overloads have a flag that is not shared by all overloads. To find the
// deviations, we XOR someOverloadFlags with allOverloadFlags
var someButNotAllOverloadFlags = someOverloadFlags ^ allOverloadFlags;
if (someButNotAllOverloadFlags !== 0) {
var canonicalFlags = getEffectiveDeclarationFlags(getCanonicalOverload(overloads, implementation), flagsToCheck);
ts.forEach(overloads, function (o) {
var deviation = getEffectiveDeclarationFlags(o, flagsToCheck) ^ canonicalFlags;
if (deviation & 2 /* Export */) {
error(o.name, ts.Diagnostics.Overload_signatures_must_all_be_exported_or_not_exported);
}
else if (deviation & 4 /* Ambient */) {
error(o.name, ts.Diagnostics.Overload_signatures_must_all_be_ambient_or_non_ambient);
}
else if (deviation & (16 /* Private */ | 32 /* Protected */)) {
error(o.name, ts.Diagnostics.Overload_signatures_must_all_be_public_private_or_protected);
}
else if (deviation & 128 /* Abstract */) {
error(o.name, ts.Diagnostics.Overload_signatures_must_all_be_abstract_or_not_abstract);
}
});
}
}
function checkQuestionTokenAgreementBetweenOverloads(overloads, implementation, someHaveQuestionToken, allHaveQuestionToken) {
if (someHaveQuestionToken !== allHaveQuestionToken) {
var canonicalHasQuestionToken = ts.hasQuestionToken(getCanonicalOverload(overloads, implementation));
ts.forEach(overloads, function (o) {
var deviation = ts.hasQuestionToken(o) !== canonicalHasQuestionToken;
if (deviation) {
error(o.name, ts.Diagnostics.Overload_signatures_must_all_be_optional_or_required);
}
});
}
}
var flagsToCheck = 2 /* Export */ | 4 /* Ambient */ | 16 /* Private */ | 32 /* Protected */ | 128 /* Abstract */;
var someNodeFlags = 0;
var allNodeFlags = flagsToCheck;
var someHaveQuestionToken = false;
var allHaveQuestionToken = true;
var hasOverloads = false;
var bodyDeclaration;
var lastSeenNonAmbientDeclaration;
var previousDeclaration;
var declarations = symbol.declarations;
var isConstructor = (symbol.flags & 16384 /* Constructor */) !== 0;
function reportImplementationExpectedError(node) {
if (node.name && ts.nodeIsMissing(node.name)) {
return;
}
var seen = false;
var subsequentNode = ts.forEachChild(node.parent, function (c) {
if (seen) {
return c;
}
else {
seen = c === node;
}
});
if (subsequentNode) {
if (subsequentNode.kind === node.kind) {
var errorNode_1 = subsequentNode.name || subsequentNode;
// TODO(jfreeman): These are methods, so handle computed name case
if (node.name && subsequentNode.name && node.name.text === subsequentNode.name.text) {
// the only situation when this is possible (same kind\same name but different symbol) - mixed static and instance class members
ts.Debug.assert(node.kind === 143 /* MethodDeclaration */ || node.kind === 142 /* MethodSignature */);
ts.Debug.assert((node.flags & 64 /* Static */) !== (subsequentNode.flags & 64 /* Static */));
var diagnostic = node.flags & 64 /* Static */ ? ts.Diagnostics.Function_overload_must_be_static : ts.Diagnostics.Function_overload_must_not_be_static;
error(errorNode_1, diagnostic);
return;
}
else if (ts.nodeIsPresent(subsequentNode.body)) {
error(errorNode_1, ts.Diagnostics.Function_implementation_name_must_be_0, ts.declarationNameToString(node.name));
return;
}
}
}
var errorNode = node.name || node;
if (isConstructor) {
error(errorNode, ts.Diagnostics.Constructor_implementation_is_missing);
}
else {
// Report different errors regarding non-consecutive blocks of declarations depending on whether
// the node in question is abstract.
if (node.flags & 128 /* Abstract */) {
error(errorNode, ts.Diagnostics.All_declarations_of_an_abstract_method_must_be_consecutive);
}
else {
error(errorNode, ts.Diagnostics.Function_implementation_is_missing_or_not_immediately_following_the_declaration);
}
}
}
// when checking exported function declarations across modules check only duplicate implementations
// names and consistency of modifiers are verified when we check local symbol
var isExportSymbolInsideModule = symbol.parent && symbol.parent.flags & 1536 /* Module */;
var duplicateFunctionDeclaration = false;
var multipleConstructorImplementation = false;
for (var _i = 0, declarations_4 = declarations; _i < declarations_4.length; _i++) {
var current = declarations_4[_i];
var node = current;
var inAmbientContext = ts.isInAmbientContext(node);
var inAmbientContextOrInterface = node.parent.kind === 215 /* InterfaceDeclaration */ || node.parent.kind === 155 /* TypeLiteral */ || inAmbientContext;
if (inAmbientContextOrInterface) {
// check if declarations are consecutive only if they are non-ambient
// 1. ambient declarations can be interleaved
// i.e. this is legal
// declare function foo();
// declare function bar();
// declare function foo();
// 2. mixing ambient and non-ambient declarations is a separate error that will be reported - do not want to report an extra one
previousDeclaration = undefined;
}
if (node.kind === 213 /* FunctionDeclaration */ || node.kind === 143 /* MethodDeclaration */ || node.kind === 142 /* MethodSignature */ || node.kind === 144 /* Constructor */) {
var currentNodeFlags = getEffectiveDeclarationFlags(node, flagsToCheck);
someNodeFlags |= currentNodeFlags;
allNodeFlags &= currentNodeFlags;
someHaveQuestionToken = someHaveQuestionToken || ts.hasQuestionToken(node);
allHaveQuestionToken = allHaveQuestionToken && ts.hasQuestionToken(node);
if (ts.nodeIsPresent(node.body) && bodyDeclaration) {
if (isConstructor) {
multipleConstructorImplementation = true;
}
else {
duplicateFunctionDeclaration = true;
}
}
else if (!isExportSymbolInsideModule && previousDeclaration && previousDeclaration.parent === node.parent && previousDeclaration.end !== node.pos) {
reportImplementationExpectedError(previousDeclaration);
}
if (ts.nodeIsPresent(node.body)) {
if (!bodyDeclaration) {
bodyDeclaration = node;
}
}
else {
hasOverloads = true;
}
previousDeclaration = node;
if (!inAmbientContextOrInterface) {
lastSeenNonAmbientDeclaration = node;
}
}
}
if (multipleConstructorImplementation) {
ts.forEach(declarations, function (declaration) {
error(declaration, ts.Diagnostics.Multiple_constructor_implementations_are_not_allowed);
});
}
if (duplicateFunctionDeclaration) {
ts.forEach(declarations, function (declaration) {
error(declaration.name, ts.Diagnostics.Duplicate_function_implementation);
});
}
// Abstract methods can't have an implementation -- in particular, they don't need one.
if (!isExportSymbolInsideModule && lastSeenNonAmbientDeclaration && !lastSeenNonAmbientDeclaration.body &&
!(lastSeenNonAmbientDeclaration.flags & 128 /* Abstract */)) {
reportImplementationExpectedError(lastSeenNonAmbientDeclaration);
}
if (hasOverloads) {
checkFlagAgreementBetweenOverloads(declarations, bodyDeclaration, flagsToCheck, someNodeFlags, allNodeFlags);
checkQuestionTokenAgreementBetweenOverloads(declarations, bodyDeclaration, someHaveQuestionToken, allHaveQuestionToken);
if (bodyDeclaration) {
var signatures = getSignaturesOfSymbol(symbol);
var bodySignature = getSignatureFromDeclaration(bodyDeclaration);
// If the implementation signature has string literals, we will have reported an error in
// checkSpecializedSignatureDeclaration
if (!bodySignature.hasStringLiterals) {
// TypeScript 1.0 spec (April 2014): 6.1
// If a function declaration includes overloads, the overloads determine the call
// signatures of the type given to the function object
// and the function implementation signature must be assignable to that type
//
// TypeScript 1.0 spec (April 2014): 3.8.4
// Note that specialized call and construct signatures (section 3.7.2.4) are not significant when determining assignment compatibility
// Consider checking against specialized signatures too. Not doing so creates a type hole:
//
// function g(x: "hi", y: boolean);
// function g(x: string, y: {});
// function g(x: string, y: string) { }
//
// The implementation is completely unrelated to the specialized signature, yet we do not check this.
for (var _a = 0, signatures_3 = signatures; _a < signatures_3.length; _a++) {
var signature = signatures_3[_a];
if (!signature.hasStringLiterals && !isSignatureAssignableTo(bodySignature, signature)) {
error(signature.declaration, ts.Diagnostics.Overload_signature_is_not_compatible_with_function_implementation);
break;
}
}
}
}
}
}
|
Syntactically and semantically checks a call or new expression.
@param node The call/new expression to be checked.
@returns On success, the expression's signature's return type. On failure, anyType.
|
checkFunctionOrConstructorSymbol
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getCanonicalOverload(overloads, implementation) {
// Consider the canonical set of flags to be the flags of the bodyDeclaration or the first declaration
// Error on all deviations from this canonical set of flags
// The caveat is that if some overloads are defined in lib.d.ts, we don't want to
// report the errors on those. To achieve this, we will say that the implementation is
// the canonical signature only if it is in the same container as the first overload
var implementationSharesContainerWithFirstOverload = implementation !== undefined && implementation.parent === overloads[0].parent;
return implementationSharesContainerWithFirstOverload ? implementation : overloads[0];
}
|
Syntactically and semantically checks a call or new expression.
@param node The call/new expression to be checked.
@returns On success, the expression's signature's return type. On failure, anyType.
|
getCanonicalOverload
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkFlagAgreementBetweenOverloads(overloads, implementation, flagsToCheck, someOverloadFlags, allOverloadFlags) {
// Error if some overloads have a flag that is not shared by all overloads. To find the
// deviations, we XOR someOverloadFlags with allOverloadFlags
var someButNotAllOverloadFlags = someOverloadFlags ^ allOverloadFlags;
if (someButNotAllOverloadFlags !== 0) {
var canonicalFlags = getEffectiveDeclarationFlags(getCanonicalOverload(overloads, implementation), flagsToCheck);
ts.forEach(overloads, function (o) {
var deviation = getEffectiveDeclarationFlags(o, flagsToCheck) ^ canonicalFlags;
if (deviation & 2 /* Export */) {
error(o.name, ts.Diagnostics.Overload_signatures_must_all_be_exported_or_not_exported);
}
else if (deviation & 4 /* Ambient */) {
error(o.name, ts.Diagnostics.Overload_signatures_must_all_be_ambient_or_non_ambient);
}
else if (deviation & (16 /* Private */ | 32 /* Protected */)) {
error(o.name, ts.Diagnostics.Overload_signatures_must_all_be_public_private_or_protected);
}
else if (deviation & 128 /* Abstract */) {
error(o.name, ts.Diagnostics.Overload_signatures_must_all_be_abstract_or_not_abstract);
}
});
}
}
|
Syntactically and semantically checks a call or new expression.
@param node The call/new expression to be checked.
@returns On success, the expression's signature's return type. On failure, anyType.
|
checkFlagAgreementBetweenOverloads
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkQuestionTokenAgreementBetweenOverloads(overloads, implementation, someHaveQuestionToken, allHaveQuestionToken) {
if (someHaveQuestionToken !== allHaveQuestionToken) {
var canonicalHasQuestionToken = ts.hasQuestionToken(getCanonicalOverload(overloads, implementation));
ts.forEach(overloads, function (o) {
var deviation = ts.hasQuestionToken(o) !== canonicalHasQuestionToken;
if (deviation) {
error(o.name, ts.Diagnostics.Overload_signatures_must_all_be_optional_or_required);
}
});
}
}
|
Syntactically and semantically checks a call or new expression.
@param node The call/new expression to be checked.
@returns On success, the expression's signature's return type. On failure, anyType.
|
checkQuestionTokenAgreementBetweenOverloads
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function reportImplementationExpectedError(node) {
if (node.name && ts.nodeIsMissing(node.name)) {
return;
}
var seen = false;
var subsequentNode = ts.forEachChild(node.parent, function (c) {
if (seen) {
return c;
}
else {
seen = c === node;
}
});
if (subsequentNode) {
if (subsequentNode.kind === node.kind) {
var errorNode_1 = subsequentNode.name || subsequentNode;
// TODO(jfreeman): These are methods, so handle computed name case
if (node.name && subsequentNode.name && node.name.text === subsequentNode.name.text) {
// the only situation when this is possible (same kind\same name but different symbol) - mixed static and instance class members
ts.Debug.assert(node.kind === 143 /* MethodDeclaration */ || node.kind === 142 /* MethodSignature */);
ts.Debug.assert((node.flags & 64 /* Static */) !== (subsequentNode.flags & 64 /* Static */));
var diagnostic = node.flags & 64 /* Static */ ? ts.Diagnostics.Function_overload_must_be_static : ts.Diagnostics.Function_overload_must_not_be_static;
error(errorNode_1, diagnostic);
return;
}
else if (ts.nodeIsPresent(subsequentNode.body)) {
error(errorNode_1, ts.Diagnostics.Function_implementation_name_must_be_0, ts.declarationNameToString(node.name));
return;
}
}
}
var errorNode = node.name || node;
if (isConstructor) {
error(errorNode, ts.Diagnostics.Constructor_implementation_is_missing);
}
else {
// Report different errors regarding non-consecutive blocks of declarations depending on whether
// the node in question is abstract.
if (node.flags & 128 /* Abstract */) {
error(errorNode, ts.Diagnostics.All_declarations_of_an_abstract_method_must_be_consecutive);
}
else {
error(errorNode, ts.Diagnostics.Function_implementation_is_missing_or_not_immediately_following_the_declaration);
}
}
}
|
Syntactically and semantically checks a call or new expression.
@param node The call/new expression to be checked.
@returns On success, the expression's signature's return type. On failure, anyType.
|
reportImplementationExpectedError
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkExportsOnMergedDeclarations(node) {
if (!produceDiagnostics) {
return;
}
// if localSymbol is defined on node then node itself is exported - check is required
var symbol = node.localSymbol;
if (!symbol) {
// local symbol is undefined => this declaration is non-exported.
// however symbol might contain other declarations that are exported
symbol = getSymbolOfNode(node);
if (!(symbol.flags & 7340032 /* Export */)) {
// this is a pure local symbol (all declarations are non-exported) - no need to check anything
return;
}
}
// run the check only for the first declaration in the list
if (ts.getDeclarationOfKind(symbol, node.kind) !== node) {
return;
}
// we use SymbolFlags.ExportValue, SymbolFlags.ExportType and SymbolFlags.ExportNamespace
// to denote disjoint declarationSpaces (without making new enum type).
var exportedDeclarationSpaces = 0 /* None */;
var nonExportedDeclarationSpaces = 0 /* None */;
var defaultExportedDeclarationSpaces = 0 /* None */;
for (var _i = 0, _a = symbol.declarations; _i < _a.length; _i++) {
var d = _a[_i];
var declarationSpaces = getDeclarationSpaces(d);
var effectiveDeclarationFlags = getEffectiveDeclarationFlags(d, 2 /* Export */ | 512 /* Default */);
if (effectiveDeclarationFlags & 2 /* Export */) {
if (effectiveDeclarationFlags & 512 /* Default */) {
defaultExportedDeclarationSpaces |= declarationSpaces;
}
else {
exportedDeclarationSpaces |= declarationSpaces;
}
}
else {
nonExportedDeclarationSpaces |= declarationSpaces;
}
}
// Spaces for anyting not declared a 'default export'.
var nonDefaultExportedDeclarationSpaces = exportedDeclarationSpaces | nonExportedDeclarationSpaces;
var commonDeclarationSpacesForExportsAndLocals = exportedDeclarationSpaces & nonExportedDeclarationSpaces;
var commonDeclarationSpacesForDefaultAndNonDefault = defaultExportedDeclarationSpaces & nonDefaultExportedDeclarationSpaces;
if (commonDeclarationSpacesForExportsAndLocals || commonDeclarationSpacesForDefaultAndNonDefault) {
// declaration spaces for exported and non-exported declarations intersect
for (var _b = 0, _c = symbol.declarations; _b < _c.length; _b++) {
var d = _c[_b];
var declarationSpaces = getDeclarationSpaces(d);
// Only error on the declarations that conributed to the intersecting spaces.
if (declarationSpaces & commonDeclarationSpacesForDefaultAndNonDefault) {
error(d.name, ts.Diagnostics.Merged_declaration_0_cannot_include_a_default_export_declaration_Consider_adding_a_separate_export_default_0_declaration_instead, ts.declarationNameToString(d.name));
}
else if (declarationSpaces & commonDeclarationSpacesForExportsAndLocals) {
error(d.name, ts.Diagnostics.Individual_declarations_in_merged_declaration_0_must_be_all_exported_or_all_local, ts.declarationNameToString(d.name));
}
}
}
function getDeclarationSpaces(d) {
switch (d.kind) {
case 215 /* InterfaceDeclaration */:
return 2097152 /* ExportType */;
case 218 /* ModuleDeclaration */:
return d.name.kind === 9 /* StringLiteral */ || ts.getModuleInstanceState(d) !== 0 /* NonInstantiated */
? 4194304 /* ExportNamespace */ | 1048576 /* ExportValue */
: 4194304 /* ExportNamespace */;
case 214 /* ClassDeclaration */:
case 217 /* EnumDeclaration */:
return 2097152 /* ExportType */ | 1048576 /* ExportValue */;
case 221 /* ImportEqualsDeclaration */:
var result = 0;
var target = resolveAlias(getSymbolOfNode(d));
ts.forEach(target.declarations, function (d) { result |= getDeclarationSpaces(d); });
return result;
default:
return 1048576 /* ExportValue */;
}
}
}
|
Syntactically and semantically checks a call or new expression.
@param node The call/new expression to be checked.
@returns On success, the expression's signature's return type. On failure, anyType.
|
checkExportsOnMergedDeclarations
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getDeclarationSpaces(d) {
switch (d.kind) {
case 215 /* InterfaceDeclaration */:
return 2097152 /* ExportType */;
case 218 /* ModuleDeclaration */:
return d.name.kind === 9 /* StringLiteral */ || ts.getModuleInstanceState(d) !== 0 /* NonInstantiated */
? 4194304 /* ExportNamespace */ | 1048576 /* ExportValue */
: 4194304 /* ExportNamespace */;
case 214 /* ClassDeclaration */:
case 217 /* EnumDeclaration */:
return 2097152 /* ExportType */ | 1048576 /* ExportValue */;
case 221 /* ImportEqualsDeclaration */:
var result = 0;
var target = resolveAlias(getSymbolOfNode(d));
ts.forEach(target.declarations, function (d) { result |= getDeclarationSpaces(d); });
return result;
default:
return 1048576 /* ExportValue */;
}
}
|
Syntactically and semantically checks a call or new expression.
@param node The call/new expression to be checked.
@returns On success, the expression's signature's return type. On failure, anyType.
|
getDeclarationSpaces
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkNonThenableType(type, location, message) {
type = getWidenedType(type);
if (!isTypeAny(type) && isTypeAssignableTo(type, getGlobalThenableType())) {
if (location) {
if (!message) {
message = ts.Diagnostics.Operand_for_await_does_not_have_a_valid_callable_then_member;
}
error(location, message);
}
return unknownType;
}
return type;
}
|
Syntactically and semantically checks a call or new expression.
@param node The call/new expression to be checked.
@returns On success, the expression's signature's return type. On failure, anyType.
|
checkNonThenableType
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getTypeOfFirstParameterOfSignature(signature) {
return getTypeAtPosition(signature, 0);
}
|
Gets the "promised type" of a promise.
@param type The type of the promise.
@remarks The "promised type" of a type is the type of the "value" parameter of the "onfulfilled" callback.
|
getTypeOfFirstParameterOfSignature
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getAwaitedType(type) {
return checkAwaitedType(type, /*location*/ undefined, /*message*/ undefined);
}
|
Gets the "awaited type" of a type.
@param type The type to await.
@remarks The "awaited type" of an expression is its "promised type" if the expression is a
Promise-like type; otherwise, it is the type of the expression. This is used to reflect
The runtime behavior of the `await` keyword.
|
getAwaitedType
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkAwaitedType(type, location, message) {
return checkAwaitedTypeWorker(type);
function checkAwaitedTypeWorker(type) {
if (type.flags & 16384 /* Union */) {
var types = [];
for (var _i = 0, _a = type.types; _i < _a.length; _i++) {
var constituentType = _a[_i];
types.push(checkAwaitedTypeWorker(constituentType));
}
return getUnionType(types);
}
else {
var promisedType = getPromisedType(type);
if (promisedType === undefined) {
// The type was not a PromiseLike, so it could not be unwrapped any further.
// As long as the type does not have a callable "then" property, it is
// safe to return the type; otherwise, an error will have been reported in
// the call to checkNonThenableType and we will return unknownType.
//
// An example of a non-promise "thenable" might be:
//
// await { then(): void {} }
//
// The "thenable" does not match the minimal definition for a PromiseLike. When
// a Promise/A+-compatible or ES6 promise tries to adopt this value, the promise
// will never settle. We treat this as an error to help flag an early indicator
// of a runtime problem. If the user wants to return this value from an async
// function, they would need to wrap it in some other value. If they want it to
// be treated as a promise, they can cast to <any>.
return checkNonThenableType(type, location, message);
}
else {
if (type.id === promisedType.id || awaitedTypeStack.indexOf(promisedType.id) >= 0) {
// We have a bad actor in the form of a promise whose promised type is
// the same promise type, or a mutually recursive promise. Return the
// unknown type as we cannot guess the shape. If this were the actual
// case in the JavaScript, this Promise would never resolve.
//
// An example of a bad actor with a singly-recursive promise type might
// be:
//
// interface BadPromise {
// then(
// onfulfilled: (value: BadPromise) => any,
// onrejected: (error: any) => any): BadPromise;
// }
//
// The above interface will pass the PromiseLike check, and return a
// promised type of `BadPromise`. Since this is a self reference, we
// don't want to keep recursing ad infinitum.
//
// An example of a bad actor in the form of a mutually-recursive
// promise type might be:
//
// interface BadPromiseA {
// then(
// onfulfilled: (value: BadPromiseB) => any,
// onrejected: (error: any) => any): BadPromiseB;
// }
//
// interface BadPromiseB {
// then(
// onfulfilled: (value: BadPromiseA) => any,
// onrejected: (error: any) => any): BadPromiseA;
// }
//
if (location) {
error(location, ts.Diagnostics._0_is_referenced_directly_or_indirectly_in_the_fulfillment_callback_of_its_own_then_method, symbolToString(type.symbol));
}
return unknownType;
}
// Keep track of the type we're about to unwrap to avoid bad recursive promise types.
// See the comments above for more information.
awaitedTypeStack.push(type.id);
var awaitedType = checkAwaitedTypeWorker(promisedType);
awaitedTypeStack.pop();
return awaitedType;
}
}
}
}
|
Gets the "awaited type" of a type.
@param type The type to await.
@remarks The "awaited type" of an expression is its "promised type" if the expression is a
Promise-like type; otherwise, it is the type of the expression. This is used to reflect
The runtime behavior of the `await` keyword.
|
checkAwaitedType
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkAwaitedTypeWorker(type) {
if (type.flags & 16384 /* Union */) {
var types = [];
for (var _i = 0, _a = type.types; _i < _a.length; _i++) {
var constituentType = _a[_i];
types.push(checkAwaitedTypeWorker(constituentType));
}
return getUnionType(types);
}
else {
var promisedType = getPromisedType(type);
if (promisedType === undefined) {
// The type was not a PromiseLike, so it could not be unwrapped any further.
// As long as the type does not have a callable "then" property, it is
// safe to return the type; otherwise, an error will have been reported in
// the call to checkNonThenableType and we will return unknownType.
//
// An example of a non-promise "thenable" might be:
//
// await { then(): void {} }
//
// The "thenable" does not match the minimal definition for a PromiseLike. When
// a Promise/A+-compatible or ES6 promise tries to adopt this value, the promise
// will never settle. We treat this as an error to help flag an early indicator
// of a runtime problem. If the user wants to return this value from an async
// function, they would need to wrap it in some other value. If they want it to
// be treated as a promise, they can cast to <any>.
return checkNonThenableType(type, location, message);
}
else {
if (type.id === promisedType.id || awaitedTypeStack.indexOf(promisedType.id) >= 0) {
// We have a bad actor in the form of a promise whose promised type is
// the same promise type, or a mutually recursive promise. Return the
// unknown type as we cannot guess the shape. If this were the actual
// case in the JavaScript, this Promise would never resolve.
//
// An example of a bad actor with a singly-recursive promise type might
// be:
//
// interface BadPromise {
// then(
// onfulfilled: (value: BadPromise) => any,
// onrejected: (error: any) => any): BadPromise;
// }
//
// The above interface will pass the PromiseLike check, and return a
// promised type of `BadPromise`. Since this is a self reference, we
// don't want to keep recursing ad infinitum.
//
// An example of a bad actor in the form of a mutually-recursive
// promise type might be:
//
// interface BadPromiseA {
// then(
// onfulfilled: (value: BadPromiseB) => any,
// onrejected: (error: any) => any): BadPromiseB;
// }
//
// interface BadPromiseB {
// then(
// onfulfilled: (value: BadPromiseA) => any,
// onrejected: (error: any) => any): BadPromiseA;
// }
//
if (location) {
error(location, ts.Diagnostics._0_is_referenced_directly_or_indirectly_in_the_fulfillment_callback_of_its_own_then_method, symbolToString(type.symbol));
}
return unknownType;
}
// Keep track of the type we're about to unwrap to avoid bad recursive promise types.
// See the comments above for more information.
awaitedTypeStack.push(type.id);
var awaitedType = checkAwaitedTypeWorker(promisedType);
awaitedTypeStack.pop();
return awaitedType;
}
}
}
|
Gets the "awaited type" of a type.
@param type The type to await.
@remarks The "awaited type" of an expression is its "promised type" if the expression is a
Promise-like type; otherwise, it is the type of the expression. This is used to reflect
The runtime behavior of the `await` keyword.
|
checkAwaitedTypeWorker
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkAsyncFunctionReturnType(node) {
var globalPromiseConstructorLikeType = getGlobalPromiseConstructorLikeType();
if (globalPromiseConstructorLikeType === emptyObjectType) {
// If we couldn't resolve the global PromiseConstructorLike type we cannot verify
// compatibility with __awaiter.
return unknownType;
}
// As part of our emit for an async function, we will need to emit the entity name of
// the return type annotation as an expression. To meet the necessary runtime semantics
// for __awaiter, we must also check that the type of the declaration (e.g. the static
// side or "constructor" of the promise type) is compatible `PromiseConstructorLike`.
//
// An example might be (from lib.es6.d.ts):
//
// interface Promise<T> { ... }
// interface PromiseConstructor {
// new <T>(...): Promise<T>;
// }
// declare var Promise: PromiseConstructor;
//
// When an async function declares a return type annotation of `Promise<T>`, we
// need to get the type of the `Promise` variable declaration above, which would
// be `PromiseConstructor`.
//
// The same case applies to a class:
//
// declare class Promise<T> {
// constructor(...);
// then<U>(...): Promise<U>;
// }
//
// When we get the type of the `Promise` symbol here, we get the type of the static
// side of the `Promise` class, which would be `{ new <T>(...): Promise<T> }`.
var promiseType = getTypeFromTypeNode(node.type);
if (promiseType === unknownType && compilerOptions.isolatedModules) {
// If we are compiling with isolatedModules, we may not be able to resolve the
// type as a value. As such, we will just return unknownType;
return unknownType;
}
var promiseConstructor = getNodeLinks(node.type).resolvedSymbol;
if (!promiseConstructor || !symbolIsValue(promiseConstructor)) {
var typeName = promiseConstructor
? symbolToString(promiseConstructor)
: typeToString(promiseType);
error(node, ts.Diagnostics.Type_0_is_not_a_valid_async_function_return_type, typeName);
return unknownType;
}
// Validate the promise constructor type.
var promiseConstructorType = getTypeOfSymbol(promiseConstructor);
if (!checkTypeAssignableTo(promiseConstructorType, globalPromiseConstructorLikeType, node, ts.Diagnostics.Type_0_is_not_a_valid_async_function_return_type)) {
return unknownType;
}
// Verify there is no local declaration that could collide with the promise constructor.
var promiseName = ts.getEntityNameFromTypeNode(node.type);
var root = getFirstIdentifier(promiseName);
var rootSymbol = getSymbol(node.locals, root.text, 107455 /* Value */);
if (rootSymbol) {
error(rootSymbol.valueDeclaration, ts.Diagnostics.Duplicate_identifier_0_Compiler_uses_declaration_1_to_support_async_functions, root.text, getFullyQualifiedName(promiseConstructor));
return unknownType;
}
// Get and return the awaited type of the return type.
return checkAwaitedType(promiseType, node, ts.Diagnostics.An_async_function_or_method_must_have_a_valid_awaitable_return_type);
}
|
Checks the return type of an async function to ensure it is a compatible
Promise implementation.
@param node The signature to check
@param returnType The return type for the function
@remarks
This checks that an async function has a valid Promise-compatible return type,
and returns the *awaited type* of the promise. An async function has a valid
Promise-compatible return type if the resolved value of the return type has a
construct signature that takes in an `initializer` function that in turn supplies
a `resolve` function as one of its arguments and results in an object with a
callable `then` signature.
|
checkAsyncFunctionReturnType
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getElementTypeOfIterable(type, errorNode) {
if (isTypeAny(type)) {
return undefined;
}
var typeAsIterable = type;
if (!typeAsIterable.iterableElementType) {
// As an optimization, if the type is instantiated directly using the globalIterableType (Iterable<number>),
// then just grab its type argument.
if ((type.flags & 4096 /* Reference */) && type.target === globalIterableType) {
typeAsIterable.iterableElementType = type.typeArguments[0];
}
else {
var iteratorFunction = getTypeOfPropertyOfType(type, ts.getPropertyNameForKnownSymbolName("iterator"));
if (isTypeAny(iteratorFunction)) {
return undefined;
}
var iteratorFunctionSignatures = iteratorFunction ? getSignaturesOfType(iteratorFunction, 0 /* Call */) : emptyArray;
if (iteratorFunctionSignatures.length === 0) {
if (errorNode) {
error(errorNode, ts.Diagnostics.Type_must_have_a_Symbol_iterator_method_that_returns_an_iterator);
}
return undefined;
}
typeAsIterable.iterableElementType = getElementTypeOfIterator(getUnionType(ts.map(iteratorFunctionSignatures, getReturnTypeOfSignature)), errorNode);
}
}
return typeAsIterable.iterableElementType;
}
|
We want to treat type as an iterable, and get the type it is an iterable of. The iterable
must have the following structure (annotated with the names of the variables below):
{ // iterable
[Symbol.iterator]: { // iteratorFunction
(): Iterator<T>
}
}
T is the type we are after. At every level that involves analyzing return types
of signatures, we union the return types of all the signatures.
Another thing to note is that at any step of this process, we could run into a dead end,
meaning either the property is missing, or we run into the anyType. If either of these things
happens, we return undefined to signal that we could not find the iterated type. If a property
is missing, and the previous step did not result in 'any', then we also give an error if the
caller requested it. Then the caller can decide what to do in the case where there is no iterated
type. This is different from returning anyType, because that would signify that we have matched the
whole pattern and that T (above) is 'any'.
|
getElementTypeOfIterable
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getElementTypeOfIterator(type, errorNode) {
if (isTypeAny(type)) {
return undefined;
}
var typeAsIterator = type;
if (!typeAsIterator.iteratorElementType) {
// As an optimization, if the type is instantiated directly using the globalIteratorType (Iterator<number>),
// then just grab its type argument.
if ((type.flags & 4096 /* Reference */) && type.target === globalIteratorType) {
typeAsIterator.iteratorElementType = type.typeArguments[0];
}
else {
var iteratorNextFunction = getTypeOfPropertyOfType(type, "next");
if (isTypeAny(iteratorNextFunction)) {
return undefined;
}
var iteratorNextFunctionSignatures = iteratorNextFunction ? getSignaturesOfType(iteratorNextFunction, 0 /* Call */) : emptyArray;
if (iteratorNextFunctionSignatures.length === 0) {
if (errorNode) {
error(errorNode, ts.Diagnostics.An_iterator_must_have_a_next_method);
}
return undefined;
}
var iteratorNextResult = getUnionType(ts.map(iteratorNextFunctionSignatures, getReturnTypeOfSignature));
if (isTypeAny(iteratorNextResult)) {
return undefined;
}
var iteratorNextValue = getTypeOfPropertyOfType(iteratorNextResult, "value");
if (!iteratorNextValue) {
if (errorNode) {
error(errorNode, ts.Diagnostics.The_type_returned_by_the_next_method_of_an_iterator_must_have_a_value_property);
}
return undefined;
}
typeAsIterator.iteratorElementType = iteratorNextValue;
}
}
return typeAsIterator.iteratorElementType;
}
|
This function has very similar logic as getElementTypeOfIterable, except that it operates on
Iterators instead of Iterables. Here is the structure:
{ // iterator
next: { // iteratorNextFunction
(): { // iteratorNextResult
value: T // iteratorNextValue
}
}
}
|
getElementTypeOfIterator
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getElementTypeOfIterableIterator(type) {
if (isTypeAny(type)) {
return undefined;
}
// As an optimization, if the type is instantiated directly using the globalIterableIteratorType (IterableIterator<number>),
// then just grab its type argument.
if ((type.flags & 4096 /* Reference */) && type.target === globalIterableIteratorType) {
return type.typeArguments[0];
}
return getElementTypeOfIterable(type, /*errorNode*/ undefined) ||
getElementTypeOfIterator(type, /*errorNode*/ undefined);
}
|
This function has very similar logic as getElementTypeOfIterable, except that it operates on
Iterators instead of Iterables. Here is the structure:
{ // iterator
next: { // iteratorNextFunction
(): { // iteratorNextResult
value: T // iteratorNextValue
}
}
}
|
getElementTypeOfIterableIterator
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkElementTypeOfArrayOrString(arrayOrStringType, errorNode) {
ts.Debug.assert(languageVersion < 2 /* ES6 */);
// After we remove all types that are StringLike, we will know if there was a string constituent
// based on whether the remaining type is the same as the initial type.
var arrayType = removeTypesFromUnionType(arrayOrStringType, 258 /* StringLike */, /*isTypeOfKind*/ true, /*allowEmptyUnionResult*/ true);
var hasStringConstituent = arrayOrStringType !== arrayType;
var reportedError = false;
if (hasStringConstituent) {
if (languageVersion < 1 /* ES5 */) {
error(errorNode, ts.Diagnostics.Using_a_string_in_a_for_of_statement_is_only_supported_in_ECMAScript_5_and_higher);
reportedError = true;
}
// Now that we've removed all the StringLike types, if no constituents remain, then the entire
// arrayOrStringType was a string.
if (arrayType === emptyObjectType) {
return stringType;
}
}
if (!isArrayLikeType(arrayType)) {
if (!reportedError) {
// Which error we report depends on whether there was a string constituent. For example,
// if the input type is number | string, we want to say that number is not an array type.
// But if the input was just number, we want to say that number is not an array type
// or a string type.
var diagnostic = hasStringConstituent
? ts.Diagnostics.Type_0_is_not_an_array_type
: ts.Diagnostics.Type_0_is_not_an_array_type_or_a_string_type;
error(errorNode, diagnostic, typeToString(arrayType));
}
return hasStringConstituent ? stringType : unknownType;
}
var arrayElementType = getIndexTypeOfType(arrayType, 1 /* Number */) || unknownType;
if (hasStringConstituent) {
// This is just an optimization for the case where arrayOrStringType is string | string[]
if (arrayElementType.flags & 258 /* StringLike */) {
return stringType;
}
return getUnionType([arrayElementType, stringType]);
}
return arrayElementType;
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
checkElementTypeOfArrayOrString
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkBreakOrContinueStatement(node) {
// Grammar checking
checkGrammarStatementInAmbientContext(node) || checkGrammarBreakOrContinueStatement(node);
// TODO: Check that target label is valid
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
checkBreakOrContinueStatement
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function isGetAccessorWithAnnotatatedSetAccessor(node) {
return !!(node.kind === 145 /* GetAccessor */ && ts.getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(node.symbol, 146 /* SetAccessor */)));
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
isGetAccessorWithAnnotatatedSetAccessor
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkReturnStatement(node) {
// Grammar checking
if (!checkGrammarStatementInAmbientContext(node)) {
var functionBlock = ts.getContainingFunction(node);
if (!functionBlock) {
grammarErrorOnFirstToken(node, ts.Diagnostics.A_return_statement_can_only_be_used_within_a_function_body);
}
}
if (node.expression) {
var func = ts.getContainingFunction(node);
if (func) {
var signature = getSignatureFromDeclaration(func);
var returnType = getReturnTypeOfSignature(signature);
var exprType = checkExpressionCached(node.expression);
if (func.asteriskToken) {
// A generator does not need its return expressions checked against its return type.
// Instead, the yield expressions are checked against the element type.
// TODO: Check return expressions of generators when return type tracking is added
// for generators.
return;
}
if (func.kind === 146 /* SetAccessor */) {
error(node.expression, ts.Diagnostics.Setters_cannot_return_a_value);
}
else if (func.kind === 144 /* Constructor */) {
if (!checkTypeAssignableTo(exprType, returnType, node.expression)) {
error(node.expression, ts.Diagnostics.Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class);
}
}
else if (func.type || isGetAccessorWithAnnotatatedSetAccessor(func) || signature.typePredicate) {
if (ts.isAsyncFunctionLike(func)) {
var promisedType = getPromisedType(returnType);
var awaitedType = checkAwaitedType(exprType, node.expression, ts.Diagnostics.Return_expression_in_async_function_does_not_have_a_valid_callable_then_member);
if (promisedType) {
// If the function has a return type, but promisedType is
// undefined, an error will be reported in checkAsyncFunctionReturnType
// so we don't need to report one here.
checkTypeAssignableTo(awaitedType, promisedType, node.expression);
}
}
else {
checkTypeAssignableTo(exprType, returnType, node.expression);
}
}
}
}
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
checkReturnStatement
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkWithStatement(node) {
// Grammar checking for withStatement
if (!checkGrammarStatementInAmbientContext(node)) {
if (node.parserContextFlags & 8 /* Await */) {
grammarErrorOnFirstToken(node, ts.Diagnostics.with_statements_are_not_allowed_in_an_async_function_block);
}
}
checkExpression(node.expression);
error(node.expression, ts.Diagnostics.All_symbols_within_a_with_block_will_be_resolved_to_any);
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
checkWithStatement
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkSwitchStatement(node) {
// Grammar checking
checkGrammarStatementInAmbientContext(node);
var firstDefaultClause;
var hasDuplicateDefaultClause = false;
var expressionType = checkExpression(node.expression);
var expressionTypeIsStringLike = someConstituentTypeHasKind(expressionType, 258 /* StringLike */);
ts.forEach(node.caseBlock.clauses, function (clause) {
// Grammar check for duplicate default clauses, skip if we already report duplicate default clause
if (clause.kind === 242 /* DefaultClause */ && !hasDuplicateDefaultClause) {
if (firstDefaultClause === undefined) {
firstDefaultClause = clause;
}
else {
var sourceFile = ts.getSourceFileOfNode(node);
var start = ts.skipTrivia(sourceFile.text, clause.pos);
var end = clause.statements.length > 0 ? clause.statements[0].pos : clause.end;
grammarErrorAtPos(sourceFile, start, end - start, ts.Diagnostics.A_default_clause_cannot_appear_more_than_once_in_a_switch_statement);
hasDuplicateDefaultClause = true;
}
}
if (produceDiagnostics && clause.kind === 241 /* CaseClause */) {
var caseClause = clause;
// TypeScript 1.0 spec (April 2014):5.9
// In a 'switch' statement, each 'case' expression must be of a type that is assignable to or from the type of the 'switch' expression.
var caseType = checkExpression(caseClause.expression);
// Permit 'number[] | "foo"' to be asserted to 'string'.
if (expressionTypeIsStringLike && someConstituentTypeHasKind(caseType, 258 /* StringLike */)) {
return;
}
if (!isTypeAssignableTo(expressionType, caseType)) {
// check 'expressionType isAssignableTo caseType' failed, try the reversed check and report errors if it fails
checkTypeAssignableTo(caseType, expressionType, caseClause.expression, /*headMessage*/ undefined);
}
}
ts.forEach(clause.statements, checkSourceElement);
});
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
checkSwitchStatement
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkLabeledStatement(node) {
// Grammar checking
if (!checkGrammarStatementInAmbientContext(node)) {
var current = node.parent;
while (current) {
if (ts.isFunctionLike(current)) {
break;
}
if (current.kind === 207 /* LabeledStatement */ && current.label.text === node.label.text) {
var sourceFile = ts.getSourceFileOfNode(node);
grammarErrorOnNode(node.label, ts.Diagnostics.Duplicate_label_0, ts.getTextOfNodeFromSourceText(sourceFile.text, node.label));
break;
}
current = current.parent;
}
}
// ensure that label is unique
checkSourceElement(node.statement);
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
checkLabeledStatement
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkThrowStatement(node) {
// Grammar checking
if (!checkGrammarStatementInAmbientContext(node)) {
if (node.expression === undefined) {
grammarErrorAfterFirstToken(node, ts.Diagnostics.Line_break_not_permitted_here);
}
}
if (node.expression) {
checkExpression(node.expression);
}
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
checkThrowStatement
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkTryStatement(node) {
// Grammar checking
checkGrammarStatementInAmbientContext(node);
checkBlock(node.tryBlock);
var catchClause = node.catchClause;
if (catchClause) {
// Grammar checking
if (catchClause.variableDeclaration) {
if (catchClause.variableDeclaration.name.kind !== 69 /* Identifier */) {
grammarErrorOnFirstToken(catchClause.variableDeclaration.name, ts.Diagnostics.Catch_clause_variable_name_must_be_an_identifier);
}
else if (catchClause.variableDeclaration.type) {
grammarErrorOnFirstToken(catchClause.variableDeclaration.type, ts.Diagnostics.Catch_clause_variable_cannot_have_a_type_annotation);
}
else if (catchClause.variableDeclaration.initializer) {
grammarErrorOnFirstToken(catchClause.variableDeclaration.initializer, ts.Diagnostics.Catch_clause_variable_cannot_have_an_initializer);
}
else {
var identifierName = catchClause.variableDeclaration.name.text;
var locals = catchClause.block.locals;
if (locals && ts.hasProperty(locals, identifierName)) {
var localSymbol = locals[identifierName];
if (localSymbol && (localSymbol.flags & 2 /* BlockScopedVariable */) !== 0) {
grammarErrorOnNode(localSymbol.valueDeclaration, ts.Diagnostics.Cannot_redeclare_identifier_0_in_catch_clause, identifierName);
}
}
}
}
checkBlock(catchClause.block);
}
if (node.finallyBlock) {
checkBlock(node.finallyBlock);
}
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
checkTryStatement
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkIndexConstraints(type) {
var declaredNumberIndexer = getIndexDeclarationOfSymbol(type.symbol, 1 /* Number */);
var declaredStringIndexer = getIndexDeclarationOfSymbol(type.symbol, 0 /* String */);
var stringIndexType = getIndexTypeOfType(type, 0 /* String */);
var numberIndexType = getIndexTypeOfType(type, 1 /* Number */);
if (stringIndexType || numberIndexType) {
ts.forEach(getPropertiesOfObjectType(type), function (prop) {
var propType = getTypeOfSymbol(prop);
checkIndexConstraintForProperty(prop, propType, type, declaredStringIndexer, stringIndexType, 0 /* String */);
checkIndexConstraintForProperty(prop, propType, type, declaredNumberIndexer, numberIndexType, 1 /* Number */);
});
if (type.flags & 1024 /* Class */ && ts.isClassLike(type.symbol.valueDeclaration)) {
var classDeclaration = type.symbol.valueDeclaration;
for (var _i = 0, _a = classDeclaration.members; _i < _a.length; _i++) {
var member = _a[_i];
// Only process instance properties with computed names here.
// Static properties cannot be in conflict with indexers,
// and properties with literal names were already checked.
if (!(member.flags & 64 /* Static */) && ts.hasDynamicName(member)) {
var propType = getTypeOfSymbol(member.symbol);
checkIndexConstraintForProperty(member.symbol, propType, type, declaredStringIndexer, stringIndexType, 0 /* String */);
checkIndexConstraintForProperty(member.symbol, propType, type, declaredNumberIndexer, numberIndexType, 1 /* Number */);
}
}
}
}
var errorNode;
if (stringIndexType && numberIndexType) {
errorNode = declaredNumberIndexer || declaredStringIndexer;
// condition 'errorNode === undefined' may appear if types does not declare nor string neither number indexer
if (!errorNode && (type.flags & 2048 /* Interface */)) {
var someBaseTypeHasBothIndexers = ts.forEach(getBaseTypes(type), function (base) { return getIndexTypeOfType(base, 0 /* String */) && getIndexTypeOfType(base, 1 /* Number */); });
errorNode = someBaseTypeHasBothIndexers ? undefined : type.symbol.declarations[0];
}
}
if (errorNode && !isTypeAssignableTo(numberIndexType, stringIndexType)) {
error(errorNode, ts.Diagnostics.Numeric_index_type_0_is_not_assignable_to_string_index_type_1, typeToString(numberIndexType), typeToString(stringIndexType));
}
function checkIndexConstraintForProperty(prop, propertyType, containingType, indexDeclaration, indexType, indexKind) {
if (!indexType) {
return;
}
// index is numeric and property name is not valid numeric literal
if (indexKind === 1 /* Number */ && !isNumericName(prop.valueDeclaration.name)) {
return;
}
// perform property check if property or indexer is declared in 'type'
// this allows to rule out cases when both property and indexer are inherited from the base class
var errorNode;
if (prop.valueDeclaration.name.kind === 136 /* ComputedPropertyName */ || prop.parent === containingType.symbol) {
errorNode = prop.valueDeclaration;
}
else if (indexDeclaration) {
errorNode = indexDeclaration;
}
else if (containingType.flags & 2048 /* Interface */) {
// for interfaces property and indexer might be inherited from different bases
// check if any base class already has both property and indexer.
// check should be performed only if 'type' is the first type that brings property\indexer together
var someBaseClassHasBothPropertyAndIndexer = ts.forEach(getBaseTypes(containingType), function (base) { return getPropertyOfObjectType(base, prop.name) && getIndexTypeOfType(base, indexKind); });
errorNode = someBaseClassHasBothPropertyAndIndexer ? undefined : containingType.symbol.declarations[0];
}
if (errorNode && !isTypeAssignableTo(propertyType, indexType)) {
var errorMessage = indexKind === 0 /* String */
? ts.Diagnostics.Property_0_of_type_1_is_not_assignable_to_string_index_type_2
: ts.Diagnostics.Property_0_of_type_1_is_not_assignable_to_numeric_index_type_2;
error(errorNode, errorMessage, symbolToString(prop), typeToString(propertyType), typeToString(indexType));
}
}
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
checkIndexConstraints
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkIndexConstraintForProperty(prop, propertyType, containingType, indexDeclaration, indexType, indexKind) {
if (!indexType) {
return;
}
// index is numeric and property name is not valid numeric literal
if (indexKind === 1 /* Number */ && !isNumericName(prop.valueDeclaration.name)) {
return;
}
// perform property check if property or indexer is declared in 'type'
// this allows to rule out cases when both property and indexer are inherited from the base class
var errorNode;
if (prop.valueDeclaration.name.kind === 136 /* ComputedPropertyName */ || prop.parent === containingType.symbol) {
errorNode = prop.valueDeclaration;
}
else if (indexDeclaration) {
errorNode = indexDeclaration;
}
else if (containingType.flags & 2048 /* Interface */) {
// for interfaces property and indexer might be inherited from different bases
// check if any base class already has both property and indexer.
// check should be performed only if 'type' is the first type that brings property\indexer together
var someBaseClassHasBothPropertyAndIndexer = ts.forEach(getBaseTypes(containingType), function (base) { return getPropertyOfObjectType(base, prop.name) && getIndexTypeOfType(base, indexKind); });
errorNode = someBaseClassHasBothPropertyAndIndexer ? undefined : containingType.symbol.declarations[0];
}
if (errorNode && !isTypeAssignableTo(propertyType, indexType)) {
var errorMessage = indexKind === 0 /* String */
? ts.Diagnostics.Property_0_of_type_1_is_not_assignable_to_string_index_type_2
: ts.Diagnostics.Property_0_of_type_1_is_not_assignable_to_numeric_index_type_2;
error(errorNode, errorMessage, symbolToString(prop), typeToString(propertyType), typeToString(indexType));
}
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
checkIndexConstraintForProperty
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkTypeNameIsReserved(name, message) {
// TS 1.0 spec (April 2014): 3.6.1
// The predefined type keywords are reserved and cannot be used as names of user defined types.
switch (name.text) {
case "any":
case "number":
case "boolean":
case "string":
case "symbol":
case "void":
error(name, message, name.text);
}
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
checkTypeNameIsReserved
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkClassExpression(node) {
checkClassLikeDeclaration(node);
return getTypeOfSymbol(getSymbolOfNode(node));
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
checkClassExpression
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkClassDeclaration(node) {
if (!node.name && !(node.flags & 512 /* Default */)) {
grammarErrorOnFirstToken(node, ts.Diagnostics.A_class_declaration_without_the_default_modifier_must_have_a_name);
}
checkClassLikeDeclaration(node);
ts.forEach(node.members, checkSourceElement);
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
checkClassDeclaration
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkClassLikeDeclaration(node) {
checkGrammarClassDeclarationHeritageClauses(node);
checkDecorators(node);
if (node.name) {
checkTypeNameIsReserved(node.name, ts.Diagnostics.Class_name_cannot_be_0);
checkCollisionWithCapturedThisVariable(node, node.name);
checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
}
checkTypeParameters(node.typeParameters);
checkExportsOnMergedDeclarations(node);
var symbol = getSymbolOfNode(node);
var type = getDeclaredTypeOfSymbol(symbol);
var typeWithThis = getTypeWithThisArgument(type);
var staticType = getTypeOfSymbol(symbol);
var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node);
if (baseTypeNode) {
emitExtends = emitExtends || !ts.isInAmbientContext(node);
var baseTypes = getBaseTypes(type);
if (baseTypes.length && produceDiagnostics) {
var baseType = baseTypes[0];
var staticBaseType = getBaseConstructorTypeOfClass(type);
checkSourceElement(baseTypeNode.expression);
if (baseTypeNode.typeArguments) {
ts.forEach(baseTypeNode.typeArguments, checkSourceElement);
for (var _i = 0, _a = getConstructorsForTypeArguments(staticBaseType, baseTypeNode.typeArguments); _i < _a.length; _i++) {
var constructor = _a[_i];
if (!checkTypeArgumentConstraints(constructor.typeParameters, baseTypeNode.typeArguments)) {
break;
}
}
}
checkTypeAssignableTo(typeWithThis, getTypeWithThisArgument(baseType, type.thisType), node.name || node, ts.Diagnostics.Class_0_incorrectly_extends_base_class_1);
checkTypeAssignableTo(staticType, getTypeWithoutSignatures(staticBaseType), node.name || node, ts.Diagnostics.Class_static_side_0_incorrectly_extends_base_class_static_side_1);
if (!(staticBaseType.symbol && staticBaseType.symbol.flags & 32 /* Class */)) {
// When the static base type is a "class-like" constructor function (but not actually a class), we verify
// that all instantiated base constructor signatures return the same type. We can simply compare the type
// references (as opposed to checking the structure of the types) because elsewhere we have already checked
// that the base type is a class or interface type (and not, for example, an anonymous object type).
var constructors = getInstantiatedConstructorsForTypeArguments(staticBaseType, baseTypeNode.typeArguments);
if (ts.forEach(constructors, function (sig) { return getReturnTypeOfSignature(sig) !== baseType; })) {
error(baseTypeNode.expression, ts.Diagnostics.Base_constructors_must_all_have_the_same_return_type);
}
}
checkKindsOfPropertyMemberOverrides(type, baseType);
}
}
var implementedTypeNodes = ts.getClassImplementsHeritageClauseElements(node);
if (implementedTypeNodes) {
for (var _b = 0, implementedTypeNodes_1 = implementedTypeNodes; _b < implementedTypeNodes_1.length; _b++) {
var typeRefNode = implementedTypeNodes_1[_b];
if (!ts.isSupportedExpressionWithTypeArguments(typeRefNode)) {
error(typeRefNode.expression, ts.Diagnostics.A_class_can_only_implement_an_identifier_Slashqualified_name_with_optional_type_arguments);
}
checkTypeReferenceNode(typeRefNode);
if (produceDiagnostics) {
var t = getTypeFromTypeNode(typeRefNode);
if (t !== unknownType) {
var declaredType = (t.flags & 4096 /* Reference */) ? t.target : t;
if (declaredType.flags & (1024 /* Class */ | 2048 /* Interface */)) {
checkTypeAssignableTo(typeWithThis, getTypeWithThisArgument(t, type.thisType), node.name || node, ts.Diagnostics.Class_0_incorrectly_implements_interface_1);
}
else {
error(typeRefNode, ts.Diagnostics.A_class_may_only_implement_another_class_or_interface);
}
}
}
}
}
if (produceDiagnostics) {
checkIndexConstraints(type);
checkTypeForDuplicateIndexSignatures(node);
}
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
checkClassLikeDeclaration
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getTargetSymbol(s) {
// if symbol is instantiated its flags are not copied from the 'target'
// so we'll need to get back original 'target' symbol to work with correct set of flags
return s.flags & 16777216 /* Instantiated */ ? getSymbolLinks(s).target : s;
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
getTargetSymbol
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getClassLikeDeclarationOfSymbol(symbol) {
return ts.forEach(symbol.declarations, function (d) { return ts.isClassLike(d) ? d : undefined; });
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
getClassLikeDeclarationOfSymbol
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkKindsOfPropertyMemberOverrides(type, baseType) {
// TypeScript 1.0 spec (April 2014): 8.2.3
// A derived class inherits all members from its base class it doesn't override.
// Inheritance means that a derived class implicitly contains all non - overridden members of the base class.
// Both public and private property members are inherited, but only public property members can be overridden.
// A property member in a derived class is said to override a property member in a base class
// when the derived class property member has the same name and kind(instance or static)
// as the base class property member.
// The type of an overriding property member must be assignable(section 3.8.4)
// to the type of the overridden property member, or otherwise a compile - time error occurs.
// Base class instance member functions can be overridden by derived class instance member functions,
// but not by other kinds of members.
// Base class instance member variables and accessors can be overridden by
// derived class instance member variables and accessors, but not by other kinds of members.
// NOTE: assignability is checked in checkClassDeclaration
var baseProperties = getPropertiesOfObjectType(baseType);
for (var _i = 0, baseProperties_1 = baseProperties; _i < baseProperties_1.length; _i++) {
var baseProperty = baseProperties_1[_i];
var base = getTargetSymbol(baseProperty);
if (base.flags & 134217728 /* Prototype */) {
continue;
}
var derived = getTargetSymbol(getPropertyOfObjectType(type, base.name));
var baseDeclarationFlags = getDeclarationFlagsFromSymbol(base);
ts.Debug.assert(!!derived, "derived should point to something, even if it is the base class' declaration.");
if (derived) {
// In order to resolve whether the inherited method was overriden in the base class or not,
// we compare the Symbols obtained. Since getTargetSymbol returns the symbol on the *uninstantiated*
// type declaration, derived and base resolve to the same symbol even in the case of generic classes.
if (derived === base) {
// derived class inherits base without override/redeclaration
var derivedClassDecl = getClassLikeDeclarationOfSymbol(type.symbol);
// It is an error to inherit an abstract member without implementing it or being declared abstract.
// If there is no declaration for the derived class (as in the case of class expressions),
// then the class cannot be declared abstract.
if (baseDeclarationFlags & 128 /* Abstract */ && (!derivedClassDecl || !(derivedClassDecl.flags & 128 /* Abstract */))) {
if (derivedClassDecl.kind === 186 /* ClassExpression */) {
error(derivedClassDecl, ts.Diagnostics.Non_abstract_class_expression_does_not_implement_inherited_abstract_member_0_from_class_1, symbolToString(baseProperty), typeToString(baseType));
}
else {
error(derivedClassDecl, ts.Diagnostics.Non_abstract_class_0_does_not_implement_inherited_abstract_member_1_from_class_2, typeToString(type), symbolToString(baseProperty), typeToString(baseType));
}
}
}
else {
// derived overrides base.
var derivedDeclarationFlags = getDeclarationFlagsFromSymbol(derived);
if ((baseDeclarationFlags & 16 /* Private */) || (derivedDeclarationFlags & 16 /* Private */)) {
// either base or derived property is private - not override, skip it
continue;
}
if ((baseDeclarationFlags & 64 /* Static */) !== (derivedDeclarationFlags & 64 /* Static */)) {
// value of 'static' is not the same for properties - not override, skip it
continue;
}
if ((base.flags & derived.flags & 8192 /* Method */) || ((base.flags & 98308 /* PropertyOrAccessor */) && (derived.flags & 98308 /* PropertyOrAccessor */))) {
// method is overridden with method or property/accessor is overridden with property/accessor - correct case
continue;
}
var errorMessage = void 0;
if (base.flags & 8192 /* Method */) {
if (derived.flags & 98304 /* Accessor */) {
errorMessage = ts.Diagnostics.Class_0_defines_instance_member_function_1_but_extended_class_2_defines_it_as_instance_member_accessor;
}
else {
ts.Debug.assert((derived.flags & 4 /* Property */) !== 0);
errorMessage = ts.Diagnostics.Class_0_defines_instance_member_function_1_but_extended_class_2_defines_it_as_instance_member_property;
}
}
else if (base.flags & 4 /* Property */) {
ts.Debug.assert((derived.flags & 8192 /* Method */) !== 0);
errorMessage = ts.Diagnostics.Class_0_defines_instance_member_property_1_but_extended_class_2_defines_it_as_instance_member_function;
}
else {
ts.Debug.assert((base.flags & 98304 /* Accessor */) !== 0);
ts.Debug.assert((derived.flags & 8192 /* Method */) !== 0);
errorMessage = ts.Diagnostics.Class_0_defines_instance_member_accessor_1_but_extended_class_2_defines_it_as_instance_member_function;
}
error(derived.valueDeclaration.name, errorMessage, typeToString(baseType), symbolToString(base), typeToString(type));
}
}
}
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
checkKindsOfPropertyMemberOverrides
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function isAccessor(kind) {
return kind === 145 /* GetAccessor */ || kind === 146 /* SetAccessor */;
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
isAccessor
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function areTypeParametersIdentical(list1, list2) {
if (!list1 && !list2) {
return true;
}
if (!list1 || !list2 || list1.length !== list2.length) {
return false;
}
// TypeScript 1.0 spec (April 2014):
// When a generic interface has multiple declarations, all declarations must have identical type parameter
// lists, i.e. identical type parameter names with identical constraints in identical order.
for (var i = 0, len = list1.length; i < len; i++) {
var tp1 = list1[i];
var tp2 = list2[i];
if (tp1.name.text !== tp2.name.text) {
return false;
}
if (!tp1.constraint && !tp2.constraint) {
continue;
}
if (!tp1.constraint || !tp2.constraint) {
return false;
}
if (!isTypeIdenticalTo(getTypeFromTypeNode(tp1.constraint), getTypeFromTypeNode(tp2.constraint))) {
return false;
}
}
return true;
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
areTypeParametersIdentical
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkInheritedPropertiesAreIdentical(type, typeNode) {
var baseTypes = getBaseTypes(type);
if (baseTypes.length < 2) {
return true;
}
var seen = {};
ts.forEach(resolveDeclaredMembers(type).declaredProperties, function (p) { seen[p.name] = { prop: p, containingType: type }; });
var ok = true;
for (var _i = 0, baseTypes_2 = baseTypes; _i < baseTypes_2.length; _i++) {
var base = baseTypes_2[_i];
var properties = getPropertiesOfObjectType(getTypeWithThisArgument(base, type.thisType));
for (var _a = 0, properties_4 = properties; _a < properties_4.length; _a++) {
var prop = properties_4[_a];
if (!ts.hasProperty(seen, prop.name)) {
seen[prop.name] = { prop: prop, containingType: base };
}
else {
var existing = seen[prop.name];
var isInheritedProperty = existing.containingType !== type;
if (isInheritedProperty && !isPropertyIdenticalTo(existing.prop, prop)) {
ok = false;
var typeName1 = typeToString(existing.containingType);
var typeName2 = typeToString(base);
var errorInfo = ts.chainDiagnosticMessages(undefined, ts.Diagnostics.Named_property_0_of_types_1_and_2_are_not_identical, symbolToString(prop), typeName1, typeName2);
errorInfo = ts.chainDiagnosticMessages(errorInfo, ts.Diagnostics.Interface_0_cannot_simultaneously_extend_types_1_and_2, typeToString(type), typeName1, typeName2);
diagnostics.add(ts.createDiagnosticForNodeFromMessageChain(typeNode, errorInfo));
}
}
}
}
return ok;
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
checkInheritedPropertiesAreIdentical
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkInterfaceDeclaration(node) {
// Grammar checking
checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarInterfaceDeclaration(node);
checkTypeParameters(node.typeParameters);
if (produceDiagnostics) {
checkTypeNameIsReserved(node.name, ts.Diagnostics.Interface_name_cannot_be_0);
checkExportsOnMergedDeclarations(node);
var symbol = getSymbolOfNode(node);
var firstInterfaceDecl = ts.getDeclarationOfKind(symbol, 215 /* InterfaceDeclaration */);
if (symbol.declarations.length > 1) {
if (node !== firstInterfaceDecl && !areTypeParametersIdentical(firstInterfaceDecl.typeParameters, node.typeParameters)) {
error(node.name, ts.Diagnostics.All_declarations_of_an_interface_must_have_identical_type_parameters);
}
}
// Only check this symbol once
if (node === firstInterfaceDecl) {
var type = getDeclaredTypeOfSymbol(symbol);
var typeWithThis = getTypeWithThisArgument(type);
// run subsequent checks only if first set succeeded
if (checkInheritedPropertiesAreIdentical(type, node.name)) {
for (var _i = 0, _a = getBaseTypes(type); _i < _a.length; _i++) {
var baseType = _a[_i];
checkTypeAssignableTo(typeWithThis, getTypeWithThisArgument(baseType, type.thisType), node.name, ts.Diagnostics.Interface_0_incorrectly_extends_interface_1);
}
checkIndexConstraints(type);
}
}
}
ts.forEach(ts.getInterfaceBaseTypeNodes(node), function (heritageElement) {
if (!ts.isSupportedExpressionWithTypeArguments(heritageElement)) {
error(heritageElement.expression, ts.Diagnostics.An_interface_can_only_extend_an_identifier_Slashqualified_name_with_optional_type_arguments);
}
checkTypeReferenceNode(heritageElement);
});
ts.forEach(node.members, checkSourceElement);
if (produceDiagnostics) {
checkTypeForDuplicateIndexSignatures(node);
}
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
checkInterfaceDeclaration
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkTypeAliasDeclaration(node) {
// Grammar checking
checkGrammarDecorators(node) || checkGrammarModifiers(node);
checkTypeNameIsReserved(node.name, ts.Diagnostics.Type_alias_name_cannot_be_0);
checkSourceElement(node.type);
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
checkTypeAliasDeclaration
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function computeEnumMemberValues(node) {
var nodeLinks = getNodeLinks(node);
if (!(nodeLinks.flags & 8192 /* EnumValuesComputed */)) {
var enumSymbol = getSymbolOfNode(node);
var enumType = getDeclaredTypeOfSymbol(enumSymbol);
var autoValue = 0; // set to undefined when enum member is non-constant
var ambient = ts.isInAmbientContext(node);
var enumIsConst = ts.isConst(node);
for (var _i = 0, _a = node.members; _i < _a.length; _i++) {
var member = _a[_i];
if (isComputedNonLiteralName(member.name)) {
error(member.name, ts.Diagnostics.Computed_property_names_are_not_allowed_in_enums);
}
else {
var text = getTextOfPropertyName(member.name);
if (isNumericLiteralName(text)) {
error(member.name, ts.Diagnostics.An_enum_member_cannot_have_a_numeric_name);
}
}
var previousEnumMemberIsNonConstant = autoValue === undefined;
var initializer = member.initializer;
if (initializer) {
autoValue = computeConstantValueForEnumMemberInitializer(initializer, enumType, enumIsConst, ambient);
}
else if (ambient && !enumIsConst) {
// In ambient enum declarations that specify no const modifier, enum member declarations
// that omit a value are considered computed members (as opposed to having auto-incremented values assigned).
autoValue = undefined;
}
else if (previousEnumMemberIsNonConstant) {
// If the member declaration specifies no value, the member is considered a constant enum member.
// If the member is the first member in the enum declaration, it is assigned the value zero.
// Otherwise, it is assigned the value of the immediately preceding member plus one,
// and an error occurs if the immediately preceding member is not a constant enum member
error(member.name, ts.Diagnostics.Enum_member_must_have_initializer);
}
if (autoValue !== undefined) {
getNodeLinks(member).enumMemberValue = autoValue++;
}
}
nodeLinks.flags |= 8192 /* EnumValuesComputed */;
}
function computeConstantValueForEnumMemberInitializer(initializer, enumType, enumIsConst, ambient) {
// Controls if error should be reported after evaluation of constant value is completed
// Can be false if another more precise error was already reported during evaluation.
var reportError = true;
var value = evalConstant(initializer);
if (reportError) {
if (value === undefined) {
if (enumIsConst) {
error(initializer, ts.Diagnostics.In_const_enum_declarations_member_initializer_must_be_constant_expression);
}
else if (ambient) {
error(initializer, ts.Diagnostics.In_ambient_enum_declarations_member_initializer_must_be_constant_expression);
}
else {
// Only here do we need to check that the initializer is assignable to the enum type.
checkTypeAssignableTo(checkExpression(initializer), enumType, initializer, /*headMessage*/ undefined);
}
}
else if (enumIsConst) {
if (isNaN(value)) {
error(initializer, ts.Diagnostics.const_enum_member_initializer_was_evaluated_to_disallowed_value_NaN);
}
else if (!isFinite(value)) {
error(initializer, ts.Diagnostics.const_enum_member_initializer_was_evaluated_to_a_non_finite_value);
}
}
}
return value;
function evalConstant(e) {
switch (e.kind) {
case 179 /* PrefixUnaryExpression */:
var value_1 = evalConstant(e.operand);
if (value_1 === undefined) {
return undefined;
}
switch (e.operator) {
case 35 /* PlusToken */: return value_1;
case 36 /* MinusToken */: return -value_1;
case 50 /* TildeToken */: return ~value_1;
}
return undefined;
case 181 /* BinaryExpression */:
var left = evalConstant(e.left);
if (left === undefined) {
return undefined;
}
var right = evalConstant(e.right);
if (right === undefined) {
return undefined;
}
switch (e.operatorToken.kind) {
case 47 /* BarToken */: return left | right;
case 46 /* AmpersandToken */: return left & right;
case 44 /* GreaterThanGreaterThanToken */: return left >> right;
case 45 /* GreaterThanGreaterThanGreaterThanToken */: return left >>> right;
case 43 /* LessThanLessThanToken */: return left << right;
case 48 /* CaretToken */: return left ^ right;
case 37 /* AsteriskToken */: return left * right;
case 39 /* SlashToken */: return left / right;
case 35 /* PlusToken */: return left + right;
case 36 /* MinusToken */: return left - right;
case 40 /* PercentToken */: return left % right;
}
return undefined;
case 8 /* NumericLiteral */:
return +e.text;
case 172 /* ParenthesizedExpression */:
return evalConstant(e.expression);
case 69 /* Identifier */:
case 167 /* ElementAccessExpression */:
case 166 /* PropertyAccessExpression */:
var member = initializer.parent;
var currentType = getTypeOfSymbol(getSymbolOfNode(member.parent));
var enumType_1;
var propertyName;
if (e.kind === 69 /* Identifier */) {
// unqualified names can refer to member that reside in different declaration of the enum so just doing name resolution won't work.
// instead pick current enum type and later try to fetch member from the type
enumType_1 = currentType;
propertyName = e.text;
}
else {
var expression;
if (e.kind === 167 /* ElementAccessExpression */) {
if (e.argumentExpression === undefined ||
e.argumentExpression.kind !== 9 /* StringLiteral */) {
return undefined;
}
expression = e.expression;
propertyName = e.argumentExpression.text;
}
else {
expression = e.expression;
propertyName = e.name.text;
}
// expression part in ElementAccess\PropertyAccess should be either identifier or dottedName
var current = expression;
while (current) {
if (current.kind === 69 /* Identifier */) {
break;
}
else if (current.kind === 166 /* PropertyAccessExpression */) {
current = current.expression;
}
else {
return undefined;
}
}
enumType_1 = checkExpression(expression);
// allow references to constant members of other enums
if (!(enumType_1.symbol && (enumType_1.symbol.flags & 384 /* Enum */))) {
return undefined;
}
}
if (propertyName === undefined) {
return undefined;
}
var property = getPropertyOfObjectType(enumType_1, propertyName);
if (!property || !(property.flags & 8 /* EnumMember */)) {
return undefined;
}
var propertyDecl = property.valueDeclaration;
// self references are illegal
if (member === propertyDecl) {
return undefined;
}
// illegal case: forward reference
if (!isBlockScopedNameDeclaredBeforeUse(propertyDecl, member)) {
reportError = false;
error(e, ts.Diagnostics.A_member_initializer_in_a_enum_declaration_cannot_reference_members_declared_after_it_including_members_defined_in_other_enums);
return undefined;
}
return getNodeLinks(propertyDecl).enumMemberValue;
}
}
}
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
computeEnumMemberValues
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function computeConstantValueForEnumMemberInitializer(initializer, enumType, enumIsConst, ambient) {
// Controls if error should be reported after evaluation of constant value is completed
// Can be false if another more precise error was already reported during evaluation.
var reportError = true;
var value = evalConstant(initializer);
if (reportError) {
if (value === undefined) {
if (enumIsConst) {
error(initializer, ts.Diagnostics.In_const_enum_declarations_member_initializer_must_be_constant_expression);
}
else if (ambient) {
error(initializer, ts.Diagnostics.In_ambient_enum_declarations_member_initializer_must_be_constant_expression);
}
else {
// Only here do we need to check that the initializer is assignable to the enum type.
checkTypeAssignableTo(checkExpression(initializer), enumType, initializer, /*headMessage*/ undefined);
}
}
else if (enumIsConst) {
if (isNaN(value)) {
error(initializer, ts.Diagnostics.const_enum_member_initializer_was_evaluated_to_disallowed_value_NaN);
}
else if (!isFinite(value)) {
error(initializer, ts.Diagnostics.const_enum_member_initializer_was_evaluated_to_a_non_finite_value);
}
}
}
return value;
function evalConstant(e) {
switch (e.kind) {
case 179 /* PrefixUnaryExpression */:
var value_1 = evalConstant(e.operand);
if (value_1 === undefined) {
return undefined;
}
switch (e.operator) {
case 35 /* PlusToken */: return value_1;
case 36 /* MinusToken */: return -value_1;
case 50 /* TildeToken */: return ~value_1;
}
return undefined;
case 181 /* BinaryExpression */:
var left = evalConstant(e.left);
if (left === undefined) {
return undefined;
}
var right = evalConstant(e.right);
if (right === undefined) {
return undefined;
}
switch (e.operatorToken.kind) {
case 47 /* BarToken */: return left | right;
case 46 /* AmpersandToken */: return left & right;
case 44 /* GreaterThanGreaterThanToken */: return left >> right;
case 45 /* GreaterThanGreaterThanGreaterThanToken */: return left >>> right;
case 43 /* LessThanLessThanToken */: return left << right;
case 48 /* CaretToken */: return left ^ right;
case 37 /* AsteriskToken */: return left * right;
case 39 /* SlashToken */: return left / right;
case 35 /* PlusToken */: return left + right;
case 36 /* MinusToken */: return left - right;
case 40 /* PercentToken */: return left % right;
}
return undefined;
case 8 /* NumericLiteral */:
return +e.text;
case 172 /* ParenthesizedExpression */:
return evalConstant(e.expression);
case 69 /* Identifier */:
case 167 /* ElementAccessExpression */:
case 166 /* PropertyAccessExpression */:
var member = initializer.parent;
var currentType = getTypeOfSymbol(getSymbolOfNode(member.parent));
var enumType_1;
var propertyName;
if (e.kind === 69 /* Identifier */) {
// unqualified names can refer to member that reside in different declaration of the enum so just doing name resolution won't work.
// instead pick current enum type and later try to fetch member from the type
enumType_1 = currentType;
propertyName = e.text;
}
else {
var expression;
if (e.kind === 167 /* ElementAccessExpression */) {
if (e.argumentExpression === undefined ||
e.argumentExpression.kind !== 9 /* StringLiteral */) {
return undefined;
}
expression = e.expression;
propertyName = e.argumentExpression.text;
}
else {
expression = e.expression;
propertyName = e.name.text;
}
// expression part in ElementAccess\PropertyAccess should be either identifier or dottedName
var current = expression;
while (current) {
if (current.kind === 69 /* Identifier */) {
break;
}
else if (current.kind === 166 /* PropertyAccessExpression */) {
current = current.expression;
}
else {
return undefined;
}
}
enumType_1 = checkExpression(expression);
// allow references to constant members of other enums
if (!(enumType_1.symbol && (enumType_1.symbol.flags & 384 /* Enum */))) {
return undefined;
}
}
if (propertyName === undefined) {
return undefined;
}
var property = getPropertyOfObjectType(enumType_1, propertyName);
if (!property || !(property.flags & 8 /* EnumMember */)) {
return undefined;
}
var propertyDecl = property.valueDeclaration;
// self references are illegal
if (member === propertyDecl) {
return undefined;
}
// illegal case: forward reference
if (!isBlockScopedNameDeclaredBeforeUse(propertyDecl, member)) {
reportError = false;
error(e, ts.Diagnostics.A_member_initializer_in_a_enum_declaration_cannot_reference_members_declared_after_it_including_members_defined_in_other_enums);
return undefined;
}
return getNodeLinks(propertyDecl).enumMemberValue;
}
}
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
computeConstantValueForEnumMemberInitializer
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function evalConstant(e) {
switch (e.kind) {
case 179 /* PrefixUnaryExpression */:
var value_1 = evalConstant(e.operand);
if (value_1 === undefined) {
return undefined;
}
switch (e.operator) {
case 35 /* PlusToken */: return value_1;
case 36 /* MinusToken */: return -value_1;
case 50 /* TildeToken */: return ~value_1;
}
return undefined;
case 181 /* BinaryExpression */:
var left = evalConstant(e.left);
if (left === undefined) {
return undefined;
}
var right = evalConstant(e.right);
if (right === undefined) {
return undefined;
}
switch (e.operatorToken.kind) {
case 47 /* BarToken */: return left | right;
case 46 /* AmpersandToken */: return left & right;
case 44 /* GreaterThanGreaterThanToken */: return left >> right;
case 45 /* GreaterThanGreaterThanGreaterThanToken */: return left >>> right;
case 43 /* LessThanLessThanToken */: return left << right;
case 48 /* CaretToken */: return left ^ right;
case 37 /* AsteriskToken */: return left * right;
case 39 /* SlashToken */: return left / right;
case 35 /* PlusToken */: return left + right;
case 36 /* MinusToken */: return left - right;
case 40 /* PercentToken */: return left % right;
}
return undefined;
case 8 /* NumericLiteral */:
return +e.text;
case 172 /* ParenthesizedExpression */:
return evalConstant(e.expression);
case 69 /* Identifier */:
case 167 /* ElementAccessExpression */:
case 166 /* PropertyAccessExpression */:
var member = initializer.parent;
var currentType = getTypeOfSymbol(getSymbolOfNode(member.parent));
var enumType_1;
var propertyName;
if (e.kind === 69 /* Identifier */) {
// unqualified names can refer to member that reside in different declaration of the enum so just doing name resolution won't work.
// instead pick current enum type and later try to fetch member from the type
enumType_1 = currentType;
propertyName = e.text;
}
else {
var expression;
if (e.kind === 167 /* ElementAccessExpression */) {
if (e.argumentExpression === undefined ||
e.argumentExpression.kind !== 9 /* StringLiteral */) {
return undefined;
}
expression = e.expression;
propertyName = e.argumentExpression.text;
}
else {
expression = e.expression;
propertyName = e.name.text;
}
// expression part in ElementAccess\PropertyAccess should be either identifier or dottedName
var current = expression;
while (current) {
if (current.kind === 69 /* Identifier */) {
break;
}
else if (current.kind === 166 /* PropertyAccessExpression */) {
current = current.expression;
}
else {
return undefined;
}
}
enumType_1 = checkExpression(expression);
// allow references to constant members of other enums
if (!(enumType_1.symbol && (enumType_1.symbol.flags & 384 /* Enum */))) {
return undefined;
}
}
if (propertyName === undefined) {
return undefined;
}
var property = getPropertyOfObjectType(enumType_1, propertyName);
if (!property || !(property.flags & 8 /* EnumMember */)) {
return undefined;
}
var propertyDecl = property.valueDeclaration;
// self references are illegal
if (member === propertyDecl) {
return undefined;
}
// illegal case: forward reference
if (!isBlockScopedNameDeclaredBeforeUse(propertyDecl, member)) {
reportError = false;
error(e, ts.Diagnostics.A_member_initializer_in_a_enum_declaration_cannot_reference_members_declared_after_it_including_members_defined_in_other_enums);
return undefined;
}
return getNodeLinks(propertyDecl).enumMemberValue;
}
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
evalConstant
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkEnumDeclaration(node) {
if (!produceDiagnostics) {
return;
}
// Grammar checking
checkGrammarDecorators(node) || checkGrammarModifiers(node);
checkTypeNameIsReserved(node.name, ts.Diagnostics.Enum_name_cannot_be_0);
checkCollisionWithCapturedThisVariable(node, node.name);
checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
checkExportsOnMergedDeclarations(node);
computeEnumMemberValues(node);
var enumIsConst = ts.isConst(node);
if (compilerOptions.isolatedModules && enumIsConst && ts.isInAmbientContext(node)) {
error(node.name, ts.Diagnostics.Ambient_const_enums_are_not_allowed_when_the_isolatedModules_flag_is_provided);
}
// Spec 2014 - Section 9.3:
// It isn't possible for one enum declaration to continue the automatic numbering sequence of another,
// and when an enum type has multiple declarations, only one declaration is permitted to omit a value
// for the first member.
//
// Only perform this check once per symbol
var enumSymbol = getSymbolOfNode(node);
var firstDeclaration = ts.getDeclarationOfKind(enumSymbol, node.kind);
if (node === firstDeclaration) {
if (enumSymbol.declarations.length > 1) {
// check that const is placed\omitted on all enum declarations
ts.forEach(enumSymbol.declarations, function (decl) {
if (ts.isConstEnumDeclaration(decl) !== enumIsConst) {
error(decl.name, ts.Diagnostics.Enum_declarations_must_all_be_const_or_non_const);
}
});
}
var seenEnumMissingInitialInitializer = false;
ts.forEach(enumSymbol.declarations, function (declaration) {
// return true if we hit a violation of the rule, false otherwise
if (declaration.kind !== 217 /* EnumDeclaration */) {
return false;
}
var enumDeclaration = declaration;
if (!enumDeclaration.members.length) {
return false;
}
var firstEnumMember = enumDeclaration.members[0];
if (!firstEnumMember.initializer) {
if (seenEnumMissingInitialInitializer) {
error(firstEnumMember.name, ts.Diagnostics.In_an_enum_with_multiple_declarations_only_one_declaration_can_omit_an_initializer_for_its_first_enum_element);
}
else {
seenEnumMissingInitialInitializer = true;
}
}
});
}
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
checkEnumDeclaration
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getFirstNonAmbientClassOrFunctionDeclaration(symbol) {
var declarations = symbol.declarations;
for (var _i = 0, declarations_5 = declarations; _i < declarations_5.length; _i++) {
var declaration = declarations_5[_i];
if ((declaration.kind === 214 /* ClassDeclaration */ ||
(declaration.kind === 213 /* FunctionDeclaration */ && ts.nodeIsPresent(declaration.body))) &&
!ts.isInAmbientContext(declaration)) {
return declaration;
}
}
return undefined;
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
getFirstNonAmbientClassOrFunctionDeclaration
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function inSameLexicalScope(node1, node2) {
var container1 = ts.getEnclosingBlockScopeContainer(node1);
var container2 = ts.getEnclosingBlockScopeContainer(node2);
if (isGlobalSourceFile(container1)) {
return isGlobalSourceFile(container2);
}
else if (isGlobalSourceFile(container2)) {
return false;
}
else {
return container1 === container2;
}
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
inSameLexicalScope
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkModuleDeclaration(node) {
if (produceDiagnostics) {
// Grammar checking
var isAmbientExternalModule = node.name.kind === 9 /* StringLiteral */;
var contextErrorMessage = isAmbientExternalModule
? ts.Diagnostics.An_ambient_module_declaration_is_only_allowed_at_the_top_level_in_a_file
: ts.Diagnostics.A_namespace_declaration_is_only_allowed_in_a_namespace_or_module;
if (checkGrammarModuleElementContext(node, contextErrorMessage)) {
// If we hit a module declaration in an illegal context, just bail out to avoid cascading errors.
return;
}
if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node)) {
if (!ts.isInAmbientContext(node) && node.name.kind === 9 /* StringLiteral */) {
grammarErrorOnNode(node.name, ts.Diagnostics.Only_ambient_modules_can_use_quoted_names);
}
}
checkCollisionWithCapturedThisVariable(node, node.name);
checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
checkExportsOnMergedDeclarations(node);
var symbol = getSymbolOfNode(node);
// The following checks only apply on a non-ambient instantiated module declaration.
if (symbol.flags & 512 /* ValueModule */
&& symbol.declarations.length > 1
&& !ts.isInAmbientContext(node)
&& ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums || compilerOptions.isolatedModules)) {
var firstNonAmbientClassOrFunc = getFirstNonAmbientClassOrFunctionDeclaration(symbol);
if (firstNonAmbientClassOrFunc) {
if (ts.getSourceFileOfNode(node) !== ts.getSourceFileOfNode(firstNonAmbientClassOrFunc)) {
error(node.name, ts.Diagnostics.A_namespace_declaration_cannot_be_in_a_different_file_from_a_class_or_function_with_which_it_is_merged);
}
else if (node.pos < firstNonAmbientClassOrFunc.pos) {
error(node.name, ts.Diagnostics.A_namespace_declaration_cannot_be_located_prior_to_a_class_or_function_with_which_it_is_merged);
}
}
// if the module merges with a class declaration in the same lexical scope,
// we need to track this to ensure the correct emit.
var mergedClass = ts.getDeclarationOfKind(symbol, 214 /* ClassDeclaration */);
if (mergedClass &&
inSameLexicalScope(node, mergedClass)) {
getNodeLinks(node).flags |= 32768 /* LexicalModuleMergesWithClass */;
}
}
// Checks for ambient external modules.
if (isAmbientExternalModule) {
if (!isGlobalSourceFile(node.parent)) {
error(node.name, ts.Diagnostics.Ambient_modules_cannot_be_nested_in_other_modules_or_namespaces);
}
if (ts.isExternalModuleNameRelative(node.name.text)) {
error(node.name, ts.Diagnostics.Ambient_module_declaration_cannot_specify_relative_module_name);
}
}
}
checkSourceElement(node.body);
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
checkModuleDeclaration
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getFirstIdentifier(node) {
while (true) {
if (node.kind === 135 /* QualifiedName */) {
node = node.left;
}
else if (node.kind === 166 /* PropertyAccessExpression */) {
node = node.expression;
}
else {
break;
}
}
ts.Debug.assert(node.kind === 69 /* Identifier */);
return node;
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
getFirstIdentifier
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkExternalImportOrExportDeclaration(node) {
var moduleName = ts.getExternalModuleName(node);
if (!ts.nodeIsMissing(moduleName) && moduleName.kind !== 9 /* StringLiteral */) {
error(moduleName, ts.Diagnostics.String_literal_expected);
return false;
}
var inAmbientExternalModule = node.parent.kind === 219 /* ModuleBlock */ && node.parent.parent.name.kind === 9 /* StringLiteral */;
if (node.parent.kind !== 248 /* SourceFile */ && !inAmbientExternalModule) {
error(moduleName, node.kind === 228 /* ExportDeclaration */ ?
ts.Diagnostics.Export_declarations_are_not_permitted_in_a_namespace :
ts.Diagnostics.Import_declarations_in_a_namespace_cannot_reference_a_module);
return false;
}
if (inAmbientExternalModule && ts.isExternalModuleNameRelative(moduleName.text)) {
// TypeScript 1.0 spec (April 2013): 12.1.6
// An ExternalImportDeclaration in an AmbientExternalModuleDeclaration may reference
// other external modules only through top - level external module names.
// Relative external module names are not permitted.
error(node, ts.Diagnostics.Import_or_export_declaration_in_an_ambient_module_declaration_cannot_reference_module_through_relative_module_name);
return false;
}
return true;
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
checkExternalImportOrExportDeclaration
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkAliasSymbol(node) {
var symbol = getSymbolOfNode(node);
var target = resolveAlias(symbol);
if (target !== unknownSymbol) {
var excludedMeanings = (symbol.flags & 107455 /* Value */ ? 107455 /* Value */ : 0) |
(symbol.flags & 793056 /* Type */ ? 793056 /* Type */ : 0) |
(symbol.flags & 1536 /* Namespace */ ? 1536 /* Namespace */ : 0);
if (target.flags & excludedMeanings) {
var message = node.kind === 230 /* ExportSpecifier */ ?
ts.Diagnostics.Export_declaration_conflicts_with_exported_declaration_of_0 :
ts.Diagnostics.Import_declaration_conflicts_with_local_declaration_of_0;
error(node, message, symbolToString(symbol));
}
}
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
checkAliasSymbol
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkImportBinding(node) {
checkCollisionWithCapturedThisVariable(node, node.name);
checkCollisionWithRequireExportsInGeneratedCode(node, node.name);
checkAliasSymbol(node);
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
checkImportBinding
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkImportDeclaration(node) {
if (checkGrammarModuleElementContext(node, ts.Diagnostics.An_import_declaration_can_only_be_used_in_a_namespace_or_module)) {
// If we hit an import declaration in an illegal context, just bail out to avoid cascading errors.
return;
}
if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & 1022 /* Modifier */)) {
grammarErrorOnFirstToken(node, ts.Diagnostics.An_import_declaration_cannot_have_modifiers);
}
if (checkExternalImportOrExportDeclaration(node)) {
var importClause = node.importClause;
if (importClause) {
if (importClause.name) {
checkImportBinding(importClause);
}
if (importClause.namedBindings) {
if (importClause.namedBindings.kind === 224 /* NamespaceImport */) {
checkImportBinding(importClause.namedBindings);
}
else {
ts.forEach(importClause.namedBindings.elements, checkImportBinding);
}
}
}
}
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
checkImportDeclaration
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkImportEqualsDeclaration(node) {
if (checkGrammarModuleElementContext(node, ts.Diagnostics.An_import_declaration_can_only_be_used_in_a_namespace_or_module)) {
// If we hit an import declaration in an illegal context, just bail out to avoid cascading errors.
return;
}
checkGrammarDecorators(node) || checkGrammarModifiers(node);
if (ts.isInternalModuleImportEqualsDeclaration(node) || checkExternalImportOrExportDeclaration(node)) {
checkImportBinding(node);
if (node.flags & 2 /* Export */) {
markExportAsReferenced(node);
}
if (ts.isInternalModuleImportEqualsDeclaration(node)) {
var target = resolveAlias(getSymbolOfNode(node));
if (target !== unknownSymbol) {
if (target.flags & 107455 /* Value */) {
// Target is a value symbol, check that it is not hidden by a local declaration with the same name
var moduleName = getFirstIdentifier(node.moduleReference);
if (!(resolveEntityName(moduleName, 107455 /* Value */ | 1536 /* Namespace */).flags & 1536 /* Namespace */)) {
error(moduleName, ts.Diagnostics.Module_0_is_hidden_by_a_local_declaration_with_the_same_name, ts.declarationNameToString(moduleName));
}
}
if (target.flags & 793056 /* Type */) {
checkTypeNameIsReserved(node.name, ts.Diagnostics.Import_name_cannot_be_0);
}
}
}
else {
if (modulekind === 5 /* ES6 */ && !ts.isInAmbientContext(node)) {
// Import equals declaration is deprecated in es6 or above
grammarErrorOnNode(node, ts.Diagnostics.Import_assignment_cannot_be_used_when_targeting_ECMAScript_6_modules_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_import_d_from_mod_or_another_module_format_instead);
}
}
}
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
checkImportEqualsDeclaration
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkExportDeclaration(node) {
if (checkGrammarModuleElementContext(node, ts.Diagnostics.An_export_declaration_can_only_be_used_in_a_module)) {
// If we hit an export in an illegal context, just bail out to avoid cascading errors.
return;
}
if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & 1022 /* Modifier */)) {
grammarErrorOnFirstToken(node, ts.Diagnostics.An_export_declaration_cannot_have_modifiers);
}
if (!node.moduleSpecifier || checkExternalImportOrExportDeclaration(node)) {
if (node.exportClause) {
// export { x, y }
// export { x, y } from "foo"
ts.forEach(node.exportClause.elements, checkExportSpecifier);
var inAmbientExternalModule = node.parent.kind === 219 /* ModuleBlock */ && node.parent.parent.name.kind === 9 /* StringLiteral */;
if (node.parent.kind !== 248 /* SourceFile */ && !inAmbientExternalModule) {
error(node, ts.Diagnostics.Export_declarations_are_not_permitted_in_a_namespace);
}
}
else {
// export * from "foo"
var moduleSymbol = resolveExternalModuleName(node, node.moduleSpecifier);
if (moduleSymbol && moduleSymbol.exports["export="]) {
error(node.moduleSpecifier, ts.Diagnostics.Module_0_uses_export_and_cannot_be_used_with_export_Asterisk, symbolToString(moduleSymbol));
}
}
}
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
checkExportDeclaration
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkGrammarModuleElementContext(node, errorMessage) {
if (node.parent.kind !== 248 /* SourceFile */ && node.parent.kind !== 219 /* ModuleBlock */ && node.parent.kind !== 218 /* ModuleDeclaration */) {
return grammarErrorOnFirstToken(node, errorMessage);
}
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
checkGrammarModuleElementContext
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkExportSpecifier(node) {
checkAliasSymbol(node);
if (!node.parent.parent.moduleSpecifier) {
markExportAsReferenced(node);
}
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
checkExportSpecifier
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkExportAssignment(node) {
if (checkGrammarModuleElementContext(node, ts.Diagnostics.An_export_assignment_can_only_be_used_in_a_module)) {
// If we hit an export assignment in an illegal context, just bail out to avoid cascading errors.
return;
}
var container = node.parent.kind === 248 /* SourceFile */ ? node.parent : node.parent.parent;
if (container.kind === 218 /* ModuleDeclaration */ && container.name.kind === 69 /* Identifier */) {
error(node, ts.Diagnostics.An_export_assignment_cannot_be_used_in_a_namespace);
return;
}
// Grammar checking
if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && (node.flags & 1022 /* Modifier */)) {
grammarErrorOnFirstToken(node, ts.Diagnostics.An_export_assignment_cannot_have_modifiers);
}
if (node.expression.kind === 69 /* Identifier */) {
markExportAsReferenced(node);
}
else {
checkExpressionCached(node.expression);
}
checkExternalModuleExports(container);
if (node.isExportEquals && !ts.isInAmbientContext(node)) {
if (modulekind === 5 /* ES6 */) {
// export assignment is not supported in es6 modules
grammarErrorOnNode(node, ts.Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_6_modules_Consider_using_export_default_or_another_module_format_instead);
}
else if (modulekind === 4 /* System */) {
// system modules does not support export assignment
grammarErrorOnNode(node, ts.Diagnostics.Export_assignment_is_not_supported_when_module_flag_is_system);
}
}
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
checkExportAssignment
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getModuleStatements(node) {
if (node.kind === 248 /* SourceFile */) {
return node.statements;
}
if (node.kind === 218 /* ModuleDeclaration */ && node.body.kind === 219 /* ModuleBlock */) {
return node.body.statements;
}
return emptyArray;
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
getModuleStatements
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function hasExportedMembers(moduleSymbol) {
for (var id in moduleSymbol.exports) {
if (id !== "export=") {
return true;
}
}
return false;
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
hasExportedMembers
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkExternalModuleExports(node) {
var moduleSymbol = getSymbolOfNode(node);
var links = getSymbolLinks(moduleSymbol);
if (!links.exportsChecked) {
var exportEqualsSymbol = moduleSymbol.exports["export="];
if (exportEqualsSymbol && hasExportedMembers(moduleSymbol)) {
var declaration = getDeclarationOfAliasSymbol(exportEqualsSymbol) || exportEqualsSymbol.valueDeclaration;
error(declaration, ts.Diagnostics.An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements);
}
links.exportsChecked = true;
}
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
checkExternalModuleExports
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkTypePredicate(node) {
if (!isInLegalTypePredicatePosition(node)) {
error(node, ts.Diagnostics.A_type_predicate_is_only_allowed_in_return_type_position_for_functions_and_methods);
}
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
checkTypePredicate
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkSourceElement(node) {
if (!node) {
return;
}
var kind = node.kind;
if (cancellationToken) {
// Only bother checking on a few construct kinds. We don't want to be excessivly
// hitting the cancellation token on every node we check.
switch (kind) {
case 218 /* ModuleDeclaration */:
case 214 /* ClassDeclaration */:
case 215 /* InterfaceDeclaration */:
case 213 /* FunctionDeclaration */:
cancellationToken.throwIfCancellationRequested();
}
}
switch (kind) {
case 137 /* TypeParameter */:
return checkTypeParameter(node);
case 138 /* Parameter */:
return checkParameter(node);
case 141 /* PropertyDeclaration */:
case 140 /* PropertySignature */:
return checkPropertyDeclaration(node);
case 152 /* FunctionType */:
case 153 /* ConstructorType */:
case 147 /* CallSignature */:
case 148 /* ConstructSignature */:
return checkSignatureDeclaration(node);
case 149 /* IndexSignature */:
return checkSignatureDeclaration(node);
case 143 /* MethodDeclaration */:
case 142 /* MethodSignature */:
return checkMethodDeclaration(node);
case 144 /* Constructor */:
return checkConstructorDeclaration(node);
case 145 /* GetAccessor */:
case 146 /* SetAccessor */:
return checkAccessorDeclaration(node);
case 151 /* TypeReference */:
return checkTypeReferenceNode(node);
case 150 /* TypePredicate */:
return checkTypePredicate(node);
case 154 /* TypeQuery */:
return checkTypeQuery(node);
case 155 /* TypeLiteral */:
return checkTypeLiteral(node);
case 156 /* ArrayType */:
return checkArrayType(node);
case 157 /* TupleType */:
return checkTupleType(node);
case 158 /* UnionType */:
case 159 /* IntersectionType */:
return checkUnionOrIntersectionType(node);
case 160 /* ParenthesizedType */:
return checkSourceElement(node.type);
case 213 /* FunctionDeclaration */:
return checkFunctionDeclaration(node);
case 192 /* Block */:
case 219 /* ModuleBlock */:
return checkBlock(node);
case 193 /* VariableStatement */:
return checkVariableStatement(node);
case 195 /* ExpressionStatement */:
return checkExpressionStatement(node);
case 196 /* IfStatement */:
return checkIfStatement(node);
case 197 /* DoStatement */:
return checkDoStatement(node);
case 198 /* WhileStatement */:
return checkWhileStatement(node);
case 199 /* ForStatement */:
return checkForStatement(node);
case 200 /* ForInStatement */:
return checkForInStatement(node);
case 201 /* ForOfStatement */:
return checkForOfStatement(node);
case 202 /* ContinueStatement */:
case 203 /* BreakStatement */:
return checkBreakOrContinueStatement(node);
case 204 /* ReturnStatement */:
return checkReturnStatement(node);
case 205 /* WithStatement */:
return checkWithStatement(node);
case 206 /* SwitchStatement */:
return checkSwitchStatement(node);
case 207 /* LabeledStatement */:
return checkLabeledStatement(node);
case 208 /* ThrowStatement */:
return checkThrowStatement(node);
case 209 /* TryStatement */:
return checkTryStatement(node);
case 211 /* VariableDeclaration */:
return checkVariableDeclaration(node);
case 163 /* BindingElement */:
return checkBindingElement(node);
case 214 /* ClassDeclaration */:
return checkClassDeclaration(node);
case 215 /* InterfaceDeclaration */:
return checkInterfaceDeclaration(node);
case 216 /* TypeAliasDeclaration */:
return checkTypeAliasDeclaration(node);
case 217 /* EnumDeclaration */:
return checkEnumDeclaration(node);
case 218 /* ModuleDeclaration */:
return checkModuleDeclaration(node);
case 222 /* ImportDeclaration */:
return checkImportDeclaration(node);
case 221 /* ImportEqualsDeclaration */:
return checkImportEqualsDeclaration(node);
case 228 /* ExportDeclaration */:
return checkExportDeclaration(node);
case 227 /* ExportAssignment */:
return checkExportAssignment(node);
case 194 /* EmptyStatement */:
checkGrammarStatementInAmbientContext(node);
return;
case 210 /* DebuggerStatement */:
checkGrammarStatementInAmbientContext(node);
return;
case 231 /* MissingDeclaration */:
return checkMissingDeclaration(node);
}
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
checkSourceElement
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkSourceFile(node) {
var start = new Date().getTime();
checkSourceFileWorker(node);
ts.checkTime += new Date().getTime() - start;
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
checkSourceFile
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkSourceFileWorker(node) {
var links = getNodeLinks(node);
if (!(links.flags & 1 /* TypeChecked */)) {
// Check whether the file has declared it is the default lib,
// and whether the user has specifically chosen to avoid checking it.
if (compilerOptions.skipDefaultLibCheck) {
// If the user specified '--noLib' and a file has a '/// <reference no-default-lib="true"/>',
// then we should treat that file as a default lib.
if (node.hasNoDefaultLib) {
return;
}
}
// Grammar checking
checkGrammarSourceFile(node);
emitExtends = false;
emitDecorate = false;
emitParam = false;
potentialThisCollisions.length = 0;
ts.forEach(node.statements, checkSourceElement);
checkFunctionAndClassExpressionBodies(node);
if (ts.isExternalOrCommonJsModule(node)) {
checkExternalModuleExports(node);
}
if (potentialThisCollisions.length) {
ts.forEach(potentialThisCollisions, checkIfThisIsCapturedInEnclosingScope);
potentialThisCollisions.length = 0;
}
if (emitExtends) {
links.flags |= 8 /* EmitExtends */;
}
if (emitDecorate) {
links.flags |= 16 /* EmitDecorate */;
}
if (emitParam) {
links.flags |= 32 /* EmitParam */;
}
if (emitAwaiter) {
links.flags |= 64 /* EmitAwaiter */;
}
if (emitGenerator || (emitAwaiter && languageVersion < 2 /* ES6 */)) {
links.flags |= 128 /* EmitGenerator */;
}
links.flags |= 1 /* TypeChecked */;
}
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
checkSourceFileWorker
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getDiagnostics(sourceFile, ct) {
try {
// Record the cancellation token so it can be checked later on during checkSourceElement.
// Do this in a finally block so we can ensure that it gets reset back to nothing after
// this call is done.
cancellationToken = ct;
return getDiagnosticsWorker(sourceFile);
}
finally {
cancellationToken = undefined;
}
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
getDiagnostics
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getDiagnosticsWorker(sourceFile) {
throwIfNonDiagnosticsProducing();
if (sourceFile) {
checkSourceFile(sourceFile);
return diagnostics.getDiagnostics(sourceFile.fileName);
}
ts.forEach(host.getSourceFiles(), checkSourceFile);
return diagnostics.getDiagnostics();
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
getDiagnosticsWorker
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getGlobalDiagnostics() {
throwIfNonDiagnosticsProducing();
return diagnostics.getGlobalDiagnostics();
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
getGlobalDiagnostics
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function throwIfNonDiagnosticsProducing() {
if (!produceDiagnostics) {
throw new Error("Trying to get diagnostics from a type checker that does not produce them.");
}
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
throwIfNonDiagnosticsProducing
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function isInsideWithStatementBody(node) {
if (node) {
while (node.parent) {
if (node.parent.kind === 205 /* WithStatement */ && node.parent.statement === node) {
return true;
}
node = node.parent;
}
}
return false;
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
isInsideWithStatementBody
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getSymbolsInScope(location, meaning) {
var symbols = {};
var memberFlags = 0;
if (isInsideWithStatementBody(location)) {
// We cannot answer semantic questions within a with block, do not proceed any further
return [];
}
populateSymbols();
return symbolsToArray(symbols);
function populateSymbols() {
while (location) {
if (location.locals && !isGlobalSourceFile(location)) {
copySymbols(location.locals, meaning);
}
switch (location.kind) {
case 248 /* SourceFile */:
if (!ts.isExternalOrCommonJsModule(location)) {
break;
}
case 218 /* ModuleDeclaration */:
copySymbols(getSymbolOfNode(location).exports, meaning & 8914931 /* ModuleMember */);
break;
case 217 /* EnumDeclaration */:
copySymbols(getSymbolOfNode(location).exports, meaning & 8 /* EnumMember */);
break;
case 186 /* ClassExpression */:
var className = location.name;
if (className) {
copySymbol(location.symbol, meaning);
}
// fall through; this fall-through is necessary because we would like to handle
// type parameter inside class expression similar to how we handle it in classDeclaration and interface Declaration
case 214 /* ClassDeclaration */:
case 215 /* InterfaceDeclaration */:
// If we didn't come from static member of class or interface,
// add the type parameters into the symbol table
// (type parameters of classDeclaration/classExpression and interface are in member property of the symbol.
// Note: that the memberFlags come from previous iteration.
if (!(memberFlags & 64 /* Static */)) {
copySymbols(getSymbolOfNode(location).members, meaning & 793056 /* Type */);
}
break;
case 173 /* FunctionExpression */:
var funcName = location.name;
if (funcName) {
copySymbol(location.symbol, meaning);
}
break;
}
if (ts.introducesArgumentsExoticObject(location)) {
copySymbol(argumentsSymbol, meaning);
}
memberFlags = location.flags;
location = location.parent;
}
copySymbols(globals, meaning);
}
/**
* Copy the given symbol into symbol tables if the symbol has the given meaning
* and it doesn't already existed in the symbol table
* @param key a key for storing in symbol table; if undefined, use symbol.name
* @param symbol the symbol to be added into symbol table
* @param meaning meaning of symbol to filter by before adding to symbol table
*/
function copySymbol(symbol, meaning) {
if (symbol.flags & meaning) {
var id = symbol.name;
// We will copy all symbol regardless of its reserved name because
// symbolsToArray will check whether the key is a reserved name and
// it will not copy symbol with reserved name to the array
if (!ts.hasProperty(symbols, id)) {
symbols[id] = symbol;
}
}
}
function copySymbols(source, meaning) {
if (meaning) {
for (var id in source) {
var symbol = source[id];
copySymbol(symbol, meaning);
}
}
}
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
getSymbolsInScope
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function populateSymbols() {
while (location) {
if (location.locals && !isGlobalSourceFile(location)) {
copySymbols(location.locals, meaning);
}
switch (location.kind) {
case 248 /* SourceFile */:
if (!ts.isExternalOrCommonJsModule(location)) {
break;
}
case 218 /* ModuleDeclaration */:
copySymbols(getSymbolOfNode(location).exports, meaning & 8914931 /* ModuleMember */);
break;
case 217 /* EnumDeclaration */:
copySymbols(getSymbolOfNode(location).exports, meaning & 8 /* EnumMember */);
break;
case 186 /* ClassExpression */:
var className = location.name;
if (className) {
copySymbol(location.symbol, meaning);
}
// fall through; this fall-through is necessary because we would like to handle
// type parameter inside class expression similar to how we handle it in classDeclaration and interface Declaration
case 214 /* ClassDeclaration */:
case 215 /* InterfaceDeclaration */:
// If we didn't come from static member of class or interface,
// add the type parameters into the symbol table
// (type parameters of classDeclaration/classExpression and interface are in member property of the symbol.
// Note: that the memberFlags come from previous iteration.
if (!(memberFlags & 64 /* Static */)) {
copySymbols(getSymbolOfNode(location).members, meaning & 793056 /* Type */);
}
break;
case 173 /* FunctionExpression */:
var funcName = location.name;
if (funcName) {
copySymbol(location.symbol, meaning);
}
break;
}
if (ts.introducesArgumentsExoticObject(location)) {
copySymbol(argumentsSymbol, meaning);
}
memberFlags = location.flags;
location = location.parent;
}
copySymbols(globals, meaning);
}
|
This function does the following steps:
1. Break up arrayOrStringType (possibly a union) into its string constituents and array constituents.
2. Take the element types of the array constituents.
3. Return the union of the element types, and string if there was a string constitutent.
For example:
string -> string
number[] -> number
string[] | number[] -> string | number
string | number[] -> string | number
string | string[] | number[] -> string | number
It also errors if:
1. Some constituent is neither a string nor an array.
2. Some constituent is a string and target is less than ES5 (because in ES3 string is not indexable).
|
populateSymbols
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function copySymbols(source, meaning) {
if (meaning) {
for (var id in source) {
var symbol = source[id];
copySymbol(symbol, meaning);
}
}
}
|
Copy the given symbol into symbol tables if the symbol has the given meaning
and it doesn't already existed in the symbol table
@param key a key for storing in symbol table; if undefined, use symbol.name
@param symbol the symbol to be added into symbol table
@param meaning meaning of symbol to filter by before adding to symbol table
|
copySymbols
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function isTypeDeclarationName(name) {
return name.kind === 69 /* Identifier */ &&
isTypeDeclaration(name.parent) &&
name.parent.name === name;
}
|
Copy the given symbol into symbol tables if the symbol has the given meaning
and it doesn't already existed in the symbol table
@param key a key for storing in symbol table; if undefined, use symbol.name
@param symbol the symbol to be added into symbol table
@param meaning meaning of symbol to filter by before adding to symbol table
|
isTypeDeclarationName
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function isTypeDeclaration(node) {
switch (node.kind) {
case 137 /* TypeParameter */:
case 214 /* ClassDeclaration */:
case 215 /* InterfaceDeclaration */:
case 216 /* TypeAliasDeclaration */:
case 217 /* EnumDeclaration */:
return true;
}
}
|
Copy the given symbol into symbol tables if the symbol has the given meaning
and it doesn't already existed in the symbol table
@param key a key for storing in symbol table; if undefined, use symbol.name
@param symbol the symbol to be added into symbol table
@param meaning meaning of symbol to filter by before adding to symbol table
|
isTypeDeclaration
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function isTypeReferenceIdentifier(entityName) {
var node = entityName;
while (node.parent && node.parent.kind === 135 /* QualifiedName */) {
node = node.parent;
}
return node.parent && node.parent.kind === 151 /* TypeReference */;
}
|
Copy the given symbol into symbol tables if the symbol has the given meaning
and it doesn't already existed in the symbol table
@param key a key for storing in symbol table; if undefined, use symbol.name
@param symbol the symbol to be added into symbol table
@param meaning meaning of symbol to filter by before adding to symbol table
|
isTypeReferenceIdentifier
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function isHeritageClauseElementIdentifier(entityName) {
var node = entityName;
while (node.parent && node.parent.kind === 166 /* PropertyAccessExpression */) {
node = node.parent;
}
return node.parent && node.parent.kind === 188 /* ExpressionWithTypeArguments */;
}
|
Copy the given symbol into symbol tables if the symbol has the given meaning
and it doesn't already existed in the symbol table
@param key a key for storing in symbol table; if undefined, use symbol.name
@param symbol the symbol to be added into symbol table
@param meaning meaning of symbol to filter by before adding to symbol table
|
isHeritageClauseElementIdentifier
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getLeftSideOfImportEqualsOrExportAssignment(nodeOnRightSide) {
while (nodeOnRightSide.parent.kind === 135 /* QualifiedName */) {
nodeOnRightSide = nodeOnRightSide.parent;
}
if (nodeOnRightSide.parent.kind === 221 /* ImportEqualsDeclaration */) {
return nodeOnRightSide.parent.moduleReference === nodeOnRightSide && nodeOnRightSide.parent;
}
if (nodeOnRightSide.parent.kind === 227 /* ExportAssignment */) {
return nodeOnRightSide.parent.expression === nodeOnRightSide && nodeOnRightSide.parent;
}
return undefined;
}
|
Copy the given symbol into symbol tables if the symbol has the given meaning
and it doesn't already existed in the symbol table
@param key a key for storing in symbol table; if undefined, use symbol.name
@param symbol the symbol to be added into symbol table
@param meaning meaning of symbol to filter by before adding to symbol table
|
getLeftSideOfImportEqualsOrExportAssignment
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function isInRightSideOfImportOrExportAssignment(node) {
return getLeftSideOfImportEqualsOrExportAssignment(node) !== undefined;
}
|
Copy the given symbol into symbol tables if the symbol has the given meaning
and it doesn't already existed in the symbol table
@param key a key for storing in symbol table; if undefined, use symbol.name
@param symbol the symbol to be added into symbol table
@param meaning meaning of symbol to filter by before adding to symbol table
|
isInRightSideOfImportOrExportAssignment
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getSymbolOfEntityNameOrPropertyAccessExpression(entityName) {
if (ts.isDeclarationName(entityName)) {
return getSymbolOfNode(entityName.parent);
}
if (entityName.parent.kind === 227 /* ExportAssignment */) {
return resolveEntityName(entityName,
/*all meanings*/ 107455 /* Value */ | 793056 /* Type */ | 1536 /* Namespace */ | 8388608 /* Alias */);
}
if (entityName.kind !== 166 /* PropertyAccessExpression */) {
if (isInRightSideOfImportOrExportAssignment(entityName)) {
// Since we already checked for ExportAssignment, this really could only be an Import
return getSymbolOfPartOfRightHandSideOfImportEquals(entityName);
}
}
if (ts.isRightSideOfQualifiedNameOrPropertyAccess(entityName)) {
entityName = entityName.parent;
}
if (isHeritageClauseElementIdentifier(entityName)) {
var meaning = 0 /* None */;
// In an interface or class, we're definitely interested in a type.
if (entityName.parent.kind === 188 /* ExpressionWithTypeArguments */) {
meaning = 793056 /* Type */;
// In a class 'extends' clause we are also looking for a value.
if (ts.isExpressionWithTypeArgumentsInClassExtendsClause(entityName.parent)) {
meaning |= 107455 /* Value */;
}
}
else {
meaning = 1536 /* Namespace */;
}
meaning |= 8388608 /* Alias */;
return resolveEntityName(entityName, meaning);
}
else if ((entityName.parent.kind === 235 /* JsxOpeningElement */) ||
(entityName.parent.kind === 234 /* JsxSelfClosingElement */) ||
(entityName.parent.kind === 237 /* JsxClosingElement */)) {
return getJsxElementTagSymbol(entityName.parent);
}
else if (ts.isExpression(entityName)) {
if (ts.nodeIsMissing(entityName)) {
// Missing entity name.
return undefined;
}
if (entityName.kind === 69 /* Identifier */) {
// Include aliases in the meaning, this ensures that we do not follow aliases to where they point and instead
// return the alias symbol.
var meaning = 107455 /* Value */ | 8388608 /* Alias */;
return resolveEntityName(entityName, meaning);
}
else if (entityName.kind === 166 /* PropertyAccessExpression */) {
var symbol = getNodeLinks(entityName).resolvedSymbol;
if (!symbol) {
checkPropertyAccessExpression(entityName);
}
return getNodeLinks(entityName).resolvedSymbol;
}
else if (entityName.kind === 135 /* QualifiedName */) {
var symbol = getNodeLinks(entityName).resolvedSymbol;
if (!symbol) {
checkQualifiedName(entityName);
}
return getNodeLinks(entityName).resolvedSymbol;
}
}
else if (isTypeReferenceIdentifier(entityName)) {
var meaning = entityName.parent.kind === 151 /* TypeReference */ ? 793056 /* Type */ : 1536 /* Namespace */;
// Include aliases in the meaning, this ensures that we do not follow aliases to where they point and instead
// return the alias symbol.
meaning |= 8388608 /* Alias */;
return resolveEntityName(entityName, meaning);
}
else if (entityName.parent.kind === 238 /* JsxAttribute */) {
return getJsxAttributePropertySymbol(entityName.parent);
}
if (entityName.parent.kind === 150 /* TypePredicate */) {
return resolveEntityName(entityName, /*meaning*/ 1 /* FunctionScopedVariable */);
}
// Do we want to return undefined here?
return undefined;
}
|
Copy the given symbol into symbol tables if the symbol has the given meaning
and it doesn't already existed in the symbol table
@param key a key for storing in symbol table; if undefined, use symbol.name
@param symbol the symbol to be added into symbol table
@param meaning meaning of symbol to filter by before adding to symbol table
|
getSymbolOfEntityNameOrPropertyAccessExpression
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getSymbolAtLocation(node) {
if (isInsideWithStatementBody(node)) {
// We cannot answer semantic questions within a with block, do not proceed any further
return undefined;
}
if (ts.isDeclarationName(node)) {
// This is a declaration, call getSymbolOfNode
return getSymbolOfNode(node.parent);
}
if (node.kind === 69 /* Identifier */) {
if (isInRightSideOfImportOrExportAssignment(node)) {
return node.parent.kind === 227 /* ExportAssignment */
? getSymbolOfEntityNameOrPropertyAccessExpression(node)
: getSymbolOfPartOfRightHandSideOfImportEquals(node);
}
else if (node.parent.kind === 163 /* BindingElement */ &&
node.parent.parent.kind === 161 /* ObjectBindingPattern */ &&
node === node.parent.propertyName) {
var typeOfPattern = getTypeOfNode(node.parent.parent);
var propertyDeclaration = typeOfPattern && getPropertyOfType(typeOfPattern, node.text);
if (propertyDeclaration) {
return propertyDeclaration;
}
}
}
switch (node.kind) {
case 69 /* Identifier */:
case 166 /* PropertyAccessExpression */:
case 135 /* QualifiedName */:
return getSymbolOfEntityNameOrPropertyAccessExpression(node);
case 97 /* ThisKeyword */:
case 95 /* SuperKeyword */:
var type = ts.isExpression(node) ? checkExpression(node) : getTypeFromTypeNode(node);
return type.symbol;
case 121 /* ConstructorKeyword */:
// constructor keyword for an overload, should take us to the definition if it exist
var constructorDeclaration = node.parent;
if (constructorDeclaration && constructorDeclaration.kind === 144 /* Constructor */) {
return constructorDeclaration.parent.symbol;
}
return undefined;
case 9 /* StringLiteral */:
// External module name in an import declaration
if ((ts.isExternalModuleImportEqualsDeclaration(node.parent.parent) &&
ts.getExternalModuleImportEqualsDeclarationExpression(node.parent.parent) === node) ||
((node.parent.kind === 222 /* ImportDeclaration */ || node.parent.kind === 228 /* ExportDeclaration */) &&
node.parent.moduleSpecifier === node)) {
return resolveExternalModuleName(node, node);
}
// Fall through
case 8 /* NumericLiteral */:
// index access
if (node.parent.kind === 167 /* ElementAccessExpression */ && node.parent.argumentExpression === node) {
var objectType = checkExpression(node.parent.expression);
if (objectType === unknownType)
return undefined;
var apparentType = getApparentType(objectType);
if (apparentType === unknownType)
return undefined;
return getPropertyOfType(apparentType, node.text);
}
break;
}
return undefined;
}
|
Copy the given symbol into symbol tables if the symbol has the given meaning
and it doesn't already existed in the symbol table
@param key a key for storing in symbol table; if undefined, use symbol.name
@param symbol the symbol to be added into symbol table
@param meaning meaning of symbol to filter by before adding to symbol table
|
getSymbolAtLocation
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getShorthandAssignmentValueSymbol(location) {
// The function returns a value symbol of an identifier in the short-hand property assignment.
// This is necessary as an identifier in short-hand property assignment can contains two meaning:
// property name and property value.
if (location && location.kind === 246 /* ShorthandPropertyAssignment */) {
return resolveEntityName(location.name, 107455 /* Value */);
}
return undefined;
}
|
Copy the given symbol into symbol tables if the symbol has the given meaning
and it doesn't already existed in the symbol table
@param key a key for storing in symbol table; if undefined, use symbol.name
@param symbol the symbol to be added into symbol table
@param meaning meaning of symbol to filter by before adding to symbol table
|
getShorthandAssignmentValueSymbol
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getTypeOfNode(node) {
if (isInsideWithStatementBody(node)) {
// We cannot answer semantic questions within a with block, do not proceed any further
return unknownType;
}
if (ts.isTypeNode(node)) {
return getTypeFromTypeNode(node);
}
if (ts.isExpression(node)) {
return getTypeOfExpression(node);
}
if (ts.isExpressionWithTypeArgumentsInClassExtendsClause(node)) {
// A SyntaxKind.ExpressionWithTypeArguments is considered a type node, except when it occurs in the
// extends clause of a class. We handle that case here.
return getBaseTypes(getDeclaredTypeOfSymbol(getSymbolOfNode(node.parent.parent)))[0];
}
if (isTypeDeclaration(node)) {
// In this case, we call getSymbolOfNode instead of getSymbolAtLocation because it is a declaration
var symbol = getSymbolOfNode(node);
return getDeclaredTypeOfSymbol(symbol);
}
if (isTypeDeclarationName(node)) {
var symbol = getSymbolAtLocation(node);
return symbol && getDeclaredTypeOfSymbol(symbol);
}
if (ts.isDeclaration(node)) {
// In this case, we call getSymbolOfNode instead of getSymbolAtLocation because it is a declaration
var symbol = getSymbolOfNode(node);
return getTypeOfSymbol(symbol);
}
if (ts.isDeclarationName(node)) {
var symbol = getSymbolAtLocation(node);
return symbol && getTypeOfSymbol(symbol);
}
if (ts.isBindingPattern(node)) {
return getTypeForVariableLikeDeclaration(node.parent);
}
if (isInRightSideOfImportOrExportAssignment(node)) {
var symbol = getSymbolAtLocation(node);
var declaredType = symbol && getDeclaredTypeOfSymbol(symbol);
return declaredType !== unknownType ? declaredType : getTypeOfSymbol(symbol);
}
return unknownType;
}
|
Copy the given symbol into symbol tables if the symbol has the given meaning
and it doesn't already existed in the symbol table
@param key a key for storing in symbol table; if undefined, use symbol.name
@param symbol the symbol to be added into symbol table
@param meaning meaning of symbol to filter by before adding to symbol table
|
getTypeOfNode
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getTypeOfExpression(expr) {
if (ts.isRightSideOfQualifiedNameOrPropertyAccess(expr)) {
expr = expr.parent;
}
return checkExpression(expr);
}
|
Copy the given symbol into symbol tables if the symbol has the given meaning
and it doesn't already existed in the symbol table
@param key a key for storing in symbol table; if undefined, use symbol.name
@param symbol the symbol to be added into symbol table
@param meaning meaning of symbol to filter by before adding to symbol table
|
getTypeOfExpression
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getParentTypeOfClassElement(node) {
var classSymbol = getSymbolOfNode(node.parent);
return node.flags & 64 /* Static */
? getTypeOfSymbol(classSymbol)
: getDeclaredTypeOfSymbol(classSymbol);
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
getParentTypeOfClassElement
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getRootSymbols(symbol) {
if (symbol.flags & 268435456 /* SyntheticProperty */) {
var symbols = [];
var name_15 = symbol.name;
ts.forEach(getSymbolLinks(symbol).containingType.types, function (t) {
var symbol = getPropertyOfType(t, name_15);
if (symbol) {
symbols.push(symbol);
}
});
return symbols;
}
else if (symbol.flags & 67108864 /* Transient */) {
var target = getSymbolLinks(symbol).target;
if (target) {
return [target];
}
}
return [symbol];
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
getRootSymbols
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function isArgumentsLocalBinding(node) {
return getReferencedValueSymbol(node) === argumentsSymbol;
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
isArgumentsLocalBinding
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function isStatementWithLocals(node) {
switch (node.kind) {
case 192 /* Block */:
case 220 /* CaseBlock */:
case 199 /* ForStatement */:
case 200 /* ForInStatement */:
case 201 /* ForOfStatement */:
return true;
}
return false;
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
isStatementWithLocals
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function isNestedRedeclarationSymbol(symbol) {
if (symbol.flags & 418 /* BlockScoped */) {
var links = getSymbolLinks(symbol);
if (links.isNestedRedeclaration === undefined) {
var container = ts.getEnclosingBlockScopeContainer(symbol.valueDeclaration);
links.isNestedRedeclaration = isStatementWithLocals(container) &&
!!resolveName(container.parent, symbol.name, 107455 /* Value */, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined);
}
return links.isNestedRedeclaration;
}
return false;
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
isNestedRedeclarationSymbol
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function isNestedRedeclaration(node) {
return isNestedRedeclarationSymbol(getSymbolOfNode(node));
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
isNestedRedeclaration
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function isValueAliasDeclaration(node) {
switch (node.kind) {
case 221 /* ImportEqualsDeclaration */:
case 223 /* ImportClause */:
case 224 /* NamespaceImport */:
case 226 /* ImportSpecifier */:
case 230 /* ExportSpecifier */:
return isAliasResolvedToValue(getSymbolOfNode(node));
case 228 /* ExportDeclaration */:
var exportClause = node.exportClause;
return exportClause && ts.forEach(exportClause.elements, isValueAliasDeclaration);
case 227 /* ExportAssignment */:
return node.expression && node.expression.kind === 69 /* Identifier */ ? isAliasResolvedToValue(getSymbolOfNode(node)) : true;
}
return false;
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
isValueAliasDeclaration
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function isTopLevelValueImportEqualsWithEntityName(node) {
if (node.parent.kind !== 248 /* SourceFile */ || !ts.isInternalModuleImportEqualsDeclaration(node)) {
// parent is not source file or it is not reference to internal module
return false;
}
var isValue = isAliasResolvedToValue(getSymbolOfNode(node));
return isValue && node.moduleReference && !ts.nodeIsMissing(node.moduleReference);
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
isTopLevelValueImportEqualsWithEntityName
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function isAliasResolvedToValue(symbol) {
var target = resolveAlias(symbol);
if (target === unknownSymbol && compilerOptions.isolatedModules) {
return true;
}
// const enums and modules that contain only const enums are not considered values from the emit perespective
// unless 'preserveConstEnums' option is set to true
return target !== unknownSymbol &&
target &&
target.flags & 107455 /* Value */ &&
(compilerOptions.preserveConstEnums || !isConstEnumOrConstEnumOnlyModule(target));
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
isAliasResolvedToValue
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function isConstEnumOrConstEnumOnlyModule(s) {
return isConstEnumSymbol(s) || s.constEnumOnlyModule;
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
isConstEnumOrConstEnumOnlyModule
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function isReferencedAliasDeclaration(node, checkChildren) {
if (ts.isAliasSymbolDeclaration(node)) {
var symbol = getSymbolOfNode(node);
if (getSymbolLinks(symbol).referenced) {
return true;
}
}
if (checkChildren) {
return ts.forEachChild(node, function (node) { return isReferencedAliasDeclaration(node, checkChildren); });
}
return false;
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
isReferencedAliasDeclaration
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function isImplementationOfOverload(node) {
if (ts.nodeIsPresent(node.body)) {
var symbol = getSymbolOfNode(node);
var signaturesOfSymbol = getSignaturesOfSymbol(symbol);
// If this function body corresponds to function with multiple signature, it is implementation of overload
// e.g.: function foo(a: string): string;
// function foo(a: number): number;
// function foo(a: any) { // This is implementation of the overloads
// return a;
// }
return signaturesOfSymbol.length > 1 ||
// If there is single signature for the symbol, it is overload if that signature isn't coming from the node
// e.g.: function foo(a: string): string;
// function foo(a: any) { // This is implementation of the overloads
// return a;
// }
(signaturesOfSymbol.length === 1 && signaturesOfSymbol[0].declaration !== node);
}
return false;
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
isImplementationOfOverload
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getNodeCheckFlags(node) {
return getNodeLinks(node).flags;
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
getNodeCheckFlags
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getEnumMemberValue(node) {
computeEnumMemberValues(node.parent);
return getNodeLinks(node).enumMemberValue;
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
getEnumMemberValue
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getConstantValue(node) {
if (node.kind === 247 /* EnumMember */) {
return getEnumMemberValue(node);
}
var symbol = getNodeLinks(node).resolvedSymbol;
if (symbol && (symbol.flags & 8 /* EnumMember */)) {
// inline property\index accesses only for const enums
if (ts.isConstEnumDeclaration(symbol.valueDeclaration.parent)) {
return getEnumMemberValue(symbol.valueDeclaration);
}
}
return undefined;
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
getConstantValue
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function isFunctionType(type) {
return type.flags & 80896 /* ObjectType */ && getSignaturesOfType(type, 0 /* Call */).length > 0;
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
isFunctionType
|
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.