-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Description
@FelixHenninger on Gitter reported that Mocha 3.5.1 gets a "Mismatched anonymous define" error from RequireJS. The following is my investigation of the issue.
Our define
-removing script uses the regex /typeof define === ['"]function['"] && define\.amd/g
but the new dependency he
uses a different, multi-line check.
Would it be possible to replace the dedefine script with a proper codemod using an AST parser and get something more like "if typeof define and define.amd are both checked in any way"?
Otherwise, I guess we could update the regex to something like /typeof\s+define\s*===?\s*['"]function['"]\s*&&\s*(?:define\.amd|typeof\s+define\.amd\s*===?\s*['"]object['"])/g
And then update it again if we ever run into Yoda-style "function" === typeof define
. Or if we ever run into typeof define.amd !== 'undefined'
. Etc.
Alternatively, we could look for a bundler, bundler flag/option or bundler plugin that handles this stuff for us. Or request that he
use the standard typeof define === 'function' && define.amd
check.