Open cexbrayat opened 5 years ago
Parsing decorators is not enabled by default for nyc, by default we only enable parser plugins for features which are natively supported in a released version of node.js - classProperties
for example. You will need to add "parserPlugins": ["decorators"]
or "parserPlugins": ["decorators-legacy"]
to your nyc config. See https://babeljs.io/docs/en/babel-parser#plugins for a list of all possible plugins, see https://github.com/istanbuljs/istanbuljs/blob/istanbul-lib-instrument%403.3.0/packages/istanbul-lib-instrument/src/instrumenter.js#L26 for the parser plugins used by default in nyc@14.1.1.
where i will find nyc config i just need to instrument a simple .ts file with decorator . i had installed nyc and instanbul . Or there is something we need to change in Package.json of our angularApp? Please Help
@coreyfarrell
Hi, can you help me? I add "parserPlugins": ["decorators"] like this, but is does not work!!
@coreyfarrell
Hi, can you help me? I add "parserPlugins": ["decorators"] like this, but is does not work!!
look here ,maybe work for you https://github.com/istanbuljs/nyc/issues/1334#issuecomment-725369527
ok thanks
------------------ Original ------------------ From: zhangyanqi1993 <notifications@github.com> Date: Thu,Dec 24,2020 4:34 PM To: istanbuljs/istanbuljs <istanbuljs@noreply.github.com> Cc: OnTheWay111 <851462306@qq.com>, Comment <comment@noreply.github.com> Subject: Re: [istanbuljs/istanbuljs] nyc-config-typescript and decorators (#459)
I had, I believe the same problem working with istanbul (as provided by jest) and trying to use vue-class-component decorators. It was resolved by adding these plugins to my babel config
'@babel/plugin-proposal-decorators', '@babel/plugin-transform-classes'
making the full config
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset',
],
plugins: [
['@babel/plugin-proposal-decorators', { legacy: true }], '@babel/plugin-transform-classes'],
};
I found that extends
will replace parser-plugins
in loading nyc config.
So two way to solve this problem.
First one, use parser-plugins
and remove extends
from your nyc config.
"nyc": {
"parser-plugins": [
"typescript",
"decorators-legacy"
]
"all": true
}
Second one, new nyc-config.js
and extends
from this file.
'use strict';
const { parserPlugins } = require('@istanbuljs/schema').defaults.nyc;
module.exports = {
cache: false,
parserPlugins: parserPlugins.concat('typescript', 'decorators-legacy')
};
"nyc": {
"extends": "./nyc-config.js",
"all": true
}
@wyp0011 any interest in submitting a patch that adds docs to the README.md with your example?
hey All, @wyp0011 i have tried the first option that you suggested. That does instrument the .ts files with decorators but it does not work properly. It is giving the issue export is moved before decorators which gives error for compiling
Can anyone please help me with this.
same issue
I would like to confirm this is still an issue. I ran into this while trying to instrument angular component files. I was able to get them to instrument properly with @wyp0011 suggestion. This can be easily reproduce by running npx nyc instrument src/ instrumented
from angular project. You will see the instrumented folder is created. But only the typescript files without decorators are properly instrumented.
Considering a simple TS file like
src/main.ts
then trying to instrument it by running:
with the following configuration:
then the result file
instrumented/main.ts
is not instrumented.If we comment the
@Foo
decorator, then the file is instrumented again.result
instrumented/main.ts
:Am I missing something or is there an issue with decorators?