@checkly/playwright-core 1.51.17-beta.2 → 1.54.2-beta.0
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/ThirdPartyNotices.txt +65 -123
- package/browsers.json +16 -14
- package/index.js +1 -1
- package/lib/androidServerImpl.js +47 -50
- package/lib/browserServerImpl.js +89 -69
- package/lib/checkly/escapeRegExp.js +23 -27
- package/lib/checkly/fetch.js +64 -46
- package/lib/checkly/secretsFilter.js +49 -35
- package/lib/cli/driver.js +71 -69
- package/lib/cli/program.js +400 -359
- package/lib/cli/programWithTestStub.js +51 -45
- package/lib/client/accessibility.js +31 -32
- package/lib/client/android.js +151 -242
- package/lib/client/api.js +135 -283
- package/lib/client/artifact.js +39 -36
- package/lib/client/browser.js +96 -71
- package/lib/client/browserContext.js +314 -345
- package/lib/client/browserType.js +103 -127
- package/lib/client/cdpSession.js +29 -31
- package/lib/client/channelOwner.js +90 -113
- package/lib/client/clientHelper.js +48 -39
- package/lib/client/clientInstrumentation.js +40 -37
- package/lib/client/clientStackTrace.js +41 -37
- package/lib/client/clock.js +36 -36
- package/lib/client/connection.js +188 -214
- package/lib/client/consoleMessage.js +31 -28
- package/lib/client/coverage.js +25 -22
- package/lib/client/dialog.js +30 -31
- package/lib/client/download.js +25 -25
- package/lib/client/electron.js +80 -77
- package/lib/client/elementHandle.js +120 -159
- package/lib/client/errors.js +53 -53
- package/lib/client/eventEmitter.js +124 -121
- package/lib/client/events.js +72 -68
- package/lib/client/fetch.js +166 -190
- package/lib/client/fileChooser.js +25 -24
- package/lib/client/fileUtils.js +31 -28
- package/lib/client/frame.js +207 -306
- package/lib/client/harRouter.js +42 -52
- package/lib/client/input.js +42 -69
- package/lib/client/jsHandle.js +54 -69
- package/lib/client/jsonPipe.js +27 -23
- package/lib/client/localUtils.js +29 -29
- package/lib/client/locator.js +145 -237
- package/lib/client/network.js +282 -307
- package/lib/client/page.js +269 -318
- package/lib/client/platform.js +46 -43
- package/lib/client/playwright.js +51 -76
- package/lib/client/selectors.js +45 -63
- package/lib/client/stream.js +29 -25
- package/lib/client/timeoutSettings.js +55 -41
- package/lib/client/tracing.js +49 -96
- package/lib/client/types.js +26 -22
- package/lib/client/video.js +35 -27
- package/lib/client/waiter.js +69 -88
- package/lib/client/webError.js +25 -23
- package/lib/client/webSocket.js +43 -56
- package/lib/client/worker.js +48 -56
- package/lib/client/writableStream.js +27 -23
- package/lib/generated/bindingsControllerSource.js +28 -0
- package/lib/generated/clockSource.js +26 -6
- package/lib/generated/consoleApiSource.js +26 -6
- package/lib/generated/injectedScriptSource.js +26 -6
- package/lib/generated/pollingRecorderSource.js +26 -6
- package/lib/generated/storageScriptSource.js +28 -0
- package/lib/generated/utilityScriptSource.js +26 -6
- package/lib/generated/webSocketMockSource.js +333 -5
- package/lib/inProcessFactory.js +51 -53
- package/lib/inprocess.js +2 -19
- package/lib/outofprocess.js +51 -46
- package/lib/protocol/serializers.js +153 -134
- package/lib/protocol/validator.js +2807 -2739
- package/lib/protocol/validatorPrimitives.js +114 -73
- package/lib/remote/playwrightConnection.js +88 -242
- package/lib/remote/playwrightServer.js +305 -92
- package/lib/server/accessibility.js +44 -37
- package/lib/server/android/android.js +251 -241
- package/lib/server/android/backendAdb.js +87 -82
- package/lib/server/artifact.js +78 -55
- package/lib/server/bidi/bidiBrowser.js +297 -158
- package/lib/server/bidi/bidiChromium.js +119 -89
- package/lib/server/bidi/bidiConnection.js +66 -83
- package/lib/server/bidi/bidiExecutionContext.js +129 -113
- package/lib/server/bidi/bidiFirefox.js +86 -76
- package/lib/server/bidi/bidiInput.js +106 -117
- package/lib/server/bidi/bidiNetworkManager.js +142 -159
- package/lib/server/bidi/bidiOverCdp.js +57 -58
- package/lib/server/bidi/bidiPage.js +260 -260
- package/lib/server/bidi/bidiPdf.js +52 -86
- package/lib/server/bidi/third_party/bidiCommands.d.js +22 -0
- package/lib/server/bidi/third_party/bidiDeserializer.js +55 -50
- package/lib/server/bidi/third_party/bidiKeyboard.js +236 -220
- package/lib/server/bidi/third_party/bidiProtocol.js +22 -137
- package/lib/server/bidi/third_party/bidiProtocolCore.js +152 -0
- package/lib/server/bidi/third_party/bidiProtocolPermissions.js +42 -0
- package/lib/server/bidi/third_party/bidiSerializer.js +67 -63
- package/lib/server/bidi/third_party/firefoxPrefs.js +141 -119
- package/lib/server/browser.js +93 -95
- package/lib/server/browserContext.js +419 -429
- package/lib/server/browserType.js +186 -216
- package/lib/server/callLog.js +47 -44
- package/lib/server/chromium/chromium.js +235 -203
- package/lib/server/chromium/chromiumSwitches.js +100 -67
- package/lib/server/chromium/crAccessibility.js +157 -131
- package/lib/server/chromium/crBrowser.js +310 -292
- package/lib/server/chromium/crConnection.js +95 -121
- package/lib/server/chromium/crCoverage.js +121 -131
- package/lib/server/chromium/crDevTools.js +60 -51
- package/lib/server/chromium/crDragDrop.js +68 -84
- package/lib/server/chromium/crExecutionContext.js +89 -83
- package/lib/server/chromium/crInput.js +118 -113
- package/lib/server/chromium/crNetworkManager.js +274 -375
- package/lib/server/chromium/crPage.js +536 -593
- package/lib/server/chromium/crPdf.js +54 -86
- package/lib/server/chromium/crProtocolHelper.js +92 -80
- package/lib/server/chromium/crServiceWorker.js +84 -73
- package/lib/server/chromium/defaultFontFamilies.js +152 -135
- package/lib/server/chromium/protocol.d.js +16 -0
- package/lib/server/chromium/videoRecorder.js +66 -99
- package/lib/server/clock.js +107 -83
- package/lib/server/codegen/csharp.js +192 -162
- package/lib/server/codegen/java.js +156 -129
- package/lib/server/codegen/javascript.js +163 -148
- package/lib/server/codegen/jsonl.js +32 -28
- package/lib/server/codegen/language.js +75 -52
- package/lib/server/codegen/languages.js +65 -27
- package/lib/server/codegen/python.js +141 -126
- package/lib/server/codegen/types.js +15 -4
- package/lib/server/console.js +28 -32
- package/lib/server/cookieStore.js +108 -86
- package/lib/server/debugController.js +147 -151
- package/lib/server/debugger.js +86 -78
- package/lib/server/deviceDescriptors.js +37 -24
- package/lib/server/deviceDescriptorsSource.json +238 -128
- package/lib/server/dialog.js +84 -39
- package/lib/server/dispatchers/androidDispatcher.js +257 -148
- package/lib/server/dispatchers/artifactDispatcher.js +79 -79
- package/lib/server/dispatchers/browserContextDispatcher.js +289 -259
- package/lib/server/dispatchers/browserDispatcher.js +96 -148
- package/lib/server/dispatchers/browserTypeDispatcher.js +50 -41
- package/lib/server/dispatchers/cdpSessionDispatcher.js +35 -39
- package/lib/server/dispatchers/debugControllerDispatcher.js +65 -83
- package/lib/server/dispatchers/dialogDispatcher.js +34 -31
- package/lib/server/dispatchers/dispatcher.js +208 -248
- package/lib/server/dispatchers/electronDispatcher.js +66 -70
- package/lib/server/dispatchers/elementHandlerDispatcher.js +164 -216
- package/lib/server/dispatchers/frameDispatcher.js +211 -272
- package/lib/server/dispatchers/jsHandleDispatcher.js +63 -75
- package/lib/server/dispatchers/jsonPipeDispatcher.js +37 -38
- package/lib/server/dispatchers/localUtilsDispatcher.js +121 -119
- package/lib/server/dispatchers/networkDispatchers.js +117 -128
- package/lib/server/dispatchers/pageDispatcher.js +256 -248
- package/lib/server/dispatchers/playwrightDispatcher.js +92 -87
- package/lib/server/dispatchers/streamDispatcher.js +52 -48
- package/lib/server/dispatchers/tracingDispatcher.js +47 -52
- package/lib/server/dispatchers/webSocketRouteDispatcher.js +126 -150
- package/lib/server/dispatchers/writableStreamDispatcher.js +65 -43
- package/lib/server/dom.js +485 -582
- package/lib/server/download.js +47 -37
- package/lib/server/electron/electron.js +216 -243
- package/lib/server/electron/loader.js +9 -37
- package/lib/server/errors.js +47 -46
- package/lib/server/fetch.js +317 -360
- package/lib/server/fileChooser.js +25 -24
- package/lib/server/fileUploadUtils.js +66 -60
- package/lib/server/firefox/ffAccessibility.js +153 -131
- package/lib/server/firefox/ffBrowser.js +268 -305
- package/lib/server/firefox/ffConnection.js +63 -84
- package/lib/server/firefox/ffExecutionContext.js +92 -73
- package/lib/server/firefox/ffInput.js +82 -84
- package/lib/server/firefox/ffNetworkManager.js +137 -114
- package/lib/server/firefox/ffPage.js +261 -293
- package/lib/server/firefox/firefox.js +80 -72
- package/lib/server/firefox/protocol.d.js +16 -0
- package/lib/server/formData.js +107 -35
- package/lib/server/frameSelectors.js +98 -114
- package/lib/server/frames.js +845 -1055
- package/lib/server/har/harRecorder.js +85 -77
- package/lib/server/har/harTracer.js +290 -223
- package/lib/server/harBackend.js +80 -80
- package/lib/server/helper.js +55 -59
- package/lib/server/index.js +59 -99
- package/lib/server/input.js +151 -189
- package/lib/server/instrumentation.js +57 -44
- package/lib/server/javascript.js +133 -134
- package/lib/server/launchApp.js +113 -75
- package/lib/server/localUtils.js +150 -142
- package/lib/server/macEditingCommands.js +141 -137
- package/lib/server/network.js +299 -303
- package/lib/server/page.js +513 -544
- package/lib/server/pipeTransport.js +49 -45
- package/lib/server/playwright.js +58 -67
- package/lib/server/progress.js +137 -68
- package/lib/server/protocolError.js +34 -31
- package/lib/server/recorder/chat.js +70 -86
- package/lib/server/recorder/recorderApp.js +341 -176
- package/lib/server/recorder/recorderInTraceViewer.js +65 -94
- package/lib/server/recorder/recorderRunner.js +93 -116
- package/lib/server/recorder/recorderSignalProcessor.js +83 -0
- package/lib/server/recorder/recorderUtils.js +104 -47
- package/lib/server/recorder/throttledFile.js +42 -30
- package/lib/server/recorder.js +395 -275
- package/lib/server/registry/browserFetcher.js +106 -101
- package/lib/server/registry/dependencies.js +245 -196
- package/lib/server/registry/index.js +930 -803
- package/lib/server/registry/nativeDeps.js +1073 -464
- package/lib/server/registry/oopDownloadBrowserMain.js +57 -75
- package/lib/server/screenshotter.js +160 -191
- package/lib/server/selectors.js +90 -51
- package/lib/server/socksClientCertificatesInterceptor.js +171 -186
- package/lib/server/socksInterceptor.js +62 -70
- package/lib/server/trace/recorder/snapshotter.js +76 -102
- package/lib/server/trace/recorder/snapshotterInjected.js +238 -217
- package/lib/server/trace/recorder/tracing.js +354 -362
- package/lib/server/trace/test/inMemorySnapshotter.js +46 -52
- package/lib/server/trace/viewer/traceViewer.js +160 -147
- package/lib/server/transport.js +119 -134
- package/lib/server/types.js +26 -22
- package/lib/server/usKeyboardLayout.js +135 -545
- package/lib/server/utils/ascii.js +39 -26
- package/lib/server/utils/comparators.js +105 -103
- package/lib/server/utils/crypto.js +157 -112
- package/lib/server/utils/debug.js +36 -32
- package/lib/server/utils/debugLogger.js +77 -48
- package/lib/server/utils/env.js +52 -37
- package/lib/server/utils/eventsHelper.js +29 -28
- package/lib/server/utils/expectUtils.js +31 -26
- package/lib/server/utils/fileUtils.js +123 -136
- package/lib/server/utils/happyEyeballs.js +141 -126
- package/lib/server/utils/hostPlatform.js +84 -120
- package/lib/server/utils/httpServer.js +106 -121
- package/lib/server/utils/image_tools/colorUtils.js +42 -51
- package/lib/server/utils/image_tools/compare.js +44 -43
- package/lib/server/utils/image_tools/imageChannel.js +38 -30
- package/lib/server/utils/image_tools/stats.js +40 -40
- package/lib/server/utils/linuxUtils.js +50 -37
- package/lib/server/utils/network.js +152 -96
- package/lib/server/utils/nodePlatform.js +87 -79
- package/lib/server/utils/pipeTransport.js +44 -42
- package/lib/server/utils/processLauncher.js +111 -121
- package/lib/server/utils/profiler.js +52 -39
- package/lib/server/utils/socksProxy.js +280 -339
- package/lib/server/utils/spawnAsync.js +37 -41
- package/lib/server/utils/task.js +31 -38
- package/lib/server/utils/userAgent.js +73 -66
- package/lib/server/utils/wsServer.js +68 -75
- package/lib/server/utils/zipFile.js +36 -37
- package/lib/server/utils/zones.js +37 -34
- package/lib/server/webkit/protocol.d.js +16 -0
- package/lib/server/webkit/webkit.js +77 -61
- package/lib/server/webkit/wkAccessibility.js +161 -118
- package/lib/server/webkit/wkBrowser.js +193 -184
- package/lib/server/webkit/wkConnection.js +59 -83
- package/lib/server/webkit/wkExecutionContext.js +85 -70
- package/lib/server/webkit/wkInput.js +97 -95
- package/lib/server/webkit/wkInterceptableRequest.js +102 -95
- package/lib/server/webkit/wkPage.js +568 -667
- package/lib/server/webkit/wkProvisionalPage.js +45 -56
- package/lib/server/webkit/wkWorkers.js +79 -79
- package/lib/utils/expectUtils.js +31 -26
- package/lib/utils/isomorphic/ariaSnapshot.js +149 -152
- package/lib/utils/isomorphic/assert.js +28 -22
- package/lib/utils/isomorphic/colors.js +66 -59
- package/lib/utils/isomorphic/cssParser.js +120 -125
- package/lib/utils/isomorphic/cssTokenizer.js +436 -364
- package/lib/utils/isomorphic/headers.js +38 -37
- package/lib/utils/isomorphic/locatorGenerators.js +358 -357
- package/lib/utils/isomorphic/locatorParser.js +96 -105
- package/lib/utils/isomorphic/locatorUtils.js +63 -44
- package/lib/utils/isomorphic/manualPromise.js +46 -39
- package/lib/utils/isomorphic/mimeType.js +447 -25
- package/lib/utils/isomorphic/multimap.js +34 -27
- package/lib/utils/isomorphic/protocolFormatter.js +68 -0
- package/lib/utils/isomorphic/protocolMetainfo.js +321 -0
- package/lib/utils/isomorphic/recorderUtils.js +140 -181
- package/lib/utils/isomorphic/rtti.js +35 -33
- package/lib/utils/isomorphic/selectorParser.js +182 -193
- package/lib/utils/isomorphic/semaphore.js +27 -24
- package/lib/utils/isomorphic/stackTrace.js +87 -98
- package/lib/utils/isomorphic/stringUtils.js +98 -112
- package/lib/utils/isomorphic/time.js +46 -22
- package/lib/utils/isomorphic/timeoutRunner.js +53 -53
- package/lib/utils/isomorphic/traceUtils.js +37 -41
- package/lib/utils/isomorphic/types.js +15 -4
- package/lib/utils/isomorphic/urlMatch.js +113 -67
- package/lib/utils/isomorphic/utilityScriptSerializers.js +251 -0
- package/lib/utils.js +101 -443
- package/lib/utilsBundle.js +101 -52
- package/lib/utilsBundleImpl/index.js +160 -150
- package/lib/zipBundle.js +32 -23
- package/lib/zipBundleImpl.js +4 -4
- package/package.json +1 -1
- package/types/protocol.d.ts +1267 -1057
- package/types/types.d.ts +131 -29
- package/lib/common/socksProxy.js +0 -569
- package/lib/common/timeoutSettings.js +0 -73
- package/lib/common/types.js +0 -5
- package/lib/image_tools/colorUtils.js +0 -98
- package/lib/image_tools/compare.js +0 -108
- package/lib/image_tools/imageChannel.js +0 -70
- package/lib/image_tools/stats.js +0 -102
- package/lib/protocol/debug.js +0 -27
- package/lib/protocol/transport.js +0 -82
- package/lib/server/dispatchers/selectorsDispatcher.js +0 -36
- package/lib/server/isomorphic/utilityScriptSerializers.js +0 -229
- package/lib/server/recorder/contextRecorder.js +0 -290
- package/lib/server/recorder/recorderCollection.js +0 -104
- package/lib/server/recorder/recorderFrontend.js +0 -5
- package/lib/server/storageScript.js +0 -160
- package/lib/server/timeoutSettings.js +0 -74
- package/lib/third_party/diff_match_patch.js +0 -2222
- package/lib/utils/ascii.js +0 -31
- package/lib/utils/comparators.js +0 -171
- package/lib/utils/crypto.js +0 -174
- package/lib/utils/debug.js +0 -46
- package/lib/utils/debugLogger.js +0 -91
- package/lib/utils/env.js +0 -49
- package/lib/utils/eventsHelper.js +0 -38
- package/lib/utils/fileUtils.js +0 -205
- package/lib/utils/happy-eyeballs.js +0 -210
- package/lib/utils/headers.js +0 -52
- package/lib/utils/hostPlatform.js +0 -133
- package/lib/utils/httpServer.js +0 -237
- package/lib/utils/index.js +0 -368
- package/lib/utils/linuxUtils.js +0 -78
- package/lib/utils/manualPromise.js +0 -109
- package/lib/utils/multimap.js +0 -75
- package/lib/utils/network.js +0 -160
- package/lib/utils/processLauncher.js +0 -248
- package/lib/utils/profiler.js +0 -53
- package/lib/utils/rtti.js +0 -44
- package/lib/utils/semaphore.js +0 -51
- package/lib/utils/spawnAsync.js +0 -45
- package/lib/utils/stackTrace.js +0 -121
- package/lib/utils/task.js +0 -58
- package/lib/utils/time.js +0 -37
- package/lib/utils/timeoutRunner.js +0 -66
- package/lib/utils/traceUtils.js +0 -44
- package/lib/utils/userAgent.js +0 -105
- package/lib/utils/wsServer.js +0 -127
- package/lib/utils/zipFile.js +0 -75
- package/lib/utils/zones.js +0 -62
- package/lib/vite/htmlReport/index.html +0 -69
- package/lib/vite/recorder/assets/codeMirrorModule-B9YMkrwa.js +0 -24
- package/lib/vite/recorder/assets/codeMirrorModule-C3UTv-Ge.css +0 -1
- package/lib/vite/recorder/assets/codicon-DCmgc-ay.ttf +0 -0
- package/lib/vite/recorder/assets/index-ELPgmkwA.js +0 -184
- package/lib/vite/recorder/assets/index-eHBmevrY.css +0 -1
- package/lib/vite/recorder/index.html +0 -29
- package/lib/vite/recorder/playwright-logo.svg +0 -9
- package/lib/vite/traceViewer/assets/codeMirrorModule-gU1OOCQO.js +0 -24
- package/lib/vite/traceViewer/assets/defaultSettingsView-B5n_FjMx.js +0 -1
- package/lib/vite/traceViewer/assets/inspectorTab-6Tru8Mn_.js +0 -235
- package/lib/vite/traceViewer/assets/workbench-B_Nj4NA2.js +0 -25
- package/lib/vite/traceViewer/assets/xtermModule-BoAIEibi.js +0 -9
- package/lib/vite/traceViewer/codeMirrorModule.C3UTv-Ge.css +0 -1
- package/lib/vite/traceViewer/codicon.DCmgc-ay.ttf +0 -0
- package/lib/vite/traceViewer/defaultSettingsView.CO3FR0CX.css +0 -1
- package/lib/vite/traceViewer/embedded.DpNPH6mk.js +0 -2
- package/lib/vite/traceViewer/embedded.html +0 -18
- package/lib/vite/traceViewer/embedded.mLhjB5IF.css +0 -1
- package/lib/vite/traceViewer/index.CFOW-Ezb.css +0 -1
- package/lib/vite/traceViewer/index.CuE3SYGw.js +0 -2
- package/lib/vite/traceViewer/index.html +0 -47
- package/lib/vite/traceViewer/inspectorTab.CXDulcFG.css +0 -1
- package/lib/vite/traceViewer/playwright-logo.svg +0 -9
- package/lib/vite/traceViewer/recorder.BD-uZJs7.js +0 -2
- package/lib/vite/traceViewer/recorder.html +0 -17
- package/lib/vite/traceViewer/recorder.tn0RQdqM.css +0 -0
- package/lib/vite/traceViewer/snapshot.html +0 -21
- package/lib/vite/traceViewer/sw.bundle.js +0 -3
- package/lib/vite/traceViewer/uiMode.BatfzHMG.css +0 -1
- package/lib/vite/traceViewer/uiMode.DHrNgddz.js +0 -5
- package/lib/vite/traceViewer/uiMode.html +0 -21
- package/lib/vite/traceViewer/workbench.B9vIAzH9.css +0 -1
- package/lib/vite/traceViewer/xtermModule.Beg8tuEN.css +0 -32
|
@@ -1,84 +1,119 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var cssTokenizer_exports = {};
|
|
20
|
+
__export(cssTokenizer_exports, {
|
|
21
|
+
AtKeywordToken: () => AtKeywordToken,
|
|
22
|
+
BadStringToken: () => BadStringToken,
|
|
23
|
+
BadURLToken: () => BadURLToken,
|
|
24
|
+
CDCToken: () => CDCToken,
|
|
25
|
+
CDOToken: () => CDOToken,
|
|
26
|
+
CSSParserToken: () => CSSParserToken,
|
|
27
|
+
CloseCurlyToken: () => CloseCurlyToken,
|
|
28
|
+
CloseParenToken: () => CloseParenToken,
|
|
29
|
+
CloseSquareToken: () => CloseSquareToken,
|
|
30
|
+
ColonToken: () => ColonToken,
|
|
31
|
+
ColumnToken: () => ColumnToken,
|
|
32
|
+
CommaToken: () => CommaToken,
|
|
33
|
+
DashMatchToken: () => DashMatchToken,
|
|
34
|
+
DelimToken: () => DelimToken,
|
|
35
|
+
DimensionToken: () => DimensionToken,
|
|
36
|
+
EOFToken: () => EOFToken,
|
|
37
|
+
FunctionToken: () => FunctionToken,
|
|
38
|
+
GroupingToken: () => GroupingToken,
|
|
39
|
+
HashToken: () => HashToken,
|
|
40
|
+
IdentToken: () => IdentToken,
|
|
41
|
+
IncludeMatchToken: () => IncludeMatchToken,
|
|
42
|
+
InvalidCharacterError: () => InvalidCharacterError,
|
|
43
|
+
NumberToken: () => NumberToken,
|
|
44
|
+
OpenCurlyToken: () => OpenCurlyToken,
|
|
45
|
+
OpenParenToken: () => OpenParenToken,
|
|
46
|
+
OpenSquareToken: () => OpenSquareToken,
|
|
47
|
+
PercentageToken: () => PercentageToken,
|
|
48
|
+
PrefixMatchToken: () => PrefixMatchToken,
|
|
49
|
+
SemicolonToken: () => SemicolonToken,
|
|
50
|
+
StringToken: () => StringToken,
|
|
51
|
+
StringValuedToken: () => StringValuedToken,
|
|
52
|
+
SubstringMatchToken: () => SubstringMatchToken,
|
|
53
|
+
SuffixMatchToken: () => SuffixMatchToken,
|
|
54
|
+
URLToken: () => URLToken,
|
|
55
|
+
WhitespaceToken: () => WhitespaceToken,
|
|
56
|
+
tokenize: () => tokenize
|
|
5
57
|
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/* eslint-disable notice/notice */
|
|
9
|
-
|
|
10
|
-
/*
|
|
11
|
-
* The code in this file is licensed under the CC0 license.
|
|
12
|
-
* http://creativecommons.org/publicdomain/zero/1.0/
|
|
13
|
-
* It is free to use for any purpose. No attribution, permission, or reproduction of this license is required.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
// Original at https://github.com/tabatkins/parse-css
|
|
17
|
-
// Changes:
|
|
18
|
-
// - JS is replaced with TS.
|
|
19
|
-
// - Universal Module Definition wrapper is removed.
|
|
20
|
-
// - Everything not related to tokenizing - below the first exports block - is removed.
|
|
21
|
-
|
|
22
|
-
const between = function (num, first, last) {
|
|
58
|
+
module.exports = __toCommonJS(cssTokenizer_exports);
|
|
59
|
+
const between = function(num, first, last) {
|
|
23
60
|
return num >= first && num <= last;
|
|
24
61
|
};
|
|
25
62
|
function digit(code) {
|
|
26
|
-
return between(code,
|
|
63
|
+
return between(code, 48, 57);
|
|
27
64
|
}
|
|
28
65
|
function hexdigit(code) {
|
|
29
|
-
return digit(code) || between(code,
|
|
66
|
+
return digit(code) || between(code, 65, 70) || between(code, 97, 102);
|
|
30
67
|
}
|
|
31
68
|
function uppercaseletter(code) {
|
|
32
|
-
return between(code,
|
|
69
|
+
return between(code, 65, 90);
|
|
33
70
|
}
|
|
34
71
|
function lowercaseletter(code) {
|
|
35
|
-
return between(code,
|
|
72
|
+
return between(code, 97, 122);
|
|
36
73
|
}
|
|
37
74
|
function letter(code) {
|
|
38
75
|
return uppercaseletter(code) || lowercaseletter(code);
|
|
39
76
|
}
|
|
40
77
|
function nonascii(code) {
|
|
41
|
-
return code >=
|
|
78
|
+
return code >= 128;
|
|
42
79
|
}
|
|
43
80
|
function namestartchar(code) {
|
|
44
|
-
return letter(code) || nonascii(code) || code ===
|
|
81
|
+
return letter(code) || nonascii(code) || code === 95;
|
|
45
82
|
}
|
|
46
83
|
function namechar(code) {
|
|
47
|
-
return namestartchar(code) || digit(code) || code ===
|
|
84
|
+
return namestartchar(code) || digit(code) || code === 45;
|
|
48
85
|
}
|
|
49
86
|
function nonprintable(code) {
|
|
50
|
-
return between(code, 0, 8) || code ===
|
|
87
|
+
return between(code, 0, 8) || code === 11 || between(code, 14, 31) || code === 127;
|
|
51
88
|
}
|
|
52
89
|
function newline(code) {
|
|
53
|
-
return code ===
|
|
90
|
+
return code === 10;
|
|
54
91
|
}
|
|
55
92
|
function whitespace(code) {
|
|
56
|
-
return newline(code) || code === 9 || code ===
|
|
93
|
+
return newline(code) || code === 9 || code === 32;
|
|
57
94
|
}
|
|
58
|
-
const maximumallowedcodepoint =
|
|
95
|
+
const maximumallowedcodepoint = 1114111;
|
|
59
96
|
class InvalidCharacterError extends Error {
|
|
60
97
|
constructor(message) {
|
|
61
98
|
super(message);
|
|
62
|
-
this.name =
|
|
99
|
+
this.name = "InvalidCharacterError";
|
|
63
100
|
}
|
|
64
101
|
}
|
|
65
|
-
exports.InvalidCharacterError = InvalidCharacterError;
|
|
66
102
|
function preprocess(str) {
|
|
67
|
-
// Turn a string into an array of code points,
|
|
68
|
-
// following the preprocessing cleanup rules.
|
|
69
103
|
const codepoints = [];
|
|
70
104
|
for (let i = 0; i < str.length; i++) {
|
|
71
105
|
let code = str.charCodeAt(i);
|
|
72
|
-
if (code ===
|
|
73
|
-
code =
|
|
106
|
+
if (code === 13 && str.charCodeAt(i + 1) === 10) {
|
|
107
|
+
code = 10;
|
|
74
108
|
i++;
|
|
75
109
|
}
|
|
76
|
-
if (code ===
|
|
77
|
-
|
|
78
|
-
if (
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const
|
|
110
|
+
if (code === 13 || code === 12)
|
|
111
|
+
code = 10;
|
|
112
|
+
if (code === 0)
|
|
113
|
+
code = 65533;
|
|
114
|
+
if (between(code, 55296, 56319) && between(str.charCodeAt(i + 1), 56320, 57343)) {
|
|
115
|
+
const lead = code - 55296;
|
|
116
|
+
const trail = str.charCodeAt(i + 1) - 56320;
|
|
82
117
|
code = Math.pow(2, 16) + lead * Math.pow(2, 10) + trail;
|
|
83
118
|
i++;
|
|
84
119
|
}
|
|
@@ -87,11 +122,11 @@ function preprocess(str) {
|
|
|
87
122
|
return codepoints;
|
|
88
123
|
}
|
|
89
124
|
function stringFromCode(code) {
|
|
90
|
-
if (code <=
|
|
91
|
-
|
|
125
|
+
if (code <= 65535)
|
|
126
|
+
return String.fromCharCode(code);
|
|
92
127
|
code -= Math.pow(2, 16);
|
|
93
|
-
const lead = Math.floor(code / Math.pow(2, 10)) +
|
|
94
|
-
const trail = code % Math.pow(2, 10) +
|
|
128
|
+
const lead = Math.floor(code / Math.pow(2, 10)) + 55296;
|
|
129
|
+
const trail = code % Math.pow(2, 10) + 56320;
|
|
95
130
|
return String.fromCharCode(lead) + String.fromCharCode(trail);
|
|
96
131
|
}
|
|
97
132
|
function tokenize(str1) {
|
|
@@ -99,39 +134,39 @@ function tokenize(str1) {
|
|
|
99
134
|
let i = -1;
|
|
100
135
|
const tokens = [];
|
|
101
136
|
let code;
|
|
102
|
-
|
|
103
|
-
// Line number information.
|
|
104
137
|
let line = 0;
|
|
105
138
|
let column = 0;
|
|
106
|
-
// The only use of lastLineLength is in reconsume().
|
|
107
139
|
let lastLineLength = 0;
|
|
108
|
-
const incrLineno = function
|
|
140
|
+
const incrLineno = function() {
|
|
109
141
|
line += 1;
|
|
110
142
|
lastLineLength = column;
|
|
111
143
|
column = 0;
|
|
112
144
|
};
|
|
113
|
-
const locStart = {
|
|
114
|
-
|
|
115
|
-
|
|
145
|
+
const locStart = { line, column };
|
|
146
|
+
const codepoint = function(i2) {
|
|
147
|
+
if (i2 >= str.length)
|
|
148
|
+
return -1;
|
|
149
|
+
return str[i2];
|
|
116
150
|
};
|
|
117
|
-
const
|
|
118
|
-
if (
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (num === undefined) num = 1;
|
|
123
|
-
if (num > 3) throw 'Spec Error: no more than three codepoints of lookahead.';
|
|
151
|
+
const next = function(num) {
|
|
152
|
+
if (num === void 0)
|
|
153
|
+
num = 1;
|
|
154
|
+
if (num > 3)
|
|
155
|
+
throw "Spec Error: no more than three codepoints of lookahead.";
|
|
124
156
|
return codepoint(i + num);
|
|
125
157
|
};
|
|
126
|
-
const consume = function
|
|
127
|
-
if (num ===
|
|
158
|
+
const consume = function(num) {
|
|
159
|
+
if (num === void 0)
|
|
160
|
+
num = 1;
|
|
128
161
|
i += num;
|
|
129
162
|
code = codepoint(i);
|
|
130
|
-
if (newline(code))
|
|
131
|
-
|
|
163
|
+
if (newline(code))
|
|
164
|
+
incrLineno();
|
|
165
|
+
else
|
|
166
|
+
column += num;
|
|
132
167
|
return true;
|
|
133
168
|
};
|
|
134
|
-
const reconsume = function
|
|
169
|
+
const reconsume = function() {
|
|
135
170
|
i -= 1;
|
|
136
171
|
if (newline(code)) {
|
|
137
172
|
line -= 1;
|
|
@@ -143,66 +178,68 @@ function tokenize(str1) {
|
|
|
143
178
|
locStart.column = column;
|
|
144
179
|
return true;
|
|
145
180
|
};
|
|
146
|
-
const eof = function
|
|
147
|
-
if (
|
|
148
|
-
|
|
181
|
+
const eof = function(codepoint2) {
|
|
182
|
+
if (codepoint2 === void 0)
|
|
183
|
+
codepoint2 = code;
|
|
184
|
+
return codepoint2 === -1;
|
|
185
|
+
};
|
|
186
|
+
const donothing = function() {
|
|
149
187
|
};
|
|
150
|
-
const
|
|
151
|
-
const parseerror = function () {
|
|
152
|
-
// Language bindings don't like writing to stdout!
|
|
153
|
-
// console.log('Parse error at index ' + i + ', processing codepoint 0x' + code.toString(16) + '.'); return true;
|
|
188
|
+
const parseerror = function() {
|
|
154
189
|
};
|
|
155
|
-
const consumeAToken = function
|
|
190
|
+
const consumeAToken = function() {
|
|
156
191
|
consumeComments();
|
|
157
192
|
consume();
|
|
158
193
|
if (whitespace(code)) {
|
|
159
|
-
while (whitespace(next()))
|
|
194
|
+
while (whitespace(next()))
|
|
195
|
+
consume();
|
|
160
196
|
return new WhitespaceToken();
|
|
161
|
-
} else if (code ===
|
|
197
|
+
} else if (code === 34) {
|
|
162
198
|
return consumeAStringToken();
|
|
163
|
-
} else if (code ===
|
|
199
|
+
} else if (code === 35) {
|
|
164
200
|
if (namechar(next()) || areAValidEscape(next(1), next(2))) {
|
|
165
|
-
const token = new HashToken(
|
|
166
|
-
if (wouldStartAnIdentifier(next(1), next(2), next(3)))
|
|
201
|
+
const token = new HashToken("");
|
|
202
|
+
if (wouldStartAnIdentifier(next(1), next(2), next(3)))
|
|
203
|
+
token.type = "id";
|
|
167
204
|
token.value = consumeAName();
|
|
168
205
|
return token;
|
|
169
206
|
} else {
|
|
170
207
|
return new DelimToken(code);
|
|
171
208
|
}
|
|
172
|
-
} else if (code ===
|
|
173
|
-
if (next() ===
|
|
209
|
+
} else if (code === 36) {
|
|
210
|
+
if (next() === 61) {
|
|
174
211
|
consume();
|
|
175
212
|
return new SuffixMatchToken();
|
|
176
213
|
} else {
|
|
177
214
|
return new DelimToken(code);
|
|
178
215
|
}
|
|
179
|
-
} else if (code ===
|
|
216
|
+
} else if (code === 39) {
|
|
180
217
|
return consumeAStringToken();
|
|
181
|
-
} else if (code ===
|
|
218
|
+
} else if (code === 40) {
|
|
182
219
|
return new OpenParenToken();
|
|
183
|
-
} else if (code ===
|
|
220
|
+
} else if (code === 41) {
|
|
184
221
|
return new CloseParenToken();
|
|
185
|
-
} else if (code ===
|
|
186
|
-
if (next() ===
|
|
222
|
+
} else if (code === 42) {
|
|
223
|
+
if (next() === 61) {
|
|
187
224
|
consume();
|
|
188
225
|
return new SubstringMatchToken();
|
|
189
226
|
} else {
|
|
190
227
|
return new DelimToken(code);
|
|
191
228
|
}
|
|
192
|
-
} else if (code ===
|
|
229
|
+
} else if (code === 43) {
|
|
193
230
|
if (startsWithANumber()) {
|
|
194
231
|
reconsume();
|
|
195
232
|
return consumeANumericToken();
|
|
196
233
|
} else {
|
|
197
234
|
return new DelimToken(code);
|
|
198
235
|
}
|
|
199
|
-
} else if (code ===
|
|
236
|
+
} else if (code === 44) {
|
|
200
237
|
return new CommaToken();
|
|
201
|
-
} else if (code ===
|
|
238
|
+
} else if (code === 45) {
|
|
202
239
|
if (startsWithANumber()) {
|
|
203
240
|
reconsume();
|
|
204
241
|
return consumeANumericToken();
|
|
205
|
-
} else if (next(1) ===
|
|
242
|
+
} else if (next(1) === 45 && next(2) === 62) {
|
|
206
243
|
consume(2);
|
|
207
244
|
return new CDCToken();
|
|
208
245
|
} else if (startsWithAnIdentifier()) {
|
|
@@ -211,29 +248,32 @@ function tokenize(str1) {
|
|
|
211
248
|
} else {
|
|
212
249
|
return new DelimToken(code);
|
|
213
250
|
}
|
|
214
|
-
} else if (code ===
|
|
251
|
+
} else if (code === 46) {
|
|
215
252
|
if (startsWithANumber()) {
|
|
216
253
|
reconsume();
|
|
217
254
|
return consumeANumericToken();
|
|
218
255
|
} else {
|
|
219
256
|
return new DelimToken(code);
|
|
220
257
|
}
|
|
221
|
-
} else if (code ===
|
|
258
|
+
} else if (code === 58) {
|
|
222
259
|
return new ColonToken();
|
|
223
|
-
} else if (code ===
|
|
260
|
+
} else if (code === 59) {
|
|
224
261
|
return new SemicolonToken();
|
|
225
|
-
} else if (code ===
|
|
226
|
-
if (next(1) ===
|
|
262
|
+
} else if (code === 60) {
|
|
263
|
+
if (next(1) === 33 && next(2) === 45 && next(3) === 45) {
|
|
227
264
|
consume(3);
|
|
228
265
|
return new CDOToken();
|
|
229
266
|
} else {
|
|
230
267
|
return new DelimToken(code);
|
|
231
268
|
}
|
|
232
|
-
} else if (code ===
|
|
233
|
-
if (wouldStartAnIdentifier(next(1), next(2), next(3)))
|
|
234
|
-
|
|
269
|
+
} else if (code === 64) {
|
|
270
|
+
if (wouldStartAnIdentifier(next(1), next(2), next(3)))
|
|
271
|
+
return new AtKeywordToken(consumeAName());
|
|
272
|
+
else
|
|
273
|
+
return new DelimToken(code);
|
|
274
|
+
} else if (code === 91) {
|
|
235
275
|
return new OpenSquareToken();
|
|
236
|
-
} else if (code ===
|
|
276
|
+
} else if (code === 92) {
|
|
237
277
|
if (startsWithAValidEscape()) {
|
|
238
278
|
reconsume();
|
|
239
279
|
return consumeAnIdentlikeToken();
|
|
@@ -241,31 +281,31 @@ function tokenize(str1) {
|
|
|
241
281
|
parseerror();
|
|
242
282
|
return new DelimToken(code);
|
|
243
283
|
}
|
|
244
|
-
} else if (code ===
|
|
284
|
+
} else if (code === 93) {
|
|
245
285
|
return new CloseSquareToken();
|
|
246
|
-
} else if (code ===
|
|
247
|
-
if (next() ===
|
|
286
|
+
} else if (code === 94) {
|
|
287
|
+
if (next() === 61) {
|
|
248
288
|
consume();
|
|
249
289
|
return new PrefixMatchToken();
|
|
250
290
|
} else {
|
|
251
291
|
return new DelimToken(code);
|
|
252
292
|
}
|
|
253
|
-
} else if (code ===
|
|
293
|
+
} else if (code === 123) {
|
|
254
294
|
return new OpenCurlyToken();
|
|
255
|
-
} else if (code ===
|
|
256
|
-
if (next() ===
|
|
295
|
+
} else if (code === 124) {
|
|
296
|
+
if (next() === 61) {
|
|
257
297
|
consume();
|
|
258
298
|
return new DashMatchToken();
|
|
259
|
-
} else if (next() ===
|
|
299
|
+
} else if (next() === 124) {
|
|
260
300
|
consume();
|
|
261
301
|
return new ColumnToken();
|
|
262
302
|
} else {
|
|
263
303
|
return new DelimToken(code);
|
|
264
304
|
}
|
|
265
|
-
} else if (code ===
|
|
305
|
+
} else if (code === 125) {
|
|
266
306
|
return new CloseCurlyToken();
|
|
267
|
-
} else if (code ===
|
|
268
|
-
if (next() ===
|
|
307
|
+
} else if (code === 126) {
|
|
308
|
+
if (next() === 61) {
|
|
269
309
|
consume();
|
|
270
310
|
return new IncludeMatchToken();
|
|
271
311
|
} else {
|
|
@@ -283,12 +323,12 @@ function tokenize(str1) {
|
|
|
283
323
|
return new DelimToken(code);
|
|
284
324
|
}
|
|
285
325
|
};
|
|
286
|
-
const consumeComments = function
|
|
287
|
-
while (next(1) ===
|
|
326
|
+
const consumeComments = function() {
|
|
327
|
+
while (next(1) === 47 && next(2) === 42) {
|
|
288
328
|
consume(2);
|
|
289
329
|
while (true) {
|
|
290
330
|
consume();
|
|
291
|
-
if (code ===
|
|
331
|
+
if (code === 42 && next() === 47) {
|
|
292
332
|
consume();
|
|
293
333
|
break;
|
|
294
334
|
} else if (eof()) {
|
|
@@ -298,7 +338,7 @@ function tokenize(str1) {
|
|
|
298
338
|
}
|
|
299
339
|
}
|
|
300
340
|
};
|
|
301
|
-
const consumeANumericToken = function
|
|
341
|
+
const consumeANumericToken = function() {
|
|
302
342
|
const num = consumeANumber();
|
|
303
343
|
if (wouldStartAnIdentifier(next(1), next(2), next(3))) {
|
|
304
344
|
const token = new DimensionToken();
|
|
@@ -307,7 +347,7 @@ function tokenize(str1) {
|
|
|
307
347
|
token.type = num.type;
|
|
308
348
|
token.unit = consumeAName();
|
|
309
349
|
return token;
|
|
310
|
-
} else if (next() ===
|
|
350
|
+
} else if (next() === 37) {
|
|
311
351
|
consume();
|
|
312
352
|
const token = new PercentageToken();
|
|
313
353
|
token.value = num.value;
|
|
@@ -321,22 +361,29 @@ function tokenize(str1) {
|
|
|
321
361
|
return token;
|
|
322
362
|
}
|
|
323
363
|
};
|
|
324
|
-
const consumeAnIdentlikeToken = function
|
|
325
|
-
const
|
|
326
|
-
if (
|
|
364
|
+
const consumeAnIdentlikeToken = function() {
|
|
365
|
+
const str2 = consumeAName();
|
|
366
|
+
if (str2.toLowerCase() === "url" && next() === 40) {
|
|
327
367
|
consume();
|
|
328
|
-
while (whitespace(next(1)) && whitespace(next(2)))
|
|
329
|
-
|
|
330
|
-
|
|
368
|
+
while (whitespace(next(1)) && whitespace(next(2)))
|
|
369
|
+
consume();
|
|
370
|
+
if (next() === 34 || next() === 39)
|
|
371
|
+
return new FunctionToken(str2);
|
|
372
|
+
else if (whitespace(next()) && (next(2) === 34 || next(2) === 39))
|
|
373
|
+
return new FunctionToken(str2);
|
|
374
|
+
else
|
|
375
|
+
return consumeAURLToken();
|
|
376
|
+
} else if (next() === 40) {
|
|
331
377
|
consume();
|
|
332
|
-
return new FunctionToken(
|
|
378
|
+
return new FunctionToken(str2);
|
|
333
379
|
} else {
|
|
334
|
-
return new IdentToken(
|
|
380
|
+
return new IdentToken(str2);
|
|
335
381
|
}
|
|
336
382
|
};
|
|
337
|
-
const consumeAStringToken = function
|
|
338
|
-
if (endingCodePoint ===
|
|
339
|
-
|
|
383
|
+
const consumeAStringToken = function(endingCodePoint) {
|
|
384
|
+
if (endingCodePoint === void 0)
|
|
385
|
+
endingCodePoint = code;
|
|
386
|
+
let string = "";
|
|
340
387
|
while (consume()) {
|
|
341
388
|
if (code === endingCodePoint || eof()) {
|
|
342
389
|
return new StringToken(string);
|
|
@@ -344,35 +391,43 @@ function tokenize(str1) {
|
|
|
344
391
|
parseerror();
|
|
345
392
|
reconsume();
|
|
346
393
|
return new BadStringToken();
|
|
347
|
-
} else if (code ===
|
|
348
|
-
if (eof(next()))
|
|
394
|
+
} else if (code === 92) {
|
|
395
|
+
if (eof(next()))
|
|
396
|
+
donothing();
|
|
397
|
+
else if (newline(next()))
|
|
398
|
+
consume();
|
|
399
|
+
else
|
|
400
|
+
string += stringFromCode(consumeEscape());
|
|
349
401
|
} else {
|
|
350
402
|
string += stringFromCode(code);
|
|
351
403
|
}
|
|
352
404
|
}
|
|
353
|
-
throw new Error(
|
|
405
|
+
throw new Error("Internal error");
|
|
354
406
|
};
|
|
355
|
-
const consumeAURLToken = function
|
|
356
|
-
const token = new URLToken(
|
|
357
|
-
while (whitespace(next()))
|
|
358
|
-
|
|
407
|
+
const consumeAURLToken = function() {
|
|
408
|
+
const token = new URLToken("");
|
|
409
|
+
while (whitespace(next()))
|
|
410
|
+
consume();
|
|
411
|
+
if (eof(next()))
|
|
412
|
+
return token;
|
|
359
413
|
while (consume()) {
|
|
360
|
-
if (code ===
|
|
414
|
+
if (code === 41 || eof()) {
|
|
361
415
|
return token;
|
|
362
416
|
} else if (whitespace(code)) {
|
|
363
|
-
while (whitespace(next()))
|
|
364
|
-
|
|
417
|
+
while (whitespace(next()))
|
|
418
|
+
consume();
|
|
419
|
+
if (next() === 41 || eof(next())) {
|
|
365
420
|
consume();
|
|
366
421
|
return token;
|
|
367
422
|
} else {
|
|
368
423
|
consumeTheRemnantsOfABadURL();
|
|
369
424
|
return new BadURLToken();
|
|
370
425
|
}
|
|
371
|
-
} else if (code ===
|
|
426
|
+
} else if (code === 34 || code === 39 || code === 40 || nonprintable(code)) {
|
|
372
427
|
parseerror();
|
|
373
428
|
consumeTheRemnantsOfABadURL();
|
|
374
429
|
return new BadURLToken();
|
|
375
|
-
} else if (code ===
|
|
430
|
+
} else if (code === 92) {
|
|
376
431
|
if (startsWithAValidEscape()) {
|
|
377
432
|
token.value += stringFromCode(consumeEscape());
|
|
378
433
|
} else {
|
|
@@ -384,14 +439,11 @@ function tokenize(str1) {
|
|
|
384
439
|
token.value += stringFromCode(code);
|
|
385
440
|
}
|
|
386
441
|
}
|
|
387
|
-
throw new Error(
|
|
442
|
+
throw new Error("Internal error");
|
|
388
443
|
};
|
|
389
|
-
const consumeEscape = function
|
|
390
|
-
// Assume the current character is the \
|
|
391
|
-
// and the next code point is not a newline.
|
|
444
|
+
const consumeEscape = function() {
|
|
392
445
|
consume();
|
|
393
446
|
if (hexdigit(code)) {
|
|
394
|
-
// Consume 1-6 hex digits
|
|
395
447
|
const digits = [code];
|
|
396
448
|
for (let total = 0; total < 5; total++) {
|
|
397
449
|
if (hexdigit(next())) {
|
|
@@ -401,39 +453,53 @@ function tokenize(str1) {
|
|
|
401
453
|
break;
|
|
402
454
|
}
|
|
403
455
|
}
|
|
404
|
-
if (whitespace(next()))
|
|
405
|
-
|
|
456
|
+
if (whitespace(next()))
|
|
457
|
+
consume();
|
|
458
|
+
let value = parseInt(digits.map(function(x) {
|
|
406
459
|
return String.fromCharCode(x);
|
|
407
|
-
}).join(
|
|
408
|
-
if (value > maximumallowedcodepoint)
|
|
460
|
+
}).join(""), 16);
|
|
461
|
+
if (value > maximumallowedcodepoint)
|
|
462
|
+
value = 65533;
|
|
409
463
|
return value;
|
|
410
464
|
} else if (eof()) {
|
|
411
|
-
return
|
|
465
|
+
return 65533;
|
|
412
466
|
} else {
|
|
413
467
|
return code;
|
|
414
468
|
}
|
|
415
469
|
};
|
|
416
|
-
const areAValidEscape = function
|
|
417
|
-
if (c1 !==
|
|
418
|
-
|
|
470
|
+
const areAValidEscape = function(c1, c2) {
|
|
471
|
+
if (c1 !== 92)
|
|
472
|
+
return false;
|
|
473
|
+
if (newline(c2))
|
|
474
|
+
return false;
|
|
419
475
|
return true;
|
|
420
476
|
};
|
|
421
|
-
const startsWithAValidEscape = function
|
|
477
|
+
const startsWithAValidEscape = function() {
|
|
422
478
|
return areAValidEscape(code, next());
|
|
423
479
|
};
|
|
424
|
-
const wouldStartAnIdentifier = function
|
|
425
|
-
if (c1 ===
|
|
480
|
+
const wouldStartAnIdentifier = function(c1, c2, c3) {
|
|
481
|
+
if (c1 === 45)
|
|
482
|
+
return namestartchar(c2) || c2 === 45 || areAValidEscape(c2, c3);
|
|
483
|
+
else if (namestartchar(c1))
|
|
484
|
+
return true;
|
|
485
|
+
else if (c1 === 92)
|
|
486
|
+
return areAValidEscape(c1, c2);
|
|
487
|
+
else
|
|
488
|
+
return false;
|
|
426
489
|
};
|
|
427
|
-
const startsWithAnIdentifier = function
|
|
490
|
+
const startsWithAnIdentifier = function() {
|
|
428
491
|
return wouldStartAnIdentifier(code, next(1), next(2));
|
|
429
492
|
};
|
|
430
|
-
const wouldStartANumber = function
|
|
431
|
-
if (c1 ===
|
|
432
|
-
if (digit(c2))
|
|
433
|
-
|
|
493
|
+
const wouldStartANumber = function(c1, c2, c3) {
|
|
494
|
+
if (c1 === 43 || c1 === 45) {
|
|
495
|
+
if (digit(c2))
|
|
496
|
+
return true;
|
|
497
|
+
if (c2 === 46 && digit(c3))
|
|
498
|
+
return true;
|
|
434
499
|
return false;
|
|
435
|
-
} else if (c1 ===
|
|
436
|
-
if (digit(c2))
|
|
500
|
+
} else if (c1 === 46) {
|
|
501
|
+
if (digit(c2))
|
|
502
|
+
return true;
|
|
437
503
|
return false;
|
|
438
504
|
} else if (digit(c1)) {
|
|
439
505
|
return true;
|
|
@@ -441,11 +507,11 @@ function tokenize(str1) {
|
|
|
441
507
|
return false;
|
|
442
508
|
}
|
|
443
509
|
};
|
|
444
|
-
const startsWithANumber = function
|
|
510
|
+
const startsWithANumber = function() {
|
|
445
511
|
return wouldStartANumber(code, next(1), next(2));
|
|
446
512
|
};
|
|
447
|
-
const consumeAName = function
|
|
448
|
-
let result =
|
|
513
|
+
const consumeAName = function() {
|
|
514
|
+
let result = "";
|
|
449
515
|
while (consume()) {
|
|
450
516
|
if (namechar(code)) {
|
|
451
517
|
result += stringFromCode(code);
|
|
@@ -456,12 +522,12 @@ function tokenize(str1) {
|
|
|
456
522
|
return result;
|
|
457
523
|
}
|
|
458
524
|
}
|
|
459
|
-
throw new Error(
|
|
525
|
+
throw new Error("Internal parse error");
|
|
460
526
|
};
|
|
461
|
-
const consumeANumber = function
|
|
462
|
-
let repr =
|
|
463
|
-
let type =
|
|
464
|
-
if (next() ===
|
|
527
|
+
const consumeANumber = function() {
|
|
528
|
+
let repr = "";
|
|
529
|
+
let type = "integer";
|
|
530
|
+
if (next() === 43 || next() === 45) {
|
|
465
531
|
consume();
|
|
466
532
|
repr += stringFromCode(code);
|
|
467
533
|
}
|
|
@@ -469,57 +535,50 @@ function tokenize(str1) {
|
|
|
469
535
|
consume();
|
|
470
536
|
repr += stringFromCode(code);
|
|
471
537
|
}
|
|
472
|
-
if (next(1) ===
|
|
538
|
+
if (next(1) === 46 && digit(next(2))) {
|
|
473
539
|
consume();
|
|
474
540
|
repr += stringFromCode(code);
|
|
475
541
|
consume();
|
|
476
542
|
repr += stringFromCode(code);
|
|
477
|
-
type =
|
|
543
|
+
type = "number";
|
|
478
544
|
while (digit(next())) {
|
|
479
545
|
consume();
|
|
480
546
|
repr += stringFromCode(code);
|
|
481
547
|
}
|
|
482
548
|
}
|
|
483
|
-
const c1 = next(1),
|
|
484
|
-
|
|
485
|
-
c3 = next(3);
|
|
486
|
-
if ((c1 === 0x45 || c1 === 0x65) && digit(c2)) {
|
|
549
|
+
const c1 = next(1), c2 = next(2), c3 = next(3);
|
|
550
|
+
if ((c1 === 69 || c1 === 101) && digit(c2)) {
|
|
487
551
|
consume();
|
|
488
552
|
repr += stringFromCode(code);
|
|
489
553
|
consume();
|
|
490
554
|
repr += stringFromCode(code);
|
|
491
|
-
type =
|
|
555
|
+
type = "number";
|
|
492
556
|
while (digit(next())) {
|
|
493
557
|
consume();
|
|
494
558
|
repr += stringFromCode(code);
|
|
495
559
|
}
|
|
496
|
-
} else if ((c1 ===
|
|
560
|
+
} else if ((c1 === 69 || c1 === 101) && (c2 === 43 || c2 === 45) && digit(c3)) {
|
|
497
561
|
consume();
|
|
498
562
|
repr += stringFromCode(code);
|
|
499
563
|
consume();
|
|
500
564
|
repr += stringFromCode(code);
|
|
501
565
|
consume();
|
|
502
566
|
repr += stringFromCode(code);
|
|
503
|
-
type =
|
|
567
|
+
type = "number";
|
|
504
568
|
while (digit(next())) {
|
|
505
569
|
consume();
|
|
506
570
|
repr += stringFromCode(code);
|
|
507
571
|
}
|
|
508
572
|
}
|
|
509
573
|
const value = convertAStringToANumber(repr);
|
|
510
|
-
return {
|
|
511
|
-
type: type,
|
|
512
|
-
value: value,
|
|
513
|
-
repr: repr
|
|
514
|
-
};
|
|
574
|
+
return { type, value, repr };
|
|
515
575
|
};
|
|
516
|
-
const convertAStringToANumber = function
|
|
517
|
-
// CSS's number rules are identical to JS, afaik.
|
|
576
|
+
const convertAStringToANumber = function(string) {
|
|
518
577
|
return +string;
|
|
519
578
|
};
|
|
520
|
-
const consumeTheRemnantsOfABadURL = function
|
|
579
|
+
const consumeTheRemnantsOfABadURL = function() {
|
|
521
580
|
while (consume()) {
|
|
522
|
-
if (code ===
|
|
581
|
+
if (code === 41 || eof()) {
|
|
523
582
|
return;
|
|
524
583
|
} else if (startsWithAValidEscape()) {
|
|
525
584
|
consumeEscape();
|
|
@@ -533,219 +592,194 @@ function tokenize(str1) {
|
|
|
533
592
|
while (!eof(next())) {
|
|
534
593
|
tokens.push(consumeAToken());
|
|
535
594
|
iterationCount++;
|
|
536
|
-
if (iterationCount > str.length * 2)
|
|
595
|
+
if (iterationCount > str.length * 2)
|
|
596
|
+
throw new Error("I'm infinite-looping!");
|
|
537
597
|
}
|
|
538
598
|
return tokens;
|
|
539
599
|
}
|
|
540
600
|
class CSSParserToken {
|
|
541
601
|
constructor() {
|
|
542
|
-
this.tokenType =
|
|
543
|
-
this.value = void 0;
|
|
602
|
+
this.tokenType = "";
|
|
544
603
|
}
|
|
545
604
|
toJSON() {
|
|
546
|
-
return {
|
|
547
|
-
token: this.tokenType
|
|
548
|
-
};
|
|
605
|
+
return { token: this.tokenType };
|
|
549
606
|
}
|
|
550
607
|
toString() {
|
|
551
608
|
return this.tokenType;
|
|
552
609
|
}
|
|
553
610
|
toSource() {
|
|
554
|
-
return
|
|
611
|
+
return "" + this;
|
|
555
612
|
}
|
|
556
613
|
}
|
|
557
|
-
exports.CSSParserToken = CSSParserToken;
|
|
558
614
|
class BadStringToken extends CSSParserToken {
|
|
559
|
-
constructor(
|
|
560
|
-
super(...
|
|
561
|
-
this.tokenType =
|
|
615
|
+
constructor() {
|
|
616
|
+
super(...arguments);
|
|
617
|
+
this.tokenType = "BADSTRING";
|
|
562
618
|
}
|
|
563
619
|
}
|
|
564
|
-
exports.BadStringToken = BadStringToken;
|
|
565
620
|
class BadURLToken extends CSSParserToken {
|
|
566
|
-
constructor(
|
|
567
|
-
super(...
|
|
568
|
-
this.tokenType =
|
|
621
|
+
constructor() {
|
|
622
|
+
super(...arguments);
|
|
623
|
+
this.tokenType = "BADURL";
|
|
569
624
|
}
|
|
570
625
|
}
|
|
571
|
-
exports.BadURLToken = BadURLToken;
|
|
572
626
|
class WhitespaceToken extends CSSParserToken {
|
|
573
|
-
constructor(
|
|
574
|
-
super(...
|
|
575
|
-
this.tokenType =
|
|
627
|
+
constructor() {
|
|
628
|
+
super(...arguments);
|
|
629
|
+
this.tokenType = "WHITESPACE";
|
|
576
630
|
}
|
|
577
631
|
toString() {
|
|
578
|
-
return
|
|
632
|
+
return "WS";
|
|
579
633
|
}
|
|
580
634
|
toSource() {
|
|
581
|
-
return
|
|
635
|
+
return " ";
|
|
582
636
|
}
|
|
583
637
|
}
|
|
584
|
-
exports.WhitespaceToken = WhitespaceToken;
|
|
585
638
|
class CDOToken extends CSSParserToken {
|
|
586
|
-
constructor(
|
|
587
|
-
super(...
|
|
588
|
-
this.tokenType =
|
|
639
|
+
constructor() {
|
|
640
|
+
super(...arguments);
|
|
641
|
+
this.tokenType = "CDO";
|
|
589
642
|
}
|
|
590
643
|
toSource() {
|
|
591
|
-
return
|
|
644
|
+
return "<!--";
|
|
592
645
|
}
|
|
593
646
|
}
|
|
594
|
-
exports.CDOToken = CDOToken;
|
|
595
647
|
class CDCToken extends CSSParserToken {
|
|
596
|
-
constructor(
|
|
597
|
-
super(...
|
|
598
|
-
this.tokenType =
|
|
648
|
+
constructor() {
|
|
649
|
+
super(...arguments);
|
|
650
|
+
this.tokenType = "CDC";
|
|
599
651
|
}
|
|
600
652
|
toSource() {
|
|
601
|
-
return
|
|
653
|
+
return "-->";
|
|
602
654
|
}
|
|
603
655
|
}
|
|
604
|
-
exports.CDCToken = CDCToken;
|
|
605
656
|
class ColonToken extends CSSParserToken {
|
|
606
|
-
constructor(
|
|
607
|
-
super(...
|
|
608
|
-
this.tokenType =
|
|
657
|
+
constructor() {
|
|
658
|
+
super(...arguments);
|
|
659
|
+
this.tokenType = ":";
|
|
609
660
|
}
|
|
610
661
|
}
|
|
611
|
-
exports.ColonToken = ColonToken;
|
|
612
662
|
class SemicolonToken extends CSSParserToken {
|
|
613
|
-
constructor(
|
|
614
|
-
super(...
|
|
615
|
-
this.tokenType =
|
|
663
|
+
constructor() {
|
|
664
|
+
super(...arguments);
|
|
665
|
+
this.tokenType = ";";
|
|
616
666
|
}
|
|
617
667
|
}
|
|
618
|
-
exports.SemicolonToken = SemicolonToken;
|
|
619
668
|
class CommaToken extends CSSParserToken {
|
|
620
|
-
constructor(
|
|
621
|
-
super(...
|
|
622
|
-
this.tokenType =
|
|
669
|
+
constructor() {
|
|
670
|
+
super(...arguments);
|
|
671
|
+
this.tokenType = ",";
|
|
623
672
|
}
|
|
624
673
|
}
|
|
625
|
-
exports.CommaToken = CommaToken;
|
|
626
674
|
class GroupingToken extends CSSParserToken {
|
|
627
|
-
constructor(
|
|
628
|
-
super(...
|
|
629
|
-
this.value =
|
|
630
|
-
this.mirror =
|
|
675
|
+
constructor() {
|
|
676
|
+
super(...arguments);
|
|
677
|
+
this.value = "";
|
|
678
|
+
this.mirror = "";
|
|
631
679
|
}
|
|
632
680
|
}
|
|
633
|
-
exports.GroupingToken = GroupingToken;
|
|
634
681
|
class OpenCurlyToken extends GroupingToken {
|
|
635
682
|
constructor() {
|
|
636
683
|
super();
|
|
637
|
-
this.tokenType =
|
|
638
|
-
this.value =
|
|
639
|
-
this.mirror =
|
|
684
|
+
this.tokenType = "{";
|
|
685
|
+
this.value = "{";
|
|
686
|
+
this.mirror = "}";
|
|
640
687
|
}
|
|
641
688
|
}
|
|
642
|
-
exports.OpenCurlyToken = OpenCurlyToken;
|
|
643
689
|
class CloseCurlyToken extends GroupingToken {
|
|
644
690
|
constructor() {
|
|
645
691
|
super();
|
|
646
|
-
this.tokenType =
|
|
647
|
-
this.value =
|
|
648
|
-
this.mirror =
|
|
692
|
+
this.tokenType = "}";
|
|
693
|
+
this.value = "}";
|
|
694
|
+
this.mirror = "{";
|
|
649
695
|
}
|
|
650
696
|
}
|
|
651
|
-
exports.CloseCurlyToken = CloseCurlyToken;
|
|
652
697
|
class OpenSquareToken extends GroupingToken {
|
|
653
698
|
constructor() {
|
|
654
699
|
super();
|
|
655
|
-
this.tokenType =
|
|
656
|
-
this.value =
|
|
657
|
-
this.mirror =
|
|
700
|
+
this.tokenType = "[";
|
|
701
|
+
this.value = "[";
|
|
702
|
+
this.mirror = "]";
|
|
658
703
|
}
|
|
659
704
|
}
|
|
660
|
-
exports.OpenSquareToken = OpenSquareToken;
|
|
661
705
|
class CloseSquareToken extends GroupingToken {
|
|
662
706
|
constructor() {
|
|
663
707
|
super();
|
|
664
|
-
this.tokenType =
|
|
665
|
-
this.value =
|
|
666
|
-
this.mirror =
|
|
708
|
+
this.tokenType = "]";
|
|
709
|
+
this.value = "]";
|
|
710
|
+
this.mirror = "[";
|
|
667
711
|
}
|
|
668
712
|
}
|
|
669
|
-
exports.CloseSquareToken = CloseSquareToken;
|
|
670
713
|
class OpenParenToken extends GroupingToken {
|
|
671
714
|
constructor() {
|
|
672
715
|
super();
|
|
673
|
-
this.tokenType =
|
|
674
|
-
this.value =
|
|
675
|
-
this.mirror =
|
|
716
|
+
this.tokenType = "(";
|
|
717
|
+
this.value = "(";
|
|
718
|
+
this.mirror = ")";
|
|
676
719
|
}
|
|
677
720
|
}
|
|
678
|
-
exports.OpenParenToken = OpenParenToken;
|
|
679
721
|
class CloseParenToken extends GroupingToken {
|
|
680
722
|
constructor() {
|
|
681
723
|
super();
|
|
682
|
-
this.tokenType =
|
|
683
|
-
this.value =
|
|
684
|
-
this.mirror =
|
|
724
|
+
this.tokenType = ")";
|
|
725
|
+
this.value = ")";
|
|
726
|
+
this.mirror = "(";
|
|
685
727
|
}
|
|
686
728
|
}
|
|
687
|
-
exports.CloseParenToken = CloseParenToken;
|
|
688
729
|
class IncludeMatchToken extends CSSParserToken {
|
|
689
|
-
constructor(
|
|
690
|
-
super(...
|
|
691
|
-
this.tokenType =
|
|
730
|
+
constructor() {
|
|
731
|
+
super(...arguments);
|
|
732
|
+
this.tokenType = "~=";
|
|
692
733
|
}
|
|
693
734
|
}
|
|
694
|
-
exports.IncludeMatchToken = IncludeMatchToken;
|
|
695
735
|
class DashMatchToken extends CSSParserToken {
|
|
696
|
-
constructor(
|
|
697
|
-
super(...
|
|
698
|
-
this.tokenType =
|
|
736
|
+
constructor() {
|
|
737
|
+
super(...arguments);
|
|
738
|
+
this.tokenType = "|=";
|
|
699
739
|
}
|
|
700
740
|
}
|
|
701
|
-
exports.DashMatchToken = DashMatchToken;
|
|
702
741
|
class PrefixMatchToken extends CSSParserToken {
|
|
703
|
-
constructor(
|
|
704
|
-
super(...
|
|
705
|
-
this.tokenType =
|
|
742
|
+
constructor() {
|
|
743
|
+
super(...arguments);
|
|
744
|
+
this.tokenType = "^=";
|
|
706
745
|
}
|
|
707
746
|
}
|
|
708
|
-
exports.PrefixMatchToken = PrefixMatchToken;
|
|
709
747
|
class SuffixMatchToken extends CSSParserToken {
|
|
710
|
-
constructor(
|
|
711
|
-
super(...
|
|
712
|
-
this.tokenType =
|
|
748
|
+
constructor() {
|
|
749
|
+
super(...arguments);
|
|
750
|
+
this.tokenType = "$=";
|
|
713
751
|
}
|
|
714
752
|
}
|
|
715
|
-
exports.SuffixMatchToken = SuffixMatchToken;
|
|
716
753
|
class SubstringMatchToken extends CSSParserToken {
|
|
717
|
-
constructor(
|
|
718
|
-
super(...
|
|
719
|
-
this.tokenType =
|
|
754
|
+
constructor() {
|
|
755
|
+
super(...arguments);
|
|
756
|
+
this.tokenType = "*=";
|
|
720
757
|
}
|
|
721
758
|
}
|
|
722
|
-
exports.SubstringMatchToken = SubstringMatchToken;
|
|
723
759
|
class ColumnToken extends CSSParserToken {
|
|
724
|
-
constructor(
|
|
725
|
-
super(...
|
|
726
|
-
this.tokenType =
|
|
760
|
+
constructor() {
|
|
761
|
+
super(...arguments);
|
|
762
|
+
this.tokenType = "||";
|
|
727
763
|
}
|
|
728
764
|
}
|
|
729
|
-
exports.ColumnToken = ColumnToken;
|
|
730
765
|
class EOFToken extends CSSParserToken {
|
|
731
|
-
constructor(
|
|
732
|
-
super(...
|
|
733
|
-
this.tokenType =
|
|
766
|
+
constructor() {
|
|
767
|
+
super(...arguments);
|
|
768
|
+
this.tokenType = "EOF";
|
|
734
769
|
}
|
|
735
770
|
toSource() {
|
|
736
|
-
return
|
|
771
|
+
return "";
|
|
737
772
|
}
|
|
738
773
|
}
|
|
739
|
-
exports.EOFToken = EOFToken;
|
|
740
774
|
class DelimToken extends CSSParserToken {
|
|
741
775
|
constructor(code) {
|
|
742
776
|
super();
|
|
743
|
-
this.tokenType =
|
|
744
|
-
this.value =
|
|
777
|
+
this.tokenType = "DELIM";
|
|
778
|
+
this.value = "";
|
|
745
779
|
this.value = stringFromCode(code);
|
|
746
780
|
}
|
|
747
781
|
toString() {
|
|
748
|
-
return
|
|
782
|
+
return "DELIM(" + this.value + ")";
|
|
749
783
|
}
|
|
750
784
|
toJSON() {
|
|
751
785
|
const json = this.constructor.prototype.constructor.prototype.toJSON.call(this);
|
|
@@ -753,14 +787,16 @@ class DelimToken extends CSSParserToken {
|
|
|
753
787
|
return json;
|
|
754
788
|
}
|
|
755
789
|
toSource() {
|
|
756
|
-
if (this.value ===
|
|
790
|
+
if (this.value === "\\")
|
|
791
|
+
return "\\\n";
|
|
792
|
+
else
|
|
793
|
+
return this.value;
|
|
757
794
|
}
|
|
758
795
|
}
|
|
759
|
-
exports.DelimToken = DelimToken;
|
|
760
796
|
class StringValuedToken extends CSSParserToken {
|
|
761
|
-
constructor(
|
|
762
|
-
super(...
|
|
763
|
-
this.value =
|
|
797
|
+
constructor() {
|
|
798
|
+
super(...arguments);
|
|
799
|
+
this.value = "";
|
|
764
800
|
}
|
|
765
801
|
ASCIIMatch(str) {
|
|
766
802
|
return this.value.toLowerCase() === str.toLowerCase();
|
|
@@ -771,61 +807,55 @@ class StringValuedToken extends CSSParserToken {
|
|
|
771
807
|
return json;
|
|
772
808
|
}
|
|
773
809
|
}
|
|
774
|
-
exports.StringValuedToken = StringValuedToken;
|
|
775
810
|
class IdentToken extends StringValuedToken {
|
|
776
811
|
constructor(val) {
|
|
777
812
|
super();
|
|
778
|
-
this.tokenType =
|
|
813
|
+
this.tokenType = "IDENT";
|
|
779
814
|
this.value = val;
|
|
780
815
|
}
|
|
781
816
|
toString() {
|
|
782
|
-
return
|
|
817
|
+
return "IDENT(" + this.value + ")";
|
|
783
818
|
}
|
|
784
819
|
toSource() {
|
|
785
820
|
return escapeIdent(this.value);
|
|
786
821
|
}
|
|
787
822
|
}
|
|
788
|
-
exports.IdentToken = IdentToken;
|
|
789
823
|
class FunctionToken extends StringValuedToken {
|
|
790
824
|
constructor(val) {
|
|
791
825
|
super();
|
|
792
|
-
this.tokenType =
|
|
793
|
-
this.mirror = void 0;
|
|
826
|
+
this.tokenType = "FUNCTION";
|
|
794
827
|
this.value = val;
|
|
795
|
-
this.mirror =
|
|
828
|
+
this.mirror = ")";
|
|
796
829
|
}
|
|
797
830
|
toString() {
|
|
798
|
-
return
|
|
831
|
+
return "FUNCTION(" + this.value + ")";
|
|
799
832
|
}
|
|
800
833
|
toSource() {
|
|
801
|
-
return escapeIdent(this.value) +
|
|
834
|
+
return escapeIdent(this.value) + "(";
|
|
802
835
|
}
|
|
803
836
|
}
|
|
804
|
-
exports.FunctionToken = FunctionToken;
|
|
805
837
|
class AtKeywordToken extends StringValuedToken {
|
|
806
838
|
constructor(val) {
|
|
807
839
|
super();
|
|
808
|
-
this.tokenType =
|
|
840
|
+
this.tokenType = "AT-KEYWORD";
|
|
809
841
|
this.value = val;
|
|
810
842
|
}
|
|
811
843
|
toString() {
|
|
812
|
-
return
|
|
844
|
+
return "AT(" + this.value + ")";
|
|
813
845
|
}
|
|
814
846
|
toSource() {
|
|
815
|
-
return
|
|
847
|
+
return "@" + escapeIdent(this.value);
|
|
816
848
|
}
|
|
817
849
|
}
|
|
818
|
-
exports.AtKeywordToken = AtKeywordToken;
|
|
819
850
|
class HashToken extends StringValuedToken {
|
|
820
851
|
constructor(val) {
|
|
821
852
|
super();
|
|
822
|
-
this.tokenType =
|
|
823
|
-
this.type = void 0;
|
|
853
|
+
this.tokenType = "HASH";
|
|
824
854
|
this.value = val;
|
|
825
|
-
this.type =
|
|
855
|
+
this.type = "unrestricted";
|
|
826
856
|
}
|
|
827
857
|
toString() {
|
|
828
|
-
return
|
|
858
|
+
return "HASH(" + this.value + ")";
|
|
829
859
|
}
|
|
830
860
|
toJSON() {
|
|
831
861
|
const json = this.constructor.prototype.constructor.prototype.toJSON.call(this);
|
|
@@ -834,47 +864,46 @@ class HashToken extends StringValuedToken {
|
|
|
834
864
|
return json;
|
|
835
865
|
}
|
|
836
866
|
toSource() {
|
|
837
|
-
if (this.type ===
|
|
867
|
+
if (this.type === "id")
|
|
868
|
+
return "#" + escapeIdent(this.value);
|
|
869
|
+
else
|
|
870
|
+
return "#" + escapeHash(this.value);
|
|
838
871
|
}
|
|
839
872
|
}
|
|
840
|
-
exports.HashToken = HashToken;
|
|
841
873
|
class StringToken extends StringValuedToken {
|
|
842
874
|
constructor(val) {
|
|
843
875
|
super();
|
|
844
|
-
this.tokenType =
|
|
876
|
+
this.tokenType = "STRING";
|
|
845
877
|
this.value = val;
|
|
846
878
|
}
|
|
847
879
|
toString() {
|
|
848
880
|
return '"' + escapeString(this.value) + '"';
|
|
849
881
|
}
|
|
850
882
|
}
|
|
851
|
-
exports.StringToken = StringToken;
|
|
852
883
|
class URLToken extends StringValuedToken {
|
|
853
884
|
constructor(val) {
|
|
854
885
|
super();
|
|
855
|
-
this.tokenType =
|
|
886
|
+
this.tokenType = "URL";
|
|
856
887
|
this.value = val;
|
|
857
888
|
}
|
|
858
889
|
toString() {
|
|
859
|
-
return
|
|
890
|
+
return "URL(" + this.value + ")";
|
|
860
891
|
}
|
|
861
892
|
toSource() {
|
|
862
893
|
return 'url("' + escapeString(this.value) + '")';
|
|
863
894
|
}
|
|
864
895
|
}
|
|
865
|
-
exports.URLToken = URLToken;
|
|
866
896
|
class NumberToken extends CSSParserToken {
|
|
867
897
|
constructor() {
|
|
868
898
|
super();
|
|
869
|
-
this.tokenType =
|
|
870
|
-
this.type =
|
|
871
|
-
this.repr =
|
|
872
|
-
this.type = 'integer';
|
|
873
|
-
this.repr = '';
|
|
899
|
+
this.tokenType = "NUMBER";
|
|
900
|
+
this.type = "integer";
|
|
901
|
+
this.repr = "";
|
|
874
902
|
}
|
|
875
903
|
toString() {
|
|
876
|
-
if (this.type ===
|
|
877
|
-
|
|
904
|
+
if (this.type === "integer")
|
|
905
|
+
return "INT(" + this.value + ")";
|
|
906
|
+
return "NUMBER(" + this.value + ")";
|
|
878
907
|
}
|
|
879
908
|
toJSON() {
|
|
880
909
|
const json = super.toJSON();
|
|
@@ -887,16 +916,14 @@ class NumberToken extends CSSParserToken {
|
|
|
887
916
|
return this.repr;
|
|
888
917
|
}
|
|
889
918
|
}
|
|
890
|
-
exports.NumberToken = NumberToken;
|
|
891
919
|
class PercentageToken extends CSSParserToken {
|
|
892
920
|
constructor() {
|
|
893
921
|
super();
|
|
894
|
-
this.tokenType =
|
|
895
|
-
this.repr =
|
|
896
|
-
this.repr = '';
|
|
922
|
+
this.tokenType = "PERCENTAGE";
|
|
923
|
+
this.repr = "";
|
|
897
924
|
}
|
|
898
925
|
toString() {
|
|
899
|
-
return
|
|
926
|
+
return "PERCENTAGE(" + this.value + ")";
|
|
900
927
|
}
|
|
901
928
|
toJSON() {
|
|
902
929
|
const json = this.constructor.prototype.constructor.prototype.toJSON.call(this);
|
|
@@ -905,23 +932,19 @@ class PercentageToken extends CSSParserToken {
|
|
|
905
932
|
return json;
|
|
906
933
|
}
|
|
907
934
|
toSource() {
|
|
908
|
-
return this.repr +
|
|
935
|
+
return this.repr + "%";
|
|
909
936
|
}
|
|
910
937
|
}
|
|
911
|
-
exports.PercentageToken = PercentageToken;
|
|
912
938
|
class DimensionToken extends CSSParserToken {
|
|
913
939
|
constructor() {
|
|
914
940
|
super();
|
|
915
|
-
this.tokenType =
|
|
916
|
-
this.type =
|
|
917
|
-
this.repr =
|
|
918
|
-
this.unit =
|
|
919
|
-
this.type = 'integer';
|
|
920
|
-
this.repr = '';
|
|
921
|
-
this.unit = '';
|
|
941
|
+
this.tokenType = "DIMENSION";
|
|
942
|
+
this.type = "integer";
|
|
943
|
+
this.repr = "";
|
|
944
|
+
this.unit = "";
|
|
922
945
|
}
|
|
923
946
|
toString() {
|
|
924
|
-
return
|
|
947
|
+
return "DIM(" + this.value + "," + this.unit + ")";
|
|
925
948
|
}
|
|
926
949
|
toJSON() {
|
|
927
950
|
const json = this.constructor.prototype.constructor.prototype.toJSON.call(this);
|
|
@@ -934,46 +957,95 @@ class DimensionToken extends CSSParserToken {
|
|
|
934
957
|
toSource() {
|
|
935
958
|
const source = this.repr;
|
|
936
959
|
let unit = escapeIdent(this.unit);
|
|
937
|
-
if (unit[0].toLowerCase() ===
|
|
938
|
-
|
|
939
|
-
// Remove the leading "e", replace with escape.
|
|
940
|
-
unit = '\\65 ' + unit.slice(1, unit.length);
|
|
960
|
+
if (unit[0].toLowerCase() === "e" && (unit[1] === "-" || between(unit.charCodeAt(1), 48, 57))) {
|
|
961
|
+
unit = "\\65 " + unit.slice(1, unit.length);
|
|
941
962
|
}
|
|
942
963
|
return source + unit;
|
|
943
964
|
}
|
|
944
965
|
}
|
|
945
|
-
exports.DimensionToken = DimensionToken;
|
|
946
966
|
function escapeIdent(string) {
|
|
947
|
-
string =
|
|
948
|
-
let result =
|
|
967
|
+
string = "" + string;
|
|
968
|
+
let result = "";
|
|
949
969
|
const firstcode = string.charCodeAt(0);
|
|
950
970
|
for (let i = 0; i < string.length; i++) {
|
|
951
971
|
const code = string.charCodeAt(i);
|
|
952
|
-
if (code ===
|
|
953
|
-
|
|
972
|
+
if (code === 0)
|
|
973
|
+
throw new InvalidCharacterError("Invalid character: the input contains U+0000.");
|
|
974
|
+
if (between(code, 1, 31) || code === 127 || i === 0 && between(code, 48, 57) || i === 1 && between(code, 48, 57) && firstcode === 45)
|
|
975
|
+
result += "\\" + code.toString(16) + " ";
|
|
976
|
+
else if (code >= 128 || code === 45 || code === 95 || between(code, 48, 57) || between(code, 65, 90) || between(code, 97, 122))
|
|
977
|
+
result += string[i];
|
|
978
|
+
else
|
|
979
|
+
result += "\\" + string[i];
|
|
954
980
|
}
|
|
955
981
|
return result;
|
|
956
982
|
}
|
|
957
983
|
function escapeHash(string) {
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
// use escapeIdent() for that.
|
|
961
|
-
string = '' + string;
|
|
962
|
-
let result = '';
|
|
984
|
+
string = "" + string;
|
|
985
|
+
let result = "";
|
|
963
986
|
for (let i = 0; i < string.length; i++) {
|
|
964
987
|
const code = string.charCodeAt(i);
|
|
965
|
-
if (code ===
|
|
966
|
-
|
|
988
|
+
if (code === 0)
|
|
989
|
+
throw new InvalidCharacterError("Invalid character: the input contains U+0000.");
|
|
990
|
+
if (code >= 128 || code === 45 || code === 95 || between(code, 48, 57) || between(code, 65, 90) || between(code, 97, 122))
|
|
991
|
+
result += string[i];
|
|
992
|
+
else
|
|
993
|
+
result += "\\" + code.toString(16) + " ";
|
|
967
994
|
}
|
|
968
995
|
return result;
|
|
969
996
|
}
|
|
970
997
|
function escapeString(string) {
|
|
971
|
-
string =
|
|
972
|
-
let result =
|
|
998
|
+
string = "" + string;
|
|
999
|
+
let result = "";
|
|
973
1000
|
for (let i = 0; i < string.length; i++) {
|
|
974
1001
|
const code = string.charCodeAt(i);
|
|
975
|
-
if (code ===
|
|
976
|
-
|
|
1002
|
+
if (code === 0)
|
|
1003
|
+
throw new InvalidCharacterError("Invalid character: the input contains U+0000.");
|
|
1004
|
+
if (between(code, 1, 31) || code === 127)
|
|
1005
|
+
result += "\\" + code.toString(16) + " ";
|
|
1006
|
+
else if (code === 34 || code === 92)
|
|
1007
|
+
result += "\\" + string[i];
|
|
1008
|
+
else
|
|
1009
|
+
result += string[i];
|
|
977
1010
|
}
|
|
978
1011
|
return result;
|
|
979
|
-
}
|
|
1012
|
+
}
|
|
1013
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1014
|
+
0 && (module.exports = {
|
|
1015
|
+
AtKeywordToken,
|
|
1016
|
+
BadStringToken,
|
|
1017
|
+
BadURLToken,
|
|
1018
|
+
CDCToken,
|
|
1019
|
+
CDOToken,
|
|
1020
|
+
CSSParserToken,
|
|
1021
|
+
CloseCurlyToken,
|
|
1022
|
+
CloseParenToken,
|
|
1023
|
+
CloseSquareToken,
|
|
1024
|
+
ColonToken,
|
|
1025
|
+
ColumnToken,
|
|
1026
|
+
CommaToken,
|
|
1027
|
+
DashMatchToken,
|
|
1028
|
+
DelimToken,
|
|
1029
|
+
DimensionToken,
|
|
1030
|
+
EOFToken,
|
|
1031
|
+
FunctionToken,
|
|
1032
|
+
GroupingToken,
|
|
1033
|
+
HashToken,
|
|
1034
|
+
IdentToken,
|
|
1035
|
+
IncludeMatchToken,
|
|
1036
|
+
InvalidCharacterError,
|
|
1037
|
+
NumberToken,
|
|
1038
|
+
OpenCurlyToken,
|
|
1039
|
+
OpenParenToken,
|
|
1040
|
+
OpenSquareToken,
|
|
1041
|
+
PercentageToken,
|
|
1042
|
+
PrefixMatchToken,
|
|
1043
|
+
SemicolonToken,
|
|
1044
|
+
StringToken,
|
|
1045
|
+
StringValuedToken,
|
|
1046
|
+
SubstringMatchToken,
|
|
1047
|
+
SuffixMatchToken,
|
|
1048
|
+
URLToken,
|
|
1049
|
+
WhitespaceToken,
|
|
1050
|
+
tokenize
|
|
1051
|
+
});
|