-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
fix: support canonical module #5040
Changes from 3 commits
23b2626
45d3f5a
8ccc02b
b4b7066
3fbdd97
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export default 123; | ||
|
||
export const foo = 'abc'; | ||
export const bar = true; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
'use strict'; | ||
|
||
var utils = require('../../lib/utils'); | ||
const esmUtils = require('../../lib/nodejs/esm-utils'); | ||
const Path = require('node:path'); | ||
var sinon = require('sinon'); | ||
|
||
describe('lib/utils', function () { | ||
|
@@ -288,6 +290,27 @@ describe('lib/utils', function () { | |
].join('\n'); | ||
expect(stringify(expected), 'to be', actual); | ||
}); | ||
|
||
it('should represent modules', async function () { | ||
if (process.browser) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The In theory though, it probably isn't necessary to use However, it appears the current version of rollup has issues parsing that. It appears rollup is ~2 major versions out of date, so I wouldn't be surprised if it just isn't equipped to handle "modern" js syntax. I tried bumping rollup version and it was not straightforward. I'm sure someone with more rollup experience can easily knock it out, but it felt out of scope for what I was trying to achieve with this fix. |
||
// Current rollup config cannot `import()` | ||
this.skip(); | ||
return; | ||
} | ||
const expected = await esmUtils.requireOrImport( | ||
Path.join(__dirname, './fixtures/module.mjs') | ||
); | ||
const actual = [ | ||
'{', | ||
' "[Symbol.toStringTag]": "Module"', | ||
' "bar": true', | ||
' "default": 123', | ||
' "foo": "abc"', | ||
'}' | ||
].join('\n'); | ||
|
||
expect(stringify(expected), 'to be', actual); | ||
}); | ||
}); | ||
|
||
it('should canonicalize the object', function () { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With a bit more manual testing (when trying to reproduce) I think this issue may fundamentally occur anytime you are dealing with null-prototyped instances...
Which is an overall rare occurrence, but maybe this isn't the right approach?
e.g.
So while this solution works for modules, I don't think it actually solves the underlying issue