Description
Version
3.0.0-rc.3
Reproduction link
https://github.com/oncomouse/vue-cli-plugin-injectImports-bug
Steps to reproduce
git clone https://github.com/oncomouse/vue-cli-plugin-injectImports-bug
vue create -d vue-project
cd vue-project
npm i ../vue-cli-plugin-injectImports-bug
vue invoke @oncomouse/vue-cli-plugin-injectImports-bug
What is expected?
The generator should add import Vue from 'vue';
at line 34 in src/components/HelloWorld.vue.
What is actually happening?
The following error is reproduced:
ERROR Error: Line 34: Unexpected token :
Error: Line 34: Unexpected token :
at ErrorHandler.constructError (/usr/local/lib/node_modules/@vue/cli/node_modules/esprima/dist/esprima.js:5004:22)
at ErrorHandler.createError (/usr/local/lib/node_modules/@vue/cli/node_modules/esprima/dist/esprima.js:5020:27)
at JSXParser.Parser.unexpectedTokenError (/usr/local/lib/node_modules/@vue/cli/node_modules/esprima/dist/esprima.js:1985:39)
at JSXParser.Parser.throwUnexpectedToken (/usr/local/lib/node_modules/@vue/cli/node_modules/esprima/dist/esprima.js:1995:21)
at JSXParser.expectJSX (/usr/local/lib/node_modules/@vue/cli/node_modules/esprima/dist/esprima.js:712:19)
at JSXParser.reenterJSX (/usr/local/lib/node_modules/@vue/cli/node_modules/esprima/dist/esprima.js:480:15)
at JSXParser.parseJSXExpressionContainer (/usr/local/lib/node_modules/@vue/cli/node_modules/esprima/dist/esprima.js:863:19)
at JSXParser.parseJSXChildren (/usr/local/lib/node_modules/@vue/cli/node_modules/esprima/dist/esprima.js:878:39)
at JSXParser.parseComplexJSXElement (/usr/local/lib/node_modules/@vue/cli/node_modules/esprima/dist/esprima.js:890:52)
at JSXParser.parseJSXElement (/usr/local/lib/node_modules/@vue/cli/node_modules/esprima/dist/esprima.js:930:28)
For a plugin I'm writing, I'm trying to us GeneratorAPI's injectImports() to add an import statement to a .vue file (src/components/HelloWorld.js in this case). The syntax of the component file is causing Esprima to throw an error when I try to do this (which is to be expected, as the file is neither JS nor JSX). This may be by design, but I think it would be useful to be able to inject into .vue files or to note that this isn't possible.