Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error loading module when Array prototype is modified #58

Closed
Sembiance opened this issue Sep 11, 2017 · 1 comment
Closed

Error loading module when Array prototype is modified #58

Sembiance opened this issue Sep 11, 2017 · 1 comment

Comments

@Sembiance
Copy link

@Sembiance Sembiance commented Sep 11, 2017

The following code produces an error when loading css-tree:

"use strict";
Array.prototype.anything = function() { };
require("css-tree");

The error produced:

/tmp/node_modules/css-tree/lib/lexer/structure.js:112
                throw new Error('Wrong value in `' + name + '` structure definition');
                ^

Error: Wrong value in `CDC` structure definition
    at processStructure (/tmp/node_modules/css-tree/lib/lexer/structure.js:112:23)
    at getStructureFromConfig (/tmp/node_modules/css-tree/lib/lexer/structure.js:134:39)
    at Lexer (/tmp/node_modules/css-tree/lib/lexer/Lexer.js:125:35)
    at createSyntax (/tmp/node_modules/css-tree/lib/syntax/create.js:70:20)
    at Object.exports.create (/tmp/node_modules/css-tree/lib/syntax/create.js:81:12)
    at Object.<anonymous> (/tmp/node_modules/css-tree/lib/syntax/index.js:14:38)
    at Module._compile (module.js:573:30)
    at Object.Module._extensions..js (module.js:584:10)
    at Module.load (module.js:507:32)
    at tryModuleLoad (module.js:470:12)

Some modules out there may add additional functions to the Array prototype and this then prevents the css-tree module from being loaded.

Can be fixed by adding this line to css-tree/lib/lexer/structure.js on line 102:

if(!structure.hasOwnProperty(key)) { continue; }

Not sure exactly what the structure.js code is doing here, so not sure if the proposed fix is safe for your code, but my hunch says it is.

@lahmatiy lahmatiy closed this in b5017af Sep 11, 2017
@lahmatiy
Copy link
Member

@lahmatiy lahmatiy commented Sep 11, 2017

Nice finding! Thank you for the report.
Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.