Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Unified Diff: tools/json_schema_compiler/js_externs_generator.py

Issue 1109793003: [Extern Generation] Normify extern enum property names (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/json_schema_compiler/js_externs_generator_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/json_schema_compiler/js_externs_generator.py
diff --git a/tools/json_schema_compiler/js_externs_generator.py b/tools/json_schema_compiler/js_externs_generator.py
index 786f05838d8f7390c6a0866fc81265ec774426d9..b76c847ac66bc523e02b5957d42453647ad7a182 100644
--- a/tools/json_schema_compiler/js_externs_generator.py
+++ b/tools/json_schema_compiler/js_externs_generator.py
@@ -14,6 +14,7 @@ from schema_util import *
import os
from datetime import datetime
+import re
LICENSE = ("""// Copyright %s The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
@@ -71,8 +72,22 @@ class _Generator(object):
.Append(self._GenerateSeeLink('type', js_type.simple_name))
.Eblock(' */'))
c.Append('chrome.%s.%s = {' % (self._namespace.name, js_type.name))
+
+ def get_property_name(e):
Dan Beam 2015/04/28 00:21:46 nit: def scare_small_children(e): https://google-s
Devlin 2015/04/28 00:25:08 Haha I don't think I've ever seen that (phrasing,
+ # Enum properties are normified to be in ALL_CAPS_STYLE.
+ # Assume enum '1ring-rulesThemAll'.
+ # Transform to '1ring-rules_Them_All'.
+ e = re.sub(r'([a-z])([A-Z])', r'\1_\2', e)
+ # Transform to '1ring_rules_Them_All'.
+ e = re.sub(r'\W', '_', e)
+ # Transform to '_1ring_rules_Them_All'.
+ e = re.sub(r'^(\d)', r'_\1', e)
+ # Transform to '_1RING_RULES_THEM_ALL'.
+ return e.upper()
+
c.Append('\n'.join(
- [" %s: '%s'," % (v.name, v.name) for v in js_type.enum_values]))
+ [" %s: '%s'," % (get_property_name(v.name), v.name)
+ for v in js_type.enum_values]))
c.Append('};')
return c
« no previous file with comments | « no previous file | tools/json_schema_compiler/js_externs_generator_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698