@katabatic/compiler 1.1.2 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/analyse/visitors/CallExpression.js +6 -0
- package/src/analyse/visitors/IfBlock.js +2 -2
- package/src/builders.js +29 -17
- package/src/checkers.js +2 -2
- package/src/transform/context.js +4 -0
- package/src/transform/visitors/IfBlock.js +6 -2
- package/src/transform/visitors/Selector.js +18 -1
package/package.json
CHANGED
|
@@ -30,7 +30,13 @@ export function CallExpression(node, ctx) {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
if (is.defineCustomElement(node)) {
|
|
33
|
+
const template = getTemplate(ctx)
|
|
33
34
|
const name = node.arguments[0].value
|
|
35
|
+
|
|
36
|
+
template.metadata ??= {}
|
|
37
|
+
template.metadata.customElementName = name
|
|
38
|
+
|
|
34
39
|
ctx.state.customElement.name = name
|
|
40
|
+
return
|
|
35
41
|
}
|
|
36
42
|
}
|
|
@@ -8,8 +8,8 @@ export function IfBlock(node, ctx) {
|
|
|
8
8
|
const program = getProgram(ctx)
|
|
9
9
|
const blocks = getBlocks(ctx)
|
|
10
10
|
matchExpression(node.test, program, blocks)
|
|
11
|
-
|
|
12
|
-
const hasElseif =
|
|
11
|
+
|
|
12
|
+
const hasElseif = node.alternate?.nodes.some(is.elseIfBlock) ?? false
|
|
13
13
|
|
|
14
14
|
node.metadata ??= {}
|
|
15
15
|
node.metadata.hasElseif = hasElseif
|
package/src/builders.js
CHANGED
|
@@ -663,6 +663,21 @@ export function createElement(value) {
|
|
|
663
663
|
}
|
|
664
664
|
}
|
|
665
665
|
|
|
666
|
+
export function createComment(value = '') {
|
|
667
|
+
return {
|
|
668
|
+
type: 'CallExpression',
|
|
669
|
+
callee: {
|
|
670
|
+
type: 'MemberExpression',
|
|
671
|
+
object: { type: 'Identifier', name: 'document' },
|
|
672
|
+
property: { type: 'Identifier', name: 'createComment' },
|
|
673
|
+
computed: false,
|
|
674
|
+
optional: false
|
|
675
|
+
},
|
|
676
|
+
arguments: [{ type: 'Literal', value }],
|
|
677
|
+
optional: false
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
|
|
666
681
|
export function $() {
|
|
667
682
|
return {
|
|
668
683
|
type: 'MemberExpression',
|
|
@@ -796,31 +811,28 @@ export function insertBefore(node, insertNode) {
|
|
|
796
811
|
}
|
|
797
812
|
|
|
798
813
|
return {
|
|
799
|
-
type: '
|
|
800
|
-
|
|
801
|
-
type: '
|
|
802
|
-
|
|
814
|
+
type: 'CallExpression',
|
|
815
|
+
callee: {
|
|
816
|
+
type: 'MemberExpression',
|
|
817
|
+
object: {
|
|
803
818
|
type: 'MemberExpression',
|
|
804
|
-
object:
|
|
805
|
-
type: 'MemberExpression',
|
|
806
|
-
object: node,
|
|
807
|
-
property: {
|
|
808
|
-
type: 'Identifier',
|
|
809
|
-
name: 'parentNode'
|
|
810
|
-
},
|
|
811
|
-
computed: false,
|
|
812
|
-
optional: false
|
|
813
|
-
},
|
|
819
|
+
object: node,
|
|
814
820
|
property: {
|
|
815
821
|
type: 'Identifier',
|
|
816
|
-
name: '
|
|
822
|
+
name: 'parentNode'
|
|
817
823
|
},
|
|
818
824
|
computed: false,
|
|
819
825
|
optional: false
|
|
820
826
|
},
|
|
821
|
-
|
|
827
|
+
property: {
|
|
828
|
+
type: 'Identifier',
|
|
829
|
+
name: 'insertBefore'
|
|
830
|
+
},
|
|
831
|
+
computed: false,
|
|
822
832
|
optional: false
|
|
823
|
-
}
|
|
833
|
+
},
|
|
834
|
+
arguments: [insertNode, node],
|
|
835
|
+
optional: false
|
|
824
836
|
}
|
|
825
837
|
}
|
|
826
838
|
|
package/src/checkers.js
CHANGED
|
@@ -139,6 +139,6 @@ export function shadowRootModeAttribute(node) {
|
|
|
139
139
|
return node.type === 'Attribute' && node.name === 'shadowRootMode'
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
-
export function
|
|
143
|
-
return node.type === 'IfBlock'
|
|
142
|
+
export function elseIfBlock(node) {
|
|
143
|
+
return node.type === 'IfBlock' && node.elseif
|
|
144
144
|
}
|
package/src/transform/context.js
CHANGED
|
@@ -32,7 +32,7 @@ export function IfBlock(node, ctx) {
|
|
|
32
32
|
|
|
33
33
|
return [...stmts1, ...stmts2, stmt3]
|
|
34
34
|
}
|
|
35
|
-
return blocks
|
|
35
|
+
return [...init.elem, ...blocks]
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
|
|
@@ -49,7 +49,11 @@ export function IfBlock(node, ctx) {
|
|
|
49
49
|
ctx.state.blocks.push(blockStmt)
|
|
50
50
|
appendText(ctx.state.template, '<!-- -->')
|
|
51
51
|
} else {
|
|
52
|
-
const
|
|
52
|
+
const anchorId = nextElementId(ctx)
|
|
53
|
+
const anchorStmt = b.declaration(anchorId, b.insertBefore('anchor', b.createComment()))
|
|
54
|
+
const blockStmt = b.ifBlock(anchorId, testStmt, consequentStmt, alternateStmt)
|
|
55
|
+
|
|
56
|
+
ctx.state.init.elem.push(anchorStmt)
|
|
53
57
|
ctx.state.blocks.push(blockStmt)
|
|
54
58
|
}
|
|
55
59
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as b from '../../builders.js'
|
|
2
|
+
import { getTemplate } from '../context.js'
|
|
2
3
|
|
|
3
4
|
export function Selector(node, ctx) {
|
|
4
5
|
node = CssTreeNodeFix(node, ctx)
|
|
@@ -11,6 +12,22 @@ export function Selector(node, ctx) {
|
|
|
11
12
|
scope()
|
|
12
13
|
children.push(child)
|
|
13
14
|
break
|
|
15
|
+
case 'PseudoClassSelector':
|
|
16
|
+
if (child.name === 'host') {
|
|
17
|
+
const template = getTemplate(ctx)
|
|
18
|
+
|
|
19
|
+
if (!template.metadata?.shadowRootMode) {
|
|
20
|
+
children.push({
|
|
21
|
+
type: 'TypeSelector',
|
|
22
|
+
name:
|
|
23
|
+
template.metadata?.customElementName ??
|
|
24
|
+
ctx.state.context.customElementName
|
|
25
|
+
})
|
|
26
|
+
} else {
|
|
27
|
+
children.push(child)
|
|
28
|
+
}
|
|
29
|
+
break
|
|
30
|
+
}
|
|
14
31
|
default:
|
|
15
32
|
unscoped.push(child)
|
|
16
33
|
break
|
|
@@ -35,7 +52,7 @@ export const CssTree = {
|
|
|
35
52
|
PseudoClassSelector: CssTreeNodeFix
|
|
36
53
|
}
|
|
37
54
|
|
|
38
|
-
function CssTreeNodeFix(node, ctx) {
|
|
55
|
+
export function CssTreeNodeFix(node, ctx) {
|
|
39
56
|
const children = node.children?.map((c) => ctx.visit(c)) ?? null
|
|
40
57
|
return { ...node, children }
|
|
41
58
|
}
|