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

acornjs 不支持 ES2018对象扩展 #1322

Open
yinxiaoli2007 opened this issue Oct 22, 2024 · 3 comments
Open

acornjs 不支持 ES2018对象扩展 #1322

yinxiaoli2007 opened this issue Oct 22, 2024 · 3 comments

Comments

@yinxiaoli2007
Copy link

acornjs不支持ES2018对象扩展方式:示例
const A = {a: 1, b:2};
const B = { ...A, c:3};
以上通过acornjs检测报语法错误

@RReverser
Copy link
Member

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.

@yinxiaoli2007
Copy link
Author

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

@RReverser
Copy link
Member

ecmaVersion: '8',

This needs to be 2018 not 8 if you want to use ES2018.

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

No branches or pull requests

2 participants