How to use the isImportEqualsDeclaration function from typescript

Find comprehensive JavaScript typescript.isImportEqualsDeclaration code examples handpicked from public code repositorys.

typescript.isImportEqualsDeclaration is a TypeScript function that checks if a node is an ImportEqualsDeclaration.

156
157
158
159
160
161
162
163
164
165
 */
function mustBeHoisted(s, isGlobal) {
    return (
        // Import/export statements must be moved to the top
        ts.isImportDeclaration(s) ||
        ts.isImportEqualsDeclaration(s) ||
        ts.isExportDeclaration(s) ||
        ts.isExportAssignment(s) ||
        // as well as many declarations
        ts.isTypeAliasDeclaration(s) ||
fork icon116
star icon294
watch icon29

158
159
160
161
162
163
164
165
166
167
if (sourceFile) {
  ts.forEachChild(sourceFile, (node) => {
    if (
      ts.isImportDeclaration(node) ||
      ts.isExportDeclaration(node) ||
      ts.isImportEqualsDeclaration(node) ||
      ts.isExportAssignment(node)
    ) {
      const moduleName = node.moduleSpecifier?.text;
      if (moduleName) {
fork icon0
star icon0
watch icon1

+ 18 other calls in file

How does typescript.isImportEqualsDeclaration work?

typescript.isImportEqualsDeclaration is a function that determines whether a given node is an ImportEqualsDeclaration node in a TypeScript AST (Abstract Syntax Tree) by examining its properties and structure. It returns a boolean value indicating whether the node is an import equals declaration or not. The function checks if the Node's kind property is ts.SyntaxKind.ImportEqualsDeclaration.

Ai Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import ts from "typescript";

const sourceFile = ts.createSourceFile(
  "example.ts",
  "import example = require('./example');",
  ts.ScriptTarget.ESNext
);

if (
  sourceFile.statements[0] &&
  ts.isImportEqualsDeclaration(sourceFile.statements[0])
) {
  console.log("This is an ImportEqualsDeclaration!");
} else {
  console.log("This is not an ImportEqualsDeclaration.");
}

In this example, typescript.isImportEqualsDeclaration is used to check whether the first statement in a source file is an ImportEqualsDeclaration. If it is, the function logs a message to the console indicating that it is indeed an ImportEqualsDeclaration, otherwise it logs a message saying that it is not.

Other functions in typescript

Sorted by popularity

function icon

typescript.SyntaxKind is the most popular function in typescript (82777 examples)