OLD | NEW |
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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 c.Concat(self._TypeToJsType(namespace_name, param.type_), new_line=False) |
| 122 if param.optional: |
| 123 c.Append('|undefined', new_line=False) |
122 if i is not len(function.params) - 1: | 124 if i is not len(function.params) - 1: |
123 c.Append(', ', new_line=False, strip_right=False) | 125 c.Append(', ', new_line=False, strip_right=False) |
124 c.Append('):', new_line=False) | 126 c.Append('):', new_line=False) |
125 | 127 |
126 if function.returns: | 128 if function.returns: |
127 c.Concat(self._TypeToJsType(namespace_name, function.returns), | 129 c.Concat(self._TypeToJsType(namespace_name, function.returns), |
128 new_line=False) | 130 new_line=False) |
129 else: | 131 else: |
130 c.Append('void', new_line=False) | 132 c.Append('void', new_line=False) |
131 | 133 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 """Returns a @see link for a given API 'object' (type, method, or event). | 174 """Returns a @see link for a given API 'object' (type, method, or event). |
173 """ | 175 """ |
174 | 176 |
175 # NOTE(devlin): This is kind of a hack. Some APIs will be hosted on | 177 # NOTE(devlin): This is kind of a hack. Some APIs will be hosted on |
176 # developer.chrome.com/apps/ instead of /extensions/, and some APIs have | 178 # developer.chrome.com/apps/ instead of /extensions/, and some APIs have |
177 # '.'s in them (like app.window), which should resolve to 'app_window'. | 179 # '.'s in them (like app.window), which should resolve to 'app_window'. |
178 # Luckily, the doc server has excellent url resolution, and knows exactly | 180 # Luckily, the doc server has excellent url resolution, and knows exactly |
179 # what we mean. This saves us from needing any complicated logic here. | 181 # what we mean. This saves us from needing any complicated logic here. |
180 return ('@see https://developer.chrome.com/extensions/%s#%s-%s' % | 182 return ('@see https://developer.chrome.com/extensions/%s#%s-%s' % |
181 (namespace_name, object_type, object_name)) | 183 (namespace_name, object_type, object_name)) |
OLD | NEW |