Skip to content

Commit

Permalink
Implement JSXNamespacedName (#204)
Browse files Browse the repository at this point in the history
* Implement JSXNamespacedName

* Add unit test

* Fix lint
  • Loading branch information
kungfooman authored Aug 8, 2024
1 parent d8a4131 commit dff604e
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -340,12 +340,15 @@ module.exports = {
"quotes": ["off", "single"],
"rest-spread-spacing": "error",
"semi": ["error", "always"],
/*
Disabled because nice for horizontal alignment.
"semi-spacing": [
"error", {
"before": false,
"after": true
}
],
*/
"semi-style": ["error", "last"],
"space-before-blocks": "error",
"space-before-function-paren": [
Expand Down
11 changes: 11 additions & 0 deletions src-transpiler/Stringifier.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {capitalize } from './capitalize.js';
import {trimEndSpaces} from './trimEndSpaces.js';
/**
* @typedef {import("@babel/types").Node} Node
Expand Down Expand Up @@ -1182,6 +1183,16 @@ class Stringifier {
// console.log('JSXIdentifier', {name});
return name;
}
/**
* @param {import("@babel/types").JSXNamespacedName} node - The Babel AST node.
* @returns {string} Stringification of the node.
*/
JSXNamespacedName(node) {
const {namespace, name} = node;
const a = this.toSource(namespace) ;
const b = capitalize(this.toSource(name ));
return a + b;
}
/**
* @param {import("@babel/types").JSXExpressionContainer} node - The Babel AST node.
* @returns {string} Stringification of the node.
Expand Down
10 changes: 10 additions & 0 deletions src-transpiler/capitalize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* @example
* capitalize("hello"); // Outputs: Hello
* @param {string} _ - The input string.
* @returns {string} The capitalized output string.
*/
function capitalize(_) {
return _[0].toUpperCase() + _.slice(1);
}
export {capitalize};
1 change: 1 addition & 0 deletions src-transpiler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export * from './addTypeChecks.js';
export * from './Asserter.js';
export * from './ast2json.js';
export * from './ast2jsonForComparison.js';
export * from './capitalize.js';
export * from './code2ast2code.js';
export * from './compareAST.js';
export * from './expandType.js';
Expand Down
4 changes: 4 additions & 0 deletions test/typechecking.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@
"input": "./test/typechecking/jsx-member-expression-input.mjs",
"output": "./test/typechecking/jsx-member-expression-output.mjs"
},
{
"input": "./test/typechecking/jsx-namespaced-name-input.mjs",
"output": "./test/typechecking/jsx-namespaced-name-output.mjs"
},
{
"input": "./test/typechecking/keyof-typeof-input.mjs",
"output": "./test/typechecking/keyof-typeof-output.mjs"
Expand Down
1 change: 1 addition & 0 deletions test/typechecking/jsx-namespaced-name-input.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<use xlink:href="/some/where"></use>
7 changes: 7 additions & 0 deletions test/typechecking/jsx-namespaced-name-output.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {createElement} from 'react';
createElement(
"use",
{
xlinkHref: "/some/where",
}
);

0 comments on commit dff604e

Please sign in to comment.