surface-ui / surface

A server-side rendering component library for Phoenix
https://surface-ui.org
MIT License
2.08k stars 150 forks source link

`mix surface.convert` tries to convert files that are commented out #649

Open simonmcconnell opened 2 years ago

simonmcconnell commented 2 years ago

Describe the bug

I have a some_component.ex where the entire contents are commented out using #. mix surface.convert attempts to convert this file and crashes.

mix surface.convert failed for file: lib/logacy_web/components/dropdown_lv.ex
** (Surface.Compiler.ParseError) nofile:16:19: expected attribute name, got: `=`
    (surface 0.8.1) lib/surface/compiler/tokenizer.ex:531: Surface.Compiler.Tokenizer.handle_attribute/5
    (surface 0.8.1) lib/surface/compiler/converter.ex:18: Surface.Compiler.Converter.convert/2
    (surface 0.8.1) lib/mix/tasks/surface/surface.convert.ex:75: anonymous fn/5 in Mix.Tasks.Surface.Convert.convert_ex_string!/2
    (elixir 1.13.4) lib/regex.ex:739: Regex.apply_list/5
    (elixir 1.13.4) lib/regex.ex:734: Regex.apply_list/5
    (elixir 1.13.4) lib/regex.ex:669: Regex.replace/4    (elixir 1.13.4) lib/enum.ex:2396: Enum."-reduce/3-lists^foldl/2-0-"/3
    (surface 0.8.1) lib/mix/tasks/surface/surface.convert.ex:65: Mix.Tasks.Surface.Convert.convert_file_contents!/3

    (surface 0.8.1) lib/mix/tasks/surface/surface.convert.ex:118: Mix.Tasks.Surface.Convert.convert_file/3
    (elixir 1.13.4) lib/task/supervised.ex:89: Task.Supervised.invoke_mfa/2
    (elixir 1.13.4) lib/task/supervised.ex:34: Task.Supervised.reply/4
    (stdlib 4.0.1) proc_lib.erl:240: :proc_lib.init_p_do_apply/3

How to reproduce it

  1. comment out the entire contents of a surface component file.
  2. run mix surface.convert
  3. :*(

The behaviour you expected

Commented out lines/files are ignored.

Your Environment

Surface: v0.8.1 LiveView: v0.17.11 Elixir: v1.13.4

Malian commented 2 years ago

I faced the same kind of issue with Sourceror, https://github.com/doorgan/sourceror/issues/57, but in this case it seems that it is directly related to Surface.