diff --git a/src/lang/extensions.coffee b/src/lang/extensions.coffee index e805461..6cf4a2c 100644 --- a/src/lang/extensions.coffee +++ b/src/lang/extensions.coffee @@ -101,12 +101,11 @@ module.exports = [ unless @when? @once 'compile:after', => @debug "augmenting '#{target.kind}:#{target.tag}'" - target.extends @nodes.map (x) -> x.clone(true) - # from = @root.tag if @parent.kind is 'module' and target.root isnt @root - # target.extends @nodes.map (x) -> - # copy = x.clone() - # copy.tag = "#{from}:#{x.tag}" if from? - # return copy + from = @root.tag if @parent.kind is 'module' and target.root isnt @root + target.extends @nodes.map (x) -> + copy = x.clone() + copy.tag = "#{from}:#{x.tag}" if from? + return copy else target.on 'apply:after', (data) => data = expr.apply data for expr in @exprs if data? diff --git a/src/property.litcoffee b/src/property.litcoffee index db849ed..91bcb30 100644 --- a/src/property.litcoffee +++ b/src/property.litcoffee @@ -73,6 +73,7 @@ path | [XPath](./src/xpath.coffee) | computed | dynamically generate XPath for .getter 'type' .getter 'default' .getter 'binding' + .getter 'module' .method 'locate' .method 'lookup' @@ -233,7 +234,12 @@ target `obj` via `Object.defineProperty`. # @debug "[join] applying existing data for #{@name} to:" # @debug obj opts.suppress = true - @set obj[@name], opts + if obj[@name] isnt undefined + @set obj[@name], opts + else if @name.indexOf(':') == -1 and @module + @set obj["#{@module}:#{@name}"], opts + else + @set undefined, opts @parent?.add? @name, this, opts # add to parent diff --git a/src/yang.litcoffee b/src/yang.litcoffee index 4614aeb..2f04c8f 100644 --- a/src/yang.litcoffee +++ b/src/yang.litcoffee @@ -205,6 +205,23 @@ function` which will invoke [eval](#eval-data-opts) when called. "#{@origin.root.tag}:#{@tag}" else @tag ? @kind + @property 'module', + get: -> + if @origin + switch + when @origin instanceof Yang and @parent.kind is 'module' + "#{@origin.tag}" + when @origin instanceof Yang and @parent.kind is 'submodule' + "#{@origin['belongs-to'].tag}" + else @origin.module + else if @parent + switch + when @parent instanceof Yang and @parent.kind is 'module' + "#{@parent.tag}" + when @parent instanceof Yang and @parent.kind is 'submodule' + "#{@parent['belongs-to'].tag}" + else @parent.module + @property 'external', get: -> @origin? and @origin.root isnt @root and @origin.root.kind is 'module' diff --git a/test/extension/module.coffee b/test/extension/module.coffee index 937aa3e..2178fea 100644 --- a/test/extension/module.coffee +++ b/test/extension/module.coffee @@ -60,8 +60,8 @@ describe 'extended schema', -> it "should evaluate configuration data", -> o = (Yang schema) 'foo:bar': - a: 'hello' - b: 10 + 'foo:a': 'hello' # fully qualified property name + b: 10 # contextual property name o.get('foo:bar').should.have.property('a').and.equal('hello') o.get('foo:bar').should.have.property('b').and.equal(10) @@ -133,15 +133,29 @@ describe 'augment schema (external)', -> import foo { prefix foo; } augment "/foo:c1/foo:c2" { - leaf a2; + container a2 { + leaf b1; + leaf b2; + } } } """ it "should parse augment module statement", -> y1 = Yang.use (Yang.parse schema1) y2 = Yang.parse schema2 - y2.locate('/foo:c1/c2/bar:a2').should.have.property('tag').and.equal('a2') - + y2.locate('/foo:c1/c2/bar:a2').should.have.property('tag').and.equal('bar:a2') + y2.locate('/foo:c1/c2/bar:a2/bar:b1').should.have.property('tag').and.equal('b1') + y2.locate('/foo:c1/c2/bar:a2/b2').should.have.property('tag').and.equal('b2') + + o = y2 + 'foo:c1': + c2: + 'bar:a2': + 'bar:b1': 'hello' # fully qualified property name + b2: 10 # contextual property name + o.get('/foo:c1/c2/bar:a2').should.have.property('b1').and.equal('hello') + o.get('/foo:c1/c2/bar:a2').should.have.property('b2').and.equal(10) + describe "import schema", -> before -> Yang.clear()