Preview fails on some valid module syntax in `.js` files
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 58/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- javascript, typescript
Línea de trabajo
Start in src/output/moduleCompiler.ts, where processModule handles superclass bindings and re-exports; trace how it parses and rewrites each reproduction. Check the generated modules for the class, namespace re-export, package re-export, and default-export cases in the issue. Done means all listed examples preview their expected values without syntax or runtime errors.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Reproduced on @vue/repl main (9b5bc87), in the preview with SSR off. In every case below, App.vue imports from a.js.
1. A class extending an imported class, unless the class is exported directly
base.js
export class Base {}
App.vue (cases 1a, 1c, 1d)
<script setup>
import { msg } from './a.js'
</script>
<template>
<h1>{{ msg }}</h1>
</template>
1a. Top-level class that is not exported.
a.js
import { Base } from './base.js'
class Foo extends Base {}
export const msg = new Foo() instanceof Base
Actual: the preview shows Cannot read properties of undefined (reading 'start'), and the console logs:
TypeError: Cannot read properties of undefined (reading 'start')
This is thrown in processModule (src/output/moduleCompiler.ts), on the line that inserts the superclass binding at parentStack[1].start.
Expected: the preview shows true.
1b. export default class extends
App.vue
<script setup>
import Foo from './a.js'
import { Base } from './base.js'
const msg = new Foo() instanceof Base
</script>
<template>
<h1>{{ msg }}</h1>
</template>
a.js
import { Base } from './base.js'
export default class extends Base {}
Actual: the preview shows Failed to execute 'appendChild' on 'Node': Unexpected token 'const'. The generated module for a.js contains:
__module__.default = const Base = __import_1__.Base;
class extends Base {}
Expected: the preview shows true.
1c. Class inside a function that is not exported.
a.js
import { Base } from './base.js'
function create() {
class Foo extends Base {}
return new Foo()
}
export const msg = create() instanceof Base
Actual: the preview shows Failed to execute 'appendChild' on 'Node': Unexpected token 'const'. The generated module for a.js contains:
function create() const Base = __import_1__.Base;
{
class Foo extends Base {}
return new Foo()
}
Expected: the preview shows true.
1d. Class inside a block.
a.js
import { Base } from './base.js'
let foo
if (true) {
class Foo extends Base {}
foo = new Foo()
}
export const msg = foo instanceof Base
Actual: the preview shows Failed to execute 'appendChild' on 'Node': Unexpected token 'const'. The generated module for a.js contains:
if (true) const Base = __import_1__.Base;
{
class Foo extends Base {}
foo = new Foo()
}
Expected: the preview shows true.
2. export * as ns from './…'
App.vue
<script setup>
import { b } from './a.js'
</script>
<template>
<h1>{{ b.msg }}</h1>
</template>
a.js
export * as b from './b.js'
b.js
export const msg = 'ok'
Actual: the preview shows Cannot read properties of undefined (reading 'name'), and the console logs:
TypeError: Cannot read properties of undefined (reading 'name')
This is thrown in processModule (src/output/moduleCompiler.ts), in the export { … } from './…' branch, where it reads spec.local.name.
Expected: the preview shows ok.
3. Re-export from a package: export { ref } from 'vue'
App.vue
<script setup>
import { ref } from './a.js'
const msg = ref('ok')
</script>
<template>
<h1>{{ msg }}</h1>
</template>
a.js
export { ref } from 'vue'
Actual: the preview shows ref is not defined, and the console logs:
ReferenceError: ref is not defined
The generated module for a.js is:
const __module__ = __modules__["src/a.js"] = { [Symbol.toStringTag]: "Module" }
__export__(__module__, "ref", () => ref)
Expected: the preview shows ok.
4. export default not written exactly as export default
App.vue (cases 4b, 4c)
<script setup>
import msg from './a.js'
</script>
<template>
<h1>{{ msg }}</h1>
</template>
4a. Parenthesized named function.
App.vue
<script setup>
import getMsg from './a.js'
const msg = getMsg()
</script>
<template>
<h1>{{ msg }}</h1>
</template>
a.js
export default (function getMsg() {
return 'ok'
})
Actual: the preview shows {(intermediate value)} is not a function. The generated module for a.js is:
const __module__ = __modules__["src/a.js"] = { [Symbol.toStringTag]: "Module" }
(function getMsg() {
return 'ok'
})
__export__(__module__, "default", () => getMsg)
Expected: the preview shows ok.
4b. Two spaces.
a.js
export default 'ok'
Actual: the preview shows Failed to execute 'appendChild' on 'Node': Unexpected string. The generated module for a.js contains:
__module__.default =t 'ok'
Expected: the preview shows ok.
4c. A comment between export and default.
a.js
export /* x */ default 'ok'
Actual: the preview shows Failed to execute 'appendChild' on 'Node': Unexpected token 'default'. The generated module for a.js contains:
__module__.default = default 'ok'
Expected: the preview shows ok.
- Lenguaje dominante
- TypeScript
- Estrellas
- 1.1k
- Forks
- 222
- Merge medio
- 2 h 10 min
- PR fusionados (30 d)
- 1
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de vuejs/repl
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
-
Feat request: export injectKeyPropsQuizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 74/100
-
Dificultad 3/5 1-2 días Aptitud para principiantes 65/100
-
using Sandbox with clearConsole false,there would be a warning message on the browser's consoleAbierto
Dificultad 3/5 1-2 días Aptitud para principiantes 35/100
-
Using `setFiles` removes tsconfig.jsonPosiblemente ocupada @ifer47 la tomó hace 121 días. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 25/100
Todos los issues de vuejs/repl
Issues similares
-
bug frontend
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
CivicTechWR/accessible-housing-portal#578 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
nekko-labs/nekko-agent#2998 ·
Los mantenedores suelen responder en 1 día
-
Console writes URL credentials to the local log, though AGENTS.md says secrets never reach diskAbierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 86/100
sandbox-quantum/switch#2163 ·
Los mantenedores suelen responder en 1 día
-
enhancement ux
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
lolimmlost/aidj#433 ·
Los mantenedores suelen responder en 1 día
-
test: ipcShownDialogKeys.test.tsx can fail the unit run with 'window is not defined' after it endsAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día