Skip to content

Fix the line number for rules produced inside a sigil_SHEET #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/live_view_native/stylesheet/rules_parser.ex
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
defmodule LiveViewNative.Stylesheet.RulesParser do
@moduledoc false

defmacro sigil_RULES({:<<>>, _meta, [rules]}, _modifier) do
defmacro sigil_RULES({:<<>>, _meta, [rules]}, opts) do
opts = [
file: __CALLER__.file,
line: __CALLER__.line + 1,
line:
if is_list(opts) && is_integer(Keyword.get(opts, :line)) do
Keyword.get(opts, :line)
else
__CALLER__.line + 1
end,
module: __CALLER__.module,
variable_context: nil
]
Expand Down
4 changes: 2 additions & 2 deletions lib/live_view_native/stylesheet/sheet_parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ defmodule LiveViewNative.Stylesheet.SheetParser do
module: __CALLER__.module
)

for {arguments, _opts, body} <- blocks do
for {arguments, opts, body} <- blocks do
quote do
def class(unquote_splicing(arguments)) do
sigil_RULES(<<unquote(body)>>, [])
sigil_RULES(<<unquote(body)>>, unquote(opts))
end
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/live_view_native/stylesheet/sheet_parser/block.ex
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ defmodule LiveViewNative.Stylesheet.SheetParser.Block do
]
else
[
line: context.block_line,
annotations: context.context.annotations
]
end
Expand Down
2 changes: 1 addition & 1 deletion test/live_view_native/stylesheet/sheet_parser_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ defmodule LiveViewNative.Stylesheet.SheetParserTest do
result = SheetParser.parse(sheet, file: @file_path, module: @module)
Application.delete_env(:live_view_native_stylesheet, :annotations)

assert result == [{["color-red"], [annotations: false], "color(.red)"}]
assert result == [{["color-red"], [line: 2, annotations: false], "color(.red)"}]
end

@annotations true
Expand Down
Loading