Spread Operator bug?
See original GitHub issueBug.
I’m requiring a file with the following statement (using require
because I’ll be using both on node and browser):
const user = require('skeemas/complexUser');
The working complexUser
:
const user = require('./user');
const individual = require('./individual');
const company = require('./company');
const credential = require('./credential');
const complexUser = {
type: {
type: 'text',
values: ['individual', 'company'],
predefined: 'individual',
}
}
Object.assign(complexUser, user, individual, company, credential);
module.exports = complexUser;
The NOT working complexUser
:
const user = require('./user');
const individual = require('./individual');
const company = require('./company');
const credential = require('./credential');
module.exports = {
type: {
type: 'text',
values: ['individual', 'company'],
predefined: 'individual',
},
...user,
...individual,
...company,
...credential,
};
Error thrown by Webpack:
ERROR in ./node_modules/skeemas/complexUser.js
Module parse failed: /Users/damz/Desktop/repmemo/node_modules/skeemas/complexUser.js Unexpected token (12:4)
You may need an appropriate loader to handle this file type.
| predefined: 'individual',
| },
| ...user,
| ...individual,
| ...company,
@ ./models/user.js 1:13-43
@ ./models/userPresenter.js
@ ./apps/user/components/profileForm.js
@ ./apps/user/router.js
@ ./apps/user/index.js
Both babel and node do not complain if running the file directly (https://goo.gl/E3ZSEq).
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:38 (8 by maintainers)
Top Results From Across the Web
Spread Operator Bug or Did I Miss Something? - JavaScript
Hey, all! First post! Anyway, I am stuck on this particular problem. I feel like my answer is doing what is asked in...
Read more >Spread Operator Bug #130266 - microsoft/vscode - GitHub
Spread Operator Bug #130266 ... It autocompletes with some random function or text when the spread operator is typed (...).
Read more >Object spread operator throw error in microsoft edge
I try to use cdn.polyfill.io and https://babeljs.io/docs/en/babel-polyfill but no luck. What i can do to run my webpack code in microsoft edge?
Read more >1644987 - Object spread syntax in console not working
Bugbug thinks this bug should belong to this component, but please revert this change in case of error. Component: Untriaged → Console.
Read more >Spread operator shows syntax error with ECMA 6 and ...
The spread operator is valid syntactically. This code actually works even though it shows errors throughout the module and project. What happens instead?...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
As I said spread operator is stage-3. So you don’t have it in your config. Please, help yourself and use such plugins directly. stage presets are changed too often.
The webpack parser will need to be updated to handle the syntax as well, since it has special-case code for each node type. I recently wrote a (hacky) webpack plugin that patches the parser to handle the syntax, so the updated “walk” functions in the code are approximately what will need to be changed. But it should be an easy fix, I think.
https://github.com/alangpierce/sucrase/tree/master/integrations/webpack-object-rest-spread-plugin https://github.com/alangpierce/sucrase/blob/master/integrations/webpack-object-rest-spread-plugin/src/index.ts#L111