moddle
Advanced tools
Comparing version 6.1.0 to 6.2.0
@@ -622,3 +622,3 @@ import { forEach, bind, pick, assign, isString, isObject } from 'min-dash'; | ||
var property = this.model.getPropertyDescriptor(target, name); | ||
var property = this.getProperty(target, name); | ||
@@ -634,3 +634,3 @@ var propertyName = property && property.name; | ||
} else { | ||
delete target.$attrs[name]; | ||
delete target.$attrs[stripGlobal(name)]; | ||
} | ||
@@ -648,3 +648,3 @@ } else { | ||
} else { | ||
target.$attrs[name] = value; | ||
target.$attrs[stripGlobal(name)] = value; | ||
} | ||
@@ -664,6 +664,6 @@ } | ||
var property = this.model.getPropertyDescriptor(target, name); | ||
var property = this.getProperty(target, name); | ||
if (!property) { | ||
return target.$attrs[name]; | ||
return target.$attrs[stripGlobal(name)]; | ||
} | ||
@@ -722,3 +722,41 @@ | ||
/** | ||
* Return property with the given name on the element. | ||
* | ||
* @param {any} target | ||
* @param {string} name | ||
* | ||
* @return {object | null} property | ||
*/ | ||
Properties.prototype.getProperty = function(target, name) { | ||
var model = this.model; | ||
var property = model.getPropertyDescriptor(target, name); | ||
if (property) { | ||
return property; | ||
} | ||
if (name.includes(':')) { | ||
return null; | ||
} | ||
const strict = model.config.strict; | ||
if (typeof strict !== 'undefined') { | ||
const error = new TypeError(`unknown property <${ name }> on <${ target.$type }>`); | ||
if (strict) { | ||
throw error; | ||
} else { | ||
// eslint-disable-next-line no-undef | ||
typeof console !== 'undefined' && console.warn(error); | ||
} | ||
} | ||
return null; | ||
}; | ||
function isUndefined(val) { | ||
@@ -737,2 +775,6 @@ return typeof val === 'undefined'; | ||
function stripGlobal(name) { | ||
return name.replace(/^:/, ''); | ||
} | ||
// Moddle implementation ///////////////////////////////////////////////// | ||
@@ -760,4 +802,6 @@ | ||
* @param {Array<Package>} packages the packages to contain | ||
* | ||
* @param { { strict?: boolean } } [config] moddle configuration | ||
*/ | ||
function Moddle(packages) { | ||
function Moddle(packages, config = {}) { | ||
@@ -770,2 +814,4 @@ this.properties = new Properties(this); | ||
this.typeCache = {}; | ||
this.config = config; | ||
} | ||
@@ -772,0 +818,0 @@ |
{ | ||
"name": "moddle", | ||
"version": "6.1.0", | ||
"version": "6.2.0", | ||
"description": "A library for importing meta-model based file formats into JS", | ||
@@ -5,0 +5,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
272485
4054