# Changelog

## UNRELEASED

### Bugfixes

- General: most language parsers crashed when encountering certain non-terminated string-like language constructs
- CSS: the value set by `--cm-content-margin-left` was erroneously always multiplied by two
- TypeScript: add support for the `declare` keyword and associated syntax, like namespaces
- EcmaScript: add proper support for regular expressions and the `accessor` keyword
- Docs: fixed various typos and missing words, add missing docs for Elixir

## v 0.0.15

### Breaking: language modules

Adding support for Elixir in 0.0.13 increased the bundle size considerably,
which made modularizing the entire project necessary. Languages are now modules
that need to be imported and instantiated explicitly:

```javascript
// Main module imports like before
import { fromStringsToScene, toAnimationHTML } from "@codemovie/code-movie";

// NEW: import the language module you want to use
import json from "@codemovie/code-movie/languages/json";

// NEW: instantiate the language. Some languages can be configured to support
// certain features by passing options to the language function (eg. enable JSX
// support in ECMAScript by passing `{ jsx: true }`)
const language = json();

let sceneData = fromStringsToScene(
  [
    /* ...keyframes... */
  ],
  {
    tabSize: 2,
    language, // NEW: now the language object instead of a string
  },
);

let html = toAnimationHTML(sceneData);
```

This change breaks the following APIs:

- The `InputOptions` passed to **`fromStringsToScene()`** as its second argument
  must now be an object returned from a language function instead of a string
  referring to the language name
- **`fromStringsToScene()`** now returns an object containing the `Scene` object
  _and_ the language object that was originally passed in the `InputOptions`
- The first argument to **`toAnimationHTML()`** must now be an object containing
  the `scene` object _and_ the language object used to create the scene (in
  other words, it still takes the output of `fromStringsToScene()` as its first
  argument, but the actual object is slightly different)
- The main module exports `SUPPORTED_LANGUAGES` (set of language names) and
  `Language` (TypeScript union type of language names) do no longer exist

The following language modules are currently available:

- `@codemovie/code-movie/languages/css`
- `@codemovie/code-movie/languages/ecmascript` (for JavaScript and TypeScript)
- `@codemovie/code-movie/languages/elixir`
- `@codemovie/code-movie/languages/html`
- `@codemovie/code-movie/languages/json`
- `@codemovie/code-movie/languages/plaintext`

### Improvement: JSX support for JavaScript and TypeScript

The language module `@codemovie/code-movie/languages/ecmascript` enables support
for JSX in both TypeScript and vanilla JavaScript:

```javascript
import ecmascript from "@codemovie/code-movie/languages/ecmascript";

let regularJavaScript = ecmascript();
let typeScript = ecmascript({ ts: true });
let javaScriptWithJSX = ecmascript({ jsx: true });
let typeScriptWithJSX = ecmascript({ ts: true, jsx: true });
```

### Improvement: optional `ranges` and `decorations`

The fields `ranges` and `decorations` on `InputFrames` (the first argument to
`fromStringsToScene()`) are now optional and default to empty arrays. They will
be empty for most frames anyway and filling in the blanks is trivial. Plus it
makes the tutorial shorter!

### Bugfixes

The bugfixes all revolve around plugging small to medium-sized holes in language
support:

- Elixir:
  - an empty string as input was causing exceptions
  - the diff algorithm had too little meta information on `do` blocks to
    reliably produce non-confusing results
- TypeScript:
  - template literal types with interpolations inside were missing their
    non-interpolation bits (the actual string parts of a template literal type)
  - `readonly` in index signatures and the `infer` keyword were not properly
    detected
- ECMAScript:
  - curly braces for object literals and `switch` bodies were not properly
    detected
  - the `break` and `continue` keywords were not properly detected

### Other

Adjusted some magic numbers in the token matchup functions. This should provide
an overall improved diffing behavior.

## v 0.0.14

Improve stability and add support for Elixir.

## v 0.0.13

Initial public release.
