Skip to content

Commit a17b6dc

Browse files
committed
refactor: lime primitives.
1 parent ab288bf commit a17b6dc

15 files changed

Lines changed: 183 additions & 111 deletions

File tree

appserver/appserver.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { type Channel } from "./channel.ts";
88
import { type Module } from "./module.ts";
99

1010
export class AppServer {
11+
static default = Symbol("default");
12+
1113
runMode: runModes.RunMode;
1214
events: typeof events;
1315
di: typeof di;
@@ -34,6 +36,10 @@ export class AppServer {
3436
this.channels.set(name, channel);
3537
}
3638

37-
execute(_options: unknown) {
39+
setAsDefaultAppServer() {
40+
this.di.register(AppServer.default, this);
3841
}
42+
43+
// execute(_options: unknown) {
44+
// }
3945
}

appserver/version-checker.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,27 @@
33
import * as runtime from "../standards/runtime.ts";
44
import { semver } from "./deps.ts";
55

6-
export function compareSemanticVersions(
6+
export const compareSemanticVersions = (
77
currentVersion: semver.SemVer,
88
targetVersion: semver.SemVerRange | semver.SemVer,
9-
) {
9+
) => {
1010
if (semver.isSemVerRange(targetVersion)) {
1111
return semver.testRange(currentVersion, targetVersion);
1212
}
1313

1414
return !semver.gte(currentVersion, targetVersion);
15-
}
15+
};
1616

17-
export function compareTextVersions(
17+
export const compareTextVersions = (
1818
currentVersion: string,
1919
targetVersion: string,
20-
) {
20+
) => {
2121
const currentSemanticVersion = semver.parse(currentVersion);
2222
const targetSemanticVersion = semver.parseRange(targetVersion);
2323

2424
return compareSemanticVersions(currentSemanticVersion, targetSemanticVersion);
25-
}
25+
};
2626

27-
export function checkMinDenoVersion(minimumVersion: string) {
27+
export const checkMinDenoVersion = (minimumVersion: string) => {
2828
return compareTextVersions(runtime.version.runtime, minimumVersion);
29-
}
29+
};

collector/collector.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export interface CollectExportsOptions {
3939
ignoreFilePattern?: RegExp;
4040
}
4141

42-
export async function collectExports(options: CollectExportsOptions) {
42+
export const collectExports = async (options: CollectExportsOptions) => {
4343
const ignoreFilePattern = options.ignoreFilePattern ??
4444
patterns.JS_TEST_FILE_PATTERN;
4545

@@ -76,4 +76,4 @@ export async function collectExports(options: CollectExportsOptions) {
7676
}
7777

7878
return exports;
79-
}
79+
};

collector/manifest.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@ const PLACEHOLDER_SUFFIX = "__//!!##";
1919
/**
2020
* Import specifiers must have forward slashes
2121
*/
22-
function toImportSpecifier(file: string) {
22+
const toImportSpecifier = (file: string) => {
2323
const specifier = posix.normalize(file).replace(/\\/g, "/");
2424

2525
if (!specifier.startsWith(".")) {
2626
return `./${specifier}`;
2727
}
2828

2929
return specifier;
30-
}
30+
};
3131

3232
// Create a valid JS identifier out of the project relative specifier.
3333
// Note that we only need to deal with strings that _must_ have been
3434
// valid file names in Windows, macOS and Linux and every identifier we
3535
// create here will be prefixed with at least one "$". This greatly
3636
// simplifies the invalid characters we have to account for.
37-
export function specifierToIdentifier(specifier: string, used: Set<string>) {
37+
export const specifierToIdentifier = (specifier: string, used: Set<string>) => {
3838
// specifier = specifier.replace(/^(?:\.\/pkg)\//, "");
3939
const ext = path.extname(specifier);
4040
if (ext) {
@@ -62,29 +62,32 @@ export function specifierToIdentifier(specifier: string, used: Set<string>) {
6262
if (used.has(ident)) {
6363
let check = ident;
6464
let i = 1;
65+
6566
while (used.has(check)) {
6667
check = `${ident}_${i++}`;
6768
}
69+
6870
ident = check;
6971
}
7072

7173
used.add(ident);
74+
7275
return ident;
73-
}
76+
};
7477

75-
const getSortFn = function () {
78+
const getSortFn = () => {
7679
const naturalCollator = new Intl.Collator(undefined, { numeric: true });
7780

7881
return naturalCollator.compare;
7982
};
8083

81-
const placeholder = function (text: string) {
84+
const placeholder = (text: string) => {
8285
return `${PLACEHOLDER_PREFIX}${text}${PLACEHOLDER_SUFFIX}`;
8386
};
8487

85-
export async function writeManifestToString(
88+
export const writeManifestToString = async (
8689
collection: Array<[string, Array<[string, unknown]>]>,
87-
) {
90+
) => {
8891
const sortFn = getSortFn();
8992

9093
const used = new Set<string>();
@@ -102,7 +105,7 @@ export async function writeManifestToString(
102105
`import * as ${IMPORT_PREFIX}${identifier} from "${specifier}";`,
103106
);
104107

105-
const ref = function (target: unknown) {
108+
const ref = (target: unknown) => {
106109
const name = (target as { name: string }).name;
107110

108111
return placeholder(`${IMPORT_PREFIX}${identifier}.${name}`);
@@ -132,9 +135,11 @@ export const manifest = ${manifestSerialized};
132135
const manifestStr = await formatter.format(output);
133136

134137
return manifestStr;
135-
}
138+
};
136139

137-
export async function buildManifest(options: collector.CollectExportsOptions) {
140+
export const buildManifest = async (
141+
options: collector.CollectExportsOptions,
142+
) => {
138143
const collection = await collector.collectExports(options);
139144

140145
const manifestStr = await writeManifestToString(collection);
@@ -152,4 +157,4 @@ export async function buildManifest(options: collector.CollectExportsOptions) {
152157
`%cThe manifest file has been generated for ${exportCount} exports in ${exportModules.length} modules.`,
153158
"color: blue",
154159
);
155-
}
160+
};

collector/validator-identifier/mod.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const nonASCIIidentifier = new RegExp(
2323
// This has a complexity linear to the value of the code. The
2424
// assumption is that looking up astral identifier characters is
2525
// rare.
26-
function isInAstralSet(code: number, set: readonly number[]): boolean {
26+
const isInAstralSet = (code: number, set: readonly number[]) => {
2727
let pos = 0x10000;
2828

2929
for (let i = 0, length = set.length; i < length; i += 2) {
@@ -39,7 +39,7 @@ function isInAstralSet(code: number, set: readonly number[]): boolean {
3939
}
4040

4141
return false;
42-
}
42+
};
4343

4444
// These are a run-length and offset-encoded representation of the
4545
// >0xffff code points that are a valid part of identifiers. The
@@ -902,53 +902,65 @@ const astralIdentifierCodes = [
902902

903903
// Test whether a given character code starts an identifier.
904904

905-
export function isIdentifierStart(code: number): boolean {
905+
export const isIdentifierStart = (code: number) => {
906906
if (code < charCodes.uppercaseA) {
907907
return code === charCodes.dollarSign;
908908
}
909+
909910
if (code <= charCodes.uppercaseZ) {
910911
return true;
911912
}
913+
912914
if (code < charCodes.lowercaseA) {
913915
return code === charCodes.underscore;
914916
}
917+
915918
if (code <= charCodes.lowercaseZ) {
916919
return true;
917920
}
921+
918922
if (code <= 0xffff) {
919923
return (
920924
code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code))
921925
);
922926
}
927+
923928
return isInAstralSet(code, astralIdentifierStartCodes);
924-
}
929+
};
925930

926931
// Test whether a given character is part of an identifier.
927932

928-
export function isIdentifierChar(code: number): boolean {
933+
export const isIdentifierChar = (code: number) => {
929934
if (code < charCodes.digit0) {
930935
return code === charCodes.dollarSign;
931936
}
937+
932938
if (code < charCodes.colon) {
933939
return true;
934940
}
941+
935942
if (code < charCodes.uppercaseA) {
936943
return false;
937944
}
945+
938946
if (code <= charCodes.uppercaseZ) {
939947
return true;
940948
}
949+
941950
if (code < charCodes.lowercaseA) {
942951
return code === charCodes.underscore;
943952
}
953+
944954
if (code <= charCodes.lowercaseZ) {
945955
return true;
946956
}
957+
947958
if (code <= 0xffff) {
948959
return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
949960
}
961+
950962
return (
951963
isInAstralSet(code, astralIdentifierStartCodes) ||
952964
isInAstralSet(code, astralIdentifierCodes)
953965
);
954-
}
966+
};

di/invoker.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ import {
77
type ServiceValue,
88
} from "./primitives.ts";
99

10-
function getFunctionParametersFromString(fnSerialized: string) {
10+
const getFunctionParametersFromString = (fnSerialized: string) => {
1111
const match = fnSerialized.match(/(?:function.*?\(|\()(.*?)(?:\)|=>)/);
1212

1313
if (match && match[1]) {
1414
return match[1].split(",").map((p) => p.trim());
1515
}
1616

1717
return [];
18-
}
18+
};
1919

20-
function getFunctionParameters(fn: AnonymousFunction) {
20+
const getFunctionParameters = (fn: AnonymousFunction) => {
2121
return getFunctionParametersFromString(fn.toString());
22-
}
22+
};
2323

24-
// function analyzeParameter(param: string) {
24+
// const analyzeParameter = (param: string) => {
2525
// const decoratorMatch = param.match(/@(\w+)\(([^)]+)\)/);
2626
// const defaultValueMatch = param.match(/(.*?)=(.*)/);
2727
// const isRestOrSpread = param.startsWith("...");
@@ -53,7 +53,7 @@ function getFunctionParameters(fn: AnonymousFunction) {
5353
// decorators: decorators,
5454
// };
5555
// }
56-
// }
56+
// };
5757

5858
export const invoke = <
5959
T extends AnonymousFunction,

functions/fn.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ bdd.describe("cool/functions/fn", () => {
99
const spyFn = mock.spy();
1010

1111
const fns = fn<Result<string>>(
12-
function () {
12+
() => {
1313
spyFn();
1414

1515
return Ok("Testing");

jsx-runtime.test/root.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ bdd.describe("cool/jsx-runtime", () => {
2424
const spyFn = mock.spy();
2525

2626
// deno-lint-ignore no-explicit-any
27-
function hook(vnode: any) {
27+
const hook = (vnode: any) => {
2828
if (vnode.props["lime-hack"]) {
2929
spyFn();
3030
}
31-
}
31+
};
3232

3333
// @ts-ignore typescript don't recognize this
3434
jsxRuntimeInternal.options.tagHelperHook = hook;

jsx-runtime.test/root.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@
22

33
// @ts-nocheck: JSX.IntrinsicElements issue.
44

5-
export function SubComponent() {
5+
export const SubComponent = () => {
66
return <div>sub component</div>;
7-
}
7+
};
88

99
export interface ComponentProps {
1010
foo: string;
1111
}
1212

13-
export function Component(props: ComponentProps) {
13+
export const Component = (props: ComponentProps) => {
1414
return (
1515
<div>
1616
hello {props.foo}
1717
<br />
1818
<SubComponent />
1919
</div>
2020
);
21-
}
21+
};
2222

23-
export function Root() {
23+
export const Root = () => {
2424
return <Component foo="bar" lime-hack />;
25-
}
25+
};

jsx-runtime/encoder.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
const ENCODED_ENTITIES = /["&<]/;
1010

1111
/** @param {string} str */
12-
export function encodeEntities(str) {
12+
export const encodeEntities = (str) => {
1313
// Skip all work for strings with no entities needing encoding:
14-
if (str.length === 0 || ENCODED_ENTITIES.test(str) === false) return str;
14+
if (str.length === 0 || ENCODED_ENTITIES.test(str) === false) {
15+
return str;
16+
}
1517

1618
let last = 0,
1719
i = 0,
@@ -33,12 +35,21 @@ export function encodeEntities(str) {
3335
default:
3436
continue;
3537
}
38+
3639
// Append skipped/buffered characters and the encoded entity:
37-
if (i !== last) out += str.slice(last, i);
40+
if (i !== last) {
41+
out += str.slice(last, i);
42+
}
43+
3844
out += ch;
45+
3946
// Start the next seek/buffer after the entity's offset:
4047
last = i + 1;
4148
}
42-
if (i !== last) out += str.slice(last, i);
49+
50+
if (i !== last) {
51+
out += str.slice(last, i);
52+
}
53+
4354
return out;
44-
}
55+
};

0 commit comments

Comments
 (0)