1/* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16const ts = require("typescript"); 17 18function getSymbol(node) { 19 return node.symbol; 20} 21 22function tsStringToString(str) { 23 return "" + str; 24} 25 26function getTextOfIdentifierOrLiteral(node) { 27 return ts.getTextOfIdentifierOrLiteral(node); 28} 29 30function isJsFile(file) { 31 return (file.scriptKind & ts.ScriptKind.JS) != 0; 32} 33 34function createEmptyNodeArray() { 35 return []; 36} 37 38function getFlowNode(stmt) { 39 return stmt.flowNode; 40} 41 42function bindSourceFile(sourceFile, options) { 43 ts.bindSourceFile(sourceFile, options); 44} 45 46function createDiagnosticForNode(node, message, ...args) { 47 return ts.createDiagnosticForNode(node, message, ...args); 48} 49 50function createCompilerDiagnostic(message, ...args) { 51 return ts.createCompilerDiagnostic(message, ...args); 52} 53 54function createFileDiagnostic(file, start, length, message, ...args) { 55 return ts.createFileDiagnostic(file, start, length, message, args); 56} 57 58function isEffectiveStrictModeSourceFile(node, compilerOptions) { 59 return ts.isEffectiveStrictModeSourceFile(node, compilerOptions); 60} 61 62function getErrorSpanForNode(sourceFile, node) { 63 return ts.getErrorSpanForNode(sourceFile, node); 64} 65 66function getSpanOfTokenAtPosition(sourceFile, pos) { 67 return ts.getSpanOfTokenAtPosition(sourceFile, pos); 68} 69 70function getContainingClass(node) { 71 return ts.getContainingClass(node); 72} 73 74function declarationNameToString(node) { 75 return ts.declarationNameToString(node); 76} 77 78function getContainingFunction(node) { 79 return ts.getContainingFunction(node); 80} 81 82function isPrologueDirective(node) { 83 return ts.isPrologueDirective(node); 84} 85 86function getSourceTextOfNodeFromSourceFile(sourceFile, node, includeTrivia) { 87 return ts.getSourceTextOfNodeFromSourceFile(sourceFile, node, includeTrivia); 88} 89 90function isAssignmentTarget(node) { 91 return ts.isAssignmentTarget(node); 92} 93 94function getSourceFileOfNode(node) { 95 return ts.getSourceFileOfNode(node); 96} 97 98function isIterationStatement(node, lookInLabeledStatements) { 99 return ts.isIterationStatement(node, lookInLabeledStatements); 100} 101 102function getTextOfNode(node, includeTrivia) { 103 return ts.getTextOfNode(node, includeTrivia); 104} 105 106function nodePosToString(node) { 107 return ts.nodePosToString(node); 108} 109 110function getContainingFunctionDeclaration(node) { 111 return ts.getContainingFunctionDeclaration(node); 112} 113 114function tokenToString(t) { 115 return ts.tokenToString(t); 116} 117 118function getNewTargetContainer(node) { 119 return ts.getNewTargetContainer(node); 120} 121 122function isVarConst(node) { 123 return ts.isVarConst(node); 124} 125 126function isLet(node) { 127 return ts.isLet(node); 128} 129 130function nodeCanBeDecorated(node) { 131 return ts.nodeCanBeDecorated(node); 132} 133 134function nodeIsPresent(node) { 135 return ts.nodeIsPresent(node); 136} 137 138function getAllAccessorDeclarations(declarations, accessor) { 139 return ts.getAllAccessorDeclarations(declarations, accessor); 140} 141 142function modifierToFlag(token) { 143 return ts.modifierToFlag(token); 144} 145 146function hasSyntacticModifier(node, flag) { 147 return ts.hasSyntacticModifier(node, flag); 148} 149 150function isAmbientModule(node) { 151 return ts.isAmbientModule(node); 152} 153 154function isKeyword(node) { 155 return ts.isKeyword(node); 156} 157 158function getThisContainer(node) { 159 return ts.getThisContainer(node); 160} 161 162function getEnclosingBlockScopeContainer(node) { 163 return ts.getEnclosingBlockScopeContainer(node); 164} 165 166function findAncestor(node, callback) { 167 return ts.findAncestor(node, callback); 168} 169 170function isBlockScope(node, parentNode) { 171 return ts.isBlockScope(node, parentNode); 172} 173 174function isIdentifierName(node) { 175 return ts.isIdentifierName(node); 176} 177 178function declarationNameToString(node) { 179 return ts.declarationNameToString(node); 180} 181 182function isInTopLevelContext(node) { 183 return ts.isInTopLevelContext(node); 184} 185 186function isExternalOrCommonJsModule(node) { 187 return ts.isExternalOrCommonJsModule(node); 188} 189 190function skipParentheses(node) { 191 return ts.skipParentheses(node); 192} 193 194function getImmediatelyInvokedFunctionExpression(node) { 195 return ts.getImmediatelyInvokedFunctionExpression(node); 196} 197 198function hasQuestionToken(node) { 199 return ts.hasQuestionToken(node); 200} 201 202function getPropertyNameForPropertyNameNode(name) { 203 return ts.getPropertyNameForPropertyNameNode(name); 204} 205 206function isFunctionBlock(node) { 207 return ts.isFunctionBlock(node); 208} 209 210function isFunctionLike(node) { 211 return ts.isFunctionLike(node); 212} 213 214function getSuperContainer(node, stopOnFunctions) { 215 return ts.getSuperContainer(node, stopOnFunctions); 216} 217 218function getClassExtendsHeritageElement(node) { 219 return ts.getClassExtendsHeritageElement(node); 220} 221 222function hasStaticModifier(node) { 223 return ts.hasStaticModifier(node); 224} 225 226function skipOuterExpressions(node, kinds) { 227 return ts.skipOuterExpressions(node, kinds); 228} 229 230function isSuperCall(node) { 231 return ts.isSuperCall(node); 232} 233 234function isThisIdentifier(node) { 235 return ts.isThisIdentifier(node); 236} 237 238function isThisProperty(node) { 239 return ts.isThisProperty(node); 240} 241 242function isSuperProperty(node) { 243 return ts.isSuperProperty(node); 244} 245 246function setParent(child, parent) { 247 return ts.setParent(child, parent); 248} 249 250module.exports = { 251 getSymbol: getSymbol, 252 tsStringToString: tsStringToString, 253 getTextOfIdentifierOrLiteral: getTextOfIdentifierOrLiteral, 254 isJsFile: isJsFile, 255 createEmptyNodeArray: createEmptyNodeArray, 256 getFlowNode: getFlowNode, 257 bindSourceFile: bindSourceFile, 258 createDiagnosticForNode: createDiagnosticForNode, 259 createCompilerDiagnostic: createCompilerDiagnostic, 260 createFileDiagnostic: createFileDiagnostic, 261 isEffectiveStrictModeSourceFile: isEffectiveStrictModeSourceFile, 262 getErrorSpanForNode: getErrorSpanForNode, 263 getSpanOfTokenAtPosition: getSpanOfTokenAtPosition, 264 getContainingClass: getContainingClass, 265 declarationNameToString: declarationNameToString, 266 getContainingFunction: getContainingFunction, 267 isPrologueDirective: isPrologueDirective, 268 getSourceTextOfNodeFromSourceFile: getSourceTextOfNodeFromSourceFile, 269 isAssignmentTarget: isAssignmentTarget, 270 getSourceFileOfNode: getSourceFileOfNode, 271 isIterationStatement: isIterationStatement, 272 getTextOfNode: getTextOfNode, 273 nodePosToString: nodePosToString, 274 getContainingFunctionDeclaration: getContainingFunctionDeclaration, 275 tokenToString: tokenToString, 276 getNewTargetContainer: getNewTargetContainer, 277 isLet: isLet, 278 isVarConst: isVarConst, 279 nodeCanBeDecorated: nodeCanBeDecorated, 280 nodeIsPresent: nodeIsPresent, 281 getAllAccessorDeclarations: getAllAccessorDeclarations, 282 modifierToFlag: modifierToFlag, 283 hasSyntacticModifier: hasSyntacticModifier, 284 isAmbientModule: isAmbientModule, 285 isKeyword: isKeyword, 286 getThisContainer: getThisContainer, 287 getEnclosingBlockScopeContainer: getEnclosingBlockScopeContainer, 288 findAncestor: findAncestor, 289 isBlockScope: isBlockScope, 290 isIdentifierName: isIdentifierName, 291 declarationNameToString: declarationNameToString, 292 isInTopLevelContext: isInTopLevelContext, 293 isExternalOrCommonJsModule: isExternalOrCommonJsModule, 294 skipParentheses: skipParentheses, 295 getImmediatelyInvokedFunctionExpression: getImmediatelyInvokedFunctionExpression, 296 hasQuestionToken: hasQuestionToken, 297 getPropertyNameForPropertyNameNode: getPropertyNameForPropertyNameNode, 298 isFunctionBlock: isFunctionBlock, 299 isFunctionLike: isFunctionLike, 300 getSuperContainer: getSuperContainer, 301 getClassExtendsHeritageElement: getClassExtendsHeritageElement, 302 hasStaticModifier: hasStaticModifier, 303 skipOuterExpressions: skipOuterExpressions, 304 isSuperCall: isSuperCall, 305 isThisIdentifier: isThisIdentifier, 306 isThisProperty: isThisProperty, 307 isSuperProperty: isSuperProperty, 308 setParent: setParent, 309}; 310