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

Side by Side Diff: tools/json_schema_compiler/js_util.py

Issue 2768213002: [Closure Externs] Add wrapping parens on optional params (Closed)
Patch Set: . Created 3 years, 9 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 unified diff | Download patch
« no previous file with comments | « tools/json_schema_compiler/js_externs_generator_test.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 from code import Code 5 from code import Code
6 from model import PropertyType 6 from model import PropertyType
7 7
8 from datetime import datetime 8 from datetime import datetime
9 9
10 LICENSE = """// Copyright %s The Chromium Authors. All rights reserved. 10 LICENSE = """// Copyright %s The Chromium Authors. All rights reserved.
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 c.Append('|undefined)', new_line=False) 111 c.Append('|undefined)', new_line=False)
112 else: 112 else:
113 c.Concat(self._TypeToJsType(namespace_name, js_type), new_line=False) 113 c.Concat(self._TypeToJsType(namespace_name, js_type), new_line=False)
114 c.Append('}', new_line=False) 114 c.Append('}', new_line=False)
115 115
116 def _FunctionToJsFunction(self, namespace_name, function): 116 def _FunctionToJsFunction(self, namespace_name, function):
117 """Converts a model.Function to a JS type (i.e., function([params])...)""" 117 """Converts a model.Function to a JS type (i.e., function([params])...)"""
118 c = Code() 118 c = Code()
119 c.Append('function(') 119 c.Append('function(')
120 for i, param in enumerate(function.params): 120 for i, param in enumerate(function.params):
121 c.Concat(self._TypeToJsType(namespace_name, param.type_), new_line=False) 121 t = self._TypeToJsType(namespace_name, param.type_)
122 if param.optional: 122 if param.optional:
123 c.Append('|undefined', new_line=False) 123 c.Append('(', new_line=False)
124 c.Concat(t, new_line=False)
125 c.Append('|undefined)', new_line=False)
126 else:
127 c.Concat(t, new_line = False)
124 if i is not len(function.params) - 1: 128 if i is not len(function.params) - 1:
125 c.Append(', ', new_line=False, strip_right=False) 129 c.Append(', ', new_line=False, strip_right=False)
126 c.Append('):', new_line=False) 130 c.Append('):', new_line=False)
127 131
128 if function.returns: 132 if function.returns:
129 c.Concat(self._TypeToJsType(namespace_name, function.returns), 133 c.Concat(self._TypeToJsType(namespace_name, function.returns),
130 new_line=False) 134 new_line=False)
131 else: 135 else:
132 c.Append('void', new_line=False) 136 c.Append('void', new_line=False)
133 137
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 """Returns a @see link for a given API 'object' (type, method, or event). 178 """Returns a @see link for a given API 'object' (type, method, or event).
175 """ 179 """
176 180
177 # NOTE(devlin): This is kind of a hack. Some APIs will be hosted on 181 # NOTE(devlin): This is kind of a hack. Some APIs will be hosted on
178 # developer.chrome.com/apps/ instead of /extensions/, and some APIs have 182 # developer.chrome.com/apps/ instead of /extensions/, and some APIs have
179 # '.'s in them (like app.window), which should resolve to 'app_window'. 183 # '.'s in them (like app.window), which should resolve to 'app_window'.
180 # Luckily, the doc server has excellent url resolution, and knows exactly 184 # Luckily, the doc server has excellent url resolution, and knows exactly
181 # what we mean. This saves us from needing any complicated logic here. 185 # what we mean. This saves us from needing any complicated logic here.
182 return ('@see https://developer.chrome.com/extensions/%s#%s-%s' % 186 return ('@see https://developer.chrome.com/extensions/%s#%s-%s' %
183 (namespace_name, object_type, object_name)) 187 (namespace_name, object_type, object_name))
OLDNEW
« no previous file with comments | « tools/json_schema_compiler/js_externs_generator_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698