remove ES5 constraint

pull/1348/head
Rich Harris 7 years ago
parent 470eacf9d4
commit 34d2fbfa58

@ -29,7 +29,7 @@
"plugin:import/warnings" "plugin:import/warnings"
], ],
"parserOptions": { "parserOptions": {
"ecmaVersion": 6, "ecmaVersion": 9,
"sourceType": "module" "sourceType": "module"
}, },
"settings": { "settings": {

@ -9,18 +9,13 @@ fs.readdirSync(__dirname).forEach(file => {
const source = fs.readFileSync(path.join(__dirname, file), 'utf-8'); const source = fs.readFileSync(path.join(__dirname, file), 'utf-8');
const ast = acorn.parse(source, { const ast = acorn.parse(source, {
ecmaVersion: 6, ecmaVersion: 9,
sourceType: 'module' sourceType: 'module'
}); });
ast.body.forEach(node => { ast.body.forEach(node => {
if (node.type !== 'ExportNamedDeclaration') return; if (node.type !== 'ExportNamedDeclaration') return;
// check no ES6+ slipped in
acorn.parse(source.slice(node.declaration.start, node.end), {
ecmaVersion: 5
});
const declaration = node.declaration; const declaration = node.declaration;
if (!declaration) return; if (!declaration) return;

@ -74,38 +74,6 @@ describe("runtime", () => {
compileOptions.immutable = config.immutable; compileOptions.immutable = config.immutable;
compileOptions.parser = v2 ? 'v2' : 'v1'; compileOptions.parser = v2 ? 'v2' : 'v1';
// check that no ES2015+ syntax slipped in
if (!config.allowES2015) {
try {
const source = fs.readFileSync(
`test/runtime/samples/${dir}/main${v2 ? '-v2' : ''}.html`,
"utf-8"
);
const { code } = compile(source, compileOptions);
const startIndex = code.indexOf("function create_main_fragment"); // may change!
if (startIndex === -1) throw new Error("missing create_main_fragment");
const endIndex = code.lastIndexOf("export default");
const es5 =
code.slice(0, startIndex).split('\n').map(x => spaces(x.length)).join('\n') +
code.slice(startIndex, endIndex);
acorn.parse(es5, { ecmaVersion: 5 });
if (/Object\.assign/.test(es5)) {
throw new Error(
"cannot use Object.assign in generated code, as it is not supported everywhere"
);
}
} catch (err) {
failed.add(dir);
if (err.frame) {
console.error(chalk.red(err.frame)); // eslint-disable-line no-console
}
showOutput(cwd, { shared, format: 'cjs', store: !!compileOptions.store, v2 }, compile); // eslint-disable-line no-console
throw err;
}
}
Object.keys(require.cache) Object.keys(require.cache)
.filter(x => x.endsWith(".html")) .filter(x => x.endsWith(".html"))
.forEach(file => { .forEach(file => {

@ -7,7 +7,6 @@ const tasks = [
export default { export default {
'skip-ssr': true, 'skip-ssr': true,
allowES2015: true,
data: { data: {
tasks, tasks,

@ -1,6 +1,4 @@
export default { export default {
allowES2015: true,
data: { data: {
numbers: [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] numbers: [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
}, },

@ -5,23 +5,6 @@ import { parse } from 'acorn';
import { Store } from '../../store.js'; import { Store } from '../../store.js';
describe('store', () => { describe('store', () => {
it('is written in ES5', () => {
const source = fs.readFileSync('store.js', 'utf-8');
const ast = parse(source, {
sourceType: 'module'
});
const magicString = new MagicString(source);
ast.body.forEach(node => {
if (/^(Im|Ex)port/.test(node.type)) magicString.remove(node.start, node.end);
});
parse(magicString.toString(), {
ecmaVersion: 5
});
});
describe('get', () => { describe('get', () => {
it('gets a specific key', () => { it('gets a specific key', () => {
const store = new Store({ const store = new Store({

Loading…
Cancel
Save