diff --git a/Cargo.lock b/Cargo.lock index 74035c539..ebda1f7d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -399,9 +399,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.113" +version = "0.2.116" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eef78b64d87775463c549fbd80e19249ef436ea3bf1de2a1eb7e717ec7fab1e9" +checksum = "565dbd88872dbe4cc8a46e527f26483c1d1f7afa6b884a3bd6cd893d4f98da74" [[package]] name = "line-wrap" @@ -537,7 +537,7 @@ checksum = "db8bcd96cb740d03149cbad5518db9fd87126a10ab519c011893b1754134c468" [[package]] name = "pixglyph" version = "0.1.0" -source = "git+https://github.com/typst/pixglyph#b63319b30eb34bcd7f3f3bb4c253a0731bae4234" +source = "git+https://github.com/typst/pixglyph#da648abb60d0e0f4353cd7602652c832132e6a39" dependencies = [ "ttf-parser", ] @@ -769,18 +769,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.135" +version = "1.0.136" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cf9235533494ea2ddcdb794665461814781c53f19d87b76e571a1c35acbad2b" +checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.135" +version = "1.0.136" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8dcde03d87d4c973c04be249e7d8f0b35db1c848c487bd43032808e59dd8328d" +checksum = "08597e7152fcd306f41838ed3e37be9eaeed2b61c42e2117266a554fab4662f9" dependencies = [ "proc-macro2", "quote", diff --git a/src/eval/mod.rs b/src/eval/mod.rs index 05fa7ebad..2fa07d49e 100644 --- a/src/eval/mod.rs +++ b/src/eval/mod.rs @@ -187,7 +187,7 @@ fn process_nodes( ctx: &mut EvalContext, nodes: &mut impl Iterator, ) -> TypResult { - let prev = mem::take(&mut ctx.styles); + let prev_styles = mem::take(&mut ctx.styles); let mut seq = Vec::with_capacity(nodes.size_hint().1.unwrap_or_default()); while let Some(piece) = nodes.next() { // Need to deal with wrap here. @@ -201,7 +201,7 @@ fn process_nodes( seq.push(Styled::new(node, ctx.styles.clone())); } - ctx.styles = prev; + ctx.styles = prev_styles; Ok(Node::Sequence(seq)) } @@ -461,7 +461,10 @@ impl Eval for TemplateExpr { type Output = Node; fn eval(&self, ctx: &mut EvalContext) -> TypResult { - self.body().eval(ctx) + ctx.scopes.enter(); + let node = self.body().eval(ctx)?; + ctx.scopes.exit(); + Ok(node) } } diff --git a/src/library/mod.rs b/src/library/mod.rs index 81c8fcdc2..44f8f947f 100644 --- a/src/library/mod.rs +++ b/src/library/mod.rs @@ -17,7 +17,7 @@ pub mod list; pub mod pad; pub mod page; pub mod par; -pub mod placed; +pub mod place; pub mod shape; pub mod spacing; pub mod stack; @@ -40,7 +40,7 @@ pub use list::*; pub use pad::*; pub use page::*; pub use par::*; -pub use placed::*; +pub use place::*; pub use shape::*; pub use spacing::*; pub use stack::*; diff --git a/src/library/placed.rs b/src/library/place.rs similarity index 100% rename from src/library/placed.rs rename to src/library/place.rs diff --git a/tests/ref/style/wrap.png b/tests/ref/style/wrap.png index 346da53f8..82d1c34da 100644 Binary files a/tests/ref/style/wrap.png and b/tests/ref/style/wrap.png differ diff --git a/tests/typ/code/block.typ b/tests/typ/code/block.typ index 5939ba9c5..9122ea486 100644 --- a/tests/typ/code/block.typ +++ b/tests/typ/code/block.typ @@ -102,6 +102,13 @@ test(a, "a1") } +--- +// Template also creates a scope. +[#let x = 1] + +// Error: 2-3 unknown variable +{x} + --- // Multiple unseparated expressions in one line. diff --git a/tests/typ/style/wrap.typ b/tests/typ/style/wrap.typ index 5e0fdd0d7..1ff3cc95e 100644 --- a/tests/typ/style/wrap.typ +++ b/tests/typ/style/wrap.typ @@ -18,6 +18,12 @@ in booklovers and the great fulfiller of human need. // Test wrap in template. A [_B #wrap c in [*#c*]; C] D +--- +// Test wrap style precedence. +#set text(fill: eastern, size: 150%) +#wrap body in text(fill: forest, body) +Forest + --- // Error: 6-17 wrap is only allowed directly in markup {1 + wrap x in y}