File tree Expand file tree Collapse file tree 13 files changed +3678
-637
lines changed Expand file tree Collapse file tree 13 files changed +3678
-637
lines changed Original file line number Diff line number Diff line change 14
14
node-version : 12
15
15
16
16
# Install dependencies
17
- - run : npm install
17
+ - run : npm ci
18
18
19
19
# Run tests
20
- - run : npm test
20
+ - run : npm test
Original file line number Diff line number Diff line change 2
2
* @jest -environment jsdom
3
3
*/
4
4
import { cssString } from "../__fixtures__/curriculum-helper-css" ;
5
- import { CSSHelp } from "../css-helper " ;
5
+ import { CSSHelp } from "../index " ;
6
6
7
7
describe ( 'css-help' , ( ) => {
8
8
const doc = document ;
Original file line number Diff line number Diff line change
1
+
2
+ interface CodeNodeProps {
3
+ type : string ;
4
+ value : string ;
5
+ match : string ;
6
+ newline : string ;
7
+ nodes : CodeNode [ ] ;
8
+ }
9
+
10
+
11
+ export type CodeNodeType = Partial < CodeNodeProps > | null ;
12
+
13
+
14
+ export class CodeNode {
15
+ type : string ;
16
+ value : any ;
17
+ match : string ;
18
+ newline : string ;
19
+
20
+ constructor ( node : CodeNodeType ) {
21
+ this . type = node . type ;
22
+ if ( node . value ) this . value = node . value ;
23
+ if ( node . match ) this . match = node . match ;
24
+ this . newline = node . newline || "" ;
25
+ }
26
+ get protected ( ) {
27
+ return Boolean ( this . match ) && this . match [ 1 ] === "!" ;
28
+ }
29
+ }
30
+
31
+ export class Block extends CodeNode {
32
+ nodes : CodeNode [ ] ;
33
+
34
+ constructor ( node : CodeNodeType ) {
35
+ super ( node ) ;
36
+ this . nodes = node . nodes || [ ] ;
37
+ }
38
+ push ( node : CodeNode ) {
39
+ this . nodes . push ( node ) ;
40
+ }
41
+ get protected ( ) {
42
+ return this . nodes . length > 0 && this . nodes [ 0 ] . protected === true ;
43
+ }
44
+ }
45
+
Original file line number Diff line number Diff line change
1
+ import { CodeNodeType } from './class/node.js' ;
2
+ import { options } from './option-types.js' ;
3
+
4
+
5
+ export const compile = ( cst , options :Partial < options > = { } ) => {
6
+ const keepProtected = options . safe === true || options . keepProtected === true ;
7
+ let firstSeen = false ;
8
+
9
+ const walk = ( node : CodeNodeType , child ?: CodeNodeType ) => {
10
+ let output = '' ;
11
+ let inner ;
12
+ let lines ;
13
+
14
+ for ( const child of node . nodes ) {
15
+ switch ( child . type ) {
16
+ case 'block' :
17
+ if ( options . first && firstSeen === true ) {
18
+ output += walk ( child , node ) ;
19
+ break ;
20
+ }
21
+
22
+ if ( options . preserveNewlines === true ) {
23
+ inner = walk ( child , node ) ;
24
+ lines = inner . split ( '\n' ) ;
25
+ output += '\n' . repeat ( lines . length - 1 ) ;
26
+ break ;
27
+ }
28
+
29
+ if ( keepProtected === true && child . protected === true ) {
30
+ output += walk ( child , node ) ;
31
+ break ;
32
+ }
33
+
34
+ firstSeen = true ;
35
+ break ;
36
+ case 'line' :
37
+ if ( options . first && firstSeen === true ) {
38
+ output += child . value ;
39
+ break ;
40
+ }
41
+
42
+ if ( keepProtected === true && child . protected === true ) {
43
+ output += child . value ;
44
+ }
45
+
46
+ firstSeen = true ;
47
+ break ;
48
+ case 'open' :
49
+ case 'close' :
50
+ case 'text' :
51
+ case 'newline' :
52
+ default : {
53
+ output += child . value || '' ;
54
+ break ;
55
+ }
56
+ }
57
+ }
58
+
59
+ return output ;
60
+ } ;
61
+
62
+ return walk ( cst ) ;
63
+ } ;
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments