A jscodeshift Codemod to convert curly braces syntax to angle brackets syntax for templatesin an Ember.js app
Refer to this RFC for more details on Angle brackets invocation syntax.
This codemod currently only supports Ember's classic filesystem layout, meaning it won't work if your app uses pods. For more info, see this issue.
WARNING: jscodeshift
, and thus this codemod, edits your files in place.It does not make a copy. Make sure your code is checked into a source controlrepository like Git and that you have no outstanding changes to commit beforerunning this tool.
$ cd my-ember-app-or-addon
$ npx ember-angle-brackets-codemod --telemetry=http://localhost:4200 ./path/of/files/ or ./some**/*glob.hbs
Telemetry helpers runs the app, grabs basic info about all of the modules at runtime. This allows the codemod to know the names of every helper, component, route, controller, etc. in the app without guessing / relying on static analysis. They basically help you to create "runtime assisted codemods".
See "Gathering runtime data" section of ember-native-class-codemod for some additonal information.
$ cd my-ember-app-or-addon
$ npx ember-angle-brackets-codemod ./path/of/files/ or ./some**/*glob.hbs
NOTE If you are not using telemetry, you will probably need to manually configure the codemod to at least skip any helpers that are invoked in the template files you are running it on.
To help the codemod disambiguate components and helpers, you can define a list of helpers from your application in a configuration file as follows:
config/anglebrackets-codemod-config.json
{
"helpers": [
"date-formatter",
"info-pill"
]
}
The codemod will then ignore the above list of helpers and prevent them from being transformed into the new angle-brackets syntax.
You can also disable the conversion of the built-in components {{link-to}}
, {{input}}
and {{textarea}}
as follows:
config/anglebrackets-codemod-config.json
{
"helpers": [],
"skipBuiltInComponents": true
}
You can execute the codemod with custom configuration by specifying a --config
command line option as follows:
$ cd my-ember-app-or-addon
$ npx ember-angle-brackets-codemod angle-brackets app/templates --config ./config/anglebrackets-codemod-config.json
To get a list of helpers in your app you can do this in the Developer Console in your browser inside of your app:
var componentLikeHelpers = Object.keys(require.entries)
.filter(name => name.includes('/helpers/') || name.includes('/helper'))
.filter(name => !name.includes('/-'))
.map(name => {
let path = name.split('/helpers/');
return path.pop();
})
.filter(name => !name.includes('/'))
.uniq();
copy(JSON.stringify(componentLikeHelpers));
If there are files that don't convert well, you can skip them by specifying an optional skipFilesThatMatchRegex
configuration setting. For example, with the configuration below, all files that contain "foo"
or "bar"
will be skipped:
config/anglebrackets-codemod-config.json
{
"helpers": [],
"skipBuiltInComponents": true,
"skipFilesThatMatchRegex": "foo|bar"
}
If there are cases where some attributes should not be prefixed with @
, you can skip them by specifying an optional skipAttributesThatMatchRegex
configuration setting.For example, with the configuration below, all attributes that matches either /data-/gim
or /aria-/gim
will not be prefixed with @
:
Curly invocations that have data-test-
attributes with no value are not processed by default. The configuration below will cause them to be processed:
config/anglebrackets-codemod-config.json
{
"includeValuelessDataTestAttributes": true
}
config/anglebrackets-codemod-config.json
{
"helpers": [],
"skipBuiltInComponents": true,
"skipAttributesThatMatchRegex": ["/data-/gim", "/aria-/gim"]
}
Input:
{{some-component data-test-foo=true aria-label="bar" foo=true}}
Output:
<SomeComponent data-test-foo={{true}} aria-label="bar" @foo={{true}} />
If you would like to only convert certain component invocations to use the angle brackets syntax, use the components
configuration setting and specify component names. For example, with the configuration below, only the {{baz}}
and {{bat}}
components will be converted, leaving everything else intact.
config/anglebrackets-codemod-config.json
{
"components": ["baz", "bat"]
}
Oftentimes, you want to debug the codemod or the transform to identify issues with the code or to understandhow the transforms are working, or to troubleshoot why some tests are failing.
Hence we recommend a debugging work-flow like below to quickly find out what is causing the issue.
debugger
statementsAdd debugger
statements, in appropriate places in the code. For example:
...
const params = a.value.params.map(p => {
debugger;
if(p.type === "SubExpression") {
return transformNestedSubExpression(p)
...
Here we are going to start the tests selectively in node debug mode. Since thecodemod is using jest in turnto run the tests, jest is having an option -t <name-of-spec>
to run a particularset of tests instead of running the whole test suite.
We are making use of both these features to start our tests in this particular fashion.For more details on node debug, visit the officialNode.js debugging guide, and for jest documentation on tests, please refer here.
node --inspect-brk ./node_modules/.bin/jest --runInBand --testNamePattern <test-name>
For example, if you want to debug the null-subexp
test or only that particular test case is failing because of an issue.
node --inspect-brk ./node_modules/.bin/jest --runInBand --testNamePattern 'null-subexp'
Or you can make use of the npm scripts defined in package.json. All you need to pass the test name as the extra parameter with the script.
npm run debug:test 'null-subexp'
Using yarn
yarn debug:test 'null-subexp'
Once you run the above command, your tests will start running in debug mode and your breakpoints will betriggered appropriately when that particular block of code gets executed. You can run the debugger insideChrome browser dev-tools. More details on here
Brackets 是 Adobe 的开源 HTML/CSS/JavaScript 集成开发环境。Brackets 当前为 Mac, Windows 以及 Linux (Debian/Ubuntu) 提供最新稳定版的二进制发布,源代码托管在 GitHub 上。
Google 今天宣布了新的开源项目 ANGLE (全称 Almost Native Graphics Layer Engine),这个项目的目标是在 Direct X 9.0c API 的基础上实现一层 OpenGL ES 2.0 API中 的 Web GL 子集接口。在开发的早期,ANGLE 项目将使用 BSD 授权发布,而最终完成后,类似 Google Chrome 之类的浏览器在 Wind
Returns an SVG markup string for the hue-rotate filter Parameters anglenumberangle of rotation Returns: string filter representation
Equivalent to Math.cos() only works with degrees, not radians. Parameters anglenumberangle in degrees Returns: number cos
Equivalent to Math.tan() only works with degrees, not radians. Parameters anglenumberangle in degrees Returns: number tan
Equivalent to Math.sin() only works with degrees, not radians. Parameters anglenumberangle in degrees Returns: number sin