Просмотр исходного кода

feat(runtime-vapor): add no side effects annotation

三咲智子 Kevin Deng 2 лет назад
Родитель
Сommit
d16359c45b

+ 5 - 0
packages/runtime-vapor/src/dom.ts

@@ -5,6 +5,7 @@ export * from './dom/prop'
 export * from './dom/event'
 export * from './dom/templateRef'
 
+/*! #__NO_SIDE_EFFECTS__ */
 export function normalizeBlock(block: Block): Node[] {
   const nodes: Node[] = []
   if (block instanceof Node) {
@@ -63,6 +64,7 @@ export function remove(block: Block, parent: ParentBlock) {
   }
 }
 
+/*! #__NO_SIDE_EFFECTS__ */
 export function children(node: Node | Node[], ...paths: number[]): Node {
   for (const idx of paths) {
     node = isArray(node) ? node[idx] : node.childNodes[idx]
@@ -70,16 +72,19 @@ export function children(node: Node | Node[], ...paths: number[]): Node {
   return node as Node
 }
 
+/*! #__NO_SIDE_EFFECTS__ */
 export function createTextNode(val?: unknown): Text {
   // eslint-disable-next-line no-restricted-globals
   return document.createTextNode(val === undefined ? '' : toDisplayString(val))
 }
 
+/*! #__NO_SIDE_EFFECTS__ */
 export function createComment(data: string): Comment {
   // eslint-disable-next-line no-restricted-globals
   return document.createComment(data)
 }
 
+/*! #__NO_SIDE_EFFECTS__ */
 export function querySelector(selectors: string): Element | null {
   // eslint-disable-next-line no-restricted-globals
   return document.querySelector(selectors)

+ 1 - 0
packages/runtime-vapor/src/for.ts

@@ -12,6 +12,7 @@ interface ForBlock extends Fragment {
   memo: any[] | undefined
 }
 
+/*! #__NO_SIDE_EFFECTS__ */
 export const createFor = (
   src: () => any[] | Record<string, string> | Set<any> | Map<any, any>,
   renderItem: (block: ForBlock) => Block,

+ 1 - 0
packages/runtime-vapor/src/if.ts

@@ -5,6 +5,7 @@ import { createComment, createTextNode, insert, remove } from './dom'
 
 type BlockFn = () => Block
 
+/*! #__NO_SIDE_EFFECTS__ */
 export const createIf = (
   condition: () => any,
   b1: BlockFn,

+ 1 - 0
packages/runtime-vapor/src/template.ts

@@ -1,3 +1,4 @@
+/*! #__NO_SIDE_EFFECTS__ */
 export function template(str: string): () => ChildNode[] {
   let cached = false
   let node: DocumentFragment