How to use the isExportAssignment function from typescript

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

typescript.isExportAssignment is a function that determines if a node in a TypeScript AST (Abstract Syntax Tree) is an export= assignment.

158
159
160
161
162
163
164
165
166
167
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) ||
    ts.isInterfaceDeclaration(s) ||
    ts.isModuleDeclaration(s) ||
fork icon116
star icon294
watch icon29

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

+ 18 other calls in file

How does typescript.isExportAssignment work?

typescript.isExportAssignment is a function provided by the TypeScript compiler API that determines whether a given node is an ExportAssignment node in the abstract syntax tree (AST) of a TypeScript module or script. In detail, typescript.isExportAssignment takes a TypeScript Node object as an argument and returns a boolean value indicating whether the node is an ExportAssignment node. An ExportAssignment node represents an export of a single value from a module or script, where the exported value is assigned to a variable or function name.

Ai Example

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

const source = `export = myFunction;`;
const sourceFile = ts.createSourceFile(
  "file.ts",
  source,
  ts.ScriptTarget.ESNext
);

const node = sourceFile.statements[0];

if (ts.isExportAssignment(node) && ts.isIdentifier(node.expression)) {
  console.log("Exporting function:", node.expression.text);
} else {
  console.log("Not an export assignment.");
}

In this example, we create a source file containing an export assignment (export = myFunction;). We then use typescript.isExportAssignment to check if the first statement in the source file is an export assignment. If it is, we check if the right-hand side of the assignment is an identifier (in this case, myFunction). If both conditions are true, we log a message to the console indicating that we are exporting the function. Otherwise, we log a message indicating that the node is not an export assignment.

Other functions in typescript

Sorted by popularity

function icon

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