Skip to content

Commit d6fd2fe

Browse files
author
elevatebart
committed
fix: check template even if no data function
1 parent 10df31f commit d6fd2fe

File tree

3 files changed

+35
-28
lines changed

3 files changed

+35
-28
lines changed

package.json

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,38 @@
1515
"cy": "cypress open --e2e"
1616
},
1717
"dependencies": {
18-
"@vue/compiler-core": "^3.2.45",
19-
"@vue/compiler-sfc": "^3.2.45",
20-
"acorn": "^8.8.1",
18+
"@vue/compiler-core": "^3.2.47",
19+
"@vue/compiler-sfc": "^3.2.47",
20+
"acorn": "^8.8.2",
2121
"acorn-walk": "^8.2.0",
22-
"core-js": "^3.26.1",
22+
"core-js": "^3.29.0",
2323
"debounce": "^1.2.1",
2424
"hash-sum": "^2.0.0",
2525
"prismjs": "^1.29.0",
26-
"vue-inbrowser-compiler-sucrase": "^4.56.6",
26+
"vue-inbrowser-compiler-sucrase": "^4.60.0",
2727
"vue-prism-editor": "^2.0.0-alpha.2"
2828
},
2929
"devDependencies": {
30-
"@babel/runtime": "^7.20.1",
30+
"@babel/runtime": "^7.21.0",
3131
"@types/debounce": "^1.2.1",
3232
"@types/hash-sum": "^1.0.0",
33-
"@types/jsdom": "^20.0.1",
34-
"@types/node": "^18.11.9",
33+
"@types/jsdom": "^21.1.0",
34+
"@types/node": "^18.14.6",
3535
"@types/prismjs": "^1.26.0",
3636
"@uivjs/vue-github-corners": "^1.0.1",
37-
"@vitejs/plugin-vue": "^3.2.0",
37+
"@vitejs/plugin-vue": "^4.0.0",
3838
"@vue/tsconfig": "^0.1.3",
3939
"autoprefixer": "^10.4.13",
40-
"cypress": "^11.0.1",
41-
"prettier": "2.7.1",
42-
"start-server-and-test": "^1.14.0",
43-
"typescript": "^4.8.4",
40+
"cypress": "^12.7.0",
41+
"prettier": "2.8.4",
42+
"start-server-and-test": "^2.0.0",
43+
"typescript": "^4.9.5",
4444
"validate-commit-msg": "^1.1.3",
45-
"vite": "^3.2.3",
46-
"vitest": "^0.25.1",
47-
"vue": "^3.2.45",
45+
"vite": "^4.1.4",
46+
"vitest": "^0.29.2",
47+
"vue": "^3.2.47",
4848
"vue-github-corners": "^1.2.3",
49-
"vue-tsc": "^1.0.9",
49+
"vue-tsc": "^1.2.0",
5050
"vue3-datepicker": "^0.3.4"
5151
},
5252
"peerDependencies": {

src/Preview.vue

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export default defineComponent({
100100
},
101101
},
102102
created() {
103+
console.log(this.requiresPlusVue)
103104
this.renderComponent(this.code.trim());
104105
},
105106
destroyed() {
@@ -176,6 +177,7 @@ export default defineComponent({
176177
await Promise.allSettled(Object.keys(this.requiresPlusVue).map(async (key) => {
177178
requires[key] = this.requiresPlusVue[key] instanceof Promise ? (await this.requiresPlusVue[key]).default : this.requiresPlusVue[key]
178179
}))
180+
console.log({ requires })
179181
options = defineComponent((evalInContext(
180182
script,
181183
(filepath) => requireAtRuntime(requires, filepath),
@@ -214,11 +216,11 @@ export default defineComponent({
214216
}
215217
}
216218
const template = renderedComponent.raw.template
217-
if (template && typeof options.data === "function") {
219+
if (template) {
218220
checkTemplate({
219-
...(options as any),
220-
template,
221-
},
221+
...(options as any),
222+
template,
223+
},
222224
this.checkVariableAvailability
223225
);
224226
}

src/utils/checkTemplate.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ interface Options {
1515
computed?: Record<string, any>;
1616
methods?: Record<string, any>;
1717
attrAllowList?: string[];
18-
setup?: () => (Record<string, any> | void)
18+
setup?: () => Record<string, any> | void;
1919
}
2020

2121
export default function (
@@ -42,23 +42,28 @@ export default function (
4242
: Object.keys($options.props)
4343
: [];
4444

45-
const dataArray =
46-
typeof $options.data === "function" ? Object.keys($options.data()) : [];
45+
const dataArray = $options.data
46+
? typeof $options.data === "function"
47+
? Object.keys($options.data())
48+
: Object.keys($options.data)
49+
: [];
4750

4851
const computedArray = $options.computed ? Object.keys($options.computed) : [];
4952

5053
const methodsArray =
5154
$options && $options.methods ? Object.keys($options.methods) : [];
52-
53-
const setupOutput =
54-
$options && typeof $options.setup === 'function' ? Object.keys($options.setup() ?? {}) : [];
55+
56+
const setupOutput =
57+
$options && typeof $options.setup === "function"
58+
? Object.keys($options.setup() ?? {})
59+
: [];
5560

5661
const scriptVars = [
5762
...propNamesArray,
5863
...dataArray,
5964
...computedArray,
6065
...methodsArray,
61-
...setupOutput
66+
...setupOutput,
6267
];
6368

6469
// Define list of attributes for which name check will be skipped. Defaults to known camelCased SVG attributes.

0 commit comments

Comments
 (0)