2023-03-14 13:18:55 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2022-03-11 10:25:21 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
name: require('./package').name,
|
2022-09-15 08:43:17 +00:00
|
|
|
getTransform: function () {
|
2022-03-11 10:25:21 +00:00
|
|
|
return {
|
|
|
|
name: 'custom-element',
|
|
|
|
plugin: class {
|
|
|
|
transform(ast) {
|
|
|
|
this.syntax.traverse(ast, {
|
|
|
|
ElementNode: (node) => {
|
2022-09-15 08:43:17 +00:00
|
|
|
if (node.tag === 'CustomElement') {
|
2022-03-11 10:25:21 +00:00
|
|
|
node.attributes = node.attributes
|
|
|
|
// completely remove these ones, they are not used runtime
|
|
|
|
// element is potentially only temporarily being removed
|
2022-09-15 08:43:17 +00:00
|
|
|
.filter(
|
|
|
|
(item) =>
|
|
|
|
!['element', 'description', 'slots', 'cssparts'].includes(
|
|
|
|
`${item.name.substr(1)}`
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.map((item) => {
|
|
|
|
switch (true) {
|
2022-03-11 10:25:21 +00:00
|
|
|
// these ones are ones where we need to remove the documentation only
|
|
|
|
// the attributes themselves are required at runtime
|
|
|
|
case ['attrs', 'cssprops'].includes(`${item.name.substr(1)}`):
|
2022-09-15 08:43:17 +00:00
|
|
|
item.value.params = item.value.params.map((item) => {
|
2022-03-11 10:25:21 +00:00
|
|
|
// we can't use arr.length here as we don't know
|
|
|
|
// whether someone has used the documentation entry
|
|
|
|
// in the array or not We use the hardcoded `3` for
|
|
|
|
// the moment if that position needs to change per
|
|
|
|
// property we can just add more cases for the
|
|
|
|
// moment
|
|
|
|
item.params = item.params.filter((item, i, arr) => i < 3);
|
|
|
|
return item;
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return item;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
return ast;
|
|
|
|
}
|
|
|
|
},
|
2022-09-15 08:43:17 +00:00
|
|
|
baseDir: function () {
|
2022-03-11 10:25:21 +00:00
|
|
|
return __dirname;
|
|
|
|
},
|
2022-09-15 08:43:17 +00:00
|
|
|
cacheKey: function () {
|
2022-03-11 10:25:21 +00:00
|
|
|
return 'custom-element';
|
2022-09-15 08:43:17 +00:00
|
|
|
},
|
2022-03-11 10:25:21 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
setupPreprocessorRegistry(type, registry) {
|
|
|
|
const transform = this.getTransform();
|
|
|
|
transform.parallelBabel = {
|
|
|
|
requireFile: __filename,
|
|
|
|
buildUsing: 'getTransform',
|
2022-09-15 08:43:17 +00:00
|
|
|
params: {},
|
2022-03-11 10:25:21 +00:00
|
|
|
};
|
|
|
|
registry.add('htmlbars-ast-plugin', transform);
|
|
|
|
},
|
|
|
|
};
|