read_pattern() — svelte Function Reference
Architecture documentation for the read_pattern() function in context.js from the svelte codebase.
Entity Profile
Dependency Diagram
graph TD 6a786ac5_79fd_078b_6df2_8e1e4a370161["read_pattern()"] caefc1b2_dc4c_2cff_4013_e8ded13e7974["context.js"] 6a786ac5_79fd_078b_6df2_8e1e4a370161 -->|defined in| caefc1b2_dc4c_2cff_4013_e8ded13e7974 f9386464_dab0_7aa2_cfd0_969e973dc903["open()"] f9386464_dab0_7aa2_cfd0_969e973dc903 -->|calls| 6a786ac5_79fd_078b_6df2_8e1e4a370161 563ea552_7fa4_4834_a19f_2b256bff987c["next()"] 563ea552_7fa4_4834_a19f_2b256bff987c -->|calls| 6a786ac5_79fd_078b_6df2_8e1e4a370161 293ea078_697f_e55b_c696_1c508cae7857["special()"] 293ea078_697f_e55b_c696_1c508cae7857 -->|calls| 6a786ac5_79fd_078b_6df2_8e1e4a370161 b0e2fc2e_b944_6248_d26e_696646af398f["read_type_annotation()"] 6a786ac5_79fd_078b_6df2_8e1e4a370161 -->|calls| b0e2fc2e_b944_6248_d26e_696646af398f 28256594_da6f_2763_1de1_63c1b3201849["expected_pattern()"] 6a786ac5_79fd_078b_6df2_8e1e4a370161 -->|calls| 28256594_da6f_2763_1de1_63c1b3201849 dacf5984_89ce_530d_f035_1eac4b0b8e1f["match_bracket()"] 6a786ac5_79fd_078b_6df2_8e1e4a370161 -->|calls| dacf5984_89ce_530d_f035_1eac4b0b8e1f bb0eb4c2_ab75_feac_3814_01d1e4346bb8["parse_expression_at()"] 6a786ac5_79fd_078b_6df2_8e1e4a370161 -->|calls| bb0eb4c2_ab75_feac_3814_01d1e4346bb8 style 6a786ac5_79fd_078b_6df2_8e1e4a370161 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/svelte/src/compiler/phases/1-parse/read/context.js lines 12–70
export default function read_pattern(parser) {
const start = parser.index;
let i = parser.index;
const id = parser.read_identifier();
if (id.name !== '') {
const annotation = read_type_annotation(parser);
return {
...id,
typeAnnotation: annotation
};
}
const char = parser.template[i];
if (char !== '{' && char !== '[') {
e.expected_pattern(i);
}
i = match_bracket(parser, start);
parser.index = i;
const pattern_string = parser.template.slice(start, i);
try {
// the length of the `space_with_newline` has to be start - 1
// because we added a `(` in front of the pattern_string,
// which shifted the entire string to right by 1
// so we offset it by removing 1 character in the `space_with_newline`
// to achieve that, we remove the 1st space encountered,
// so it will not affect the `column` of the node
let space_with_newline = parser.template
.slice(0, start)
.replace(regex_not_newline_characters, ' ');
const first_space = space_with_newline.indexOf(' ');
space_with_newline =
space_with_newline.slice(0, first_space) + space_with_newline.slice(first_space + 1);
const expression = /** @type {any} */ (
parse_expression_at(
`${space_with_newline}(${pattern_string} = 1)`,
parser.root.comments,
parser.ts,
start - 1
)
).left;
expression.typeAnnotation = read_type_annotation(parser);
if (expression.typeAnnotation) {
expression.end = expression.typeAnnotation.end;
}
return expression;
} catch (error) {
parser.acorn_error(error);
}
}
Domain
Subdomains
Source
Frequently Asked Questions
What does read_pattern() do?
read_pattern() is a function in the svelte codebase, defined in packages/svelte/src/compiler/phases/1-parse/read/context.js.
Where is read_pattern() defined?
read_pattern() is defined in packages/svelte/src/compiler/phases/1-parse/read/context.js at line 12.
What does read_pattern() call?
read_pattern() calls 4 function(s): expected_pattern, match_bracket, parse_expression_at, read_type_annotation.
What calls read_pattern()?
read_pattern() is called by 3 function(s): next, open, special.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free