-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot import library with ES Modules #79
Comments
idk man; |
hey @knownasilya,
so possible options:
i personally don't care for ES Modules, but if anyone wants to contribute here i'm keen. |
|
I'd strongly urge people to steer clear from |
agreed, the syntax they came up with is pretty ridiculous but oh well haha |
@tj thanks for the tip |
@tj approach didn't work for me :( |
Based on the outputs of rollup and babel for this file: import sf from 'sheetify';
const loginCss = sf`
.login {
position: absolute;
width: 100%;
height: 100%;
}
`;
console.log(loginCss); Outputs before transform: (rollup) 'use strict';
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var sf = _interopDefault(require('sheetify'));
const loginCss = sf`
.login {
position: absolute;
width: 100%;
height: 100%;
}
`;
console.log(loginCss); (babel-cli) 'use strict';
var _sheetify = require('sheetify');
var _sheetify2 = _interopRequireDefault(_sheetify);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const loginCss = _sheetify2.default`
.login {
position: absolute;
width: 100%;
height: 100%;
}
`;
console.log(loginCss); One possible patch for the transform.js could be something like: transform.js --- left
+++ right
@@ -79,7 +79,18 @@
node.arguments.length === 1 &&
node.arguments[0].value === 'sheetify') {
node.update('0')
- mname = node.parent.id.name
+ // rollup
+ if (node.parent.callee && node.parent.callee.name === '_interopDefault') {
+ mname = node.parent.callee.parent.parent.id.name;
+ }
+ if (node.parent.id) {
+ // babel
+ if (node.parent.id.name === '_sheetify') {
+ mname = '_sheetify2';
+ }
+ // commonjs
+ mname = node.parent.id.name;
+ }
}
}
@@ -91,7 +102,9 @@
function extractTemplateNodes (node) {
if (node.type !== 'TemplateLiteral') return
if (!node.parent || !node.parent.tag) return
- if (node.parent.tag.name !== mname) return
+ if (node.parent.tag.name !== mname &&
+ !node.parent.tag.object &&
+ node.parent.tag.object.name !== mname) return
const css = [ node.quasis.map(cooked) ]
.concat(node.expressions.map(expr)).join('').trim()
|
if this should be implemented at all, or live under an option, or be a different project altogether is open for discussion ;) |
the first solution proposed by @ahdinosaur
Might be the simple solution, however acorn wont like files mixing import and require. ( --- left
+++ right
@@ -58,8 +58,8 @@
var ast
try {
- const tmpAst = falafel(src, { ecmaVersion: 6 }, identifyModuleName)
- ast = falafel(tmpAst.toString(), { ecmaVersion: 6 }, extractNodes)
+ const tmpAst = falafel(src, { ecmaVersion: 6, allowImportExportEverywhere: true }, identifyModuleName)
+ ast = falafel(tmpAst.toString(), { ecmaVersion: 6, allowImportExportEverywhere: true }, extractNodes)
} catch (err) {
return self.emit('error', err)
} |
@yoshuawuyts What do you think about the last proposed solution of @fczuardi? I think it's a good compromise for only a small change. |
If you maintain something that uses ES Modules you can just fork https://github.com/chinedufn/sheetify/blob/master/transform.js#L82-L91 Then depend on your fork. Assuming you have no other reasonable option and you're cool with all that comes with depending on a own fork instead of mainline.
|
I'm using "babel-preset-es2015": "^6.9.0" with "babelify": "^7.3.0", and
import sf from 'sheetify';
doesn't work (5.0.3 of sheetify). I get:The text was updated successfully, but these errors were encountered: