WarnerHooh / babel-plugin-parameter-decorator

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

Cannot read property 'name' of undefined #5

Closed berickson1 closed 5 years ago

berickson1 commented 5 years ago

When using this with ReSub using both parameter decorations and function decorations, we're seeing the following exception on build

import { autoSubscribe, key, StoreBase } from 'resub';

@AutoSubscribeStore
class MyStore extends StoreBase {

    @autoSubscribe
    aFunction(@key address: string): undefined {
        // This would normally return something but not needed for an exmaple
        return undefined;
    }
}

error: bundling failed: TypeError: Cannot read property 'name' of undefined at /src/project/node_modules/babel-plugin-parameter-decorator/lib/index.js:39:60 at Array.forEach () at /src/project/node_modules/babel-plugin-parameter-decorator/lib/index.js:38:44 at Array.forEach () at /src/project/node_modules/babel-plugin-parameter-decorator/lib/index.js:37:37 at Array.forEach () at /src/project/node_modules/babel-plugin-parameter-decorator/lib/index.js:36:31 at Array.forEach () at /src/project/node_modules/babel-plugin-parameter-decorator/lib/index.js:35:16

I logged the decorator at line 39 and this is the output

{"type":"Decorator","start":386,"end":390,"loc":{"start":{"line":13,"column":13},"end":{"line":13,"column":17}},"expression":{"type":"Identifier","start":387,"end":390,"loc":{"start":{"line":13,"column":14},"end":{"line":13,"column":17},"identifierName":"key"},"name":"key"}}

I think lib/index.js should probably read as

if (decorator.expression.callee) {
    decorators[decorator.expression.callee.name] = decorator;

} else {
    decorators[deorator.expression.name] = decorator;
}
WarnerHooh commented 5 years ago

Thanks for your feedback, @berickson1 Will have a quick look today.

WarnerHooh commented 5 years ago

Hello @berickson1 , I have fixed this and patch a new version. So this should be ok with the new version. Please let me know if you have any other problem.

berickson1 commented 5 years ago

Thanks for the quick turnaround! This fixed the issue we were seeing

WarnerHooh commented 5 years ago

This issue has been resolved in 1.0.9