tungsten 0.3.1 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.build-complete +1 -0
- package/dist/Components.d.ts +2 -1
- package/dist/Components.d.ts.map +1 -1
- package/dist/Components.js +10 -1
- package/dist/DomRegion.js +1 -1
- package/dist/Framework.d.ts +2 -0
- package/dist/Framework.d.ts.map +1 -1
- package/dist/Framework.js +68 -57
- package/dist/FrameworkConfig.d.ts +6 -0
- package/dist/FrameworkConfig.d.ts.map +1 -1
- package/dist/FunctionComponentStandIn.d.ts +2 -0
- package/dist/FunctionComponentStandIn.d.ts.map +1 -1
- package/dist/FunctionComponentStandIn.js +10 -1
- package/dist/Instance/Instance.d.ts.map +1 -1
- package/dist/Instance/Instance.js +18 -1
- package/dist/Instance/InstanceConfig.d.ts +1 -0
- package/dist/Instance/InstanceConfig.d.ts.map +1 -1
- package/dist/PopMessage.type.d.ts +6 -0
- package/dist/PopMessage.type.d.ts.map +1 -0
- package/dist/PopMessage.type.js +1 -0
- package/dist/Servers/DevServer.d.ts +4 -0
- package/dist/Servers/DevServer.d.ts.map +1 -1
- package/dist/Servers/DevServer.js +116 -13
- package/dist/Servers/MatchedRouteInfo.d.ts +1 -1
- package/dist/Servers/MatchedRouteInfo.d.ts.map +1 -1
- package/dist/Servers/ProdServer.d.ts +1 -0
- package/dist/Servers/ProdServer.d.ts.map +1 -1
- package/dist/Servers/ProdServer.js +79 -5
- package/dist/Servers/devErrorPageAutoRetry.d.ts +4 -0
- package/dist/Servers/devErrorPageAutoRetry.d.ts.map +1 -0
- package/dist/Servers/devErrorPageAutoRetry.js +26 -0
- package/dist/Servers/hono/DevServerHono.js +25 -29
- package/dist/Servers/hono/ProdServerHono.js +49 -142
- package/dist/Servers/hono/TungstenServerHono.d.ts +1 -1
- package/dist/Servers/hono/TungstenServerHono.d.ts.map +1 -1
- package/dist/Servers/hono/TungstenServerHono.js +12 -29
- package/dist/Servers/routing.d.ts.map +1 -1
- package/dist/Servers/routing.js +10 -6
- package/dist/Servers/tungstenCorePrivateEnvSchema.d.ts +0 -3
- package/dist/Servers/tungstenCorePrivateEnvSchema.d.ts.map +1 -1
- package/dist/Servers/tungstenCorePrivateEnvSchema.js +3 -3
- package/dist/Servers/tungstenCorePublicEnvSchema.d.ts +8 -0
- package/dist/Servers/tungstenCorePublicEnvSchema.d.ts.map +1 -0
- package/dist/Servers/tungstenCorePublicEnvSchema.js +14 -0
- package/dist/Store/InternalStoreSchema.d.ts +2 -0
- package/dist/Store/InternalStoreSchema.d.ts.map +1 -1
- package/dist/Store/InternalStoreSchema.js +1 -0
- package/dist/api/Request.d.ts +1 -1
- package/dist/api/Request.d.ts.map +1 -1
- package/dist/api/Response.d.ts +1 -1
- package/dist/api/Response.d.ts.map +1 -1
- package/dist/api/getExport.d.ts.map +1 -1
- package/dist/api/getExport.js +2 -1
- package/dist/babelPlugins/BabelAddDevCacheBust.d.ts +11 -0
- package/dist/babelPlugins/BabelAddDevCacheBust.d.ts.map +1 -0
- package/dist/babelPlugins/BabelAddDevCacheBust.js +68 -0
- package/dist/babelPlugins/BabelTypes.d.ts +2 -2
- package/dist/babelPlugins/BabelTypes.d.ts.map +1 -1
- package/dist/babelPlugins/BabelTypes.js +0 -1
- package/dist/bin/commands/build.d.ts.map +1 -1
- package/dist/bin/commands/build.js +3 -0
- package/dist/bin/commands/dev.d.ts.map +1 -1
- package/dist/bin/commands/dev.js +16 -3
- package/dist/bin/commands/devmon.d.ts +2 -0
- package/dist/bin/commands/devmon.d.ts.map +1 -0
- package/dist/bin/commands/devmon.js +66 -0
- package/dist/bin/index.d.ts.map +1 -1
- package/dist/bin/index.js +6 -0
- package/dist/booleanAttributeValue.d.ts +21 -0
- package/dist/booleanAttributeValue.d.ts.map +1 -0
- package/dist/booleanAttributeValue.js +23 -0
- package/dist/build/compileJavascript.js +1 -1
- package/dist/build/compileUserApp.d.ts +2 -1
- package/dist/build/compileUserApp.d.ts.map +1 -1
- package/dist/build/compileUserApp.js +10 -9
- package/dist/build/createInstanceConfigFile.js +1 -1
- package/dist/build/makeBabelUserDevConfig.d.ts.map +1 -1
- package/dist/build/makeBabelUserDevConfig.js +6 -1
- package/dist/compat/types.d.ts +1 -1
- package/dist/compat/types.d.ts.map +1 -1
- package/dist/components/PopMessages.d.ts +12 -0
- package/dist/components/PopMessages.d.ts.map +1 -0
- package/dist/components/PopMessages.js +45 -0
- package/dist/defaultConfig.d.ts +3 -0
- package/dist/defaultConfig.d.ts.map +1 -1
- package/dist/defaultConfig.js +4 -1
- package/dist/env/Interfaces.d.ts +2 -1
- package/dist/env/Interfaces.d.ts.map +1 -1
- package/dist/env/getEnvSchemas.d.ts +1 -1
- package/dist/env/getEnvSchemas.d.ts.map +1 -1
- package/dist/env/getEnvSchemas.js +2 -1
- package/dist/env/publicEnv.d.ts.map +1 -1
- package/dist/env/publicEnv.js +4 -1
- package/dist/frameworkConfigSchema.d.ts +4 -0
- package/dist/frameworkConfigSchema.d.ts.map +1 -1
- package/dist/frameworkConfigSchema.js +2 -1
- package/dist/getComponent.d.ts.map +1 -1
- package/dist/getComponent.js +2 -1
- package/dist/getRoutes.d.ts.map +1 -1
- package/dist/getRoutes.js +2 -1
- package/dist/hmr/applyHmrModule.d.ts +11 -0
- package/dist/hmr/applyHmrModule.d.ts.map +1 -0
- package/dist/hmr/applyHmrModule.js +78 -0
- package/dist/hmr/componentIdentity.d.ts +9 -0
- package/dist/hmr/componentIdentity.d.ts.map +1 -0
- package/dist/hmr/componentIdentity.js +17 -0
- package/dist/hmr/instanceRegistry.d.ts +4 -0
- package/dist/hmr/instanceRegistry.d.ts.map +1 -0
- package/dist/hmr/instanceRegistry.js +6 -0
- package/dist/hmr/liveReloadHub.d.ts +10 -0
- package/dist/hmr/liveReloadHub.d.ts.map +1 -0
- package/dist/{dev → hmr}/liveReloadHub.js +8 -2
- package/dist/hmr/refreshStylesheets.d.ts +2 -0
- package/dist/hmr/refreshStylesheets.d.ts.map +1 -0
- package/dist/hmr/refreshStylesheets.js +26 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +1 -0
- package/dist/hooks/useInstance.d.ts +3 -0
- package/dist/hooks/useInstance.d.ts.map +1 -0
- package/dist/hooks/useInstance.js +4 -0
- package/dist/hydrate/hydrate.d.ts +10 -0
- package/dist/hydrate/hydrate.d.ts.map +1 -1
- package/dist/hydrate/hydrate.js +81 -19
- package/dist/hydrate/reconcileHydratedAttributes.d.ts.map +1 -1
- package/dist/hydrate/reconcileHydratedAttributes.js +14 -5
- package/dist/hydrate/renderHydrationMismatchBanner.d.ts +7 -0
- package/dist/hydrate/renderHydrationMismatchBanner.d.ts.map +1 -0
- package/dist/hydrate/renderHydrationMismatchBanner.js +69 -0
- package/dist/importDevModuleWithRetry.d.ts +3 -0
- package/dist/importDevModuleWithRetry.d.ts.map +1 -0
- package/dist/importDevModuleWithRetry.js +46 -0
- package/dist/indexInner.d.ts +8 -0
- package/dist/indexInner.d.ts.map +1 -1
- package/dist/indexInner.js +7 -1
- package/dist/makeInstanceConfigFromFrameworkConfig.d.ts.map +1 -1
- package/dist/makeInstanceConfigFromFrameworkConfig.js +2 -1
- package/dist/pop.d.ts +10 -0
- package/dist/pop.d.ts.map +1 -0
- package/dist/pop.js +49 -0
- package/dist/rawHtml/filterContentNode.d.ts +20 -0
- package/dist/rawHtml/filterContentNode.d.ts.map +1 -0
- package/dist/rawHtml/filterContentNode.js +96 -0
- package/dist/rawHtml/parseHtml.d.ts +14 -0
- package/dist/rawHtml/parseHtml.d.ts.map +1 -1
- package/dist/rawHtml/parseHtml.js +4 -4
- package/dist/rawHtml/sanitizeHtml.d.ts +17 -0
- package/dist/rawHtml/sanitizeHtml.d.ts.map +1 -0
- package/dist/rawHtml/sanitizeHtml.js +19 -0
- package/dist/render/HeadData.d.ts +2 -0
- package/dist/render/HeadData.d.ts.map +1 -1
- package/dist/render/contentNodeToHtml.d.ts +18 -0
- package/dist/render/contentNodeToHtml.d.ts.map +1 -0
- package/dist/render/contentNodeToHtml.js +66 -0
- package/dist/render/contentToHtml.d.ts.map +1 -1
- package/dist/render/contentToHtml.js +3 -1
- package/dist/render/processHead.d.ts.map +1 -1
- package/dist/render/processHead.js +53 -6
- package/dist/render/renderingTreeToHtml.d.ts.map +1 -1
- package/dist/render/renderingTreeToHtml.js +8 -1
- package/dist/routing/ErrorRouteType.d.ts +6 -0
- package/dist/routing/ErrorRouteType.d.ts.map +1 -0
- package/dist/routing/ErrorRouteType.js +1 -0
- package/dist/routing/RouteTypes.d.ts +2 -1
- package/dist/routing/RouteTypes.d.ts.map +1 -1
- package/dist/routing/Routes.d.ts +5 -0
- package/dist/routing/Routes.d.ts.map +1 -1
- package/dist/routing/TungstenErrorInfo.d.ts +6 -0
- package/dist/routing/TungstenErrorInfo.d.ts.map +1 -0
- package/dist/routing/TungstenErrorInfo.js +6 -0
- package/dist/style/styleContentSxy.js +21 -0
- package/dist/testing/hydrateTestApp.d.ts +38 -0
- package/dist/testing/hydrateTestApp.d.ts.map +1 -0
- package/dist/testing/hydrateTestApp.js +242 -0
- package/dist/testing/index.d.ts +4 -3
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +16 -2
- package/dist/timeProfiler.d.ts +6 -0
- package/dist/timeProfiler.d.ts.map +1 -0
- package/dist/timeProfiler.js +31 -0
- package/dist/update/integrateUpdateVdom.d.ts +16 -1
- package/dist/update/integrateUpdateVdom.d.ts.map +1 -1
- package/dist/update/integrateUpdateVdom.js +116 -7
- package/dist/warnOnFrameworkChange.d.ts +2 -0
- package/dist/warnOnFrameworkChange.d.ts.map +1 -0
- package/dist/warnOnFrameworkChange.js +27 -0
- package/package.json +18 -16
- package/dist/Instance/gotoRedirect.sxyt.d.ts +0 -2
- package/dist/Instance/gotoRedirect.sxyt.d.ts.map +0 -1
- package/dist/Instance/gotoRedirect.sxyt.js +0 -148
- package/dist/Instance/runTrackedWork.sxyt.d.ts +0 -2
- package/dist/Instance/runTrackedWork.sxyt.d.ts.map +0 -1
- package/dist/Instance/runTrackedWork.sxyt.js +0 -35
- package/dist/_client/cjsHelpers.sxyt.d.ts +0 -2
- package/dist/_client/cjsHelpers.sxyt.d.ts.map +0 -1
- package/dist/_client/cjsHelpers.sxyt.js +0 -45
- package/dist/auth/passwordHashing.sxyt.d.ts +0 -2
- package/dist/auth/passwordHashing.sxyt.d.ts.map +0 -1
- package/dist/auth/passwordHashing.sxyt.js +0 -46
- package/dist/auth/ref/checkPasswordResetToken.sxyt.d.ts +0 -2
- package/dist/auth/ref/checkPasswordResetToken.sxyt.d.ts.map +0 -1
- package/dist/auth/ref/checkPasswordResetToken.sxyt.js +0 -40
- package/dist/auth/ref/createPasswordResetToken.sxyt.d.ts +0 -2
- package/dist/auth/ref/createPasswordResetToken.sxyt.d.ts.map +0 -1
- package/dist/auth/ref/createPasswordResetToken.sxyt.js +0 -10
- package/dist/babelPlugins/fixImportsInSassErrorMessage.sxyt.d.ts +0 -2
- package/dist/babelPlugins/fixImportsInSassErrorMessage.sxyt.d.ts.map +0 -1
- package/dist/babelPlugins/fixImportsInSassErrorMessage.sxyt.js +0 -108
- package/dist/babelPlugins/transformPackageImports/resolveBareImport.sxyt.d.ts +0 -2
- package/dist/babelPlugins/transformPackageImports/resolveBareImport.sxyt.d.ts.map +0 -1
- package/dist/babelPlugins/transformPackageImports/resolveBareImport.sxyt.js +0 -104
- package/dist/bin/commands/compile.sxyt.d.ts +0 -2
- package/dist/bin/commands/compile.sxyt.d.ts.map +0 -1
- package/dist/bin/commands/compile.sxyt.js +0 -255
- package/dist/build/modifySassImports.sxyt.d.ts +0 -2
- package/dist/build/modifySassImports.sxyt.d.ts.map +0 -1
- package/dist/build/modifySassImports.sxyt.js +0 -55
- package/dist/build/sassImportParser.sxyt.d.ts +0 -2
- package/dist/build/sassImportParser.sxyt.d.ts.map +0 -1
- package/dist/build/sassImportParser.sxyt.js +0 -110
- package/dist/build/scssImportParserChatgpt.sxyt.d.ts +0 -2
- package/dist/build/scssImportParserChatgpt.sxyt.d.ts.map +0 -1
- package/dist/build/scssImportParserChatgpt.sxyt.js +0 -120
- package/dist/clone.sxyt.d.ts +0 -2
- package/dist/clone.sxyt.d.ts.map +0 -1
- package/dist/clone.sxyt.js +0 -24
- package/dist/componentProxyHandlers.sxyt.d.ts +0 -2
- package/dist/componentProxyHandlers.sxyt.d.ts.map +0 -1
- package/dist/componentProxyHandlers.sxyt.js +0 -130
- package/dist/components/RawHtml.sxyt.d.ts +0 -2
- package/dist/components/RawHtml.sxyt.d.ts.map +0 -1
- package/dist/components/RawHtml.sxyt.js +0 -104
- package/dist/components/bindable/BindableSelect.sxyt.d.ts +0 -2
- package/dist/components/bindable/BindableSelect.sxyt.d.ts.map +0 -1
- package/dist/components/bindable/BindableSelect.sxyt.js +0 -186
- package/dist/dev/liveReloadHub.d.ts +0 -6
- package/dist/dev/liveReloadHub.d.ts.map +0 -1
- package/dist/env/injectEnv.sxyt.d.ts +0 -2
- package/dist/env/injectEnv.sxyt.d.ts.map +0 -1
- package/dist/env/injectEnv.sxyt.js +0 -20
- package/dist/env/parseEnv.sxyt.d.ts +0 -2
- package/dist/env/parseEnv.sxyt.d.ts.map +0 -1
- package/dist/env/parseEnv.sxyt.js +0 -11
- package/dist/findProjectDir.sxyt.d.ts +0 -2
- package/dist/findProjectDir.sxyt.d.ts.map +0 -1
- package/dist/findProjectDir.sxyt.js +0 -82
- package/dist/hydrate/reconcileHydratedAttributes.sxyt.d.ts +0 -2
- package/dist/hydrate/reconcileHydratedAttributes.sxyt.d.ts.map +0 -1
- package/dist/hydrate/reconcileHydratedAttributes.sxyt.js +0 -173
- package/dist/innerHtmlFromProps.sxyt.d.ts +0 -2
- package/dist/innerHtmlFromProps.sxyt.d.ts.map +0 -1
- package/dist/innerHtmlFromProps.sxyt.js +0 -99
- package/dist/postcssPlugins/parseSelectors.sxyt.d.ts +0 -2
- package/dist/postcssPlugins/parseSelectors.sxyt.d.ts.map +0 -1
- package/dist/postcssPlugins/parseSelectors.sxyt.js +0 -62
- package/dist/postcssPlugins/parseSelectorsRich.sxyt.d.ts +0 -2
- package/dist/postcssPlugins/parseSelectorsRich.sxyt.d.ts.map +0 -1
- package/dist/postcssPlugins/parseSelectorsRich.sxyt.js +0 -155
- package/dist/rawHtml/parseHtml.sxyt.d.ts +0 -2
- package/dist/rawHtml/parseHtml.sxyt.d.ts.map +0 -1
- package/dist/rawHtml/parseHtml.sxyt.js +0 -239
- package/dist/render/getFunctionBodyAsString.sxyt.d.ts +0 -2
- package/dist/render/getFunctionBodyAsString.sxyt.d.ts.map +0 -1
- package/dist/render/getFunctionBodyAsString.sxyt.js +0 -37
- package/dist/render/processProps.sxyt.d.ts +0 -2
- package/dist/render/processProps.sxyt.d.ts.map +0 -1
- package/dist/render/processProps.sxyt.js +0 -90
- package/dist/routing/compareRequestToRegex.sxyt.d.ts +0 -2
- package/dist/routing/compareRequestToRegex.sxyt.d.ts.map +0 -1
- package/dist/routing/compareRequestToRegex.sxyt.js +0 -65
- package/dist/routing/getPathPriority.sxyt.d.ts +0 -2
- package/dist/routing/getPathPriority.sxyt.d.ts.map +0 -1
- package/dist/routing/getPathPriority.sxyt.js +0 -24
- package/dist/routing/matchPath.sxyt.d.ts +0 -2
- package/dist/routing/matchPath.sxyt.d.ts.map +0 -1
- package/dist/routing/matchPath.sxyt.js +0 -41
- package/dist/routing/patternToRegex.sxyt.d.ts +0 -2
- package/dist/routing/patternToRegex.sxyt.d.ts.map +0 -1
- package/dist/routing/patternToRegex.sxyt.js +0 -69
- package/dist/routing/splitRequest.sxyt.d.ts +0 -2
- package/dist/routing/splitRequest.sxyt.d.ts.map +0 -1
- package/dist/routing/splitRequest.sxyt.js +0 -47
- package/dist/style/jssToCss.sxyt.d.ts +0 -2
- package/dist/style/jssToCss.sxyt.d.ts.map +0 -1
- package/dist/style/jssToCss.sxyt.js +0 -17
- package/dist/testing/createTestApp.sxyt.d.ts +0 -2
- package/dist/testing/createTestApp.sxyt.d.ts.map +0 -1
- package/dist/testing/createTestApp.sxyt.js +0 -470
- package/dist/testing/ensureTestEnvLoaded.sxyt.d.ts +0 -2
- package/dist/testing/ensureTestEnvLoaded.sxyt.d.ts.map +0 -1
- package/dist/testing/ensureTestEnvLoaded.sxyt.js +0 -20
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { describe } from 'sxy-test-runner';
|
|
2
|
-
import { parseSelectors } from "./parseSelectors.js";
|
|
3
|
-
describe('parseSelectors()', ({
|
|
4
|
-
it
|
|
5
|
-
}) => {
|
|
6
|
-
const input = 'html';
|
|
7
|
-
it(`parses out a tag selector from '${input}'`, () => {
|
|
8
|
-
const selectors = parseSelectors(input);
|
|
9
|
-
selectors.should.deep.equal(['html']);
|
|
10
|
-
});
|
|
11
|
-
const input2 = 'html body';
|
|
12
|
-
it(`parses out two tag selectors from '${input2}'`, () => {
|
|
13
|
-
const selectors = parseSelectors(input2);
|
|
14
|
-
selectors.should.deep.equal(['html', 'body']);
|
|
15
|
-
});
|
|
16
|
-
const input3 = '.foo';
|
|
17
|
-
it(`parses out a class selector from '${input3}'`, () => {
|
|
18
|
-
const selectors = parseSelectors(input3);
|
|
19
|
-
selectors.should.deep.equal(['.foo']);
|
|
20
|
-
});
|
|
21
|
-
const input4 = ' .foo ';
|
|
22
|
-
it(`parses out a class selector with whitespace from '${input4}'`, () => {
|
|
23
|
-
const selectors = parseSelectors(input4);
|
|
24
|
-
selectors.should.deep.equal(['.foo']);
|
|
25
|
-
});
|
|
26
|
-
const input5 = '.foo .bar';
|
|
27
|
-
it(`parses out a two class selectors from '${input5}'`, () => {
|
|
28
|
-
const selectors = parseSelectors(input5);
|
|
29
|
-
selectors.should.deep.equal(['.foo', '.bar']);
|
|
30
|
-
});
|
|
31
|
-
const input6 = 'html.bar';
|
|
32
|
-
it(`parses out connected tag and class '${input6}'`, () => {
|
|
33
|
-
const selectors = parseSelectors(input6);
|
|
34
|
-
selectors.should.deep.equal(['html', '.bar']);
|
|
35
|
-
});
|
|
36
|
-
const input7 = '.foo.bar';
|
|
37
|
-
it(`parses out connected classes '${input7}'`, () => {
|
|
38
|
-
const selectors = parseSelectors(input7);
|
|
39
|
-
selectors.should.deep.equal(['.foo', '.bar']);
|
|
40
|
-
});
|
|
41
|
-
const input8 = 'html#foo.bar';
|
|
42
|
-
it(`parses out connected tag, id and class '${input8}'`, () => {
|
|
43
|
-
const selectors = parseSelectors(input8);
|
|
44
|
-
selectors.should.deep.equal(['html', '#foo', '.bar']);
|
|
45
|
-
});
|
|
46
|
-
const input9 = 'html[lang="en"]';
|
|
47
|
-
it(`parses out tag with attribute selector from '${input9}'`, () => {
|
|
48
|
-
const selectors = parseSelectors(input9);
|
|
49
|
-
selectors.should.deep.equal(['html', '[lang="en"]']);
|
|
50
|
-
});
|
|
51
|
-
const input10 = ':i(div)';
|
|
52
|
-
it(`parses out :i pseudo '${input10}'`, () => {
|
|
53
|
-
const selectors = parseSelectors(input10);
|
|
54
|
-
selectors.should.deep.equal([':i(div)']);
|
|
55
|
-
});
|
|
56
|
-
const input11 = 'html :i(div)';
|
|
57
|
-
it(`parses out tag then :i pseudo '${input11}'`, () => {
|
|
58
|
-
const selectors = parseSelectors(input11);
|
|
59
|
-
//console.log('selectors', selectors)
|
|
60
|
-
selectors.should.deep.equal(['html', ':i(div)']);
|
|
61
|
-
});
|
|
62
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parseSelectorsRich.sxyt.d.ts","sourceRoot":"","sources":["../../src/postcssPlugins/parseSelectorsRich.sxyt.ts"],"names":[],"mappings":""}
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import { describe } from 'sxy-test-runner';
|
|
2
|
-
import { parseSelectorsRich } from "./parseSelectorsRich.js";
|
|
3
|
-
function tagSelector(tag) {
|
|
4
|
-
return {
|
|
5
|
-
type: 'tag',
|
|
6
|
-
content: tag,
|
|
7
|
-
valid: true
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
function idSelector(id) {
|
|
11
|
-
return {
|
|
12
|
-
type: 'id',
|
|
13
|
-
content: id,
|
|
14
|
-
valid: true
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
function classSelector(className) {
|
|
18
|
-
return {
|
|
19
|
-
type: 'class',
|
|
20
|
-
content: className,
|
|
21
|
-
valid: true
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
function pseudoSelector(pesudo) {
|
|
25
|
-
return {
|
|
26
|
-
type: 'pseudo-class',
|
|
27
|
-
content: pesudo,
|
|
28
|
-
valid: true
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
function pseudoElementSelector(pseudoElement) {
|
|
32
|
-
return {
|
|
33
|
-
type: 'pseudo-element',
|
|
34
|
-
content: pseudoElement,
|
|
35
|
-
valid: true
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
function attributeSelector(attribute) {
|
|
39
|
-
return {
|
|
40
|
-
type: 'attribute',
|
|
41
|
-
content: attribute,
|
|
42
|
-
valid: true
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
function whitespace() {
|
|
46
|
-
return {
|
|
47
|
-
type: 'whitespace',
|
|
48
|
-
content: ' ',
|
|
49
|
-
valid: true
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
describe('parseSelectorsRich()', ({
|
|
53
|
-
it
|
|
54
|
-
}) => {
|
|
55
|
-
const input = 'html';
|
|
56
|
-
it(`parses out a tag selector from '${input}'`, () => {
|
|
57
|
-
const selectors = parseSelectorsRich(input);
|
|
58
|
-
selectors.should.deep.equal([tagSelector('html')]);
|
|
59
|
-
});
|
|
60
|
-
const input2 = 'html body';
|
|
61
|
-
it(`parses out two tag selectors from '${input2}'`, () => {
|
|
62
|
-
const selectors = parseSelectorsRich(input2);
|
|
63
|
-
// console.log('selectors', selectors)
|
|
64
|
-
// console.log('expected', [
|
|
65
|
-
// tagSelector('html'),
|
|
66
|
-
// tagSelector('body')
|
|
67
|
-
// ])
|
|
68
|
-
selectors.should.deep.equal([tagSelector('html'), whitespace(), tagSelector('body')]);
|
|
69
|
-
});
|
|
70
|
-
const input3 = '.foo';
|
|
71
|
-
it(`parses out a class selector from '${input3}'`, () => {
|
|
72
|
-
const selectors = parseSelectorsRich(input3);
|
|
73
|
-
selectors.should.deep.equal([classSelector('.foo')]);
|
|
74
|
-
});
|
|
75
|
-
const input4 = ' .foo ';
|
|
76
|
-
it(`parses out a class selector with whitespace from '${input4}'`, () => {
|
|
77
|
-
const selectors = parseSelectorsRich(input4);
|
|
78
|
-
selectors.should.deep.equal([whitespace(), classSelector('.foo'), whitespace()]);
|
|
79
|
-
});
|
|
80
|
-
const input5 = '.foo .bar';
|
|
81
|
-
it(`parses out a two class selectors from '${input5}'`, () => {
|
|
82
|
-
const selectors = parseSelectorsRich(input5);
|
|
83
|
-
selectors.should.deep.equal([classSelector('.foo'), whitespace(), classSelector('.bar')]);
|
|
84
|
-
});
|
|
85
|
-
const input6 = 'html.bar';
|
|
86
|
-
it(`parses out connected tag and class '${input6}'`, () => {
|
|
87
|
-
const selectors = parseSelectorsRich(input6);
|
|
88
|
-
selectors.should.deep.equal([tagSelector('html'), classSelector('.bar')]);
|
|
89
|
-
});
|
|
90
|
-
const input7 = '.foo.bar';
|
|
91
|
-
it(`parses out connected classes '${input7}'`, () => {
|
|
92
|
-
const selectors = parseSelectorsRich(input7);
|
|
93
|
-
selectors.should.deep.equal([classSelector('.foo'), classSelector('.bar')]);
|
|
94
|
-
});
|
|
95
|
-
const input8 = 'html#foo.bar';
|
|
96
|
-
it(`parses out connected tag, id and class '${input8}'`, () => {
|
|
97
|
-
const selectors = parseSelectorsRich(input8);
|
|
98
|
-
selectors.should.deep.equal([tagSelector('html'), idSelector('#foo'), classSelector('.bar')]);
|
|
99
|
-
});
|
|
100
|
-
const input9 = 'html[lang="en"]';
|
|
101
|
-
it(`parses out tag with attribute selector from '${input9}'`, () => {
|
|
102
|
-
const selectors = parseSelectorsRich(input9);
|
|
103
|
-
// console.log(JSON.stringify(selectors))
|
|
104
|
-
// console.log(JSON.stringify([
|
|
105
|
-
// tagSelector('html'),
|
|
106
|
-
// attributeSelector('[lang="en"]')
|
|
107
|
-
// ]))
|
|
108
|
-
selectors.should.deep.equal([tagSelector('html'), attributeSelector('[lang="en"]')]);
|
|
109
|
-
});
|
|
110
|
-
const input10 = 'html[lang="en"]';
|
|
111
|
-
it(`parses out tag with attribute selector from '${input10}'`, () => {
|
|
112
|
-
const selectors = parseSelectorsRich(input10);
|
|
113
|
-
// console.log(JSON.stringify(selectors))
|
|
114
|
-
// console.log(JSON.stringify([
|
|
115
|
-
// tagSelector('html'),
|
|
116
|
-
// attributeSelector('[lang="en"]')
|
|
117
|
-
// ]))
|
|
118
|
-
selectors.should.deep.equal([tagSelector('html'), attributeSelector('[lang="en"]')]);
|
|
119
|
-
});
|
|
120
|
-
const input11 = 'a:hover';
|
|
121
|
-
it(`parses out :hover pseudo on an anchor in '${input11}'`, () => {
|
|
122
|
-
const selectors = parseSelectorsRich(input11);
|
|
123
|
-
// console.log(JSON.stringify(selectors))
|
|
124
|
-
// console.log(JSON.stringify([
|
|
125
|
-
// tagSelector('a'),
|
|
126
|
-
// pseudoSelector(':hover')
|
|
127
|
-
// ]))
|
|
128
|
-
selectors.should.deep.equal([tagSelector('a'), pseudoSelector(':hover')]);
|
|
129
|
-
});
|
|
130
|
-
const input12 = ':i(div)';
|
|
131
|
-
it(`parses out :i pseudo '${input12}'`, () => {
|
|
132
|
-
const selectors = parseSelectorsRich(input12);
|
|
133
|
-
selectors.should.deep.equal([pseudoSelector(':i(div)')]);
|
|
134
|
-
});
|
|
135
|
-
const input13 = 'html :i(div)';
|
|
136
|
-
it(`parses out tag then :i pseudo '${input13}'`, () => {
|
|
137
|
-
const selectors = parseSelectorsRich(input13);
|
|
138
|
-
selectors.should.deep.equal([tagSelector('html'), whitespace(), pseudoSelector(':i(div)')]);
|
|
139
|
-
});
|
|
140
|
-
const input14 = 'summary::before';
|
|
141
|
-
it(`parses out a pseudo-element from '${input14}'`, () => {
|
|
142
|
-
const selectors = parseSelectorsRich(input14);
|
|
143
|
-
selectors.should.deep.equal([tagSelector('summary'), pseudoElementSelector('::before')]);
|
|
144
|
-
});
|
|
145
|
-
const input15 = 'summary::-webkit-details-marker';
|
|
146
|
-
it(`parses out a vendor prefixed pseudo-element from '${input15}'`, () => {
|
|
147
|
-
const selectors = parseSelectorsRich(input15);
|
|
148
|
-
selectors.should.deep.equal([tagSelector('summary'), pseudoElementSelector('::-webkit-details-marker')]);
|
|
149
|
-
});
|
|
150
|
-
const input16 = 'input:-moz-focusring';
|
|
151
|
-
it(`parses out a vendor prefixed pseudo-class from '${input16}'`, () => {
|
|
152
|
-
const selectors = parseSelectorsRich(input16);
|
|
153
|
-
selectors.should.deep.equal([tagSelector('input'), pseudoSelector(':-moz-focusring')]);
|
|
154
|
-
});
|
|
155
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parseHtml.sxyt.d.ts","sourceRoot":"","sources":["../../src/rawHtml/parseHtml.sxyt.ts"],"names":[],"mappings":""}
|
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
import { describe } from 'sxy-test-runner';
|
|
2
|
-
import { expect } from 'chai';
|
|
3
|
-
import { parseHtml } from "./parseHtml.js";
|
|
4
|
-
import { safeHtmlAllowList } from "./safeHtmlAllowList.js";
|
|
5
|
-
import { decodeHtmlEntities } from "./decodeHtmlEntities.js";
|
|
6
|
-
import { tokenizeHtml } from "./tokenizeHtml.js";
|
|
7
|
-
import { renderingNodeToHtml } from "../render/renderingTreeToHtml.js";
|
|
8
|
-
import { $props, $type } from "../contentNodeSymbols.js";
|
|
9
|
-
// `found: true` short-circuits the <head> handling these tests do not need.
|
|
10
|
-
// eslint-disable-next-line no-type-assertion/no-type-assertion
|
|
11
|
-
const noHeadData = {
|
|
12
|
-
found: true
|
|
13
|
-
};
|
|
14
|
-
// Renders a parsed tree back to markup. The renderer takes a RenderingNode,
|
|
15
|
-
// which for plain HTML content is structurally what parseHtml returns.
|
|
16
|
-
const render = async content => renderingNodeToHtml(
|
|
17
|
-
// eslint-disable-next-line no-type-assertion/no-type-assertion
|
|
18
|
-
content, false, noHeadData, null);
|
|
19
|
-
const roundTrip = html => render(parseHtml(html));
|
|
20
|
-
describe('decodeHtmlEntities()', ({
|
|
21
|
-
it
|
|
22
|
-
}) => {
|
|
23
|
-
it('decodes named, decimal and hex references', () => {
|
|
24
|
-
expect(decodeHtmlEntities('£100 & more')).to.equal('£100 & more');
|
|
25
|
-
expect(decodeHtmlEntities('AB')).to.equal('AB');
|
|
26
|
-
expect(decodeHtmlEntities('AB')).to.equal('AB');
|
|
27
|
-
});
|
|
28
|
-
it('leaves unknown and malformed references exactly as written', () => {
|
|
29
|
-
expect(decodeHtmlEntities('¬areal; &')).to.equal('¬areal; &');
|
|
30
|
-
expect(decodeHtmlEntities('a & b')).to.equal('a & b');
|
|
31
|
-
});
|
|
32
|
-
it('does not throw on out-of-range numeric references', () => {
|
|
33
|
-
expect(decodeHtmlEntities('�')).to.equal('�');
|
|
34
|
-
expect(decodeHtmlEntities('�')).to.equal('�');
|
|
35
|
-
expect(decodeHtmlEntities('�')).to.equal('�');
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
describe('tokenizeHtml()', ({
|
|
39
|
-
it
|
|
40
|
-
}) => {
|
|
41
|
-
it('reads attributes in every quoting style', () => {
|
|
42
|
-
const [token] = tokenizeHtml('<a href="/x" title=\'y\' data-n=3 hidden>');
|
|
43
|
-
expect(token?.kind).to.equal('open');
|
|
44
|
-
expect(token?.kind === 'open' && token.attributes).to.deep.equal({
|
|
45
|
-
href: '/x',
|
|
46
|
-
title: 'y',
|
|
47
|
-
'data-n': '3',
|
|
48
|
-
hidden: true
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
it('drops comments and doctypes', () => {
|
|
52
|
-
expect(tokenizeHtml('<!doctype html><!-- hi --><b>x</b>').map(token => token.kind)).to.deep.equal(['open', 'text', 'close']);
|
|
53
|
-
});
|
|
54
|
-
it('treats a bare < as text', () => {
|
|
55
|
-
expect(tokenizeHtml('5 < 6 and 7 > 2')).to.deep.equal([{
|
|
56
|
-
kind: 'text',
|
|
57
|
-
text: '5 < 6 and 7 > 2'
|
|
58
|
-
}]);
|
|
59
|
-
});
|
|
60
|
-
it('takes script content as literal text, not markup', () => {
|
|
61
|
-
expect(tokenizeHtml('<script>if (a<b) x()</script>').map(token => token.kind)).to.deep.equal(['open', 'text', 'close']);
|
|
62
|
-
});
|
|
63
|
-
// scanning for the first > would cut this tag short and build a tree the
|
|
64
|
-
// browser disagrees with
|
|
65
|
-
it('does not end a tag at a > inside a quoted attribute value', () => {
|
|
66
|
-
const [token] = tokenizeHtml('<a title="a > b" href="/x">');
|
|
67
|
-
expect(token?.kind === 'open' && token.attributes).to.deep.equal({
|
|
68
|
-
title: 'a > b',
|
|
69
|
-
href: '/x'
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
describe('parseHtml()', ({
|
|
74
|
-
it
|
|
75
|
-
}) => {
|
|
76
|
-
it('returns null for empty and non-string input', () => {
|
|
77
|
-
expect(parseHtml('')).to.equal(null);
|
|
78
|
-
// eslint-disable-next-line no-type-assertion/no-type-assertion
|
|
79
|
-
expect(parseHtml(undefined)).to.equal(null);
|
|
80
|
-
});
|
|
81
|
-
it('builds an element tree with decoded text', async () => {
|
|
82
|
-
const content = parseHtml('<p>Bonus £100</p>');
|
|
83
|
-
// eslint-disable-next-line no-type-assertion/no-type-assertion
|
|
84
|
-
const node = content;
|
|
85
|
-
expect(node[$type]).to.equal('p');
|
|
86
|
-
expect(node[$props].children).to.equal('Bonus £100');
|
|
87
|
-
});
|
|
88
|
-
it('maps class to className and style to css, which the renderer expects', async () => {
|
|
89
|
-
expect(await roundTrip('<p class="a b" style="color: red">x</p>')).to.equal('<p class="a b" style="color: red">x</p>');
|
|
90
|
-
});
|
|
91
|
-
it('keeps sibling paragraphs as siblings rather than nesting them', async () => {
|
|
92
|
-
expect(await roundTrip('<p>one</p><p>two</p>')).to.equal('<p>one</p><p>two</p>');
|
|
93
|
-
});
|
|
94
|
-
// The rule that broke the dashboard: a browser closes an open <p> at the
|
|
95
|
-
// next block-level start tag, so the parser must too, or the tree and the
|
|
96
|
-
// DOM disagree and hydration walks off the end.
|
|
97
|
-
it('applies the implied end tag that closes a p at a block element', async () => {
|
|
98
|
-
expect(await roundTrip('<p>one<div>two</div>')).to.equal('<p>one</p><div>two</div>');
|
|
99
|
-
});
|
|
100
|
-
it('closes list items and table cells implicitly', async () => {
|
|
101
|
-
expect(await roundTrip('<ul><li>a<li>b</ul>')).to.equal('<ul><li>a</li><li>b</li></ul>');
|
|
102
|
-
expect(await roundTrip('<table><tbody><tr><td>a<td>b</tbody></table>')).to.equal('<table><tbody><tr><td>a</td><td>b</td></tr></tbody></table>');
|
|
103
|
-
});
|
|
104
|
-
// Parsers disagree over whether whitespace survives inside a table, so the
|
|
105
|
-
// markup carries none — the tree and the DOM then agree either way.
|
|
106
|
-
it('drops whitespace between table tags', async () => {
|
|
107
|
-
expect(await roundTrip('<table>\n<tbody>\n<tr><td>a</td></tr>\n</tbody>\n</table>')).to.equal('<table><tbody><tr><td>a</td></tr></tbody></table>');
|
|
108
|
-
});
|
|
109
|
-
it('foster-parents real text out to just before the table', async () => {
|
|
110
|
-
expect(await roundTrip('<table><tbody>stray<tr><td>a</td></tr></tbody></table>')).to.equal('stray<table><tbody><tr><td>a</td></tr></tbody></table>');
|
|
111
|
-
});
|
|
112
|
-
it('leaves stray text alone in lists and selects, which do not relocate it', async () => {
|
|
113
|
-
expect(await roundTrip('<ul>loose<li>a</li></ul>')).to.equal('<ul>loose<li>a</li></ul>');
|
|
114
|
-
});
|
|
115
|
-
it('handles void and self-closing elements', async () => {
|
|
116
|
-
expect(await roundTrip('<p>a<br>b<img src="/x" />c</p>')).to.equal('<p>a<br />b<img src="/x" />c</p>');
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
describe('parseHtml() resilience', ({
|
|
120
|
-
it
|
|
121
|
-
}) => {
|
|
122
|
-
// "Safe" here means it always produces something renderable, whatever it
|
|
123
|
-
// is handed. None of these may throw.
|
|
124
|
-
const malformed = ['<p>unclosed', '</p>stray end tag', '<p><b>crossed</p></b>', '<<>><p>x</p>', '<p class="unterminated>x</p>', '<!-- never closed', '<p', '<>', '<p><p><p><p>deep', '&&&;&#;&#x;', '<div><span></div></span>', '<TABLE><TR><TD>caps</TD></TR></TABLE>'];
|
|
125
|
-
for (const html of malformed) {
|
|
126
|
-
it(`does not throw on ${JSON.stringify(html)}`, async () => {
|
|
127
|
-
const content = parseHtml(html);
|
|
128
|
-
const rendered = await render(content);
|
|
129
|
-
expect(rendered).to.be.a('string');
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
it('keeps the text of an unclosed element', async () => {
|
|
133
|
-
expect(await roundTrip('<p>unclosed')).to.equal('<p>unclosed</p>');
|
|
134
|
-
});
|
|
135
|
-
it('ignores a stray end tag but keeps its text', async () => {
|
|
136
|
-
expect(await roundTrip('</p>after')).to.equal('after');
|
|
137
|
-
});
|
|
138
|
-
});
|
|
139
|
-
describe('parseHtml() sanitizing', ({
|
|
140
|
-
it
|
|
141
|
-
}) => {
|
|
142
|
-
it('drops script elements together with their contents', async () => {
|
|
143
|
-
expect(await roundTrip('<p>a</p><script>alert(1)</script><p>b</p>')).to.equal('<p>a</p><p>b</p>');
|
|
144
|
-
});
|
|
145
|
-
it('drops on* handler attributes', async () => {
|
|
146
|
-
expect(await roundTrip('<p onclick="alert(1)" onerror="x()" title="keep">a</p>')).to.equal('<p title="keep">a</p>');
|
|
147
|
-
});
|
|
148
|
-
it('drops javascript: urls, including obfuscated ones', async () => {
|
|
149
|
-
expect(await roundTrip('<a href="javascript:alert(1)">x</a>')).to.equal('<a>x</a>');
|
|
150
|
-
expect(await roundTrip('<a href=" JaVaScRiPt:alert(1)">x</a>')).to.equal('<a>x</a>');
|
|
151
|
-
// browsers ignore control characters inside the scheme, so this runs
|
|
152
|
-
expect(await roundTrip('<a href="java\tscript:alert(1)">x</a>')).to.equal('<a>x</a>');
|
|
153
|
-
expect(await roundTrip('<a href="vbscript:x">x</a>')).to.equal('<a>x</a>');
|
|
154
|
-
expect(await roundTrip('<a href="/safe">x</a>')).to.equal('<a href="/safe">x</a>');
|
|
155
|
-
expect(await roundTrip('<a href="https://x.test/">x</a>')).to.equal('<a href="https://x.test/">x</a>');
|
|
156
|
-
});
|
|
157
|
-
it('bars data: urls from navigation but allows them as image sources', async () => {
|
|
158
|
-
expect(await roundTrip('<a href="data:text/html,hello">x</a>')).to.equal('<a>x</a>');
|
|
159
|
-
expect(await roundTrip('<img src="data:image/png;base64,AAAA" />')).to.equal('<img src="data:image/png;base64,AAAA" />');
|
|
160
|
-
});
|
|
161
|
-
it('keeps handler attributes out even when sanitizing is off', async () => {
|
|
162
|
-
// Tungsten reads on* props as event listeners, so a string there is a
|
|
163
|
-
// hydration fault, not just a security question.
|
|
164
|
-
const content = parseHtml('<p onclick="alert(1)">a</p>', {
|
|
165
|
-
sanitize: false
|
|
166
|
-
});
|
|
167
|
-
expect(await render(content)).to.equal('<p>a</p>');
|
|
168
|
-
});
|
|
169
|
-
it('keeps scripts when sanitizing is turned off', async () => {
|
|
170
|
-
const content = parseHtml('<div><script>x()</script></div>', {
|
|
171
|
-
sanitize: false
|
|
172
|
-
});
|
|
173
|
-
expect(await render(content)).to.equal('<div><script>x()</script></div>');
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
describe('parseHtml() allow lists', ({
|
|
177
|
-
it
|
|
178
|
-
}) => {
|
|
179
|
-
const withList = (html, allowList) => render(parseHtml(html, {
|
|
180
|
-
allowList
|
|
181
|
-
}));
|
|
182
|
-
const onlyEmphasis = {
|
|
183
|
-
tags: ['p', 'em'],
|
|
184
|
-
attributes: []
|
|
185
|
-
};
|
|
186
|
-
it('keeps listed tags and unwraps unlisted ones, preserving their text', async () => {
|
|
187
|
-
expect(await withList('<p>keep <em>this</em> and <b>that</b></p>', onlyEmphasis)).to.equal('<p>keep <em>this</em> and that</p>');
|
|
188
|
-
});
|
|
189
|
-
it('unwraps an unlisted element without losing its listed descendants', async () => {
|
|
190
|
-
expect(await withList('<div><p>inner</p></div>', onlyEmphasis)).to.equal('<p>inner</p>');
|
|
191
|
-
});
|
|
192
|
-
it('drops program-text elements entirely rather than unwrapping them', async () => {
|
|
193
|
-
// unwrapping <style> would put its CSS on the page as visible text
|
|
194
|
-
expect(await withList('<p>a</p><style>p { color: red }</style>', onlyEmphasis)).to.equal('<p>a</p>');
|
|
195
|
-
});
|
|
196
|
-
it('keeps only listed attributes', async () => {
|
|
197
|
-
const list = {
|
|
198
|
-
tags: ['p'],
|
|
199
|
-
attributes: ['title']
|
|
200
|
-
};
|
|
201
|
-
expect(await withList('<p title="t" id="i" data-x="1">a</p>', list)).to.equal('<p title="t">a</p>');
|
|
202
|
-
});
|
|
203
|
-
it('applies per-tag attributes only to their own tag', async () => {
|
|
204
|
-
const list = {
|
|
205
|
-
tags: ['a', 'p'],
|
|
206
|
-
attributes: [],
|
|
207
|
-
tagAttributes: {
|
|
208
|
-
a: ['href']
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
expect(await withList('<a href="/x">link</a><p href="/y">para</p>', list)).to.equal('<a href="/x">link</a><p>para</p>');
|
|
212
|
-
});
|
|
213
|
-
});
|
|
214
|
-
describe('safeHtmlAllowList', ({
|
|
215
|
-
it
|
|
216
|
-
}) => {
|
|
217
|
-
const safely = html => render(parseHtml(html, {
|
|
218
|
-
allowList: safeHtmlAllowList
|
|
219
|
-
}));
|
|
220
|
-
it('keeps ordinary authored rich text intact', async () => {
|
|
221
|
-
const html = '<h2>Title</h2><p>Some <strong>bold</strong> and <em>italic</em>.</p>' + '<ul><li>one</li><li>two</li></ul>';
|
|
222
|
-
expect(await safely(html)).to.equal(html);
|
|
223
|
-
});
|
|
224
|
-
it('keeps tables with their layout attributes', async () => {
|
|
225
|
-
const html = '<table><tbody><tr><th align="left">H</th><td colspan="2">C</td></tr></tbody></table>';
|
|
226
|
-
expect(await safely(html)).to.equal(html);
|
|
227
|
-
});
|
|
228
|
-
it('keeps links and images with their own attributes', async () => {
|
|
229
|
-
expect(await safely('<a href="/x" target="_blank" rel="noopener">go</a>')).to.equal('<a href="/x" target="_blank" rel="noopener">go</a>');
|
|
230
|
-
expect(await safely('<img src="/a.png" alt="a" width="10" />')).to.equal('<img src="/a.png" alt="a" width="10" />');
|
|
231
|
-
});
|
|
232
|
-
it('strips style attributes, which can disguise the page without any script', async () => {
|
|
233
|
-
expect(await safely('<p style="position:fixed;top:0">a</p>')).to.equal('<p>a</p>');
|
|
234
|
-
});
|
|
235
|
-
it('removes embedding and form elements but keeps their text', async () => {
|
|
236
|
-
expect(await safely('<iframe src="//evil"></iframe><p>a</p>')).to.equal('<p>a</p>');
|
|
237
|
-
expect(await safely('<form><p>a</p></form>')).to.equal('<p>a</p>');
|
|
238
|
-
});
|
|
239
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getFunctionBodyAsString.sxyt.d.ts","sourceRoot":"","sources":["../../src/render/getFunctionBodyAsString.sxyt.ts"],"names":[],"mappings":""}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { describe } from 'sxy-test-runner';
|
|
2
|
-
import { should as setupShould } from 'chai';
|
|
3
|
-
const should = setupShould(); // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
4
|
-
import { getFunctionBodyAsString } from "./getFunctionBodyAsString.js";
|
|
5
|
-
describe('getFunctionBodyAsString()', ({
|
|
6
|
-
it
|
|
7
|
-
}) => {
|
|
8
|
-
it('should return the function body of a conventional function as a string', () => {
|
|
9
|
-
const func = function () {
|
|
10
|
-
return 'Hello World';
|
|
11
|
-
};
|
|
12
|
-
const body = getFunctionBodyAsString(func);
|
|
13
|
-
//console.log('body', body)
|
|
14
|
-
body.should.equal('return \'Hello World\';');
|
|
15
|
-
});
|
|
16
|
-
it('should handle multi line conventional functions', () => {
|
|
17
|
-
const func = function () {
|
|
18
|
-
return 'Hello World';
|
|
19
|
-
};
|
|
20
|
-
const body = getFunctionBodyAsString(func);
|
|
21
|
-
//console.log('body', body)
|
|
22
|
-
body.should.equal('return \'Hello World\';');
|
|
23
|
-
});
|
|
24
|
-
it('should return the function body of a braceless arrow function as a string', () => {
|
|
25
|
-
const func = () => 'Hello World';
|
|
26
|
-
const body = getFunctionBodyAsString(func);
|
|
27
|
-
//console.log('body', body)
|
|
28
|
-
body.should.equal('return \'Hello World\';');
|
|
29
|
-
});
|
|
30
|
-
it('should handle multi line braceless arrow functions', () => {
|
|
31
|
-
const func = () => 'Hello' + ' World';
|
|
32
|
-
const body = getFunctionBodyAsString(func);
|
|
33
|
-
//console.log('body', body)
|
|
34
|
-
body.should.equal('return \'Hello\' + \' World\';');
|
|
35
|
-
//body.should.equal('return \'Hello\'\n+ \' World\';')
|
|
36
|
-
});
|
|
37
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"processProps.sxyt.d.ts","sourceRoot":"","sources":["../../src/render/processProps.sxyt.ts"],"names":[],"mappings":""}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { describe } from 'sxy-test-runner';
|
|
2
|
-
import { expect } from 'chai';
|
|
3
|
-
import { processProps } from "./processProps.js";
|
|
4
|
-
import { htmlEvents } from "../htmlEvents.js";
|
|
5
|
-
describe('processProps()', ({
|
|
6
|
-
it
|
|
7
|
-
}) => {
|
|
8
|
-
it('keeps ordinary attributes', () => {
|
|
9
|
-
expect(processProps({
|
|
10
|
-
name: 'a',
|
|
11
|
-
title: 't',
|
|
12
|
-
'data-x': '1'
|
|
13
|
-
})).to.deep.equal({
|
|
14
|
-
name: 'a',
|
|
15
|
-
title: 't',
|
|
16
|
-
'data-x': '1'
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
// The list of handlers used to be written out by hand and missed most of
|
|
20
|
-
// them, so anything not named leaked into the markup as an attribute
|
|
21
|
-
// holding a stringified function.
|
|
22
|
-
it('strips every event handler Tungsten recognises, not a hand-picked few', () => {
|
|
23
|
-
const handlers = Object.fromEntries(Object.keys(htmlEvents).map(name => [name, () => undefined]));
|
|
24
|
-
expect(processProps({
|
|
25
|
-
...handlers,
|
|
26
|
-
name: 'a'
|
|
27
|
-
})).to.deep.equal({
|
|
28
|
-
name: 'a'
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
it('strips the handlers that were missing from the old list', () => {
|
|
32
|
-
const kept = processProps({
|
|
33
|
-
onInput: () => undefined,
|
|
34
|
-
onFocus: () => undefined,
|
|
35
|
-
onBlur: () => undefined,
|
|
36
|
-
onScroll: () => undefined,
|
|
37
|
-
onPaste: () => undefined,
|
|
38
|
-
name: 'a'
|
|
39
|
-
});
|
|
40
|
-
expect(Object.keys(kept)).to.deep.equal(['name']);
|
|
41
|
-
});
|
|
42
|
-
it('strips props that are instructions to Tungsten rather than attributes', () => {
|
|
43
|
-
const kept = processProps({
|
|
44
|
-
ref: {
|
|
45
|
-
current: null
|
|
46
|
-
},
|
|
47
|
-
__zoneHtml: '<b>x</b>',
|
|
48
|
-
__opaque: true,
|
|
49
|
-
dangerouslySetInnerHTML: {
|
|
50
|
-
__html: '<b>x</b>'
|
|
51
|
-
},
|
|
52
|
-
name: 'a'
|
|
53
|
-
});
|
|
54
|
-
expect(Object.keys(kept)).to.deep.equal(['name']);
|
|
55
|
-
});
|
|
56
|
-
it('renames className to class', () => {
|
|
57
|
-
expect(processProps({
|
|
58
|
-
className: 'a b'
|
|
59
|
-
})).to.deep.equal({
|
|
60
|
-
class: 'a b'
|
|
61
|
-
});
|
|
62
|
-
// a raw class prop is dropped; className is the one that reaches HTML
|
|
63
|
-
expect(processProps({
|
|
64
|
-
class: 'ignored'
|
|
65
|
-
})).to.deep.equal({});
|
|
66
|
-
});
|
|
67
|
-
it('turns a style object into a css string', () => {
|
|
68
|
-
expect(processProps({
|
|
69
|
-
style: {
|
|
70
|
-
backgroundColor: 'red'
|
|
71
|
-
}
|
|
72
|
-
}).style).to.equal('background-color: red;');
|
|
73
|
-
});
|
|
74
|
-
it('folds css into style and does not leave css behind as an attribute', () => {
|
|
75
|
-
const kept = processProps({
|
|
76
|
-
css: 'color: red'
|
|
77
|
-
});
|
|
78
|
-
expect(kept.style).to.equal('color: red');
|
|
79
|
-
expect('css' in kept).to.equal(false);
|
|
80
|
-
});
|
|
81
|
-
it('does not mutate the props it is given', () => {
|
|
82
|
-
const props = {
|
|
83
|
-
className: 'a',
|
|
84
|
-
onClick: () => undefined,
|
|
85
|
-
name: 'n'
|
|
86
|
-
};
|
|
87
|
-
processProps(props);
|
|
88
|
-
expect(Object.keys(props).sort()).to.deep.equal(['className', 'name', 'onClick']);
|
|
89
|
-
});
|
|
90
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"compareRequestToRegex.sxyt.d.ts","sourceRoot":"","sources":["../../src/routing/compareRequestToRegex.sxyt.ts"],"names":[],"mappings":""}
|