MCPcopy Create free account
hub / github.com/nodejs/node / convertExportsPropertyAssignment

Function convertExportsPropertyAssignment

test/fixtures/snapshot/typescript.js:152354–152370  ·  view source on GitHub ↗
(_a, sourceFile, changes)

Source from the content-addressed store, hash-verified

152352 return makeExportDeclaration([ts.factory.createExportSpecifier(/*isTypeOnly*/ false, /*propertyName*/ undefined, "default")], moduleSpecifier);
152353 }
152354 function convertExportsPropertyAssignment(_a, sourceFile, changes) {
152355 var left = _a.left, right = _a.right, parent = _a.parent;
152356 var name = left.name.text;
152357 if ((ts.isFunctionExpression(right) || ts.isArrowFunction(right) || ts.isClassExpression(right)) && (!right.name || right.name.text === name)) {
152358 // `exports.f = function() {}` -> `export function f() {}` -- Replace `exports.f = ` with `export `, and insert the name after `function`.
152359 changes.replaceRange(sourceFile, { pos: left.getStart(sourceFile), end: right.getStart(sourceFile) }, ts.factory.createToken(93 /* SyntaxKind.ExportKeyword */), { suffix: " " });
152360 if (!right.name)
152361 changes.insertName(sourceFile, right, name);
152362 var semi = ts.findChildOfKind(parent, 26 /* SyntaxKind.SemicolonToken */, sourceFile);
152363 if (semi)
152364 changes.delete(sourceFile, semi);
152365 }
152366 else {
152367 // `exports.f = function g() {}` -> `export const f = function g() {}` -- just replace `exports.` with `export const `
152368 changes.replaceNodeRangeWithNodes(sourceFile, left.expression, ts.findChildOfKind(left, 24 /* SyntaxKind.DotToken */, sourceFile), [ts.factory.createToken(93 /* SyntaxKind.ExportKeyword */), ts.factory.createToken(85 /* SyntaxKind.ConstKeyword */)], { joiner: " ", suffix: " " });
152369 }
152370 }
152371 // TODO: GH#22492 this will cause an error if a change has been made inside the body of the node.
152372 function convertExportsDotXEquals_replaceNode(name, exported, useSitesToUnqualify) {
152373 var modifiers = [ts.factory.createToken(93 /* SyntaxKind.ExportKeyword */)];

Callers 1

convertNamedExportFunction · 0.85

Calls 1

deleteMethod · 0.65

Tested by

no test coverage detected