Skip to content

3.5.1-introduced dependency he breaks AMD usage #3000

@ScottFreeCode

Description

@ScottFreeCode

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

Metadata

Metadata

Labels

area: browserbrowser-specifictype: buga defect, confirmed by a maintainer

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions