Skip to content

Commit 6d663b6

Browse files
author
那里好脏不可以
authoredMay 7, 2020
Stylus: Fixed comments breaking declarations + minor improvements (#2372)
Comments broke URLs in all non-greedy declarations. Comments are now matched as part of these declarations. This also adds support for comments inside selectors.
1 parent eb82e80 commit 6d663b6

6 files changed

+41
-7
lines changed
 

‎components/prism-stylus.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,6 @@
7474
};
7575

7676
Prism.languages.stylus = {
77-
'comment': {
78-
pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,
79-
lookbehind: true
80-
},
8177
'atrule-declaration': {
8278
pattern: /(^\s*)@.+/m,
8379
lookbehind: true,
@@ -109,7 +105,6 @@
109105
'property-declaration': {
110106
pattern: /((?:^|\{)([ \t]*))(?:[\w-]|\{[^}\r\n]+\})+(?:\s*:\s*|[ \t]+)[^{\r\n]*(?:;|[^{\r\n,](?=$)(?!(?:\r?\n|\r)(?:\{|\2[ \t]+)))/m,
111107
lookbehind: true,
112-
greedy: true,
113108
inside: {
114109
'property': {
115110
pattern: /^[^\s:]+/,
@@ -131,12 +126,18 @@
131126
lookbehind: true,
132127
inside: {
133128
'interpolation': inside.interpolation,
129+
'comment': inside.comment,
134130
'punctuation': /[{},]/
135131
}
136132
},
137133

138134
'func': inside.func,
139135
'string': inside.string,
136+
'comment': {
137+
pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|\/\/.*)/,
138+
lookbehind: true,
139+
greedy: true
140+
},
140141
'interpolation': inside.interpolation,
141142
'punctuation': /[{}()\[\];:.]/
142143
};

‎components/prism-stylus.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎tests/languages/stylus/atrule-declaration_feature.test

+13
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
@font-face {
44
@keyframes {
55
@media (max-{foo}: bar)
6+
@namespace url(http://www.w3.org/1999/xhtml) // comment
7+
@namespace svg url(http://www.w3.org/2000/svg) // comment
68

79
----------------------------------------------------
810

@@ -23,6 +25,17 @@
2325
["punctuation", ":"],
2426
" bar",
2527
["punctuation", ")"]
28+
]],
29+
["atrule-declaration", [
30+
["atrule", "@namespace"],
31+
["url", "url(http://www.w3.org/1999/xhtml)"],
32+
["comment", "// comment"]
33+
]],
34+
["atrule-declaration", [
35+
["atrule", "@namespace"],
36+
" svg ",
37+
["url", "url(http://www.w3.org/2000/svg)"],
38+
["comment", "// comment"]
2639
]]
2740
]
2841

‎tests/languages/stylus/keyword_feature.test

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ for i in 1..5
22
if a == 3
33
z-index: 1 unless @z-index;
44
return pair[1] if pair[0] == key for pair in hash
5+
if url == "http://example.com" // comment
56

67
----------------------------------------------------
78

@@ -36,6 +37,13 @@ return pair[1] if pair[0] == key for pair in hash
3637
["operator", "=="], " key ",
3738
["keyword", "for"], " pair ",
3839
["operator", "in"], " hash"
40+
]],
41+
["statement", [
42+
["keyword", "if"],
43+
" url ",
44+
["operator", "=="],
45+
["string", "\"http://example.com\""],
46+
["comment", "// comment"]
3947
]]
4048
]
4149

‎tests/languages/stylus/selector_feature.test

+6-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ color red
1818
{foo} {bar}:hover
1919
color red
2020

21+
div // comment
22+
display inline-block // comment
23+
2124
----------------------------------------------------
2225

2326
[
@@ -41,7 +44,9 @@ color red
4144
]],
4245
":hover"
4346
]],
44-
["property-declaration", [["property", ["color"]], ["color", "red"]]]
47+
["property-declaration", [["property", ["color"]], ["color", "red"]]],
48+
["selector", ["div ", ["comment", "// comment"]]],
49+
["property-declaration", [["property", ["display"]], " inline-block ", ["comment", "// comment"]]]
4550
]
4651

4752
----------------------------------------------------

‎tests/languages/stylus/variable-declaration_feature.test

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ foo = 'bar'
22
a = 4
33
bar-baz = 5
44
a += 8
5+
url = "http://example.com" // comment
56

67
----------------------------------------------------
78

@@ -25,6 +26,12 @@ a += 8
2526
["variable", "a"],
2627
["operator", "+="],
2728
["number", "8"]
29+
]],
30+
["variable-declaration", [
31+
["variable", "url"],
32+
["operator", "="],
33+
["string", "\"http://example.com\""],
34+
["comment", "// comment"]
2835
]]
2936
]
3037

0 commit comments

Comments
 (0)
Please sign in to comment.