Skip to content

Commit

Permalink
fix(babel): fixed detection of export/import statements (fixes #1367) (
Browse files Browse the repository at this point in the history
…#1370)

* fix(babel): fixed detection of export/import statements (fixes #1367)

* chore: changeset
  • Loading branch information
Anber committed Oct 9, 2023
1 parent a6a15b9 commit e25e91f
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .changeset/lazy-owls-dream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@linaria/babel-preset': patch
'@linaria/shaker': patch
---

Fixed detection of export/import statements. Fixes #1367
2 changes: 1 addition & 1 deletion docs/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ module.exports = {
return false;
}
return /(?:^|\*\/|;)\s*(?:export|import)\s/m.test(code);
return /(?:^|\*\/|;|})\s*(?:export|import)\s/m.test(code);
},
action: require.resolve('@linaria/shaker'),
}
Expand Down
2 changes: 1 addition & 1 deletion examples/vite/.linariarc.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = {
return false;
}

return /(?:^|\*\/|;)\s*(?:export|import)\s/m.test(code);
return /(?:^|\*\/|;|})\s*(?:export|import)\s/m.test(code);
},
action: require.resolve('@linaria/shaker'),
},
Expand Down
2 changes: 1 addition & 1 deletion packages/babel/src/transform/helpers/loadLinariaOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default function loadLinariaOptions(
}

// If a file contains `export` or `import` keywords, we assume it's an ES-module
return /(?:^|\*\/|;)\s*(?:export|import)\s/m.test(code);
return /(?:^|\*\/|;|})\s*(?:export|import)\s/m.test(code);
},
action: require.resolve('@linaria/shaker'),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const keep =
configFile: false,
filename,
presets,
sourceType: /(?:^|\*\/|;)\s*(?:export|import)\s/m.test(formattedCode)
sourceType: /(?:^|\*\/|;|})\s*(?:export|import)\s/m.test(formattedCode)
? 'module'
: 'script',
plugins: [
Expand Down

0 comments on commit e25e91f

Please sign in to comment.