@@ -12,7 +12,6 @@ import { expressions } from 'edge-parser'
1212
1313import { nanoid } from '../utils.js'
1414import { TagContract } from '../types.js'
15- import type { Template } from '../template.js'
1615
1716declare module '../template.js' {
1817 export interface Template {
@@ -32,29 +31,6 @@ export const pushOnceToTag: TagContract & { generateId(): string } = {
3231 generateId ( ) {
3332 return `stack_${ nanoid ( ) } `
3433 } ,
35- boot ( template ) {
36- /**
37- * Tracking stack sources to avoid duplicate calls
38- * from the same file:line:col
39- */
40- template . getter (
41- 'stackSources' ,
42- ( ) => {
43- return { }
44- } ,
45- true
46- )
47-
48- template . macro ( 'trackStackSource' , function ( this : Template , stack , filename , line , col ) {
49- const key = `${ stack } _${ filename } _${ line } _${ col } `
50- if ( this . stackSources [ key ] ) {
51- return false
52- }
53-
54- this . stackSources [ key ] = true
55- return true
56- } )
57- } ,
5834 compile ( parser , buffer , token ) {
5935 const parsed = parser . utils . transformAst (
6036 parser . utils . generateAST ( token . properties . jsArg , token . loc , token . filename ) ,
@@ -80,23 +56,13 @@ export const pushOnceToTag: TagContract & { generateId(): string } = {
8056 * Each stack must be unique
8157 */
8258 const stackId = this . generateId ( )
83- const stackName = parser . utils . stringify ( parsed )
8459
8560 /**
8661 * Create a custom buffer for the stack. Since we do not want to the write
8762 * to the main buffer
8863 */
8964 const stackBuffer = buffer . create ( token . filename , { outputVar : stackId } )
9065
91- const { line, col } = token . loc . start
92- const normalizedFileName = token . filename . replace ( / \\ | \/ / g, '_' )
93- const conditional = `template.trackStackSource(${ stackName } , '${ normalizedFileName } ', ${ line } , ${ col } )`
94-
95- /**
96- * Start if block
97- */
98- buffer . writeStatement ( `if (${ conditional } ) {` , token . filename , line )
99-
10066 /**
10167 * Process children
10268 */
@@ -114,18 +80,17 @@ export const pushOnceToTag: TagContract & { generateId(): string } = {
11480 . disableTryCatchBlock ( )
11581 . flush ( ) ,
11682 token . filename ,
117- line
83+ token . loc . start . line
11884 )
11985
86+ const { line, col } = token . loc . start
87+ const normalizedFileName = token . filename . replace ( / \\ | \/ / g, '_' )
88+ const sourceId = `${ normalizedFileName } -${ line } -${ col } `
89+
12090 buffer . writeExpression (
121- `template.stacks.pushTo (${ parser . utils . stringify ( parsed ) } , ${ stackId } )` ,
91+ `template.stacks.pushOnceTo (${ parser . utils . stringify ( parsed ) } , ' ${ sourceId } ' , ${ stackId } )` ,
12292 token . filename ,
12393 line
12494 )
125-
126- /**
127- * End if block
128- */
129- buffer . writeStatement ( '}' , token . filename , line )
13095 } ,
13196}
0 commit comments