Commit bba416f4 authored by rdevlin.cronin's avatar rdevlin.cronin Committed by Commit bot

[Extensions] Precede api enums with an '_' if the first character is a digit

If the first character of an extension api enum is a digit (we know that the
enums can only be composed of a-zA-Z0-9_ now), then precede it with a digit
so that people can do chrome.fooApi._345_CRAZY_ENUM.

BUG=463184

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

Cr-Commit-Position: refs/heads/master@{#327198}
parent fbaa5dc2
...@@ -307,6 +307,10 @@ Binding.prototype = { ...@@ -307,6 +307,10 @@ Binding.prototype = {
$String.replace(enumValue, /([a-z])([A-Z])/g, '$1_$2'); $String.replace(enumValue, /([a-z])([A-Z])/g, '$1_$2');
// Replace my_Enum-Foo with my_Enum_Foo: // Replace my_Enum-Foo with my_Enum_Foo:
propertyName = $String.replace(propertyName, /\W/g, '_'); propertyName = $String.replace(propertyName, /\W/g, '_');
// If the first character is a digit (we know it must be one of
// a digit, a letter, or an underscore), precede it with an
// underscore.
propertyName = $String.replace(propertyName, /^(\d)/g, '_$1');
// Uppercase (replace my_Enum_Foo with MY_ENUM_FOO): // Uppercase (replace my_Enum_Foo with MY_ENUM_FOO):
propertyName = $String.toUpperCase(propertyName); propertyName = $String.toUpperCase(propertyName);
mod[id][propertyName] = enumValue; mod[id][propertyName] = enumValue;
......
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