Skip to content

Commit b63e73a

Browse files
committed
internal/lexer: add crlf ignoring
I'm not quite sure if this is what we should be doing, but we'll try for now.
1 parent 96662c3 commit b63e73a

File tree

3 files changed

+123
-0
lines changed

3 files changed

+123
-0
lines changed

api_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,19 @@ func TestApi_BrokenImport(t *testing.T) {
5555
assert.Len(t, result.Files, 1)
5656
assert.Len(t, errors, 1)
5757
}
58+
59+
func TestApi_Crlf(t *testing.T) {
60+
var errors TestReporter
61+
result := cssc.Compile(cssc.Options{
62+
Entry: []string{
63+
"testdata/crlf/monaco.css",
64+
},
65+
Transforms: transforms.Options{
66+
ImportRules: transforms.ImportRulesInline,
67+
},
68+
Reporter: &errors,
69+
})
70+
71+
assert.Len(t, result.Files, 1)
72+
assert.Len(t, errors, 0)
73+
}

internal/lexer/lexer.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,19 @@ func (l *Lexer) step() {
8282
return
8383
}
8484

85+
// "Convert" to newline. https://www.w3.org/TR/css-syntax-3/#newline
86+
if cp == '\r' {
87+
next, nextSize := utf8.DecodeRuneInString(l.source.Content[l.pos+size:])
88+
if next == '\n' {
89+
l.source.Lines = append(l.source.Lines, l.pos+size+nextSize)
90+
}
91+
92+
l.ch = next
93+
l.lastPos = l.pos
94+
l.pos += size + nextSize
95+
return
96+
}
97+
8598
if cp == '\n' {
8699
l.source.Lines = append(l.source.Lines, l.pos+size)
87100
}

testdata/crlf/monaco.css

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
.monaco-action-bar {
7+
text-align: right;
8+
overflow: hidden;
9+
white-space: nowrap;
10+
}
11+
12+
.monaco-action-bar .actions-container {
13+
display: flex;
14+
margin: 0 auto;
15+
padding: 0;
16+
width: 100%;
17+
justify-content: flex-end;
18+
}
19+
20+
.monaco-action-bar.vertical .actions-container {
21+
display: inline-block;
22+
}
23+
24+
.monaco-action-bar.reverse .actions-container {
25+
flex-direction: row-reverse;
26+
}
27+
28+
.monaco-action-bar .action-item {
29+
cursor: pointer;
30+
display: inline-block;
31+
transition: transform 50ms ease;
32+
position: relative; /* DO NOT REMOVE - this is the key to preventing the ghosting icon bug in Chrome 42 */
33+
}
34+
35+
.monaco-action-bar .action-item.disabled {
36+
cursor: default;
37+
}
38+
39+
.monaco-action-bar.animated .action-item.active {
40+
transform: scale(1.272019649, 1.272019649); /* 1.272019649 = √φ */
41+
}
42+
43+
.monaco-action-bar .action-item .icon,
44+
.monaco-action-bar .action-item .codicon {
45+
display: inline-block;
46+
}
47+
48+
.monaco-action-bar .action-label {
49+
font-size: 11px;
50+
margin-right: 4px;
51+
}
52+
53+
.monaco-action-bar .action-item.disabled .action-label,
54+
.monaco-action-bar .action-item.disabled .action-label:hover {
55+
opacity: 0.4;
56+
}
57+
58+
/* Vertical actions */
59+
60+
.monaco-action-bar.vertical {
61+
text-align: left;
62+
}
63+
64+
.monaco-action-bar.vertical .action-item {
65+
display: block;
66+
}
67+
68+
.monaco-action-bar.vertical .action-label.separator {
69+
display: block;
70+
border-bottom: 1px solid #bbb;
71+
padding-top: 1px;
72+
margin-left: .8em;
73+
margin-right: .8em;
74+
}
75+
76+
.monaco-action-bar.animated.vertical .action-item.active {
77+
transform: translate(5px, 0);
78+
}
79+
80+
.secondary-actions .monaco-action-bar .action-label {
81+
margin-left: 6px;
82+
}
83+
84+
/* Action Items */
85+
.monaco-action-bar .action-item.select-container {
86+
overflow: hidden; /* somehow the dropdown overflows its container, we prevent it here to not push */
87+
flex: 1;
88+
max-width: 170px;
89+
min-width: 60px;
90+
display: flex;
91+
align-items: center;
92+
justify-content: center;
93+
margin-right: 10px;
94+
}

0 commit comments

Comments
 (0)