Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

moddle

Package Overview
Dependencies
Maintainers
3
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

moddle - npm Package Compare versions

Comparing version 0.6.2 to 0.6.3

test/fixtures/model/redefine.json

52

lib/descriptor-builder.js

@@ -25,5 +25,18 @@ 'use strict';

DescriptorBuilder.prototype.addProperty = function(p, idx) {
this.addNamedProperty(p, true);
/**
* Add property at given index.
*
* @param {Object} p
* @param {Number} [idx]
* @param {Boolean} [validate=true]
*/
DescriptorBuilder.prototype.addProperty = function(p, idx, validate) {
if (typeof idx === 'boolean') {
validate = idx;
idx = undefined;
}
this.addNamedProperty(p, validate !== false);
var properties = this.properties;

@@ -39,3 +52,3 @@

DescriptorBuilder.prototype.replaceProperty = function(oldProperty, newProperty) {
DescriptorBuilder.prototype.replaceProperty = function(oldProperty, newProperty, replace) {
var oldNameNs = oldProperty.ns;

@@ -59,7 +72,3 @@

// replacing the named property is intentional
// thus, validate only if this is a "rename" operation
this.addNamedProperty(newProperty, rename);
// replace old property at index with new one
// validate existence and get location of old property
var idx = props.indexOf(oldProperty);

@@ -70,5 +79,13 @@ if (idx === -1) {

props[idx] = newProperty;
// remove old property
props.splice(idx, 1);
// replace propertiesByName entry with new property
// replacing the named property is intentional
//
// * validate only if this is a "rename" operation
// * add at specific index unless we "replace"
//
this.addProperty(newProperty, replace ? undefined : idx, rename);
// make new property available under old name
propertiesByName[oldNameNs.name] = propertiesByName[oldNameNs.localName] = newProperty;

@@ -78,6 +95,6 @@ };

DescriptorBuilder.prototype.redefineProperty = function(p) {
DescriptorBuilder.prototype.redefineProperty = function(p, targetPropertyName, replace) {
var nsPrefix = p.ns.prefix;
var parts = p.redefines.split('#');
var parts = targetPropertyName.split('#');

@@ -91,3 +108,3 @@ var name = parseNameNs(parts[0], nsPrefix);

} else {
this.replaceProperty(redefinedProperty, p);
this.replaceProperty(redefinedProperty, p, replace);
}

@@ -179,5 +196,8 @@

// add redefine support
if (p.redefines) {
this.redefineProperty(p);
var replaces = p.replaces,
redefines = p.redefines;
// add replace/redefine support
if (replaces || redefines) {
this.redefineProperty(p, replaces || redefines, replaces);
} else {

@@ -184,0 +204,0 @@ if (p.isBody) {

{
"name": "moddle",
"version": "0.6.2",
"version": "0.6.3",
"description": "A library for importing meta-model based file formats into JS",

@@ -5,0 +5,0 @@ "directories": {

@@ -8,4 +8,3 @@ 'use strict';

var createModel = Helper.createModelBuilder('test/fixtures/model/extension/');
var model = createModel([ 'base', 'custom' ]);
var createModel = Helper.createModelBuilder('test/fixtures/model/');

@@ -15,2 +14,5 @@

var model = createModel([ 'extension/base', 'extension/custom' ]);
describe('trait', function() {

@@ -131,2 +133,60 @@

describe('property replacement', function() {
var model = createModel([ 'replace' ]);
it('should replace in descriptor', function() {
// given
var Extension = model.getType('r:Extension');
// when
var descriptor = model.getElementDescriptor(Extension),
propertyNames = descriptor.properties.map(function(p) {
return p.name;
});
// then
expect(propertyNames).to.eql([
'name',
'value',
'id'
]);
expect(descriptor.propertiesByName['r:id'].type).to.eql('Integer');
expect(descriptor.propertiesByName['id'].type).to.eql('Integer');
})
});
describe('property redefinition', function() {
var model = createModel([ 'redefine' ]);
it('should redefine in descriptor', function() {
// given
var Extension = model.getType('r:Extension');
// when
var descriptor = model.getElementDescriptor(Extension),
propertyNames = descriptor.properties.map(function(p) {
return p.name;
});
// then
expect(propertyNames).to.eql([
'id',
'name',
'value'
]);
expect(descriptor.propertiesByName['r:id'].type).to.eql('Integer');
expect(descriptor.propertiesByName['id'].type).to.eql('Integer');
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc