swf2js 0.1.2 → 0.4.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/README.md +81 -14
- package/package.json +11 -7
- package/studio/actionscript-roundtrip.test.js +54 -0
- package/studio/actionscript-scripts.test.js +169 -0
- package/studio/animated-image.test.js +137 -0
- package/studio/arithmetic.test.js +16 -0
- package/studio/as3-import.test.js +110 -0
- package/studio/audio-info.test.js +44 -0
- package/studio/components.test.js +152 -0
- package/studio/document-editing.test.js +92 -0
- package/studio/examples/01-space-mission.json +1628 -0
- package/studio/examples/02-clockwork-vault.json +1079 -0
- package/studio/examples/03-neon-synth.json +1364 -0
- package/studio/examples/04-kinetic-poster.json +923 -0
- package/studio/examples/05-signal-relay.json +1131 -0
- package/studio/examples/06-calculator.json +564 -0
- package/studio/frame-editing.test.js +129 -0
- package/studio/frame-events.test.js +117 -0
- package/studio/groups.test.js +88 -0
- package/studio/index.html +962 -0
- package/studio/interaction-triggers.test.js +37 -0
- package/studio/linked-actions.test.js +48 -0
- package/studio/lottie.test.js +208 -0
- package/studio/masks.test.js +43 -0
- package/studio/media-assets.test.js +62 -0
- package/studio/paint-tools.test.js +60 -0
- package/studio/playback.test.js +17 -0
- package/studio/project-io.test.js +405 -0
- package/studio/project-preview.test.js +475 -0
- package/studio/scene-transition.test.js +32 -0
- package/studio/server/archive-companions.js +27 -0
- package/studio/server/as3-library.js +91 -0
- package/studio/server/assets.js +162 -0
- package/studio/server/audio-info.js +82 -0
- package/studio/server/font-files.js +332 -0
- package/studio/server/http.js +135 -0
- package/studio/server/linked-actions.js +93 -0
- package/studio/server/png-decode.js +1 -0
- package/studio/server/project-movie.js +1164 -0
- package/studio/server/project-preview.js +152 -0
- package/studio/server/projects.js +370 -0
- package/studio/server/report.js +29 -0
- package/studio/server/routes.js +93 -0
- package/studio/server/swf-authoring.js +90 -0
- package/studio/server/swf-control-runtime.as +513 -0
- package/studio/server/swf-controls.js +119 -0
- package/studio/server/swf-export.js +293 -0
- package/studio/server/swf-import.js +1675 -0
- package/studio/server/swf-morphs.js +64 -0
- package/studio/server/swf-routes.js +42 -0
- package/studio/server/swf-streams.js +80 -0
- package/studio/server/swf-transition-runtime.as +52 -0
- package/studio/server/tween-recovery.js +106 -0
- package/studio/server-api.test.js +283 -0
- package/studio/server.js +320 -0
- package/studio/src/animated-image.js +423 -0
- package/studio/src/appearance-inspector.js +63 -0
- package/studio/src/arithmetic.js +50 -0
- package/studio/src/authored-controls.js +42 -0
- package/studio/src/busy.js +41 -0
- package/studio/src/canvas.js +430 -0
- package/studio/src/clipper-browser.js +2 -0
- package/studio/src/color-transform.js +38 -0
- package/studio/src/component-inspector.js +126 -0
- package/studio/src/components.js +268 -0
- package/studio/src/display-frame.js +262 -0
- package/studio/src/document-editing.js +69 -0
- package/studio/src/event-editor.js +150 -0
- package/studio/src/frame-editing.js +150 -0
- package/studio/src/frame-events.js +128 -0
- package/studio/src/frame-image.js +28 -0
- package/studio/src/groups.js +125 -0
- package/studio/src/handler-editor.js +122 -0
- package/studio/src/history.js +83 -0
- package/studio/src/imported-paths.js +99 -0
- package/studio/src/index.js +3582 -0
- package/studio/src/interaction-triggers.js +42 -0
- package/studio/src/json-patch.js +77 -0
- package/studio/src/layer-icons.js +25 -0
- package/studio/src/lottie-export.js +948 -0
- package/studio/src/lottie-import.js +1138 -0
- package/studio/src/masks.js +69 -0
- package/studio/src/media-assets.js +188 -0
- package/studio/src/media-library.js +193 -0
- package/studio/src/model.js +431 -0
- package/studio/src/numeric-fields.js +46 -0
- package/studio/src/object-list.js +57 -0
- package/studio/src/paint-tools.js +76 -0
- package/studio/src/placement-effects.js +74 -0
- package/studio/src/playback.js +10 -0
- package/studio/src/preview-audio.js +64 -0
- package/studio/src/preview-interactions.js +106 -0
- package/studio/src/preview-recorder.js +335 -0
- package/studio/src/preview-surface.js +338 -0
- package/studio/src/project-io.js +905 -0
- package/studio/src/project-session.js +375 -0
- package/studio/src/projects-dialog.js +319 -0
- package/studio/src/scene-transition.js +129 -0
- package/studio/src/script-editor.js +175 -0
- package/studio/src/script-references.js +74 -0
- package/studio/src/scripted-controls.js +146 -0
- package/studio/src/scripts.js +185 -0
- package/studio/src/stage-guides.js +101 -0
- package/studio/src/svg-animation.js +416 -0
- package/studio/src/svg-context.js +522 -0
- package/studio/src/svg-frame.js +413 -0
- package/studio/src/svg-import.js +1208 -0
- package/studio/src/swf-recording.js +104 -0
- package/studio/src/symbol-library.js +39 -0
- package/studio/src/symbols.js +62 -0
- package/studio/src/text-fields.js +58 -0
- package/studio/src/theme.js +43 -0
- package/studio/src/timeline.js +321 -0
- package/studio/src/vector-cut.js +103 -0
- package/studio/src/vector-geometry.js +254 -0
- package/studio/src/vector-style.js +146 -0
- package/studio/src/video-encode.js +84 -0
- package/studio/src/video-export.js +331 -0
- package/studio/src/video-mux.js +339 -0
- package/studio/src/video-playback.js +281 -0
- package/studio/src/workspace.js +344 -0
- package/studio/stroke-style.test.js +119 -0
- package/studio/styles.css +1547 -0
- package/studio/svg-export.test.js +162 -0
- package/studio/svg-import.test.js +318 -0
- package/studio/swf-authoring.test.js +140 -0
- package/studio/swf-export.test.js +324 -0
- package/studio/swf-import.test.js +489 -0
- package/studio/symbols.test.js +68 -0
- package/studio/tests/accessibility-interactions.mjs +138 -0
- package/studio/tests/appearance-interactions.mjs +103 -0
- package/studio/tests/control-interactions.mjs +60 -0
- package/studio/tests/event-interactions.mjs +117 -0
- package/studio/tests/external-resources.mjs +174 -0
- package/studio/tests/frame-image.mjs +71 -0
- package/studio/tests/html-export.mjs +68 -0
- package/studio/tests/import-files.mjs +131 -0
- package/studio/tests/lottie.mjs +125 -0
- package/studio/tests/mask-interactions.mjs +148 -0
- package/studio/tests/media-interactions.mjs +109 -0
- package/studio/tests/paint-interactions.mjs +64 -0
- package/studio/tests/project-interactions.mjs +244 -0
- package/studio/tests/script-interactions.mjs +178 -0
- package/studio/tests/scripted-control-interactions.mjs +107 -0
- package/studio/tests/svg-export.mjs +149 -0
- package/studio/tests/text-field-interactions.mjs +64 -0
- package/studio/tests/theme-interactions.mjs +53 -0
- package/studio/tests/timeline-browser.mjs +507 -0
- package/studio/tests/transition-interactions.mjs +94 -0
- package/studio/tests/trigger-interactions.mjs +93 -0
- package/studio/tests/video-export.mjs +243 -0
- package/studio/tests/workspace-interactions.mjs +226 -0
- package/studio/tween-recovery.test.js +31 -0
- package/studio/vector-style.test.js +56 -0
- package/studio/video-export.test.js +326 -0
- package/studiospec/actionscript.md +88 -0
- package/studiospec/architecture.md +378 -0
- package/studiospec/controls.md +100 -0
- package/studiospec/file-support.md +268 -0
- package/studiospec/lottie.md +69 -0
- package/studiospec/requirements.md +135 -0
- package/studiospec/stroke-style.md +95 -0
- package/studiospec/svg-export.md +83 -0
- package/studiospec/svg-import.md +139 -0
- package/studiospec/swooflib-integration.md +115 -0
- package/studiospec/tasks.md +573 -0
- package/studiospec/video-export.md +127 -0
- package/swf2js/__tests__/actionscript.test.js +1609 -0
- package/swf2js/__tests__/adpcm-audio.test.js +43 -0
- package/swf2js/__tests__/as2-compiler.test.js +153 -0
- package/swf2js/__tests__/as3-mixed-depth.test.js +498 -0
- package/swf2js/__tests__/authored-sprite-hit.test.js +118 -0
- package/swf2js/__tests__/authored-sprite-sizing.test.js +164 -0
- package/swf2js/__tests__/avm1-action-prefix.test.js +134 -0
- package/swf2js/__tests__/avm1-attach-movie.test.js +1151 -0
- package/swf2js/__tests__/avm1-boxhead-budget.test.js +73 -0
- package/swf2js/__tests__/avm1-cfg-bubble-tanks.test.js +101 -0
- package/swf2js/__tests__/avm1-cfg-mario-kart.test.js +184 -0
- package/swf2js/__tests__/avm1-cfg-mario.test.js +31 -0
- package/swf2js/__tests__/avm1-cfg-pacman.test.js +49 -0
- package/swf2js/__tests__/avm1-checkers-gameplay.test.js +122 -0
- package/swf2js/__tests__/avm1-clip-actions.test.js +2002 -0
- package/swf2js/__tests__/avm1-clone-drag.test.js +626 -0
- package/swf2js/__tests__/avm1-decompiler.test.js +102 -0
- package/swf2js/__tests__/avm1-dynamic-locals.test.js +159 -0
- package/swf2js/__tests__/avm1-formal-parameters.test.js +71 -0
- package/swf2js/__tests__/avm1-key-events.test.js +52 -0
- package/swf2js/__tests__/avm1-load-bitmap.test.js +75 -0
- package/swf2js/__tests__/avm1-loading-host-actions.test.js +764 -0
- package/swf2js/__tests__/avm1-multibyte-strings.test.js +63 -0
- package/swf2js/__tests__/avm1-pacman-gameplay.test.js +115 -0
- package/swf2js/__tests__/avm1-shape-hittest.test.js +311 -0
- package/swf2js/__tests__/avm1-shared-bodies.test.js +57 -0
- package/swf2js/__tests__/avm1-shared-runtime.test.js +1364 -0
- package/swf2js/__tests__/avm1-snake-gameplay.test.js +139 -0
- package/swf2js/__tests__/avm1-super.test.js +70 -0
- package/swf2js/__tests__/avm1-target-path.test.js +325 -0
- package/swf2js/__tests__/avm1-try.test.js +229 -0
- package/swf2js/__tests__/avm2-activation-closures.test.js +65 -0
- package/swf2js/__tests__/avm2-applytype.test.js +180 -0
- package/swf2js/__tests__/avm2-call-ops.test.js +232 -0
- package/swf2js/__tests__/avm2-callsuperid.test.js +231 -0
- package/swf2js/__tests__/avm2-class-initializer.test.js +219 -0
- package/swf2js/__tests__/avm2-custom-namespace.test.js +139 -0
- package/swf2js/__tests__/avm2-describe-type.test.js +96 -0
- package/swf2js/__tests__/avm2-dictionary.test.js +96 -0
- package/swf2js/__tests__/avm2-domain-memory.test.js +332 -0
- package/swf2js/__tests__/avm2-e4x.test.js +326 -0
- package/swf2js/__tests__/avm2-exceptions.test.js +81 -0
- package/swf2js/__tests__/avm2-findprop.test.js +110 -0
- package/swf2js/__tests__/avm2-getlex.test.js +166 -0
- package/swf2js/__tests__/avm2-global-slot.test.js +106 -0
- package/swf2js/__tests__/avm2-interface.test.js +95 -0
- package/swf2js/__tests__/avm2-multiname-precedence.test.js +148 -0
- package/swf2js/__tests__/avm2-named-namespace-types.test.js +106 -0
- package/swf2js/__tests__/avm2-optional-args.test.js +100 -0
- package/swf2js/__tests__/avm2-outer-scopes.test.js +101 -0
- package/swf2js/__tests__/avm2-package-internal-class.test.js +106 -0
- package/swf2js/__tests__/avm2-protected-namespace.test.js +105 -0
- package/swf2js/__tests__/avm2-protected.test.js +214 -0
- package/swf2js/__tests__/avm2-qwop-gameplay.test.js +116 -0
- package/swf2js/__tests__/avm2-runtime-namespaces.test.js +159 -0
- package/swf2js/__tests__/avm2-script-traits.test.js +89 -0
- package/swf2js/__tests__/avm2-shared-runtime.test.js +52 -0
- package/swf2js/__tests__/avm2-slot-ops.test.js +117 -0
- package/swf2js/__tests__/avm2-type-ops.test.js +224 -0
- package/swf2js/__tests__/bevel-filter.test.js +116 -0
- package/swf2js/__tests__/bitmap-button-mask.test.js +106 -0
- package/swf2js/__tests__/bitmap-data-draw.test.js +388 -0
- package/swf2js/__tests__/bitmap-decoder.test.js +108 -0
- package/swf2js/__tests__/bitmapdata-color-bounds.test.js +70 -0
- package/swf2js/__tests__/bitmapdata-copy-channel.test.js +91 -0
- package/swf2js/__tests__/bitmapdata-copy-pixels.test.js +136 -0
- package/swf2js/__tests__/bitmapdata-fill-compare.test.js +241 -0
- package/swf2js/__tests__/bitmapdata-filter.test.js +232 -0
- package/swf2js/__tests__/bitmapdata-hit-test.test.js +71 -0
- package/swf2js/__tests__/bitmapdata-merge.test.js +84 -0
- package/swf2js/__tests__/bitmapdata-palette-map.test.js +92 -0
- package/swf2js/__tests__/bitmapdata-pixels-io.test.js +198 -0
- package/swf2js/__tests__/bitmapdata-threshold.test.js +97 -0
- package/swf2js/__tests__/bitmapdata-vector.test.js +82 -0
- package/swf2js/__tests__/blur-filter.test.js +48 -0
- package/swf2js/__tests__/bundle-emitter.test.js +394 -0
- package/swf2js/__tests__/button-actions.test.js +370 -0
- package/swf2js/__tests__/button-color-transform.test.js +48 -0
- package/swf2js/__tests__/button-decoder.test.js +106 -0
- package/swf2js/__tests__/button-hit-test.test.js +825 -0
- package/swf2js/__tests__/button-scaling-grid.test.js +124 -0
- package/swf2js/__tests__/button-sound.test.js +105 -0
- package/swf2js/__tests__/bytearray-coercion.test.js +23 -0
- package/swf2js/__tests__/bytearray-object-serialization.test.js +380 -0
- package/swf2js/__tests__/cfg-switch-loop.test.js +103 -0
- package/swf2js/__tests__/clip-depth-mask.test.js +119 -0
- package/swf2js/__tests__/clipped-bitmap-fill.test.js +118 -0
- package/swf2js/__tests__/companion-swf.test.js +638 -0
- package/swf2js/__tests__/context-menu.test.js +149 -0
- package/swf2js/__tests__/convolution-filter.test.js +74 -0
- package/swf2js/__tests__/definefont4.test.js +280 -0
- package/swf2js/__tests__/display-displacement.test.js +161 -0
- package/swf2js/__tests__/display-list.test.js +80 -0
- package/swf2js/__tests__/display-mask-render.test.js +656 -0
- package/swf2js/__tests__/displayobject-stage.test.js +320 -0
- package/swf2js/__tests__/embedded-script-audio.test.js +131 -0
- package/swf2js/__tests__/embedded-swf.test.js +202 -0
- package/swf2js/__tests__/embedded-textfield.test.js +107 -0
- package/swf2js/__tests__/embedded-timeline-audio.test.js +182 -0
- package/swf2js/__tests__/embedded-timeline-input.test.js +420 -0
- package/swf2js/__tests__/embedded-timer-lifecycle.test.js +145 -0
- package/swf2js/__tests__/event-priority-order.test.js +125 -0
- package/swf2js/__tests__/event-weak-listeners.test.js +53 -0
- package/swf2js/__tests__/event-will-trigger.test.js +43 -0
- package/swf2js/__tests__/flash-text-engine-content.test.js +115 -0
- package/swf2js/__tests__/flash-text-engine-format.test.js +95 -0
- package/swf2js/__tests__/flash-text-engine-line.test.js +314 -0
- package/swf2js/__tests__/font-encoder.test.js +95 -0
- package/swf2js/__tests__/font-outline-text.test.js +659 -0
- package/swf2js/__tests__/glow-shadow-filter.test.js +68 -0
- package/swf2js/__tests__/graphics-bitmap-smoothing.test.js +32 -0
- package/swf2js/__tests__/graphics-fill-lifetime.test.js +36 -0
- package/swf2js/__tests__/graphics-gradient-matrix.test.js +53 -0
- package/swf2js/__tests__/graphics-stroke-hit-test.test.js +457 -0
- package/swf2js/__tests__/hit-test-primitives.test.js +414 -0
- package/swf2js/__tests__/input-events.test.js +714 -0
- package/swf2js/__tests__/integration/corpus.test.js +41 -0
- package/swf2js/__tests__/loader-embedded-swf.test.js +210 -0
- package/swf2js/__tests__/loader-info.test.js +81 -0
- package/swf2js/__tests__/local-connection.test.js +122 -0
- package/swf2js/__tests__/morph-focal-gradient.test.js +51 -0
- package/swf2js/__tests__/morph-topology.test.js +267 -0
- package/swf2js/__tests__/movie-data-codec.test.js +128 -0
- package/swf2js/__tests__/nellymoser-audio.test.js +84 -0
- package/swf2js/__tests__/opaque-background-cache.test.js +352 -0
- package/swf2js/__tests__/path-stream.test.js +81 -0
- package/swf2js/__tests__/place-object-filters.test.js +88 -0
- package/swf2js/__tests__/place-object3-decoder.test.js +116 -0
- package/swf2js/__tests__/place-object3-image.test.js +85 -0
- package/swf2js/__tests__/player-version.test.js +46 -0
- package/swf2js/__tests__/root-textfield.test.js +287 -0
- package/swf2js/__tests__/scaling-grid.test.js +183 -0
- package/swf2js/__tests__/shape-decoder.test.js +361 -0
- package/swf2js/__tests__/shape-line-style2.test.js +138 -0
- package/swf2js/__tests__/shape-nonscaling-stroke.test.js +131 -0
- package/swf2js/__tests__/shape-pixel-hint.test.js +101 -0
- package/swf2js/__tests__/simplebutton-pointer.test.js +1477 -0
- package/swf2js/__tests__/socket-offline.test.js +67 -0
- package/swf2js/__tests__/sound-avm1-stop.test.js +99 -0
- package/swf2js/__tests__/sound-envelope.test.js +110 -0
- package/swf2js/__tests__/sound-extract.test.js +168 -0
- package/swf2js/__tests__/sound-id3.test.js +283 -0
- package/swf2js/__tests__/sound-load.test.js +259 -0
- package/swf2js/__tests__/sound-mixer-spectrum.test.js +261 -0
- package/swf2js/__tests__/sound-stream-sprite.test.js +624 -0
- package/swf2js/__tests__/sound-transform.test.js +104 -0
- package/swf2js/__tests__/speex-audio.test.js +77 -0
- package/swf2js/__tests__/stage-noscale.test.js +45 -0
- package/swf2js/__tests__/swf-encoder.test.js +134 -0
- package/swf2js/__tests__/swflib-assemble.test.js +20 -0
- package/swf2js/__tests__/textfield-html-text.test.js +368 -0
- package/swf2js/__tests__/textfield-line-layout.test.js +339 -0
- package/swf2js/__tests__/textfield-programmatic-overlay.test.js +2506 -0
- package/swf2js/__tests__/textfield-scroll.test.js +79 -0
- package/swf2js/__tests__/textfield-selection.test.js +383 -0
- package/swf2js/__tests__/timeline-effect-surfaces.test.js +295 -0
- package/swf2js/__tests__/timeline-named-anchor.test.js +139 -0
- package/swf2js/__tests__/timeline-scenes.test.js +1723 -0
- package/swf2js/__tests__/urlloader-http-status.test.js +236 -0
- package/{src → swf2js}/cli.js +43 -11
- package/swf2js/compiler/as2-classes.js +156 -0
- package/swf2js/compiler/as2-parser.js +598 -0
- package/swf2js/compiler/avm1-codegen.js +897 -0
- package/swf2js/compiler/index.js +28 -0
- package/{src → swf2js}/decoder/button-decoder.js +3 -1
- package/swf2js/decoder/png.js +114 -0
- package/{src → swf2js}/decoder/shape-decoder.js +20 -10
- package/{src → swf2js}/decoder/tag-decoder.js +5 -3
- package/{src → swf2js}/decoder/tag-types.js +4 -0
- package/swf2js/decompiler/avm1-decompiler.js +1138 -0
- package/{src → swf2js}/emitter/asset-encoder.js +66 -113
- package/{src → swf2js}/emitter/bundle-emitter.js +209 -78
- package/swf2js/emitter/external-resources.js +39 -0
- package/swf2js/emitter/movie-data-codec.js +91 -0
- package/swf2js/encoder/bit-writer.js +182 -0
- package/swf2js/encoder/shape-encoder.js +310 -0
- package/swf2js/encoder/swf-builder.js +639 -0
- package/swf2js/encoder/swf-writer.js +55 -0
- package/{src/runtime/swflib/assemble.js → swf2js/runtime/assemble-swooflib.js} +4 -3
- package/{src → swf2js}/runtime/avm1-runtime.js +102 -63
- package/{src → swf2js}/runtime/index.js +1 -1
- package/{src → swf2js}/runtime/movie-runtime.js +28 -2
- package/{src → swf2js}/transpiler/actionscript.js +82 -19
- package/{src → swf2js}/transpiler/avm1/avm1-opcodes.js +5 -3
- package/{src → swf2js}/transpiler/avm1/avm1-transpiler.js +69 -6
- package/{src → swf2js}/transpiler/avm2/avm2-transpiler.js +1 -1
- package/{src → swf2js}/transpiler/timeline/display-list.js +41 -22
- package/{src → swf2js}/transpiler/timeline/timeline-codegen.js +97 -36
- package/swooflib/README.md +569 -0
- package/swooflib/adpcm.js +147 -0
- package/{src/runtime/swflib → swooflib}/builtins.js +6 -0
- package/{src/runtime/swflib → swooflib}/context-menu.js +7 -1
- package/swooflib/control-definitions.js +42 -0
- package/swooflib/control-widget.js +763 -0
- package/swooflib/controls.js +300 -0
- package/{src/runtime/swflib → swooflib}/display.js +16 -10
- package/{src/runtime/swflib → swooflib}/events.js +11 -0
- package/{src/runtime/swflib → swooflib}/flash.js +6 -5
- package/{src/runtime/swflib → swooflib}/graphics.js +81 -19
- package/{src/runtime/swflib → swooflib}/input.js +12 -14
- package/{src/runtime/swflib → swooflib}/loader.js +52 -22
- package/swooflib/movie-network.js +86 -0
- package/swooflib/path-stream.js +169 -0
- package/{src/runtime/swflib → swooflib}/render.js +3 -13
- package/{src/runtime/swflib → swooflib}/sound.js +25 -2
- package/{src/runtime/swflib → swooflib}/stage.js +3 -3
- package/swooflib/stream-time.js +21 -0
- package/{src/runtime/swflib → swooflib}/system.js +88 -37
- package/{src/runtime/swflib → swooflib}/text-paint.js +14 -3
- package/{src/runtime/swflib → swooflib}/text.js +8 -0
- package/swooflib/xml-node.js +53 -0
- package/src/emitter/timeline-data-codec.js +0 -58
- /package/{src → swf2js}/decoder/symbol-table.js +0 -0
- /package/{src → swf2js}/emitter/embedded-swf.js +0 -0
- /package/{src → swf2js}/emitter/font-encoder.js +0 -0
- /package/{src → swf2js}/model/swf-document.js +0 -0
- /package/{src → swf2js}/model/transpile-result.js +0 -0
- /package/{src → swf2js}/parser/bit-reader.js +0 -0
- /package/{src → swf2js}/parser/decompressor.js +0 -0
- /package/{src → swf2js}/parser/swf-parser.js +0 -0
- /package/{src → swf2js}/pretty-printer/pretty-printer.js +0 -0
- /package/{src → swf2js}/runtime/avm2-runtime.js +0 -0
- /package/{src → swf2js}/runtime/embedded-movie-runtime.js +0 -0
- /package/{src → swf2js}/transpiler/avm1/avm1-ir.js +0 -0
- /package/{src → swf2js}/transpiler/avm1/avm1-rewrite.js +0 -0
- /package/{src → swf2js}/transpiler/avm2/abc-reader.js +0 -0
- /package/{src → swf2js}/transpiler/cfg-structurer.js +0 -0
- /package/{src → swf2js}/util/diagnostics.js +0 -0
- /package/{src → swf2js}/util/logger.js +0 -0
- /package/{src/runtime/swflib → swooflib}/bitmap-image.js +0 -0
- /package/{src/runtime/swflib → swooflib}/bitmap.js +0 -0
- /package/{src/runtime/swflib → swooflib}/bytearray.js +0 -0
- /package/{src/runtime/swflib → swooflib}/compiled-swf.js +0 -0
- /package/{src/runtime/swflib → swooflib}/cursor-flag.js +0 -0
- /package/{src/runtime/swflib → swooflib}/dictionary.js +0 -0
- /package/{src/runtime/swflib → swooflib}/filters.js +0 -0
- /package/{src/runtime/swflib → swooflib}/geom.js +0 -0
- /package/{src/runtime/swflib → swooflib}/glyph-metrics.js +0 -0
- /package/{src/runtime/swflib → swooflib}/host.js +0 -0
- /package/{src/runtime/swflib → swooflib}/inherit.js +0 -0
- /package/{src/runtime/swflib → swooflib}/marks.js +0 -0
- /package/{src/runtime/swflib → swooflib}/matrix3d.js +0 -0
- /package/{src/runtime/swflib → swooflib}/pointer-bridge.js +0 -0
- /package/{src/runtime/swflib → swooflib}/projection.js +0 -0
- /package/{src/runtime/swflib → swooflib}/sprite-drag.js +0 -0
- /package/{src/runtime/swflib → swooflib}/stage-ref.js +0 -0
- /package/{src/runtime/swflib → swooflib}/text-field.js +0 -0
- /package/{src/runtime/swflib → swooflib}/transform.js +0 -0
- /package/{src/runtime/swflib → swooflib}/xml.js +0 -0
|
@@ -0,0 +1,598 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview ActionScript 1/2 lexer and parser (studiospec/actionscript.md §4).
|
|
3
|
+
*
|
|
4
|
+
* Produces an ESTree-shaped tree with `line`/`column` on every node. Type annotations
|
|
5
|
+
* (`var x:Number`, `function f(a:String):Void`, `catch (e:Error)`) are accepted and dropped, as
|
|
6
|
+
* Flash's compiler does for code generation. Studio extensions: labeled statements, so the
|
|
7
|
+
* decompiler can write control flow that has no plain AS2 form.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export class CompileError extends Error {
|
|
11
|
+
constructor(message, line, column) {
|
|
12
|
+
super(line ? `${message} (line ${line}, column ${column})` : message);
|
|
13
|
+
this.name = 'CompileError';
|
|
14
|
+
this.reason = message;
|
|
15
|
+
this.line = line;
|
|
16
|
+
this.column = column;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const KEYWORDS = new Set([
|
|
21
|
+
'break', 'case', 'catch', 'continue', 'default', 'delete', 'do', 'else', 'false', 'finally', 'for',
|
|
22
|
+
'function', 'if', 'in', 'instanceof', 'new', 'null', 'return', 'switch', 'this', 'throw', 'true',
|
|
23
|
+
'try', 'typeof', 'var', 'void', 'while', 'with',
|
|
24
|
+
'class', 'interface', 'extends', 'implements', 'import',
|
|
25
|
+
]);
|
|
26
|
+
|
|
27
|
+
const PUNCTUATORS = [
|
|
28
|
+
'>>>=', '===', '!==', '>>>', '<<=', '>>=',
|
|
29
|
+
'==', '!=', '<=', '>=', '&&', '||', '++', '--', '+=', '-=', '*=', '/=', '%=', '&=', '|=', '^=', '<<', '>>',
|
|
30
|
+
'{', '}', '(', ')', '[', ']', ';', ',', '<', '>', '+', '-', '*', '/', '%', '&', '|', '^', '!', '~', '?', ':', '=', '.',
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
const isIdStart = ch => /[A-Za-z_$\u0080-]/.test(ch);
|
|
34
|
+
const isIdPart = ch => /[A-Za-z0-9_$\u0080-]/.test(ch);
|
|
35
|
+
|
|
36
|
+
/** Split source into tokens: { type: 'name'|'keyword'|'num'|'string'|'punct'|'eof', value, line, column, newline }. */
|
|
37
|
+
export function tokenize(source) {
|
|
38
|
+
const tokens = [];
|
|
39
|
+
let pos = 0, line = 1, lineStart = 0, newline = false;
|
|
40
|
+
const error = message => { throw new CompileError(message, line, pos - lineStart + 1); };
|
|
41
|
+
while (pos < source.length) {
|
|
42
|
+
const ch = source[pos];
|
|
43
|
+
if (ch === '\n') { pos++; line++; lineStart = pos; newline = true; continue; }
|
|
44
|
+
if (/\s/.test(ch)) { pos++; continue; }
|
|
45
|
+
if (ch === '/' && source[pos + 1] === '/') {
|
|
46
|
+
while (pos < source.length && source[pos] !== '\n') pos++;
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (ch === '/' && source[pos + 1] === '*') {
|
|
50
|
+
const end = source.indexOf('*/', pos + 2);
|
|
51
|
+
if (end < 0) error('Unclosed comment');
|
|
52
|
+
for (let i = pos; i < end; i++) if (source[i] === '\n') { line++; lineStart = i + 1; newline = true; }
|
|
53
|
+
pos = end + 2;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
// Flash pragmas: `#initclip` blocks are attached by Studio; the markers themselves are ignored.
|
|
57
|
+
if (ch === '#' && (pos === lineStart || /^\s*$/.test(source.slice(lineStart, pos)))) {
|
|
58
|
+
const end = source.indexOf('\n', pos);
|
|
59
|
+
const pragma = source.slice(pos, end < 0 ? source.length : end).trim();
|
|
60
|
+
if (!/^#(initclip|endinitclip)\b/.test(pragma)) error(`${pragma.split(/\s/)[0]} is not supported`);
|
|
61
|
+
pos = end < 0 ? source.length : end;
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
const start = { line, column: pos - lineStart + 1, newline };
|
|
65
|
+
newline = false;
|
|
66
|
+
if (isIdStart(ch)) {
|
|
67
|
+
let end = pos + 1;
|
|
68
|
+
while (end < source.length && isIdPart(source[end])) end++;
|
|
69
|
+
const word = source.slice(pos, end);
|
|
70
|
+
tokens.push({ type: KEYWORDS.has(word) ? 'keyword' : 'name', value: word, ...start });
|
|
71
|
+
pos = end;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (/[0-9]/.test(ch) || (ch === '.' && /[0-9]/.test(source[pos + 1] ?? ''))) {
|
|
75
|
+
const match = /^0[xX][0-9a-fA-F]+/.exec(source.slice(pos)) ?? /^(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?/.exec(source.slice(pos));
|
|
76
|
+
const text = match[0];
|
|
77
|
+
if (isIdStart(source[pos + text.length] ?? '')) error(`Invalid number ${text}${source[pos + text.length]}`);
|
|
78
|
+
tokens.push({ type: 'num', value: Number(text), ...start });
|
|
79
|
+
pos += text.length;
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
if (ch === '"' || ch === "'") {
|
|
83
|
+
let value = '';
|
|
84
|
+
pos++;
|
|
85
|
+
for (;;) {
|
|
86
|
+
if (pos >= source.length || source[pos] === '\n') error('Unclosed string');
|
|
87
|
+
const c = source[pos++];
|
|
88
|
+
if (c === ch) break;
|
|
89
|
+
if (c !== '\\') { value += c; continue; }
|
|
90
|
+
const e = source[pos++];
|
|
91
|
+
const simple = { n: '\n', r: '\r', t: '\t', b: '\b', f: '\f', v: '\v', 0: '\0' };
|
|
92
|
+
if (e in simple) value += simple[e];
|
|
93
|
+
else if (e === 'x' || e === 'u') {
|
|
94
|
+
const digits = e === 'x' ? 2 : 4;
|
|
95
|
+
const hex = source.slice(pos, pos + digits);
|
|
96
|
+
if (!new RegExp(`^[0-9a-fA-F]{${digits}}$`).test(hex)) error(`Invalid escape \\${e}${hex}`);
|
|
97
|
+
value += String.fromCharCode(parseInt(hex, 16));
|
|
98
|
+
pos += digits;
|
|
99
|
+
} else if (e === '\n') { line++; lineStart = pos; }
|
|
100
|
+
else value += e;
|
|
101
|
+
}
|
|
102
|
+
tokens.push({ type: 'string', value, ...start });
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
const punct = PUNCTUATORS.find(p => source.startsWith(p, pos));
|
|
106
|
+
if (!punct) error(`Unexpected character ${JSON.stringify(ch)}`);
|
|
107
|
+
tokens.push({ type: 'punct', value: punct, ...start });
|
|
108
|
+
pos += punct.length;
|
|
109
|
+
}
|
|
110
|
+
tokens.push({ type: 'eof', value: '', line, column: pos - lineStart + 1, newline: true });
|
|
111
|
+
return tokens;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const BINARY_PRECEDENCE = {
|
|
115
|
+
'||': 1, '&&': 2, '|': 3, '^': 4, '&': 5,
|
|
116
|
+
'==': 6, '!=': 6, '===': 6, '!==': 6,
|
|
117
|
+
'<': 7, '>': 7, '<=': 7, '>=': 7, instanceof: 7,
|
|
118
|
+
'<<': 8, '>>': 8, '>>>': 8,
|
|
119
|
+
'+': 9, '-': 9, '*': 10, '/': 10, '%': 10,
|
|
120
|
+
};
|
|
121
|
+
const ASSIGNMENT = new Set(['=', '+=', '-=', '*=', '/=', '%=', '<<=', '>>=', '>>>=', '&=', '|=', '^=']);
|
|
122
|
+
|
|
123
|
+
/** Parse ActionScript source into a `Program` node. Throws CompileError. */
|
|
124
|
+
export function parse(source) {
|
|
125
|
+
const tokens = tokenize(source);
|
|
126
|
+
let index = 0;
|
|
127
|
+
const peek = (offset = 0) => tokens[Math.min(index + offset, tokens.length - 1)];
|
|
128
|
+
const next = () => tokens[index++];
|
|
129
|
+
const at = (value, type) => peek().value === value && (type ? peek().type === type : peek().type === 'punct' || peek().type === 'keyword');
|
|
130
|
+
const fail = (message, token = peek()) => { throw new CompileError(message, token.line, token.column); };
|
|
131
|
+
const describe = token => token.type === 'eof' ? 'end of script' : token.type === 'string' ? 'a string' : `"${token.value}"`;
|
|
132
|
+
// In a list: a comma, or the closing bracket.
|
|
133
|
+
const separator = close => {
|
|
134
|
+
if (at(',')) { next(); return; }
|
|
135
|
+
if (!at(close)) fail(`Expected "," or "${close}" but found ${describe(peek())}`);
|
|
136
|
+
};
|
|
137
|
+
const expect = value => {
|
|
138
|
+
if (!at(value)) fail(`Expected "${value}" but found ${describe(peek())}`);
|
|
139
|
+
return next();
|
|
140
|
+
};
|
|
141
|
+
const node = (type, token, props) => ({ type, line: token.line, column: token.column, ...props });
|
|
142
|
+
const identifier = () => {
|
|
143
|
+
const token = peek();
|
|
144
|
+
if (token.type !== 'name') fail(`Expected a name but found ${describe(token)}`);
|
|
145
|
+
next();
|
|
146
|
+
return node('Identifier', token, { name: token.value });
|
|
147
|
+
};
|
|
148
|
+
// `:Type` or `:mx.controls.Button`, dropped.
|
|
149
|
+
const typeAnnotation = () => {
|
|
150
|
+
if (!at(':')) return;
|
|
151
|
+
next();
|
|
152
|
+
if (peek().type !== 'name' && !at('void') && !at('Function', 'name')) fail('Expected a type name');
|
|
153
|
+
next();
|
|
154
|
+
while (at('.')) { next(); identifier(); }
|
|
155
|
+
};
|
|
156
|
+
// Statement end: a semicolon, or a line break, `}` or the end of the script before the next token.
|
|
157
|
+
const semicolon = () => {
|
|
158
|
+
if (at(';')) { next(); return; }
|
|
159
|
+
if (at('}') || peek().type === 'eof' || peek().newline) return;
|
|
160
|
+
fail(`Expected ";" but found ${describe(peek())}`);
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
function program() {
|
|
164
|
+
const body = [];
|
|
165
|
+
while (peek().type !== 'eof') body.push(statement());
|
|
166
|
+
return { type: 'Program', line: 1, column: 1, body };
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function block() {
|
|
170
|
+
const token = expect('{');
|
|
171
|
+
const body = [];
|
|
172
|
+
while (!at('}')) {
|
|
173
|
+
if (peek().type === 'eof') fail('Missing "}"', token);
|
|
174
|
+
body.push(statement());
|
|
175
|
+
}
|
|
176
|
+
next();
|
|
177
|
+
return node('BlockStatement', token, { body });
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function variableDeclaration(token, { inFor = false } = {}) {
|
|
181
|
+
const declarations = [];
|
|
182
|
+
do {
|
|
183
|
+
const id = identifier();
|
|
184
|
+
typeAnnotation();
|
|
185
|
+
let init = null;
|
|
186
|
+
if (at('=')) { next(); init = assignment({ noIn: inFor }); }
|
|
187
|
+
declarations.push(node('VariableDeclarator', id, { id, init }));
|
|
188
|
+
} while (at(',') && next());
|
|
189
|
+
return node('VariableDeclaration', token, { declarations });
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function functionRest(token, { declaration, signature = false }) {
|
|
193
|
+
let id = null;
|
|
194
|
+
if (peek().type === 'name') id = identifier();
|
|
195
|
+
else if (declaration) fail('Expected a function name');
|
|
196
|
+
expect('(');
|
|
197
|
+
const params = [];
|
|
198
|
+
while (!at(')')) {
|
|
199
|
+
params.push(identifier());
|
|
200
|
+
typeAnnotation();
|
|
201
|
+
separator(')');
|
|
202
|
+
}
|
|
203
|
+
next();
|
|
204
|
+
typeAnnotation();
|
|
205
|
+
const body = signature ? (semicolon(), []) : block().body;
|
|
206
|
+
return node(declaration ? 'FunctionDeclaration' : 'FunctionExpression', token, { id, params, body });
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function qualifiedName(wildcard = false) {
|
|
210
|
+
const parts = [identifier().name];
|
|
211
|
+
while (at('.')) {
|
|
212
|
+
next();
|
|
213
|
+
if (wildcard && at('*')) { next(); parts.push('*'); break; }
|
|
214
|
+
parts.push(identifier().name);
|
|
215
|
+
}
|
|
216
|
+
return parts;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function classDeclaration(token) {
|
|
220
|
+
const name = qualifiedName(), interfaces = [], members = [];
|
|
221
|
+
const isInterface = token.value === 'interface';
|
|
222
|
+
let base = null;
|
|
223
|
+
if (at('extends')) {
|
|
224
|
+
next();
|
|
225
|
+
if (isInterface) { do { interfaces.push(qualifiedName()); } while (at(',') && next()); }
|
|
226
|
+
else base = qualifiedName();
|
|
227
|
+
}
|
|
228
|
+
if (!isInterface && at('implements')) {
|
|
229
|
+
next();
|
|
230
|
+
do { interfaces.push(qualifiedName()); } while (at(',') && next());
|
|
231
|
+
}
|
|
232
|
+
expect('{');
|
|
233
|
+
while (!at('}')) {
|
|
234
|
+
if (at(';')) { next(); continue; }
|
|
235
|
+
let isStatic = false;
|
|
236
|
+
while (peek().type === 'name' && ['public', 'private', 'static'].includes(peek().value)) {
|
|
237
|
+
if (next().value === 'static') isStatic = true;
|
|
238
|
+
}
|
|
239
|
+
const member = peek();
|
|
240
|
+
if (at('var')) {
|
|
241
|
+
next();
|
|
242
|
+
for (const field of variableDeclaration(member).declarations) members.push({ ...field, isStatic });
|
|
243
|
+
semicolon();
|
|
244
|
+
} else if (at('function')) {
|
|
245
|
+
next();
|
|
246
|
+
const accessor = ['get', 'set'].includes(peek().value) && peek(1).type === 'name' ? next().value : null;
|
|
247
|
+
members.push({ ...functionRest(member, { declaration: true, signature: isInterface }), accessor, isStatic });
|
|
248
|
+
} else fail('Expected a class field or method');
|
|
249
|
+
}
|
|
250
|
+
next();
|
|
251
|
+
return node('ClassDeclaration', token, { name, base, interfaces, members, isInterface });
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function statement() {
|
|
255
|
+
const token = peek();
|
|
256
|
+
if (token.type === 'punct') {
|
|
257
|
+
if (token.value === '{') return block();
|
|
258
|
+
if (token.value === ';') { next(); return node('EmptyStatement', token); }
|
|
259
|
+
}
|
|
260
|
+
if (token.type === 'name' && peek(1).value === ':' && peek(1).type === 'punct') {
|
|
261
|
+
next(); next();
|
|
262
|
+
return node('LabeledStatement', token, { label: token.value, body: statement() });
|
|
263
|
+
}
|
|
264
|
+
if (token.type === 'name' && (token.value === 'on' || token.value === 'onClipEvent') && peek(1).value === '(') {
|
|
265
|
+
fail(`${token.value} handlers are set in the object's events, not in script code`);
|
|
266
|
+
}
|
|
267
|
+
if (token.type === 'name' && token.value === 'tellTarget' && peek(1).value === '(') {
|
|
268
|
+
next(); expect('(');
|
|
269
|
+
const target = expression();
|
|
270
|
+
expect(')');
|
|
271
|
+
return node('TellTargetStatement', token, { target, body: statement() });
|
|
272
|
+
}
|
|
273
|
+
if (at('ifFrameLoaded', 'name') && peek(1).value === '(') {
|
|
274
|
+
next();
|
|
275
|
+
const list = args();
|
|
276
|
+
if (list.length < 1 || list.length > 2) fail('ifFrameLoaded takes a frame and an optional scene', token);
|
|
277
|
+
const body = statement();
|
|
278
|
+
const alternate = at('else') ? (next(), statement()) : null;
|
|
279
|
+
return node('IfFrameLoadedStatement', token, { frame: list.at(-1), scene: list.length === 2 ? list[0] : null, body, alternate });
|
|
280
|
+
}
|
|
281
|
+
if (at('dynamic', 'name') && peek(1).value === 'class') { next(); return classDeclaration(next()); }
|
|
282
|
+
if (token.type !== 'keyword') return expressionStatement();
|
|
283
|
+
switch (token.value) {
|
|
284
|
+
case 'var': {
|
|
285
|
+
next();
|
|
286
|
+
const declaration = variableDeclaration(token);
|
|
287
|
+
semicolon();
|
|
288
|
+
return declaration;
|
|
289
|
+
}
|
|
290
|
+
case 'function':
|
|
291
|
+
// A named function at statement level is a declaration; `function () {}()` is not.
|
|
292
|
+
if (peek(1).type === 'name') { next(); return functionRest(token, { declaration: true }); }
|
|
293
|
+
return expressionStatement();
|
|
294
|
+
case 'if': {
|
|
295
|
+
next(); expect('(');
|
|
296
|
+
const test = expression();
|
|
297
|
+
expect(')');
|
|
298
|
+
const consequent = statement();
|
|
299
|
+
let alternate = null;
|
|
300
|
+
if (at('else')) { next(); alternate = statement(); }
|
|
301
|
+
return node('IfStatement', token, { test, consequent, alternate });
|
|
302
|
+
}
|
|
303
|
+
case 'while': {
|
|
304
|
+
next(); expect('(');
|
|
305
|
+
const test = expression();
|
|
306
|
+
expect(')');
|
|
307
|
+
return node('WhileStatement', token, { test, body: statement() });
|
|
308
|
+
}
|
|
309
|
+
case 'do': {
|
|
310
|
+
next();
|
|
311
|
+
const body = statement();
|
|
312
|
+
expect('while'); expect('(');
|
|
313
|
+
const test = expression();
|
|
314
|
+
expect(')');
|
|
315
|
+
if (at(';')) next();
|
|
316
|
+
return node('DoWhileStatement', token, { body, test });
|
|
317
|
+
}
|
|
318
|
+
case 'for': {
|
|
319
|
+
next(); expect('(');
|
|
320
|
+
let init = null;
|
|
321
|
+
if (at('var')) {
|
|
322
|
+
const varToken = next();
|
|
323
|
+
init = variableDeclaration(varToken, { inFor: true });
|
|
324
|
+
} else if (!at(';')) {
|
|
325
|
+
init = expression({ noIn: true });
|
|
326
|
+
}
|
|
327
|
+
if (at('in')) {
|
|
328
|
+
next();
|
|
329
|
+
const right = expression();
|
|
330
|
+
expect(')');
|
|
331
|
+
const left = init;
|
|
332
|
+
if (left.type === 'VariableDeclaration' && (left.declarations.length !== 1 || left.declarations[0].init)) fail('Expected one variable in for…in', left);
|
|
333
|
+
if (left.type !== 'VariableDeclaration' && left.type !== 'Identifier' && left.type !== 'MemberExpression') fail('Invalid for…in variable', left);
|
|
334
|
+
return node('ForInStatement', token, { left, right, body: statement() });
|
|
335
|
+
}
|
|
336
|
+
expect(';');
|
|
337
|
+
const test = at(';') ? null : expression();
|
|
338
|
+
expect(';');
|
|
339
|
+
const update = at(')') ? null : expression();
|
|
340
|
+
expect(')');
|
|
341
|
+
return node('ForStatement', token, { init, test, update, body: statement() });
|
|
342
|
+
}
|
|
343
|
+
case 'break': case 'continue': {
|
|
344
|
+
next();
|
|
345
|
+
let label = null;
|
|
346
|
+
if (peek().type === 'name' && !peek().newline) label = next().value;
|
|
347
|
+
semicolon();
|
|
348
|
+
return node(token.value === 'break' ? 'BreakStatement' : 'ContinueStatement', token, { label });
|
|
349
|
+
}
|
|
350
|
+
case 'return': {
|
|
351
|
+
next();
|
|
352
|
+
let argument = null;
|
|
353
|
+
if (!at(';') && !at('}') && peek().type !== 'eof' && !peek().newline) argument = expression();
|
|
354
|
+
semicolon();
|
|
355
|
+
return node('ReturnStatement', token, { argument });
|
|
356
|
+
}
|
|
357
|
+
case 'throw': {
|
|
358
|
+
next();
|
|
359
|
+
const argument = expression();
|
|
360
|
+
semicolon();
|
|
361
|
+
return node('ThrowStatement', token, { argument });
|
|
362
|
+
}
|
|
363
|
+
case 'try': {
|
|
364
|
+
next();
|
|
365
|
+
const tryBlock = block();
|
|
366
|
+
let param = null, handler = null, finalizer = null;
|
|
367
|
+
if (at('catch')) {
|
|
368
|
+
next(); expect('(');
|
|
369
|
+
param = identifier();
|
|
370
|
+
typeAnnotation();
|
|
371
|
+
expect(')');
|
|
372
|
+
handler = block();
|
|
373
|
+
}
|
|
374
|
+
if (at('finally')) { next(); finalizer = block(); }
|
|
375
|
+
if (!handler && !finalizer) fail('Expected catch or finally');
|
|
376
|
+
return node('TryStatement', token, { block: tryBlock, param, handler, finalizer });
|
|
377
|
+
}
|
|
378
|
+
case 'switch': {
|
|
379
|
+
next(); expect('(');
|
|
380
|
+
const discriminant = expression();
|
|
381
|
+
expect(')'); expect('{');
|
|
382
|
+
const cases = [];
|
|
383
|
+
let hasDefault = false;
|
|
384
|
+
while (!at('}')) {
|
|
385
|
+
const caseToken = peek();
|
|
386
|
+
let test = null;
|
|
387
|
+
if (at('case')) { next(); test = expression(); }
|
|
388
|
+
else if (at('default')) {
|
|
389
|
+
if (hasDefault) fail('A switch can have one default');
|
|
390
|
+
hasDefault = true;
|
|
391
|
+
next();
|
|
392
|
+
} else fail(`Expected case or default but found ${describe(peek())}`);
|
|
393
|
+
expect(':');
|
|
394
|
+
const consequent = [];
|
|
395
|
+
while (!at('case') && !at('default') && !at('}')) {
|
|
396
|
+
if (peek().type === 'eof') fail('Missing "}"', token);
|
|
397
|
+
consequent.push(statement());
|
|
398
|
+
}
|
|
399
|
+
cases.push(node('SwitchCase', caseToken, { test, consequent }));
|
|
400
|
+
}
|
|
401
|
+
next();
|
|
402
|
+
return node('SwitchStatement', token, { discriminant, cases });
|
|
403
|
+
}
|
|
404
|
+
case 'with': {
|
|
405
|
+
next(); expect('(');
|
|
406
|
+
const object = expression();
|
|
407
|
+
expect(')');
|
|
408
|
+
return node('WithStatement', token, { object, body: statement() });
|
|
409
|
+
}
|
|
410
|
+
case 'class': case 'interface':
|
|
411
|
+
next(); return classDeclaration(token);
|
|
412
|
+
case 'import': {
|
|
413
|
+
next(); const name = qualifiedName(true); semicolon();
|
|
414
|
+
return node('ImportDeclaration', token, { name });
|
|
415
|
+
}
|
|
416
|
+
default:
|
|
417
|
+
return expressionStatement();
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
function expressionStatement() {
|
|
422
|
+
const token = peek();
|
|
423
|
+
const expr = expression();
|
|
424
|
+
semicolon();
|
|
425
|
+
return node('ExpressionStatement', token, { expression: expr });
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
function expression(options = {}) {
|
|
429
|
+
const token = peek();
|
|
430
|
+
const first = assignment(options);
|
|
431
|
+
if (!at(',')) return first;
|
|
432
|
+
const expressions = [first];
|
|
433
|
+
while (at(',')) { next(); expressions.push(assignment(options)); }
|
|
434
|
+
return node('SequenceExpression', token, { expressions });
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
function assignment(options = {}) {
|
|
438
|
+
const token = peek();
|
|
439
|
+
const left = conditional(options);
|
|
440
|
+
if (peek().type === 'punct' && ASSIGNMENT.has(peek().value)) {
|
|
441
|
+
const operator = next().value;
|
|
442
|
+
if (left.type !== 'Identifier' && left.type !== 'MemberExpression') fail('Invalid assignment target', left);
|
|
443
|
+
return node('AssignmentExpression', token, { operator, left, right: assignment(options) });
|
|
444
|
+
}
|
|
445
|
+
return left;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
function conditional(options) {
|
|
449
|
+
const token = peek();
|
|
450
|
+
const test = binary(0, options);
|
|
451
|
+
if (!at('?')) return test;
|
|
452
|
+
next();
|
|
453
|
+
const consequent = assignment();
|
|
454
|
+
expect(':');
|
|
455
|
+
return node('ConditionalExpression', token, { test, consequent, alternate: assignment(options) });
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
function binary(minimum, options) {
|
|
459
|
+
let left = unary();
|
|
460
|
+
for (;;) {
|
|
461
|
+
const token = peek();
|
|
462
|
+
const operator = token.value;
|
|
463
|
+
const precedence = (token.type === 'punct' || operator === 'instanceof') ? BINARY_PRECEDENCE[operator] : undefined;
|
|
464
|
+
if (precedence === undefined || precedence <= minimum) break;
|
|
465
|
+
if (operator === 'in' && options.noIn) break;
|
|
466
|
+
next();
|
|
467
|
+
const right = binary(precedence, options);
|
|
468
|
+
const type = operator === '&&' || operator === '||' ? 'LogicalExpression' : 'BinaryExpression';
|
|
469
|
+
left = node(type, left, { operator, left, right });
|
|
470
|
+
}
|
|
471
|
+
return left;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
function unary() {
|
|
475
|
+
const token = peek();
|
|
476
|
+
if ((token.type === 'punct' && ['!', '-', '+', '~'].includes(token.value)) || (token.type === 'keyword' && ['typeof', 'void', 'delete'].includes(token.value))) {
|
|
477
|
+
next();
|
|
478
|
+
const argument = unary();
|
|
479
|
+
if (token.value === 'delete' && argument.type !== 'Identifier' && argument.type !== 'MemberExpression') fail('delete needs a variable or a property', argument);
|
|
480
|
+
return node('UnaryExpression', token, { operator: token.value, argument });
|
|
481
|
+
}
|
|
482
|
+
if (token.type === 'punct' && (token.value === '++' || token.value === '--')) {
|
|
483
|
+
next();
|
|
484
|
+
const argument = unary();
|
|
485
|
+
if (argument.type !== 'Identifier' && argument.type !== 'MemberExpression') fail(`${token.value} needs a variable or a property`, argument);
|
|
486
|
+
return node('UpdateExpression', token, { operator: token.value, prefix: true, argument });
|
|
487
|
+
}
|
|
488
|
+
const expr = postfixTarget();
|
|
489
|
+
if (peek().type === 'punct' && (peek().value === '++' || peek().value === '--') && !peek().newline) {
|
|
490
|
+
if (expr.type !== 'Identifier' && expr.type !== 'MemberExpression') fail(`${peek().value} needs a variable or a property`);
|
|
491
|
+
return node('UpdateExpression', token, { operator: next().value, prefix: false, argument: expr });
|
|
492
|
+
}
|
|
493
|
+
return expr;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
function args() {
|
|
497
|
+
expect('(');
|
|
498
|
+
const list = [];
|
|
499
|
+
while (!at(')')) {
|
|
500
|
+
list.push(assignment());
|
|
501
|
+
separator(')');
|
|
502
|
+
}
|
|
503
|
+
next();
|
|
504
|
+
return list;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
function postfixTarget() {
|
|
508
|
+
const token = peek();
|
|
509
|
+
let expr;
|
|
510
|
+
if (at('new')) {
|
|
511
|
+
next();
|
|
512
|
+
// `new a.b.C(…)`: the callee is a member chain without calls.
|
|
513
|
+
let callee = primary();
|
|
514
|
+
while (at('.') || at('[')) callee = member(callee);
|
|
515
|
+
const list = at('(') ? args() : [];
|
|
516
|
+
expr = node('NewExpression', token, { callee, arguments: list });
|
|
517
|
+
} else {
|
|
518
|
+
expr = primary();
|
|
519
|
+
}
|
|
520
|
+
for (;;) {
|
|
521
|
+
if (at('.') || at('[')) expr = member(expr);
|
|
522
|
+
else if (at('(')) expr = node('CallExpression', expr, { callee: expr, arguments: args() });
|
|
523
|
+
else return expr;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
function member(object) {
|
|
528
|
+
if (at('.')) {
|
|
529
|
+
next();
|
|
530
|
+
const token = peek();
|
|
531
|
+
// Any word is a property name after a dot, keywords included (`o.delete`, `xml.new`).
|
|
532
|
+
if (token.type !== 'name' && token.type !== 'keyword') fail('Expected a property name');
|
|
533
|
+
next();
|
|
534
|
+
return node('MemberExpression', object, { object, property: node('Identifier', token, { name: token.value }), computed: false });
|
|
535
|
+
}
|
|
536
|
+
next();
|
|
537
|
+
const property = expression();
|
|
538
|
+
expect(']');
|
|
539
|
+
return node('MemberExpression', object, { object, property, computed: true });
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
function primary() {
|
|
543
|
+
const token = peek();
|
|
544
|
+
switch (token.type) {
|
|
545
|
+
case 'num': next(); return node('Literal', token, { value: token.value });
|
|
546
|
+
case 'string': next(); return node('Literal', token, { value: token.value });
|
|
547
|
+
case 'name':
|
|
548
|
+
next();
|
|
549
|
+
if (token.value === 'undefined') return node('Literal', token, { value: undefined });
|
|
550
|
+
return node('Identifier', token, { name: token.value });
|
|
551
|
+
case 'keyword':
|
|
552
|
+
if (token.value === 'true' || token.value === 'false') { next(); return node('Literal', token, { value: token.value === 'true' }); }
|
|
553
|
+
if (token.value === 'null') { next(); return node('Literal', token, { value: null }); }
|
|
554
|
+
if (token.value === 'this') { next(); return node('ThisExpression', token); }
|
|
555
|
+
if (token.value === 'function') { next(); return functionRest(token, { declaration: false }); }
|
|
556
|
+
break;
|
|
557
|
+
case 'punct':
|
|
558
|
+
if (token.value === '(') {
|
|
559
|
+
next();
|
|
560
|
+
const inner = expression();
|
|
561
|
+
expect(')');
|
|
562
|
+
// `(f)()` calls the value of f (CallMethod), not the function named f (CallFunction).
|
|
563
|
+
return { ...inner, parenthesized: true };
|
|
564
|
+
}
|
|
565
|
+
if (token.value === '[') {
|
|
566
|
+
next();
|
|
567
|
+
const elements = [];
|
|
568
|
+
while (!at(']')) {
|
|
569
|
+
elements.push(assignment());
|
|
570
|
+
separator(']');
|
|
571
|
+
}
|
|
572
|
+
next();
|
|
573
|
+
return node('ArrayExpression', token, { elements });
|
|
574
|
+
}
|
|
575
|
+
if (token.value === '{') {
|
|
576
|
+
next();
|
|
577
|
+
const properties = [];
|
|
578
|
+
while (!at('}')) {
|
|
579
|
+
const keyToken = next();
|
|
580
|
+
let key;
|
|
581
|
+
if (keyToken.type === 'name' || keyToken.type === 'keyword' || keyToken.type === 'string') key = String(keyToken.value);
|
|
582
|
+
else if (keyToken.type === 'num') key = String(keyToken.value);
|
|
583
|
+
else fail('Expected a property name', keyToken);
|
|
584
|
+
expect(':');
|
|
585
|
+
properties.push({ key, value: assignment(), line: keyToken.line, column: keyToken.column });
|
|
586
|
+
separator('}');
|
|
587
|
+
}
|
|
588
|
+
next();
|
|
589
|
+
return node('ObjectExpression', token, { properties });
|
|
590
|
+
}
|
|
591
|
+
break;
|
|
592
|
+
default:
|
|
593
|
+
}
|
|
594
|
+
fail(`Unexpected ${describe(token)}`);
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
return program();
|
|
598
|
+
}
|