You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A list of language injections to support embedded languages in the project like JS/CSS in HTML.
151
+
This is an experimental feature.
152
+
153
+
Please see the [guide](/advanced/language-injection.html) for detailed instructions.
154
+
155
+
A language injection object has the following options.
156
+
157
+
### `hostLanguage`
158
+
* type: `String`
159
+
* required: Yes
160
+
161
+
The host language name, e.g. `html`. This is the language of documents that contains the embedded language code.
162
+
163
+
### `rule`
164
+
* type: `Rule` object
165
+
* required: Yes
166
+
167
+
Defines the ast-grep rule to identify the injected language region within the host language documents.
168
+
169
+
### `injected`
170
+
* type: `String` or `List<String>`
171
+
* required: Yes
172
+
173
+
The injected language name, e.g. `js`. This is the language of the embedded code.
174
+
175
+
It can be a static string or a list of strings. If it is a list, ast-grep will use the `$LANG` meta variable captured in the rule to dynamically determine the injected language. The list of strings is the candidate language names to match the `$LANG` meta variable.
176
+
177
+
**Example:**
178
+
179
+
This is a configuration to support styled-components in JS files with static `injected` language.
180
+
181
+
```yaml
182
+
languageInjections:
183
+
- hostLanguage: js
184
+
rule:
185
+
pattern: styled.$TAG`$CONTENT`
186
+
injected: css
187
+
```
188
+
189
+
This is a configuration to support CSS in JS style in JS files with dynamic `injected` language.
0 commit comments