Skip to content

Commit

Permalink
Add test for import attributes for babel parser and ESM only
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalduez committed Oct 28, 2024
1 parent bbb9072 commit 2a2d4b5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
13 changes: 11 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,21 @@
*/

/**
* 1. Ensure all helpers are imported instead of inlined.
* 1. https://babeljs.io/docs/babel-generator#:~:text=importAttributesKeyword
*
* 2. Ensure all helpers are imported instead of inlined.
* See https://github.com/babel/babel/issues/9297#issuecomment-453750049
*/

module.exports = (context, options = {}) => {
let { parser = 'babel', ...envOptions } = options;

let configOpts = {
generatorOpts: {
importAttributesKeyword: 'with', // 1
},
};

let envOpts = {
bugfixes: true,
...envOptions,
Expand All @@ -45,7 +53,7 @@ module.exports = (context, options = {}) => {
corejs: 3,
helpers: true,
regenerator: true,
version: '7.26.0', // 1
version: '7.26.0', // 2
};

let presets = [
Expand All @@ -60,6 +68,7 @@ module.exports = (context, options = {}) => {
];

return {
...configOpts,
presets,
plugins,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import styles from 'styles.css' with { type: 'css' };
3 changes: 2 additions & 1 deletion test/babel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { toMatchFile } = require('jest-file-snapshot');
const preset = require('../');

const es = require('./fixtures/es');
const stage4 = require('./fixtures/stage4');
const flow = require('./fixtures/flow');
const react = require('./fixtures/react');
const regressions = require('./fixtures/regressions');
Expand All @@ -21,7 +22,7 @@ describe('babel', () => {
expect(code).toMatchFile();
});

test.each(cases)('esm > %s', (name, input) => {
test.each([...stage4, ...cases])('esm > %s', (name, input) => {
let { code } = transform(input, {
presets: [[preset, { modules: false }]],
});
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/stage4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = [
[
'Stafe 4: import attributes',
`
import styles from 'styles.css' with { type: 'css' };
`,
],
];

0 comments on commit 2a2d4b5

Please sign in to comment.