Handle namespace provides
It looks like the convention in the Closure Library is to export either namespaces (starting with lowercase), constructors (starting with uppercase), or enums (all uppercase, one instance). I don't see any places where the Closure Library exports a function that is not a constructor. Following the same convention, when we export `ol.foo`, it means we are making available function properties of the `ol.foo` object that start with a lowercase letter.
This commit is contained in:
25
build.py
25
build.py
@@ -460,17 +460,23 @@ def build_check_requires_timestamp(t):
|
|||||||
self.children = {}
|
self.children = {}
|
||||||
|
|
||||||
def _build_re(self, key):
|
def _build_re(self, key):
|
||||||
if len(self.children) == 1:
|
if key == '*':
|
||||||
|
assert len(self.children) == 0
|
||||||
|
# We want to match `.doIt` but not `.SomeClass` or `.more.stuff`
|
||||||
|
return '(?=\\.[a-z]\\w*\\b(?!\\.))'
|
||||||
|
elif len(self.children) == 1:
|
||||||
child_key, child = next(self.children.iteritems())
|
child_key, child = next(self.children.iteritems())
|
||||||
child_re = '\\.' + child._build_re(child_key)
|
child_re = child._build_re(child_key)
|
||||||
|
if child_key != '*':
|
||||||
|
child_re = '\\.' + child_re
|
||||||
if self.present:
|
if self.present:
|
||||||
return key + '(' + child_re + ')?'
|
return key + '(' + child_re + ')?'
|
||||||
else:
|
else:
|
||||||
return key + child_re
|
return key + child_re
|
||||||
elif self.children:
|
elif self.children:
|
||||||
children_re = '(?:\\.(?:' + '|'.join(
|
children_re = '(?:' + '|'.join(
|
||||||
self.children[k]._build_re(k)
|
('\\.' if k != '*' else '') + self.children[k]._build_re(k)
|
||||||
for k in sorted(self.children.keys())) + '))'
|
for k in sorted(self.children.keys())) + ')'
|
||||||
if self.present:
|
if self.present:
|
||||||
return key + children_re + '?'
|
return key + children_re + '?'
|
||||||
else:
|
else:
|
||||||
@@ -488,7 +494,14 @@ def build_check_requires_timestamp(t):
|
|||||||
if component not in node.children:
|
if component not in node.children:
|
||||||
node.children[component] = Node()
|
node.children[component] = Node()
|
||||||
node = node.children[component]
|
node = node.children[component]
|
||||||
node.present = True
|
if component[0].islower():
|
||||||
|
# We've arrived at a namespace provide like `ol.foo`.
|
||||||
|
# In this case, we want to match uses like `ol.foo.doIt()` but
|
||||||
|
# not match things like `new ol.foo.SomeClass()`.
|
||||||
|
# For this purpose, we use the special wildcard key for the child.
|
||||||
|
node.children['*'] = Node()
|
||||||
|
else:
|
||||||
|
node.present = True
|
||||||
provide_res = [child.build_re(key)
|
provide_res = [child.build_re(key)
|
||||||
for key, child in root.children.iteritems()]
|
for key, child in root.children.iteritems()]
|
||||||
missing_count = 0
|
missing_count = 0
|
||||||
|
|||||||
Reference in New Issue
Block a user