Closed ghost closed 7 years ago
Yeah, let me fix that...
Congrats on being issue #1! :tada:
Could you try the latest version and let me know if that fixes your issue? Thanks!
thanks for the quick reply, same thing though, using 1.1.3
:
~
❯ echo "// @codegen\nimport fs from 'fs';" >> foo.js
~
❯ babel --plugins=transform-es2015-modules-commonjs,codegen foo.js
SyntaxError: foo.js: Unexpected token import
undefined
~
❯ babel --plugins=transform-es2015-modules-commonjs foo.js
'use strict';
var _fs = require('fs');
var _fs2 = _interopRequireDefault(_fs);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
Hmm.... Weird! Could you add a test case in the tests? That would help us figure out what's going on...
I don't see any tests? nps
(not sure what that is?) throws an err saying no config is found. And side-note, yarn is telling me babel-register
conflicts in dependencies
vs devDependencies
:)
Ah yes, if you could remove babel-register
from devDependencies
that'd be awesome.
The tests are here. Probably best to just put it here at the bottom. Something like:
'pragma on a file can handle ES6 imports': {
skip: true, // until we get this test passing
code: `
// codegen
import fs from 'fs'
`
}
That make sense?
Oh, and you can run the tests in watch mode with npm start test.watch
I get
SyntaxError: Unexpected token, expected ";" (2:84)
1 | /* @babel/template */;
> 2 | {lastNameClose: ({ lastNameClose }) => new Date(lastNameClose),lastPervoteBucketFill: ({ lastPervoteBucketFill }) => new Date(lastPervoteBucketFill)}
| ^
Trying to do so:
export const GlobalStatus = {
...codegen`module.exports = '{' + ['lastNameClose', 'lastPervoteBucketFill'].map(field =>
\`\${field}: ({ \${field} }) => new Date(\${field})\`
).join(',') + '}'`,
};
// to
export const GlobalStatus = {
...{
lastNameClose: ({ lastNameClose }) => new Date(lastNameClose),
lastPervoteBucketFill: ({ lastPervoteBucketFill }) => new Date(lastPervoteBucketFill),
},
};
babel-plugin-codegen no longer runs your codegen-source code through babel. It must be written in code that's supported natively in the version of node you're running.
In short, I'm having this issue:
the above throws
unexpected token import
, if I remove the// @codegen
line it works fine. My babel plugins are:I'd expect that
codegen
would get code transformed fromtransform-es2015-modules-commonjs
and then execute that, but it doesn't seem to be the case. Thoughts?