...
 
Commits (17)
# html-validate changelog
# [2.13.0](https://gitlab.com/html-validate/html-validate/compare/v2.12.0...v2.13.0) (2020-02-02)
### Features
- **meta:** allow plugins to add copyable metadata ([242eaa8](https://gitlab.com/html-validate/html-validate/commit/242eaa882afb71e527b07a2a92e6d45adf4f02e7))
# [2.12.0](https://gitlab.com/html-validate/html-validate/compare/v2.11.0...v2.12.0) (2020-01-27)
### Bug Fixes
......
......@@ -277,3 +277,53 @@ switch (meta.myProperty) {
default: /* ... */
}
```
### Copyable metadata
Plugins leveraging usage of `loadMeta` for advanced handling of metadata loading must explicitly mark the copyable properties as `copyable`:
```js
module.exports = {
elementSchema: {
properties: {
foo: {
copyable: true,
},
bar: {
copyable: false,
},
},
},
};
```
Given these two properties only `foo` will be copied (loaded) onto the element when using `loadMeta`:
```js
module.exports = {
"my-element": {
foo: "original",
bar: "original",
},
"my-element:slot": {
foo: "overwritten",
bar: "overwritten",
},
};
```
```js
function processElement(node) {
const meta = this.getMetaFor("my-element:slot");
node.loadMeta(meta);
}
```
The resulting metadata will now be:
```json
{
"foo": "overwritten",
"bar": "original"
}
```
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"name": "html-validate",
"version": "2.12.0",
"version": "2.13.0",
"description": "html linter",
"keywords": [
"html",
......@@ -94,8 +94,8 @@
"minimist": "^1.2.0"
},
"devDependencies": {
"@babel/core": "7.8.3",
"@babel/preset-env": "7.8.3",
"@babel/core": "7.8.4",
"@babel/preset-env": "7.8.4",
"@commitlint/cli": "8.3.5",
"@html-validate/commitlint-config": "1.0.1",
"@html-validate/eslint-config": "1.0.8",
......@@ -105,10 +105,10 @@
"@types/estree": "0.0.42",
"@types/glob": "7.1.1",
"@types/inquirer": "6.5.0",
"@types/jest": "24.9.1",
"@types/jest": "25.1.1",
"@types/json-merge-patch": "0.0.4",
"@types/minimist": "1.2.0",
"@types/node": "11.15.4",
"@types/node": "11.15.5",
"autoprefixer": "9.7.4",
"babelify": "10.0.0",
"bootstrap-sass": "3.4.1",
......@@ -138,15 +138,15 @@
"jest-diff": "25.1.0",
"jest-junit": "10.0.0",
"jquery": "3.4.1",
"lint-staged": "10.0.2",
"lint-staged": "10.0.7",
"load-grunt-tasks": "5.1.0",
"minimatch": "3.0.4",
"prettier": "1.19.1",
"sass": "1.25.0",
"semantic-release": "16.0.3",
"semantic-release": "17.0.2",
"serve-static": "1.14.1",
"strip-ansi": "6.0.0",
"ts-jest": "25.0.0",
"ts-jest": "25.1.0",
"tslint": "5.20.1",
"tslint-config-prettier": "1.18.0",
"typescript": "3.7.5"
......
......@@ -5,7 +5,7 @@ import path from "path";
import { Source } from "../context";
import { NestedError, SchemaValidationError } from "../error";
import { MetaTable } from "../meta";
import { MetaDataTable } from "../meta/element";
import { MetaCopyableProperty, MetaDataTable } from "../meta/element";
import { Plugin } from "../plugin";
import schema from "../schema/config.json";
import { TransformContext, Transformer, TRANSFORMER_API } from "../transform";
......@@ -174,6 +174,7 @@ export class Config {
/* load plugins */
this.plugins = this.loadPlugins(this.config.plugins || []);
this.configurations = this.loadConfigurations(this.plugins);
this.extendMeta(this.plugins);
/* process extended configs */
for (const extend of this.config.extends) {
......@@ -394,6 +395,25 @@ export class Config {
return configs;
}
private extendMeta(plugins: LoadedPlugin[]): void {
for (const plugin of plugins) {
if (!plugin.elementSchema) {
continue;
}
const { properties } = plugin.elementSchema;
if (!properties) {
continue;
}
for (const [key, schema] of Object.entries(properties)) {
if (schema.copyable && !MetaCopyableProperty.includes(key)) {
MetaCopyableProperty.push(key);
}
}
}
}
/**
* Transform a source.
*
......
import { Config } from "../config";
import { ConfigError } from "../config/error";
import { Source } from "../context";
import { HtmlElement } from "../dom";
import { Engine } from "../engine";
import { EventHandler } from "../event";
import { Parser } from "../parser";
......@@ -236,6 +237,45 @@ describe("Plugin", () => {
});
expect(() => config.getMetaTable()).not.toThrow();
});
it("should support copyable properties", () => {
mockPlugin.elementSchema = {
properties: {
foo: {
copyable: true,
},
bar: {
copyable: false,
},
},
};
config = Config.fromObject({
plugins: ["mock-plugin"],
elements: [
{
"my-element": {
foo: "original",
bar: "original",
},
"my-element:real": {
foo: "copied",
bar: "copied",
},
},
],
});
const metaTable = config.getMetaTable();
const a = metaTable.getMetaFor("my-element");
const b = metaTable.getMetaFor("my-element:real");
const node = new HtmlElement("my-element", null, null, a);
node.loadMeta(b);
expect(node.meta).toEqual({
tagName: "my-element",
foo: "copied" /* foo is marked for copying */,
bar: "original" /* bar is not marked for copying */,
void: false /* autofilled */,
});
});
});
describe("callbacks", () => {
......