chrome-types-helpers
Advanced tools
Comparing version 0.1.0-beta5 to 0.1.0-beta6
@@ -227,2 +227,6 @@ /** | ||
if (selfPermissions.size) { | ||
selfFeature.permissions = [...selfPermissions]; | ||
} | ||
return selfFeature; | ||
@@ -233,2 +237,10 @@ } | ||
/** | ||
* Returns a sparse {@link types.Feature} describing the differences between a target feature and | ||
* its parent feature (both which must not be sparse themselves). | ||
* | ||
* @param {Partial<types.Feature>} selfFeature | ||
* @param {Partial<types.Feature>} parentFeature | ||
* @return {Partial<types.Feature>} | ||
*/ | ||
export function sparseFeature(selfFeature, parentFeature) { | ||
@@ -247,6 +259,11 @@ /** @type {Partial<types.Feature>} */ | ||
// Compare permissions as a list. | ||
const permissions = [...(selfFeature.permissions ?? [])].filter((p) => !parentFeature.permissions?.includes(p)); | ||
out.permissions = permissions.length ? permissions : undefined; | ||
/** @type {Set<string>} */ | ||
const sparsePermissions = new Set(); | ||
(selfFeature.permissions ?? []).forEach((p) => sparsePermissions.add(p)); | ||
(parentFeature.permissions ?? []).forEach((p) => sparsePermissions.delete(p)); | ||
if (sparsePermissions.size) { | ||
out.permissions = [...sparsePermissions]; | ||
} | ||
return out; | ||
@@ -253,0 +270,0 @@ } |
@@ -366,2 +366,9 @@ /** | ||
get expansions() { | ||
/** @type {Property[][]} */ | ||
const all = []; | ||
this.forEach((...p) => all.push(p)); | ||
return all; | ||
} | ||
/** | ||
@@ -368,0 +375,0 @@ * @param {(returns: Property, ...parameters: Property[]) => void} fn |
@@ -5,3 +5,3 @@ { | ||
"license": "Apache-2.0", | ||
"version": "0.1.0-beta5", | ||
"version": "0.1.0-beta6", | ||
"type": "module", | ||
@@ -8,0 +8,0 @@ "dependencies": { |
@@ -75,6 +75,6 @@ /** | ||
buf.line(); | ||
renderComment(buf, namespace, null); | ||
renderComment(buf, namespace); | ||
buf.line(`namespace _${namespace.name} {`); | ||
} else { | ||
renderComment(buf, namespace, null); | ||
renderComment(buf, namespace); | ||
buf.line(`export namespace ${namespace.name} {`); | ||
@@ -104,3 +104,3 @@ } | ||
buf.line(); | ||
renderComment(buf, prop, namespace); | ||
renderComment(buf, prop); | ||
@@ -112,9 +112,9 @@ buf.append(invalid ? '\n' : '\nexport '); | ||
} else if (prop.isType) { | ||
buf.append(`type ${effectiveName} = ${renderType(prop.type, prop)};`); | ||
buf.append(`type ${effectiveName} = ${renderType(prop.type)};`); | ||
} else if (prop.optional) { | ||
// This only occurs for `runtime.lastError`. | ||
const optionalType = new model.ChoicesType([prop.type, undefinedType]); | ||
buf.append(`let ${effectiveName}: ${renderType(optionalType, prop)};`); | ||
buf.append(`let ${effectiveName}: ${renderType(optionalType)};`); | ||
} else { | ||
buf.append(`const ${effectiveName}: ${renderType(prop.type, prop)};`); | ||
buf.append(`const ${effectiveName}: ${renderType(prop.type)};`); | ||
} | ||
@@ -166,3 +166,3 @@ } | ||
} | ||
return `${prop.name} = ${renderType(prop.type, prop, true)}`; | ||
return `${prop.name} = ${renderType(prop.type, true)}`; | ||
}); | ||
@@ -194,6 +194,6 @@ templatePart = `<${parts.join(', ')}>`; | ||
buf.line(); | ||
renderComment(buf, child, prop); | ||
renderComment(buf, child); | ||
const opt = child.optional ? '?' : ''; | ||
buf.line(`${name}${opt}: ${renderType(child.type, prop)};`); | ||
buf.line(`${name}${opt}: ${renderType(child.type)};`); | ||
} | ||
@@ -209,7 +209,6 @@ } | ||
* @param {model.Type} type to render | ||
* @param {model.Node} parent could be property of this type | ||
* @param {boolean} ambig whether this is in an ambigious context (e.g., "X[]") | ||
* @return {string} | ||
*/ | ||
export function renderType(type, parent, ambig = false) { | ||
export function renderType(type, ambig = false) { | ||
/** | ||
@@ -227,3 +226,3 @@ * @type {(s: string) => string} | ||
if (type.templates.length) { | ||
out += `<${type.templates.map((t) => renderType(t, parent)).join(', ')}>` | ||
out += `<${type.templates.map((t) => renderType(t)).join(', ')}>` | ||
} | ||
@@ -235,3 +234,3 @@ return out; | ||
if (type.maxItems === undefined) { | ||
const t = renderType(itemType, parent, true); | ||
const t = renderType(itemType, true); | ||
const arr = `${t}[]`; | ||
@@ -256,3 +255,3 @@ | ||
const inner = renderType(itemType, parent, true); | ||
const inner = renderType(itemType, true); | ||
for (let i = low; i <= high; ++i) { | ||
@@ -269,3 +268,3 @@ parts.push(renderTuple(i, inner)); | ||
const additionalPropertiesPart = type.additionalProperties ? | ||
`[name: string]: ${renderType(type.additionalProperties, parent)}` : | ||
`[name: string]: ${renderType(type.additionalProperties)}` : | ||
''; | ||
@@ -297,6 +296,6 @@ | ||
} | ||
renderComment(buf, prop, parent); | ||
renderComment(buf, prop); | ||
const opt = prop.optional ? '?' : ''; | ||
buf.line(`${name}${opt}: ${renderType(prop.type, parent)},`); | ||
buf.line(`${name}${opt}: ${renderType(prop.type)},`); | ||
} | ||
@@ -307,6 +306,6 @@ | ||
} else if (type instanceof model.UnionType) { | ||
const inner = type.types.map((t) => renderType(t, parent, true)).join(' & '); | ||
const inner = type.types.map((t) => renderType(t, true)).join(' & '); | ||
return maybeWrap(inner); | ||
} else if (type instanceof model.ChoicesType) { | ||
const inner = type.choices.map((t) => renderType(t, parent, true)).join(' | '); | ||
const inner = type.choices.map((t) => renderType(t, true)).join(' | '); | ||
return maybeWrap(inner); | ||
@@ -332,3 +331,3 @@ } else if (type instanceof model.FunctionType) { | ||
if (renderComment(buf, p, parent)) { | ||
if (renderComment(buf, p)) { | ||
needsGap = true; | ||
@@ -338,3 +337,3 @@ } | ||
const opt = p.optional ? '?' : ''; | ||
buf.line(`${p.name}${opt}: ${renderType(p.type, parent)},`); | ||
buf.line(`${p.name}${opt}: ${renderType(p.type)},`); | ||
}); | ||
@@ -345,3 +344,3 @@ | ||
buf.append(` => ${renderType(parameters[0].type, parent, true)}`); | ||
buf.append(` => ${renderType(parameters[0].type, true)}`); | ||
return buf.render(); | ||
@@ -358,7 +357,6 @@ } | ||
* @param {model.Node} node | ||
* @param {model.Node?} parent | ||
* @param {model.Property[]?} overrideParameters | ||
* @return {boolean} | ||
*/ | ||
function renderComment(buf, node, parent, overrideParameters = null) { | ||
function renderComment(buf, node, overrideParameters = null) { | ||
/** @type {types.Tag[]} */ | ||
@@ -452,6 +450,6 @@ const tags = []; | ||
const suffix = `: ${renderType(returnProperty.type, fn)};`; | ||
const suffix = `: ${renderType(returnProperty.type)};`; | ||
buf.line(); | ||
renderComment(buf, fn, parent, [returnProperty, ...parameters]); | ||
renderComment(buf, fn, [returnProperty, ...parameters]); | ||
buf.line(`${prefix}${effectiveName}(`); | ||
@@ -475,3 +473,3 @@ | ||
buf.line(`${effectiveParameterName}${opt}: ${renderType(p.type, fn)},`); | ||
buf.line(`${effectiveParameterName}${opt}: ${renderType(p.type)},`); | ||
} | ||
@@ -478,0 +476,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
166884
4993