Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

babel-sugar-inject-h has a bug when compile code with ts (target es5) before babel process #192

Open
simplefeel opened this issue Apr 14, 2021 · 0 comments · May be fixed by #193
Open

babel-sugar-inject-h has a bug when compile code with ts (target es5) before babel process #192

simplefeel opened this issue Apr 14, 2021 · 0 comments · May be fixed by #193

Comments

@simplefeel
Copy link

simplefeel commented Apr 14, 2021

I have a .tsx file

import Vue, { VNode } from 'vue'

export default Vue.extend({
    data() {
        return {}
    },
    methods: {
        handleClick() {
            alert('hello,world')
        }
    },
    render(): VNode {
        return (
            <button onClick={this.handleClick} className="button_bg">
                Click
            </button>
        )
    }
})

it will compile first by typescript , tsconfig.json is

"compilerOptions": {
    "target": "es5"
  }

after ts compile with es5

exports.default = vue_1.default.extend({
    data: function () {
        return {};
    },
    methods: {
        handleClick: function () {
            alert('hello,world');
        }
    },
    render: function () {
        return (<button onClick={this.handleClick} className="button_bg">
                Click
            </button>);
    }
});

when target is es5 , it will have problem , after bable will compile is ObjectProperty

image

but , the plugin code traverse ObjectMethod|ClassMethod

image

howover, if target is esnext it will work ,because this node ast is ObjectMethod

after ts compile with exnext

exports.default = vue_1.default.extend({
    data() {
        return {};
    },
    methods: {
        handleClick() {
            alert('hello,world');
        }
    },
    render() {
        return (<button onClick={this.handleClick} className="button_bg">
                Click
            </button>);
    }
});

image

"compilerOptions": {
    "target": "esnext"
  }

above is work

I think maybe is babel/parser transform ast result not some with different stage code

@simplefeel simplefeel changed the title babel-sugar-inject-h has a bug with ts babel-sugar-inject-h has a bug when compile code with ts (target es5) before babel process Apr 16, 2021
@simplefeel simplefeel linked a pull request Apr 16, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant