MCPcopy Create free account
hub / github.com/uiwjs/react-codemirror / parseLoadSpec

Function parseLoadSpec

extensions/langs/gen-langs-map.cjs:84–166  ·  view source on GitHub ↗
(loadNode)

Source from the content-addressed store, hash-verified

82}
83
84function parseLoadSpec(loadNode) {
85 // 可能是: import('pkg').then(m => m.xxx(...))
86 // 或 import('pkg').then(m => legacy(m.xxx(...)))
87 // 或 sql("Dialect")
88 // 或 直接 return legacy(m.xyz)(几乎不会,但兼容)
89 if (!loadNode) return null;
90
91 // sql("DialectName")
92 if (loadNode.type === 'CallExpression' && loadNode.callee?.name === 'sql') {
93 const dialect = litStr(loadNode.arguments[0]);
94 if (!dialect) return null;
95 addStar('@codemirror/lang-sql', 'SQL');
96 return { kind: 'sql', dialect };
97 }
98
99 // import('pkg').then(arrow)
100 if (
101 loadNode.type === 'CallExpression' &&
102 loadNode.callee?.type === 'MemberExpression' &&
103 loadNode.callee.property?.name === 'then'
104 ) {
105 const importCall = loadNode.callee.object;
106 if (
107 importCall?.type === 'CallExpression' &&
108 importCall.callee?.type === 'Import'
109 ) {
110 const modArg = importCall.arguments[0];
111 const modulePath = litStr(modArg);
112 const thenArg = loadNode.arguments[0];
113 // then(m => <expr>)
114 let body = thenArg?.type === 'ArrowFunctionExpression' ? thenArg.body : null;
115 if (!body) return null;
116
117 // legacy(m.xxx(...)) or legacy(m.xxx)
118 if (body.type === 'CallExpression' && body.callee?.name === 'legacy') {
119 needsStreamLanguage = true;
120 const inner = body.arguments[0];
121 if (inner?.type === 'MemberExpression') {
122 const symbol = inner.property.name || inner.property.value;
123 addNamed(modulePath, symbol);
124 usedSymbols.add(symbol);
125 return { kind: 'legacy', modulePath, symbol, call: false, args: [] };
126 }
127 if (inner?.type === 'CallExpression' && inner.callee.type === 'MemberExpression') {
128 const symbol = inner.callee.property.name || inner.callee.property.value;
129 const args = inner.arguments.map(a => codeFrom(a));
130 addNamed(modulePath, symbol);
131 usedSymbols.add(symbol);
132 return { kind: 'legacy', modulePath, symbol, call: true, args };
133 }
134 return null;
135 }
136
137 // m.xxx(...) 或 m.xxx
138 if (body.type === 'CallExpression' && body.callee?.type === 'MemberExpression') {
139 const symbol = body.callee.property.name || body.callee.property.value;
140 const args = body.arguments.map(a => codeFrom(a));
141 addNamed(modulePath, symbol);

Callers 1

gen-langs-map.cjsFile · 0.85

Calls 5

litStrFunction · 0.85
addStarFunction · 0.85
addNamedFunction · 0.85
codeFromFunction · 0.85
addMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…