Skip to content

Commit

Permalink
Use a kludge to improve tree-shaking of extension sets
Browse files Browse the repository at this point in the history
FIX: Work around limitations in tree-shaking software that prevented `basicSetup`
from being removed when unused.
  • Loading branch information
marijnh committed Jun 30, 2022
1 parent 4b83cb1 commit 49e3909
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/codemirror.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import {searchKeymap, highlightSelectionMatches} from "@codemirror/search"
import {autocompletion, completionKeymap, closeBrackets, closeBracketsKeymap} from "@codemirror/autocomplete"
import {lintKeymap} from "@codemirror/lint"

// (The superfluous function calls around the list of extensions work
// around current limitations in tree-shaking software.)

This comment has been minimized.

Copy link
@olsonpm

olsonpm Dec 6, 2024

Thanks for this comment. Is there a bug or pending feature this refers to ? Or was it a quick fix where you didn't dig into the specifics.

I ask because I'd like to understand in case I encounter it in the future

This comment has been minimized.

Copy link
@marijnh

marijnh Dec 6, 2024

Author Member

I don't really remember. I'd guess some of these calls weren't seen as pure by the bundler, even though they are, and this extra wrapper (which your build setup will mark as pure) helps avoid pulling them in when basicSetup isn't used.

This comment has been minimized.

Copy link
@olsonpm

olsonpm Dec 6, 2024

makes sense - I appreciate your time and your work on codemirror


/// This is an extension value that just pulls together a number of
/// extensions that you might want in a basic editor. It is meant as a
/// convenient helper to quickly set up CodeMirror without installing
Expand Down Expand Up @@ -44,7 +47,7 @@ import {lintKeymap} from "@codemirror/lint"
/// you take this package's source (which is just a bunch of imports
/// and an array literal), copy it into your own code, and adjust it
/// as desired.
export const basicSetup: Extension = [
export const basicSetup: Extension = (() => [
lineNumbers(),
highlightActiveLineGutter(),
highlightSpecialChars(),
Expand All @@ -71,15 +74,15 @@ export const basicSetup: Extension = [
...completionKeymap,
...lintKeymap
])
]
])()

/// A minimal set of extensions to create a functional editor. Only
/// includes [the default keymap](#commands.defaultKeymap), [undo
/// history](#commands.history), [special character
/// highlighting](#view.highlightSpecialChars), [custom selection
/// drawing](#view.drawSelection), and [default highlight
/// style](#language.defaultHighlightStyle).
export const minimalSetup: Extension = [
export const minimalSetup: Extension = (() => [
highlightSpecialChars(),
history(),
drawSelection(),
Expand All @@ -88,6 +91,6 @@ export const minimalSetup: Extension = [
...defaultKeymap,
...historyKeymap,
])
]
])()

export {EditorView} from "@codemirror/view"

0 comments on commit 49e3909

Please sign in to comment.