vault/ui/scripts/codemods/no-quoteless-attributes.js
Vault Automation 0c6c13dd38
license: update headers to IBM Corp. (#10229) (#10233)
* license: update headers to IBM Corp.
* `make proto`
* update offset because source file changed

Signed-off-by: Ryan Cragun <me@ryan.ec>
Co-authored-by: Ryan Cragun <me@ryan.ec>
2025-10-21 15:20:20 -06:00

29 lines
732 B
JavaScript

#!/usr/bin/env node
/**
* Copyright IBM Corp. 2016, 2025
* SPDX-License-Identifier: BUSL-1.1
*/
/* eslint-env node */
/**
* Codemod to convert quoteless attribute or argument to mustache statement
* eg. data-test-foo=true -> data-test-foo={{true}}
* eg @isVisible=true -> @isVisible={{true}}
*/
module.exports = (env) => {
const { builders } = env.syntax;
return {
ElementNode({ attributes }) {
let i = 0;
while (i < attributes.length) {
const { type, chars } = attributes[i].value;
if (type === 'TextNode' && chars && !attributes[i].quoteType) {
attributes[i].value = builders.mustache(builders.path(attributes[i].value.chars));
}
i++;
}
},
};
};