diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fda8cbfc2..a46c7f750a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ - Remove obsolete `@bs.open` feature. https://github.com/rescript-lang/rescript-compiler/pull/6629 - Drop Node.js version <18 support, due to it reaching End-of-Life. https://github.com/rescript-lang/rescript-compiler/pull/6429 - Remove deprecated -bs-super-errors option. https://github.com/rescript-lang/rescript-compiler/pull/6814 +- Some global names and old keywords are no longer prefixed. https://github.com/rescript-lang/rescript-compiler/pull/6831 #### :bug: Bug Fix diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c9f7cc4a71..b97585a998 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -300,17 +300,6 @@ To generate the html: ../scripts/ninja docs ``` -## Update JS Reserved Keywords Map - -The compiler sources include a list of reserved JS keywords in `jscomp/ext/js_reserved_map.ml` which includes all identifiers in global scope (`window`). This list should be updated from time to time for newer browser versions. - -To update it, run: - -```sh -npm install puppeteer -node scripts/build_reserved.js -``` - ## Code structure The highlevel architecture is illustrated as below: diff --git a/jscomp/ext/ext_ident.ml b/jscomp/ext/ext_ident.ml index 272a21b43c..4f1e6dfa7a 100644 --- a/jscomp/ext/ext_ident.ml +++ b/jscomp/ext/ext_ident.ml @@ -23,12 +23,6 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) - - - - - - let js_flag = 0b1_000 (* check with ocaml compiler *) (* let js_module_flag = 0b10_000 (\* javascript external modules *\) *) @@ -172,18 +166,14 @@ let name_mangle name = Ext_buffer.add_string buffer (convert ~op:(i=0) c) done; Ext_buffer.contents buffer -(* TODO: - check name conflicts with javascript conventions - {[ - Ext_ident.convert "^";; - - : string = "$caret" - ]} - [convert name] if [name] is a js keyword,add "$$" +(** + [convert name] if [name] is a js keyword or js global, add "$$" otherwise do the name mangling to make sure ocaml identifier it is a valid js identifier *) let convert (name : string) = - if Js_reserved_map.is_reserved name then + let name = unwrap_uppercase_exotic name in + if Js_reserved_map.is_js_keyword name || Js_reserved_map.is_js_global name then "$$" ^ name else name_mangle name diff --git a/jscomp/ext/js_reserved_map.ml b/jscomp/ext/js_reserved_map.ml index a5eaeeca91..8918dabd1d 100644 --- a/jscomp/ext/js_reserved_map.ml +++ b/jscomp/ext/js_reserved_map.ml @@ -1,4 +1,3 @@ - (* Copyright (C) 2019-Present Hongbo Zhang, Authors of ReScript * * This program is free software: you can redistribute it and/or modify @@ -23,798 +22,198 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -let sorted_keywords = [| - "AbortController"; - "AbortSignal"; - "AbstractRange"; - "ActiveXObject"; +module STbl = struct + include Hashtbl.Make (String) + + let of_array arr = + let tbl = create (Array.length arr) in + let () = Array.iter (fun el -> add tbl el ()) arr in + tbl +end + +(** Words that can never be identifier's name. + + See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#reserved_words + *) +let js_keywords = STbl.of_array [| + "break"; + "case"; + "catch"; + "class"; + "const"; + "continue"; + "debugger"; + "default"; + "delete"; + "do"; + "else"; + "export"; + "extends"; + "false"; + "finally"; + "for"; + "function"; + "if"; + "import"; + "in"; + "instanceof"; + "new"; + "null"; + "return"; + "super"; + "switch"; + "this"; + "throw"; + "true"; + "try"; + "typeof"; + "var"; + "void"; + "while"; + "with"; + (* The following are also reserved in strict context, including ESM *) + "let"; + "static"; + "yield"; + (* `await` is reserved in async context, including ESM *) + "await"; + (* Future reserved words *) + "enum"; + "implements"; + "interface"; + "package"; + "private"; + "protected"; + "public"; +|] + +let is_js_keyword s = STbl.mem js_keywords s + +(** Identifiers with special meanings. + + They can have different meanings depending on the context when used as identifier names, so it should be done carefully. + + See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#identifiers_with_special_meanings + + However, these names are actually used with no problems today. Preventing this can be annoying. + *) +let js_special_words = STbl.of_array [| + "arguments"; + "as"; + "async"; + "eval"; + "from"; + "get"; + "of"; + "set"; +|] + +let is_js_special_word s = STbl.mem js_special_words s + +(** Identifier names _might_ need to care about *) +let js_globals = STbl.of_array [| + (* JavaScript standards built-ins + See https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects + *) "AggregateError"; - "AnalyserNode"; - "Animation"; - "AnimationEffect"; - "AnimationEvent"; - "AnimationPlaybackEvent"; - "AnimationTimeline"; "Array"; "ArrayBuffer"; + "AsyncFunction"; + "AsyncGenerator"; + "AsyncGeneratorFunction"; + "AsyncIterator"; "Atomics"; - "Attr"; - "Audio"; - "AudioBuffer"; - "AudioBufferSourceNode"; - "AudioContext"; - "AudioData"; - "AudioDestinationNode"; - "AudioListener"; - "AudioNode"; - "AudioParam"; - "AudioParamMap"; - "AudioProcessingEvent"; - "AudioScheduledSourceNode"; - "AudioSinkInfo"; - "AudioWorkletNode"; - "BackgroundFetchManager"; - "BackgroundFetchRecord"; - "BackgroundFetchRegistration"; - "BarProp"; - "BaseAudioContext"; - "BeforeInstallPromptEvent"; - "BeforeUnloadEvent"; "BigInt"; "BigInt64Array"; "BigUint64Array"; - "BiquadFilterNode"; - "Blob"; - "BlobEvent"; - "BluetoothUUID"; "Boolean"; - "BroadcastChannel"; - "BrowserCaptureMediaStreamTrack"; - "Buffer"; - "Bun"; - "ByteLengthQueuingStrategy"; - "CDATASection"; - "CSS"; - "CSSAnimation"; - "CSSConditionRule"; - "CSSContainerRule"; - "CSSCounterStyleRule"; - "CSSFontFaceRule"; - "CSSFontPaletteValuesRule"; - "CSSGroupingRule"; - "CSSImageValue"; - "CSSImportRule"; - "CSSKeyframeRule"; - "CSSKeyframesRule"; - "CSSKeywordValue"; - "CSSLayerBlockRule"; - "CSSLayerStatementRule"; - "CSSMathClamp"; - "CSSMathInvert"; - "CSSMathMax"; - "CSSMathMin"; - "CSSMathNegate"; - "CSSMathProduct"; - "CSSMathSum"; - "CSSMathValue"; - "CSSMatrixComponent"; - "CSSMediaRule"; - "CSSNamespaceRule"; - "CSSNumericArray"; - "CSSNumericValue"; - "CSSPageRule"; - "CSSPerspective"; - "CSSPositionValue"; - "CSSPropertyRule"; - "CSSRotate"; - "CSSRule"; - "CSSRuleList"; - "CSSScale"; - "CSSSkew"; - "CSSSkewX"; - "CSSSkewY"; - "CSSStyleDeclaration"; - "CSSStyleRule"; - "CSSStyleSheet"; - "CSSStyleValue"; - "CSSSupportsRule"; - "CSSTransformComponent"; - "CSSTransformValue"; - "CSSTransition"; - "CSSTranslate"; - "CSSUnitValue"; - "CSSUnparsedValue"; - "CSSVariableReferenceValue"; - "CanvasCaptureMediaStreamTrack"; - "CanvasGradient"; - "CanvasPattern"; - "CanvasRenderingContext2D"; - "ChannelMergerNode"; - "ChannelSplitterNode"; - "CharacterData"; - "ClipboardEvent"; - "CloseEvent"; - "Comment"; - "CompositionEvent"; - "CompressionStream"; - "ConstantSourceNode"; - "ContentVisibilityAutoStateChangeEvent"; - "ConvolverNode"; - "CountQueuingStrategy"; - "CropTarget"; - "Crypto"; - "CustomElementRegistry"; - "CustomEvent"; - "CustomStateSet"; - "DOMError"; - "DOMException"; - "DOMImplementation"; - "DOMMatrix"; - "DOMMatrixReadOnly"; - "DOMParser"; - "DOMPoint"; - "DOMPointReadOnly"; - "DOMQuad"; - "DOMRect"; - "DOMRectList"; - "DOMRectReadOnly"; - "DOMStringList"; - "DOMStringMap"; - "DOMTokenList"; - "DataTransfer"; - "DataTransferItem"; - "DataTransferItemList"; "DataView"; "Date"; - "DecompressionStream"; - "DelayNode"; - "DelegatedInkTrailPresenter"; - "Deno"; - "Document"; - "DocumentFragment"; - "DocumentPictureInPictureEvent"; - "DocumentTimeline"; - "DocumentType"; - "DragEvent"; - "DynamicsCompressorNode"; - "Element"; - "ElementInternals"; - "EncodedAudioChunk"; - "EncodedVideoChunk"; + "decodeURI"; + "decodeURIComponent"; + "encodeURI"; + "encodeURIComponent"; "Error"; - "ErrorEvent"; + "eval"; "EvalError"; - "Event"; - "EventCounts"; - "EventSource"; - "EventTarget"; - "External"; - "FeaturePolicy"; - "File"; - "FileList"; - "FileReader"; "FinalizationRegistry"; + "Float16Array"; "Float32Array"; "Float64Array"; - "FocusEvent"; - "FontFace"; - "FontFaceSetLoadEvent"; - "FormData"; - "FormDataEvent"; - "FragmentDirective"; "Function"; - "GainNode"; - "Gamepad"; - "GamepadButton"; - "GamepadEvent"; - "GamepadHapticActuator"; - "Geolocation"; - "GeolocationCoordinates"; - "GeolocationPosition"; - "GeolocationPositionError"; - "HTMLAllCollection"; - "HTMLAnchorElement"; - "HTMLAreaElement"; - "HTMLAudioElement"; - "HTMLBRElement"; - "HTMLBaseElement"; - "HTMLBodyElement"; - "HTMLButtonElement"; - "HTMLCanvasElement"; - "HTMLCollection"; - "HTMLDListElement"; - "HTMLDataElement"; - "HTMLDataListElement"; - "HTMLDetailsElement"; - "HTMLDialogElement"; - "HTMLDirectoryElement"; - "HTMLDivElement"; - "HTMLDocument"; - "HTMLElement"; - "HTMLEmbedElement"; - "HTMLFieldSetElement"; - "HTMLFontElement"; - "HTMLFormControlsCollection"; - "HTMLFormElement"; - "HTMLFrameElement"; - "HTMLFrameSetElement"; - "HTMLHRElement"; - "HTMLHeadElement"; - "HTMLHeadingElement"; - "HTMLHtmlElement"; - "HTMLIFrameElement"; - "HTMLImageElement"; - "HTMLInputElement"; - "HTMLLIElement"; - "HTMLLabelElement"; - "HTMLLegendElement"; - "HTMLLinkElement"; - "HTMLMapElement"; - "HTMLMarqueeElement"; - "HTMLMediaElement"; - "HTMLMenuElement"; - "HTMLMetaElement"; - "HTMLMeterElement"; - "HTMLModElement"; - "HTMLOListElement"; - "HTMLObjectElement"; - "HTMLOptGroupElement"; - "HTMLOptionElement"; - "HTMLOptionsCollection"; - "HTMLOutputElement"; - "HTMLParagraphElement"; - "HTMLParamElement"; - "HTMLPictureElement"; - "HTMLPreElement"; - "HTMLProgressElement"; - "HTMLQuoteElement"; - "HTMLScriptElement"; - "HTMLSelectElement"; - "HTMLSlotElement"; - "HTMLSourceElement"; - "HTMLSpanElement"; - "HTMLStyleElement"; - "HTMLTableCaptionElement"; - "HTMLTableCellElement"; - "HTMLTableColElement"; - "HTMLTableElement"; - "HTMLTableRowElement"; - "HTMLTableSectionElement"; - "HTMLTemplateElement"; - "HTMLTextAreaElement"; - "HTMLTimeElement"; - "HTMLTitleElement"; - "HTMLTrackElement"; - "HTMLUListElement"; - "HTMLUnknownElement"; - "HTMLVideoElement"; - "HashChangeEvent"; - "Headers"; - "Highlight"; - "HighlightRegistry"; - "History"; - "IDBCursor"; - "IDBCursorWithValue"; - "IDBDatabase"; - "IDBFactory"; - "IDBIndex"; - "IDBKeyRange"; - "IDBObjectStore"; - "IDBOpenDBRequest"; - "IDBRequest"; - "IDBTransaction"; - "IDBVersionChangeEvent"; - "IIRFilterNode"; - "IdleDeadline"; - "Image"; - "ImageBitmap"; - "ImageBitmapRenderingContext"; - "ImageCapture"; - "ImageData"; - "ImageTrack"; - "ImageTrackList"; + "Generator"; + "GeneratorFunction"; + "globalThis"; "Infinity"; - "Ink"; - "InputDeviceCapabilities"; - "InputDeviceInfo"; - "InputEvent"; "Int16Array"; "Int32Array"; "Int8Array"; - "IntersectionObserver"; - "IntersectionObserverEntry"; "Intl"; + "isFinite"; + "isNaN"; + "Iterator"; "JSON"; - "KeyboardEvent"; - "KeyframeEffect"; - "LargestContentfulPaint"; - "LaunchParams"; - "LaunchQueue"; - "LayoutShift"; - "LayoutShiftAttribution"; - "Location"; "Map"; "Math"; - "MathMLElement"; - "MediaCapabilities"; - "MediaElementAudioSourceNode"; - "MediaEncryptedEvent"; - "MediaError"; - "MediaList"; - "MediaMetadata"; - "MediaQueryList"; - "MediaQueryListEvent"; - "MediaRecorder"; - "MediaSession"; - "MediaSource"; - "MediaSourceHandle"; - "MediaStream"; - "MediaStreamAudioDestinationNode"; - "MediaStreamAudioSourceNode"; - "MediaStreamEvent"; - "MediaStreamTrack"; - "MediaStreamTrackEvent"; - "MediaStreamTrackGenerator"; - "MediaStreamTrackProcessor"; - "MessageChannel"; - "MessageEvent"; - "MessagePort"; - "MimeType"; - "MimeTypeArray"; - "MouseEvent"; - "MutationEvent"; - "MutationObserver"; - "MutationRecord"; "NaN"; - "NamedNodeMap"; - "NavigateEvent"; - "Navigation"; - "NavigationCurrentEntryChangeEvent"; - "NavigationDestination"; - "NavigationHistoryEntry"; - "NavigationTransition"; - "Navigator"; - "NavigatorUAData"; - "NetworkInformation"; - "Node"; - "NodeFilter"; - "NodeIterator"; - "NodeList"; - "Notification"; "Number"; "Object"; - "OfflineAudioCompletionEvent"; - "OfflineAudioContext"; - "OffscreenCanvas"; - "OffscreenCanvasRenderingContext2D"; - "Option"; - "OscillatorNode"; - "OverconstrainedError"; - "PageTransitionEvent"; - "PannerNode"; - "Path2D"; - "PaymentManager"; - "PaymentRequestUpdateEvent"; - "Performance"; - "PerformanceElementTiming"; - "PerformanceEntry"; - "PerformanceEventTiming"; - "PerformanceLongTaskTiming"; - "PerformanceMark"; - "PerformanceMeasure"; - "PerformanceNavigation"; - "PerformanceNavigationTiming"; - "PerformanceObserver"; - "PerformanceObserverEntryList"; - "PerformancePaintTiming"; - "PerformanceResourceTiming"; - "PerformanceServerTiming"; - "PerformanceTiming"; - "PeriodicSyncManager"; - "PeriodicWave"; - "PermissionStatus"; - "Permissions"; - "PictureInPictureEvent"; - "PictureInPictureWindow"; - "Plugin"; - "PluginArray"; - "PointerEvent"; - "PopStateEvent"; - "ProcessingInstruction"; - "Profiler"; - "ProgressEvent"; + "parseFloat"; + "parseInt"; "Promise"; - "PromiseRejectionEvent"; "Proxy"; - "PushManager"; - "PushSubscription"; - "PushSubscriptionOptions"; - "RTCCertificate"; - "RTCDTMFSender"; - "RTCDTMFToneChangeEvent"; - "RTCDataChannel"; - "RTCDataChannelEvent"; - "RTCDtlsTransport"; - "RTCEncodedAudioFrame"; - "RTCEncodedVideoFrame"; - "RTCError"; - "RTCErrorEvent"; - "RTCIceCandidate"; - "RTCIceTransport"; - "RTCPeerConnection"; - "RTCPeerConnectionIceErrorEvent"; - "RTCPeerConnectionIceEvent"; - "RTCRtpReceiver"; - "RTCRtpSender"; - "RTCRtpTransceiver"; - "RTCSctpTransport"; - "RTCSessionDescription"; - "RTCStatsReport"; - "RTCTrackEvent"; - "RadioNodeList"; - "Range"; "RangeError"; - "ReadableByteStreamController"; - "ReadableStream"; - "ReadableStreamBYOBReader"; - "ReadableStreamBYOBRequest"; - "ReadableStreamDefaultController"; - "ReadableStreamDefaultReader"; "ReferenceError"; "Reflect"; "RegExp"; - "RemotePlayback"; - "ReportingObserver"; - "Request"; - "ResizeObserver"; - "ResizeObserverEntry"; - "ResizeObserverSize"; - "Response"; - "SVGAElement"; - "SVGAngle"; - "SVGAnimateElement"; - "SVGAnimateMotionElement"; - "SVGAnimateTransformElement"; - "SVGAnimatedAngle"; - "SVGAnimatedBoolean"; - "SVGAnimatedEnumeration"; - "SVGAnimatedInteger"; - "SVGAnimatedLength"; - "SVGAnimatedLengthList"; - "SVGAnimatedNumber"; - "SVGAnimatedNumberList"; - "SVGAnimatedPreserveAspectRatio"; - "SVGAnimatedRect"; - "SVGAnimatedString"; - "SVGAnimatedTransformList"; - "SVGAnimationElement"; - "SVGCircleElement"; - "SVGClipPathElement"; - "SVGComponentTransferFunctionElement"; - "SVGDefsElement"; - "SVGDescElement"; - "SVGElement"; - "SVGEllipseElement"; - "SVGFEBlendElement"; - "SVGFEColorMatrixElement"; - "SVGFEComponentTransferElement"; - "SVGFECompositeElement"; - "SVGFEConvolveMatrixElement"; - "SVGFEDiffuseLightingElement"; - "SVGFEDisplacementMapElement"; - "SVGFEDistantLightElement"; - "SVGFEDropShadowElement"; - "SVGFEFloodElement"; - "SVGFEFuncAElement"; - "SVGFEFuncBElement"; - "SVGFEFuncGElement"; - "SVGFEFuncRElement"; - "SVGFEGaussianBlurElement"; - "SVGFEImageElement"; - "SVGFEMergeElement"; - "SVGFEMergeNodeElement"; - "SVGFEMorphologyElement"; - "SVGFEOffsetElement"; - "SVGFEPointLightElement"; - "SVGFESpecularLightingElement"; - "SVGFESpotLightElement"; - "SVGFETileElement"; - "SVGFETurbulenceElement"; - "SVGFilterElement"; - "SVGForeignObjectElement"; - "SVGGElement"; - "SVGGeometryElement"; - "SVGGradientElement"; - "SVGGraphicsElement"; - "SVGImageElement"; - "SVGLength"; - "SVGLengthList"; - "SVGLineElement"; - "SVGLinearGradientElement"; - "SVGMPathElement"; - "SVGMarkerElement"; - "SVGMaskElement"; - "SVGMatrix"; - "SVGMetadataElement"; - "SVGNumber"; - "SVGNumberList"; - "SVGPathElement"; - "SVGPatternElement"; - "SVGPoint"; - "SVGPointList"; - "SVGPolygonElement"; - "SVGPolylineElement"; - "SVGPreserveAspectRatio"; - "SVGRadialGradientElement"; - "SVGRect"; - "SVGRectElement"; - "SVGSVGElement"; - "SVGScriptElement"; - "SVGSetElement"; - "SVGStopElement"; - "SVGStringList"; - "SVGStyleElement"; - "SVGSwitchElement"; - "SVGSymbolElement"; - "SVGTSpanElement"; - "SVGTextContentElement"; - "SVGTextElement"; - "SVGTextPathElement"; - "SVGTextPositioningElement"; - "SVGTitleElement"; - "SVGTransform"; - "SVGTransformList"; - "SVGUnitTypes"; - "SVGUseElement"; - "SVGViewElement"; - "Scheduler"; - "Scheduling"; - "Screen"; - "ScreenOrientation"; - "ScriptProcessorNode"; - "ScrollTimeline"; - "SecurityPolicyViolationEvent"; - "Selection"; "Set"; - "ShadowRoot"; - "SharedWorker"; - "SourceBuffer"; - "SourceBufferList"; - "SpeechSynthesisErrorEvent"; - "SpeechSynthesisEvent"; - "SpeechSynthesisUtterance"; - "StaticRange"; - "StereoPannerNode"; - "Storage"; - "StorageEvent"; + "SharedArrayBuffer"; "String"; - "StylePropertyMap"; - "StylePropertyMapReadOnly"; - "StyleSheet"; - "StyleSheetList"; - "SubmitEvent"; "Symbol"; - "SyncManager"; "SyntaxError"; - "TaskAttributionTiming"; - "TaskController"; - "TaskPriorityChangeEvent"; - "TaskSignal"; - "Text"; - "TextDecoder"; - "TextDecoderStream"; - "TextEncoder"; - "TextEncoderStream"; - "TextEvent"; - "TextMetrics"; - "TextTrack"; - "TextTrackCue"; - "TextTrackCueList"; - "TextTrackList"; - "TimeRanges"; - "ToggleEvent"; - "Touch"; - "TouchEvent"; - "TouchList"; - "TrackEvent"; - "TransformStream"; - "TransformStreamDefaultController"; - "TransitionEvent"; - "TreeWalker"; - "TrustedHTML"; - "TrustedScript"; - "TrustedScriptURL"; - "TrustedTypePolicy"; - "TrustedTypePolicyFactory"; + "TypedArray"; "TypeError"; - "UIEvent"; - "URIError"; - "URL"; - "URLPattern"; - "URLSearchParams"; "Uint16Array"; "Uint32Array"; "Uint8Array"; "Uint8ClampedArray"; - "UserActivation"; - "VTTCue"; - "ValidityState"; - "VideoColorSpace"; - "VideoFrame"; - "VideoPlaybackQuality"; - "ViewTimeline"; - "ViewTransition"; - "VirtualKeyboardGeometryChangeEvent"; - "VisibilityStateEntry"; - "VisualViewport"; - "WaveShaperNode"; + "undefined"; + "URIError"; "WeakMap"; "WeakRef"; "WeakSet"; - "WebAssembly"; - "WebGL2RenderingContext"; - "WebGLActiveInfo"; - "WebGLBuffer"; - "WebGLContextEvent"; - "WebGLFramebuffer"; - "WebGLProgram"; - "WebGLQuery"; - "WebGLRenderbuffer"; - "WebGLRenderingContext"; - "WebGLSampler"; - "WebGLShader"; - "WebGLShaderPrecisionFormat"; - "WebGLSync"; - "WebGLTexture"; - "WebGLTransformFeedback"; - "WebGLUniformLocation"; - "WebGLVertexArrayObject"; - "WebKitCSSMatrix"; - "WebKitMutationObserver"; - "WebSocket"; - "WheelEvent"; - "Window"; - "WindowControlsOverlay"; - "WindowControlsOverlayGeometryChangeEvent"; - "Worker"; - "WritableStream"; - "WritableStreamDefaultController"; - "WritableStreamDefaultWriter"; - "XDomainRequest"; - "XMLDocument"; - "XMLHttpRequest"; - "XMLHttpRequestEventTarget"; - "XMLHttpRequestUpload"; - "XMLSerializer"; - "XPathEvaluator"; - "XPathExpression"; - "XPathResult"; - "XSLTProcessor"; - "__dirname"; - "__esModule"; - "__filename"; - "abstract"; - "arguments"; - "await"; - "boolean"; - "break"; - "byte"; - "case"; - "catch"; - "char"; - "class"; - "clearImmediate"; - "clearInterval"; - "clearTimeout"; - "console"; - "const"; - "continue"; - "debugger"; - "decodeURI"; - "decodeURIComponent"; - "default"; - "delete"; - "do"; + + (* A few of the HTML standard globals + + See https://developer.mozilla.org/en-US/docs/Web/API/Window + See https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope + + But we don't actually need to protect these names. + + "window"; + "self"; "document"; - "double"; - "else"; - "encodeURI"; - "encodeURIComponent"; - "enum"; - "escape"; - "eval"; - "event"; - "export"; - "exports"; - "extends"; - "false"; - "fetch"; - "final"; - "finally"; - "float"; - "for"; - "function"; - "global"; - "goto"; - "if"; - "implements"; - "import"; - "in"; - "instanceof"; - "int"; - "interface"; - "isFinite"; - "isNaN"; - "let"; "location"; - "long"; - "module"; - "native"; "navigator"; - "new"; - "null"; - "package"; - "parseFloat"; - "parseInt"; - "private"; - "process"; - "protected"; - "public"; - "require"; - "return"; - "setImmediate"; - "setInterval"; - "setTimeout"; - "short"; - "static"; - "super"; - "switch"; - "synchronized"; - "this"; - "throw"; - "transient"; - "true"; - "try"; - "typeof"; - "undefined"; - "unescape"; - "var"; - "void"; - "volatile"; - "while"; - "window"; - "with"; - "yield"; - |] - + "origin"; + *) -type element = string + (* A few of the Node.js globals + + Specifically related to the CommonJS module system + They cannot be redeclared in nested scope. + *) + "__dirname"; + "__filename"; + "require"; + "module"; + "exports"; -let rec binary_search_aux (arr : element array) (lo : int) (hi : int) key : bool = - let mid = (lo + hi)/2 in - let mid_val = Array.unsafe_get arr mid in - (* let c = cmp key midVal [@bs] in *) - if key = mid_val then true - else if key < mid_val then (* a[lo] =< key < a[mid] <= a[hi] *) - if hi = mid then - (Array.unsafe_get arr lo) = key - else binary_search_aux arr lo mid key - else (* a[lo] =< a[mid] < key <= a[hi] *) - if lo = mid then - (Array.unsafe_get arr hi) = key - else binary_search_aux arr mid hi key + (* Bun's global namespace *) + "Bun"; -let binary_search (sorted : element array) (key : element) : bool = - let len = Array.length sorted in - if len = 0 then false - else - let lo = Array.unsafe_get sorted 0 in - (* let c = cmp key lo [@bs] in *) - if key < lo then false - else - let hi = Array.unsafe_get sorted (len - 1) in - (* let c2 = cmp key hi [@bs]in *) - if key > hi then false - else binary_search_aux sorted 0 (len - 1) key + (* Deno's global namespace *) + "Deno"; +|] -let is_reserved s = binary_search sorted_keywords s +let is_js_global s = STbl.mem js_globals s diff --git a/jscomp/ext/js_reserved_map.mli b/jscomp/ext/js_reserved_map.mli index 072737f89c..cf4e1cb2bd 100644 --- a/jscomp/ext/js_reserved_map.mli +++ b/jscomp/ext/js_reserved_map.mli @@ -22,4 +22,8 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -val is_reserved : string -> bool +val is_js_keyword: string -> bool + +val is_js_special_word: string -> bool + +val is_js_global: string -> bool diff --git a/jscomp/keywords.list b/jscomp/keywords.list deleted file mode 100644 index b51740d007..0000000000 --- a/jscomp/keywords.list +++ /dev/null @@ -1,661 +0,0 @@ -AbortController -AbortSignal -AbstractRange -AggregateError -AnalyserNode -Animation -AnimationEffect -AnimationEvent -AnimationPlaybackEvent -AnimationTimeline -Array -ArrayBuffer -Atomics -Attr -Audio -AudioBuffer -AudioBufferSourceNode -AudioContext -AudioData -AudioDestinationNode -AudioListener -AudioNode -AudioParam -AudioParamMap -AudioProcessingEvent -AudioScheduledSourceNode -AudioSinkInfo -AudioWorkletNode -BackgroundFetchManager -BackgroundFetchRecord -BackgroundFetchRegistration -BarProp -BaseAudioContext -BeforeInstallPromptEvent -BeforeUnloadEvent -BigInt -BigInt64Array -BigUint64Array -BiquadFilterNode -Blob -BlobEvent -BluetoothUUID -Boolean -BroadcastChannel -BrowserCaptureMediaStreamTrack -ByteLengthQueuingStrategy -CDATASection -CSS -CSSAnimation -CSSConditionRule -CSSContainerRule -CSSCounterStyleRule -CSSFontFaceRule -CSSFontPaletteValuesRule -CSSGroupingRule -CSSImageValue -CSSImportRule -CSSKeyframeRule -CSSKeyframesRule -CSSKeywordValue -CSSLayerBlockRule -CSSLayerStatementRule -CSSMathClamp -CSSMathInvert -CSSMathMax -CSSMathMin -CSSMathNegate -CSSMathProduct -CSSMathSum -CSSMathValue -CSSMatrixComponent -CSSMediaRule -CSSNamespaceRule -CSSNumericArray -CSSNumericValue -CSSPageRule -CSSPerspective -CSSPositionValue -CSSPropertyRule -CSSRotate -CSSRule -CSSRuleList -CSSScale -CSSSkew -CSSSkewX -CSSSkewY -CSSStyleDeclaration -CSSStyleRule -CSSStyleSheet -CSSStyleValue -CSSSupportsRule -CSSTransformComponent -CSSTransformValue -CSSTransition -CSSTranslate -CSSUnitValue -CSSUnparsedValue -CSSVariableReferenceValue -CanvasCaptureMediaStreamTrack -CanvasGradient -CanvasPattern -CanvasRenderingContext2D -ChannelMergerNode -ChannelSplitterNode -CharacterData -ClipboardEvent -CloseEvent -Comment -CompositionEvent -CompressionStream -ConstantSourceNode -ContentVisibilityAutoStateChangeEvent -ConvolverNode -CountQueuingStrategy -CropTarget -Crypto -CustomElementRegistry -CustomEvent -CustomStateSet -DOMError -DOMException -DOMImplementation -DOMMatrix -DOMMatrixReadOnly -DOMParser -DOMPoint -DOMPointReadOnly -DOMQuad -DOMRect -DOMRectList -DOMRectReadOnly -DOMStringList -DOMStringMap -DOMTokenList -DataTransfer -DataTransferItem -DataTransferItemList -DataView -Date -DecompressionStream -DelayNode -DelegatedInkTrailPresenter -Document -DocumentFragment -DocumentPictureInPictureEvent -DocumentTimeline -DocumentType -DragEvent -DynamicsCompressorNode -Element -ElementInternals -EncodedAudioChunk -EncodedVideoChunk -Error -ErrorEvent -EvalError -Event -EventCounts -EventSource -EventTarget -External -FeaturePolicy -File -FileList -FileReader -FinalizationRegistry -Float32Array -Float64Array -FocusEvent -FontFace -FontFaceSetLoadEvent -FormData -FormDataEvent -FragmentDirective -Function -GainNode -Gamepad -GamepadButton -GamepadEvent -GamepadHapticActuator -Geolocation -GeolocationCoordinates -GeolocationPosition -GeolocationPositionError -HTMLAllCollection -HTMLAnchorElement -HTMLAreaElement -HTMLAudioElement -HTMLBRElement -HTMLBaseElement -HTMLBodyElement -HTMLButtonElement -HTMLCanvasElement -HTMLCollection -HTMLDListElement -HTMLDataElement -HTMLDataListElement -HTMLDetailsElement -HTMLDialogElement -HTMLDirectoryElement -HTMLDivElement -HTMLDocument -HTMLElement -HTMLEmbedElement -HTMLFieldSetElement -HTMLFontElement -HTMLFormControlsCollection -HTMLFormElement -HTMLFrameElement -HTMLFrameSetElement -HTMLHRElement -HTMLHeadElement -HTMLHeadingElement -HTMLHtmlElement -HTMLIFrameElement -HTMLImageElement -HTMLInputElement -HTMLLIElement -HTMLLabelElement -HTMLLegendElement -HTMLLinkElement -HTMLMapElement -HTMLMarqueeElement -HTMLMediaElement -HTMLMenuElement -HTMLMetaElement -HTMLMeterElement -HTMLModElement -HTMLOListElement -HTMLObjectElement -HTMLOptGroupElement -HTMLOptionElement -HTMLOptionsCollection -HTMLOutputElement -HTMLParagraphElement -HTMLParamElement -HTMLPictureElement -HTMLPreElement -HTMLProgressElement -HTMLQuoteElement -HTMLScriptElement -HTMLSelectElement -HTMLSlotElement -HTMLSourceElement -HTMLSpanElement -HTMLStyleElement -HTMLTableCaptionElement -HTMLTableCellElement -HTMLTableColElement -HTMLTableElement -HTMLTableRowElement -HTMLTableSectionElement -HTMLTemplateElement -HTMLTextAreaElement -HTMLTimeElement -HTMLTitleElement -HTMLTrackElement -HTMLUListElement -HTMLUnknownElement -HTMLVideoElement -HashChangeEvent -Headers -Highlight -HighlightRegistry -History -IDBCursor -IDBCursorWithValue -IDBDatabase -IDBFactory -IDBIndex -IDBKeyRange -IDBObjectStore -IDBOpenDBRequest -IDBRequest -IDBTransaction -IDBVersionChangeEvent -IIRFilterNode -IdleDeadline -Image -ImageBitmap -ImageBitmapRenderingContext -ImageCapture -ImageData -ImageTrack -ImageTrackList -Infinity -Ink -InputDeviceCapabilities -InputDeviceInfo -InputEvent -Int16Array -Int32Array -Int8Array -IntersectionObserver -IntersectionObserverEntry -Intl -JSON -KeyboardEvent -KeyframeEffect -LargestContentfulPaint -LaunchParams -LaunchQueue -LayoutShift -LayoutShiftAttribution -Location -Map -Math -MathMLElement -MediaCapabilities -MediaElementAudioSourceNode -MediaEncryptedEvent -MediaError -MediaList -MediaMetadata -MediaQueryList -MediaQueryListEvent -MediaRecorder -MediaSession -MediaSource -MediaSourceHandle -MediaStream -MediaStreamAudioDestinationNode -MediaStreamAudioSourceNode -MediaStreamEvent -MediaStreamTrack -MediaStreamTrackEvent -MediaStreamTrackGenerator -MediaStreamTrackProcessor -MessageChannel -MessageEvent -MessagePort -MimeType -MimeTypeArray -MouseEvent -MutationEvent -MutationObserver -MutationRecord -NaN -NamedNodeMap -NavigateEvent -Navigation -NavigationCurrentEntryChangeEvent -NavigationDestination -NavigationHistoryEntry -NavigationTransition -Navigator -NavigatorUAData -NetworkInformation -Node -NodeFilter -NodeIterator -NodeList -Notification -Number -Object -OfflineAudioCompletionEvent -OfflineAudioContext -OffscreenCanvas -OffscreenCanvasRenderingContext2D -Option -OscillatorNode -OverconstrainedError -PageTransitionEvent -PannerNode -Path2D -PaymentManager -PaymentRequestUpdateEvent -Performance -PerformanceElementTiming -PerformanceEntry -PerformanceEventTiming -PerformanceLongTaskTiming -PerformanceMark -PerformanceMeasure -PerformanceNavigation -PerformanceNavigationTiming -PerformanceObserver -PerformanceObserverEntryList -PerformancePaintTiming -PerformanceResourceTiming -PerformanceServerTiming -PerformanceTiming -PeriodicSyncManager -PeriodicWave -PermissionStatus -Permissions -PictureInPictureEvent -PictureInPictureWindow -Plugin -PluginArray -PointerEvent -PopStateEvent -ProcessingInstruction -Profiler -ProgressEvent -Promise -PromiseRejectionEvent -Proxy -PushManager -PushSubscription -PushSubscriptionOptions -RTCCertificate -RTCDTMFSender -RTCDTMFToneChangeEvent -RTCDataChannel -RTCDataChannelEvent -RTCDtlsTransport -RTCEncodedAudioFrame -RTCEncodedVideoFrame -RTCError -RTCErrorEvent -RTCIceCandidate -RTCIceTransport -RTCPeerConnection -RTCPeerConnectionIceErrorEvent -RTCPeerConnectionIceEvent -RTCRtpReceiver -RTCRtpSender -RTCRtpTransceiver -RTCSctpTransport -RTCSessionDescription -RTCStatsReport -RTCTrackEvent -RadioNodeList -Range -RangeError -ReadableByteStreamController -ReadableStream -ReadableStreamBYOBReader -ReadableStreamBYOBRequest -ReadableStreamDefaultController -ReadableStreamDefaultReader -ReferenceError -Reflect -RegExp -RemotePlayback -ReportingObserver -Request -ResizeObserver -ResizeObserverEntry -ResizeObserverSize -Response -SVGAElement -SVGAngle -SVGAnimateElement -SVGAnimateMotionElement -SVGAnimateTransformElement -SVGAnimatedAngle -SVGAnimatedBoolean -SVGAnimatedEnumeration -SVGAnimatedInteger -SVGAnimatedLength -SVGAnimatedLengthList -SVGAnimatedNumber -SVGAnimatedNumberList -SVGAnimatedPreserveAspectRatio -SVGAnimatedRect -SVGAnimatedString -SVGAnimatedTransformList -SVGAnimationElement -SVGCircleElement -SVGClipPathElement -SVGComponentTransferFunctionElement -SVGDefsElement -SVGDescElement -SVGElement -SVGEllipseElement -SVGFEBlendElement -SVGFEColorMatrixElement -SVGFEComponentTransferElement -SVGFECompositeElement -SVGFEConvolveMatrixElement -SVGFEDiffuseLightingElement -SVGFEDisplacementMapElement -SVGFEDistantLightElement -SVGFEDropShadowElement -SVGFEFloodElement -SVGFEFuncAElement -SVGFEFuncBElement -SVGFEFuncGElement -SVGFEFuncRElement -SVGFEGaussianBlurElement -SVGFEImageElement -SVGFEMergeElement -SVGFEMergeNodeElement -SVGFEMorphologyElement -SVGFEOffsetElement -SVGFEPointLightElement -SVGFESpecularLightingElement -SVGFESpotLightElement -SVGFETileElement -SVGFETurbulenceElement -SVGFilterElement -SVGForeignObjectElement -SVGGElement -SVGGeometryElement -SVGGradientElement -SVGGraphicsElement -SVGImageElement -SVGLength -SVGLengthList -SVGLineElement -SVGLinearGradientElement -SVGMPathElement -SVGMarkerElement -SVGMaskElement -SVGMatrix -SVGMetadataElement -SVGNumber -SVGNumberList -SVGPathElement -SVGPatternElement -SVGPoint -SVGPointList -SVGPolygonElement -SVGPolylineElement -SVGPreserveAspectRatio -SVGRadialGradientElement -SVGRect -SVGRectElement -SVGSVGElement -SVGScriptElement -SVGSetElement -SVGStopElement -SVGStringList -SVGStyleElement -SVGSwitchElement -SVGSymbolElement -SVGTSpanElement -SVGTextContentElement -SVGTextElement -SVGTextPathElement -SVGTextPositioningElement -SVGTitleElement -SVGTransform -SVGTransformList -SVGUnitTypes -SVGUseElement -SVGViewElement -Scheduler -Scheduling -Screen -ScreenOrientation -ScriptProcessorNode -ScrollTimeline -SecurityPolicyViolationEvent -Selection -Set -ShadowRoot -SharedWorker -SourceBuffer -SourceBufferList -SpeechSynthesisErrorEvent -SpeechSynthesisEvent -SpeechSynthesisUtterance -StaticRange -StereoPannerNode -Storage -StorageEvent -String -StylePropertyMap -StylePropertyMapReadOnly -StyleSheet -StyleSheetList -SubmitEvent -Symbol -SyncManager -SyntaxError -TaskAttributionTiming -TaskController -TaskPriorityChangeEvent -TaskSignal -Text -TextDecoder -TextDecoderStream -TextEncoder -TextEncoderStream -TextEvent -TextMetrics -TextTrack -TextTrackCue -TextTrackCueList -TextTrackList -TimeRanges -ToggleEvent -Touch -TouchEvent -TouchList -TrackEvent -TransformStream -TransformStreamDefaultController -TransitionEvent -TreeWalker -TrustedHTML -TrustedScript -TrustedScriptURL -TrustedTypePolicy -TrustedTypePolicyFactory -TypeError -UIEvent -URIError -URL -URLPattern -URLSearchParams -Uint16Array -Uint32Array -Uint8Array -Uint8ClampedArray -UserActivation -VTTCue -ValidityState -VideoColorSpace -VideoFrame -VideoPlaybackQuality -ViewTimeline -ViewTransition -VirtualKeyboardGeometryChangeEvent -VisibilityStateEntry -VisualViewport -WaveShaperNode -WeakMap -WeakRef -WeakSet -WebAssembly -WebGL2RenderingContext -WebGLActiveInfo -WebGLBuffer -WebGLContextEvent -WebGLFramebuffer -WebGLProgram -WebGLQuery -WebGLRenderbuffer -WebGLRenderingContext -WebGLSampler -WebGLShader -WebGLShaderPrecisionFormat -WebGLSync -WebGLTexture -WebGLTransformFeedback -WebGLUniformLocation -WebGLVertexArrayObject -WebKitCSSMatrix -WebKitMutationObserver -WebSocket -WheelEvent -Window -WindowControlsOverlay -WindowControlsOverlayGeometryChangeEvent -Worker -WritableStream -WritableStreamDefaultController -WritableStreamDefaultWriter -XMLDocument -XMLHttpRequest -XMLHttpRequestEventTarget -XMLHttpRequestUpload -XMLSerializer -XPathEvaluator -XPathExpression -XPathResult -XSLTProcessor \ No newline at end of file diff --git a/jscomp/test/buffer_test.js b/jscomp/test/buffer_test.js index c1268be622..71888e3cba 100644 --- a/jscomp/test/buffer_test.js +++ b/jscomp/test/buffer_test.js @@ -3,7 +3,7 @@ let Mt = require("./mt.js"); let Bytes = require("../../lib/js/bytes.js"); -let $$Buffer = require("../../lib/js/buffer.js"); +let Buffer = require("../../lib/js/buffer.js"); let Caml_bytes = require("../../lib/js/caml_bytes.js"); let Caml_string = require("../../lib/js/caml_string.js"); @@ -49,13 +49,13 @@ let suites_1 = { hd: [ "buffer", (function (param) { - let v = $$Buffer.create(30); + let v = Buffer.create(30); for(let i = 0; i <= 10; ++i){ - $$Buffer.add_string(v, String(i)); + Buffer.add_string(v, String(i)); } return { TAG: "Eq", - _0: $$Buffer.contents(v), + _0: Buffer.contents(v), _1: "012345678910" }; }) diff --git a/jscomp/test/escape_esmodule.js b/jscomp/test/escape_esmodule.js index 3e8d98b76b..4a0d036ebc 100644 --- a/jscomp/test/escape_esmodule.js +++ b/jscomp/test/escape_esmodule.js @@ -2,11 +2,11 @@ 'use strict'; -let $$__esModule = false; +let __esModule = false; let $$default = 4; -exports.$$__esModule = $$__esModule; +exports.__esModule = __esModule; exports.default = $$default; exports.__esModule = true; /* No side effect */ diff --git a/jscomp/test/export_keyword.js b/jscomp/test/export_keyword.js index b69b473b54..7d53aca900 100644 --- a/jscomp/test/export_keyword.js +++ b/jscomp/test/export_keyword.js @@ -4,11 +4,11 @@ let $$case = 3; -let $$window = 2; +let window = 2; let $$switch = 3; exports.$$case = $$case; -exports.$$window = $$window; +exports.window = window; exports.$$switch = $$switch; /* No side effect */ diff --git a/jscomp/test/global_mangles.js b/jscomp/test/global_mangles.js index d34e7b5e60..f7c9ff325a 100644 --- a/jscomp/test/global_mangles.js +++ b/jscomp/test/global_mangles.js @@ -6,42 +6,42 @@ let $$__dirname = 1; let $$__filename = 2; -let $$clearImmediate = 3; +let clearImmediate = 3; -let $$clearInterval = 4; +let clearInterval = 4; -let $$clearTimeout = 5; +let clearTimeout = 5; -let $$console = 6; +let console = 6; let $$exports = 7; -let $$global = 8; +let global = 8; let _module = 9; -let $$process = 10; +let process = 10; let $$require = 11; -let $$setImmediate = 12; +let setImmediate = 12; -let $$setInterval = 13; +let setInterval = 13; -let $$setTimeout = 14; +let setTimeout = 14; exports.$$__dirname = $$__dirname; exports.$$__filename = $$__filename; -exports.$$clearImmediate = $$clearImmediate; -exports.$$clearInterval = $$clearInterval; -exports.$$clearTimeout = $$clearTimeout; -exports.$$console = $$console; +exports.clearImmediate = clearImmediate; +exports.clearInterval = clearInterval; +exports.clearTimeout = clearTimeout; +exports.console = console; exports.$$exports = $$exports; -exports.$$global = $$global; +exports.global = global; exports._module = _module; -exports.$$process = $$process; +exports.process = process; exports.$$require = $$require; -exports.$$setImmediate = $$setImmediate; -exports.$$setInterval = $$setInterval; -exports.$$setTimeout = $$setTimeout; +exports.setImmediate = setImmediate; +exports.setInterval = setInterval; +exports.setTimeout = setTimeout; /* No side effect */ diff --git a/jscomp/test/gpr_2633_test.js b/jscomp/test/gpr_2633_test.js index 850ef7b215..ac7f5d007c 100644 --- a/jscomp/test/gpr_2633_test.js +++ b/jscomp/test/gpr_2633_test.js @@ -3,12 +3,12 @@ let Curry = require("../../lib/js/curry.js"); -function on1(foo, $$event) { - foo.on($$event.NAME, $$event.VAL); +function on1(foo, event) { + foo.on(event.NAME, event.VAL); } -function on2(foo, h, $$event) { - foo.on(Curry._1(h, $$event).NAME, Curry._1(h, $$event).VAL); +function on2(foo, h, event) { + foo.on(Curry._1(h, event).NAME, Curry._1(h, event).VAL); } exports.on1 = on1; diff --git a/jscomp/test/key_word_property.js b/jscomp/test/key_word_property.js index 23bb343a31..57ebfadaa7 100644 --- a/jscomp/test/key_word_property.js +++ b/jscomp/test/key_word_property.js @@ -15,19 +15,19 @@ let oefault = OmeEs6Module; let oefault2 = OmeEs6Module$1.default2; -let $$window = Vscode.window; +let window = Vscode.window; -function mk($$window, $$default) { +function mk(window, $$default) { return { - window: $$window, + window: window, default: $$default }; } -function mk2($$window, $$default) { +function mk2(window, $$default) { return { hd: { - window: $$window, + window: window, default: $$default }, tl: /* [] */0 @@ -47,7 +47,7 @@ let test = { }; function u(param) { - return $$window.switch(); + return window.switch(); } let $$case = 3; @@ -57,7 +57,7 @@ exports.__esModule = true; exports.default2 = default2; exports.oefault = oefault; exports.oefault2 = oefault2; -exports.$$window = $$window; +exports.window = window; exports.mk = mk; exports.mk2 = mk2; exports.des = des; diff --git a/jscomp/test/key_word_property2.js b/jscomp/test/key_word_property2.js index a11df10346..b576e13b98 100644 --- a/jscomp/test/key_word_property2.js +++ b/jscomp/test/key_word_property2.js @@ -19,13 +19,13 @@ function test(p) { let $$case = Export_keyword.$$case; -let $$window = Export_keyword.$$window; +let window = Export_keyword.window; let $$switch = Export_keyword.$$switch; exports.test2 = test2; exports.test = test; exports.$$case = $$case; -exports.$$window = $$window; +exports.window = window; exports.$$switch = $$switch; /* No side effect */ diff --git a/jscomp/test/key_word_property_plus_test.js b/jscomp/test/key_word_property_plus_test.js index c40d94c062..039f59d620 100644 --- a/jscomp/test/key_word_property_plus_test.js +++ b/jscomp/test/key_word_property_plus_test.js @@ -46,7 +46,7 @@ eq("File \"key_word_property_plus_test.res\", line 10, characters 2-9", [ 14 ].reduce((function (prim0, prim1) { return prim0 + prim1 | 0; -}), 0), ((((((((((((Global_mangles.$$__dirname + Global_mangles.$$__filename | 0) + Global_mangles.$$clearImmediate | 0) + Global_mangles.$$clearInterval | 0) + Global_mangles.$$clearTimeout | 0) + Global_mangles.$$console | 0) + Global_mangles.$$exports | 0) + Global_mangles.$$global | 0) + Global_mangles._module | 0) + Global_mangles.$$process | 0) + Global_mangles.$$require | 0) + Global_mangles.$$setImmediate | 0) + Global_mangles.$$setInterval | 0) + Global_mangles.$$setTimeout | 0); +}), 0), ((((((((((((Global_mangles.$$__dirname + Global_mangles.$$__filename | 0) + Global_mangles.clearImmediate | 0) + Global_mangles.clearInterval | 0) + Global_mangles.clearTimeout | 0) + Global_mangles.console | 0) + Global_mangles.$$exports | 0) + Global_mangles.global | 0) + Global_mangles._module | 0) + Global_mangles.process | 0) + Global_mangles.$$require | 0) + Global_mangles.setImmediate | 0) + Global_mangles.setInterval | 0) + Global_mangles.setTimeout | 0); Mt.from_pair_suites("Key_word_property_plus_test", suites.contents); diff --git a/jscomp/test/mario_game.js b/jscomp/test/mario_game.js index cd6c69b564..64ffa43389 100644 --- a/jscomp/test/mario_game.js +++ b/jscomp/test/mario_game.js @@ -772,7 +772,7 @@ function update_vel(part) { part.vel.y = part.vel.y + part.acc.y; } -function $$process(part) { +function process(part) { part.life = part.life - 1 | 0; if (part.life === 0) { part.kill = true; @@ -785,7 +785,7 @@ function $$process(part) { let Particle = { make: make$1, make_score: make_score, - $$process: $$process + process: process }; let id_counter = { @@ -2338,7 +2338,7 @@ function update_loop(canvas, param, map_dim) { run_update_collid(state$1, obj, objs); }), objs); List.iter((function (part) { - $$process(part); + process(part); let x = part.pos.x - state$1.vpt.pos.x; let y = part.pos.y - state$1.vpt.pos.y; render(part.params.sprite, [ @@ -2601,7 +2601,7 @@ function generate_clouds(cbx, cby, typ, num) { function generate_coins(_block_coord) { while(true) { let block_coord = _block_coord; - let place_coin = Random.$$int(2); + let place_coin = Random.int(2); if (!block_coord) { return /* [] */0; } @@ -2630,9 +2630,9 @@ function choose_block_pattern(blockw, blockh, cbx, cby, prob) { if (cbx > blockw || cby > blockh) { return /* [] */0; } - let block_typ = Random.$$int(4); - let stair_typ = Random.$$int(2); - let life_block_chance = Random.$$int(5); + let block_typ = Random.int(4); + let stair_typ = Random.int(2); + let life_block_chance = Random.int(5); let middle_block = life_block_chance === 0 ? 3 : stair_typ; switch (prob) { case 0 : @@ -2698,7 +2698,7 @@ function choose_block_pattern(blockw, blockh, cbx, cby, prob) { }; } case 1 : - let num_clouds = Random.$$int(5) + 5 | 0; + let num_clouds = Random.int(5) + 5 | 0; if (cby < 5) { return generate_clouds(cbx, cby, 2, num_clouds); } else { @@ -3074,7 +3074,7 @@ function generate_enemies(blockw, blockh, _cbx, _cby, acc) { _cby = cby + 1; continue; } - let prob = Random.$$int(30); + let prob = Random.int(30); if (prob < 3 && blockh - 1 === cby) { let enemy_0 = [ prob, @@ -3097,8 +3097,8 @@ function generate_enemies(blockw, blockh, _cbx, _cby, acc) { function generate_block_enemies(_block_coord) { while(true) { let block_coord = _block_coord; - let place_enemy = Random.$$int(20); - let enemy_typ = Random.$$int(3); + let place_enemy = Random.int(20); + let enemy_typ = Random.int(3); if (!block_coord) { return /* [] */0; } @@ -3143,7 +3143,7 @@ function generate_block_locs(blockw, blockh, _cbx, _cby, _acc) { _cby = cby + 1; continue; } - let prob = Random.$$int(100); + let prob = Random.int(100); if (prob < 5) { let newacc = choose_block_pattern(blockw, blockh, cbx, cby, prob); let undup_lst = avoid_overlap(newacc, acc); @@ -3175,7 +3175,7 @@ function generate_ground(blockw, blockh, _inc, _acc) { return acc; } if (inc > 10) { - let skip = Random.$$int(10); + let skip = Random.int(10); let newacc = Pervasives.$at(acc, { hd: [ 4, diff --git a/jscomp/test/ocaml_re_test.js b/jscomp/test/ocaml_re_test.js index 86daf05311..d52abaf351 100644 --- a/jscomp/test/ocaml_re_test.js +++ b/jscomp/test/ocaml_re_test.js @@ -1413,9 +1413,9 @@ function delta_4(c, next_cat, prev_cat, l, rem) { } } -function delta(tbl_ref, next_cat, $$char, st) { +function delta(tbl_ref, next_cat, char, st) { let prev_cat = st.category; - let match = remove_duplicates(/* [] */0, delta_4($$char, next_cat, prev_cat, st.desc, /* [] */0), eps_expr); + let match = remove_duplicates(/* [] */0, delta_4(char, next_cat, prev_cat, st.desc, /* [] */0), eps_expr); let expr$p = match[0]; let idx = free_index(tbl_ref, expr$p); let expr$p$p = set_idx(idx, expr$p); @@ -1598,7 +1598,7 @@ function loop(info, s, pos, st) { }; } -function $$final(info, st, cat) { +function final(info, st, cat) { try { return List.assq(cat, st.final); } @@ -3254,7 +3254,7 @@ function exec_internal(name, posOpt, lenOpt, groups, re, s) { res = status(st.desc); } else { let final_cat = last === slen ? Curry._2(Re_automata_Category.$plus$plus, Re_automata_Category.search_boundary, Re_automata_Category.inexistant) : Curry._2(Re_automata_Category.$plus$plus, Re_automata_Category.search_boundary, category(re, get_color(re, s, last))); - let match = $$final(info, st, final_cat); + let match = final(info, st, final_cat); if (groups) { Caml_array.set(info.positions, match[0], last + 1 | 0); } @@ -3464,7 +3464,7 @@ function parse(multiline, dollar_endonly, dotall, ungreedy, s) { if (s !== /* [] */0 && accept(/* ']' */93)) { return s; } - let match = $$char(); + let match = char(); if (match.NAME === "Char") { let c = match.VAL; if (accept(/* '-' */45)) { @@ -3489,7 +3489,7 @@ function parse(multiline, dollar_endonly, dotall, ungreedy, s) { } }; } - let match$1 = $$char(); + let match$1 = char(); if (match$1.NAME !== "Char") { return { hd: { @@ -3879,7 +3879,7 @@ function parse(multiline, dollar_endonly, dotall, ungreedy, s) { i.contents = i.contents - 1 | 0; return r; }; - let $$char = function (param) { + let char = function (param) { if (i.contents === l) { throw new Error(Parse_error, { cause: { diff --git a/jscomp/test/random_test.js b/jscomp/test/random_test.js index be7890cc8d..6cd6a227ba 100644 --- a/jscomp/test/random_test.js +++ b/jscomp/test/random_test.js @@ -33,7 +33,7 @@ function approx(f) { }; } -Mt_global.collect_neq(id, suites, "File \"random_test.res\", line 9, characters 2-9", (Random.self_init(), Random.$$int(10000)), (Random.self_init(), Random.$$int(1000))); +Mt_global.collect_neq(id, suites, "File \"random_test.res\", line 9, characters 2-9", (Random.self_init(), Random.int(10000)), (Random.self_init(), Random.int(1000))); Random.init(0); @@ -65,7 +65,7 @@ let h = Random.int64([ let vv = Random.bits(); -let xx = Random.$$float(3.0); +let xx = Random.float(3.0); let xxx = Random.int32(103); diff --git a/jscomp/test/reactEvent.js b/jscomp/test/reactEvent.js index 9448ed898f..ad6c3b1c3b 100644 --- a/jscomp/test/reactEvent.js +++ b/jscomp/test/reactEvent.js @@ -16,9 +16,9 @@ let Form = {}; let Mouse = {}; -let $$Selection = {}; +let Selection = {}; -let $$Touch = {}; +let Touch = {}; let UI = {}; @@ -26,9 +26,9 @@ let Wheel = {}; let Media = {}; -let $$Image = {}; +let Image = {}; -let $$Animation = {}; +let Animation = {}; let Transition = {}; @@ -39,12 +39,12 @@ exports.Keyboard = Keyboard; exports.Focus = Focus; exports.Form = Form; exports.Mouse = Mouse; -exports.$$Selection = $$Selection; -exports.$$Touch = $$Touch; +exports.Selection = Selection; +exports.Touch = Touch; exports.UI = UI; exports.Wheel = Wheel; exports.Media = Media; -exports.$$Image = $$Image; -exports.$$Animation = $$Animation; +exports.Image = Image; +exports.Animation = Animation; exports.Transition = Transition; /* No side effect */ diff --git a/jscomp/test/reactTestUtils.js b/jscomp/test/reactTestUtils.js index dca2fa6dfb..b94a28de95 100644 --- a/jscomp/test/reactTestUtils.js +++ b/jscomp/test/reactTestUtils.js @@ -21,21 +21,21 @@ function actAsync(func) { } function changeWithValue(element, value) { - let $$event = { + let event = { target: { value: value } }; - TestUtils.Simulate.change(element, $$event); + TestUtils.Simulate.change(element, event); } function changeWithChecked(element, value) { - let $$event = { + let event = { target: { checked: value } }; - TestUtils.Simulate.change(element, $$event); + TestUtils.Simulate.change(element, event); } let Simulate = { diff --git a/jscomp/test/reasonReactRouter.js b/jscomp/test/reasonReactRouter.js index af82ab9612..b85dea0242 100644 --- a/jscomp/test/reasonReactRouter.js +++ b/jscomp/test/reasonReactRouter.js @@ -8,17 +8,17 @@ function safeMakeEvent(eventName) { if (typeof Event === "function") { return new Event(eventName); } - let $$event = document.createEvent("Event"); - $$event.initEvent(eventName, true, true); - return $$event; + let event = document.createEvent("Event"); + event.initEvent(eventName, true, true); + return event; } function path(param) { - let $$window = typeof window === "undefined" ? undefined : window; - if ($$window === undefined) { + let window = typeof window === "undefined" ? undefined : window; + if (window === undefined) { return /* [] */0; } - let raw = $$window.location.pathname; + let raw = window.location.pathname; switch (raw) { case "" : case "/" : @@ -47,11 +47,11 @@ function path(param) { } function hash(param) { - let $$window = typeof window === "undefined" ? undefined : window; - if ($$window === undefined) { + let window = typeof window === "undefined" ? undefined : window; + if (window === undefined) { return ""; } - let raw = $$window.location.hash; + let raw = window.location.hash; switch (raw) { case "" : case "#" : @@ -62,11 +62,11 @@ function hash(param) { } function search(param) { - let $$window = typeof window === "undefined" ? undefined : window; - if ($$window === undefined) { + let window = typeof window === "undefined" ? undefined : window; + if (window === undefined) { return ""; } - let raw = $$window.location.search; + let raw = window.location.search; switch (raw) { case "" : case "?" : @@ -136,8 +136,8 @@ function url(param) { } function watchUrl(callback) { - let $$window = typeof window === "undefined" ? undefined : window; - if ($$window === undefined) { + let window = typeof window === "undefined" ? undefined : window; + if (window === undefined) { return function (param) { }; @@ -145,14 +145,14 @@ function watchUrl(callback) { let watcherID = function (param) { Curry._1(callback, url()); }; - $$window.addEventListener("popstate", watcherID); + window.addEventListener("popstate", watcherID); return watcherID; } function unwatchUrl(watcherID) { - let $$window = typeof window === "undefined" ? undefined : window; - if ($$window !== undefined) { - $$window.removeEventListener("popstate", watcherID); + let window = typeof window === "undefined" ? undefined : window; + if (window !== undefined) { + window.removeEventListener("popstate", watcherID); return; } diff --git a/jscomp/test/res_debug.js b/jscomp/test/res_debug.js index 19e1fd8326..500a818437 100644 --- a/jscomp/test/res_debug.js +++ b/jscomp/test/res_debug.js @@ -5,8 +5,8 @@ let Curry = require("../../lib/js/curry.js"); let Caml_obj = require("../../lib/js/caml_obj.js"); let Caml_option = require("../../lib/js/caml_option.js"); -function f($$window, a, b) { - return $$window.location(a, b); +function f(window, a, b) { + return window.location(a, b); } let v0 = { diff --git a/jscomp/test/sexpm.js b/jscomp/test/sexpm.js index bb09aa7c16..252d30acdd 100644 --- a/jscomp/test/sexpm.js +++ b/jscomp/test/sexpm.js @@ -7,7 +7,7 @@ let Char = require("../../lib/js/char.js"); let List = require("../../lib/js/list.js"); let Bytes = require("../../lib/js/bytes.js"); let Curry = require("../../lib/js/curry.js"); -let $$Buffer = require("../../lib/js/buffer.js"); +let Buffer = require("../../lib/js/buffer.js"); let $$String = require("../../lib/js/string.js"); let Caml_bytes = require("../../lib/js/caml_bytes.js"); let Pervasives = require("../../lib/js/pervasives.js"); @@ -98,35 +98,35 @@ function to_buf(b, t) { let l = t.VAL; if (l) { if (l.tl) { - $$Buffer.add_char(b, /* '(' */40); + Buffer.add_char(b, /* '(' */40); List.iteri((function (i, t$p) { if (i > 0) { - $$Buffer.add_char(b, /* ' ' */32); + Buffer.add_char(b, /* ' ' */32); } to_buf(b, t$p); }), l); - return $$Buffer.add_char(b, /* ')' */41); + return Buffer.add_char(b, /* ')' */41); } else { - $$Buffer.add_string(b, "("); + Buffer.add_string(b, "("); to_buf(b, l.hd); - return $$Buffer.add_string(b, ")"); + return Buffer.add_string(b, ")"); } } else { - return $$Buffer.add_string(b, "()"); + return Buffer.add_string(b, "()"); } } let s = t.VAL; if (_must_escape(s)) { - return $$Buffer.add_string(b, "\"" + ($$String.escaped(s) + "\"")); + return Buffer.add_string(b, "\"" + ($$String.escaped(s) + "\"")); } else { - return $$Buffer.add_string(b, s); + return Buffer.add_string(b, s); } } function to_string(t) { - let b = $$Buffer.create(128); + let b = Buffer.create(128); to_buf(b, t); - return $$Buffer.contents(b); + return Buffer.contents(b); } function make(bufsizeOpt, refill) { @@ -135,7 +135,7 @@ function make(bufsizeOpt, refill) { return { buf: Caml_bytes.create(bufsize$1), refill: refill, - atom: $$Buffer.create(32), + atom: Buffer.create(32), i: 0, len: 0, line: 1, @@ -190,10 +190,10 @@ function _error(param) { let line = param.line; let col = param.col; return function (msg) { - let b = $$Buffer.create(32); - $$Buffer.add_string(b, "at " + (line + (", " + (col + ": ")))); - $$Buffer.add_string(b, msg); - let msg$p = $$Buffer.contents(b); + let b = Buffer.create(32); + Buffer.add_string(b, "at " + (line + (", " + (col + ": ")))); + Buffer.add_string(b, msg); + let msg$p = Buffer.contents(b); return { NAME: "Error", VAL: msg$p @@ -280,7 +280,7 @@ function expr_starting_with(c, k, t) { } }); } - $$Buffer.add_char(t.atom, c); + Buffer.add_char(t.atom, c); return atom(k, t); } @@ -339,7 +339,7 @@ function expr_list(acc, k, t) { } function _return_atom(last, k, t) { - let s = $$Buffer.contents(t.atom); + let s = Buffer.contents(t.atom); t.atom.position = 0; return Curry._2(k, last, { NAME: "Atom", @@ -388,7 +388,7 @@ function atom(k, t) { } switch (exit) { case 1 : - $$Buffer.add_char(t.atom, c); + Buffer.add_char(t.atom, c); continue; case 2 : return _return_atom(c, k, t); @@ -410,11 +410,11 @@ function quoted(k, t) { } if (c === 92) { return escaped((function (c) { - $$Buffer.add_char(t.atom, c); + Buffer.add_char(t.atom, c); return quoted(k, t); }), t); } - $$Buffer.add_char(t.atom, c); + Buffer.add_char(t.atom, c); continue; }; } diff --git a/lib/es6/arg.js b/lib/es6/arg.js index c62d842b49..a7a56bbe89 100644 --- a/lib/es6/arg.js +++ b/lib/es6/arg.js @@ -5,7 +5,7 @@ import * as Caml from "./caml.js"; import * as List from "./list.js"; import * as $$Array from "./array.js"; import * as Curry from "./curry.js"; -import * as $$Buffer from "./buffer.js"; +import * as Buffer from "./buffer.js"; import * as $$String from "./string.js"; import * as Caml_obj from "./caml_obj.js"; import * as Caml_array from "./caml_array.js"; @@ -126,7 +126,7 @@ function add_help(speclist) { } function usage_b(buf, speclist, errmsg) { - $$Buffer.add_string(buf, errmsg + "\n"); + Buffer.add_string(buf, errmsg + "\n"); List.iter((function (param) { let doc = param[2]; if (doc.length === 0) { @@ -135,17 +135,17 @@ function usage_b(buf, speclist, errmsg) { let spec = param[1]; let key = param[0]; if (spec.TAG !== "Symbol") { - return $$Buffer.add_string(buf, " " + key + " " + doc + "\n"); + return Buffer.add_string(buf, " " + key + " " + doc + "\n"); } let sym = make_symlist("{", "|", "}", spec._0); - return $$Buffer.add_string(buf, " " + key + " " + sym + doc + "\n"); + return Buffer.add_string(buf, " " + key + " " + sym + doc + "\n"); }), add_help(speclist)); } function usage_string(speclist, errmsg) { - let b = $$Buffer.create(200); + let b = Buffer.create(200); usage_b(b, speclist, errmsg); - return $$Buffer.contents(b); + return Buffer.contents(b); } function usage(speclist, errmsg) { @@ -204,7 +204,7 @@ function float_of_string_opt(x) { function parse_and_expand_argv_dynamic_aux(allow_expand, current, argv, speclist, anonfun, errmsg) { let initpos = current.contents; let convert_error = function (error) { - let b = $$Buffer.create(200); + let b = Buffer.create(200); let progname = initpos < argv.contents.length ? Caml_array.get(argv.contents, initpos) : "(?)"; switch (error.TAG) { case "Unknown" : @@ -214,17 +214,17 @@ function parse_and_expand_argv_dynamic_aux(allow_expand, current, argv, speclist case "-help" : break; default: - $$Buffer.add_string(b, progname + ": unknown option '" + s + "'.\n"); + Buffer.add_string(b, progname + ": unknown option '" + s + "'.\n"); } break; case "Wrong" : - $$Buffer.add_string(b, progname + ": wrong argument '" + error._1 + "'; option '" + error._0 + "' expects " + error._2 + ".\n"); + Buffer.add_string(b, progname + ": wrong argument '" + error._1 + "'; option '" + error._0 + "' expects " + error._2 + ".\n"); break; case "Missing" : - $$Buffer.add_string(b, progname + ": option '" + error._0 + "' needs an argument.\n"); + Buffer.add_string(b, progname + ": option '" + error._0 + "' needs an argument.\n"); break; case "Message" : - $$Buffer.add_string(b, progname + ": " + error._0 + ".\n"); + Buffer.add_string(b, progname + ": " + error._0 + ".\n"); break; } @@ -238,12 +238,12 @@ function parse_and_expand_argv_dynamic_aux(allow_expand, current, argv, speclist })) { return { RE_EXN_ID: Help, - _1: $$Buffer.contents(b) + _1: Buffer.contents(b) }; } else { return { RE_EXN_ID: Bad, - _1: $$Buffer.contents(b) + _1: Buffer.contents(b) }; } }; diff --git a/lib/es6/belt.js b/lib/es6/belt.js index 0a2bd7d6e3..46fc28ba53 100644 --- a/lib/es6/belt.js +++ b/lib/es6/belt.js @@ -13,7 +13,7 @@ let MutableStack; let List; -let $$Range; +let Range; let $$Set; @@ -27,7 +27,7 @@ let HashSet; let HashMap; -let $$Option; +let Option; let Result; @@ -42,14 +42,14 @@ export { MutableQueue, MutableStack, List, - $$Range, + Range, $$Set, $$Map, MutableSet, MutableMap, HashSet, HashMap, - $$Option, + Option, Result, Int, Float, diff --git a/lib/es6/digest.js b/lib/es6/digest.js index 61ae4600ec..d321133827 100644 --- a/lib/es6/digest.js +++ b/lib/es6/digest.js @@ -97,12 +97,12 @@ function from_hex(s) { } return c - /* '0' */48 | 0; }; - let $$byte = function (i) { + let byte = function (i) { return (digit(Caml_string.get(s, i)) << 4) + digit(Caml_string.get(s, i + 1 | 0)) | 0; }; let result = Caml_bytes.create(16); for(let i = 0; i <= 15; ++i){ - Caml_bytes.set(result, i, Char.chr($$byte((i << 1)))); + Caml_bytes.set(result, i, Char.chr(byte((i << 1)))); } return Bytes.unsafe_to_string(result); } diff --git a/lib/es6/dom.js b/lib/es6/dom.js index 8aae4560b2..35819b0ce4 100644 --- a/lib/es6/dom.js +++ b/lib/es6/dom.js @@ -1,12 +1,12 @@ -let $$Storage; +let Storage; let Storage2; export { - $$Storage, + Storage, Storage2, } /* No side effect */ diff --git a/lib/es6/filename.js b/lib/es6/filename.js index ed11551906..cd135f9404 100644 --- a/lib/es6/filename.js +++ b/lib/es6/filename.js @@ -3,7 +3,7 @@ import * as Sys from "./sys.js"; import * as Bytes from "./bytes.js"; import * as Curry from "./curry.js"; -import * as $$Buffer from "./buffer.js"; +import * as Buffer from "./buffer.js"; import * as $$String from "./string.js"; import * as Caml_sys from "./caml_sys.js"; import * as Caml_string from "./caml_string.js"; @@ -134,17 +134,17 @@ catch (raw_exn){ function quote(param) { let quotequote = "'\\''"; let l = param.length; - let b = $$Buffer.create(l + 20 | 0); - $$Buffer.add_char(b, /* '\'' */39); + let b = Buffer.create(l + 20 | 0); + Buffer.add_char(b, /* '\'' */39); for(let i = 0; i < l; ++i){ if (Caml_string.get(param, i) === /* '\'' */39) { - $$Buffer.add_string(b, quotequote); + Buffer.add_string(b, quotequote); } else { - $$Buffer.add_char(b, Caml_string.get(param, i)); + Buffer.add_char(b, Caml_string.get(param, i)); } } - $$Buffer.add_char(b, /* '\'' */39); - return $$Buffer.contents(b); + Buffer.add_char(b, /* '\'' */39); + return Buffer.contents(b); } function basename(param) { @@ -216,13 +216,13 @@ catch (raw_exn$1){ function quote$1(s) { let l = s.length; - let b = $$Buffer.create(l + 20 | 0); - $$Buffer.add_char(b, /* '"' */34); + let b = Buffer.create(l + 20 | 0); + Buffer.add_char(b, /* '"' */34); let loop = function (_i) { while(true) { let i = _i; if (i === l) { - return $$Buffer.add_char(b, /* '"' */34); + return Buffer.add_char(b, /* '"' */34); } let c = Caml_string.get(s, i); if (c === 34) { @@ -231,7 +231,7 @@ function quote$1(s) { if (c === 92) { return loop_bs(0, i); } - $$Buffer.add_char(b, c); + Buffer.add_char(b, c); _i = i + 1 | 0; continue; }; @@ -241,7 +241,7 @@ function quote$1(s) { let i = _i; let n = _n; if (i === l) { - $$Buffer.add_char(b, /* '"' */34); + Buffer.add_char(b, /* '"' */34); return add_bs(n); } let match = Caml_string.get(s, i); @@ -255,17 +255,17 @@ function quote$1(s) { continue; } add_bs((n << 1) + 1 | 0); - $$Buffer.add_char(b, /* '"' */34); + Buffer.add_char(b, /* '"' */34); return loop(i + 1 | 0); }; }; let add_bs = function (n) { for(let _j = 1; _j <= n; ++_j){ - $$Buffer.add_char(b, /* '\\' */92); + Buffer.add_char(b, /* '\\' */92); } }; loop(0); - return $$Buffer.contents(b); + return Buffer.contents(b); } function has_drive(s) { diff --git a/lib/es6/genlex.js b/lib/es6/genlex.js index 9d45e7fdd2..0771228c63 100644 --- a/lib/es6/genlex.js +++ b/lib/es6/genlex.js @@ -118,7 +118,7 @@ function make_lexer(keywords) { Stream.junk(strm__); let c$1; try { - c$1 = $$char(strm__); + c$1 = char(strm__); } catch (raw_exn){ let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); @@ -477,7 +477,7 @@ function make_lexer(keywords) { Stream.junk(strm__); let c$1; try { - c$1 = $$escape(strm__); + c$1 = escape(strm__); } catch (raw_exn){ let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); @@ -506,7 +506,7 @@ function make_lexer(keywords) { }); }; }; - let $$char = function (strm__) { + let char = function (strm__) { let c = Stream.peek(strm__); if (c !== undefined) { if (c !== 92) { @@ -515,7 +515,7 @@ function make_lexer(keywords) { } Stream.junk(strm__); try { - return $$escape(strm__); + return escape(strm__); } catch (raw_exn){ let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); @@ -539,7 +539,7 @@ function make_lexer(keywords) { }); } }; - let $$escape = function (strm__) { + let escape = function (strm__) { let c1 = Stream.peek(strm__); if (c1 !== undefined) { if (c1 >= 58) { diff --git a/lib/es6/js.js b/lib/es6/js.js index 65c68ceb54..41b136afd0 100644 --- a/lib/es6/js.js +++ b/lib/es6/js.js @@ -53,11 +53,11 @@ let Int; let $$BigInt; -let $$File; +let File; -let $$Blob; +let Blob; -let $$Option; +let Option; let Result; @@ -102,9 +102,9 @@ export { Float, Int, $$BigInt, - $$File, - $$Blob, - $$Option, + File, + Blob, + Option, Result, List, Vector, diff --git a/lib/es6/jsxEventC.js b/lib/es6/jsxEventC.js index 4a8684de93..268c4a40e9 100644 --- a/lib/es6/jsxEventC.js +++ b/lib/es6/jsxEventC.js @@ -21,9 +21,9 @@ let Mouse = {}; let Pointer = {}; -let $$Selection = {}; +let Selection = {}; -let $$Touch = {}; +let Touch = {}; let UI = {}; @@ -31,9 +31,9 @@ let Wheel = {}; let Media = {}; -let $$Image = {}; +let Image = {}; -let $$Animation = {}; +let Animation = {}; let Transition = {}; @@ -47,13 +47,13 @@ export { Form, Mouse, Pointer, - $$Selection, - $$Touch, + Selection, + Touch, UI, Wheel, Media, - $$Image, - $$Animation, + Image, + Animation, Transition, } /* No side effect */ diff --git a/lib/es6/jsxEventU.js b/lib/es6/jsxEventU.js index 4a8684de93..268c4a40e9 100644 --- a/lib/es6/jsxEventU.js +++ b/lib/es6/jsxEventU.js @@ -21,9 +21,9 @@ let Mouse = {}; let Pointer = {}; -let $$Selection = {}; +let Selection = {}; -let $$Touch = {}; +let Touch = {}; let UI = {}; @@ -31,9 +31,9 @@ let Wheel = {}; let Media = {}; -let $$Image = {}; +let Image = {}; -let $$Animation = {}; +let Animation = {}; let Transition = {}; @@ -47,13 +47,13 @@ export { Form, Mouse, Pointer, - $$Selection, - $$Touch, + Selection, + Touch, UI, Wheel, Media, - $$Image, - $$Animation, + Image, + Animation, Transition, } /* No side effect */ diff --git a/lib/es6/random.js b/lib/es6/random.js index dc0bd62a70..21cff477be 100644 --- a/lib/es6/random.js +++ b/lib/es6/random.js @@ -73,7 +73,7 @@ function bits(s) { return newval30; } -function $$int(s, bound) { +function int(s, bound) { if (bound > 1073741823 || bound <= 0) { throw new Error("Invalid_argument", { cause: { @@ -141,7 +141,7 @@ function rawfloat(s) { return (r1 / 1073741824.0 + r2) / 1073741824.0; } -function $$float(s, bound) { +function float(s, bound) { return rawfloat(s) * bound; } @@ -214,8 +214,8 @@ function bits$1(param) { return bits($$default); } -function $$int$1(bound) { - return $$int($$default, bound); +function int$1(bound) { + return int($$default, bound); } function int32$1(bound) { @@ -226,7 +226,7 @@ function int64$1(bound) { return int64($$default, bound); } -function $$float$1(scale) { +function float$1(scale) { return rawfloat($$default) * scale; } @@ -259,10 +259,10 @@ let State = { make_self_init: make_self_init, copy: copy, bits: bits, - $$int: $$int, + int: int, int32: int32, int64: int64, - $$float: $$float, + float: float, bool: bool }; @@ -271,10 +271,10 @@ export { full_init$1 as full_init, self_init, bits$1 as bits, - $$int$1 as $$int, + int$1 as int, int32$1 as int32, int64$1 as int64, - $$float$1 as $$float, + float$1 as float, bool$1 as bool, State, get_state, diff --git a/lib/js/arg.js b/lib/js/arg.js index 28a73acb7f..794153823a 100644 --- a/lib/js/arg.js +++ b/lib/js/arg.js @@ -5,7 +5,7 @@ let Caml = require("./caml.js"); let List = require("./list.js"); let $$Array = require("./array.js"); let Curry = require("./curry.js"); -let $$Buffer = require("./buffer.js"); +let Buffer = require("./buffer.js"); let $$String = require("./string.js"); let Caml_obj = require("./caml_obj.js"); let Caml_array = require("./caml_array.js"); @@ -126,7 +126,7 @@ function add_help(speclist) { } function usage_b(buf, speclist, errmsg) { - $$Buffer.add_string(buf, errmsg + "\n"); + Buffer.add_string(buf, errmsg + "\n"); List.iter((function (param) { let doc = param[2]; if (doc.length === 0) { @@ -135,17 +135,17 @@ function usage_b(buf, speclist, errmsg) { let spec = param[1]; let key = param[0]; if (spec.TAG !== "Symbol") { - return $$Buffer.add_string(buf, " " + key + " " + doc + "\n"); + return Buffer.add_string(buf, " " + key + " " + doc + "\n"); } let sym = make_symlist("{", "|", "}", spec._0); - return $$Buffer.add_string(buf, " " + key + " " + sym + doc + "\n"); + return Buffer.add_string(buf, " " + key + " " + sym + doc + "\n"); }), add_help(speclist)); } function usage_string(speclist, errmsg) { - let b = $$Buffer.create(200); + let b = Buffer.create(200); usage_b(b, speclist, errmsg); - return $$Buffer.contents(b); + return Buffer.contents(b); } function usage(speclist, errmsg) { @@ -204,7 +204,7 @@ function float_of_string_opt(x) { function parse_and_expand_argv_dynamic_aux(allow_expand, current, argv, speclist, anonfun, errmsg) { let initpos = current.contents; let convert_error = function (error) { - let b = $$Buffer.create(200); + let b = Buffer.create(200); let progname = initpos < argv.contents.length ? Caml_array.get(argv.contents, initpos) : "(?)"; switch (error.TAG) { case "Unknown" : @@ -214,17 +214,17 @@ function parse_and_expand_argv_dynamic_aux(allow_expand, current, argv, speclist case "-help" : break; default: - $$Buffer.add_string(b, progname + ": unknown option '" + s + "'.\n"); + Buffer.add_string(b, progname + ": unknown option '" + s + "'.\n"); } break; case "Wrong" : - $$Buffer.add_string(b, progname + ": wrong argument '" + error._1 + "'; option '" + error._0 + "' expects " + error._2 + ".\n"); + Buffer.add_string(b, progname + ": wrong argument '" + error._1 + "'; option '" + error._0 + "' expects " + error._2 + ".\n"); break; case "Missing" : - $$Buffer.add_string(b, progname + ": option '" + error._0 + "' needs an argument.\n"); + Buffer.add_string(b, progname + ": option '" + error._0 + "' needs an argument.\n"); break; case "Message" : - $$Buffer.add_string(b, progname + ": " + error._0 + ".\n"); + Buffer.add_string(b, progname + ": " + error._0 + ".\n"); break; } @@ -238,12 +238,12 @@ function parse_and_expand_argv_dynamic_aux(allow_expand, current, argv, speclist })) { return { RE_EXN_ID: Help, - _1: $$Buffer.contents(b) + _1: Buffer.contents(b) }; } else { return { RE_EXN_ID: Bad, - _1: $$Buffer.contents(b) + _1: Buffer.contents(b) }; } }; diff --git a/lib/js/belt.js b/lib/js/belt.js index f240b450cd..78d1d8521a 100644 --- a/lib/js/belt.js +++ b/lib/js/belt.js @@ -13,7 +13,7 @@ let MutableStack; let List; -let $$Range; +let Range; let $$Set; @@ -27,7 +27,7 @@ let HashSet; let HashMap; -let $$Option; +let Option; let Result; @@ -41,14 +41,14 @@ exports.SortArray = SortArray; exports.MutableQueue = MutableQueue; exports.MutableStack = MutableStack; exports.List = List; -exports.$$Range = $$Range; +exports.Range = Range; exports.$$Set = $$Set; exports.$$Map = $$Map; exports.MutableSet = MutableSet; exports.MutableMap = MutableMap; exports.HashSet = HashSet; exports.HashMap = HashMap; -exports.$$Option = $$Option; +exports.Option = Option; exports.Result = Result; exports.Int = Int; exports.Float = Float; diff --git a/lib/js/digest.js b/lib/js/digest.js index 867fe591f8..51307ddf23 100644 --- a/lib/js/digest.js +++ b/lib/js/digest.js @@ -97,12 +97,12 @@ function from_hex(s) { } return c - /* '0' */48 | 0; }; - let $$byte = function (i) { + let byte = function (i) { return (digit(Caml_string.get(s, i)) << 4) + digit(Caml_string.get(s, i + 1 | 0)) | 0; }; let result = Caml_bytes.create(16); for(let i = 0; i <= 15; ++i){ - Caml_bytes.set(result, i, Char.chr($$byte((i << 1)))); + Caml_bytes.set(result, i, Char.chr(byte((i << 1)))); } return Bytes.unsafe_to_string(result); } diff --git a/lib/js/dom.js b/lib/js/dom.js index 595bc1805a..1f37eda4e8 100644 --- a/lib/js/dom.js +++ b/lib/js/dom.js @@ -1,10 +1,10 @@ 'use strict'; -let $$Storage; +let Storage; let Storage2; -exports.$$Storage = $$Storage; +exports.Storage = Storage; exports.Storage2 = Storage2; /* No side effect */ diff --git a/lib/js/filename.js b/lib/js/filename.js index 59f88a3344..2ee6ea8812 100644 --- a/lib/js/filename.js +++ b/lib/js/filename.js @@ -3,7 +3,7 @@ let Sys = require("./sys.js"); let Bytes = require("./bytes.js"); let Curry = require("./curry.js"); -let $$Buffer = require("./buffer.js"); +let Buffer = require("./buffer.js"); let $$String = require("./string.js"); let Caml_sys = require("./caml_sys.js"); let Caml_string = require("./caml_string.js"); @@ -134,17 +134,17 @@ catch (raw_exn){ function quote(param) { let quotequote = "'\\''"; let l = param.length; - let b = $$Buffer.create(l + 20 | 0); - $$Buffer.add_char(b, /* '\'' */39); + let b = Buffer.create(l + 20 | 0); + Buffer.add_char(b, /* '\'' */39); for(let i = 0; i < l; ++i){ if (Caml_string.get(param, i) === /* '\'' */39) { - $$Buffer.add_string(b, quotequote); + Buffer.add_string(b, quotequote); } else { - $$Buffer.add_char(b, Caml_string.get(param, i)); + Buffer.add_char(b, Caml_string.get(param, i)); } } - $$Buffer.add_char(b, /* '\'' */39); - return $$Buffer.contents(b); + Buffer.add_char(b, /* '\'' */39); + return Buffer.contents(b); } function basename(param) { @@ -216,13 +216,13 @@ catch (raw_exn$1){ function quote$1(s) { let l = s.length; - let b = $$Buffer.create(l + 20 | 0); - $$Buffer.add_char(b, /* '"' */34); + let b = Buffer.create(l + 20 | 0); + Buffer.add_char(b, /* '"' */34); let loop = function (_i) { while(true) { let i = _i; if (i === l) { - return $$Buffer.add_char(b, /* '"' */34); + return Buffer.add_char(b, /* '"' */34); } let c = Caml_string.get(s, i); if (c === 34) { @@ -231,7 +231,7 @@ function quote$1(s) { if (c === 92) { return loop_bs(0, i); } - $$Buffer.add_char(b, c); + Buffer.add_char(b, c); _i = i + 1 | 0; continue; }; @@ -241,7 +241,7 @@ function quote$1(s) { let i = _i; let n = _n; if (i === l) { - $$Buffer.add_char(b, /* '"' */34); + Buffer.add_char(b, /* '"' */34); return add_bs(n); } let match = Caml_string.get(s, i); @@ -255,17 +255,17 @@ function quote$1(s) { continue; } add_bs((n << 1) + 1 | 0); - $$Buffer.add_char(b, /* '"' */34); + Buffer.add_char(b, /* '"' */34); return loop(i + 1 | 0); }; }; let add_bs = function (n) { for(let _j = 1; _j <= n; ++_j){ - $$Buffer.add_char(b, /* '\\' */92); + Buffer.add_char(b, /* '\\' */92); } }; loop(0); - return $$Buffer.contents(b); + return Buffer.contents(b); } function has_drive(s) { diff --git a/lib/js/genlex.js b/lib/js/genlex.js index 515a683d73..c3be339c5a 100644 --- a/lib/js/genlex.js +++ b/lib/js/genlex.js @@ -118,7 +118,7 @@ function make_lexer(keywords) { Stream.junk(strm__); let c$1; try { - c$1 = $$char(strm__); + c$1 = char(strm__); } catch (raw_exn){ let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); @@ -477,7 +477,7 @@ function make_lexer(keywords) { Stream.junk(strm__); let c$1; try { - c$1 = $$escape(strm__); + c$1 = escape(strm__); } catch (raw_exn){ let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); @@ -506,7 +506,7 @@ function make_lexer(keywords) { }); }; }; - let $$char = function (strm__) { + let char = function (strm__) { let c = Stream.peek(strm__); if (c !== undefined) { if (c !== 92) { @@ -515,7 +515,7 @@ function make_lexer(keywords) { } Stream.junk(strm__); try { - return $$escape(strm__); + return escape(strm__); } catch (raw_exn){ let exn = Caml_js_exceptions.internalToOCamlException(raw_exn); @@ -539,7 +539,7 @@ function make_lexer(keywords) { }); } }; - let $$escape = function (strm__) { + let escape = function (strm__) { let c1 = Stream.peek(strm__); if (c1 !== undefined) { if (c1 >= 58) { diff --git a/lib/js/js.js b/lib/js/js.js index b1b67b66fd..70f2b12f29 100644 --- a/lib/js/js.js +++ b/lib/js/js.js @@ -53,11 +53,11 @@ let Int; let $$BigInt; -let $$File; +let File; -let $$Blob; +let Blob; -let $$Option; +let Option; let Result; @@ -101,9 +101,9 @@ exports.Types = Types; exports.Float = Float; exports.Int = Int; exports.$$BigInt = $$BigInt; -exports.$$File = $$File; -exports.$$Blob = $$Blob; -exports.$$Option = $$Option; +exports.File = File; +exports.Blob = Blob; +exports.Option = Option; exports.Result = Result; exports.List = List; exports.Vector = Vector; diff --git a/lib/js/jsxEventC.js b/lib/js/jsxEventC.js index 8570b3b8d5..882412b208 100644 --- a/lib/js/jsxEventC.js +++ b/lib/js/jsxEventC.js @@ -21,9 +21,9 @@ let Mouse = {}; let Pointer = {}; -let $$Selection = {}; +let Selection = {}; -let $$Touch = {}; +let Touch = {}; let UI = {}; @@ -31,9 +31,9 @@ let Wheel = {}; let Media = {}; -let $$Image = {}; +let Image = {}; -let $$Animation = {}; +let Animation = {}; let Transition = {}; @@ -46,12 +46,12 @@ exports.Focus = Focus; exports.Form = Form; exports.Mouse = Mouse; exports.Pointer = Pointer; -exports.$$Selection = $$Selection; -exports.$$Touch = $$Touch; +exports.Selection = Selection; +exports.Touch = Touch; exports.UI = UI; exports.Wheel = Wheel; exports.Media = Media; -exports.$$Image = $$Image; -exports.$$Animation = $$Animation; +exports.Image = Image; +exports.Animation = Animation; exports.Transition = Transition; /* No side effect */ diff --git a/lib/js/jsxEventU.js b/lib/js/jsxEventU.js index 8570b3b8d5..882412b208 100644 --- a/lib/js/jsxEventU.js +++ b/lib/js/jsxEventU.js @@ -21,9 +21,9 @@ let Mouse = {}; let Pointer = {}; -let $$Selection = {}; +let Selection = {}; -let $$Touch = {}; +let Touch = {}; let UI = {}; @@ -31,9 +31,9 @@ let Wheel = {}; let Media = {}; -let $$Image = {}; +let Image = {}; -let $$Animation = {}; +let Animation = {}; let Transition = {}; @@ -46,12 +46,12 @@ exports.Focus = Focus; exports.Form = Form; exports.Mouse = Mouse; exports.Pointer = Pointer; -exports.$$Selection = $$Selection; -exports.$$Touch = $$Touch; +exports.Selection = Selection; +exports.Touch = Touch; exports.UI = UI; exports.Wheel = Wheel; exports.Media = Media; -exports.$$Image = $$Image; -exports.$$Animation = $$Animation; +exports.Image = Image; +exports.Animation = Animation; exports.Transition = Transition; /* No side effect */ diff --git a/lib/js/random.js b/lib/js/random.js index 7fd1d5faa8..d4a9d9002d 100644 --- a/lib/js/random.js +++ b/lib/js/random.js @@ -73,7 +73,7 @@ function bits(s) { return newval30; } -function $$int(s, bound) { +function int(s, bound) { if (bound > 1073741823 || bound <= 0) { throw new Error("Invalid_argument", { cause: { @@ -141,7 +141,7 @@ function rawfloat(s) { return (r1 / 1073741824.0 + r2) / 1073741824.0; } -function $$float(s, bound) { +function float(s, bound) { return rawfloat(s) * bound; } @@ -214,8 +214,8 @@ function bits$1(param) { return bits($$default); } -function $$int$1(bound) { - return $$int($$default, bound); +function int$1(bound) { + return int($$default, bound); } function int32$1(bound) { @@ -226,7 +226,7 @@ function int64$1(bound) { return int64($$default, bound); } -function $$float$1(scale) { +function float$1(scale) { return rawfloat($$default) * scale; } @@ -259,10 +259,10 @@ let State = { make_self_init: make_self_init, copy: copy, bits: bits, - $$int: $$int, + int: int, int32: int32, int64: int64, - $$float: $$float, + float: float, bool: bool }; @@ -270,10 +270,10 @@ exports.init = init; exports.full_init = full_init$1; exports.self_init = self_init; exports.bits = bits$1; -exports.$$int = $$int$1; +exports.int = int$1; exports.int32 = int32$1; exports.int64 = int64$1; -exports.$$float = $$float$1; +exports.float = float$1; exports.bool = bool$1; exports.State = State; exports.get_state = get_state; diff --git a/scripts/build_reserved.js b/scripts/build_reserved.js deleted file mode 100644 index 18e1042bd8..0000000000 --- a/scripts/build_reserved.js +++ /dev/null @@ -1,32 +0,0 @@ -//@ts-check - -const fs = require("fs"); -const path = require("path"); -const { execSync } = require("child_process"); -const puppeteer = require("puppeteer"); - -const jscompDir = path.join(__dirname, "..", "jscomp"); -const keywordsFile = path.join(jscompDir, "keywords.list"); -const reservedMap = path.join(jscompDir, "ext", "js_reserved_map.ml"); - -(async function () { - const browser = await puppeteer.launch(); - const page = await browser.newPage(); - /** - * @type string[] - */ - const result = await page.evaluate(`Object.getOwnPropertyNames(window)`); - fs.writeFileSync( - keywordsFile, - result - .filter(x => /^[A-Z]/.test(x)) - .sort() - .join("\n"), - "utf8" - ); - await browser.close(); - - execSync(`ocaml build_reserved.ml ${keywordsFile} ${reservedMap}`, { - cwd: __dirname, - }); -})(); diff --git a/scripts/build_reserved.ml b/scripts/build_reserved.ml deleted file mode 100644 index 6e5103a1e9..0000000000 --- a/scripts/build_reserved.ml +++ /dev/null @@ -1,239 +0,0 @@ -(* Copyright (C) 2019-Present Hongbo Zhang, Authors of ReScript - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) - - let reserved_words = - [| - (* keywords *) - "break"; - "case"; "catch"; "continue"; - "debugger";"default";"delete";"do"; - "else"; - "finally";"for";"function"; - "if"; (* "then"; *) "in";"instanceof"; - "new"; - "return"; - "switch"; - "this"; "throw"; "try"; "typeof"; - "var"; "void"; "while"; "with"; - - (* reserved in ECMAScript 5 *) - "class"; "enum"; "export"; "extends"; "import"; "super"; - - "implements";"interface"; - "let"; - "package";"private";"protected";"public"; - "static"; - "yield"; - - (* other *) - "null"; - "true"; - "false"; - "NaN"; - - - "undefined"; - "this"; - - (* also reserved in ECMAScript 3 *) - "abstract"; "boolean"; "byte"; "char"; "const"; "double"; - "final"; "float"; "goto"; "int"; "long"; "native"; "short"; - "synchronized"; - (* "throws"; *) - (* seems to be fine, like nodejs [assert.throws] *) - "transient"; "volatile"; - - (* also reserved in ECMAScript 6 *) - "await"; - - "event"; - "location"; - "window"; - "document"; - "eval"; - "navigator"; - (* "self"; *) - - "Array"; - "Date"; - "Math"; - "JSON"; - "Object"; - "RegExp"; - "String"; - "Boolean"; - "Number"; - "Buffer"; (* Node *) - "Map"; (* es6*) - "Set"; - "Promise"; - "Infinity"; - "isFinite"; - - "ActiveXObject"; - "XMLHttpRequest"; - "XDomainRequest"; - - "DOMException"; - "Error"; - "SyntaxError"; - "arguments"; - - "decodeURI"; - "decodeURIComponent"; - "encodeURI"; - "encodeURIComponent"; - "escape"; - "unescape"; - "fetch"; - "isNaN"; - "parseFloat"; - "parseInt"; - - (** reserved for commonjs and NodeJS globals*) - "require"; - "exports"; - "module"; - "clearImmediate"; - "clearInterval"; - "clearTimeout"; - "console"; - "global"; - "process"; - "require"; - "setImmediate"; - "setInterval"; - "setTimeout"; - "__dirname"; - "__filename"; - "__esModule"; - - (* Bun global obj *) - "Bun"; - - (* Deno global obj *) - "Deno"; - |] - - -module SSet = Set.Make(String) -let get_predefined_words (fn : string) = - let v = ref SSet.empty in - let in_chan = open_in_bin fn in - (try - while true do - let new_word = input_line in_chan in - if String.length new_word <> 0 then - v := SSet.add new_word !v - done - with End_of_file -> ()); - !v - -let fill_extra (ss : SSet.t) : SSet.t = - let v = ref ss in - for i = 0 to Array.length reserved_words - 1 do - v := SSet.add reserved_words.(i) !v - done; - !v -let license = {| -(* Copyright (C) 2019-Present Hongbo Zhang, Authors of ReScript - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) - -|} -let binary_search = {| - -type element = string - -let rec binarySearchAux (arr : element array) (lo : int) (hi : int) key : bool = - let mid = (lo + hi)/2 in - let midVal = Array.unsafe_get arr mid in - (* let c = cmp key midVal [@bs] in *) - if key = midVal then true - else if key < midVal then (* a[lo] =< key < a[mid] <= a[hi] *) - if hi = mid then - (Array.unsafe_get arr lo) = key - else binarySearchAux arr lo mid key - else (* a[lo] =< a[mid] < key <= a[hi] *) - if lo = mid then - (Array.unsafe_get arr hi) = key - else binarySearchAux arr mid hi key - -let binarySearch (sorted : element array) (key : element) : bool = - let len = Array.length sorted in - if len = 0 then false - else - let lo = Array.unsafe_get sorted 0 in - (* let c = cmp key lo [@bs] in *) - if key < lo then false - else - let hi = Array.unsafe_get sorted (len - 1) in - (* let c2 = cmp key hi [@bs]in *) - if key > hi then false - else binarySearchAux sorted 0 (len - 1) key - -let is_reserved s = binarySearch sorted_keywords s -|} -let main keyword_file output_file = - let ss = get_predefined_words keyword_file in - let ss = fill_extra ss in - let keywords_array = - (SSet.fold - (fun s acc -> acc ^ "\"" ^ s ^ "\";\n " - ) ss "let sorted_keywords = [|\n ") ^ "|]\n" - in - let oc = open_out_bin output_file in - output_string oc license ; - output_string oc keywords_array; - output_string oc binary_search; - close_out oc -(* -;; -for i = 0 to Array.length Sys.argv - 1 do - print_endline ">"; print_string Sys.argv.(i) -done -;; *) -let () = main Sys.argv.(1) Sys.argv.(2) - -