@markuplint/ml-spec
Advanced tools
Comparing version 2.0.0-dev.20211227.1 to 2.0.0-dev.20220106.0
import type { MLMLSpec, Attribute } from './types'; | ||
export declare function getAttrSpecs(nameWithNS: string, { specs, def }: MLMLSpec): Attribute[] | null; | ||
export declare function getAttrSpecs(nameWithNS: string, schema: MLMLSpec): Attribute[] | null; | ||
declare type HasName = { | ||
@@ -4,0 +4,0 @@ name: string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.nameCompare = exports.getAttrSpecs = void 0; | ||
function getAttrSpecs(nameWithNS, { specs, def }) { | ||
const elSpec = specs.find(spec => spec.name === nameWithNS); | ||
const cacheMap = new Map(); | ||
const schemaCache = new WeakSet(); | ||
function getAttrSpecs(nameWithNS, schema) { | ||
if (!schemaCache.has(schema)) { | ||
cacheMap.clear(); | ||
} | ||
const cache = cacheMap.get(nameWithNS); | ||
if (cache !== undefined) { | ||
return cache; | ||
} | ||
schemaCache.add(schema); | ||
const elSpec = schema.specs.find(spec => spec.name === nameWithNS); | ||
if (!elSpec) { | ||
cacheMap.set(nameWithNS, null); | ||
return null; | ||
} | ||
const globalAttrs = def['#globalAttrs']; | ||
const globalAttrs = schema.def['#globalAttrs']; | ||
let attrs = {}; | ||
@@ -69,2 +80,3 @@ for (const catName in elSpec.globalAttrs) { | ||
attrList.sort(nameCompare); | ||
cacheMap.set(nameWithNS, attrList); | ||
return attrList; | ||
@@ -71,0 +83,0 @@ } |
@@ -5,3 +5,8 @@ "use strict"; | ||
const get_attr_specs_1 = require("./get-attr-specs"); | ||
const cacheMap = new WeakMap(); | ||
function getSpecOM(spec) { | ||
const cache = cacheMap.get(spec); | ||
if (cache) { | ||
return cache; | ||
} | ||
const som = {}; | ||
@@ -20,2 +25,3 @@ for (const el of spec.specs) { | ||
} | ||
cacheMap.set(spec, som); | ||
return som; | ||
@@ -22,0 +28,0 @@ } |
{ | ||
"name": "@markuplint/ml-spec", | ||
"version": "2.0.0-dev.20211227.1", | ||
"version": "2.0.0-dev.20220106.0", | ||
"description": "Types and schema that specs of the Markup languages for markuplint", | ||
@@ -27,6 +27,6 @@ "repository": "git@github.com:markuplint/markuplint.git", | ||
"devDependencies": { | ||
"@markuplint/types": "1.0.0-dev.20211213.3", | ||
"@markuplint/types": "1.0.0-dev.20220106.0", | ||
"json-schema-to-typescript": "^10.1.5" | ||
}, | ||
"gitHead": "73fab2765c080b0a42e71bdc1eed09bae0ed360e" | ||
"gitHead": "ae095a6ca5d8ee8590fe21310c097b47d6d79486" | ||
} |
import type { MLMLSpec, Attribute } from './types'; | ||
export function getAttrSpecs(nameWithNS: string, { specs, def }: MLMLSpec) { | ||
const elSpec = specs.find(spec => spec.name === nameWithNS); | ||
const cacheMap = new Map<string, Attribute[] | null>(); | ||
const schemaCache = new WeakSet<MLMLSpec>(); | ||
export function getAttrSpecs(nameWithNS: string, schema: MLMLSpec) { | ||
if (!schemaCache.has(schema)) { | ||
cacheMap.clear(); | ||
} | ||
const cache = cacheMap.get(nameWithNS); | ||
if (cache !== undefined) { | ||
return cache; | ||
} | ||
schemaCache.add(schema); | ||
const elSpec = schema.specs.find(spec => spec.name === nameWithNS); | ||
if (!elSpec) { | ||
cacheMap.set(nameWithNS, null); | ||
return null; | ||
} | ||
const globalAttrs = def['#globalAttrs']; | ||
const globalAttrs = schema.def['#globalAttrs']; | ||
let attrs: Record<string, Partial<Attribute>> = {}; | ||
@@ -79,2 +95,3 @@ | ||
cacheMap.set(nameWithNS, attrList); | ||
return attrList; | ||
@@ -81,0 +98,0 @@ } |
@@ -5,3 +5,9 @@ import type { MLDOMElementSpec, MLMLSpec, SpecOM } from './types'; | ||
const cacheMap = new WeakMap<MLMLSpec, SpecOM>(); | ||
function getSpecOM(spec: MLMLSpec): SpecOM { | ||
const cache = cacheMap.get(spec); | ||
if (cache) { | ||
return cache; | ||
} | ||
const som: SpecOM = {}; | ||
@@ -20,2 +26,3 @@ for (const el of spec.specs) { | ||
} | ||
cacheMap.set(spec, som); | ||
return som; | ||
@@ -22,0 +29,0 @@ } |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
194884
4824