@@ -21,43 +21,56 @@ const DojoAMDRequireItemDependency = require("./DojoAMDRequireItemDependency");
21
21
const DojoAMDRequireArrayDependency = require ( "./DojoAMDRequireArrayDependency" ) ;
22
22
const ConstDependency = require ( "webpack/lib/dependencies/ConstDependency" ) ;
23
23
const DojoAMDDefineDependency = require ( "./DojoAMDDefineDependency" ) ;
24
+ const AMDDefineDependencyParserPlugin = require ( "webpack/lib/dependencies/AMDDefineDependencyParserPlugin" ) ;
24
25
const LocalModuleDependency = require ( "webpack/lib/dependencies/LocalModuleDependency" ) ;
25
26
const LocalModulesHelpers = require ( "webpack/lib/dependencies/LocalModulesHelpers" ) ;
26
27
const AMDDefineDependency = require ( "webpack/lib/dependencies/AMDDefineDependency" ) ;
27
28
28
- module . exports = class DojoAMDDefineDependencyParserPlugin {
29
+ module . exports = class DojoAMDDefineDependencyParserPlugin extends AMDDefineDependencyParserPlugin {
29
30
constructor ( options , dojoRequire ) {
31
+ super ( { } ) ;
30
32
this . options = options ;
31
33
this . dojoRequire = dojoRequire ;
32
34
}
33
35
34
- apply ( parser ) {
35
- parser . plugin ( "call define" , ( expr ) => {
36
- if ( expr . dojoSkipFlag ) return ;
37
- expr . dojoSkipFlag = true ;
38
- parser . state . current . isAMD = true ;
39
- const result = parser . applyPluginsBailResult ( "call define" , expr ) ;
40
- delete expr . dojoSkipFlag ;
36
+ // Overrides base class implementation.
37
+ newDefineDependency ( range , arrayRange , functionRange , objectRange , namedModule ) {
38
+ return new DojoAMDDefineDependency ( range , arrayRange , functionRange , objectRange , namedModule ) ;
39
+ }
41
40
42
- if ( result ) {
43
- // This is pretty hacky. We want to avoid duplicating the implementation of the 'call define' plugin handler in
44
- // AMDDefineDependencyParserPlugin, but it doesn't provide the ability to override the define dependency object
45
- // creation so instead, we reach into the module's dependencies to find the instance of the AMDDefineDependency
46
- // object and replace it our own. There should only be one AMDDefineDependency of any given module.
47
- const deps = parser . state . current . dependencies ;
48
- for ( let i = deps . length - 1 ; i >= 0 ; i -- ) {
49
- const dep = deps [ i ] ;
50
- if ( dep instanceof AMDDefineDependency ) {
51
- const newDep = new DojoAMDDefineDependency ( dep . range , dep . arrayRange , dep . functionRange , dep . objectRange , dep . namedModule ) ;
52
- newDep . loc = dep . loc ;
53
- newDep . localModule = dep . localModule ;
54
- deps [ i ] = newDep ;
55
- break ;
56
- }
41
+ apply ( parser ) {
42
+
43
+ super . apply ( Object . assign ( Object . create ( parser ) , {
44
+ plugin : ( expression , callback ) => {
45
+ if ( expression === "call define" ) {
46
+ // Augment base class implementation for "call define"
47
+ parser . plugin ( expression , ( expr ) => {
48
+ parser . state . current . isAMD = true ;
49
+ const result = callback ( expr ) ; // invoke base class implementation
50
+ /* istanbul ignore if */
51
+ if ( ! AMDDefineDependencyParserPlugin . prototype . newDefineDependency ) {
52
+ // This is pretty hacky. Earlier versions of webpack don't provide the newDefineDependency method allowing us
53
+ // to override the object creation, so instead, we reach into the module's dependencies to find the instance
54
+ // of the AMDDefineDependency object and replace it our own. There should only be one AMDDefineDependency of
55
+ // any given module.
56
+ // The newDefineDependency method was introduced in webpack with https://github.com/webpack/webpack/pull/5783
57
+ const deps = parser . state . current . dependencies ;
58
+ for ( let i = deps . length - 1 ; i >= 0 ; i -- ) {
59
+ const dep = deps [ i ] ;
60
+ if ( dep instanceof AMDDefineDependency ) {
61
+ const newDep = this . newDefineDependency ( dep . range , dep . arrayRange , dep . functionRange , dep . objectRange , dep . namedModule ) ;
62
+ newDep . loc = dep . loc ;
63
+ newDep . localModule = dep . localModule ;
64
+ deps [ i ] = newDep ;
65
+ break ;
66
+ }
67
+ }
68
+ }
69
+ return result ;
70
+ } ) ;
57
71
}
58
72
}
59
- return result ;
60
- } ) ;
73
+ } ) ) ;
61
74
62
75
parser . plugin ( "call define:amd:array" , ( expr , param , identifiers , namedModule ) => {
63
76
if ( param . isArray ( ) ) {
0 commit comments