Subscribe on changes!

Whether the const keyword can be removed from compiler-core exported NodeTypes

avatar
Apr 29th 2022

Version

3.2.33

Reproduction link

github.com

Steps to reproduce

// 1
pnpm i 

// 2 
pnpm test compiler.demo 
image

so you can see the above error

the reason is:

// vue3/compiler-core/src/ast.ts

export const enum NodeTypes {
  ROOT,
  ELEMENT,
  TEXT,
  ……

because "const" keyword , see link const enum in Typescript


compiler-core exports the enum NodeType But because of the const keyword, there's really no way to use this NodeType if you want to So I wonder if it is possible to remove the const keyword for NodeType Then it makes sense to export the NodeType so that it can be used externally

What is expected?

The NodeType type can be used

What is actually happening?

The NodeType type can not be used now

avatar
Apr 29th 2022

Hi, thanks for your interest but Github issues are for bug reports and feature requests only. You can ask questions on the forum, the Discord server or StackOverflow.

avatar
Apr 30th 2022

@edison1105 but I think this is an API defect

because '@vue/compiler-core' is released as A separate package

it exports "NodeTypes" API, but outside can not be used.

What do you think?

or about API defects we can where discuss?

avatar
Apr 30th 2022

@cuixiaorui as you can see const enum has no code associated with it after compilation, so it is relatively memory efficient and only serves as a syntax hint. And it's an internal enum for compiler-dom and compiler-sfc etc.