Skip to content

Commit

Permalink
Merge pull request #34 from vuejs/main
Browse files Browse the repository at this point in the history
sync
  • Loading branch information
encourage317125 committed Jun 23, 2023
2 parents 8aaee63 + 124160e commit 0097e9e
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 37 deletions.
2 changes: 1 addition & 1 deletion packages/compiler-core/src/babelUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function walkIdentifiers(
root.body[0].type === 'ExpressionStatement' &&
root.body[0].expression

;(walk as any)(root, {
walk(root, {
enter(node: Node & { scopeIds?: Set<string> }, parent: Node | undefined) {
parent && parentStack.push(parent)
if (
Expand Down
6 changes: 3 additions & 3 deletions packages/compiler-sfc/src/compileScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,8 @@ export function compileScript(
node.type.endsWith('Statement')
) {
const scope: Statement[][] = [scriptSetupAst.body]
;(walk as any)(node, {
enter(child: Node, parent: Node) {
walk(node, {
enter(child: Node, parent: Node | undefined) {
if (isFunctionType(child)) {
this.skip()
}
Expand All @@ -633,7 +633,7 @@ export function compileScript(
ctx,
child,
needsSemi,
parent.type === 'ExpressionStatement'
parent!.type === 'ExpressionStatement'
)
}
},
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-sfc/src/script/definePropsDestructure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export function transformDestructuredProps(
// check root scope first
const ast = ctx.scriptSetupAst!
walkScope(ast, true)
;(walk as any)(ast, {
walk(ast, {
enter(node: Node, parent?: Node) {
parent && parentStack.push(parent)

Expand Down
11 changes: 11 additions & 0 deletions packages/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ declare module 'file-saver' {
export function saveAs(blob: any, name: any): void
}

declare module 'estree-walker' {
export function walk<T>(
root: T,
options: {
enter?: (node: T, parent: T | undefined) => any
leave?: (node: T, parent: T | undefined) => any
exit?: (node: T) => any
} & ThisType<{ skip: () => void }>
)
}

declare interface String {
/**
* @deprecated Please use String.prototype.slice instead of String.prototype.substring in the repository.
Expand Down
2 changes: 1 addition & 1 deletion packages/reactivity-transform/src/reactivityTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ export function transformAST(

// check root scope first
walkScope(ast, true)
;(walk as any)(ast, {
walk(ast, {
enter(node: Node, parent?: Node) {
parent && parentStack.push(parent)

Expand Down
14 changes: 7 additions & 7 deletions packages/sfc-playground/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
<title>Vue SFC Playground</title>
<script>
// process shim for old versions of @vue/compiler-sfc dependency
window.process = { env: {} }
const savedPreferDark = localStorage.getItem('vue-sfc-playground-prefer-dark')
if (
savedPreferDark === 'true' ||
(!savedPreferDark && window.matchMedia('(prefers-color-scheme: dark)').matches)
) {
// window.process = { env: {} }
// const savedPreferDark = localStorage.getItem('vue-sfc-playground-prefer-dark')
// if (
// savedPreferDark === 'true' ||
// (!savedPreferDark && window.matchMedia('(prefers-color-scheme: dark)').matches)
// ) {
document.documentElement.classList.add('dark')
}
// }
</script>
<script type="module" src="/src/main.ts"></script>
</head>
Expand Down
2 changes: 1 addition & 1 deletion packages/sfc-playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"vite": "^4.3.0"
},
"dependencies": {
"@vue/repl": "^1.5.0",
"@vue/repl": "^2.1.3",
"file-saver": "^2.0.5",
"jszip": "^3.6.0",
"vue": "workspace:*"
Expand Down
2 changes: 2 additions & 0 deletions packages/sfc-playground/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script setup lang="ts">
import Header from './Header.vue'
import { Repl, ReplStore, SFCOptions } from '@vue/repl'
import Monaco from '@vue/repl/monaco-editor'
import { ref, watchEffect } from 'vue'
const setVH = () => {
Expand Down Expand Up @@ -82,6 +83,7 @@ function toggleSSR() {
@toggle-ssr="toggleSSR"
/>
<Repl
:editor="Monaco"
@keydown.ctrl.s.prevent
@keydown.meta.s.prevent
:ssr="useSSRMode"
Expand Down
24 changes: 12 additions & 12 deletions packages/sfc-playground/src/Header.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script setup lang="ts">
import { downloadProject } from './download/download'
import { ref, onMounted } from 'vue'
import Sun from './icons/Sun.vue'
import Moon from './icons/Moon.vue'
// import Sun from './icons/Sun.vue'
// import Moon from './icons/Moon.vue'
import Share from './icons/Share.vue'
import Download from './icons/Download.vue'
import GitHub from './icons/GitHub.vue'
Expand Down Expand Up @@ -51,14 +51,14 @@ async function copyLink(e: MouseEvent) {
alert('Sharable URL has been copied to clipboard.')
}
function toggleDark() {
const cls = document.documentElement.classList
cls.toggle('dark')
localStorage.setItem(
'vue-sfc-playground-prefer-dark',
String(cls.contains('dark'))
)
}
// function toggleDark() {
// const cls = document.documentElement.classList
// cls.toggle('dark')
// localStorage.setItem(
// 'vue-sfc-playground-prefer-dark',
// String(cls.contains('dark'))
// )
// }
onMounted(async () => {
window.addEventListener('click', () => {
Expand Down Expand Up @@ -145,10 +145,10 @@ async function fetchVersions(): Promise<string[]> {
>
<span>{{ ssr ? 'SSR ON' : 'SSR OFF' }}</span>
</button>
<button title="Toggle dark mode" class="toggle-dark" @click="toggleDark">
<!-- <button title="Toggle dark mode" class="toggle-dark" @click="toggleDark">
<Sun class="light" />
<Moon class="dark" />
</button>
</button> -->
<button title="Copy sharable URL" class="share" @click="copyLink">
<Share />
</button>
Expand Down
6 changes: 5 additions & 1 deletion packages/sfc-playground/src/download/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ export async function downloadProject(store: ReplStore) {

const files = store.getFiles()
for (const file in files) {
src.file(file, files[file])
if (file !== 'import-map.json') {
src.file(file, files[file])
} else {
zip.file(file, files[file])
}
}

const blob = await zip.generateAsync({ type: 'blob' })
Expand Down
14 changes: 5 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"newLine": "LF",
"useDefineForClassFields": false,
"module": "esnext",
"moduleResolution": "node",
"moduleResolution": "bundler",
"allowJs": false,
"strict": true,
"noUnusedLocals": true,
Expand Down

0 comments on commit 0097e9e

Please sign in to comment.