Commit f18c8469 authored by Nicolas Biri's avatar Nicolas Biri

Remove instanceof Array (official node REPL bug creator)

parent 2564baa5
Pipeline #856 passed with stage
in 1 minute and 6 seconds
......@@ -194,7 +194,7 @@ function populateClassFunction(cls) {
}
function setSuperType(s) {
const ss = s instanceof Array ? s : [s]
const ss = _.isArray(s) ? s : [s]
this.superClasses = _.uniq(this.superClasses.concat(ss))
}
......@@ -262,7 +262,7 @@ function createSetAttribute(o, name, desc) {
}
function hasClass(x, type) {
const types = type instanceof Array ? type : [type]
const types = _.isArray(type) ? type : [type]
return _.some(x.conformsTo().getInheritanceChain(), c => _.includes(types, c))
}
......@@ -271,7 +271,7 @@ function createReference(o, name, desc) {
Object.defineProperty(o, name,
{ get: () => o.__jsmf__.references[name]
, set: xs => {
xs = xs instanceof Array ? xs : [xs]
xs = _.isArray(xs) ? xs : [xs]
const invalid = _.filter(xs, x => {
const type = conformsTo(x)
return type === undefined
......@@ -300,7 +300,7 @@ function createReference(o, name, desc) {
function createAddReference(o, name, desc) {
Object.defineProperty(o, addName(name),
{ value: function(xs, associated) {
xs = xs instanceof Array ? xs : [xs]
xs = _.isArray(xs) ? xs : [xs]
const associationMap = o.__jsmf__.associated
const backup = associationMap[name]
o.__jsmf__.references[name] = o[name].concat(xs)
......@@ -329,7 +329,7 @@ function createAddReference(o, name, desc) {
function createRemoveReference(o, name) {
Object.defineProperty(o, removeName(name),
{ value: xs => {
xs = xs instanceof Array ? xs : [xs]
xs = _.isArray(xs) ? xs : [xs]
const associationMap = o.__jsmf__.associated
associationMap[name] = _.differenceWith(associationMap[name], xs, (x,y) => x.elem === y)
o.__jsmf__.references[name] = _.difference(o.__jsmf__.references[name], xs)
......
......@@ -39,7 +39,7 @@ function Enum(name, values) {
, getName: {value: getName}
, conformsTo: {value: () => conformsTo(jsmfEnum)}
})
if (values instanceof Array) {
if (_.isArray(values)) {
_.forEach(values, (v, k) => jsmfEnum[v] = k)
} else {
_.forEach(values, (v, k) => jsmfEnum[k] = v)
......
......@@ -50,7 +50,7 @@ function Model(name, referenceModel, modellingElements, transitive) {
this.elemByClassId = new Map()
this.classes = {}
if (modellingElements !== undefined) {
modellingElements = modellingElements instanceof Array ? modellingElements : [modellingElements]
modellingElements = _.isArray(modellingElements) ? modellingElements : [modellingElements]
if (transitive) {
modellingElements = crawlElements(modellingElements)
}
......@@ -65,7 +65,7 @@ function modelExport(m) {
}
Model.prototype.addModellingElement = function(es) {
es = es instanceof Array ? es : [es]
es = _.isArray(es) ? es : [es]
_.forEach(es, e => {
if (!isJSMFElement(e)) {throw new TypeError(`can't Add ${e} to model ${this}`)}
addToClass(this, e)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment