mirror of
https://github.com/hanzoai/postcss.git
synced 2026-09-24 17:01:56 +00:00
Add end position to nodes
This commit is contained in:
+33
-12
@@ -18,6 +18,7 @@ class Parser
|
||||
|
||||
@pos = -1
|
||||
@line = 1
|
||||
@lines = []
|
||||
@column = 0
|
||||
@buffer = ''
|
||||
|
||||
@@ -145,12 +146,7 @@ class Parser
|
||||
@error('Unexpected }')
|
||||
else
|
||||
if @inside('value')
|
||||
start = @buffer.search(/\s*\}$/)
|
||||
after = @buffer[start..-2]
|
||||
@buffer = @buffer[0..start]
|
||||
|
||||
@inValue('close')
|
||||
@current.after = after
|
||||
@fixEnd -> @inValue('close')
|
||||
else
|
||||
@current.semicolon = true if @semicolon
|
||||
@current.after = @prevBuffer()
|
||||
@@ -207,12 +203,7 @@ class Parser
|
||||
|
||||
endFile: ->
|
||||
if @inside('atrule-param') or @inside('atrule-name')
|
||||
start = @buffer.search(/\s*$/)
|
||||
after = @buffer[start..-1]
|
||||
@buffer = @buffer[0..start]
|
||||
|
||||
@inAtrule('close')
|
||||
@buffer = after
|
||||
@fixEnd -> @inAtrule('close')
|
||||
|
||||
if @parents.length > 1
|
||||
@error('Unclosed block', @current.source.start)
|
||||
@@ -235,6 +226,7 @@ class Parser
|
||||
@buffer += @letter
|
||||
|
||||
if @letter == "\n"
|
||||
@lines[@line] = @column - 1
|
||||
@line += 1
|
||||
@column = 0
|
||||
|
||||
@@ -264,7 +256,36 @@ class Parser
|
||||
@current.before = @buffer[0..-2]
|
||||
@buffer = ''
|
||||
|
||||
fixEnd: (callback) ->
|
||||
if @letter == '}'
|
||||
start = @buffer.search(/\s*\}$/)
|
||||
after = @buffer[start..-2]
|
||||
else
|
||||
start = @buffer.search(/\s*$/)
|
||||
after = @buffer[start..-1]
|
||||
@buffer = @buffer[0..start]
|
||||
|
||||
el = @current
|
||||
callback.apply(@)
|
||||
|
||||
lines = after.match(/\n/g)
|
||||
if lines
|
||||
el.source.end.line -= lines.length
|
||||
all = @lines[el.source.end.line]
|
||||
last = after.indexOf("\n")
|
||||
last = after.length if last == -1
|
||||
el.source.end.column = all - last
|
||||
else
|
||||
el.source.end.column -= after.length
|
||||
|
||||
@current.after = after
|
||||
@buffer = after
|
||||
|
||||
pop: ->
|
||||
@current.source.end =
|
||||
line: @line
|
||||
column: @column
|
||||
|
||||
@popType()
|
||||
@parents.pop()
|
||||
@current = @parents[@parents.length - 1]
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"before": "",
|
||||
@@ -22,6 +26,10 @@
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 21
|
||||
}
|
||||
},
|
||||
"before": "\n ",
|
||||
@@ -41,6 +49,10 @@
|
||||
"start": {
|
||||
"line": 5,
|
||||
"column": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 7,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"before": "\n\n",
|
||||
@@ -56,6 +68,10 @@
|
||||
"start": {
|
||||
"line": 6,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 6,
|
||||
"column": 28
|
||||
}
|
||||
},
|
||||
"before": "\n ",
|
||||
@@ -76,6 +92,10 @@
|
||||
"start": {
|
||||
"line": 9,
|
||||
"column": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 11,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"before": "\n\n",
|
||||
@@ -91,6 +111,10 @@
|
||||
"start": {
|
||||
"line": 10,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 10,
|
||||
"column": 17
|
||||
}
|
||||
},
|
||||
"before": "\n ",
|
||||
@@ -111,6 +135,10 @@
|
||||
"start": {
|
||||
"line": 13,
|
||||
"column": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 15,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"before": "\n\n",
|
||||
@@ -126,6 +154,10 @@
|
||||
"start": {
|
||||
"line": 14,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 14,
|
||||
"column": 17
|
||||
}
|
||||
},
|
||||
"before": "\n ",
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 17
|
||||
}
|
||||
},
|
||||
"before": "",
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 8
|
||||
}
|
||||
},
|
||||
"before": "",
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 16
|
||||
}
|
||||
},
|
||||
"before": "\n",
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 69
|
||||
}
|
||||
},
|
||||
"before": "",
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 10,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"before": "",
|
||||
@@ -22,6 +26,10 @@
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 9,
|
||||
"column": 5
|
||||
}
|
||||
},
|
||||
"before": "\n ",
|
||||
@@ -40,6 +48,10 @@
|
||||
"start": {
|
||||
"line": 4,
|
||||
"column": 13
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 25
|
||||
}
|
||||
},
|
||||
"before": "\n ",
|
||||
@@ -55,6 +67,10 @@
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 9
|
||||
},
|
||||
"end": {
|
||||
"line": 5,
|
||||
"column": 9
|
||||
}
|
||||
},
|
||||
"before": "\n ",
|
||||
@@ -74,6 +90,10 @@
|
||||
"start": {
|
||||
"line": 7,
|
||||
"column": 13
|
||||
},
|
||||
"end": {
|
||||
"line": 7,
|
||||
"column": 24
|
||||
}
|
||||
},
|
||||
"before": "\n ",
|
||||
@@ -89,6 +109,10 @@
|
||||
"start": {
|
||||
"line": 6,
|
||||
"column": 9
|
||||
},
|
||||
"end": {
|
||||
"line": 8,
|
||||
"column": 9
|
||||
}
|
||||
},
|
||||
"before": "\n ",
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
"start": {
|
||||
"line": 4,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 17
|
||||
}
|
||||
},
|
||||
"before": "\n /* inside */\n ",
|
||||
@@ -26,6 +30,10 @@
|
||||
"start": {
|
||||
"line": 6,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 7,
|
||||
"column": 13
|
||||
}
|
||||
},
|
||||
"before": "\n /* between */\n ",
|
||||
@@ -41,6 +49,10 @@
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 8,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"before": "/* a { color: black } */\n",
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 17
|
||||
}
|
||||
},
|
||||
"before": "\n ",
|
||||
@@ -26,6 +30,10 @@
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 22
|
||||
}
|
||||
},
|
||||
"before": "\n ",
|
||||
@@ -41,6 +49,10 @@
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"before": "",
|
||||
|
||||
@@ -8,6 +8,10 @@
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 2
|
||||
}
|
||||
},
|
||||
"before": "",
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 105
|
||||
}
|
||||
},
|
||||
"before": "\n ",
|
||||
@@ -25,6 +29,10 @@
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"before": "",
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 29
|
||||
}
|
||||
},
|
||||
"before": "\n ",
|
||||
@@ -25,6 +29,10 @@
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"before": "",
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 19
|
||||
}
|
||||
},
|
||||
"before": "\n *",
|
||||
@@ -26,6 +30,10 @@
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 23
|
||||
}
|
||||
},
|
||||
"before": "\n _",
|
||||
@@ -42,6 +50,10 @@
|
||||
"start": {
|
||||
"line": 4,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 23
|
||||
}
|
||||
},
|
||||
"before": "\n ",
|
||||
@@ -57,6 +69,10 @@
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 5,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"before": "",
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 26
|
||||
}
|
||||
},
|
||||
"before": "\n ",
|
||||
@@ -26,6 +30,10 @@
|
||||
"start": {
|
||||
"line": 3,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 21
|
||||
}
|
||||
},
|
||||
"before": "\n ",
|
||||
@@ -41,6 +49,10 @@
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"before": "",
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 22
|
||||
}
|
||||
},
|
||||
"before": " ",
|
||||
@@ -25,6 +29,10 @@
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 24
|
||||
}
|
||||
},
|
||||
"before": "",
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 3
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 14
|
||||
}
|
||||
},
|
||||
"before": "",
|
||||
@@ -25,6 +29,10 @@
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 14
|
||||
}
|
||||
},
|
||||
"before": "",
|
||||
|
||||
@@ -8,6 +8,10 @@
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 15
|
||||
}
|
||||
},
|
||||
"before": "\n",
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 5
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 17
|
||||
}
|
||||
},
|
||||
"before": ";;\n ",
|
||||
@@ -25,6 +29,10 @@
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 4,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"before": "",
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 2
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 13
|
||||
}
|
||||
},
|
||||
"before": "\n\t",
|
||||
@@ -25,6 +29,10 @@
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 1
|
||||
},
|
||||
"end": {
|
||||
"line": 3,
|
||||
"column": 1
|
||||
}
|
||||
},
|
||||
"before": "",
|
||||
|
||||
Reference in New Issue
Block a user