Commit 32c970a8 authored by abarth's avatar abarth Committed by Commit bot

Improve the names used in Mojo JS modules

Previously, we just used ugly numbered names as the local names for modules in
JavaScript. Now we try to use a meaningful name based on the name of the
module.

There shouldn't be any behavior change.

R=hansmuller@chromium.org

Review URL: https://codereview.chromium.org/653793002

Cr-Commit-Position: refs/heads/master@{#299413}
parent 6820c707
......@@ -275,11 +275,20 @@ class Generator(generator.Generator):
self.Write(self.GenerateHTMLModule(), "%s.html" % self.module.name)
def GetImports(self):
# Since each import is assigned a variable in JS, they need to have unique
# names.
counter = 1
for each in self.module.imports:
each["unique_name"] = "import" + str(counter)
used_names = set()
for each_import in self.module.imports:
simple_name = each_import["module_name"].split(".")[0]
# Since each import is assigned a variable in JS, they need to have unique
# names.
unique_name = simple_name
counter = 0
while unique_name in used_names:
counter += 1
unique_name = simple_name + str(counter)
used_names.add(unique_name)
each_import["unique_name"] = unique_name
counter += 1
return self.module.imports
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment