Skip to content

Commit 75fc6cd

Browse files
authored
Document that clang-format may clobber javascript and how to work around this (#19810)
1 parent 91f2012 commit 75fc6cd

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

.clang-format

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ ConstructorInitializerIndentWidth: 2
88
SpaceAfterTemplateKeyword: false
99
BinPackArguments: false
1010
BinPackParameters: false
11+
WhitespaceSensitiveMacros: ['EM_ASM', 'EM_JS', 'EM_ASM_INT', 'EM_ASM_DOUBLE', 'EM_ASM_PTR', 'MAIN_THREAD_EM_ASM', 'MAIN_THREAD_EM_ASM_INT', 'MAIN_THREAD_EM_ASM_DOUBLE', 'MAIN_THREAD_EM_ASM_DOUBLE', 'MAIN_THREAD_ASYNC_EM_ASM']
1112
---
1213
Language: JavaScript
1314
BasedOnStyle: LLVM

site/source/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.rst

+6
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,11 @@ See the :c:macro:`emscripten.h docs <EM_ASM_>` for more details.
347347
single quotes('). Double quotes(") will cause a syntax error that
348348
is not detected by the compiler and is only shown when looking at
349349
a JavaScript console while running the offending code.
350+
- clang-format may clobber Javascript constructions, such as ``=>``
351+
turning to ``= >``. To avoid this, add to your ``.clang-format``:
352+
``WhitespaceSensitiveMacros: ['EM_ASM', 'EM_JS', 'EM_ASM_INT', 'EM_ASM_DOUBLE', 'EM_ASM_PTR', 'MAIN_THREAD_EM_ASM', 'MAIN_THREAD_EM_ASM_INT', 'MAIN_THREAD_EM_ASM_DOUBLE', 'MAIN_THREAD_EM_ASM_DOUBLE', 'MAIN_THREAD_ASYNC_EM_ASM']``.
353+
Or, turn `clang-format off`_ by writing ``// clang-format off``
354+
before the ``EM_ASM`` section and ``// clang-format on`` after it.
350355

351356

352357
.. _implement-c-in-javascript:
@@ -814,6 +819,7 @@ you can give it a try. See `Emnapi documentation`_ for more details.
814819
.. _test/test_core.py: https://github.com/emscripten-core/emscripten/blob/1.29.12/tests/test_core.py#L4597
815820
.. _Box2D: https://github.com/kripken/box2d.js/#box2djs
816821
.. _Bullet: https://github.com/kripken/ammo.js/#ammojs
822+
.. _clang-format off: https://clang.llvm.org/docs/ClangFormatStyleOptions.html#disabling-formatting-on-a-piece-of-code
817823
.. _Emnapi: https://github.com/toyobayashi/emnapi
818824
.. _Node-API: https://nodejs.org/dist/latest/docs/api/n-api.html
819825
.. _Emnapi documentation: https://emnapi-docs.vercel.app/guide/getting-started.html

0 commit comments

Comments
 (0)