MCPcopy Create free account
hub / github.com/thetarnav/solid-devtools / jsxLocationPlugin

Function jsxLocationPlugin

packages/main/src/babel/babel.ts:263–359  ·  view source on GitHub ↗
(config: JsxLocationPluginConfig)

Source from the content-addressed store, hash-verified

261const jsx_location_attr = t.jsxIdentifier(debug.LOCATION_ATTRIBUTE_NAME)
262
263export function jsxLocationPlugin(config: JsxLocationPluginConfig): babel.PluginObj<any> {
264
265 let file_transform = false
266 let file_imported = false
267 let file_filename = ''
268 let file_program: babel.NodePath<babel.types.Program> | undefined
269
270 const project_path_ast = babel.template(
271 `globalThis.${debug.WINDOW_PROJECTPATH_PROPERTY} = %%loc%%;`)({
272 loc: t.stringLiteral(process.cwd()),
273 }
274 ) as t.Statement
275
276 const buildSetComponentLocationAst = babel.template(
277 `if (${SDT_GET_OWNER}()) ${SDT_GET_OWNER}().${debug.OWNER_LOCATION_PROP} = %%loc%%;`
278 ) as (...args: Parameters<ReturnType<typeof babel.template>>) => t.Statement
279
280 function addLocationToBody(
281 body: babel.types.BlockStatement,
282 node: t.Node,
283 ) {
284 let location = getNodeLocationAttribute(node, file_filename)
285 if (location) {
286
287 if (!file_imported) {
288 file_imported = true
289
290 file_program!.unshiftContainer('body', [
291 t.importDeclaration(
292 [t.importSpecifier(sdt_get_owner_ident, get_owner_ident)],
293 solid_js_str,
294 ),
295 ])
296 }
297
298 body.body.unshift(buildSetComponentLocationAst({loc: t.stringLiteral(location)}))
299 }
300 }
301
302 return {
303 name: '@solid-devtools/location',
304 visitor: {
305 Program(path, state) {
306
307 file_transform = false
308 file_imported = false
309 file_filename = ''
310 file_program = undefined
311
312 if (typeof state.filename === 'string') {
313 file_transform = true
314 file_filename = state.filename
315 file_program = path
316
317 // inject projectPath variable
318 file_program.node.body.push(project_path_ast)
319 }
320 },

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…