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

Function transform

packages/main/src/vite/vite.ts:97–137  ·  view source on GitHub ↗
(source, id, transformOptions)

Source from the content-addressed store, hash-verified

95 return code
96 },
97 async transform(source, id, transformOptions) {
98
99 // production and server should be disabled
100 if (transformOptions?.ssr) return
101
102 const extname = get_extname(id)
103
104 if (!['mjs', 'cjs', 'cts', 'mts', 'js', 'jsx', 'ts', 'tsx'].includes(extname)) return
105
106 const is_jsx = extname === 'jsx' || extname === 'tsx'
107 const plugins: PluginItem[] = []
108
109 // plugins that should only run on .tsx/.jsx files in development
110 if (jsx_location_plugin_config != null && is_jsx) {
111 plugins.push(babel.jsxLocationPlugin(jsx_location_plugin_config))
112 }
113 if (options.autoname) {
114 plugins.push(babel.namePlugin)
115 }
116
117 if (plugins.length === 0) {
118 return {code: source}
119 }
120
121 // babel doesn't work with typescript by default
122 plugins.unshift([plugin_ts_syntax, {isTSX: is_jsx}])
123
124 const result = await transformAsync(source, {
125 babelrc: false,
126 configFile: false,
127 root: project_root,
128 filename: id,
129 sourceFileName: id,
130 sourceMaps: true,
131 plugins: plugins,
132 })
133
134 if (result) {
135 return {code: result.code!, map: result.map!}
136 }
137 },
138 }
139}

Callers

nothing calls this directly

Calls 1

get_extnameFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…