]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
wip: comments
authorEvan You <yyx990803@gmail.com>
Thu, 16 Nov 2023 03:05:31 +0000 (11:05 +0800)
committerEvan You <yyx990803@gmail.com>
Sat, 25 Nov 2023 08:18:29 +0000 (16:18 +0800)
packages/compiler-core/src/parser/Tokenizer.ts
packages/compiler-core/src/parser/index.ts

index 53074c49d1e10a4ee31ae457b63e2e1e557b16b8..214817a425bc4db41fc970e2292ccb669d45f347 100644 (file)
@@ -157,8 +157,8 @@ export interface Callbacks {
   ondirarg(start: number, endIndex: number): void
   ondirmodifier(start: number, endIndex: number): void
 
-  oncomment(start: number, endIndex: number, endOffset: number): void
-  oncdata(start: number, endIndex: number, endOffset: number): void
+  oncomment(start: number, endIndex: number): void
+  oncdata(start: number, endIndex: number): void
 
   // onprocessinginstruction(start: number, endIndex: number): void
   // ondeclaration(start: number, endIndex: number): void
@@ -400,9 +400,9 @@ export default class Tokenizer {
     if (c === this.currentSequence[this.sequenceIndex]) {
       if (++this.sequenceIndex === this.currentSequence.length) {
         if (this.currentSequence === Sequences.CdataEnd) {
-          this.cbs.oncdata(this.sectionStart, this.index, 2)
+          this.cbs.oncdata(this.sectionStart, this.index - 2)
         } else {
-          this.cbs.oncomment(this.sectionStart, this.index, 2)
+          this.cbs.oncomment(this.sectionStart, this.index - 2)
         }
 
         this.sequenceIndex = 0
@@ -691,7 +691,7 @@ export default class Tokenizer {
   }
   private stateInSpecialComment(c: number): void {
     if (c === CharCodes.Gt || this.fastForwardTo(CharCodes.Gt)) {
-      this.cbs.oncomment(this.sectionStart, this.index, 0)
+      this.cbs.oncomment(this.sectionStart, this.index)
       this.state = State.Text
       this.sectionStart = this.index + 1
     }
@@ -920,9 +920,9 @@ export default class Tokenizer {
 
     if (this.state === State.InCommentLike) {
       if (this.currentSequence === Sequences.CdataEnd) {
-        this.cbs.oncdata(this.sectionStart, endIndex, 0)
+        this.cbs.oncdata(this.sectionStart, endIndex)
       } else {
-        this.cbs.oncomment(this.sectionStart, endIndex, 0)
+        this.cbs.oncomment(this.sectionStart, endIndex)
       }
     } else if (
       this.state === State.InTagName ||
index 97937d434603ea66f0c9e24674c81e10d3a03aca..585af7e0d42844f435eafd2e70aa528e184082dc 100644 (file)
@@ -291,8 +291,14 @@ const tokenizer = new Tokenizer({
     currentAttrStartIndex = currentAttrEndIndex = -1
   },
 
-  oncomment(start, end, offset) {
-    // TODO oncomment
+  oncomment(start, end) {
+    if (currentOptions.comments) {
+      addNode({
+        type: NodeTypes.COMMENT,
+        content: getSlice(start, end),
+        loc: getLoc(start - 4, end + 3)
+      })
+    }
   },
 
   onend() {
@@ -302,7 +308,7 @@ const tokenizer = new Tokenizer({
     }
   },
 
-  oncdata(start, end, offset) {
+  oncdata(start, end) {
     // TODO throw error
   }
 })