| 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 Generator that produces an externs file for the Closure Compiler. | 5 Generator that produces an externs file for the Closure Compiler. |
| 6 Note: This is a work in progress, and generated externs may require tweaking. | 6 Note: This is a work in progress, and generated externs may require tweaking. |
| 7 | 7 |
| 8 See https://developers.google.com/closure/compiler/docs/api-tutorial3#externs | 8 See https://developers.google.com/closure/compiler/docs/api-tutorial3#externs |
| 9 """ | 9 """ |
| 10 | 10 |
| 11 from code import Code | 11 from code import Code |
| 12 from js_util import JsUtil | 12 from js_util import JsUtil |
| 13 from model import * | 13 from model import * |
| 14 from schema_util import * | 14 from schema_util import * |
| 15 | 15 |
| 16 import os | 16 import os |
| 17 import sys | 17 import sys |
| 18 import re | 18 import re |
| 19 | 19 |
| 20 NOTE = """// NOTE: The format of types has changed. 'FooType' is now | 20 NOTE = """// NOTE: The format of types has changed. 'FooType' is now |
| 21 // 'chrome.%s.FooType'. | 21 // 'chrome.%s.FooType'. |
| 22 // Please run the closure compiler before committing changes. | 22 // Please run the closure compiler before committing changes. |
| 23 // See https://code.google.com/p/chromium/wiki/ClosureCompilation. | 23 // See https://chromium.googlesource.com/chromium/src/+/master/docs/closure_comp
ilation.md |
| 24 """ | 24 """ |
| 25 | 25 |
| 26 class JsExternsGenerator(object): | 26 class JsExternsGenerator(object): |
| 27 def Generate(self, namespace): | 27 def Generate(self, namespace): |
| 28 return _Generator(namespace).Generate() | 28 return _Generator(namespace).Generate() |
| 29 | 29 |
| 30 class _Generator(object): | 30 class _Generator(object): |
| 31 def __init__(self, namespace): | 31 def __init__(self, namespace): |
| 32 self._namespace = namespace | 32 self._namespace = namespace |
| 33 self._js_util = JsUtil() | 33 self._js_util = JsUtil() |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 c.Append('chrome.%s = {};' % self._namespace.name) | 186 c.Append('chrome.%s = {};' % self._namespace.name) |
| 187 c.Append() | 187 c.Append() |
| 188 | 188 |
| 189 def _GetFunctionParams(self, function): | 189 def _GetFunctionParams(self, function): |
| 190 """Returns the function params string for function. | 190 """Returns the function params string for function. |
| 191 """ | 191 """ |
| 192 params = function.params[:] | 192 params = function.params[:] |
| 193 if function.callback: | 193 if function.callback: |
| 194 params.append(function.callback) | 194 params.append(function.callback) |
| 195 return ', '.join(param.name for param in params) | 195 return ', '.join(param.name for param in params) |
| OLD | NEW |