@@ -33,23 +33,39 @@ module.exports = class DojoAMDDefineDependencyParserPlugin extends AMDDefineDepe
33
33
}
34
34
35
35
apply ( parser ) {
36
- super . apply ( Object . assign ( Object . create ( parser ) , {
37
- plugin : ( expression , callback ) => {
38
- if ( expression === "call define" ) {
39
- // Augment base class implementation for "call define"
40
- parser . plugin ( expression , this . callDefine . bind ( this , callback , parser ) ) ;
41
- }
42
- }
43
- } ) ) ;
36
+ this . subclassCallDefineHandler ( parser ) ;
44
37
45
38
parser . plugin ( "call define:amd:array" , this . callDefineAmdArray . bind ( this , parser ) ) ;
46
39
47
40
parser . plugin ( "call define:amd:item" , this . callDefineAmdItem . bind ( this , parser ) ) ;
48
41
}
49
42
43
+ subclassCallDefineHandler ( parser ) {
44
+ // "Subclasses" the 'call define' handler in the base class implementation. This is a bit
45
+ // painful because the base class is not set up to support subclassing, but we manage by
46
+ // replacing the parser plugin handler for the duration of the apply call in the super
47
+ // class and then grabbing the 'call define' callback so that we can use it for our own
48
+ // 'call define' handler.
49
+ var original_plugin ;
50
+ if ( parser . hasOwnProperty ( "plugin" ) ) {
51
+ original_plugin = parser . plugin ;
52
+ }
53
+ parser . plugin = ( expression , callback ) => {
54
+ if ( expression === "call define" ) {
55
+ // Augment base class implementation for "call define"
56
+ ( original_plugin || parser . __proto__ . plugin ) . call ( parser , expression , this . callDefine . bind ( this , callback , parser ) ) ;
57
+ }
58
+ } ;
59
+ super . apply ( parser ) ;
60
+ delete parser . plugin ;
61
+ if ( original_plugin ) {
62
+ parser . plugin = original_plugin ;
63
+ }
64
+ }
65
+
50
66
callDefine ( cb , parser , expr ) {
51
67
parser . state . current . isAMD = true ;
52
- const result = cb . call ( parser , expr ) ; // invoke base class implementation
68
+ const result = cb . call ( this , expr ) ; // invoke base class implementation
53
69
/* istanbul ignore if */
54
70
if ( ! AMDDefineDependencyParserPlugin . prototype . newDefineDependency ) {
55
71
// This is pretty hacky. Earlier versions of webpack don't provide the newDefineDependency method allowing us
0 commit comments