Packages

Shorthand syntax for Elixir maps: `%{foo, bar} = map; IO.puts(foo)`

Current section

8 Versions

Jump to

Compare versions

5 files changed
+29 additions
-13 deletions
  @@ -38,7 +38,11 @@ Simply remove the `runtime: false` parameter from the dependency definition in `
38 38 This feature builds on top of both the base implementation change & runtime instrumentation.
39 39 ElixirLS will see and analyze the expanded code.
40 40
41 - ## 1.0.2 (Unreleased)
41 + ## 1.0.3 (Unreleased)
42 +
43 + - Fix compatibility with Elixir 1.20's new `string_to_tokens` return shape
44 +
45 + ## 1.0.2
42 46
43 47 ### Features
  @@ -54,7 +54,7 @@ end
54 54
55 55 def deps do
56 56 [
57 - {:es6_maps, "~> 1.0.2"}
57 + {:es6_maps, "~> 1.0.3"}
58 58 ]
59 59 end
60 60 ```
  @@ -156,6 +156,6 @@ After `es6_maps` runs as one of the Mix compilers, the Elixir compiler will use
156 156 > [!IMPORTANT]
157 157 >
158 158 > By the nature of this solution it's tightly coupled to the internal Elixir implementation.
159 - > The current version of `es6_maps` should work for Elixir 1.15, 1.16, 1.17, 1.18 and the upcoming 1.19 version, but may break in the future.
159 + > The current version of `es6_maps` should work for Elixir 1.15, 1.16, 1.17, 1.18, 1.19, 1.20, and the upcoming 1.21 version, but may break in the future.
160 160 >
161 161 > That said, starting with version 1.0.0 `es6_maps` instruments a very stable API that's unlikely to change.
  @@ -1,6 +1,6 @@
1 1 {<<"links">>,[{<<"GitHub">>,<<"https://github.com/kzemek/es6_maps">>}]}.
2 2 {<<"name">>,<<"es6_maps">>}.
3 - {<<"version">>,<<"1.0.2">>}.
3 + {<<"version">>,<<"1.0.3">>}.
4 4 {<<"description">>,
5 5 <<"Shorthand syntax for Elixir maps: `%{foo, bar} = map; IO.puts(foo)`">>}.
6 6 {<<"elixir">>,<<"~> 1.16">>}.
  @@ -13,12 +13,12 @@
13 13 {<<"requirement">>,<<"~> 0.2.2">>},
14 14 {<<"repository">>,<<"hexpm">>}]]}.
15 15 {<<"files">>,
16 - [<<"lib">>,<<"lib/mix">>,<<"lib/mix/tasks">>,<<"lib/mix/tasks/compile">>,
17 - <<"lib/mix/tasks/compile/es6_maps.ex">>,<<"lib/es6_maps">>,
16 + [<<"lib">>,<<"lib/es6_maps">>,<<"lib/es6_maps/es6_maps.ex">>,
18 17 <<"lib/es6_maps/internal">>,
19 18 <<"lib/es6_maps/internal/bytecode_injector.ex">>,
20 - <<"lib/es6_maps/es6_maps.ex">>,<<"lib/es6_maps/formatter.ex">>,
21 19 <<"lib/es6_maps/elixir_sense">>,<<"lib/es6_maps/elixir_sense/plugin.ex">>,
20 + <<"lib/es6_maps/formatter.ex">>,<<"lib/mix">>,<<"lib/mix/tasks">>,
21 + <<"lib/mix/tasks/compile">>,<<"lib/mix/tasks/compile/es6_maps.ex">>,
22 22 <<".formatter.exs">>,<<"mix.exs">>,<<"README.md">>,<<"LICENSE">>,
23 23 <<"CHANGELOG.md">>]}.
24 24 {<<"build_tools">>,[<<"mix">>]}.
  @@ -11,12 +11,24 @@ defmodule Es6Maps.Internal.BytecodeInjector do
11 11 def string_to_tokens(string, line, column, file, opts) do
12 12 {enabled?, opts} = Keyword.pop(opts, :es6_maps, true)
13 13
14 - with {:ok, tokens} <- string_to_tokens_orig(string, line, column, file, opts) do
14 + # Elixir <=1.19 return {:ok, tokens}; >1.20 return {:ok, tokens, warnings}
15 + with orig_result when elem(orig_result, 0) == :ok <-
16 + string_to_tokens_orig(string, line, column, file, opts) do
17 + tokens = elem(orig_result, 1)
18 +
15 19 with true <- enabled?,
16 20 opts = Keyword.put(opts, :columns, true),
17 - {:ok, quoted} <- :elixir.tokens_to_quoted(tokens, file, opts),
18 - do: {:ok, es6_maps_expand_identifiers(tokens, quoted)},
19 - else: (_ -> {:ok, tokens})
21 + {:ok, quoted} <- es6_maps_tokens_to_quoted(tokens, file, opts),
22 + do: put_elem(orig_result, 1, es6_maps_expand_identifiers(tokens, quoted)),
23 + else: (_ -> orig_result)
24 + end
25 + end
26 +
27 + defp es6_maps_tokens_to_quoted(tokens, file, opts) do
28 + case :elixir.tokens_to_quoted(tokens, file, opts) do
29 + {:ok, quoted} -> {:ok, quoted}
30 + {:ok, quoted, _warnings} -> {:ok, quoted}
31 + {:error, reason} -> {:error, reason}
20 32 end
21 33 end
  @@ -4,7 +4,7 @@ defmodule Es6Maps.MixProject do
4 4 def project do
5 5 [
6 6 app: :es6_maps,
7 - version: "1.0.2",
7 + version: "1.0.3",
8 8 description: "Shorthand syntax for Elixir maps: `%{foo, bar} = map; IO.puts(foo)`",
9 9 package: package(),
10 10 source_url: "https://github.com/kzemek/es6_maps",
  @@ -24,7 +24,7 @@ defmodule Es6Maps.MixProject do
24 24 defp deps do
25 25 [
26 26 {:beam_patch, "~> 0.2.2"},
27 - {:ex_doc, "~> 0.39.1", only: :dev, runtime: false, optional: true},
27 + {:ex_doc, "~> 0.40.0", only: :dev, runtime: false, optional: true},
28 28 {:credo, "~> 1.7", only: [:dev, :test], runtime: false, optional: true},
29 29 {:dialyxir, "~> 1.4", only: [:dev, :test], runtime: false, optional: true}
30 30 ]