Erase JS MIME types
This commit is contained in:
parent
3c90daa644
commit
bab73243d7
|
@ -45,8 +45,8 @@ const programs = {
|
||||||
removeScriptTypeAttributes: true,
|
removeScriptTypeAttributes: true,
|
||||||
removeStyleLinkTypeAttributes: true,
|
removeStyleLinkTypeAttributes: true,
|
||||||
removeTagWhitespace: true,
|
removeTagWhitespace: true,
|
||||||
sortAttributes: true,
|
sortAttributes: false,
|
||||||
sortClassName: true,
|
sortClassName: false,
|
||||||
trimCustomFragments: false,
|
trimCustomFragments: false,
|
||||||
useShortDoctype: true,
|
useShortDoctype: true,
|
||||||
}).length,
|
}).length,
|
||||||
|
@ -153,9 +153,9 @@ suite
|
||||||
.on('complete', async function () {
|
.on('complete', async function () {
|
||||||
const speedResults = this.map(b => ({
|
const speedResults = this.map(b => ({
|
||||||
name: b.name,
|
name: b.name,
|
||||||
count: b.count,
|
|
||||||
ops: b.hz,
|
ops: b.hz,
|
||||||
})).sort((a, b) => a.hz - b.hz);
|
}));
|
||||||
|
fs.writeFileSync(path.join(__dirname, "speed.json"), JSON.stringify(speedResults, null, 2));
|
||||||
await renderChart('speed', {
|
await renderChart('speed', {
|
||||||
type: 'bar',
|
type: 'bar',
|
||||||
data: {
|
data: {
|
||||||
|
@ -170,6 +170,7 @@ suite
|
||||||
|
|
||||||
const testNames = Object.keys(sizes);
|
const testNames = Object.keys(sizes);
|
||||||
const programNames = Object.keys(programs);
|
const programNames = Object.keys(programs);
|
||||||
|
fs.writeFileSync(path.join(__dirname, "minification.json"), JSON.stringify(sizes, null, 2));
|
||||||
await renderChart('minification', {
|
await renderChart('minification', {
|
||||||
type: 'bar',
|
type: 'bar',
|
||||||
scaleFontColor: 'red',
|
scaleFontColor: 'red',
|
||||||
|
|
|
@ -36,6 +36,7 @@ fn is_valid_tag_name_char(c: u8) -> bool {
|
||||||
is_alphanumeric(c) || c == b':' || c == b'-'
|
is_alphanumeric(c) || c == b':' || c == b'-'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
enum TagType {
|
enum TagType {
|
||||||
Script,
|
Script,
|
||||||
Style,
|
Style,
|
||||||
|
@ -89,8 +90,8 @@ pub fn process_tag(proc: &mut Processor, prev_sibling_closing_tag: Option<Proces
|
||||||
|
|
||||||
let mut last_attr_type: Option<AttrType> = None;
|
let mut last_attr_type: Option<AttrType> = None;
|
||||||
let mut self_closing = false;
|
let mut self_closing = false;
|
||||||
// Value of any "type" attribute; if multiple, last kept.
|
// Set to false if `tag_type` is Script and "type" attribute exists and has value that is not empty and not one of `JAVASCRIPT_MIME_TYPES`.
|
||||||
let mut attr_type_value: Option<ProcessorRange> = None;
|
let mut script_tag_type_is_js: bool = true;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
// At the beginning of this loop, the last parsed unit was either the tag name or an attribute (including its value, if it had one).
|
// At the beginning of this loop, the last parsed unit was either the tag name or an attribute (including its value, if it had one).
|
||||||
|
@ -111,6 +112,10 @@ pub fn process_tag(proc: &mut Processor, prev_sibling_closing_tag: Option<Proces
|
||||||
return Err(ErrorType::NoSpaceBeforeAttr);
|
return Err(ErrorType::NoSpaceBeforeAttr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mark attribute start in case we want to erase it completely.
|
||||||
|
let attr_checkpoint = proc.checkpoint();
|
||||||
|
let mut erase_attr = false;
|
||||||
|
|
||||||
// Write space after tag name or unquoted/valueless attribute.
|
// Write space after tag name or unquoted/valueless attribute.
|
||||||
// Don't write after unquoted.
|
// Don't write after unquoted.
|
||||||
match last_attr_type {
|
match last_attr_type {
|
||||||
|
@ -119,19 +124,29 @@ pub fn process_tag(proc: &mut Processor, prev_sibling_closing_tag: Option<Proces
|
||||||
};
|
};
|
||||||
|
|
||||||
let ProcessedAttr { name, typ, value } = process_attr(proc)?;
|
let ProcessedAttr { name, typ, value } = process_attr(proc)?;
|
||||||
match &proc[name] {
|
match (tag_type, &proc[name]) {
|
||||||
b"type" => attr_type_value = value,
|
(TagType::Script, b"type") => {
|
||||||
|
// It's JS if the value is empty or one of `JAVASCRIPT_MIME_TYPES`.
|
||||||
|
script_tag_type_is_js = value.filter(|v| !JAVASCRIPT_MIME_TYPES.contains(&proc[*v])).is_none();
|
||||||
|
if script_tag_type_is_js {
|
||||||
|
erase_attr = true;
|
||||||
|
};
|
||||||
|
},
|
||||||
_ => {}
|
_ => {}
|
||||||
};
|
};
|
||||||
|
if erase_attr {
|
||||||
|
proc.erase_written(attr_checkpoint);
|
||||||
|
} else {
|
||||||
last_attr_type = Some(typ);
|
last_attr_type = Some(typ);
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
|
||||||
if self_closing || VOID_TAGS.contains(&proc[opening_name_range]) {
|
if self_closing || VOID_TAGS.contains(&proc[opening_name_range]) {
|
||||||
return Ok(ProcessedTag { name: opening_name_range, closing_tag: None });
|
return Ok(ProcessedTag { name: opening_name_range, closing_tag: None });
|
||||||
};
|
};
|
||||||
|
|
||||||
match tag_type {
|
match tag_type {
|
||||||
TagType::Script => if attr_type_value.is_none() || attr_type_value.filter(|n| JAVASCRIPT_MIME_TYPES.contains(&proc[*n])).is_some() {
|
TagType::Script => if script_tag_type_is_js {
|
||||||
process_js_script(proc)?;
|
process_js_script(proc)?;
|
||||||
} else {
|
} else {
|
||||||
process_text_script(proc)?;
|
process_text_script(proc)?;
|
||||||
|
|
Loading…
Reference in New Issue