@@ -34,17 +34,23 @@ export default function importAssertions(options = {}) {
34
34
35
35
// we want to make sure acorn knows how to parse import assertions
36
36
37
- // The acorn parser only implements stage 4 js proposals.
37
+ // For rollup v2 or v2,
38
+ // the acorn parser only implements stage 4 js proposals.
38
39
// At the moment "import assertions" are a stage 3 proposal and as such
39
40
// cannot be parsed by acorn. However, there exist a plugin,
40
41
// so we inject the adhoc plugin into the options
41
42
// by leveraging https://rollupjs.org/guide/en/#acorninjectplugins
42
43
options ( opts ) {
43
- // eslint-disable-next-line no-param-reassign
44
- opts . acornInjectPlugins = opts . acornInjectPlugins || [ ] ;
45
- if ( ! opts . acornInjectPlugins . includes ( acornImportAssertions ) ) {
46
- opts . acornInjectPlugins . push ( acornImportAssertions ) ;
44
+ const rollupMajorVersion = Number ( this . meta . rollupVersion . split ( '.' ) [ 0 ] ) ;
45
+
46
+ if ( rollupMajorVersion <= 3 ) {
47
+ // eslint-disable-next-line no-param-reassign
48
+ opts . acornInjectPlugins = opts . acornInjectPlugins || [ ] ;
49
+ if ( ! opts . acornInjectPlugins . includes ( acornImportAssertions ) ) {
50
+ opts . acornInjectPlugins . push ( acornImportAssertions ) ;
51
+ }
47
52
}
53
+
48
54
return opts ;
49
55
} ,
50
56
@@ -63,9 +69,11 @@ export default function importAssertions(options = {}) {
63
69
64
70
const moduleInfo = self . getModuleInfo ( id ) ;
65
71
const assertType =
66
- 'assertions' in moduleInfo
72
+ 'attributes' in moduleInfo
73
+ ? moduleInfo . attributes . type /* rollup v4 */
74
+ : 'assertions' in moduleInfo
67
75
? moduleInfo . assertions . type /* rollup v3 */
68
- : moduleInfo . meta [ 'import-assertions' ] ;
76
+ : moduleInfo . meta [ 'import-assertions' ] ; /* rollup v<=2 */
69
77
70
78
if ( assertType === 'json' )
71
79
// from @rollup /plugin-json
0 commit comments