Skip to content

Commit 5d999c1

Browse files
committed
* PokeApi-Explorer.html runs within dist/
* generate-mixin.js renders HTMLElementMixin.d.ts
1 parent c6e4bdb commit 5d999c1

File tree

5 files changed

+18
-14
lines changed

5 files changed

+18
-14
lines changed

build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
node types/generate-mixin.js
12
bash ./test.sh
23

34
PACKAGE_VERSION=$(node -pe "require('css-chain/package.json').version")
@@ -6,6 +7,7 @@ echo $PACKAGE_VERSION
67
rm -rf dist
78
mkdir dist
89
cp src/*.html dist
10+
cp src/*.d.ts dist
911
sed "s/..\/src\/css-chain-element.js/css-chain-element.js/" src/demo.html >dist/demo.html
1012

1113
# https://kangax.github.io/compat-table/es2016plus/

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/PokeApi-Explorer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import FetchElement from 'https://unpkg.com/[email protected]/fetch-element.js';
2-
import { CssChain as $$ } from "https://unpkg.com/css-chain@1/CssChain.js";
3-
// import { CssChain as $$ } from "./CssChain.js";
2+
// import { CssChain as $$ } from "https://unpkg.com/css-chain@1/CssChain.js";
3+
import { CssChain as $$ } from "./CssChain.js";
44

55
const arr2str = (arr,cb, separator='') => arr.map(cb).join(separator)
66
, isImg = url => url && url.endsWith && ['png','gif','svg'].find( x=>url.endsWith(x) );

types/TYPES.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ CssChain.d.ts uses DOM definitions from
88

99
npx -p typescript tsc src/*.js --declaration --allowJs --emitDeclarationOnly --outDir types
1010
## 2. combine whole HTMLElement dependency tree
11+
[generate-mixin.js](generate-mixin.js)
12+
1113
From [typescript/lib/lib.dom.d.ts](https://github.com/microsoft/TypeScript/blob/main/lib/lib.dom.d.ts).
1214

1315
1. Traverse over `lib.dom.d.ts` AST and create the inheritance tree for all interfaces.
1416
2. From inheritance tree collect all related to HTMLElement as collection of names
15-
3. by iterating over AST, dump out bodies of the interfaces from collection into DomMixinInterface
17+
3. by iterating over AST, dump out bodies of the interfaces from collection into HTMLElementMixin interface.
1618

1719
#links
1820
* [Using TypeScript compiler](https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API)

types/ast-parse.js renamed to types/generate-mixin.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1+
// generator of HTMLElementMixin.d.ts
2+
13
import ts from "typescript";
24
import fs from 'fs';
35

46
let checker, sourceFile;
57

68
const getNodeName = node => node.name?.text;
7-
// checker.getSymbolAtLocation(node.name).getName();
8-
// checker.getFullyQualifiedName( checker.getSymbolAtLocation(node.name) )
9-
// node.name?.text;
10-
// node.name?.escapedText;
119

1210
function getParents( node /* ts.ClassDeclaration*/ )
1311
{
@@ -149,17 +147,19 @@ const methods = Object.keys(member2types).map( m=>
149147
}).join('\n');
150148

151149
/*
152-
0. generated CssChain.d.ts edited manually and cloned into CssChain-manual.d.ts
153-
1. create CssChain.d.ts
154-
2. copy CssChain-manual.d.ts into CssChain.d.ts
155-
3. append HTMLElementMixin.d.ts
150+
0. CssChain.d.ts is generated out of CssChain.js and edited manually
151+
1. HTMLElementMixin.d.ts is rendered by this script
156152
*/
157153

158154
var stream = fs.createWriteStream("src/HTMLElementMixin.d.ts");
159155
stream.once('open', function(fd) {
160156
stream.write(
161-
`import type { CssChainT} from './CssChain';
157+
`// generated by css-chain-test/types/ast-parse.js
162158
159+
import type { CssChainT} from './CssChain';
160+
/** Mixin of HTMLElement inherited and parents from node_modules/typescript/lib/lib.dom.d.ts
161+
all methods return CssChainT
162+
*/
163163
export interface HTMLElementMixin {
164164
`);
165165
stream.write(methods);

0 commit comments

Comments
 (0)