MCPcopy Index your code
hub / github.com/nodejs/node / createSystemModuleBody

Function createSystemModuleBody

test/fixtures/snapshot/typescript.js:105957–106042  ·  view source on GitHub ↗

* Adds the statements for the module body function for the source file. * * @param node The source file for the module. * @param dependencyGroups The grouped dependencies of the module.

(node, dependencyGroups)

Source from the content-addressed store, hash-verified

105955 * @param dependencyGroups The grouped dependencies of the module.
105956 */
105957 function createSystemModuleBody(node, dependencyGroups) {
105958 // Shape of the body in system modules:
105959 //
105960 // function (exports) {
105961 // <list of local aliases for imports>
105962 // <hoisted variable declarations>
105963 // <hoisted function declarations>
105964 // return {
105965 // setters: [
105966 // <list of setter function for imports>
105967 // ],
105968 // execute: function() {
105969 // <module statements>
105970 // }
105971 // }
105972 // <temp declarations>
105973 // }
105974 //
105975 // i.e:
105976 //
105977 // import {x} from 'file1'
105978 // var y = 1;
105979 // export function foo() { return y + x(); }
105980 // console.log(y);
105981 //
105982 // Will be transformed to:
105983 //
105984 // function(exports) {
105985 // function foo() { return y + file_1.x(); }
105986 // exports("foo", foo);
105987 // var file_1, y;
105988 // return {
105989 // setters: [
105990 // function(v) { file_1 = v }
105991 // ],
105992 // execute(): function() {
105993 // y = 1;
105994 // console.log(y);
105995 // }
105996 // };
105997 // }
105998 var statements = [];
105999 // We start a new lexical environment in this function body, but *not* in the
106000 // body of the execute function. This allows us to emit temporary declarations
106001 // only in the outer module body and not in the inner one.
106002 startLexicalEnvironment();
106003 // Add any prologue directives.
106004 var ensureUseStrict = ts.getStrictOptionValue(compilerOptions, "alwaysStrict") || (!compilerOptions.noImplicitUseStrict && ts.isExternalModule(currentSourceFile));
106005 var statementOffset = factory.copyPrologue(node.statements, statements, ensureUseStrict, topLevelVisitor);
106006 // var __moduleName = context_1 && context_1.id;
106007 statements.push(factory.createVariableStatement(
106008 /*modifiers*/ undefined, factory.createVariableDeclarationList([
106009 factory.createVariableDeclaration("__moduleName",
106010 /*exclamationToken*/ undefined,
106011 /*type*/ undefined, factory.createLogicalAnd(contextObject, factory.createPropertyAccessExpression(contextObject, "id")))
106012 ])));
106013 // Visit the synthetic external helpers import declaration if present
106014 ts.visitNode(moduleInfo.externalHelpersImportDeclaration, topLevelVisitor, ts.isStatement);

Callers 1

transformSourceFileFunction · 0.85

Calls 6

startLexicalEnvironmentFunction · 0.85
endLexicalEnvironmentFunction · 0.85
addExportStarIfNeededFunction · 0.85
createSettersArrayFunction · 0.85
addRangeMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…