Hi, just running into a small issue when using svelte-intl-precompile, when you have a locale file that declares a default export, it throws an error when the default export is a node of type "Identifier" (e.g. const locale = {}; export default locale; but works as expected when the node is the type "ObjectExpression" (e.g. export default {}).
[svelte-intl-precompile] Could not load $locales/en (imported by $locales): /packages/app/src/locales/en.js: Cannot read propert
ies of undefined (reading 'forEach')
> Could not load $locales/en (imported by $locales): /packages/app/src/locales/en.js: Cannot read properties of undefined (readi
ng 'forEach')
at flattenObjectProperties (/node_modules/.pnpm/babel-plugin-precompile-intl@0.3.0/node_modules/babel-plugin-precompile-intl
/src/index.js:169:32)
at PluginPass.ExportDefaultDeclaration (/Users/connor/wk/ui/main/node_modules/.pnpm/babel-plugin-precompile-intl@0.3.0/node_modules/babel-plugin-pre
compile-intl/src/index.js:216:11)
at newFn (/node_modules/.pnpm/@babel+traverse@7.17.3/node_modules/@babel/traverse/lib/visitors.js:177:21)
at NodePath._call (/node_modules/.pnpm/@babel+traverse@7.17.3/node_modules/@babel/traverse/lib/path/context.js:53:20)
at NodePath.call (/node_modules/.pnpm/@babel+traverse@7.17.3/node_modules/@babel/traverse/lib/path/context.js:40:17)
at NodePath.visit (/node_modules/.pnpm/@babel+traverse@7.17.3/node_modules/@babel/traverse/lib/path/context.js:100:31)
at TraversalContext.visitQueue (/node_modules/.pnpm/@babel+traverse@7.17.3/node_modules/@babel/traverse/lib/context.js:103:1
6)
at TraversalContext.visitMultiple (/node_modules/.pnpm/@babel+traverse@7.17.3/node_modules/@babel/traverse/lib/context.js:72
:17)
at TraversalContext.visit (/node_modules/.pnpm/@babel+traverse@7.17.3/node_modules/@babel/traverse/lib/context.js:129:19)
at traverseNode (/node_modules/.pnpm/@babel+traverse@7.17.3/node_modules/@babel/traverse/lib/traverse-node.js:24:17)
This is the babel node that throws the error, notice declaration: Node { type: 'Identifier' , ... } is missing the "properties" property?
Hi, just running into a small issue when using
svelte-intl-precompile
, when you have a locale file that declares a default export, it throws an error when the default export is a node of type "Identifier" (e.g.const locale = {}; export default locale;
but works as expected when the node is the type "ObjectExpression" (e.g.export default {}
).Here's a minimal reproduction: https://stackblitz.com/edit/sveltejs-kit-template-default-jm1kse?file=locales/en.js
Here's the error
This is the babel node that throws the error, notice
declaration: Node { type: 'Identifier' , ... }
is missing the "properties" property?Works when node type is "ObjectExpression", because it has the "properties" property is an array.
Would be best to handle both types, but just noting it in documentation someplace (website or readme) would be good too.
Thank you :)