{
"type": "ExpressionStatement",
"start": 21948,
"end": 22029,
"expression": {
"type": "LogicalExpression",
"start": 21948,
"end": 22028,
"left": {
"type": "LogicalExpression",
"start": 21948,
"end": 21985,
"left": {
"type": "BinaryExpression",
"start": 21948,
"end": 21965,
"left": {
"type": "UnaryExpression",
"start": 21948,
"end": 21961,
"operator": "typeof",
"prefix": true,
"argument": {
"type": "Identifier",
"start": 21955,
"end": 21961,
"name": "window"
}
},
"operator": "<",
"right": {
"type": "Literal",
"start": 21962,
"end": 21965,
"value": "u",
"raw": "\"u\""
}
},
"operator": "&&",
"right": {
"type": "BinaryExpression",
"start": 21967,
"end": 21985,
"left": {
"type": "UnaryExpression",
"start": 21967,
"end": 21981,
"operator": "typeof",
"prefix": true,
"argument": {
"type": "Identifier",
"start": 21974,
"end": 21981,
"name": "require"
}
},
"operator": "<",
"right": {
"type": "Literal",
"start": 21982,
"end": 21985,
"value": "u",
"raw": "\"u\""
}
}
},
"operator": "&&",
"right": {
"type": "AssignmentExpression",
"start": 21988,
"end": 22027,
"operator": "=",
"left": {
"type": "MemberExpression",
"start": 21988,
"end": 22001,
"object": {
"type": "Identifier",
"start": 21988,
"end": 21994,
"name": "window"
},
"property": {
"type": "Identifier",
"start": 21995,
"end": 22001,
"name": "Buffer"
},
"computed": false,
"optional": false
},
"right": {
"type": "MemberExpression",
"start": 22002,
"end": 22027,
"object": {
"type": "CallExpression",
"start": 22002,
"end": 22020,
"callee": {
"type": "Identifier",
"start": 22002,
"end": 22009,
"name": "require"
},
"arguments": [
{
"type": "Literal",
"start": 22010,
"end": 22019,
"value": "buffer/",
"raw": "\"buffer/\""
}
],
"optional": false
},
"property": {
"type": "Identifier",
"start": 22021,
"end": 22027,
"name": "Buffer"
},
"computed": false,
"optional": false
}
}
}
}
Hi again! 👋
As I mentioned before, thanks for your work on this project! 🙂
Today I used patch-package to patch import-manager@0.4.2 for the project I'm working on (source code for the plugin configuration here).
It seems
requirestatements that don't match the expected pattern of declaration and instantiation in one expression (e.g.typeof window<"u"&&typeof require<"u"&&(window.Buffer=require("buffer/").Buffer);) cause an error that closes the program and fails to build:Essentially, it seems that
core.js's#cjsNodeToUnitassumes the acorn node will be a straight-forward expression with declaration and instantiation without any complexity (e.g.var name = require('mod');). However, I just received the error when#cjsNodeToUnitwas trying to parse the node when thecodevariable was set totypeof window<"u"&&typeof require<"u"&&(window.Buffer=require("buffer/").Buffer);(I think some dependency of mine was trying to polyfillBuffer). I stringified thenode, whose contents follow in the dropdown:JSON.stringify(node, null, 2)
{ "type": "ExpressionStatement", "start": 21948, "end": 22029, "expression": { "type": "LogicalExpression", "start": 21948, "end": 22028, "left": { "type": "LogicalExpression", "start": 21948, "end": 21985, "left": { "type": "BinaryExpression", "start": 21948, "end": 21965, "left": { "type": "UnaryExpression", "start": 21948, "end": 21961, "operator": "typeof", "prefix": true, "argument": { "type": "Identifier", "start": 21955, "end": 21961, "name": "window" } }, "operator": "<", "right": { "type": "Literal", "start": 21962, "end": 21965, "value": "u", "raw": "\"u\"" } }, "operator": "&&", "right": { "type": "BinaryExpression", "start": 21967, "end": 21985, "left": { "type": "UnaryExpression", "start": 21967, "end": 21981, "operator": "typeof", "prefix": true, "argument": { "type": "Identifier", "start": 21974, "end": 21981, "name": "require" } }, "operator": "<", "right": { "type": "Literal", "start": 21982, "end": 21985, "value": "u", "raw": "\"u\"" } } }, "operator": "&&", "right": { "type": "AssignmentExpression", "start": 21988, "end": 22027, "operator": "=", "left": { "type": "MemberExpression", "start": 21988, "end": 22001, "object": { "type": "Identifier", "start": 21988, "end": 21994, "name": "window" }, "property": { "type": "Identifier", "start": 21995, "end": 22001, "name": "Buffer" }, "computed": false, "optional": false }, "right": { "type": "MemberExpression", "start": 22002, "end": 22027, "object": { "type": "CallExpression", "start": 22002, "end": 22020, "callee": { "type": "Identifier", "start": 22002, "end": 22009, "name": "require" }, "arguments": [ { "type": "Literal", "start": 22010, "end": 22019, "value": "buffer/", "raw": "\"buffer/\"" } ], "optional": false }, "property": { "type": "Identifier", "start": 22021, "end": 22027, "name": "Buffer" }, "computed": false, "optional": false } } } }It appears that there are no declarations in the statement, so
node.declarationsisundefined. When#cjsNodeToUnitaccesses that property, it throws the error.acornparses the expression withoperator: '&&'and the actual assignment of the import (where it should haveoperator: '=') is nested inlefts andrights.Fortunately for my current use case, I don't need to do any modification of this particular import statement, so I made a quick patch that essentially ignores the problematic line. However, I suggest a better long-term solution would be to traverse the
nodeto find theoperator: '='and operate on that (accounting in any case fornode.declarationsbeingundefined).Some other examples of different kinds of
requires that likely don't match the expected pattern follow:Here is the diff that solved my problem:
Thank you again for all your hard work on this awesome library!
This issue body was partially generated by patch-package.