Open yinxiaoli2007 opened 1 month ago
Sorry, this is not enough to go on without a repro sample we could run.
Also, please raise an issue in English - none of the maintainers speak Chinese, and automatic translation might lead to misunderstandings.
const acorn = require('acorn'); const code = `
// Unexpected token (ES2018 spread object )
const A = {a:1, b:2};
const A1 = {...A, c:6};
// correct (ES2018 spread array)
const C = [1,2,3];
const D = [4,5,6];
const C1 = [...C, ...D];
`; try { acorn.parse(code, { sourceType: 'script', ecmaVersion: '8', locations: true, allowReserved: true }); return true; } catch (ex) { const len = 30; console.log('...' + code.substr(ex.pos - len, len * 2) + '...'); console.log(new Array(len + 3).join('-') + '^'); console.log(ex.message); return false; }
// Run all of the above code and get the Unexpected token, but the correct thing to do is not to output anything, thanks
ecmaVersion: '8',
This needs to be 2018
not 8
if you want to use ES2018.
acornjs不支持ES2018对象扩展方式:示例 const A = {a: 1, b:2}; const B = { ...A, c:3}; 以上通过acornjs检测报语法错误