WarnerHooh / babel-plugin-parameter-decorator

Function parameter decorator transform plugin for babel v7, just like typescript.
34 stars 9 forks source link

Only some parameter decorator effect! #15

Closed pxr89 closed 4 years ago

pxr89 commented 4 years ago

as said in title: Only some effect when you use multi parameter decorator in a class function.

this is my parameter Decorator code

export function ReportParams(key: string) {

    console.log("ReportParams --------------load")

    return function (target: any, funcName: string, index: number) {

        console.log("ReportParams-------------start",funcName, index, key);

    }

}

used:

@Report('reportTable')

    public reportTest(

        @ReportParams('key1')  key1: string = '',

        @ReportParams('key2')  key2: string = '',

        @ReportParams('key3') key3: string = '',

        @ReportParams('key4')  key4: string = '',

        @ReportParams('key5') key5: number = 0,

        @ReportParams('key6') key6: string = ''

    ): void {

        console.log(TAG,'reportTest')

    }

Here is the log when I run the code:

12-18 13:57:04.394  1330 10808 I ReactNativeJS: ReportParams --------------load

12-18 13:57:04.395  1330 10808 I ReactNativeJS: 'ReportParams-------------start', 'reportTest', 4, 'key5'

12-18 13:57:04.395  1330 10808 I ReactNativeJS: ReportParams --------------load

12-18 13:57:04.395  1330 10808 I ReactNativeJS: 'ReportParams-------------start', 'reportTest', 1, 'key2'

that means only 'key2' and 'key5' effect , and others ? how can i make all parameter decorator effect?

pxr89 commented 4 years ago

Now! parametor decorator do't work anymore! here is my babel config:

{
  "presets": [
    "module:metro-react-native-babel-preset",
    "@babel/preset-env",
    "@babel/preset-typescript"
  ],
  "plugins": [
    [
      "@babel/plugin-proposal-decorators",
      {
        "legacy": true
      }
    ],
    [
      "@babel/plugin-proposal-class-properties",
      {
        "loose": true
      }
    ],
    "babel-plugin-parameter-decorator"
  ]
}

package.json

  "devDependencies": {
        "@babel/core": "^7.4.5",
        "@babel/plugin-proposal-class-properties": "^7.7.4",
        "@babel/plugin-proposal-decorators": "^7.7.4",
        "@babel/preset-env": "^7.7.4",
        "@babel/preset-react": "^7.0.0",
        "@babel/preset-typescript": "^7.7.4",
        "@babel/runtime": "^7.4.5",
        "@types/jest": "^24.0.13",
        "@types/react": "^16.8.21",
        "@types/react-native": "^0.57.65",
        "@types/react-test-renderer": "^16.8.1",

anyone has any idea?

WarnerHooh commented 4 years ago

Hi @pxr89 ,

I will have a look, will let you know once get any update

WarnerHooh commented 4 years ago

This is an incompatibility bug appears when using param decorators along with the default param. So a quick temp workaround is to remove the default param clause (= ''). I will fix this asap.

WarnerHooh commented 4 years ago

Sorry for the delay, I have released a new version 1.0.15 which should fix this problem. Please let me know if you have any other issue @pxr89 .

pxr89 commented 4 years ago

@WarnerHooh Hello, i tried version 1.0.15. and still can't work for param with default clause (= ''). but it work for others