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 getTypeReferenceSerializationKind(typeName) {
// Resolve the symbol as a value to ensure the type can be reached at runtime during emit.
var valueSymbol = resolveEntityName(typeName, 107455 /* Value */, /*ignoreErrors*/ true);
var constructorType = valueSymbol ? getTypeOfSymbol(valueSymbol) : undefined;
if (constructorType && isConstructorType(constructorType)) {
return ts.TypeReferenceSerializationKind.TypeWithConstructSignatureAndValue;
}
// Resolve the symbol as a type so that we can provide a more useful hint for the type serializer.
var typeSymbol = resolveEntityName(typeName, 793056 /* Type */, /*ignoreErrors*/ true);
// We might not be able to resolve type symbol so use unknown type in that case (eg error case)
if (!typeSymbol) {
return ts.TypeReferenceSerializationKind.ObjectType;
}
var type = getDeclaredTypeOfSymbol(typeSymbol);
if (type === unknownType) {
return ts.TypeReferenceSerializationKind.Unknown;
}
else if (type.flags & 1 /* Any */) {
return ts.TypeReferenceSerializationKind.ObjectType;
}
else if (allConstituentTypesHaveKind(type, 16 /* Void */)) {
return ts.TypeReferenceSerializationKind.VoidType;
}
else if (allConstituentTypesHaveKind(type, 8 /* Boolean */)) {
return ts.TypeReferenceSerializationKind.BooleanType;
}
else if (allConstituentTypesHaveKind(type, 132 /* NumberLike */)) {
return ts.TypeReferenceSerializationKind.NumberLikeType;
}
else if (allConstituentTypesHaveKind(type, 258 /* StringLike */)) {
return ts.TypeReferenceSerializationKind.StringLikeType;
}
else if (allConstituentTypesHaveKind(type, 8192 /* Tuple */)) {
return ts.TypeReferenceSerializationKind.ArrayLikeType;
}
else if (allConstituentTypesHaveKind(type, 16777216 /* ESSymbol */)) {
return ts.TypeReferenceSerializationKind.ESSymbolType;
}
else if (isFunctionType(type)) {
return ts.TypeReferenceSerializationKind.TypeWithCallSignature;
}
else if (isArrayType(type)) {
return ts.TypeReferenceSerializationKind.ArrayLikeType;
}
else {
return ts.TypeReferenceSerializationKind.ObjectType;
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
getTypeReferenceSerializationKind
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function writeTypeOfDeclaration(declaration, enclosingDeclaration, flags, writer) {
// Get type of the symbol if this is the valid symbol otherwise get type at location
var symbol = getSymbolOfNode(declaration);
var type = symbol && !(symbol.flags & (2048 /* TypeLiteral */ | 131072 /* Signature */))
? getTypeOfSymbol(symbol)
: unknownType;
getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags);
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
writeTypeOfDeclaration
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function writeReturnTypeOfSignatureDeclaration(signatureDeclaration, enclosingDeclaration, flags, writer) {
var signature = getSignatureFromDeclaration(signatureDeclaration);
getSymbolDisplayBuilder().buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags);
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
writeReturnTypeOfSignatureDeclaration
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function writeTypeOfExpression(expr, enclosingDeclaration, flags, writer) {
var type = getTypeOfExpression(expr);
getSymbolDisplayBuilder().buildTypeDisplay(type, writer, enclosingDeclaration, flags);
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
writeTypeOfExpression
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function hasGlobalName(name) {
return ts.hasProperty(globals, name);
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
hasGlobalName
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getReferencedValueSymbol(reference) {
return getNodeLinks(reference).resolvedSymbol ||
resolveName(reference, reference.text, 107455 /* Value */ | 1048576 /* ExportValue */ | 8388608 /* Alias */,
/*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined);
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
getReferencedValueSymbol
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getReferencedValueDeclaration(reference) {
ts.Debug.assert(!ts.nodeIsSynthesized(reference));
var symbol = getReferencedValueSymbol(reference);
return symbol && getExportSymbolOfValueSymbolIfExported(symbol).valueDeclaration;
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
getReferencedValueDeclaration
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function instantiateSingleCallFunctionType(functionType, typeArguments) {
if (functionType === unknownType) {
return unknownType;
}
var signature = getSingleCallSignature(functionType);
if (!signature) {
return unknownType;
}
var instantiatedSignature = getSignatureInstantiation(signature, typeArguments);
return getOrCreateTypeFromSignature(instantiatedSignature);
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
instantiateSingleCallFunctionType
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function createResolver() {
return {
getReferencedExportContainer: getReferencedExportContainer,
getReferencedImportDeclaration: getReferencedImportDeclaration,
getReferencedNestedRedeclaration: getReferencedNestedRedeclaration,
isNestedRedeclaration: isNestedRedeclaration,
isValueAliasDeclaration: isValueAliasDeclaration,
hasGlobalName: hasGlobalName,
isReferencedAliasDeclaration: isReferencedAliasDeclaration,
getNodeCheckFlags: getNodeCheckFlags,
isTopLevelValueImportEqualsWithEntityName: isTopLevelValueImportEqualsWithEntityName,
isDeclarationVisible: isDeclarationVisible,
isImplementationOfOverload: isImplementationOfOverload,
writeTypeOfDeclaration: writeTypeOfDeclaration,
writeReturnTypeOfSignatureDeclaration: writeReturnTypeOfSignatureDeclaration,
writeTypeOfExpression: writeTypeOfExpression,
isSymbolAccessible: isSymbolAccessible,
isEntityNameVisible: isEntityNameVisible,
getConstantValue: getConstantValue,
collectLinkedAliases: collectLinkedAliases,
getReferencedValueDeclaration: getReferencedValueDeclaration,
getTypeReferenceSerializationKind: getTypeReferenceSerializationKind,
isOptionalParameter: isOptionalParameter,
isArgumentsLocalBinding: isArgumentsLocalBinding,
getExternalModuleFileFromDeclaration: getExternalModuleFileFromDeclaration
};
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
createResolver
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getExternalModuleFileFromDeclaration(declaration) {
var specifier = ts.getExternalModuleName(declaration);
var moduleSymbol = getSymbolAtLocation(specifier);
if (!moduleSymbol) {
return undefined;
}
return ts.getDeclarationOfKind(moduleSymbol, 248 /* SourceFile */);
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
getExternalModuleFileFromDeclaration
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function initializeTypeChecker() {
// Bind all source files and propagate errors
ts.forEach(host.getSourceFiles(), function (file) {
ts.bindSourceFile(file, compilerOptions);
});
// Initialize global symbol table
ts.forEach(host.getSourceFiles(), function (file) {
if (!ts.isExternalOrCommonJsModule(file)) {
mergeSymbolTable(globals, file.locals);
}
});
getSymbolLinks(undefinedSymbol).type = undefinedType;
getSymbolLinks(argumentsSymbol).type = getGlobalType("IArguments");
getSymbolLinks(unknownSymbol).type = unknownType;
globals[undefinedSymbol.name] = undefinedSymbol;
// Initialize special types
globalArrayType = getGlobalType("Array", /*arity*/ 1);
globalObjectType = getGlobalType("Object");
globalFunctionType = getGlobalType("Function");
globalStringType = getGlobalType("String");
globalNumberType = getGlobalType("Number");
globalBooleanType = getGlobalType("Boolean");
globalRegExpType = getGlobalType("RegExp");
jsxElementType = getExportedTypeFromNamespace("JSX", JsxNames.Element);
getGlobalClassDecoratorType = ts.memoize(function () { return getGlobalType("ClassDecorator"); });
getGlobalPropertyDecoratorType = ts.memoize(function () { return getGlobalType("PropertyDecorator"); });
getGlobalMethodDecoratorType = ts.memoize(function () { return getGlobalType("MethodDecorator"); });
getGlobalParameterDecoratorType = ts.memoize(function () { return getGlobalType("ParameterDecorator"); });
getGlobalTypedPropertyDescriptorType = ts.memoize(function () { return getGlobalType("TypedPropertyDescriptor", /*arity*/ 1); });
getGlobalPromiseType = ts.memoize(function () { return getGlobalType("Promise", /*arity*/ 1); });
tryGetGlobalPromiseType = ts.memoize(function () { return getGlobalSymbol("Promise", 793056 /* Type */, /*diagnostic*/ undefined) && getGlobalPromiseType(); });
getGlobalPromiseLikeType = ts.memoize(function () { return getGlobalType("PromiseLike", /*arity*/ 1); });
getInstantiatedGlobalPromiseLikeType = ts.memoize(createInstantiatedPromiseLikeType);
getGlobalPromiseConstructorSymbol = ts.memoize(function () { return getGlobalValueSymbol("Promise"); });
getGlobalPromiseConstructorLikeType = ts.memoize(function () { return getGlobalType("PromiseConstructorLike"); });
getGlobalThenableType = ts.memoize(createThenableType);
// If we're in ES6 mode, load the TemplateStringsArray.
// Otherwise, default to 'unknown' for the purposes of type checking in LS scenarios.
if (languageVersion >= 2 /* ES6 */) {
globalTemplateStringsArrayType = getGlobalType("TemplateStringsArray");
globalESSymbolType = getGlobalType("Symbol");
globalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol");
globalIterableType = getGlobalType("Iterable", /*arity*/ 1);
globalIteratorType = getGlobalType("Iterator", /*arity*/ 1);
globalIterableIteratorType = getGlobalType("IterableIterator", /*arity*/ 1);
}
else {
globalTemplateStringsArrayType = unknownType;
// Consider putting Symbol interface in lib.d.ts. On the plus side, putting it in lib.d.ts would make it
// extensible for Polyfilling Symbols. But putting it into lib.d.ts could also break users that have
// a global Symbol already, particularly if it is a class.
globalESSymbolType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
globalESSymbolConstructorSymbol = undefined;
globalIterableType = emptyGenericType;
globalIteratorType = emptyGenericType;
globalIterableIteratorType = emptyGenericType;
}
anyArrayType = createArrayType(anyType);
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
initializeTypeChecker
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function createInstantiatedPromiseLikeType() {
var promiseLikeType = getGlobalPromiseLikeType();
if (promiseLikeType !== emptyGenericType) {
return createTypeReference(promiseLikeType, [anyType]);
}
return emptyObjectType;
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
createInstantiatedPromiseLikeType
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function createThenableType() {
// build the thenable type that is used to verify against a non-promise "thenable" operand to `await`.
var thenPropertySymbol = createSymbol(67108864 /* Transient */ | 4 /* Property */, "then");
getSymbolLinks(thenPropertySymbol).type = globalFunctionType;
var thenableType = createObjectType(65536 /* Anonymous */);
thenableType.properties = [thenPropertySymbol];
thenableType.members = createSymbolTable(thenableType.properties);
thenableType.callSignatures = [];
thenableType.constructSignatures = [];
return thenableType;
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
createThenableType
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkGrammarModifiers(node) {
switch (node.kind) {
case 145 /* GetAccessor */:
case 146 /* SetAccessor */:
case 144 /* Constructor */:
case 141 /* PropertyDeclaration */:
case 140 /* PropertySignature */:
case 143 /* MethodDeclaration */:
case 142 /* MethodSignature */:
case 149 /* IndexSignature */:
case 218 /* ModuleDeclaration */:
case 222 /* ImportDeclaration */:
case 221 /* ImportEqualsDeclaration */:
case 228 /* ExportDeclaration */:
case 227 /* ExportAssignment */:
case 138 /* Parameter */:
break;
case 213 /* FunctionDeclaration */:
if (node.modifiers && (node.modifiers.length > 1 || node.modifiers[0].kind !== 118 /* AsyncKeyword */) &&
node.parent.kind !== 219 /* ModuleBlock */ && node.parent.kind !== 248 /* SourceFile */) {
return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here);
}
break;
case 214 /* ClassDeclaration */:
case 215 /* InterfaceDeclaration */:
case 193 /* VariableStatement */:
case 216 /* TypeAliasDeclaration */:
if (node.modifiers && node.parent.kind !== 219 /* ModuleBlock */ && node.parent.kind !== 248 /* SourceFile */) {
return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here);
}
break;
case 217 /* EnumDeclaration */:
if (node.modifiers && (node.modifiers.length > 1 || node.modifiers[0].kind !== 74 /* ConstKeyword */) &&
node.parent.kind !== 219 /* ModuleBlock */ && node.parent.kind !== 248 /* SourceFile */) {
return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here);
}
break;
default:
return false;
}
if (!node.modifiers) {
return;
}
var lastStatic, lastPrivate, lastProtected, lastDeclare, lastAsync;
var flags = 0;
for (var _i = 0, _a = node.modifiers; _i < _a.length; _i++) {
var modifier = _a[_i];
switch (modifier.kind) {
case 112 /* PublicKeyword */:
case 111 /* ProtectedKeyword */:
case 110 /* PrivateKeyword */:
var text = void 0;
if (modifier.kind === 112 /* PublicKeyword */) {
text = "public";
}
else if (modifier.kind === 111 /* ProtectedKeyword */) {
text = "protected";
lastProtected = modifier;
}
else {
text = "private";
lastPrivate = modifier;
}
if (flags & 56 /* AccessibilityModifier */) {
return grammarErrorOnNode(modifier, ts.Diagnostics.Accessibility_modifier_already_seen);
}
else if (flags & 64 /* Static */) {
return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, text, "static");
}
else if (flags & 256 /* Async */) {
return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, text, "async");
}
else if (node.parent.kind === 219 /* ModuleBlock */ || node.parent.kind === 248 /* SourceFile */) {
return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_element, text);
}
else if (flags & 128 /* Abstract */) {
if (modifier.kind === 110 /* PrivateKeyword */) {
return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_with_1_modifier, text, "abstract");
}
else {
return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, text, "abstract");
}
}
flags |= ts.modifierToFlag(modifier.kind);
break;
case 113 /* StaticKeyword */:
if (flags & 64 /* Static */) {
return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "static");
}
else if (flags & 256 /* Async */) {
return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, "static", "async");
}
else if (node.parent.kind === 219 /* ModuleBlock */ || node.parent.kind === 248 /* SourceFile */) {
return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_module_element, "static");
}
else if (node.kind === 138 /* Parameter */) {
return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "static");
}
else if (flags & 128 /* Abstract */) {
return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_with_1_modifier, "static", "abstract");
}
flags |= 64 /* Static */;
lastStatic = modifier;
break;
case 82 /* ExportKeyword */:
if (flags & 2 /* Export */) {
return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "export");
}
else if (flags & 4 /* Ambient */) {
return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, "export", "declare");
}
else if (flags & 128 /* Abstract */) {
return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, "export", "abstract");
}
else if (flags & 256 /* Async */) {
return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_must_precede_1_modifier, "export", "async");
}
else if (node.parent.kind === 214 /* ClassDeclaration */) {
return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_class_element, "export");
}
else if (node.kind === 138 /* Parameter */) {
return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "export");
}
flags |= 2 /* Export */;
break;
case 122 /* DeclareKeyword */:
if (flags & 4 /* Ambient */) {
return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "declare");
}
else if (flags & 256 /* Async */) {
return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_in_an_ambient_context, "async");
}
else if (node.parent.kind === 214 /* ClassDeclaration */) {
return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_class_element, "declare");
}
else if (node.kind === 138 /* Parameter */) {
return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "declare");
}
else if (ts.isInAmbientContext(node.parent) && node.parent.kind === 219 /* ModuleBlock */) {
return grammarErrorOnNode(modifier, ts.Diagnostics.A_declare_modifier_cannot_be_used_in_an_already_ambient_context);
}
flags |= 4 /* Ambient */;
lastDeclare = modifier;
break;
case 115 /* AbstractKeyword */:
if (flags & 128 /* Abstract */) {
return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "abstract");
}
if (node.kind !== 214 /* ClassDeclaration */) {
if (node.kind !== 143 /* MethodDeclaration */) {
return grammarErrorOnNode(modifier, ts.Diagnostics.abstract_modifier_can_only_appear_on_a_class_or_method_declaration);
}
if (!(node.parent.kind === 214 /* ClassDeclaration */ && node.parent.flags & 128 /* Abstract */)) {
return grammarErrorOnNode(modifier, ts.Diagnostics.Abstract_methods_can_only_appear_within_an_abstract_class);
}
if (flags & 64 /* Static */) {
return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_with_1_modifier, "static", "abstract");
}
if (flags & 16 /* Private */) {
return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_with_1_modifier, "private", "abstract");
}
}
flags |= 128 /* Abstract */;
break;
case 118 /* AsyncKeyword */:
if (flags & 256 /* Async */) {
return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_already_seen, "async");
}
else if (flags & 4 /* Ambient */ || ts.isInAmbientContext(node.parent)) {
return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_be_used_in_an_ambient_context, "async");
}
else if (node.kind === 138 /* Parameter */) {
return grammarErrorOnNode(modifier, ts.Diagnostics._0_modifier_cannot_appear_on_a_parameter, "async");
}
flags |= 256 /* Async */;
lastAsync = modifier;
break;
}
}
if (node.kind === 144 /* Constructor */) {
if (flags & 64 /* Static */) {
return grammarErrorOnNode(lastStatic, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "static");
}
if (flags & 128 /* Abstract */) {
return grammarErrorOnNode(lastStatic, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "abstract");
}
else if (flags & 32 /* Protected */) {
return grammarErrorOnNode(lastProtected, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "protected");
}
else if (flags & 16 /* Private */) {
return grammarErrorOnNode(lastPrivate, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "private");
}
else if (flags & 256 /* Async */) {
return grammarErrorOnNode(lastAsync, ts.Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "async");
}
return;
}
else if ((node.kind === 222 /* ImportDeclaration */ || node.kind === 221 /* ImportEqualsDeclaration */) && flags & 4 /* Ambient */) {
return grammarErrorOnNode(lastDeclare, ts.Diagnostics.A_0_modifier_cannot_be_used_with_an_import_declaration, "declare");
}
else if (node.kind === 138 /* Parameter */ && (flags & 56 /* AccessibilityModifier */) && ts.isBindingPattern(node.name)) {
return grammarErrorOnNode(node, ts.Diagnostics.A_parameter_property_may_not_be_a_binding_pattern);
}
if (flags & 256 /* Async */) {
return checkGrammarAsyncModifier(node, lastAsync);
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
checkGrammarModifiers
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkGrammarAsyncModifier(node, asyncModifier) {
if (languageVersion < 2 /* ES6 */) {
return grammarErrorOnNode(asyncModifier, ts.Diagnostics.Async_functions_are_only_available_when_targeting_ECMAScript_6_and_higher);
}
switch (node.kind) {
case 143 /* MethodDeclaration */:
case 213 /* FunctionDeclaration */:
case 173 /* FunctionExpression */:
case 174 /* ArrowFunction */:
if (!node.asteriskToken) {
return false;
}
break;
}
return grammarErrorOnNode(asyncModifier, ts.Diagnostics._0_modifier_cannot_be_used_here, "async");
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
checkGrammarAsyncModifier
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkGrammarForDisallowedTrailingComma(list) {
if (list && list.hasTrailingComma) {
var start = list.end - ",".length;
var end = list.end;
var sourceFile = ts.getSourceFileOfNode(list[0]);
return grammarErrorAtPos(sourceFile, start, end - start, ts.Diagnostics.Trailing_comma_not_allowed);
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
checkGrammarForDisallowedTrailingComma
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkGrammarTypeParameterList(node, typeParameters, file) {
if (checkGrammarForDisallowedTrailingComma(typeParameters)) {
return true;
}
if (typeParameters && typeParameters.length === 0) {
var start = typeParameters.pos - "<".length;
var end = ts.skipTrivia(file.text, typeParameters.end) + ">".length;
return grammarErrorAtPos(file, start, end - start, ts.Diagnostics.Type_parameter_list_cannot_be_empty);
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
checkGrammarTypeParameterList
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkGrammarParameterList(parameters) {
if (checkGrammarForDisallowedTrailingComma(parameters)) {
return true;
}
var seenOptionalParameter = false;
var parameterCount = parameters.length;
for (var i = 0; i < parameterCount; i++) {
var parameter = parameters[i];
if (parameter.dotDotDotToken) {
if (i !== (parameterCount - 1)) {
return grammarErrorOnNode(parameter.dotDotDotToken, ts.Diagnostics.A_rest_parameter_must_be_last_in_a_parameter_list);
}
if (ts.isBindingPattern(parameter.name)) {
return grammarErrorOnNode(parameter.name, ts.Diagnostics.A_rest_element_cannot_contain_a_binding_pattern);
}
if (parameter.questionToken) {
return grammarErrorOnNode(parameter.questionToken, ts.Diagnostics.A_rest_parameter_cannot_be_optional);
}
if (parameter.initializer) {
return grammarErrorOnNode(parameter.name, ts.Diagnostics.A_rest_parameter_cannot_have_an_initializer);
}
}
else if (parameter.questionToken) {
seenOptionalParameter = true;
if (parameter.initializer) {
return grammarErrorOnNode(parameter.name, ts.Diagnostics.Parameter_cannot_have_question_mark_and_initializer);
}
}
else if (seenOptionalParameter && !parameter.initializer) {
return grammarErrorOnNode(parameter.name, ts.Diagnostics.A_required_parameter_cannot_follow_an_optional_parameter);
}
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
checkGrammarParameterList
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkGrammarFunctionLikeDeclaration(node) {
// Prevent cascading error by short-circuit
var file = ts.getSourceFileOfNode(node);
return checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarTypeParameterList(node, node.typeParameters, file) ||
checkGrammarParameterList(node.parameters) || checkGrammarArrowFunction(node, file);
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
checkGrammarFunctionLikeDeclaration
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkGrammarArrowFunction(node, file) {
if (node.kind === 174 /* ArrowFunction */) {
var arrowFunction = node;
var startLine = ts.getLineAndCharacterOfPosition(file, arrowFunction.equalsGreaterThanToken.pos).line;
var endLine = ts.getLineAndCharacterOfPosition(file, arrowFunction.equalsGreaterThanToken.end).line;
if (startLine !== endLine) {
return grammarErrorOnNode(arrowFunction.equalsGreaterThanToken, ts.Diagnostics.Line_terminator_not_permitted_before_arrow);
}
}
return false;
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
checkGrammarArrowFunction
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkGrammarIndexSignatureParameters(node) {
var parameter = node.parameters[0];
if (node.parameters.length !== 1) {
if (parameter) {
return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_must_have_exactly_one_parameter);
}
else {
return grammarErrorOnNode(node, ts.Diagnostics.An_index_signature_must_have_exactly_one_parameter);
}
}
if (parameter.dotDotDotToken) {
return grammarErrorOnNode(parameter.dotDotDotToken, ts.Diagnostics.An_index_signature_cannot_have_a_rest_parameter);
}
if (parameter.flags & 1022 /* Modifier */) {
return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_cannot_have_an_accessibility_modifier);
}
if (parameter.questionToken) {
return grammarErrorOnNode(parameter.questionToken, ts.Diagnostics.An_index_signature_parameter_cannot_have_a_question_mark);
}
if (parameter.initializer) {
return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_cannot_have_an_initializer);
}
if (!parameter.type) {
return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_must_have_a_type_annotation);
}
if (parameter.type.kind !== 130 /* StringKeyword */ && parameter.type.kind !== 128 /* NumberKeyword */) {
return grammarErrorOnNode(parameter.name, ts.Diagnostics.An_index_signature_parameter_type_must_be_string_or_number);
}
if (!node.type) {
return grammarErrorOnNode(node, ts.Diagnostics.An_index_signature_must_have_a_type_annotation);
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
checkGrammarIndexSignatureParameters
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkGrammarForIndexSignatureModifier(node) {
if (node.flags & 1022 /* Modifier */) {
grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_not_permitted_on_index_signature_members);
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
checkGrammarForIndexSignatureModifier
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkGrammarIndexSignature(node) {
// Prevent cascading error by short-circuit
return checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarIndexSignatureParameters(node) || checkGrammarForIndexSignatureModifier(node);
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
checkGrammarIndexSignature
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkGrammarForAtLeastOneTypeArgument(node, typeArguments) {
if (typeArguments && typeArguments.length === 0) {
var sourceFile = ts.getSourceFileOfNode(node);
var start = typeArguments.pos - "<".length;
var end = ts.skipTrivia(sourceFile.text, typeArguments.end) + ">".length;
return grammarErrorAtPos(sourceFile, start, end - start, ts.Diagnostics.Type_argument_list_cannot_be_empty);
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
checkGrammarForAtLeastOneTypeArgument
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkGrammarTypeArguments(node, typeArguments) {
return checkGrammarForDisallowedTrailingComma(typeArguments) ||
checkGrammarForAtLeastOneTypeArgument(node, typeArguments);
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
checkGrammarTypeArguments
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkGrammarForOmittedArgument(node, args) {
if (args) {
var sourceFile = ts.getSourceFileOfNode(node);
for (var _i = 0, args_1 = args; _i < args_1.length; _i++) {
var arg = args_1[_i];
if (arg.kind === 187 /* OmittedExpression */) {
return grammarErrorAtPos(sourceFile, arg.pos, 0, ts.Diagnostics.Argument_expression_expected);
}
}
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
checkGrammarForOmittedArgument
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkGrammarArguments(node, args) {
return checkGrammarForDisallowedTrailingComma(args) ||
checkGrammarForOmittedArgument(node, args);
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
checkGrammarArguments
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkGrammarHeritageClause(node) {
var types = node.types;
if (checkGrammarForDisallowedTrailingComma(types)) {
return true;
}
if (types && types.length === 0) {
var listType = ts.tokenToString(node.token);
var sourceFile = ts.getSourceFileOfNode(node);
return grammarErrorAtPos(sourceFile, types.pos, 0, ts.Diagnostics._0_list_cannot_be_empty, listType);
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
checkGrammarHeritageClause
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkGrammarClassDeclarationHeritageClauses(node) {
var seenExtendsClause = false;
var seenImplementsClause = false;
if (!checkGrammarDecorators(node) && !checkGrammarModifiers(node) && node.heritageClauses) {
for (var _i = 0, _a = node.heritageClauses; _i < _a.length; _i++) {
var heritageClause = _a[_i];
if (heritageClause.token === 83 /* ExtendsKeyword */) {
if (seenExtendsClause) {
return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.extends_clause_already_seen);
}
if (seenImplementsClause) {
return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.extends_clause_must_precede_implements_clause);
}
if (heritageClause.types.length > 1) {
return grammarErrorOnFirstToken(heritageClause.types[1], ts.Diagnostics.Classes_can_only_extend_a_single_class);
}
seenExtendsClause = true;
}
else {
ts.Debug.assert(heritageClause.token === 106 /* ImplementsKeyword */);
if (seenImplementsClause) {
return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.implements_clause_already_seen);
}
seenImplementsClause = true;
}
// Grammar checking heritageClause inside class declaration
checkGrammarHeritageClause(heritageClause);
}
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
checkGrammarClassDeclarationHeritageClauses
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkGrammarInterfaceDeclaration(node) {
var seenExtendsClause = false;
if (node.heritageClauses) {
for (var _i = 0, _a = node.heritageClauses; _i < _a.length; _i++) {
var heritageClause = _a[_i];
if (heritageClause.token === 83 /* ExtendsKeyword */) {
if (seenExtendsClause) {
return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.extends_clause_already_seen);
}
seenExtendsClause = true;
}
else {
ts.Debug.assert(heritageClause.token === 106 /* ImplementsKeyword */);
return grammarErrorOnFirstToken(heritageClause, ts.Diagnostics.Interface_declaration_cannot_have_implements_clause);
}
// Grammar checking heritageClause inside class declaration
checkGrammarHeritageClause(heritageClause);
}
}
return false;
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
checkGrammarInterfaceDeclaration
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkGrammarComputedPropertyName(node) {
// If node is not a computedPropertyName, just skip the grammar checking
if (node.kind !== 136 /* ComputedPropertyName */) {
return false;
}
var computedPropertyName = node;
if (computedPropertyName.expression.kind === 181 /* BinaryExpression */ && computedPropertyName.expression.operatorToken.kind === 24 /* CommaToken */) {
return grammarErrorOnNode(computedPropertyName.expression, ts.Diagnostics.A_comma_expression_is_not_allowed_in_a_computed_property_name);
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
checkGrammarComputedPropertyName
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkGrammarForGenerator(node) {
if (node.asteriskToken) {
ts.Debug.assert(node.kind === 213 /* FunctionDeclaration */ ||
node.kind === 173 /* FunctionExpression */ ||
node.kind === 143 /* MethodDeclaration */);
if (ts.isInAmbientContext(node)) {
return grammarErrorOnNode(node.asteriskToken, ts.Diagnostics.Generators_are_not_allowed_in_an_ambient_context);
}
if (!node.body) {
return grammarErrorOnNode(node.asteriskToken, ts.Diagnostics.An_overload_signature_cannot_be_declared_as_a_generator);
}
if (languageVersion < 2 /* ES6 */) {
return grammarErrorOnNode(node.asteriskToken, ts.Diagnostics.Generators_are_only_available_when_targeting_ECMAScript_6_or_higher);
}
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
checkGrammarForGenerator
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkGrammarForInvalidQuestionMark(node, questionToken, message) {
if (questionToken) {
return grammarErrorOnNode(questionToken, message);
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
checkGrammarForInvalidQuestionMark
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkGrammarObjectLiteralExpression(node, inDestructuring) {
var seen = {};
var Property = 1;
var GetAccessor = 2;
var SetAccesor = 4;
var GetOrSetAccessor = GetAccessor | SetAccesor;
for (var _i = 0, _a = node.properties; _i < _a.length; _i++) {
var prop = _a[_i];
var name_16 = prop.name;
if (prop.kind === 187 /* OmittedExpression */ ||
name_16.kind === 136 /* ComputedPropertyName */) {
// If the name is not a ComputedPropertyName, the grammar checking will skip it
checkGrammarComputedPropertyName(name_16);
continue;
}
if (prop.kind === 246 /* ShorthandPropertyAssignment */ && !inDestructuring && prop.objectAssignmentInitializer) {
// having objectAssignmentInitializer is only valid in ObjectAssignmentPattern
// outside of destructuring it is a syntax error
return grammarErrorOnNode(prop.equalsToken, ts.Diagnostics.can_only_be_used_in_an_object_literal_property_inside_a_destructuring_assignment);
}
// ECMA-262 11.1.5 Object Initialiser
// If previous is not undefined then throw a SyntaxError exception if any of the following conditions are true
// a.This production is contained in strict code and IsDataDescriptor(previous) is true and
// IsDataDescriptor(propId.descriptor) is true.
// b.IsDataDescriptor(previous) is true and IsAccessorDescriptor(propId.descriptor) is true.
// c.IsAccessorDescriptor(previous) is true and IsDataDescriptor(propId.descriptor) is true.
// d.IsAccessorDescriptor(previous) is true and IsAccessorDescriptor(propId.descriptor) is true
// and either both previous and propId.descriptor have[[Get]] fields or both previous and propId.descriptor have[[Set]] fields
var currentKind = void 0;
if (prop.kind === 245 /* PropertyAssignment */ || prop.kind === 246 /* ShorthandPropertyAssignment */) {
// Grammar checking for computedPropertName and shorthandPropertyAssignment
checkGrammarForInvalidQuestionMark(prop, prop.questionToken, ts.Diagnostics.An_object_member_cannot_be_declared_optional);
if (name_16.kind === 8 /* NumericLiteral */) {
checkGrammarNumericLiteral(name_16);
}
currentKind = Property;
}
else if (prop.kind === 143 /* MethodDeclaration */) {
currentKind = Property;
}
else if (prop.kind === 145 /* GetAccessor */) {
currentKind = GetAccessor;
}
else if (prop.kind === 146 /* SetAccessor */) {
currentKind = SetAccesor;
}
else {
ts.Debug.fail("Unexpected syntax kind:" + prop.kind);
}
if (!ts.hasProperty(seen, name_16.text)) {
seen[name_16.text] = currentKind;
}
else {
var existingKind = seen[name_16.text];
if (currentKind === Property && existingKind === Property) {
continue;
}
else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) {
if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) {
seen[name_16.text] = currentKind | existingKind;
}
else {
return grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name);
}
}
else {
return grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name);
}
}
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
checkGrammarObjectLiteralExpression
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkGrammarJsxElement(node) {
var seen = {};
for (var _i = 0, _a = node.attributes; _i < _a.length; _i++) {
var attr = _a[_i];
if (attr.kind === 239 /* JsxSpreadAttribute */) {
continue;
}
var jsxAttr = attr;
var name_17 = jsxAttr.name;
if (!ts.hasProperty(seen, name_17.text)) {
seen[name_17.text] = true;
}
else {
return grammarErrorOnNode(name_17, ts.Diagnostics.JSX_elements_cannot_have_multiple_attributes_with_the_same_name);
}
var initializer = jsxAttr.initializer;
if (initializer && initializer.kind === 240 /* JsxExpression */ && !initializer.expression) {
return grammarErrorOnNode(jsxAttr.initializer, ts.Diagnostics.JSX_attributes_must_only_be_assigned_a_non_empty_expression);
}
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
checkGrammarJsxElement
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkGrammarForInOrForOfStatement(forInOrOfStatement) {
if (checkGrammarStatementInAmbientContext(forInOrOfStatement)) {
return true;
}
if (forInOrOfStatement.initializer.kind === 212 /* VariableDeclarationList */) {
var variableList = forInOrOfStatement.initializer;
if (!checkGrammarVariableDeclarationList(variableList)) {
if (variableList.declarations.length > 1) {
var diagnostic = forInOrOfStatement.kind === 200 /* ForInStatement */
? ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement
: ts.Diagnostics.Only_a_single_variable_declaration_is_allowed_in_a_for_of_statement;
return grammarErrorOnFirstToken(variableList.declarations[1], diagnostic);
}
var firstDeclaration = variableList.declarations[0];
if (firstDeclaration.initializer) {
var diagnostic = forInOrOfStatement.kind === 200 /* ForInStatement */
? ts.Diagnostics.The_variable_declaration_of_a_for_in_statement_cannot_have_an_initializer
: ts.Diagnostics.The_variable_declaration_of_a_for_of_statement_cannot_have_an_initializer;
return grammarErrorOnNode(firstDeclaration.name, diagnostic);
}
if (firstDeclaration.type) {
var diagnostic = forInOrOfStatement.kind === 200 /* ForInStatement */
? ts.Diagnostics.The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation
: ts.Diagnostics.The_left_hand_side_of_a_for_of_statement_cannot_use_a_type_annotation;
return grammarErrorOnNode(firstDeclaration, diagnostic);
}
}
}
return false;
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
checkGrammarForInOrForOfStatement
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkGrammarAccessor(accessor) {
var kind = accessor.kind;
if (languageVersion < 1 /* ES5 */) {
return grammarErrorOnNode(accessor.name, ts.Diagnostics.Accessors_are_only_available_when_targeting_ECMAScript_5_and_higher);
}
else if (ts.isInAmbientContext(accessor)) {
return grammarErrorOnNode(accessor.name, ts.Diagnostics.An_accessor_cannot_be_declared_in_an_ambient_context);
}
else if (accessor.body === undefined) {
return grammarErrorAtPos(ts.getSourceFileOfNode(accessor), accessor.end - 1, ";".length, ts.Diagnostics._0_expected, "{");
}
else if (accessor.typeParameters) {
return grammarErrorOnNode(accessor.name, ts.Diagnostics.An_accessor_cannot_have_type_parameters);
}
else if (kind === 145 /* GetAccessor */ && accessor.parameters.length) {
return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_get_accessor_cannot_have_parameters);
}
else if (kind === 146 /* SetAccessor */) {
if (accessor.type) {
return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_cannot_have_a_return_type_annotation);
}
else if (accessor.parameters.length !== 1) {
return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_must_have_exactly_one_parameter);
}
else {
var parameter = accessor.parameters[0];
if (parameter.dotDotDotToken) {
return grammarErrorOnNode(parameter.dotDotDotToken, ts.Diagnostics.A_set_accessor_cannot_have_rest_parameter);
}
else if (parameter.flags & 1022 /* Modifier */) {
return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation);
}
else if (parameter.questionToken) {
return grammarErrorOnNode(parameter.questionToken, ts.Diagnostics.A_set_accessor_cannot_have_an_optional_parameter);
}
else if (parameter.initializer) {
return grammarErrorOnNode(accessor.name, ts.Diagnostics.A_set_accessor_parameter_cannot_have_an_initializer);
}
}
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
checkGrammarAccessor
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkGrammarForNonSymbolComputedProperty(node, message) {
if (ts.isDynamicName(node)) {
return grammarErrorOnNode(node, message);
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
checkGrammarForNonSymbolComputedProperty
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkGrammarMethod(node) {
if (checkGrammarDisallowedModifiersOnObjectLiteralExpressionMethod(node) ||
checkGrammarFunctionLikeDeclaration(node) ||
checkGrammarForGenerator(node)) {
return true;
}
if (node.parent.kind === 165 /* ObjectLiteralExpression */) {
if (checkGrammarForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional)) {
return true;
}
else if (node.body === undefined) {
return grammarErrorAtPos(getSourceFile(node), node.end - 1, ";".length, ts.Diagnostics._0_expected, "{");
}
}
if (ts.isClassLike(node.parent)) {
if (checkGrammarForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional)) {
return true;
}
// Technically, computed properties in ambient contexts is disallowed
// for property declarations and accessors too, not just methods.
// However, property declarations disallow computed names in general,
// and accessors are not allowed in ambient contexts in general,
// so this error only really matters for methods.
if (ts.isInAmbientContext(node)) {
return checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_an_ambient_context_must_directly_refer_to_a_built_in_symbol);
}
else if (!node.body) {
return checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_method_overload_must_directly_refer_to_a_built_in_symbol);
}
}
else if (node.parent.kind === 215 /* InterfaceDeclaration */) {
return checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_an_interface_must_directly_refer_to_a_built_in_symbol);
}
else if (node.parent.kind === 155 /* TypeLiteral */) {
return checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_type_literal_must_directly_refer_to_a_built_in_symbol);
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
checkGrammarMethod
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkGrammarBreakOrContinueStatement(node) {
var current = node;
while (current) {
if (ts.isFunctionLike(current)) {
return grammarErrorOnNode(node, ts.Diagnostics.Jump_target_cannot_cross_function_boundary);
}
switch (current.kind) {
case 207 /* LabeledStatement */:
if (node.label && current.label.text === node.label.text) {
// found matching label - verify that label usage is correct
// continue can only target labels that are on iteration statements
var isMisplacedContinueLabel = node.kind === 202 /* ContinueStatement */
&& !ts.isIterationStatement(current.statement, /*lookInLabeledStatement*/ true);
if (isMisplacedContinueLabel) {
return grammarErrorOnNode(node, ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement);
}
return false;
}
break;
case 206 /* SwitchStatement */:
if (node.kind === 203 /* BreakStatement */ && !node.label) {
// unlabeled break within switch statement - ok
return false;
}
break;
default:
if (ts.isIterationStatement(current, /*lookInLabeledStatement*/ false) && !node.label) {
// unlabeled break or continue within iteration statement - ok
return false;
}
break;
}
current = current.parent;
}
if (node.label) {
var message = node.kind === 203 /* BreakStatement */
? ts.Diagnostics.A_break_statement_can_only_jump_to_a_label_of_an_enclosing_statement
: ts.Diagnostics.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement;
return grammarErrorOnNode(node, message);
}
else {
var message = node.kind === 203 /* BreakStatement */
? ts.Diagnostics.A_break_statement_can_only_be_used_within_an_enclosing_iteration_or_switch_statement
: ts.Diagnostics.A_continue_statement_can_only_be_used_within_an_enclosing_iteration_statement;
return grammarErrorOnNode(node, message);
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
checkGrammarBreakOrContinueStatement
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkGrammarBindingElement(node) {
if (node.dotDotDotToken) {
var elements = node.parent.elements;
if (node !== ts.lastOrUndefined(elements)) {
return grammarErrorOnNode(node, ts.Diagnostics.A_rest_element_must_be_last_in_an_array_destructuring_pattern);
}
if (node.name.kind === 162 /* ArrayBindingPattern */ || node.name.kind === 161 /* ObjectBindingPattern */) {
return grammarErrorOnNode(node.name, ts.Diagnostics.A_rest_element_cannot_contain_a_binding_pattern);
}
if (node.initializer) {
// Error on equals token which immediate precedes the initializer
return grammarErrorAtPos(ts.getSourceFileOfNode(node), node.initializer.pos - 1, 1, ts.Diagnostics.A_rest_element_cannot_have_an_initializer);
}
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
checkGrammarBindingElement
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkGrammarVariableDeclaration(node) {
if (node.parent.parent.kind !== 200 /* ForInStatement */ && node.parent.parent.kind !== 201 /* ForOfStatement */) {
if (ts.isInAmbientContext(node)) {
if (node.initializer) {
// Error on equals token which immediate precedes the initializer
var equalsTokenLength = "=".length;
return grammarErrorAtPos(ts.getSourceFileOfNode(node), node.initializer.pos - equalsTokenLength, equalsTokenLength, ts.Diagnostics.Initializers_are_not_allowed_in_ambient_contexts);
}
}
else if (!node.initializer) {
if (ts.isBindingPattern(node.name) && !ts.isBindingPattern(node.parent)) {
return grammarErrorOnNode(node, ts.Diagnostics.A_destructuring_declaration_must_have_an_initializer);
}
if (ts.isConst(node)) {
return grammarErrorOnNode(node, ts.Diagnostics.const_declarations_must_be_initialized);
}
}
}
var checkLetConstNames = languageVersion >= 2 /* ES6 */ && (ts.isLet(node) || ts.isConst(node));
// 1. LexicalDeclaration : LetOrConst BindingList ;
// It is a Syntax Error if the BoundNames of BindingList contains "let".
// 2. ForDeclaration: ForDeclaration : LetOrConst ForBinding
// It is a Syntax Error if the BoundNames of ForDeclaration contains "let".
// It is a SyntaxError if a VariableDeclaration or VariableDeclarationNoIn occurs within strict code
// and its Identifier is eval or arguments
return checkLetConstNames && checkGrammarNameInLetOrConstDeclarations(node.name);
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
checkGrammarVariableDeclaration
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkGrammarNameInLetOrConstDeclarations(name) {
if (name.kind === 69 /* Identifier */) {
if (name.text === "let") {
return grammarErrorOnNode(name, ts.Diagnostics.let_is_not_allowed_to_be_used_as_a_name_in_let_or_const_declarations);
}
}
else {
var elements = name.elements;
for (var _i = 0, elements_2 = elements; _i < elements_2.length; _i++) {
var element = elements_2[_i];
if (element.kind !== 187 /* OmittedExpression */) {
checkGrammarNameInLetOrConstDeclarations(element.name);
}
}
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
checkGrammarNameInLetOrConstDeclarations
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkGrammarVariableDeclarationList(declarationList) {
var declarations = declarationList.declarations;
if (checkGrammarForDisallowedTrailingComma(declarationList.declarations)) {
return true;
}
if (!declarationList.declarations.length) {
return grammarErrorAtPos(ts.getSourceFileOfNode(declarationList), declarations.pos, declarations.end - declarations.pos, ts.Diagnostics.Variable_declaration_list_cannot_be_empty);
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
checkGrammarVariableDeclarationList
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function allowLetAndConstDeclarations(parent) {
switch (parent.kind) {
case 196 /* IfStatement */:
case 197 /* DoStatement */:
case 198 /* WhileStatement */:
case 205 /* WithStatement */:
case 199 /* ForStatement */:
case 200 /* ForInStatement */:
case 201 /* ForOfStatement */:
return false;
case 207 /* LabeledStatement */:
return allowLetAndConstDeclarations(parent.parent);
}
return true;
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
allowLetAndConstDeclarations
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkGrammarForDisallowedLetOrConstStatement(node) {
if (!allowLetAndConstDeclarations(node.parent)) {
if (ts.isLet(node.declarationList)) {
return grammarErrorOnNode(node, ts.Diagnostics.let_declarations_can_only_be_declared_inside_a_block);
}
else if (ts.isConst(node.declarationList)) {
return grammarErrorOnNode(node, ts.Diagnostics.const_declarations_can_only_be_declared_inside_a_block);
}
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
checkGrammarForDisallowedLetOrConstStatement
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function isIntegerLiteral(expression) {
if (expression.kind === 179 /* PrefixUnaryExpression */) {
var unaryExpression = expression;
if (unaryExpression.operator === 35 /* PlusToken */ || unaryExpression.operator === 36 /* MinusToken */) {
expression = unaryExpression.operand;
}
}
if (expression.kind === 8 /* NumericLiteral */) {
// Allows for scientific notation since literalExpression.text was formed by
// coercing a number to a string. Sometimes this coercion can yield a string
// in scientific notation.
// We also don't need special logic for hex because a hex integer is converted
// to decimal when it is coerced.
return /^[0-9]+([eE]\+?[0-9]+)?$/.test(expression.text);
}
return false;
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
isIntegerLiteral
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function hasParseDiagnostics(sourceFile) {
return sourceFile.parseDiagnostics.length > 0;
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
hasParseDiagnostics
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function grammarErrorOnFirstToken(node, message, arg0, arg1, arg2) {
var sourceFile = ts.getSourceFileOfNode(node);
if (!hasParseDiagnostics(sourceFile)) {
var span = ts.getSpanOfTokenAtPosition(sourceFile, node.pos);
diagnostics.add(ts.createFileDiagnostic(sourceFile, span.start, span.length, message, arg0, arg1, arg2));
return true;
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
grammarErrorOnFirstToken
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function grammarErrorAtPos(sourceFile, start, length, message, arg0, arg1, arg2) {
if (!hasParseDiagnostics(sourceFile)) {
diagnostics.add(ts.createFileDiagnostic(sourceFile, start, length, message, arg0, arg1, arg2));
return true;
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
grammarErrorAtPos
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function grammarErrorOnNode(node, message, arg0, arg1, arg2) {
var sourceFile = ts.getSourceFileOfNode(node);
if (!hasParseDiagnostics(sourceFile)) {
diagnostics.add(ts.createDiagnosticForNode(node, message, arg0, arg1, arg2));
return true;
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
grammarErrorOnNode
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function isEvalOrArgumentsIdentifier(node) {
return node.kind === 69 /* Identifier */ &&
(node.text === "eval" || node.text === "arguments");
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
isEvalOrArgumentsIdentifier
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkGrammarConstructorTypeParameters(node) {
if (node.typeParameters) {
return grammarErrorAtPos(ts.getSourceFileOfNode(node), node.typeParameters.pos, node.typeParameters.end - node.typeParameters.pos, ts.Diagnostics.Type_parameters_cannot_appear_on_a_constructor_declaration);
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
checkGrammarConstructorTypeParameters
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkGrammarConstructorTypeAnnotation(node) {
if (node.type) {
return grammarErrorOnNode(node.type, ts.Diagnostics.Type_annotation_cannot_appear_on_a_constructor_declaration);
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
checkGrammarConstructorTypeAnnotation
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkGrammarProperty(node) {
if (ts.isClassLike(node.parent)) {
if (checkGrammarForInvalidQuestionMark(node, node.questionToken, ts.Diagnostics.A_class_member_cannot_be_declared_optional) ||
checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_class_property_declaration_must_directly_refer_to_a_built_in_symbol)) {
return true;
}
}
else if (node.parent.kind === 215 /* InterfaceDeclaration */) {
if (checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_an_interface_must_directly_refer_to_a_built_in_symbol)) {
return true;
}
}
else if (node.parent.kind === 155 /* TypeLiteral */) {
if (checkGrammarForNonSymbolComputedProperty(node.name, ts.Diagnostics.A_computed_property_name_in_a_type_literal_must_directly_refer_to_a_built_in_symbol)) {
return true;
}
}
if (ts.isInAmbientContext(node) && node.initializer) {
return grammarErrorOnFirstToken(node.initializer, ts.Diagnostics.Initializers_are_not_allowed_in_ambient_contexts);
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
checkGrammarProperty
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkGrammarTopLevelElementForRequiredDeclareModifier(node) {
// A declare modifier is required for any top level .d.ts declaration except export=, export default,
// interfaces and imports categories:
//
// DeclarationElement:
// ExportAssignment
// export_opt InterfaceDeclaration
// export_opt TypeAliasDeclaration
// export_opt ImportDeclaration
// export_opt ExternalImportDeclaration
// export_opt AmbientDeclaration
//
// TODO: The spec needs to be amended to reflect this grammar.
if (node.kind === 215 /* InterfaceDeclaration */ ||
node.kind === 216 /* TypeAliasDeclaration */ ||
node.kind === 222 /* ImportDeclaration */ ||
node.kind === 221 /* ImportEqualsDeclaration */ ||
node.kind === 228 /* ExportDeclaration */ ||
node.kind === 227 /* ExportAssignment */ ||
(node.flags & 4 /* Ambient */) ||
(node.flags & (2 /* Export */ | 512 /* Default */))) {
return false;
}
return grammarErrorOnFirstToken(node, ts.Diagnostics.A_declare_modifier_is_required_for_a_top_level_declaration_in_a_d_ts_file);
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
checkGrammarTopLevelElementForRequiredDeclareModifier
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkGrammarTopLevelElementsForRequiredDeclareModifier(file) {
for (var _i = 0, _a = file.statements; _i < _a.length; _i++) {
var decl = _a[_i];
if (ts.isDeclaration(decl) || decl.kind === 193 /* VariableStatement */) {
if (checkGrammarTopLevelElementForRequiredDeclareModifier(decl)) {
return true;
}
}
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
checkGrammarTopLevelElementsForRequiredDeclareModifier
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkGrammarSourceFile(node) {
return ts.isInAmbientContext(node) && checkGrammarTopLevelElementsForRequiredDeclareModifier(node);
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
checkGrammarSourceFile
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkGrammarStatementInAmbientContext(node) {
if (ts.isInAmbientContext(node)) {
// An accessors is already reported about the ambient context
if (isAccessor(node.parent.kind)) {
return getNodeLinks(node).hasReportedStatementInAmbientContext = true;
}
// Find containing block which is either Block, ModuleBlock, SourceFile
var links = getNodeLinks(node);
if (!links.hasReportedStatementInAmbientContext && ts.isFunctionLike(node.parent)) {
return getNodeLinks(node).hasReportedStatementInAmbientContext = grammarErrorOnFirstToken(node, ts.Diagnostics.An_implementation_cannot_be_declared_in_ambient_contexts);
}
// We are either parented by another statement, or some sort of block.
// If we're in a block, we only want to really report an error once
// to prevent noisyness. So use a bit on the block to indicate if
// this has already been reported, and don't report if it has.
//
if (node.parent.kind === 192 /* Block */ || node.parent.kind === 219 /* ModuleBlock */ || node.parent.kind === 248 /* SourceFile */) {
var links_1 = getNodeLinks(node.parent);
// Check if the containing block ever report this error
if (!links_1.hasReportedStatementInAmbientContext) {
return links_1.hasReportedStatementInAmbientContext = grammarErrorOnFirstToken(node, ts.Diagnostics.Statements_are_not_allowed_in_ambient_contexts);
}
}
else {
}
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
checkGrammarStatementInAmbientContext
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function checkGrammarNumericLiteral(node) {
// Grammar checking
if (node.flags & 32768 /* OctalLiteral */ && languageVersion >= 1 /* ES5 */) {
return grammarErrorOnNode(node, ts.Diagnostics.Octal_literals_are_not_available_when_targeting_ECMAScript_5_and_higher);
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
checkGrammarNumericLiteral
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function grammarErrorAfterFirstToken(node, message, arg0, arg1, arg2) {
var sourceFile = ts.getSourceFileOfNode(node);
if (!hasParseDiagnostics(sourceFile)) {
var span = ts.getSpanOfTokenAtPosition(sourceFile, node.pos);
diagnostics.add(ts.createFileDiagnostic(sourceFile, ts.textSpanEnd(span), /*length*/ 0, message, arg0, arg1, arg2));
return true;
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
grammarErrorAfterFirstToken
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getDeclarationDiagnostics(host, resolver, targetSourceFile) {
var diagnostics = [];
var jsFilePath = ts.getOwnEmitOutputFilePath(targetSourceFile, host, ".js");
emitDeclarations(host, resolver, diagnostics, jsFilePath, targetSourceFile);
return diagnostics;
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
getDeclarationDiagnostics
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function emitDeclarations(host, resolver, diagnostics, jsFilePath, root) {
var newLine = host.getNewLine();
var compilerOptions = host.getCompilerOptions();
var write;
var writeLine;
var increaseIndent;
var decreaseIndent;
var writeTextOfNode;
var writer = createAndSetNewTextWriterWithSymbolWriter();
var enclosingDeclaration;
var currentText;
var currentLineMap;
var currentIdentifiers;
var isCurrentFileExternalModule;
var reportedDeclarationError = false;
var errorNameNode;
var emitJsDocComments = compilerOptions.removeComments ? function (declaration) { } : writeJsDocComments;
var emit = compilerOptions.stripInternal ? stripInternal : emitNode;
var noDeclare = !root;
var moduleElementDeclarationEmitInfo = [];
var asynchronousSubModuleDeclarationEmitInfo;
// Contains the reference paths that needs to go in the declaration file.
// Collecting this separately because reference paths need to be first thing in the declaration file
// and we could be collecting these paths from multiple files into single one with --out option
var referencePathsOutput = "";
if (root) {
// Emitting just a single file, so emit references in this file only
if (!compilerOptions.noResolve) {
var addedGlobalFileReference = false;
ts.forEach(root.referencedFiles, function (fileReference) {
var referencedFile = ts.tryResolveScriptReference(host, root, fileReference);
// All the references that are not going to be part of same file
if (referencedFile && ((referencedFile.flags & 4096 /* DeclarationFile */) ||
ts.shouldEmitToOwnFile(referencedFile, compilerOptions) ||
!addedGlobalFileReference)) {
writeReferencePath(referencedFile);
if (!ts.isExternalModuleOrDeclarationFile(referencedFile)) {
addedGlobalFileReference = true;
}
}
});
}
emitSourceFile(root);
// create asynchronous output for the importDeclarations
if (moduleElementDeclarationEmitInfo.length) {
var oldWriter = writer;
ts.forEach(moduleElementDeclarationEmitInfo, function (aliasEmitInfo) {
if (aliasEmitInfo.isVisible) {
ts.Debug.assert(aliasEmitInfo.node.kind === 222 /* ImportDeclaration */);
createAndSetNewTextWriterWithSymbolWriter();
ts.Debug.assert(aliasEmitInfo.indent === 0);
writeImportDeclaration(aliasEmitInfo.node);
aliasEmitInfo.asynchronousOutput = writer.getText();
}
});
setWriter(oldWriter);
}
}
else {
// Emit references corresponding to this file
var emittedReferencedFiles = [];
var prevModuleElementDeclarationEmitInfo = [];
ts.forEach(host.getSourceFiles(), function (sourceFile) {
if (!ts.isDeclarationFile(sourceFile)) {
// Check what references need to be added
if (!compilerOptions.noResolve) {
ts.forEach(sourceFile.referencedFiles, function (fileReference) {
var referencedFile = ts.tryResolveScriptReference(host, sourceFile, fileReference);
// If the reference file is a declaration file, emit that reference
if (referencedFile && (ts.isDeclarationFile(referencedFile) &&
!ts.contains(emittedReferencedFiles, referencedFile))) {
writeReferencePath(referencedFile);
emittedReferencedFiles.push(referencedFile);
}
});
}
}
if (!ts.isExternalModuleOrDeclarationFile(sourceFile)) {
noDeclare = false;
emitSourceFile(sourceFile);
}
else if (ts.isExternalModule(sourceFile)) {
noDeclare = true;
write("declare module \"" + ts.getResolvedExternalModuleName(host, sourceFile) + "\" {");
writeLine();
increaseIndent();
emitSourceFile(sourceFile);
decreaseIndent();
write("}");
writeLine();
// create asynchronous output for the importDeclarations
if (moduleElementDeclarationEmitInfo.length) {
var oldWriter = writer;
ts.forEach(moduleElementDeclarationEmitInfo, function (aliasEmitInfo) {
if (aliasEmitInfo.isVisible && !aliasEmitInfo.asynchronousOutput) {
ts.Debug.assert(aliasEmitInfo.node.kind === 222 /* ImportDeclaration */);
createAndSetNewTextWriterWithSymbolWriter();
ts.Debug.assert(aliasEmitInfo.indent === 1);
increaseIndent();
writeImportDeclaration(aliasEmitInfo.node);
aliasEmitInfo.asynchronousOutput = writer.getText();
decreaseIndent();
}
});
setWriter(oldWriter);
}
prevModuleElementDeclarationEmitInfo = prevModuleElementDeclarationEmitInfo.concat(moduleElementDeclarationEmitInfo);
moduleElementDeclarationEmitInfo = [];
}
});
moduleElementDeclarationEmitInfo = moduleElementDeclarationEmitInfo.concat(prevModuleElementDeclarationEmitInfo);
}
return {
reportedDeclarationError: reportedDeclarationError,
moduleElementDeclarationEmitInfo: moduleElementDeclarationEmitInfo,
synchronousDeclarationOutput: writer.getText(),
referencePathsOutput: referencePathsOutput
};
function hasInternalAnnotation(range) {
var comment = currentText.substring(range.pos, range.end);
return comment.indexOf("@internal") >= 0;
}
function stripInternal(node) {
if (node) {
var leadingCommentRanges = ts.getLeadingCommentRanges(currentText, node.pos);
if (ts.forEach(leadingCommentRanges, hasInternalAnnotation)) {
return;
}
emitNode(node);
}
}
function createAndSetNewTextWriterWithSymbolWriter() {
var writer = ts.createTextWriter(newLine);
writer.trackSymbol = trackSymbol;
writer.reportInaccessibleThisError = reportInaccessibleThisError;
writer.writeKeyword = writer.write;
writer.writeOperator = writer.write;
writer.writePunctuation = writer.write;
writer.writeSpace = writer.write;
writer.writeStringLiteral = writer.writeLiteral;
writer.writeParameter = writer.write;
writer.writeSymbol = writer.write;
setWriter(writer);
return writer;
}
function setWriter(newWriter) {
writer = newWriter;
write = newWriter.write;
writeTextOfNode = newWriter.writeTextOfNode;
writeLine = newWriter.writeLine;
increaseIndent = newWriter.increaseIndent;
decreaseIndent = newWriter.decreaseIndent;
}
function writeAsynchronousModuleElements(nodes) {
var oldWriter = writer;
ts.forEach(nodes, function (declaration) {
var nodeToCheck;
if (declaration.kind === 211 /* VariableDeclaration */) {
nodeToCheck = declaration.parent.parent;
}
else if (declaration.kind === 225 /* NamedImports */ || declaration.kind === 226 /* ImportSpecifier */ || declaration.kind === 223 /* ImportClause */) {
ts.Debug.fail("We should be getting ImportDeclaration instead to write");
}
else {
nodeToCheck = declaration;
}
var moduleElementEmitInfo = ts.forEach(moduleElementDeclarationEmitInfo, function (declEmitInfo) { return declEmitInfo.node === nodeToCheck ? declEmitInfo : undefined; });
if (!moduleElementEmitInfo && asynchronousSubModuleDeclarationEmitInfo) {
moduleElementEmitInfo = ts.forEach(asynchronousSubModuleDeclarationEmitInfo, function (declEmitInfo) { return declEmitInfo.node === nodeToCheck ? declEmitInfo : undefined; });
}
// If the alias was marked as not visible when we saw its declaration, we would have saved the aliasEmitInfo, but if we haven't yet visited the alias declaration
// then we don't need to write it at this point. We will write it when we actually see its declaration
// Eg.
// export function bar(a: foo.Foo) { }
// import foo = require("foo");
// Writing of function bar would mark alias declaration foo as visible but we haven't yet visited that declaration so do nothing,
// we would write alias foo declaration when we visit it since it would now be marked as visible
if (moduleElementEmitInfo) {
if (moduleElementEmitInfo.node.kind === 222 /* ImportDeclaration */) {
// we have to create asynchronous output only after we have collected complete information
// because it is possible to enable multiple bindings as asynchronously visible
moduleElementEmitInfo.isVisible = true;
}
else {
createAndSetNewTextWriterWithSymbolWriter();
for (var declarationIndent = moduleElementEmitInfo.indent; declarationIndent; declarationIndent--) {
increaseIndent();
}
if (nodeToCheck.kind === 218 /* ModuleDeclaration */) {
ts.Debug.assert(asynchronousSubModuleDeclarationEmitInfo === undefined);
asynchronousSubModuleDeclarationEmitInfo = [];
}
writeModuleElement(nodeToCheck);
if (nodeToCheck.kind === 218 /* ModuleDeclaration */) {
moduleElementEmitInfo.subModuleElementDeclarationEmitInfo = asynchronousSubModuleDeclarationEmitInfo;
asynchronousSubModuleDeclarationEmitInfo = undefined;
}
moduleElementEmitInfo.asynchronousOutput = writer.getText();
}
}
});
setWriter(oldWriter);
}
function handleSymbolAccessibilityError(symbolAccesibilityResult) {
if (symbolAccesibilityResult.accessibility === 0 /* Accessible */) {
// write the aliases
if (symbolAccesibilityResult && symbolAccesibilityResult.aliasesToMakeVisible) {
writeAsynchronousModuleElements(symbolAccesibilityResult.aliasesToMakeVisible);
}
}
else {
// Report error
reportedDeclarationError = true;
var errorInfo = writer.getSymbolAccessibilityDiagnostic(symbolAccesibilityResult);
if (errorInfo) {
if (errorInfo.typeName) {
diagnostics.push(ts.createDiagnosticForNode(symbolAccesibilityResult.errorNode || errorInfo.errorNode, errorInfo.diagnosticMessage, ts.getTextOfNodeFromSourceText(currentText, errorInfo.typeName), symbolAccesibilityResult.errorSymbolName, symbolAccesibilityResult.errorModuleName));
}
else {
diagnostics.push(ts.createDiagnosticForNode(symbolAccesibilityResult.errorNode || errorInfo.errorNode, errorInfo.diagnosticMessage, symbolAccesibilityResult.errorSymbolName, symbolAccesibilityResult.errorModuleName));
}
}
}
}
function trackSymbol(symbol, enclosingDeclaration, meaning) {
handleSymbolAccessibilityError(resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning));
}
function reportInaccessibleThisError() {
if (errorNameNode) {
diagnostics.push(ts.createDiagnosticForNode(errorNameNode, ts.Diagnostics.The_inferred_type_of_0_references_an_inaccessible_this_type_A_type_annotation_is_necessary, ts.declarationNameToString(errorNameNode)));
}
}
function writeTypeOfDeclaration(declaration, type, getSymbolAccessibilityDiagnostic) {
writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic;
write(": ");
if (type) {
// Write the type
emitType(type);
}
else {
errorNameNode = declaration.name;
resolver.writeTypeOfDeclaration(declaration, enclosingDeclaration, 2 /* UseTypeOfFunction */, writer);
errorNameNode = undefined;
}
}
function writeReturnTypeAtSignature(signature, getSymbolAccessibilityDiagnostic) {
writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic;
write(": ");
if (signature.type) {
// Write the type
emitType(signature.type);
}
else {
errorNameNode = signature.name;
resolver.writeReturnTypeOfSignatureDeclaration(signature, enclosingDeclaration, 2 /* UseTypeOfFunction */, writer);
errorNameNode = undefined;
}
}
function emitLines(nodes) {
for (var _i = 0, nodes_2 = nodes; _i < nodes_2.length; _i++) {
var node = nodes_2[_i];
emit(node);
}
}
function emitSeparatedList(nodes, separator, eachNodeEmitFn, canEmitFn) {
var currentWriterPos = writer.getTextPos();
for (var _i = 0, nodes_3 = nodes; _i < nodes_3.length; _i++) {
var node = nodes_3[_i];
if (!canEmitFn || canEmitFn(node)) {
if (currentWriterPos !== writer.getTextPos()) {
write(separator);
}
currentWriterPos = writer.getTextPos();
eachNodeEmitFn(node);
}
}
}
function emitCommaList(nodes, eachNodeEmitFn, canEmitFn) {
emitSeparatedList(nodes, ", ", eachNodeEmitFn, canEmitFn);
}
function writeJsDocComments(declaration) {
if (declaration) {
var jsDocComments = ts.getJsDocCommentsFromText(declaration, currentText);
ts.emitNewLineBeforeLeadingComments(currentLineMap, writer, declaration, jsDocComments);
// jsDoc comments are emitted at /*leading comment1 */space/*leading comment*/space
ts.emitComments(currentText, currentLineMap, writer, jsDocComments, /*trailingSeparator*/ true, newLine, ts.writeCommentRange);
}
}
function emitTypeWithNewGetSymbolAccessibilityDiagnostic(type, getSymbolAccessibilityDiagnostic) {
writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic;
emitType(type);
}
function emitType(type) {
switch (type.kind) {
case 117 /* AnyKeyword */:
case 130 /* StringKeyword */:
case 128 /* NumberKeyword */:
case 120 /* BooleanKeyword */:
case 131 /* SymbolKeyword */:
case 103 /* VoidKeyword */:
case 97 /* ThisKeyword */:
case 9 /* StringLiteral */:
return writeTextOfNode(currentText, type);
case 188 /* ExpressionWithTypeArguments */:
return emitExpressionWithTypeArguments(type);
case 151 /* TypeReference */:
return emitTypeReference(type);
case 154 /* TypeQuery */:
return emitTypeQuery(type);
case 156 /* ArrayType */:
return emitArrayType(type);
case 157 /* TupleType */:
return emitTupleType(type);
case 158 /* UnionType */:
return emitUnionType(type);
case 159 /* IntersectionType */:
return emitIntersectionType(type);
case 160 /* ParenthesizedType */:
return emitParenType(type);
case 152 /* FunctionType */:
case 153 /* ConstructorType */:
return emitSignatureDeclarationWithJsDocComments(type);
case 155 /* TypeLiteral */:
return emitTypeLiteral(type);
case 69 /* Identifier */:
return emitEntityName(type);
case 135 /* QualifiedName */:
return emitEntityName(type);
case 150 /* TypePredicate */:
return emitTypePredicate(type);
}
function writeEntityName(entityName) {
if (entityName.kind === 69 /* Identifier */) {
writeTextOfNode(currentText, entityName);
}
else {
var left = entityName.kind === 135 /* QualifiedName */ ? entityName.left : entityName.expression;
var right = entityName.kind === 135 /* QualifiedName */ ? entityName.right : entityName.name;
writeEntityName(left);
write(".");
writeTextOfNode(currentText, right);
}
}
function emitEntityName(entityName) {
var visibilityResult = resolver.isEntityNameVisible(entityName,
// Aliases can be written asynchronously so use correct enclosing declaration
entityName.parent.kind === 221 /* ImportEqualsDeclaration */ ? entityName.parent : enclosingDeclaration);
handleSymbolAccessibilityError(visibilityResult);
writeEntityName(entityName);
}
function emitExpressionWithTypeArguments(node) {
if (ts.isSupportedExpressionWithTypeArguments(node)) {
ts.Debug.assert(node.expression.kind === 69 /* Identifier */ || node.expression.kind === 166 /* PropertyAccessExpression */);
emitEntityName(node.expression);
if (node.typeArguments) {
write("<");
emitCommaList(node.typeArguments, emitType);
write(">");
}
}
}
function emitTypeReference(type) {
emitEntityName(type.typeName);
if (type.typeArguments) {
write("<");
emitCommaList(type.typeArguments, emitType);
write(">");
}
}
function emitTypePredicate(type) {
writeTextOfNode(currentText, type.parameterName);
write(" is ");
emitType(type.type);
}
function emitTypeQuery(type) {
write("typeof ");
emitEntityName(type.exprName);
}
function emitArrayType(type) {
emitType(type.elementType);
write("[]");
}
function emitTupleType(type) {
write("[");
emitCommaList(type.elementTypes, emitType);
write("]");
}
function emitUnionType(type) {
emitSeparatedList(type.types, " | ", emitType);
}
function emitIntersectionType(type) {
emitSeparatedList(type.types, " & ", emitType);
}
function emitParenType(type) {
write("(");
emitType(type.type);
write(")");
}
function emitTypeLiteral(type) {
write("{");
if (type.members.length) {
writeLine();
increaseIndent();
// write members
emitLines(type.members);
decreaseIndent();
}
write("}");
}
}
function emitSourceFile(node) {
currentText = node.text;
currentLineMap = ts.getLineStarts(node);
currentIdentifiers = node.identifiers;
isCurrentFileExternalModule = ts.isExternalModule(node);
enclosingDeclaration = node;
ts.emitDetachedComments(currentText, currentLineMap, writer, ts.writeCommentRange, node, newLine, true /* remove comments */);
emitLines(node.statements);
}
// Return a temp variable name to be used in `export default` statements.
// The temp name will be of the form _default_counter.
// Note that export default is only allowed at most once in a module, so we
// do not need to keep track of created temp names.
function getExportDefaultTempVariableName() {
var baseName = "_default";
if (!ts.hasProperty(currentIdentifiers, baseName)) {
return baseName;
}
var count = 0;
while (true) {
var name_18 = baseName + "_" + (++count);
if (!ts.hasProperty(currentIdentifiers, name_18)) {
return name_18;
}
}
}
function emitExportAssignment(node) {
if (node.expression.kind === 69 /* Identifier */) {
write(node.isExportEquals ? "export = " : "export default ");
writeTextOfNode(currentText, node.expression);
}
else {
// Expression
var tempVarName = getExportDefaultTempVariableName();
write("declare var ");
write(tempVarName);
write(": ");
writer.getSymbolAccessibilityDiagnostic = getDefaultExportAccessibilityDiagnostic;
resolver.writeTypeOfExpression(node.expression, enclosingDeclaration, 2 /* UseTypeOfFunction */, writer);
write(";");
writeLine();
write(node.isExportEquals ? "export = " : "export default ");
write(tempVarName);
}
write(";");
writeLine();
// Make all the declarations visible for the export name
if (node.expression.kind === 69 /* Identifier */) {
var nodes = resolver.collectLinkedAliases(node.expression);
// write each of these declarations asynchronously
writeAsynchronousModuleElements(nodes);
}
function getDefaultExportAccessibilityDiagnostic(diagnostic) {
return {
diagnosticMessage: ts.Diagnostics.Default_export_of_the_module_has_or_is_using_private_name_0,
errorNode: node
};
}
}
function isModuleElementVisible(node) {
return resolver.isDeclarationVisible(node);
}
function emitModuleElement(node, isModuleElementVisible) {
if (isModuleElementVisible) {
writeModuleElement(node);
}
else if (node.kind === 221 /* ImportEqualsDeclaration */ ||
(node.parent.kind === 248 /* SourceFile */ && isCurrentFileExternalModule)) {
var isVisible;
if (asynchronousSubModuleDeclarationEmitInfo && node.parent.kind !== 248 /* SourceFile */) {
// Import declaration of another module that is visited async so lets put it in right spot
asynchronousSubModuleDeclarationEmitInfo.push({
node: node,
outputPos: writer.getTextPos(),
indent: writer.getIndent(),
isVisible: isVisible
});
}
else {
if (node.kind === 222 /* ImportDeclaration */) {
var importDeclaration = node;
if (importDeclaration.importClause) {
isVisible = (importDeclaration.importClause.name && resolver.isDeclarationVisible(importDeclaration.importClause)) ||
isVisibleNamedBinding(importDeclaration.importClause.namedBindings);
}
}
moduleElementDeclarationEmitInfo.push({
node: node,
outputPos: writer.getTextPos(),
indent: writer.getIndent(),
isVisible: isVisible
});
}
}
}
function writeModuleElement(node) {
switch (node.kind) {
case 213 /* FunctionDeclaration */:
return writeFunctionDeclaration(node);
case 193 /* VariableStatement */:
return writeVariableStatement(node);
case 215 /* InterfaceDeclaration */:
return writeInterfaceDeclaration(node);
case 214 /* ClassDeclaration */:
return writeClassDeclaration(node);
case 216 /* TypeAliasDeclaration */:
return writeTypeAliasDeclaration(node);
case 217 /* EnumDeclaration */:
return writeEnumDeclaration(node);
case 218 /* ModuleDeclaration */:
return writeModuleDeclaration(node);
case 221 /* ImportEqualsDeclaration */:
return writeImportEqualsDeclaration(node);
case 222 /* ImportDeclaration */:
return writeImportDeclaration(node);
default:
ts.Debug.fail("Unknown symbol kind");
}
}
function emitModuleElementDeclarationFlags(node) {
// If the node is parented in the current source file we need to emit export declare or just export
if (node.parent.kind === 248 /* SourceFile */) {
// If the node is exported
if (node.flags & 2 /* Export */) {
write("export ");
}
if (node.flags & 512 /* Default */) {
write("default ");
}
else if (node.kind !== 215 /* InterfaceDeclaration */ && !noDeclare) {
write("declare ");
}
}
}
function emitClassMemberDeclarationFlags(node) {
if (node.flags & 16 /* Private */) {
write("private ");
}
else if (node.flags & 32 /* Protected */) {
write("protected ");
}
if (node.flags & 64 /* Static */) {
write("static ");
}
if (node.flags & 128 /* Abstract */) {
write("abstract ");
}
}
function writeImportEqualsDeclaration(node) {
// note usage of writer. methods instead of aliases created, just to make sure we are using
// correct writer especially to handle asynchronous alias writing
emitJsDocComments(node);
if (node.flags & 2 /* Export */) {
write("export ");
}
write("import ");
writeTextOfNode(currentText, node.name);
write(" = ");
if (ts.isInternalModuleImportEqualsDeclaration(node)) {
emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.moduleReference, getImportEntityNameVisibilityError);
write(";");
}
else {
write("require(");
writeTextOfNode(currentText, ts.getExternalModuleImportEqualsDeclarationExpression(node));
write(");");
}
writer.writeLine();
function getImportEntityNameVisibilityError(symbolAccesibilityResult) {
return {
diagnosticMessage: ts.Diagnostics.Import_declaration_0_is_using_private_name_1,
errorNode: node,
typeName: node.name
};
}
}
function isVisibleNamedBinding(namedBindings) {
if (namedBindings) {
if (namedBindings.kind === 224 /* NamespaceImport */) {
return resolver.isDeclarationVisible(namedBindings);
}
else {
return ts.forEach(namedBindings.elements, function (namedImport) { return resolver.isDeclarationVisible(namedImport); });
}
}
}
function writeImportDeclaration(node) {
if (!node.importClause && !(node.flags & 2 /* Export */)) {
// do not write non-exported import declarations that don't have import clauses
return;
}
emitJsDocComments(node);
if (node.flags & 2 /* Export */) {
write("export ");
}
write("import ");
if (node.importClause) {
var currentWriterPos = writer.getTextPos();
if (node.importClause.name && resolver.isDeclarationVisible(node.importClause)) {
writeTextOfNode(currentText, node.importClause.name);
}
if (node.importClause.namedBindings && isVisibleNamedBinding(node.importClause.namedBindings)) {
if (currentWriterPos !== writer.getTextPos()) {
// If the default binding was emitted, write the separated
write(", ");
}
if (node.importClause.namedBindings.kind === 224 /* NamespaceImport */) {
write("* as ");
writeTextOfNode(currentText, node.importClause.namedBindings.name);
}
else {
write("{ ");
emitCommaList(node.importClause.namedBindings.elements, emitImportOrExportSpecifier, resolver.isDeclarationVisible);
write(" }");
}
}
write(" from ");
}
emitExternalModuleSpecifier(node.moduleSpecifier);
write(";");
writer.writeLine();
}
function emitExternalModuleSpecifier(moduleSpecifier) {
if (moduleSpecifier.kind === 9 /* StringLiteral */ && (!root) && (compilerOptions.out || compilerOptions.outFile)) {
var moduleName = ts.getExternalModuleNameFromDeclaration(host, resolver, moduleSpecifier.parent);
if (moduleName) {
write("\"");
write(moduleName);
write("\"");
return;
}
}
writeTextOfNode(currentText, moduleSpecifier);
}
function emitImportOrExportSpecifier(node) {
if (node.propertyName) {
writeTextOfNode(currentText, node.propertyName);
write(" as ");
}
writeTextOfNode(currentText, node.name);
}
function emitExportSpecifier(node) {
emitImportOrExportSpecifier(node);
// Make all the declarations visible for the export name
var nodes = resolver.collectLinkedAliases(node.propertyName || node.name);
// write each of these declarations asynchronously
writeAsynchronousModuleElements(nodes);
}
function emitExportDeclaration(node) {
emitJsDocComments(node);
write("export ");
if (node.exportClause) {
write("{ ");
emitCommaList(node.exportClause.elements, emitExportSpecifier);
write(" }");
}
else {
write("*");
}
if (node.moduleSpecifier) {
write(" from ");
emitExternalModuleSpecifier(node.moduleSpecifier);
}
write(";");
writer.writeLine();
}
function writeModuleDeclaration(node) {
emitJsDocComments(node);
emitModuleElementDeclarationFlags(node);
if (node.flags & 65536 /* Namespace */) {
write("namespace ");
}
else {
write("module ");
}
writeTextOfNode(currentText, node.name);
while (node.body.kind !== 219 /* ModuleBlock */) {
node = node.body;
write(".");
writeTextOfNode(currentText, node.name);
}
var prevEnclosingDeclaration = enclosingDeclaration;
enclosingDeclaration = node;
write(" {");
writeLine();
increaseIndent();
emitLines(node.body.statements);
decreaseIndent();
write("}");
writeLine();
enclosingDeclaration = prevEnclosingDeclaration;
}
function writeTypeAliasDeclaration(node) {
var prevEnclosingDeclaration = enclosingDeclaration;
enclosingDeclaration = node;
emitJsDocComments(node);
emitModuleElementDeclarationFlags(node);
write("type ");
writeTextOfNode(currentText, node.name);
emitTypeParameters(node.typeParameters);
write(" = ");
emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.type, getTypeAliasDeclarationVisibilityError);
write(";");
writeLine();
enclosingDeclaration = prevEnclosingDeclaration;
function getTypeAliasDeclarationVisibilityError(symbolAccesibilityResult) {
return {
diagnosticMessage: ts.Diagnostics.Exported_type_alias_0_has_or_is_using_private_name_1,
errorNode: node.type,
typeName: node.name
};
}
}
function writeEnumDeclaration(node) {
emitJsDocComments(node);
emitModuleElementDeclarationFlags(node);
if (ts.isConst(node)) {
write("const ");
}
write("enum ");
writeTextOfNode(currentText, node.name);
write(" {");
writeLine();
increaseIndent();
emitLines(node.members);
decreaseIndent();
write("}");
writeLine();
}
function emitEnumMemberDeclaration(node) {
emitJsDocComments(node);
writeTextOfNode(currentText, node.name);
var enumMemberValue = resolver.getConstantValue(node);
if (enumMemberValue !== undefined) {
write(" = ");
write(enumMemberValue.toString());
}
write(",");
writeLine();
}
function isPrivateMethodTypeParameter(node) {
return node.parent.kind === 143 /* MethodDeclaration */ && (node.parent.flags & 16 /* Private */);
}
function emitTypeParameters(typeParameters) {
function emitTypeParameter(node) {
increaseIndent();
emitJsDocComments(node);
decreaseIndent();
writeTextOfNode(currentText, node.name);
// If there is constraint present and this is not a type parameter of the private method emit the constraint
if (node.constraint && !isPrivateMethodTypeParameter(node)) {
write(" extends ");
if (node.parent.kind === 152 /* FunctionType */ ||
node.parent.kind === 153 /* ConstructorType */ ||
(node.parent.parent && node.parent.parent.kind === 155 /* TypeLiteral */)) {
ts.Debug.assert(node.parent.kind === 143 /* MethodDeclaration */ ||
node.parent.kind === 142 /* MethodSignature */ ||
node.parent.kind === 152 /* FunctionType */ ||
node.parent.kind === 153 /* ConstructorType */ ||
node.parent.kind === 147 /* CallSignature */ ||
node.parent.kind === 148 /* ConstructSignature */);
emitType(node.constraint);
}
else {
emitTypeWithNewGetSymbolAccessibilityDiagnostic(node.constraint, getTypeParameterConstraintVisibilityError);
}
}
function getTypeParameterConstraintVisibilityError(symbolAccesibilityResult) {
// Type parameter constraints are named by user so we should always be able to name it
var diagnosticMessage;
switch (node.parent.kind) {
case 214 /* ClassDeclaration */:
diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_class_has_or_is_using_private_name_1;
break;
case 215 /* InterfaceDeclaration */:
diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1;
break;
case 148 /* ConstructSignature */:
diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1;
break;
case 147 /* CallSignature */:
diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1;
break;
case 143 /* MethodDeclaration */:
case 142 /* MethodSignature */:
if (node.parent.flags & 64 /* Static */) {
diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1;
}
else if (node.parent.parent.kind === 214 /* ClassDeclaration */) {
diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1;
}
else {
diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1;
}
break;
case 213 /* FunctionDeclaration */:
diagnosticMessage = ts.Diagnostics.Type_parameter_0_of_exported_function_has_or_is_using_private_name_1;
break;
default:
ts.Debug.fail("This is unknown parent for type parameter: " + node.parent.kind);
}
return {
diagnosticMessage: diagnosticMessage,
errorNode: node,
typeName: node.name
};
}
}
if (typeParameters) {
write("<");
emitCommaList(typeParameters, emitTypeParameter);
write(">");
}
}
function emitHeritageClause(typeReferences, isImplementsList) {
if (typeReferences) {
write(isImplementsList ? " implements " : " extends ");
emitCommaList(typeReferences, emitTypeOfTypeReference);
}
function emitTypeOfTypeReference(node) {
if (ts.isSupportedExpressionWithTypeArguments(node)) {
emitTypeWithNewGetSymbolAccessibilityDiagnostic(node, getHeritageClauseVisibilityError);
}
else if (!isImplementsList && node.expression.kind === 93 /* NullKeyword */) {
write("null");
}
function getHeritageClauseVisibilityError(symbolAccesibilityResult) {
var diagnosticMessage;
// Heritage clause is written by user so it can always be named
if (node.parent.parent.kind === 214 /* ClassDeclaration */) {
// Class or Interface implemented/extended is inaccessible
diagnosticMessage = isImplementsList ?
ts.Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_private_name_1 :
ts.Diagnostics.Extends_clause_of_exported_class_0_has_or_is_using_private_name_1;
}
else {
// interface is inaccessible
diagnosticMessage = ts.Diagnostics.Extends_clause_of_exported_interface_0_has_or_is_using_private_name_1;
}
return {
diagnosticMessage: diagnosticMessage,
errorNode: node,
typeName: node.parent.parent.name
};
}
}
}
function writeClassDeclaration(node) {
function emitParameterProperties(constructorDeclaration) {
if (constructorDeclaration) {
ts.forEach(constructorDeclaration.parameters, function (param) {
if (param.flags & 56 /* AccessibilityModifier */) {
emitPropertyDeclaration(param);
}
});
}
}
emitJsDocComments(node);
emitModuleElementDeclarationFlags(node);
if (node.flags & 128 /* Abstract */) {
write("abstract ");
}
write("class ");
writeTextOfNode(currentText, node.name);
var prevEnclosingDeclaration = enclosingDeclaration;
enclosingDeclaration = node;
emitTypeParameters(node.typeParameters);
var baseTypeNode = ts.getClassExtendsHeritageClauseElement(node);
if (baseTypeNode) {
emitHeritageClause([baseTypeNode], /*isImplementsList*/ false);
}
emitHeritageClause(ts.getClassImplementsHeritageClauseElements(node), /*isImplementsList*/ true);
write(" {");
writeLine();
increaseIndent();
emitParameterProperties(ts.getFirstConstructorWithBody(node));
emitLines(node.members);
decreaseIndent();
write("}");
writeLine();
enclosingDeclaration = prevEnclosingDeclaration;
}
function writeInterfaceDeclaration(node) {
emitJsDocComments(node);
emitModuleElementDeclarationFlags(node);
write("interface ");
writeTextOfNode(currentText, node.name);
var prevEnclosingDeclaration = enclosingDeclaration;
enclosingDeclaration = node;
emitTypeParameters(node.typeParameters);
emitHeritageClause(ts.getInterfaceBaseTypeNodes(node), /*isImplementsList*/ false);
write(" {");
writeLine();
increaseIndent();
emitLines(node.members);
decreaseIndent();
write("}");
writeLine();
enclosingDeclaration = prevEnclosingDeclaration;
}
function emitPropertyDeclaration(node) {
if (ts.hasDynamicName(node)) {
return;
}
emitJsDocComments(node);
emitClassMemberDeclarationFlags(node);
emitVariableDeclaration(node);
write(";");
writeLine();
}
function emitVariableDeclaration(node) {
// If we are emitting property it isn't moduleElement and hence we already know it needs to be emitted
// so there is no check needed to see if declaration is visible
if (node.kind !== 211 /* VariableDeclaration */ || resolver.isDeclarationVisible(node)) {
if (ts.isBindingPattern(node.name)) {
emitBindingPattern(node.name);
}
else {
// If this node is a computed name, it can only be a symbol, because we've already skipped
// it if it's not a well known symbol. In that case, the text of the name will be exactly
// what we want, namely the name expression enclosed in brackets.
writeTextOfNode(currentText, node.name);
// If optional property emit ?
if ((node.kind === 141 /* PropertyDeclaration */ || node.kind === 140 /* PropertySignature */) && ts.hasQuestionToken(node)) {
write("?");
}
if ((node.kind === 141 /* PropertyDeclaration */ || node.kind === 140 /* PropertySignature */) && node.parent.kind === 155 /* TypeLiteral */) {
emitTypeOfVariableDeclarationFromTypeLiteral(node);
}
else if (!(node.flags & 16 /* Private */)) {
writeTypeOfDeclaration(node, node.type, getVariableDeclarationTypeVisibilityError);
}
}
}
function getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult) {
if (node.kind === 211 /* VariableDeclaration */) {
return symbolAccesibilityResult.errorModuleName ?
symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ?
ts.Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
ts.Diagnostics.Exported_variable_0_has_or_is_using_name_1_from_private_module_2 :
ts.Diagnostics.Exported_variable_0_has_or_is_using_private_name_1;
}
else if (node.kind === 141 /* PropertyDeclaration */ || node.kind === 140 /* PropertySignature */) {
// TODO(jfreeman): Deal with computed properties in error reporting.
if (node.flags & 64 /* Static */) {
return symbolAccesibilityResult.errorModuleName ?
symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ?
ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 :
ts.Diagnostics.Public_static_property_0_of_exported_class_has_or_is_using_private_name_1;
}
else if (node.parent.kind === 214 /* ClassDeclaration */) {
return symbolAccesibilityResult.errorModuleName ?
symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ?
ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 :
ts.Diagnostics.Public_property_0_of_exported_class_has_or_is_using_private_name_1;
}
else {
// Interfaces cannot have types that cannot be named
return symbolAccesibilityResult.errorModuleName ?
ts.Diagnostics.Property_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 :
ts.Diagnostics.Property_0_of_exported_interface_has_or_is_using_private_name_1;
}
}
}
function getVariableDeclarationTypeVisibilityError(symbolAccesibilityResult) {
var diagnosticMessage = getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult);
return diagnosticMessage !== undefined ? {
diagnosticMessage: diagnosticMessage,
errorNode: node,
typeName: node.name
} : undefined;
}
function emitBindingPattern(bindingPattern) {
// Only select non-omitted expression from the bindingPattern's elements.
// We have to do this to avoid emitting trailing commas.
// For example:
// original: var [, c,,] = [ 2,3,4]
// emitted: declare var c: number; // instead of declare var c:number, ;
var elements = [];
for (var _i = 0, _a = bindingPattern.elements; _i < _a.length; _i++) {
var element = _a[_i];
if (element.kind !== 187 /* OmittedExpression */) {
elements.push(element);
}
}
emitCommaList(elements, emitBindingElement);
}
function emitBindingElement(bindingElement) {
function getBindingElementTypeVisibilityError(symbolAccesibilityResult) {
var diagnosticMessage = getVariableDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult);
return diagnosticMessage !== undefined ? {
diagnosticMessage: diagnosticMessage,
errorNode: bindingElement,
typeName: bindingElement.name
} : undefined;
}
if (bindingElement.name) {
if (ts.isBindingPattern(bindingElement.name)) {
emitBindingPattern(bindingElement.name);
}
else {
writeTextOfNode(currentText, bindingElement.name);
writeTypeOfDeclaration(bindingElement, /*type*/ undefined, getBindingElementTypeVisibilityError);
}
}
}
}
function emitTypeOfVariableDeclarationFromTypeLiteral(node) {
// if this is property of type literal,
// or is parameter of method/call/construct/index signature of type literal
// emit only if type is specified
if (node.type) {
write(": ");
emitType(node.type);
}
}
function isVariableStatementVisible(node) {
return ts.forEach(node.declarationList.declarations, function (varDeclaration) { return resolver.isDeclarationVisible(varDeclaration); });
}
function writeVariableStatement(node) {
emitJsDocComments(node);
emitModuleElementDeclarationFlags(node);
if (ts.isLet(node.declarationList)) {
write("let ");
}
else if (ts.isConst(node.declarationList)) {
write("const ");
}
else {
write("var ");
}
emitCommaList(node.declarationList.declarations, emitVariableDeclaration, resolver.isDeclarationVisible);
write(";");
writeLine();
}
function emitAccessorDeclaration(node) {
if (ts.hasDynamicName(node)) {
return;
}
var accessors = ts.getAllAccessorDeclarations(node.parent.members, node);
var accessorWithTypeAnnotation;
if (node === accessors.firstAccessor) {
emitJsDocComments(accessors.getAccessor);
emitJsDocComments(accessors.setAccessor);
emitClassMemberDeclarationFlags(node);
writeTextOfNode(currentText, node.name);
if (!(node.flags & 16 /* Private */)) {
accessorWithTypeAnnotation = node;
var type = getTypeAnnotationFromAccessor(node);
if (!type) {
// couldn't get type for the first accessor, try the another one
var anotherAccessor = node.kind === 145 /* GetAccessor */ ? accessors.setAccessor : accessors.getAccessor;
type = getTypeAnnotationFromAccessor(anotherAccessor);
if (type) {
accessorWithTypeAnnotation = anotherAccessor;
}
}
writeTypeOfDeclaration(node, type, getAccessorDeclarationTypeVisibilityError);
}
write(";");
writeLine();
}
function getTypeAnnotationFromAccessor(accessor) {
if (accessor) {
return accessor.kind === 145 /* GetAccessor */
? accessor.type // Getter - return type
: accessor.parameters.length > 0
? accessor.parameters[0].type // Setter parameter type
: undefined;
}
}
function getAccessorDeclarationTypeVisibilityError(symbolAccesibilityResult) {
var diagnosticMessage;
if (accessorWithTypeAnnotation.kind === 146 /* SetAccessor */) {
// Setters have to have type named and cannot infer it so, the type should always be named
if (accessorWithTypeAnnotation.parent.flags & 64 /* Static */) {
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
ts.Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
ts.Diagnostics.Parameter_0_of_public_static_property_setter_from_exported_class_has_or_is_using_private_name_1;
}
else {
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
ts.Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
ts.Diagnostics.Parameter_0_of_public_property_setter_from_exported_class_has_or_is_using_private_name_1;
}
return {
diagnosticMessage: diagnosticMessage,
errorNode: accessorWithTypeAnnotation.parameters[0],
// TODO(jfreeman): Investigate why we are passing node.name instead of node.parameters[0].name
typeName: accessorWithTypeAnnotation.name
};
}
else {
if (accessorWithTypeAnnotation.flags & 64 /* Static */) {
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ?
ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named :
ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 :
ts.Diagnostics.Return_type_of_public_static_property_getter_from_exported_class_has_or_is_using_private_name_0;
}
else {
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ?
ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named :
ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_name_0_from_private_module_1 :
ts.Diagnostics.Return_type_of_public_property_getter_from_exported_class_has_or_is_using_private_name_0;
}
return {
diagnosticMessage: diagnosticMessage,
errorNode: accessorWithTypeAnnotation.name,
typeName: undefined
};
}
}
}
function writeFunctionDeclaration(node) {
if (ts.hasDynamicName(node)) {
return;
}
// If we are emitting Method/Constructor it isn't moduleElement and hence already determined to be emitting
// so no need to verify if the declaration is visible
if (!resolver.isImplementationOfOverload(node)) {
emitJsDocComments(node);
if (node.kind === 213 /* FunctionDeclaration */) {
emitModuleElementDeclarationFlags(node);
}
else if (node.kind === 143 /* MethodDeclaration */) {
emitClassMemberDeclarationFlags(node);
}
if (node.kind === 213 /* FunctionDeclaration */) {
write("function ");
writeTextOfNode(currentText, node.name);
}
else if (node.kind === 144 /* Constructor */) {
write("constructor");
}
else {
writeTextOfNode(currentText, node.name);
if (ts.hasQuestionToken(node)) {
write("?");
}
}
emitSignatureDeclaration(node);
}
}
function emitSignatureDeclarationWithJsDocComments(node) {
emitJsDocComments(node);
emitSignatureDeclaration(node);
}
function emitSignatureDeclaration(node) {
// Construct signature or constructor type write new Signature
if (node.kind === 148 /* ConstructSignature */ || node.kind === 153 /* ConstructorType */) {
write("new ");
}
emitTypeParameters(node.typeParameters);
if (node.kind === 149 /* IndexSignature */) {
write("[");
}
else {
write("(");
}
var prevEnclosingDeclaration = enclosingDeclaration;
enclosingDeclaration = node;
// Parameters
emitCommaList(node.parameters, emitParameterDeclaration);
if (node.kind === 149 /* IndexSignature */) {
write("]");
}
else {
write(")");
}
// If this is not a constructor and is not private, emit the return type
var isFunctionTypeOrConstructorType = node.kind === 152 /* FunctionType */ || node.kind === 153 /* ConstructorType */;
if (isFunctionTypeOrConstructorType || node.parent.kind === 155 /* TypeLiteral */) {
// Emit type literal signature return type only if specified
if (node.type) {
write(isFunctionTypeOrConstructorType ? " => " : ": ");
emitType(node.type);
}
}
else if (node.kind !== 144 /* Constructor */ && !(node.flags & 16 /* Private */)) {
writeReturnTypeAtSignature(node, getReturnTypeVisibilityError);
}
enclosingDeclaration = prevEnclosingDeclaration;
if (!isFunctionTypeOrConstructorType) {
write(";");
writeLine();
}
function getReturnTypeVisibilityError(symbolAccesibilityResult) {
var diagnosticMessage;
switch (node.kind) {
case 148 /* ConstructSignature */:
// Interfaces cannot have return types that cannot be named
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
ts.Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 :
ts.Diagnostics.Return_type_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_0;
break;
case 147 /* CallSignature */:
// Interfaces cannot have return types that cannot be named
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
ts.Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 :
ts.Diagnostics.Return_type_of_call_signature_from_exported_interface_has_or_is_using_private_name_0;
break;
case 149 /* IndexSignature */:
// Interfaces cannot have return types that cannot be named
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
ts.Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_name_0_from_private_module_1 :
ts.Diagnostics.Return_type_of_index_signature_from_exported_interface_has_or_is_using_private_name_0;
break;
case 143 /* MethodDeclaration */:
case 142 /* MethodSignature */:
if (node.flags & 64 /* Static */) {
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ?
ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named :
ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 :
ts.Diagnostics.Return_type_of_public_static_method_from_exported_class_has_or_is_using_private_name_0;
}
else if (node.parent.kind === 214 /* ClassDeclaration */) {
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ?
ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named :
ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_name_0_from_private_module_1 :
ts.Diagnostics.Return_type_of_public_method_from_exported_class_has_or_is_using_private_name_0;
}
else {
// Interfaces cannot have return types that cannot be named
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
ts.Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_name_0_from_private_module_1 :
ts.Diagnostics.Return_type_of_method_from_exported_interface_has_or_is_using_private_name_0;
}
break;
case 213 /* FunctionDeclaration */:
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ?
ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_external_module_1_but_cannot_be_named :
ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_name_0_from_private_module_1 :
ts.Diagnostics.Return_type_of_exported_function_has_or_is_using_private_name_0;
break;
default:
ts.Debug.fail("This is unknown kind for signature: " + node.kind);
}
return {
diagnosticMessage: diagnosticMessage,
errorNode: node.name || node
};
}
}
function emitParameterDeclaration(node) {
increaseIndent();
emitJsDocComments(node);
if (node.dotDotDotToken) {
write("...");
}
if (ts.isBindingPattern(node.name)) {
// For bindingPattern, we can't simply writeTextOfNode from the source file
// because we want to omit the initializer and using writeTextOfNode will result in initializer get emitted.
// Therefore, we will have to recursively emit each element in the bindingPattern.
emitBindingPattern(node.name);
}
else {
writeTextOfNode(currentText, node.name);
}
if (resolver.isOptionalParameter(node)) {
write("?");
}
decreaseIndent();
if (node.parent.kind === 152 /* FunctionType */ ||
node.parent.kind === 153 /* ConstructorType */ ||
node.parent.parent.kind === 155 /* TypeLiteral */) {
emitTypeOfVariableDeclarationFromTypeLiteral(node);
}
else if (!(node.parent.flags & 16 /* Private */)) {
writeTypeOfDeclaration(node, node.type, getParameterDeclarationTypeVisibilityError);
}
function getParameterDeclarationTypeVisibilityError(symbolAccesibilityResult) {
var diagnosticMessage = getParameterDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult);
return diagnosticMessage !== undefined ? {
diagnosticMessage: diagnosticMessage,
errorNode: node,
typeName: node.name
} : undefined;
}
function getParameterDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult) {
switch (node.parent.kind) {
case 144 /* Constructor */:
return symbolAccesibilityResult.errorModuleName ?
symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ?
ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
ts.Diagnostics.Parameter_0_of_constructor_from_exported_class_has_or_is_using_private_name_1;
case 148 /* ConstructSignature */:
// Interfaces cannot have parameter types that cannot be named
return symbolAccesibilityResult.errorModuleName ?
ts.Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 :
ts.Diagnostics.Parameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1;
case 147 /* CallSignature */:
// Interfaces cannot have parameter types that cannot be named
return symbolAccesibilityResult.errorModuleName ?
ts.Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 :
ts.Diagnostics.Parameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1;
case 143 /* MethodDeclaration */:
case 142 /* MethodSignature */:
if (node.parent.flags & 64 /* Static */) {
return symbolAccesibilityResult.errorModuleName ?
symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ?
ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
ts.Diagnostics.Parameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1;
}
else if (node.parent.parent.kind === 214 /* ClassDeclaration */) {
return symbolAccesibilityResult.errorModuleName ?
symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ?
ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
ts.Diagnostics.Parameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1;
}
else {
// Interfaces cannot have parameter types that cannot be named
return symbolAccesibilityResult.errorModuleName ?
ts.Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 :
ts.Diagnostics.Parameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1;
}
case 213 /* FunctionDeclaration */:
return symbolAccesibilityResult.errorModuleName ?
symbolAccesibilityResult.accessibility === 2 /* CannotBeNamed */ ?
ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_external_module_2_but_cannot_be_named :
ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 :
ts.Diagnostics.Parameter_0_of_exported_function_has_or_is_using_private_name_1;
default:
ts.Debug.fail("This is unknown parent for parameter: " + node.parent.kind);
}
}
function emitBindingPattern(bindingPattern) {
// We have to explicitly emit square bracket and bracket because these tokens are not store inside the node.
if (bindingPattern.kind === 161 /* ObjectBindingPattern */) {
write("{");
emitCommaList(bindingPattern.elements, emitBindingElement);
write("}");
}
else if (bindingPattern.kind === 162 /* ArrayBindingPattern */) {
write("[");
var elements = bindingPattern.elements;
emitCommaList(elements, emitBindingElement);
if (elements && elements.hasTrailingComma) {
write(", ");
}
write("]");
}
}
function emitBindingElement(bindingElement) {
function getBindingElementTypeVisibilityError(symbolAccesibilityResult) {
var diagnosticMessage = getParameterDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult);
return diagnosticMessage !== undefined ? {
diagnosticMessage: diagnosticMessage,
errorNode: bindingElement,
typeName: bindingElement.name
} : undefined;
}
if (bindingElement.kind === 187 /* OmittedExpression */) {
// If bindingElement is an omittedExpression (i.e. containing elision),
// we will emit blank space (although this may differ from users' original code,
// it allows emitSeparatedList to write separator appropriately)
// Example:
// original: function foo([, x, ,]) {}
// emit : function foo([ , x, , ]) {}
write(" ");
}
else if (bindingElement.kind === 163 /* BindingElement */) {
if (bindingElement.propertyName) {
// bindingElement has propertyName property in the following case:
// { y: [a,b,c] ...} -> bindingPattern will have a property called propertyName for "y"
// We have to explicitly emit the propertyName before descending into its binding elements.
// Example:
// original: function foo({y: [a,b,c]}) {}
// emit : declare function foo({y: [a, b, c]}: { y: [any, any, any] }) void;
writeTextOfNode(currentText, bindingElement.propertyName);
write(": ");
}
if (bindingElement.name) {
if (ts.isBindingPattern(bindingElement.name)) {
// If it is a nested binding pattern, we will recursively descend into each element and emit each one separately.
// In the case of rest element, we will omit rest element.
// Example:
// original: function foo([a, [[b]], c] = [1,[["string"]], 3]) {}
// emit : declare function foo([a, [[b]], c]: [number, [[string]], number]): void;
// original with rest: function foo([a, ...c]) {}
// emit : declare function foo([a, ...c]): void;
emitBindingPattern(bindingElement.name);
}
else {
ts.Debug.assert(bindingElement.name.kind === 69 /* Identifier */);
// If the node is just an identifier, we will simply emit the text associated with the node's name
// Example:
// original: function foo({y = 10, x}) {}
// emit : declare function foo({y, x}: {number, any}): void;
if (bindingElement.dotDotDotToken) {
write("...");
}
writeTextOfNode(currentText, bindingElement.name);
}
}
}
}
}
function emitNode(node) {
switch (node.kind) {
case 213 /* FunctionDeclaration */:
case 218 /* ModuleDeclaration */:
case 221 /* ImportEqualsDeclaration */:
case 215 /* InterfaceDeclaration */:
case 214 /* ClassDeclaration */:
case 216 /* TypeAliasDeclaration */:
case 217 /* EnumDeclaration */:
return emitModuleElement(node, isModuleElementVisible(node));
case 193 /* VariableStatement */:
return emitModuleElement(node, isVariableStatementVisible(node));
case 222 /* ImportDeclaration */:
// Import declaration without import clause is visible, otherwise it is not visible
return emitModuleElement(node, /*isModuleElementVisible*/ !node.importClause);
case 228 /* ExportDeclaration */:
return emitExportDeclaration(node);
case 144 /* Constructor */:
case 143 /* MethodDeclaration */:
case 142 /* MethodSignature */:
return writeFunctionDeclaration(node);
case 148 /* ConstructSignature */:
case 147 /* CallSignature */:
case 149 /* IndexSignature */:
return emitSignatureDeclarationWithJsDocComments(node);
case 145 /* GetAccessor */:
case 146 /* SetAccessor */:
return emitAccessorDeclaration(node);
case 141 /* PropertyDeclaration */:
case 140 /* PropertySignature */:
return emitPropertyDeclaration(node);
case 247 /* EnumMember */:
return emitEnumMemberDeclaration(node);
case 227 /* ExportAssignment */:
return emitExportAssignment(node);
case 248 /* SourceFile */:
return emitSourceFile(node);
}
}
function writeReferencePath(referencedFile) {
var declFileName = referencedFile.flags & 4096 /* DeclarationFile */
? referencedFile.fileName // Declaration file, use declaration file name
: ts.shouldEmitToOwnFile(referencedFile, compilerOptions)
? ts.getOwnEmitOutputFilePath(referencedFile, host, ".d.ts") // Own output file so get the .d.ts file
: ts.removeFileExtension(compilerOptions.outFile || compilerOptions.out) + ".d.ts"; // Global out file
declFileName = ts.getRelativePathToDirectoryOrUrl(ts.getDirectoryPath(ts.normalizeSlashes(jsFilePath)), declFileName, host.getCurrentDirectory(), host.getCanonicalFileName,
/*isAbsolutePathAnUrl*/ false);
referencePathsOutput += "/// <reference path=\"" + declFileName + "\" />" + newLine;
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
emitDeclarations
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function hasInternalAnnotation(range) {
var comment = currentText.substring(range.pos, range.end);
return comment.indexOf("@internal") >= 0;
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
hasInternalAnnotation
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function stripInternal(node) {
if (node) {
var leadingCommentRanges = ts.getLeadingCommentRanges(currentText, node.pos);
if (ts.forEach(leadingCommentRanges, hasInternalAnnotation)) {
return;
}
emitNode(node);
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
stripInternal
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function createAndSetNewTextWriterWithSymbolWriter() {
var writer = ts.createTextWriter(newLine);
writer.trackSymbol = trackSymbol;
writer.reportInaccessibleThisError = reportInaccessibleThisError;
writer.writeKeyword = writer.write;
writer.writeOperator = writer.write;
writer.writePunctuation = writer.write;
writer.writeSpace = writer.write;
writer.writeStringLiteral = writer.writeLiteral;
writer.writeParameter = writer.write;
writer.writeSymbol = writer.write;
setWriter(writer);
return writer;
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
createAndSetNewTextWriterWithSymbolWriter
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function setWriter(newWriter) {
writer = newWriter;
write = newWriter.write;
writeTextOfNode = newWriter.writeTextOfNode;
writeLine = newWriter.writeLine;
increaseIndent = newWriter.increaseIndent;
decreaseIndent = newWriter.decreaseIndent;
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
setWriter
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function writeAsynchronousModuleElements(nodes) {
var oldWriter = writer;
ts.forEach(nodes, function (declaration) {
var nodeToCheck;
if (declaration.kind === 211 /* VariableDeclaration */) {
nodeToCheck = declaration.parent.parent;
}
else if (declaration.kind === 225 /* NamedImports */ || declaration.kind === 226 /* ImportSpecifier */ || declaration.kind === 223 /* ImportClause */) {
ts.Debug.fail("We should be getting ImportDeclaration instead to write");
}
else {
nodeToCheck = declaration;
}
var moduleElementEmitInfo = ts.forEach(moduleElementDeclarationEmitInfo, function (declEmitInfo) { return declEmitInfo.node === nodeToCheck ? declEmitInfo : undefined; });
if (!moduleElementEmitInfo && asynchronousSubModuleDeclarationEmitInfo) {
moduleElementEmitInfo = ts.forEach(asynchronousSubModuleDeclarationEmitInfo, function (declEmitInfo) { return declEmitInfo.node === nodeToCheck ? declEmitInfo : undefined; });
}
// If the alias was marked as not visible when we saw its declaration, we would have saved the aliasEmitInfo, but if we haven't yet visited the alias declaration
// then we don't need to write it at this point. We will write it when we actually see its declaration
// Eg.
// export function bar(a: foo.Foo) { }
// import foo = require("foo");
// Writing of function bar would mark alias declaration foo as visible but we haven't yet visited that declaration so do nothing,
// we would write alias foo declaration when we visit it since it would now be marked as visible
if (moduleElementEmitInfo) {
if (moduleElementEmitInfo.node.kind === 222 /* ImportDeclaration */) {
// we have to create asynchronous output only after we have collected complete information
// because it is possible to enable multiple bindings as asynchronously visible
moduleElementEmitInfo.isVisible = true;
}
else {
createAndSetNewTextWriterWithSymbolWriter();
for (var declarationIndent = moduleElementEmitInfo.indent; declarationIndent; declarationIndent--) {
increaseIndent();
}
if (nodeToCheck.kind === 218 /* ModuleDeclaration */) {
ts.Debug.assert(asynchronousSubModuleDeclarationEmitInfo === undefined);
asynchronousSubModuleDeclarationEmitInfo = [];
}
writeModuleElement(nodeToCheck);
if (nodeToCheck.kind === 218 /* ModuleDeclaration */) {
moduleElementEmitInfo.subModuleElementDeclarationEmitInfo = asynchronousSubModuleDeclarationEmitInfo;
asynchronousSubModuleDeclarationEmitInfo = undefined;
}
moduleElementEmitInfo.asynchronousOutput = writer.getText();
}
}
});
setWriter(oldWriter);
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
writeAsynchronousModuleElements
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function handleSymbolAccessibilityError(symbolAccesibilityResult) {
if (symbolAccesibilityResult.accessibility === 0 /* Accessible */) {
// write the aliases
if (symbolAccesibilityResult && symbolAccesibilityResult.aliasesToMakeVisible) {
writeAsynchronousModuleElements(symbolAccesibilityResult.aliasesToMakeVisible);
}
}
else {
// Report error
reportedDeclarationError = true;
var errorInfo = writer.getSymbolAccessibilityDiagnostic(symbolAccesibilityResult);
if (errorInfo) {
if (errorInfo.typeName) {
diagnostics.push(ts.createDiagnosticForNode(symbolAccesibilityResult.errorNode || errorInfo.errorNode, errorInfo.diagnosticMessage, ts.getTextOfNodeFromSourceText(currentText, errorInfo.typeName), symbolAccesibilityResult.errorSymbolName, symbolAccesibilityResult.errorModuleName));
}
else {
diagnostics.push(ts.createDiagnosticForNode(symbolAccesibilityResult.errorNode || errorInfo.errorNode, errorInfo.diagnosticMessage, symbolAccesibilityResult.errorSymbolName, symbolAccesibilityResult.errorModuleName));
}
}
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
handleSymbolAccessibilityError
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function trackSymbol(symbol, enclosingDeclaration, meaning) {
handleSymbolAccessibilityError(resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning));
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
trackSymbol
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function reportInaccessibleThisError() {
if (errorNameNode) {
diagnostics.push(ts.createDiagnosticForNode(errorNameNode, ts.Diagnostics.The_inferred_type_of_0_references_an_inaccessible_this_type_A_type_annotation_is_necessary, ts.declarationNameToString(errorNameNode)));
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
reportInaccessibleThisError
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function writeTypeOfDeclaration(declaration, type, getSymbolAccessibilityDiagnostic) {
writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic;
write(": ");
if (type) {
// Write the type
emitType(type);
}
else {
errorNameNode = declaration.name;
resolver.writeTypeOfDeclaration(declaration, enclosingDeclaration, 2 /* UseTypeOfFunction */, writer);
errorNameNode = undefined;
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
writeTypeOfDeclaration
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function writeReturnTypeAtSignature(signature, getSymbolAccessibilityDiagnostic) {
writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic;
write(": ");
if (signature.type) {
// Write the type
emitType(signature.type);
}
else {
errorNameNode = signature.name;
resolver.writeReturnTypeOfSignatureDeclaration(signature, enclosingDeclaration, 2 /* UseTypeOfFunction */, writer);
errorNameNode = undefined;
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
writeReturnTypeAtSignature
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function emitLines(nodes) {
for (var _i = 0, nodes_2 = nodes; _i < nodes_2.length; _i++) {
var node = nodes_2[_i];
emit(node);
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
emitLines
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function emitSeparatedList(nodes, separator, eachNodeEmitFn, canEmitFn) {
var currentWriterPos = writer.getTextPos();
for (var _i = 0, nodes_3 = nodes; _i < nodes_3.length; _i++) {
var node = nodes_3[_i];
if (!canEmitFn || canEmitFn(node)) {
if (currentWriterPos !== writer.getTextPos()) {
write(separator);
}
currentWriterPos = writer.getTextPos();
eachNodeEmitFn(node);
}
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
emitSeparatedList
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function emitCommaList(nodes, eachNodeEmitFn, canEmitFn) {
emitSeparatedList(nodes, ", ", eachNodeEmitFn, canEmitFn);
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
emitCommaList
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function writeJsDocComments(declaration) {
if (declaration) {
var jsDocComments = ts.getJsDocCommentsFromText(declaration, currentText);
ts.emitNewLineBeforeLeadingComments(currentLineMap, writer, declaration, jsDocComments);
// jsDoc comments are emitted at /*leading comment1 */space/*leading comment*/space
ts.emitComments(currentText, currentLineMap, writer, jsDocComments, /*trailingSeparator*/ true, newLine, ts.writeCommentRange);
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
writeJsDocComments
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function emitTypeWithNewGetSymbolAccessibilityDiagnostic(type, getSymbolAccessibilityDiagnostic) {
writer.getSymbolAccessibilityDiagnostic = getSymbolAccessibilityDiagnostic;
emitType(type);
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
emitTypeWithNewGetSymbolAccessibilityDiagnostic
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function emitType(type) {
switch (type.kind) {
case 117 /* AnyKeyword */:
case 130 /* StringKeyword */:
case 128 /* NumberKeyword */:
case 120 /* BooleanKeyword */:
case 131 /* SymbolKeyword */:
case 103 /* VoidKeyword */:
case 97 /* ThisKeyword */:
case 9 /* StringLiteral */:
return writeTextOfNode(currentText, type);
case 188 /* ExpressionWithTypeArguments */:
return emitExpressionWithTypeArguments(type);
case 151 /* TypeReference */:
return emitTypeReference(type);
case 154 /* TypeQuery */:
return emitTypeQuery(type);
case 156 /* ArrayType */:
return emitArrayType(type);
case 157 /* TupleType */:
return emitTupleType(type);
case 158 /* UnionType */:
return emitUnionType(type);
case 159 /* IntersectionType */:
return emitIntersectionType(type);
case 160 /* ParenthesizedType */:
return emitParenType(type);
case 152 /* FunctionType */:
case 153 /* ConstructorType */:
return emitSignatureDeclarationWithJsDocComments(type);
case 155 /* TypeLiteral */:
return emitTypeLiteral(type);
case 69 /* Identifier */:
return emitEntityName(type);
case 135 /* QualifiedName */:
return emitEntityName(type);
case 150 /* TypePredicate */:
return emitTypePredicate(type);
}
function writeEntityName(entityName) {
if (entityName.kind === 69 /* Identifier */) {
writeTextOfNode(currentText, entityName);
}
else {
var left = entityName.kind === 135 /* QualifiedName */ ? entityName.left : entityName.expression;
var right = entityName.kind === 135 /* QualifiedName */ ? entityName.right : entityName.name;
writeEntityName(left);
write(".");
writeTextOfNode(currentText, right);
}
}
function emitEntityName(entityName) {
var visibilityResult = resolver.isEntityNameVisible(entityName,
// Aliases can be written asynchronously so use correct enclosing declaration
entityName.parent.kind === 221 /* ImportEqualsDeclaration */ ? entityName.parent : enclosingDeclaration);
handleSymbolAccessibilityError(visibilityResult);
writeEntityName(entityName);
}
function emitExpressionWithTypeArguments(node) {
if (ts.isSupportedExpressionWithTypeArguments(node)) {
ts.Debug.assert(node.expression.kind === 69 /* Identifier */ || node.expression.kind === 166 /* PropertyAccessExpression */);
emitEntityName(node.expression);
if (node.typeArguments) {
write("<");
emitCommaList(node.typeArguments, emitType);
write(">");
}
}
}
function emitTypeReference(type) {
emitEntityName(type.typeName);
if (type.typeArguments) {
write("<");
emitCommaList(type.typeArguments, emitType);
write(">");
}
}
function emitTypePredicate(type) {
writeTextOfNode(currentText, type.parameterName);
write(" is ");
emitType(type.type);
}
function emitTypeQuery(type) {
write("typeof ");
emitEntityName(type.exprName);
}
function emitArrayType(type) {
emitType(type.elementType);
write("[]");
}
function emitTupleType(type) {
write("[");
emitCommaList(type.elementTypes, emitType);
write("]");
}
function emitUnionType(type) {
emitSeparatedList(type.types, " | ", emitType);
}
function emitIntersectionType(type) {
emitSeparatedList(type.types, " & ", emitType);
}
function emitParenType(type) {
write("(");
emitType(type.type);
write(")");
}
function emitTypeLiteral(type) {
write("{");
if (type.members.length) {
writeLine();
increaseIndent();
// write members
emitLines(type.members);
decreaseIndent();
}
write("}");
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
emitType
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function writeEntityName(entityName) {
if (entityName.kind === 69 /* Identifier */) {
writeTextOfNode(currentText, entityName);
}
else {
var left = entityName.kind === 135 /* QualifiedName */ ? entityName.left : entityName.expression;
var right = entityName.kind === 135 /* QualifiedName */ ? entityName.right : entityName.name;
writeEntityName(left);
write(".");
writeTextOfNode(currentText, right);
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
writeEntityName
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function emitEntityName(entityName) {
var visibilityResult = resolver.isEntityNameVisible(entityName,
// Aliases can be written asynchronously so use correct enclosing declaration
entityName.parent.kind === 221 /* ImportEqualsDeclaration */ ? entityName.parent : enclosingDeclaration);
handleSymbolAccessibilityError(visibilityResult);
writeEntityName(entityName);
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
emitEntityName
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function emitExpressionWithTypeArguments(node) {
if (ts.isSupportedExpressionWithTypeArguments(node)) {
ts.Debug.assert(node.expression.kind === 69 /* Identifier */ || node.expression.kind === 166 /* PropertyAccessExpression */);
emitEntityName(node.expression);
if (node.typeArguments) {
write("<");
emitCommaList(node.typeArguments, emitType);
write(">");
}
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
emitExpressionWithTypeArguments
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function emitTypeReference(type) {
emitEntityName(type.typeName);
if (type.typeArguments) {
write("<");
emitCommaList(type.typeArguments, emitType);
write(">");
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
emitTypeReference
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function emitTypePredicate(type) {
writeTextOfNode(currentText, type.parameterName);
write(" is ");
emitType(type.type);
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
emitTypePredicate
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function emitTypeQuery(type) {
write("typeof ");
emitEntityName(type.exprName);
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
emitTypeQuery
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function emitArrayType(type) {
emitType(type.elementType);
write("[]");
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
emitArrayType
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function emitTupleType(type) {
write("[");
emitCommaList(type.elementTypes, emitType);
write("]");
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
emitTupleType
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function emitUnionType(type) {
emitSeparatedList(type.types, " | ", emitType);
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
emitUnionType
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function emitIntersectionType(type) {
emitSeparatedList(type.types, " & ", emitType);
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
emitIntersectionType
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function emitParenType(type) {
write("(");
emitType(type.type);
write(")");
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
emitParenType
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function emitTypeLiteral(type) {
write("{");
if (type.members.length) {
writeLine();
increaseIndent();
// write members
emitLines(type.members);
decreaseIndent();
}
write("}");
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
emitTypeLiteral
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function emitSourceFile(node) {
currentText = node.text;
currentLineMap = ts.getLineStarts(node);
currentIdentifiers = node.identifiers;
isCurrentFileExternalModule = ts.isExternalModule(node);
enclosingDeclaration = node;
ts.emitDetachedComments(currentText, currentLineMap, writer, ts.writeCommentRange, node, newLine, true /* remove comments */);
emitLines(node.statements);
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
emitSourceFile
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getExportDefaultTempVariableName() {
var baseName = "_default";
if (!ts.hasProperty(currentIdentifiers, baseName)) {
return baseName;
}
var count = 0;
while (true) {
var name_18 = baseName + "_" + (++count);
if (!ts.hasProperty(currentIdentifiers, name_18)) {
return name_18;
}
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
getExportDefaultTempVariableName
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function emitExportAssignment(node) {
if (node.expression.kind === 69 /* Identifier */) {
write(node.isExportEquals ? "export = " : "export default ");
writeTextOfNode(currentText, node.expression);
}
else {
// Expression
var tempVarName = getExportDefaultTempVariableName();
write("declare var ");
write(tempVarName);
write(": ");
writer.getSymbolAccessibilityDiagnostic = getDefaultExportAccessibilityDiagnostic;
resolver.writeTypeOfExpression(node.expression, enclosingDeclaration, 2 /* UseTypeOfFunction */, writer);
write(";");
writeLine();
write(node.isExportEquals ? "export = " : "export default ");
write(tempVarName);
}
write(";");
writeLine();
// Make all the declarations visible for the export name
if (node.expression.kind === 69 /* Identifier */) {
var nodes = resolver.collectLinkedAliases(node.expression);
// write each of these declarations asynchronously
writeAsynchronousModuleElements(nodes);
}
function getDefaultExportAccessibilityDiagnostic(diagnostic) {
return {
diagnosticMessage: ts.Diagnostics.Default_export_of_the_module_has_or_is_using_private_name_0,
errorNode: node
};
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
emitExportAssignment
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function getDefaultExportAccessibilityDiagnostic(diagnostic) {
return {
diagnosticMessage: ts.Diagnostics.Default_export_of_the_module_has_or_is_using_private_name_0,
errorNode: node
};
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
getDefaultExportAccessibilityDiagnostic
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function isModuleElementVisible(node) {
return resolver.isDeclarationVisible(node);
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
isModuleElementVisible
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function emitModuleElement(node, isModuleElementVisible) {
if (isModuleElementVisible) {
writeModuleElement(node);
}
else if (node.kind === 221 /* ImportEqualsDeclaration */ ||
(node.parent.kind === 248 /* SourceFile */ && isCurrentFileExternalModule)) {
var isVisible;
if (asynchronousSubModuleDeclarationEmitInfo && node.parent.kind !== 248 /* SourceFile */) {
// Import declaration of another module that is visited async so lets put it in right spot
asynchronousSubModuleDeclarationEmitInfo.push({
node: node,
outputPos: writer.getTextPos(),
indent: writer.getIndent(),
isVisible: isVisible
});
}
else {
if (node.kind === 222 /* ImportDeclaration */) {
var importDeclaration = node;
if (importDeclaration.importClause) {
isVisible = (importDeclaration.importClause.name && resolver.isDeclarationVisible(importDeclaration.importClause)) ||
isVisibleNamedBinding(importDeclaration.importClause.namedBindings);
}
}
moduleElementDeclarationEmitInfo.push({
node: node,
outputPos: writer.getTextPos(),
indent: writer.getIndent(),
isVisible: isVisible
});
}
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
emitModuleElement
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function writeModuleElement(node) {
switch (node.kind) {
case 213 /* FunctionDeclaration */:
return writeFunctionDeclaration(node);
case 193 /* VariableStatement */:
return writeVariableStatement(node);
case 215 /* InterfaceDeclaration */:
return writeInterfaceDeclaration(node);
case 214 /* ClassDeclaration */:
return writeClassDeclaration(node);
case 216 /* TypeAliasDeclaration */:
return writeTypeAliasDeclaration(node);
case 217 /* EnumDeclaration */:
return writeEnumDeclaration(node);
case 218 /* ModuleDeclaration */:
return writeModuleDeclaration(node);
case 221 /* ImportEqualsDeclaration */:
return writeImportEqualsDeclaration(node);
case 222 /* ImportDeclaration */:
return writeImportDeclaration(node);
default:
ts.Debug.fail("Unknown symbol kind");
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
writeModuleElement
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function emitModuleElementDeclarationFlags(node) {
// If the node is parented in the current source file we need to emit export declare or just export
if (node.parent.kind === 248 /* SourceFile */) {
// If the node is exported
if (node.flags & 2 /* Export */) {
write("export ");
}
if (node.flags & 512 /* Default */) {
write("default ");
}
else if (node.kind !== 215 /* InterfaceDeclaration */ && !noDeclare) {
write("declare ");
}
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
emitModuleElementDeclarationFlags
|
javascript
|
amol-/dukpy
|
dukpy/jsmodules/typescriptServices.js
|
https://github.com/amol-/dukpy/blob/master/dukpy/jsmodules/typescriptServices.js
|
MIT
|
function emitClassMemberDeclarationFlags(node) {
if (node.flags & 16 /* Private */) {
write("private ");
}
else if (node.flags & 32 /* Protected */) {
write("protected ");
}
if (node.flags & 64 /* Static */) {
write("static ");
}
if (node.flags & 128 /* Abstract */) {
write("abstract ");
}
}
|
Gets either the static or instance type of a class element, based on
whether the element is declared as "static".
|
emitClassMemberDeclarationFlags
|
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.