Mocha: 3.5.1-introduced dependency `he` breaks AMD usage

Created on 10 Sep 2017  路  2Comments  路  Source: mochajs/mocha

@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.

browser confirmed-bug

Most helpful comment

I'm just gonna hack around it.

All 2 comments

I can't actually remember why I had to write that script.

I'm just gonna hack around it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

enigmatic00 picture enigmatic00  路  3Comments

CADBOT picture CADBOT  路  3Comments

Aarbel picture Aarbel  路  3Comments

niftylettuce picture niftylettuce  路  3Comments

seelikes picture seelikes  路  3Comments