S
SolidJSβ€’11mo ago
Seventimes<3

Converting code to ES5

Hello! I need to convert my code to ES5 format and I faced such a problem that const and let variables remain in the assembled project, I expected that all variables will be converted to var, but this did not happen. This is what the assembled project looks like (1 image), I'm not sure, but almost all const and let variables were created by SolidJS This is what my Babel Loader looks like: const babelLoader = { test: /.(js|jsx|ts|tsx)$/, exclude: [options.paths.corejs], use: { loader: 'babel-loader', options: { babelrc: false, configFile: false, sourceType: 'unambiguous', presets: [ [ '@babel/preset-env', { targets: { samsung: '4', }, useBuiltIns: 'usage', corejs: '3.27', }, ], 'solid', '@babel/preset-typescript', ], plugins: getBabelPlugins(options.isDev), }, }, }; getBabelPlugins(options.isDev) returns: [ '@babel/plugin-syntax-dynamic-import', '@babel/plugin-proposal-class-properties', '@babel/plugin-proposal-object-rest-spread', '@babel/plugin-transform-block-scoping' ] My main question comes up is how can I convert const variables and let them into var within SolidJS itself? P.S. I need this because I have to support 2013 browsers. I will be glad for any hint, thanks for your attention πŸ™‚
10 Replies
Birk Skyum
Birk Skyumβ€’11mo ago
I'm not so strong at Babel, but if you use typescript you can set the target to es5, and that does remove the let/const
Trader101
Trader101β€’11mo ago
I'm curious for your use case because tbh I really don't see why you need es5
Seventimes<3
Seventimes<3β€’11mo ago
Can you please elaborate on what target you are talking about?
Birk Skyum
Birk Skyumβ€’11mo ago
TSConfig Reference - Docs on every TSConfig option
From allowJs to useDefineForClassFields the TSConfig reference includes information about all of the active compiler flags setting up a TypeScript project.
Trader101
Trader101β€’11mo ago
I mean why do you need to polyfill es6 ?
Seventimes<3
Seventimes<3β€’11mo ago
I need this because I need to support very old TVs, unfortunately you can’t update the browser on them
Trader101
Trader101β€’11mo ago
ok interesting makes sense then. It's just that in 2023 there really is no need to polyfill es6 for normal usage
Seventimes<3
Seventimes<3β€’11mo ago
Unfortunately :(, this did not help me, I think that the problem appears at the moment when the "jsxTransform" occurs and it just creates all these const and let variables
bigmistqke
bigmistqkeβ€’11mo ago
I wonder if mb the order of the presets matter? From https://github.com/babel/babel/issues/4882 :
Plugins run before Presets.
Plugin ordering is first to last.
Preset ordering is reversed (last to first).
Plugins run before Presets.
Plugin ordering is first to last.
Preset ordering is reversed (last to first).
GitHub
plugins/presets order Β· Issue #4882 Β· babel/babel
In documentation it is written: Plugins run before Presets. Plugin ordering is first to last. Preset ordering is reversed (last to first). I wrote my own plugin which works with const and let. It w...
NesCafe
NesCafeβ€’11mo ago
sometimes it can happen. for example for apps I develop at work in our organization there are very old machines. some running win XP and no way to install latest browsers there. though (with firefox) they support part of modern JS api, like let and Map, Set but it thowed me errors for something I made with Vue (I guess shadowRoot. I just defined some object to window to suppress those. because none of my components use that feature, it is just Vue internals have checks)