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

feat: 支持默认类组件导出 #10

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,5 @@ dist

# TernJS port file
.tern-port

.idea
3 changes: 3 additions & 0 deletions example/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { defineComponent } from 'vue';
import A from './A';
import { B } from './B';
import C from './C'
import D, { D1 } from './D'
const App = defineComponent({
data() {
return {
Expand All @@ -17,6 +18,8 @@ const App = defineComponent({
<A />
<B />
<C />
<D />
<D1 />
</>
)
}
Expand Down
17 changes: 17 additions & 0 deletions example/D.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { VueComponent } from 'vue3-oop'

export class D1 extends VueComponent {
render() {
return <div>我是类命名导出组件</div>
}
}

export default class D extends VueComponent {
render() {
return (
<div>
我是类默认导出组件
</div>
)
}
}
1 change: 1 addition & 0 deletions example/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import '@abraham/reflection'
import { createApp } from 'vue';
import App from './App';

Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@
"lodash-es": "^4.17.20"
},
"devDependencies": {
"@abraham/reflection": "^0.8.0",
"@babel/core": "^7.12.10",
"@types/loader-utils": "^2.0.1",
"@vue/babel-plugin-jsx": "^1.0.0",
"babel-loader": "^8.2.2",
"injection-js": "^2.4.0",
"jest": "^26.6.3",
"typescript": "^4.0.3",
"vue": "^3.0.5",
"vue": "^3.2.26",
"vue3-oop": "^0.0.16",
"webpack": "^4.44.2",
"webpack-cli": "^3.0.0",
"webpack-dev-server": "^3.11.1"
Expand Down
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export default function loader(
id: string;
}[] = [];
let hasDefault = false;

for (const node of file.program.body) {
if (t.isVariableDeclaration(node)) {
declaredComponents.push(...parseComponentDecls(node));
Expand Down Expand Up @@ -77,6 +76,11 @@ export default function loader(
id: hash(`${filename}-default`)
});
hasDefault = true
} else if (t.isClassDeclaration(declaration)) {
hotComponents.push({
local: declaration.id.name,
id: hash(`${filename}-default`)
});
}
}
}
Expand Down
Loading