![Introducing Enhanced Alert Actions and Triage Functionality](https://cdn.sanity.io/images/cgdhsj6q/production/fe71306d515f85de6139b46745ea7180362324f0-2530x946.png?w=800&fit=max&auto=format)
Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
ember-template-recast
Advanced tools
Changelog
v5.0.3 (2021-05-19)
Readme
With ember-template-recast, transform a template's AST and reprint it. Its formatting will be preserved.
For instance, it is possible to change a component's property while preserving its formatting:
const recast = require('ember-template-recast');
const template = `
<Sidebar
foo="bar"
item={{hmmm}}
/>
`;
// parse
let ast = recast.parse(template);
// transform
ast.body[1].attributes[1].value.path = builders.path('this.hmmm');
// print
let ouput = recast.print(ast);
output === `
<Sidebar
foo="bar"
item={{this.hmmm}}
/>
`; // is true!
ember-template-recast comes with a binary for running a transform across multiple files, similar to jscodeshift.
npx ember-template-recast directory/of/templates -t transform.js
Example transform plugin:
module.exports = (env) => {
let { builders: b } = env.syntax;
return {
MustacheStatement() {
return b.mustache(b.path('wat-wat'));
},
};
};
Used to parse a given template string into an AST. Generally speaking, this AST
can be mutated and passed into print
(docs below).
const templateRecast = require('ember-template-recast');
const template = `
{{foo-bar
baz="stuff"
}}
`;
let ast = templateRecast.parse(template);
// now you can work with `ast`
Used to generate a new template string representing the provided AST.
const templateRecast = require('ember-template-recast');
const template = `
{{foo-bar
baz="stuff"
}}
`;
let ast = templateRecast.parse(template);
ast.body[0].hash[0].key = 'derp';
templateRecast.print(ast);
{{foo-bar
derp="stuff"
}}
Used to easily traverse (and possibly mutate) a given template. Returns the resulting AST and the printed template.
The plugin argument has roughly the following interface:
export interface Syntax {
parse: typeof preprocess;
builders: typeof builders;
print: typeof print;
traverse: typeof traverse;
Walker: typeof Walker;
}
export interface TransformPluginEnv {
syntax: Syntax;
contents: string;
filePath?: string;
parseOptions: {
srcName?: string;
};
}
export interface TransformPluginBuilder {
(env: TransformPluginEnv): NodeVisitor;
}
The list of known builders on the env.syntax.builders
are found
here.
Example:
const { transform } = require('ember-template-recast');
const template = `
{{foo-bar
baz="stuff"
}}
`;
let { code } = transform({
template,
plugin(env) {
let { builders: b } = env.syntax;
return {
MustacheStatement() {
return b.mustache(b.path('wat-wat'));
},
};
}
});
console.log(code); // => {{wat-wat}}
Due to usage of TypeScript and bundling external APIs this project has somewhat unique SemVer commitments. A high level summary is:
The following are scenarios that would cause a major version (aka breaking change) release:
@glimmer/syntax
)@glimmer/syntax
builder APIsThe following are scenarios that would cause a minor version (aka new feature) release:
ember-template-recast
ember-template-recast
to be more accurate
(e.g. narrowing / broadening of previously published types).The following are scenarios that would cause a patch release:
@glimmer/syntax
This project is distributed under the MIT license, see LICENSE for details.
FAQs
Non-destructive template transformer.
The npm package ember-template-recast receives a total of 86,698 weekly downloads. As such, ember-template-recast popularity was classified as popular.
We found that ember-template-recast demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.